Search in sources :

Example 21 with Network

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network in project netvirt by opendaylight.

the class InterfaceStateEventListener method getRouterIdForPort.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private String getRouterIdForPort(String interfaceName) {
    String routerName = null;
    VpnInterface vpnInterface = null;
    try {
        vpnInterface = NatUtil.getConfiguredVpnInterface(dataBroker, interfaceName);
    } catch (Exception ex) {
        LOG.error("getRouterIdForPort : Unable to process for interface {} as it is not configured", interfaceName, ex);
    }
    if (vpnInterface != null) {
        // getVpnName
        if (vpnInterface.getVpnInstanceNames() == null) {
            LOG.debug("getRouterIdForPort : vpnName not found for vpnInterface {} of port {}", vpnInterface, interfaceName);
        } else {
            for (VpnInstanceNames vpnInstance : vpnInterface.getVpnInstanceNames()) {
                String vpnName = vpnInstance.getVpnName();
                try {
                    routerName = NatUtil.getRouterIdfromVpnInstance(dataBroker, vpnName);
                } catch (Exception e) {
                    LOG.error("getRouterIdForPort : Unable to get routerId for vpnName {}", vpnName, e);
                }
                if (routerName != null) {
                    // check router is associated to external network
                    if (NatUtil.isSnatEnabledForRouterId(dataBroker, routerName)) {
                        LOG.debug("getRouterIdForPort : Retreived Router Id {} for vpnname {} " + "associated to interface {}", routerName, vpnName, interfaceName);
                        return routerName;
                    } else {
                        LOG.warn("getRouterIdForPort : Interface {} associated to routerId {} is not " + "associated to external network", interfaceName, routerName);
                    }
                } else {
                    LOG.warn("getRouterIdForPort : Router is not associated to vpnname {} for interface {}", vpnName, interfaceName);
                }
            }
        }
    } else {
        LOG.debug("getRouterIdForPort : Interface {} is not a vpninterface", interfaceName);
    }
    return null;
}
Also used : VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames) ExecutionException(java.util.concurrent.ExecutionException)

Example 22 with Network

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network in project netvirt by opendaylight.

the class VpnFloatingIpHandler method onAddFloatingIp.

@Override
public void onAddFloatingIp(final BigInteger dpnId, final String routerUuid, final long routerId, final Uuid networkId, final String interfaceName, final InternalToExternalPortMap mapping, WriteTransaction writeFlowInvTx) {
    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;
    }
    String rd = NatUtil.getVpnRd(dataBroker, vpnName);
    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.
        */
    if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanService, provType)) {
        NatOverVxlanUtil.validateAndCreateVxlanVniPool(dataBroker, nvpnManager, idManager, NatConstants.ODL_VNI_POOL_NAME);
    }
    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, writeFlowInvTx);
        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();
    Future<RpcResult<GenerateVpnLabelOutput>> labelFuture = vpnService.generateVpnLabel(labelInput);
    ListenableFuture<RpcResult<Void>> future = Futures.transformAsync(JdkFutureAdapters.listenInPoolThread(labelFuture), (AsyncFunction<RpcResult<GenerateVpnLabelOutput>, RpcResult<Void>>) result -> {
        if (result.isSuccessful()) {
            GenerateVpnLabelOutput output = result.getResult();
            long label = output.getLabel();
            LOG.debug("onAddFloatingIp : Generated label {} for prefix {}", label, externalIp);
            FloatingIPListener.updateOperationalDS(dataBroker, routerUuid, interfaceName, label, internalIp, externalIp);
            long l3vni = 0;
            if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanService, provType)) {
                l3vni = NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, l3vni).longValue();
            }
            String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
            NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd, subnetId, 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));
            makeTunnelTableEntry(vpnName, dpnId, label, instructions, writeFlowInvTx, provType);
            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));
            makeLFibTableEntry(dpnId, label, floatingIpPortMacAddress, NwConstants.PDNAT_TABLE, writeFlowInvTx);
            CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId).setInstruction(customInstructions).setIpAddress(fibExternalIp).setServiceId(label).setIpAddressSource(CreateFibEntryInput.IpAddressSource.FloatingIP).setInstruction(customInstructions).build();
            Future<RpcResult<Void>> 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(tx -> {
                vpnManager.addSubnetMacIntoVpnInstance(networkVpnName, subnetVpnName, floatingIpPortMacAddress, dpnId, tx);
                vpnManager.addArpResponderFlowsToExternalNetworkIps(routerUuid, Collections.singleton(externalIp), floatingIpPortMacAddress, dpnId, networkId, tx);
            });
            return JdkFutureAdapters.listenInPoolThread(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<Void>>() {

        @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<Void> 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);
}
Also used : SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) IFibManager(org.opendaylight.netvirt.fibmanager.api.IFibManager) GenerateVpnLabelOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.GenerateVpnLabelOutput) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) FibRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.FibRpcService) LoggerFactory(org.slf4j.LoggerFactory) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) SendArpRequestInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.SendArpRequestInput) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) Future(java.util.concurrent.Future) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) Optional(com.google.common.base.Optional) IBgpManager(org.opendaylight.netvirt.bgpmanager.api.IBgpManager) InterfaceAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.interfaces.InterfaceAddress) BigInteger(java.math.BigInteger) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) VpnRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.VpnRpcService) PhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress) Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) RemoveFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInput) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) List(java.util.List) SendArpRequestInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.SendArpRequestInputBuilder) ActionSetFieldEthernetDestination(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetDestination) CreateFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInput) InterfaceAddressBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.interfaces.InterfaceAddressBuilder) FloatingIpIdToPortMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.port.info.FloatingIpIdToPortMapping) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) CreateFibEntryInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) IElanService(org.opendaylight.netvirt.elanmanager.api.IElanService) Singleton(javax.inject.Singleton) JdkFutureAdapters(com.google.common.util.concurrent.JdkFutureAdapters) INeutronVpnManager(org.opendaylight.netvirt.neutronvpn.interfaces.INeutronVpnManager) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) RemoveVpnLabelInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveVpnLabelInputBuilder) MatchTunnelId(org.opendaylight.genius.mdsalutil.matches.MatchTunnelId) RemoveFibEntryInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInputBuilder) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) ActionPopMpls(org.opendaylight.genius.mdsalutil.actions.ActionPopMpls) Nonnull(javax.annotation.Nonnull) JdkFutures(org.opendaylight.infrautils.utils.concurrent.JdkFutures) Logger(org.slf4j.Logger) GenerateVpnLabelInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.GenerateVpnLabelInputBuilder) NatUtil.buildfloatingIpIdToPortMappingIdentifier(org.opendaylight.netvirt.natservice.internal.NatUtil.buildfloatingIpIdToPortMappingIdentifier) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin) IVpnManager(org.opendaylight.netvirt.vpnmanager.api.IVpnManager) RemoveVpnLabelInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveVpnLabelInput) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) FutureCallback(com.google.common.util.concurrent.FutureCallback) ListenableFutures(org.opendaylight.infrautils.utils.concurrent.ListenableFutures) Futures(com.google.common.util.concurrent.Futures) GenerateVpnLabelInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.GenerateVpnLabelInput) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) MatchMplsLabel(org.opendaylight.genius.mdsalutil.matches.MatchMplsLabel) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) AsyncFunction(com.google.common.util.concurrent.AsyncFunction) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) Collections(java.util.Collections) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) IpAddressBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder) OdlArputilService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.OdlArputilService) GenerateVpnLabelOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.GenerateVpnLabelOutput) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) List(java.util.List) ArrayList(java.util.ArrayList) GenerateVpnLabelInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.GenerateVpnLabelInputBuilder) GenerateVpnLabelInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.GenerateVpnLabelInput) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) CreateFibEntryInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) CreateFibEntryInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInput) ActionSetFieldEthernetDestination(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetDestination) Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Future(java.util.concurrent.Future) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Example 23 with Network

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network in project netvirt by opendaylight.

the class NaptSwitchHA method installSnatFlows.

protected void installSnatFlows(String routerName, Long routerId, BigInteger naptSwitch, Long routerVpnId, WriteTransaction writeFlowInvTx) {
    if (routerId.equals(routerVpnId)) {
        LOG.debug("installSnatFlows : Installing flows for router with internalvpnId");
        // 36 -> 46 ..Install flow forwarding packet to table46 from table36
        LOG.debug("installSnatFlows : installTerminatingServiceTblEntry in naptswitch with dpnId {} for " + "routerName {} with routerId {}", naptSwitch, routerName, routerId);
        externalRouterListener.installTerminatingServiceTblEntry(naptSwitch, routerName, routerId, writeFlowInvTx);
        // Install default flows punting to controller in table 46(OutBoundNapt table)
        LOG.debug("installSnatFlows : installOutboundMissEntry in naptswitch with dpnId {} for " + "routerName {} with routerId {}", naptSwitch, routerName, routerId);
        externalRouterListener.createOutboundTblEntry(naptSwitch, routerId, writeFlowInvTx);
        // Table 47 point to table 21 for inbound traffic
        LOG.debug("installSnatFlows : installNaptPfibEntry in naptswitch with dpnId {} for router {}", naptSwitch, routerId);
        externalRouterListener.installNaptPfibEntry(naptSwitch, routerId, writeFlowInvTx);
        // Table 47 point to group
        LOG.debug("installSnatFlows : installNaptPfibExternalOutputFlow in naptswitch with dpnId {} for router {}", naptSwitch, routerId);
        externalRouterListener.installNaptPfibExternalOutputFlow(routerName, routerId, naptSwitch, writeFlowInvTx);
    } else {
        Uuid extNetworkUuid = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
        if (extNetworkUuid == null) {
            LOG.error("onRouterAssociatedToVpn : Unable to retrieve external network Uuid for router {}", routerName);
            return;
        }
        ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNetworkUuid);
        if (extNwProvType == null) {
            LOG.error("onRouterAssociatedToVpn : External Network Provider Type missing");
            return;
        }
        // 36 -> 46 ..Install flow forwarding packet to table46 from table36
        LOG.debug("installSnatFlows : installTerminatingServiceTblEntry in naptswitch with dpnId {} for " + "routerName {} with BgpVpnId {}", naptSwitch, routerName, routerVpnId);
        externalRouterListener.installTerminatingServiceTblEntryWithUpdatedVpnId(naptSwitch, routerName, routerId, routerVpnId, writeFlowInvTx, extNwProvType);
        // Install default flows punting to controller in table 46(OutBoundNapt table)
        LOG.debug("installSnatFlows : installOutboundMissEntry in naptswitch with dpnId {} for " + "routerName {} with BgpVpnId {}", naptSwitch, routerName, routerVpnId);
        externalRouterListener.createOutboundTblEntryWithBgpVpn(naptSwitch, routerId, routerVpnId, writeFlowInvTx);
        // Table 47 point to table 21 for inbound traffic
        LOG.debug("installSnatFlows : installNaptPfibEntry in naptswitch with dpnId {} for router {} " + "with BgpVpnId {}", naptSwitch, routerId, routerVpnId);
        externalRouterListener.installNaptPfibEntryWithBgpVpn(naptSwitch, routerId, routerVpnId, writeFlowInvTx);
    }
    Uuid networkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
    String vpnName = getExtNetworkVpnName(routerName, networkId);
    if (vpnName != null) {
        // NAPT PFIB point to FIB table for outbound traffic
        long vpnId = NatUtil.getVpnId(dataBroker, vpnName);
        boolean shouldInstallNaptPfibWithExtNetworkVpnId = true;
        Collection<Uuid> externalSubnetIds = NatUtil.getExternalSubnetIdsForRouter(dataBroker, routerName);
        if (!externalSubnetIds.isEmpty()) {
            // NAPT PFIB point to FIB table for outbound traffic - using external subnetID as vpnID.
            for (Uuid externalSubnetId : externalSubnetIds) {
                long externalSubnetVpnId = NatUtil.getExternalSubnetVpnId(dataBroker, externalSubnetId);
                if (externalSubnetVpnId != NatConstants.INVALID_ID) {
                    shouldInstallNaptPfibWithExtNetworkVpnId = false;
                    LOG.debug("installSnatFlows : installNaptPfibEntry fin naptswitch with dpnId {} for " + "BgpVpnId {}", naptSwitch, externalSubnetVpnId);
                    externalRouterListener.installNaptPfibEntry(naptSwitch, externalSubnetVpnId, writeFlowInvTx);
                }
            }
        }
        if (vpnId != NatConstants.INVALID_ID && shouldInstallNaptPfibWithExtNetworkVpnId) {
            // NAPT PFIB table point to FIB table for outbound traffic - using external networkID as vpnID.
            LOG.debug("installSnatFlows : installNaptPfibEntry fin naptswitch with dpnId {} for " + "BgpVpnId {}", naptSwitch, vpnId);
            externalRouterListener.installNaptPfibEntry(naptSwitch, vpnId, writeFlowInvTx);
        } else if (vpnId != NatConstants.INVALID_ID) {
            LOG.debug("installSnatFlows : Associated BgpvpnId not found for router {}", routerId);
        }
        // Install Fib entries for ExternalIps & program 36 -> 44
        Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
        String rd = NatUtil.getVpnRd(dataBroker, vpnName);
        for (String externalIp : externalIps) {
            removeFibEntry(rd, externalIp);
            LOG.debug("installSnatFlows : advToBgpAndInstallFibAndTsFlows in naptswitch id {} " + "with vpnName {} and externalIp {}", naptSwitch, vpnName, externalIp);
            externalRouterListener.advToBgpAndInstallFibAndTsFlows(naptSwitch, NwConstants.INBOUND_NAPT_TABLE, vpnName, routerId, routerName, externalIp, networkId, null, /* external-router */
            writeFlowInvTx);
            LOG.debug("installSnatFlows : Successfully added fib entries in naptswitch {} for " + "router {} with external IP {}", naptSwitch, routerId, externalIp);
        }
    } else {
        LOG.debug("installSnatFlows : Associated vpnName not found for router {}", routerId);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)

Example 24 with Network

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network in project netvirt by opendaylight.

the class NaptSwitchHA method removeSnatFlowsInOldNaptSwitch.

/* This method checks the switch that gone down is a NaptSwitch for a router.
       If it is a NaptSwitch
          1) selects new NAPT switch
          2) installs nat flows in new NAPT switch
          table 21(FIB)->26(PSNAT)->group(resubmit/napttunnel)->36(Terminating)->46(outbound)->47(resubmit)->21
          3) modify the group and miss entry flow in other vSwitches pointing to newNaptSwitch
          4) Remove nat flows in oldNaptSwitch
     */
/*public void handleNaptSwitchDown(BigInteger dpnId){

        LOG.debug("handleNaptSwitchDown method is called with dpnId {}",dpnId);
        BigInteger naptSwitch;
        try {
            NaptSwitches naptSwitches = NatUtil.getNaptSwitch(dataBroker);
            if (naptSwitches == null || naptSwitches.getRouterToNaptSwitch() == null
             || naptSwitches.getRouterToNaptSwitch().isEmpty()) {
                LOG.debug("NaptSwitchDown: NaptSwitch is not allocated for none of the routers");
                return;
            }
            for (RouterToNaptSwitch routerToNaptSwitch : naptSwitches.getRouterToNaptSwitch()) {
                String routerName = routerToNaptSwitch.getRouterName();
                naptSwitch = routerToNaptSwitch.getPrimarySwitchId();
                boolean naptStatus = isNaptSwitchDown(routerName,dpnId,naptSwitch);
                if (!naptStatus) {
                    LOG.debug("NaptSwitchDown: Switch with DpnId {} is not naptSwitch for router {}",
                            dpnId, routerName);
                } else {
                    removeSnatFlowsInOldNaptSwitch(routerName,naptSwitch);
                    return;
                }
            }
        } catch (Exception ex) {
            LOG.error("Exception in handleNaptSwitchDown method {}",ex);
        }
    }*/
protected void removeSnatFlowsInOldNaptSwitch(String routerName, Long routerId, BigInteger naptSwitch, Map<String, Long> externalIpmap, WriteTransaction removeFlowInvTx) {
    // remove SNAT flows in old NAPT SWITCH
    Uuid networkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
    String vpnName = getExtNetworkVpnName(routerName, networkId);
    if (vpnName == null) {
        LOG.error("removeSnatFlowsInOldNaptSwitch : Vpn is not associated to externalN/w of router {}", routerName);
        return;
    }
    ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, networkId);
    if (extNwProvType == null) {
        LOG.error("removeSnatFlowsInOldNaptSwitch : Unable to retrieve the External Network Provider Type " + "for Router {}", routerName);
        return;
    }
    if (extNwProvType == ProviderTypes.VXLAN) {
        evpnNaptSwitchHA.evpnRemoveSnatFlowsInOldNaptSwitch(routerName, routerId, vpnName, naptSwitch, removeFlowInvTx);
    } else {
        // Remove the Terminating Service table entry which forwards the packet to Outbound NAPT Table
        long tunnelId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, elanManager, idManager, routerId, routerName);
        String tsFlowRef = externalRouterListener.getFlowRefTs(naptSwitch, NwConstants.INTERNAL_TUNNEL_TABLE, tunnelId);
        FlowEntity tsNatFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.INTERNAL_TUNNEL_TABLE, tsFlowRef);
        LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for the old napt switch " + "with the DPN ID {} and router ID {}", NwConstants.INTERNAL_TUNNEL_TABLE, naptSwitch, routerId);
        mdsalManager.removeFlowToTx(tsNatFlowEntity, removeFlowInvTx);
    }
    if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
        // Remove the flow table 25->44 If there is no FIP Match on table 25 (PDNAT_TABLE)
        NatUtil.removePreDnatToSnatTableEntry(mdsalManager, naptSwitch, removeFlowInvTx);
    }
    // Remove the Outbound flow entry which forwards the packet to Outbound NAPT Table
    String outboundNatFlowRef = externalRouterListener.getFlowRefOutbound(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, routerId);
    FlowEntity outboundNatFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, outboundNatFlowRef);
    LOG.info("Remove the flow in table {} for the old napt switch with the DPN ID {} and router ID {}", NwConstants.OUTBOUND_NAPT_TABLE, naptSwitch, routerId);
    mdsalManager.removeFlowToTx(outboundNatFlowEntity, removeFlowInvTx);
    // Remove the NAPT PFIB TABLE (47->21) which forwards the incoming packet to FIB Table matching on the
    // External Subnet Vpn Id.
    Collection<Uuid> externalSubnetIdsForRouter = NatUtil.getExternalSubnetIdsForRouter(dataBroker, routerName);
    for (Uuid externalSubnetId : externalSubnetIdsForRouter) {
        long subnetVpnId = NatUtil.getVpnId(dataBroker, externalSubnetId.getValue());
        if (subnetVpnId != -1) {
            String natPfibSubnetFlowRef = externalRouterListener.getFlowRefTs(naptSwitch, NwConstants.NAPT_PFIB_TABLE, subnetVpnId);
            FlowEntity natPfibFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.NAPT_PFIB_TABLE, natPfibSubnetFlowRef);
            mdsalManager.removeFlowToTx(natPfibFlowEntity, removeFlowInvTx);
            LOG.debug("removeSnatFlowsInOldNaptSwitch : Removed the flow in table {} with external subnet " + "Vpn Id {} as metadata on Napt Switch {}", NwConstants.NAPT_PFIB_TABLE, subnetVpnId, naptSwitch);
        }
    }
    // Remove the NAPT_PFIB_TABLE(47) flow entry forwards the packet to Fib Table for inbound traffic
    // matching on the router ID.
    String naptPFibflowRef = externalRouterListener.getFlowRefTs(naptSwitch, NwConstants.NAPT_PFIB_TABLE, routerId);
    FlowEntity naptPFibFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.NAPT_PFIB_TABLE, naptPFibflowRef);
    LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for the old napt switch " + "with the DPN ID {} and router ID {}", NwConstants.NAPT_PFIB_TABLE, naptSwitch, routerId);
    mdsalManager.removeFlowToTx(naptPFibFlowEntity, removeFlowInvTx);
    // Remove the NAPT_PFIB_TABLE(47) flow entry forwards the packet to Fib Table for outbound traffic
    // matching on the vpn ID.
    boolean switchSharedByRouters = false;
    Uuid extNetworkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
    if (extNetworkId != null) {
        List<String> routerNamesAssociated = getRouterIdsForExtNetwork(extNetworkId);
        for (String routerNameAssociated : routerNamesAssociated) {
            if (!routerNameAssociated.equals(routerName)) {
                Long routerIdAssociated = NatUtil.getVpnId(dataBroker, routerNameAssociated);
                BigInteger naptDpn = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerNameAssociated);
                if (naptDpn != null && naptDpn.equals(naptSwitch)) {
                    LOG.debug("removeSnatFlowsInOldNaptSwitch : Napt switch {} is also acting as primary " + "for router {}", naptSwitch, routerIdAssociated);
                    switchSharedByRouters = true;
                    break;
                }
            }
        }
        if (!switchSharedByRouters) {
            Long vpnId = getVpnIdForRouter(routerId, extNetworkId);
            if (vpnId != NatConstants.INVALID_ID) {
                String naptFibflowRef = externalRouterListener.getFlowRefTs(naptSwitch, NwConstants.NAPT_PFIB_TABLE, vpnId);
                FlowEntity naptFibFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.NAPT_PFIB_TABLE, naptFibflowRef);
                LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for the old napt switch" + " with the DPN ID {} and vpnId {}", NwConstants.NAPT_PFIB_TABLE, naptSwitch, vpnId);
                mdsalManager.removeFlowToTx(naptFibFlowEntity, removeFlowInvTx);
            } else {
                LOG.error("removeSnatFlowsInOldNaptSwitch : Invalid vpnId retrieved for routerId {}", routerId);
                return;
            }
        }
    }
    // Remove Fib entries,tables 20->44 ,36-> 44
    String gwMacAddress = NatUtil.getExtGwMacAddFromRouterName(dataBroker, routerName);
    if (externalIpmap != null && !externalIpmap.isEmpty()) {
        for (Entry<String, Long> entry : externalIpmap.entrySet()) {
            String externalIp = entry.getKey();
            Long label = entry.getValue();
            externalRouterListener.delFibTsAndReverseTraffic(naptSwitch, routerId, externalIp, vpnName, extNetworkId, label, gwMacAddress, true, removeFlowInvTx);
            LOG.debug("removeSnatFlowsInOldNaptSwitch : Successfully removed fib entries in old naptswitch {} " + "for router {} and externalIps {} label {}", naptSwitch, routerId, externalIp, label);
        }
    } else {
        List<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerName);
        if (networkId != null) {
            externalRouterListener.clearFibTsAndReverseTraffic(naptSwitch, routerId, networkId, externalIps, null, gwMacAddress, removeFlowInvTx);
            LOG.debug("removeSnatFlowsInOldNaptSwitch : Successfully removed fib entries in old naptswitch {} for " + "router {} with networkId {} and externalIps {}", naptSwitch, routerId, networkId, externalIps);
        } else {
            LOG.debug("removeSnatFlowsInOldNaptSwitch : External network not associated to router {}", routerId);
        }
        externalRouterListener.removeNaptFibExternalOutputFlows(routerId, naptSwitch, extNetworkId, externalIps, removeFlowInvTx);
    }
    // For the router ID get the internal IP , internal port and the corresponding external IP and external Port.
    IpPortMapping ipPortMapping = NatUtil.getIportMapping(dataBroker, routerId);
    if (ipPortMapping == null || ipPortMapping.getIntextIpProtocolType() == null || ipPortMapping.getIntextIpProtocolType().isEmpty()) {
        LOG.warn("removeSnatFlowsInOldNaptSwitch : No Internal Ip Port mapping associated to router {}, " + "no flows need to be removed in oldNaptSwitch {}", routerId, naptSwitch);
        return;
    }
    BigInteger cookieSnatFlow = NatUtil.getCookieNaptFlow(routerId);
    List<IntextIpProtocolType> intextIpProtocolTypes = ipPortMapping.getIntextIpProtocolType();
    for (IntextIpProtocolType intextIpProtocolType : intextIpProtocolTypes) {
        if (intextIpProtocolType.getIpPortMap() == null || intextIpProtocolType.getIpPortMap().isEmpty()) {
            LOG.debug("removeSnatFlowsInOldNaptSwitch : No {} session associated to router {}," + "no flows need to be removed in oldNaptSwitch {}", intextIpProtocolType.getProtocol(), routerId, naptSwitch);
            break;
        }
        List<IpPortMap> ipPortMaps = intextIpProtocolType.getIpPortMap();
        for (IpPortMap ipPortMap : ipPortMaps) {
            String ipPortInternal = ipPortMap.getIpPortInternal();
            String[] ipPortParts = ipPortInternal.split(":");
            if (ipPortParts.length != 2) {
                LOG.error("removeSnatFlowsInOldNaptSwitch : Unable to retrieve the Internal IP and port");
                continue;
            }
            String internalIp = ipPortParts[0];
            String internalPort = ipPortParts[1];
            // Build and remove flow in outbound NAPT table
            String switchFlowRef = NatUtil.getNaptFlowRef(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, String.valueOf(routerId), internalIp, Integer.parseInt(internalPort));
            FlowEntity outboundNaptFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, cookieSnatFlow, switchFlowRef);
            LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for old napt switch " + "with the DPN ID {} and router ID {}", NwConstants.OUTBOUND_NAPT_TABLE, naptSwitch, routerId);
            mdsalManager.removeFlowToTx(outboundNaptFlowEntity, removeFlowInvTx);
            IpPortExternal ipPortExternal = ipPortMap.getIpPortExternal();
            if (ipPortExternal == null) {
                LOG.debug("removeSnatFlowsInOldNaptSwitch : External Ipport mapping not found for internalIp {} " + "with port {} for router {}", internalIp, internalPort, routerId);
                continue;
            }
            String externalIp = ipPortExternal.getIpAddress();
            int externalPort = ipPortExternal.getPortNum();
            // Build and remove flow in  inbound NAPT table
            switchFlowRef = NatUtil.getNaptFlowRef(naptSwitch, NwConstants.INBOUND_NAPT_TABLE, String.valueOf(routerId), externalIp, externalPort);
            FlowEntity inboundNaptFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.INBOUND_NAPT_TABLE, cookieSnatFlow, switchFlowRef);
            LOG.info("removeSnatFlowsInOldNaptSwitch : Remove the flow in table {} for old napt switch with the " + "DPN ID {} and router ID {}", NwConstants.INBOUND_NAPT_TABLE, naptSwitch, routerId);
            mdsalManager.removeFlowToTx(inboundNaptFlowEntity, removeFlowInvTx);
        }
    }
}
Also used : ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) IpPortMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMapping) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) IpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap) IntextIpProtocolType(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.IntextIpProtocolType) BigInteger(java.math.BigInteger) IpPortExternal(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.ip.port.map.IpPortExternal)

Example 25 with Network

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network in project netvirt by opendaylight.

the class NeutronUtils method getNumberSegmentsFromNeutronNetwork.

public static Long getNumberSegmentsFromNeutronNetwork(Network network) {
    NetworkProviderExtension providerExtension = network.getAugmentation(NetworkProviderExtension.class);
    Integer numSegs = 0;
    if (providerExtension != null) {
        List<Segments> providerSegments = providerExtension.getSegments();
        if (providerSegments != null) {
            numSegs = providerSegments.size();
        }
    }
    return Long.valueOf(numSegs);
}
Also used : Segments(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.neutron.networks.network.Segments) NetworkProviderExtension(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtension)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)93 ArrayList (java.util.ArrayList)46 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)33 BigInteger (java.math.BigInteger)31 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)31 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)26 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)19 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)19 Port (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port)19 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)17 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)15 ElanInstance (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance)12 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)11 ExecutionException (java.util.concurrent.ExecutionException)10 ExternalNetworks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks)10 Networks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks)10 QosPolicy (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.qos.rev160613.qos.attributes.qos.policies.QosPolicy)10 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)9 HashSet (java.util.HashSet)8 Nonnull (javax.annotation.Nonnull)8