package org.opendaylight.netvirt.bgpmanager;
import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.net.InetAddresses;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.netty.util.concurrent.GlobalEventExecutor;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Nullable;
import org.apache.thrift.TApplicationException;
import org.apache.thrift.TException;
import org.apache.thrift.transport.TTransport;
-import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.tcp.security.option.grouping.tcp.security.option.TcpMd5SignatureOption;
import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.tcp.security.option.grouping.tcp.security.option.TcpMd5SignatureOptionBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// to have stale FIB map (RD, Prefix)
// number of seconds wait for route sync-up between ODL and BGP
private static final int BGP_RESTART_ROUTE_SYNC_SEC = 600;
- private static final String DEF_LOGFILE = "/var/log/bgp_debug.log";
- private static final String DEF_LOGLEVEL = "errors";
private static final String UPDATE_PORT = "bgp.thrift.service.port";
private static final String CONFIG_HOST = "vpnservice.bgpspeaker.host.name";
private static final String CONFIG_PORT = "vpnservice.bgpspeaker.thrift.port";
private static final String DEF_UPORT = "6644";
private static final String DEF_CHOST = "255.255.255.255"; // Invalid Host IP
- private static final String DEF_CPORT = "0"; // Invalid Port
+ private static final String DEF_CPORT = "7644";
private static final String DEF_BGP_SDNC_MIP = "127.0.0.1";
- private static final String BGP_SDNC_MIP = "vpnservice.bgp.thrift.sdnc.mip";
+ //vpnservice.bgp.thrift.bgp.mip is the MIP present with ODL. Here we open 6644 port
+ private static final String BGP_SDNC_MIP = "vpnservice.bgp.thrift.bgp.mip";
private static final int RESTART_DEFAULT_GR = 90;
private static final int DS_RETRY_COUNT = 100; //100 retries, each after WAIT_TIME_BETWEEN_EACH_TRY_MILLIS seconds
private static final long WAIT_TIME_BETWEEN_EACH_TRY_MILLIS = 1000L; //one second sleep after every retry
private static final String BGP_ENTITY_TYPE_FOR_OWNERSHIP = "bgp";
+ private static final String BGP_EOR_DELAY = "vpnservice.bgp.eordelay";
+ private static final String DEF_BGP_EOR_DELAY = "1800";
private static final String BGP_ENTITY_NAME = "bgp";
private static final String ADD_WARN = "Config store updated; undo with Delete if needed.";
private static final String DEL_WARN = "Config store updated; undo with Add if needed.";
private volatile Bgp config;
private final BgpRouter bgpRouter;
private final BgpSyncHandle bgpSyncHandle = new BgpSyncHandle();
- private BgpThriftService updateServer;
+ private volatile BgpThriftService bgpThriftService = null;
+ private final int delayEorSeconds;
private final CountDownLatch initer = new CountDownLatch(1);
final IVpnLinkService vpnLinkSrvce,
final BundleContext bundleContext,
final BgpUtil bgpUtil,
- final MetricProvider metricProvider)
- throws InterruptedException, ExecutionException, TimeoutException {
+ final MetricProvider metricProvider) {
this.dataBroker = dataBroker;
this.fibDSWriter = fibDSWriter;
this.vpnLinkService = vpnLinkSrvce;
this.bundleContext = bundleContext;
this.bgpUtil = bgpUtil;
this.metricProvider = metricProvider;
- String updatePort = getProperty(UPDATE_PORT, DEF_UPORT);
hostStartup = getProperty(CONFIG_HOST, DEF_CHOST);
portStartup = getProperty(CONFIG_PORT, DEF_CPORT);
- LOG.info("UpdateServer at localhost:" + updatePort + " ConfigServer at "
- + hostStartup + ":" + portStartup);
+ LOG.info("ConfigServer at {}:{}", hostStartup, portStartup);
VtyshCli.setHostAddr(hostStartup);
ClearBgpCli.setHostAddr(hostStartup);
bgpRouter = BgpRouter.newInstance(this::getConfig, this::isBGPEntityOwner);
- registerCallbacks();
+ delayEorSeconds = Integer.parseInt(getProperty(BGP_EOR_DELAY, DEF_BGP_EOR_DELAY));
entityOwnershipUtils = new EntityOwnershipUtils(entityOwnershipService);
candidateRegistration = registerEntityCandidate(entityOwnershipService);
entityListenerRegistration = registerEntityListener(entityOwnershipService);
+ /*register callbacks for reactors, shall be called after EoS registration.
+ * as listeners user EoS service to identify Owner node. Listener call-backs
+ * can get triggered immediately after registeration (before EoS register complete)
+ */
+ registerCallbacks();
+
LOG.info("BGP Configuration manager initialized");
initer.countDown();
GlobalEventExecutor.INSTANCE.execute(() -> {
- final WaitingServiceTracker<IBgpManager> tracker = WaitingServiceTracker.create(
- IBgpManager.class, bundleContext);
- bgpManager = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
- updateServer = new BgpThriftService(Integer.parseInt(updatePort), bgpManager, this);
- updateServer.start();
+ ServiceTracker<IBgpManager, ?> tracker = null;
+ try {
+ tracker = new ServiceTracker<>(bundleContext, IBgpManager.class, null);
+ tracker.open();
+ bgpManager = (IBgpManager) tracker.waitForService(TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES));
+ Preconditions.checkState(bgpManager != null, "IBgpManager service not found");
+ } catch (InterruptedException e) {
+ throw new IllegalStateException("Error retrieving IBgpManager service", e);
+ } finally {
+ if (tracker != null) {
+ tracker.close();
+ }
+ }
+
+ String updatePort = getProperty(UPDATE_PORT, DEF_UPORT);
+ if (InetAddresses.isInetAddress(getBgpSdncMipIp())) {
+ InetSocketAddress bgpThriftServerSocketAddr = new InetSocketAddress(getBgpSdncMipIp(),
+ Integer.parseInt(updatePort));
+ bgpThriftService = new BgpThriftService(bgpThriftServerSocketAddr, bgpManager, this);
+ if (isBGPEntityOwner()) {
+ //I am EoS owner of BGP, opening bgp thrift UPDATE-SERVER port.
+ LOG.info("BGP Configuration manager initialized: UPDATE-SERVER started");
+ bgpThriftService.start();
+ }
+ LOG.info("UPDATE server started :ip:port={}:{}", getBgpSdncMipIp(), updatePort);
+ } else {
+ LOG.error("Failed to init UPDATE server invalid ip:port={}:{}", getBgpSdncMipIp(), updatePort);
+ }
LOG.info("BgpConfigurationManager initialized. IBgpManager={}", bgpManager);
});
}
public void close() {
executor.shutdown();
- if (updateServer != null) {
- updateServer.stop();
+ if (bgpThriftService != null) {
+ bgpThriftService.stop();
+ bgpThriftService = null;
+ }
+
+ if (isBgpConnected()) {
+ //disconnect the CONFIG SERVER port (which was )opened during I was Owner
+ bgpRouter.disconnect();
}
if (candidateRegistration != null) {
if (ownershipChange.getState() == EntityOwnershipChangeState.LOCAL_OWNERSHIP_GRANTED) {
LOG.trace("This PL is the Owner");
- activateMIP();
+ if (bgpThriftService != null) {
+ //opening UPDATE-SERVER port.
+ bgpThriftService.start();
+ } else {
+ LOG.error("I am the owner of BGP entity, but bgpThriftService is not initialized yet");
+ }
bgpRestarted();
} else {
LOG.debug("Not owner: hasOwner: {}, isOwner: {}", ownershipChange.getState().hasOwner(),
ownershipChange.getState().isOwner());
+ if (bgpThriftService != null && bgpThriftService.isBgpThriftServiceStarted()) {
+ //close the bgp Thrift Update-SERVER port opened on non-Entity Owner
+ bgpThriftService.stop();
+ bgpThriftService = null;
+ }
+ if (isBgpConnected()) {
+ //disconnect the CONFIG SERVER port (which was )opened during I was Owner
+ bgpRouter.disconnect();
+ }
}
});
}
public boolean isBGPEntityOwner() {
+ if (entityOwnershipUtils == null) {
+ LOG.error("entityOwnershipUtils is NULL when listener callbacks fired");
+ return false;
+ }
return entityOwnershipUtils.isEntityOwner(new Entity(BGP_ENTITY_TYPE_FOR_OWNERSHIP, BGP_ENTITY_NAME), 0, 1);
}
bgpRouter.configServerUpdated();
synchronized (BgpConfigurationManager.this) {
+ Bgp conf = getConfig();
+ if (conf != null) {
+ AsId asId = conf.getAsId();
+ if (asId != null) {
+ long asNum = asId.getLocalAs();
+ try {
+ bgpRouter.stopBgp(asNum);
+ stopBgpCountersTask();
+ stopBgpAlarmsTask();
+ } catch (TException | BgpRouterException e) {
+ LOG.error("{} Delete received exception; {}", YANG_OBJ, DEL_WARN, e);
+ }
+ } else {
+ LOG.debug("bgp as-id is null while removing config-server");
+ }
+ } else {
+ LOG.error("Config Null while removing the config-server");
+ }
bgpRouter.disconnect();
}
}
synchronized (BgpConfigurationManager.this) {
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.debug("{} Unable to process add for asNum {}; {}", YANG_OBJ, val.getLocalAs(),
+ LOG.debug("{} Unable to process add for asNum {}; {} {}", YANG_OBJ, val.getLocalAs(),
BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
return;
}
long asNum = val.getLocalAs();
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.debug("{} Unable to process remove for asNum {}; {}", YANG_OBJ, asNum,
+ LOG.debug("{} Unable to process remove for asNum {}; {} {}", YANG_OBJ, asNum,
BgpRouterException.BGP_ERR_NOT_INITED, DEL_WARN);
return;
}
int stalePathTime = val.getStalepathTime().intValue();
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.error("{} Unable to add stale-path time {}; {}", YANG_OBJ, stalePathTime,
+ LOG.error("{} Unable to add stale-path time {}; {} {}", YANG_OBJ, stalePathTime,
BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
return;
}
synchronized (BgpConfigurationManager.this) {
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.error("{} Unable to delete stale-path time; {}", YANG_OBJ,
+ LOG.error("{} Unable to delete stale-path time; {} {}", YANG_OBJ,
BgpRouterException.BGP_ERR_NOT_INITED, DEL_WARN);
return;
}
int stalePathTime = newval.getStalepathTime().intValue();
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.error("{} Unable to update stale-path time to {}; {}", YANG_OBJ, stalePathTime,
+ LOG.error("{} Unable to update stale-path time to {}; {} {}", YANG_OBJ, stalePathTime,
BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
return;
}
synchronized (BgpConfigurationManager.this) {
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.error("{} Unable to add logging for qbgp; {}", YANG_OBJ,
+ LOG.error("{} Unable to add logging for qbgp; {} {}", YANG_OBJ,
BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
return;
}
synchronized (BgpConfigurationManager.this) {
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.error("{} Unable to remove logging for qbgp; {}", YANG_OBJ,
+ LOG.error("{} Unable to remove logging for qbgp; {} {}", YANG_OBJ,
BgpRouterException.BGP_ERR_NOT_INITED, DEL_WARN);
return;
}
try {
- br.setLogging(DEF_LOGFILE, DEF_LOGLEVEL);
+ br.setLogging(BgpConstants.BGP_DEF_LOG_FILE, BgpConstants.BGP_DEF_LOG_LEVEL);
} catch (TException | BgpRouterException e) {
LOG.error("{} Delete received exception; {}", YANG_OBJ, DEL_WARN, e);
}
synchronized (BgpConfigurationManager.this) {
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.error("{} Unable to update logging for qbgp; {}", YANG_OBJ,
+ LOG.error("{} Unable to update logging for qbgp; {} {}", YANG_OBJ,
BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
return;
}
final String md5Secret = extractMd5Secret(val);
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.debug("{} Unable to process add for peer {} as {}; {}", YANG_OBJ, peerIp, as,
+ LOG.debug("{} Unable to process add for peer {} as {}; {} {}", YANG_OBJ, peerIp, as,
BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
return;
}
String peerIp = val.getAddress().getValue();
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.debug("{} Unable to process remove for peer {}; {}", YANG_OBJ, peerIp,
+ LOG.debug("{} Unable to process remove for peer {}; {} {}", YANG_OBJ, peerIp,
BgpRouterException.BGP_ERR_NOT_INITED, DEL_WARN);
return;
}
String peerIp = val.getPeerIp().getValue();
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.debug("{} Unable to process add for peer {}; {}", YANG_OBJ, peerIp,
+ LOG.debug("{} Unable to process add for peer {}; {} {}", YANG_OBJ, peerIp,
BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
return;
}
String peerIp = val.getPeerIp().getValue();
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.debug("{} Unable to process remove for peer {}; {}", YANG_OBJ, peerIp,
+ LOG.debug("{} Unable to process remove for peer {}; {} {}", YANG_OBJ, peerIp,
BgpRouterException.BGP_ERR_NOT_INITED, DEL_WARN);
return;
}
String peerIp = val.getPeerIp().getValue();
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.debug("{} Unable to process add for peer {}; {}", YANG_OBJ, peerIp,
+ LOG.debug("{} Unable to process add for peer {}; {} {}", YANG_OBJ, peerIp,
BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
return;
}
String peerIp = val.getPeerIp().getValue();
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.debug("{} Unable to process remove for peer {}; {}", YANG_OBJ, peerIp,
+ LOG.debug("{} Unable to process remove for peer {}; {} {}", YANG_OBJ, peerIp,
BgpRouterException.BGP_ERR_NOT_INITED, DEL_WARN);
return;
}
String peerIp = val.getPeerIp().getValue();
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.debug("{} Unable to process add for peer {}; {}", YANG_OBJ, peerIp,
+ LOG.debug("{} Unable to process add for peer {}; {} {}", YANG_OBJ, peerIp,
BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
return;
}
String peerIp = val.getPeerIp().getValue();
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.debug("{} Unable to process remove for peer {}; {}", YANG_OBJ, peerIp,
+ LOG.debug("{} Unable to process remove for peer {}; {} {}", YANG_OBJ, peerIp,
BgpRouterException.BGP_ERR_NOT_INITED, DEL_WARN);
return;
}
String nh = val.getNexthop().getValue();
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.debug("{} Unable to process add for rd {} prefix {} nexthop {}; {}", YANG_OBJ, rd, pfxlen, nh,
- BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
+ LOG.debug("{} Unable to process add for rd {} prefix {} nexthop {}; {} {}", YANG_OBJ, rd, pfxlen,
+ nh, BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
return;
}
Long label = val.getLabel();
String pfxlen = val.getPrefixLen();
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.debug("{} Unable to process remove for rd {} prefix {}; {}", YANG_OBJ, rd, pfxlen,
+ LOG.debug("{} Unable to process remove for rd {} prefix {}; {} {}", YANG_OBJ, rd, pfxlen,
BgpRouterException.BGP_ERR_NOT_INITED, DEL_WARN);
return;
}
String rd = vrfs.getRd();
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.debug("{} Unable to process add for rd {}; {}", YANG_OBJ, rd,
+ LOG.debug("{} Unable to process add for rd {}; {} {}", YANG_OBJ, rd,
BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
return;
}
List<AddressFamiliesVrf> vrfAddrFamilyList = vrfs.getAddressFamiliesVrf();
for (AddressFamiliesVrf vrfAddrFamily : vrfAddrFamilyList) {
/*add to br the new vrfs arguments*/
- br.addVrf(BgpUtil.getLayerType(vrfAddrFamily), rd, vrfs.getImportRts(), vrfs.getExportRts(),
- vrfAddrFamily.getAfi(), vrfAddrFamily.getSafi());
+ br.addVrf(BgpUtil.getLayerType(vrfAddrFamily), rd, vrfs.getImportRts(), vrfs.getExportRts()
+ );
}
/*add to br the vrfs contained in mapNewAdFamily*/
List<AddressFamiliesVrf> vrfAddrFamilyListFromMap = mapNewAdFamily.get(rd);
mapNewAdFamily.remove(rd);
} else if (adf != null) {
- br.addVrf(BgpUtil.getLayerType(adf), rd, vrfs.getImportRts(), vrfs.getExportRts(),
- adf.getAfi(), adf.getSafi());
+ br.addVrf(BgpUtil.getLayerType(adf), rd, vrfs.getImportRts(), vrfs.getExportRts()
+ );
// remove AddressFamiliesVrf which was already added to BGP
vrfAddrFamilyListFromMap.remove(adf);
if (vrfAddrFamilyListFromMap.isEmpty()) {
}
}
} catch (TException | BgpRouterException e) {
- LOG.error("{} get {}, Add received exception; {}", YANG_OBJ, ADD_WARN, e);
+ LOG.error("{} get {}, Add received exception", YANG_OBJ, ADD_WARN, e);
}
}
}
String rd = val.getRd();
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.debug("{} Unable to process remove for rd {}; {}", YANG_OBJ, rd,
+ LOG.debug("{} Unable to process remove for rd {}; {} {}", YANG_OBJ, rd,
BgpRouterException.BGP_ERR_NOT_INITED, DEL_WARN);
return;
}
if (rd != null) {
BgpRouter br = getClient(YANG_OBJ);
if (br == null) {
- LOG.debug("{} Unable to process add for rd {}; {}", YANG_OBJ, rd,
+ LOG.debug("{} Unable to process add for rd {}; {} {}", YANG_OBJ, rd,
BgpRouterException.BGP_ERR_NOT_INITED, ADD_WARN);
return;
}
try {
LOG.debug("call addVRf rd {} afi {} safi {}", rd, adfvrf.getAfi(), adfvrf.getSafi());
br.addVrf(BgpUtil.getLayerType(adfvrf), rd, newval.getImportRts(),
- newval.getExportRts(), adfvrf.getAfi(), adfvrf.getSafi());
+ newval.getExportRts());
} catch (TException | BgpRouterException e) {
LOG.error("{} Add received exception; {}", YANG_OBJ, ADD_WARN, e);
}
br.disableMultipath(afi, safi);
}
} catch (TException | BgpRouterException e) {
- LOG.error(YANG_OBJ + " received exception: \"" + e + "\"");
+ LOG.error("{} received exception", YANG_OBJ, e);
}
}
}
if (br != null) {
try {
br.multipaths(vrfMaxpathVal.getRd(), vrfMaxpathVal.getMaxpaths());
- LOG.debug("Maxpath for vrf: " + vrfMaxpathVal.getRd() + " : is "
- + vrfMaxpathVal.getMaxpaths());
+ LOG.debug("Maxpath for vrf {} is {}", vrfMaxpathVal.getRd(),
+ vrfMaxpathVal.getMaxpaths());
} catch (TException | BgpRouterException e) {
- LOG.error(YANG_OBJ
- + " received exception: \"" + e + "\"");
+ LOG.error("{} received exception", YANG_OBJ, e);
}
}
}
}
public static boolean isValidConfigBgpHostPort(String bgpHost, int bgpPort) {
- if (!bgpHost.equals(DEF_CHOST) && bgpPort != Integer.parseInt(DEF_CPORT)) {
+ if (!bgpHost.equals(DEF_CHOST)) {
return true;
} else {
return false;
cancelPreviousReplayJob();
}
Runnable task = () -> {
- try {
- LOG.info("running bgp replay task ");
- if (get() == null) {
- String host = getConfigHost();
- int port = getConfigPort();
- LOG.info("connecting to bgp host {} ", host);
- bgpRouter.connect(host, port);
- LOG.info("no config to push in bgp replay task ");
- return;
- }
- setStaleStartTime(System.currentTimeMillis());
- LOG.info("started creating stale fibDSWriter map ");
- createStaleFibMap();
- setStaleEndTime(System.currentTimeMillis());
- LOG.info("took {} msecs for stale fibDSWriter map creation ", getStaleEndTime() - getStaleStartTime());
- LOG.info("started bgp config replay ");
- setCfgReplayStartTime(System.currentTimeMillis());
- boolean replaySucceded = replay();
- setCfgReplayEndTime(System.currentTimeMillis());
- LOG.info("took {} msecs for bgp replay ", getCfgReplayEndTime() - getCfgReplayStartTime());
- if (replaySucceded) {
- LOG.info("starting the stale cleanup timer");
- long routeSyncTime = getStalePathtime(BGP_RESTART_ROUTE_SYNC_SEC, config.getAsId());
- setStaleCleanupTime(routeSyncTime);
- routeCleanupFuture = executor.schedule(new RouteCleanup(), routeSyncTime, TimeUnit.SECONDS);
- } else {
- staledFibEntriesMap.clear();
- }
- } catch (InterruptedException | TimeoutException | ExecutionException eCancel) {
- LOG.error("Stale Cleanup Task Cancelled", eCancel);
+ LOG.info("running bgp replay task ");
+ if (get() == null) {
+ String host = getConfigHost();
+ int port = getConfigPort();
+ LOG.info("connecting to bgp host {} ", host);
+ bgpRouter.connect(host, port);
+ LOG.info("no config to push in bgp replay task ");
+ return;
+ }
+ setStaleStartTime(System.currentTimeMillis());
+ LOG.info("started creating stale fibDSWriter map ");
+ createStaleFibMap();
+ setStaleEndTime(System.currentTimeMillis());
+ LOG.info("took {} msecs for stale fibDSWriter map creation ", getStaleEndTime() - getStaleStartTime());
+ LOG.info("started bgp config replay ");
+ setCfgReplayStartTime(System.currentTimeMillis());
+ boolean replaySucceded = replay();
+ setCfgReplayEndTime(System.currentTimeMillis());
+ LOG.info("took {} msecs for bgp replay ", getCfgReplayEndTime() - getCfgReplayStartTime());
+ if (replaySucceded) {
+ LOG.info("starting the stale cleanup timer");
+ long routeSyncTime = getStalePathtime(BGP_RESTART_ROUTE_SYNC_SEC, config.getAsId());
+ setStaleCleanupTime(routeSyncTime);
+ routeCleanupFuture = executor.schedule(new RouteCleanup(), routeSyncTime, TimeUnit.SECONDS);
+ } else {
+ staledFibEntriesMap.clear();
}
};
lastReplayJobFt = executor.submit(task);
}
}
- private void doRouteSync() throws InterruptedException, TimeoutException, ExecutionException {
+ private void doRouteSync() {
LOG.error("Starting BGP route sync");
try {
bgpRouter.initRibSync(bgpSyncHandle);
- } catch (TException | BgpRouterException e) {
+ } catch (BgpRouterException e) {
LOG.error("Route sync aborted, exception when initializing", e);
return;
}
prefix,
plen,
nexthop,
- update.getEthtag(),
- update.getEsi(),
update.getMacaddress(),
label,
l2label,
try {
LOG.error("Ending BGP route-sync");
bgpRouter.endRibSync(bgpSyncHandle);
- } catch (TException | BgpRouterException e) {
+ } catch (BgpRouterException e) {
// Ignored?
}
}
*/
public void onUpdatePushRoute(protocol_type protocolType, String rd, String prefix, int plen, String nextHop,
- int ethtag, String esi, String macaddress, int label, int l2label, String routermac, af_afi afi)
- throws InterruptedException, ExecutionException, TimeoutException {
+ String macaddress, int label, int l2label, String routermac, af_afi afi) {
boolean addroute = false;
boolean macupdate = false;
long l3vni = 0L;
rd, prefix, nextHop, label, afi);
// TODO: modify addFibEntryToDS signature
List<String> nextHopList = Collections.singletonList(nextHop);
- fibDSWriter.addFibEntryToDS(rd, macaddress, prefix + "/" + plen, nextHopList, encapType, label, l3vni,
+ fibDSWriter.addFibEntryToDS(rd, prefix + "/" + plen, nextHopList, encapType, label, l3vni,
routermac, RouteOrigin.BGP);
LOG.info("ADD: Added Fib entry rd {} prefix {} nexthop {} label {}", rd, prefix, nextHop, label);
String vpnName = bgpUtil.getVpnNameFromRd(rd);
}
public void onUpdateWithdrawRoute(protocol_type protocolType, String rd, String prefix, int plen, String nextHop,
- String macaddress) throws InterruptedException, ExecutionException, TimeoutException {
+ String macaddress) {
long vni = 0L;
boolean macupdate = false;
if (protocolType.equals(protocol_type.PROTOCOL_EVPN)) {
if (vpnInstanceOpDataEntry != null) {
vni = vpnInstanceOpDataEntry.getL3vni();
if (vpnInstanceOpDataEntry.getType() == VpnInstanceOpDataEntry.Type.L2) {
- LOG.debug("Got RT2 withdraw for RD %s from tep %s with mac %s remote RD %s",
+ LOG.debug("Got RT2 withdraw for RD {} {} from tep {} with mac {} remote RD {}",
vpnInstanceOpDataEntry.getVpnInstanceName(), vni, nextHop, macaddress, rd);
deleteTepfromElanDS(rd, nextHop, macaddress);
- LOG.debug("For rd %s. skipping fib update", rd);
+ LOG.debug("For rd {}. skipping fib update", rd);
macupdate = true;
}
} else {
}
@SuppressWarnings("checkstyle:IllegalCatch")
- public synchronized boolean replay() throws InterruptedException, TimeoutException, ExecutionException {
+ public synchronized boolean replay() {
boolean replaySucceded = true;
String host = getConfigHost();
int port = getConfigPort();
LOG.error("connecting to bgp host {} ", host);
boolean res = bgpRouter.connect(host, port);
if (!res) {
- String msg = "Cannot connect to BGP config server at " + host + ":" + port;
- if (config != null) {
- msg += "; Configuration Replay aborted";
- }
- LOG.error(msg);
+ LOG.error("Cannot connect to BGP config server at {}:{}{}", host, port,
+ config != null ? "; Configuration Replay aborted" : "");
return replaySucceded;
}
config = getConfig();
}
long asNum = asId.getLocalAs();
IpAddress routerId = asId.getRouterId();
- String rid = routerId == null ? "" : new String(routerId.getValue());
+ String rid = routerId == null ? "" : routerId.stringValue();
int stalepathTime = (int) getStalePathtime(RESTART_DEFAULT_GR, config.getAsId());
boolean announceFbit = true;
boolean replayDone = false;
* 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);
- //}
+ 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) {
for (AddressFamiliesVrf adf : vrf.getAddressFamiliesVrf()) {
try {
br.addVrf(BgpUtil.getLayerType(adf), vrf.getRd(), vrf.getImportRts(),
- vrf.getExportRts(), adf.getAfi(), adf.getSafi());
+ vrf.getExportRts());
} catch (TException | BgpRouterException e) {
LOG.error("Replay:addVrf() received exception", e);
}
br.disableMultipath(afi, safi);
}
} catch (TException | BgpRouterException e) {
- LOG.info("Replay:multipaths() received exception: \"" + e + "\"");
+ LOG.info("Replay:multipaths() received exception", e);
}
}
}
try {
br.multipaths(vrfMaxpath.getRd(), vrfMaxpath.getMaxpaths());
} catch (TException | BgpRouterException e) {
- LOG.info("Replay:vrfMaxPath() received exception: \"" + e + "\"");
+ LOG.info("Replay:vrfMaxPath() received exception", e);
}
}
}
}
private <T extends DataObject> void update(InstanceIdentifier<T> iid, T dto) {
- bgpUtil.update(LogicalDatastoreType.CONFIGURATION, iid, dto);
+ bgpUtil.update(iid, dto);
}
private <T extends DataObject> void delete(InstanceIdentifier<T> iid) {
- bgpUtil.delete(LogicalDatastoreType.CONFIGURATION, iid);
+ bgpUtil.delete(iid);
}
public void startConfig(String bgpHost, int thriftPort) {
}
public void startBgp(long as, String routerId, int spt, boolean fbit) {
- IpAddress rid = routerId == null ? null : new IpAddress(routerId.toCharArray());
+ IpAddress rid = routerId == null ? null : IpAddressBuilder.getDefaultInstance(routerId);
Long staleTime = (long) spt;
InstanceIdentifier.InstanceIdentifierBuilder<AsId> iib =
InstanceIdentifier.builder(Bgp.class).child(AsId.class);
InstanceIdentifier<Vrfs> iid = iib.build();
+ InstanceIdentifier.builder(Bgp.class).build()
+ .child(Multipath.class, new MultipathKey(adfBuilder.getAfi(), adfBuilder.getSafi()));
@SuppressWarnings("static-access")
- InstanceIdentifier<Bgp> iid6 = iid.builder(Bgp.class).build()
- .child(Multipath.class, new MultipathKey(adfBuilder.getAfi(), adfBuilder.getSafi())).create(Bgp.class);
+ InstanceIdentifier<Bgp> iid6 = InstanceIdentifier.create(Bgp.class);
InstanceIdentifierBuilder<Vrfs> iib3 = iid6.child(Vrfs.class, new VrfsKey(rd)).builder();
InstanceIdentifier<Vrfs> iidFinal = iib3.build();
rt2TepMap.get(rd).get(tepIp).put(mac, l2vni);
} else {
LOG.debug("RT2 with mac {} l2vni {} from existing rd {} and new tep-ip {}",
- mac, rd, tepIp);
+ mac, l2vni, rd, tepIp);
isFirstMacUpdateFromTep = true;
Map<String, Long> macList = new HashMap<>();
macList.put(mac, l2vni);
TimeUnit.MILLISECONDS);
LOG.info("Bgp Counters task scheduled for every two minutes.");
- bgpManager.setQbgpLog(BgpConstants.BGP_DEF_LOG_FILE, BgpConstants.BGP_DEF_LOG_LEVEL);
+ addLogging(BgpConstants.BGP_DEF_LOG_FILE, BgpConstants.BGP_DEF_LOG_LEVEL);
}
}