use of org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination in project netvirt by opendaylight.
the class AbstractSnatService method installSnatMissEntry.
protected void installSnatMissEntry(BigInteger dpnId, Long routerId, String routerName, BigInteger primarySwitchId, String externalIp, long extSubnetId, int addOrRemove) {
LOG.debug("installSnatMissEntry : Installing SNAT miss entry in switch {}", dpnId);
List<ActionInfo> listActionInfoPrimary = new ArrayList<>();
String ifNamePrimary = getTunnelInterfaceName(dpnId, primarySwitchId);
List<BucketInfo> listBucketInfo = new ArrayList<>();
if (ifNamePrimary != null) {
LOG.debug("installSnatMissEntry : On Non- Napt switch , Primary Tunnel interface is {}", ifNamePrimary);
listActionInfoPrimary = NatUtil.getEgressActionsForInterface(interfaceManager, ifNamePrimary, routerId);
}
BucketInfo bucketPrimary = new BucketInfo(listActionInfoPrimary);
listBucketInfo.add(0, bucketPrimary);
LOG.debug("installSnatMissEntry : installSnatMissEntry called for dpnId {} with primaryBucket {} ", dpnId, listBucketInfo.get(0));
// Install the select group
long groupId = createGroupId(getGroupIdKey(routerName));
GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll, listBucketInfo);
LOG.debug("installSnatMissEntry : installing the SNAT to NAPT GroupEntity:{}", groupEntity);
mdsalManager.installGroup(groupEntity);
// Install miss entry pointing to group
LOG.debug("installSnatMissEntry : buildSnatFlowEntity is called for dpId {}, routerName {} and groupId {}", dpnId, routerName, groupId);
List<MatchInfo> matches = new ArrayList<>();
matches.add(new MatchEthernetType(0x0800L));
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(routerId), MetaDataUtil.METADATA_MASK_VRFID));
List<ActionInfo> actionsInfo = new ArrayList<>();
actionsInfo.add(new ActionSetFieldTunnelId(BigInteger.valueOf(routerId)));
LOG.debug("installSnatMissEntry : Setting the tunnel to the list of action infos {}", actionsInfo);
actionsInfo.add(new ActionGroup(groupId));
List<InstructionInfo> instructions = new ArrayList<>();
instructions.add(new InstructionApplyActions(actionsInfo));
String flowRef = getFlowRef(dpnId, NwConstants.PSNAT_TABLE, routerId);
syncFlow(dpnId, NwConstants.PSNAT_TABLE, flowRef, NatConstants.DEFAULT_PSNAT_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches, instructions, addOrRemove);
// Install the FIB entry for traffic destined to SNAT IP in Non-NAPT switch.
matches = new ArrayList<>();
actionsInfo = new ArrayList<>();
matches.add(new MatchEthernetType(0x0800L));
if (addOrRemove == NwConstants.ADD_FLOW) {
if (extSubnetId == NatConstants.INVALID_ID) {
LOG.error("installSnatMissEntry : external subnet id is invalid.");
return;
}
actionsInfo.add(new ActionSetFieldTunnelId(BigInteger.valueOf(extSubnetId)));
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(extSubnetId), MetaDataUtil.METADATA_MASK_VRFID));
}
matches.add(new MatchIpv4Destination(externalIp, "32"));
LOG.debug("installSnatMissEntry : Setting the tunnel to the list of action infos {}", actionsInfo);
actionsInfo.add(new ActionGroup(groupId));
instructions = new ArrayList<>();
instructions.add(new InstructionApplyActions(actionsInfo));
flowRef = getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, routerId);
flowRef = flowRef + "inboundmiss" + externalIp;
syncFlow(dpnId, NwConstants.L3_FIB_TABLE, flowRef, NatConstants.SNAT_FIB_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 VrfEntryListener method installSubnetBroadcastAddrDropRule.
private void installSubnetBroadcastAddrDropRule(final BigInteger dpnId, final String rd, final long vpnId, final VrfEntry vrfEntry, int addOrRemove, WriteTransaction tx) {
List<MatchInfo> matches = new ArrayList<>();
LOG.debug("SUBNETROUTE: installSubnetBroadcastAddrDropRule: destPrefix {} rd {} vpnId {} dpnId {}", vrfEntry.getDestPrefix(), rd, vpnId, dpnId);
String[] ipAddress = vrfEntry.getDestPrefix().split("/");
String subnetBroadcastAddr = FibUtil.getBroadcastAddressFromCidr(vrfEntry.getDestPrefix());
final int prefixLength = ipAddress.length == 1 ? 0 : Integer.parseInt(ipAddress[1]);
InetAddress destPrefix;
try {
destPrefix = InetAddress.getByName(subnetBroadcastAddr);
} catch (UnknownHostException e) {
LOG.error("Failed to get destPrefix for prefix {} rd {} VpnId {} DPN {}", vrfEntry.getDestPrefix(), rd, vpnId, dpnId, e);
return;
}
// Match on VpnId and SubnetBroadCast IP address
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
matches.add(MatchEthernetType.IPV4);
if (prefixLength != 0) {
matches.add(new MatchIpv4Destination(subnetBroadcastAddr, Integer.toString(IPV4_ADDR_PREFIX_LENGTH)));
}
// Action is to drop the packet
List<InstructionInfo> dropInstructions = new ArrayList<>();
List<ActionInfo> actionsInfos = new ArrayList<>();
actionsInfos.add(new ActionDrop());
dropInstructions.add(new InstructionApplyActions(actionsInfos));
int priority = DEFAULT_FIB_FLOW_PRIORITY + IPV4_ADDR_PREFIX_LENGTH;
String flowRef = FibUtil.getFlowRef(dpnId, NwConstants.L3_SUBNET_ROUTE_TABLE, rd, priority, destPrefix);
FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpnId, NwConstants.L3_SUBNET_ROUTE_TABLE, flowRef, priority, flowRef, 0, 0, COOKIE_TABLE_MISS, matches, dropInstructions);
Flow flow = flowEntity.getFlowBuilder().build();
String flowId = flowEntity.getFlowId();
FlowKey flowKey = new FlowKey(new FlowId(flowId));
Node nodeDpn = FibUtil.buildDpnNode(dpnId);
InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flowKey).build();
if (addOrRemove == NwConstants.ADD_FLOW) {
tx.put(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow, true);
} else {
tx.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId);
}
}
use of org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination in project netvirt by opendaylight.
the class BaseVrfEntryHandler method installPingResponderFlowEntry.
public void installPingResponderFlowEntry(BigInteger dpnId, long vpnId, String routerInternalIp, MacAddress routerMac, long label, int addOrRemove) {
List<MatchInfo> matches = new ArrayList<>();
matches.add(MatchIpProtocol.ICMP);
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
matches.add(new MatchIcmpv4((short) 8, (short) 0));
matches.add(MatchEthernetType.IPV4);
matches.add(new MatchIpv4Destination(routerInternalIp, "32"));
List<ActionInfo> actionsInfos = new ArrayList<>();
// Set Eth Src and Eth Dst
actionsInfos.add(new ActionMoveSourceDestinationEth());
actionsInfos.add(new ActionSetFieldEthernetSource(routerMac));
// Move Ip Src to Ip Dst
actionsInfos.add(new ActionMoveSourceDestinationIp());
actionsInfos.add(new ActionSetSourceIp(routerInternalIp, "32"));
// Set the ICMP type to 0 (echo reply)
actionsInfos.add(new ActionSetIcmpType((short) 0));
actionsInfos.add(new ActionNxLoadInPort(BigInteger.ZERO));
actionsInfos.add(new ActionNxResubmit(NwConstants.L3_FIB_TABLE));
List<InstructionInfo> instructions = new ArrayList<>();
instructions.add(new InstructionApplyActions(actionsInfos));
int priority = FibConstants.DEFAULT_FIB_FLOW_PRIORITY + FibConstants.DEFAULT_PREFIX_LENGTH;
String flowRef = FibUtil.getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, label, priority);
FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpnId, NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef, 0, 0, NwConstants.COOKIE_VM_FIB_TABLE, matches, instructions);
if (addOrRemove == NwConstants.ADD_FLOW) {
mdsalManager.syncInstallFlow(flowEntity);
} else {
mdsalManager.syncRemoveFlow(flowEntity);
}
}
use of org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination 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.MatchIpv4Destination in project netvirt by opendaylight.
the class FloatingIPListener method buildPreDNATFlowEntity.
private FlowEntity buildPreDNATFlowEntity(BigInteger dpId, InternalToExternalPortMap mapping, long routerId, long associatedVpn) {
String externalIp = mapping.getExternalIp();
Uuid floatingIpId = mapping.getExternalId();
// Get the FIP MAC address for DNAT
String floatingIpPortMacAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(dataBroker, floatingIpId);
if (floatingIpPortMacAddress == null) {
LOG.error("buildPreDNATFlowEntity : Unable to retrieve floatingIpPortMacAddress from floating IP UUID {} " + "for floating IP {}", floatingIpId, externalIp);
return null;
}
LOG.debug("buildPreDNATFlowEntity : Bulding DNAT Flow entity for ip {} ", externalIp);
long segmentId = associatedVpn == NatConstants.INVALID_ID ? routerId : associatedVpn;
LOG.debug("buildPreDNATFlowEntity : Segment id {} in build preDNAT Flow", segmentId);
List<MatchInfo> matches = new ArrayList<>();
matches.add(MatchEthernetType.IPV4);
matches.add(new MatchIpv4Destination(externalIp, "32"));
// Match Destination Floating IP MAC Address on table = 25 (PDNAT_TABLE)
matches.add(new MatchEthernetDestination(new MacAddress(floatingIpPortMacAddress)));
// matches.add(new MatchMetadata(
// BigInteger.valueOf(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
List<ActionInfo> actionsInfos = new ArrayList<>();
String internalIp = mapping.getInternalIp();
actionsInfos.add(new ActionSetDestinationIp(internalIp, "32"));
List<InstructionInfo> instructions = new ArrayList<>();
instructions.add(new InstructionWriteMetadata(MetaDataUtil.getVpnIdMetadata(segmentId), MetaDataUtil.METADATA_MASK_VRFID));
instructions.add(new InstructionApplyActions(actionsInfos));
instructions.add(new InstructionGotoTable(NwConstants.DNAT_TABLE));
String flowRef = NatUtil.getFlowRef(dpId, NwConstants.PDNAT_TABLE, routerId, externalIp);
FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.PDNAT_TABLE, flowRef, NatConstants.DEFAULT_DNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE, matches, instructions);
return flowEntity;
}
Aggregations