// Get the rd of the vpn instance
String rd = getRouteDistinguisher(vpnName);
-
- String nextHopIp = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, dpnId);
- if (nextHopIp == null){
- LOG.error("NextHop for interface {} is null", interfaceName);
- return;
+ String nextHopIp = null;
+ try {
+ nextHopIp = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, dpnId);
+ } catch (Exception e) {
+ LOG.warn("Unable to retrieve enpoint ip address for dpnId {} for vpnInterface {} vpnName {}",
+ dpnId, interfaceName, vpnName);
+ }
+ List<java.lang.String> nhList = new ArrayList<>();
+ if (nextHopIp != null){
+ nhList.add(nextHopIp);
+ LOG.trace("NextHop for interface {} is {}", interfaceName, nhList);
}
List<VpnInstanceOpDataEntry> vpnsToImportRoute = getVpnsImportingMyRoute(vpnName);
}
List<String> adjNextHop = nextHop.getNextHopIpList();
value.add(new AdjacencyBuilder(nextHop).setLabel(label).setNextHopIpList(
- (adjNextHop != null && !adjNextHop.isEmpty()) ? adjNextHop : Arrays.asList(nextHopIp))
+ (adjNextHop != null && !adjNextHop.isEmpty()) ? adjNextHop : nhList)
.setIpAddress(prefix).setKey(new AdjacencyKey(prefix)).build());
if (nextHop.isPrimaryAdjacency()) {
for (Adjacency nextHop : aug.getAdjacency()) {
long label = nextHop.getLabel();
if (rd != null) {
- addToLabelMapper(label, dpnId, nextHop.getIpAddress(), Arrays.asList(nextHopIp), vpnId,
+ addToLabelMapper(label, dpnId, nextHop.getIpAddress(), nhList, vpnId,
interfaceName, null,false, rd, writeOperTxn);
- addPrefixToBGP(rd, nextHop.getIpAddress(), nextHopIp, label, RouteOrigin.LOCAL, writeConfigTxn);
+ addPrefixToBGP(rd, nextHop.getIpAddress(), nhList, label, RouteOrigin.LOCAL, writeConfigTxn);
//TODO: ERT - check for VPNs importing my route
for (VpnInstanceOpDataEntry vpn : vpnsToImportRoute) {
String vpnRd = vpn.getVrfId();
if (vpnRd != null) {
LOG.debug("Exporting route with rd {} prefix {} nexthop {} label {} to VPN {}", vpnRd, nextHop.getIpAddress(), nextHopIp, label, vpn);
- fibManager.addOrUpdateFibEntry(dataBroker, vpnRd, nextHop.getIpAddress(), Arrays.asList(nextHopIp), (int) label,
+ fibManager.addOrUpdateFibEntry(dataBroker, vpnRd, nextHop.getIpAddress(), nhList, (int) label,
RouteOrigin.SELF_IMPORTED, writeConfigTxn);
}
}
}
}
- private void addPrefixToBGP(String rd, String prefix, String nextHopIp, long label, RouteOrigin origin,
+ private void addPrefixToBGP(String rd, String prefix, List<String> nextHopList, long label, RouteOrigin origin,
WriteTransaction writeConfigTxn) {
try {
- LOG.info("ADD: Adding Fib entry rd {} prefix {} nextHop {} label {}", rd, prefix, nextHopIp, label);
- fibManager.addOrUpdateFibEntry(dataBroker, rd, prefix, Arrays.asList(nextHopIp), (int)label, origin,
- writeConfigTxn);
- bgpManager.advertisePrefix(rd, prefix, Arrays.asList(nextHopIp), (int)label);
- LOG.info("ADD: Added Fib entry rd {} prefix {} nextHop {} label {}", rd, prefix, nextHopIp, label);
+ LOG.info("ADD: Adding Fib entry rd {} prefix {} nextHop {} label {}", rd, prefix, nextHopList, label);
+ fibManager.addOrUpdateFibEntry(dataBroker, rd, prefix, nextHopList, (int)label, origin, writeConfigTxn);
+ LOG.info("ADD: Added Fib entry rd {} prefix {} nextHop {} label {}", rd, prefix, nextHopList, label);
+ // Advertize the prefix to BGP only if nexthop ip is available
+ if (nextHopList!= null && !nextHopList.isEmpty()) {
+ bgpManager.advertisePrefix(rd, prefix, nextHopList, (int)label);
+ } else {
+ LOG.warn("NextHopList is null/empty. Hence rd {} prefix {} is not advertised to BGP", rd, prefix);
+ }
} catch(Exception e) {
LOG.error("Add prefix failed", e);
}
// This is either an extra-route (or) a learned IP via subnet-route
String nextHopIp = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, dpnId);
if (nextHopIp == null || nextHopIp.isEmpty()) {
- LOG.error("Unable to obtain nextHopIp for extra-route/learned-route in rd {} prefix {}",
+ LOG.warn("Unable to obtain nextHopIp for extra-route/learned-route in rd {} prefix {}",
rd, nextHop.getIpAddress());
- continue;
+ } else {
+ nhList = Arrays.asList(nextHopIp);
}
- nhList = Arrays.asList(nextHopIp);
} else {
// This is a primary adjacency
nhList = nextHop.getNextHopIpList();
}
- if (rd.equals(vpnName)) {
- //this is an internal vpn - the rd is assigned to the vpn instance name;
- //remove from FIB directly
- for(String nh : nhList) {
- fibManager.removeOrUpdateFibEntry(dataBroker, vpnName, nextHop.getIpAddress(), nh, writeConfigTxn);
- }
- } else {
- List<VpnInstanceOpDataEntry> vpnsToImportRoute = getVpnsImportingMyRoute(vpnName);
- for (String nh : nhList) {
- //IRT: remove routes from other vpns importing it
- removePrefixFromBGP(rd, nextHop.getIpAddress(), nh, writeConfigTxn);
- for (VpnInstanceOpDataEntry vpn : vpnsToImportRoute) {
- String vpnRd = vpn.getVrfId();
- if (vpnRd != null) {
- LOG.info("Removing Exported route with rd {} prefix {} from VPN {}", vpnRd, nextHop.getIpAddress(), vpn.getVpnInstanceName());
- fibManager.removeOrUpdateFibEntry(dataBroker, vpnRd, nextHop.getIpAddress(), nh, writeConfigTxn);
+
+ if (!nhList.isEmpty()) {
+ if (rd.equals(vpnName)) {
+ //this is an internal vpn - the rd is assigned to the vpn instance name;
+ //remove from FIB directly
+ for (String nh : nhList) {
+ fibManager.removeOrUpdateFibEntry(dataBroker, vpnName, nextHop.getIpAddress(), nh, writeConfigTxn);
+ }
+ } else {
+ List<VpnInstanceOpDataEntry> vpnsToImportRoute = getVpnsImportingMyRoute(vpnName);
+ for (String nh : nhList) {
+ //IRT: remove routes from other vpns importing it
+ removePrefixFromBGP(rd, nextHop.getIpAddress(), nh, writeConfigTxn);
+ for (VpnInstanceOpDataEntry vpn : vpnsToImportRoute) {
+ String vpnRd = vpn.getVrfId();
+ if (vpnRd != null) {
+ LOG.info("Removing Exported route with rd {} prefix {} from VPN {}", vpnRd, nextHop.getIpAddress(), vpn.getVpnInstanceName());
+ fibManager.removeOrUpdateFibEntry(dataBroker, vpnRd, nextHop.getIpAddress(), nh, writeConfigTxn);
+ }
}
}
}
+ } else {
+ fibManager.removeFibEntry(dataBroker, rd , nextHop.getIpAddress(), writeConfigTxn);
}
+
String ip = nextHop.getIpAddress().split("/")[0];
VpnPortipToPort vpnPortipToPort = VpnUtil.getNeutronPortFromVpnPortFixedIp(dataBroker,
vpnName, ip);
dpnId = InterfaceUtils.getDpnForInterface(ifaceMgrRpcService, intfName);
String nextHopIp = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, dpnId);
if (nextHopIp == null || nextHopIp.isEmpty()) {
- LOG.error("NextHop for interface {} is null / empty. Failed advertising extra route for prefix {}",
- intfName, destination);
+ LOG.error("NextHop for interface {} is null / empty. Failed advertising extra route for rd {} prefix {}",
+ intfName, rd, destination);
return;
}
nextHop = nextHopIp;
InterVpnLinkUtil.leakRoute(dataBroker, bgpManager, interVpnLink, srcVpnUuid, dstVpnUuid, destination, newLabel);
} else {
if (rd != null) {
- addPrefixToBGP(rd, destination, nextHop, label, origin, writeConfigTxn);
+ addPrefixToBGP(rd, destination, nextHopIpList, label, origin, writeConfigTxn);
} else {
// ### add FIB route directly
- fibManager.addOrUpdateFibEntry(dataBroker, routerID, destination, Arrays.asList(nextHop), label,
- origin, writeConfigTxn);
+ fibManager.addOrUpdateFibEntry(dataBroker, routerID, destination, nextHopIpList, label, origin, writeConfigTxn);
}
}
if (!writeOperTxnPresent) {
logger.error("Unable to fetch label from Id Manager. Bailing out of handling addition of subnet {} to vpn {}", subnetIp, vpnName);
return;
}
- addSubnetRouteToFib(rd, subnetIp, nhDpnId, vpnName, elanTag, label);
- advertiseSubnetRouteToBgp(rd, subnetIp, nhDpnId, vpnName, elanTag, label);
+ addSubnetRouteToFib(rd, subnetIp, nhDpnId, vpnName, elanTag, label, subnetId);
subOpBuilder.setRouteAdvState(TaskState.Done);
} catch (Exception ex) {
logger.error("onSubnetAddedToVpn: FIB rules and Advertising nhDpnId " + nhDpnId +
try {
//Withdraw the routes for all the interfaces on this subnet
//Remove subnet route entry from FIB
- deleteSubnetRouteFromFib(rd, subnetIp, vpnName, nhDpnId);
- withdrawSubnetRoutefromBgp(rd, subnetIp);
+ deleteSubnetRouteFromFib(rd, subnetIp, vpnName);
} catch (Exception ex) {
logger.error("onSubnetAddedToVpn: Withdrawing routes from BGP for subnet " +
subnetId.getValue() + " failed {}" + ex);
logger.error("Unable to fetch label from Id Manager. Bailing out of handling addition of port {} to subnet {} in vpn {}", portId.getValue(), subnetIp, vpnName);
return;
}
- addSubnetRouteToFib(rd, subnetIp, nhDpnId, vpnName, elanTag, label);
- advertiseSubnetRouteToBgp(rd, subnetIp, nhDpnId, vpnName, elanTag, label);
+ addSubnetRouteToFib(rd, subnetIp, nhDpnId, vpnName, elanTag, label, subnetId);
subOpBuilder.setRouteAdvState(TaskState.Done);
} catch (Exception ex) {
logger.error("onPortAddedToSubnet: Advertising NextHopDPN "+ nhDpnId +
subOpBuilder.setNhDpnId(null);
try {
// withdraw route from BGP
- deleteSubnetRouteFromFib(rd, subnetIp, vpnName, nhDpnId);
- withdrawSubnetRoutefromBgp(rd, subnetIp);
+ deleteSubnetRouteFromFib(rd, subnetIp, vpnName);
subOpBuilder.setRouteAdvState(TaskState.Na);
} catch (Exception ex) {
logger.error("onPortRemovedFromSubnet: Withdrawing NextHopDPN " + dpnId + " information for subnet " +
logger.error("Unable to fetch label from Id Manager. Bailing out of handling removal of port {} from subnet {} in vpn {}", portId.getValue(), subnetIp, vpnName);
return;
}
- addSubnetRouteToFib(rd, subnetIp, nhDpnId, vpnName, elanTag, label);
- advertiseSubnetRouteToBgp(rd, subnetIp, nhDpnId, vpnName, elanTag, label);
+ addSubnetRouteToFib(rd, subnetIp, nhDpnId, vpnName, elanTag, label, subnetId);
subOpBuilder.setRouteAdvState(TaskState.Done);
} catch (Exception ex) {
logger.error("onPortRemovedFromSubnet: Swapping Withdrawing NextHopDPN " + dpnId +
logger.error("Unable to fetch label from Id Manager. Bailing out of handling interface up event for port {} for subnet {} in vpn {}", intfName, subnetIp, vpnName);
return;
}
- addSubnetRouteToFib(rd, subnetIp, nhDpnId, vpnName, elanTag, label);
- advertiseSubnetRouteToBgp(rd, subnetIp, nhDpnId, vpnName, elanTag, label);
+ addSubnetRouteToFib(rd, subnetIp, nhDpnId, vpnName, elanTag, label, subnetId);
subOpBuilder.setRouteAdvState(TaskState.Done);
} catch (Exception ex) {
logger.error("onInterfaceUp: Advertising NextHopDPN " + nhDpnId + " information for subnet " +
subOpBuilder.setNhDpnId(null);
try {
// Withdraw route from BGP for this subnet
- deleteSubnetRouteFromFib(rd, subnetIp, vpnName, nhDpnId);
- withdrawSubnetRoutefromBgp(rd, subnetIp);
+ deleteSubnetRouteFromFib(rd, subnetIp, vpnName);
subOpBuilder.setRouteAdvState(TaskState.Na);
} catch (Exception ex) {
logger.error("onInterfaceDown: Withdrawing NextHopDPN " + dpnId + " information for subnet " +
logger.error("Unable to fetch label from Id Manager. Bailing out of handling interface down event for port {} in subnet {} for vpn {}", interfaceName, subnetIp, vpnName);
return;
}
- addSubnetRouteToFib(rd, subnetIp, nhDpnId, vpnName, elanTag, label);
- advertiseSubnetRouteToBgp(rd, subnetIp, nhDpnId, vpnName, elanTag, label);
+ addSubnetRouteToFib(rd, subnetIp, nhDpnId, vpnName, elanTag, label, subnetId);
subOpBuilder.setRouteAdvState(TaskState.Done);
} catch (Exception ex) {
logger.error("onInterfaceDown: Swapping Withdrawing NextHopDPN " + dpnId + " information for subnet " +
}
private void addSubnetRouteToFib(String rd, String subnetIp, BigInteger nhDpnId, String vpnName,
- Long elanTag, int label) {
+ Long elanTag, int label, Uuid subnetId) throws Exception {
Preconditions.checkNotNull(rd, "RouteDistinguisher cannot be null or empty!");
Preconditions.checkNotNull(subnetIp, "SubnetRouteIp cannot be null or empty!");
Preconditions.checkNotNull(vpnName, "vpnName cannot be null or empty!");
Preconditions.checkNotNull(elanTag, "elanTag cannot be null or empty!");
- String nexthopIp = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, nhDpnId);
- if(nexthopIp != null)
- vpnInterfaceManager.addSubnetRouteFibEntryToDS(rd, vpnName, subnetIp, nexthopIp, label, elanTag, nhDpnId , null);
- else
- logger.info("Unable to get nextHop ip address for nextHop DPN {}. Abort adding subnet route to FIB table.", nhDpnId);
+ String nexthopIp = null;
+ try {
+ nexthopIp = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, nhDpnId);
+ } catch (Exception e) {
+ logger.warn("Unable to find nexthopip for subnetroute subnetip {}", subnetIp);
+ return;
+ }
+ if (nexthopIp != null) {
+ VpnUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(VpnUtil.getVpnId(dataBroker, vpnName), subnetIp), VpnUtil.getPrefixToInterface(nhDpnId, subnetId.getValue(), subnetIp));
+ vpnInterfaceManager.addSubnetRouteFibEntryToDS(rd, vpnName, subnetIp, nexthopIp, label, elanTag, nhDpnId, null);
+ try {
+ // BGPManager (inside ODL) requires a withdraw followed by advertise
+ // due to bugs with ClusterDataChangeListener used by BGPManager.
+ //bgpManager.withdrawPrefix(rd, subnetIp);
+ bgpManager.advertisePrefix(rd, subnetIp, Arrays.asList(nexthopIp), label);
+ } catch (Exception e) {
+ logger.error("Fail: Subnet route not advertised for rd {} subnetIp {}", rd, subnetIp, e);
+ throw e;
+ }
+ } else {
+ logger.warn("The nexthopip is empty for subnetroute subnetip {}, ignoring fib route addition", subnetIp);
+ }
}
private int getLabel(String rd, String subnetIp) {
return label;
}
- private void deleteSubnetRouteFromFib(String rd, String subnetIp, String vpnName,
- BigInteger nhDpnId) {
+ private void deleteSubnetRouteFromFib(String rd, String subnetIp, String vpnName) throws Exception {
Preconditions.checkNotNull(rd, "RouteDistinguisher cannot be null or empty!");
Preconditions.checkNotNull(subnetIp, "SubnetRouteIp cannot be null or empty!");
vpnInterfaceManager.deleteSubnetRouteFibEntryFromDS(rd, subnetIp, vpnName);
- }
-
- private void advertiseSubnetRouteToBgp(String rd, String subnetIp, BigInteger nhDpnId, String vpnName,
- Long elanTag, int label) throws Exception {
- Preconditions.checkNotNull(rd, "RouteDistinguisher cannot be null or empty!");
- Preconditions.checkNotNull(subnetIp, "SubnetRouteIp cannot be null or empty!");
- Preconditions.checkNotNull(elanTag, "elanTag cannot be null or empty!");
- Preconditions.checkNotNull(nhDpnId, "nhDpnId cannot be null or empty!");
- Preconditions.checkNotNull(vpnName, "vpnName cannot be null or empty!");
- String nexthopIp = null;
- nexthopIp = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, nhDpnId);
- if (nexthopIp == null) {
- logger.error("createSubnetRouteInVpn: Unable to obtain endpointIp address for DPNId " + nhDpnId);
- throw new Exception("Unable to obtain endpointIp address for DPNId " + nhDpnId);
- }
- try {
- // BGPManager (inside ODL) requires a withdraw followed by advertise
- // due to bugs with ClusterDataChangeListener used by BGPManager.
- //bgpManager.withdrawPrefix(rd, subnetIp);
- bgpManager.advertisePrefix(rd, subnetIp, Arrays.asList(nexthopIp), label);
- } catch (Exception e) {
- logger.error("Subnet route not advertised for rd " + rd + " failed ", e);
- throw e;
- }
- }
-
- private void withdrawSubnetRoutefromBgp(String rd, String subnetIp) throws Exception {
- Preconditions.checkNotNull(rd, "RouteDistinguisher cannot be null or empty!");
- Preconditions.checkNotNull(subnetIp, "SubnetIp cannot be null or empty!");
try {
bgpManager.withdrawPrefix(rd, subnetIp);
} catch (Exception e) {
- logger.error("Subnet route not advertised for rd " + rd + " failed ", e);
+ logger.error("Fail: Subnet route not withdrawn for rd {} subnetIp {}", rd, subnetIp, e);
throw e;
}
}