initial: learning switch example
[openflowplugin.git] / samples / learning-switch / src / main / java / org / opendaylight / openflowplugin / learningswitch / WakeupOnNode.java
1 /**
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowplugin.learningswitch;
10
11 import java.util.Map;
12 import java.util.Map.Entry;
13
14 import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
15 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * 
24  */
25 public class WakeupOnNode implements DataChangeListener {
26     
27     private static final Logger LOG = LoggerFactory
28             .getLogger(WakeupOnNode.class);
29     
30     private SimpleLearningSwitchHandler learningSwitchHandler;
31
32     @Override
33     public void onDataChanged(DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
34         Short requiredTableId = 0;
35         
36         // TODO add flow
37         Map<InstanceIdentifier<?>, DataObject> updated = change.getUpdatedOperationalData();
38         for (Entry<InstanceIdentifier<?>, DataObject> updateItem : updated.entrySet()) {
39             DataObject table = updateItem.getValue();
40             if (table instanceof Table) {
41                 Table tableSure = (Table) table;
42                 LOG.trace("table: {}", table);
43                 
44                 if (requiredTableId.equals(tableSure.getId())) {
45                     @SuppressWarnings("unchecked")
46                     InstanceIdentifier<Table> tablePath = (InstanceIdentifier<Table>) updateItem.getKey();
47                     learningSwitchHandler.onSwitchAppeared(tablePath);
48                 }
49             }
50         }
51     }
52     
53     /**
54      * @param learningSwitchHandler the learningSwitchHandler to set
55      */
56     public void setLearningSwitchHandler(
57             SimpleLearningSwitchHandler learningSwitchHandler) {
58         this.learningSwitchHandler = learningSwitchHandler;
59     }
60 }