Search in sources :

Example 1 with ExternalCountersKey

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;
}
Also used : ExternalCountersKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.ExternalCountersKey) ExternalIpCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounter) ExternalCounters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.ExternalCounters)

Example 2 with ExternalCountersKey

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);
}
Also used : ExternalCountersKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.ExternalCountersKey) ExternalIpCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounter) ExternalIpCounterKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounterKey) ExternalIpsCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalIpsCounter)

Example 3 with ExternalCountersKey

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);
}
Also used : ExternalCountersKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.ExternalCountersKey) ExternalIpCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounter) ExternalIpCounterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounterBuilder) ExternalIpCounterKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounterKey) ExternalIpsCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalIpsCounter)

Aggregations

ExternalCountersKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.ExternalCountersKey)3 ExternalIpCounter (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounter)3 ExternalIpsCounter (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalIpsCounter)2 ExternalIpCounterKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounterKey)2 ExternalCounters (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.ExternalCounters)1 ExternalIpCounterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounterBuilder)1