use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project netvirt by opendaylight.
the class VpnSubnetRouteHandler method electNewDpnForSubnetRoute.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void electNewDpnForSubnetRoute(SubnetOpDataEntryBuilder subOpBuilder, BigInteger oldDpnId, Uuid subnetId, Uuid networkId, boolean isBgpVpn) {
List<SubnetToDpn> subDpnList = null;
boolean isRouteAdvertised = false;
subDpnList = subOpBuilder.getSubnetToDpn();
String rd = subOpBuilder.getVrfId();
String subnetIp = subOpBuilder.getSubnetCidr();
String vpnName = subOpBuilder.getVpnName();
long elanTag = subOpBuilder.getElanTag();
boolean isAlternateDpnSelected = false;
long l3vni = 0;
long label = 0;
String networkName = networkId != null ? networkId.getValue() : null;
LOG.info("{} electNewDpnForSubnetRoute: Handling subnet {} subnetIp {} vpn {} rd {} TaskState {}" + " lastTaskState {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, subOpBuilder.getVpnName(), subOpBuilder.getVrfId(), subOpBuilder.getRouteAdvState(), subOpBuilder.getLastAdvState());
if (!isBgpVpn) {
// blended more better into this design.
if (VpnUtil.isL3VpnOverVxLan(subOpBuilder.getL3vni())) {
l3vni = subOpBuilder.getL3vni();
} else {
label = getLabel(rd, subnetIp);
subOpBuilder.setLabel(label);
}
isRouteAdvertised = addSubnetRouteToFib(rd, subnetIp, null, /* nhDpnId */
null, /* nhTepIp */
vpnName, elanTag, label, l3vni, subnetId, isBgpVpn, networkName);
if (isRouteAdvertised) {
subOpBuilder.setRouteAdvState(TaskState.Advertised);
} else {
LOG.error("{} electNewDpnForSubnetRoute: Unable to find TepIp for subnet {} subnetip {} vpnName {}" + " rd {}, attempt next dpn", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, rd);
subOpBuilder.setRouteAdvState(TaskState.PendingAdvertise);
}
return;
}
String nhTepIp = null;
BigInteger nhDpnId = null;
Iterator<SubnetToDpn> subnetDpnIter = subDpnList.iterator();
while (subnetDpnIter.hasNext()) {
SubnetToDpn subnetToDpn = subnetDpnIter.next();
if (subnetToDpn.getDpnId().equals(oldDpnId)) {
// Is this same is as input dpnId, then ignore it
continue;
}
nhDpnId = subnetToDpn.getDpnId();
if (vpnNodeListener.isConnectedNode(nhDpnId)) {
// but does it have a TEP configured at all?
try {
nhTepIp = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, nhDpnId);
if (nhTepIp != null) {
isAlternateDpnSelected = true;
break;
}
} catch (Exception e) {
LOG.warn("{} electNewDpnForSubnetRoute: Unable to find TepIp for rd {} subnetroute subnetip {}" + " for dpnid {}, attempt next", LOGGING_PREFIX, rd, subnetIp, nhDpnId.toString(), e);
continue;
}
}
}
if (!isAlternateDpnSelected) {
// If no alternate Dpn is selected as nextHopDpn, withdraw the subnetroute if it had a nextHop already.
if (isRouteAdvertised(subOpBuilder) && oldDpnId != null) {
LOG.info("{} electNewDpnForSubnetRoute: No alternate DPN available for subnet {} subnetIp {} vpn {}" + " rd {} Prefix withdrawn from BGP", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, rd);
// Withdraw route from BGP for this subnet
boolean routeWithdrawn = deleteSubnetRouteFromFib(rd, subnetIp, vpnName, isBgpVpn);
subOpBuilder.setNhDpnId(null);
subOpBuilder.setLastAdvState(subOpBuilder.getRouteAdvState());
if (routeWithdrawn) {
subOpBuilder.setRouteAdvState(TaskState.Withdrawn);
} else {
LOG.error("{} electNewDpnForSubnetRoute: Withdrawing NextHopDPN {} for subnet {} subnetIp {}" + " vpn {} rd {} from BGP failed", LOGGING_PREFIX, oldDpnId, subnetId.getValue(), subnetIp, vpnName, rd);
subOpBuilder.setRouteAdvState(TaskState.PendingWithdraw);
}
}
} else {
// If alternate Dpn is selected as nextHopDpn, use that for subnetroute.
subOpBuilder.setNhDpnId(nhDpnId);
if (VpnUtil.isL3VpnOverVxLan(subOpBuilder.getL3vni())) {
l3vni = subOpBuilder.getL3vni();
} else {
label = getLabel(rd, subnetIp);
subOpBuilder.setLabel(label);
}
// update the VRF entry for the subnetroute.
isRouteAdvertised = addSubnetRouteToFib(rd, subnetIp, nhDpnId, nhTepIp, vpnName, elanTag, label, l3vni, subnetId, isBgpVpn, networkName);
subOpBuilder.setLastAdvState(subOpBuilder.getRouteAdvState());
if (isRouteAdvertised) {
subOpBuilder.setRouteAdvState(TaskState.Advertised);
} else {
LOG.error("{} electNewDpnForSubnetRoute: Swapping to add new NextHopDpn {} for subnet {} subnetIp {}" + " vpn {} rd {} failed", LOGGING_PREFIX, nhDpnId, subnetId.getValue(), subnetIp, vpnName, rd);
subOpBuilder.setRouteAdvState(TaskState.PendingAdvertise);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project netvirt by opendaylight.
the class VpnSubnetRouteHandler method onInterfaceUp.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void onInterfaceUp(BigInteger dpnId, String intfName, Uuid subnetId) {
// TODO(vivek): Change this to use more granularized lock at subnetId level
SubnetToDpn subDpn = null;
if (dpnId == null || Objects.equals(dpnId, BigInteger.ZERO)) {
LOG.error("{} onInterfaceUp: Unable to determine the DPNID for port {} on subnet {}", LOGGING_PREFIX, intfName, subnetId.getValue());
return;
}
try {
VpnUtil.lockSubnet(lockManager, subnetId.getValue());
try {
InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
Optional<SubnetOpDataEntry> optionalSubs = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
if (!optionalSubs.isPresent()) {
LOG.trace("{} onInterfaceUp: SubnetOpDataEntry for subnet {} is not available." + " Ignoring interfaceUp for port{}", LOGGING_PREFIX, subnetId.getValue(), intfName);
return;
}
subOpDpnManager.addPortOpDataEntry(intfName, subnetId, dpnId);
subDpn = subOpDpnManager.addInterfaceToDpn(subnetId, dpnId, intfName);
if (subDpn == null) {
return;
}
SubnetOpDataEntry subnetOpDataEntry = optionalSubs.get();
SubnetOpDataEntryBuilder subOpBuilder = new SubnetOpDataEntryBuilder(subnetOpDataEntry);
LOG.info("{} onInterfaceUp: Updating the SubnetOpDataEntry node for subnet {} subnetIp {} vpn {}" + " rd {} TaskState {} lastTaskState {}", LOGGING_PREFIX, subnetId.getValue(), subOpBuilder.getSubnetCidr(), subOpBuilder.getVpnName(), subOpBuilder.getVrfId(), subOpBuilder.getRouteAdvState(), subOpBuilder.getLastAdvState());
boolean isExternalSubnetVpn = VpnUtil.isExternalSubnetVpn(subnetOpDataEntry.getVpnName(), subnetId.getValue());
List<SubnetToDpn> subDpnList = subOpBuilder.getSubnetToDpn();
subDpnList.add(subDpn);
subOpBuilder.setSubnetToDpn(subDpnList);
if (subOpBuilder.getRouteAdvState() != TaskState.Advertised) {
if (subOpBuilder.getNhDpnId() == null) {
// No nexthop selected yet, elect one now
electNewDpnForSubnetRoute(subOpBuilder, null, /* oldDpnId */
subnetId, null, /*networkId*/
!isExternalSubnetVpn);
} else if (!isExternalSubnetVpn) {
// Already nexthop has been selected, only publishing to bgp required, so publish to bgp
getNexthopTepAndPublishRoute(subOpBuilder, subnetId);
}
}
SubnetOpDataEntry subOpEntry = subOpBuilder.build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpEntry);
LOG.info("{} onInterfaceUp: Updated subnetopdataentry to OP Datastore port {} up for subnet {}" + " subnetIp {} vpnName {} rd {} TaskState {} lastTaskState {} ", LOGGING_PREFIX, intfName, subnetId.getValue(), subOpEntry.getSubnetCidr(), subOpEntry.getVpnName(), subOpEntry.getVrfId(), subOpEntry.getRouteAdvState(), subOpEntry.getLastAdvState());
} catch (Exception ex) {
LOG.error("{} onInterfaceUp: Updation of SubnetOpDataEntry for subnet {} on port {} up failed", LOGGING_PREFIX, subnetId.getValue(), intfName, ex);
} finally {
VpnUtil.unlockSubnet(lockManager, subnetId.getValue());
}
} catch (RuntimeException e) {
LOG.error("{} onInterfaceUp: Unable to handle interface up event for port {} in subnet {}", LOGGING_PREFIX, intfName, subnetId.getValue(), e);
}
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project netvirt by opendaylight.
the class InterVpnLinkUtil method leakRoute.
/**
* Leaks a route from one VPN to another. By default, the origin for this leaked route is INTERVPN.
*
* @param broker dataBroker service reference
* @param bgpManager Used to advertise routes to the BGP Router
* @param interVpnLink Reference to the object that holds the info about the link between the 2 VPNs
* @param srcVpnUuid UUID of the VPN that has the route that is going to be leaked to the other VPN
* @param dstVpnUuid UUID of the VPN that is going to receive the route
* @param prefix Prefix of the route
* @param label Label of the route in the original VPN
*/
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public static void leakRoute(DataBroker broker, IBgpManager bgpManager, InterVpnLink interVpnLink, String srcVpnUuid, String dstVpnUuid, String prefix, Long label) {
Preconditions.checkNotNull(interVpnLink);
// The source VPN must participate in the InterVpnLink
Preconditions.checkArgument(interVpnLink.getFirstEndpoint().getVpnUuid().getValue().equals(srcVpnUuid) || interVpnLink.getSecondEndpoint().getVpnUuid().getValue().equals(srcVpnUuid), "The source VPN {} does not participate in the interVpnLink {}", srcVpnUuid, interVpnLink.getName());
// The destination VPN must participate in the InterVpnLink
Preconditions.checkArgument(interVpnLink.getFirstEndpoint().getVpnUuid().getValue().equals(dstVpnUuid) || interVpnLink.getSecondEndpoint().getVpnUuid().getValue().equals(dstVpnUuid), "The destination VPN {} does not participate in the interVpnLink {}", dstVpnUuid, interVpnLink.getName());
boolean destinationIs1stEndpoint = interVpnLink.getFirstEndpoint().getVpnUuid().getValue().equals(dstVpnUuid);
String endpointIp = destinationIs1stEndpoint ? interVpnLink.getSecondEndpoint().getIpAddress().getValue() : interVpnLink.getFirstEndpoint().getIpAddress().getValue();
VrfEntry newVrfEntry = FibHelper.getVrfEntryBuilder(prefix, label, endpointIp, RouteOrigin.INTERVPN, null).build();
String dstVpnRd = VpnUtil.getVpnRd(broker, dstVpnUuid);
InstanceIdentifier<VrfEntry> newVrfEntryIid = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(dstVpnRd)).child(VrfEntry.class, new VrfEntryKey(newVrfEntry.getDestPrefix())).build();
VpnUtil.asyncWrite(broker, LogicalDatastoreType.CONFIGURATION, newVrfEntryIid, newVrfEntry);
// Finally, route is advertised it to the DC-GW. But while in the FibEntries the nexthop is the other
// endpoint's IP, in the DC-GW the nexthop for those prefixes are the IPs of those DPNs where the target
// VPN has been instantiated
Optional<InterVpnLinkState> optVpnLinkState = getInterVpnLinkState(broker, interVpnLink.getName());
if (optVpnLinkState.isPresent()) {
InterVpnLinkState vpnLinkState = optVpnLinkState.get();
List<BigInteger> dpnIdList = destinationIs1stEndpoint ? vpnLinkState.getFirstEndpointState().getDpId() : vpnLinkState.getSecondEndpointState().getDpId();
List<String> nexthops = new ArrayList<>();
for (BigInteger dpnId : dpnIdList) {
nexthops.add(InterfaceUtils.getEndpointIpAddressForDPN(broker, dpnId));
}
try {
LOG.debug("Advertising route in VPN={} [prefix={} label={} nexthops={}] to DC-GW", dstVpnRd, newVrfEntry.getDestPrefix(), label.intValue(), nexthops);
bgpManager.advertisePrefix(dstVpnRd, null, /*macAddress*/
newVrfEntry.getDestPrefix(), nexthops, VrfEntry.EncapType.Mplsgre, label.intValue(), 0, /*l3vni*/
0, /*l2vni*/
null);
} catch (Exception ex) {
LOG.error("Could not advertise prefix {} with label {} to VPN rd={}", newVrfEntry.getDestPrefix(), label.intValue(), dstVpnRd, ex);
}
} else {
LOG.warn("Error when advertising leaked routes: Could not find State for InterVpnLink={}", interVpnLink.getName());
}
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp 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.Bgp in project netvirt by opendaylight.
the class BgpConfigurationManager method createStaleFibMap.
/*
* BGP restart scenario, ODL-BGP manager was/is running.
* On re-sync notification, Get a copy of FIB database.
*/
public void createStaleFibMap() {
totalStaledCount = 0;
try {
staledFibEntriesMap.clear();
InstanceIdentifier<FibEntries> id = InstanceIdentifier.create(FibEntries.class);
Optional<FibEntries> fibEntries = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
if (fibEntries.isPresent()) {
List<VrfTables> staleVrfTables = fibEntries.get().getVrfTables();
for (VrfTables vrfTable : staleVrfTables) {
Map<String, Long> staleFibEntMap = new HashMap<>();
for (VrfEntry vrfEntry : vrfTable.getVrfEntry()) {
if (RouteOrigin.value(vrfEntry.getOrigin()) != RouteOrigin.BGP) {
// Stale marking and cleanup is only meant for the routes learned through BGP.
continue;
}
if (Thread.interrupted()) {
break;
}
totalStaledCount++;
// Create MAP from staleVrfTables.
vrfEntry.getRoutePaths().forEach(routePath -> staleFibEntMap.put(appendNextHopToPrefix(vrfEntry.getDestPrefix(), routePath.getNexthopAddress()), routePath.getLabel()));
}
staledFibEntriesMap.put(vrfTable.getRouteDistinguisher(), staleFibEntMap);
}
} else {
LOG.error("createStaleFibMap:: FIBentries.class is not present");
}
} catch (ReadFailedException e) {
LOG.error("createStaleFibMap:: error ", e);
}
LOG.error("created {} staled entries ", totalStaledCount);
}
Aggregations