use of org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination in project netvirt by opendaylight.
the class AclServiceOFFlowBuilder method addDstIpMatches.
/**
* Adds destination ip matches to the flows.
* @param acl the access control list
* @return the list of flows.
*/
public static List<MatchInfoBase> addDstIpMatches(AceIp acl) {
List<MatchInfoBase> flowMatches = new ArrayList<>();
if (acl.getAceIpVersion() instanceof AceIpv4) {
flowMatches.add(MatchEthernetType.IPV4);
Ipv4Prefix dstNetwork = ((AceIpv4) acl.getAceIpVersion()).getDestinationIpv4Network();
if (null != dstNetwork && !dstNetwork.getValue().equals(AclConstants.IPV4_ALL_NETWORK)) {
flowMatches.add(new MatchIpv4Destination(dstNetwork));
}
} else if (acl.getAceIpVersion() instanceof AceIpv6) {
flowMatches.add(MatchEthernetType.IPV6);
Ipv6Prefix dstNetwork = ((AceIpv6) acl.getAceIpVersion()).getDestinationIpv6Network();
if (null != dstNetwork && !dstNetwork.getValue().equals(AclConstants.IPV6_ALL_NETWORK)) {
flowMatches.add(new MatchIpv6Destination(dstNetwork));
}
}
return flowMatches;
}
use of org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination in project netvirt by opendaylight.
the class FloatingIPListener method buildDNATFlowEntity.
private FlowEntity buildDNATFlowEntity(BigInteger dpId, InternalToExternalPortMap mapping, long routerId, long associatedVpn) {
String externalIp = mapping.getExternalIp();
LOG.info("buildDNATFlowEntity : Bulding DNAT Flow entity for ip {} ", externalIp);
long segmentId = associatedVpn == NatConstants.INVALID_ID ? routerId : associatedVpn;
LOG.debug("buildDNATFlowEntity : Segment id {} in build DNAT", segmentId);
List<MatchInfo> matches = new ArrayList<>();
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(segmentId), MetaDataUtil.METADATA_MASK_VRFID));
matches.add(MatchEthernetType.IPV4);
String internalIp = mapping.getInternalIp();
matches.add(new MatchIpv4Destination(internalIp, "32"));
List<ActionInfo> actionsInfos = new ArrayList<>();
// actionsInfos.add(new ActionSetDestinationIp(internalIp, "32"));
List<InstructionInfo> instructions = new ArrayList<>();
// instructions.add(new InstructionWriteMetadata(BigInteger.valueOf
// (routerId), MetaDataUtil.METADATA_MASK_VRFID));
actionsInfos.add(new ActionNxResubmit(NwConstants.L3_FIB_TABLE));
instructions.add(new InstructionApplyActions(actionsInfos));
// instructions.add(new InstructionGotoTable(NatConstants.L3_FIB_TABLE));
String flowRef = NatUtil.getFlowRef(dpId, NwConstants.DNAT_TABLE, routerId, internalIp);
FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.DNAT_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.MatchIpv4Destination 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.MatchIpv4Destination in project netvirt by opendaylight.
the class VxlanGreConntrackBasedSnatService method installInboundEntryForVxlanGre.
protected void installInboundEntryForVxlanGre(BigInteger dpnId, long routerId, Long extNeVpnId, List<ExternalIps> externalIps, int elanId, int addOrRemove) {
LOG.info("installInboundEntryForVxlanGre: Install Inbound table entry on dpId {} for routerId {}", dpnId, routerId);
List<MatchInfoBase> matches = new ArrayList<>();
matches.add(MatchEthernetType.IPV4);
if (externalIps.isEmpty()) {
LOG.error("installInboundEntryForVxlanGre : createInboundTblEntry no externalIP present for routerId {}", routerId);
return;
}
String externalIp = externalIps.get(0).getIpAddress();
matches.add(new MatchIpv4Destination(externalIp, "32"));
if (addOrRemove == NwConstants.ADD_FLOW) {
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(extNeVpnId), MetaDataUtil.METADATA_MASK_VRFID));
}
List<ActionInfo> actionsInfos = new ArrayList<>();
List<ActionNxConntrack.NxCtAction> ctActionsList = new ArrayList<>();
ActionNxConntrack.NxCtAction nxCtAction = new ActionNxConntrack.NxNat(0, 0, 0, null, null, 0, 0);
ActionSetFieldMeta actionSetFieldMeta = new ActionSetFieldMeta(MetaDataUtil.getVpnIdMetadata(routerId));
actionsInfos.add(actionSetFieldMeta);
ctActionsList.add(nxCtAction);
ActionNxConntrack actionNxConntrack = new ActionNxConntrack(0, 0, elanId, NwConstants.NAPT_PFIB_TABLE, ctActionsList);
actionsInfos.add(actionNxConntrack);
List<InstructionInfo> instructions = new ArrayList<>();
instructions.add(new InstructionApplyActions(actionsInfos));
String flowRef = getFlowRef(dpnId, NwConstants.INBOUND_NAPT_TABLE, routerId);
syncFlow(dpnId, NwConstants.INBOUND_NAPT_TABLE, flowRef, NatConstants.DEFAULT_TS_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches, instructions, addOrRemove);
}
use of org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination in project netvirt by opendaylight.
the class AbstractSnatService method installInboundFibEntry.
protected void installInboundFibEntry(BigInteger dpnId, String externalIp, Long routerId, long extSubnetId, int addOrRemove) {
List<MatchInfo> matches = new ArrayList<>();
matches.add(MatchEthernetType.IPV4);
if (addOrRemove == NwConstants.ADD_FLOW) {
if (extSubnetId == NatConstants.INVALID_ID) {
LOG.error("ConntrackBasedSnatService : installInboundFibEntry : external subnet id is invalid.");
return;
}
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(extSubnetId), MetaDataUtil.METADATA_MASK_VRFID));
}
matches.add(new MatchIpv4Destination(externalIp, "32"));
ArrayList<ActionInfo> listActionInfo = new ArrayList<>();
ArrayList<InstructionInfo> instructionInfo = new ArrayList<>();
listActionInfo.add(new ActionNxResubmit(NwConstants.INBOUND_NAPT_TABLE));
instructionInfo.add(new InstructionApplyActions(listActionInfo));
String flowRef = getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, routerId);
flowRef = flowRef + "inbound" + externalIp;
syncFlow(dpnId, NwConstants.L3_FIB_TABLE, flowRef, NatConstants.SNAT_FIB_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches, instructionInfo, addOrRemove);
}
Aggregations