Switch to MD-SAL APIs
[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 package org.opendaylight.openflowplugin.learningswitch;
9
10 import java.util.Collection;
11 import javax.annotation.Nonnull;
12 import org.opendaylight.mdsal.binding.api.DataObjectModification.ModificationType;
13 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
14 import org.opendaylight.mdsal.binding.api.DataTreeModification;
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 public class WakeupOnNode implements DataTreeChangeListener<Table> {
22
23     private static final Logger LOG = LoggerFactory.getLogger(WakeupOnNode.class);
24     private LearningSwitchHandler learningSwitchHandler;
25
26     @Override
27     public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<Table>> modifications) {
28         Short requiredTableId = 0;
29         // TODO add flow
30
31         for (DataTreeModification<Table> modification : modifications) {
32             if (modification.getRootNode().getModificationType() == ModificationType.SUBTREE_MODIFIED) {
33                 DataObject table = modification.getRootNode().getDataAfter();
34                 if (table instanceof Table) {
35                     Table tableSure = (Table) table;
36                     LOG.trace("table: {}", table);
37
38                     if (requiredTableId.equals(tableSure.getId())) {
39                         InstanceIdentifier<Table> tablePath =
40                                 modification.getRootPath().getRootIdentifier();
41                         learningSwitchHandler.onSwitchAppeared(tablePath);
42                     }
43                 }
44             }
45         }
46     }
47
48     /**
49      * Sets the LearningSwitchHandler.
50      *
51      * @param learningSwitchHandler the learningSwitchHandler to set
52      */
53     public void setLearningSwitchHandler(
54             LearningSwitchHandler learningSwitchHandler) {
55         this.learningSwitchHandler = learningSwitchHandler;
56     }
57 }