Search in sources :

Example 21 with BGP

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP in project netvirt by opendaylight.

the class VpnSubnetRouteHandler method addSubnetRouteToFib.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private boolean addSubnetRouteToFib(String rd, String subnetIp, BigInteger nhDpnId, String nextHopIp, String vpnName, Long elanTag, long label, long l3vni, Uuid subnetId, boolean isBgpVpn, String networkName) {
    Preconditions.checkNotNull(rd, LOGGING_PREFIX + " addSubnetRouteToFib: RouteDistinguisher cannot be null or empty!");
    Preconditions.checkNotNull(subnetIp, LOGGING_PREFIX + " addSubnetRouteToFib: SubnetRouteIp cannot be null or empty!");
    Preconditions.checkNotNull(vpnName, LOGGING_PREFIX + " addSubnetRouteToFib: vpnName cannot be null or empty!");
    Preconditions.checkNotNull(elanTag, LOGGING_PREFIX + " addSubnetRouteToFib: elanTag cannot be null or empty!");
    Preconditions.checkNotNull(label, LOGGING_PREFIX + " addSubnetRouteToFib: label cannot be null or empty!");
    VrfEntry.EncapType encapType = VpnUtil.getEncapType(VpnUtil.isL3VpnOverVxLan(l3vni));
    VpnPopulator vpnPopulator = L3vpnRegistry.getRegisteredPopulator(encapType);
    LOG.info("{} addSubnetRouteToFib: Adding SubnetRoute fib entry for vpnName {}, subnetIP {}, elanTag {}", LOGGING_PREFIX, vpnName, subnetIp, elanTag);
    L3vpnInput input = new L3vpnInput().setRouteOrigin(RouteOrigin.CONNECTED).setRd(rd).setVpnName(vpnName).setSubnetIp(subnetIp).setNextHopIp(nextHopIp).setL3vni(l3vni).setLabel(label).setElanTag(elanTag).setDpnId(nhDpnId).setEncapType(encapType).setNetworkName(networkName).setPrimaryRd(rd);
    if (!isBgpVpn) {
        vpnPopulator.populateFib(input, null);
        return true;
    }
    Preconditions.checkNotNull(nextHopIp, LOGGING_PREFIX + "NextHopIp cannot be null or empty!");
    VpnUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(VpnUtil.getVpnId(dataBroker, vpnName), subnetIp), VpnUtil.getPrefixToInterface(nhDpnId, subnetId.getValue(), subnetIp, subnetId, Prefixes.PrefixCue.SubnetRoute));
    vpnPopulator.populateFib(input, null);
    try {
        // BGP manager will handle withdraw and advertise internally if prefix
        // already exist
        bgpManager.advertisePrefix(rd, null, /*macAddress*/
        subnetIp, Collections.singletonList(nextHopIp), encapType, label, l3vni, 0, /*l2vni*/
        null);
    } catch (Exception e) {
        LOG.error("{} addSubnetRouteToFib: Subnet route not advertised for subnet {} subnetIp {} vpnName {} rd {} " + "with dpnid {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, rd, nhDpnId, e);
        return false;
    }
    return true;
}
Also used : VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VpnPopulator(org.opendaylight.netvirt.vpnmanager.populator.intfc.VpnPopulator) L3vpnInput(org.opendaylight.netvirt.vpnmanager.populator.input.L3vpnInput)

Example 22 with BGP

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP in project netvirt by opendaylight.

the class VpnSubnetRouteHandler method onPortAddedToSubnet.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void onPortAddedToSubnet(Subnetmap subnetmap, Uuid portId) {
    Uuid subnetId = subnetmap.getId();
    LOG.info("{} onPortAddedToSubnet: Port {} being added to subnet {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue());
    // TODO(vivek): Change this to use more granularized lock at subnetId level
    try {
        VpnUtil.lockSubnet(lockManager, subnetId.getValue());
        try {
            InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
            Optional<SubnetOpDataEntry> optionalSubs = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
            if (!optionalSubs.isPresent()) {
                LOG.info("{} onPortAddedToSubnet: Port {} is part of a subnet {} that is not in VPN, ignoring", LOGGING_PREFIX, portId.getValue(), subnetId.getValue());
                return;
            }
            String vpnName = optionalSubs.get().getVpnName();
            String subnetIp = optionalSubs.get().getSubnetCidr();
            String rd = optionalSubs.get().getVrfId();
            String routeAdvState = optionalSubs.get().getRouteAdvState().toString();
            LOG.info("{} onPortAddedToSubnet: Port {} being added to subnet {} subnetIp {} vpnName {} rd {} " + "TaskState {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd, routeAdvState);
            subOpDpnManager.addPortOpDataEntry(portId.getValue(), subnetId, null);
            Interface intfState = InterfaceUtils.getInterfaceStateFromOperDS(dataBroker, portId.getValue());
            if (intfState == null) {
                // Interface State not yet available
                return;
            }
            final BigInteger dpnId;
            try {
                dpnId = InterfaceUtils.getDpIdFromInterface(intfState);
            } catch (Exception e) {
                LOG.error("{} onPortAddedToSubnet: Unable to obtain dpnId for interface {}. subnetroute inclusion" + " for this interface failed for subnet {} subnetIp {} vpn {} rd {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd, e);
                return;
            }
            if (dpnId.equals(BigInteger.ZERO)) {
                LOG.error("{} onPortAddedToSubnet: Port {} is not assigned DPN yet, ignoring subnetRoute " + "inclusion for the interface into subnet {} subnetIp {} vpnName {} rd {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd);
                return;
            }
            subOpDpnManager.addPortOpDataEntry(portId.getValue(), subnetId, dpnId);
            if (intfState.getOperStatus() != OperStatus.Up) {
                LOG.error("{} onPortAddedToSubnet: Port {} is not UP yet, ignoring subnetRoute inclusion for " + "the interface into subnet {} subnetIp {} vpnName {} rd {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd);
                return;
            }
            LOG.debug("{} onPortAddedToSubnet: Port {} added. Updating the SubnetOpDataEntry node for subnet {} " + "subnetIp {} vpnName {} rd {} TaskState {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd, routeAdvState);
            SubnetToDpn subDpn = subOpDpnManager.addInterfaceToDpn(subnetId, dpnId, portId.getValue());
            if (subDpn == null) {
                LOG.error("{} onPortAddedToSubnet: subnet-to-dpn list is null for subnetId {}. portId {}, " + "vpnName {}, rd {}, subnetIp {}", LOGGING_PREFIX, subnetId.getValue(), portId.getValue(), vpnName, rd, subnetIp);
                return;
            }
            SubnetOpDataEntry subnetOpDataEntry = optionalSubs.get();
            SubnetOpDataEntryBuilder subOpBuilder = new SubnetOpDataEntryBuilder(subnetOpDataEntry);
            List<SubnetToDpn> subDpnList = subOpBuilder.getSubnetToDpn();
            subDpnList.add(subDpn);
            subOpBuilder.setSubnetToDpn(subDpnList);
            if (subOpBuilder.getRouteAdvState() != TaskState.Advertised) {
                if (subOpBuilder.getNhDpnId() == null) {
                    // No nexthop selected yet, elect one now
                    electNewDpnForSubnetRoute(subOpBuilder, null, /* oldDpnId */
                    subnetId, subnetmap.getNetworkId(), true);
                } else if (!VpnUtil.isExternalSubnetVpn(subnetOpDataEntry.getVpnName(), subnetId.getValue())) {
                    // Already nexthop has been selected, only publishing to bgp required, so publish to bgp
                    getNexthopTepAndPublishRoute(subOpBuilder, subnetId);
                }
            }
            SubnetOpDataEntry subOpEntry = subOpBuilder.build();
            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpEntry);
            LOG.info("{} onPortAddedToSubnet: Updated subnetopdataentry to OP Datastore for port {} subnet {}" + " subnetIp {} vpnName {} rd {} TaskState {} lastTaskState {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subOpEntry.getSubnetCidr(), subOpEntry.getVpnName(), subOpBuilder.getVrfId(), subOpEntry.getRouteAdvState(), subOpEntry.getLastAdvState());
        } catch (Exception ex) {
            LOG.error("{} onPortAddedToSubnet: Updation of subnetOpEntry for port {} subnet {} falied", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), ex);
        } finally {
            VpnUtil.unlockSubnet(lockManager, subnetId.getValue());
        }
    } catch (Exception e) {
        LOG.error("{} onPortAddedToSubnet: Unable to handle port {} added to subnet {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), e);
    }
}
Also used : SubnetOpDataEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryBuilder) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) SubnetOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey) BigInteger(java.math.BigInteger) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) SubnetToDpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpn)

Example 23 with BGP

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP in project netvirt by opendaylight.

the class VpnSubnetRouteHandler method updateSubnetRouteOnTunnelUpEvent.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void updateSubnetRouteOnTunnelUpEvent(Uuid subnetId, BigInteger dpnId) {
    LOG.info("{} updateSubnetRouteOnTunnelUpEvent: Subnet {} Dpn {}", LOGGING_PREFIX, subnetId.getValue(), dpnId.toString());
    try {
        VpnUtil.lockSubnet(lockManager, subnetId.getValue());
        try {
            InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
            Optional<SubnetOpDataEntry> optionalSubs = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
            if (!optionalSubs.isPresent()) {
                LOG.error("{} updateSubnetRouteOnTunnelUpEvent: SubnetOpDataEntry for subnet {} is not available", LOGGING_PREFIX, subnetId.getValue());
                return;
            }
            LOG.info("{} updateSubnetRouteOnTunnelUpEvent: Subnet {} subnetIp {} vpnName {} rd {} TaskState {}" + " lastTaskState {} Dpn {}", LOGGING_PREFIX, subnetId.getValue(), optionalSubs.get().getSubnetCidr(), optionalSubs.get().getVpnName(), optionalSubs.get().getVrfId(), optionalSubs.get().getRouteAdvState(), optionalSubs.get().getLastAdvState(), dpnId.toString());
            SubnetOpDataEntry subOpEntry = optionalSubs.get();
            SubnetOpDataEntryBuilder subOpBuilder = new SubnetOpDataEntryBuilder(subOpEntry);
            boolean isExternalSubnetVpn = VpnUtil.isExternalSubnetVpn(subOpEntry.getVpnName(), subnetId.getValue());
            if (subOpBuilder.getRouteAdvState() != TaskState.Advertised) {
                if (subOpBuilder.getNhDpnId() == null) {
                    // No nexthop selected yet, elect one now
                    electNewDpnForSubnetRoute(subOpBuilder, null, /* oldDpnId */
                    subnetId, null, /*networkId*/
                    !isExternalSubnetVpn);
                } else if (!isExternalSubnetVpn) {
                    // Already nexthop has been selected, only publishing to bgp required, so publish to bgp
                    getNexthopTepAndPublishRoute(subOpBuilder, subnetId);
                }
            }
            subOpEntry = subOpBuilder.build();
            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpEntry);
            LOG.info("{} updateSubnetRouteOnTunnelUpEvent: Updated subnetopdataentry to OP Datastore tunnel up" + " on dpn {} for subnet {} subnetIp {} vpnName {} rd {} TaskState {} lastTaskState {}", LOGGING_PREFIX, dpnId.toString(), subnetId.getValue(), subOpEntry.getSubnetCidr(), subOpEntry.getVpnName(), subOpEntry.getVrfId(), subOpEntry.getRouteAdvState(), subOpEntry.getLastAdvState());
        } catch (RuntimeException ex) {
            LOG.error("{} updateSubnetRouteOnTunnelUpEvent: updating subnetRoute for subnet {} on dpn {}", LOGGING_PREFIX, subnetId.getValue(), dpnId.toString(), ex);
        } finally {
            VpnUtil.unlockSubnet(lockManager, subnetId.getValue());
        }
    } catch (RuntimeException e) {
        LOG.error("{} updateSubnetRouteOnTunnelUpEvent: Unable to handle tunnel up event for subnetId {} dpnId {}", LOGGING_PREFIX, subnetId.getValue(), dpnId.toString(), e);
    }
}
Also used : SubnetOpDataEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryBuilder) SubnetOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry)

Example 24 with BGP

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP in project bgpcep by opendaylight.

the class AbstractBGPDispatcherTest method createServer.

Channel createServer(final InetSocketAddress serverAddress) {
    this.registry.addPeer(new IpAddress(new Ipv4Address(serverAddress.getAddress().getHostAddress())), this.serverListener, createPreferences(serverAddress));
    LoggerFactory.getLogger(AbstractBGPDispatcherTest.class).info("createServer");
    final ChannelFuture future = this.serverDispatcher.createServer(serverAddress);
    future.addListener(future1 -> Preconditions.checkArgument(future1.isSuccess(), "Unable to start bgp server on %s", future1.cause()));
    waitFutureSuccess(future);
    return future.channel();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 25 with BGP

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.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)

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