use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.route.monitoring.message.Update in project netvirt by opendaylight.
the class BgpConfigurationManager method setMultipathStatus.
public void setMultipathStatus(af_afi afi, af_safi safi, boolean enable) {
long lafi = afi.getValue();
long lsafi = safi.getValue();
InstanceIdentifier.InstanceIdentifierBuilder<Multipath> iib = InstanceIdentifier.builder(Bgp.class).child(MultipathContainer.class).child(Multipath.class, new MultipathKey(Long.valueOf(afi.getValue()), Long.valueOf(safi.getValue())));
Multipath dto = new MultipathBuilder().setAfi(lafi).setSafi(lsafi).setMultipathEnabled(enable).build();
update(iib.build(), dto);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.route.monitoring.message.Update in project netvirt by opendaylight.
the class ExternalRoutersListener method update.
@Override
public void update(InstanceIdentifier<Routers> identifier, Routers original, Routers update) {
if (natMode != NatMode.Controller) {
return;
}
LOG.trace("update : origRouter: {} updatedRouter: {}", original, update);
String routerName = original.getRouterName();
Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("update : external router event - Invalid routerId for routerName {}", routerName);
return;
}
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + update.key(), () -> {
List<ListenableFuture<?>> futures = new ArrayList<>();
futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, writeFlowInvTx -> {
futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, removeFlowInvTx -> {
Uint32 bgpVpnId = NatConstants.INVALID_ID;
Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
if (bgpVpnUuid != null) {
bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
}
// BigInteger dpnId = getPrimaryNaptSwitch(routerName);
/* Get Primary Napt Switch for existing router from "router-to-napt-switch" DS.
* if dpnId value is null or zero then go for electing new Napt switch for existing router.
*/
Uint64 dpnId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
boolean isPrimaryNaptSwitchNotSelected = (dpnId == null || dpnId.equals(Uint64.valueOf(BigInteger.ZERO)));
Uuid networkId = original.getNetworkId();
// Check if its update on SNAT flag
boolean originalSNATEnabled = original.isEnableSnat();
boolean updatedSNATEnabled = update.isEnableSnat();
LOG.debug("update :called with originalFlag and updatedFlag for SNAT enabled " + "as {} and {} with Elected Dpn {}(isPrimaryNaptSwitchNotSelected:{})", originalSNATEnabled, updatedSNATEnabled, dpnId, isPrimaryNaptSwitchNotSelected);
// 3. First Elect dpnId and process other changes with valid dpnId
if (originalSNATEnabled != updatedSNATEnabled || isPrimaryNaptSwitchNotSelected) {
if (originalSNATEnabled && !updatedSNATEnabled) {
if (isPrimaryNaptSwitchNotSelected) {
LOG.info("No Action to be taken when SNAT is disabled " + "with no Napt Switch Election for Router {}", routerName);
return;
}
// SNAT disabled for the router
Uuid networkUuid = original.getNetworkId();
LOG.info("update : SNAT disabled for Router {}", routerName);
Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
final String vpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
handleDisableSnat(original, networkUuid, externalIps, false, vpnName, dpnId, routerId, removeFlowInvTx);
} else if (updatedSNATEnabled) {
LOG.info("update : SNAT enabled for Router {}", routerName);
addOrDelDefFibRouteToSNAT(routerName, routerId, bgpVpnId, bgpVpnUuid, true, writeFlowInvTx);
if (isPrimaryNaptSwitchNotSelected) {
dpnId = selectNewNAPTSwitch(routerName);
if (dpnId != null && !dpnId.equals(Uint64.valueOf(BigInteger.ZERO))) {
handleEnableSnat(update, routerId, dpnId, bgpVpnId, removeFlowInvTx);
} else {
LOG.error("update : Failed to elect Napt Switch During update event" + " of router {}", routerName);
}
}
}
LOG.info("update : no need to process external/subnet changes as it's will taken care" + "in handleDisableSnat/handleEnableSnat");
return;
}
if (!Objects.equals(original.getExtGwMacAddress(), update.getExtGwMacAddress())) {
NatUtil.installRouterGwFlows(txRunner, vpnManager, original, dpnId, NwConstants.DEL_FLOW);
NatUtil.installRouterGwFlows(txRunner, vpnManager, update, dpnId, NwConstants.ADD_FLOW);
}
if (updatedSNATEnabled != originalSNATEnabled) {
LOG.info("update : no need to process external/subnet changes as it's will taken care in " + "handleDisableSnat/handleEnableSnat");
return;
}
// Check if the Update is on External IPs
LOG.debug("update : Checking if this is update on External IPs for router {}", routerName);
List<String> originalExternalIps = NatUtil.getIpsListFromExternalIps(new ArrayList<ExternalIps>(original.nonnullExternalIps().values()));
List<String> updatedExternalIps = NatUtil.getIpsListFromExternalIps(new ArrayList<ExternalIps>(update.nonnullExternalIps().values()));
// Check if the External IPs are removed during the update.
Set<String> removedExternalIps = new HashSet<>(originalExternalIps);
removedExternalIps.removeAll(updatedExternalIps);
if (removedExternalIps.size() > 0) {
LOG.debug("update : Start processing of the External IPs removal for router {}", routerName);
vpnManager.removeArpResponderFlowsToExternalNetworkIps(routerName, removedExternalIps, original.getExtGwMacAddress(), dpnId, networkId);
for (String removedExternalIp : removedExternalIps) {
/*
1) Remove the mappings in the IntExt IP model which has external IP.
2) Remove the external IP in the ExternalCounter model.
3) For the corresponding subnet IDs whose external IP mapping was removed, allocate one of the
least loaded external IP.
Store the subnet IP and the reallocated external IP mapping in the IntExtIp model.
4) Increase the count of the allocated external IP by one.
5) Advertise to the BGP if external IP is allocated for the first time for the router
i.e. the route for the external IP is absent.
6) Remove the NAPT translation entries from Inbound and Outbound NAPT tables for
the removed external IPs and also from the model.
7) Advertise to the BGP for removing the route for the removed external IPs.
*/
String[] externalIpParts = NatUtil.getExternalIpAndPrefix(removedExternalIp);
String externalIp = externalIpParts[0];
String externalIpPrefix = externalIpParts[1];
String externalIpAddrStr = externalIp + "/" + externalIpPrefix;
LOG.debug("update : Clear the routes from the BGP and remove the FIB and TS " + "entries for removed external IP {}", externalIpAddrStr);
Uuid vpnUuId = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
String vpnName = "";
if (vpnUuId != null) {
vpnName = vpnUuId.getValue();
}
clrRtsFromBgpAndDelFibTs(dpnId, routerId, externalIpAddrStr, vpnName, networkId, update.getExtGwMacAddress(), removeFlowInvTx);
LOG.debug("update : Remove the mappings in the IntExtIP model which has external IP.");
// Get the internal IPs which are associated to the removed external IPs
List<IpMap> ipMaps = naptManager.getIpMapList(dataBroker, routerId);
List<String> removedInternalIps = new ArrayList<>();
for (IpMap ipMap : ipMaps) {
if (ipMap.getExternalIp().equals(externalIpAddrStr)) {
removedInternalIps.add(ipMap.getInternalIp());
}
}
LOG.debug("update : Remove the mappings of the internal IPs from the IntExtIP model.");
for (String removedInternalIp : removedInternalIps) {
LOG.debug("update : Remove the IP mapping of the internal IP {} for the " + "router ID {} from the IntExtIP model", removedInternalIp, routerId);
naptManager.removeFromIpMapDS(routerId, removedInternalIp);
}
LOG.debug("update : Remove the count mapping of the external IP {} for the " + "router ID {} from the ExternalIpsCounter model.", externalIpAddrStr, routerId);
naptManager.removeExternalIpCounter(routerId, externalIpAddrStr);
LOG.debug("update : Allocate the least loaded external IPs to the subnets " + "whose external IPs were removed.");
for (String removedInternalIp : removedInternalIps) {
allocateExternalIp(dpnId, update, routerId, routerName, networkId, removedInternalIp, writeFlowInvTx);
}
LOG.debug("update : Remove the NAPT translation entries from " + "Inbound and Outbound NAPT tables for the removed external IPs.");
// Get the internalIP and internal Port which were associated to the removed external IP.
Map<ProtocolTypes, List<String>> protoTypesIntIpPortsMap = new HashMap<>();
InstanceIdentifier<IpPortMapping> ipPortMappingId = InstanceIdentifier.builder(IntextIpPortMap.class).child(IpPortMapping.class, new IpPortMappingKey(routerId)).build();
Optional<IpPortMapping> ipPortMapping;
try {
ipPortMapping = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, ipPortMappingId);
} catch (InterruptedException | ExecutionException e) {
LOG.error("Failed to read ipPortMapping for router id {}", routerId, e);
ipPortMapping = Optional.empty();
}
if (ipPortMapping.isPresent()) {
for (IntextIpProtocolType intextIpProtocolType : ipPortMapping.get().nonnullIntextIpProtocolType().values()) {
ProtocolTypes protoType = intextIpProtocolType.getProtocol();
for (IpPortMap ipPortMap : intextIpProtocolType.nonnullIpPortMap().values()) {
IpPortExternal ipPortExternal = ipPortMap.getIpPortExternal();
if (ipPortExternal.getIpAddress().equals(externalIp)) {
List<String> removedInternalIpPorts = protoTypesIntIpPortsMap.get(protoType);
if (removedInternalIpPorts != null) {
removedInternalIpPorts.add(ipPortMap.getIpPortInternal());
protoTypesIntIpPortsMap.put(protoType, removedInternalIpPorts);
} else {
removedInternalIpPorts = new ArrayList<>();
removedInternalIpPorts.add(ipPortMap.getIpPortInternal());
protoTypesIntIpPortsMap.put(protoType, removedInternalIpPorts);
}
}
}
}
}
// Remove the IP port map from the intext-ip-port-map model, which were containing
// the removed external IP.
Set<Map.Entry<ProtocolTypes, List<String>>> protoTypesIntIpPorts = protoTypesIntIpPortsMap.entrySet();
Map<String, List<String>> internalIpPortMap = new HashMap<>();
for (Map.Entry protoTypesIntIpPort : protoTypesIntIpPorts) {
ProtocolTypes protocolType = (ProtocolTypes) protoTypesIntIpPort.getKey();
List<String> removedInternalIpPorts = (List<String>) protoTypesIntIpPort.getValue();
for (String removedInternalIpPort : removedInternalIpPorts) {
// Remove the IP port map from the intext-ip-port-map model,
// which were containing the removed external IP
naptManager.removeFromIpPortMapDS(routerId, removedInternalIpPort, protocolType);
// Remove the IP port incomint packer map.
naptPacketInHandler.removeIncomingPacketMap(routerId + NatConstants.COLON_SEPARATOR + removedInternalIpPort);
String[] removedInternalIpPortParts = removedInternalIpPort.split(NatConstants.COLON_SEPARATOR);
if (removedInternalIpPortParts.length == 2) {
String removedInternalIp = removedInternalIpPortParts[0];
String removedInternalPort = removedInternalIpPortParts[1];
List<String> removedInternalPortsList = internalIpPortMap.get(removedInternalPort);
if (removedInternalPortsList != null) {
removedInternalPortsList.add(removedInternalPort);
internalIpPortMap.put(removedInternalIp, removedInternalPortsList);
naptPacketInHandler.removeIncomingPacketMap(routerId + NatConstants.COLON_SEPARATOR + removedInternalIp + NatConstants.COLON_SEPARATOR + removedInternalPort);
// Remove the NAPT translation entries from Outbound NAPT table
naptEventHandler.removeNatFlows(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId, removedInternalIp, Integer.parseInt(removedInternalPort), protocolType.getName());
naptEventHandler.removeNatFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, routerId, removedInternalIp, Integer.parseInt(removedInternalPort), protocolType.getName());
} else {
removedInternalPortsList = new ArrayList<>();
removedInternalPortsList.add(removedInternalPort);
internalIpPortMap.put(removedInternalIp, removedInternalPortsList);
naptPacketInHandler.removeIncomingPacketMap(routerId + NatConstants.COLON_SEPARATOR + removedInternalIp + NatConstants.COLON_SEPARATOR + removedInternalPort);
// Remove the NAPT translation entries from Outbound NAPT table
naptEventHandler.removeNatFlows(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId, removedInternalIp, Integer.parseInt(removedInternalPort), protocolType.getName());
naptEventHandler.removeNatFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, routerId, removedInternalIp, Integer.parseInt(removedInternalPort), protocolType.getName());
}
}
}
}
// Delete the entry from SnatIntIpPortMap DS
Set<String> internalIps = internalIpPortMap.keySet();
for (String internalIp : internalIps) {
LOG.debug("update : Removing IpPort having the internal IP {} from the " + "model SnatIntIpPortMap", internalIp);
naptManager.removeFromSnatIpPortDS(routerId, internalIp);
}
naptManager.removeNaptPortPool(externalIp);
}
LOG.debug("update : End processing of the External IPs removal for router {}", routerName);
}
// Check if the External IPs are added during the update.
Set<String> addedExternalIps = new HashSet<>(updatedExternalIps);
addedExternalIps.removeAll(originalExternalIps);
if (addedExternalIps.size() != 0) {
LOG.debug("update : Start processing of the External IPs addition for router {}", routerName);
vpnManager.addArpResponderFlowsToExternalNetworkIps(routerName, addedExternalIps, update.getExtGwMacAddress(), dpnId, update.getNetworkId());
for (String addedExternalIp : addedExternalIps) {
/*
1) Do nothing in the IntExtIp model.
2) Initialise the count of the added external IP to 0 in the ExternalCounter model.
*/
String[] externalIpParts = NatUtil.getExternalIpAndPrefix(addedExternalIp);
String externalIp = externalIpParts[0];
String externalIpPrefix = externalIpParts[1];
String externalpStr = externalIp + "/" + externalIpPrefix;
LOG.debug("update : Initialise the count mapping of the external IP {} for the " + "router ID {} in the ExternalIpsCounter model.", externalpStr, routerId);
naptManager.initialiseNewExternalIpCounter(routerId, externalpStr);
subnetRegisterMapping(update, routerId);
LOG.info("update : Installing fib flow fo newly added Ips");
handleSnatReverseTraffic(writeFlowInvTx, dpnId, update, routerId, routerName, externalpStr);
}
LOG.debug("update : End processing of the External IPs addition during the update operation");
}
// Check if its Update on subnets
LOG.debug("update : Checking if this is update on subnets for router {}", routerName);
List<Uuid> originalSubnetIds = original.getSubnetIds();
List<Uuid> updatedSubnetIds = update.getSubnetIds();
Set<Uuid> addedSubnetIds = updatedSubnetIds != null ? new HashSet<>(updatedSubnetIds) : new HashSet<>();
if (originalSubnetIds != null) {
addedSubnetIds.removeAll(originalSubnetIds);
}
// Check if the Subnet IDs are added during the update.
if (addedSubnetIds.size() != 0) {
LOG.debug("update : Start processing of the Subnet IDs addition for router {}", routerName);
for (Uuid addedSubnetId : addedSubnetIds) {
/*
1) Select the least loaded external IP for the subnet and store the mapping of the
subnet IP and the external IP in the IntExtIp model.
2) Increase the count of the selected external IP by one.
3) Advertise to the BGP if external IP is allocated for the first time for the
router i.e. the route for the external IP is absent.
*/
String subnetIp = NatUtil.getSubnetIp(dataBroker, addedSubnetId);
if (subnetIp != null) {
allocateExternalIp(dpnId, update, routerId, routerName, networkId, subnetIp, writeFlowInvTx);
}
}
LOG.debug("update : End processing of the Subnet IDs addition for router {}", routerName);
}
// Check if the Subnet IDs are removed during the update.
Set<Uuid> removedSubnetIds = new HashSet<>(originalSubnetIds);
removedSubnetIds.removeAll(updatedSubnetIds);
if (removedSubnetIds.size() != 0) {
LOG.debug("update : Start processing of the Subnet IDs removal for router {}", routerName);
for (Uuid removedSubnetId : removedSubnetIds) {
String[] subnetAddr = NatUtil.getSubnetIpAndPrefix(dataBroker, removedSubnetId);
if (subnetAddr != null) {
/*
1) Remove the subnet IP and the external IP in the IntExtIp map
2) Decrease the count of the coresponding external IP by one.
3) Advertise to the BGP for removing the routes of the corresponding external
IP if its not allocated to any other internal IP.
*/
String externalIp = naptManager.getExternalIpAllocatedForSubnet(routerId, subnetAddr[0] + "/" + subnetAddr[1]);
if (externalIp == null) {
LOG.error("update : No mapping found for router ID {} and internal IP {}", routerId, subnetAddr[0]);
return;
}
naptManager.updateCounter(routerId, externalIp, false);
// used by any other internal ip in any router
if (!isExternalIpAllocated(externalIp)) {
LOG.debug("update : external ip is not allocated to any other " + "internal IP so proceeding to remove routes");
clrRtsFromBgpAndDelFibTs(dpnId, routerId, networkId, Collections.singleton(externalIp), null, update.getExtGwMacAddress(), removeFlowInvTx);
LOG.debug("update : Successfully removed fib entries in switch {} for " + "router {} with networkId {} and externalIp {}", dpnId, routerId, networkId, externalIp);
}
LOG.debug("update : Remove the IP mapping for the router ID {} and " + "internal IP {} external IP {}", routerId, subnetAddr[0], externalIp);
naptManager.removeIntExtIpMapDS(routerId, subnetAddr[0] + "/" + subnetAddr[1]);
}
}
LOG.debug("update : End processing of the Subnet IDs removal for router {}", routerName);
}
}));
}));
return futures;
}, NatConstants.NAT_DJC_MAX_RETRIES);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.route.monitoring.message.Update in project netvirt by opendaylight.
the class NaptManager method getExternalAddressMapping.
/**
* method to get external ip/port mapping when provided with internal ip/port pair
* If already a mapping exist for the given input, then the existing mapping is returned
* instead of overwriting with new ip/port pair.
*
* @param segmentId - Router ID
* @param sourceAddress - internal ip address/port pair
* @param protocol - TCP/UDP
* @return external ip address/port
*/
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Nullable
public SessionAddress getExternalAddressMapping(Uint32 segmentId, SessionAddress sourceAddress, NAPTEntryEvent.Protocol protocol) {
LOG.debug("getExternalAddressMapping : called with segmentId {}, internalIp {} and port {}", segmentId, sourceAddress.getIpAddress(), sourceAddress.getPortNumber());
/*
1. Get Internal IP, Port in IP:Port format
2. Inside DB with routerId get the list of entries and check if it matches with existing IP:Port
3. If True return SessionAddress of ExternalIp and Port
4. Else check ip Map and Form the ExternalIp and Port and update DB and then return ExternalIp and Port
*/
// SessionAddress externalIpPort = new SessionAddress();
String internalIpPort = sourceAddress.getIpAddress() + ":" + sourceAddress.getPortNumber();
// First check existing Port Map.
SessionAddress existingIpPort = checkIpPortMap(segmentId, internalIpPort, protocol);
if (existingIpPort != null) {
// populate externalIpPort from IpPortMap and return
LOG.debug("getExternalAddressMapping : successfully returning existingIpPort as {} and {}", existingIpPort.getIpAddress(), existingIpPort.getPortNumber());
return existingIpPort;
}
// Now check in ip-map
String externalIp = checkIpMap(segmentId, sourceAddress.getIpAddress());
if (externalIp == null) {
LOG.error("getExternalAddressMapping : Unexpected error, internal to external " + "ip map does not exist");
return null;
}
/* Logic assuming internalIp is always ip and not subnet
* case 1: externalIp is ip
* a) goto externalIp pool and getPort and return
* b) else return error
* case 2: externalIp is subnet
* a) Take first externalIp and goto that Pool and getPort
* if port -> return
* else Take second externalIp and create that Pool and getPort
* if port ->return
* else
* Continue same with third externalIp till we exhaust subnet
* b) Nothing worked return error
*/
SubnetUtils externalIpSubnet;
List<String> allIps = new ArrayList<>();
String subnetPrefix = "/" + String.valueOf(NatConstants.DEFAULT_PREFIX);
boolean extSubnetFlag = false;
if (!externalIp.contains(subnetPrefix)) {
extSubnetFlag = true;
externalIpSubnet = new SubnetUtils(externalIp);
allIps = Arrays.asList(externalIpSubnet.getInfo().getAllAddresses());
LOG.debug("getExternalAddressMapping : total count of externalIps available {}", externalIpSubnet.getInfo().getAddressCount());
} else {
LOG.debug("getExternalAddressMapping : getExternalAddress single ip case");
if (externalIp.contains(subnetPrefix)) {
// remove /32 what we got from checkIpMap
externalIp = externalIp.substring(0, externalIp.indexOf(subnetPrefix));
}
allIps.add(externalIp);
}
boolean nextExtIpFlag = false;
for (String extIp : allIps) {
LOG.info("getExternalAddressMapping : Looping externalIPs with externalIP now as {}", extIp);
if (nextExtIpFlag) {
createNaptPortPool(extIp);
LOG.debug("getExternalAddressMapping : Created Pool for next Ext IP {}", extIp);
}
Uint32 extPort = NatUtil.getUniqueId(idManager, extIp, internalIpPort);
if (extPort == NatConstants.INVALID_ID) {
LOG.error("getExternalAddressMapping : getExternalAddressMapping, idManager could not " + "allocate id retry if subnet");
if (!extSubnetFlag) {
LOG.error("getExternalAddressMapping : getExternalAddressMapping returning null " + "for single IP case, may be ports exhausted");
return null;
}
LOG.debug("getExternalAddressMapping : Could be ports exhausted case, " + "try with another externalIP if possible");
nextExtIpFlag = true;
continue;
}
// Write to ip-port-map before returning
IpPortExternalBuilder ipExt = new IpPortExternalBuilder();
IpPortExternal ipPortExt = ipExt.setIpAddress(extIp).setPortNum(extPort.intValue()).build();
IpPortMap ipm = new IpPortMapBuilder().withKey(new IpPortMapKey(internalIpPort)).setIpPortInternal(internalIpPort).setIpPortExternal(ipPortExt).build();
LOG.debug("getExternalAddressMapping : writing into ip-port-map with " + "externalIP {} and port {}", ipPortExt.getIpAddress(), ipPortExt.getPortNum());
try {
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, getIpPortMapIdentifier(segmentId, internalIpPort, protocol), ipm);
} catch (UncheckedExecutionException uee) {
LOG.error("getExternalAddressMapping : Failed to write into ip-port-map with exception", uee);
}
// Write to snat-internal-ip-port-info
String internalIpAddress = sourceAddress.getIpAddress();
int ipPort = sourceAddress.getPortNumber();
ProtocolTypes protocolType = NatUtil.getProtocolType(protocol);
final ReentrantLock lock = lockFor(segmentId, internalIpAddress, protocolType);
lock.lock();
try {
List<Uint16> portList = new ArrayList<>(NatUtil.getInternalIpPortListInfo(dataBroker, segmentId, internalIpAddress, protocolType));
portList.add(Uint16.valueOf(ipPort));
IntIpProtoTypeBuilder builder = new IntIpProtoTypeBuilder();
IntIpProtoType intIpProtocolType = builder.withKey(new IntIpProtoTypeKey(protocolType)).setPorts(portList).build();
try {
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, NatUtil.buildSnatIntIpPortIdentifier(segmentId, internalIpAddress, protocolType), intIpProtocolType);
} catch (Exception ex) {
LOG.error("getExternalAddressMapping : Failed to write into snat-internal-ip-port-info " + "with exception", ex);
}
} finally {
lock.unlock();
}
SessionAddress externalIpPort = new SessionAddress(extIp, extPort.intValue());
LOG.debug("getExternalAddressMapping : successfully returning externalIP {} " + "and port {}", externalIpPort.getIpAddress(), externalIpPort.getPortNumber());
return externalIpPort;
}
// end of for loop
LOG.error("getExternalAddressMapping : Unable to handle external IP address and port mapping with segmentId {}," + "internalIp {} and internalPort {}", segmentId, sourceAddress.getIpAddress(), sourceAddress.getPortNumber());
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.route.monitoring.message.Update in project netvirt by opendaylight.
the class NaptManager method initialiseExternalCounter.
protected void initialiseExternalCounter(Routers routers, Uint32 routerId) {
LOG.debug("initialiseExternalCounter : Initialise External IPs counter");
// update the new counter value for this externalIp
for (ExternalIps externalIp : routers.nonnullExternalIps().values()) {
String[] ipSplit = externalIp.getIpAddress().split("/");
String extIp = ipSplit[0];
String extPrefix = Short.toString(NatConstants.DEFAULT_PREFIX);
if (ipSplit.length == 2) {
extPrefix = ipSplit[1];
}
extIp = extIp + "/" + extPrefix;
initialiseNewExternalIpCounter(routerId, extIp);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.route.monitoring.message.Update in project netvirt by opendaylight.
the class ExternalNetworksChangeListener method update.
@Override
public void update(InstanceIdentifier<Networks> identifier, Networks original, Networks update) {
// Check for VPN disassociation
Uuid originalVpn = original.getVpnid();
Uuid updatedVpn = update.getVpnid();
if (originalVpn == null && updatedVpn != null) {
// external network is dis-associated from L3VPN instance
associateExternalNetworkWithVPN(update);
} else if (originalVpn != null && updatedVpn == null) {
// external network is associated with vpn
disassociateExternalNetworkFromVPN(update, originalVpn.getValue());
// Remove the SNAT entries
removeSnatEntries(original, original.getId());
}
}
Aggregations