use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets in project netvirt by opendaylight.
the class TunnelInterfaceStateListener method handleTunnelEventForDPN.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleTunnelEventForDPN(StateTunnelList stateTunnelList, TunnelAction tunnelAction) {
final BigInteger srcDpnId = new BigInteger(stateTunnelList.getSrcInfo().getTepDeviceId());
final String srcTepIp = String.valueOf(stateTunnelList.getSrcInfo().getTepIp().getValue());
String destTepIp = String.valueOf(stateTunnelList.getDstInfo().getTepIp().getValue());
String rd;
BigInteger remoteDpnId = null;
boolean isTepDeletedOnDpn = false;
LOG.info("handleTunnelEventForDPN: Handle tunnel event for srcDpn {} SrcTepIp {} DestTepIp {} ", srcDpnId, srcTepIp, destTepIp);
int tunTypeVal = getTunnelType(stateTunnelList);
LOG.trace("handleTunnelEventForDPN: tunTypeVal is {}", tunTypeVal);
try {
if (tunnelAction == TunnelAction.TUNNEL_EP_ADD) {
LOG.info("handleTunnelEventForDPN: Tunnel ADD event received for Dpn {} VTEP Ip {} destTepIp {}", srcDpnId, srcTepIp, destTepIp);
if (isTunnelInLogicalGroup(stateTunnelList)) {
return;
}
} else if (tunnelAction == TunnelAction.TUNNEL_EP_DELETE) {
LOG.info("handleTunnelEventForDPN: Tunnel DELETE event received for Dpn {} VTEP Ip {} DestTepIp {}", srcDpnId, srcTepIp, destTepIp);
// When tunnel EP is deleted on a DPN , VPN gets two deletion event.
// One for a DPN on which tunnel EP was deleted and another for other-end DPN.
// Update the adj for the vpninterfaces for a DPN on which TEP is deleted.
// Update the adj & VRF for the vpninterfaces for a DPN on which TEP is deleted.
// Dont update the adj & VRF for vpninterfaces for a DPN on which TEP is not deleted.
String endpointIpForDPN = null;
try {
endpointIpForDPN = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, srcDpnId);
} catch (Exception e) {
LOG.error("handleTunnelEventForDPN: Unable to resolve endpoint IP for srcDpn {}", srcDpnId);
/* this dpn does not have the VTEP */
endpointIpForDPN = null;
}
if (endpointIpForDPN == null) {
LOG.info("handleTunnelEventForDPN: Tunnel TEP is deleted on Dpn {} VTEP Ip {} destTepIp {}", srcDpnId, srcTepIp, destTepIp);
isTepDeletedOnDpn = true;
}
}
// Get the list of VpnInterfaces from Intf Mgr for a SrcDPN on which TEP is added/deleted
Future<RpcResult<GetDpnInterfaceListOutput>> result;
List<Interfaces> srcDpninterfacelist = new ArrayList<>();
List<Interfaces> destDpninterfacelist = new ArrayList<>();
try {
result = intfRpcService.getDpnInterfaceList(new GetDpnInterfaceListInputBuilder().setDpid(srcDpnId).build());
RpcResult<GetDpnInterfaceListOutput> rpcResult = result.get();
if (!rpcResult.isSuccessful()) {
LOG.error("handleTunnelEventForDPN: RPC Call to GetDpnInterfaceList for srcDpnid {} srcTepIp {}" + " destTepIP {} returned with Errors {}", srcDpnId, srcTepIp, destTepIp, rpcResult.getErrors());
} else {
srcDpninterfacelist = rpcResult.getResult().getInterfaces();
}
} catch (Exception e) {
LOG.error("handleTunnelEventForDPN: Exception when querying for GetDpnInterfaceList for srcDpnid {}" + " srcTepIp {} destTepIp {}", srcDpnId, srcTepIp, destTepIp, e);
}
// Get the list of VpnInterfaces from Intf Mgr for a destDPN only for internal tunnel.
if (tunTypeVal == VpnConstants.ITMTunnelLocType.Internal.getValue()) {
remoteDpnId = new BigInteger(stateTunnelList.getDstInfo().getTepDeviceId());
try {
result = intfRpcService.getDpnInterfaceList(new GetDpnInterfaceListInputBuilder().setDpid(remoteDpnId).build());
RpcResult<GetDpnInterfaceListOutput> rpcResult = result.get();
if (!rpcResult.isSuccessful()) {
LOG.error("handleTunnelEventForDPN: RPC Call to GetDpnInterfaceList for remoteDpnid {}" + " srcTepIP {} destTepIp {} returned with Errors {}", remoteDpnId, srcTepIp, destTepIp, rpcResult.getErrors());
} else {
destDpninterfacelist = rpcResult.getResult().getInterfaces();
}
} catch (Exception e) {
LOG.error("handleTunnelEventForDPN: Exception when querying for GetDpnInterfaceList" + " for remoteDpnid {} srcTepIp {} destTepIp {}", remoteDpnId, srcTepIp, destTepIp, e);
}
}
/*
* Iterate over the list of VpnInterface for a SrcDpn on which TEP is added or deleted and read the adj.
* Update the adjacencies with the updated nexthop.
*/
Iterator<Interfaces> interfacelistIter = srcDpninterfacelist.iterator();
Interfaces interfaces = null;
String intfName = null;
List<Uuid> subnetList = new ArrayList<>();
Map<Long, String> vpnIdRdMap = new HashMap<>();
Set<String> listVpnName = new HashSet<>();
while (interfacelistIter.hasNext()) {
interfaces = interfacelistIter.next();
if (!L2vlan.class.equals(interfaces.getInterfaceType())) {
LOG.info("handleTunnelEventForDPN: Interface {} not of type L2Vlan", interfaces.getInterfaceName());
return;
}
intfName = interfaces.getInterfaceName();
VpnInterface vpnInterface = VpnUtil.getConfiguredVpnInterface(dataBroker, intfName);
if (vpnInterface != null && !Boolean.TRUE.equals(vpnInterface.isScheduledForRemove())) {
listVpnName.addAll(VpnHelper.getVpnInterfaceVpnInstanceNamesString(vpnInterface.getVpnInstanceNames()));
handleTunnelEventForDPNVpn(stateTunnelList, vpnIdRdMap, tunnelAction, isTepDeletedOnDpn, subnetList, TunnelEventProcessingMethod.POPULATESUBNETS, vpnInterface);
}
}
/*
* Iterate over the list of VpnInterface for destDPN and get the prefix .
* Create remote rule for each of those prefix on srcDPN.
*/
interfacelistIter = destDpninterfacelist.iterator();
while (interfacelistIter.hasNext()) {
interfaces = interfacelistIter.next();
if (!L2vlan.class.equals(interfaces.getInterfaceType())) {
LOG.info("handleTunnelEventForDPN: Interface {} not of type L2Vlan", interfaces.getInterfaceName());
return;
}
intfName = interfaces.getInterfaceName();
VpnInterface vpnInterface = VpnUtil.getConfiguredVpnInterface(dataBroker, intfName);
if (vpnInterface != null) {
handleTunnelEventForDPNVpn(stateTunnelList, vpnIdRdMap, tunnelAction, isTepDeletedOnDpn, subnetList, TunnelEventProcessingMethod.MANAGEREMOTEROUTES, vpnInterface);
}
}
// Iterate over the VpnId-to-Rd map.
for (Map.Entry<Long, String> entry : vpnIdRdMap.entrySet()) {
Long vpnId = entry.getKey();
rd = entry.getValue();
if (tunnelAction == TunnelAction.TUNNEL_EP_ADD && tunTypeVal == VpnConstants.ITMTunnelLocType.External.getValue()) {
fibManager.populateExternalRoutesOnDpn(srcDpnId, vpnId, rd, srcTepIp, destTepIp);
} else if (tunnelAction == TunnelAction.TUNNEL_EP_DELETE && tunTypeVal == VpnConstants.ITMTunnelLocType.External.getValue()) {
fibManager.cleanUpExternalRoutesOnDpn(srcDpnId, vpnId, rd, srcTepIp, destTepIp);
}
}
if (listVpnName.size() >= 1) {
if (tunnelAction == TunnelAction.TUNNEL_EP_ADD) {
for (Uuid subnetId : subnetList) {
// Populate the List of subnets
vpnSubnetRouteHandler.updateSubnetRouteOnTunnelUpEvent(subnetId, srcDpnId);
}
}
if (tunnelAction == TunnelAction.TUNNEL_EP_DELETE && isTepDeletedOnDpn) {
for (Uuid subnetId : subnetList) {
// Populate the List of subnets
vpnSubnetRouteHandler.updateSubnetRouteOnTunnelDownEvent(subnetId, srcDpnId);
}
}
}
} catch (RuntimeException e) {
LOG.error("handleTunnelEventForDpn: Unable to handle the tunnel event for srcDpnId {} srcTepIp {}" + " remoteDpnId {} destTepIp {}", srcDpnId, srcTepIp, remoteDpnId, destTepIp, e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets in project netvirt by opendaylight.
the class RouterDpnChangeListener method installDefaultNatRouteForRouterExternalSubnets.
private void installDefaultNatRouteForRouterExternalSubnets(BigInteger dpnId, Collection<Uuid> externalSubnetIds) {
if (externalSubnetIds == null) {
LOG.error("installDefaultNatRouteForRouterExternalSubnets : No external subnets for router");
return;
}
for (Uuid subnetId : externalSubnetIds) {
long vpnIdForSubnet = NatUtil.getExternalSubnetVpnId(dataBroker, subnetId);
if (vpnIdForSubnet != NatConstants.INVALID_ID) {
LOG.info("installDefaultNatRouteForRouterExternalSubnets : Installing default routes in FIB on dpn {} " + "for subnetId {} with vpnId {}", dpnId, subnetId, vpnIdForSubnet);
snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnIdForSubnet, subnetId.getValue());
} else {
LOG.debug("installDefaultNatRouteForRouterExternalSubnets : No vpnID for subnet {} found", subnetId);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets in project netvirt by opendaylight.
the class ExternalRoutersListener method allocateExternalIp.
private void allocateExternalIp(BigInteger dpnId, Routers router, long routerId, String routerName, Uuid networkId, String subnetIp, WriteTransaction writeFlowInvTx) {
String[] subnetIpParts = NatUtil.getSubnetIpAndPrefix(subnetIp);
try {
InetAddress address = InetAddress.getByName(subnetIpParts[0]);
if (address instanceof Inet6Address) {
LOG.debug("allocateExternalIp : Skipping ipv6 address {} for the router {}.", address, routerName);
return;
}
} catch (UnknownHostException e) {
LOG.error("allocateExternalIp : Invalid ip address {}", subnetIpParts[0], e);
return;
}
String leastLoadedExtIpAddr = NatUtil.getLeastLoadedExternalIp(dataBroker, routerId);
if (leastLoadedExtIpAddr != null) {
String[] externalIpParts = NatUtil.getExternalIpAndPrefix(leastLoadedExtIpAddr);
String leastLoadedExtIp = externalIpParts[0];
String leastLoadedExtIpPrefix = externalIpParts[1];
IPAddress externalIpAddr = new IPAddress(leastLoadedExtIp, Integer.parseInt(leastLoadedExtIpPrefix));
subnetIp = subnetIpParts[0];
String subnetIpPrefix = subnetIpParts[1];
IPAddress subnetIpAddr = new IPAddress(subnetIp, Integer.parseInt(subnetIpPrefix));
LOG.debug("allocateExternalIp : Add the IP mapping for the router ID {} and internal " + "IP {} and prefix {} -> external IP {} and prefix {}", routerId, subnetIp, subnetIpPrefix, leastLoadedExtIp, leastLoadedExtIpPrefix);
naptManager.registerMapping(routerId, subnetIpAddr, externalIpAddr);
// Check if external IP is already assigned a route. (i.e. External IP is previously
// allocated to any of the subnets)
// If external IP is already assigned a route, (, do not re-advertise to the BGP
String leastLoadedExtIpAddrStr = leastLoadedExtIp + "/" + leastLoadedExtIpPrefix;
Long label = checkExternalIpLabel(routerId, leastLoadedExtIpAddrStr);
if (label != null) {
// update
String internalIp = subnetIpParts[0] + "/" + subnetIpParts[1];
IpMapKey ipMapKey = new IpMapKey(internalIp);
LOG.debug("allocateExternalIp : Setting label {} for internalIp {} and externalIp {}", label, internalIp, leastLoadedExtIpAddrStr);
IpMap newIpm = new IpMapBuilder().setKey(ipMapKey).setInternalIp(internalIp).setExternalIp(leastLoadedExtIpAddrStr).setLabel(label).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, naptManager.getIpMapIdentifier(routerId, internalIp), newIpm);
return;
}
// Re-advertise to the BGP for the external IP, which is allocated to the subnet
// for the first time and hence not having a route.
// Get the VPN Name using the network ID
final String vpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
if (vpnName != null) {
LOG.debug("allocateExternalIp : Retrieved vpnName {} for networkId {}", vpnName, networkId);
if (dpnId == null || dpnId.equals(BigInteger.ZERO)) {
LOG.debug("allocateExternalIp : Best effort for getting primary napt switch when router i/f are" + "added after gateway-set");
dpnId = NatUtil.getPrimaryNaptfromRouterId(dataBroker, routerId);
if (dpnId == null || dpnId.equals(BigInteger.ZERO)) {
LOG.error("allocateExternalIp : dpnId is null or Zero for the router {}", routerName);
return;
}
}
advToBgpAndInstallFibAndTsFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, vpnName, routerId, routerName, leastLoadedExtIp + "/" + leastLoadedExtIpPrefix, networkId, router, writeFlowInvTx);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets in project netvirt by opendaylight.
the class WeightedCentralizedSwitchScheduler method addToDpnMaps.
private void addToDpnMaps(String routerName, List<Uuid> addedSubnetIds, BigInteger primarySwitchId) {
if (addedSubnetIds == null || addedSubnetIds.isEmpty()) {
LOG.debug("addToDpnMaps no subnets associated with {}", routerName);
return;
}
String primaryRd = NatUtil.getPrimaryRd(dataBroker, routerName);
WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
for (Uuid subnetUuid : addedSubnetIds) {
try {
Subnetmap subnetMapEntry = SingleTransactionDataBroker.syncRead(dataBroker, LogicalDatastoreType.CONFIGURATION, getSubnetMapIdentifier(subnetUuid));
Uuid routerPortUuid = subnetMapEntry.getRouterInterfacePortId();
subnetIdToRouterPortMap.put(subnetUuid.getValue(), routerPortUuid.getValue());
vpnFootprintService.updateVpnToDpnMapping(primarySwitchId, routerName, primaryRd, routerPortUuid.getValue(), null, true);
NatUtil.addToNeutronRouterDpnsMap(dataBroker, routerName, routerPortUuid.getValue(), primarySwitchId, writeOperTxn);
NatUtil.addToDpnRoutersMap(dataBroker, routerName, routerPortUuid.getValue(), primarySwitchId, writeOperTxn);
} catch (ReadFailedException e) {
LOG.error("addToDpnMaps failed for {}", routerName);
}
}
writeOperTxn.submit();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets in project netvirt by opendaylight.
the class ExternalRoutersListener method subnetRegisterMapping.
protected void subnetRegisterMapping(Routers routerEntry, Long segmentId) {
List<Uuid> subnetList = null;
List<String> externalIps = null;
LOG.debug("subnetRegisterMapping : Fetching values from extRouters model");
subnetList = routerEntry.getSubnetIds();
externalIps = NatUtil.getIpsListFromExternalIps(routerEntry.getExternalIps());
int counter = 0;
int extIpCounter = externalIps.size();
LOG.debug("subnetRegisterMapping : counter values before looping counter {} and extIpCounter {}", counter, extIpCounter);
for (Uuid subnet : subnetList) {
LOG.debug("subnetRegisterMapping : Looping internal subnets for subnet {}", subnet);
InstanceIdentifier<Subnetmap> subnetmapId = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnet)).build();
Optional<Subnetmap> sn = read(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetmapId);
if (sn.isPresent()) {
// subnets
Subnetmap subnetmapEntry = sn.get();
String subnetString = subnetmapEntry.getSubnetIp();
String[] subnetSplit = subnetString.split("/");
String subnetIp = subnetSplit[0];
try {
InetAddress address = InetAddress.getByName(subnetIp);
if (address instanceof Inet6Address) {
LOG.debug("subnetRegisterMapping : Skipping ipv6 subnet {} for the router {} with ipv6 address " + "{} ", subnet, routerEntry.getRouterName(), address);
continue;
}
} catch (UnknownHostException e) {
LOG.error("subnetRegisterMapping : Invalid ip address {}", subnetIp, e);
return;
}
String subnetPrefix = "0";
if (subnetSplit.length == 2) {
subnetPrefix = subnetSplit[1];
}
IPAddress subnetAddr = new IPAddress(subnetIp, Integer.parseInt(subnetPrefix));
LOG.debug("subnetRegisterMapping : subnetAddr is {} and subnetPrefix is {}", subnetAddr.getIpAddress(), subnetAddr.getPrefixLength());
// externalIps
LOG.debug("subnetRegisterMapping : counter values counter {} and extIpCounter {}", counter, extIpCounter);
if (extIpCounter != 0) {
if (counter < extIpCounter) {
String[] ipSplit = externalIps.get(counter).split("/");
String externalIp = ipSplit[0];
String extPrefix = Short.toString(NatConstants.DEFAULT_PREFIX);
if (ipSplit.length == 2) {
extPrefix = ipSplit[1];
}
IPAddress externalIpAddr = new IPAddress(externalIp, Integer.parseInt(extPrefix));
LOG.debug("subnetRegisterMapping : externalIp is {} and extPrefix is {}", externalIpAddr.getIpAddress(), externalIpAddr.getPrefixLength());
naptManager.registerMapping(segmentId, subnetAddr, externalIpAddr);
LOG.debug("subnetRegisterMapping : Called registerMapping for subnetIp {}, prefix {}, " + "externalIp {}. prefix {}", subnetIp, subnetPrefix, externalIp, extPrefix);
} else {
// Reset the counter which runs on externalIps for round-robbin effect
counter = 0;
LOG.debug("subnetRegisterMapping : Counter on externalIps got reset");
String[] ipSplit = externalIps.get(counter).split("/");
String externalIp = ipSplit[0];
String extPrefix = Short.toString(NatConstants.DEFAULT_PREFIX);
if (ipSplit.length == 2) {
extPrefix = ipSplit[1];
}
IPAddress externalIpAddr = new IPAddress(externalIp, Integer.parseInt(extPrefix));
LOG.debug("subnetRegisterMapping : externalIp is {} and extPrefix is {}", externalIpAddr.getIpAddress(), externalIpAddr.getPrefixLength());
naptManager.registerMapping(segmentId, subnetAddr, externalIpAddr);
LOG.debug("subnetRegisterMapping : Called registerMapping for subnetIp {}, prefix {}, " + "externalIp {}. prefix {}", subnetIp, subnetPrefix, externalIp, extPrefix);
}
}
counter++;
LOG.debug("subnetRegisterMapping : Counter on externalIps incremented to {}", counter);
} else {
LOG.warn("subnetRegisterMapping : No internal subnets present in extRouters Model");
}
}
}
Aggregations