Convert OF samples to use DTCL instead of DCL
[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.Collection;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
14 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
15 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
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 DataTreeChangeListener<Table> {
26
27     private static final Logger LOG = LoggerFactory.getLogger(WakeupOnNode.class);
28     private LearningSwitchHandler learningSwitchHandler;
29
30     @Override
31     public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<Table>> modifications) {
32         Short requiredTableId = 0;
33         // TODO add flow
34
35         for (DataTreeModification modification : modifications) {
36             if (modification.getRootNode().getModificationType() == ModificationType.SUBTREE_MODIFIED) {
37                 DataObject table = modification.getRootNode().getDataAfter();
38                 if (table instanceof Table) {
39                     Table tableSure = (Table) table;
40                     LOG.trace("table: {}", table);
41
42                     if (requiredTableId.equals(tableSure.getId())) {
43                         InstanceIdentifier<Table> tablePath = (InstanceIdentifier<Table>) modification.getRootPath().getRootIdentifier();
44                         learningSwitchHandler.onSwitchAppeared(tablePath);
45                     }
46                 }
47             }
48         }
49     }
50
51     /**
52      * @param learningSwitchHandler the learningSwitchHandler to set
53      */
54     public void setLearningSwitchHandler(
55             LearningSwitchHandler learningSwitchHandler) {
56         this.learningSwitchHandler = learningSwitchHandler;
57     }
58
59 }