Search in sources :

Example 1 with SrRangeBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrRangeBuilder 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));
}
Also used : SrRange(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrRange) SrRangeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrRangeBuilder) ArrayList(java.util.ArrayList) SubTlvs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.range.tlv.SubTlvs) BindingSubTlvs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.BindingSubTlvs) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 2 with SrRangeBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrRangeBuilder 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));
}
Also used : SrRange(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrRange) Ipv6EroCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6EroCaseBuilder) BindingSubTlvsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.BindingSubTlvsBuilder) SubTlvsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.range.tlv.SubTlvsBuilder) SrRangeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrRangeBuilder) ArrayList(java.util.ArrayList) SubTlvs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.range.tlv.SubTlvs) BindingSubTlvs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.BindingSubTlvs) ByteBuf(io.netty.buffer.ByteBuf) Ipv6EroBackupCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6EroBackupCaseBuilder) Weight(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Weight) BindingSubTlvsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.BindingSubTlvsBuilder) Ipv6Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address) BindingSubTlvs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.BindingSubTlvs) BindingSidTlvCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.range.sub.tlvs.range.sub.tlv.BindingSidTlvCaseBuilder) Test(org.junit.Test)

Example 3 with SrRangeBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrRangeBuilder 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();
}
Also used : SrRangeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrRangeBuilder) BitArray(org.opendaylight.protocol.util.BitArray)

Aggregations

SrRangeBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrRangeBuilder)3 ByteBuf (io.netty.buffer.ByteBuf)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 SrRange (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrRange)2 BindingSubTlvs (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.BindingSubTlvs)2 SubTlvs (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.range.tlv.SubTlvs)2 BitArray (org.opendaylight.protocol.util.BitArray)1 Ipv6Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address)1 Weight (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Weight)1 BindingSubTlvsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.BindingSubTlvsBuilder)1 Ipv6EroBackupCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6EroBackupCaseBuilder)1 Ipv6EroCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.Ipv6EroCaseBuilder)1 BindingSidTlvCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.range.sub.tlvs.range.sub.tlv.BindingSidTlvCaseBuilder)1 SubTlvsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.range.tlv.SubTlvsBuilder)1