Turn ted-name into a leafref 53/104053/5
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 17 Jan 2023 00:34:32 +0000 (01:34 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 17 Jan 2023 10:13:42 +0000 (11:13 +0100)
We want to express strong consistency here. Use a leafref, which gives
us a type-safe reference along with expressing a consistency constraint.

Change-Id: I6026fb6cf5d6f2bf169a22eeaabb62719afeb5f2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
pcep/topology/topology-api/src/main/yang/network-topology-pcep.yang
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/PCEPTopologyConfiguration.java
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/ServerSessionManager.java

index 5c1f59266b983f1bc811c2b9cd95e7d7ebb9cb93..79401dae923e55523046e82dd5b2d90bc974a471 100644 (file)
@@ -87,10 +87,10 @@ module network-topology-pcep {
         container topology-pcep {
             presence "indicates a PCEP-aware topology";
 
-            // FIXME: leaf-ref to a topology
             leaf ted-name {
-                type string;
-                default "example-linkstate-topology";
+                type leafref {
+                    path /nt:network-topology/nt:topology/nt:topology-id;
+                }
             }
 
             uses pdc:pcep-config;
index a482f5c8650000ee2965fc807de6ff0b5c76d958..7cff6b5c877c1cd08150285d0e003841ab2d744a 100644 (file)
@@ -34,6 +34,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.pcep
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev230112.PcepSessionTls;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.Node1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.TopologyTypes1;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
@@ -46,7 +47,7 @@ final class PCEPTopologyConfiguration implements Immutable {
         new PCEPStatefulCapability(), P2MPTeLspCapability.of(), PCEPSegmentRoutingCapability.of());
 
     private final @NonNull InetSocketAddress address;
-    private final @NonNull GraphKey graphKey;
+    private final @Nullable GraphKey graphKey;
     private final @NonNull KeyMapping keys;
     private final @NonNull PCEPTimerProposal timerProposal;
     private final @NonNull ImmutableList<PCEPCapability> capabilities;
@@ -55,13 +56,13 @@ final class PCEPTopologyConfiguration implements Immutable {
     private final long updateIntervalNanos;
     private final short rpcTimeout;
 
-    PCEPTopologyConfiguration(final InetSocketAddress address, final KeyMapping keys, final GraphKey graphKey,
+    PCEPTopologyConfiguration(final InetSocketAddress address, final KeyMapping keys, final @Nullable GraphKey graphKey,
             final short rpcTimeout, final long updateIntervalNanos, final PCEPTimerProposal timerProposal,
             final @NonNull ImmutableList<PCEPCapability> capabilities, final Uint16 maxUnknownMessages,
             final @Nullable PcepSessionTls tls) {
         this.address = requireNonNull(address);
         this.keys = requireNonNull(keys);
-        this.graphKey = requireNonNull(graphKey);
+        this.graphKey = graphKey;
         this.rpcTimeout = rpcTimeout;
         this.updateIntervalNanos = updateIntervalNanos;
         this.timerProposal = requireNonNull(timerProposal);
@@ -89,6 +90,7 @@ final class PCEPTopologyConfiguration implements Immutable {
         }
         final var capabilityAug = topologyPcep.augmentation(TopologyPcep1.class);
         final var capabilities = capabilityAug != null ? capabilityAug.getCapabilities() : null;
+
         if (capabilities != null && !capabilities.nonnullStateful().requireEnabled()) {
             return null;
         }
@@ -136,7 +138,7 @@ final class PCEPTopologyConfiguration implements Immutable {
         return keys;
     }
 
-    @NonNull GraphKey getGraphKey() {
+    @Nullable GraphKey getGraphKey() {
         return graphKey;
     }
 
@@ -188,8 +190,8 @@ final class PCEPTopologyConfiguration implements Immutable {
         return KeyMapping.of(passwords);
     }
 
-    private static @NonNull GraphKey constructGraphKey(final String name) {
-        return new GraphKey(name.startsWith("ted://") ? name : "ted://" + name);
+    private static @Nullable GraphKey constructGraphKey(final @Nullable TopologyId topologyId) {
+        return topologyId != null ? new GraphKey("ted://" + topologyId.getValue()) : null;
     }
 
     private static InetAddress nodeAddress(final Node node) {
index 46f58f183dbd8ab2da76430d3ac607bac3fa20ed..8fde9947f136d0487108c749294a10ca93706241 100644 (file)
@@ -75,7 +75,7 @@ class ServerSessionManager implements PCEPSessionListenerFactory, TopologySessio
 
     private final @NonNull KeyedInstanceIdentifier<Topology, TopologyKey> topology;
     private final @NonNull PCEPTopologyProviderDependencies dependencies;
-    private final @NonNull GraphKey graphKey;
+    private final @Nullable GraphKey graphKey;
 
     @GuardedBy("this")
     private final Map<NodeId, TopologySessionListener> nodes = new HashMap<>();
@@ -91,7 +91,7 @@ class ServerSessionManager implements PCEPSessionListenerFactory, TopologySessio
             final short rpcTimeout, final long updateInterval) {
         this.dependencies = requireNonNull(dependencies);
         this.topology = requireNonNull(topology);
-        this.graphKey = requireNonNull(graphKey);
+        this.graphKey = graphKey;
         this.rpcTimeout = rpcTimeout;
         this.updateInterval = updateInterval;
     }
@@ -127,7 +127,7 @@ class ServerSessionManager implements PCEPSessionListenerFactory, TopologySessio
 
         // Register this new topology to PCE Server
         final PceServerProvider server = dependencies.getPceServerProvider();
-        if (server != null) {
+        if (server != null && graphKey != null) {
             server.registerPcepTopology(topology, graphKey);
         }
         return future;