Search in sources :

Example 16 with MatchIpv4Destination

use of org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination in project netvirt by opendaylight.

the class AclServiceUtils method buildIpMatches.

/**
 * Builds the ip matches.
 *
 * @param ipPrefixOrAddress the ip prefix or address
 * @param matchCriteria the source_ip or destination_ip used for the match
 * @return the list
 */
public static List<MatchInfoBase> buildIpMatches(IpPrefixOrAddress ipPrefixOrAddress, MatchCriteria matchCriteria) {
    List<MatchInfoBase> flowMatches = new ArrayList<>();
    IpPrefix ipPrefix = ipPrefixOrAddress.getIpPrefix();
    if (ipPrefix != null) {
        Ipv4Prefix ipv4Prefix = ipPrefix.getIpv4Prefix();
        if (ipv4Prefix != null) {
            flowMatches.add(MatchEthernetType.IPV4);
            if (!ipv4Prefix.getValue().equals(AclConstants.IPV4_ALL_NETWORK)) {
                flowMatches.add(matchCriteria == MatchCriteria.MATCH_SOURCE ? new MatchIpv4Source(ipv4Prefix) : new MatchIpv4Destination(ipv4Prefix));
            }
        } else {
            flowMatches.add(MatchEthernetType.IPV6);
            flowMatches.add(matchCriteria == MatchCriteria.MATCH_SOURCE ? new MatchIpv6Source(ipPrefix.getIpv6Prefix()) : new MatchIpv6Destination(ipPrefix.getIpv6Prefix()));
        }
    } else {
        IpAddress ipAddress = ipPrefixOrAddress.getIpAddress();
        if (ipAddress.getIpv4Address() != null) {
            flowMatches.add(MatchEthernetType.IPV4);
            flowMatches.add(matchCriteria == MatchCriteria.MATCH_SOURCE ? new MatchIpv4Source(ipAddress.getIpv4Address().getValue(), "32") : new MatchIpv4Destination(ipAddress.getIpv4Address().getValue(), "32"));
        } else {
            flowMatches.add(MatchEthernetType.IPV6);
            flowMatches.add(matchCriteria == MatchCriteria.MATCH_SOURCE ? new MatchIpv6Source(ipAddress.getIpv6Address().getValue() + "/128") : new MatchIpv6Destination(ipAddress.getIpv6Address().getValue() + "/128"));
        }
    }
    return flowMatches;
}
Also used : IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) MatchIpv6Source(org.opendaylight.genius.mdsalutil.matches.MatchIpv6Source) MatchIpv6Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv6Destination) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) MatchIpv4Source(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase)

Example 17 with MatchIpv4Destination

use of org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination in project netvirt by opendaylight.

the class AclServiceUtils method buildIpAndDstServiceMatch.

public static List<? extends MatchInfoBase> buildIpAndDstServiceMatch(Integer aclTag, AllowedAddressPairs aap) {
    List<MatchInfoBase> flowMatches = new ArrayList<>();
    flowMatches.add(buildRemoteAclTagMetadataMatch(aclTag));
    if (aap.getIpAddress().getIpAddress() != null) {
        if (aap.getIpAddress().getIpAddress().getIpv4Address() != null) {
            MatchEthernetType ipv4EthMatch = new MatchEthernetType(NwConstants.ETHTYPE_IPV4);
            flowMatches.add(ipv4EthMatch);
            MatchIpv4Destination dstMatch = new MatchIpv4Destination(new Ipv4Prefix(aap.getIpAddress().getIpAddress().getIpv4Address().getValue() + "/32"));
            flowMatches.add(dstMatch);
        } else if (aap.getIpAddress().getIpAddress().getIpv6Address() != null) {
            MatchEthernetType ipv6EthMatch = new MatchEthernetType(NwConstants.ETHTYPE_IPV6);
            flowMatches.add(ipv6EthMatch);
            MatchIpv6Destination dstMatch = new MatchIpv6Destination(new Ipv6Prefix(aap.getIpAddress().getIpAddress().getIpv6Address().getValue() + "/128"));
            flowMatches.add(dstMatch);
        }
    } else if (aap.getIpAddress().getIpPrefix() != null) {
        if (aap.getIpAddress().getIpPrefix().getIpv4Prefix() != null) {
            MatchEthernetType ipv4EthMatch = new MatchEthernetType(NwConstants.ETHTYPE_IPV4);
            flowMatches.add(ipv4EthMatch);
            MatchIpv4Destination dstMatch = new MatchIpv4Destination(aap.getIpAddress().getIpPrefix().getIpv4Prefix());
            flowMatches.add(dstMatch);
        } else if (aap.getIpAddress().getIpPrefix().getIpv6Prefix() != null) {
            MatchEthernetType ipv6EthMatch = new MatchEthernetType(NwConstants.ETHTYPE_IPV6);
            flowMatches.add(ipv6EthMatch);
            MatchIpv6Destination dstMatch = new MatchIpv6Destination(aap.getIpAddress().getIpPrefix().getIpv6Prefix());
            flowMatches.add(dstMatch);
        }
    }
    return flowMatches;
}
Also used : MatchIpv6Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv6Destination) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) Ipv6Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)

Example 18 with MatchIpv4Destination

use of org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination in project netvirt by opendaylight.

the class AclServiceOFFlowBuilderTest method testaddDstIpMatches_v4.

@Test
public void testaddDstIpMatches_v4() {
    AceIpBuilder builder = new AceIpBuilder();
    AceIpv4Builder v4builder = new AceIpv4Builder();
    v4builder.setDestinationIpv4Network(new Ipv4Prefix("10.1.1.1/24"));
    builder.setAceIpVersion(v4builder.build());
    List<MatchInfoBase> flowMatches = AclServiceOFFlowBuilder.addDstIpMatches(builder.build());
    assertTrue(flowMatches.contains(MatchEthernetType.IPV4));
    assertTrue(flowMatches.contains(new MatchIpv4Destination("10.1.1.1", "24")));
}
Also used : 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) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) 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) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase) Test(org.junit.Test)

Aggregations

MatchIpv4Destination (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination)18 ArrayList (java.util.ArrayList)17 MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)12 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)11 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)8 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)8 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)8 MatchInfoBase (org.opendaylight.genius.mdsalutil.MatchInfoBase)7 InetAddress (java.net.InetAddress)5 UnknownHostException (java.net.UnknownHostException)5 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)5 MatchIpv6Destination (org.opendaylight.genius.mdsalutil.matches.MatchIpv6Destination)5 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)4 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)4 ActionNxResubmit (org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit)3 MatchIpv4Source (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ActionNxConntrack (org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack)2 NxCtAction (org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack.NxCtAction)2 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)2