use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.ExternalCountersKey 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.ExternalCountersKey in project netvirt by opendaylight.
the class NaptManager method removeExternalIpCounter.
protected void removeExternalIpCounter(long routerId, String externalIp) {
// Remove from external-counters model
InstanceIdentifier<ExternalIpCounter> id = InstanceIdentifier.builder(ExternalIpsCounter.class).child(ExternalCounters.class, new ExternalCountersKey(routerId)).child(ExternalIpCounter.class, new ExternalIpCounterKey(externalIp)).build();
LOG.debug("removeExternalIpCounter : Removing ExternalIpsCounter from datastore");
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.ExternalCountersKey in project netvirt by opendaylight.
the class NaptManager method updateCounter.
public void updateCounter(long 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 = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (externalIpCounter.isPresent()) {
counter = externalIpCounter.get().getCounter();
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().setKey(new ExternalIpCounterKey(externalIp)).setExternalIp(externalIp).setCounter(counter).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, getExternalIpsIdentifier(segmentId, externalIp), externalIpCounterData);
}
Aggregations