use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.EncapType 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;
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.EncapType in project netvirt by opendaylight.
the class BgpConfigurationManager method onUpdatePushRoute.
/* onUpdatePushRoute
* Get Stale fibDSWriter map, and compare current route/fibDSWriter entry.
* - Entry compare shall include NextHop, Label.
* - If entry matches: delete from STALE Map. NO Change to FIB Config DS.
* - If entry not found, add to FIB Config DS.
* - If entry found, but either Label/NextHop doesn't match.
* - Update FIB Config DS with modified values.
* - delete from Stale Map.
*/
public void onUpdatePushRoute(protocol_type protocolType, String rd, String prefix, int plen, String nextHop, String macaddress, int label, int l2label, String routermac, af_afi afi) {
boolean addroute = false;
boolean macupdate = false;
long l3vni = 0L;
VrfEntry.EncapType encapType = VrfEntry.EncapType.Mplsgre;
if (protocolType.equals(protocol_type.PROTOCOL_EVPN)) {
encapType = VrfEntry.EncapType.Vxlan;
VpnInstanceOpDataEntry vpnInstanceOpDataEntry = bgpUtil.getVpnInstanceOpData(rd);
if (vpnInstanceOpDataEntry != null) {
if (vpnInstanceOpDataEntry.getType() == VpnInstanceOpDataEntry.Type.L2) {
LOG.info("Got RT2 route for RD {} l3label {} l2label {} from tep {} with mac {} remote RD {}", vpnInstanceOpDataEntry.getVpnInstanceName(), label, l2label, nextHop, macaddress, rd);
addTepToElanDS(rd, nextHop, macaddress, (long) l2label);
macupdate = true;
} else {
l3vni = vpnInstanceOpDataEntry.getL3vni();
}
} else {
LOG.error("No corresponding vpn instance found for rd {}. Aborting.", rd);
return;
}
}
if (!staledFibEntriesMap.isEmpty()) {
// restart Scenario, as MAP is not empty.
Map<String, Long> map = staledFibEntriesMap.get(rd);
if (map != null) {
String prefixNextHop = appendNextHopToPrefix(prefix + "/" + plen, nextHop);
Long labelInStaleMap = map.get(prefixNextHop);
if (null == labelInStaleMap) {
// New Entry, which happened to be added during restart.
addroute = true;
} else {
map.remove(prefixNextHop);
if (isRouteModified(label, labelInStaleMap)) {
LOG.debug("Route add ** {} ** {}/{} ** {} ** {} ", rd, prefix, plen, nextHop, label);
// Existing entry, where in Label got modified during restart
addroute = true;
}
}
} else {
LOG.debug("rd {} map is null while processing prefix {} ", rd, prefix);
addroute = true;
}
} else {
LOG.debug("Route add ** {} ** {}/{} ** {} ** {} ", rd, prefix, plen, nextHop, label);
addroute = true;
}
if (macupdate) {
LOG.info("ADD: Adding Mac Fib entry rd {} mac{} nexthop {} l2vni {}", rd, macaddress, nextHop, l2label);
fibDSWriter.addMacEntryToDS(rd, macaddress, prefix, Collections.singletonList(nextHop), encapType, l2label, routermac, RouteOrigin.BGP);
LOG.info("ADD: Added Mac Fib entry rd {} prefix {} nexthop {} label {}", rd, macaddress, nextHop, l2label);
} else if (addroute) {
LOG.info("ADD: Adding Fib entry rd {} prefix {} nexthop {} label {} afi {}", rd, prefix, nextHop, label, afi);
// TODO: modify addFibEntryToDS signature
List<String> nextHopList = Collections.singletonList(nextHop);
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 (vpnName != null) {
vpnLinkService.leakRouteIfNeeded(vpnName, prefix, nextHopList, label, RouteOrigin.BGP, NwConstants.ADD_FLOW);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.EncapType in project netvirt by opendaylight.
the class FibDSWriter method addFibEntryToDS.
public synchronized void addFibEntryToDS(String rd, String prefix, List<String> nextHopList, VrfEntry.EncapType encapType, int label, long l3vni, String gatewayMacAddress, RouteOrigin origin) {
if (rd == null || rd.isEmpty()) {
LOG.error("Prefix {} not associated with vpn", prefix);
return;
}
Preconditions.checkNotNull(nextHopList, "NextHopList can't be null");
for (String nextHop : nextHopList) {
if (nextHop == null || nextHop.isEmpty()) {
LOG.error("nextHop list contains null element");
return;
}
LOG.debug("Created vrfEntry for {} nexthop {} label {}", prefix, nextHop, label);
}
// Looking for existing prefix in MDSAL database
InstanceIdentifier<VrfEntry> vrfEntryId = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd)).child(VrfEntry.class, new VrfEntryKey(prefix)).build();
VrfEntryBuilder vrfEntryBuilder = new VrfEntryBuilder().setDestPrefix(prefix).setOrigin(origin.getValue());
buildVpnEncapSpecificInfo(vrfEntryBuilder, encapType, label, l3vni, gatewayMacAddress, nextHopList);
bgpUtil.update(vrfEntryId, vrfEntryBuilder.build());
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.EncapType in project netvirt by opendaylight.
the class FibDSWriter method addMacEntryToDS.
public void addMacEntryToDS(String rd, String macAddress, String prefix, List<String> nextHopList, VrfEntry.EncapType encapType, long l2vni, String gatewayMacAddress, RouteOrigin origin) {
if (StringUtils.isEmpty(rd)) {
LOG.error("Mac {} not associated with vpn", macAddress);
return;
}
Preconditions.checkNotNull(nextHopList, "NextHopList can't be null");
for (String nextHop : nextHopList) {
if (StringUtils.isEmpty(nextHop)) {
LOG.error("nextHop list contains null element for macVrf");
return;
}
}
MacVrfEntryBuilder macEntryBuilder = new MacVrfEntryBuilder().setOrigin(origin.getValue());
buildVpnEncapSpecificInfo(macEntryBuilder, encapType, l2vni, gatewayMacAddress, nextHopList);
macEntryBuilder.setMac(macAddress);
macEntryBuilder.setDestPrefix(prefix);
InstanceIdentifier<MacVrfEntry> macEntryId = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd)).child(MacVrfEntry.class, new MacVrfEntryKey(macAddress)).build();
bgpUtil.update(macEntryId, macEntryBuilder.build());
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.EncapType in project netvirt by opendaylight.
the class FibUtil method writeFibEntryToDs.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void writeFibEntryToDs(InstanceIdentifier<VrfEntry> vrfEntryId, String prefix, List<String> nextHopList, long label, Long l3vni, VrfEntry.EncapType encapType, RouteOrigin origin, String macAddress, String gatewayMacAddress, String parentVpnRd, WriteTransaction writeConfigTxn) {
VrfEntryBuilder vrfEntryBuilder = new VrfEntryBuilder().setDestPrefix(prefix).setOrigin(origin.getValue());
if (parentVpnRd != null) {
vrfEntryBuilder.setParentVpnRd(parentVpnRd);
}
buildVpnEncapSpecificInfo(vrfEntryBuilder, encapType, label, l3vni, macAddress, gatewayMacAddress, nextHopList);
if (writeConfigTxn != null) {
writeConfigTxn.merge(LogicalDatastoreType.CONFIGURATION, vrfEntryId, vrfEntryBuilder.build(), true);
} else {
MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, vrfEntryId, vrfEntryBuilder.build());
}
}
Aggregations