Search in sources :

Example 1 with ExternalCounters

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;
}
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 ExternalCounters

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

Aggregations

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