use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.as.path.Segments in project netvirt by opendaylight.
the class NeutronUtils method getNumberSegmentsFromNeutronNetwork.
public static Long getNumberSegmentsFromNeutronNetwork(Network network) {
NetworkProviderExtension providerExtension = network.getAugmentation(NetworkProviderExtension.class);
Integer numSegs = 0;
if (providerExtension != null) {
List<Segments> providerSegments = providerExtension.getSegments();
if (providerSegments != null) {
numSegs = providerSegments.size();
}
}
return Long.valueOf(numSegs);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.as.path.Segments in project netvirt by opendaylight.
the class NeutronNetworkChangeListener method buildSegments.
@Nonnull
private List<ElanSegments> buildSegments(Network input) {
Long numSegments = NeutronUtils.getNumberSegmentsFromNeutronNetwork(input);
List<ElanSegments> segments = new ArrayList<>();
for (long index = 0L; index < numSegments; index++) {
ElanSegmentsBuilder elanSegmentsBuilder = new ElanSegmentsBuilder();
elanSegmentsBuilder.setSegmentationId(0L);
if (NeutronUtils.getSegmentationIdFromNeutronNetworkSegment(input, index) != null) {
try {
elanSegmentsBuilder.setSegmentationId(Long.valueOf(NeutronUtils.getSegmentationIdFromNeutronNetworkSegment(input, index)));
} catch (NumberFormatException error) {
LOG.error("Failed to get the segment id for network {}", input);
}
}
if (NeutronUtils.isNetworkSegmentType(input, index, NetworkTypeVxlan.class)) {
elanSegmentsBuilder.setSegmentType(SegmentTypeVxlan.class);
} else if (NeutronUtils.isNetworkSegmentType(input, index, NetworkTypeVlan.class)) {
elanSegmentsBuilder.setSegmentType(SegmentTypeVlan.class);
} else if (NeutronUtils.isNetworkSegmentType(input, index, NetworkTypeFlat.class)) {
elanSegmentsBuilder.setSegmentType(SegmentTypeFlat.class);
}
elanSegmentsBuilder.setSegmentationIndex(index);
segments.add(elanSegmentsBuilder.build());
LOG.debug("Added segment {} to ELANInstance", segments.get((int) index - 1));
}
return segments;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.as.path.Segments in project bgpcep by opendaylight.
the class AsPathPrepend method applyExportAction.
@Override
public Attributes applyExportAction(final RouteEntryBaseAttributes routeEntryInfo, final BGPRouteEntryExportParameters exportParameters, final Attributes attributes, final SetAsPathPrepend actions) {
final List<Segments> oldSegments = attributes.getAsPath().getSegments();
/*
* We need to check the first segment.
* If it has as-set then new as-sequence with local AS is prepended.
* If it has as-sequence, we may add local AS when it has less than 255 elements.
* Otherwise we need to create new as-sequence for local AS.
*/
final ArrayList<AsNumber> newAsSequence = new ArrayList<>();
newAsSequence.add(new AsNumber(routeEntryInfo.getLocalAs()));
List<Segments> newSegments = new ArrayList<>();
if (oldSegments == null || oldSegments.isEmpty()) {
newSegments = Collections.singletonList(new SegmentsBuilder().setAsSequence(newAsSequence).build());
} else {
final Segments firstSegment = oldSegments.remove(0);
final List<AsNumber> firstAsSequence = firstSegment.getAsSequence();
if (firstAsSequence != null && firstAsSequence.size() < Values.UNSIGNED_BYTE_MAX_VALUE) {
newAsSequence.addAll(firstAsSequence);
newSegments.add(new SegmentsBuilder().setAsSequence(newAsSequence).build());
} else {
newSegments.add(new SegmentsBuilder().setAsSequence(newAsSequence).build());
newSegments.add(firstSegment);
}
newSegments.addAll(oldSegments);
}
return new AttributesBuilder(attributes).setAsPath(new AsPathBuilder().setSegments(newSegments).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.as.path.Segments in project bgpcep by opendaylight.
the class AsPathAttributeParser method serializeAttribute.
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object.");
final Attributes pathAttributes = (Attributes) attribute;
final AsPath asPath = pathAttributes.getAsPath();
if (asPath == null) {
return;
}
final ByteBuf segmentsBuffer = Unpooled.buffer();
if (asPath.getSegments() != null) {
for (final Segments segments : asPath.getSegments()) {
if (segments.getAsSequence() != null) {
AsPathSegmentParser.serializeAsList(segments.getAsSequence(), SegmentType.AS_SEQUENCE, segmentsBuffer);
} else if (segments.getAsSet() != null) {
AsPathSegmentParser.serializeAsList(segments.getAsSet(), SegmentType.AS_SET, segmentsBuffer);
} else {
LOG.warn("Segment doesn't have AsSequence nor AsSet list.");
}
}
}
AttributeUtil.formatAttribute(AttributeUtil.TRANSITIVE, TYPE, segmentsBuffer, byteAggregator);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.as.path.Segments in project bgpcep by opendaylight.
the class BGPParserTest method testIPv6Nlri.
/*
* Tests IPv6 NEXT_HOP, NLRI, ORIGIN.IGP, MULTI_EXIT_DISC, ORIGINATOR-ID, CLUSTER_LIST.
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 80 <- length (128) - including header
* 02 <- message type
* 00 00 <- withdrawn routes length
* 00 69 <- total path attribute length (105)
* 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 e9 <- path segment value (65001)
* 40 <- attribute flags
* 03 <- attribute type code (next hop)
* 04 <- attribute length
* 0a 00 00 00 <- next hop value (10.0.0.0)
* 80 <- attribute flags
* 04 <- attribute type code (multi exit disc)
* 04 <- attribute length
* 00 00 00 00 <- value
* 80 <- attribute flags
* 09 <- attribute type code (originator id)
* 04 <- attribute length
* 7f 00 00 01 <- value (localhost ip)
* 80 <- attribute flags
* 0a <- attribute type code (cluster list)
* 08 <- attribute length
* 01 02 03 04 <- value
* 05 06 07 08 <- value
* 80 <- attribute flags
* 0e <- attribute type code (mp reach nlri)
* 40 <- attribute length
* 00 02 <- AFI (Ipv6)
* 01 <- SAFI (Unicast)
* 20 <- length of next hop
* 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 01 <- global
* fe 80 00 00 00 00 00 00 c0 01 0b ff fe 7e 00 <- link local
* 00 <- reserved
*
* //NLRI
* 40 20 01 0d b8 00 01 00 02 <- IPv6 Prefix (2001:db8:1:2:: / 64)
* 40 20 01 0d b8 00 01 00 01 <- IPv6 Prefix (2001:db8:1:1:: / 64)
* 40 20 01 0d b8 00 01 00 00 <- IPv6 Prefix (2001:db8:1:: / 64)
*
*/
@Test
public void testIPv6Nlri() throws Exception {
final Update message = (Update) messageRegistry.parseMessage(Unpooled.wrappedBuffer(input.get(1)), null);
// check fields
assertNull(message.getWithdrawnRoutes());
final UpdateBuilder builder = new UpdateBuilder();
// check NLRI
final List<Ipv6Prefixes> prefs = new ArrayList<>();
prefs.add(new Ipv6PrefixesBuilder().setPrefix(new Ipv6Prefix("2001:db8:1:2::/64")).build());
prefs.add(new Ipv6PrefixesBuilder().setPrefix(new Ipv6Prefix("2001:db8:1:1::/64")).build());
prefs.add(new Ipv6PrefixesBuilder().setPrefix(new Ipv6Prefix("2001:db8:1::/64")).build());
assertNull(message.getNlri());
// attributes
final List<AsNumber> asNumbers = new ArrayList<>();
asNumbers.add(new AsNumber(Uint32.valueOf(65001)));
final List<Segments> asPath = new ArrayList<>();
asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
final Ipv6NextHopCase nextHop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(new Ipv6AddressNoZone("2001:db8::1")).setLinkLocal(new Ipv6AddressNoZone("fe80::c001:bff:fe7e:0")).build()).build();
final List<ClusterIdentifier> clusters = Lists.newArrayList(new ClusterIdentifier(new Ipv4AddressNoZone("1.2.3.4")), new ClusterIdentifier(new Ipv4AddressNoZone("5.6.7.8")));
// 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.setMultiExitDisc(new MultiExitDiscBuilder().setMed(Uint32.ZERO).build());
assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
paBuilder.setOriginatorId(new OriginatorIdBuilder().setOriginator(new Ipv4AddressNoZone("127.0.0.1")).build());
assertEquals(paBuilder.getOriginatorId(), attrs.getOriginatorId());
paBuilder.setClusterId(new ClusterIdBuilder().setCluster(clusters).build());
assertEquals(paBuilder.getClusterId(), attrs.getClusterId());
final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder().setAfi(Ipv6AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setCNextHop(nextHop).setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(prefs).build()).build()).build());
paBuilder.addAugmentation(new AttributesReachBuilder().setMpReachNlri(mpBuilder.build()).build());
assertEquals(paBuilder.augmentation(AttributesReach.class).getMpReachNlri(), attrs.augmentation(AttributesReach.class).getMpReachNlri());
paBuilder.setUnrecognizedAttributes(Collections.emptyMap());
// check API message
builder.setAttributes(paBuilder.build());
assertEquals(builder.build(), message);
final ByteBuf buffer = Unpooled.buffer();
messageRegistry.serializeMessage(message, buffer);
assertArrayEquals(input.get(1), ByteArray.readAllBytes(buffer));
}
Aggregations