use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey in project netvirt by opendaylight.
the class NaptManager method removeIntExtIpMapDS.
protected void removeIntExtIpMapDS(long segmentId, String internalIp) {
InstanceIdentifierBuilder<IpMap> idBuilder = InstanceIdentifier.builder(IntextIpMap.class).child(IpMapping.class, new IpMappingKey(segmentId)).child(IpMap.class, new IpMapKey(internalIp));
InstanceIdentifier<IpMap> id = idBuilder.build();
LOG.debug("removeIntExtIpMapDS : Removing ipmap from datastore");
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey in project netvirt by opendaylight.
the class NaptManager method checkIpMap.
protected String checkIpMap(long 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 = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (ipMapping.isPresent()) {
List<IpMap> ipMaps = ipMapping.get().getIpMap();
for (IpMap ipMap : ipMaps) {
if (ipMap.getInternalIp().equals(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.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey in project netvirt by opendaylight.
the class NaptManagerTest method testRegisterMappingSubnetSubnet.
@Ignore
@Test
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void testRegisterMappingSubnetSubnet() {
// TODO : This needs to be modified to make it work
ipmapId = InstanceIdentifier.builder(IntextIpMap.class).child(IpMapping.class, new IpMappingKey(6L)).child(IpMap.class, new IpMapKey("10.2.0.2/24")).build();
ipmap = new IpMapBuilder().setKey(new IpMapKey("10.2.0.2/24")).setInternalIp("10.2.0.2/24").setExternalIp("192.21.16.1/16").build();
try {
PowerMockito.doNothing().when(MDSALUtil.class, "syncWrite", dataBroker, LogicalDatastoreType.OPERATIONAL, ipmapId, ipmap);
} catch (Exception e) {
// Test failed anyways
assertEquals("true", "false");
}
IPAddress internal = new IPAddress("10.2.0.2", 24);
IPAddress external = new IPAddress("192.21.16.1", 16);
naptManager.registerMapping(6, internal, external);
PowerMockito.verifyStatic();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey in project netvirt by opendaylight.
the class NaptManager method removeFromIpMapDS.
protected void removeFromIpMapDS(long segmentId, String internalIp) {
InstanceIdentifierBuilder<IpMap> idBuilder = InstanceIdentifier.builder(IntextIpMap.class).child(IpMapping.class, new IpMappingKey(segmentId)).child(IpMap.class, new IpMapKey(internalIp));
InstanceIdentifier<IpMap> id = idBuilder.build();
// Get externalIp and decrement the counter
String externalIp = null;
Optional<IpMap> ipMap = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (ipMap.isPresent()) {
externalIp = ipMap.get().getExternalIp();
LOG.debug("removeFromIpMapDS : externalIP is {}", externalIp);
} else {
LOG.warn("removeFromIpMapDS : ipMap not present for the internal IP {}", internalIp);
}
if (externalIp != null) {
updateCounter(segmentId, externalIp, false);
// remove from ipmap DS
LOG.debug("removeFromIpMapDS : Removing ipmap from datastore");
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
} else {
LOG.warn("removeFromIpMapDS : externalIp not present for the internal IP {}", internalIp);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey in project netvirt by opendaylight.
the class NaptManager method getExternalIpAllocatedForSubnet.
protected String getExternalIpAllocatedForSubnet(long segmentId, String internalIp) {
InstanceIdentifierBuilder<IpMap> idBuilder = InstanceIdentifier.builder(IntextIpMap.class).child(IpMapping.class, new IpMappingKey(segmentId)).child(IpMap.class, new IpMapKey(internalIp));
InstanceIdentifier<IpMap> id = idBuilder.build();
Optional<IpMap> ipMap = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (ipMap.isPresent()) {
return ipMap.get().getExternalIp();
}
return null;
}
Aggregations