Search in sources :

Example 1 with MatchInfoBase

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

the class ElanNodeListener method addSmacLearnedTableFlow.

private void addSmacLearnedTableFlow(BigInteger dpId) {
    // T50 - match on Reg4 and goto T51
    List<MatchInfoBase> mkMatches = new ArrayList<>();
    mkMatches.add(new NxMatchRegister(NxmNxReg4.class, LEARN_MATCH_REG4_VALUE));
    List<InstructionInfo> mkInstructions = new ArrayList<>();
    mkInstructions.add(new InstructionGotoTable(NwConstants.ELAN_DMAC_TABLE));
    String flowRef = new StringBuffer().append(NwConstants.ELAN_SMAC_TABLE).append(NwConstants.FLOWID_SEPARATOR).append(LEARN_MATCH_REG4_VALUE).toString();
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_SMAC_TABLE, flowRef, 10, "ELAN sMac Table Reg4 Flow", 0, 0, ElanConstants.COOKIE_ELAN_KNOWN_SMAC.add(BigInteger.valueOf(LEARN_MATCH_REG4_VALUE)), mkMatches, mkInstructions);
    mdsalManager.installFlow(flowEntity);
}
Also used : NxmNxReg4(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ArrayList(java.util.ArrayList) NxMatchRegister(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchRegister) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 2 with MatchInfoBase

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

the class IngressCountersServiceImpl method syncCounterFlows.

@Override
public void syncCounterFlows(ElementCountersRequest ecr, int operation) {
    int lportTag = ecr.getLportTag();
    List<MatchInfoBase> flowMatches = CountersServiceUtils.getCounterFlowMatch(ecr, lportTag, ElementCountersDirection.INGRESS);
    List<ActionInfo> actionsInfos = new ArrayList<>();
    List<InstructionInfo> instructions = CountersServiceUtils.getDispatcherTableResubmitInstructions(actionsInfos, ElementCountersDirection.INGRESS);
    BigInteger dpn = ecr.getDpn();
    String flowName = createFlowName(ecr, lportTag, dpn);
    syncFlow(dpn, NwConstants.INGRESS_COUNTERS_TABLE, flowName, CountersServiceUtils.COUNTER_TABLE_COUNTER_FLOW_PRIORITY, CountersServiceUtils.COUNTER_FLOW_NAME, 0, 0, CountersServiceUtils.COOKIE_COUNTERS_BASE, flowMatches, instructions, operation);
}
Also used : InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase)

Example 3 with MatchInfoBase

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

the class AclServiceOFFlowBuilder method programUdpFlow.

/**
 *Converts UDP matches to flows.
 * @param acl the access control list
 * @return the map containing the flows and the respective flow id
 */
public static Map<String, List<MatchInfoBase>> programUdpFlow(AceIp acl) {
    Map<String, List<MatchInfoBase>> flowMatchesMap = new HashMap<>();
    SourcePortRange sourcePortRange = acl.getSourcePortRange();
    DestinationPortRange destinationPortRange = acl.getDestinationPortRange();
    if (sourcePortRange == null && destinationPortRange == null) {
        List<MatchInfoBase> flowMatches = new ArrayList<>();
        flowMatches.addAll(addSrcIpMatches(acl));
        flowMatches.addAll(addDstIpMatches(acl));
        flowMatches.add(new MatchIpProtocol(acl.getProtocol()));
        String flowId = "UDP_SOURCE_ALL_";
        flowMatchesMap.put(flowId, flowMatches);
        return flowMatchesMap;
    }
    if (sourcePortRange != null) {
        Map<Integer, Integer> portMaskMap = getLayer4MaskForRange(sourcePortRange.getLowerPort().getValue(), sourcePortRange.getUpperPort().getValue());
        for (Entry<Integer, Integer> entry : portMaskMap.entrySet()) {
            Integer port = entry.getKey();
            List<MatchInfoBase> flowMatches = new ArrayList<>();
            flowMatches.addAll(addSrcIpMatches(acl));
            flowMatches.addAll(addDstIpMatches(acl));
            Integer mask = entry.getValue();
            if (mask != AclConstants.ALL_LAYER4_PORT_MASK) {
                flowMatches.add(new NxMatchUdpSourcePort(port, mask));
            }
            flowMatches.add(new MatchIpProtocol(acl.getProtocol()));
            String flowId = "UDP_SOURCE_" + port + "_" + mask;
            flowMatchesMap.put(flowId, flowMatches);
        }
    }
    if (destinationPortRange != null) {
        Map<Integer, Integer> portMaskMap = getLayer4MaskForRange(destinationPortRange.getLowerPort().getValue(), destinationPortRange.getUpperPort().getValue());
        for (Entry<Integer, Integer> entry : portMaskMap.entrySet()) {
            Integer port = entry.getKey();
            List<MatchInfoBase> flowMatches = new ArrayList<>();
            flowMatches.addAll(addSrcIpMatches(acl));
            flowMatches.addAll(addDstIpMatches(acl));
            Integer mask = entry.getValue();
            if (mask != AclConstants.ALL_LAYER4_PORT_MASK) {
                flowMatches.add(new NxMatchUdpDestinationPort(port, mask));
            }
            flowMatches.add(new MatchIpProtocol(acl.getProtocol()));
            String flowId = "UDP_DESTINATION_" + port + "_" + mask;
            flowMatchesMap.put(flowId, flowMatches);
        }
    }
    return flowMatchesMap;
}
Also used : SourcePortRange(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160218.acl.transport.header.fields.SourcePortRange) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MatchIpProtocol(org.opendaylight.genius.mdsalutil.matches.MatchIpProtocol) NxMatchUdpDestinationPort(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchUdpDestinationPort) DestinationPortRange(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160218.acl.transport.header.fields.DestinationPortRange) ArrayList(java.util.ArrayList) List(java.util.List) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase) NxMatchUdpSourcePort(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchUdpSourcePort)

Example 4 with MatchInfoBase

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

the class AclServiceOFFlowBuilder method programIcmpFlow.

/**
 *Converts icmp matches to flows.
 * @param acl the access control list
 * @return the map containing the flows and the respective flow id
 */
public static Map<String, List<MatchInfoBase>> programIcmpFlow(AceIp acl) {
    List<MatchInfoBase> flowMatches = new ArrayList<>();
    flowMatches.addAll(addSrcIpMatches(acl));
    flowMatches.addAll(addDstIpMatches(acl));
    // For ICMP port range indicates type and code
    SourcePortRange sourcePortRange = acl.getSourcePortRange();
    String flowId = "ICMP_";
    if (sourcePortRange != null) {
        if (acl.getAceIpVersion() instanceof AceIpv4) {
            flowMatches.add(new MatchIcmpv4(sourcePortRange.getLowerPort().getValue().shortValue(), sourcePortRange.getUpperPort().getValue().shortValue()));
            flowId = flowId + "V4_SOURCE_" + sourcePortRange.getLowerPort().getValue() + sourcePortRange.getUpperPort().getValue();
        } else if (acl.getAceIpVersion() instanceof AceIpv6) {
            flowMatches.add(new MatchIcmpv6(sourcePortRange.getLowerPort().getValue().shortValue(), sourcePortRange.getUpperPort().getValue().shortValue()));
            flowId = flowId + "V6_SOURCE_" + sourcePortRange.getLowerPort().getValue() + "_" + sourcePortRange.getUpperPort().getValue() + "_";
        }
    }
    DestinationPortRange destinationPortRange = acl.getDestinationPortRange();
    if (destinationPortRange != null) {
        if (acl.getAceIpVersion() instanceof AceIpv4) {
            flowMatches.add(new MatchIcmpv4(destinationPortRange.getLowerPort().getValue().shortValue(), destinationPortRange.getUpperPort().getValue().shortValue()));
            flowId = flowId + "V4_DESTINATION_" + destinationPortRange.getLowerPort().getValue() + destinationPortRange.getUpperPort().getValue() + "_";
        } else if (acl.getAceIpVersion() instanceof AceIpv6) {
            flowMatches.add(new MatchIcmpv6(destinationPortRange.getLowerPort().getValue().shortValue(), destinationPortRange.getUpperPort().getValue().shortValue()));
            flowId = flowId + "V6_DESTINATION_" + destinationPortRange.getLowerPort().getValue() + destinationPortRange.getUpperPort().getValue() + "_";
        }
    }
    if (acl.getAceIpVersion() instanceof AceIpv6 && acl.getProtocol() == NwConstants.IP_PROT_ICMP) {
        // We are aligning our implementation similar to Neutron Firewall driver where a Security
        // Group rule with "Ethertype as IPv6 and Protocol as icmp" is treated as ICMPV6 SG Rule.
        flowMatches.add(new MatchIpProtocol(AclConstants.IP_PROT_ICMPV6));
    } else {
        flowMatches.add(new MatchIpProtocol(acl.getProtocol()));
    }
    Map<String, List<MatchInfoBase>> flowMatchesMap = new HashMap<>();
    flowMatchesMap.put(flowId, flowMatches);
    return flowMatchesMap;
}
Also used : SourcePortRange(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160218.acl.transport.header.fields.SourcePortRange) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MatchIpProtocol(org.opendaylight.genius.mdsalutil.matches.MatchIpProtocol) DestinationPortRange(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160218.acl.transport.header.fields.DestinationPortRange) MatchIcmpv4(org.opendaylight.genius.mdsalutil.matches.MatchIcmpv4) MatchIcmpv6(org.opendaylight.genius.mdsalutil.matches.MatchIcmpv6) ArrayList(java.util.ArrayList) List(java.util.List) AceIpv6(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv6) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase) AceIpv4(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv4)

Example 5 with MatchInfoBase

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

the class AclServiceOFFlowBuilder method addDstIpMatches.

/**
 * Adds destination ip matches to the flows.
 * @param acl the access control list
 * @return the list of flows.
 */
public static List<MatchInfoBase> addDstIpMatches(AceIp acl) {
    List<MatchInfoBase> flowMatches = new ArrayList<>();
    if (acl.getAceIpVersion() instanceof AceIpv4) {
        flowMatches.add(MatchEthernetType.IPV4);
        Ipv4Prefix dstNetwork = ((AceIpv4) acl.getAceIpVersion()).getDestinationIpv4Network();
        if (null != dstNetwork && !dstNetwork.getValue().equals(AclConstants.IPV4_ALL_NETWORK)) {
            flowMatches.add(new MatchIpv4Destination(dstNetwork));
        }
    } else if (acl.getAceIpVersion() instanceof AceIpv6) {
        flowMatches.add(MatchEthernetType.IPV6);
        Ipv6Prefix dstNetwork = ((AceIpv6) acl.getAceIpVersion()).getDestinationIpv6Network();
        if (null != dstNetwork && !dstNetwork.getValue().equals(AclConstants.IPV6_ALL_NETWORK)) {
            flowMatches.add(new MatchIpv6Destination(dstNetwork));
        }
    }
    return flowMatches;
}
Also used : MatchIpv6Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv6Destination) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) AceIpv6(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv6) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase) AceIpv4(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv4) Ipv6Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)

Aggregations

MatchInfoBase (org.opendaylight.genius.mdsalutil.MatchInfoBase)70 ArrayList (java.util.ArrayList)60 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)33 BigInteger (java.math.BigInteger)18 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)18 List (java.util.List)16 MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)15 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)13 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)11 Test (org.junit.Test)10 NxMatchCtState (org.opendaylight.genius.mdsalutil.nxmatches.NxMatchCtState)10 AceIpBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpBuilder)10 MatchIpv4Destination (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination)9 ActionNxConntrack (org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack)8 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)8 AllowedAddressPairs (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs)8 MatchIpv4Source (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source)7 AceIpv4Builder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv4Builder)7 HashMap (java.util.HashMap)6 NxCtAction (org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack.NxCtAction)6