use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.MultiExitDiscBuilder in project bgpcep by opendaylight.
the class AppendActionTest method testAppend.
@Test
public void testAppend() {
Statement statement = this.basicStatements.stream().filter(st -> st.getName().equals("multiple-append-test")).findFirst().get();
final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().build());
RouteAttributeContainer result = this.statementRegistry.applyExportStatement(this.baseAttributes, this.exportParameters, attributeContainer, statement);
final Attributes expected = new AttributesBuilder().setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build()).setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("4.5.6.7")).build()).build()).setLocalPref(new LocalPrefBuilder().setPref(100L).build()).setMultiExitDisc(new MultiExitDiscBuilder().setMed(15L).build()).build();
assertEquals(expected, result.getAttributes());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.MultiExitDiscBuilder 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.message.rev200120.path.attributes.attributes.MultiExitDiscBuilder in project bgpcep by opendaylight.
the class AppendActionTest method testMultipleAppend.
@Test
public void testMultipleAppend() {
Statement statement = this.basicStatements.stream().filter(st -> st.getName().equals("multiple-append-test")).findFirst().get();
final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().build());
RouteAttributeContainer result = this.statementRegistry.applyExportStatement(this.baseAttributes, IPV4UNICAST.class, this.exportParameters, attributeContainer, statement);
final Attributes expected = new AttributesBuilder().setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build()).setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4AddressNoZone("4.5.6.7")).build()).build()).setLocalPref(new LocalPrefBuilder().setPref(Uint32.valueOf(100)).build()).setMultiExitDisc(new MultiExitDiscBuilder().setMed(Uint32.valueOf(15)).build()).build();
assertEquals(expected, result.getAttributes());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.MultiExitDiscBuilder in project bgpcep by opendaylight.
the class BGPParserTest method testGetUpdateMessage3.
/*
* Tests more AS Numbers in AS_PATH, AGGREGATOR, ORIGIN.INCOMPLETE
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 4b <- length (75) - including header
* 02 <- message type
* 00 00 <- withdrawn routes length
* 00 30 <- total path attribute length (48)
* 40 <- attribute flags
* 01 <- attribute type code (origin)
* 01 <- attribute length
* 02 <- Origin value (Incomplete)
* 40 <- attribute flags
* 02 <- attribute type code (as path)
* 10 <- attribute length
* 02 <- AS_SEQUENCE
* 01 <- path segment count
* 00 00 00 1e <- path segment value (30)
* 01 <- AS_SET
* 02 <- path segment count
* 00 00 00 0a <- path segment value (10)
* 00 00 00 14 <- path segment value (20)
* 40 <- attribute flags
* 03 <- attribute type (Next hop)
* 04 <- attribute length
* 0a 00 00 09 <- value (10.0.0.9)
* 80 <- attribute flags
* 04 <- attribute type code (multi exit disc)
* 04 <- attribute length
* 00 00 00 00 <- value
* c0 <- attribute flags
* 07 <- attribute type (Aggregator)
* 08 <- attribute length
* 00 00 00 1e <- value (AS number = 30)
* 0a 00 00 09 <- value (IP address = 10.0.0.9)
*
* //NLRI
* 15 ac 10 00 <- IPv4 Prefix (172.16.0.0 / 21)
*/
@Test
public void testGetUpdateMessage3() throws Exception {
final byte[] body = ByteArray.cutBytes(INPUT_BYTES.get(2), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(INPUT_BYTES.get(2), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, null);
final UpdateBuilder builder = new UpdateBuilder();
// check nlri
final List<Nlri> nlris = List.of(new NlriBuilder().setPrefix(new Ipv4Prefix("172.16.0.0/21")).build());
builder.setNlri(nlris);
assertEquals(builder.getNlri(), message.getNlri());
// check fields
assertNull(message.getWithdrawnRoutes());
// attributes
final List<AsNumber> asNumbers = new ArrayList<>();
asNumbers.add(new AsNumber(Uint32.valueOf(30)));
final List<Segments> asPath = new ArrayList<>();
asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
final List<AsNumber> asSet = List.of(new AsNumber(Uint32.TEN), new AsNumber(Uint32.valueOf(20)));
asPath.add(new SegmentsBuilder().setAsSet(asSet).build());
final Aggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber(Uint32.valueOf(30))).setNetworkAddress(new Ipv4AddressNoZone("10.0.0.9")).build();
final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4AddressNoZone("10.0.0.9")).build()).build();
// check path attributes
final Attributes attrs = message.getAttributes();
final AttributesBuilder paBuilder = new AttributesBuilder();
paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Incomplete).build());
assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
paBuilder.setCNextHop(nextHop);
assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(Uint32.ZERO).build());
assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
paBuilder.setAggregator(aggregator);
assertEquals(paBuilder.getAggregator(), attrs.getAggregator());
paBuilder.setUnrecognizedAttributes(Map.of());
builder.setAttributes(paBuilder.build());
assertEquals(builder.build(), message);
final ByteBuf buffer = Unpooled.buffer();
BGPParserTest.updateParser.serializeMessage(message, buffer);
assertArrayEquals(INPUT_BYTES.get(2), ByteArray.readAllBytes(buffer));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.MultiExitDiscBuilder in project bgpcep by opendaylight.
the class BGPParserTest method testUpdateMessageNlriAddPath.
/*
* Tests IPv4 NEXT_HOP, ATOMIC_AGGREGATE, COMMUNITY, NLRI with multiple paths.
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 60 <- length (96) - including header
* 02 <- message type
* 00 00 <- withdrawn routes length
* 00 31 <- total path attribute length (49)
* 40 <- attribute flags
* 01 <- attribute type code (origin)
* 01 <- attribute length
* 00 <- Origin value (IGP)
* 40 <- attribute flags
* 02 <- attribute type code (as path)
* 06 <- attribute length
* 02 <- AS_SEQUENCE
* 01 <- path segment count
* 00 00 fd ea <- path segment value (65002)
* 40 <- attribute flags
* 03 <- attribute type code (Next Hop)
* 04 <- attribute length
* 0a 00 00 02 <- value (10.0.0.2)
* 80 <- attribute flags
* 04 <- attribute type code (multi exit disc)
* 04 <- attribute length
* 00 00 00 00 <- value
* 40 <- attribute flags
* 06 <- attribute type code (atomic aggregate)
* 00 <- attribute length
* C0 <- attribute flags
* 08 <- attribute type code (community)
* 10 <- attribute length
* FF FF FF 01 <- value (NO_EXPORT)
* FF FF FF 02 <- value (NO_ADVERTISE)
* FF FF FF 03 <- value (NO_EXPORT_SUBCONFED)
* FF FF FF 10 <- unknown Community
*
* //NLRI
* 00 00 00 01 <- path-id (1)
* 18 ac 11 02 <- IPv4 Prefix (172.17.1.0 / 24)
* 00 00 00 01 <- path-id (2)
* 18 ac 11 01 <- IPv4 Prefix (172.17.1.0 / 24)
* 00 00 00 01 <- path-id (1)
* 18 ac 11 00 <- IPv4 Prefix (172.17.0.0 / 24)
*/
@Test
public void testUpdateMessageNlriAddPath() throws Exception {
final byte[] body = ByteArray.cutBytes(updatesWithMultiplePath.get(0), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(updatesWithMultiplePath.get(0), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, mpConstraint);
// check fields
assertNull(message.getWithdrawnRoutes());
// attributes
final List<AsNumber> asNumbers = new ArrayList<>();
asNumbers.add(new AsNumber(Uint32.valueOf(65002)));
final List<Segments> asPath = new ArrayList<>();
asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4AddressNoZone("10.0.0.2")).build()).build();
final List<Communities> comms = new ArrayList<>();
comms.add((Communities) CommunityUtil.NO_EXPORT);
comms.add((Communities) CommunityUtil.NO_ADVERTISE);
comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
comms.add((Communities) CommunityUtil.create(NoopReferenceCache.getInstance(), 0xFFFF, 0xFF10));
final UpdateBuilder builder = new UpdateBuilder();
// check nlri
final List<Nlri> nlris = new ArrayList<>();
nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("172.17.1.0/24")).setPathId(new PathId(Uint32.ONE)).build());
nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("172.17.1.0/24")).setPathId(new PathId(Uint32.TWO)).build());
nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("172.17.0.0/24")).setPathId(new PathId(Uint32.ONE)).build());
assertEquals(nlris, message.getNlri());
builder.setNlri(nlris);
// check path attributes
final Attributes attrs = message.getAttributes();
final AttributesBuilder paBuilder = new AttributesBuilder();
paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
paBuilder.setCNextHop(nextHop);
assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(Uint32.ZERO).build());
assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
paBuilder.setAtomicAggregate(new AtomicAggregateBuilder().build());
assertEquals(paBuilder.getAtomicAggregate(), attrs.getAtomicAggregate());
paBuilder.setCommunities(comms);
assertEquals(paBuilder.getCommunities(), attrs.getCommunities());
paBuilder.setUnrecognizedAttributes(Map.of());
builder.setAttributes(paBuilder.build());
assertEquals(builder.build(), message);
final ByteBuf buffer = Unpooled.buffer();
BGPParserTest.updateParser.serializeMessage(message, buffer);
assertArrayEquals(updatesWithMultiplePath.get(0), ByteArray.readAllBytes(buffer));
}
Aggregations