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.yangtools.concepts.ListenerRegistration;
21 import org.opendaylight.yangtools.concepts.Registration;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Listens to packetIn notification.
29 * <li>in HUB mode simply floods all switch ports (except ingress port)</li>
30 * <li>in LSWITCH mode collects source MAC address of packetIn and bind it with ingress port.
31 * If target MAC address is already bound then a flow is created (for direct communication between
32 * corresponding MACs)</li>
35 public class LearningSwitchManagerSimpleImpl
36 implements DataTreeChangeListenerRegistrationHolder, LearningSwitchManager {
38 private static final Logger LOG = LoggerFactory.getLogger(LearningSwitchManagerSimpleImpl.class);
39 private NotificationService notificationService;
40 private PacketProcessingService packetProcessingService;
41 private DataBroker data;
42 private Registration packetInRegistration;
43 private ListenerRegistration<DataTreeChangeListener> dataTreeChangeListenerRegistration;
46 * Sets the NotificationService.
48 * @param notificationService the notificationService to set
51 public void setNotificationService(NotificationService notificationService) {
52 this.notificationService = notificationService;
56 * Sets the PacketProcessingService.
58 * @param packetProcessingService the packetProcessingService to set
61 public void setPacketProcessingService(
62 PacketProcessingService packetProcessingService) {
63 this.packetProcessingService = packetProcessingService;
67 * Sets the DataBroker.
70 public void setDataBroker(DataBroker broker) {
75 * Starts learning switch.
79 LOG.debug("start() -->");
80 FlowCommitWrapper dataStoreAccessor = new FlowCommitWrapperImpl(data);
82 LearningSwitchHandlerSimpleImpl learningSwitchHandler = new LearningSwitchHandlerSimpleImpl(dataStoreAccessor,
83 packetProcessingService, this);
84 packetInRegistration = notificationService.registerNotificationListener(learningSwitchHandler);
86 WakeupOnNode wakeupListener = new WakeupOnNode();
87 wakeupListener.setLearningSwitchHandler(learningSwitchHandler);
88 final InstanceIdentifier<Table> instanceIdentifier = InstanceIdentifier.create(Nodes.class)
90 .augmentation(FlowCapableNode.class)
92 final DataTreeIdentifier<Table> dataTreeIdentifier =
93 DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
94 dataTreeChangeListenerRegistration = data.registerDataTreeChangeListener(dataTreeIdentifier, wakeupListener);
95 LOG.debug("start() <--");
99 * Stops the learning switch.
103 LOG.debug("stop() -->");
104 //TODO: remove flow (created in #start())
106 packetInRegistration.close();
108 dataTreeChangeListenerRegistration.close();
110 LOG.debug("stop() <--");
114 public ListenerRegistration<DataTreeChangeListener> getDataTreeChangeListenerRegistration() {
115 return dataTreeChangeListenerRegistration;