Define PCEP LSP operational state instruction 03/3203/1
authorRobert Varga <rovarga@cisco.com>
Wed, 27 Nov 2013 15:51:47 +0000 (16:51 +0100)
committerRobert Varga <rovarga@cisco.com>
Thu, 28 Nov 2013 13:26:53 +0000 (14:26 +0100)
Change-Id: I80b6885e2c0332de2d592af93dfb625803031268
Signed-off-by: Robert Varga <rovarga@cisco.com>
pcep/topology-api/src/main/yang/network-topology-pcep-programming.yang
pcep/topology-api/src/main/yang/network-topology-pcep.yang
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/ServerSessionManager.java
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyProgramming.java
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyRPCs.java

index ed740d489690226f78d3524758a7df0a7ae96ed9..246924465c392dbd8a01093b7a8064a0022c6718 100644 (file)
@@ -61,5 +61,15 @@ module network-topology-pcep-programming {
             uses ntp:topology-instruction-output;
         }
     }
+
+    rpc submit-ensure-lsp-operational {
+        input {
+            uses ntp:topology-instruction-input;
+            uses pcep:ensure-lsp-operational-args;
+        }
+        output {
+            uses ntp:topology-instruction-output;
+        }
+    }
 }
 
index b96b40fc2eca16ecc0edce213e2264703da1ce4c..74a2ce1ad06cf3f60b01f8acdcfafd94c93bbde7 100644 (file)
@@ -179,5 +179,29 @@ module network-topology-pcep {
             uses operation-result;
         }
     }
+
+    grouping ensure-lsp-operational-args {
+        uses lsp-id;
+
+        container arguments {
+            leaf operational {
+                type pcep:operational-status;
+                mandatory true;
+            }
+        }
+    }
+
+    rpc ensure-lsp-operational {
+        description
+            "Ensure that the target LSP is provisioned and has specified
+             operational status.";
+
+        input {
+            uses ensure-lsp-operational-args;
+        }
+        output {
+            uses operation-result;
+        }
+    }
 }
 
index f81df0683f298c41d3dafea8aeb404b2c586f90f..8a74cde694f8c11a8c3e33782e3c51b78948479d 100644 (file)
@@ -53,6 +53,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.symbolic.path.name.tlv.SymbolicPathName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.symbolic.path.name.tlv.SymbolicPathNameBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspArgs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.FailureType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1Builder;
@@ -498,4 +499,30 @@ final class ServerSessionManager implements SessionListenerFactory<PCEPSessionLi
                ub.setUpdates(ImmutableList.of(rb.build()));
                return l.sendMessage(new PcupdBuilder().setPcupdMessage(ub.build()).build(), rb.getSrp().getOperationId());
        }
+
+       synchronized ListenableFuture<OperationResult> realEnsureLspOperational(final EnsureLspOperationalInput input) {
+               // Get the listener corresponding to the node
+               final SessionListener l = this.nodes.get(input.getNode());
+               if (l == null) {
+                       LOG.debug("Session for node {} not found", input.getNode());
+                       return Futures.immediateFuture(OPERATION_UNSENT);
+               }
+
+               // Make sure the LSP exists
+               final InstanceIdentifier<ReportedLsps> lsp = InstanceIdentifier.builder(l.topologyAugment).
+                               child(PathComputationClient.class).
+                               child(ReportedLsps.class, new ReportedLspsKey(input.getName())).toInstance();
+               LOG.debug("Checking if LSP {} has operational state {}", lsp, input.getArguments().getOperational());
+               final ReportedLsps rep = (ReportedLsps) this.dataProvider.readOperationalData(lsp);
+               if (rep == null) {
+                       LOG.debug("Node {} does not contain LSP {}", input.getNode(), input.getName());
+                       return Futures.immediateFuture(OPERATION_UNSENT);
+               }
+
+               if (rep.getLsp().getOperational().equals(input.getArguments().getOperational())) {
+                       return Futures.immediateFuture(OPERATION_SUCCESS);
+               } else {
+                       return Futures.immediateFuture(OPERATION_UNSENT);
+               }
+       }
 }
index 7c7887cf2b0775186bc0672b27392c2191beb677..aecfb48d2a7ddd2fdab714ded568172dfe90120f 100644 (file)
@@ -17,12 +17,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitAddLspInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitAddLspOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitAddLspOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitEnsureLspOperationalInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitEnsureLspOperationalOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitEnsureLspOperationalOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitRemoveLspInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitRemoveLspOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitRemoveLspOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitUpdateLspInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitUpdateLspOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitUpdateLspOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
@@ -108,4 +112,27 @@ final class TopologyProgramming implements NetworkTopologyPcepProgrammingService
                return Futures.immediateFuture(res);
        }
 
+       @Override
+       public ListenableFuture<RpcResult<SubmitEnsureLspOperationalOutput>> submitEnsureLspOperational(final SubmitEnsureLspOperationalInput input) {
+               Preconditions.checkArgument(input.getNode() != null);
+               Preconditions.checkArgument(input.getName() != null);
+               Preconditions.checkArgument(input.getArguments() != null);
+               Preconditions.checkArgument(input.getArguments().getOperational() != null);
+
+               final InstructionExecutor e = new AbstractTopologyProgrammingExecutor() {
+                       @Override
+                       protected ListenableFuture<OperationResult> executeImpl() {
+                               return manager.realEnsureLspOperational(new EnsureLspOperationalInputBuilder(input).build());
+                       }
+               };
+
+               final Failure f = this.scheduler.submitInstruction(input, e);
+               final SubmitEnsureLspOperationalOutputBuilder b = new SubmitEnsureLspOperationalOutputBuilder();
+               if (f != null) {
+                       b.setResult(new FailureBuilder().setFailure(f).build());
+               }
+
+               final RpcResult<SubmitEnsureLspOperationalOutput> res = SuccessfulRpcResult.create(b.build());
+               return Futures.immediateFuture(res);
+       }
 }
index 070bfe171e1631aafaff96806b91faee4637faa0..5c0762fa1f34a1d61cc327505ae2e8e4762769d9 100644 (file)
@@ -13,6 +13,9 @@ import org.opendaylight.bgpcep.programming.spi.SuccessfulRpcResult;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.NetworkTopologyPcepService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspInput;
@@ -63,4 +66,14 @@ final class TopologyRPCs implements NetworkTopologyPcepService {
                        }
                });
        }
+
+       @Override
+       public Future<RpcResult<EnsureLspOperationalOutput>> ensureLspOperational(final EnsureLspOperationalInput input) {
+               return Futures.transform(manager.realEnsureLspOperational(input), new Function<OperationResult, RpcResult<EnsureLspOperationalOutput>>() {
+                       @Override
+                       public RpcResult<EnsureLspOperationalOutput> apply(final OperationResult input) {
+                               return SuccessfulRpcResult.create(new EnsureLspOperationalOutputBuilder(input).build());
+                       }
+               });
+       }
 }