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.md.controller.topology.manager;
10 import java.util.concurrent.ExecutionException;
12 import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
14 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
15 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
16 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
22 import org.opendaylight.yangtools.concepts.ListenerRegistration;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.opendaylight.yangtools.yang.binding.NotificationListener;
25 import org.osgi.framework.BundleContext;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 public class FlowCapableTopologyProvider extends AbstractBindingAwareProvider implements AutoCloseable {
30 private final static Logger LOG = LoggerFactory.getLogger(FlowCapableTopologyProvider.class);
31 private ListenerRegistration<NotificationListener> listenerRegistration;
32 private Thread thread;
35 * Gets called on start of a bundle.
40 public synchronized void onSessionInitiated(final ProviderContext session) {
41 final DataProviderService dataService = session.getSALService(DataProviderService.class);
42 final NotificationProviderService notificationService = session.getSALService(NotificationProviderService.class);
44 final String name = "flow:1";
45 final TopologyKey key = new TopologyKey(new TopologyId(name));
46 final InstanceIdentifier<Topology> path = InstanceIdentifier
47 .builder(NetworkTopology.class)
48 .child(Topology.class, key)
51 final OperationProcessor processor = new OperationProcessor(dataService);
52 final FlowCapableTopologyExporter listener = new FlowCapableTopologyExporter(processor, path);
53 this.listenerRegistration = notificationService.registerNotificationListener(listener);
55 final DataModificationTransaction tx = dataService.beginTransaction();
56 tx.putOperationalData(path, new TopologyBuilder().setKey(key).build());
59 } catch (InterruptedException | ExecutionException e) {
60 LOG.warn("Initial topology export failed, continuing anyway", e);
63 thread = new Thread(processor);
64 thread.setDaemon(true);
65 thread.setName("FlowCapableTopologyExporter-" + name);
70 public synchronized void close() throws InterruptedException {
71 LOG.info("FlowCapableTopologyProvider stopped.");
72 if (this.listenerRegistration != null) {
74 this.listenerRegistration.close();
75 } catch (Exception e) {
76 LOG.error("Failed to close listener registration", e);
78 listenerRegistration = null;
88 * Gets called during stop bundle
91 * The execution context of the bundle being stopped.
94 public void stopImpl(final BundleContext context) {
97 } catch (InterruptedException e) {
98 LOG.error("Failed to stop provider", e);