Search in sources :

Example 1 with MatchIpv4Source

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

the class AclServiceOFFlowBuilderTest method testaddSrcIpMatches_v4.

@Test
public void testaddSrcIpMatches_v4() {
    AceIpBuilder builder = new AceIpBuilder();
    AceIpv4Builder v4builder = new AceIpv4Builder();
    v4builder.setSourceIpv4Network(new Ipv4Prefix("10.1.1.1/24"));
    builder.setAceIpVersion(v4builder.build());
    List<MatchInfoBase> flowMatches = AclServiceOFFlowBuilder.addSrcIpMatches(builder.build());
    assertTrue(flowMatches.contains(MatchEthernetType.IPV4));
    assertTrue(flowMatches.contains(new MatchIpv4Source("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) 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) MatchIpv4Source(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase) Test(org.junit.Test)

Example 2 with MatchIpv4Source

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

the class NaptEventHandler method buildAndGetMatchInfo.

private static List<MatchInfo> buildAndGetMatchInfo(String ip, int port, short tableId, NAPTEntryEvent.Protocol protocol, long segmentId) {
    MatchInfo ipMatchInfo = null;
    MatchInfo portMatchInfo = null;
    MatchInfo protocolMatchInfo = null;
    InetAddress ipAddress = null;
    String ipAddressAsString = null;
    try {
        ipAddress = InetAddress.getByName(ip);
        ipAddressAsString = ipAddress.getHostAddress();
    } catch (UnknownHostException e) {
        LOG.error("buildAndGetMatchInfo : UnknowHostException in buildAndGetMatchInfo." + "Failed  to build NAPT Flow for ip {}", ip, e);
        return null;
    }
    MatchInfo metaDataMatchInfo = null;
    if (tableId == NwConstants.OUTBOUND_NAPT_TABLE) {
        ipMatchInfo = new MatchIpv4Source(ipAddressAsString, "32");
        if (protocol == NAPTEntryEvent.Protocol.TCP) {
            protocolMatchInfo = MatchIpProtocol.TCP;
            portMatchInfo = new MatchTcpSourcePort(port);
        } else if (protocol == NAPTEntryEvent.Protocol.UDP) {
            protocolMatchInfo = MatchIpProtocol.UDP;
            portMatchInfo = new MatchUdpSourcePort(port);
        }
        metaDataMatchInfo = new MatchMetadata(MetaDataUtil.getVpnIdMetadata(segmentId), MetaDataUtil.METADATA_MASK_VRFID);
    } else {
        ipMatchInfo = new MatchIpv4Destination(ipAddressAsString, "32");
        if (protocol == NAPTEntryEvent.Protocol.TCP) {
            protocolMatchInfo = MatchIpProtocol.TCP;
            portMatchInfo = new MatchTcpDestinationPort(port);
        } else if (protocol == NAPTEntryEvent.Protocol.UDP) {
            protocolMatchInfo = MatchIpProtocol.UDP;
            portMatchInfo = new MatchUdpDestinationPort(port);
        }
    // metaDataMatchInfo = new MatchMetadata(BigInteger.valueOf(vpnId), MetaDataUtil.METADATA_MASK_VRFID);
    }
    ArrayList<MatchInfo> matchInfo = new ArrayList<>();
    matchInfo.add(MatchEthernetType.IPV4);
    matchInfo.add(ipMatchInfo);
    matchInfo.add(protocolMatchInfo);
    matchInfo.add(portMatchInfo);
    if (tableId == NwConstants.OUTBOUND_NAPT_TABLE) {
        matchInfo.add(metaDataMatchInfo);
    }
    return matchInfo;
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) MatchTcpSourcePort(org.opendaylight.genius.mdsalutil.matches.MatchTcpSourcePort) MatchUdpDestinationPort(org.opendaylight.genius.mdsalutil.matches.MatchUdpDestinationPort) UnknownHostException(java.net.UnknownHostException) MatchTcpDestinationPort(org.opendaylight.genius.mdsalutil.matches.MatchTcpDestinationPort) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) MatchIpv4Source(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) MatchUdpSourcePort(org.opendaylight.genius.mdsalutil.matches.MatchUdpSourcePort) InetAddress(java.net.InetAddress)

Example 3 with MatchIpv4Source

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

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

the class FloatingIPListener method buildSNATFlowEntity.

private FlowEntity buildSNATFlowEntity(BigInteger dpId, InternalToExternalPortMap mapping, long vpnId, Uuid externalNetworkId) {
    String internalIp = mapping.getInternalIp();
    LOG.debug("buildSNATFlowEntity : Building SNAT Flow entity for ip {} ", internalIp);
    ProviderTypes provType = NatUtil.getProviderTypefromNetworkId(dataBroker, externalNetworkId);
    if (provType == null) {
        LOG.error("buildSNATFlowEntity : Unable to get Network Provider Type for network {}", externalNetworkId);
        return null;
    }
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
    matches.add(MatchEthernetType.IPV4);
    String externalIp = mapping.getExternalIp();
    matches.add(new MatchIpv4Source(externalIp, "32"));
    List<ActionInfo> actionsInfo = new ArrayList<>();
    Uuid floatingIpId = mapping.getExternalId();
    String macAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(dataBroker, floatingIpId);
    if (macAddress != null) {
        actionsInfo.add(new ActionSetFieldEthernetSource(new MacAddress(macAddress)));
    } else {
        LOG.warn("buildSNATFlowEntity : No MAC address found for floating IP {}", externalIp);
    }
    LOG.trace("buildSNATFlowEntity : External Network Provider Type is {}, resubmit to FIB", provType.toString());
    actionsInfo.add(new ActionNxResubmit(NwConstants.L3_FIB_TABLE));
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionApplyActions(actionsInfo));
    String flowRef = NatUtil.getFlowRef(dpId, NwConstants.SNAT_TABLE, vpnId, externalIp);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.SNAT_TABLE, flowRef, NatConstants.DEFAULT_DNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE, matches, instructions);
    return flowEntity;
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) MatchIpv4Source(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ActionSetFieldEthernetSource(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Example 5 with MatchIpv4Source

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

the class FloatingIPListener method buildPreSNATFlowEntity.

private FlowEntity buildPreSNATFlowEntity(BigInteger dpId, String internalIp, String externalIp, long vpnId, long routerId, long associatedVpn) {
    LOG.debug("buildPreSNATFlowEntity : Building PSNAT Flow entity for ip {} ", internalIp);
    long segmentId = associatedVpn == NatConstants.INVALID_ID ? routerId : associatedVpn;
    LOG.debug("buildPreSNATFlowEntity : Segment id {} in build preSNAT flow", segmentId);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    matches.add(new MatchIpv4Source(internalIp, "32"));
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(segmentId), MetaDataUtil.METADATA_MASK_VRFID));
    List<ActionInfo> actionsInfos = new ArrayList<>();
    actionsInfos.add(new ActionSetSourceIp(externalIp, "32"));
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionWriteMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
    instructions.add(new InstructionApplyActions(actionsInfos));
    instructions.add(new InstructionGotoTable(NwConstants.SNAT_TABLE));
    String flowRef = NatUtil.getFlowRef(dpId, NwConstants.PSNAT_TABLE, routerId, internalIp);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.PSNAT_TABLE, flowRef, NatConstants.DEFAULT_DNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE, matches, instructions);
    return flowEntity;
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) ArrayList(java.util.ArrayList) ActionSetSourceIp(org.opendaylight.genius.mdsalutil.actions.ActionSetSourceIp) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) MatchIpv4Source(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Aggregations

MatchIpv4Source (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source)8 ArrayList (java.util.ArrayList)7 MatchInfoBase (org.opendaylight.genius.mdsalutil.MatchInfoBase)5 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)4 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)3 MatchIpv4Destination (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination)3 MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)3 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)2 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)2 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)2 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)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 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 Test (org.junit.Test)1 ActionNxResubmit (org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit)1 ActionSetFieldEthernetSource (org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource)1