Search in sources :

Example 1 with RouterToNaptSwitchBuilder

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);
}
Also used : RouterToNaptSwitch(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitch) RouterToNaptSwitchKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchKey) RouterToNaptSwitchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchBuilder) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with RouterToNaptSwitchBuilder

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;
    }
}
Also used : BigInteger(java.math.BigInteger) RouterToNaptSwitch(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitch) TreeSet(java.util.TreeSet) BigInteger(java.math.BigInteger) RouterToNaptSwitchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchBuilder)

Example 3 with RouterToNaptSwitchBuilder

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;
}
Also used : RouterToNaptSwitch(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitch) RouterToNaptSwitchKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchKey) RouterToNaptSwitchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchBuilder) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with RouterToNaptSwitchBuilder

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;
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) RouterToNaptSwitch(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitch) BigInteger(java.math.BigInteger) RouterToNaptSwitchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchBuilder)

Aggregations

RouterToNaptSwitch (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitch)4 RouterToNaptSwitchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchBuilder)4 BigInteger (java.math.BigInteger)2 ExecutionException (java.util.concurrent.ExecutionException)2 RouterToNaptSwitchKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchKey)2 UnknownHostException (java.net.UnknownHostException)1 TreeSet (java.util.TreeSet)1 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)1