use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.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.rev171207.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.rev171207.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.rev171207.path.attributes.attributes.as.path.Segments in project bgpcep by opendaylight.
the class MatchAsPathSetHandler method matchAsPathSetCondition.
private boolean matchAsPathSetCondition(final AsPath asPath, final String asPathSetName, final MatchSetOptionsType matchSetOptions) {
if (asPath == null) {
return false;
}
final AsPathSet asPathSetFilter = this.sets.getUnchecked(StringUtils.substringBetween(asPathSetName, "=\"", "\""));
final List<Segments> segments = asPath.getSegments();
if (asPathSetFilter == null || segments == null) {
return false;
}
final List<AsNumber> l1 = segments.stream().map(AsPathSegment::getAsSequence).filter(Objects::nonNull).flatMap(Collection::stream).filter(Objects::nonNull).collect(Collectors.toList());
final List<AsNumber> l2 = segments.stream().map(AsPathSegment::getAsSet).filter(Objects::nonNull).flatMap(Collection::stream).filter(Objects::nonNull).collect(Collectors.toList());
List<AsNumber> allAs = Stream.of(l1, l2).flatMap(Collection::stream).collect(Collectors.toList());
final List<AsNumber> asPathSetFilterList = asPathSetFilter.getAsPathSetMember();
if (matchSetOptions.equals(MatchSetOptionsType.ALL)) {
return allAs.containsAll(asPathSetFilterList) && asPathSetFilterList.containsAll(allAs);
}
final boolean noneInCommon = Collections.disjoint(allAs, asPathSetFilterList);
if (matchSetOptions.equals(MatchSetOptionsType.ANY)) {
return !noneInCommon;
}
// (matchSetOptions.equals(MatchSetOptionsType.INVERT))
return noneInCommon;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.Segments in project bgpcep by opendaylight.
the class BGPMessageParserMockTest method fillMessages.
/**
* Helper method to fill messages variable.
*
* @param asn this parameter is passed to ASNumber constructor
*/
private static Update fillMessages(final long asn) {
final UpdateBuilder builder = new UpdateBuilder();
final List<Segments> asPath = Lists.newArrayList();
asPath.add(new SegmentsBuilder().setAsSequence(Lists.newArrayList(new AsNumber(asn))).build());
final CNextHop nextHop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
final Ipv6Prefix pref1 = new Ipv6Prefix("2001:db8:1:2::/64");
final Ipv6Prefix pref2 = new Ipv6Prefix("2001:db8:1:1::/64");
final Ipv6Prefix pref3 = new Ipv6Prefix("2001:db8:1::/64");
final AttributesBuilder paBuilder = new AttributesBuilder();
paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
final MpReachNlriBuilder mpReachBuilder = new MpReachNlriBuilder();
mpReachBuilder.setAfi(Ipv6AddressFamily.class);
mpReachBuilder.setSafi(UnicastSubsequentAddressFamily.class);
mpReachBuilder.setCNextHop(nextHop);
mpReachBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(Lists.newArrayList(new Ipv6PrefixesBuilder().setPrefix(pref1).build(), new Ipv6PrefixesBuilder().setPrefix(pref2).build(), new Ipv6PrefixesBuilder().setPrefix(pref3).build())).build()).build()).build());
paBuilder.addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mpReachBuilder.build()).build());
builder.setAttributes(paBuilder.build());
return builder.build();
}
Aggregations