c355cc4f4f4e4ade3ed5016e13f212d02a01237e
[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 org.opendaylight.mdsal.binding.api.DataObjectModification.ModificationType;
12 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
13 import org.opendaylight.mdsal.binding.api.DataTreeModification;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
15 import org.opendaylight.yangtools.yang.common.Uint8;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public class WakeupOnNode implements DataTreeChangeListener<Table> {
20     private static final Logger LOG = LoggerFactory.getLogger(WakeupOnNode.class);
21
22     private LearningSwitchHandler learningSwitchHandler = null;
23
24     @Override
25     public void onDataTreeChanged(final Collection<DataTreeModification<Table>> modifications) {
26         Uint8 requiredTableId = Uint8.ZERO;
27         // TODO add flow
28
29         for (var modification : modifications) {
30             if (modification.getRootNode().getModificationType() == ModificationType.SUBTREE_MODIFIED) {
31                 var table = modification.getRootNode().getDataAfter();
32                 if (table != null) {
33                     LOG.trace("table: {}", table);
34                     if (requiredTableId.equals(table.getId())) {
35                         learningSwitchHandler.onSwitchAppeared(modification.getRootPath().getRootIdentifier());
36                     }
37                 }
38             }
39         }
40     }
41
42     /**
43      * Sets the LearningSwitchHandler.
44      *
45      * @param learningSwitchHandler the learningSwitchHandler to set
46      */
47     public void setLearningSwitchHandler(final LearningSwitchHandler learningSwitchHandler) {
48         this.learningSwitchHandler = learningSwitchHandler;
49     }
50 }