use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.path.binding.tlv.PathBindingBuilder in project bgpcep by opendaylight.
the class PathBindingTlvParser method parseTlv.
@Override
public Tlv parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
if (buffer == null) {
return null;
}
final Uint16 type = ByteBufUtils.readUint16(buffer);
final PathBindingTlvCodec codec = BT_PARSERS.get(type);
if (codec == null) {
throw new PCEPDeserializerException("Unsupported Path Binding Type: " + type);
}
return new PathBindingBuilder().setBindingTypeValue(codec.readEntry(buffer)).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.path.binding.tlv.PathBindingBuilder in project bgpcep by opendaylight.
the class PCEPTlvParserTest method testPathBindingTlvMplsLabel.
@Test
public void testPathBindingTlvMplsLabel() {
final byte[] pathBindingBytes = { 0x00, 0x1f, 0x00, 0x06, 0x00, 0x00, (byte) 0xA8, 0x0F, (byte) 0x60, 0x00, 0x00, 0x00 };
final PathBindingTlvParser parser = new PathBindingTlvParser();
final PathBindingBuilder builder = new PathBindingBuilder();
builder.setBindingTypeValue(new MplsLabelBuilder().setMplsLabel(new MplsLabel(Uint32.valueOf(688374))).build());
final ByteBuf buff = Unpooled.buffer();
parser.serializeTlv(builder.build(), buff);
assertArrayEquals(pathBindingBytes, ByteArray.readAllBytes(buff));
try {
final byte[] wrong = { 0, 0x1f, 0, 4, 1, 1, 2, 3 };
parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(wrong, 4)));
fail();
} catch (final PCEPDeserializerException e) {
assertEquals("Unsupported Path Binding Type: 257", e.getMessage());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.path.binding.tlv.PathBindingBuilder in project bgpcep by opendaylight.
the class PCEPTlvParserTest method testPathBindingTlvMplsLabelEntry.
@Test
public void testPathBindingTlvMplsLabelEntry() {
final byte[] pathBindingBytes = { 0x00, 0x1f, 0x00, 0x06, 0x00, 0x01, (byte) 0xA8, (byte) 0x0F, (byte) 0x6D, (byte) 0xAD, 0x00, 0x00 };
final PathBindingTlvParser parser = new PathBindingTlvParser();
final PathBindingBuilder builder = new PathBindingBuilder();
builder.setBindingTypeValue(new MplsLabelEntryBuilder().setTrafficClass(Uint8.valueOf(6)).setTimeToLive(Uint8.valueOf(173)).setBottomOfStack(true).setLabel(new MplsLabel(Uint32.valueOf(688374))).build());
final PathBinding tlv = builder.build();
final ByteBuf buff = Unpooled.buffer();
parser.serializeTlv(tlv, buff);
assertArrayEquals(pathBindingBytes, ByteArray.readAllBytes(buff));
}
Aggregations