use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounterBuilder in project netvirt by opendaylight.
the class NaptManager method initialiseNewExternalIpCounter.
protected void initialiseNewExternalIpCounter(long routerId, String externalIp) {
ExternalIpCounter externalIpCounterData = new ExternalIpCounterBuilder().setKey(new ExternalIpCounterKey(externalIp)).setExternalIp(externalIp).setCounter((short) 0).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, getExternalIpsIdentifier(routerId, externalIp), externalIpCounterData);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounterBuilder 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