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 org.opendaylight.bgpcep.topology.DefaultTopologyReference;
11 import org.opendaylight.bgpcep.topology.TopologyReference;
12 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
13 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
14 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
19 import org.opendaylight.yangtools.concepts.ListenerRegistration;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import com.google.common.base.Preconditions;
24 public final class PCEPTunnelTopologyProvider implements AutoCloseable {
25 private final ListenerRegistration<DataChangeListener> reg;
26 private final TopologyReference ref;
28 private PCEPTunnelTopologyProvider(final InstanceIdentifier<Topology> dst, final ListenerRegistration<DataChangeListener> reg) {
29 this.ref = new DefaultTopologyReference(dst);
30 this.reg = Preconditions.checkNotNull(reg);
33 public static PCEPTunnelTopologyProvider create(final DataProviderService dataProvider,
34 final InstanceIdentifier<Topology> sourceTopology, final TopologyId targetTopology) {
35 final InstanceIdentifier<Topology> dst =
36 InstanceIdentifier.builder(NetworkTopology.class).
37 child(Topology.class, new TopologyKey(targetTopology)).toInstance();
38 final NodeChangedListener ncl = new NodeChangedListener(dataProvider, dst);
40 final InstanceIdentifier<Node> src = InstanceIdentifier.builder(sourceTopology).child(Node.class).toInstance();
41 final ListenerRegistration<DataChangeListener> reg = dataProvider.registerDataChangeListener(src, ncl);
43 return new PCEPTunnelTopologyProvider(dst, reg);
51 public TopologyReference getTopologyReference() {