use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.mp.unreach.nlri.WithdrawnRoutes in project bgpcep by opendaylight.
the class BGPUpdateMessageParser method withdrawUpdate.
private Update withdrawUpdate(final Update parsed, final RevisedErrorHandling errorHandling, final BGPTreatAsWithdrawException withdrawCause) throws BGPDocumentedException {
if (errorHandling == RevisedErrorHandling.NONE) {
throw new BGPDocumentedException(withdrawCause);
}
// TODO: additional checks as per RFC7606 section 5.2
LOG.debug("Converting BGP Update message {} to withdraw", parsed, withdrawCause);
final UpdateBuilder builder = new UpdateBuilder();
final List<Nlri> nlris = parsed.getNlri();
final List<WithdrawnRoutes> withdrawn;
if (nlris != null && !nlris.isEmpty()) {
withdrawn = Streams.concat(parsed.nonnullWithdrawnRoutes().stream(), nlris.stream().map(nlri -> new WithdrawnRoutesBuilder(nlri).build())).collect(ImmutableList.toImmutableList());
} else {
withdrawn = parsed.getWithdrawnRoutes();
}
builder.setWithdrawnRoutes(withdrawn);
final Attributes attributes = parsed.getAttributes();
if (attributes != null) {
builder.setAttributes(withdrawAttributes(attributes, withdrawCause));
}
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.mp.unreach.nlri.WithdrawnRoutes in project bgpcep by opendaylight.
the class BGPUpdateMessageParser method serializeMessage.
@Override
public void serializeMessage(final Notification message, final ByteBuf bytes) {
checkArgument(message instanceof Update, "Message needs to be of type Update");
final Update update = (Update) message;
final ByteBuf messageBody = Unpooled.buffer();
final List<WithdrawnRoutes> withdrawnRoutes = update.getWithdrawnRoutes();
if (withdrawnRoutes != null) {
final ByteBuf withdrawnRoutesBuf = Unpooled.buffer();
withdrawnRoutes.forEach(withdrawnRoute -> writePathIdPrefix(withdrawnRoutesBuf, withdrawnRoute.getPathId(), withdrawnRoute.getPrefix()));
messageBody.writeShort(withdrawnRoutesBuf.writerIndex());
messageBody.writeBytes(withdrawnRoutesBuf);
} else {
messageBody.writeShort(0);
}
if (update.getAttributes() != null) {
final ByteBuf pathAttributesBuf = Unpooled.buffer();
this.attrReg.serializeAttribute(update.getAttributes(), pathAttributesBuf);
messageBody.writeShort(pathAttributesBuf.writerIndex());
messageBody.writeBytes(pathAttributesBuf);
} else {
messageBody.writeShort(0);
}
final List<Nlri> nlris = update.getNlri();
if (nlris != null) {
nlris.forEach(nlri -> writePathIdPrefix(messageBody, nlri.getPathId(), nlri.getPrefix()));
}
MessageUtil.formatMessage(TYPE, messageBody, bytes);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.mp.unreach.nlri.WithdrawnRoutes 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));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.mp.unreach.nlri.WithdrawnRoutes in project bgpcep by opendaylight.
the class MvpnIpv6NlriHandler method serializeAttribute.
@Override
public void serializeAttribute(final Attributes pathAttributes, final ByteBuf byteAggregator) {
final AttributesReach pathAttributes1 = pathAttributes.augmentation(AttributesReach.class);
final AttributesUnreach pathAttributes2 = pathAttributes.augmentation(AttributesUnreach.class);
if (pathAttributes1 != null) {
final AdvertizedRoutes routes = pathAttributes1.getMpReachNlri().getAdvertizedRoutes();
if (routes != null && routes.getDestinationType() instanceof DestinationMvpnIpv6AdvertizedCase) {
final DestinationMvpnIpv6AdvertizedCase reach = (DestinationMvpnIpv6AdvertizedCase) routes.getDestinationType();
Ipv6NlriHandler.serializeNlri(reach.getDestinationMvpn().getMvpnDestination(), byteAggregator);
}
} else if (pathAttributes2 != null) {
final WithdrawnRoutes withdrawnRoutes = pathAttributes2.getMpUnreachNlri().getWithdrawnRoutes();
if (withdrawnRoutes != null && withdrawnRoutes.getDestinationType() instanceof DestinationMvpnIpv6WithdrawnCase) {
final DestinationMvpnIpv6WithdrawnCase reach = (DestinationMvpnIpv6WithdrawnCase) withdrawnRoutes.getDestinationType();
Ipv6NlriHandler.serializeNlri(reach.getDestinationMvpn().getMvpnDestination(), byteAggregator);
}
}
}
Aggregations