Search in sources :

Example 1 with MatchIpv6Source

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

the class CountersServiceUtils method buildIpMatches.

private static List<MatchInfoBase> buildIpMatches(String ip, ElementCountersDirection direction) {
    List<MatchInfoBase> flowMatches = new ArrayList<>();
    IpAddress ipAddress = new IpAddress(ip.toCharArray());
    if (ipAddress.getIpv4Address() != null) {
        flowMatches.add(MatchEthernetType.IPV4);
        flowMatches.add(direction == ElementCountersDirection.EGRESS ? new MatchIpv4Source(ipAddress.getIpv4Address().getValue(), "32") : new MatchIpv4Destination(ipAddress.getIpv4Address().getValue(), "32"));
    } else {
        flowMatches.add(MatchEthernetType.IPV6);
        flowMatches.add(direction == ElementCountersDirection.EGRESS ? new MatchIpv6Source(ipAddress.getIpv6Address().getValue() + "/128") : new MatchIpv6Destination(ipAddress.getIpv6Address().getValue() + "/128"));
    }
    return flowMatches;
}
Also used : 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) MatchIpv4Source(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase)

Example 2 with MatchIpv6Source

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

the class AclServiceOFFlowBuilder method addSrcIpMatches.

/**
 * Adds source ip matches to the flows.
 * @param acl the access control list
 * @return the list of flows.
 */
public static List<MatchInfoBase> addSrcIpMatches(AceIp acl) {
    List<MatchInfoBase> flowMatches = new ArrayList<>();
    if (acl.getAceIpVersion() instanceof AceIpv4) {
        flowMatches.add(MatchEthernetType.IPV4);
        Ipv4Prefix srcNetwork = ((AceIpv4) acl.getAceIpVersion()).getSourceIpv4Network();
        if (null != srcNetwork && !srcNetwork.getValue().equals(AclConstants.IPV4_ALL_NETWORK)) {
            flowMatches.add(new MatchIpv4Source(srcNetwork));
        }
    } else if (acl.getAceIpVersion() instanceof AceIpv6) {
        flowMatches.add(MatchEthernetType.IPV6);
        Ipv6Prefix srcNetwork = ((AceIpv6) acl.getAceIpVersion()).getSourceIpv6Network();
        if (null != srcNetwork && !srcNetwork.getValue().equals(AclConstants.IPV6_ALL_NETWORK)) {
            flowMatches.add(new MatchIpv6Source(srcNetwork));
        }
    }
    return flowMatches;
}
Also used : MatchIpv6Source(org.opendaylight.genius.mdsalutil.matches.MatchIpv6Source) ArrayList(java.util.ArrayList) 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) MatchIpv4Source(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source) 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)

Example 3 with MatchIpv6Source

use of org.opendaylight.genius.mdsalutil.matches.MatchIpv6Source 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 4 with MatchIpv6Source

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

the class AclServiceUtils method buildIpAndSrcServiceMatch.

public static List<? extends MatchInfoBase> buildIpAndSrcServiceMatch(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);
            MatchIpv4Source srcMatch = new MatchIpv4Source(new Ipv4Prefix(aap.getIpAddress().getIpAddress().getIpv4Address().getValue() + "/32"));
            flowMatches.add(srcMatch);
        } else if (aap.getIpAddress().getIpAddress().getIpv6Address() != null) {
            MatchEthernetType ipv6EthMatch = new MatchEthernetType(NwConstants.ETHTYPE_IPV6);
            flowMatches.add(ipv6EthMatch);
            MatchIpv6Source srcMatch = new MatchIpv6Source(new Ipv6Prefix(aap.getIpAddress().getIpAddress().getIpv6Address().getValue() + "/128"));
            flowMatches.add(srcMatch);
        }
    } else if (aap.getIpAddress().getIpPrefix() != null) {
        if (aap.getIpAddress().getIpPrefix().getIpv4Prefix() != null) {
            MatchEthernetType ipv4EthMatch = new MatchEthernetType(NwConstants.ETHTYPE_IPV4);
            flowMatches.add(ipv4EthMatch);
            MatchIpv4Source srcMatch = new MatchIpv4Source(aap.getIpAddress().getIpPrefix().getIpv4Prefix());
            flowMatches.add(srcMatch);
        } else if (aap.getIpAddress().getIpPrefix().getIpv6Prefix() != null) {
            MatchEthernetType ipv6EthMatch = new MatchEthernetType(NwConstants.ETHTYPE_IPV6);
            flowMatches.add(ipv6EthMatch);
            MatchIpv6Source srcMatch = new MatchIpv6Source(aap.getIpAddress().getIpPrefix().getIpv6Prefix());
            flowMatches.add(srcMatch);
        }
    }
    return flowMatches;
}
Also used : MatchIpv6Source(org.opendaylight.genius.mdsalutil.matches.MatchIpv6Source) ArrayList(java.util.ArrayList) MatchIpv4Source(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source) 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)

Aggregations

ArrayList (java.util.ArrayList)4 MatchInfoBase (org.opendaylight.genius.mdsalutil.MatchInfoBase)4 MatchIpv4Source (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source)4 MatchIpv6Source (org.opendaylight.genius.mdsalutil.matches.MatchIpv6Source)4 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)3 MatchIpv4Destination (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination)2 MatchIpv6Destination (org.opendaylight.genius.mdsalutil.matches.MatchIpv6Destination)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 Ipv6Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)2 MatchEthernetType (org.opendaylight.genius.mdsalutil.matches.MatchEthernetType)1 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)1 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)1 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)1