package org.opendaylight.netvirt.bgpmanager;
import com.google.common.base.Optional;
+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;
// 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";
private static final int RESTART_DEFAULT_GR = 90;
private volatile Bgp config;
private final BgpRouter bgpRouter;
private final BgpSyncHandle bgpSyncHandle = new BgpSyncHandle();
- private BgpThriftService updateServer;
+ private volatile BgpThriftService bgpThriftService = null;
private final CountDownLatch initer = new CountDownLatch(1);
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);
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();
+ 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();
+ }
}
});
}
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);
}
}
}
prefix,
plen,
nexthop,
- update.getEthtag(),
- update.getEsi(),
update.getMacaddress(),
label,
l2label,
*/
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) {
+ 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);
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 {
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();
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) {
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);