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")));
}
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;
}
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;
}
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;
}
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;
}
Aggregations