use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.mp.unreach.nlri.WithdrawnRoutesBuilder 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(INPUT_BYTES.get(4), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(INPUT_BYTES.get(4), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, null);
// attributes
final List<WithdrawnRoutes> withdrawnRoutes = List.of(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(INPUT_BYTES.get(4), ByteArray.readAllBytes(buffer));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.mp.unreach.nlri.WithdrawnRoutesBuilder in project bgpcep by opendaylight.
the class SimpleNlriRegistry method convertMpReachToMpUnReach.
@Override
public Optional<MpUnreachNlri> convertMpReachToMpUnReach(final MpReachNlri mpReachNlri, final MpUnreachNlri mpUnreachNlri) {
if (mpUnreachNlri == null) {
return Optional.of(new MpUnreachNlriBuilder().setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(mpReachNlri.getAdvertizedRoutes().getDestinationType()).build()).build());
}
final BgpTableType key = createKey(mpUnreachNlri.getAfi(), mpUnreachNlri.getSafi());
final NlriParser parser = this.handlers.get(key);
if (parser == null) {
LOG.debug("Parser for {} not found", key);
return Optional.empty();
}
final MpUnreachNlriBuilder builder = new MpUnreachNlriBuilder(mpUnreachNlri);
return parser.convertMpReachToMpUnReach(mpReachNlri, builder) ? Optional.of(builder.build()) : Optional.empty();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.mp.unreach.nlri.WithdrawnRoutesBuilder in project bgpcep by opendaylight.
the class AbstractAddPathTest method createSimpleWithdrawalUpdate.
private static Update createSimpleWithdrawalUpdate(final Ipv4Prefix prefix, final long localPreference) {
final AttributesBuilder attBuilder = new AttributesBuilder();
attBuilder.setLocalPref(new LocalPrefBuilder().setPref(Uint32.valueOf(localPreference)).build());
attBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
attBuilder.setUnrecognizedAttributes(Collections.emptyMap());
return new UpdateBuilder().setWithdrawnRoutes(Collections.singletonList(new WithdrawnRoutesBuilder().setPrefix(prefix).build())).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.mp.unreach.nlri.WithdrawnRoutesBuilder in project bgpcep by opendaylight.
the class TestUtil method createWithdrawnRoutes.
private static List<WithdrawnRoutes> createWithdrawnRoutes() {
final WithdrawnRoutes w1 = new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("10.10.20.0/24")).build();
final WithdrawnRoutes w2 = new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("20.20.10.0/24")).build();
final WithdrawnRoutes w3 = new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("30.10.10.0/24")).build();
return Lists.newArrayList(w1, w2, w3);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.mp.unreach.nlri.WithdrawnRoutesBuilder in project bgpcep by opendaylight.
the class MultiPathAbstractRIBSupportTest method buildUpdate.
@Test
public void buildUpdate() {
final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
final Attributes attr = new AttributesBuilder().setCNextHop(nextHop).build();
final Collection<MapEntryNode> routes = new HashSet<>();
assertEquals(new UpdateBuilder().setAttributes(new AttributesBuilder().build()).build(), MULTI_PATH_ABSTRACT_TEST.buildUpdate(routes, routes, attr));
routes.add(this.mapEntryNode);
final MpReachNlri mpReach = new MpReachNlriBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setCNextHop(nextHop).setAdvertizedRoutes(new AdvertizedRoutesBuilder().build()).build();
final Attributes attMpR = new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mpReach).build()).build();
assertEquals(new UpdateBuilder().setAttributes(attMpR).build(), MULTI_PATH_ABSTRACT_TEST.buildUpdate(routes, Collections.emptySet(), attr));
final MpUnreachNlri mpUnreach = new MpUnreachNlriBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setWithdrawnRoutes(new WithdrawnRoutesBuilder().build()).build();
final Attributes attMpU = new AttributesBuilder().addAugmentation(Attributes2.class, new Attributes2Builder().setMpUnreachNlri(mpUnreach).build()).build();
assertEquals(new UpdateBuilder().setAttributes(attMpU).build(), MULTI_PATH_ABSTRACT_TEST.buildUpdate(Collections.emptySet(), routes, attr));
}
Aggregations