use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrRange in project bgpcep by opendaylight.
the class PrefixAttributesParser method parseAttribute.
private static void parseAttribute(final int key, final ByteBuf value, final ProtocolId protocolId, final PrefixAttributesBuilder builder, final List<RouteTag> routeTags, final List<ExtendedRouteTag> exRouteTags) {
switch(key) {
case IGP_FLAGS:
parseIgpFags(builder, value);
break;
case ROUTE_TAG:
parseRouteTags(routeTags, value);
break;
case EXTENDED_ROUTE_TAG:
parseExtendedRouteTags(exRouteTags, value);
break;
case PREFIX_METRIC:
final IgpMetric metric = new IgpMetric(value.readUnsignedInt());
builder.setPrefixMetric(metric);
LOG.debug("Parsed Metric: {}", metric);
break;
case FORWARDING_ADDRESS:
final IpAddress fwdAddress = parseForwardingAddress(value);
builder.setOspfForwardingAddress(fwdAddress);
LOG.debug("Parsed FWD Address: {}", fwdAddress);
break;
case PREFIX_OPAQUE:
if (LOG.isDebugEnabled()) {
LOG.debug("Parsed Opaque value: {}, not preserving it", ByteBufUtil.hexDump(value));
}
break;
case PREFIX_SID:
final SrPrefix prefix = SrPrefixAttributesParser.parseSrPrefix(value, protocolId);
builder.setSrPrefix(prefix);
LOG.debug("Parsed SR Prefix: {}", prefix);
break;
case IPV6_PREFIX_SID:
final Ipv6SrPrefix ipv6Prefix = Ipv6SrPrefixAttributesParser.parseSrIpv6Prefix(value);
builder.setIpv6SrPrefix(ipv6Prefix);
LOG.debug("Parsed Ipv6 SR Prefix: {}", ipv6Prefix);
break;
case RANGE:
final SrRange range = RangeTlvParser.parseSrRange(value, protocolId);
builder.setSrRange(range);
LOG.debug("Parsed SR Range: {}", range);
break;
case BINDING_SID:
parseBindingSid(builder, value, protocolId);
break;
default:
LOG.warn("TLV {} is not a valid prefix attribute, ignoring it", key);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrRange in project bgpcep by opendaylight.
the class SrAttributeParserTest method testRangeTlv.
// tools.ietf.org/html/draft-gredler-idr-bgp-ls-segment-routing-ext-00#section-2.3.2
@Test
public void testRangeTlv() {
final byte[] tested = { 0, 0, 0, 5, // sid
4, // sid
(byte) 0x89, // sid
0, // sid
4, // sid
1, // sid
2, // sid
3, // sid
4, // prefix + mpls label
4, // prefix + mpls label
(byte) 0x86, // prefix + mpls label
0, // prefix + mpls label
7, // prefix + mpls label
(byte) 0xac, // prefix + mpls label
1, // prefix + mpls label
0, // prefix + mpls label
0, // prefix + mpls label
1, // prefix + mpls label
2, // prefix + mpls label
0, // binding sid
4, // binding sid
(byte) 0x88, // binding sid
0, // binding sid
0x58, // binding sid
5, // binding sid
0x48, // binding sid
0, // binding sid
0, // prefix
4, // prefix
(byte) 0x86, // prefix
0, // prefix
8, // prefix
(byte) 0xa0, // prefix
1, // prefix
0, // prefix
0, // prefix
1, // prefix
2, // prefix
3, // prefix
4, // sid
4, // sid
(byte) 0x89, // sid
0, // sid
4, // sid
1, // sid
2, // sid
3, // sid
4, // ero metric
4, // ero metric
(byte) 0x8a, // ero metric
0, // ero metric
4, // ero metric
0, // ero metric
0, // ero metric
0, // ero metric
6, // IPv4 ERO
4, // IPv4 ERO
(byte) 0x8b, // IPv4 ERO
0, // IPv4 ERO
8, // IPv4 ERO
0, // IPv4 ERO
0, // IPv4 ERO
0, // IPv4 ERO
0, // IPv4 ERO
9, // IPv4 ERO
8, // IPv4 ERO
7, // IPv4 ERO
6, // Unnumbered Interface ID ERO Sub-TLV
4, // Unnumbered Interface ID ERO Sub-TLV
(byte) 0x8d, // Unnumbered Interface ID ERO Sub-TLV
0, // Unnumbered Interface ID ERO Sub-TLV
0x0c, // Unnumbered Interface ID ERO Sub-TLV
0, // Unnumbered Interface ID ERO Sub-TLV
0, // Unnumbered Interface ID ERO Sub-TLV
0, // Unnumbered Interface ID ERO Sub-TLV
0, // Unnumbered Interface ID ERO Sub-TLV
1, // Unnumbered Interface ID ERO Sub-TLV
1, // Unnumbered Interface ID ERO Sub-TLV
1, // Unnumbered Interface ID ERO Sub-TLV
1, // Unnumbered Interface ID ERO Sub-TLV
2, // Unnumbered Interface ID ERO Sub-TLV
2, // Unnumbered Interface ID ERO Sub-TLV
2, // Unnumbered Interface ID ERO Sub-TLV
2, // IPv4 ERO backup
4, // IPv4 ERO backup
(byte) 0x8e, // IPv4 ERO backup
0, // IPv4 ERO backup
8, // IPv4 ERO backup
0, // IPv4 ERO backup
0, // IPv4 ERO backup
0, // IPv4 ERO backup
0, // IPv4 ERO backup
3, // IPv4 ERO backup
4, // IPv4 ERO backup
5, // IPv4 ERO backup
6, // Unnumbered Interface ID ERO Sub-TLV Backup
4, // Unnumbered Interface ID ERO Sub-TLV Backup
(byte) 0x90, // Unnumbered Interface ID ERO Sub-TLV Backup
0, // Unnumbered Interface ID ERO Sub-TLV Backup
0x0c, // Unnumbered Interface ID ERO Sub-TLV Backup
0, // Unnumbered Interface ID ERO Sub-TLV Backup
0, // Unnumbered Interface ID ERO Sub-TLV Backup
0, // Unnumbered Interface ID ERO Sub-TLV Backup
0, // Unnumbered Interface ID ERO Sub-TLV Backup
3, // Unnumbered Interface ID ERO Sub-TLV Backup
3, // Unnumbered Interface ID ERO Sub-TLV Backup
3, // Unnumbered Interface ID ERO Sub-TLV Backup
3, // Unnumbered Interface ID ERO Sub-TLV Backup
4, // Unnumbered Interface ID ERO Sub-TLV Backup
4, // Unnumbered Interface ID ERO Sub-TLV Backup
4, // Unnumbered Interface ID ERO Sub-TLV Backup
4 };
final SrRange parsedRange = RangeTlvParser.parseSrRange(Unpooled.wrappedBuffer(tested), ProtocolId.IsisLevel1);
final List<SubTlvs> rangeSubTlvs = new ArrayList<>();
addSubTlvs(rangeSubTlvs);
final SrRange expected = new SrRangeBuilder().setInterArea(Boolean.FALSE).setRangeSize(5).setSubTlvs(rangeSubTlvs).build();
assertEquals(expected, parsedRange);
final ByteBuf serializedRange = Unpooled.buffer();
RangeTlvParser.serializeSrRange(parsedRange, serializedRange);
assertArrayEquals(tested, ByteArray.getAllBytes(serializedRange));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrRange in project bgpcep by opendaylight.
the class SrAttributeParserTest method testRangeTlvIpv6.
@Test
public void testRangeTlvIpv6() {
final byte[] tested = Bytes.concat(new byte[] { 0, 0, 0, 5, // binding sid
4, // binding sid
(byte) 0x88, // binding sid
0, // binding sid
0x34, // binding sid
5, // binding sid
0x48, // binding sid
0, // binding sid
0, // binding sub-tlvs
4, (byte) 0x8c, 0, 0x14, 0, 0, 0, // IPv6 ERO
0 }, // IPv6 ERO
IPV6_A_BYTES, // IPv6 ERO backup
new byte[] { 4, (byte) 0x8f, 0, 0x14, 0, 0, 0, 0 }, // IPv6 ERO backup
IPV6_B_BYTES);
final SrRange parsedRange = RangeTlvParser.parseSrRange(Unpooled.wrappedBuffer(tested), ProtocolId.IsisLevel1);
final List<SubTlvs> rangeSubTlvs = new ArrayList<>();
final List<BindingSubTlvs> bindingSubTlvs = new ArrayList<>();
bindingSubTlvs.add(new BindingSubTlvsBuilder().setBindingSubTlv(new Ipv6EroCaseBuilder().setLoose(Boolean.FALSE).setAddress(new Ipv6Address(IPV6_A)).build()).build());
bindingSubTlvs.add(new BindingSubTlvsBuilder().setBindingSubTlv(new Ipv6EroBackupCaseBuilder().setLoose(Boolean.FALSE).setAddress(new Ipv6Address(IPV6_B)).build()).build());
rangeSubTlvs.add(new SubTlvsBuilder().setRangeSubTlv(new BindingSidTlvCaseBuilder().setWeight(new Weight((short) 5)).setFlags(BINDING_FLAGS).setBindingSubTlvs(bindingSubTlvs).build()).build());
final SrRange expected = new SrRangeBuilder().setInterArea(Boolean.FALSE).setRangeSize(5).setSubTlvs(rangeSubTlvs).build();
assertEquals(expected, parsedRange);
final ByteBuf serializedRange = Unpooled.buffer();
RangeTlvParser.serializeSrRange(parsedRange, serializedRange);
assertArrayEquals(tested, ByteArray.getAllBytes(serializedRange));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrRange in project bgpcep by opendaylight.
the class RangeTlvParser method parseSrRange.
public static SrRange parseSrRange(final ByteBuf buffer, final ProtocolId protocolId) {
final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
final SrRangeBuilder range = new SrRangeBuilder();
if (protocolId.equals(ProtocolId.Ospf)) {
range.setInterArea(flags.get(INNER_AREA));
} else {
range.setInterArea(Boolean.FALSE);
}
buffer.skipBytes(RESERVED);
range.setRangeSize(buffer.readUnsignedShort());
range.setSubTlvs(parseRangeSubTlvs(buffer, protocolId));
return range.build();
}
Aggregations