use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.
the class NaptSwitchHA method isNaptSwitchDown.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public boolean isNaptSwitchDown(String routerName, Long routerId, BigInteger dpnId, BigInteger naptSwitch, Long routerVpnId, Collection<String> externalIpCache, boolean isClearBgpRts, WriteTransaction writeFlowInvTx) {
externalIpsCache = externalIpCache;
if (!naptSwitch.equals(dpnId)) {
LOG.debug("isNaptSwitchDown : DpnId {} is not a naptSwitch {} for Router {}", dpnId, naptSwitch, routerName);
return false;
}
LOG.debug("NaptSwitch {} is down for Router {}", naptSwitch, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("isNaptSwitchDown : Invalid routerId returned for routerName {}", routerName);
return true;
}
Uuid networkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
String vpnName = getExtNetworkVpnName(routerName, networkId);
// elect a new NaptSwitch
naptSwitch = naptSwitchSelector.selectNewNAPTSwitch(routerName);
if (natMode == NatMode.Conntrack) {
Routers extRouters = NatUtil.getRoutersFromConfigDS(dataBroker, routerName);
natServiceManager.notify(extRouters, dpnId, dpnId, SnatServiceManager.Action.SNAT_ALL_SWITCH_DISBL);
natServiceManager.notify(extRouters, naptSwitch, naptSwitch, SnatServiceManager.Action.SNAT_ALL_SWITCH_ENBL);
} else {
if (naptSwitch.equals(BigInteger.ZERO)) {
LOG.warn("isNaptSwitchDown : No napt switch is elected since all the switches for router {}" + " are down. SNAT IS NOT SUPPORTED FOR ROUTER {}", routerName, routerName);
boolean naptUpdatedStatus = updateNaptSwitch(routerName, naptSwitch);
if (!naptUpdatedStatus) {
LOG.debug("isNaptSwitchDown : Failed to update naptSwitch {} for router {} in ds", naptSwitch, routerName);
}
// clearBgpRoutes
if (externalIpsCache != null) {
if (vpnName != null) {
// if (externalIps != null) {
if (isClearBgpRts) {
LOG.debug("isNaptSwitchDown : Clearing both FIB entries and the BGP routes");
for (String externalIp : externalIpsCache) {
externalRouterListener.clearBgpRoutes(externalIp, vpnName);
}
} else {
LOG.debug("isNaptSwitchDown : Clearing the FIB entries but not the BGP routes");
String rd = NatUtil.getVpnRd(dataBroker, vpnName);
for (String externalIp : externalIpsCache) {
LOG.debug("isNaptSwitchDown : Removing Fib entry rd {} prefix {}", rd, externalIp);
fibManager.removeFibEntry(rd, externalIp, null);
}
}
} else {
LOG.debug("isNaptSwitchDown : vpn is not associated to extn/w for router {}", routerName);
}
} else {
LOG.debug("isNaptSwitchDown : No ExternalIps found for subnets under router {}, " + "no bgp routes need to be cleared", routerName);
}
return true;
}
// checking elected switch health status
if (!getSwitchStatus(naptSwitch)) {
LOG.error("isNaptSwitchDown : Newly elected Napt switch {} for router {} is down", naptSwitch, routerName);
return true;
}
LOG.debug("isNaptSwitchDown : New NaptSwitch {} is up for Router {} and can proceed for flow installation", naptSwitch, routerName);
// update napt model for new napt switch
boolean naptUpdated = updateNaptSwitch(routerName, naptSwitch);
if (naptUpdated) {
// update group of ordinary switch point to naptSwitch tunnel port
updateNaptSwitchBucketStatus(routerName, routerId, naptSwitch);
} else {
LOG.error("isNaptSwitchDown : Failed to update naptSwitch model for newNaptSwitch {} for router {}", naptSwitch, routerName);
}
// update table26 forward packets to table46(outbound napt table)
FlowEntity flowEntity = buildSnatFlowEntityForNaptSwitch(naptSwitch, routerName, routerVpnId, NatConstants.ADD_FLOW);
if (flowEntity == null) {
LOG.error("isNaptSwitchDown : Failed to populate flowentity for router {} in naptSwitch {}", routerName, naptSwitch);
} else {
LOG.debug("isNaptSwitchDown : Successfully installed flow in naptSwitch {} for router {}", naptSwitch, routerName);
mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
}
installSnatFlows(routerName, routerId, naptSwitch, routerVpnId, writeFlowInvTx);
boolean flowInstalledStatus = handleNatFlowsInNewNaptSwitch(routerName, routerId, dpnId, naptSwitch, routerVpnId, networkId);
if (flowInstalledStatus) {
LOG.debug("isNaptSwitchDown :Installed all active session flows in newNaptSwitch {} for routerName {}", naptSwitch, routerName);
} else {
LOG.error("isNaptSwitchDown : Failed to install flows in newNaptSwitch {} for routerId {}", naptSwitch, routerId);
}
// remove group in new naptswitch, coz this switch acted previously as ordinary switch
long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
GroupEntity groupEntity = null;
try {
groupEntity = MDSALUtil.buildGroupEntity(naptSwitch, groupId, routerName, GroupTypes.GroupAll, Collections.emptyList());
LOG.info("isNaptSwitchDown : Removing NAPT Group in new naptSwitch {}", naptSwitch);
mdsalManager.removeGroup(groupEntity);
} catch (Exception ex) {
LOG.error("isNaptSwitchDown : Failed to remove group in new naptSwitch {}", groupEntity, ex);
}
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.
the class AbstractSnatService method installSnatCommonEntriesForNonNaptSwitch.
protected void installSnatCommonEntriesForNonNaptSwitch(Routers routers, BigInteger primarySwitchId, BigInteger dpnId, int addOrRemove) {
String routerName = routers.getRouterName();
Long routerId = NatUtil.getVpnId(dataBroker, routerName);
List<ExternalIps> externalIps = routers.getExternalIps();
if (externalIps.isEmpty()) {
LOG.error("AbstractSnatService: installSnatCommonEntriesForNaptSwitch no externalIP present" + " for routerId {}", routerId);
return;
}
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);
}
installDefaultFibRouteForSNAT(dpnId, routerId, addOrRemove);
installSnatMissEntry(dpnId, routerId, routerName, primarySwitchId, externalIp, extSubnetId, addOrRemove);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.
the class NeutronvpnNatManager method handleExternalFixedIpsForRouter.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleExternalFixedIpsForRouter(Router update) {
Uuid routerId = update.getUuid();
InstanceIdentifier<Routers> routersIdentifier = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
try {
Optional<Routers> optionalRouters = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier);
LOG.trace("Updating External Fixed IPs Routers node {}", routerId.getValue());
if (optionalRouters.isPresent()) {
RoutersBuilder builder = new RoutersBuilder(optionalRouters.get());
List<ExternalIps> externalIps = new ArrayList<>();
for (ExternalFixedIps fixedIps : update.getExternalGatewayInfo().getExternalFixedIps()) {
addExternalFixedIpToExternalIpsList(externalIps, fixedIps);
}
builder.setExternalIps(externalIps);
updateExternalSubnetsForRouter(routerId, update.getExternalGatewayInfo().getExternalNetworkId(), update.getExternalGatewayInfo().getExternalFixedIps());
Routers routerss = builder.build();
LOG.trace("Updating external fixed ips for router {} with value {}", routerId.getValue(), routerss);
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier, routerss);
LOG.trace("Added External Fixed IPs successfully for Routers to CONFIG Datastore");
}
} catch (TransactionCommitFailedException | ReadFailedException ex) {
LOG.error("Updating extfixedips for {} in extrouters failed", routerId.getValue(), ex);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.
the class VpnUtil method getAssociatedExternalRouter.
public static String getAssociatedExternalRouter(DataBroker dataBroker, String extIp) {
InstanceIdentifier<ExtRouters> extRouterInstanceIndentifier = InstanceIdentifier.builder(ExtRouters.class).build();
Optional<ExtRouters> extRouterData = read(dataBroker, LogicalDatastoreType.CONFIGURATION, extRouterInstanceIndentifier);
if (extRouterData.isPresent()) {
for (Routers routerData : extRouterData.get().getRouters()) {
List<ExternalIps> externalIps = routerData.getExternalIps();
for (ExternalIps externalIp : externalIps) {
if (externalIp.getIpAddress().equals(extIp)) {
return routerData.getRouterName();
}
}
}
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps in project netvirt by opendaylight.
the class NatUtil method getExternalIpsForRouter.
@Nonnull
public static Collection<String> getExternalIpsForRouter(DataBroker dataBroker, Long routerId) {
Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping> ipMappingOptional = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, getIpMappingBuilder(routerId));
// Ensure there are no duplicates
Collection<String> externalIps = new HashSet<>();
if (ipMappingOptional.isPresent()) {
List<IpMap> ipMaps = ipMappingOptional.get().getIpMap();
for (IpMap ipMap : ipMaps) {
externalIps.add(ipMap.getExternalIp());
}
}
return externalIps;
}
Aggregations