Search in sources :

Example 11 with MatchIpv4Destination

use of org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination in project netvirt by opendaylight.

the class ConntrackBasedSnatService method installInboundEntry.

protected void installInboundEntry(BigInteger dpnId, long routerId, String externalIp, int elanId, long extSubnetId, int addOrRemove) {
    LOG.info("installInboundEntry : dpId {} and routerId {}", dpnId, routerId);
    List<MatchInfoBase> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    matches.add(new MatchIpv4Destination(externalIp, "32"));
    if (addOrRemove == NwConstants.ADD_FLOW) {
        if (extSubnetId == NatConstants.INVALID_ID) {
            LOG.error("installInboundEntry : external subnet id is invalid.");
            return;
        }
        matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(extSubnetId), MetaDataUtil.METADATA_MASK_VRFID));
    }
    List<ActionInfo> actionsInfos = new ArrayList<>();
    List<NxCtAction> ctActionsList = new ArrayList<>();
    NxCtAction nxCtAction = new ActionNxConntrack.NxNat(0, 0, 0, null, null, 0, 0);
    ActionNxLoadMetadata actionLoadMeta = new ActionNxLoadMetadata(MetaDataUtil.getVpnIdMetadata(routerId), LOAD_START, LOAD_END);
    actionsInfos.add(actionLoadMeta);
    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);
    flowRef = flowRef + "OUTBOUND";
    syncFlow(dpnId, NwConstants.INBOUND_NAPT_TABLE, flowRef, NatConstants.DEFAULT_TS_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) ActionNxConntrack(org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack) ActionNxLoadMetadata(org.opendaylight.genius.mdsalutil.actions.ActionNxLoadMetadata) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) NxCtAction(org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack.NxCtAction) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase)

Example 12 with MatchIpv4Destination

use of org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination in project netvirt by opendaylight.

the class FibRpcServiceImpl method makeLocalFibEntry.

private void makeLocalFibEntry(long vpnId, BigInteger dpnId, String ipPrefix, List<Instruction> customInstructions) {
    String[] values = ipPrefix.split("/");
    String ipAddress = values[0];
    int prefixLength = values.length == 1 ? 0 : Integer.parseInt(values[1]);
    LOG.debug("Adding route to DPN. ip {} masklen {}", ipAddress, prefixLength);
    InetAddress destPrefix = null;
    try {
        destPrefix = InetAddress.getByName(ipAddress);
    } catch (UnknownHostException e) {
        LOG.error("UnknowHostException in addRoute. Failed  to add Route for ipPrefix {} VpnId {} DPN{}", ipAddress, vpnId, dpnId, e);
        return;
    }
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
    matches.add(MatchEthernetType.IPV4);
    if (prefixLength != 0) {
        matches.add(new MatchIpv4Destination(destPrefix.getHostAddress(), Integer.toString(prefixLength)));
    }
    String flowRef = getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, vpnId, ipAddress);
    int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
    Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef, 0, 0, NwConstants.COOKIE_VM_FIB_TABLE, matches, customInstructions);
    mdsalManager.installFlow(dpnId, flowEntity);
    LOG.debug("FIB entry for route {} on dpn {} installed successfully - flow {}", ipAddress, dpnId, flowEntity);
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) UnknownHostException(java.net.UnknownHostException) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) InetAddress(java.net.InetAddress) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Example 13 with MatchIpv4Destination

use of org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination in project netvirt by opendaylight.

the class FibRpcServiceImpl method removeLocalFibEntry.

private void removeLocalFibEntry(BigInteger dpnId, long vpnId, String ipPrefix) {
    String[] values = ipPrefix.split("/");
    String ipAddress = values[0];
    int prefixLength = values.length == 1 ? 0 : Integer.parseInt(values[1]);
    LOG.debug("Removing route from DPN. ip {} masklen {}", ipAddress, prefixLength);
    InetAddress destPrefix = null;
    try {
        destPrefix = InetAddress.getByName(ipAddress);
    } catch (UnknownHostException e) {
        LOG.error("UnknowHostException in removeRoute. Failed  to remove Route for ipPrefix {} DPN {} Vpn {}", ipAddress, dpnId, vpnId, e);
        return;
    }
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
    matches.add(MatchEthernetType.IPV4);
    if (prefixLength != 0) {
        matches.add(new MatchIpv4Destination(destPrefix.getHostAddress(), Integer.toString(prefixLength)));
    }
    String flowRef = getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, vpnId, ipAddress);
    int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
    Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef, 0, 0, NwConstants.COOKIE_VM_FIB_TABLE, matches, null);
    mdsalManager.removeFlow(dpnId, flowEntity);
    LOG.info("FIB entry for prefix {} on dpn {} vpn {} removed successfully", ipAddress, dpnId, vpnId);
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) UnknownHostException(java.net.UnknownHostException) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) InetAddress(java.net.InetAddress) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Example 14 with MatchIpv4Destination

use of org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination in project netvirt by opendaylight.

the class VrfEntryListener method installIVpnLinkSwitchingFlows.

/*
     * Installs the flows in FIB table that, for a given route, do the switching from one VPN to the other.
     */
private void installIVpnLinkSwitchingFlows(final InterVpnLinkDataComposite interVpnLink, final String vpnUuid, final VrfEntry vrfEntry, long vpnTag) {
    Preconditions.checkNotNull(interVpnLink, "InterVpnLink cannot be null");
    Preconditions.checkArgument(vrfEntry.getRoutePaths() != null && vrfEntry.getRoutePaths().size() == 1);
    String destination = vrfEntry.getDestPrefix();
    String nextHop = vrfEntry.getRoutePaths().get(0).getNexthopAddress();
    String interVpnLinkName = interVpnLink.getInterVpnLinkName();
    // using as metadata the LPortTag associated to that vpn in the inter-vpn-link.
    if (interVpnLink.getState().or(State.Error) != State.Active) {
        LOG.warn("Route to {} with nexthop={} cannot be installed because the interVpnLink {} is not active", destination, nextHop, interVpnLinkName);
        return;
    }
    Optional<Long> optOtherEndpointLportTag = interVpnLink.getOtherEndpointLportTagByVpnName(vpnUuid);
    if (!optOtherEndpointLportTag.isPresent()) {
        LOG.warn("Could not find suitable LportTag for the endpoint opposite to vpn {} in interVpnLink {}", vpnUuid, interVpnLinkName);
        return;
    }
    List<BigInteger> targetDpns = interVpnLink.getEndpointDpnsByVpnName(vpnUuid);
    if (targetDpns.isEmpty()) {
        LOG.warn("Could not find DPNs for endpoint opposite to vpn {} in interVpnLink {}", vpnUuid, interVpnLinkName);
        return;
    }
    String[] values = destination.split("/");
    String destPrefixIpAddress = values[0];
    int prefixLength = values.length == 1 ? 0 : Integer.parseInt(values[1]);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnTag), MetaDataUtil.METADATA_MASK_VRFID));
    matches.add(MatchEthernetType.IPV4);
    if (prefixLength != 0) {
        matches.add(new MatchIpv4Destination(destPrefixIpAddress, Integer.toString(prefixLength)));
    }
    List<Instruction> instructions = Arrays.asList(new InstructionWriteMetadata(MetaDataUtil.getMetaDataForLPortDispatcher(optOtherEndpointLportTag.get().intValue(), ServiceIndex.getIndex(NwConstants.L3VPN_SERVICE_NAME, NwConstants.L3VPN_SERVICE_INDEX)), MetaDataUtil.getMetaDataMaskForLPortDispatcher()).buildInstruction(0), new InstructionGotoTable(NwConstants.L3_INTERFACE_TABLE).buildInstruction(1));
    int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
    String flowRef = getInterVpnFibFlowRef(interVpnLinkName, destination, nextHop);
    Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef, 0, 0, COOKIE_VM_FIB_TABLE, matches, instructions);
    LOG.trace("Installing flow in FIB table for vpn {} interVpnLink {} nextHop {} key {}", vpnUuid, interVpnLink.getInterVpnLinkName(), nextHop, flowRef);
    for (BigInteger dpId : targetDpns) {
        LOG.debug("Installing flow: VrfEntry=[prefix={} route-paths={}] dpn {} for InterVpnLink {} in FIB", vrfEntry.getDestPrefix(), vrfEntry.getRoutePaths(), dpId, interVpnLink.getInterVpnLinkName());
        mdsalManager.installFlow(dpId, flowEntity);
    }
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) BigInteger(java.math.BigInteger) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata)

Example 15 with MatchIpv4Destination

use of org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination in project netvirt by opendaylight.

the class BaseVrfEntryHandler method makeConnectedRoute.

protected void makeConnectedRoute(BigInteger dpId, long vpnId, VrfEntry vrfEntry, String rd, List<InstructionInfo> instructions, int addOrRemove, WriteTransaction tx, List<SubTransaction> subTxns) {
    Boolean wrTxPresent = true;
    if (tx == null) {
        wrTxPresent = false;
        tx = dataBroker.newWriteOnlyTransaction();
    }
    LOG.trace("makeConnectedRoute: vrfEntry {}", vrfEntry);
    String[] values = vrfEntry.getDestPrefix().split("/");
    String ipAddress = values[0];
    int prefixLength = values.length == 1 ? 0 : Integer.parseInt(values[1]);
    if (addOrRemove == NwConstants.ADD_FLOW) {
        LOG.debug("Adding route to DPN {} for rd {} prefix {} ", dpId, rd, vrfEntry.getDestPrefix());
    } else {
        LOG.debug("Removing route from DPN {} for rd {} prefix {}", dpId, rd, vrfEntry.getDestPrefix());
    }
    InetAddress destPrefix;
    try {
        destPrefix = InetAddress.getByName(ipAddress);
    } catch (UnknownHostException e) {
        LOG.error("Failed to get destPrefix for prefix {} rd {} VpnId {} DPN {}", vrfEntry.getDestPrefix(), rd, vpnId, dpId, e);
        return;
    }
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
    if (destPrefix instanceof Inet4Address) {
        matches.add(MatchEthernetType.IPV4);
        if (prefixLength != 0) {
            matches.add(new MatchIpv4Destination(destPrefix.getHostAddress(), Integer.toString(prefixLength)));
        }
    } else {
        matches.add(MatchEthernetType.IPV6);
        if (prefixLength != 0) {
            matches.add(new MatchIpv6Destination(destPrefix.getHostAddress() + "/" + prefixLength));
        }
    }
    int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
    String flowRef = FibUtil.getFlowRef(dpId, NwConstants.L3_FIB_TABLE, rd, priority, destPrefix);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef, 0, 0, COOKIE_VM_FIB_TABLE, matches, instructions);
    Flow flow = flowEntity.getFlowBuilder().build();
    String flowId = flowEntity.getFlowId();
    FlowKey flowKey = new FlowKey(new FlowId(flowId));
    Node nodeDpn = FibUtil.buildDpnNode(dpId);
    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 (RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.BGP) {
        SubTransaction subTransaction = new SubTransactionImpl();
        if (addOrRemove == NwConstants.ADD_FLOW) {
            subTransaction.setInstanceIdentifier(flowInstanceId);
            subTransaction.setInstance(flow);
            subTransaction.setAction(SubTransaction.CREATE);
        } else {
            subTransaction.setInstanceIdentifier(flowInstanceId);
            subTransaction.setAction(SubTransaction.DELETE);
        }
        subTxns.add(subTransaction);
    }
    if (addOrRemove == NwConstants.ADD_FLOW) {
        tx.put(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow, true);
    } else {
        tx.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId);
    }
    if (!wrTxPresent) {
        tx.submit();
    }
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) Inet4Address(java.net.Inet4Address) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) UnknownHostException(java.net.UnknownHostException) SubTransactionImpl(org.opendaylight.genius.utils.batching.SubTransactionImpl) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) ArrayList(java.util.ArrayList) SubTransaction(org.opendaylight.genius.utils.batching.SubTransaction) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) MatchIpv6Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv6Destination) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InetAddress(java.net.InetAddress)

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