Search in sources :

Example 6 with FlowId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId 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 7 with FlowId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId 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 8 with FlowId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId in project netvirt by opendaylight.

the class AclServiceUtils method getFlowForAllowedAddresses.

public static Map<String, List<MatchInfoBase>> getFlowForAllowedAddresses(List<AllowedAddressPairs> syncAllowedAddresses, Map<String, List<MatchInfoBase>> flowMatchesMap, boolean isSourceIpMacMatch) {
    if (flowMatchesMap == null) {
        return null;
    }
    Map<String, List<MatchInfoBase>> updatedFlowMatchesMap = new HashMap<>();
    MatchInfoBase ipv4Match = MatchEthernetType.IPV4;
    MatchInfoBase ipv6Match = MatchEthernetType.IPV6;
    for (Entry<String, List<MatchInfoBase>> entry : flowMatchesMap.entrySet()) {
        String flowName = entry.getKey();
        List<MatchInfoBase> flows = entry.getValue();
        // iterate over allow address pair and update match type
        for (AllowedAddressPairs aap : syncAllowedAddresses) {
            List<MatchInfoBase> matchInfoBaseList;
            String flowId;
            if (flows.contains(ipv4Match) && isIPv4Address(aap) && isNotIpv4AllNetwork(aap)) {
                matchInfoBaseList = updateAAPMatches(isSourceIpMacMatch, flows, aap);
                flowId = flowName + "_ipv4_remoteACL_interface_aap_" + getAapFlowId(aap);
                updatedFlowMatchesMap.put(flowId, matchInfoBaseList);
            } else if (flows.contains(ipv6Match) && !isIPv4Address(aap) && isNotIpv6AllNetwork(aap)) {
                matchInfoBaseList = updateAAPMatches(isSourceIpMacMatch, flows, aap);
                flowId = flowName + "_ipv6_remoteACL_interface_aap_" + getAapFlowId(aap);
                updatedFlowMatchesMap.put(flowId, matchInfoBaseList);
            }
        }
    }
    return updatedFlowMatchesMap;
}
Also used : HashMap(java.util.HashMap) AllowedAddressPairs(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs) ArrayList(java.util.ArrayList) List(java.util.List) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase)

Example 9 with FlowId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId in project netvirt by opendaylight.

the class AclServiceOFFlowBuilderTest method testprogramUdpFlow_WithSrcDstPortRange.

@Test
public void testprogramUdpFlow_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.programUdpFlow(builder.build());
    List<MatchInfoBase> srcFlowMatches = new ArrayList<>();
    List<MatchInfoBase> dstFlowMatches = new ArrayList<>();
    for (String flowId : flowMatchesMap.keySet()) {
        if (flowId.startsWith("UDP_SOURCE_")) {
            srcFlowMatches.addAll(flowMatchesMap.get(flowId));
        }
        if (flowId.startsWith("UDP_DESTINATION_")) {
            dstFlowMatches.addAll(flowMatchesMap.get(flowId));
        }
    }
    AclServiceTestUtils.verifyGeneralFlows(srcFlowMatches, "1", "10.1.1.1", "20.1.1.1", "24");
    List<MatchInfoBase> udpSrcMatches = srcFlowMatches.stream().filter(item -> item instanceof NxMatchUdpSourcePort).collect(Collectors.toList());
    assertEquals(new NxMatchUdpSourcePort(1024, 65535), udpSrcMatches.get(0));
    AclServiceTestUtils.verifyGeneralFlows(dstFlowMatches, "1", "10.1.1.1", "20.1.1.1", "24");
    List<MatchInfoBase> udpDstMatches = dstFlowMatches.stream().filter(item -> item instanceof NxMatchUdpDestinationPort).collect(Collectors.toList());
    assertEquals(new NxMatchUdpDestinationPort(1024, 65535), udpDstMatches.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) 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) NxMatchUdpDestinationPort(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchUdpDestinationPort) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase) NxMatchUdpSourcePort(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchUdpSourcePort) Test(org.junit.Test)

Example 10 with FlowId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId in project netvirt by opendaylight.

the class NaptEventHandler method getFlowRef.

public static FlowRef getFlowRef(BigInteger dpId, Flow flow) {
    FlowKey flowKey = new FlowKey(new FlowId(flow.getId()));
    Node nodeDpn = buildInventoryDpnNode(dpId);
    InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flowKey).build();
    return new FlowRef(flowInstanceId);
}
Also used : FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) FlowRef(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Aggregations

FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)79 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)53 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)46 FlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder)43 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)25 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)24 ArrayList (java.util.ArrayList)22 BigInteger (java.math.BigInteger)21 Test (org.junit.Test)21 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)21 TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)19 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)15 FlowCookie (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie)13 FlowModFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags)10 List (java.util.List)9 Table (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table)9 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)9 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)8 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)8 MatchInfoBase (org.opendaylight.genius.mdsalutil.MatchInfoBase)8