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;
+ }
}
}
}
import javax.management.InstanceAlreadyExistsException;
import javax.management.ObjectName;
-
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.config.api.ValidationException;
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 {
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;
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));
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));
}
}
--- /dev/null
+/*
+ * 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));
+ }
+}
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 {
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();
+ }
}