use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv in project bgpcep by opendaylight.
the class RangeTlvParser method parseRangeSubTlvs.
private static List<SubTlvs> parseRangeSubTlvs(final ByteBuf buffer, final ProtocolId protocolId) {
final List<SubTlvs> subTlvs = new ArrayList<>();
while (buffer.isReadable()) {
final RangeSubTlv subTlvCase;
final int type = buffer.readUnsignedShort();
final int length = buffer.readUnsignedShort();
switch(type) {
case PREFIX_SID:
subTlvCase = new PrefixSidTlvCaseBuilder().setPrefixSidTlv(new PrefixSidTlvBuilder(SrPrefixAttributesParser.parseSrPrefix(buffer.readSlice(length), protocolId)).build()).build();
break;
case IPV6_PREFIX_SID:
subTlvCase = new Ipv6PrefixSidTlvCaseBuilder().setIpv6PrefixSidTlv(new Ipv6PrefixSidTlvBuilder(Ipv6SrPrefixAttributesParser.parseSrIpv6Prefix(buffer.readSlice(length))).build()).build();
break;
case BINDING_SID:
subTlvCase = new BindingSidTlvCaseBuilder(BindingSidLabelParser.parseBindingSidLabel(buffer.readSlice(length), protocolId)).build();
break;
case SID_TYPE:
subTlvCase = new SidLabelTlvCaseBuilder().setSidLabelIndex(SidLabelIndexParser.parseSidLabelIndex(Size.forValue(length), buffer.readSlice(length))).build();
break;
default:
LOG.info("Unknown type of range sub-tlv: {}", type);
buffer.skipBytes(length);
continue;
}
subTlvs.add(new SubTlvsBuilder().setRangeSubTlv(subTlvCase).build());
}
return subTlvs;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv in project bgpcep by opendaylight.
the class BgpPrefixSidTlvsTest method testOriginatorParser.
@Test
public void testOriginatorParser() {
final OriginatorSrgbTlvParser parser = new OriginatorSrgbTlvParser();
final List<SrgbValue> list = new ArrayList<>();
final Srgb srgb1 = new Srgb(Uint32.ONE);
final Srgb srgb2 = new Srgb(Uint32.TWO);
list.add(new SrgbValueBuilder().setBase(srgb1).setRange(srgb2).build());
list.add(new SrgbValueBuilder().setBase(srgb2).setRange(srgb1).build());
final LuOriginatorSrgbTlv tlv = new LuOriginatorSrgbTlvBuilder().setSrgbValue(list).build();
final ByteBuf serialized = Unpooled.buffer(14);
parser.serializeBgpPrefixSidTlv(tlv, serialized);
final byte[] expected = new byte[] { 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 2, 0, 0, 1 };
assertArrayEquals(expected, serialized.array());
final LuOriginatorSrgbTlv parsed = parser.parseBgpPrefixSidTlv(serialized);
assertEquals(tlv.getSrgbValue().size(), parsed.getSrgbValue().size());
assertEquals(tlv.getSrgbValue().get(0).getBase(), srgb1);
assertEquals(tlv.getSrgbValue().get(0).getRange(), srgb2);
assertEquals(tlv.getSrgbValue().get(1).getBase(), srgb2);
assertEquals(tlv.getSrgbValue().get(1).getRange(), srgb1);
assertEquals(3, parser.getType());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv in project bgpcep by opendaylight.
the class OriginatorSrgbTlvParser method serializeBgpPrefixSidTlv.
@Override
public void serializeBgpPrefixSidTlv(final BgpPrefixSidTlv tlv, final ByteBuf valueBuf) {
checkArgument(tlv instanceof LuOriginatorSrgbTlv, "Incoming TLV is not LuOriginatorSrgbTlv");
final LuOriginatorSrgbTlv luTlv = (LuOriginatorSrgbTlv) tlv;
valueBuf.writeZero(ORIGINATOR_FLAGS_BYTES);
for (final SrgbValue val : luTlv.nonnullSrgbValue()) {
writeUint24(valueBuf, val.getBase());
writeUint24(valueBuf, val.getRange());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv in project bgpcep by opendaylight.
the class InitiationHandler method parseMessageBody.
@Override
public Notification parseMessageBody(final ByteBuf bytes) throws BmpDeserializationException {
final InitiationMessageBuilder initiationBuilder = new InitiationMessageBuilder();
final TlvsBuilder tlvsBuilder = new TlvsBuilder();
tlvsBuilder.setStringInformation(ImmutableList.of());
parseTlvs(tlvsBuilder, bytes);
if (tlvsBuilder.getDescriptionTlv() == null || tlvsBuilder.getDescriptionTlv().getDescription() == null) {
throw new BmpDeserializationException("Inclusion of sysDescr TLV is mandatory.");
}
if (tlvsBuilder.getNameTlv() == null || tlvsBuilder.getNameTlv().getName() == null) {
throw new BmpDeserializationException("Inclusion of sysName TLV is mandatory.");
}
return initiationBuilder.setTlvs(tlvsBuilder.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv in project bgpcep by opendaylight.
the class TerminationHandler method parseMessageBody.
@Override
public Notification parseMessageBody(final ByteBuf bytes) throws BmpDeserializationException {
final TerminationMessageBuilder terminationMessage = new TerminationMessageBuilder();
final TlvsBuilder tlvsBuilder = new TlvsBuilder();
tlvsBuilder.setStringInformation(ImmutableList.of());
parseTlvs(tlvsBuilder, bytes);
if (tlvsBuilder.getReasonTlv() == null || tlvsBuilder.getReasonTlv().getReason() == null) {
throw new BmpDeserializationException("Inclusion of Reason TLV is mandatory.");
}
return terminationMessage.setTlvs(tlvsBuilder.build()).build();
}
Aggregations