Search in sources :

Example 56 with Attribute

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.

the class AigpAttributeParser method serializeAigpTLV.

/**
 * Transform AIGP attribute data from instance of Aigp class into byte buffer representation.
 *
 * @param aigp
 *          instance of Aigp class
 * @return
 *          byte buffer representation or empty buffer if AIGP TLV is null
 */
private static ByteBuf serializeAigpTLV(final Aigp aigp) {
    final AigpTlv tlv = aigp.getAigpTlv();
    if (tlv == null) {
        return Unpooled.EMPTY_BUFFER;
    }
    final ByteBuf value = Unpooled.buffer(AIGP_TLV_SIZE);
    value.writeByte(AIGP_TLV_TYPE);
    value.writeShort(AIGP_TLV_SIZE);
    value.writeLong(tlv.getMetric().getValue().longValue());
    return value;
}
Also used : AigpTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.aigp.AigpTlv) ByteBuf(io.netty.buffer.ByteBuf)

Example 57 with Attribute

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.

the class AsPathAttributeParser method parseAsPath.

/**
 * Parses AS_PATH from bytes.
 *
 * @param refCache ReferenceCache shared reference of object
 * @param buffer bytes to be parsed
 * @return new ASPath object
 * @throws BGPDocumentedException if there is no AS_SEQUENCE present (mandatory)
 * @throws BGPParsingException
 */
private static AsPath parseAsPath(final ReferenceCache refCache, final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
    if (!buffer.isReadable()) {
        return EMPTY;
    }
    final ArrayList<Segments> ases = new ArrayList<>();
    boolean isSequence = false;
    while (buffer.isReadable()) {
        final int type = buffer.readUnsignedByte();
        final SegmentType segmentType = AsPathSegmentParser.parseType(type);
        if (segmentType == null) {
            throw new BGPParsingException("AS Path segment type unknown : " + type);
        }
        final int count = buffer.readUnsignedByte();
        final List<AsNumber> asList = AsPathSegmentParser.parseAsSegment(refCache, count, buffer.readSlice(count * AsPathSegmentParser.AS_NUMBER_LENGTH));
        if (segmentType == SegmentType.AS_SEQUENCE) {
            ases.add(new SegmentsBuilder().setAsSequence(asList).build());
            isSequence = true;
        } else {
            ases.add(new SegmentsBuilder().setAsSet(asList).build());
        }
    }
    if (!isSequence) {
        throw new BGPDocumentedException("AS_SEQUENCE must be present in AS_PATH attribute.", BGPError.AS_PATH_MALFORMED);
    }
    ases.trimToSize();
    return new AsPathBuilder().setSegments(ases).build();
}
Also used : SegmentType(org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathSegmentParser.SegmentType) AsPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder) SegmentsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.SegmentsBuilder) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) ArrayList(java.util.ArrayList) Segments(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.Segments) BGPParsingException(org.opendaylight.protocol.bgp.parser.BGPParsingException) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)

Example 58 with Attribute

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.

the class OriginAttributeParser method serializeAttribute.

@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
    Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object.");
    final Origin origin = ((Attributes) attribute).getOrigin();
    if (origin == null) {
        return;
    }
    AttributeUtil.formatAttribute(AttributeUtil.TRANSITIVE, TYPE, Unpooled.wrappedBuffer(new byte[] { UnsignedBytes.checkedCast(origin.getValue().getIntValue()) }), byteAggregator);
}
Also used : Origin(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Origin) BgpOrigin(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes)

Example 59 with Attribute

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.

the class UnrecognizedAttributesSerializer method serializeAttribute.

@Override
public void serializeAttribute(final DataObject attributes, final ByteBuf byteAggregator) {
    Preconditions.checkArgument(attributes instanceof Attributes, "Attributes parameter is not a PathAttribute object.");
    final List<UnrecognizedAttributes> unrecognizedAttrs = ((Attributes) attributes).getUnrecognizedAttributes();
    if (unrecognizedAttrs == null) {
        return;
    }
    for (final UnrecognizedAttributes unrecognizedAttr : unrecognizedAttrs) {
        LOG.trace("Serializing unrecognized attribute of type {}", unrecognizedAttr.getType());
        int flags = AttributeUtil.OPTIONAL;
        if (unrecognizedAttr.isPartial()) {
            flags |= AttributeUtil.PARTIAL;
        }
        if (unrecognizedAttr.isTransitive()) {
            flags |= AttributeUtil.TRANSITIVE;
        }
        AttributeUtil.formatAttribute(flags, unrecognizedAttr.getType(), Unpooled.wrappedBuffer(unrecognizedAttr.getValue()), byteAggregator);
    }
}
Also used : UnrecognizedAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributes) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) UnrecognizedAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.UnrecognizedAttributes)

Example 60 with Attribute

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.

the class BgpPrefixSidAttributeParser method serializeAttribute.

@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
    Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object.");
    final Attributes pathAttributes = (Attributes) attribute;
    final BgpPrefixSid prefixSid = pathAttributes.getBgpPrefixSid();
    if (prefixSid == null) {
        return;
    }
    for (final BgpPrefixSidTlvs tlv : prefixSid.getBgpPrefixSidTlvs()) {
        this.reg.serializeBgpPrefixSidTlv(tlv.getBgpPrefixSidTlv(), byteAggregator);
    }
}
Also used : BgpPrefixSidTlvs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.bgp.prefix.sid.BgpPrefixSidTlvs) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) BgpPrefixSid(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.BgpPrefixSid)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)42 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes)25 PeerSpecificParserConstraint (org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)21 ArrayList (java.util.ArrayList)19 Test (org.junit.Test)17 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update)15 UpdateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateBuilder)10 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes)10 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder)10 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)8 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)8 AsPathBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.AsPathBuilder)8 Attributes2 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes2)8 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)7 OriginBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.OriginBuilder)7 Attributes1 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1)7 Ipv4NextHopCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCase)7 Ipv4NextHopCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCaseBuilder)7 Ipv4NextHopBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder)7 Attribute (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute)7