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.DataTreeChangeListener;
12 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.controller.sal.binding.api.NotificationService;
15 import org.opendaylight.openflowplugin.learningswitch.DataTreeChangeListenerRegistrationHolder;
16 import org.opendaylight.openflowplugin.learningswitch.FlowCommitWrapper;
17 import org.opendaylight.openflowplugin.learningswitch.FlowCommitWrapperImpl;
18 import org.opendaylight.openflowplugin.learningswitch.LearningSwitchManager;
19 import org.opendaylight.openflowplugin.learningswitch.WakeupOnNode;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
25 import org.opendaylight.yangtools.concepts.ListenerRegistration;
26 import org.opendaylight.yangtools.concepts.Registration;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * Listens to packetIn notification and
34 * <li>in HUB mode simply floods all switch ports (except ingress port)</li>
35 * <li>in LSWITCH mode collects source MAC address of packetIn and bind it with ingress port.
36 * If target MAC address is already bound then a flow is created (for direct communication between
37 * corresponding MACs)</li>
40 public class LearningSwitchManagerMultiImpl implements DataTreeChangeListenerRegistrationHolder, LearningSwitchManager {
42 private static final Logger LOG = LoggerFactory.getLogger(LearningSwitchManagerMultiImpl.class);
43 private NotificationService notificationService;
44 private PacketProcessingService packetProcessingService;
45 private DataBroker data;
46 private Registration packetInRegistration;
47 private ListenerRegistration<DataTreeChangeListener> dataTreeChangeListenerRegistration;
50 * @param notificationService the notificationService to set
53 public void setNotificationService(NotificationService notificationService) {
54 this.notificationService = notificationService;
58 * @param packetProcessingService the packetProcessingService to set
61 public void setPacketProcessingService(
62 PacketProcessingService packetProcessingService) {
63 this.packetProcessingService = packetProcessingService;
67 * @param data the data to set
70 public void setDataBroker(DataBroker data) {
75 * starting learning switch
79 LOG.debug("start() -->");
80 FlowCommitWrapper dataStoreAccessor = new FlowCommitWrapperImpl(data);
82 PacketInDispatcherImpl packetInDispatcher = new PacketInDispatcherImpl();
83 MultipleLearningSwitchHandlerFacadeImpl learningSwitchHandler = new MultipleLearningSwitchHandlerFacadeImpl();
84 learningSwitchHandler.setRegistrationPublisher(this);
85 learningSwitchHandler.setDataStoreAccessor(dataStoreAccessor);
86 learningSwitchHandler.setPacketProcessingService(packetProcessingService);
87 learningSwitchHandler.setPacketInDispatcher(packetInDispatcher);
88 packetInRegistration = notificationService.registerNotificationListener(packetInDispatcher);
90 WakeupOnNode wakeupListener = new WakeupOnNode();
91 wakeupListener.setLearningSwitchHandler(learningSwitchHandler);
92 final InstanceIdentifier<Table> instanceIdentifier = InstanceIdentifier.create(Nodes.class)
94 .augmentation(FlowCapableNode.class)
96 final DataTreeIdentifier<Table> dataTreeIdentifier = new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
97 dataTreeChangeListenerRegistration = data.registerDataTreeChangeListener(dataTreeIdentifier, wakeupListener);
98 LOG.debug("start() <--");
102 * stopping learning switch
106 LOG.debug("stop() -->");
107 //TODO: remove flow (created in #start())
109 packetInRegistration.close();
110 } catch (Exception e) {
111 LOG.warn("Error unregistering packet in listener: {}", e.getMessage());
112 LOG.debug("Error unregistering packet in listener.. ", e);
115 dataTreeChangeListenerRegistration.close();
116 } catch (Exception e) {
117 LOG.warn("Error unregistering data change listener: {}", e.getMessage());
118 LOG.debug("Error unregistering data change listener.. ", e);
120 LOG.debug("stop() <--");
125 public ListenerRegistration<DataTreeChangeListener> getDataTreeChangeListenerRegistration() {
126 return dataTreeChangeListenerRegistration;