Search in sources :

Example 1 with NxMatchTcpSourcePort

use of org.opendaylight.genius.mdsalutil.nxmatches.NxMatchTcpSourcePort in project netvirt by opendaylight.

the class AclServiceOFFlowBuilder method programTcpFlow.

/**
 *Converts TCP 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>> programTcpFlow(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 = "TCP_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 NxMatchTcpSourcePort(port, mask));
            }
            flowMatches.add(new MatchIpProtocol(acl.getProtocol()));
            String flowId = "TCP_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 NxMatchTcpDestinationPort(port, mask));
            }
            flowMatches.add(new MatchIpProtocol(acl.getProtocol()));
            String flowId = "TCP_DESTINATION_" + port + "_" + mask;
            flowMatchesMap.put(flowId, flowMatches);
        }
    }
    return flowMatchesMap;
}
Also used : NxMatchTcpDestinationPort(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchTcpDestinationPort) 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) NxMatchTcpSourcePort(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchTcpSourcePort) 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) ArrayList(java.util.ArrayList) List(java.util.List) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase)

Example 2 with NxMatchTcpSourcePort

use of org.opendaylight.genius.mdsalutil.nxmatches.NxMatchTcpSourcePort in project netvirt by opendaylight.

the class AclServiceOFFlowBuilderTest method testprogramTcpFlow_WithSrcDstPortRange.

@Test
public void testprogramTcpFlow_WithSrcDstPortRange() {
    AceIpBuilder builder = AclServiceTestUtils.prepareAceIpBuilder("10.1.1.1/24", "20.1.1.1/24", "1024", "1024", (short) 1);
    Map<String, List<MatchInfoBase>> flowMatchesMap = AclServiceOFFlowBuilder.programTcpFlow(builder.build());
    List<MatchInfoBase> srcFlowMatches = new ArrayList<>();
    List<MatchInfoBase> dstFlowMatches = new ArrayList<>();
    for (String flowId : flowMatchesMap.keySet()) {
        if (flowId.startsWith("TCP_SOURCE_")) {
            srcFlowMatches.addAll(flowMatchesMap.get(flowId));
        }
        if (flowId.startsWith("TCP_DESTINATION_")) {
            dstFlowMatches.addAll(flowMatchesMap.get(flowId));
        }
    }
    AclServiceTestUtils.verifyGeneralFlows(srcFlowMatches, "1", "10.1.1.1", "20.1.1.1", "24");
    List<MatchInfoBase> tcpSrcMatches = srcFlowMatches.stream().filter(item -> item instanceof NxMatchTcpSourcePort).collect(Collectors.toList());
    assertEquals(new NxMatchTcpSourcePort(1024, 65535), tcpSrcMatches.get(0));
    AclServiceTestUtils.verifyGeneralFlows(dstFlowMatches, "1", "10.1.1.1", "20.1.1.1", "24");
    List<MatchInfoBase> tcpDstMatches = dstFlowMatches.stream().filter(item -> item instanceof NxMatchTcpDestinationPort).collect(Collectors.toList());
    assertEquals(new NxMatchTcpDestinationPort(1024, 65535), tcpDstMatches.get(0));
}
Also used : MatchIpv4Source(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source) NxMatchUdpSourcePort(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchUdpSourcePort) NxMatchTcpSourcePort(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchTcpSourcePort) NxMatchUdpDestinationPort(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchUdpDestinationPort) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase) Collectors(java.util.stream.Collectors) NxMatchTcpDestinationPort(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchTcpDestinationPort) ArrayList(java.util.ArrayList) MatchIcmpv4(org.opendaylight.genius.mdsalutil.matches.MatchIcmpv4) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Map(java.util.Map) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) 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) Assert.assertEquals(org.junit.Assert.assertEquals) 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) NxMatchTcpDestinationPort(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchTcpDestinationPort) NxMatchTcpSourcePort(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchTcpSourcePort) 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) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 MatchInfoBase (org.opendaylight.genius.mdsalutil.MatchInfoBase)2 NxMatchTcpDestinationPort (org.opendaylight.genius.mdsalutil.nxmatches.NxMatchTcpDestinationPort)2 NxMatchTcpSourcePort (org.opendaylight.genius.mdsalutil.nxmatches.NxMatchTcpSourcePort)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNull (org.junit.Assert.assertNull)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Test (org.junit.Test)1 MatchEthernetType (org.opendaylight.genius.mdsalutil.matches.MatchEthernetType)1 MatchIcmpv4 (org.opendaylight.genius.mdsalutil.matches.MatchIcmpv4)1 MatchIpProtocol (org.opendaylight.genius.mdsalutil.matches.MatchIpProtocol)1 MatchIpv4Destination (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination)1 MatchIpv4Source (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source)1 NxMatchUdpDestinationPort (org.opendaylight.genius.mdsalutil.nxmatches.NxMatchUdpDestinationPort)1 NxMatchUdpSourcePort (org.opendaylight.genius.mdsalutil.nxmatches.NxMatchUdpSourcePort)1 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)1