use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.Prefix in project netvirt by opendaylight.
the class SubnetGwMacChangeListener method handleSubnetGwIpChange.
private void handleSubnetGwIpChange(LearntVpnVipToPort learntVpnVipToPort) {
String macAddress = learntVpnVipToPort.getMacAddress();
if (macAddress == null) {
LOG.error("handleSubnetGwIpChange : Mac address is null for LearntVpnVipToPort for vpn {} prefix {}", learntVpnVipToPort.getVpnName(), learntVpnVipToPort.getPortFixedip());
return;
}
String fixedIp = learntVpnVipToPort.getPortFixedip();
if (fixedIp == null) {
LOG.error("handleSubnetGwIpChange : Fixed ip is null for LearntVpnVipToPort for vpn {}", learntVpnVipToPort.getVpnName());
return;
}
try {
InetAddress address = InetAddress.getByName(fixedIp);
if (address instanceof Inet6Address) {
// TODO: Revisit when IPv6 North-South communication support is added.
LOG.debug("handleSubnetGwIpChange : Skipping ipv6 address {}.", address);
return;
}
} catch (UnknownHostException e) {
LOG.warn("handleSubnetGwIpChange : Invalid ip address {}", fixedIp, e);
return;
}
for (Uuid subnetId : nvpnManager.getSubnetIdsForGatewayIp(new IpAddress(new Ipv4Address(fixedIp)))) {
LOG.trace("handleSubnetGwIpChange : Updating MAC resolution on vpn {} for GW ip {} to {}", learntVpnVipToPort.getVpnName(), fixedIp, macAddress);
extNetworkInstaller.installExtNetGroupEntries(subnetId, macAddress);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.Prefix in project netvirt by opendaylight.
the class VpnFloatingIpHandler method onAddFloatingIp.
@Override
public void onAddFloatingIp(final Uint64 dpnId, final String routerUuid, final Uint32 routerId, final Uuid networkId, final String interfaceName, final InternalToExternalPortMap mapping, final String rd, TypedReadWriteTransaction<Configuration> confTx) {
String externalIp = mapping.getExternalIp();
String internalIp = mapping.getInternalIp();
Uuid floatingIpId = mapping.getExternalId();
Uuid subnetId = NatUtil.getFloatingIpPortSubnetIdFromFloatingIpId(dataBroker, floatingIpId);
String floatingIpPortMacAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(dataBroker, floatingIpId);
if (floatingIpPortMacAddress == null) {
LOG.error("onAddFloatingIp: Unable to retrieve floatingIp port MAC address from floatingIpId {} for " + "router {} to handle floatingIp {}", floatingIpId, routerUuid, externalIp);
return;
}
Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker, subnetId);
final String vpnName = externalSubnet.isPresent() ? subnetId.getValue() : NatUtil.getAssociatedVPN(dataBroker, networkId);
final String subnetVpnName = externalSubnet.isPresent() ? subnetId.getValue() : null;
if (vpnName == null) {
LOG.error("onAddFloatingIp: No VPN is associated with ext nw {} to handle add floating ip {} configuration " + "for router {}", networkId, externalIp, routerId);
return;
}
if (rd == null) {
LOG.error("onAddFloatingIp: Unable to retrieve external (internet) VPN RD from external VPN {} for " + "router {} to handle floatingIp {}", vpnName, routerId, externalIp);
return;
}
ProviderTypes provType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerUuid, networkId);
if (provType == null) {
return;
}
/*
* For external network of type GRE, it is required to use "Internet VPN VNI" for intra-DC
* communication, but we still require "MPLS labels" to reach SNAT/DNAT VMs from external
* entities via MPLSOverGRE.
*
* MPLSOverGRE based external networks, the ``opendaylight-vni-ranges`` pool will be
* used to carve out a unique VNI per Internet VPN (GRE-provider-type) to be used in the
* datapath for traffic forwarding for ``SNAT-to-DNAT`` and ``DNAT-to-DNAT`` cases within the
* DataCenter.
*/
String nextHopIp = NatUtil.getEndpointIpAddressForDPN(dataBroker, dpnId);
LOG.debug("onAddFloatingIp: Nexthop ip for prefix {} is {}", externalIp, nextHopIp);
if (provType == ProviderTypes.VXLAN) {
Uuid floatingIpInterface = NatEvpnUtil.getFloatingIpInterfaceIdFromFloatingIpId(dataBroker, floatingIpId);
evpnDnatFlowProgrammer.onAddFloatingIp(dpnId, routerUuid, routerId, vpnName, internalIp, externalIp, networkId, interfaceName, floatingIpInterface.getValue(), floatingIpPortMacAddress, rd, nextHopIp, confTx);
return;
}
/*
* MPLS label will be used to advertise prefixes and in "L3_LFIB_TABLE" (table 20) taking the packet
* to "INBOUND_NAPT_TABLE" (table 44) and "PDNAT_TABLE" (table 25).
*/
GenerateVpnLabelInput labelInput = new GenerateVpnLabelInputBuilder().setVpnName(vpnName).setIpPrefix(externalIp).build();
ListenableFuture<RpcResult<GenerateVpnLabelOutput>> labelFuture = vpnService.generateVpnLabel(labelInput);
ListenableFuture<RpcResult<CreateFibEntryOutput>> future = Futures.transformAsync(labelFuture, result -> {
if (result.isSuccessful()) {
GenerateVpnLabelOutput output = result.getResult();
Uint32 label = output.getLabel();
LOG.debug("onAddFloatingIp : Generated label {} for prefix {}", label, externalIp);
FloatingIPListener.updateOperationalDS(dataBroker, routerUuid, interfaceName, label, internalIp, externalIp);
/*
* For external network of type VXLAN all packets going from VMs within the DC, towards the
* external gateway device via the External VXLAN Tunnel,we are setting the VXLAN Tunnel ID to
* the L3VNI value of VPNInstance to which the VM belongs to.
*/
Uint32 l3vni = Uint32.ZERO;
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanService, provType)) {
l3vni = natOverVxlanUtil.getInternetVpnVni(vpnName, l3vni);
}
String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
// Inform BGP
NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd, fibExternalIp, nextHopIp, networkId.getValue(), floatingIpPortMacAddress, label, l3vni, RouteOrigin.STATIC, dpnId);
List<Instruction> instructions = new ArrayList<>();
List<ActionInfo> actionsInfos = new ArrayList<>();
actionsInfos.add(new ActionNxResubmit(NwConstants.PDNAT_TABLE));
instructions.add(new InstructionApplyActions(actionsInfos).buildInstruction(0));
List<ActionInfo> actionInfoFib = new ArrayList<>();
List<Instruction> customInstructions = new ArrayList<>();
actionInfoFib.add(new ActionSetFieldEthernetDestination(new MacAddress(floatingIpPortMacAddress)));
customInstructions.add(new InstructionApplyActions(actionInfoFib).buildInstruction(0));
customInstructions.add(new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(1));
LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, innerConfTx -> {
makeTunnelTableEntry(vpnName, dpnId, label, instructions, innerConfTx, provType);
makeLFibTableEntry(dpnId, label, floatingIpPortMacAddress, NwConstants.PDNAT_TABLE, innerConfTx);
}), LOG, "Error adding tunnel or FIB table entries");
CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId).setInstruction(customInstructions).setIpAddress(fibExternalIp).setServiceId(label).setIpAddressSource(CreateFibEntryInput.IpAddressSource.FloatingIP).setInstruction(customInstructions).build();
// Future<RpcResult<java.lang.Void>> createFibEntry(CreateFibEntryInput input);
ListenableFuture<RpcResult<CreateFibEntryOutput>> future1 = fibService.createFibEntry(input);
LOG.debug("onAddFloatingIp : Add Floating Ip {} , found associated to fixed port {}", externalIp, interfaceName);
String networkVpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
vpnManager.addSubnetMacIntoVpnInstance(networkVpnName, subnetVpnName, floatingIpPortMacAddress, dpnId, tx);
vpnManager.addArpResponderFlowsToExternalNetworkIps(routerUuid, Collections.singleton(externalIp), floatingIpPortMacAddress, dpnId, networkId);
});
return future1;
} else {
String errMsg = String.format("onAddFloatingIp : Could not retrieve the label for prefix %s " + "in VPN %s, %s", externalIp, vpnName, result.getErrors());
LOG.error(errMsg);
return Futures.immediateFailedFuture(new RuntimeException(errMsg));
}
}, MoreExecutors.directExecutor());
Futures.addCallback(future, new FutureCallback<RpcResult<CreateFibEntryOutput>>() {
@Override
public void onFailure(@NonNull Throwable error) {
LOG.error("onAddFloatingIp : Error in generate label or fib install process", error);
}
@Override
public void onSuccess(@NonNull RpcResult<CreateFibEntryOutput> result) {
if (result.isSuccessful()) {
LOG.info("onAddFloatingIp : Successfully installed custom FIB routes for prefix {}", externalIp);
} else {
LOG.error("onAddFloatingIp : Error in rpc call to create custom Fib entries for prefix {} " + "in DPN {}, {}", externalIp, dpnId, result.getErrors());
}
}
}, MoreExecutors.directExecutor());
// Handle GARP transmission
final IpAddress extrenalAddress = IpAddressBuilder.getDefaultInstance(externalIp);
sendGarpOnInterface(dpnId, networkId, extrenalAddress, floatingIpPortMacAddress);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.Prefix in project netvirt by opendaylight.
the class VpnFloatingIpHandler method cleanupFibEntries.
@Override
public void cleanupFibEntries(Uint64 dpnId, String vpnName, String externalIp, Uint32 label, final String rd, TypedReadWriteTransaction<Configuration> confTx, ProviderTypes provType) {
// Remove Prefix from BGP
String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
NatUtil.removePrefixFromBGP(bgpManager, fibManager, rd, fibExternalIp, vpnName);
NatUtil.deletePrefixToInterface(dataBroker, NatUtil.getVpnId(dataBroker, vpnName), fibExternalIp);
// Remove custom FIB routes
// Future<RpcResult<java.lang.Void>> removeFibEntry(RemoveFibEntryInput input);
RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId).setIpAddress(fibExternalIp).setServiceId(label).setIpAddressSource(RemoveFibEntryInput.IpAddressSource.FloatingIP).build();
ListenableFuture<RpcResult<RemoveFibEntryOutput>> future = fibService.removeFibEntry(input);
ListenableFuture<RpcResult<RemoveVpnLabelOutput>> labelFuture = Futures.transformAsync(future, result -> {
// Release label
if (result.isSuccessful()) {
/* check if any floating IP information is available in vpn-to-dpn-list for given dpn id. If exist any
* floating IP then do not remove INTERNAL_TUNNEL_TABLE (table=36) -> PDNAT_TABLE (table=25) flow entry
*/
Boolean removeTunnelFlow = Boolean.TRUE;
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanService, provType)) {
if (NatUtil.isFloatingIpPresentForDpn(dataBroker, dpnId, rd, vpnName, externalIp, false)) {
removeTunnelFlow = Boolean.FALSE;
}
}
if (removeTunnelFlow) {
removeTunnelTableEntry(dpnId, label, confTx);
}
removeLFibTableEntry(dpnId, label, confTx);
RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder().setVpnName(vpnName).setIpPrefix(externalIp).build();
Future<RpcResult<RemoveVpnLabelOutput>> labelFuture1 = vpnService.removeVpnLabel(labelInput);
if (labelFuture1.get() == null || !labelFuture1.get().isSuccessful()) {
String errMsg = String.format("VpnFloatingIpHandler: RPC call to remove VPN label on dpn %s " + "for prefix %s failed for vpn %s - %s", dpnId, externalIp, vpnName, result.getErrors());
LOG.error(errMsg);
return Futures.immediateFailedFuture(new RuntimeException(errMsg));
}
return JdkFutureAdapters.listenInPoolThread(labelFuture1);
} else {
String errMsg = String.format("onRemoveFloatingIp :RPC call to remove custom FIB entries " + "on dpn %s for prefix %s Failed - %s", dpnId, externalIp, result.getErrors());
LOG.error(errMsg);
return Futures.immediateFailedFuture(new RuntimeException(errMsg));
}
}, MoreExecutors.directExecutor());
Futures.addCallback(labelFuture, new FutureCallback<RpcResult<RemoveVpnLabelOutput>>() {
@Override
public void onFailure(@NonNull Throwable error) {
LOG.error("onRemoveFloatingIp : Error in removing the label or custom fib entries", error);
}
@Override
public void onSuccess(@NonNull RpcResult<RemoveVpnLabelOutput> result) {
if (result.isSuccessful()) {
LOG.debug("onRemoveFloatingIp : Successfully removed the label for the prefix {} from VPN {}", externalIp, vpnName);
} else {
LOG.error("onRemoveFloatingIp : Error in removing the label for prefix {} from VPN {}, {}", externalIp, vpnName, result.getErrors());
}
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.Prefix in project netvirt by opendaylight.
the class NaptSwitchHA method removeFibEntry.
private void removeFibEntry(String rd, String prefix) {
InstanceIdentifier.InstanceIdentifierBuilder<VrfEntry> idBuilder = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd)).child(VrfEntry.class, new VrfEntryKey(prefix));
InstanceIdentifier<VrfEntry> vrfEntryId = idBuilder.build();
Optional<VrfEntry> ent;
try {
ent = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vrfEntryId);
} catch (ExecutionException | InterruptedException e) {
LOG.error("removeFibEntry: Exception while reading the VrfEntry for the prefix {} rd {}", prefix, rd, e);
return;
}
if (ent.isPresent()) {
LOG.debug("removeFibEntry : Removing Fib entry rd {} prefix {}", rd, prefix);
fibManager.removeFibEntry(rd, prefix, null, null);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.Prefix in project netvirt by opendaylight.
the class NaptSwitchHA method isNaptSwitchDown.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public boolean isNaptSwitchDown(Routers extRouter, Uint32 routerId, Uint64 dpnId, Uint64 naptSwitch, Uint32 routerVpnId, Collection<String> externalIpCache, boolean isClearBgpRts, TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
externalIpsCache = externalIpCache;
String routerName = extRouter.getRouterName();
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 = extRouter.getNetworkId();
String vpnName = getExtNetworkVpnName(routerName, networkId);
// elect a new NaptSwitch
naptSwitch = naptSwitchSelector.selectNewNAPTSwitch(routerName, Arrays.asList(naptSwitch));
if (natMode == NatMode.Conntrack) {
Routers extRouters = NatUtil.getRoutersFromConfigDS(dataBroker, routerName);
natServiceManager.notify(confTx, extRouters, null, dpnId, dpnId, SnatServiceManager.Action.CNT_ROUTER_ALL_SWITCH_DISBL);
if (extRouters.isEnableSnat()) {
natServiceManager.notify(confTx, extRouters, null, dpnId, dpnId, SnatServiceManager.Action.SNAT_ALL_SWITCH_DISBL);
}
natServiceManager.notify(confTx, extRouters, null, naptSwitch, naptSwitch, SnatServiceManager.Action.CNT_ROUTER_ALL_SWITCH_ENBL);
if (extRouters.isEnableSnat()) {
natServiceManager.notify(confTx, extRouters, null, naptSwitch, naptSwitch, SnatServiceManager.Action.SNAT_ALL_SWITCH_ENBL);
}
} else {
if (naptSwitch.equals(Uint64.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, 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 (!NatUtil.getSwitchStatus(dataBroker, 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.addFlow(confTx, flowEntity);
}
installSnatFlows(routerName, routerId, naptSwitch, routerVpnId, networkId, vpnName, confTx);
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
Uint32 groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(routerName));
if (groupId != NatConstants.INVALID_ID) {
try {
LOG.info("isNaptSwitchDown : Removing NAPT Group in new naptSwitch {}", naptSwitch);
mdsalManager.removeGroup(confTx, naptSwitch, groupId.longValue());
} catch (Exception ex) {
LOG.error("isNaptSwitchDown : Failed to remove group in new naptSwitch {}", naptSwitch, ex);
}
} else {
LOG.error("NAT Service : Unable to obtain groupId for router:{}", routerName);
}
}
return true;
}
Aggregations