Bug-2208: Include symbolic path name in PCRpt 42/17042/6
authorMilos Fabian <milfabia@cisco.com>
Tue, 24 Mar 2015 09:48:54 +0000 (10:48 +0100)
committerMilos Fabian <milfabia@cisco.com>
Mon, 6 Apr 2015 15:52:53 +0000 (17:52 +0200)
-include SYMBOLIC-PATH-NAME TLV in a PCRpt's LSP object as a response to PCUpd message.

Change-Id: If804c7bb2832f0750ffedf2dc22081177e0d8e97
Signed-off-by: Milos Fabian <milfabia@cisco.com>
pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/MsgBuilderUtil.java
pcep/pcc-mock/src/main/java/org/opendaylight/protocol/pcep/pcc/mock/SimpleSessionListener.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful07TopologySessionListenerTest.java

index 2945c3d8f235eb62fbf3310fb2bfac8084a36749..40ad4b0af8ec5d48eb2f26cdfbeec3f0c2938581 100644 (file)
@@ -109,8 +109,8 @@ public final class MsgBuilderUtil {
         return pathBuilder.build();
     }
 
-    public static Tlvs createLspTlvs(final long lspId, final boolean symbolicPathName, String tunnelEndpoint,
-            String tunnelSender, String extendedTunnelAddress) {
+    public static Tlvs createLspTlvs(final long lspId, final boolean symbolicPathName, final String tunnelEndpoint,
+            final String tunnelSender, final String extendedTunnelAddress, final Optional<byte[]> symbolicName) {
         final TlvsBuilder tlvs = new TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder()
                 .setLspId(new LspId(lspId))
                 .setAddressFamily(
@@ -122,9 +122,14 @@ public final class MsgBuilderUtil {
                                                 new Ipv4ExtendedTunnelId(extendedTunnelAddress))
                                         .build()).build()).setTunnelId(new TunnelId((int) lspId)).build());
         if (symbolicPathName) {
-            final String pathName = "pcc_" + tunnelSender + "_tunnel_" + lspId;
+            final byte[] pathName;
+            if (symbolicName.isPresent()) {
+                pathName = symbolicName.get();
+            } else {
+                pathName = ("pcc_" + tunnelSender + "_tunnel_" + lspId).getBytes(Charsets.UTF_8);
+            }
             tlvs.setSymbolicPathName(new SymbolicPathNameBuilder().setPathName(
-                    new SymbolicPathName(pathName.getBytes(Charsets.UTF_8))).build());
+                    new SymbolicPathName(pathName)).build());
         }
         return tlvs.build();
     }
index ef001933a3cd07e4d7c6f4b3cefde641c559db8c..cb84261e91b54c629cdf8583c3051a956b3a73ae 100644 (file)
@@ -21,9 +21,12 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import java.net.InetAddress;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Random;
 import java.util.concurrent.atomic.AtomicLong;
+import javax.annotation.concurrent.GuardedBy;
 import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.PCEPSessionListener;
 import org.opendaylight.protocol.pcep.PCEPTerminationReason;
@@ -40,7 +43,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.iet
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.PlspId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.LspBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.Tlvs;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcupd.message.pcupd.message.Updates;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
@@ -66,6 +68,8 @@ public class SimpleSessionListener implements PCEPSessionListener {
     private final boolean pcError;
     private final String address;
     private final AtomicLong plspIDs;
+    @GuardedBy("this")
+    private final Map<Long, byte[]> pathNames = new HashMap<>();
 
     public SimpleSessionListener(final int lspsCount, final boolean pcError, final InetAddress address) {
         Preconditions.checkArgument(lspsCount >= 0);
@@ -85,8 +89,9 @@ public class SimpleSessionListener implements PCEPSessionListener {
             if (this.pcError) {
                 session.sendMessage(MsgBuilderUtil.createErrorMsg(getRandomError(), srpId));
             } else {
-                final Tlvs tlvs = createLspTlvs(updates.getLsp().getPlspId().getValue(), false,
-                        getDestinationAddress(updates.getPath().getEro().getSubobject()), this.address, this.address);
+                final Tlvs tlvs = createLspTlvs(updates.getLsp().getPlspId().getValue(), true,
+                        getDestinationAddress(updates.getPath().getEro().getSubobject()), this.address, this.address,
+                        Optional.fromNullable(pathNames.get(updates.getLsp().getPlspId().getValue())));
                 final Pcrpt pcRpt = createPcRtpMessage(new LspBuilder(updates.getLsp()).setTlvs(tlvs).build(),
                         Optional.fromNullable(createSrp(srpId)), updToRptPath(updates.getPath()));
                 session.sendMessage(pcRpt);
@@ -100,14 +105,17 @@ public class SimpleSessionListener implements PCEPSessionListener {
                 final Pcrpt pcRpt;
                 if (request.getSrp().getAugmentation(Srp1.class) != null && request.getSrp().getAugmentation(Srp1.class).isRemove()) {
                     pcRpt = createPcRtpMessage(request.getLsp(), Optional.fromNullable(request.getSrp()), reqToRptPath(request));
+                    this.pathNames.remove(request.getLsp().getPlspId().getValue());
                 } else {
                     final LspBuilder lspBuilder = new LspBuilder(request.getLsp());
                     lspBuilder.setPlspId(new PlspId(this.plspIDs.incrementAndGet()));
                     lspBuilder.addAugmentation(Lsp1.class, new Lsp1Builder().setCreate(true).build());
-                    final Tlvs tlvs = createLspTlvs(lspBuilder.getPlspId().getValue(), false,
-                            ((Ipv4Case) request.getEndpointsObj().getAddressFamily()).getIpv4().getDestinationIpv4Address().getValue(), this.address, this.address);
-                    lspBuilder.setTlvs(new TlvsBuilder(tlvs).setSymbolicPathName(request.getLsp().getTlvs().getSymbolicPathName()).build());
+                    final Tlvs tlvs = createLspTlvs(lspBuilder.getPlspId().getValue(), true,
+                            ((Ipv4Case) request.getEndpointsObj().getAddressFamily()).getIpv4().getDestinationIpv4Address().getValue(), this.address, this.address,
+                            Optional.of(request.getLsp().getTlvs().getSymbolicPathName().getPathName().getValue()));
+                    lspBuilder.setTlvs(tlvs);
                     pcRpt = createPcRtpMessage(lspBuilder.build(), Optional.fromNullable(request.getSrp()), reqToRptPath(request));
+                    this.pathNames.put(lspBuilder.getPlspId().getValue(), tlvs.getSymbolicPathName().getPathName().getValue());
                 }
                 session.sendMessage(pcRpt);
             }
@@ -119,7 +127,7 @@ public class SimpleSessionListener implements PCEPSessionListener {
         LOG.debug("Session up.");
         for (int i = 1; i <= this.lspsCount; i++) {
             final Tlvs tlvs = MsgBuilderUtil.createLspTlvs(i, true, ENDPOINT_ADDRESS, this.address,
-                    this.address);
+                    this.address, Optional.<byte[]>absent());
             session.sendMessage(createPcRtpMessage(
                     createLsp(i, true, Optional.<Tlvs> fromNullable(tlvs)), Optional.<Srp> absent(),
                     createPath(Lists.newArrayList(DEFAULT_ENDPOINT_HOP))));
index 53be117e81cf56697f03885fd92530accd82589c..ab00b1490332371072e0f2d40cf98e315c18ef19 100644 (file)
@@ -129,7 +129,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
         final long srpId = req.getSrp().getOperationId().getValue();
         final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
-                TEST_ADDRESS, TEST_ADDRESS, TEST_ADDRESS);
+                TEST_ADDRESS, TEST_ADDRESS, TEST_ADDRESS, Optional.<byte[]>absent());
         final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
         final Pcrpt esm = MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setSync(false).build(), Optional.of(MsgBuilderUtil.createSrp(0L)), null);
         this.listener.onMessage(this.session, esm);
@@ -176,7 +176,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         final Updates upd = updateMsg.getPcupdMessage().getUpdates().get(0);
         final long srpId2 = upd.getSrp().getOperationId().getValue();
         final Tlvs tlvs2 = createLspTlvs(upd.getLsp().getPlspId().getValue(), false,
-                NEW_DESTINATION_ADDRESS, TEST_ADDRESS, TEST_ADDRESS);
+                NEW_DESTINATION_ADDRESS, TEST_ADDRESS, TEST_ADDRESS, Optional.<byte[]>absent());
         final Pcrpt pcRpt2 = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(upd.getLsp()).setTlvs(tlvs2).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId2)), MsgBuilderUtil.createPath(upd.getPath().getEro().getSubobject()));
         this.listener.onMessage(this.session, pcRpt2);
         //check updated lsp
@@ -219,7 +219,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         final Requests req2 = pcinitiate2.getPcinitiateMessage().getRequests().get(0);
         final long srpId3 = req2.getSrp().getOperationId().getValue();
         final Tlvs tlvs3 = createLspTlvs(req2.getLsp().getPlspId().getValue(), false,
-                TEST_ADDRESS, TEST_ADDRESS, TEST_ADDRESS);
+                TEST_ADDRESS, TEST_ADDRESS, TEST_ADDRESS, Optional.<byte[]>absent());
         final Pcrpt pcRpt3 = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req2.getLsp()).setTlvs(tlvs3).setRemove(true).setSync(true).setOperational(OperationalStatus.Down).build(), Optional.of(MsgBuilderUtil.createSrp(srpId3)), MsgBuilderUtil.createPath(Collections.<Subobject>emptyList()));
         this.listener.onMessage(this.session, pcRpt3);
         // check if lsp was removed
@@ -286,7 +286,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
         final long srpId = req.getSrp().getOperationId().getValue();
         final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
-                TEST_ADDRESS, TEST_ADDRESS, TEST_ADDRESS);
+                TEST_ADDRESS, TEST_ADDRESS, TEST_ADDRESS, Optional.<byte[]>absent());
         final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
         this.listener.onMessage(this.session, pcRpt);
         assertEquals(1, getTopology().get().getNode().size());
@@ -346,7 +346,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
         final long srpId = req.getSrp().getOperationId().getValue();
         final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
-                TEST_ADDRESS, TEST_ADDRESS, TEST_ADDRESS);
+                TEST_ADDRESS, TEST_ADDRESS, TEST_ADDRESS, Optional.<byte[]>absent());
         final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
         this.listener.onMessage(this.session, pcRpt);