use of org.opendaylight.genius.mdsalutil.MatchInfo 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.MatchInfo 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.MatchInfo in project netvirt by opendaylight.
the class SNATDefaultRouteProgrammer method buildDefNATFlowEntity.
private FlowEntity buildDefNATFlowEntity(BigInteger dpId, long bgpVpnId, long routerId) {
InetAddress defaultIP = null;
try {
defaultIP = InetAddress.getByName("0.0.0.0");
} catch (UnknownHostException e) {
LOG.error("buildDefNATFlowEntity : Failed to build FIB Table Flow for " + "Default Route to NAT table", e);
return null;
}
List<MatchInfo> matches = new ArrayList<>();
matches.add(MatchEthernetType.IPV4);
// add match for default route "0.0.0.0/0"
// matches.add(new MatchInfo(MatchFieldType.ipv4_dst, new long[] {
// NatUtil.getIpAddress(defaultIP.getAddress()), 0 }));
// add match for vrfid
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(bgpVpnId), MetaDataUtil.METADATA_MASK_VRFID));
List<InstructionInfo> instructions = new ArrayList<>();
instructions.add(new InstructionGotoTable(NwConstants.PSNAT_TABLE));
String flowRef = NatUtil.getFlowRef(dpId, NwConstants.L3_FIB_TABLE, defaultIP, routerId);
FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_FIB_TABLE, flowRef, NatConstants.DEFAULT_DNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE, matches, instructions);
return flowEntity;
}
use of org.opendaylight.genius.mdsalutil.MatchInfo in project netvirt by opendaylight.
the class VpnFloatingIpHandler method makeLFibTableEntry.
private void makeLFibTableEntry(BigInteger dpId, long serviceId, String floatingIpPortMacAddress, short tableId, WriteTransaction writeFlowInvTx) {
List<MatchInfo> matches = new ArrayList<>();
matches.add(MatchEthernetType.MPLS_UNICAST);
matches.add(new MatchMplsLabel(serviceId));
List<Instruction> instructions = new ArrayList<>();
List<ActionInfo> actionsInfos = new ArrayList<>();
actionsInfos.add(new ActionPopMpls());
actionsInfos.add(new ActionSetFieldEthernetDestination(new MacAddress(floatingIpPortMacAddress)));
Instruction writeInstruction = new InstructionApplyActions(actionsInfos).buildInstruction(0);
instructions.add(writeInstruction);
instructions.add(new InstructionGotoTable(tableId).buildInstruction(1));
// Install the flow entry in L3_LFIB_TABLE
String flowRef = getFlowRef(dpId, NwConstants.L3_LFIB_TABLE, serviceId, "");
Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_LFIB_TABLE, flowRef, 10, flowRef, 0, 0, NwConstants.COOKIE_VM_LFIB_TABLE, matches, instructions);
mdsalManager.addFlowToTx(dpId, flowEntity, writeFlowInvTx);
LOG.debug("makeLFibTableEntry : LFIB Entry for dpID {} : label : {} modified successfully", dpId, serviceId);
}
use of org.opendaylight.genius.mdsalutil.MatchInfo in project netvirt by opendaylight.
the class VpnFloatingIpHandler method makeTunnelTableEntry.
private void makeTunnelTableEntry(String vpnName, BigInteger dpnId, long serviceId, List<Instruction> customInstructions, WriteTransaction writeFlowInvTx, ProviderTypes provType) {
List<MatchInfo> mkMatches = new ArrayList<>();
LOG.info("makeTunnelTableEntry on DpnId = {} and serviceId = {}", dpnId, serviceId);
int flowPriority = 5;
// then handled back to using using flow 25->44(which will be installed as part of SNAT)
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanService, provType)) {
mkMatches.add(new MatchTunnelId(NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, serviceId)));
flowPriority = 6;
} else {
mkMatches.add(new MatchTunnelId(BigInteger.valueOf(serviceId)));
}
Flow terminatingServiceTableFlowEntity = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE, getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, serviceId, ""), flowPriority, String.format("%s:%d", "TST Flow Entry ", serviceId), 0, 0, COOKIE_TUNNEL.add(BigInteger.valueOf(serviceId)), mkMatches, customInstructions);
mdsalManager.addFlowToTx(dpnId, terminatingServiceTableFlowEntity, writeFlowInvTx);
}
Aggregations