use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap in project netvirt by opendaylight.
the class NaptManager method removeFromIpPortMapDS.
protected void removeFromIpPortMapDS(long segmentId, String internalIpPort, ProtocolTypes protocolType) {
InstanceIdentifierBuilder<IpPortMap> idBuilder = InstanceIdentifier.builder(IntextIpPortMap.class).child(IpPortMapping.class, new IpPortMappingKey(segmentId)).child(IntextIpProtocolType.class, new IntextIpProtocolTypeKey(protocolType)).child(IpPortMap.class, new IpPortMapKey(internalIpPort));
InstanceIdentifier<IpPortMap> id = idBuilder.build();
// remove from ipportmap DS
LOG.debug("removeFromIpPortMapDS : Removing ipportmap from datastore : {}", id);
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap in project netvirt by opendaylight.
the class NaptSwitchHA method handleNatFlowsInNewNaptSwitch.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private boolean handleNatFlowsInNewNaptSwitch(String routerName, Long routerId, BigInteger oldNaptSwitch, BigInteger newNaptSwitch, Long routerVpnId, Uuid networkId) {
LOG.debug("handleNatFlowsInNewNaptSwitch : Proceeding to install flows in newNaptSwitch {} for routerId {}", newNaptSwitch, routerId);
IpPortMapping ipPortMapping = NatUtil.getIportMapping(dataBroker, routerId);
if (ipPortMapping == null || ipPortMapping.getIntextIpProtocolType() == null || ipPortMapping.getIntextIpProtocolType().isEmpty()) {
LOG.debug("handleNatFlowsInNewNaptSwitch : No Internal Ip Port mapping associated to router {}," + "no flows need to be installed in newNaptSwitch {}", routerId, newNaptSwitch);
return true;
}
// getvpnId
Long vpnId = getVpnIdForRouter(routerId, networkId);
if (vpnId == NatConstants.INVALID_ID) {
LOG.error("handleNatFlowsInNewNaptSwitch : Invalid vpnId for routerId {}", routerId);
return false;
}
Long bgpVpnId;
if (routerId.equals(routerVpnId)) {
bgpVpnId = NatConstants.INVALID_ID;
} else {
bgpVpnId = routerVpnId;
}
LOG.debug("handleNatFlowsInNewNaptSwitch : retrieved bgpVpnId {} for router {}", bgpVpnId, routerId);
// Get the External Gateway MAC Address
String extGwMacAddress = NatUtil.getExtGwMacAddFromRouterName(dataBroker, routerName);
if (extGwMacAddress != null) {
LOG.debug("handleNatFlowsInNewNaptSwitch :External Gateway MAC address {} found for External Router ID {}", extGwMacAddress, routerId);
} else {
LOG.error("handleNatFlowsInNewNaptSwitch : No External Gateway MAC address found for External Router ID {}", routerId);
return false;
}
for (IntextIpProtocolType protocolType : ipPortMapping.getIntextIpProtocolType()) {
if (protocolType.getIpPortMap() == null || protocolType.getIpPortMap().isEmpty()) {
LOG.debug("handleNatFlowsInNewNaptSwitch : No {} session associated to router {}", protocolType.getProtocol(), routerId);
return true;
}
for (IpPortMap intIpPortMap : protocolType.getIpPortMap()) {
String internalIpAddress = intIpPortMap.getIpPortInternal().split(":")[0];
String intportnum = intIpPortMap.getIpPortInternal().split(":")[1];
LOG.debug("handleNatFlowsInNewNaptSwitch : Found Internal IP Address {} and Port Number {}", internalIpAddress, intportnum);
// Get the external IP address and the port from the model
NAPTEntryEvent.Protocol proto = protocolType.getProtocol().toString().equals(ProtocolTypes.TCP.toString()) ? NAPTEntryEvent.Protocol.TCP : NAPTEntryEvent.Protocol.UDP;
IpPortExternal ipPortExternal = NatUtil.getExternalIpPortMap(dataBroker, routerId, internalIpAddress, intportnum, proto);
if (ipPortExternal == null) {
LOG.debug("handleNatFlowsInNewNaptSwitch : External Ipport mapping is not found for internalIp {} " + "with port {}", internalIpAddress, intportnum);
continue;
}
String externalIpAddress = ipPortExternal.getIpAddress();
Integer extportNumber = ipPortExternal.getPortNum();
LOG.debug("handleNatFlowsInNewNaptSwitch : ExternalIPport {}:{} mapping for internal ipport {}:{}", externalIpAddress, extportNumber, internalIpAddress, intportnum);
SessionAddress sourceAddress = new SessionAddress(internalIpAddress, Integer.parseInt(intportnum));
SessionAddress externalAddress = new SessionAddress(externalIpAddress, extportNumber);
// checking naptSwitch status before installing flows
if (getSwitchStatus(newNaptSwitch)) {
// Install the flow in newNaptSwitch Inbound NAPT table.
try {
naptEventHandler.buildAndInstallNatFlows(newNaptSwitch, NwConstants.INBOUND_NAPT_TABLE, vpnId, routerId, bgpVpnId, externalAddress, sourceAddress, proto, extGwMacAddress);
} catch (RuntimeException ex) {
LOG.error("handleNatFlowsInNewNaptSwitch : Failed to add flow in INBOUND_NAPT_TABLE for " + "routerid {} dpnId {} extIpport{}:{} proto {} ipport {}:{} BgpVpnId {}", routerId, newNaptSwitch, externalAddress, extportNumber, proto, internalIpAddress, intportnum, bgpVpnId);
return false;
}
LOG.debug("handleNatFlowsInNewNaptSwitch : Successfully installed a flow in Primary switch {} " + "Inbound NAPT table for router {} ipport {}:{} proto {} extIpport {}:{} BgpVpnId {}", newNaptSwitch, routerId, internalIpAddress, intportnum, proto, externalAddress, extportNumber, bgpVpnId);
// Install the flow in newNaptSwitch Outbound NAPT table.
try {
naptEventHandler.buildAndInstallNatFlows(newNaptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, vpnId, routerId, bgpVpnId, sourceAddress, externalAddress, proto, extGwMacAddress);
} catch (RuntimeException ex) {
LOG.error("handleNatFlowsInNewNaptSwitch : Failed to add flow in OUTBOUND_NAPT_TABLE for " + "routerid {} dpnId {} ipport {}:{} proto {} extIpport {}:{} BgpVpnId {}", routerId, newNaptSwitch, internalIpAddress, intportnum, proto, externalAddress, extportNumber, bgpVpnId, ex);
return false;
}
LOG.debug("handleNatFlowsInNewNaptSwitch : Successfully installed a flow in Primary switch {} " + "Outbound NAPT table for router {} ipport {}:{} proto {} extIpport {}:{} BgpVpnId {}", newNaptSwitch, routerId, internalIpAddress, intportnum, proto, externalAddress, extportNumber, bgpVpnId);
} else {
LOG.error("handleNatFlowsInNewNaptSwitch : NewNaptSwitch {} gone down while installing flows " + "from oldNaptswitch {}", newNaptSwitch, oldNaptSwitch);
return false;
}
}
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap in project netvirt by opendaylight.
the class NatRpcServiceImpl method getNatTranslationsForNetworkAndIpaddress.
public Future<RpcResult<GetNatTranslationsForNetworkAndIpaddressOutput>> getNatTranslationsForNetworkAndIpaddress(GetNatTranslationsForNetworkAndIpaddressInput input) {
String ipAddress = String.valueOf(input.getIpAddress().getValue());
RpcResultBuilder<GetNatTranslationsForNetworkAndIpaddressOutput> rpcResultBuilder = null;
GetNatTranslationsForNetworkAndIpaddressOutputBuilder output = null;
List<Uuid> subnetUuidList = NatUtil.getSubnetIdsFromNetworkId(dataBroker, input.getNetworkUuid());
if (subnetUuidList.isEmpty()) {
String errMsg = String.format("404 Not Found - Invalid Network UUID {%s} provided as no Subnetworks found", input.getNetworkUuid().getValue());
rpcResultBuilder = RpcResultBuilder.<GetNatTranslationsForNetworkAndIpaddressOutput>failed().withError(RpcError.ErrorType.APPLICATION, errMsg);
return Futures.immediateFuture(rpcResultBuilder.build());
}
Subnet subNet = null;
Boolean isIpInSubnet = Boolean.FALSE;
outerloop: for (Uuid subnetUuid : subnetUuidList) {
subNet = nvpnManager.getNeutronSubnet(subnetUuid);
for (AllocationPools allocationPool : subNet.getAllocationPools()) {
if (NatUtil.isIpInSubnet(ipAddress, String.valueOf(allocationPool.getStart().getValue()), String.valueOf(allocationPool.getEnd().getValue()))) {
LOG.debug("getNatTranslationsForNetworkAndIpaddress : IP Adderess {} falls within the Subnet {}", ipAddress, subNet.getUuid().getValue());
isIpInSubnet = Boolean.TRUE;
break outerloop;
}
}
}
if (!isIpInSubnet) {
String errMsg = String.format("404 Not Found - IP Adress {%s} does not fall within the Subnet IP range" + " of Network {%s}", ipAddress, input.getNetworkUuid().getValue());
rpcResultBuilder = RpcResultBuilder.<GetNatTranslationsForNetworkAndIpaddressOutput>failed().withError(RpcError.ErrorType.APPLICATION, errMsg);
return Futures.immediateFuture(rpcResultBuilder.build());
}
Subnetmap subnetMap = NatUtil.getSubnetMap(dataBroker, subNet.getUuid());
long routerId = NatUtil.getVpnId(dataBroker, subnetMap.getRouterId().getValue());
List<Ports> fipPorts = NatUtil.getFloatingIpPortsForRouter(dataBroker, subnetMap.getRouterId());
if (fipPorts.isEmpty()) {
LOG.warn("getNatTranslationsForNetworkAndIpaddress : No DNAT IP Mapping found for IP {}", ipAddress);
} else {
for (Ports fipPort : fipPorts) {
List<InternalToExternalPortMap> ipMapping = fipPort.getInternalToExternalPortMap();
for (InternalToExternalPortMap fipMap : ipMapping) {
if (fipMap.getInternalIp().equals(ipAddress)) {
output = new GetNatTranslationsForNetworkAndIpaddressOutputBuilder().setExternalIp(fipMap.getExternalIp()).setNatTranslation("DNAT");
rpcResultBuilder = RpcResultBuilder.success();
rpcResultBuilder.withResult(output.build());
return Futures.immediateFuture(rpcResultBuilder.build());
}
}
}
}
IpPortMapping ipPortMapping = NatUtil.getIportMapping(dataBroker, routerId);
if (ipPortMapping == null) {
LOG.warn("getNatTranslationsForNetworkAndIpaddress : No SNAT IP Mapping found for IP {}", ipAddress);
} else {
for (IntextIpProtocolType protocolType : ipPortMapping.getIntextIpProtocolType()) {
for (IpPortMap ipPortMap : protocolType.getIpPortMap()) {
String[] internalIpPort = ipPortMap.getIpPortInternal().split(NwConstants.MACADDR_SEP);
if (ipAddress.equals(internalIpPort[0])) {
output = new GetNatTranslationsForNetworkAndIpaddressOutputBuilder().setExternalIp(ipPortMap.getIpPortExternal().getIpAddress()).setInternalIp(internalIpPort[0]).setNatTranslation("SNAT").setInternalPort(internalIpPort[1]).setExternalPort(ipPortMap.getIpPortExternal().getPortNum().toString()).setProtocol(protocolType.getProtocol().getName());
rpcResultBuilder = RpcResultBuilder.success();
rpcResultBuilder.withResult(output.build());
return Futures.immediateFuture(rpcResultBuilder.build());
}
}
}
}
String errMsg = String.format("404 Not Found - No NAT Translation found for IP {%s}", ipAddress);
rpcResultBuilder = RpcResultBuilder.<GetNatTranslationsForNetworkAndIpaddressOutput>failed().withError(RpcError.ErrorType.APPLICATION, errMsg);
return Futures.immediateFuture(rpcResultBuilder.build());
}
Aggregations