use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers in project netvirt by opendaylight.
the class SnatCentralizedSwitchChangeListener method add.
@Override
protected void add(InstanceIdentifier<RouterToNaptSwitch> key, RouterToNaptSwitch routerToNaptSwitch) {
LOG.debug("Adding {}", routerToNaptSwitch);
BigInteger primarySwitchId = routerToNaptSwitch.getPrimarySwitchId();
Routers router = NatUtil.getRoutersFromConfigDS(dataBroker, routerToNaptSwitch.getRouterName());
natDataUtil.addtoRouterMap(router);
snatServiceManger.notify(router, primarySwitchId, null, SnatServiceManager.Action.SNAT_ALL_SWITCH_ENBL);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers 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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers in project netvirt by opendaylight.
the class WeightedCentralizedSwitchScheduler method removeSwitch.
@Override
public boolean removeSwitch(BigInteger dpnId) {
LOG.info("removeSwitch: Removing {} dpnId to switchWeightsMap", dpnId);
if (!INITIAL_SWITCH_WEIGHT.equals(switchWeightsMap.get(dpnId))) {
NaptSwitches naptSwitches = getNaptSwitches(dataBroker);
for (RouterToNaptSwitch routerToNaptSwitch : naptSwitches.getRouterToNaptSwitch()) {
if (dpnId.equals(routerToNaptSwitch.getPrimarySwitchId())) {
Routers router = NatUtil.getRoutersFromConfigDS(dataBroker, routerToNaptSwitch.getRouterName());
releaseCentralizedSwitch(router);
switchWeightsMap.remove(dpnId);
scheduleCentralizedSwitch(router);
break;
}
}
} else {
switchWeightsMap.remove(dpnId);
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers in project netvirt by opendaylight.
the class AbstractSnatService method installSnatCommonEntriesForNaptSwitch.
protected void installSnatCommonEntriesForNaptSwitch(Routers routers, BigInteger dpnId, int addOrRemove) {
String routerName = routers.getRouterName();
Long routerId = NatUtil.getVpnId(dataBroker, routerName);
installDefaultFibRouteForSNAT(dpnId, routerId, addOrRemove);
List<ExternalIps> externalIps = routers.getExternalIps();
if (externalIps.isEmpty()) {
LOG.error("AbstractSnatService: installSnatCommonEntriesForNaptSwitch no externalIP present" + " for routerId {}", routerId);
return;
}
// The logic now handle only one external IP per router, others if present will be ignored.
String externalIp = externalIps.get(0).getIpAddress();
Uuid externalSubnetId = externalIps.get(0).getSubnetId();
long extSubnetId = NatConstants.INVALID_ID;
if (addOrRemove == NwConstants.ADD_FLOW) {
extSubnetId = NatUtil.getExternalSubnetVpnId(dataBroker, externalSubnetId);
}
installInboundFibEntry(dpnId, externalIp, routerId, extSubnetId, addOrRemove);
installInboundTerminatingServiceTblEntry(dpnId, routerId, extSubnetId, addOrRemove);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers in project netvirt by opendaylight.
the class ConntrackBasedSnatService method installSnatSpecificEntriesForNaptSwitch.
@Override
protected void installSnatSpecificEntriesForNaptSwitch(Routers routers, BigInteger dpnId, int addOrRemove) {
LOG.info("installSnatSpecificEntriesForNaptSwitch: called for router {}", routers.getRouterName());
String routerName = routers.getRouterName();
Long routerId = NatUtil.getVpnId(getDataBroker(), routerName);
int elanId = NatUtil.getElanInstanceByName(routers.getNetworkId().getValue(), getDataBroker()).getElanTag().intValue();
/* Install Outbound NAT entries */
installSnatMissEntryForPrimrySwch(dpnId, routerId, elanId, addOrRemove);
installTerminatingServiceTblEntry(dpnId, routerId, elanId, addOrRemove);
String extGwMacAddress = NatUtil.getExtGwMacAddFromRouterName(getDataBroker(), routerName);
createOutboundTblTrackEntry(dpnId, routerId, extGwMacAddress, addOrRemove);
List<ExternalIps> externalIps = routers.getExternalIps();
if (externalIps.isEmpty()) {
LOG.error("AbstractSnatService: installSnatCommonEntriesForNaptSwitch no externalIP present" + " for routerId {}", routerId);
return;
}
// The logic now handle only one external IP per router, others if present will be ignored.
String externalIp = externalIps.get(0).getIpAddress();
Uuid externalSubnetId = externalIps.get(0).getSubnetId();
long extSubnetId = NatConstants.INVALID_ID;
if (addOrRemove == NwConstants.ADD_FLOW) {
extSubnetId = NatUtil.getExternalSubnetVpnId(getDataBroker(), externalSubnetId);
}
createOutboundTblEntry(dpnId, routerId, externalIp, elanId, extGwMacAddress, addOrRemove);
installNaptPfibFlow(routers, dpnId, routerId, extSubnetId, addOrRemove);
// Install Inbound NAT entries
installInboundEntry(dpnId, routerId, externalIp, elanId, extSubnetId, addOrRemove);
installNaptPfibEntry(dpnId, routerId, addOrRemove);
}
Aggregations