learning switch shifted to new data broker API
[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 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
14 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  *
23  */
24 public class WakeupOnNode implements DataChangeListener {
25
26     private static final Logger LOG = LoggerFactory
27             .getLogger(WakeupOnNode.class);
28
29     private LearningSwitchHandler learningSwitchHandler;
30
31     @Override
32     public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
33         Short requiredTableId = 0;
34
35         // TODO add flow
36
37         Map<InstanceIdentifier<?>, DataObject> updated = change.getUpdatedData();
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             LearningSwitchHandler learningSwitchHandler) {
58         this.learningSwitchHandler = learningSwitchHandler;
59     }
60
61 }