Search in sources :

Example 1 with 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 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);
}
Also used : Segments(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.neutron.networks.network.Segments) NetworkProviderExtension(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtension)

Example 2 with 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 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;
}
Also used : SegmentTypeVlan(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.SegmentTypeVlan) ElanSegments(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.elan.instance.ElanSegments) ElanSegmentsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.elan.instance.ElanSegmentsBuilder) ArrayList(java.util.ArrayList) NetworkTypeVlan(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.NetworkTypeVlan) Nonnull(javax.annotation.Nonnull)

Example 3 with 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();
}
Also used : AsPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder) SegmentsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.SegmentsBuilder) ArrayList(java.util.ArrayList) Segments(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.Segments) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder)

Example 4 with 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 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;
}
Also used : AsPathSet(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.defined.sets.bgp.defined.sets.as.path.sets.AsPathSet) MatchAsPathSet(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.bgp.match.conditions.MatchAsPathSet) Segments(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.Segments) Collection(java.util.Collection) AsPathSegment(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AsPathSegment) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)

Example 5 with 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 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();
}
Also used : DestinationIpv6Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv6.prefixes.DestinationIpv6Builder) MpReachNlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlriBuilder) Ipv6NextHopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder) OriginBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.OriginBuilder) DestinationIpv6CaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6CaseBuilder) Segments(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.Segments) UpdateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.UpdateBuilder) CNextHop(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) Ipv6Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix) AdvertizedRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder) Attributes1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1Builder) AsPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder) Ipv6PrefixesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv6.prefixes.destination.ipv6.Ipv6PrefixesBuilder) SegmentsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.SegmentsBuilder) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder) Ipv6Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address) Ipv6NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCaseBuilder)

Aggregations

Segments (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.Segments)11 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)9 AsPathBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder)8 SegmentsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.SegmentsBuilder)8 ArrayList (java.util.ArrayList)7 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder)7 OriginBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.OriginBuilder)6 ByteBuf (io.netty.buffer.ByteBuf)5 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)5 UpdateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.UpdateBuilder)5 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes)5 MultiExitDiscBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.MultiExitDiscBuilder)5 Test (org.junit.Test)4 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update)4 Ipv4NextHopCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder)4 Ipv4NextHopBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder)4 PeerSpecificParserConstraint (org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)3 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)3 NetworkProviderExtension (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtension)3 Segments (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.neutron.networks.network.Segments)3