use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv6NextHopCaseBuilder in project bgpcep by opendaylight.
the class NextHopParserSerializerTest method testSerializeIpv6LinkNextHopCase.
@Test
public void testSerializeIpv6LinkNextHopCase() throws BGPParsingException {
this.hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(IPV6).setLinkLocal(IPV6L).build()).build();
this.buffer.clear();
this.ipv6NextHopParserSerializer.serializeNextHop(this.hop, this.buffer);
assertArrayEquals(IPV6LB, ByteArray.readAllBytes(this.buffer));
final CNextHop parsedHop = this.ipv6NextHopParserSerializer.parseNextHop(Unpooled.wrappedBuffer(IPV6LB));
assertTrue(parsedHop instanceof Ipv6NextHopCase);
assertEquals(this.hop, parsedHop);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv6NextHopCaseBuilder in project bgpcep by opendaylight.
the class NextHopUtilTest method testSerializeNextHop.
@Test
public void testSerializeNextHop() {
CNextHop hop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(IPV4).build()).build();
final ByteBuf buffer = Unpooled.buffer();
NextHopUtil.serializeNextHop(hop, buffer);
assertArrayEquals(IPV4B, ByteArray.readAllBytes(buffer));
hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(IPV6).build()).build();
buffer.clear();
NextHopUtil.serializeNextHop(hop, buffer);
assertArrayEquals(IPV6B, ByteArray.readAllBytes(buffer));
hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(IPV6).setLinkLocal(IPV6L).build()).build();
buffer.clear();
NextHopUtil.serializeNextHop(hop, buffer);
assertArrayEquals(IPV6LB, ByteArray.readAllBytes(buffer));
buffer.clear();
hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setLinkLocal(IPV6L).build()).build();
buffer.clear();
try {
NextHopUtil.serializeNextHop(hop, buffer);
fail("Exception should happen");
} catch (final IllegalArgumentException e) {
assertEquals("Ipv6 Next Hop is missing Global address.", e.getMessage());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv6NextHopCaseBuilder in project bgpcep by opendaylight.
the class ActionsRegistryImpl method applyExportAction.
@SuppressWarnings("unchecked")
Attributes applyExportAction(final RouteEntryBaseAttributes routeEntryInfo, final BGPRouteEntryExportParameters routeEntryExportParameters, final Attributes attributes, final Actions actions) {
requireNonNull(attributes);
if (actions.getRouteDisposition() instanceof RejectRoute) {
return null;
}
Attributes attributesUpdated = attributes;
final Actions1 augmentation = actions.augmentation(Actions1.class);
if (augmentation != null && augmentation.getBgpActions() != null) {
final BgpActions bgpAction = augmentation.getBgpActions();
final SetAsPathPrepend asPrependAction = bgpAction.getSetAsPathPrepend();
final Uint32 localPrefPrependAction = bgpAction.getSetLocalPref();
final BgpOriginAttrType localOriginAction = bgpAction.getSetRouteOrigin();
final BgpSetMedType medAction = bgpAction.getSetMed();
final BgpNextHopType nhAction = bgpAction.getSetNextHop();
final SetCommunity setCommunityAction = bgpAction.getSetCommunity();
final SetExtCommunity setExtCommunityAction = bgpAction.getSetExtCommunity();
if (asPrependAction != null) {
attributesUpdated = this.bgpActions.get(SetAsPathPrepend.class).applyExportAction(routeEntryInfo, routeEntryExportParameters, attributesUpdated, asPrependAction);
}
if (attributesUpdated == null) {
return null;
}
if (setCommunityAction != null) {
attributesUpdated = this.bgpActions.get(SetCommunity.class).applyExportAction(routeEntryInfo, routeEntryExportParameters, attributesUpdated, setCommunityAction);
}
if (attributesUpdated == null) {
return null;
}
if (setExtCommunityAction != null) {
attributesUpdated = this.bgpActions.get(SetExtCommunity.class).applyExportAction(routeEntryInfo, routeEntryExportParameters, attributesUpdated, setExtCommunityAction);
}
boolean updated = false;
if (localPrefPrependAction != null || localOriginAction != null || medAction != null || nhAction != null) {
updated = true;
}
if (updated) {
final AttributesBuilder attributesUpdatedBuilder = new AttributesBuilder(attributes);
if (localPrefPrependAction != null) {
attributesUpdatedBuilder.setLocalPref(new LocalPrefBuilder().setPref(localPrefPrependAction).build());
}
if (localOriginAction != null) {
attributesUpdatedBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.forValue(localOriginAction.getIntValue())).build());
}
if (medAction != null) {
attributesUpdatedBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(medAction.getUint32()).build());
}
if (nhAction != null) {
final IpAddress address = nhAction.getIpAddress();
CNextHop nhNew;
if (address != null) {
if (address.getIpv4Address() != null) {
nhNew = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(IetfInetUtil.INSTANCE.ipv4AddressNoZoneFor(address.getIpv4Address())).build()).build();
} else {
nhNew = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(IetfInetUtil.INSTANCE.ipv6AddressNoZoneFor(address.getIpv6Address())).build()).build();
}
attributesUpdatedBuilder.setCNextHop(nhNew);
} else if (nhAction.getEnumeration() != null && BgpNextHopType.Enumeration.SELF == nhAction.getEnumeration()) {
nhNew = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(routeEntryInfo.getOriginatorId()).build()).build();
attributesUpdatedBuilder.setCNextHop(nhNew);
}
}
attributesUpdated = attributesUpdatedBuilder.build();
}
for (final Augmentation<BgpActions> action : bgpAction.augmentations().values()) {
final BgpActionAugPolicy handler = this.bgpAugActionsRegistry.get(action.implementedInterface());
if (handler == null) {
continue;
} else if (attributesUpdated == null) {
return null;
}
attributesUpdated = handler.applyExportAction(routeEntryInfo, routeEntryExportParameters, attributesUpdated, action);
}
}
if (attributesUpdated == null) {
return null;
}
// Export Actions Aug
for (final Augmentation<Actions> entry : actions.augmentations().values()) {
final ActionsAugPolicy handler = this.actionsRegistry.get(entry.implementedInterface());
if (attributesUpdated == null) {
return null;
} else if (handler == null) {
continue;
}
attributesUpdated = handler.applyExportAction(routeEntryInfo, routeEntryExportParameters, attributesUpdated, entry);
}
return attributesUpdated;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv6NextHopCaseBuilder 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.types.rev200120.next.hop.c.next.hop.Ipv6NextHopCaseBuilder in project bgpcep by opendaylight.
the class NextHopAttributeParserTest method testParseEmptyIpv6Attribute.
@Test
public void testParseEmptyIpv6Attribute() {
final NullPointerException ex = assertThrows(NullPointerException.class, () -> registry.serializeAttribute(new AttributesBuilder().setCNextHop(new Ipv6NextHopCaseBuilder().build()).build(), Unpooled.buffer()));
assertNull(ex.getMessage());
}
Aggregations