use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route in project bgpcep by opendaylight.
the class AbstractFlowspecNlriParser method extractFlowspec.
public final List<Flowspec> extractFlowspec(final DataContainerNode<?> route) {
requireNonNull(route, "Cannot extract flowspec from null route.");
final List<Flowspec> fsList = new ArrayList<>();
final Optional<DataContainerChild<? extends PathArgument, ?>> flowspecs = route.getChild(FLOWSPEC_NID);
if (flowspecs.isPresent()) {
for (final UnkeyedListEntryNode flowspec : ((UnkeyedListNode) flowspecs.get()).getValue()) {
final FlowspecBuilder fsBuilder = new FlowspecBuilder();
final Optional<DataContainerChild<?, ?>> flowspecType = flowspec.getChild(FLOWSPEC_TYPE_NID);
if (flowspecType.isPresent()) {
final ChoiceNode fsType = (ChoiceNode) flowspecType.get();
processFlowspecType(fsType, fsBuilder);
}
fsList.add(fsBuilder.build());
}
}
return fsList;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route in project bgpcep by opendaylight.
the class BGPRouteRefreshMessageParser method serializeMessage.
/**
* Serializes BGP Route Refresh message.
*
* @param message to be serialized
* @param bytes ByteBuf where the message will be serialized
*/
@Override
public void serializeMessage(final Notification message, final ByteBuf bytes) {
Preconditions.checkArgument(message instanceof RouteRefresh, "Message is not of type RouteRefresh.");
final RouteRefresh msg = (RouteRefresh) message;
final ByteBuf msgBuf = Unpooled.buffer(TRIPLET_BYTE_SIZE);
MultiprotocolCapabilitiesUtil.serializeMPAfiSafi(this.afiReg, this.safiReg, msg.getAfi(), msg.getSafi(), msgBuf);
LOG.trace("RouteRefresh message serialized to: {}", ByteBufUtil.hexDump(msgBuf));
MessageUtil.formatMessage(TYPE, msgBuf, bytes);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route in project bgpcep by opendaylight.
the class BGPParserTest method testGetUpdateMessage5.
/*
* Tests withdrawn routes.
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 1c <- length (28) - including header
* 02 <- message type
* 00 05 <- withdrawn routes length (5)
* 1e ac 10 00 04 <- route (172.16.0.4)
* 00 00 <- total path attribute length
*/
@Test
public void testGetUpdateMessage5() throws Exception {
final byte[] body = ByteArray.cutBytes(inputBytes.get(4), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(4), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
// attributes
final List<WithdrawnRoutes> withdrawnRoutes = Lists.newArrayList(new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("172.16.0.4/30")).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(inputBytes.get(4), ByteArray.readAllBytes(buffer));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route in project bgpcep by opendaylight.
the class AggregatorAttributeParser 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 Aggregator aggregator = pathAttributes.getAggregator();
if (aggregator == null) {
return;
}
Preconditions.checkArgument(aggregator.getAsNumber() != null, "Missing AS number that formed the aggregate route (encoded as 2 octets).");
final ShortAsNumber shortAsNumber = new ShortAsNumber(aggregator.getAsNumber());
final ByteBuf buffer = Unpooled.buffer();
buffer.writeInt(shortAsNumber.getValue().intValue());
buffer.writeBytes(Ipv4Util.bytesForAddress(aggregator.getNetworkAddress()));
AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL | AttributeUtil.TRANSITIVE, TYPE, buffer, byteAggregator);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route in project bgpcep by opendaylight.
the class FlowspecL3vpnIpv6RIBSupportTest method testBuildMpReachNlriUpdate.
@Test
public void testBuildMpReachNlriUpdate() {
final Update update = RIB_SUPPORT.buildUpdate(createRoutes(new FlowspecL3vpnIpv6RoutesBuilder().setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build()), Collections.emptyList(), ATTRIBUTES);
final AdvertizedRoutes advertised = update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri().getAdvertizedRoutes();
assertEquals(REACH_NLRI, advertised.getDestinationType());
assertNull(update.getAttributes().getAugmentation(Attributes2.class));
}
Aggregations