use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.path.binding.tlv.PathBinding in project bgpcep by opendaylight.
the class PCEPTlvParserTest method testPathBindingTlvMplsLabelEntry.
@Test
public void testPathBindingTlvMplsLabelEntry() throws PCEPDeserializerException {
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((short) 6).setTimeToLive((short) 173).setBottomOfStack(true).setLabel(new MplsLabel(688_374L)).build());
final PathBinding tlv = builder.build();
final ByteBuf buff = Unpooled.buffer();
parser.serializeTlv(tlv, buff);
assertArrayEquals(pathBindingBytes, ByteArray.readAllBytes(buff));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.path.binding.tlv.PathBinding in project bgpcep by opendaylight.
the class PathBindingTlvParser method serializeTlv.
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
Preconditions.checkArgument(tlv instanceof PathBinding, "The TLV must be PathBinding type, but was %s", tlv.getClass());
final PathBinding pTlv = (PathBinding) tlv;
final BindingTypeValue bindingTypeValue = pTlv.getBindingTypeValue();
Preconditions.checkArgument(bindingTypeValue != null, "Missing Binding Value in Path Bidning TLV: %s", pTlv);
final ByteBuf body = Unpooled.buffer(MPLS_BINDING_LENGTH);
final PathBindingTlvCodec codec = BT_SERIALIZERS.get(bindingTypeValue.getImplementedInterface());
Preconditions.checkArgument(codec != null, "Unsupported Path Binding Type: %s", bindingTypeValue.getImplementedInterface());
ByteBufWriteUtil.writeUnsignedShort(codec.getBindingType(), body);
body.writeBytes(codec.serialize(bindingTypeValue));
TlvUtil.formatTlv(TYPE, body, buffer);
}
Aggregations