use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.ExternalCounters in project netvirt by opendaylight.
the class NatUtil method getLeastLoadedExternalIp.
public static String getLeastLoadedExternalIp(DataBroker dataBroker, long segmentId) {
String leastLoadedExternalIp = null;
InstanceIdentifier<ExternalCounters> id = InstanceIdentifier.builder(ExternalIpsCounter.class).child(ExternalCounters.class, new ExternalCountersKey(segmentId)).build();
Optional<ExternalCounters> externalCountersData = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (externalCountersData.isPresent()) {
ExternalCounters externalCounter = externalCountersData.get();
List<ExternalIpCounter> externalIpCounterList = externalCounter.getExternalIpCounter();
short countOfLstLoadExtIp = 32767;
for (ExternalIpCounter externalIpCounter : externalIpCounterList) {
String curExternalIp = externalIpCounter.getExternalIp();
short countOfCurExtIp = externalIpCounter.getCounter();
if (countOfCurExtIp < countOfLstLoadExtIp) {
countOfLstLoadExtIp = countOfCurExtIp;
leastLoadedExternalIp = curExternalIp;
}
}
}
return leastLoadedExternalIp;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.ExternalCounters in project netvirt by opendaylight.
the class ExternalRoutersListener method isExternalIpAllocated.
private boolean isExternalIpAllocated(String externalIp) {
InstanceIdentifier<ExternalIpsCounter> id = InstanceIdentifier.builder(ExternalIpsCounter.class).build();
Optional<ExternalIpsCounter> externalCountersData = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (externalCountersData.isPresent()) {
ExternalIpsCounter externalIpsCounters = externalCountersData.get();
List<ExternalCounters> externalCounters = externalIpsCounters.getExternalCounters();
for (ExternalCounters ext : externalCounters) {
for (ExternalIpCounter externalIpCount : ext.getExternalIpCounter()) {
if (externalIpCount.getExternalIp().equals(externalIp)) {
if (externalIpCount.getCounter() != 0) {
return true;
}
break;
}
}
}
}
return false;
}
Aggregations