Search in sources :

Example 6 with ActionNxConntrack

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

the class ConntrackBasedSnatService method createOutboundTblEntry.

protected void createOutboundTblEntry(BigInteger dpnId, long routerId, String externalIp, int elanId, String extGwMacAddress, int addOrRemove) {
    LOG.info("createOutboundTblEntry : dpId {} and routerId {}", dpnId, routerId);
    List<MatchInfoBase> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    matches.add(new NxMatchCtState(TRACKED_NEW_CT_STATE, TRACKED_NEW_CT_MASK));
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(routerId), MetaDataUtil.METADATA_MASK_VRFID));
    List<ActionInfo> actionsInfos = new ArrayList<>();
    if (addOrRemove == NwConstants.ADD_FLOW) {
        actionsInfos.add(new ActionSetFieldEthernetSource(new MacAddress(extGwMacAddress)));
    }
    List<NxCtAction> ctActionsListCommit = new ArrayList<>();
    int rangePresent = NxActionNatRangePresent.NXNATRANGEIPV4MIN.getIntValue();
    int flags = NxActionNatFlags.NXNATFSRC.getIntValue();
    NxCtAction nxCtActionCommit = new ActionNxConntrack.NxNat(0, flags, rangePresent, new IpPrefixOrAddress(externalIp.toCharArray()).getIpAddress(), null, 0, 0);
    ctActionsListCommit.add(nxCtActionCommit);
    int ctCommitFlag = 1;
    ActionNxConntrack actionNxConntrackSubmit = new ActionNxConntrack(ctCommitFlag, 0, elanId, NwConstants.NAPT_PFIB_TABLE, ctActionsListCommit);
    actionsInfos.add(actionNxConntrackSubmit);
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionApplyActions(actionsInfos));
    String flowRef = getFlowRef(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId);
    syncFlow(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, flowRef, NatConstants.SNAT_NEW_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches, instructions, addOrRemove);
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) IpPrefixOrAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.types.rev160517.IpPrefixOrAddress) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionNxConntrack(org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) NxMatchCtState(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchCtState) ActionSetFieldEthernetSource(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) NxCtAction(org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack.NxCtAction) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase)

Example 7 with ActionNxConntrack

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

the class AbstractAclServiceImpl method programAclCommitRuleForConntrack.

/**
 * Program acl commit rule for conntrack.
 *
 * @param dpId the dp id
 * @param lportTag the lport tag
 * @param portId the port id
 * @param matchEtherType the match ether type
 * @param addOrRemove the add or remove
 */
protected void programAclCommitRuleForConntrack(BigInteger dpId, int lportTag, String portId, MatchEthernetType matchEtherType, int addOrRemove) {
    List<MatchInfoBase> matches = new ArrayList<>();
    matches.add(matchEtherType);
    matches.addAll(AclServiceUtils.buildMatchesForLPortTagAndConntrackClassifierType(lportTag, AclConntrackClassifierType.CONNTRACK_SUPPORTED, serviceMode));
    List<ActionInfo> actionsInfos = new ArrayList<>();
    if (addOrRemove == NwConstants.ADD_FLOW) {
        Long elanId = getElanIdFromAclInterface(portId);
        if (elanId == null) {
            LOG.error("ElanId not found for portId={}; Context: dpId={}, lportTag={}, addOrRemove={}", portId, dpId, lportTag, addOrRemove);
            return;
        }
        List<NxCtAction> ctActionsList = Lists.newArrayList(new ActionNxConntrack.NxCtMark(AclConstants.CT_MARK_EST_STATE));
        actionsInfos.add(new ActionNxConntrack(2, 1, 0, elanId.intValue(), (short) 255, ctActionsList));
    }
    List<InstructionInfo> instructions = getDispatcherTableResubmitInstructions(actionsInfos);
    String flowName = directionString + "_Acl_Commit_Conntrack_" + dpId + "_" + lportTag + "_" + matchEtherType;
    // Flow for conntrack traffic to commit and resubmit to dispatcher
    syncFlow(dpId, getAclCommitterTable(), flowName, AclConstants.ACL_DEFAULT_PRIORITY, "ACL", 0, 0, AclConstants.COOKIE_ACL_BASE, matches, instructions, addOrRemove);
}
Also used : ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionNxConntrack(org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) NxCtAction(org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack.NxCtAction) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase)

Example 8 with ActionNxConntrack

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

the class ActionInfoImmutableTest method actionInfoActionKeyDoesNotMagicallyChangeOnFlowEntityGetFlowBuilder.

@Test
public void actionInfoActionKeyDoesNotMagicallyChangeOnFlowEntityGetFlowBuilder() {
    FlowEntityBuilder flowEntityBuilder = new FlowEntityBuilder().setDpnId(BigInteger.valueOf(123L)).setTableId((short) 1).setPriority(2).setFlowName("TEST-NAME").setFlowId("TEST-ID").setCookie(BigInteger.valueOf(110100480L));
    ActionInfo actionInfo = new ActionNxConntrack(27, 1, 0, 0, (short) 255);
    List<ActionInfo> actionInfos = new ArrayList<>();
    actionInfos.add(actionInfo);
    flowEntityBuilder.addInstructionInfoList(new InstructionApplyActions(actionInfos));
    FlowEntity flowEntity = flowEntityBuilder.build();
    assertEquals(27, ((InstructionApplyActions) flowEntity.getInstructionInfoList().get(0)).getActionInfos().get(0).getActionKey());
    flowEntity.getFlowBuilder();
    assertEquals(27, ((InstructionApplyActions) flowEntity.getInstructionInfoList().get(0)).getActionInfos().get(0).getActionKey());
    flowEntity.getFlowBuilder();
    assertEquals(27, ((InstructionApplyActions) flowEntity.getInstructionInfoList().get(0)).getActionInfos().get(0).getActionKey());
}
Also used : FlowEntityBuilder(org.opendaylight.genius.mdsalutil.FlowEntityBuilder) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionNxConntrack(org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) Test(org.junit.Test)

Example 9 with ActionNxConntrack

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

the class ConntrackBasedSnatService method installTerminatingServiceTblEntry.

protected void installTerminatingServiceTblEntry(BigInteger dpnId, Long routerId, int elanId, int addOrRemove) {
    LOG.info("installTerminatingServiceTblEntry : creating entry for Terminating Service Table " + "for switch {}, routerId {}", dpnId, routerId);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    matches.add(new MatchTunnelId(BigInteger.valueOf(routerId)));
    List<ActionInfo> actionsInfos = new ArrayList<>();
    List<NxCtAction> ctActionsList = new ArrayList<>();
    NxCtAction nxCtAction = new ActionNxConntrack.NxNat(0, 0, 0, null, null, 0, 0);
    ctActionsList.add(nxCtAction);
    ActionNxConntrack actionNxConntrack = new ActionNxConntrack(0, 0, elanId, NwConstants.OUTBOUND_NAPT_TABLE, ctActionsList);
    ActionNxLoadMetadata actionLoadMeta = new ActionNxLoadMetadata(MetaDataUtil.getVpnIdMetadata(routerId.longValue()), LOAD_START, LOAD_END);
    actionsInfos.add(actionLoadMeta);
    actionsInfos.add(actionNxConntrack);
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionApplyActions(actionsInfos));
    String flowRef = getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, routerId.longValue());
    syncFlow(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, flowRef, NatConstants.DEFAULT_TS_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches, instructions, addOrRemove);
}
Also used : ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionNxConntrack(org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack) ActionNxLoadMetadata(org.opendaylight.genius.mdsalutil.actions.ActionNxLoadMetadata) MatchTunnelId(org.opendaylight.genius.mdsalutil.matches.MatchTunnelId) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) NxCtAction(org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack.NxCtAction) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Example 10 with ActionNxConntrack

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

the class ConntrackBasedSnatService method installInboundEntry.

protected void installInboundEntry(BigInteger dpnId, long routerId, String externalIp, int elanId, long extSubnetId, int addOrRemove) {
    LOG.info("installInboundEntry : dpId {} and routerId {}", dpnId, routerId);
    List<MatchInfoBase> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    matches.add(new MatchIpv4Destination(externalIp, "32"));
    if (addOrRemove == NwConstants.ADD_FLOW) {
        if (extSubnetId == NatConstants.INVALID_ID) {
            LOG.error("installInboundEntry : external subnet id is invalid.");
            return;
        }
        matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(extSubnetId), MetaDataUtil.METADATA_MASK_VRFID));
    }
    List<ActionInfo> actionsInfos = new ArrayList<>();
    List<NxCtAction> ctActionsList = new ArrayList<>();
    NxCtAction nxCtAction = new ActionNxConntrack.NxNat(0, 0, 0, null, null, 0, 0);
    ActionNxLoadMetadata actionLoadMeta = new ActionNxLoadMetadata(MetaDataUtil.getVpnIdMetadata(routerId), LOAD_START, LOAD_END);
    actionsInfos.add(actionLoadMeta);
    ctActionsList.add(nxCtAction);
    ActionNxConntrack actionNxConntrack = new ActionNxConntrack(0, 0, elanId, NwConstants.NAPT_PFIB_TABLE, ctActionsList);
    actionsInfos.add(actionNxConntrack);
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionApplyActions(actionsInfos));
    String flowRef = getFlowRef(dpnId, NwConstants.INBOUND_NAPT_TABLE, routerId);
    flowRef = flowRef + "OUTBOUND";
    syncFlow(dpnId, NwConstants.INBOUND_NAPT_TABLE, flowRef, NatConstants.DEFAULT_TS_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches, instructions, addOrRemove);
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionNxConntrack(org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack) ActionNxLoadMetadata(org.opendaylight.genius.mdsalutil.actions.ActionNxLoadMetadata) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) NxCtAction(org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack.NxCtAction) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase)

Aggregations

ArrayList (java.util.ArrayList)12 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)12 ActionNxConntrack (org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack)12 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)11 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)11 NxCtAction (org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack.NxCtAction)9 MatchInfoBase (org.opendaylight.genius.mdsalutil.MatchInfoBase)7 MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)5 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)3 ActionSetFieldMeta (org.opendaylight.genius.mdsalutil.actions.ActionSetFieldMeta)3 NxMatchCtState (org.opendaylight.genius.mdsalutil.nxmatches.NxMatchCtState)3 ActionNxLoadMetadata (org.opendaylight.genius.mdsalutil.actions.ActionNxLoadMetadata)2 MatchIpv4Destination (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination)2 MatchTunnelId (org.opendaylight.genius.mdsalutil.matches.MatchTunnelId)2 IpPrefixOrAddress (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.types.rev160517.IpPrefixOrAddress)2 BigInteger (java.math.BigInteger)1 Test (org.junit.Test)1 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)1 FlowEntityBuilder (org.opendaylight.genius.mdsalutil.FlowEntityBuilder)1 ActionSetFieldEthernetSource (org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource)1