use of org.opendaylight.netvirt.bgpmanager.thrift.client.BgpRouter 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