use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.ExtendedCommunitiesBuilder in project bgpcep by opendaylight.
the class SetExtCommunityHandler method setExtComm.
private Attributes setExtComm(final Attributes attributes, final SetExtCommunityMethod setExtCommunityMethod, final BgpSetCommunityOptionType options) {
if (setExtCommunityMethod instanceof Inline) {
final Inline inline = (Inline) setExtCommunityMethod;
final List<ExtendedCommunities> list = inline.getExtCommunityMember().stream().map(ge -> new ExtendedCommunitiesBuilder().setExtendedCommunity(ge.getExtendedCommunity()).setTransitive(ge.getTransitive()).build()).collect(Collectors.toList());
return inlineSetExtComm(attributes, list, options);
}
return referenceSetExtComm(attributes, ((Reference) setExtCommunityMethod).getExtCommunitySetRef(), options);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.ExtendedCommunitiesBuilder in project bgpcep by opendaylight.
the class MatchExtComTest method testExtComAll.
@Test
public void testExtComAll() {
Statement statement = this.basicStatements.stream().filter(st -> st.getName().equals("ext-community-all-test")).findFirst().get();
RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().build());
RouteAttributeContainer result = this.statementRegistry.applyExportStatement(this.baseAttributes, IPV4UNICAST.class, this.exportParameters, attributeContainer, statement);
assertNotNull(result.getAttributes());
attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setExtendedCommunities(Arrays.asList(new ExtendedCommunitiesBuilder().setExtendedCommunity(new As4RouteOriginExtendedCommunityCaseBuilder().setAs4RouteOriginExtendedCommunity(new As4RouteOriginExtendedCommunityBuilder().setAs4SpecificCommon(new As4SpecificCommonBuilder().setAsNumber(AsNumber.getDefaultInstance("65000")).setLocalAdministrator(Uint16.valueOf(123)).build()).build()).build()).build(), new ExtendedCommunitiesBuilder().setExtendedCommunity(new EncapsulationCaseBuilder().setEncapsulationExtendedCommunity(new EncapsulationExtendedCommunityBuilder().setTunnelType(Vxlan).build()).build()).build())).build());
result = this.statementRegistry.applyExportStatement(this.baseAttributes, IPV4UNICAST.class, this.exportParameters, attributeContainer, statement);
assertNull(result.getAttributes());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.ExtendedCommunitiesBuilder in project bgpcep by opendaylight.
the class MatchExtComTest method testExtComAny.
@Test
public void testExtComAny() {
Statement statement = this.basicStatements.stream().filter(st -> st.getName().equals("ext-community-any-test")).findFirst().get();
RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().build());
RouteAttributeContainer result = this.statementRegistry.applyExportStatement(this.baseAttributes, IPV4UNICAST.class, this.exportParameters, attributeContainer, statement);
assertNotNull(result.getAttributes());
attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setExtendedCommunities(Collections.singletonList(new ExtendedCommunitiesBuilder().setExtendedCommunity(new As4RouteOriginExtendedCommunityCaseBuilder().setAs4RouteOriginExtendedCommunity(new As4RouteOriginExtendedCommunityBuilder().setAs4SpecificCommon(new As4SpecificCommonBuilder().setAsNumber(AsNumber.getDefaultInstance("65000")).setLocalAdministrator(Uint16.valueOf(123)).build()).build()).build()).build())).build());
result = this.statementRegistry.applyExportStatement(this.baseAttributes, IPV4UNICAST.class, this.exportParameters, attributeContainer, statement);
assertNull(result.getAttributes());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.ExtendedCommunitiesBuilder in project bgpcep by opendaylight.
the class MatchExtComTest method testExtComInvert.
@Test
public void testExtComInvert() {
Statement statement = this.basicStatements.stream().filter(st -> st.getName().equals("ext-community-invert-test")).findFirst().get();
RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().build());
RouteAttributeContainer result = this.statementRegistry.applyExportStatement(this.baseAttributes, IPV4UNICAST.class, this.exportParameters, attributeContainer, statement);
assertNull(result.getAttributes());
attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setExtendedCommunities(Collections.singletonList(new ExtendedCommunitiesBuilder().setExtendedCommunity(new As4RouteOriginExtendedCommunityCaseBuilder().setAs4RouteOriginExtendedCommunity(new As4RouteOriginExtendedCommunityBuilder().setAs4SpecificCommon(new As4SpecificCommonBuilder().setAsNumber(AsNumber.getDefaultInstance("65000")).setLocalAdministrator(Uint16.valueOf(123)).build()).build()).build()).build())).build());
result = this.statementRegistry.applyExportStatement(this.baseAttributes, IPV4UNICAST.class, this.exportParameters, attributeContainer, statement);
assertNotNull(result.getAttributes());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.ExtendedCommunitiesBuilder in project bgpcep by opendaylight.
the class BGPParserTest method testGetUpdateMessage4.
/*
* Tests empty AS_PATH, ORIGIN.EGP, LOCAL_PREF, EXTENDED_COMMUNITIES (Ipv4 Addr specific)
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 4A <- length (73) - including header
* 02 <- message type
* 00 00 <- withdrawn routes length
* 00 27 <- total path attribute length (39)
* 40 <- attribute flags
* 01 <- attribute type code (Origin)
* 01 <- attribute length
* 01 <- Origin value (EGP)
* 40 <- attribute flags
* 02 <- attribute type code (As path)
* 00 <- attribute length
* 40 <- attribute flags
* 03 <- attribute type (Next hop)
* 04 <- attribute length
* 03 03 03 03 <- value (3.3.3.3)
* 80 <- attribute flags
* 04 <- attribute type code (Multi exit disc)
* 04 <- attribute length
* 00 00 00 00 <- value
* 40 <- attribute flags
* 05 <- attribute type (Local Pref)
* 04 <- attribute length
* 00 00 00 64 <- value (100)
* c0 <- attribute flags
* 10 <- attribute type (extended community)
* 08 <- attribute length
* 01 04 <- value (type - Ipv4 Address Specific Extended Community)
* c0 a8 01 00 <- value (global adm. 198.162.1.0)
* 12 34 <- value (local adm. 4660)
*
* //NLRI
* 18 0a 1e 03 <- IPv4 Prefix (10.30.3.0 / 24)
* 18 0a 1e 02 <- IPv4 Prefix (10.30.2.0 / 24)
* 18 0a 1e 01 <- IPv4 Prefix (10.30.1.0 / 24)
*/
@Test
public void testGetUpdateMessage4() throws Exception {
final byte[] body = ByteArray.cutBytes(INPUT_BYTES.get(3), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(INPUT_BYTES.get(3), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, null);
final UpdateBuilder builder = new UpdateBuilder();
// check fields
assertNull(message.getWithdrawnRoutes());
// check nlri
final List<Nlri> nlris = new ArrayList<>();
nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("10.30.3.0/24")).build());
nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("10.30.2.0/24")).build());
nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("10.30.1.0/24")).build());
assertEquals(nlris, message.getNlri());
builder.setNlri(nlris);
// attributes
final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4AddressNoZone("3.3.3.3")).build()).build();
final List<ExtendedCommunities> comms = new ArrayList<>();
comms.add(new ExtendedCommunitiesBuilder().setTransitive(true).setExtendedCommunity(new RouteTargetIpv4CaseBuilder().setRouteTargetIpv4(new RouteTargetIpv4Builder().setGlobalAdministrator(new Ipv4AddressNoZone("192.168.1.0")).setLocalAdministrator(Uint16.valueOf(4660)).build()).build()).build());
// check path attributes
final Attributes attrs = message.getAttributes();
final AttributesBuilder paBuilder = new AttributesBuilder();
paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
paBuilder.setAsPath(new AsPathBuilder().setSegments(List.of()).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.setLocalPref(new LocalPrefBuilder().setPref(Uint32.valueOf(100)).build());
assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
paBuilder.setExtendedCommunities(comms);
assertEquals(paBuilder.getExtendedCommunities(), attrs.getExtendedCommunities());
paBuilder.setUnrecognizedAttributes(Map.of());
// check API message
builder.setAttributes(paBuilder.build());
assertEquals(builder.build(), message);
final ByteBuf buffer = Unpooled.buffer();
BGPParserTest.updateParser.serializeMessage(message, buffer);
assertArrayEquals(INPUT_BYTES.get(3), ByteArray.readAllBytes(buffer));
}
Aggregations