use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.SegmentId in project netvirt by opendaylight.
the class NaptManager method removeFromIpPortMapDS.
protected void removeFromIpPortMapDS(Uint32 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.params.xml.ns.yang.topology.sr.rev130819.SegmentId in project netvirt by opendaylight.
the class NaptManager method updateCounter.
public void updateCounter(Uint32 segmentId, String externalIp, boolean isAdd) {
short counter = 0;
InstanceIdentifier<ExternalIpCounter> id = InstanceIdentifier.builder(ExternalIpsCounter.class).child(ExternalCounters.class, new ExternalCountersKey(segmentId)).child(ExternalIpCounter.class, new ExternalIpCounterKey(externalIp)).build();
Optional<ExternalIpCounter> externalIpCounter = Optional.empty();
try {
externalIpCounter = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
} catch (ExecutionException | InterruptedException e) {
LOG.error("updateCounter: Exception while reading ExternalIpCounter DS for the segmentId {} externalIp {} ", segmentId, externalIp, e);
}
if (externalIpCounter.isPresent()) {
counter = externalIpCounter.get().getCounter().toJava();
if (isAdd) {
counter++;
LOG.debug("updateCounter : externalIp and counter after increment are {} and {}", externalIp, counter);
} else {
if (counter > 0) {
counter--;
}
LOG.debug("updateCounter : externalIp and counter after decrement are {} and {}", externalIp, counter);
}
} else if (isAdd) {
counter = 1;
}
// update the new counter value for this externalIp
ExternalIpCounter externalIpCounterData = new ExternalIpCounterBuilder().withKey(new ExternalIpCounterKey(externalIp)).setExternalIp(externalIp).setCounter(counter).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, getExternalIpsIdentifier(segmentId, externalIp), externalIpCounterData);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.SegmentId in project netvirt by opendaylight.
the class NaptManager method checkIpMap.
@Nullable
protected String checkIpMap(Uint32 segmentId, String internalIp) {
LOG.debug("checkIpMap : called with segmentId {} and internalIp {}", segmentId, internalIp);
String externalIp;
// check if ip-map node is there
InstanceIdentifierBuilder<IpMapping> idBuilder = InstanceIdentifier.builder(IntextIpMap.class).child(IpMapping.class, new IpMappingKey(segmentId));
InstanceIdentifier<IpMapping> id = idBuilder.build();
Optional<IpMapping> ipMapping = Optional.empty();
try {
ipMapping = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
} catch (ExecutionException | InterruptedException e) {
LOG.error("checkIpMap: Exception while reading IpMapping DS for the segmentId {} internalIp {}", segmentId, internalIp, e);
}
if (ipMapping.isPresent()) {
for (IpMap ipMap : ipMapping.get().nonnullIpMap().values()) {
if (Objects.equals(ipMap.getInternalIp(), internalIp)) {
LOG.debug("checkIpMap : IpMap : {}", ipMap);
externalIp = ipMap.getExternalIp();
LOG.debug("checkIpMap : successfully returning externalIp {}", externalIp);
return externalIp;
} else if (ipMap.getInternalIp().contains("/")) {
// subnet case
SubnetUtils subnetUtils = new SubnetUtils(ipMap.getInternalIp());
SubnetInfo subnetInfo = subnetUtils.getInfo();
if (subnetInfo.isInRange(internalIp)) {
LOG.debug("checkIpMap : internalIp {} found to be IpMap of internalIpSubnet {}", internalIp, ipMap.getInternalIp());
externalIp = ipMap.getExternalIp();
LOG.debug("checkIpMap : checkIpMap successfully returning externalIp {}", externalIp);
return externalIp;
}
}
}
}
// return null if not found
LOG.error("checkIpMap : failed, returning NULL for segmentId {} and internalIp {}", segmentId, internalIp);
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.SegmentId in project netvirt by opendaylight.
the class NaptManager method removeFromSnatIpPortDS.
protected void removeFromSnatIpPortDS(Uint32 segmentId, String internalIp) {
InstanceIdentifier<IpPort> intIp = InstanceIdentifier.builder(SnatintIpPortMap.class).child(IntipPortMap.class, new IntipPortMapKey(segmentId)).child(IpPort.class, new IpPortKey(internalIp)).build();
// remove from SnatIpPortDS
LOG.debug("removeFromSnatIpPortDS : Removing SnatIpPort from datastore : {}", intIp);
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, intIp);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.SegmentId in project netvirt by opendaylight.
the class NaptManager method releaseIpExtPortMapping.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void releaseIpExtPortMapping(Uint32 segmentId, SessionAddress address, NAPTEntryEvent.Protocol protocol) {
String internalIpPort = address.getIpAddress() + ":" + address.getPortNumber();
SessionAddress existingIpPort = checkIpPortMap(segmentId, internalIpPort, protocol);
if (existingIpPort != null) {
// delete the entry from IpPortMap DS
try {
removeFromIpPortMapDS(segmentId, internalIpPort, protocol);
// Finally release port from idmanager
Uint32 releasedId = NatUtil.releaseId(idManager, existingIpPort.getIpAddress(), internalIpPort);
if (releasedId == NatConstants.INVALID_ID) {
LOG.error("releaseIpExtPortMapping : Unable to release ID for key {}", existingIpPort.getIpAddress());
}
} catch (Exception e) {
LOG.error("releaseIpExtPortMapping : failed, Removal of ipportmap {} for " + "router {} failed", internalIpPort, segmentId, e);
}
} else {
LOG.error("releaseIpExtPortMapping : failed, segmentId {} and " + "internalIpPort {} not found in IpPortMap DS", segmentId, internalIpPort);
}
// delete the entry of port for InternalIp from snatIntIpportMappingDS
ProtocolTypes protocolType = NatUtil.getProtocolType(protocol);
final ReentrantLock lock = lockFor(segmentId, address.getIpAddress(), protocolType);
lock.lock();
try {
removeSnatIntIpPortDS(segmentId, address, protocolType);
} catch (Exception e) {
LOG.error("releaseSnatIpPortMapping : failed, Removal of snatipportmap {} for router {} failed", address.getIpAddress(), segmentId, e);
} finally {
lock.unlock();
}
}
Aggregations