-/**
+/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
*/
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.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.sal.binding.api.NotificationService;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
+import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
+import org.opendaylight.mdsal.binding.api.NotificationService;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.LoggerFactory;
/**
- * Listens to packetIn notification and
+ * Listens to packetIn notification.
* <ul>
* <li>in HUB mode simply floods all switch ports (except ingress port)</li>
* <li>in LSWITCH mode collects source MAC address of packetIn and bind it with ingress port.
* corresponding MACs)</li>
* </ul>
*/
-public class LearningSwitchManagerSimpleImpl implements DataChangeListenerRegistrationHolder,
- LearningSwitchManager {
-
- protected 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<DataChangeListener> dataChangeListenerRegistration;
+ private ListenerRegistration<DataTreeChangeListener> dataTreeChangeListenerRegistration;
/**
+ * Sets the NotificationService.
+ *
* @param notificationService the notificationService to set
*/
@Override
}
/**
+ * Sets the PacketProcessingService.
+ *
* @param packetProcessingService the packetProcessingService to set
*/
@Override
}
/**
- * @param data the data to set
+ * Sets the DataBroker.
*/
@Override
- public void setDataBroker(DataBroker data) {
- this.data = data;
+ public void setDataBroker(DataBroker broker) {
+ data = broker;
}
/**
- * starting learning switch
+ * Starts learning switch.
*/
@Override
public void start() {
LOG.debug("start() -->");
FlowCommitWrapper dataStoreAccessor = new FlowCommitWrapperImpl(data);
- LearningSwitchHandlerSimpleImpl learningSwitchHandler = new LearningSwitchHandlerSimpleImpl();
- learningSwitchHandler.setRegistrationPublisher(this);
- learningSwitchHandler.setDataStoreAccessor(dataStoreAccessor);
- learningSwitchHandler.setPacketProcessingService(packetProcessingService);
- packetInRegistration = notificationService.registerNotificationListener(learningSwitchHandler);
+ LearningSwitchHandlerSimpleImpl learningSwitchHandler = new LearningSwitchHandlerSimpleImpl(dataStoreAccessor,
+ packetProcessingService, this);
+ packetInRegistration = notificationService.registerListener(PacketReceived.class, learningSwitchHandler);
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<Table> instanceIdentifier = InstanceIdentifier.create(Nodes.class)
+ .child(Node.class)
+ .augmentation(FlowCapableNode.class)
+ .child(Table.class);
+ final DataTreeIdentifier<Table> dataTreeIdentifier =
+ DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
+ dataTreeChangeListenerRegistration = data.registerDataTreeChangeListener(dataTreeIdentifier, wakeupListener);
LOG.debug("start() <--");
}
/**
- * stopping learning switch
+ * Stops the learning switch.
*/
@Override
public void stop() {
LOG.debug("stop() -->");
//TODO: remove flow (created in #start())
- try {
- packetInRegistration.close();
- } catch (Exception e) {
- LOG.warn("closing packetInRegistration failed: {}", e.getMessage());
- LOG.debug("closing packetInRegistration failed..", e);
- }
- try {
- dataChangeListenerRegistration.close();
- } catch (Exception e) {
- LOG.warn("failed to close dataChangeListenerRegistration: {}", e.getMessage());
- LOG.debug("failed to close dataChangeListenerRegistration..", e);
- }
+
+ packetInRegistration.close();
+
+ dataTreeChangeListenerRegistration.close();
+
LOG.debug("stop() <--");
}
-
@Override
- public ListenerRegistration<DataChangeListener> getDataChangeListenerRegistration() {
- return dataChangeListenerRegistration;
+ public ListenerRegistration<DataTreeChangeListener> getDataTreeChangeListenerRegistration() {
+ return dataTreeChangeListenerRegistration;
}
}