Bug-1737 - Advertize Segment-routing PATH-SETUP-TYPE in SRP 92/10892/1
authorMilos Fabian <milfabia@cisco.com>
Mon, 8 Sep 2014 07:36:12 +0000 (09:36 +0200)
committerMilos Fabian <milfabia@cisco.com>
Mon, 8 Sep 2014 07:36:12 +0000 (09:36 +0200)
Change-Id: I7c952d9a03dc1febbac3b8ff499794c1ed2cdc56
Signed-off-by: Milos Fabian <milfabia@cisco.com>
pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing02/SrEroUtil.java
pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing02/SrPcInitiateMessageParser.java
pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing02/SrPcRptMessageParser.java
pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing02/SrPcUpdMessageParser.java

index 30a23613b0953f3ab2f2b97baf612ce3cddfc009..1250e31d2122616155b2fa2d4dfacfb88f3a4ca1 100644 (file)
@@ -9,7 +9,13 @@
 package org.opendaylight.protocol.pcep.segment.routing02;
 
 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
+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.ietf.stateful.rev131222.srp.object.SrpBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.PathSetupTypeTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs5;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs5Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.path.setup.type.tlv.PathSetupTypeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing._02.rev140506.SrEroSubobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
@@ -22,16 +28,15 @@ public final class SrEroUtil {
     }
 
     protected static PCEPErrors validateSrEroSubobjects(final Ero ero) {
-        if (ero.getSubobject() == null || ero.getSubobject().isEmpty()) {
-            return null;
-        }
-        for (final Subobject subobject : ero.getSubobject()) {
-            if (!(subobject.getSubobjectType() instanceof SrEroSubobject)) {
-                return PCEPErrors.NON_IDENTICAL_ERO_SUBOBJECTS;
-            }
-            final SrEroSubobject srEroSubobject = (SrEroSubobject) subobject.getSubobjectType();
-            if (srEroSubobject.getFlags().isM() && srEroSubobject.getSid() < MPLS_LABEL_MIN_VALUE) {
-                return PCEPErrors.BAD_LABEL_VALUE;
+        if (ero.getSubobject() != null && !ero.getSubobject().isEmpty()) {
+            for (final Subobject subobject : ero.getSubobject()) {
+                if (!(subobject.getSubobjectType() instanceof SrEroSubobject)) {
+                    return PCEPErrors.NON_IDENTICAL_ERO_SUBOBJECTS;
+                }
+                final SrEroSubobject srEroSubobject = (SrEroSubobject) subobject.getSubobjectType();
+                if (srEroSubobject.getFlags().isM() && srEroSubobject.getSid() < MPLS_LABEL_MIN_VALUE) {
+                    return PCEPErrors.BAD_LABEL_VALUE;
+                }
             }
         }
         return null;
@@ -44,4 +49,21 @@ public final class SrEroUtil {
         return false;
     }
 
+    protected static boolean isSegmentRoutingPath(final Ero ero) {
+        if (ero != null && ero.getSubobject() != null && !ero.getSubobject().isEmpty()) {
+            for (final Subobject subobject : ero.getSubobject()) {
+                if (!(subobject.getSubobjectType() instanceof SrEroSubobject)) {
+                    return false;
+                }
+            }
+            return true;
+        }
+        return false;
+    }
+
+    protected static Srp addSRPathSetupTypeTlv(final Srp srp) {
+        return new SrpBuilder(srp).setTlvs(new TlvsBuilder(srp.getTlvs()).addAugmentation(Tlvs5.class,
+                new Tlvs5Builder().setPathSetupType(new PathSetupTypeBuilder().setPst(true).build()).build()).build()).build();
+    }
+
 }
index 7866b0d0e54dc259305b0558921728c2d0888852..c2875cf870c6db7d81f7051d6b6713df6b6bc27e 100644 (file)
@@ -29,15 +29,12 @@ public class SrPcInitiateMessageParser extends CInitiated00PCInitiateMessagePars
 
     @Override
     protected void serializeRequest(Requests req, ByteBuf buffer) {
-        if (isSegmentRoutingPath(req.getSrp())) {
-            serializeObject(req.getSrp(), buffer);
+        if (SrEroUtil.isSegmentRoutingPath(req.getEro())) {
+            serializeObject(SrEroUtil.addSRPathSetupTypeTlv(req.getSrp()), buffer);
             if (req.getLsp() != null) {
                 serializeObject(req.getLsp(), buffer);
             }
-            final Ero srEro = req.getEro();
-            if (srEro != null) {
-                serializeObject(srEro, buffer);
-            }
+            serializeObject(req.getEro(), buffer);
         } else {
             super.serializeRequest(req, buffer);
         }
index 5e057e6eaf561ddb5e4e7d33814364cbf0455e77..ed1a346aab2a7e0a67c70a7984fd5f1eb02ac8d0 100644 (file)
@@ -33,13 +33,10 @@ public class SrPcRptMessageParser extends Stateful07PCReportMessageParser {
 
     @Override
     protected void serializeReport(Reports report, ByteBuf buffer) {
-        if (isSegmentRoutingPath(report.getSrp())) {
-            serializeObject(report.getSrp(), buffer);
+        if (report.getPath() != null && SrEroUtil.isSegmentRoutingPath(report.getPath().getEro())) {
+            serializeObject(SrEroUtil.addSRPathSetupTypeTlv(report.getSrp()), buffer);
             serializeObject(report.getLsp(), buffer);
-            final Ero srEro = report.getPath().getEro();
-            if (srEro != null) {
-                serializeObject(srEro, buffer);
-            }
+            serializeObject(report.getPath().getEro(), buffer);
         } else {
             super.serializeReport(report, buffer);
         }
index 40be76fed309963c03ff6008a85071a890ed914c..643843b17c6632edf6e02e1b797cd9ccb723c1b1 100644 (file)
@@ -34,15 +34,12 @@ public class SrPcUpdMessageParser extends Stateful07PCUpdateRequestMessageParser
 
     @Override
     protected void serializeUpdate(Updates update, ByteBuf buffer) {
-        if (isSegmentRoutingPath(update.getSrp())) {
-            serializeObject(update.getSrp(), buffer);
+        if (update.getPath() != null && SrEroUtil.isSegmentRoutingPath(update.getPath().getEro())) {
+            serializeObject(SrEroUtil.addSRPathSetupTypeTlv(update.getSrp()), buffer);
             if (update.getLsp() != null) {
                 serializeObject(update.getLsp(), buffer);
             }
-            final Ero srEro = update.getPath().getEro();
-            if (srEro != null) {
-                serializeObject(srEro, buffer);
-            }
+            serializeObject(update.getPath().getEro(), buffer);
         } else {
             super.serializeUpdate(update, buffer);
         }