Search in sources :

Example 1 with ExternalIpCounter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounter 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 ExternalIpCounter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounter 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 ExternalIpCounter

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

Example 4 with ExternalIpCounter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounter 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)

Example 5 with ExternalIpCounter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounter 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

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