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.bgpcep.pcep.tunnel.provider;
10 import com.google.common.base.Preconditions;
12 import org.opendaylight.bgpcep.topology.DefaultTopologyReference;
13 import org.opendaylight.bgpcep.topology.TopologyReference;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
16 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
23 import org.opendaylight.yangtools.concepts.ListenerRegistration;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 public final class PCEPTunnelTopologyProvider implements AutoCloseable {
27 private final ListenerRegistration<DataChangeListener> reg;
28 private final TopologyReference ref;
30 private PCEPTunnelTopologyProvider(final InstanceIdentifier<Topology> dst, final ListenerRegistration<DataChangeListener> reg) {
31 this.ref = new DefaultTopologyReference(dst);
32 this.reg = Preconditions.checkNotNull(reg);
35 public static PCEPTunnelTopologyProvider create(final DataBroker dataProvider,
36 final InstanceIdentifier<Topology> sourceTopology, final TopologyId targetTopology) {
37 final InstanceIdentifier<Topology> dst = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
38 new TopologyKey(targetTopology)).build();
39 final NodeChangedListener ncl = new NodeChangedListener(dataProvider, dst);
41 final InstanceIdentifier<Node> src = sourceTopology.child(Node.class);
42 final ListenerRegistration<DataChangeListener> reg = dataProvider.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, src, ncl, DataChangeScope.SUBTREE);
44 return new PCEPTunnelTopologyProvider(dst, reg);
52 public TopologyReference getTopologyReference() {