From 7318454368be093d0e1f0eff98ca90f08f4bfab0 Mon Sep 17 00:00:00 2001 From: Andrej Leitner Date: Wed, 14 Sep 2016 16:25:50 +0200 Subject: [PATCH] Convert OF samples to use DTCL instead of DCL Change-Id: I53eebe8672996ed4351240a8c649e6c2815e8a0c Signed-off-by: Andrej Leitner --- .../learningswitch/Activator.java | 8 +--- ...TreeChangeListenerRegistrationHolder.java} | 10 ++--- .../learningswitch/FlowUtils.java | 4 +- .../InstanceIdentifierUtils.java | 5 --- .../learningswitch/LearningSwitchHandler.java | 2 +- .../LearningSwitchHandlerSimpleImpl.java | 12 ++---- .../LearningSwitchManagerSimpleImpl.java | 38 ++++++++---------- .../learningswitch/WakeupOnNode.java | 40 +++++++++---------- .../multi/LearningSwitchManagerMultiImpl.java | 35 +++++++--------- ...ltipleLearningSwitchHandlerFacadeImpl.java | 29 +++++--------- .../multi/PacketInDispatcherImpl.java | 18 +++------ .../samples/consumer/SimpleDropFirewall.java | 38 +++++++----------- 12 files changed, 93 insertions(+), 146 deletions(-) rename samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/{DataChangeListenerRegistrationHolder.java => DataTreeChangeListenerRegistrationHolder.java} (54%) diff --git a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/Activator.java b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/Activator.java index cd308d59b2..7201fdd353 100644 --- a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/Activator.java +++ b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/Activator.java @@ -18,8 +18,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * learning switch activator - *

+ * Learning switch activator * Activator is derived from AbstractBindingAwareConsumer, which takes care * of looking up MD-SAL in Service Registry and registering consumer * when MD-SAL is present. @@ -27,10 +26,8 @@ import org.slf4j.LoggerFactory; public class Activator extends AbstractBindingAwareConsumer implements AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(Activator.class); - private LearningSwitchManager learningSwitch; - @Override protected void startImpl(BundleContext context) { LOG.info("startImpl() passing"); @@ -46,11 +43,10 @@ public class Activator extends AbstractBindingAwareConsumer implements AutoClose * We create instance of our LearningSwitchManager * and set all required dependencies, * - * which are + * which are * Data Broker (data storage service) - for configuring flows and reading stored switch state * PacketProcessingService - for sending out packets * NotificationService - for receiving notifications such as packet in. - * */ learningSwitch = new LearningSwitchManagerMultiImpl(); learningSwitch.setDataBroker(session.getSALService(DataBroker.class)); diff --git a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/DataChangeListenerRegistrationHolder.java b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/DataTreeChangeListenerRegistrationHolder.java similarity index 54% rename from samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/DataChangeListenerRegistrationHolder.java rename to samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/DataTreeChangeListenerRegistrationHolder.java index a480ec4915..34593097cf 100644 --- a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/DataChangeListenerRegistrationHolder.java +++ b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/DataTreeChangeListenerRegistrationHolder.java @@ -8,17 +8,17 @@ package org.opendaylight.openflowplugin.learningswitch; -import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; +import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; import org.opendaylight.yangtools.concepts.ListenerRegistration; /** - * + * Holder for {@link org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener} registration. */ -public interface DataChangeListenerRegistrationHolder { +public interface DataTreeChangeListenerRegistrationHolder { /** - * @return the dataChangeListenerRegistration + * @return the DataTreeChangeListenerRegistration */ - ListenerRegistration getDataChangeListenerRegistration(); + ListenerRegistration getDataTreeChangeListenerRegistration(); } diff --git a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/FlowUtils.java b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/FlowUtils.java index aa44ea007f..e9eb2993ff 100644 --- a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/FlowUtils.java +++ b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/FlowUtils.java @@ -8,9 +8,9 @@ package org.opendaylight.openflowplugin.learningswitch; +import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.List; - import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; @@ -40,8 +40,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder; -import com.google.common.collect.ImmutableList; - public class FlowUtils { private FlowUtils() { //prohibite to instantiate util class diff --git a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/InstanceIdentifierUtils.java b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/InstanceIdentifierUtils.java index e409d58ad5..d99a0e7a51 100644 --- a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/InstanceIdentifierUtils.java +++ b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/InstanceIdentifierUtils.java @@ -21,7 +21,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.N import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - public class InstanceIdentifierUtils { private InstanceIdentifierUtils() { @@ -50,7 +49,6 @@ public class InstanceIdentifierUtils { return nodeChild.firstIdentifierOf(Node.class); } - /** * Creates a table path by appending table specific location to node path * @@ -86,14 +84,11 @@ public class InstanceIdentifierUtils { /** * Extracts NodeConnectorKey from node connector path. - * */ public static NodeConnectorKey getNodeConnectorKey(final InstanceIdentifier nodeConnectorPath) { return nodeConnectorPath.firstKeyOf(NodeConnector.class, NodeConnectorKey.class); } - - // public static final InstanceIdentifier createNodeConnectorPath(final InstanceIdentifier nodeKey,final NodeConnectorKey nodeConnectorKey) { return nodeKey.child(NodeConnector.class,nodeConnectorKey); } diff --git a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/LearningSwitchHandler.java b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/LearningSwitchHandler.java index be0aca404c..238c09be64 100644 --- a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/LearningSwitchHandler.java +++ b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/LearningSwitchHandler.java @@ -34,5 +34,5 @@ public interface LearningSwitchHandler { /** * @param registrationPublisher the registrationPublisher to set */ - void setRegistrationPublisher(DataChangeListenerRegistrationHolder registrationPublisher); + void setRegistrationPublisher(DataTreeChangeListenerRegistrationHolder registrationPublisher); } diff --git a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/LearningSwitchHandlerSimpleImpl.java b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/LearningSwitchHandlerSimpleImpl.java index 20063df139..7a953f53e6 100644 --- a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/LearningSwitchHandlerSimpleImpl.java +++ b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/LearningSwitchHandlerSimpleImpl.java @@ -42,18 +42,14 @@ import org.slf4j.LoggerFactory; /** * Simple Learning Switch implementation which does mac learning for one switch. - * - * */ public class LearningSwitchHandlerSimpleImpl implements LearningSwitchHandler, PacketProcessingListener { private static final Logger LOG = LoggerFactory.getLogger(LearningSwitchHandlerSimpleImpl.class); - private static final byte[] ETH_TYPE_IPV4 = new byte[] { 0x08, 0x00 }; - private static final int DIRECT_FLOW_PRIORITY = 512; - private DataChangeListenerRegistrationHolder registrationPublisher; + private DataTreeChangeListenerRegistrationHolder registrationPublisher; private FlowCommitWrapper dataStoreAccessor; private PacketProcessingService packetProcessingService; @@ -81,8 +77,8 @@ public class LearningSwitchHandlerSimpleImpl implements LearningSwitchHandler, P // disable listening - simple learning handles only one node (switch) if (registrationPublisher != null) { try { - LOG.debug("closing dataChangeListenerRegistration"); - registrationPublisher.getDataChangeListenerRegistration().close(); + LOG.debug("closing dataTreeChangeListenerRegistration"); + registrationPublisher.getDataTreeChangeListenerRegistration().close(); } catch (Exception e) { LOG.warn("closing registration upon flowCapable node update listener failed: {}", e.getMessage()); LOG.debug("closing registration upon flowCapable node update listener failed.. ", e); @@ -113,7 +109,7 @@ public class LearningSwitchHandlerSimpleImpl implements LearningSwitchHandler, P } @Override - public void setRegistrationPublisher(DataChangeListenerRegistrationHolder registrationPublisher) { + public void setRegistrationPublisher(DataTreeChangeListenerRegistrationHolder registrationPublisher) { this.registrationPublisher = registrationPublisher; } diff --git a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/LearningSwitchManagerSimpleImpl.java b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/LearningSwitchManagerSimpleImpl.java index 9b97e801eb..b0195e6ab6 100644 --- a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/LearningSwitchManagerSimpleImpl.java +++ b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/LearningSwitchManagerSimpleImpl.java @@ -8,7 +8,8 @@ package org.opendaylight.openflowplugin.learningswitch; import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; +import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; +import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.sal.binding.api.NotificationService; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; @@ -31,19 +32,14 @@ import org.slf4j.LoggerFactory; * corresponding MACs) * */ -public class LearningSwitchManagerSimpleImpl implements DataChangeListenerRegistrationHolder, - LearningSwitchManager { - - private static final Logger LOG = LoggerFactory - .getLogger(LearningSwitchManagerSimpleImpl.class); +public class LearningSwitchManagerSimpleImpl implements DataTreeChangeListenerRegistrationHolder, LearningSwitchManager { + private static final Logger LOG = LoggerFactory.getLogger(LearningSwitchManagerSimpleImpl.class); private NotificationService notificationService; private PacketProcessingService packetProcessingService; private DataBroker data; - private Registration packetInRegistration; - - private ListenerRegistration dataChangeListenerRegistration; + private ListenerRegistration dataTreeChangeListenerRegistration; /** * @param notificationService the notificationService to set @@ -86,13 +82,12 @@ public class LearningSwitchManagerSimpleImpl implements DataChangeListenerRegist WakeupOnNode wakeupListener = new WakeupOnNode(); wakeupListener.setLearningSwitchHandler(learningSwitchHandler); - dataChangeListenerRegistration = data.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, - InstanceIdentifier.builder(Nodes.class) - .child(Node.class) - .augmentation(FlowCapableNode.class) - .child(Table.class).build(), - wakeupListener, - DataBroker.DataChangeScope.SUBTREE); + final InstanceIdentifier instanceIdentifier = InstanceIdentifier.create(Nodes.class) + .child(Node.class) + .augmentation(FlowCapableNode.class) + .child(Table.class); + final DataTreeIdentifier
dataTreeIdentifier = new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, instanceIdentifier); + dataTreeChangeListenerRegistration = data.registerDataTreeChangeListener(dataTreeIdentifier, wakeupListener); LOG.debug("start() <--"); } @@ -110,17 +105,16 @@ public class LearningSwitchManagerSimpleImpl implements DataChangeListenerRegist LOG.debug("closing packetInRegistration failed..", e); } try { - dataChangeListenerRegistration.close(); + dataTreeChangeListenerRegistration.close(); } catch (Exception e) { - LOG.warn("failed to close dataChangeListenerRegistration: {}", e.getMessage()); - LOG.debug("failed to close dataChangeListenerRegistration..", e); + LOG.warn("failed to close dataTreeChangeListenerRegistration: {}", e.getMessage()); + LOG.debug("failed to close dataTreeChangeListenerRegistration..", e); } LOG.debug("stop() <--"); } - @Override - public ListenerRegistration getDataChangeListenerRegistration() { - return dataChangeListenerRegistration; + public ListenerRegistration getDataTreeChangeListenerRegistration() { + return dataTreeChangeListenerRegistration; } } diff --git a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/WakeupOnNode.java b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/WakeupOnNode.java index 7a860ffed7..a8fd52c5d1 100644 --- a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/WakeupOnNode.java +++ b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/WakeupOnNode.java @@ -8,10 +8,11 @@ package org.opendaylight.openflowplugin.learningswitch; -import java.util.Map; -import java.util.Map.Entry; -import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; +import java.util.Collection; +import javax.annotation.Nonnull; +import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType; +import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; +import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -21,30 +22,27 @@ import org.slf4j.LoggerFactory; /** * */ -public class WakeupOnNode implements DataChangeListener { - - private static final Logger LOG = LoggerFactory - .getLogger(WakeupOnNode.class); +public class WakeupOnNode implements DataTreeChangeListener
{ + private static final Logger LOG = LoggerFactory.getLogger(WakeupOnNode.class); private LearningSwitchHandler learningSwitchHandler; @Override - public void onDataChanged(AsyncDataChangeEvent, DataObject> change) { + public void onDataTreeChanged(@Nonnull Collection> modifications) { Short requiredTableId = 0; - // TODO add flow - Map, DataObject> updated = change.getUpdatedData(); - for (Entry, DataObject> updateItem : updated.entrySet()) { - DataObject table = updateItem.getValue(); - if (table instanceof Table) { - Table tableSure = (Table) table; - LOG.trace("table: {}", table); - - if (requiredTableId.equals(tableSure.getId())) { - @SuppressWarnings("unchecked") - InstanceIdentifier
tablePath = (InstanceIdentifier
) updateItem.getKey(); - learningSwitchHandler.onSwitchAppeared(tablePath); + for (DataTreeModification modification : modifications) { + if (modification.getRootNode().getModificationType() == ModificationType.SUBTREE_MODIFIED) { + DataObject table = modification.getRootNode().getDataAfter(); + if (table instanceof Table) { + Table tableSure = (Table) table; + LOG.trace("table: {}", table); + + if (requiredTableId.equals(tableSure.getId())) { + InstanceIdentifier
tablePath = (InstanceIdentifier
) modification.getRootPath().getRootIdentifier(); + learningSwitchHandler.onSwitchAppeared(tablePath); + } } } } diff --git a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/multi/LearningSwitchManagerMultiImpl.java b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/multi/LearningSwitchManagerMultiImpl.java index e70303ce09..4092753fdc 100644 --- a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/multi/LearningSwitchManagerMultiImpl.java +++ b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/multi/LearningSwitchManagerMultiImpl.java @@ -8,10 +8,11 @@ package org.opendaylight.openflowplugin.learningswitch.multi; import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; +import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; +import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.sal.binding.api.NotificationService; -import org.opendaylight.openflowplugin.learningswitch.DataChangeListenerRegistrationHolder; +import org.opendaylight.openflowplugin.learningswitch.DataTreeChangeListenerRegistrationHolder; import org.opendaylight.openflowplugin.learningswitch.FlowCommitWrapper; import org.opendaylight.openflowplugin.learningswitch.FlowCommitWrapperImpl; import org.opendaylight.openflowplugin.learningswitch.LearningSwitchManager; @@ -36,19 +37,14 @@ import org.slf4j.LoggerFactory; * corresponding MACs) * */ -public class LearningSwitchManagerMultiImpl implements DataChangeListenerRegistrationHolder, - LearningSwitchManager { - - private static final Logger LOG = LoggerFactory - .getLogger(LearningSwitchManagerMultiImpl.class); +public class LearningSwitchManagerMultiImpl implements DataTreeChangeListenerRegistrationHolder, LearningSwitchManager { + private static final Logger LOG = LoggerFactory.getLogger(LearningSwitchManagerMultiImpl.class); private NotificationService notificationService; private PacketProcessingService packetProcessingService; private DataBroker data; - private Registration packetInRegistration; - - private ListenerRegistration dataChangeListenerRegistration; + private ListenerRegistration dataTreeChangeListenerRegistration; /** * @param notificationService the notificationService to set @@ -93,13 +89,12 @@ public class LearningSwitchManagerMultiImpl implements DataChangeListenerRegistr WakeupOnNode wakeupListener = new WakeupOnNode(); wakeupListener.setLearningSwitchHandler(learningSwitchHandler); - dataChangeListenerRegistration = data.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, - InstanceIdentifier.builder(Nodes.class) - .child(Node.class) - .augmentation(FlowCapableNode.class) - .child(Table.class).build(), - wakeupListener, - DataBroker.DataChangeScope.SUBTREE); + final InstanceIdentifier
instanceIdentifier = InstanceIdentifier.create(Nodes.class) + .child(Node.class) + .augmentation(FlowCapableNode.class) + .child(Table.class); + final DataTreeIdentifier
dataTreeIdentifier = new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, instanceIdentifier); + dataTreeChangeListenerRegistration = data.registerDataTreeChangeListener(dataTreeIdentifier, wakeupListener); LOG.debug("start() <--"); } @@ -117,7 +112,7 @@ public class LearningSwitchManagerMultiImpl implements DataChangeListenerRegistr LOG.debug("Error unregistering packet in listener.. ", e); } try { - dataChangeListenerRegistration.close(); + dataTreeChangeListenerRegistration.close(); } catch (Exception e) { LOG.warn("Error unregistering data change listener: {}", e.getMessage()); LOG.debug("Error unregistering data change listener.. ", e); @@ -127,7 +122,7 @@ public class LearningSwitchManagerMultiImpl implements DataChangeListenerRegistr @Override - public ListenerRegistration getDataChangeListenerRegistration() { - return dataChangeListenerRegistration; + public ListenerRegistration getDataTreeChangeListenerRegistration() { + return dataTreeChangeListenerRegistration; } } diff --git a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/multi/MultipleLearningSwitchHandlerFacadeImpl.java b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/multi/MultipleLearningSwitchHandlerFacadeImpl.java index 7824dce3fd..7f08744af8 100644 --- a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/multi/MultipleLearningSwitchHandlerFacadeImpl.java +++ b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/multi/MultipleLearningSwitchHandlerFacadeImpl.java @@ -8,9 +8,9 @@ package org.opendaylight.openflowplugin.learningswitch.multi; -import org.opendaylight.openflowplugin.learningswitch.DataChangeListenerRegistrationHolder; -import org.opendaylight.openflowplugin.learningswitch.InstanceIdentifierUtils; +import org.opendaylight.openflowplugin.learningswitch.DataTreeChangeListenerRegistrationHolder; import org.opendaylight.openflowplugin.learningswitch.FlowCommitWrapper; +import org.opendaylight.openflowplugin.learningswitch.InstanceIdentifierUtils; import org.opendaylight.openflowplugin.learningswitch.LearningSwitchHandler; import org.opendaylight.openflowplugin.learningswitch.LearningSwitchHandlerSimpleImpl; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table; @@ -20,14 +20,9 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * - */ public class MultipleLearningSwitchHandlerFacadeImpl implements LearningSwitchHandler { - - private static final Logger LOG = LoggerFactory - .getLogger(MultipleLearningSwitchHandlerFacadeImpl.class); - + + private static final Logger LOG = LoggerFactory.getLogger(MultipleLearningSwitchHandlerFacadeImpl.class); private FlowCommitWrapper dataStoreAccessor; private PacketProcessingService packetProcessingService; private PacketInDispatcherImpl packetInDispatcher; @@ -35,28 +30,26 @@ public class MultipleLearningSwitchHandlerFacadeImpl implements LearningSwitchHa @Override public synchronized void onSwitchAppeared(InstanceIdentifier
appearedTablePath) { LOG.debug("expected table acquired, learning .."); - + /** * appearedTablePath is in form of /nodes/node/node-id/table/table-id * so we shorten it to /nodes/node/node-id to get identifier of switch. - * */ InstanceIdentifier nodePath = InstanceIdentifierUtils.getNodePath(appearedTablePath); - + /** * We check if we already initialized dispatcher for that node, * if not we create new handler for switch. - * */ if (!packetInDispatcher.getHandlerMapping().containsKey(nodePath)) { - // delegate this node (owning appearedTable) to SimpleLearningSwitchHandler + // delegate this node (owning appearedTable) to SimpleLearningSwitchHandler LearningSwitchHandlerSimpleImpl simpleLearningSwitch = new LearningSwitchHandlerSimpleImpl(); /** * We set runtime dependencies */ simpleLearningSwitch.setDataStoreAccessor(dataStoreAccessor); simpleLearningSwitch.setPacketProcessingService(packetProcessingService); - + /** * We propagate table event to newly instantiated instance of learning switch */ @@ -70,15 +63,15 @@ public class MultipleLearningSwitchHandlerFacadeImpl implements LearningSwitchHa @Override public void setRegistrationPublisher( - DataChangeListenerRegistrationHolder registrationPublisher) { + DataTreeChangeListenerRegistrationHolder registrationPublisher) { //NOOP } - + @Override public void setDataStoreAccessor(FlowCommitWrapper dataStoreAccessor) { this.dataStoreAccessor = dataStoreAccessor; } - + @Override public void setPacketProcessingService( PacketProcessingService packetProcessingService) { diff --git a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/multi/PacketInDispatcherImpl.java b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/multi/PacketInDispatcherImpl.java index 30abfdc9bc..b8058c964b 100644 --- a/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/multi/PacketInDispatcherImpl.java +++ b/samples/learning-switch/src/main/java/org/opendaylight/openflowplugin/learningswitch/multi/PacketInDispatcherImpl.java @@ -10,19 +10,15 @@ package org.opendaylight.openflowplugin.learningswitch.multi; import java.util.HashMap; import java.util.Map; - import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingListener; import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -/** - * - */ public class PacketInDispatcherImpl implements PacketProcessingListener { - + private Map, PacketProcessingListener> handlerMapping; - + /** * default constructor */ @@ -36,30 +32,26 @@ public class PacketInDispatcherImpl implements PacketProcessingListener { /** * Notification contains reference to ingress port * in a form of path in inventory: /nodes/node/node-connector - * + * * In order to get path we shorten path to the first node reference * by using firstIdentifierOf helper method provided by InstanceIdentifier, * this will effectively shorten the path to /nodes/node. - * */ InstanceIdentifier ingressPort = notification.getIngress().getValue(); InstanceIdentifier nodeOfPacket = ingressPort.firstIdentifierOf(Node.class); /** * We lookup up the the packet-in listener for this node. - * */ PacketProcessingListener nodeHandler = handlerMapping.get(nodeOfPacket); - + /** - * * If we have packet-processing listener, we delegate notification. - * */ if (nodeHandler != null) { nodeHandler.onPacketReceived(notification); } } - + /** * @return the handlerMapping */ diff --git a/samples/sample-consumer/src/main/java/org/opendaylight/openflowplugin/openflow/samples/consumer/SimpleDropFirewall.java b/samples/sample-consumer/src/main/java/org/opendaylight/openflowplugin/openflow/samples/consumer/SimpleDropFirewall.java index 842fd62065..f9be98fe0a 100644 --- a/samples/sample-consumer/src/main/java/org/opendaylight/openflowplugin/openflow/samples/consumer/SimpleDropFirewall.java +++ b/samples/sample-consumer/src/main/java/org/opendaylight/openflowplugin/openflow/samples/consumer/SimpleDropFirewall.java @@ -7,19 +7,18 @@ */ package org.opendaylight.openflowplugin.openflow.samples.consumer; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; +import java.util.Collection; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; - -import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent; +import javax.annotation.Nonnull; +import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType; +import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; +import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext; import org.opendaylight.controller.sal.binding.api.NotificationService; import org.opendaylight.controller.sal.binding.api.data.DataBrokerService; -import org.opendaylight.controller.sal.binding.api.data.DataChangeListener; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService; @@ -29,17 +28,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRem import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.OpendaylightInventoryListener; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; public class SimpleDropFirewall { private ConsumerContext context; private SalFlowService flowService; - private DataChangeListener listener = new NodeListener(); - private DataBrokerService data; - + private DataTreeChangeListener listener = new NodeListener(); + private DataBrokerService data; + public void setContext(ConsumerContext session) { this.context = session; } @@ -58,20 +55,13 @@ public class SimpleDropFirewall { return result.get(5, TimeUnit.SECONDS).isSuccessful(); } - - private class NodeListener implements DataChangeListener { - - + + private class NodeListener implements DataTreeChangeListener { @Override - public void onDataChanged( - DataChangeEvent, DataObject> change) { - - Map, DataObject> updated = change.getUpdatedConfigurationData(); - Set, DataObject>> set = updated.entrySet(); - for (Entry, DataObject> entry : set) { - Class changedObjectType = entry.getKey().getTargetType(); - if(Node.class.equals(changedObjectType)) { - // We now that this is node updated + public void onDataTreeChanged(@Nonnull Collection> modifications) { + for (DataTreeModification modification : modifications) { + if (modification.getRootNode().getModificationType() == ModificationType.SUBTREE_MODIFIED) { + // node updated } } } -- 2.36.6