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;
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.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
21 import org.opendaylight.yangtools.concepts.ListenerRegistration;
22 import org.opendaylight.yangtools.concepts.Registration;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * Listens to packetIn notification.
30 * <li>in HUB mode simply floods all switch ports (except ingress port)</li>
31 * <li>in LSWITCH mode collects source MAC address of packetIn and bind it with ingress port.
32 * If target MAC address is already bound then a flow is created (for direct communication between
33 * corresponding MACs)</li>
36 public class LearningSwitchManagerSimpleImpl
37 implements DataTreeChangeListenerRegistrationHolder, LearningSwitchManager {
39 private static final Logger LOG = LoggerFactory.getLogger(LearningSwitchManagerSimpleImpl.class);
40 private NotificationService notificationService;
41 private PacketProcessingService packetProcessingService;
42 private DataBroker data;
43 private Registration packetInRegistration;
44 private ListenerRegistration<DataTreeChangeListener> dataTreeChangeListenerRegistration;
47 * Sets the NotificationService.
49 * @param notificationService the notificationService to set
52 public void setNotificationService(NotificationService notificationService) {
53 this.notificationService = notificationService;
57 * Sets the PacketProcessingService.
59 * @param packetProcessingService the packetProcessingService to set
62 public void setPacketProcessingService(
63 PacketProcessingService packetProcessingService) {
64 this.packetProcessingService = packetProcessingService;
68 * Sets the DataBroker.
71 public void setDataBroker(DataBroker broker) {
76 * Starts learning switch.
80 LOG.debug("start() -->");
81 FlowCommitWrapper dataStoreAccessor = new FlowCommitWrapperImpl(data);
83 LearningSwitchHandlerSimpleImpl learningSwitchHandler = new LearningSwitchHandlerSimpleImpl(dataStoreAccessor,
84 packetProcessingService, this);
85 packetInRegistration = notificationService.registerListener(PacketReceived.class, learningSwitchHandler);
87 WakeupOnNode wakeupListener = new WakeupOnNode();
88 wakeupListener.setLearningSwitchHandler(learningSwitchHandler);
89 final InstanceIdentifier<Table> instanceIdentifier = InstanceIdentifier.create(Nodes.class)
91 .augmentation(FlowCapableNode.class)
93 final DataTreeIdentifier<Table> dataTreeIdentifier =
94 DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
95 dataTreeChangeListenerRegistration = data.registerDataTreeChangeListener(dataTreeIdentifier, wakeupListener);
96 LOG.debug("start() <--");
100 * Stops the learning switch.
104 LOG.debug("stop() -->");
105 //TODO: remove flow (created in #start())
107 packetInRegistration.close();
109 dataTreeChangeListenerRegistration.close();
111 LOG.debug("stop() <--");
115 public ListenerRegistration<DataTreeChangeListener> getDataTreeChangeListenerRegistration() {
116 return dataTreeChangeListenerRegistration;