Search in sources :

Example 6 with Attributes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes 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 7 with Attributes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes in project bgpcep by opendaylight.

the class BgpConditionsRegistry method matchExportCondition.

@SuppressWarnings("unchecked")
private boolean matchExportCondition(final RouteEntryBaseAttributes routeEntryInfo, final BGPRouteEntryExportParameters routeEntryExportParameters, final Attributes attributes, final BgpConditions conditions) {
    if (!matchAsPathLength(attributes.getAsPath(), conditions.getAsPathLength())) {
        return false;
    }
    if (!matchMED(attributes.getMultiExitDisc(), conditions.getMedEq())) {
        return false;
    }
    if (!matchOrigin(attributes.getOrigin(), conditions.getOriginEq())) {
        return false;
    }
    if (!matchNextHopIn(attributes.getCNextHop(), conditions.getNextHopIn())) {
        return false;
    }
    if (!matchLocalPref(attributes.getLocalPref(), conditions.getLocalPrefEq())) {
        return false;
    }
    final MatchCommunitySet matchCond = conditions.getMatchCommunitySet();
    if (matchCond != null) {
        final BgpConditionsPolicy handler = this.bgpConditionsRegistry.get(MatchCommunitySet.class);
        if (!handler.matchExportCondition(routeEntryInfo, routeEntryExportParameters, handler.getConditionParameter(attributes), matchCond)) {
            return false;
        }
    }
    final MatchAsPathSet matchAsPathSet = conditions.getMatchAsPathSet();
    if (matchAsPathSet != null) {
        final BgpConditionsPolicy handler = this.bgpConditionsRegistry.get(MatchAsPathSet.class);
        if (!handler.matchExportCondition(routeEntryInfo, routeEntryExportParameters, handler.getConditionParameter(attributes), matchAsPathSet)) {
            return false;
        }
    }
    final MatchExtCommunitySet matchExtCommSet = conditions.getMatchExtCommunitySet();
    if (matchExtCommSet != null) {
        final BgpConditionsPolicy handler = this.bgpConditionsRegistry.get(MatchExtCommunitySet.class);
        if (!handler.matchExportCondition(routeEntryInfo, routeEntryExportParameters, handler.getConditionParameter(attributes), matchExtCommSet)) {
            return false;
        }
    }
    return true;
}
Also used : BgpConditionsPolicy(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.condition.BgpConditionsPolicy) MatchAsPathSet(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.bgp.match.conditions.MatchAsPathSet) MatchExtCommunitySet(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.bgp.match.conditions.MatchExtCommunitySet) MatchCommunitySet(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.bgp.match.conditions.MatchCommunitySet)

Example 8 with Attributes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes in project bgpcep by opendaylight.

the class BgpConditionsRegistry method matchImportCondition.

@SuppressWarnings("unchecked")
private boolean matchImportCondition(final RouteEntryBaseAttributes routeEntryInfo, final BGPRouteEntryImportParameters routeEntryImportParameters, final Attributes attributes, final BgpConditions conditions) {
    if (!matchAsPathLength(attributes.getAsPath(), conditions.getAsPathLength())) {
        return false;
    }
    if (!matchMED(attributes.getMultiExitDisc(), conditions.getMedEq())) {
        return false;
    }
    if (!matchOrigin(attributes.getOrigin(), conditions.getOriginEq())) {
        return false;
    }
    if (!matchNextHopIn(attributes.getCNextHop(), conditions.getNextHopIn())) {
        return false;
    }
    if (!matchLocalPref(attributes.getLocalPref(), conditions.getLocalPrefEq())) {
        return false;
    }
    final MatchCommunitySet matchCond = conditions.getMatchCommunitySet();
    if (matchCond != null) {
        final BgpConditionsPolicy handler = this.bgpConditionsRegistry.get(MatchCommunitySet.class);
        if (!handler.matchImportCondition(routeEntryInfo, routeEntryImportParameters, handler.getConditionParameter(attributes), matchCond)) {
            return false;
        }
    }
    final MatchAsPathSet matchAsPathSet = conditions.getMatchAsPathSet();
    if (matchCond != null) {
        final BgpConditionsPolicy handler = this.bgpConditionsRegistry.get(MatchAsPathSet.class);
        if (!handler.matchImportCondition(routeEntryInfo, routeEntryImportParameters, handler.getConditionParameter(attributes), matchAsPathSet)) {
            return false;
        }
    }
    final MatchExtCommunitySet matchExtCommSet = conditions.getMatchExtCommunitySet();
    if (matchExtCommSet != null) {
        final BgpConditionsPolicy handler = this.bgpConditionsRegistry.get(MatchAsPathSet.class);
        if (!handler.matchImportCondition(routeEntryInfo, routeEntryImportParameters, handler.getConditionParameter(attributes), matchExtCommSet)) {
            return false;
        }
    }
    return true;
}
Also used : BgpConditionsPolicy(org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.condition.BgpConditionsPolicy) MatchAsPathSet(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.bgp.match.conditions.MatchAsPathSet) MatchExtCommunitySet(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.bgp.match.conditions.MatchExtCommunitySet) MatchCommunitySet(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.bgp.match.conditions.MatchCommunitySet)

Example 9 with Attributes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes in project bgpcep by opendaylight.

the class PrefixesBuilder method createAttributes.

private static Attributes createAttributes(final List<String> extCom, final boolean multiPathSupport, final Ipv4Prefix addressPrefix) {
    final AttributesBuilder attBuilder = new AttributesBuilder();
    attBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
    attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
    attBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
    attBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
    attBuilder.setExtendedCommunities(createExtComm(extCom));
    attBuilder.setUnrecognizedAttributes(Collections.emptyList());
    final Ipv4PrefixesBuilder prefixes = new Ipv4PrefixesBuilder().setPrefix(addressPrefix);
    if (multiPathSupport) {
        prefixes.setPathId(new PathId(5L));
    }
    attBuilder.addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(new MpReachNlriBuilder().setCNextHop(NEXT_HOP).setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder().setIpv4Prefixes(Collections.singletonList(prefixes.build())).build()).build()).build()).build()).build());
    return attBuilder.build();
}
Also used : LocalPrefBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.LocalPrefBuilder) MpReachNlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlriBuilder) OriginBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.OriginBuilder) MultiExitDiscBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.MultiExitDiscBuilder) DestinationIpv4Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.prefixes.DestinationIpv4Builder) PathId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.PathId) Attributes1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1Builder) AdvertizedRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder) AsPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder) Ipv4PrefixesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.prefixes.destination.ipv4.Ipv4PrefixesBuilder) DestinationIpv4CaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4CaseBuilder) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder) UnicastSubsequentAddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily)

Example 10 with Attributes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes in project genius by opendaylight.

the class OvsInterfaceStateUpdateHelper method updateState.

public List<ListenableFuture<Void>> updateState(String interfaceName, FlowCapableNodeConnector flowCapableNodeConnectorNew, FlowCapableNodeConnector flowCapableNodeConnectorOld) {
    LOG.debug("Updating interface state information for interface: {}", interfaceName);
    Interface.OperStatus operStatusNew = InterfaceManagerCommonUtils.getOpState(flowCapableNodeConnectorNew);
    MacAddress macAddressNew = flowCapableNodeConnectorNew.getHardwareAddress();
    Interface.OperStatus operStatusOld = InterfaceManagerCommonUtils.getOpState(flowCapableNodeConnectorOld);
    MacAddress macAddressOld = flowCapableNodeConnectorOld.getHardwareAddress();
    boolean opstateModified = !operStatusNew.equals(operStatusOld);
    boolean hardwareAddressModified = !macAddressNew.equals(macAddressOld);
    if (!opstateModified && !hardwareAddressModified) {
        LOG.debug("If State entry for port: {} Not Modified.", interfaceName);
        return Collections.emptyList();
    }
    org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface = interfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceName);
    // For monitoring enabled tunnels, skip opstate update
    if (isTunnelInterface(iface) && !modifyTunnelOpState(iface, opstateModified)) {
        LOG.debug("skip interface-state updation for monitoring enabled tunnel interface {}", interfaceName);
        opstateModified = false;
    }
    if (!opstateModified && !hardwareAddressModified) {
        LOG.debug("If State entry for port: {} Not Modified.", interfaceName);
        return Collections.emptyList();
    }
    InterfaceBuilder ifaceBuilder = new InterfaceBuilder();
    if (hardwareAddressModified) {
        LOG.debug("Hw-Address Modified for Port: {}", interfaceName);
        PhysAddress physAddress = new PhysAddress(macAddressNew.getValue());
        ifaceBuilder.setPhysAddress(physAddress);
    }
    if (opstateModified) {
        return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
            // modify the attributes in interface operational DS
            handleInterfaceStateUpdates(iface, tx, ifaceBuilder, true, interfaceName, flowCapableNodeConnectorNew.getName(), operStatusNew);
            // start/stop monitoring based on opState
            if (isTunnelInterface(iface)) {
                handleTunnelMonitoringUpdates(iface.getAugmentation(IfTunnel.class), iface.getName(), operStatusNew);
            }
        }));
    } else {
        return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
            // modify the attributes in interface operational DS
            handleInterfaceStateUpdates(iface, tx, ifaceBuilder, false, interfaceName, flowCapableNodeConnectorNew.getName(), operStatusNew);
        }));
    }
}
Also used : IfmUtil(org.opendaylight.genius.interfacemanager.IfmUtil) AlivenessMonitorUtils(org.opendaylight.genius.interfacemanager.commons.AlivenessMonitorUtils) InterfaceBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder) FlowCapableNodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector) Logger(org.slf4j.Logger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) LoggerFactory(org.slf4j.LoggerFactory) InterfaceManagerCommonUtils(org.opendaylight.genius.interfacemanager.commons.InterfaceManagerCommonUtils) Singleton(javax.inject.Singleton) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Inject(javax.inject.Inject) IfTunnel(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) Collections(java.util.Collections) PhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress) InterfaceKey(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey) InterfaceBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) PhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress)

Aggregations

Test (org.junit.Test)104 ByteBuf (io.netty.buffer.ByteBuf)82 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes)60 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes)47 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update)47 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder)42 AbstractRIBSupportTest (org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest)38 AttributesReach (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesReach)35 AttributesUnreach (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesUnreach)35 ArrayList (java.util.ArrayList)31 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)14 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)13 UpdateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateBuilder)13 Ipv4NextHopCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCaseBuilder)12 Ipv4NextHopBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder)12 PmsiTunnelBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev200120.pmsi.tunnel.PmsiTunnelBuilder)12 Collections (java.util.Collections)11 AsPathBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.AsPathBuilder)11 MpUnreachNlri (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlri)11 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)10