Search in sources :

Example 71 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.

the class AbstractSnatService method addSnatMissEntry.

protected void addSnatMissEntry(TypedReadWriteTransaction<Configuration> confTx, Uint64 dpnId, Uint32 routerId, String routerName, Uint64 primarySwitchId) {
    LOG.debug("installSnatMissEntry : Installing SNAT miss entry in switch {}", dpnId);
    List<ActionInfo> listActionInfoPrimary = new ArrayList<>();
    String ifNamePrimary = NatUtil.getTunnelInterfaceName(dpnId, primarySwitchId, itmManager);
    List<BucketInfo> listBucketInfo = new ArrayList<>();
    if (ifNamePrimary != null) {
        LOG.debug("installSnatMissEntry : On Non- Napt switch , Primary Tunnel interface is {}", ifNamePrimary);
        listActionInfoPrimary = NatUtil.getEgressActionsForInterface(odlInterfaceRpcService, itmManager, interfaceManager, ifNamePrimary, routerId, true);
    }
    BucketInfo bucketPrimary = new BucketInfo(listActionInfoPrimary);
    listBucketInfo.add(0, bucketPrimary);
    LOG.debug("installSnatMissEntry : installSnatMissEntry called for dpnId {} with primaryBucket {} ", dpnId, listBucketInfo.get(0));
    // Install the select group
    Uint32 groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, getGroupIdKey(routerName));
    if (groupId != NatConstants.INVALID_ID) {
        GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId.longValue(), routerName, GroupTypes.GroupAll, listBucketInfo);
        LOG.debug("installing the PSNAT to NAPTSwitch GroupEntity:{} with GroupId: {}", groupEntity, groupId);
        mdsalManager.addGroup(confTx, groupEntity);
        // Add the flow to send the packet to the group only after group is available in Config datastore
        eventCallbacks.onAddOrUpdate(LogicalDatastoreType.CONFIGURATION, NatUtil.getGroupInstanceId(dpnId, groupId), (unused, newGroupId) -> {
            LOG.info("group {} is created in the config", groupId);
            LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, innerConfTx -> addSnatMissFlowForGroup(innerConfTx, dpnId, routerId, groupId)), LOG, "Error adding flow for the group {}", groupId);
            return DataTreeEventCallbackRegistrar.NextAction.UNREGISTER;
        }, Duration.ofSeconds(5), iid -> LOG.error("groupId {} not found in config datastore", groupId));
    } else {
        LOG.error("installSnatMissEntry: Unable to get groupId for routerName:{}", routerName);
    }
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) IFibManager(org.opendaylight.netvirt.fibmanager.api.IFibManager) LoggerFactory(org.slf4j.LoggerFactory) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) AdjacenciesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.AdjacenciesBuilder) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) DataTreeEventCallbackRegistrar(org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar) Duration(java.time.Duration) LearntVpnVipToPortDataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.LearntVpnVipToPortDataBuilder) VpnInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInterfaces) LoggingFutures(org.opendaylight.infrautils.utils.concurrent.LoggingFutures) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) VpnInterfacesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInterfacesBuilder) MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) ActionNxLoadMetadata(org.opendaylight.genius.mdsalutil.actions.ActionNxLoadMetadata) Configuration(org.opendaylight.mdsal.binding.util.Datastore.Configuration) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) NatDataUtil(org.opendaylight.netvirt.natservice.ha.NatDataUtil) Objects(java.util.Objects) List(java.util.List) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) TypedWriteTransaction(org.opendaylight.mdsal.binding.util.TypedWriteTransaction) TypedReadWriteTransaction(org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction) IVpnFootprintService(org.opendaylight.netvirt.vpnmanager.api.IVpnFootprintService) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps) VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface) ActionSetFieldTunnelId(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId) NWUtil(org.opendaylight.genius.mdsalutil.NWUtil) SnatServiceListener(org.opendaylight.netvirt.natservice.api.SnatServiceListener) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency) Uint64(org.opendaylight.yangtools.yang.common.Uint64) OdlInterfaceRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService) LearntVpnVipToPortData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.LearntVpnVipToPortData) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) MatchTunnelId(org.opendaylight.genius.mdsalutil.matches.MatchTunnelId) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) IInterfaceManager(org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager) Uint32(org.opendaylight.yangtools.yang.common.Uint32) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) Logger(org.slf4j.Logger) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin) VpnInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceBuilder) ExpectedDataObjectNotFoundException(org.opendaylight.genius.datastoreutils.ExpectedDataObjectNotFoundException) GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.Adjacencies) ExecutionException(java.util.concurrent.ExecutionException) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) GroupTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort) BucketInfo(org.opendaylight.genius.mdsalutil.BucketInfo) Collections(java.util.Collections) MetaDataUtil(org.opendaylight.genius.mdsalutil.MetaDataUtil) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) ItmRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService) GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) BucketInfo(org.opendaylight.genius.mdsalutil.BucketInfo) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 72 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.

the class AbstractSnatService method addCommonEntriesForNaptSwitch.

private void addCommonEntriesForNaptSwitch(TypedReadWriteTransaction<Configuration> confTx, Routers routers, Uint64 dpnId) {
    String routerName = routers.getRouterName();
    Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
    addDefaultFibRouteForSNAT(confTx, dpnId, routerId);
    for (ExternalIps externalIp : routers.nonnullExternalIps().values()) {
        if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
            // In this class we handle only IPv4 use-cases.
            continue;
        }
        // The logic now handle only one external IP per router, others if present will be ignored.
        Uint32 extSubnetId = NatUtil.getExternalSubnetVpnId(dataBroker, externalIp.getSubnetId());
        addInboundTerminatingServiceTblEntry(confTx, dpnId, routerId, extSubnetId);
        addTerminatingServiceTblEntry(confTx, dpnId, routerId);
        break;
    }
}
Also used : Uint32(org.opendaylight.yangtools.yang.common.Uint32) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Example 73 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.

the class ExternalRoutersListener method handleSnatReverseTraffic.

public void handleSnatReverseTraffic(TypedWriteTransaction<Configuration> confTx, Uint64 dpnId, Routers router, Uint32 routerId, String routerName, String externalIp) {
    LOG.debug("handleSnatReverseTraffic : entry for DPN ID {}, routerId {}, externalIp: {}", dpnId, routerId, externalIp);
    Uuid networkId = router.getNetworkId();
    if (networkId == null) {
        LOG.error("handleSnatReverseTraffic : networkId is null for the router ID {}", routerId);
        return;
    }
    Collection<Uuid> externalSubnetList = NatUtil.getExternalSubnetIdsFromExternalIps(new ArrayList<ExternalIps>(router.nonnullExternalIps().values()));
    // FLAT/VLAN case having external-subnet as VPN
    String externalSubnetVpn = null;
    if (externalSubnetList != null && !externalSubnetList.isEmpty()) {
        Boolean isExternalIpsAdvertized = Boolean.FALSE;
        for (Uuid externalSubnetId : externalSubnetList) {
            Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker, externalSubnetId);
            // externalSubnet data model will exist for FLAT/VLAN external netowrk UCs.
            if (externalSubnet.isPresent()) {
                externalSubnetVpn = externalSubnetId.getValue();
                advToBgpAndInstallFibAndTsFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, externalSubnetVpn, routerId, routerName, externalIp, networkId, router, confTx);
                isExternalIpsAdvertized = Boolean.TRUE;
            }
        }
        if (isExternalIpsAdvertized) {
            LOG.trace("External Ips {} advertized for Router {}", router.getExternalIps(), routerName);
            return;
        }
    }
    // VXVLAN/GRE case having Internet-VPN
    final String vpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
    if (vpnName == null) {
        LOG.error("handleSnatReverseTraffic : No VPN associated with ext nw {} to handle add external ip " + "configuration {} in router {}", networkId, externalIp, routerId);
        return;
    }
    advToBgpAndInstallFibAndTsFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, vpnName, routerId, routerName, externalIp, networkId, router, confTx);
    LOG.debug("handleSnatReverseTraffic : exit for DPN ID {}, routerId {}, externalIp : {}", dpnId, routerId, externalIp);
}
Also used : 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) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Example 74 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.

the class Ipv6SubnetFlowProgrammer method addIPv6FlowToUpdateSrcMacToRouterGwMac.

private void addIPv6FlowToUpdateSrcMacToRouterGwMac(TypedReadWriteTransaction<Configuration> confTx, String extGwMacAddress, Uint32 extSubnetId, Uint64 dpnId, Uint32 routerId, Uint64 routerMetadata) {
    LOG.debug("addIPv6FlowToUpdateSrcMacToRouterGwMac : called for switch {}, routerId {}", dpnId, routerId);
    List<MatchInfoBase> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV6);
    matches.add(new MatchMetadata(routerMetadata, MetaDataUtil.METADATA_MASK_VRFID));
    ArrayList<ActionInfo> listActionInfo = new ArrayList<>();
    listActionInfo.add(new ActionSetFieldEthernetSource(new MacAddress(extGwMacAddress)));
    ActionNxLoadMetadata actionLoadMeta = new ActionNxLoadMetadata(MetaDataUtil.getVpnIdMetadata(extSubnetId.longValue()), LOAD_START, LOAD_END);
    listActionInfo.add(actionLoadMeta);
    ArrayList<InstructionInfo> instructionInfo = new ArrayList<>();
    listActionInfo.add(new ActionNxResubmit(NwConstants.NAPT_PFIB_TABLE));
    instructionInfo.add(new InstructionApplyActions(listActionInfo));
    String flowRef = NatUtil.getIpv6FlowRef(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId);
    flowRef += ".Outbound";
    NatUtil.addFlow(confTx, mdsalManager, dpnId, NwConstants.OUTBOUND_NAPT_TABLE, flowRef, NatConstants.SNAT_TRK_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches, instructionInfo);
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) ActionNxLoadMetadata(org.opendaylight.genius.mdsalutil.actions.ActionNxLoadMetadata) ActionSetFieldEthernetSource(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase)

Example 75 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.RouterId in project netvirt by opendaylight.

the class NatUtil method removeSnatEntriesForPort.

public static void removeSnatEntriesForPort(DataBroker dataBroker, NaptManager naptManager, IMdsalApiManager mdsalManager, NeutronvpnService neutronVpnService, String interfaceName, String routerName) {
    Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("removeSnatEntriesForPort: routerId not found for routername {}", routerName);
        return;
    }
    Uint64 naptSwitch = getPrimaryNaptfromRouterName(dataBroker, routerName);
    if (naptSwitch == null || naptSwitch.equals(Uint64.ZERO)) {
        LOG.error("removeSnatEntriesForPort: NaptSwitch is not elected for router {}" + "with Id {}", routerName, routerId);
        return;
    }
    // getInternalIp for port
    List<String> fixedIps = getFixedIpsForPort(neutronVpnService, interfaceName);
    if (fixedIps == null) {
        LOG.error("removeSnatEntriesForPort: Internal Ips not found for InterfaceName {} in router {} with id {}", interfaceName, routerName, routerId);
        return;
    }
    List<ProtocolTypes> protocolTypesList = getPortocolList();
    for (String internalIp : fixedIps) {
        LOG.debug("removeSnatEntriesForPort: Internal Ip retrieved for interface {} is {} in router with Id {}", interfaceName, internalIp, routerId);
        for (ProtocolTypes protocol : protocolTypesList) {
            List<Uint16> portList = NatUtil.getInternalIpPortListInfo(dataBroker, routerId, internalIp, protocol);
            if (portList != null) {
                for (Uint16 portnum : portList) {
                    // build and remove the flow in outbound table
                    removeNatFlow(mdsalManager, naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, routerId, internalIp, portnum.toJava(), protocol.getName());
                    // build and remove the flow in inboundtable
                    removeNatFlow(mdsalManager, naptSwitch, NwConstants.INBOUND_NAPT_TABLE, routerId, internalIp, portnum.toJava(), protocol.getName());
                    // Get the external IP address and the port from the model
                    NAPTEntryEvent.Protocol proto = protocol.toString().equals(ProtocolTypes.TCP.toString()) ? NAPTEntryEvent.Protocol.TCP : NAPTEntryEvent.Protocol.UDP;
                    IpPortExternal ipPortExternal = NatUtil.getExternalIpPortMap(dataBroker, routerId, internalIp, String.valueOf(portnum.toJava()), proto);
                    if (ipPortExternal == null) {
                        LOG.error("removeSnatEntriesForPort: Mapping for internalIp {} " + "with port {} is not found in " + "router with Id {}", internalIp, portnum, routerId);
                        return;
                    }
                    String externalIpAddress = ipPortExternal.getIpAddress();
                    String internalIpPort = internalIp + ":" + portnum.toJava();
                    // delete the entry from IntExtIpPortMap DS
                    naptManager.removeFromIpPortMapDS(routerId, internalIpPort, proto);
                    naptManager.removePortFromPool(internalIpPort, externalIpAddress);
                }
            } else {
                LOG.debug("removeSnatEntriesForPort: No {} session for interface {} with internalIP {} " + "in router with id {}", protocol, interfaceName, internalIp, routerId);
            }
        }
        // delete the entry from SnatIntIpPortMap DS
        LOG.debug("removeSnatEntriesForPort: Removing InternalIp :{} of router {} from snatint-ip-port-map", internalIp, routerId);
        naptManager.removeFromSnatIpPortDS(routerId, internalIp);
    }
}
Also used : ProtocolTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProtocolTypes) Uint16(org.opendaylight.yangtools.yang.common.Uint16) 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) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)152 ArrayList (java.util.ArrayList)78 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)76 ExecutionException (java.util.concurrent.ExecutionException)63 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)44 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)43 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)34 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)34 BigInteger (java.math.BigInteger)33 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)33 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)29 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)29 Logger (org.slf4j.Logger)27 LoggerFactory (org.slf4j.LoggerFactory)27 Inject (javax.inject.Inject)25 Singleton (javax.inject.Singleton)25 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)25 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)24 List (java.util.List)23 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)23