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.sal.binding.api.NotificationService;
11 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
12 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
19 import org.opendaylight.yangtools.concepts.Registration;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.opendaylight.yangtools.yang.binding.NotificationListener;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Listens to packetIn notification and
28 * <li>in HUB mode simply floods all switch ports (except ingress port)</li>
29 * <li>in LSWITCH mode collects source MAC address of packetIn and bind it with ingress port.
30 * If target MAC address is already bound then a flow is created (for direct communication between
31 * corresponding MACs)</li>
34 public class LearningSwitchManagerSimpleImpl implements DataChangeListenerRegistrationHolder,
35 LearningSwitchManager {
37 protected static final Logger LOG = LoggerFactory
38 .getLogger(LearningSwitchManagerSimpleImpl.class);
40 private NotificationService notificationService;
41 private PacketProcessingService packetProcessingService;
42 private DataBrokerService data;
44 private Registration packetInRegistration;
46 private ListenerRegistration<DataChangeListener> dataChangeListenerRegistration;
49 * @param notificationService the notificationService to set
52 public void setNotificationService(NotificationService notificationService) {
53 this.notificationService = notificationService;
57 * @param packetProcessingService the packetProcessingService to set
60 public void setPacketProcessingService(
61 PacketProcessingService packetProcessingService) {
62 this.packetProcessingService = packetProcessingService;
66 * @param data the data to set
69 public void setDataBroker(DataBrokerService data) {
74 * starting learning switch
78 LOG.debug("start() -->");
79 FlowCommitWrapper dataStoreAccessor = new FlowCommitWrapperImpl(data);
81 LearningSwitchHandlerSimpleImpl learningSwitchHandler = new LearningSwitchHandlerSimpleImpl();
82 learningSwitchHandler.setRegistrationPublisher(this);
83 learningSwitchHandler.setDataStoreAccessor(dataStoreAccessor);
84 learningSwitchHandler.setPacketProcessingService(packetProcessingService);
85 packetInRegistration = notificationService.registerNotificationListener(learningSwitchHandler);
87 WakeupOnNode wakeupListener = new WakeupOnNode();
88 wakeupListener.setLearningSwitchHandler(learningSwitchHandler);
89 dataChangeListenerRegistration = data.registerDataChangeListener(
90 InstanceIdentifier.builder(Nodes.class)
92 .augmentation(FlowCapableNode.class)
93 .child(Table.class).toInstance(),
95 LOG.debug("start() <--");
99 * stopping learning switch
103 LOG.debug("stop() -->");
104 //TODO: remove flow (created in #start())
106 packetInRegistration.close();
107 } catch (Exception e) {
108 LOG.error(e.getMessage(), e);
111 dataChangeListenerRegistration.close();
112 } catch (Exception e) {
113 LOG.error(e.getMessage(), e);
115 LOG.debug("stop() <--");
120 public ListenerRegistration<DataChangeListener> getDataChangeListenerRegistration() {
121 return dataChangeListenerRegistration;