Search in sources :

Example 36 with Bgp

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project bgpcep by opendaylight.

the class AddPathAllPathsTest method testUseCase1.

/*
     * All-Paths
     *                                            ___________________
     *                                           | ODL BGP 127.0.0.1 |
     * [peer://127.0.0.2; p1, lp100] --(iBGP)--> |                   | --(RR-client, non add-path) --> [Peer://127.0.0.5; (p1, lp100), (p1, lp1200)]
     * [peer://127.0.0.3; p1, lp200] --(iBGP)--> |                   |
     * [peer://127.0.0.4; p1, lp50] --(iBGP)-->  |                   | --(RR-client, add-path) --> [Peer://127.0.0.6; (p1, path-id1, lp100), (p1, path-id2, pl50), (p1, path-id3, pl200), (p1, path-id4, pl20)]
     * [peer://127.0.0.2; p1, lp20] --(iBGP)-->  |___________________|
     * p1 = 1.1.1.1/32
     */
@Test
public void testUseCase1() throws Exception {
    final BgpParameters nonAddPathParams = createParameter(false);
    final BgpParameters addPathParams = createParameter(true);
    final BGPPeer peer1 = configurePeer(PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
    final BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
    configurePeer(PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
    final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
    configurePeer(PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
    final BGPSessionImpl session3 = createPeerSession(PEER3, nonAddPathParams, new SimpleSessionListener());
    final SimpleSessionListener listener4 = new SimpleSessionListener();
    final BGPPeer peer4 = configurePeer(PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
    BGPPeerState peer4State = peer4.getPeerState();
    assertNull(peer4State.getGroupId());
    assertEquals(new IpAddress(PEER4), peer4State.getNeighborAddress());
    assertEquals(0L, peer4State.getTotalPathsCount());
    assertEquals(0L, peer4State.getTotalPrefixes());
    assertNull(peer4State.getBGPTimersState());
    assertNull(peer4State.getBGPTransportState());
    assertNull(peer4State.getBGPSessionState());
    assertEquals(0L, peer4State.getBGPErrorHandlingState().getErroneousUpdateReceivedCount());
    BGPGracelfulRestartState gracefulRestart = peer4State.getBGPGracelfulRestart();
    assertFalse(gracefulRestart.isGracefulRestartAdvertized(TABLES_KEY));
    assertFalse(gracefulRestart.isGracefulRestartReceived(TABLES_KEY));
    assertFalse(gracefulRestart.isLocalRestarting());
    assertFalse(gracefulRestart.isPeerRestarting());
    assertEquals(0L, gracefulRestart.getPeerRestartTime());
    BGPAfiSafiState afiSafiState = peer4State.getBGPAfiSafiState();
    assertEquals(AFI_SAFIS_ADVERTIZED, afiSafiState.getAfiSafisAdvertized());
    assertEquals(Collections.emptySet(), afiSafiState.getAfiSafisReceived());
    assertEquals(0L, afiSafiState.getPrefixesSentCount(TABLES_KEY));
    assertEquals(0L, afiSafiState.getPrefixesReceivedCount(TABLES_KEY));
    assertEquals(0L, afiSafiState.getPrefixesInstalledCount(TABLES_KEY));
    assertFalse(afiSafiState.isGracefulRestartAdvertized(TABLES_KEY));
    assertFalse(afiSafiState.isGracefulRestartAdvertized(TABLES_KEY));
    assertFalse(afiSafiState.isLocalRestarting());
    assertFalse(afiSafiState.isPeerRestarting());
    assertFalse(afiSafiState.isAfiSafiSupported(TABLES_KEY));
    final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
    final SimpleSessionListener listener5 = new SimpleSessionListener();
    configurePeer(PEER5, this.ribImpl, addPathParams, PeerRole.RrClient, this.serverRegistry);
    final BGPSessionImpl session5 = createPeerSession(PEER5, addPathParams, listener5);
    checkPeersPresentOnDataStore(5);
    // the best route
    sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 1);
    checkReceivedMessages(listener4, 1);
    checkReceivedMessages(listener5, 1);
    assertEquals(UPD_100, listener5.getListMsg().get(0));
    final BGPPeerState peer1State = peer1.getPeerState();
    assertNull(peer1State.getGroupId());
    assertEquals(new IpAddress(PEER1), peer1State.getNeighborAddress());
    assertEquals(1L, peer1State.getTotalPathsCount());
    assertEquals(1L, peer1State.getTotalPrefixes());
    final BGPTimersState timerStatePeer1 = peer1State.getBGPTimersState();
    assertEquals(HOLDTIMER, timerStatePeer1.getNegotiatedHoldTime());
    assertTrue(timerStatePeer1.getUpTime() > 0L);
    final BGPTransportState transportStatePeer1 = peer1State.getBGPTransportState();
    assertEquals(new PortNumber(PORT), transportStatePeer1.getLocalPort());
    assertEquals(new IpAddress(PEER1), transportStatePeer1.getRemoteAddress());
    assertEquals(State.UP, peer1State.getBGPSessionState().getSessionState());
    checkEquals(() -> assertEquals(1L, peer1State.getBGPPeerMessagesState().getUpdateMessagesReceivedCount()));
    checkEquals(() -> assertEquals(0L, peer1State.getBGPPeerMessagesState().getUpdateMessagesSentCount()));
    final BGPSessionState sessionStatePeer1 = peer1State.getBGPSessionState();
    assertFalse(sessionStatePeer1.isAddPathCapabilitySupported());
    assertFalse(sessionStatePeer1.isAsn32CapabilitySupported());
    assertFalse(sessionStatePeer1.isGracefulRestartCapabilitySupported());
    assertTrue(sessionStatePeer1.isMultiProtocolCapabilitySupported());
    assertFalse(sessionStatePeer1.isRouterRefreshCapabilitySupported());
    final BGPAfiSafiState afiSafiStatePeer1 = peer1State.getBGPAfiSafiState();
    assertEquals(AFI_SAFIS_ADVERTIZED, afiSafiStatePeer1.getAfiSafisAdvertized());
    assertEquals(AFI_SAFIS_ADVERTIZED, afiSafiStatePeer1.getAfiSafisReceived());
    assertEquals(0L, afiSafiStatePeer1.getPrefixesSentCount(TABLES_KEY));
    assertEquals(1L, afiSafiStatePeer1.getPrefixesReceivedCount(TABLES_KEY));
    assertEquals(1L, afiSafiStatePeer1.getPrefixesInstalledCount(TABLES_KEY));
    assertFalse(afiSafiStatePeer1.isGracefulRestartAdvertized(TABLES_KEY));
    assertFalse(afiSafiStatePeer1.isGracefulRestartAdvertized(TABLES_KEY));
    assertFalse(afiSafiStatePeer1.isLocalRestarting());
    assertFalse(afiSafiStatePeer1.isPeerRestarting());
    assertTrue(afiSafiStatePeer1.isAfiSafiSupported(TABLES_KEY));
    final BGPRibState ribState = this.ribImpl.getRIBState();
    assertEquals(1, ribState.getPathsCount().size());
    assertEquals(1L, ribState.getTablesPrefixesCount().size());
    assertEquals(BGP_ID, ribState.getRouteId());
    assertEquals(AS_NUMBER, ribState.getAs());
    assertEquals(1L, ribState.getPathCount(TABLES_KEY));
    assertEquals(1L, ribState.getPrefixesCount(TABLES_KEY));
    assertEquals(1L, ribState.getTotalPathsCount());
    assertEquals(1L, ribState.getTotalPrefixesCount());
    final SimpleSessionListener listener6 = new SimpleSessionListener();
    final BGPPeer peer6 = configurePeer(PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
    final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
    checkPeersPresentOnDataStore(6);
    checkReceivedMessages(listener6, 1);
    assertEquals(UPD_NA_100, listener6.getListMsg().get(0));
    causeBGPError(session6);
    checkEquals(() -> assertEquals(1L, peer6.getPeerState().getBGPPeerMessagesState().getNotificationMessagesSentCount()));
    checkPeersPresentOnDataStore(5);
    // the second best route
    sendRouteAndCheckIsOnLocRib(session2, PREFIX1, 50, 2);
    checkReceivedMessages(listener4, 1);
    checkReceivedMessages(listener5, 2);
    assertEquals(UPD_50, listener5.getListMsg().get(1));
    // new best route
    sendRouteAndCheckIsOnLocRib(session3, PREFIX1, 200, 3);
    checkReceivedMessages(listener4, 2);
    checkReceivedMessages(listener5, 3);
    assertEquals(UPD_200, listener5.getListMsg().get(2));
    peer4State = peer4.getPeerState();
    assertNull(peer4State.getGroupId());
    assertEquals(new IpAddress(PEER4), peer4State.getNeighborAddress());
    assertEquals(0L, peer4State.getTotalPathsCount());
    assertEquals(0L, peer4State.getTotalPrefixes());
    final BGPTimersState timerState = peer4State.getBGPTimersState();
    assertEquals(HOLDTIMER, timerState.getNegotiatedHoldTime());
    assertTrue(timerState.getUpTime() > 0L);
    final BGPTransportState transportState = peer4State.getBGPTransportState();
    assertEquals(new PortNumber(PORT), transportState.getLocalPort());
    assertEquals(new IpAddress(PEER4), transportState.getRemoteAddress());
    final BGPPeerMessagesState peerMessagesState = peer4State.getBGPPeerMessagesState();
    assertEquals(0L, peerMessagesState.getNotificationMessagesReceivedCount());
    assertEquals(0L, peerMessagesState.getNotificationMessagesSentCount());
    assertEquals(0L, peerMessagesState.getUpdateMessagesReceivedCount());
    assertEquals(2L, peerMessagesState.getUpdateMessagesSentCount());
    final BGPSessionState bgpSessionState = peer4State.getBGPSessionState();
    assertEquals(State.UP, bgpSessionState.getSessionState());
    assertFalse(bgpSessionState.isAddPathCapabilitySupported());
    assertFalse(bgpSessionState.isAsn32CapabilitySupported());
    assertFalse(bgpSessionState.isGracefulRestartCapabilitySupported());
    assertTrue(bgpSessionState.isMultiProtocolCapabilitySupported());
    assertFalse(bgpSessionState.isRouterRefreshCapabilitySupported());
    final BGPErrorHandlingState errorHandling = peer4State.getBGPErrorHandlingState();
    assertEquals(0L, errorHandling.getErroneousUpdateReceivedCount());
    gracefulRestart = peer4State.getBGPGracelfulRestart();
    assertFalse(gracefulRestart.isGracefulRestartAdvertized(TABLES_KEY));
    assertFalse(gracefulRestart.isGracefulRestartReceived(TABLES_KEY));
    assertFalse(gracefulRestart.isLocalRestarting());
    assertFalse(gracefulRestart.isPeerRestarting());
    assertEquals(0L, gracefulRestart.getPeerRestartTime());
    afiSafiState = peer4State.getBGPAfiSafiState();
    assertEquals(AFI_SAFIS_ADVERTIZED, afiSafiState.getAfiSafisAdvertized());
    assertEquals(AFI_SAFIS_ADVERTIZED, afiSafiState.getAfiSafisReceived());
    assertEquals(2L, afiSafiState.getPrefixesSentCount(TABLES_KEY));
    assertEquals(0L, afiSafiState.getPrefixesReceivedCount(TABLES_KEY));
    assertEquals(0L, afiSafiState.getPrefixesInstalledCount(TABLES_KEY));
    assertFalse(afiSafiState.isGracefulRestartAdvertized(TABLES_KEY));
    assertFalse(afiSafiState.isGracefulRestartAdvertized(TABLES_KEY));
    assertFalse(afiSafiState.isLocalRestarting());
    assertFalse(afiSafiState.isPeerRestarting());
    assertTrue(afiSafiState.isAfiSafiSupported(TABLES_KEY));
    // the worst route
    sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 20, 3);
    checkReceivedMessages(listener4, 2);
    checkReceivedMessages(listener5, 4);
    assertEquals(UPD_200.getAttributes().getLocalPref(), ((Update) listener4.getListMsg().get(1)).getAttributes().getLocalPref());
    assertEquals(UPD_20, listener5.getListMsg().get(3));
    // withdraw second best route, 1 advertisement(1 withdrawal) for add-path supported, none for non add path
    sendWithdrawalRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 2);
    checkReceivedMessages(listener4, 2);
    checkReceivedMessages(listener5, 5);
    // we advertise again to try new test
    sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 3);
    checkReceivedMessages(listener4, 2);
    checkReceivedMessages(listener5, 6);
    assertEquals(UPD_200, listener5.getListMsg().get(2));
    // withdraw second best route, 1 advertisement(1 withdrawal) for add-path supported, 1 for non add path (withdrawal)
    sendWithdrawalRouteAndCheckIsOnLocRib(session3, PREFIX1, 200, 2);
    checkReceivedMessages(listener4, 3);
    checkReceivedMessages(listener5, 7);
    sendNotification(session1);
    checkEquals(() -> assertEquals(1L, peer1.getPeerState().getBGPPeerMessagesState().getNotificationMessagesReceivedCount()));
    session1.close();
    session2.close();
    session3.close();
    session4.close();
    session5.close();
}
Also used : BGPTimersState(org.opendaylight.protocol.bgp.rib.spi.state.BGPTimersState) BGPTransportState(org.opendaylight.protocol.bgp.rib.spi.state.BGPTransportState) BGPSessionState(org.opendaylight.protocol.bgp.rib.spi.state.BGPSessionState) BGPPeerState(org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerState) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters) Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update) BGPAfiSafiState(org.opendaylight.protocol.bgp.rib.spi.state.BGPAfiSafiState) BGPRibState(org.opendaylight.protocol.bgp.rib.spi.state.BGPRibState) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) BGPPeerMessagesState(org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerMessagesState) BGPGracelfulRestartState(org.opendaylight.protocol.bgp.rib.spi.state.BGPGracelfulRestartState) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) BGPErrorHandlingState(org.opendaylight.protocol.bgp.rib.spi.state.BGPErrorHandlingState) Test(org.junit.Test)

Example 37 with Bgp

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project bgpcep by opendaylight.

the class AddPathNPathsTest method testUseCase1.

/*
     * N-Paths
     *                                            ___________________
     *                                           | ODL BGP 127.0.0.1 |
     * [peer://127.0.0.2; p1, lp100] --(iBGP)--> |                   | --(RR-client, non add-path) --> [Peer://127.0.0.5; (p1, lp100), (p1, lp1200)]
     * [peer://127.0.0.3; p1, lp200] --(iBGP)--> |                   |
     * [peer://127.0.0.4; p1, lp50] --(iBGP)-->  |                   | --(RR-client, add-path) --> [Peer://127.0.0.6; (p1, path-id1, lp100), (p1, path-id2, pl50), (p1, path-id3, pl200)]
     * [peer://127.0.0.2; p1, lp20] --(iBGP)-->  |___________________|
     * p1 = 1.1.1.1/32
     */
@Test
public void testUseCase1() throws Exception {
    final BgpParameters nonAddPathParams = createParameter(false);
    final BgpParameters addPathParams = createParameter(true);
    configurePeer(PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
    final BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
    configurePeer(PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
    final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
    configurePeer(PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
    final BGPSessionImpl session3 = createPeerSession(PEER3, nonAddPathParams, new SimpleSessionListener());
    final SimpleSessionListener listener4 = new SimpleSessionListener();
    configurePeer(PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
    final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
    final SimpleSessionListener listener5 = new SimpleSessionListener();
    configurePeer(PEER5, this.ribImpl, addPathParams, PeerRole.RrClient, this.serverRegistry);
    final BGPSessionImpl session5 = createPeerSession(PEER5, addPathParams, listener5);
    checkPeersPresentOnDataStore(5);
    // new best route so far
    sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 1);
    checkReceivedMessages(listener4, 1);
    checkReceivedMessages(listener5, 1);
    assertEquals(UPD_100, listener5.getListMsg().get(0));
    final SimpleSessionListener listener6 = new SimpleSessionListener();
    configurePeer(PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient, this.serverRegistry);
    final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
    checkPeersPresentOnDataStore(6);
    checkReceivedMessages(listener6, 1);
    assertEquals(UPD_NA_100, listener6.getListMsg().get(0));
    session6.close();
    checkPeersPresentOnDataStore(5);
    // the second best route
    sendRouteAndCheckIsOnLocRib(session2, PREFIX1, 50, 2);
    checkReceivedMessages(listener4, 1);
    checkReceivedMessages(listener5, 2);
    assertEquals(UPD_50, listener5.getListMsg().get(1));
    // new best route
    sendRouteAndCheckIsOnLocRib(session3, PREFIX1, 200, 2);
    checkReceivedMessages(listener4, 2);
    checkReceivedMessages(listener5, 3);
    assertEquals(UPD_200, listener5.getListMsg().get(2));
    // the worst prefix, no changes
    sendRouteAndCheckIsOnLocRib(session2, PREFIX1, 20, 2);
    checkReceivedMessages(listener4, 2);
    checkReceivedMessages(listener5, 3);
    // withdraw second best route, 2 advertisement (1 withdrawal) for add-path supported, none for non add path
    sendWithdrawalRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 2);
    checkReceivedMessages(listener4, 2);
    checkReceivedMessages(listener5, 5);
    // we advertise again to try new test
    sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 2);
    checkReceivedMessages(listener4, 2);
    checkReceivedMessages(listener5, 6);
    // withdraw second best route, 2 advertisement (1 withdrawal) for add-path supported, 1 withdrawal for non add path
    sendWithdrawalRouteAndCheckIsOnLocRib(session3, PREFIX1, 200, 2);
    checkReceivedMessages(listener4, 3);
    checkReceivedMessages(listener5, 8);
    session1.close();
    session2.close();
    session3.close();
    session4.close();
    session5.close();
}
Also used : BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters) Test(org.junit.Test)

Example 38 with Bgp

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project bgpcep by opendaylight.

the class BGPSynchronization method updReceived.

/**
 * For each received Update message, the upd sync variable needs to be updated to true, for particular AFI/SAFI
 * combination. Currently we only assume Unicast SAFI. From the Update message we have to extract the AFI. Each
 * Update message can contain BGP Object with one type of AFI. If the object is BGP Link, BGP Node or a BGPPrefix
 * the AFI is Linkstate. In case of BGPRoute, the AFI depends on the IP Address of the prefix.
 *
 * @param msg received Update message
 */
public void updReceived(final Update msg) {
    TablesKey type = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
    boolean isEOR = false;
    if (msg.getNlri() == null && msg.getWithdrawnRoutes() == null) {
        if (msg.getAttributes() != null) {
            if (msg.getAttributes().getAugmentation(Attributes1.class) != null) {
                final Attributes1 pa = msg.getAttributes().getAugmentation(Attributes1.class);
                if (pa.getMpReachNlri() != null) {
                    type = new TablesKey(pa.getMpReachNlri().getAfi(), pa.getMpReachNlri().getSafi());
                }
            } else if (msg.getAttributes().getAugmentation(Attributes2.class) != null) {
                final Attributes2 pa = msg.getAttributes().getAugmentation(Attributes2.class);
                if (pa.getMpUnreachNlri() != null) {
                    type = new TablesKey(pa.getMpUnreachNlri().getAfi(), pa.getMpUnreachNlri().getSafi());
                }
                if (pa.getMpUnreachNlri().getWithdrawnRoutes() == null) {
                    // EOR message contains only MPUnreach attribute and no NLRI
                    isEOR = true;
                }
            }
        } else {
            // true for empty Update Message
            isEOR = true;
        }
    }
    syncType(type, isEOR);
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey) Attributes2(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes2) Attributes1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1)

Example 39 with Bgp

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp 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 40 with Bgp

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project bgpcep by opendaylight.

the class ParserTest method testBGPNode.

/*
     * TEST BGP Node
     *
     *  00 00 <- withdrawn routes length
        00 b1 <- total path attribute length (177)
        80 <- attribute flags
        0e <- attribute type code (MP reach)
        a0 <- attribute length (160)
        40 04 <- AFI (16388 - Linkstate)
        47 <- SAFI (71 - Linkstate)
        04 <- next hop length
        19 19 19 01 - nexthop (25.25.25.1)
        00 <- reserved

        00 01 <- NLRI type (1 - nodeNLRI)
        00 31 <- NLRI length (49)
        03 <- ProtocolID - OSPF
        00 00 00 00 00 00 00 01 <- identifier
        01 00 <- local node descriptor type (256)
        00 24 <- length (36)
        02 00 <- node descriptor type (member AS - 512)
        00 04 <- length
        00 00 00 64 <- value (100)
        02 01 <- node descriptor type (bgpId - 513)
        00 04 <- length
        19 19 19 01 <- bgpId (25.25.25.1)
        02 02 <- node descriptor type (areaId - 514)
        00 04 <- length
        00 00 00 00 <- value
        02 03 <- node descriptor type (routeId - 515)
        00 08 <- length
        03 03 03 04 0b 0b 0b 03 <- OSPF Router Id

        00 01 <- NLRI type (1 - nodeNLRI)
        00 2d <- NLRI length (45)
        03 <- ProtocolID - OSPF
        00 00 00 00 00 00 00 01 <- identifier
        01 00 <- local node descriptor type (256)
        00 20 <- length (32)
        02 00 <- node descriptor type (member AS - 512)
        00 04 <- length
        00 00 00 64 <- value (100)
        02 01 <- node descriptor type (bgpId - 513)
        00 04 <- length
        19 19 19 01 <- bgpId (25.25.25.1)
        02 02 <- node descriptor type (areaId - 514)
        00 04 <- length
        00 00 00 00 <- value
        02 03 <- node descriptor type (routeId - 515)
        00 04 <- length
        03 03 03 04 <- OSPF Router Id

        00 01 <- NLRI type (1 - nodeNLRI)
        00 2d <- NLRI length (45)
        03 <- ProtocolID - OSPF
        00 00 00 00 00 00 00 01 <- identifier
        01 00 <- local node descriptor type (256)
        00 20 <- length (32)
        02 00 <- node descriptor type (member AS - 512)
        00 04 <- length
        00 00 00 64 <- value (100)
        02 01 <- node descriptor type (bgpId - 513)
        00 04 <- length
        19 19 19 01 <- bgpId (25.25.25.1)
        02 02 <- node descriptor type (areaId - 514)
        00 04 <- length
        00 00 00 00 <- value
        02 03 <- node descriptor type (routeId - 515)
        00 04 <- length
        01 01 01 02  <- OSPF Router Id

        40 <- attribute flags
        01 <- attribute type (Origin)
        01 <- attribute length
        00 <- value (IGP)
        40 <- attribute flags
        02 <- attribute type (AS Path)
        00 <- length
        40 <- attribute flags
        05 <- attribute type (local pref)
        04 <- length
        00 00 00 64 <- value
     */
@Test
public void testBGPNode() throws Exception {
    final byte[] body = ByteArray.cutBytes(inputBytes.get(2), MessageUtil.COMMON_HEADER_LENGTH);
    final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
    final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
    final UpdateBuilder builder = new UpdateBuilder();
    // check fields
    assertNull(message.getWithdrawnRoutes());
    // attributes
    final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
    final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
    clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
    clBuilder.setProtocolId(ProtocolId.Ospf);
    final NodeDescriptorsBuilder n = new NodeDescriptorsBuilder();
    n.setAsNumber(new AsNumber((long) 100)).setDomainId(new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
    final List<CLinkstateDestination> linkstates = Lists.newArrayList();
    final NodeCaseBuilder nCase = new NodeCaseBuilder();
    nCase.setNodeDescriptors(n.setCRouterIdentifier(new OspfPseudonodeCaseBuilder().setOspfPseudonode(new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
    linkstates.add(clBuilder.setObjectType(nCase.build()).build());
    nCase.setNodeDescriptors(n.setCRouterIdentifier(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
    linkstates.add(clBuilder.setObjectType(nCase.build()).build());
    nCase.setNodeDescriptors(n.setCRouterIdentifier(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
    linkstates.add(clBuilder.setObjectType(nCase.build()).build());
    final Attributes1Builder lsBuilder = new Attributes1Builder();
    final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
    mpBuilder.setAfi(LinkstateAddressFamily.class);
    mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
    mpBuilder.setCNextHop(nextHop);
    final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
    dBuilder.setCLinkstateDestination(linkstates);
    mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
    lsBuilder.setMpReachNlri(mpBuilder.build());
    // check path attributes
    final Attributes attrs = message.getAttributes();
    final AttributesBuilder paBuilder = new AttributesBuilder();
    paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
    assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
    paBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
    assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
    paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
    assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
    paBuilder.addAugmentation(Attributes1.class, lsBuilder.build());
    paBuilder.setUnrecognizedAttributes(Collections.emptyList());
    final MpReachNlri mp = attrs.getAugmentation(Attributes1.class).getMpReachNlri();
    assertEquals(mpBuilder.getAfi(), mp.getAfi());
    assertEquals(mpBuilder.getSafi(), mp.getSafi());
    assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
    final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
    assertEquals(linkstates.size(), dests.size());
    assertEquals(linkstates, dests);
    // check API message
    builder.setAttributes(paBuilder.build());
    assertEquals(builder.build(), message);
    final ByteBuf buffer = Unpooled.buffer();
    ParserTest.updateParser.serializeMessage(message, buffer);
    assertArrayEquals(inputBytes.get(2), ByteArray.readAllBytes(buffer));
}
Also used : NodeCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.object.type.NodeCaseBuilder) OspfNodeCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.identifier.c.router.identifier.OspfNodeCaseBuilder) 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) CLinkstateDestinationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.destination.CLinkstateDestinationBuilder) DestinationLinkstateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) UpdateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.UpdateBuilder) Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update) DestinationLinkstateCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCaseBuilder) ByteBuf(io.netty.buffer.ByteBuf) AsPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder) OspfInterfaceIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.OspfInterfaceIdentifier) AreaIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.AreaIdentifier) Ipv4InterfaceIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Ipv4InterfaceIdentifier) Identifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Identifier) DomainIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.DomainIdentifier) Ipv4NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder) OspfNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder) OspfPseudonodeCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.identifier.c.router.identifier.OspfPseudonodeCaseBuilder) OspfNodeCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.identifier.c.router.identifier.OspfNodeCaseBuilder) CLinkstateDestination(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.destination.CLinkstateDestination) OspfPseudonodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonodeBuilder) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) DomainIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.DomainIdentifier) Attributes1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1) Ipv4NextHopCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) LocalNodeDescriptorsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.object.type.link._case.LocalNodeDescriptorsBuilder) NodeDescriptorsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.object.type.node._case.NodeDescriptorsBuilder) RemoteNodeDescriptorsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.object.type.link._case.RemoteNodeDescriptorsBuilder) 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) 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) AreaIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.AreaIdentifier) OspfInterfaceIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.OspfInterfaceIdentifier) LinkAttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributesBuilder) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder) MpReachNlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri) Test(org.junit.Test)

Aggregations

BigInteger (java.math.BigInteger)18 Test (org.junit.Test)17 ByteBuf (io.netty.buffer.ByteBuf)16 ArrayList (java.util.ArrayList)16 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)16 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)11 VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)10 ExecutionException (java.util.concurrent.ExecutionException)9 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)9 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)9 Bgp (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp)7 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters)7 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)7 List (java.util.List)6 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)6 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)5 Neighbors (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Neighbors)5 Collections (java.util.Collections)4