use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class BGPUpdateMessageParser method withdrawAttributes.
private Attributes withdrawAttributes(final Attributes parsed, final BGPTreatAsWithdrawException withdrawCause) throws BGPDocumentedException {
final AttributesBuilder builder = new AttributesBuilder();
final MpReachNlri mpReachNlri = getMpReach(parsed);
if (mpReachNlri == null) {
// No MP_REACH attribute, just reuse MP_UNREACH if it is present.
final AttributesUnreach attrs2 = parsed.augmentation(AttributesUnreach.class);
if (attrs2 != null) {
builder.addAugmentation(attrs2);
}
return builder.build();
}
final MpUnreachNlri unreachNlri = getMpUnreach(parsed);
if (unreachNlri != null) {
final TablesKey reachKey = new TablesKey(mpReachNlri.getAfi(), mpReachNlri.getSafi());
final TablesKey unreachKey = new TablesKey(unreachNlri.getAfi(), unreachNlri.getSafi());
if (!reachKey.equals(unreachKey)) {
LOG.warn("Unexpected mismatch between MP_REACH ({}) and MP_UNREACH ({})", reachKey, unreachKey, withdrawCause);
throw new BGPDocumentedException(withdrawCause);
}
}
final MpUnreachNlri converted = this.nlriReg.convertMpReachToMpUnReach(mpReachNlri, unreachNlri).orElseThrow(() -> {
LOG.warn("Could not convert attributes {} to withdraw attributes", parsed, withdrawCause);
return new BGPDocumentedException(withdrawCause);
});
builder.addAugmentation(new AttributesUnreachBuilder().setMpUnreachNlri(converted).build());
return builder.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 AigpAttributeParser method parseAigpTLV.
/**
* Reads data from buffer until reaches TLV of type AIGP TLV.
*
* @param buffer TLVs in ByteBuf format
* @return instance of AigpTlv class or null if buffer contains unknown TLV type
*/
private static AigpTlv parseAigpTLV(final ByteBuf buffer) {
final int tlvType = buffer.readByte();
buffer.skipBytes(TLV_SIZE_IN_BYTES);
if (tlvType != AIGP_TLV_TYPE) {
LOG.warn("AIGP attribute contains unknown TLV type {}.", tlvType);
return null;
}
return new AigpTlvBuilder().setMetric(new AccumulatedIgpMetric(ByteBufUtils.readUint64(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 ClusterIdAttributeParser 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.10
LOG.debug("Discarded CLUSTER_LIST attribute from external peer");
return;
}
final int readable = buffer.readableBytes();
if (readable == 0 && errorHandling != RevisedErrorHandling.NONE) {
throw new BGPTreatAsWithdrawException(BGPError.ATTR_LENGTH_ERROR, "Empty CLUSTER_LIST attribute");
}
if (readable % Ipv4Util.IP4_LENGTH != 0) {
throw errorHandling.reportError(BGPError.ATTR_LENGTH_ERROR, "Length of CLUSTER_LIST should be a multiple of 4, but is %s", readable);
}
final int count = readable / Ipv4Util.IP4_LENGTH;
final List<ClusterIdentifier> list = new ArrayList<>(count);
for (int i = 0; i < count; ++i) {
list.add(new ClusterIdentifier(Ipv4Util.addressForByteBuf(buffer)));
}
builder.setClusterId(new ClusterIdBuilder().setCluster(list).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 BGPParserTest method testGetUpdateMessage3.
/*
* Tests more AS Numbers in AS_PATH, AGGREGATOR, ORIGIN.INCOMPLETE
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 4b <- length (75) - including header
* 02 <- message type
* 00 00 <- withdrawn routes length
* 00 30 <- total path attribute length (48)
* 40 <- attribute flags
* 01 <- attribute type code (origin)
* 01 <- attribute length
* 02 <- Origin value (Incomplete)
* 40 <- attribute flags
* 02 <- attribute type code (as path)
* 10 <- attribute length
* 02 <- AS_SEQUENCE
* 01 <- path segment count
* 00 00 00 1e <- path segment value (30)
* 01 <- AS_SET
* 02 <- path segment count
* 00 00 00 0a <- path segment value (10)
* 00 00 00 14 <- path segment value (20)
* 40 <- attribute flags
* 03 <- attribute type (Next hop)
* 04 <- attribute length
* 0a 00 00 09 <- value (10.0.0.9)
* 80 <- attribute flags
* 04 <- attribute type code (multi exit disc)
* 04 <- attribute length
* 00 00 00 00 <- value
* c0 <- attribute flags
* 07 <- attribute type (Aggregator)
* 08 <- attribute length
* 00 00 00 1e <- value (AS number = 30)
* 0a 00 00 09 <- value (IP address = 10.0.0.9)
*
* //NLRI
* 15 ac 10 00 <- IPv4 Prefix (172.16.0.0 / 21)
*/
@Test
public void testGetUpdateMessage3() throws Exception {
final byte[] body = ByteArray.cutBytes(INPUT_BYTES.get(2), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(INPUT_BYTES.get(2), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, null);
final UpdateBuilder builder = new UpdateBuilder();
// check nlri
final List<Nlri> nlris = List.of(new NlriBuilder().setPrefix(new Ipv4Prefix("172.16.0.0/21")).build());
builder.setNlri(nlris);
assertEquals(builder.getNlri(), message.getNlri());
// check fields
assertNull(message.getWithdrawnRoutes());
// attributes
final List<AsNumber> asNumbers = new ArrayList<>();
asNumbers.add(new AsNumber(Uint32.valueOf(30)));
final List<Segments> asPath = new ArrayList<>();
asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
final List<AsNumber> asSet = List.of(new AsNumber(Uint32.TEN), new AsNumber(Uint32.valueOf(20)));
asPath.add(new SegmentsBuilder().setAsSet(asSet).build());
final Aggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber(Uint32.valueOf(30))).setNetworkAddress(new Ipv4AddressNoZone("10.0.0.9")).build();
final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4AddressNoZone("10.0.0.9")).build()).build();
// check path attributes
final Attributes attrs = message.getAttributes();
final AttributesBuilder paBuilder = new AttributesBuilder();
paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Incomplete).build());
assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
paBuilder.setCNextHop(nextHop);
assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(Uint32.ZERO).build());
assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
paBuilder.setAggregator(aggregator);
assertEquals(paBuilder.getAggregator(), attrs.getAggregator());
paBuilder.setUnrecognizedAttributes(Map.of());
builder.setAttributes(paBuilder.build());
assertEquals(builder.build(), message);
final ByteBuf buffer = Unpooled.buffer();
BGPParserTest.updateParser.serializeMessage(message, buffer);
assertArrayEquals(INPUT_BYTES.get(2), ByteArray.readAllBytes(buffer));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class BGPParserTest method testUpdateMessageWithdrawAddPath.
/*
* Tests withdrawn routes with multiple paths.
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 29 <- length (41) - including header
* 02 <- message type
* 00 12 <- withdrawn routes length (18)
* 00 00 00 01 <- path-id (1)
* 1e ac 10 00 04 <- route (172.16.0.4)
* 00 00 00 02 <- path-id (2)
* 1e ac 10 00 04 <- route (172.16.0.4)
* 00 00 <- total path attribute length
*
*/
@Test
public void testUpdateMessageWithdrawAddPath() throws Exception {
final byte[] body = ByteArray.cutBytes(updatesWithMultiplePath.get(1), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(updatesWithMultiplePath.get(1), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, mpConstraint);
// attributes
final List<WithdrawnRoutes> withdrawnRoutes = new ArrayList<>();
withdrawnRoutes.add(new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("172.16.0.4/30")).setPathId(new PathId(Uint32.ONE)).build());
withdrawnRoutes.add(new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("172.16.0.4/30")).setPathId(new PathId(Uint32.TWO)).build());
// check API message
final Update expectedMessage = new UpdateBuilder().setWithdrawnRoutes(withdrawnRoutes).build();
assertEquals(expectedMessage.getWithdrawnRoutes(), message.getWithdrawnRoutes());
final ByteBuf buffer = Unpooled.buffer();
BGPParserTest.updateParser.serializeMessage(message, buffer);
assertArrayEquals(updatesWithMultiplePath.get(1), ByteArray.readAllBytes(buffer));
}
Aggregations