Search in sources :

Example 66 with Tlv

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;
}
Also used : PrefixSidTlvBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.range.sub.tlvs.range.sub.tlv.prefix.sid.tlv._case.PrefixSidTlvBuilder) Ipv6PrefixSidTlvBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.range.sub.tlvs.range.sub.tlv.ipv6.prefix.sid.tlv._case.Ipv6PrefixSidTlvBuilder) Ipv6PrefixSidTlvBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.range.sub.tlvs.range.sub.tlv.ipv6.prefix.sid.tlv._case.Ipv6PrefixSidTlvBuilder) SubTlvsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.range.tlv.SubTlvsBuilder) RangeSubTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.range.sub.tlvs.RangeSubTlv) ArrayList(java.util.ArrayList) Ipv6PrefixSidTlvCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.range.sub.tlvs.range.sub.tlv.Ipv6PrefixSidTlvCaseBuilder) PrefixSidTlvCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.range.sub.tlvs.range.sub.tlv.PrefixSidTlvCaseBuilder) Ipv6PrefixSidTlvCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.range.sub.tlvs.range.sub.tlv.Ipv6PrefixSidTlvCaseBuilder) SubTlvs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.range.tlv.SubTlvs) SidLabelTlvCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.range.sub.tlvs.range.sub.tlv.SidLabelTlvCaseBuilder) BindingSidTlvCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.range.sub.tlvs.range.sub.tlv.BindingSidTlvCaseBuilder)

Example 67 with Tlv

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());
}
Also used : LuOriginatorSrgbTlvBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.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.rev180329.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.rev180329.originator.srgb.tlv.SrgbValue) SrgbValueBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.originator.srgb.tlv.SrgbValueBuilder) ByteBuf(io.netty.buffer.ByteBuf) Srgb(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.Srgb) Test(org.junit.Test)

Example 68 with Tlv

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());
    }
}
Also used : LuOriginatorSrgbTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.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.rev180329.originator.srgb.tlv.SrgbValue)

Example 69 with Tlv

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();
}
Also used : TlvsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.initiation.TlvsBuilder) InitiationMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.InitiationMessageBuilder) BmpDeserializationException(org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException)

Example 70 with Tlv

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();
}
Also used : TlvsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.termination.TlvsBuilder) TerminationMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.TerminationMessageBuilder) BmpDeserializationException(org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)59 Test (org.junit.Test)28 Tlv (es.gob.jmulticard.asn1.Tlv)11 ArrayList (java.util.ArrayList)10 TunnelId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId)8 LspId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId)7 TlvException (es.gob.jmulticard.asn1.TlvException)6 Stateful (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.stateful.capability.tlv.Stateful)5 Ipv4ExtendedTunnelId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.Ipv4ExtendedTunnelId)5 Asn1Exception (es.gob.jmulticard.asn1.Asn1Exception)4 DecoderObject (es.gob.jmulticard.asn1.DecoderObject)4 BitArray (org.opendaylight.protocol.util.BitArray)4 Ipv6ExtendedTunnelId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.Ipv6ExtendedTunnelId)4 ObjectHeaderImpl (org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl)3 EnterpriseNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber)3 Stateful (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.stateful.capability.tlv.Stateful)3 LspIdentifiers (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.identifiers.tlv.LspIdentifiers)3 LspIdentifiersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.identifiers.tlv.LspIdentifiersBuilder)3 AddressFamily (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.identifiers.tlv.lsp.identifiers.AddressFamily)3 RsvpErrorSpec (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.rsvp.error.spec.tlv.RsvpErrorSpec)3