Bug-730: Add pcep-segment-routing tests. 98/10998/4
authorMilos Fabian <milfabia@cisco.com>
Wed, 10 Sep 2014 14:23:12 +0000 (16:23 +0200)
committerMilos Fabian <milfabia@cisco.com>
Wed, 10 Sep 2014 17:08:09 +0000 (17:08 +0000)
Change-Id: I1b0337613823baf63b171f1d59949dfa7913aba6
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/test/java/org/opendaylight/controller/config/yang/pcep/sr02/cfg/Sr02PCEPSessionProposalFactoryModuleTest.java
pcep/segment-routing/src/test/java/org/opendaylight/protocol/pcep/lsp/setup/type01/PcepObjectParserTest.java
pcep/segment-routing/src/test/java/org/opendaylight/protocol/pcep/segment/routing02/SegmentRouting02SessionProposalTest.java [new file with mode: 0644]
pcep/segment-routing/src/test/java/org/opendaylight/protocol/pcep/segment/routing02/SrEroUtilTest.java

index 0ad19fac3074b8a423373e510c880c6979315637..6f0b5515aec25e0c8c54fd2c18e427069014d0dc 100644 (file)
@@ -35,8 +35,10 @@ public final class SrEroUtil {
                     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 (srEroSubobject.getFlags() != null) {
+                    if (srEroSubobject.getFlags().isM() && srEroSubobject.getSid() < MPLS_LABEL_MIN_VALUE) {
+                        return PCEPErrors.BAD_LABEL_VALUE;
+                    }
                 }
             }
         }
index 38d11d0f715a567deeb3de45cf43d51750fc59b5..3d3b14240ba78f3bdc2dd4502b2a983c12b29c3a 100644 (file)
@@ -13,7 +13,6 @@ import static org.junit.Assert.fail;
 
 import javax.management.InstanceAlreadyExistsException;
 import javax.management.ObjectName;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.config.api.ValidationException;
@@ -33,6 +32,75 @@ public class Sr02PCEPSessionProposalFactoryModuleTest extends AbstractConfigTest
         super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, new Sr02PCEPSessionProposalFactoryModuleFactory()));
     }
 
+    @Test
+    public void testValidationExceptionDeadTimerValueNotSet() throws Exception {
+        try {
+            createInstance(null, (short) 100, true, true, true, true);
+            fail();
+        } catch (final ValidationException e) {
+            assertTrue(e.getMessage().contains("DeadTimerValue value is not set"));
+        }
+    }
+
+    @Test
+    public void testValidationExceptionKeepAliveTimerNotSet() throws Exception {
+        try {
+            createInstance((short) 200, null, true, true, true, true);
+            fail();
+        } catch (final ValidationException e) {
+            assertTrue(e.getMessage().contains("KeepAliveTimerValue value is not set"));
+        }
+    }
+
+    @Test
+    public void testValidationExceptionStatefulNotSet() throws Exception {
+        try {
+            createInstance((short) 200, (short) 100, null, false, false, true);
+            fail();
+        } catch (final ValidationException e) {
+            assertTrue(e.getMessage().contains("Stateful value is not set"));
+        }
+    }
+
+    @Test
+    public void testValidationExceptionActiveNotSet() throws Exception {
+        try {
+            createInstance((short) 200, (short) 100, true, null, true, true);
+            fail();
+        } catch (final ValidationException e) {
+            assertTrue(e.getMessage().contains("Active value is not set"));
+        }
+    }
+
+    @Test
+    public void testValidationExceptionInstantiatedNotSet() throws Exception {
+        try {
+            createInstance((short) 200, (short) 100, true, true, null, true);
+            fail();
+        } catch (final ValidationException e) {
+            assertTrue(e.getMessage().contains("Initiated value is not set"));
+        }
+    }
+
+    @Test
+    public void testValidationExceptionKeepAliveTimerMinValue() throws Exception {
+        try {
+            createInstance((short) 200, (short) -10, true, true, true, true);
+            fail();
+        } catch (final ValidationException e) {
+            assertTrue(e.getMessage().contains("minimum value is 1."));
+        }
+    }
+
+    @Test
+    public void testStatefulAfterCommitted() throws Exception {
+        createInstance((short) 200, (short) 100, false, true, true, true);
+        final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
+        final Stateful07PCEPSessionProposalFactoryModuleMXBean mxBean = transaction.newMXBeanProxy(transaction.lookupConfigBean(
+                FACTORY_NAME, INSTANCE_NAME), Stateful07PCEPSessionProposalFactoryModuleMXBean.class);
+        assertTrue(mxBean.getStateful());
+    }
+
     @Test
     public void testValidationExceptionSrCapableValueNotSet() throws Exception {
         try {
index 2926de993661a996347bcb2857b434881604838b..6bd464ec74ae7552379decc576f32282c38f99b3 100644 (file)
@@ -28,8 +28,20 @@ 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.srp.object.SrpBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs3;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs3Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs4Builder;
+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.Tlvs6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs6Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs7;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs7Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs8;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs8Builder;
 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.types.rev131005.RequestId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.RpBuilder;
@@ -88,13 +100,31 @@ public class PcepObjectParserTest {
                 parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
         final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(rpObjectWithPstTlvBytes,ByteArray.getAllBytes(buf));
+        assertArrayEquals(rpObjectWithPstTlvBytes, ByteArray.getAllBytes(buf));
+
+        buf.clear();
+        builder.setTlvs(new TlvsBuilder().addAugmentation(Tlvs2.class,
+                new Tlvs2Builder().setPathSetupType(new PathSetupTypeBuilder().setPst(true).build()).build()).build());
+        parser.serializeObject(builder.build(), buf);
+        assertArrayEquals(rpObjectWithPstTlvBytes, ByteArray.getAllBytes(buf));
+
+        buf.clear();
+        builder.setTlvs(new TlvsBuilder().addAugmentation(Tlvs3.class,
+                new Tlvs3Builder().setPathSetupType(new PathSetupTypeBuilder().setPst(true).build()).build()).build());
+        parser.serializeObject(builder.build(), buf);
+        assertArrayEquals(rpObjectWithPstTlvBytes, ByteArray.getAllBytes(buf));
+
+        buf.clear();
+        builder.setTlvs(new TlvsBuilder().addAugmentation(Tlvs4.class,
+                new Tlvs4Builder().setPathSetupType(new PathSetupTypeBuilder().setPst(true).build()).build()).build());
+        parser.serializeObject(builder.build(), buf);
+        assertArrayEquals(rpObjectWithPstTlvBytes, ByteArray.getAllBytes(buf));
     }
 
     @Test
     public void testSrpObjectWithPstTlvParser() throws PCEPDeserializerException {
         final CInitiated00SrpObjectWithPstTlvParser parser = new CInitiated00SrpObjectWithPstTlvParser(this.tlvRegistry, this.viTlvRegistry);
-        final SrpBuilder builder = new SrpBuilder();
+        SrpBuilder builder = new SrpBuilder();
         builder.setProcessingRule(false);
         builder.setIgnore(false);
         builder.setOperationId(new SrpIdNumber(1L));
@@ -108,6 +138,27 @@ public class PcepObjectParserTest {
                 parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
         final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
-        assertArrayEquals(srpObjectWithPstTlvBytes,ByteArray.getAllBytes(buf));
+        assertArrayEquals(srpObjectWithPstTlvBytes, ByteArray.getAllBytes(buf));
+
+        buf.clear();
+        builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder().addAugmentation(Tlvs8.class,
+                new Tlvs8Builder().setPathSetupType(new PathSetupTypeBuilder().setPst(true).build()).build())
+                .build());
+        parser.serializeObject(builder.build(), buf);
+        assertArrayEquals(srpObjectWithPstTlvBytes, ByteArray.getAllBytes(buf));
+
+        buf.clear();
+        builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder().addAugmentation(Tlvs6.class,
+                new Tlvs6Builder().setPathSetupType(new PathSetupTypeBuilder().setPst(true).build()).build())
+                .build());
+        parser.serializeObject(builder.build(), buf);
+        assertArrayEquals(srpObjectWithPstTlvBytes, ByteArray.getAllBytes(buf));
+
+        buf.clear();
+        builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder().addAugmentation(Tlvs5.class,
+                new Tlvs5Builder().setPathSetupType(new PathSetupTypeBuilder().setPst(true).build()).build())
+                .build());
+        parser.serializeObject(builder.build(), buf);
+        assertArrayEquals(srpObjectWithPstTlvBytes, ByteArray.getAllBytes(buf));
     }
 }
diff --git a/pcep/segment-routing/src/test/java/org/opendaylight/protocol/pcep/segment/routing02/SegmentRouting02SessionProposalTest.java b/pcep/segment-routing/src/test/java/org/opendaylight/protocol/pcep/segment/routing02/SegmentRouting02SessionProposalTest.java
new file mode 100644 (file)
index 0000000..75c79c5
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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.routing02;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Stateful1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Stateful1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.StatefulBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing._02.rev140506.sr.pce.capability.tlv.SrPceCapabilityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
+
+public class SegmentRouting02SessionProposalTest {
+
+    private static final int DEAD_TIMER = 4;
+    private static final int KEEP_ALIVE = 1;
+    private static final int SESSION_ID = 1;
+    private static final Open OPEN_MSG = new OpenBuilder()
+            .setDeadTimer((short) DEAD_TIMER)
+            .setKeepalive((short) KEEP_ALIVE)
+            .setSessionId((short) SESSION_ID)
+            .setTlvs(new TlvsBuilder()
+                .addAugmentation(Tlvs1.class, new Tlvs1Builder().setStateful(new StatefulBuilder().addAugmentation(Stateful1.class,
+                        new Stateful1Builder().setInitiation(true).build()).setLspUpdateCapability(true).build()).build())
+                .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing._02.rev140506.Tlvs1.class,
+                        new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing._02.rev140506.Tlvs1Builder()
+                        .setSrPceCapability(new SrPceCapabilityBuilder().setMsd((short) 0).build()).build())
+                .build())
+            .build();
+
+    @Test
+    public void testSegmentRouting02SessionProposalFactory() {
+        final SegmentRouting02SessionProposalFactory sspf = new SegmentRouting02SessionProposalFactory(DEAD_TIMER, KEEP_ALIVE, true, true, true, true);
+        Assert.assertEquals(DEAD_TIMER, sspf.getDeadTimer());
+        Assert.assertEquals(KEEP_ALIVE, sspf.getKeepAlive());
+        Assert.assertTrue(sspf.isActive());
+        Assert.assertTrue(sspf.isInstant());
+        Assert.assertTrue(sspf.isStateful());
+        Assert.assertTrue(sspf.isSegmentRoutingCapable());
+        Assert.assertEquals(OPEN_MSG, sspf.getSessionProposal(null, SESSION_ID));
+    }
+}
index 416e58f84b004001a58ccf2ada9a4845fc5be574..8bd42e85e77e5985cc240edce6a1901abe6fae11 100644 (file)
@@ -8,15 +8,26 @@
 
 package org.opendaylight.protocol.pcep.segment.routing02;
 
+import com.google.common.collect.Lists;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
-import junit.framework.Assert;
+import java.util.Collections;
+import java.util.List;
+import org.junit.Assert;
 import org.junit.Test;
+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.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.Flags;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing._02.rev140506.pcinitiate.pcinitiate.message.requests.ero.subobject.subobject.type.SrEroTypeBuilder;
+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.EroBuilder;
+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.explicit.route.object.ero.SubobjectBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
 
 public class SrEroUtilTest {
 
@@ -45,4 +56,48 @@ public class SrEroUtilTest {
         Assert.assertFalse(SrEroUtil.isPst(null));
         Assert.assertFalse(SrEroUtil.isPst(new Tlvs5Builder().build()));
     }
+
+    @Test
+    public void testIsSegmentRoutingPath() {
+        Assert.assertTrue(SrEroUtil.isSegmentRoutingPath(createEro(Lists.newArrayList(createSRSubobject()))));
+        Assert.assertFalse(SrEroUtil.isSegmentRoutingPath(createEro(Collections.<Subobject>emptyList())));
+        Assert.assertFalse(SrEroUtil.isSegmentRoutingPath(createEro(null)));
+        Assert.assertFalse(SrEroUtil.isSegmentRoutingPath(null));
+        Assert.assertFalse(SrEroUtil.isSegmentRoutingPath(createEro(Lists.newArrayList(createIpPrefixSubobject()))));
+    }
+
+    @Test
+    public void testValidateSrEroSubobjects() {
+        Assert.assertNull(SrEroUtil.validateSrEroSubobjects(createEro(Lists.newArrayList(createSRSubobject()))));
+        Assert.assertNull(SrEroUtil.validateSrEroSubobjects(createEro(Collections.<Subobject>emptyList())));
+        Assert.assertNull(SrEroUtil.validateSrEroSubobjects(createEro(null)));
+        Assert.assertNull(SrEroUtil.validateSrEroSubobjects(createEro(Lists.newArrayList(createSRSubobject(20L, true)))));
+        Assert.assertNull(SrEroUtil.validateSrEroSubobjects(createEro(Lists.newArrayList(createSRSubobject(20L, false)))));
+        Assert.assertNull(SrEroUtil.validateSrEroSubobjects(createEro(Lists.newArrayList(createSRSubobject(10L, false)))));
+        Assert.assertEquals(PCEPErrors.BAD_LABEL_VALUE, SrEroUtil.validateSrEroSubobjects(createEro(Lists.newArrayList(createSRSubobject(10L, true)))));
+        Assert.assertEquals(PCEPErrors.NON_IDENTICAL_ERO_SUBOBJECTS,
+                SrEroUtil.validateSrEroSubobjects(createEro(Lists.newArrayList(createIpPrefixSubobject()))));
+    }
+
+    private Ero createEro(final List<Subobject> subobejcts) {
+        return new EroBuilder().setSubobject(subobejcts).build();
+    }
+
+    private Subobject createSRSubobject() {
+        final SubobjectBuilder builder = new SubobjectBuilder();
+        builder.setSubobjectType(new SrEroTypeBuilder().build());
+        return builder.build();
+    }
+
+    private Subobject createSRSubobject(final long sid, final boolean isM) {
+        final SubobjectBuilder builder = new SubobjectBuilder();
+        builder.setSubobjectType(new SrEroTypeBuilder().setFlags(new Flags(false, false, isM, false)).setSid(sid).build());
+        return builder.build();
+    }
+
+    private Subobject createIpPrefixSubobject() {
+        final SubobjectBuilder builder = new SubobjectBuilder();
+        builder.setSubobjectType(new IpPrefixCaseBuilder().build());
+        return builder.build();
+    }
 }