use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.rsvp.error.spec.tlv.RsvpErrorSpec in project bgpcep by opendaylight.
the class PCEPObjectParserTest method testStateful07LspObjectWithTlv.
@Test
public void testStateful07LspObjectWithTlv() throws IOException, PCEPDeserializerException {
final Stateful07LspObjectParser parser = new Stateful07LspObjectParser(this.tlvRegistry, this.viTlvRegistry);
final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspObject2WithTLV.bin"));
final LspBuilder builder = new LspBuilder();
builder.setProcessingRule(true);
builder.setIgnore(true);
builder.setAdministrative(true);
builder.setDelegate(false);
builder.setRemove(true);
builder.setSync(false);
builder.setOperational(OperationalStatus.GoingDown);
builder.setPlspId(new PlspId(0x12345L));
final LspErrorCode tlv1 = new LspErrorCodeBuilder().setErrorCode(627610883L).build();
final SymbolicPathName tlv2 = new SymbolicPathNameBuilder().setPathName(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.SymbolicPathName("Med".getBytes())).build();
final Ipv4Builder afi = new Ipv4Builder();
afi.setIpv4TunnelSenderAddress(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })));
afi.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }))));
afi.setIpv4TunnelEndpointAddress(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })));
final LspIdentifiers tlv3 = new LspIdentifiersBuilder().setAddressFamily(new Ipv4CaseBuilder().setIpv4(afi.build()).build()).setLspId(new LspId(65535L)).setTunnelId(new TunnelId(4660)).build();
final RsvpErrorBuilder rsvpBuilder = new RsvpErrorBuilder();
rsvpBuilder.setNode(new IpAddress(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }))));
rsvpBuilder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ErrorSpec.Flags(false, true));
rsvpBuilder.setCode((short) 146);
rsvpBuilder.setValue(5634);
final RsvpErrorSpec tlv4 = new RsvpErrorSpecBuilder().setErrorType(new RsvpCaseBuilder().setRsvpError(rsvpBuilder.build()).build()).build();
builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.lsp.object.lsp.TlvsBuilder().setLspErrorCode(tlv1).setSymbolicPathName(tlv2).setLspIdentifiers(tlv3).setRsvpErrorSpec(tlv4).build());
assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)));
final ByteBuf buf = Unpooled.buffer();
parser.serializeObject(builder.build(), buf);
assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.rsvp.error.spec.tlv.RsvpErrorSpec in project bgpcep by opendaylight.
the class Stateful07RSVPErrorSpecTlvParser method serializeTlv.
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
Preconditions.checkArgument(tlv instanceof RsvpErrorSpec, "RSVPErrorSpecTlv is mandatory.");
final RsvpErrorSpec rsvp = (RsvpErrorSpec) tlv;
final ByteBuf body = Unpooled.buffer();
if (rsvp.getErrorType().getImplementedInterface().equals(RsvpCase.class)) {
final RsvpCase r = (RsvpCase) rsvp.getErrorType();
serializeRsvp(r.getRsvpError(), body);
TlvUtil.formatTlv(TYPE, body, buffer);
} else {
final UserCase u = (UserCase) rsvp.getErrorType();
serializerUserError(u.getUserError(), body);
TlvUtil.formatTlv(TYPE, body, buffer);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.rsvp.error.spec.tlv.RsvpErrorSpec 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.ietf.stateful.rev200720.rsvp.error.spec.tlv.RsvpErrorSpec in project bgpcep by opendaylight.
the class PCEPTlvParserTest method testUserErrorSpecTlv.
@Test
public void testUserErrorSpecTlv() throws PCEPDeserializerException {
final StatefulRSVPErrorSpecTlvParser parser = new StatefulRSVPErrorSpecTlvParser();
final UserErrorBuilder builder = new UserErrorBuilder().setEnterprise(new EnterpriseNumber(Uint32.valueOf(12345))).setSubOrg(Uint8.valueOf(5)).setValue(Uint16.valueOf(38)).setDescription("user desc");
final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder().setErrorType(new UserCaseBuilder().setUserError(builder.build()).build()).build();
assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(USER_ERROR_BYTES, 4))));
final ByteBuf buff = Unpooled.buffer();
parser.serializeTlv(tlv, buff);
assertArrayEquals(USER_ERROR_BYTES, ByteArray.getAllBytes(buff));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.rsvp.error.spec.tlv.RsvpErrorSpec in project bgpcep by opendaylight.
the class PCEPTlvParserTest method testRSVPError6SpecTlv.
@Test
public void testRSVPError6SpecTlv() throws PCEPDeserializerException {
final StatefulRSVPErrorSpecTlvParser parser = new StatefulRSVPErrorSpecTlvParser();
final RsvpErrorBuilder builder = new RsvpErrorBuilder().setNode(new IpAddressNoZone(Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0 })))).setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ErrorSpec.Flags(false, true)).setCode(Uint8.valueOf(213)).setValue(Uint16.valueOf(50649));
final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder().setErrorType(new RsvpCaseBuilder().setRsvpError(builder.build()).build()).build();
assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(RSVP_ERROR6_BYTES, 4))));
final ByteBuf buff = Unpooled.buffer();
parser.serializeTlv(tlv, buff);
assertArrayEquals(RSVP_ERROR6_BYTES, ByteArray.getAllBytes(buff));
}
Aggregations