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.sal.binding.api.NotificationService;
11 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
12 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
13 import org.opendaylight.openflowplugin.learningswitch.DataChangeListenerRegistrationHolder;
14 import org.opendaylight.openflowplugin.learningswitch.LearningSwitchManager;
15 import org.opendaylight.openflowplugin.learningswitch.FlowCommitWrapper;
16 import org.opendaylight.openflowplugin.learningswitch.FlowCommitWrapperImpl;
17 import org.opendaylight.openflowplugin.learningswitch.WakeupOnNode;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
23 import org.opendaylight.yangtools.concepts.ListenerRegistration;
24 import org.opendaylight.yangtools.concepts.Registration;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.opendaylight.yangtools.yang.binding.NotificationListener;
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 DataBrokerService 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(DataBrokerService 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(
97 InstanceIdentifier.builder(Nodes.class)
99 .augmentation(FlowCapableNode.class)
100 .child(Table.class).toInstance(),
102 LOG.debug("start() <--");
106 * stopping learning switch
110 LOG.debug("stop() -->");
111 //TODO: remove flow (created in #start())
113 packetInRegistration.close();
114 } catch (Exception e) {
115 LOG.error(e.getMessage(), e);
118 dataChangeListenerRegistration.close();
119 } catch (Exception e) {
120 LOG.error(e.getMessage(), e);
122 LOG.debug("stop() <--");
127 public ListenerRegistration<DataChangeListener> getDataChangeListenerRegistration() {
128 return dataChangeListenerRegistration;