Search in sources :

Example 11 with PiTableId

use of org.onosproject.net.pi.model.PiTableId in project onos by opennetworkinglab.

the class MyTunnelApp method insertTunnelIngressRule.

/**
 * Generates and insert a flow rule to perform the tunnel INGRESS function
 * for the given switch, destination IP address and tunnel ID.
 *
 * @param switchId  switch ID
 * @param dstIpAddr IP address to forward inside the tunnel
 * @param tunId     tunnel ID
 */
private void insertTunnelIngressRule(DeviceId switchId, IpAddress dstIpAddr, int tunId) {
    PiTableId tunnelIngressTableId = PiTableId.of("c_ingress.t_tunnel_ingress");
    // Longest prefix match on IPv4 dest address.
    PiMatchFieldId ipDestMatchFieldId = PiMatchFieldId.of("hdr.ipv4.dst_addr");
    PiCriterion match = PiCriterion.builder().matchLpm(ipDestMatchFieldId, dstIpAddr.toOctets(), 32).build();
    PiActionParam tunIdParam = new PiActionParam(PiActionParamId.of("tun_id"), tunId);
    PiActionId ingressActionId = PiActionId.of("c_ingress.my_tunnel_ingress");
    PiAction action = PiAction.builder().withId(ingressActionId).withParameter(tunIdParam).build();
    log.info("Inserting INGRESS rule on switch {}: table={}, match={}, action={}", switchId, tunnelIngressTableId, match, action);
    insertPiFlowRule(switchId, tunnelIngressTableId, match, action);
}
Also used : PiActionId(org.onosproject.net.pi.model.PiActionId) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) PiTableId(org.onosproject.net.pi.model.PiTableId) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 12 with PiTableId

use of org.onosproject.net.pi.model.PiTableId in project onos by opennetworkinglab.

the class MyTunnelApp method insertTunnelForwardRule.

/**
 * Generates and insert a flow rule to perform the tunnel FORWARD/EGRESS
 * function for the given switch, output port address and tunnel ID.
 *
 * @param switchId switch ID
 * @param outPort  output port where to forward tunneled packets
 * @param tunId    tunnel ID
 * @param isEgress if true, perform tunnel egress action, otherwise forward
 *                 packet as is to port
 */
private void insertTunnelForwardRule(DeviceId switchId, PortNumber outPort, int tunId, boolean isEgress) {
    PiTableId tunnelForwardTableId = PiTableId.of("c_ingress.t_tunnel_fwd");
    // Exact match on tun_id
    PiMatchFieldId tunIdMatchFieldId = PiMatchFieldId.of("hdr.my_tunnel.tun_id");
    PiCriterion match = PiCriterion.builder().matchExact(tunIdMatchFieldId, tunId).build();
    // Action depend on isEgress parameter.
    // if true, perform tunnel egress action on the given outPort, otherwise
    // simply forward packet as is (set_out_port action).
    PiActionParamId portParamId = PiActionParamId.of("port");
    PiActionParam portParam = new PiActionParam(portParamId, (short) outPort.toLong());
    final PiAction action;
    if (isEgress) {
        // Tunnel egress action.
        // Remove MyTunnel header and forward to outPort.
        PiActionId egressActionId = PiActionId.of("c_ingress.my_tunnel_egress");
        action = PiAction.builder().withId(egressActionId).withParameter(portParam).build();
    } else {
        // Tunnel transit action.
        // Forward the packet as is to outPort.
        /*
             * TODO EXERCISE: create action object for the transit case.
             * Look at the t_tunnel_fwd table in the P4 program. Which of the 3
             * actions can be used to simply set the output port? Get the full
             * action name from the P4Info file, and use that when creating the
             * PiActionId object. When creating the PiAction object, remember to
             * add all action parameters as defined in the P4 program.
             *
             * Hint: the code will be similar to the case when isEgress is true.
             */
        // Replace null with your solution.
        action = null;
    }
    log.info("Inserting {} rule on switch {}: table={}, match={}, action={}", isEgress ? "EGRESS" : "TRANSIT", switchId, tunnelForwardTableId, match, action);
    insertPiFlowRule(switchId, tunnelForwardTableId, match, action);
}
Also used : PiActionParamId(org.onosproject.net.pi.model.PiActionParamId) PiActionId(org.onosproject.net.pi.model.PiActionId) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) PiTableId(org.onosproject.net.pi.model.PiTableId) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 13 with PiTableId

use of org.onosproject.net.pi.model.PiTableId in project fabric-tna by stratum.

the class NextObjectiveTranslator method selectGroup.

private int selectGroup(NextObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
    final PiTableId hashedTableId = P4InfoConstants.FABRIC_INGRESS_NEXT_HASHED;
    final List<DefaultNextTreatment> defaultNextTreatments = defaultNextTreatments(obj.nextTreatments(), true);
    final List<TrafficTreatment> piTreatments = Lists.newArrayList();
    for (DefaultNextTreatment t : defaultNextTreatments) {
        // Map treatment to PI...
        piTreatments.add(mapTreatmentToPiIfNeeded(t.treatment(), hashedTableId));
        // ...and handle egress if necessary.
        handleEgress(obj, t.treatment(), resultBuilder, false);
    }
    final List<GroupBucket> bucketList = piTreatments.stream().map(DefaultGroupBucket::createSelectGroupBucket).collect(Collectors.toList());
    final int groupId = obj.id();
    final PiGroupKey groupKey = (PiGroupKey) getGroupKey(obj);
    resultBuilder.addGroup(new DefaultGroupDescription(deviceId, GroupDescription.Type.SELECT, new GroupBuckets(bucketList), groupKey, groupId, obj.appId()));
    return groupId;
}
Also used : DefaultNextTreatment(org.onosproject.net.flowobjective.DefaultNextTreatment) PiGroupKey(org.onosproject.net.pi.runtime.PiGroupKey) PiTableId(org.onosproject.net.pi.model.PiTableId) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Aggregations

PiTableId (org.onosproject.net.pi.model.PiTableId)13 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)5 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)4 DefaultNextTreatment (org.onosproject.net.flowobjective.DefaultNextTreatment)4 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)4 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)4 GroupBucket (org.onosproject.net.group.GroupBucket)4 GroupBuckets (org.onosproject.net.group.GroupBuckets)4 PiActionId (org.onosproject.net.pi.model.PiActionId)4 PiActionModel (org.onosproject.net.pi.model.PiActionModel)4 PiMatchFieldId (org.onosproject.net.pi.model.PiMatchFieldId)4 PiMatchFieldModel (org.onosproject.net.pi.model.PiMatchFieldModel)4 PiPipelineModel (org.onosproject.net.pi.model.PiPipelineModel)4 PiTableModel (org.onosproject.net.pi.model.PiTableModel)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)3 PiActionParamModel (org.onosproject.net.pi.model.PiActionParamModel)3 PiActionProfileModel (org.onosproject.net.pi.model.PiActionProfileModel)3