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.mdsal.binding.api.DataBroker;
11 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
12 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
13 import org.opendaylight.mdsal.binding.api.NotificationService;
14 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
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.
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 * Sets the NotificationService.
52 * @param notificationService the notificationService to set
55 public void setNotificationService(NotificationService notificationService) {
56 this.notificationService = notificationService;
60 * Sets the PacketProcessingService.
62 * @param packetProcessingService the packetProcessingService to set
65 public void setPacketProcessingService(
66 PacketProcessingService packetProcessingService) {
67 this.packetProcessingService = packetProcessingService;
71 * Sets the DataBroker.
73 * @param broker the data to set
76 public void setDataBroker(DataBroker broker) {
81 * Starts learning switch.
85 LOG.debug("start() -->");
86 FlowCommitWrapper dataStoreAccessor = new FlowCommitWrapperImpl(data);
88 PacketInDispatcherImpl packetInDispatcher = new PacketInDispatcherImpl();
89 MultipleLearningSwitchHandlerFacadeImpl learningSwitchHandler = new MultipleLearningSwitchHandlerFacadeImpl(
90 dataStoreAccessor, packetProcessingService, packetInDispatcher);
91 packetInRegistration = notificationService.registerNotificationListener(packetInDispatcher);
93 WakeupOnNode wakeupListener = new WakeupOnNode();
94 wakeupListener.setLearningSwitchHandler(learningSwitchHandler);
95 final InstanceIdentifier<Table> instanceIdentifier = InstanceIdentifier.create(Nodes.class)
97 .augmentation(FlowCapableNode.class)
99 final DataTreeIdentifier<Table> dataTreeIdentifier =
100 DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
101 dataTreeChangeListenerRegistration = data.registerDataTreeChangeListener(dataTreeIdentifier, wakeupListener);
102 LOG.debug("start() <--");
106 * Stops learning switch.
110 LOG.debug("stop() -->");
111 //TODO: remove flow (created in #start())
113 packetInRegistration.close();
115 dataTreeChangeListenerRegistration.close();
116 LOG.debug("stop() <--");
121 public ListenerRegistration<DataTreeChangeListener> getDataTreeChangeListenerRegistration() {
122 return dataTreeChangeListenerRegistration;