Search in sources :

Example 21 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.Peer in project bgpcep by opendaylight.

the class StrictBGPPeerRegistry method getPeer.

@Override
public synchronized BGPSessionListener getPeer(final IpAddress ip, final Ipv4Address sourceId, final Ipv4Address remoteId, final Open openObj) throws BGPDocumentedException {
    requireNonNull(ip);
    requireNonNull(sourceId);
    requireNonNull(remoteId);
    final AsNumber remoteAsNumber = AsNumberUtil.advertizedAsNumber(openObj);
    requireNonNull(remoteAsNumber);
    final BGPSessionPreferences prefs = getPeerPreferences(ip);
    checkPeerConfigured(ip);
    final BGPSessionId currentConnection = new BGPSessionId(sourceId, remoteId, remoteAsNumber);
    final BGPSessionListener p = this.peers.get(ip);
    final BGPSessionId previousConnection = this.sessionIds.get(ip);
    if (previousConnection != null) {
        LOG.warn("Duplicate BGP session established with {}", ip);
        // Session reestablished with different ids
        if (!previousConnection.equals(currentConnection)) {
            LOG.warn("BGP session with {} {} has to be dropped. Same session already present {}", ip, currentConnection, previousConnection);
            throw new BGPDocumentedException(String.format("BGP session with %s %s has to be dropped. Same session already present %s", ip, currentConnection, previousConnection), BGPError.CEASE);
        // Session reestablished with lower source bgp id, dropping current
        } else if (previousConnection.isHigherDirection(currentConnection) || previousConnection.hasHigherAsNumber(currentConnection)) {
            LOG.warn("BGP session with {} {} has to be dropped. Opposite session already present", ip, currentConnection);
            throw new BGPDocumentedException(String.format("BGP session with %s initiated %s has to be dropped. " + "Opposite session already present", ip, currentConnection), BGPError.CEASE);
        // Session reestablished with higher source bgp id, dropping previous
        } else if (currentConnection.isHigherDirection(previousConnection) || currentConnection.hasHigherAsNumber(previousConnection)) {
            LOG.warn("BGP session with {} {} released. Replaced by opposite session", ip, previousConnection);
            this.peers.get(ip).releaseConnection();
            return this.peers.get(ip);
        // Session reestablished with same source bgp id, dropping current as duplicate
        } else {
            LOG.warn("BGP session with %s initiated from %s to %s has to be dropped. Same session already present", ip, sourceId, remoteId);
            throw new BGPDocumentedException(String.format("BGP session with %s initiated %s has to be dropped. " + "Same session already present", ip, currentConnection), BGPError.CEASE);
        }
    }
    validateAs(remoteAsNumber, openObj, prefs);
    // Map session id to peer IP address
    this.sessionIds.put(ip, currentConnection);
    for (final PeerRegistrySessionListener peerRegistrySessionListener : this.sessionListeners) {
        peerRegistrySessionListener.onSessionCreated(ip);
    }
    return p;
}
Also used : BGPSessionListener(org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener) BGPSessionPreferences(org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) PeerRegistrySessionListener(org.opendaylight.protocol.bgp.rib.impl.spi.PeerRegistrySessionListener) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)

Example 22 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.Peer in project bgpcep by opendaylight.

the class StrictBGPPeerRegistry method addPeer.

@Override
public synchronized void addPeer(final IpAddress oldIp, final BGPSessionListener peer, final BGPSessionPreferences preferences) {
    IpAddress 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) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)

Example 23 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.Peer in project bgpcep by opendaylight.

the class PcepStateUtils method displayNodeState.

private static void displayNodeState(final String topologyId, final String nodeId, final PcepSessionState pcepSessionState, final PrintStream stream) {
    final ShellTable table = new ShellTable();
    table.column("Attribute").alignLeft();
    table.column("Value").alignLeft();
    showNodeState(table, topologyId, nodeId, pcepSessionState);
    addHeader(table, "Local preferences");
    final LocalPref localPref = pcepSessionState.getLocalPref();
    showPreferences(table, localPref);
    final PcepEntityIdStatsAug entAug = localPref.getAugmentation(PcepEntityIdStatsAug.class);
    if (entAug != null) {
        table.addRow().addContent("Speaker Entity Identifier", Arrays.toString(entAug.getSpeakerEntityIdValue()));
    }
    addHeader(table, "Peer preferences");
    final PeerPref peerPref = pcepSessionState.getPeerPref();
    showPreferences(table, peerPref);
    showCapabilities(table, pcepSessionState.getPeerCapabilities());
    final Messages messages = pcepSessionState.getMessages();
    showMessages(table, messages);
    final ErrorMessages error = messages.getErrorMessages();
    showErrorMessages(table, error);
    final ReplyTime reply = messages.getReplyTime();
    showReplyMessages(table, reply);
    table.print(stream);
}
Also used : ErrorMessages(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.error.messages.grouping.ErrorMessages) PcepEntityIdStatsAug(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stateful.stats.rev171113.PcepEntityIdStatsAug) ShellTable(org.apache.karaf.shell.table.ShellTable) Messages(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.Messages) ErrorMessages(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.error.messages.grouping.ErrorMessages) LocalPref(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.LocalPref) PeerPref(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.PeerPref) ReplyTime(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.reply.time.grouping.ReplyTime)

Example 24 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.Peer in project bgpcep by opendaylight.

the class AbstractTopologySessionListener method onSessionUp.

@Override
public final synchronized void onSessionUp(final PCEPSession psession) {
    /*
         * The session went up. Look up the router in Inventory model,
         * create it if it is not there (marking that fact for later
         * deletion), and mark it as synchronizing. Also create it in
         * the topology model, with empty LSP list.
         */
    final InetAddress peerAddress = psession.getRemoteAddress();
    this.syncOptimization = new SyncOptimization(psession);
    final TopologyNodeState state = this.serverSessionManager.takeNodeState(peerAddress, this, isLspDbRetreived());
    // takeNodeState(..) may fail when the server session manager is being restarted due to configuration change
    if (state == null) {
        LOG.error("Unable to fetch topology node state for PCEP session. Closing session {}", psession);
        psession.close(TerminationReason.UNKNOWN);
        this.onSessionTerminated(psession, new PCEPCloseTermination(TerminationReason.UNKNOWN));
        return;
    }
    if (this.session != null || this.nodeState != null) {
        LOG.error("PCEP session is already up with {}. Closing session {}", psession.getRemoteAddress(), psession);
        psession.close(TerminationReason.UNKNOWN);
        this.onSessionTerminated(psession, new PCEPCloseTermination(TerminationReason.UNKNOWN));
        return;
    }
    this.session = psession;
    this.nodeState = state;
    this.serverSessionManager.bind(this.nodeState.getNodeId(), this.listenerState);
    LOG.trace("Peer {} resolved to topology node {}", peerAddress, state.getNodeId());
    // Our augmentation in the topology node
    final PathComputationClientBuilder pccBuilder = new PathComputationClientBuilder();
    onSessionUp(psession, pccBuilder);
    this.synced.set(isSynchronized());
    pccBuilder.setIpAddress(IpAddressBuilder.getDefaultInstance(peerAddress.getHostAddress()));
    final InstanceIdentifier<Node1> topologyAugment = state.getNodeId().augmentation(Node1.class);
    this.pccIdentifier = topologyAugment.child(PathComputationClient.class);
    final Node initialNodeState = state.getInitialNodeState();
    final boolean isNodePresent = isLspDbRetreived() && initialNodeState != null;
    if (isNodePresent) {
        loadLspData(initialNodeState, this.lspData, this.lsps, isIncrementalSynchro());
        pccBuilder.setReportedLsp(initialNodeState.getAugmentation(Node1.class).getPathComputationClient().getReportedLsp());
    }
    state.storeNode(topologyAugment, new Node1Builder().setPathComputationClient(pccBuilder.build()).build(), this.session);
    this.listenerState.init(psession);
    LOG.info("Session with {} attached to topology node {}", psession.getRemoteAddress(), state.getNodeId());
}
Also used : PCEPCloseTermination(org.opendaylight.protocol.pcep.PCEPCloseTermination) Node1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.Node1) Node1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.Node1Builder) PathComputationClient(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.pcep.client.attributes.PathComputationClient) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) PathComputationClientBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.pcep.client.attributes.PathComputationClientBuilder) InetAddress(java.net.InetAddress)

Example 25 with Peer

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.Peer in project bgpcep by opendaylight.

the class BmpRouterImpl method onPeerUp.

private synchronized void onPeerUp(final PeerUpNotification peerUp) {
    final PeerId peerId = getPeerIdFromOpen(peerUp.getReceivedOpen());
    if (!getPeer(peerId).isPresent()) {
        final BmpRouterPeer peer = BmpRouterPeerImpl.createRouterPeer(this.domTxChain, this.peersYangIId, peerUp, this.extensions, this.tree, peerId);
        this.peers.put(peerId, peer);
        LOG.debug("Router {}: Peer {} goes up.", this.routerIp, peerId.getValue());
    } else {
        LOG.debug("Peer: {} for Router: {} already exists.", peerId.getValue(), this.routerIp);
    }
}
Also used : BmpRouterPeer(org.opendaylight.protocol.bmp.impl.spi.BmpRouterPeer) PeerId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId)

Aggregations

Test (org.junit.Test)23 ByteBuf (io.netty.buffer.ByteBuf)12 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)10 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)9 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)7 Peer (org.opendaylight.protocol.bgp.rib.spi.Peer)6 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)6 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes)6 RIBSupport (org.opendaylight.protocol.bgp.rib.spi.RIBSupport)5 ArrayList (java.util.ArrayList)4 BGPRouteEntryExportParametersImpl (org.opendaylight.protocol.bgp.mode.impl.BGPRouteEntryExportParametersImpl)4 BGPSessionPreferences (org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences)4 BGPRouteEntryExportParameters (org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters)4 PortStatusMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage)4 TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey)4 KeyedInstanceIdentifier (org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier)4 Preconditions (com.google.common.base.Preconditions)3 BgpTableTypeImpl (org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl)3 BGPSessionListener (org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener)3 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)3