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.sal.binding.api.AbstractBindingAwareConsumer;
12 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
13 import org.opendaylight.controller.sal.binding.api.NotificationService;
14 import org.opendaylight.openflowplugin.learningswitch.multi.LearningSwitchManagerMultiImpl;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
16 import org.osgi.framework.BundleContext;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 * learning switch activator
23 * Activator is derived from AbstractBindingAwareConsumer, which takes care
24 * of looking up MD-SAL in Service Registry and registering consumer
25 * when MD-SAL is present.
27 public class Activator extends AbstractBindingAwareConsumer implements AutoCloseable {
29 private static final Logger LOG = LoggerFactory.getLogger(Activator.class);
31 private LearningSwitchManager learningSwitch;
35 protected void startImpl(BundleContext context) {
36 LOG.info("startImpl() passing");
40 * Invoked when consumer is registered to the MD-SAL.
43 public void onSessionInitialized(ConsumerContext session) {
44 LOG.info("inSessionInitialized() passing");
46 * We create instance of our LearningSwitchManager
47 * and set all required dependencies,
50 * Data Broker (data storage service) - for configuring flows and reading stored switch state
51 * PacketProcessingService - for sending out packets
52 * NotificationService - for receiving notifications such as packet in.
55 learningSwitch = new LearningSwitchManagerMultiImpl();
56 learningSwitch.setDataBroker(session.getSALService(DataBroker.class));
57 learningSwitch.setPacketProcessingService(session.getRpcService(PacketProcessingService.class));
58 learningSwitch.setNotificationService(session.getSALService(NotificationService.class));
59 learningSwitch.start();
64 LOG.info("close() passing");
65 if (learningSwitch != null) {
66 learningSwitch.stop();
71 protected void stopImpl(BundleContext context) {
73 super.stopImpl(context);