Search in sources :

Example 1 with SrgbValue

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.originator.srgb.tlv.SrgbValue in project bgpcep by opendaylight.

the class OriginatorSrgbTlvParser method parseSrgbs.

private static List<SrgbValue> parseSrgbs(final ByteBuf buffer) {
    Preconditions.checkState(buffer.readableBytes() % SRGB_LENGTH == 0, "Number of SRGBs doesn't fit available bytes.");
    final List<SrgbValue> ret = new ArrayList<>();
    while (buffer.isReadable()) {
        ret.add(new SrgbValueBuilder().setBase(new Srgb((long) buffer.readUnsignedMedium())).setRange(new Srgb((long) buffer.readUnsignedMedium())).build());
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) SrgbValue(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.originator.srgb.tlv.SrgbValue) SrgbValueBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.originator.srgb.tlv.SrgbValueBuilder) Srgb(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.Srgb)

Example 2 with SrgbValue

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.originator.srgb.tlv.SrgbValue 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(1L);
    final Srgb srgb2 = new Srgb(2L);
    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());
    assertTrue(tlv.getSrgbValue().get(0).getBase().equals(srgb1));
    assertTrue(tlv.getSrgbValue().get(0).getRange().equals(srgb2));
    assertTrue(tlv.getSrgbValue().get(1).getBase().equals(srgb2));
    assertTrue(tlv.getSrgbValue().get(1).getRange().equals(srgb1));
    assertEquals(3, parser.getType());
}
Also used : LuOriginatorSrgbTlvBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.update.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.bgp.prefix.sid.tlv.LuOriginatorSrgbTlvBuilder) ArrayList(java.util.ArrayList) LuOriginatorSrgbTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.update.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.bgp.prefix.sid.tlv.LuOriginatorSrgbTlv) SrgbValue(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.originator.srgb.tlv.SrgbValue) SrgbValueBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.originator.srgb.tlv.SrgbValueBuilder) ByteBuf(io.netty.buffer.ByteBuf) Srgb(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.Srgb) Test(org.junit.Test)

Example 3 with SrgbValue

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.originator.srgb.tlv.SrgbValue in project bgpcep by opendaylight.

the class OriginatorSrgbTlvParser method serializeBgpPrefixSidTlv.

@Override
public void serializeBgpPrefixSidTlv(final BgpPrefixSidTlv tlv, final ByteBuf valueBuf) {
    Preconditions.checkArgument(tlv instanceof LuOriginatorSrgbTlv, "Incoming TLV is not LuOriginatorSrgbTlv");
    final LuOriginatorSrgbTlv luTlv = (LuOriginatorSrgbTlv) tlv;
    valueBuf.writeZero(ORIGINATOR_FLAGS_BYTES);
    for (final SrgbValue val : luTlv.getSrgbValue()) {
        valueBuf.writeMedium(val.getBase().getValue().intValue());
        valueBuf.writeMedium(val.getRange().getValue().intValue());
    }
}
Also used : LuOriginatorSrgbTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.update.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.bgp.prefix.sid.tlv.LuOriginatorSrgbTlv) SrgbValue(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.originator.srgb.tlv.SrgbValue)

Aggregations

SrgbValue (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.originator.srgb.tlv.SrgbValue)3 ArrayList (java.util.ArrayList)2 Srgb (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.Srgb)2 SrgbValueBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.originator.srgb.tlv.SrgbValueBuilder)2 LuOriginatorSrgbTlv (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.update.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.bgp.prefix.sid.tlv.LuOriginatorSrgbTlv)2 ByteBuf (io.netty.buffer.ByteBuf)1 Test (org.junit.Test)1 LuOriginatorSrgbTlvBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.update.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.bgp.prefix.sid.tlv.LuOriginatorSrgbTlvBuilder)1