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
22 * Activator is derived from AbstractBindingAwareConsumer, which takes care
23 * of looking up MD-SAL in Service Registry and registering consumer
24 * when MD-SAL is present.
26 public class Activator extends AbstractBindingAwareConsumer implements AutoCloseable {
28 private static final Logger LOG = LoggerFactory.getLogger(Activator.class);
29 private LearningSwitchManager learningSwitch;
32 protected void startImpl(BundleContext context) {
33 LOG.info("startImpl() passing");
37 * Invoked when consumer is registered to the MD-SAL.
40 public void onSessionInitialized(ConsumerContext session) {
41 LOG.info("inSessionInitialized() passing");
43 * We create instance of our LearningSwitchManager
44 * and set all required dependencies,
47 * Data Broker (data storage service) - for configuring flows and reading stored switch state
48 * PacketProcessingService - for sending out packets
49 * NotificationService - for receiving notifications such as packet in.
51 learningSwitch = new LearningSwitchManagerMultiImpl();
52 learningSwitch.setDataBroker(session.getSALService(DataBroker.class));
53 learningSwitch.setPacketProcessingService(session.getRpcService(PacketProcessingService.class));
54 learningSwitch.setNotificationService(session.getSALService(NotificationService.class));
55 learningSwitch.start();
60 LOG.info("close() passing");
61 if (learningSwitch != null) {
62 learningSwitch.stop();
67 protected void stopImpl(BundleContext context) {
69 super.stopImpl(context);