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)
*/
private static AsPath parseAsPath(final ReferenceCache refCache, final ByteBuf buffer, final RevisedErrorHandling errorHandling) throws BGPDocumentedException, BGPTreatAsWithdrawException {
if (!buffer.isReadable()) {
return EMPTY;
}
final List<Segments> ases = new ArrayList<>();
boolean isSequence = false;
for (int readable = buffer.readableBytes(); readable != 0; readable = buffer.readableBytes()) {
if (readable < 2) {
throw errorHandling.reportError(BGPError.AS_PATH_MALFORMED, "Insufficient AS PATH segment header length %s", readable);
}
final int type = buffer.readUnsignedByte();
final SegmentType segmentType = AsPathSegmentParser.parseType(type);
if (segmentType == null) {
throw errorHandling.reportError(BGPError.AS_PATH_MALFORMED, "Unknown AS PATH segment type %s", type);
}
final int count = buffer.readUnsignedByte();
if (count == 0 && errorHandling != RevisedErrorHandling.NONE) {
throw new BGPTreatAsWithdrawException(BGPError.AS_PATH_MALFORMED, "Empty AS_PATH segment");
}
// We read 2 bytes of header at this point
readable -= 2;
final int segmentLength = count * AsPathSegmentParser.AS_NUMBER_LENGTH;
if (segmentLength > readable) {
throw errorHandling.reportError(BGPError.AS_PATH_MALFORMED, "Calculated segment length %s would overflow available buffer %s", segmentLength, readable);
}
final List<AsNumber> asList = AsPathSegmentParser.parseAsSegment(refCache, count, buffer.readSlice(segmentLength));
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 errorHandling.reportError(BGPError.AS_PATH_MALFORMED, "AS_SEQUENCE must be present in AS_PATH attribute.");
}
return new AsPathBuilder().setSegments(ImmutableList.copyOf(ases)).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class LocalPreferenceAttributeParser method parseAttribute.
@Override
public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder, final RevisedErrorHandling errorHandling, final PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPTreatAsWithdrawException {
if (errorHandling == RevisedErrorHandling.EXTERNAL) {
// RFC7606 section 7.7
LOG.debug("Discarded LOCAL_PREF attribute from external peer");
return;
}
final int readable = buffer.readableBytes();
if (readable != 4) {
throw errorHandling.reportError(BGPError.ATTR_LENGTH_ERROR, "Expected 4 bytes, have %s", readable);
}
builder.setLocalPref(new LocalPrefBuilder().setPref(ByteBufUtils.readUint32(buffer)).build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class MPUnreachAttributeParser method serializeAttribute.
@Override
public void serializeAttribute(final Attributes attribute, final ByteBuf byteAggregator) {
final AttributesUnreach pathAttributes2 = attribute.augmentation(AttributesUnreach.class);
if (pathAttributes2 != null) {
final ByteBuf unreachBuffer = Unpooled.buffer();
reg.serializeMpUnReach(pathAttributes2.getMpUnreachNlri(), unreachBuffer);
for (final NlriSerializer nlriSerializer : this.reg.getSerializers()) {
nlriSerializer.serializeAttribute(attribute, unreachBuffer);
}
AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, TYPE, unreachBuffer, byteAggregator);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class NextHopAttributeParser method parseAttribute.
@Override
public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder, final RevisedErrorHandling errorHandling, final PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPTreatAsWithdrawException {
final int readable = buffer.readableBytes();
final CNextHop nextHop;
switch(readable) {
case IP4_LENGTH:
nextHop = NextHopUtil.parseNextHopIpv4(buffer);
break;
case IPV6_LENGTH:
nextHop = NextHopUtil.parseNextHopIpv6(buffer);
break;
case IPV6_LENGTH * 2:
nextHop = NextHopUtil.parseNextHopFullIpv6(buffer);
break;
default:
throw errorHandling.reportError(BGPError.ATTR_LENGTH_ERROR, "NEXT_HOP attribute is expected to have length of {%s, %s, %s} but has %s", IP4_LENGTH, IPV6_LENGTH, IPV6_LENGTH * 2, readable);
}
builder.setCNextHop(nextHop);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class NextHopAttributeParser method serializeAttribute.
@Override
public void serializeAttribute(final Attributes attribute, final ByteBuf byteAggregator) {
final CNextHop cNextHop = attribute.getCNextHop();
if (cNextHop != null) {
final ByteBuf nextHopBuffer = Unpooled.buffer();
NextHopUtil.serializeNextHop(cNextHop, nextHopBuffer);
AttributeUtil.formatAttribute(AttributeUtil.TRANSITIVE, TYPE, nextHopBuffer, byteAggregator);
}
}
Aggregations