Search in sources :

Example 6 with MatchIpv4Destination

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);
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionSetFieldTunnelId(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) BucketInfo(org.opendaylight.genius.mdsalutil.BucketInfo) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Example 7 with MatchIpv4Destination

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);
    }
}
Also used : FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionDrop(org.opendaylight.genius.mdsalutil.actions.ActionDrop) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) UnknownHostException(java.net.UnknownHostException) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) InetAddress(java.net.InetAddress)

Example 8 with MatchIpv4Destination

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);
    }
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) ActionMoveSourceDestinationIp(org.opendaylight.genius.mdsalutil.actions.ActionMoveSourceDestinationIp) ActionSetIcmpType(org.opendaylight.genius.mdsalutil.actions.ActionSetIcmpType) ArrayList(java.util.ArrayList) ActionSetSourceIp(org.opendaylight.genius.mdsalutil.actions.ActionSetSourceIp) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) ActionNxLoadInPort(org.opendaylight.genius.mdsalutil.actions.ActionNxLoadInPort) ActionSetFieldEthernetSource(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource) MatchIcmpv4(org.opendaylight.genius.mdsalutil.matches.MatchIcmpv4) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ActionMoveSourceDestinationEth(org.opendaylight.genius.mdsalutil.actions.ActionMoveSourceDestinationEth) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Example 9 with MatchIpv4Destination

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;
}
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 10 with MatchIpv4Destination

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;
}
Also used : InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) MatchEthernetDestination(org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ActionSetDestinationIp(org.opendaylight.genius.mdsalutil.actions.ActionSetDestinationIp) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Aggregations

MatchIpv4Destination (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination)18 ArrayList (java.util.ArrayList)17 MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)12 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)11 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)8 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)8 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)8 MatchInfoBase (org.opendaylight.genius.mdsalutil.MatchInfoBase)7 InetAddress (java.net.InetAddress)5 UnknownHostException (java.net.UnknownHostException)5 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)5 MatchIpv6Destination (org.opendaylight.genius.mdsalutil.matches.MatchIpv6Destination)5 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)4 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)4 ActionNxResubmit (org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit)3 MatchIpv4Source (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ActionNxConntrack (org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack)2 NxCtAction (org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack.NxCtAction)2 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)2