use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassType in project bgpcep by opendaylight.
the class PCEPObjectParserTest method testClassTypeObject.
@Test
public void testClassTypeObject() throws PCEPDeserializerException {
final PCEPClassTypeObjectParser parser = new PCEPClassTypeObjectParser();
final ByteBuf result = Unpooled.wrappedBuffer(new byte[] { (byte) 0x16, (byte) 0x12, (byte) 0x00, (byte) 0x08, 0, 0, 0, (byte) 0x04 });
final ClassTypeBuilder builder = new ClassTypeBuilder();
builder.setProcessingRule(true);
builder.setIgnore(false);
builder.setClassType(new ClassType((short) 4));
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
final ByteBuf buf = Unpooled.buffer();
parser.serializeObject(builder.build(), buf);
assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
try {
parser.parseObject(new ObjectHeaderImpl(true, true), null);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
try {
parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassType in project bgpcep by opendaylight.
the class Stateful07RSVPErrorSpecTlvParser method parseTlv.
@Override
public RsvpErrorSpec parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
if (buffer == null) {
return null;
}
// throw away contents of length field
buffer.readUnsignedShort();
final int classNum = buffer.readUnsignedByte();
final int classType = buffer.readUnsignedByte();
ErrorType errorType = null;
if (classNum == RSVP_ERROR_CLASS_NUM) {
errorType = parseRsvp(classType, buffer.slice());
} else if (classNum == USER_ERROR_CLASS_NUM && classType == USER_ERROR_CLASS_TYPE) {
errorType = parseUserError(buffer.slice());
}
return new RsvpErrorSpecBuilder().setErrorType(errorType).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassType in project bgpcep by opendaylight.
the class PCEPRequestMessageParser method insertObject.
private static State insertObject(final State state, final List<Object> objects, final List<VendorInformationObject> viObjects, final P2pBuilder builder, final List<Metrics> metrics, final List<Message> errors, final Rp rp) {
final Object obj = objects.get(0);
switch(state) {
case INIT:
if (obj instanceof Rro) {
builder.setRro((Rro) obj);
objects.remove(0);
final Object nextObj = objects.get(0);
if (nextObj instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth) {
builder.setReoptimizationBandwidth((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reoptimization.bandwidth.object.ReoptimizationBandwidth) nextObj);
}
return State.REPORTED_IN;
}
case REPORTED_IN:
if (obj instanceof VendorInformationObject) {
viObjects.add((VendorInformationObject) obj);
return State.REPORTED_IN;
}
case VENDOR_INFO_LIST:
if (obj instanceof LoadBalancing) {
builder.setLoadBalancing((LoadBalancing) obj);
return State.LOAD_BIN;
}
case LOAD_BIN:
if (obj instanceof Lspa) {
builder.setLspa((Lspa) obj);
return State.LSPA_IN;
}
case LSPA_IN:
if (obj instanceof Bandwidth) {
builder.setBandwidth((Bandwidth) obj);
return State.BANDWIDTH_IN;
}
case BANDWIDTH_IN:
if (obj instanceof Metric) {
metrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
return State.BANDWIDTH_IN;
}
case METRIC_IN:
if (obj instanceof Iro) {
builder.setIro((Iro) obj);
return State.IRO_IN;
}
case IRO_IN:
if (obj instanceof Rro) {
builder.setRro((Rro) obj);
return State.RRO_IN;
}
case RRO_IN:
if (obj instanceof Xro) {
builder.setXro((Xro) obj);
return State.XRO_IN;
}
case XRO_IN:
if (obj instanceof Of) {
builder.setOf((Of) obj);
return State.OF_IN;
}
case OF_IN:
if (obj instanceof ClassType) {
final ClassType classType = (ClassType) obj;
if (!classType.isProcessingRule()) {
errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, Optional.of(rp)));
} else {
builder.setClassType(classType);
}
return State.CT_IN;
}
case CT_IN:
case END:
return State.END;
default:
return state;
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassType in project bgpcep by opendaylight.
the class PCEPClassTypeObjectParser method parseObject.
@Override
public Object parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
if (!header.isProcessingRule()) {
LOG.debug("Processed bit not set on CLASS TYPE OBJECT, ignoring it");
return null;
}
if (bytes.readableBytes() != SIZE) {
throw new PCEPDeserializerException("Size of byte array doesn't match defined size. Expected: " + SIZE + "; Passed: " + bytes.readableBytes());
}
final ClassTypeBuilder builder = new ClassTypeBuilder();
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
final short ct = (short) bytes.readUnsignedInt();
builder.setClassType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType(ct));
final Object obj = builder.build();
if (ct < 0 || ct > Byte.SIZE) {
LOG.debug("Invalid class type {}", ct);
return new UnknownObject(PCEPErrors.INVALID_CT, obj);
}
return obj;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassType in project bgpcep by opendaylight.
the class TunnelProgrammingTest method testTunnelProgramming.
@Test
public void testTunnelProgramming() throws TransactionCommitFailedException {
final Bandwidth bwd = new Bandwidth(new byte[] { 0x00, 0x00, 0x00, (byte) 0xff });
final ClassType classType = new ClassType((short) 1);
final String tunnelName = "create-tunnel";
final NetworkTopologyRef topologyRef = new NetworkTopologyRef(TOPO_IID);
// create tunnel
final PcepCreateP2pTunnelInputBuilder createInputBuilder = new PcepCreateP2pTunnelInputBuilder();
createInputBuilder.setDestination(new DestinationBuilder().setNode(NODE2_ID).setTp(TP2_ID).build());
createInputBuilder.setSource(new SourceBuilder().setNode(NODE1_ID).setTp(TP1_ID).build());
createInputBuilder.setNetworkTopologyRef(topologyRef);
createInputBuilder.setBandwidth(bwd);
createInputBuilder.setClassType(classType);
createInputBuilder.setSymbolicPathName(tunnelName);
createInputBuilder.setExplicitHops(Lists.newArrayList());
createInputBuilder.addAugmentation(PcepCreateP2pTunnelInput1.class, new PcepCreateP2pTunnelInput1Builder().setAdministrativeStatus(AdministrativeStatus.Active).build());
this.tunnelProgramming.pcepCreateP2pTunnel(createInputBuilder.build());
// check add-lsp input
Assert.assertNotNull(this.addLspInput);
Assert.assertEquals(tunnelName, this.addLspInput.getName());
final Arguments agrs = this.addLspInput.getArguments();
Assert.assertNotNull(agrs);
Assert.assertEquals(bwd, agrs.getBandwidth().getBandwidth());
Assert.assertEquals(classType, agrs.getClassType().getClassType());
final Ipv4 ipv4Endpoints = ((Ipv4Case) agrs.getEndpointsObj().getAddressFamily()).getIpv4();
Assert.assertEquals(NODE1_IPV4, ipv4Endpoints.getSourceIpv4Address().getValue());
Assert.assertEquals(NODE2_IPV4, ipv4Endpoints.getDestinationIpv4Address().getValue());
Assert.assertEquals(NODE1_ID.getValue(), this.addLspInput.getNode().getValue());
createLink();
// update tunnel
final PcepUpdateTunnelInputBuilder updateInputBuilder = new PcepUpdateTunnelInputBuilder();
updateInputBuilder.setNetworkTopologyRef(topologyRef);
updateInputBuilder.setBandwidth(bwd);
updateInputBuilder.setClassType(classType);
updateInputBuilder.setExplicitHops(Lists.newArrayList(createExplicitHop(IPV4_PREFIX1), createExplicitHop(IPV4_PREFIX2)));
updateInputBuilder.setLinkId(LINK1_ID);
updateInputBuilder.addAugmentation(PcepUpdateTunnelInput1.class, new PcepUpdateTunnelInput1Builder().setAdministrativeStatus(AdministrativeStatus.Active).build());
this.tunnelProgramming.pcepUpdateTunnel(updateInputBuilder.build());
// check update-lsp input
Assert.assertNotNull(this.updateLspInput);
Assert.assertEquals(LINK1_ID.getValue(), this.updateLspInput.getName());
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.update.lsp.args.Arguments updArgs = this.updateLspInput.getArguments();
Assert.assertEquals(2, updArgs.getEro().getSubobject().size());
final List<Subobject> subObjects = updArgs.getEro().getSubobject();
final IpPrefixCase prefix1 = (IpPrefixCase) subObjects.get(0).getSubobjectType();
final IpPrefixCase prefix2 = (IpPrefixCase) subObjects.get(1).getSubobjectType();
Assert.assertEquals(IPV4_PREFIX1, prefix1.getIpPrefix().getIpPrefix().getIpv4Prefix().getValue());
Assert.assertEquals(IPV4_PREFIX2, prefix2.getIpPrefix().getIpPrefix().getIpv4Prefix().getValue());
// delete tunnel
final PcepDestroyTunnelInputBuilder destroyInputBuilder = new PcepDestroyTunnelInputBuilder();
destroyInputBuilder.setLinkId(LINK1_ID);
destroyInputBuilder.setNetworkTopologyRef(topologyRef);
this.tunnelProgramming.pcepDestroyTunnel(destroyInputBuilder.build());
Assert.assertNotNull(this.removeLspInput);
Assert.assertEquals(LINK1_ID.getValue(), this.removeLspInput.getName());
Assert.assertEquals(NODE1_ID.getValue(), this.removeLspInput.getNode().getValue());
}
Aggregations