Search in sources :

Example 6 with ActionSetFieldTunnelId

use of org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId in project netvirt by opendaylight.

the class EvpnVrfEntryHandler method createRemoteFibEntry.

private void createRemoteFibEntry(final BigInteger remoteDpnId, final long vpnId, final VrfTablesKey vrfTableKey, final VrfEntry vrfEntry, boolean isNatPrefix, WriteTransaction tx) {
    String rd = vrfTableKey.getRouteDistinguisher();
    List<SubTransaction> subTxns = new ArrayList<>();
    LOG.debug("createremotefibentry: adding route {} for rd {} with transaction {}", vrfEntry.getDestPrefix(), rd, tx);
    List<NexthopManager.AdjacencyResult> tunnelInterfaceList = resolveAdjacency(remoteDpnId, vpnId, vrfEntry, rd);
    if (tunnelInterfaceList.isEmpty()) {
        LOG.error("Could not get interface for route-paths: {} in vpn {}", vrfEntry.getRoutePaths(), rd);
        LOG.warn("Failed to add Route: {} in vpn: {}", vrfEntry.getDestPrefix(), rd);
        return;
    }
    for (NexthopManager.AdjacencyResult adjacencyResult : tunnelInterfaceList) {
        List<ActionInfo> actionInfos = new ArrayList<>();
        BigInteger tunnelId;
        String prefix = adjacencyResult.getPrefix();
        Prefixes prefixInfo = getFibUtil().getPrefixToInterface(vpnId, prefix);
        String interfaceName = prefixInfo.getVpnInterfaceName();
        if (vrfEntry.getOrigin().equals(RouteOrigin.BGP.getValue()) || isNatPrefix) {
            tunnelId = BigInteger.valueOf(vrfEntry.getL3vni());
        } else if (elanManager.isOpenStackVniSemanticsEnforced()) {
            tunnelId = BigInteger.valueOf(getFibUtil().getVniForVxlanNetwork(prefixInfo.getSubnetId()).get());
        } else {
            Interface interfaceState = getFibUtil().getInterfaceStateFromOperDS(interfaceName);
            tunnelId = BigInteger.valueOf(interfaceState.getIfIndex());
        }
        LOG.debug("adding set tunnel id action for label {}", tunnelId);
        String macAddress = null;
        String vpnName = getFibUtil().getVpnNameFromId(vpnId);
        if (vpnName == null) {
            LOG.debug("Failed to get VPN name for vpnId {}", vpnId);
            return;
        }
        if (interfaceName != null) {
            macAddress = getFibUtil().getMacAddressFromPrefix(interfaceName, vpnName, prefix);
            actionInfos.add(new ActionSetFieldEthernetDestination(new MacAddress(macAddress)));
        }
        actionInfos.add(new ActionSetFieldTunnelId(tunnelId));
        List<ActionInfo> egressActions = nexthopManager.getEgressActionsForInterface(adjacencyResult.getInterfaceName(), actionInfos.size());
        if (egressActions.isEmpty()) {
            LOG.error("Failed to retrieve egress action for prefix {} route-paths {} interface {}." + " Aborting remote FIB entry creation..", vrfEntry.getDestPrefix(), vrfEntry.getRoutePaths(), adjacencyResult.getInterfaceName());
            return;
        }
        actionInfos.addAll(egressActions);
        List<InstructionInfo> instructions = new ArrayList<>();
        instructions.add(new InstructionApplyActions(actionInfos));
        makeConnectedRoute(remoteDpnId, vpnId, vrfEntry, rd, instructions, NwConstants.ADD_FLOW, tx, subTxns);
    }
    LOG.debug("Successfully added FIB entry for prefix {} in rd {}", vrfEntry.getDestPrefix(), rd);
}
Also used : SubTransaction(org.opendaylight.genius.utils.batching.SubTransaction) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) ActionSetFieldTunnelId(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId) ActionSetFieldEthernetDestination(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetDestination) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) BigInteger(java.math.BigInteger) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface)

Example 7 with ActionSetFieldTunnelId

use of org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId in project genius by opendaylight.

the class IfmUtil method getEgressActionInfosForInterface.

/**
 * Returns the list of egress actions for a given interface.
 *
 * @param interfaceInfo the interface to look up
 * @param portNo port number
 * @param ifaceType the type of the interface
 * @param tunnelKey the tunnel key
 * @param actionKeyStart the start for the first key assigned for the new actions
 * @param isDefaultEgress if it is the default egress
 * @param ifIndex interface index
 * @param groupId group Id
 * @return list of actions for the interface
 */
// The following suppression is for javac, not for checkstyle
@SuppressWarnings("fallthrough")
@SuppressFBWarnings("SF_SWITCH_FALLTHROUGH")
public static List<ActionInfo> getEgressActionInfosForInterface(Interface interfaceInfo, String portNo, InterfaceInfo.InterfaceType ifaceType, Long tunnelKey, int actionKeyStart, boolean isDefaultEgress, int ifIndex, long groupId) {
    List<ActionInfo> result = new ArrayList<>();
    switch(ifaceType) {
        case MPLS_OVER_GRE:
        // fall through
        case GRE_TRUNK_INTERFACE:
            if (!isDefaultEgress) {
                // stores the value coming from a VXLAN tunnel
                if (tunnelKey == null) {
                    tunnelKey = 0L;
                }
            }
        // fall through
        case VXLAN_TRUNK_INTERFACE:
            if (!isDefaultEgress) {
                if (tunnelKey != null) {
                    result.add(new ActionSetFieldTunnelId(actionKeyStart++, BigInteger.valueOf(tunnelKey)));
                }
            } else {
                // For OF Tunnels default egress actions need to set tunnelIps
                IfTunnel ifTunnel = interfaceInfo.getAugmentation(IfTunnel.class);
                if (BooleanUtils.isTrue(ifTunnel.isTunnelRemoteIpFlow() && ifTunnel.getTunnelDestination() != null)) {
                    result.add(new ActionSetTunnelDestinationIp(actionKeyStart++, ifTunnel.getTunnelDestination()));
                }
                if (BooleanUtils.isTrue(ifTunnel.isTunnelSourceIpFlow() && ifTunnel.getTunnelSource() != null)) {
                    result.add(new ActionSetTunnelSourceIp(actionKeyStart++, ifTunnel.getTunnelSource()));
                }
            }
        // fall through
        case VLAN_INTERFACE:
            if (isDefaultEgress) {
                IfL2vlan vlanIface = interfaceInfo.getAugmentation(IfL2vlan.class);
                LOG.trace("get egress actions for l2vlan interface: {}", vlanIface);
                boolean isVlanTransparent = false;
                int vlanVid = 0;
                if (vlanIface != null) {
                    vlanVid = vlanIface.getVlanId() == null ? 0 : vlanIface.getVlanId().getValue();
                    isVlanTransparent = vlanIface.getL2vlanMode() == IfL2vlan.L2vlanMode.Transparent;
                }
                if (vlanVid != 0 && !isVlanTransparent) {
                    result.add(new ActionPushVlan(actionKeyStart++));
                    result.add(new ActionSetFieldVlanVid(actionKeyStart++, vlanVid));
                }
                result.add(new ActionOutput(actionKeyStart++, new Uri(portNo)));
            } else {
                addEgressActionInfosForInterface(ifIndex, actionKeyStart, result);
            }
            break;
        case LOGICAL_GROUP_INTERFACE:
            if (isDefaultEgress) {
                result.add(new ActionGroup(groupId));
            } else {
                addEgressActionInfosForInterface(ifIndex, actionKeyStart, result);
            }
            break;
        default:
            LOG.warn("Interface Type {} not handled yet", ifaceType);
            break;
    }
    return result;
}
Also used : ActionSetTunnelDestinationIp(org.opendaylight.genius.mdsalutil.actions.ActionSetTunnelDestinationIp) ArrayList(java.util.ArrayList) IfTunnel(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel) ActionSetFieldVlanVid(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldVlanVid) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionSetFieldTunnelId(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId) ActionPushVlan(org.opendaylight.genius.mdsalutil.actions.ActionPushVlan) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) ActionSetTunnelSourceIp(org.opendaylight.genius.mdsalutil.actions.ActionSetTunnelSourceIp) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) ActionOutput(org.opendaylight.genius.mdsalutil.actions.ActionOutput) IfL2vlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 8 with ActionSetFieldTunnelId

use of org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId in project genius by opendaylight.

the class ActionInfoBuilderTest method set_field_tunnel_idActionWithBigActionValuesWithActionKey.

@Test
public void set_field_tunnel_idActionWithBigActionValuesWithActionKey() {
    ActionInfo actionInfo = new ActionSetFieldTunnelId(69, BigInteger.valueOf(123));
    assertEquals("new ActionSetFieldTunnelId(69, 123bi)", generator.getExpression(actionInfo));
}
Also used : ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionSetFieldTunnelId(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId) Test(org.junit.Test)

Example 9 with ActionSetFieldTunnelId

use of org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId in project netvirt by opendaylight.

the class ExternalRoutersListener method buildSnatFlowEntityWithUpdatedVpnId.

public FlowEntity buildSnatFlowEntityWithUpdatedVpnId(BigInteger dpId, String routerName, long groupId, long changedVpnId) {
    LOG.debug("buildSnatFlowEntityWithUpdatedVpnId : called for dpId {}, routerName {} groupId {} " + "changed VPN ID {}", dpId, routerName, groupId, changedVpnId);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(changedVpnId), MetaDataUtil.METADATA_MASK_VRFID));
    List<ActionInfo> actionsInfo = new ArrayList<>();
    long tunnelId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, elanManager, idManager, changedVpnId, routerName);
    actionsInfo.add(new ActionSetFieldTunnelId(BigInteger.valueOf(tunnelId)));
    LOG.debug("buildSnatFlowEntityWithUpdatedVpnId : Setting the tunnel to the list of action infos {}", actionsInfo);
    actionsInfo.add(new ActionGroup(groupId));
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionApplyActions(actionsInfo));
    String flowRef = getFlowRefSnat(dpId, NwConstants.PSNAT_TABLE, routerName);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.PSNAT_TABLE, flowRef, NatConstants.DEFAULT_PSNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_SNAT_TABLE, matches, instructions);
    LOG.debug("buildSnatFlowEntityWithUpdatedVpnId : Returning SNAT Flow Entity {}", flowEntity);
    return flowEntity;
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionSetFieldTunnelId(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Example 10 with ActionSetFieldTunnelId

use of org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId in project netvirt by opendaylight.

the class ExternalRoutersListener method buildSnatFlowEntity.

private FlowEntity buildSnatFlowEntity(BigInteger dpId, String routerName, long routerId, long groupId) {
    LOG.debug("buildSnatFlowEntity : called for dpId {}, routerName {} and groupId {}", dpId, routerName, groupId);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(routerId), MetaDataUtil.METADATA_MASK_VRFID));
    List<ActionInfo> actionsInfo = new ArrayList<>();
    long tunnelId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, elanManager, idManager, routerId, routerName);
    actionsInfo.add(new ActionSetFieldTunnelId(BigInteger.valueOf(tunnelId)));
    LOG.debug("buildSnatFlowEntity : Setting the tunnel to the list of action infos {}", actionsInfo);
    actionsInfo.add(new ActionGroup(groupId));
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionApplyActions(actionsInfo));
    String flowRef = getFlowRefSnat(dpId, NwConstants.PSNAT_TABLE, routerName);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.PSNAT_TABLE, flowRef, NatConstants.DEFAULT_PSNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_SNAT_TABLE, matches, instructions);
    LOG.debug("buildSnatFlowEntity : Returning SNAT Flow Entity {}", flowEntity);
    return flowEntity;
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionSetFieldTunnelId(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Aggregations

ActionSetFieldTunnelId (org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId)15 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)12 ArrayList (java.util.ArrayList)10 ActionGroup (org.opendaylight.genius.mdsalutil.actions.ActionGroup)7 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)6 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)6 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)5 ActionOutput (org.opendaylight.genius.mdsalutil.actions.ActionOutput)5 MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)5 BigInteger (java.math.BigInteger)4 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)4 BucketInfo (org.opendaylight.genius.mdsalutil.BucketInfo)3 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)3 GroupEntity (org.opendaylight.genius.mdsalutil.GroupEntity)3 Test (org.junit.Test)2 ActionPushMpls (org.opendaylight.genius.mdsalutil.actions.ActionPushMpls)2 ActionPushVlan (org.opendaylight.genius.mdsalutil.actions.ActionPushVlan)2 MatchEthernetType (org.opendaylight.genius.mdsalutil.matches.MatchEthernetType)2 TunnelTypeVxlan (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan)2 Prefixes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes)2