Search in sources :

Example 1 with SrPrefixBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.SrPrefixBuilder in project bgpcep by opendaylight.

the class SrPrefixAttributesParser method parseSrPrefix.

public static SrPrefix parseSrPrefix(final ByteBuf buffer, final ProtocolId protocol) {
    final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
    final SrPrefixBuilder builder = new SrPrefixBuilder().setFlags(parsePrefixFlags(flags, protocol)).setAlgorithm(Algorithm.forValue(buffer.readUnsignedByte()));
    buffer.skipBytes(RESERVED_PREFIX);
    return builder.setSidLabelIndex(SidLabelIndexParser.parseSidLabelIndexByFlags(Size.forValue(buffer.readableBytes()), buffer, flags.get(VALUE), flags.get(LOCAL))).build();
}
Also used : SrPrefixBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.SrPrefixBuilder) BitArray(org.opendaylight.protocol.util.BitArray)

Example 2 with SrPrefixBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.SrPrefixBuilder in project bgpcep by opendaylight.

the class SrAttributeParserTest method testSrPrefix.

// tools.ietf.org/html/draft-gredler-idr-bgp-ls-segment-routing-ext-00#section-2.3.1
@Test
public void testSrPrefix() {
    final byte[] bytes = { (byte) 0xA0, 0, 0, 0, 1, 2, 3, 4 };
    final byte[] bytesOspf = { (byte) 0x20, 0, 0, 0, 1, 2, 3, 4 };
    final SrPrefix prefixIsis = new SrPrefixBuilder().setFlags(ISIS_PREFIX_FLAGS).setAlgorithm(Algorithm.ShortestPathFirst).setSidLabelIndex(new SidCaseBuilder().setSid(Uint32.valueOf(16909060L)).build()).build();
    final SrPrefix prefixOspf = new SrPrefixBuilder().setFlags(OSPF_PREFIX_FLAGS).setAlgorithm(Algorithm.ShortestPathFirst).setSidLabelIndex(new SidCaseBuilder().setSid(Uint32.valueOf(16909060L)).build()).build();
    assertEquals(prefixIsis, SrPrefixAttributesParser.parseSrPrefix(Unpooled.wrappedBuffer(bytes), ProtocolId.IsisLevel1));
    assertEquals(prefixOspf, SrPrefixAttributesParser.parseSrPrefix(Unpooled.wrappedBuffer(bytes), ProtocolId.Ospf));
    final ByteBuf serializedPrefix = Unpooled.buffer();
    final ByteBuf serializedPrefixOspf = Unpooled.buffer();
    SrPrefixAttributesParser.serializeSrPrefix(prefixIsis, serializedPrefix);
    SrPrefixAttributesParser.serializeSrPrefix(prefixOspf, serializedPrefixOspf);
    assertArrayEquals(bytes, ByteArray.readAllBytes(serializedPrefix));
    assertArrayEquals(bytesOspf, ByteArray.readAllBytes(serializedPrefixOspf));
}
Also used : SrPrefix(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.SrPrefix) Ipv6SrPrefix(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.Ipv6SrPrefix) SrPrefixBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.SrPrefixBuilder) Ipv6SrPrefixBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.Ipv6SrPrefixBuilder) SidCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.SidCaseBuilder) PrefixSidCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.binding.sub.tlvs.binding.sub.tlv.PrefixSidCaseBuilder) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

SrPrefixBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.SrPrefixBuilder)2 ByteBuf (io.netty.buffer.ByteBuf)1 Test (org.junit.Test)1 BitArray (org.opendaylight.protocol.util.BitArray)1 Ipv6SrPrefix (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.Ipv6SrPrefix)1 Ipv6SrPrefixBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.Ipv6SrPrefixBuilder)1 SrPrefix (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.prefix.state.SrPrefix)1 PrefixSidCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.binding.sub.tlvs.binding.sub.tlv.PrefixSidCaseBuilder)1 SidCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.sid.label.index.sid.label.index.SidCaseBuilder)1