use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlriBuilder in project bgpcep by opendaylight.
the class LinkstateNlriParserTest method setUp.
private void setUp(final byte[] data) throws BGPParsingException {
final LinkstateNlriParser parser = new LinkstateNlriParser();
final MpReachNlriBuilder builder = new MpReachNlriBuilder();
this.registry = SimpleNlriTypeRegistry.getInstance();
final BGPActivator act = new BGPActivator(new SimpleRSVPExtensionProviderContext());
final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
act.start(context);
parser.parseNlri(Unpooled.copiedBuffer(data), builder, null);
final DestinationLinkstate ls = ((DestinationLinkstateCase) builder.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate();
assertEquals(1, ls.getCLinkstateDestination().size());
this.dest = ls.getCLinkstateDestination().get(0);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlriBuilder in project bgpcep by opendaylight.
the class LinkstateNlriParserTest method testSerializeAttribute.
@Test
public void testSerializeAttribute() throws BGPParsingException {
final LinkstateNlriParser parser = new LinkstateNlriParser();
setUp(this.prefixNlri);
final List<CLinkstateDestination> dests = Lists.newArrayList(this.dest);
final DestinationLinkstateCase dlc = new DestinationLinkstateCaseBuilder().setDestinationLinkstate(new DestinationLinkstateBuilder().setCLinkstateDestination(dests).build()).build();
final AdvertizedRoutes aroutes = new AdvertizedRoutesBuilder().setDestinationType(dlc).build();
Attributes pa = new AttributesBuilder().addAugmentation(new AttributesReachBuilder().setMpReachNlri(new MpReachNlriBuilder().setAdvertizedRoutes(aroutes).build()).build()).build();
ByteBuf result = Unpooled.buffer();
parser.serializeAttribute(pa, result);
assertArrayEquals(this.prefixNlri, ByteArray.getAllBytes(result));
setUp(this.nodeNlri);
final List<CLinkstateDestination> destsU = Lists.newArrayList(this.dest);
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase dlcU = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(destsU).build()).build();
final WithdrawnRoutes wroutes = new WithdrawnRoutesBuilder().setDestinationType(dlcU).build();
pa = new AttributesBuilder().addAugmentation(new AttributesUnreachBuilder().setMpUnreachNlri(new MpUnreachNlriBuilder().setWithdrawnRoutes(wroutes).build()).build()).build();
result = Unpooled.buffer();
parser.serializeAttribute(pa, result);
assertArrayEquals(this.nodeNlri, ByteArray.getAllBytes(result));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlriBuilder in project bgpcep by opendaylight.
the class LinkstateNlriParser method parseNlri.
@Override
public void parseNlri(final ByteBuf nlri, final MpReachNlriBuilder builder, final PeerSpecificParserConstraint constraint) throws BGPParsingException {
if (!nlri.isReadable()) {
return;
}
final List<CLinkstateDestination> dst = parseNlri(nlri);
builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationLinkstateCaseBuilder().setDestinationLinkstate(new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build()).build()).build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlriBuilder in project bgpcep by opendaylight.
the class PeerUtil method createMpReachNlri.
static MpReachNlri createMpReachNlri(final IpAddressNoZone nextHop, final List<IpPrefix> prefixes) {
final Class<? extends AddressFamily> afi;
final CNextHop cNextHop;
final DestinationType destinationType;
if (nextHop.getIpv4AddressNoZone() != null) {
afi = Ipv4AddressFamily.class;
cNextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(nextHop.getIpv4AddressNoZone()).build()).build();
destinationType = new DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder().setIpv4Prefixes(prefixes.stream().map(prefix -> new Ipv4PrefixesBuilder().setPathId(PathIdUtil.NON_PATH_ID).setPrefix(new Ipv4Prefix(prefix.getIpv4Prefix())).build()).collect(Collectors.toList())).build()).build();
} else {
afi = Ipv6AddressFamily.class;
cNextHop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(nextHop.getIpv6AddressNoZone()).build()).build();
destinationType = new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(prefixes.stream().map(prefix -> new Ipv6PrefixesBuilder().setPathId(PathIdUtil.NON_PATH_ID).setPrefix(new Ipv6Prefix(prefix.getIpv6Prefix())).build()).collect(Collectors.toList())).build()).build();
}
return new MpReachNlriBuilder().setCNextHop(cNextHop).setAfi(afi).setSafi(UnicastSubsequentAddressFamily.class).setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(destinationType).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlriBuilder in project bgpcep by opendaylight.
the class AbstractAddPathTest method addAttributeAugmentation.
private static void addAttributeAugmentation(final AttributesBuilder attBuilder, final Ipv4Prefix prefix, final PathId pathId) {
attBuilder.setUnrecognizedAttributes(Collections.emptyMap());
attBuilder.addAugmentation(new AttributesReachBuilder().setMpReachNlri(new MpReachNlriBuilder().setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(NH1).build()).build()).setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder().setIpv4Prefixes(Collections.singletonList(new Ipv4PrefixesBuilder().setPathId(pathId).setPrefix(new Ipv4Prefix(prefix)).build())).build()).build()).build()).build()).build());
}
Aggregations