Search in sources :

Example 16 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.

the class AbstractBGPSessionNegotiator method handleMessage.

synchronized void handleMessage(final Notification msg) {
    LOG.debug("Channel {} handling message in state {}, msg: {}", this.channel, this.state, msg);
    switch(this.state) {
        case FINISHED:
            sendMessage(buildErrorNotify(BGPError.FSM_ERROR));
            return;
        case IDLE:
            // executed
            if (msg instanceof Open) {
                startNegotiation();
                handleOpen((Open) msg);
                return;
            }
            sendMessage(buildErrorNotify(BGPError.FSM_ERROR));
            break;
        case OPEN_CONFIRM:
            if (msg instanceof Keepalive) {
                negotiationSuccessful();
                LOG.info("BGP Session with peer {} established successfully.", this.channel);
            } else if (msg instanceof Notify) {
                final Notify ntf = (Notify) msg;
                negotiationFailed(new BGPDocumentedException("Peer refusal", BGPError.forValue(ntf.getErrorCode(), ntf.getErrorSubcode())));
            }
            this.state = State.FINISHED;
            return;
        case OPEN_SENT:
            if (msg instanceof Open) {
                handleOpen((Open) msg);
                return;
            }
            break;
        default:
            break;
    }
    // Catch-all for unexpected message
    LOG.warn("Channel {} state {} unexpected message {}", this.channel, this.state, msg);
    sendMessage(buildErrorNotify(BGPError.FSM_ERROR));
    negotiationFailed(new BGPDocumentedException("Unexpected message channel: " + this.channel + ", state: " + this.state + ", message: " + msg, BGPError.FSM_ERROR));
    this.state = State.FINISHED;
}
Also used : Notify(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Notify) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) Keepalive(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Keepalive) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Open)

Example 17 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.

the class AbstractBestPathSelector method isExistingPathBetter.

/**
 * Chooses best route according to BGP best path selection.
 *
 * @param state attributes of the new route
 * @return true if the existing path is better, false if the new path is better
 */
protected boolean isExistingPathBetter(@NonNull final BestPathState state) {
    // 0. draft-uttaro-idr-bgp-persistence-04 defines "depreferenced" paths
    final boolean stateDepref = state.isDepreferenced();
    if (this.bestState.isDepreferenced() != stateDepref) {
        return stateDepref;
    }
    // 1. prefer path with accessible nexthop
    // - we assume that all nexthops are accessible
    /*
         * 2. prefer path with higher LOCAL_PREF
         *
         * FIXME: for eBGP cases (when the LOCAL_PREF is missing), we should assign a policy-based preference
         *        before we ever get here.
         */
    final Uint32 bestLocal = this.bestState.getLocalPref();
    final Uint32 stateLocal = state.getLocalPref();
    if (stateLocal != null) {
        if (bestLocal == null) {
            return true;
        }
        final int cmp = stateLocal.compareTo(bestLocal);
        if (cmp != 0) {
            return cmp < 0;
        }
    } else if (bestLocal != null) {
        return false;
    }
    // 4. prefer the path with the shortest AS_PATH.
    if (this.bestState.getAsPathLength() != state.getAsPathLength()) {
        return this.bestState.getAsPathLength() < state.getAsPathLength();
    }
    // - IGP is lower than Exterior Gateway Protocol (EGP), and EGP is lower than INCOMPLETE
    if (!this.bestState.getOrigin().equals(state.getOrigin())) {
        final BgpOrigin bo = this.bestState.getOrigin();
        final BgpOrigin no = state.getOrigin();
        // This trick relies on the order in which the values are declared in the model.
        return no.ordinal() > bo.ordinal();
    }
    // FIXME: we should be able to cache the best AS
    final long bestAs = this.bestState.getPeerAs();
    final long newAs = state.getPeerAs();
    /*
         * Checks 6 and 7 are mutually-exclusive, as MEDs are comparable
         * only when the routes originated from the same AS. On the other
         * hand, when they are from the same AS, they are in the same iBGP/eBGP
         * relationship.
         *
         */
    if (bestAs == newAs) {
        // 6. prefer the path with the lowest multi-exit discriminator (MED)
        final Boolean cmp = firstLower(this.bestState.getMultiExitDisc(), state.getMultiExitDisc());
        if (cmp != null) {
            return cmp;
        }
    } else {
        /*
             * 7. prefer eBGP over iBGP paths
             *
             * EBGP is peering between two different AS, whereas IBGP is between same AS (Autonomous System),
             * so we just compare the AS numbers to our AS.
             *
             * FIXME: we should know this information from the peer directly.
             */
        if (this.ourAs != bestAs && this.ourAs == newAs) {
            return true;
        }
    }
    /*
         * 10. Prefer the route that comes from the BGP router with the lowest router ID.
         *
         * This is normally guaranteed by the iteration order of our caller, which runs selection
         * in the order of increasing router ID, but RFC-4456 Route Reflection throws a wrench into that.
         *
         * With RFC-5004, this gets a bit easier, because it completely eliminates step f) and later :-)
         *
         * RFC-5004 states that this algorithm should end here and select existing path over new path in the
         * best path selection process. Benefits are listed in the RFC: @see http://tools.ietf.org/html/rfc500
         * - This algorithm SHOULD NOT be applied when either path is from a BGP Confederation peer.
         *  - not applicable, we don't deal with confederation peers
         * - The algorithm SHOULD NOT be applied when both paths are from peers with an identical BGP identifier
         *   (i.e., there exist parallel BGP sessions between two BGP speakers).
         *  - not applicable, BUG-2631 prevents parallel sessions to be created.
         */
    return true;
}
Also used : Uint32(org.opendaylight.yangtools.yang.common.Uint32) BgpOrigin(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpOrigin)

Example 18 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.

the class BGPPeer method onSessionUp.

@Override
public synchronized void onSessionUp(final BGPSession session) {
    this.currentSession = session;
    this.sessionUp = true;
    this.ribOutChain = this.rib.createPeerDOMChain(new DOMTransactionChainListener() {

        @Override
        public void onTransactionChainSuccessful(final DOMTransactionChain chain) {
            LOG.debug("RibOut transaction chain {} successful.", chain);
        }

        @Override
        public void onTransactionChainFailed(final DOMTransactionChain chain, final DOMDataTreeTransaction transaction, final Throwable cause) {
            onRibOutChainFailed(cause);
        }
    });
    if (this.currentSession instanceof BGPSessionStateProvider) {
        ((BGPSessionStateProvider) this.currentSession).registerMessagesCounter(this);
    }
    final GracefulRestartCapability advertisedGracefulRestartCapability = session.getAdvertisedGracefulRestartCapability();
    final var advertisedTables = advertisedGracefulRestartCapability.getTables();
    final var advertisedLLTables = session.getAdvertisedLlGracefulRestartCapability().getTables();
    final List<AddressFamilies> addPathTablesType = session.getAdvertisedAddPathTableTypes();
    final Set<BgpTableType> advertizedTableTypes = session.getAdvertisedTableTypes();
    LOG.info("Session with peer {} went up with tables {} and Add Path tables {}", getName(), advertizedTableTypes, addPathTablesType);
    final Set<TablesKey> setTables = advertizedTableTypes.stream().map(t -> new TablesKey(t.getAfi(), t.getSafi())).collect(Collectors.toSet());
    this.tables = ImmutableSet.copyOf(setTables);
    this.addPathTableMaps = mapTableTypesFamilies(addPathTablesType);
    final boolean restartingLocally = isLocalRestarting();
    if (!restartingLocally) {
        addBgp4Support();
    }
    if (!isRestartingGracefully()) {
        this.peerId = RouterIds.createPeerId(session.getBgpId());
        final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.Peer, PeerKey> peerIId = getInstanceIdentifier().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.Peer.class, new PeerKey(this.peerId));
        this.peerPath = createPeerPath(this.peerId);
        this.peerRibOutIId = peerPath.node(ADJRIBOUT_NID);
        this.trackerRegistration = this.rib.getPeerTracker().registerPeer(this);
        createEffRibInWriter();
        registerPrefixesCounters(this.effRibInWriter, this.effRibInWriter);
        this.effRibInWriter.init();
        this.ribWriter = this.ribWriter.transform(this.peerId, this.peerPath, this.rib.getRibSupportContext(), this.tables, this.addPathTableMaps);
        if (this.rpcRegistry != null) {
            this.rpcRegistration = this.rpcRegistry.registerRpcImplementation(BgpPeerRpcService.class, new BgpPeerRpc(this, session, this.tables), ImmutableSet.of(this.rib.getInstanceIdentifier().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.Peer.class, new PeerKey(this.peerId))));
        }
    } else {
        final Set<TablesKey> forwardingTables;
        if (advertisedTables == null) {
            forwardingTables = Collections.emptySet();
        } else {
            forwardingTables = advertisedTables.values().stream().filter(table -> table.getAfiFlags() != null).filter(table -> table.getAfiFlags().getForwardingState()).map(table -> new TablesKey(table.getAfi(), table.getSafi())).collect(Collectors.toSet());
        }
        this.ribWriter.clearTables(Sets.difference(this.tables, forwardingTables));
        if (restartingLocally) {
            this.effRibInWriter.close();
            this.peerRestartStopwatch = Stopwatch.createStarted();
            handleSelectionReferralTimer();
            this.missingEOT.addAll(this.tables);
        }
    }
    if (advertisedTables == null || advertisedTables.isEmpty()) {
        setAdvertizedGracefulRestartTableTypes(Collections.emptyList());
    } else {
        setAdvertizedGracefulRestartTableTypes(advertisedTables.values().stream().map(t -> new TablesKey(t.getAfi(), t.getSafi())).collect(Collectors.toList()));
    }
    setAfiSafiGracefulRestartState(advertisedGracefulRestartCapability.getRestartTime().toJava(), false, restartingLocally);
    final Map<TablesKey, Integer> llTablesReceived;
    if (advertisedLLTables != null) {
        llTablesReceived = new HashMap<>();
        for (var table : advertisedLLTables.values()) {
            llTablesReceived.put(new TablesKey(table.getAfi(), table.getSafi()), table.getLongLivedStaleTime().getValue().intValue());
        }
    } else {
        llTablesReceived = Collections.emptyMap();
    }
    setAdvertizedLlGracefulRestartTableTypes(llTablesReceived);
    if (!llTablesReceived.isEmpty()) {
        llgrSupport = true;
    // FIXME: propagate preserved tables
    } else {
        // FIXME: clear preserved tables
        llgrSupport = false;
    }
    if (!restartingLocally) {
        if (!setTables.contains(IPV4_UCAST_TABLE_KEY)) {
            createAdjRibOutListener(IPV4_UCAST_TABLE_KEY, false);
        }
        for (final TablesKey key : getAfiSafisAdvertized()) {
            createAdjRibOutListener(key, true);
        }
    }
    // SpotBugs does not grok Optional.ifPresent() and thinks we are using unsynchronized access
    final Optional<RevisedErrorHandlingSupport> errorHandling = this.bgpPeer.getErrorHandling();
    if (errorHandling.isPresent()) {
        this.currentSession.addDecoderConstraint(RevisedErrorHandlingSupport.class, errorHandling.get());
    }
}
Also used : AddressFamilies(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.add.path.capability.AddressFamilies) LoadingCache(com.google.common.cache.LoadingCache) RevisedErrorHandlingSupport(org.opendaylight.protocol.bgp.parser.spi.RevisedErrorHandlingSupport) BgpAddPathTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpAddPathTableType) LoggerFactory(org.slf4j.LoggerFactory) PeerKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.PeerKey) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes) MpReachNlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlriBuilder) BgpPeerRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev180329.BgpPeerRpcService) Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update) MpReachNlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlri) Ipv4AddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily) LocalPreferenceAttributeParser(org.opendaylight.protocol.bgp.parser.impl.message.update.LocalPreferenceAttributeParser) GracefulRestartUtil(org.opendaylight.protocol.bgp.rib.impl.config.GracefulRestartUtil) Notification(org.opendaylight.yangtools.yang.binding.Notification) Nlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.Nlri) RouteRefresh(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.RouteRefresh) WithdrawnRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.mp.unreach.nlri.WithdrawnRoutesBuilder) ObjectRegistration(org.opendaylight.yangtools.concepts.ObjectRegistration) Map(java.util.Map) SendReceive(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.SendReceive) AdvertizedRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.mp.reach.nlri.AdvertizedRoutesBuilder) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DestinationIpv4Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.DestinationIpv4Builder) BgpPeer(org.opendaylight.protocol.bgp.rib.impl.config.BgpPeer) TABLES_NID(org.opendaylight.protocol.bgp.rib.spi.RIBNodeIdentifiers.TABLES_NID) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters) Set(java.util.Set) TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) BGPSessionPreferences(org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences) Collectors(java.util.stream.Collectors) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder) Sets(com.google.common.collect.Sets) DestinationIpv4CaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4CaseBuilder) CacheLoader(com.google.common.cache.CacheLoader) Objects(java.util.Objects) MpUnreachNlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlri) List(java.util.List) DOMDataTreeTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeTransaction) GuardedBy(org.checkerframework.checker.lock.qual.GuardedBy) ADJRIBOUT_NID(org.opendaylight.protocol.bgp.rib.spi.RIBNodeIdentifiers.ADJRIBOUT_NID) DOMTransactionChain(org.opendaylight.mdsal.dom.api.DOMTransactionChain) BGPSessionStateProvider(org.opendaylight.protocol.bgp.rib.impl.state.BGPSessionStateProvider) BGPTerminationReason(org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason) Optional(java.util.Optional) CacheBuilder(com.google.common.cache.CacheBuilder) MpUnreachNlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlriBuilder) Registration(org.opendaylight.yangtools.concepts.Registration) NonNull(org.eclipse.jdt.annotation.NonNull) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) IpAddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone) BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType) RIB(org.opendaylight.protocol.bgp.rib.impl.spi.RIB) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) DOMTransactionChainListener(org.opendaylight.mdsal.dom.api.DOMTransactionChainListener) Stopwatch(com.google.common.base.Stopwatch) GracefulRestartCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.GracefulRestartCapability) ClusterIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.ClusterIdentifier) RouterIds(org.opendaylight.protocol.bgp.rib.spi.RouterIds) HashMap(java.util.HashMap) BGPError(org.opendaylight.protocol.bgp.parser.BGPError) Ipv4PrefixesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.destination.ipv4.Ipv4PrefixesBuilder) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Ipv4Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.destination.ipv4.Ipv4Prefixes) BGPSessionState(org.opendaylight.protocol.bgp.rib.spi.state.BGPSessionState) AddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.AddressFamily) RouteTarget(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteTarget) SubsequentAddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.SubsequentAddressFamily) MessageUtil(org.opendaylight.protocol.bgp.parser.spi.MessageUtil) Objects.requireNonNull(java.util.Objects.requireNonNull) BGPSessionListener(org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener) BGPTransportState(org.opendaylight.protocol.bgp.rib.spi.state.BGPTransportState) Logger(org.slf4j.Logger) RIBSupport(org.opendaylight.protocol.bgp.rib.spi.RIBSupport) PeerRole(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole) MoreObjects(com.google.common.base.MoreObjects) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) TimeUnit(java.util.concurrent.TimeUnit) Ipv4Util(org.opendaylight.protocol.util.Ipv4Util) Futures(com.google.common.util.concurrent.Futures) Holding(org.checkerframework.checker.lock.qual.Holding) RpcProviderService(org.opendaylight.mdsal.binding.api.RpcProviderService) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) BGPTableTypeRegistryConsumer(org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer) BGPTimersState(org.opendaylight.protocol.bgp.rib.spi.state.BGPTimersState) Collections(java.util.Collections) UnicastSubsequentAddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.UnicastSubsequentAddressFamily) FluentFuture(com.google.common.util.concurrent.FluentFuture) BGPSession(org.opendaylight.protocol.bgp.rib.spi.BGPSession) RevisedErrorHandlingSupport(org.opendaylight.protocol.bgp.parser.spi.RevisedErrorHandlingSupport) Collections(java.util.Collections) AddressFamilies(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.add.path.capability.AddressFamilies) DOMDataTreeTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeTransaction) BGPSessionStateProvider(org.opendaylight.protocol.bgp.rib.impl.state.BGPSessionStateProvider) DOMTransactionChainListener(org.opendaylight.mdsal.dom.api.DOMTransactionChainListener) BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType) TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey) BgpPeer(org.opendaylight.protocol.bgp.rib.impl.config.BgpPeer) DOMTransactionChain(org.opendaylight.mdsal.dom.api.DOMTransactionChain) PeerKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.PeerKey) BgpPeerRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev180329.BgpPeerRpcService) GracefulRestartCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.GracefulRestartCapability)

Example 19 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.

the class AbstractPeer method applyExportPolicy.

private Optional<ContainerNode> applyExportPolicy(final RouteEntryDependenciesContainer entryDep, final PeerId fromPeerId, final MapEntryNode route, final YangInstanceIdentifier routePath, final ContainerNode attrs) {
    final Peer fromPeer = entryDep.getPeerTracker().getPeer(fromPeerId);
    final RIBSupport<?, ?> ribSupport = entryDep.getRIBSupport();
    final BGPRouteEntryExportParameters routeEntry = new BGPRouteEntryExportParametersImpl(fromPeer, this, ribSupport.extractRouteKey(route.getIdentifier()), rtCache);
    final Attributes bindingAttrs = ribSupport.attributeFromContainerNode(attrs);
    final Optional<Attributes> optExportAttrs = entryDep.getRoutingPolicies().applyExportPolicies(routeEntry, bindingAttrs, entryDep.getAfiSafType());
    if (optExportAttrs.isEmpty()) {
        // Discards route
        return Optional.empty();
    }
    final Attributes exportAttrs = optExportAttrs.orElseThrow();
    // churn objects when it does not have to
    return Optional.of(exportAttrs == bindingAttrs ? attrs : ribSupport.attributeToContainerNode(routePath.node(ribSupport.routeAttributesIdentifier()), exportAttrs));
}
Also used : Peer(org.opendaylight.protocol.bgp.rib.spi.Peer) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes) BGPRouteEntryExportParametersImpl(org.opendaylight.protocol.bgp.mode.impl.BGPRouteEntryExportParametersImpl) BGPRouteEntryExportParameters(org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters)

Example 20 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.

the class StrictBGPPeerRegistry method addPeer.

@Override
public synchronized void addPeer(final IpAddressNoZone oldIp, final BGPSessionListener peer, final BGPSessionPreferences preferences) {
    IpAddressNoZone fullIp = getFullIp(oldIp);
    Preconditions.checkArgument(!this.peers.containsKey(fullIp), "Peer for %s already present", fullIp);
    this.peers.put(fullIp, requireNonNull(peer));
    requireNonNull(preferences.getMyAs());
    requireNonNull(preferences.getParams());
    requireNonNull(preferences.getBgpId());
    this.peerPreferences.put(fullIp, preferences);
    for (final PeerRegistryListener peerRegistryListener : this.listeners) {
        peerRegistryListener.onPeerAdded(fullIp, preferences);
    }
}
Also used : PeerRegistryListener(org.opendaylight.protocol.bgp.rib.impl.spi.PeerRegistryListener) IpAddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone)

Aggregations

Test (org.junit.Test)29 ByteBuf (io.netty.buffer.ByteBuf)13 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)11 IpAddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone)9 BGPSessionPreferences (org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences)8 Peer (org.opendaylight.protocol.bgp.rib.spi.Peer)8 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)7 ArrayList (java.util.ArrayList)6 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)6 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)6 BGPRouteEntryExportParametersImpl (org.opendaylight.protocol.bgp.mode.impl.BGPRouteEntryExportParametersImpl)5 RIBSupport (org.opendaylight.protocol.bgp.rib.spi.RIBSupport)5 BGPRouteEntryExportParameters (org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters)5 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters)5 PeerId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId)5 CommitInfo (org.opendaylight.mdsal.common.api.CommitInfo)4 PeerSpecificParserConstraint (org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)4 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)4 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)4 PortStatusMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage)4