use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchBuilder in project netvirt by opendaylight.
the class ExternalRoutersListener method updateNaptSwitch.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void updateNaptSwitch(String routerName, BigInteger naptSwitchId) {
RouterToNaptSwitch naptSwitch = new RouterToNaptSwitchBuilder().setKey(new RouterToNaptSwitchKey(routerName)).setPrimarySwitchId(naptSwitchId).build();
try {
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, NatUtil.buildNaptSwitchRouterIdentifier(routerName), naptSwitch);
} catch (Exception ex) {
LOG.error("updateNaptSwitch : Failed to write naptSwitch {} for router {} in ds", naptSwitchId, routerName);
}
LOG.debug("updateNaptSwitch : Successfully updated naptSwitch {} for router {} in ds", naptSwitchId, routerName);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchBuilder in project netvirt by opendaylight.
the class NAPTSwitchSelector method selectNewNAPTSwitch.
BigInteger selectNewNAPTSwitch(String routerName) {
LOG.info("selectNewNAPTSwitch : Select a new NAPT switch for router {}", routerName);
Map<BigInteger, Integer> naptSwitchWeights = constructNAPTSwitches();
List<BigInteger> routerSwitches = getDpnsForVpn(routerName);
if (routerSwitches.isEmpty()) {
LOG.warn("selectNewNAPTSwitch : Delaying NAPT switch selection due to no dpns scenario for router {}", routerName);
return BigInteger.ZERO;
}
Set<SwitchWeight> switchWeights = new TreeSet<>();
for (BigInteger dpn : routerSwitches) {
if (naptSwitchWeights.get(dpn) != null) {
switchWeights.add(new SwitchWeight(dpn, naptSwitchWeights.get(dpn)));
} else {
switchWeights.add(new SwitchWeight(dpn, 0));
}
}
BigInteger primarySwitch;
if (!switchWeights.isEmpty()) {
LOG.debug("selectNewNAPTSwitch : Current switch weights for router {} - {}", routerName, switchWeights);
RouterToNaptSwitchBuilder routerToNaptSwitchBuilder = new RouterToNaptSwitchBuilder().setRouterName(routerName);
SwitchWeight firstSwitchWeight = switchWeights.iterator().next();
primarySwitch = firstSwitchWeight.getSwitch();
RouterToNaptSwitch id = routerToNaptSwitchBuilder.setPrimarySwitchId(primarySwitch).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, getNaptSwitchesIdentifier(routerName), id);
LOG.debug("selectNewNAPTSwitch : successful addition of RouterToNaptSwitch to napt-switches container");
return primarySwitch;
} else {
primarySwitch = BigInteger.ZERO;
LOG.debug("selectNewNAPTSwitch : switchWeights empty, primarySwitch: {} ", primarySwitch);
return primarySwitch;
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchBuilder in project netvirt by opendaylight.
the class NaptSwitchHA method updateNaptSwitch.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public boolean updateNaptSwitch(String routerName, BigInteger naptSwitchId) {
RouterToNaptSwitch naptSwitch = new RouterToNaptSwitchBuilder().setKey(new RouterToNaptSwitchKey(routerName)).setPrimarySwitchId(naptSwitchId).build();
try {
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, NatUtil.buildNaptSwitchRouterIdentifier(routerName), naptSwitch);
} catch (Exception ex) {
LOG.error("updateNaptSwitch : Failed to write naptSwitch {} for router {} in ds", naptSwitchId, routerName);
return false;
}
LOG.debug("updateNaptSwitch : Successfully updated naptSwitch {} for router {} in ds", naptSwitchId, routerName);
return true;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchBuilder in project netvirt by opendaylight.
the class WeightedCentralizedSwitchScheduler method scheduleCentralizedSwitch.
@Override
public boolean scheduleCentralizedSwitch(Routers router) {
BigInteger nextSwitchId = getSwitchWithLowestWeight();
String routerName = router.getRouterName();
RouterToNaptSwitchBuilder routerToNaptSwitchBuilder = new RouterToNaptSwitchBuilder().setRouterName(routerName);
RouterToNaptSwitch id = routerToNaptSwitchBuilder.setPrimarySwitchId(nextSwitchId).build();
addToDpnMaps(routerName, router.getSubnetIds(), nextSwitchId);
try {
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, getNaptSwitchesIdentifier(routerName), id);
switchWeightsMap.put(nextSwitchId, switchWeightsMap.get(nextSwitchId) + 1);
} catch (TransactionCommitFailedException e) {
LOG.error("ScheduleCentralizedSwitch failed for {}", routerName);
}
return true;
}
Aggregations