2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.learningswitch.multi;
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.controller.sal.binding.api.NotificationService;
14 import org.opendaylight.openflowplugin.learningswitch.DataChangeListenerRegistrationHolder;
15 import org.opendaylight.openflowplugin.learningswitch.FlowCommitWrapper;
16 import org.opendaylight.openflowplugin.learningswitch.FlowCommitWrapperImpl;
17 import org.opendaylight.openflowplugin.learningswitch.LearningSwitchManager;
18 import org.opendaylight.openflowplugin.learningswitch.WakeupOnNode;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
24 import org.opendaylight.yangtools.concepts.ListenerRegistration;
25 import org.opendaylight.yangtools.concepts.Registration;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * Listens to packetIn notification and
33 * <li>in HUB mode simply floods all switch ports (except ingress port)</li>
34 * <li>in LSWITCH mode collects source MAC address of packetIn and bind it with ingress port.
35 * If target MAC address is already bound then a flow is created (for direct communication between
36 * corresponding MACs)</li>
39 public class LearningSwitchManagerMultiImpl implements DataChangeListenerRegistrationHolder,
40 LearningSwitchManager {
42 protected static final Logger LOG = LoggerFactory
43 .getLogger(LearningSwitchManagerMultiImpl.class);
45 private NotificationService notificationService;
46 private PacketProcessingService packetProcessingService;
47 private DataBroker data;
49 private Registration packetInRegistration;
51 private ListenerRegistration<DataChangeListener> dataChangeListenerRegistration;
54 * @param notificationService the notificationService to set
57 public void setNotificationService(NotificationService notificationService) {
58 this.notificationService = notificationService;
62 * @param packetProcessingService the packetProcessingService to set
65 public void setPacketProcessingService(
66 PacketProcessingService packetProcessingService) {
67 this.packetProcessingService = packetProcessingService;
71 * @param data the data to set
74 public void setDataBroker(DataBroker data) {
79 * starting learning switch
83 LOG.debug("start() -->");
84 FlowCommitWrapper dataStoreAccessor = new FlowCommitWrapperImpl(data);
86 PacketInDispatcherImpl packetInDispatcher = new PacketInDispatcherImpl();
87 MultipleLearningSwitchHandlerFacadeImpl learningSwitchHandler = new MultipleLearningSwitchHandlerFacadeImpl();
88 learningSwitchHandler.setRegistrationPublisher(this);
89 learningSwitchHandler.setDataStoreAccessor(dataStoreAccessor);
90 learningSwitchHandler.setPacketProcessingService(packetProcessingService);
91 learningSwitchHandler.setPacketInDispatcher(packetInDispatcher);
92 packetInRegistration = notificationService.registerNotificationListener(packetInDispatcher);
94 WakeupOnNode wakeupListener = new WakeupOnNode();
95 wakeupListener.setLearningSwitchHandler(learningSwitchHandler);
96 dataChangeListenerRegistration = data.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
97 InstanceIdentifier.builder(Nodes.class)
99 .augmentation(FlowCapableNode.class)
100 .child(Table.class).toInstance(),
102 DataBroker.DataChangeScope.SUBTREE);
103 LOG.debug("start() <--");
107 * stopping learning switch
111 LOG.debug("stop() -->");
112 //TODO: remove flow (created in #start())
114 packetInRegistration.close();
115 } catch (Exception e) {
116 LOG.error(e.getMessage(), e);
119 dataChangeListenerRegistration.close();
120 } catch (Exception e) {
121 LOG.error(e.getMessage(), e);
123 LOG.debug("stop() <--");
128 public ListenerRegistration<DataChangeListener> getDataChangeListenerRegistration() {
129 return dataChangeListenerRegistration;