Search in sources :

Example 86 with FlowEntity

use of org.opendaylight.genius.mdsalutil.FlowEntity in project netvirt by opendaylight.

the class RouterDpnChangeListener method handleSNATForDPN.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
void handleSNATForDPN(BigInteger dpnId, String routerName, long routerId, Long routerVpnId, WriteTransaction writeFlowInvTx, WriteTransaction removeFlowInvTx, ProviderTypes extNwProvType) {
    // Check if primary and secondary switch are selected, If not select the role
    // Install select group to NAPT switch
    // Install default miss entry to NAPT switch
    BigInteger naptSwitch;
    try {
        BigInteger naptId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
        if (naptId == null || naptId.equals(BigInteger.ZERO) || !naptSwitchHA.getSwitchStatus(naptId)) {
            LOG.debug("handleSNATForDPN : No NaptSwitch is selected for router {}", routerName);
            naptSwitch = dpnId;
            boolean naptstatus = naptSwitchHA.updateNaptSwitch(routerName, naptSwitch);
            if (!naptstatus) {
                LOG.error("handleSNATForDPN : Failed to update newNaptSwitch {} for routername {}", naptSwitch, routerName);
                return;
            }
            LOG.debug("handleSNATForDPN : Switch {} is elected as NaptSwitch for router {}", dpnId, routerName);
            // When NAPT switch is elected during first VM comes up for the given Router
            if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
                NatOverVxlanUtil.validateAndCreateVxlanVniPool(dataBroker, nvpnManager, idManager, NatConstants.ODL_VNI_POOL_NAME);
            }
            Routers extRouters = NatUtil.getRoutersFromConfigDS(dataBroker, routerName);
            if (extRouters != null) {
                NatUtil.createRouterIdsConfigDS(dataBroker, routerId, routerName);
                naptSwitchHA.subnetRegisterMapping(extRouters, routerId);
            }
            naptSwitchHA.installSnatFlows(routerName, routerId, naptSwitch, routerVpnId, writeFlowInvTx);
            // Install miss entry (table 26) pointing to table 46
            FlowEntity flowEntity = naptSwitchHA.buildSnatFlowEntityForNaptSwitch(dpnId, routerName, routerVpnId, NatConstants.ADD_FLOW);
            if (flowEntity == null) {
                LOG.error("handleSNATForDPN : Failed to populate flowentity for router {} with dpnId {}", routerName, dpnId);
                return;
            }
            LOG.debug("handleSNATForDPN : Successfully installed flow for dpnId {} router {}", dpnId, routerName);
            mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
            // Removing primary flows from old napt switch
            if (naptId != null && !naptId.equals(BigInteger.ZERO)) {
                LOG.debug("handleSNATForDPN : Removing primary flows from old napt switch {} for router {}", naptId, routerName);
                naptSwitchHA.removeSnatFlowsInOldNaptSwitch(routerName, routerId, naptId, null, removeFlowInvTx);
            }
        } else if (naptId.equals(dpnId)) {
            LOG.debug("handleSNATForDPN : NaptSwitch {} gone down during cluster reboot came alive", naptId);
        } else {
            naptSwitch = naptId;
            LOG.debug("handleSNATForDPN : Napt switch with Id {} is already elected for router {}", naptId, routerName);
            // installing group
            List<BucketInfo> bucketInfo = naptSwitchHA.handleGroupInNeighborSwitches(dpnId, routerName, routerId, naptSwitch);
            naptSwitchHA.installSnatGroupEntry(dpnId, bucketInfo, routerName);
            // Install miss entry (table 26) pointing to group
            long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
            FlowEntity flowEntity = naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId, routerVpnId, NatConstants.ADD_FLOW);
            if (flowEntity == null) {
                LOG.error("handleSNATForDPN : Failed to populate flowentity for router {} with dpnId {} groupId {}", routerName, dpnId, groupId);
                return;
            }
            LOG.debug("handleSNATForDPN : Successfully installed flow for dpnId {} router {} group {}", dpnId, routerName, groupId);
            mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
        }
    } catch (Exception ex) {
        LOG.error("handleSNATForDPN : Exception in handleSNATForDPN", ex);
    }
}
Also used : Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) BigInteger(java.math.BigInteger) ArrayList(java.util.ArrayList) RouterDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnList) DpnVpninterfacesList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList) List(java.util.List) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 87 with FlowEntity

use of org.opendaylight.genius.mdsalutil.FlowEntity in project netvirt by opendaylight.

the class FloatingIPListener method buildPreDNATFlowEntity.

private FlowEntity buildPreDNATFlowEntity(BigInteger dpId, InternalToExternalPortMap mapping, long routerId, long associatedVpn) {
    String externalIp = mapping.getExternalIp();
    Uuid floatingIpId = mapping.getExternalId();
    // Get the FIP MAC address for DNAT
    String floatingIpPortMacAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(dataBroker, floatingIpId);
    if (floatingIpPortMacAddress == null) {
        LOG.error("buildPreDNATFlowEntity : Unable to retrieve floatingIpPortMacAddress from floating IP UUID {} " + "for floating IP {}", floatingIpId, externalIp);
        return null;
    }
    LOG.debug("buildPreDNATFlowEntity : Bulding DNAT Flow entity for ip {} ", externalIp);
    long segmentId = associatedVpn == NatConstants.INVALID_ID ? routerId : associatedVpn;
    LOG.debug("buildPreDNATFlowEntity : Segment id {} in build preDNAT Flow", segmentId);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    matches.add(new MatchIpv4Destination(externalIp, "32"));
    // Match Destination Floating IP MAC Address on table = 25 (PDNAT_TABLE)
    matches.add(new MatchEthernetDestination(new MacAddress(floatingIpPortMacAddress)));
    // matches.add(new MatchMetadata(
    // BigInteger.valueOf(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
    List<ActionInfo> actionsInfos = new ArrayList<>();
    String internalIp = mapping.getInternalIp();
    actionsInfos.add(new ActionSetDestinationIp(internalIp, "32"));
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionWriteMetadata(MetaDataUtil.getVpnIdMetadata(segmentId), MetaDataUtil.METADATA_MASK_VRFID));
    instructions.add(new InstructionApplyActions(actionsInfos));
    instructions.add(new InstructionGotoTable(NwConstants.DNAT_TABLE));
    String flowRef = NatUtil.getFlowRef(dpId, NwConstants.PDNAT_TABLE, routerId, externalIp);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.PDNAT_TABLE, flowRef, NatConstants.DEFAULT_DNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE, matches, instructions);
    return flowEntity;
}
Also used : InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) MatchEthernetDestination(org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ActionSetDestinationIp(org.opendaylight.genius.mdsalutil.actions.ActionSetDestinationIp) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Example 88 with FlowEntity

use of org.opendaylight.genius.mdsalutil.FlowEntity in project netvirt by opendaylight.

the class FloatingIPListener method removeSNATTblEntry.

private void removeSNATTblEntry(BigInteger dpnId, String internalIp, String externalIp, long routerId, long vpnId, WriteTransaction removeFlowInvTx) {
    FlowEntity preFlowEntity = buildPreSNATDeleteFlowEntity(dpnId, internalIp, routerId);
    mdsalManager.removeFlowToTx(preFlowEntity, removeFlowInvTx);
    FlowEntity flowEntity = buildSNATDeleteFlowEntity(dpnId, externalIp, vpnId);
    if (flowEntity != null) {
        mdsalManager.removeFlowToTx(flowEntity, removeFlowInvTx);
    }
}
Also used : FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 89 with FlowEntity

use of org.opendaylight.genius.mdsalutil.FlowEntity in project netvirt by opendaylight.

the class FloatingIPListener method buildPreDNATDeleteFlowEntity.

private FlowEntity buildPreDNATDeleteFlowEntity(BigInteger dpId, String externalIp, long routerId) {
    LOG.info("buildPreDNATDeleteFlowEntity : Bulding Delete DNAT Flow entity for ip {} ", externalIp);
    String flowRef = NatUtil.getFlowRef(dpId, NwConstants.PDNAT_TABLE, routerId, externalIp);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.PDNAT_TABLE, flowRef, NatConstants.DEFAULT_DNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE, null, null);
    return flowEntity;
}
Also used : FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 90 with FlowEntity

use of org.opendaylight.genius.mdsalutil.FlowEntity in project netvirt by opendaylight.

the class FloatingIPListener method buildSNATFlowEntity.

private FlowEntity buildSNATFlowEntity(BigInteger dpId, InternalToExternalPortMap mapping, long vpnId, Uuid externalNetworkId) {
    String internalIp = mapping.getInternalIp();
    LOG.debug("buildSNATFlowEntity : Building SNAT Flow entity for ip {} ", internalIp);
    ProviderTypes provType = NatUtil.getProviderTypefromNetworkId(dataBroker, externalNetworkId);
    if (provType == null) {
        LOG.error("buildSNATFlowEntity : Unable to get Network Provider Type for network {}", externalNetworkId);
        return null;
    }
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
    matches.add(MatchEthernetType.IPV4);
    String externalIp = mapping.getExternalIp();
    matches.add(new MatchIpv4Source(externalIp, "32"));
    List<ActionInfo> actionsInfo = new ArrayList<>();
    Uuid floatingIpId = mapping.getExternalId();
    String macAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(dataBroker, floatingIpId);
    if (macAddress != null) {
        actionsInfo.add(new ActionSetFieldEthernetSource(new MacAddress(macAddress)));
    } else {
        LOG.warn("buildSNATFlowEntity : No MAC address found for floating IP {}", externalIp);
    }
    LOG.trace("buildSNATFlowEntity : External Network Provider Type is {}, resubmit to FIB", provType.toString());
    actionsInfo.add(new ActionNxResubmit(NwConstants.L3_FIB_TABLE));
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionApplyActions(actionsInfo));
    String flowRef = NatUtil.getFlowRef(dpId, NwConstants.SNAT_TABLE, vpnId, externalIp);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.SNAT_TABLE, flowRef, NatConstants.DEFAULT_DNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE, matches, instructions);
    return flowEntity;
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) 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) MatchIpv4Source(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ActionSetFieldEthernetSource(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Aggregations

FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)119 ArrayList (java.util.ArrayList)56 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)52 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)50 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)37 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)37 BigInteger (java.math.BigInteger)23 MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)22 ActionNxResubmit (org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit)17 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)14 ActionPuntToController (org.opendaylight.genius.mdsalutil.actions.ActionPuntToController)12 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)9 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)9 MatchTunnelId (org.opendaylight.genius.mdsalutil.matches.MatchTunnelId)7 Test (org.junit.Test)6 ActionGroup (org.opendaylight.genius.mdsalutil.actions.ActionGroup)6 InstructionWriteMetadata (org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata)6 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)6 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)6 BucketInfo (org.opendaylight.genius.mdsalutil.BucketInfo)5