use of org.onosproject.net.pi.runtime.PiAction 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);
}
use of org.onosproject.net.pi.runtime.PiAction 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);
}
use of org.onosproject.net.pi.runtime.PiAction 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);
}
use of org.onosproject.net.pi.runtime.PiAction 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);
}
use of org.onosproject.net.pi.runtime.PiAction 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;
}
Aggregations