Search in sources :

Example 46 with PiCriterion

use of org.onosproject.net.flow.criteria.PiCriterion 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 47 with PiCriterion

use of org.onosproject.net.flow.criteria.PiCriterion 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 48 with PiCriterion

use of org.onosproject.net.flow.criteria.PiCriterion in project TFG by mattinelorza.

the class Ipv6RoutingComponent method setUpMyStationTable.

// --------------------------------------------------------------------------
// METHODS TO COMPLETE.
// 
// Complete the implementation wherever you see TODO.
// --------------------------------------------------------------------------
/**
 * Sets up the "My Station" table for the given device using the
 * myStationMac address found in the config.
 * <p>
 * This method will be called at component activation for each device
 * (switch) known by ONOS, and every time a new device-added event is
 * captured by the InternalDeviceListener defined below.
 *
 * @param deviceId the device ID
 */
private void setUpMyStationTable(DeviceId deviceId) {
    log.info("Adding My Station rules to {}...", deviceId);
    final MacAddress myStationMac = getMyStationMac(deviceId);
    // HINT: in our solution, the My Station table matches on the *ethernet
    // destination* and there is only one action called *NoAction*, which is
    // used as an indication of "table hit" in the control block.
    // *** 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.my_station_table";
    final PiCriterion match = PiCriterion.builder().matchExact(PiMatchFieldId.of("hdr.ethernet.dst_addr"), myStationMac.toBytes()).build();
    // Creates an action which do *NoAction* when hit.
    final PiTableAction action = PiAction.builder().withId(PiActionId.of("NoAction")).build();
    // ---- END SOLUTION ----
    final FlowRule myStationRule = Utils.buildFlowRule(deviceId, appId, tableId, match, action);
    flowRuleService.applyFlowRules(myStationRule);
}
Also used : PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) PiTableAction(org.onosproject.net.pi.runtime.PiTableAction) FlowRule(org.onosproject.net.flow.FlowRule) MacAddress(org.onlab.packet.MacAddress)

Example 49 with PiCriterion

use of org.onosproject.net.flow.criteria.PiCriterion in project TFG by mattinelorza.

the class Ipv6RoutingComponent method createRoutingRule.

/**
 * Creates a routing flow rule that matches on the given IPv6 prefix and
 * executes the given group ID (created before).
 *
 * @param deviceId  the device where flow rule will be installed
 * @param ip6Prefix the IPv6 prefix
 * @param groupId   the group ID
 * @return a flow rule
 */
private FlowRule createRoutingRule(DeviceId deviceId, Ip6Prefix ip6Prefix, int groupId) {
    // *** 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.routing_v6_table";
    final PiCriterion match = PiCriterion.builder().matchLpm(PiMatchFieldId.of("hdr.ipv6.dst_addr"), ip6Prefix.address().toOctets(), ip6Prefix.prefixLength()).build();
    final PiTableAction action = PiActionProfileGroupId.of(groupId);
    return Utils.buildFlowRule(deviceId, appId, tableId, match, action);
}
Also used : PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) PiTableAction(org.onosproject.net.pi.runtime.PiTableAction)

Example 50 with PiCriterion

use of org.onosproject.net.flow.criteria.PiCriterion 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)

Aggregations

PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)69 PiAction (org.onosproject.net.pi.runtime.PiAction)45 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)31 TrafficSelector (org.onosproject.net.flow.TrafficSelector)29 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)28 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)27 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)26 FlowRule (org.onosproject.net.flow.FlowRule)25 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)16 PiTableAction (org.onosproject.net.pi.runtime.PiTableAction)13 Test (org.junit.Test)8 UpfProgrammableException (org.onosproject.net.behaviour.upf.UpfProgrammableException)8 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)8 NextObjective (org.onosproject.net.flowobjective.NextObjective)8 PiActionId (org.onosproject.net.pi.model.PiActionId)7 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)6 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)6 GroupBucket (org.onosproject.net.group.GroupBucket)6 GroupBuckets (org.onosproject.net.group.GroupBuckets)6 GroupDescription (org.onosproject.net.group.GroupDescription)6