Search in sources :

Example 76 with PiActionParam

use of org.onosproject.net.pi.runtime.PiActionParam 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 77 with PiActionParam

use of org.onosproject.net.pi.runtime.PiActionParam in project onos by opennetworkinglab.

the class PipelineInterpreterImpl method mapTreatment.

@Override
public PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId) throws PiInterpreterException {
    if (piTableId != TABLE_L2_FWD_ID) {
        throw new PiInterpreterException("Can map treatments only for 't_l2_fwd' table");
    }
    if (treatment.allInstructions().size() == 0) {
        // 0 instructions means "NoAction"
        return PiAction.builder().withId(ACT_ID_NOP).build();
    } else if (treatment.allInstructions().size() > 1) {
        // We understand treatments with only 1 instruction.
        throw new PiInterpreterException("Treatment has multiple instructions");
    }
    // Get the first and only instruction.
    Instruction instruction = treatment.allInstructions().get(0);
    if (instruction.type() != OUTPUT) {
        // We can map only instructions of type OUTPUT.
        throw new PiInterpreterException(format("Instruction of type '%s' not supported", instruction.type()));
    }
    OutputInstruction outInstruction = (OutputInstruction) instruction;
    PortNumber port = outInstruction.port();
    if (!port.isLogical()) {
        return PiAction.builder().withId(ACT_ID_SET_EGRESS_PORT).withParameter(new PiActionParam(ACT_PARAM_ID_PORT, copyFrom(port.toLong()))).build();
    } else if (port.equals(CONTROLLER)) {
        return PiAction.builder().withId(ACT_ID_SEND_TO_CPU).build();
    } else {
        throw new PiInterpreterException(format("Output on logical port '%s' not supported", port));
    }
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) PortNumber(org.onosproject.net.PortNumber) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam)

Example 78 with PiActionParam

use of org.onosproject.net.pi.runtime.PiActionParam in project TFG by mattinelorza.

the class Ipv6SimpleRoutingComponent method createL2NextHopRule.

// --------------------------------------------------------------------------
// METHODS TO COMPLETE.
// 
// Complete the implementation wherever you see TODO.
// --------------------------------------------------------------------------
/**
 * Creates a flow rule for the L2 table mapping the given next hop MAC to
 * the given output port.
 * <p>
 * This is called by the routing policy methods below to establish L2-based
 * forwarding inside the fabric, e.g., when deviceId is a leaf switch and
 * nextHopMac is the one of a spine switch.
 *
 * @param deviceId   the device
 * @param nexthopMac the next hop (destination) mac
 * @param outPort    the output port
 */
private FlowRule createL2NextHopRule(DeviceId deviceId, MacAddress nexthopMac, PortNumber outPort) {
    // *** TODO EXERCISE 5
    // Modify P4Runtime entity names to match content of P4Info file (look
    // for the fully qualified name of tables, match fields, and actions.
    // ---- START SOLUTION ----
    final String tableId = "IngressPipeImpl.l2_exact_table";
    final PiCriterion match = PiCriterion.builder().matchExact(PiMatchFieldId.of("hdr.ethernet.dst_addr"), nexthopMac.toBytes()).build();
    final PiAction action = PiAction.builder().withId(PiActionId.of("IngressPipeImpl.set_egress_port")).withParameter(new PiActionParam(PiActionParamId.of("port_num"), outPort.toLong())).build();
    return Utils.buildFlowRule(deviceId, appId, tableId, match, action);
}
Also used : PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 79 with PiActionParam

use of org.onosproject.net.pi.runtime.PiActionParam in project TFG by mattinelorza.

the class L2BridgingComponent method learnHost.

/**
 * Insert flow rules to forward packets to a given host located at the given
 * device and port.
 * <p>
 * This method will be called at component activation for each host known by
 * ONOS, and every time a new host-added event is captured by the
 * InternalHostListener defined below.
 *
 * @param host     host instance
 * @param deviceId device where the host is located
 * @param port     port where the host is attached to
 */
private void learnHost(Host host, DeviceId deviceId, PortNumber port) {
    log.info("Adding L2 unicast rule on {} for host {} (port {})...", deviceId, host.id(), port);
    // Modify P4Runtime entity names to match content of P4Info file (look
    // for the fully qualified name of tables, match fields, and actions.
    // ---- START SOLUTION ----
    final String tableId = "IngressPipeImpl.l2_exact_table";
    // Match exactly on the host MAC address.
    final MacAddress hostMac = host.mac();
    final PiCriterion hostMacCriterion = PiCriterion.builder().matchExact(PiMatchFieldId.of("hdr.ethernet.dst_addr"), hostMac.toBytes()).build();
    // Action: set output port
    final PiAction l2UnicastAction = PiAction.builder().withId(PiActionId.of("IngressPipeImpl.set_egress_port")).withParameter(new PiActionParam(PiActionParamId.of("port_num"), port.toLong())).build();
    // ---- END SOLUTION ----
    // Forge flow rule.
    final FlowRule rule = Utils.buildFlowRule(deviceId, appId, tableId, hostMacCriterion, l2UnicastAction);
    // Insert.
    flowRuleService.applyFlowRules(rule);
}
Also used : PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) FlowRule(org.onosproject.net.flow.FlowRule) MacAddress(org.onlab.packet.MacAddress) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 80 with PiActionParam

use of org.onosproject.net.pi.runtime.PiActionParam in project TFG by mattinelorza.

the class NdpReplyComponent method buildNdpReplyFlowRule.

/**
 * Build a flow rule for the NDP reply table on the given device, for the
 * given target IPv6 address and MAC address.
 *
 * @param deviceId          device ID where to install the flow rules
 * @param targetIpv6Address target IPv6 address
 * @param targetMac         target MAC address
 * @return flow rule object
 */
private FlowRule buildNdpReplyFlowRule(DeviceId deviceId, Ip6Address targetIpv6Address, MacAddress targetMac) {
    // *** TODO EXERCISE 5
    // Modify P4Runtime entity names to match content of P4Info file (look
    // for the fully qualified name of tables, match fields, and actions.
    // ---- START SOLUTION ----
    // Build match.
    final PiCriterion match = PiCriterion.builder().matchExact(PiMatchFieldId.of("hdr.ndp.target_ipv6_addr"), targetIpv6Address.toOctets()).build();
    // Build action.
    final PiActionParam targetMacParam = new PiActionParam(PiActionParamId.of("target_mac"), targetMac.toBytes());
    final PiAction action = PiAction.builder().withId(PiActionId.of("IngressPipeImpl.ndp_ns_to_na")).withParameter(targetMacParam).build();
    // Table ID.
    final String tableId = "IngressPipeImpl.ndp_reply_table";
    // ---- END SOLUTION ----
    // Build flow rule.
    final FlowRule rule = Utils.buildFlowRule(deviceId, appId, tableId, match, action);
    return rule;
}
Also used : PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) FlowRule(org.onosproject.net.flow.FlowRule) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Aggregations

PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)102 PiAction (org.onosproject.net.pi.runtime.PiAction)90 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)50 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)50 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)39 TrafficSelector (org.onosproject.net.flow.TrafficSelector)39 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)39 Test (org.junit.Test)30 FlowRule (org.onosproject.net.flow.FlowRule)27 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)21 GroupDescription (org.onosproject.net.group.GroupDescription)11 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)10 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)8 NextObjective (org.onosproject.net.flowobjective.NextObjective)8 PortNumber (org.onosproject.net.PortNumber)7 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)7 GroupBucket (org.onosproject.net.group.GroupBucket)7 GroupBuckets (org.onosproject.net.group.GroupBuckets)7 PiActionProfileGroupId (org.onosproject.net.pi.runtime.PiActionProfileGroupId)7 PiGroupKey (org.onosproject.net.pi.runtime.PiGroupKey)6