use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.GracefulRestart 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();
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.GracefulRestart in project bgpcep by opendaylight.
the class NeighborUtilTest method buildAfisSafisState.
@Test
public void buildAfisSafisState() {
assertEquals(Collections.emptyList(), NeighborUtil.buildAfisSafisState(this.bgpAfiSafiState, this.tableRegistry));
final GracefulRestart graceful = new GracefulRestartBuilder().setState(new StateBuilder().addAugmentation(NeighborAfiSafiGracefulRestartStateAugmentation.class, new NeighborAfiSafiGracefulRestartStateAugmentationBuilder().setAdvertised(false).setReceived(false).build()).build()).build();
final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.State afiSafiState = new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.StateBuilder().addAugmentation(NeighborAfiSafiStateAugmentation.class, new NeighborAfiSafiStateAugmentationBuilder().setActive(false).build()).build();
this.afiSafi = Optional.of(IPV4UNICAST.class);
final AfiSafi expected = new AfiSafiBuilder().setAfiSafiName(this.afiSafi.get()).setState(afiSafiState).setGracefulRestart(graceful).build();
assertEquals(Collections.singletonList(expected), NeighborUtil.buildAfisSafisState(this.bgpAfiSafiState, this.tableRegistry));
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.GracefulRestart in project bgpcep by opendaylight.
the class StateProviderImplTest method buildGracefulRestart.
private GracefulRestart buildGracefulRestart() {
final NeighborGracefulRestartStateAugmentationBuilder gracefulAugmentation = new NeighborGracefulRestartStateAugmentationBuilder();
gracefulAugmentation.setPeerRestarting(false);
gracefulAugmentation.setLocalRestarting(false);
gracefulAugmentation.setPeerRestartTime(0);
gracefulAugmentation.setLocalRestarting(true).setPeerRestarting(true).setPeerRestartTime(this.restartTime);
final GracefulRestart gracefulRestart = new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.graceful.restart.GracefulRestartBuilder().setState(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.graceful.restart.graceful.restart.StateBuilder().addAugmentation(NeighborGracefulRestartStateAugmentation.class, gracefulAugmentation.build()).build()).build();
return gracefulRestart;
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.GracefulRestart in project bgpcep by opendaylight.
the class StateProviderImplTest method testActiveStateProvider.
@Test
public void testActiveStateProvider() throws Exception {
doReturn(true).when(this.bgpRibState).isActive();
doReturn(true).when(this.bgpPeerState).isActive();
final StateProviderImpl stateProvider = new StateProviderImpl(getDataBroker(), 1, this.tableTypeRegistry, this.stateCollector, "global-bgp");
stateProvider.init();
final Global globalExpected = buildGlobalExpected(0);
this.bgpRibStates.add(this.bgpRibState);
readDataOperational(getDataBroker(), this.bgpInstanceIdentifier, bgpRib -> {
final Global global = bgpRib.getGlobal();
assertEquals(globalExpected, global);
return bgpRib;
});
this.totalPathsCounter.increment();
this.totalPrefixesCounter.increment();
final Global globalExpected2 = buildGlobalExpected(1);
readDataOperational(getDataBroker(), this.bgpInstanceIdentifier, bgpRib -> {
final Global global = bgpRib.getGlobal();
assertEquals(globalExpected2, global);
return bgpRib;
});
this.totalPathsCounter.decrement();
this.totalPrefixesCounter.decrement();
final Global globalExpected3 = buildGlobalExpected(0);
readDataOperational(getDataBroker(), this.bgpInstanceIdentifier, bgpRib -> {
final Global global = bgpRib.getGlobal();
assertEquals(globalExpected3, global);
Assert.assertNull(bgpRib.getNeighbors());
Assert.assertNull(bgpRib.getPeerGroups());
return bgpRib;
});
this.bgpPeerStates.add(this.bgpPeerState);
final PeerGroup peerGroupExpected = buildGroupExpected();
this.totalPathsCounter.increment();
this.totalPrefixesCounter.increment();
final AfiSafis expectedAfiSafis = buildAfiSafis();
final ErrorHandling expectedErrorHandling = buildErrorHandling();
final GracefulRestart expectedGracefulRestart = buildGracefulRestart();
final Transport expectedTransport = buildTransport();
final Timers expectedTimers = buildTimers();
final BgpNeighborStateAugmentation expectedBgpNeighborState = buildBgpNeighborStateAugmentation();
readDataOperational(getDataBroker(), this.bgpInstanceIdentifier, bgpRib -> {
final Neighbors neighbors = bgpRib.getNeighbors();
Assert.assertNotNull(neighbors);
assertEquals(peerGroupExpected, bgpRib.getPeerGroups().getPeerGroup().get(0));
final Neighbor neighborResult = neighbors.getNeighbor().get(0);
assertEquals(this.neighborAddress, neighborResult.getNeighborAddress());
assertEquals(expectedAfiSafis, neighborResult.getAfiSafis());
assertEquals(expectedErrorHandling, neighborResult.getErrorHandling());
assertEquals(expectedGracefulRestart, neighborResult.getGracefulRestart());
assertEquals(expectedTransport, neighborResult.getTransport());
assertEquals(expectedTimers, neighborResult.getTimers());
final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.State stateResult = neighborResult.getState();
assertEquals(expectedBgpNeighborState, stateResult.getAugmentation(BgpNeighborStateAugmentation.class));
assertEquals(BgpNeighborState.SessionState.ESTABLISHED, stateResult.getAugmentation(NeighborStateAugmentation.class).getSessionState());
final List<Class<? extends BgpCapability>> supportedCapabilitiesResult = stateResult.getAugmentation(NeighborStateAugmentation.class).getSupportedCapabilities();
Assert.assertTrue(supportedCapabilitiesResult.containsAll(this.supportedCap));
return bgpRib;
});
this.bgpRibStates.clear();
checkNotPresentOperational(getDataBroker(), this.bgpInstanceIdentifier);
stateProvider.close();
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.GracefulRestart in project netvirt by opendaylight.
the class BgpConfigurationManager method replay.
@SuppressWarnings("checkstyle:IllegalCatch")
public synchronized boolean replay() throws InterruptedException, TimeoutException, ExecutionException {
boolean replaySucceded = true;
String host = getConfigHost();
int port = getConfigPort();
LOG.error("connecting to bgp host {} ", host);
boolean res = bgpRouter.connect(host, port);
if (!res) {
LOG.error("Cannot connect to BGP config server at {}:{}{}", host, port, config != null ? "; Configuration Replay aborted" : "");
return replaySucceded;
}
config = getConfig();
if (config == null) {
LOG.error("bgp config is empty nothing to push to bgp");
return replaySucceded;
}
BgpRouter br = bgpRouter;
AsId asId = config.getAsId();
if (asId == null) {
LOG.error("bgp as-id is null");
return replaySucceded;
}
long asNum = asId.getLocalAs();
IpAddress routerId = asId.getRouterId();
String rid = routerId == null ? "" : new String(routerId.getValue());
int stalepathTime = (int) getStalePathtime(RESTART_DEFAULT_GR, config.getAsId());
boolean announceFbit = true;
boolean replayDone = false;
final int numberOfStartBgpRetries = 3;
RetryOnException startBgpRetry = new RetryOnException(numberOfStartBgpRetries);
do {
try {
LOG.debug("Replaying BGPConfig ");
br.startBgp(asNum, rid, stalepathTime, announceFbit);
LOG.debug("Replay BGPConfig successful");
replayDone = true;
break;
} catch (BgpRouterException bre) {
if (bre.getErrorCode() == BgpRouterException.BGP_ERR_ACTIVE) {
LOG.debug("Starting the routesync for exception", bre);
startBgpRetry.errorOccured();
if (!startBgpRetry.shouldRetry()) {
LOG.debug("starting route sync for BgpRouter exception");
doRouteSync();
}
} else {
LOG.error("Replay: startBgp() received exception error {} : ", bre.getErrorCode(), bre);
startBgpRetry.errorOccured();
}
} catch (TApplicationException tae) {
if (tae.getType() == BgpRouterException.BGP_ERR_ACTIVE) {
LOG.debug("Starting the routesync for exception", tae);
startBgpRetry.errorOccured();
if (!startBgpRetry.shouldRetry()) {
LOG.debug("starting route sync for Thrift BGP_ERR_ACTIVE exception");
doRouteSync();
}
} else if (tae.getType() == BgpRouterException.BGP_ERR_COMMON_FAILURE) {
LOG.debug("Starting the routesync for AS-ID started exception", tae);
startBgpRetry.errorOccured();
if (!startBgpRetry.shouldRetry()) {
LOG.debug("starting route sync for Thrift BGP_ERR_COMMON_FAILURE exception");
doRouteSync();
}
} else {
LOG.error("Replay: startBgp() received exception type {}: ", tae.getType(), tae);
startBgpRetry.errorOccured();
}
} catch (Exception e) {
// not unusual. We may have restarted & BGP is already on
LOG.error("Replay:startBgp() received exception: ", e);
startBgpRetry.errorOccured();
}
} while (startBgpRetry.shouldRetry());
replaySucceded = replayDone;
startBgpCountersTask();
startBgpAlarmsTask();
/*
* commenting this due to a bug with QBGP. Will uncomment once QBGP fix is done.
* This wont have any functional impacts
*/
// try {
// br.delayEOR(delayEorSeconds);
// } catch (TException | BgpRouterException e) {
// LOG.error("Replay: delayEOR() number of seconds to wait for EOR from ODL:", e);
// }
List<Neighbors> neighbors = config.getNeighbors();
if (neighbors != null) {
LOG.error("configuring existing Neighbors present for replay total neighbors {}", neighbors.size());
boolean neighborConfigReplayResult = replayNbrConfig(neighbors, br);
if (neighborConfigReplayResult == false) {
replaySucceded = false;
}
} else {
LOG.error("no Neighbors present for replay config ");
}
Logging logging = config.getLogging();
if (logging != null) {
try {
br.setLogging(logging.getFile(), logging.getLevel());
} catch (TException | BgpRouterException e) {
LOG.error("Replay:setLogging() received exception", e);
}
}
GracefulRestart gracefulRestart = config.getGracefulRestart();
if (gracefulRestart != null) {
try {
br.addGracefulRestart(gracefulRestart.getStalepathTime().intValue());
} catch (TException | BgpRouterException e) {
LOG.error("Replay:addGr() received exception", e);
}
}
List<Vrfs> vrfs = config.getVrfs();
if (vrfs == null) {
vrfs = new ArrayList<>();
}
for (Vrfs vrf : vrfs) {
for (AddressFamiliesVrf adf : vrf.getAddressFamiliesVrf()) {
try {
br.addVrf(BgpUtil.getLayerType(adf), vrf.getRd(), vrf.getImportRts(), vrf.getExportRts());
} catch (TException | BgpRouterException e) {
LOG.error("Replay:addVrf() received exception", e);
}
}
}
List<Networks> ln = config.getNetworks();
if (ln != null) {
for (Networks net : ln) {
String rd = net.getRd();
String pfxlen = net.getPrefixLen();
String nh = net.getNexthop().getValue();
Long label = net.getLabel();
int lbl = label == null ? 0 : label.intValue();
int l3vni = net.getL3vni() == null ? 0 : net.getL3vni().intValue();
int l2vni = net.getL2vni() == null ? 0 : net.getL2vni().intValue();
if (rd == null && lbl > 0) {
// LU prefix is being deleted.
rd = Integer.toString(lbl);
}
BgpControlPlaneType protocolType = net.getBgpControlPlaneType();
int ethernetTag = net.getEthtag().intValue();
String esi = net.getEsi();
String macaddress = net.getMacaddress();
EncapType encapType = net.getEncapType();
String routerMac = net.getRoutermac();
try {
br.addPrefix(rd, pfxlen, nh, lbl, l3vni, l2vni, BgpUtil.convertToThriftProtocolType(protocolType), ethernetTag, esi, macaddress, BgpUtil.convertToThriftEncapType(encapType), routerMac);
} catch (TException | BgpRouterException e) {
LOG.error("Replay:addPfx() received exception", e);
}
}
}
List<Multipath> multipaths = config.getMultipath();
if (multipaths != null) {
for (Multipath multipath : multipaths) {
if (multipath != null) {
af_afi afi = af_afi.findByValue(multipath.getAfi().intValue());
af_safi safi = af_safi.findByValue(multipath.getSafi().intValue());
try {
if (multipath.isMultipathEnabled()) {
br.enableMultipath(afi, safi);
} else {
br.disableMultipath(afi, safi);
}
} catch (TException | BgpRouterException e) {
LOG.info("Replay:multipaths() received exception", e);
}
}
}
}
List<VrfMaxpath> vrfMaxpaths = config.getVrfMaxpath();
if (vrfMaxpaths != null) {
for (VrfMaxpath vrfMaxpath : vrfMaxpaths) {
try {
br.multipaths(vrfMaxpath.getRd(), vrfMaxpath.getMaxpaths());
} catch (TException | BgpRouterException e) {
LOG.info("Replay:vrfMaxPath() received exception", e);
}
}
}
// send End of Rib Marker to Qthriftd.
final int numberOfEORRetries = 3;
replayDone = false;
RetryOnException eorRetry = new RetryOnException(numberOfEORRetries);
do {
try {
br.sendEOR();
LOG.debug("Replay sendEOR {} successful");
replayDone = true;
break;
} catch (Exception e) {
eorRetry.errorOccured();
LOG.error("Replay:sedEOR() received exception:", e);
}
} while (eorRetry.shouldRetry());
return replaySucceded && replayDone;
}
Aggregations