*/
package org.opendaylight.netvirt.natservice.internal;
-import com.google.common.base.Optional;
-import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
+import java.util.concurrent.ExecutionException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.genius.cloudscaler.api.TombstonedNodeManager;
+import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.common.api.ReadFailedException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.NaptSwitches;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitch;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
this.tombstonedNodeManager = tombstonedNodeManager;
}
- BigInteger selectNewNAPTSwitch(String routerName, List<BigInteger> excludeDpns) {
+ Uint64 selectNewNAPTSwitch(String routerName, List<Uint64> excludeDpns) {
LOG.info("selectNewNAPTSwitch : Select a new NAPT switch for router {}", routerName);
- Map<BigInteger, Integer> naptSwitchWeights = constructNAPTSwitches();
- List<BigInteger> routerSwitches = getDpnsForVpn(routerName);
+ Map<Uint64, Integer> naptSwitchWeights = constructNAPTSwitches();
+ List<Uint64> routerSwitches = getDpnsForVpn(routerName);
if (routerSwitches.isEmpty()) {
LOG.warn("selectNewNAPTSwitch : Delaying NAPT switch selection due to no dpns scenario for router {}",
routerName);
- return BigInteger.ZERO;
+ return Uint64.ZERO;
}
try {
if (excludeDpns != null) {
LOG.error("selectNewNAPTSwitch : filterTombStoned Exception thrown", ex);
}
Set<SwitchWeight> switchWeights = new TreeSet<>();
- for (BigInteger dpn : routerSwitches) {
+ for (Uint64 dpn : routerSwitches) {
if (naptSwitchWeights.get(dpn) != null) {
switchWeights.add(new SwitchWeight(dpn, naptSwitchWeights.get(dpn)));
} else {
}
}
- BigInteger primarySwitch;
+ Uint64 primarySwitch;
if (!switchWeights.isEmpty()) {
LOG.debug("selectNewNAPTSwitch : successful addition of RouterToNaptSwitch to napt-switches container");
return primarySwitch;
} else {
- primarySwitch = BigInteger.ZERO;
+ primarySwitch = Uint64.ZERO;
LOG.debug("selectNewNAPTSwitch : switchWeights empty, primarySwitch: {} ", primarySwitch);
return primarySwitch;
}
}
- private Map<BigInteger, Integer> constructNAPTSwitches() {
- Optional<NaptSwitches> optNaptSwitches =
- MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, getNaptSwitchesIdentifier());
- Map<BigInteger, Integer> switchWeights = new HashMap<>();
+ private Map<Uint64, Integer> constructNAPTSwitches() {
+ Optional<NaptSwitches> optNaptSwitches = Optional.empty();
+ try {
+ optNaptSwitches = SingleTransactionDataBroker.syncReadOptional(dataBroker,
+ LogicalDatastoreType.CONFIGURATION, getNaptSwitchesIdentifier());
+ } catch (ExecutionException | InterruptedException e) {
+ LOG.error("constructNAPTSwitches: Exception while reading the NaptSwitches DS", e);
+ }
+ Map<Uint64, Integer> switchWeights = new HashMap<>();
if (optNaptSwitches.isPresent()) {
NaptSwitches naptSwitches = optNaptSwitches.get();
for (RouterToNaptSwitch naptSwitch : naptSwitches.nonnullRouterToNaptSwitch()) {
- BigInteger primarySwitch = naptSwitch.getPrimarySwitchId();
+ Uint64 primarySwitch = naptSwitch.getPrimarySwitchId();
//update weight
Integer weight = switchWeights.get(primarySwitch);
if (weight == null) {
}
@NonNull
- public List<BigInteger> getDpnsForVpn(String routerName) {
+ public List<Uint64> getDpnsForVpn(String routerName) {
LOG.debug("getDpnsForVpn: called for RouterName {}", routerName);
- long bgpVpnId = NatUtil.getBgpVpnId(dataBroker, routerName);
+ Uint32 bgpVpnId = NatUtil.getBgpVpnId(dataBroker, routerName);
// TODO Why?
if (bgpVpnId != NatConstants.INVALID_ID) {
return NatUtil.getDpnsForRouter(dataBroker, routerName);
}
private static class SwitchWeight implements Comparable<SwitchWeight> {
- private final BigInteger swich;
+ private final Uint64 swich;
private int weight;
- SwitchWeight(BigInteger swich, int weight) {
+ SwitchWeight(Uint64 swich, int weight) {
this.swich = swich;
this.weight = weight;
}
return true;
}
- public BigInteger getSwitch() {
+ public Uint64 getSwitch() {
return swich;
}