Search in sources :

Example 36 with InstructionInfo

use of org.opendaylight.genius.mdsalutil.InstructionInfo 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 37 with InstructionInfo

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

the class ExternalNetworksChangeListenerTest method testSnatFlowEntity.

@Test
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void testSnatFlowEntity() {
    FlowEntity flowMock = mock(FlowEntity.class);
    final short snatTable = 40;
    final int defaultSnatFlowPriority = 0;
    final String flowidSeparator = ".";
    String routerName = "200";
    List<BucketInfo> bucketInfo = new ArrayList<>();
    List<ActionInfo> listActionInfoPrimary = new ArrayList<>();
    listActionInfoPrimary.add(new ActionOutput(new Uri("3")));
    BucketInfo bucketPrimary = new BucketInfo(listActionInfoPrimary);
    List<ActionInfo> listActionInfoSecondary = new ArrayList<>();
    listActionInfoSecondary.add(new ActionOutput(new Uri("4")));
    BucketInfo bucketSecondary = new BucketInfo(listActionInfoPrimary);
    bucketInfo.add(0, bucketPrimary);
    bucketInfo.add(1, bucketSecondary);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    List<InstructionInfo> instructions = new ArrayList<>();
    List<ActionInfo> actionsInfos = new ArrayList<>();
    long groupId = 300;
    actionsInfos.add(new ActionGroup(groupId));
    instructions.add(new InstructionApplyActions(actionsInfos));
    BigInteger dpnId = new BigInteger("100");
    long routerId = 200;
    String snatFlowidPrefix = "SNAT.";
    String flowRef = snatFlowidPrefix + dpnId + flowidSeparator + snatTable + flowidSeparator + routerId;
    BigInteger cookieSnat = NatUtil.getCookieSnatFlow(routerId);
    try {
        PowerMockito.when(MDSALUtil.class, "buildFlowEntity", dpnId, snatTable, flowRef, defaultSnatFlowPriority, flowRef, 0, 0, cookieSnat, matches, instructions).thenReturn(flowMock);
    } catch (Exception e) {
        // Test failed anyways
        assertEquals("true", "false");
    }
/* TODO : Fix this to mock it properly when it reads DS
        extNetworks.buildSnatFlowEntity(dpnId, routerName, groupId);
        PowerMockito.verifyStatic(); */
}
Also used : MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) BigInteger(java.math.BigInteger) BucketInfo(org.opendaylight.genius.mdsalutil.BucketInfo) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) ActionOutput(org.opendaylight.genius.mdsalutil.actions.ActionOutput) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 38 with InstructionInfo

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

the class Ipv6ServiceUtils method installIcmpv6RsPuntFlow.

public void installIcmpv6RsPuntFlow(short tableId, BigInteger dpId, Long elanTag, int addOrRemove) {
    if (dpId == null || dpId.equals(Ipv6Constants.INVALID_DPID)) {
        return;
    }
    List<MatchInfo> routerSolicitationMatch = getIcmpv6RSMatch(elanTag);
    List<InstructionInfo> instructions = new ArrayList<>();
    List<ActionInfo> actionsInfos = new ArrayList<>();
    // Punt to controller
    actionsInfos.add(new ActionPuntToController());
    instructions.add(new InstructionApplyActions(actionsInfos));
    FlowEntity rsFlowEntity = MDSALUtil.buildFlowEntity(dpId, tableId, getIPv6FlowRef(dpId, elanTag, "IPv6RS"), Ipv6Constants.DEFAULT_FLOW_PRIORITY, "IPv6RS", 0, 0, NwConstants.COOKIE_IPV6_TABLE, routerSolicitationMatch, instructions);
    if (addOrRemove == Ipv6Constants.DEL_FLOW) {
        LOG.trace("Removing IPv6 Router Solicitation Flow DpId {}, elanTag {}", dpId, elanTag);
        mdsalUtil.removeFlow(rsFlowEntity);
    } else {
        LOG.trace("Installing IPv6 Router Solicitation Flow DpId {}, elanTag {}", dpId, elanTag);
        mdsalUtil.installFlow(rsFlowEntity);
    }
}
Also used : MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ActionPuntToController(org.opendaylight.genius.mdsalutil.actions.ActionPuntToController) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 39 with InstructionInfo

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

the class AbstractAclServiceImpl method programForAceNotHavingRemoteAclId.

protected void programForAceNotHavingRemoteAclId(AclInterface port, String aclName, Ace ace, Map<String, List<MatchInfoBase>> flowMap, int addOrRemove) {
    if (null == flowMap) {
        return;
    }
    MatchInfoBase lportTagMatch = AclServiceUtils.buildLPortTagMatch(port.getLPortTag(), serviceMode);
    List<InstructionInfo> instructions = AclServiceOFFlowBuilder.getGotoInstructionInfo(getAclCommitterTable());
    Integer flowPriority = this.aclServiceUtils.getAceFlowPriority(aclName);
    for (Entry<String, List<MatchInfoBase>> entry : flowMap.entrySet()) {
        String flowName = entry.getKey();
        List<MatchInfoBase> matches = entry.getValue();
        matches.add(lportTagMatch);
        String flowId = flowName + this.directionString + "_" + port.getDpId() + "_" + port.getLPortTag() + "_" + ace.getKey().getRuleName();
        int operation = addOrRemove == NwConstants.MOD_FLOW ? NwConstants.DEL_FLOW : addOrRemove;
        syncFlow(port.getDpId(), getAclFilterCumDispatcherTable(), flowId, flowPriority, "ACL", 0, 0, AclConstants.COOKIE_ACL_BASE, matches, instructions, operation);
        if (addOrRemove != NwConstants.DEL_FLOW) {
            programAclForExistingTrafficTable(port, ace, addOrRemove, flowName, matches, flowPriority);
        }
    }
}
Also used : BigInteger(java.math.BigInteger) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) List(java.util.List) ArrayList(java.util.ArrayList) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase)

Example 40 with InstructionInfo

use of org.opendaylight.genius.mdsalutil.InstructionInfo 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)

Aggregations

InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)120 ArrayList (java.util.ArrayList)113 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)74 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)74 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)63 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)52 MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)41 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)34 BigInteger (java.math.BigInteger)33 MatchInfoBase (org.opendaylight.genius.mdsalutil.MatchInfoBase)33 ActionNxResubmit (org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit)27 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)17 InstructionWriteMetadata (org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata)16 ActionGroup (org.opendaylight.genius.mdsalutil.actions.ActionGroup)13 ActionNxConntrack (org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack)12 ActionPuntToController (org.opendaylight.genius.mdsalutil.actions.ActionPuntToController)11 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)10 NxCtAction (org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack.NxCtAction)10 MatchTunnelId (org.opendaylight.genius.mdsalutil.matches.MatchTunnelId)10 MatchIpv4Destination (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination)9