Bug-2225 Update PCEP segment routing according draft version 00.
[bgpcep.git] / pcep / segment-routing / src / main / java / org / opendaylight / protocol / pcep / segment / routing / SrEroUtil.java
diff --git a/pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/SrEroUtil.java b/pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/SrEroUtil.java
new file mode 100644 (file)
index 0000000..1f43df4
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.pcep.segment.routing;
+
+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.segment.routing.rev150112.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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.setup.type.tlv.PathSetupType;
+
+public final class SrEroUtil {
+
+    private static final int MPLS_LABEL_MIN_VALUE = 16;
+
+    private SrEroUtil() {
+        throw new UnsupportedOperationException();
+    }
+
+    protected static PCEPErrors validateSrEroSubobjects(final Ero ero) {
+        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.isMFlag() != null && srEroSubobject.isMFlag() && srEroSubobject.getSid() < MPLS_LABEL_MIN_VALUE) {
+                    return PCEPErrors.BAD_LABEL_VALUE;
+                }
+            }
+        }
+        return null;
+    }
+
+    protected static boolean isSegmentRoutingPath(final Srp srp) {
+        if (srp != null && srp.getTlvs() != null && isSrTePst(srp.getTlvs().getPathSetupType())) {
+            return true;
+        }
+        return false;
+    }
+
+    private static boolean isSrTePst(final PathSetupType tlv) {
+        if (tlv != null && tlv.getPst() == 1) {
+            return true;
+        }
+        return false;
+    }
+
+}