2 * Copyright (c) 2014 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.controller.sample.l2switch.md;
10 import org.opendaylight.controller.sample.l2switch.md.addresstracker.AddressTracker;
11 import org.opendaylight.controller.sample.l2switch.md.flow.FlowWriterService;
12 import org.opendaylight.controller.sample.l2switch.md.flow.FlowWriterServiceImpl;
13 import org.opendaylight.controller.sample.l2switch.md.inventory.InventoryService;
14 import org.opendaylight.controller.sample.l2switch.md.packet.PacketHandler;
15 import org.opendaylight.controller.sample.l2switch.md.topology.NetworkGraphDijkstra;
16 import org.opendaylight.controller.sample.l2switch.md.topology.NetworkGraphService;
17 import org.opendaylight.controller.sample.l2switch.md.topology.TopologyLinkDataChangeHandler;
18 import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareConsumer;
19 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
20 import org.opendaylight.controller.sal.binding.api.NotificationService;
21 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
23 import org.opendaylight.yangtools.concepts.Registration;
24 import org.opendaylight.yangtools.yang.binding.NotificationListener;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * L2SwitchProvider serves as the Activator for our L2Switch OSGI bundle.
31 public class L2SwitchProvider extends AbstractBindingAwareConsumer
32 implements AutoCloseable {
34 private final static Logger _logger = LoggerFactory.getLogger(L2SwitchProvider.class);
36 private Registration<NotificationListener> listenerRegistration;
37 private AddressTracker addressTracker;
38 private TopologyLinkDataChangeHandler topologyLinkDataChangeHandler;
43 * @param consumerContext The context of the L2Switch.
46 public void onSessionInitialized(BindingAwareBroker.ConsumerContext consumerContext) {
47 DataBrokerService dataService = consumerContext.<DataBrokerService>getSALService(DataBrokerService.class);
48 addressTracker = new AddressTracker(dataService);
50 NetworkGraphService networkGraphService = new NetworkGraphDijkstra();
51 FlowWriterService flowWriterService = new FlowWriterServiceImpl(dataService, networkGraphService);
53 NotificationService notificationService =
54 consumerContext.<NotificationService>getSALService(NotificationService.class);
55 PacketProcessingService packetProcessingService =
56 consumerContext.<PacketProcessingService>getRpcService(PacketProcessingService.class);
57 PacketHandler packetHandler = new PacketHandler();
58 packetHandler.setAddressTracker(addressTracker);
59 packetHandler.setFlowWriterService(flowWriterService);
60 packetHandler.setPacketProcessingService(packetProcessingService);
61 packetHandler.setInventoryService(new InventoryService(dataService));
63 this.listenerRegistration = notificationService.registerNotificationListener(packetHandler);
64 this.topologyLinkDataChangeHandler = new TopologyLinkDataChangeHandler(dataService, networkGraphService);
65 topologyLinkDataChangeHandler.registerAsDataChangeListener();
69 * Cleanup the L2Switch.
70 * @throws Exception occurs when the NotificationListener is closed
73 public void close() throws Exception {
74 if (listenerRegistration != null)
75 listenerRegistration.close();