use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix in project netvirt by opendaylight.
the class VrfEntryListener method cleanUpOpDataForFib.
protected void cleanUpOpDataForFib(Long vpnId, String primaryRd, final VrfEntry vrfEntry) {
/* Get interface info from prefix to interface mapping;
Use the interface info to get the corresponding vpn interface op DS entry,
remove the adjacency corresponding to this fib entry.
If adjacency removed is the last adjacency, clean up the following:
- vpn interface from dpntovpn list, dpn if last vpn interface on dpn
- prefix to interface entry
- vpn interface op DS
*/
LOG.debug("Cleanup of prefix {} in VPN {}", vrfEntry.getDestPrefix(), vpnId);
Prefixes prefixInfo = fibUtil.getPrefixToInterface(vpnId, vrfEntry.getDestPrefix());
if (prefixInfo == null) {
List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnId, vrfEntry.getDestPrefix());
String usedRd = usedRds.isEmpty() ? primaryRd : usedRds.get(0);
Routes extraRoute = baseVrfEntryHandler.getVpnToExtraroute(vpnId, usedRd, vrfEntry.getDestPrefix());
if (extraRoute != null) {
for (String nextHopIp : extraRoute.getNexthopIpList()) {
LOG.debug("NextHop IP for destination {} is {}", vrfEntry.getDestPrefix(), nextHopIp);
if (nextHopIp != null) {
String ipPrefix;
if (isIpv4Address(nextHopIp)) {
ipPrefix = nextHopIp + NwConstants.IPV4PREFIX;
} else {
ipPrefix = nextHopIp + NwConstants.IPV6PREFIX;
}
prefixInfo = fibUtil.getPrefixToInterface(vpnId, ipPrefix);
checkCleanUpOpDataForFib(prefixInfo, vpnId, primaryRd, vrfEntry, extraRoute);
}
}
}
if (prefixInfo == null) {
java.util.Optional<Long> optionalLabel = FibUtil.getLabelFromRoutePaths(vrfEntry);
if (optionalLabel.isPresent()) {
Long label = optionalLabel.get();
List<String> nextHopAddressList = FibHelper.getNextHopListFromRoutePaths(vrfEntry);
LabelRouteInfo lri = getLabelRouteInfo(label);
if (isPrefixAndNextHopPresentInLri(vrfEntry.getDestPrefix(), nextHopAddressList, lri)) {
PrefixesBuilder prefixBuilder = new PrefixesBuilder();
prefixBuilder.setDpnId(lri.getDpnId());
prefixBuilder.setVpnInterfaceName(lri.getVpnInterfaceName());
prefixBuilder.setIpAddress(lri.getPrefix());
prefixInfo = prefixBuilder.build();
LOG.debug("Fetched labelRouteInfo for label {} interface {} and got dpn {}", label, prefixInfo.getVpnInterfaceName(), lri.getDpnId());
checkCleanUpOpDataForFib(prefixInfo, vpnId, primaryRd, vrfEntry, extraRoute);
}
}
}
} else {
checkCleanUpOpDataForFib(prefixInfo, vpnId, primaryRd, vrfEntry, null);
}
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix in project netvirt by opendaylight.
the class BaseVrfEntryHandler method resolveAdjacency.
@Nonnull
protected List<AdjacencyResult> resolveAdjacency(final BigInteger remoteDpnId, final long vpnId, final VrfEntry vrfEntry, String rd) {
List<RoutePaths> routePaths = vrfEntry.getRoutePaths();
FibHelper.sortIpAddress(routePaths);
List<AdjacencyResult> adjacencyList = new ArrayList<>();
List<String> prefixIpList;
LOG.trace("resolveAdjacency called with remotedDpnId {}, vpnId{}, VrfEntry {}", remoteDpnId, vpnId, vrfEntry);
try {
if (RouteOrigin.value(vrfEntry.getOrigin()) != RouteOrigin.BGP) {
List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnId, vrfEntry.getDestPrefix());
List<Routes> vpnExtraRoutes = VpnExtraRouteHelper.getAllVpnExtraRoutes(dataBroker, fibUtil.getVpnNameFromId(vpnId), usedRds, vrfEntry.getDestPrefix());
if (vpnExtraRoutes.isEmpty()) {
Prefixes prefixInfo = fibUtil.getPrefixToInterface(vpnId, vrfEntry.getDestPrefix());
// We don't want to provide an adjacencyList for an extra-route-prefix.
if (prefixInfo == null) {
LOG.debug("The extra route {} in rd {} for vpn {} has been removed from all the next hops", vrfEntry.getDestPrefix(), rd, vpnId);
return adjacencyList;
}
prefixIpList = Collections.singletonList(vrfEntry.getDestPrefix());
} else {
List<String> prefixIpListLocal = new ArrayList<>();
vpnExtraRoutes.stream().forEach(route -> {
route.getNexthopIpList().stream().forEach(extraRouteIp -> {
String ipPrefix;
if (isIpv4Address(extraRouteIp)) {
ipPrefix = extraRouteIp + NwConstants.IPV4PREFIX;
} else {
ipPrefix = extraRouteIp + NwConstants.IPV6PREFIX;
}
prefixIpListLocal.add(ipPrefix);
});
});
prefixIpList = prefixIpListLocal;
}
} else {
prefixIpList = Collections.singletonList(vrfEntry.getDestPrefix());
}
for (String prefixIp : prefixIpList) {
if (routePaths == null || routePaths.isEmpty()) {
LOG.trace("Processing Destination IP {} without NextHop IP", prefixIp);
AdjacencyResult adjacencyResult = nextHopManager.getRemoteNextHopPointer(remoteDpnId, vpnId, prefixIp, null);
addAdjacencyResultToList(adjacencyList, adjacencyResult);
continue;
}
adjacencyList.addAll(routePaths.stream().map(routePath -> {
LOG.debug("NextHop IP for destination {} is {}", prefixIp, routePath.getNexthopAddress());
return nextHopManager.getRemoteNextHopPointer(remoteDpnId, vpnId, prefixIp, routePath.getNexthopAddress());
}).filter(adjacencyResult -> adjacencyResult != null && !adjacencyList.contains(adjacencyResult)).distinct().collect(toList()));
}
} catch (NullPointerException e) {
LOG.trace("", e);
}
return adjacencyList;
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix in project netvirt by opendaylight.
the class BaseVrfEntryHandler method addRewriteDstMacAction.
protected void addRewriteDstMacAction(long vpnId, VrfEntry vrfEntry, Prefixes prefixInfo, List<ActionInfo> actionInfos) {
if (vrfEntry.getMac() != null) {
actionInfos.add(new ActionSetFieldEthernetDestination(actionInfos.size(), new MacAddress(vrfEntry.getMac())));
return;
}
if (prefixInfo == null) {
prefixInfo = fibUtil.getPrefixToInterface(vpnId, vrfEntry.getDestPrefix());
// Checking PrefixtoInterface again as it is populated later in some cases
if (prefixInfo == null) {
LOG.debug("No prefix info found for prefix {}", vrfEntry.getDestPrefix());
return;
}
}
String ipPrefix = prefixInfo.getIpAddress();
String ifName = prefixInfo.getVpnInterfaceName();
if (ifName == null) {
LOG.debug("Failed to get VPN interface for prefix {}", ipPrefix);
return;
}
String vpnName = fibUtil.getVpnNameFromId(vpnId);
if (vpnName == null) {
LOG.debug("Failed to get VPN name for vpnId {}", vpnId);
return;
}
String macAddress = fibUtil.getMacAddressFromPrefix(ifName, vpnName, ipPrefix);
if (macAddress == null) {
LOG.warn("No MAC address found for VPN interface {} prefix {}", ifName, ipPrefix);
return;
}
actionInfos.add(new ActionSetFieldEthernetDestination(actionInfos.size(), new MacAddress(macAddress)));
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix in project netvirt by opendaylight.
the class IfMgr method addSubnet.
/**
* Add Subnet.
*
* @param snetId subnet id
* @param name subnet name
* @param tenantId tenant id
* @param gatewayIp gateway ip address
* @param ipVersion IP Version "IPv4 or IPv6"
* @param subnetCidr subnet CIDR
* @param ipV6AddressMode Address Mode of IPv6 Subnet
* @param ipV6RaMode RA Mode of IPv6 Subnet.
*/
public void addSubnet(Uuid snetId, String name, Uuid tenantId, IpAddress gatewayIp, String ipVersion, IpPrefix subnetCidr, String ipV6AddressMode, String ipV6RaMode) {
// in expanded form and are used during Neighbor Discovery Support.
if (gatewayIp != null) {
Ipv6Address addr = new Ipv6Address(InetAddresses.forString(gatewayIp.getIpv6Address().getValue()).getHostAddress());
gatewayIp = new IpAddress(addr);
}
VirtualSubnet snet = VirtualSubnet.builder().subnetUUID(snetId).tenantID(tenantId).name(name).gatewayIp(gatewayIp).subnetCidr(subnetCidr).ipVersion(ipVersion).ipv6AddressMode(ipV6AddressMode).ipv6RAMode(ipV6RaMode).build();
vsubnets.put(snetId, snet);
List<VirtualPort> intfList = unprocessedSubnetIntfs.remove(snetId);
if (intfList == null) {
LOG.debug("No unprocessed interfaces for the subnet {}", snetId);
return;
}
synchronized (intfList) {
for (VirtualPort intf : intfList) {
if (intf != null) {
intf.setSubnet(snetId, snet);
snet.addInterface(intf);
VirtualRouter rtr = intf.getRouter();
if (rtr != null) {
rtr.addSubnet(snet);
}
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix in project netvirt by opendaylight.
the class AclServiceUtils method cleanUpStaleEntriesInAclPortsLookup.
private void cleanUpStaleEntriesInAclPortsLookup(String aclName, WriteTransaction tx) {
AclPortsByIp aclPortsByIp = getAclPortsByIpFromOperDs(aclName);
if (aclPortsByIp == null) {
return;
}
boolean deleteEntireAcl;
List<AclIpPrefixes> ipPrefixes = aclPortsByIp.getAclIpPrefixes();
if (ipPrefixes == null || ipPrefixes.isEmpty()) {
deleteEntireAcl = true;
} else {
boolean deleteMap = true;
for (AclIpPrefixes ipPrefix : ipPrefixes) {
if (ipPrefix.getPortIds() != null && !ipPrefix.getPortIds().isEmpty()) {
deleteMap = false;
break;
}
}
deleteEntireAcl = deleteMap;
}
if (deleteEntireAcl) {
tx.delete(LogicalDatastoreType.OPERATIONAL, AclServiceUtils.aclPortsByIpPath(aclName));
} else {
for (AclIpPrefixes ipPrefix : ipPrefixes) {
if (ipPrefix.getPortIds() == null || ipPrefix.getPortIds().isEmpty()) {
InstanceIdentifier<AclIpPrefixes> delPath = AclServiceUtils.getAclIpPrefixesPath(aclName, ipPrefix.getIpPrefix());
tx.delete(LogicalDatastoreType.OPERATIONAL, delPath);
}
}
}
}
Aggregations