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