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.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.controller.sal.binding.api.NotificationService;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
19 import org.opendaylight.yangtools.concepts.ListenerRegistration;
20 import org.opendaylight.yangtools.concepts.Registration;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.opendaylight.yangtools.yang.binding.NotificationListener;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Listens to packetIn notification and
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 implements DataChangeListenerRegistrationHolder,
36 LearningSwitchManager {
38 protected static final Logger LOG = LoggerFactory
39 .getLogger(LearningSwitchManagerSimpleImpl.class);
41 private NotificationService notificationService;
42 private PacketProcessingService packetProcessingService;
43 private DataBroker data;
45 private Registration packetInRegistration;
47 private ListenerRegistration<DataChangeListener> dataChangeListenerRegistration;
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 LearningSwitchHandlerSimpleImpl learningSwitchHandler = new LearningSwitchHandlerSimpleImpl();
83 learningSwitchHandler.setRegistrationPublisher(this);
84 learningSwitchHandler.setDataStoreAccessor(dataStoreAccessor);
85 learningSwitchHandler.setPacketProcessingService(packetProcessingService);
86 packetInRegistration = notificationService.registerNotificationListener(learningSwitchHandler);
88 WakeupOnNode wakeupListener = new WakeupOnNode();
89 wakeupListener.setLearningSwitchHandler(learningSwitchHandler);
90 dataChangeListenerRegistration = data.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
91 InstanceIdentifier.builder(Nodes.class)
93 .augmentation(FlowCapableNode.class)
94 .child(Table.class).toInstance(),
96 DataBroker.DataChangeScope.SUBTREE);
97 LOG.debug("start() <--");
101 * stopping learning switch
105 LOG.debug("stop() -->");
106 //TODO: remove flow (created in #start())
108 packetInRegistration.close();
109 } catch (Exception e) {
110 LOG.error(e.getMessage(), e);
113 dataChangeListenerRegistration.close();
114 } catch (Exception e) {
115 LOG.error(e.getMessage(), e);
117 LOG.debug("stop() <--");
122 public ListenerRegistration<DataChangeListener> getDataChangeListenerRegistration() {
123 return dataChangeListenerRegistration;