Search in sources :

Example 6 with FlowRule

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

the class L2BridgingComponent method insertMulticastFlowRules.

/**
 * Insert flow rules matching ethernet destination
 * broadcast/multicast addresses (e.g. ARP requests, NDP Neighbor
 * Solicitation, etc.). Such packets should be processed by the multicast
 * group created before.
 * <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 device ID where to install the rules
 */
private void insertMulticastFlowRules(DeviceId deviceId) {
    log.info("Adding L2 multicast rules on {}...", deviceId);
    // Modify P4Runtime entity names to match content of P4Info file (look
    // for the fully qualified name of tables, match fields, and actions.
    // ---- START SOLUTION ----
    // Match ARP request - Match exactly FF:FF:FF:FF:FF:FF
    final PiCriterion macBroadcastCriterion = PiCriterion.builder().matchTernary(PiMatchFieldId.of("hdr.ethernet.dst_addr"), MacAddress.valueOf("FF:FF:FF:FF:FF:FF").toBytes(), MacAddress.valueOf("FF:FF:FF:FF:FF:FF").toBytes()).build();
    // Match NDP NS - Match ternary 33:33:**:**:**:**
    final PiCriterion ipv6MulticastCriterion = PiCriterion.builder().matchTernary(PiMatchFieldId.of("hdr.ethernet.dst_addr"), MacAddress.valueOf("33:33:00:00:00:00").toBytes(), MacAddress.valueOf("FF:FF:00:00:00:00").toBytes()).build();
    // Action: set multicast group id
    final PiAction setMcastGroupAction = PiAction.builder().withId(PiActionId.of("IngressPipeImpl.set_multicast_group")).withParameter(new PiActionParam(PiActionParamId.of("gid"), DEFAULT_BROADCAST_GROUP_ID)).build();
    // Build 2 flow rules.
    final String tableId = "IngressPipeImpl.l2_ternary_table";
    // ---- END SOLUTION ----
    final FlowRule rule1 = Utils.buildFlowRule(deviceId, appId, tableId, macBroadcastCriterion, setMcastGroupAction);
    final FlowRule rule2 = Utils.buildFlowRule(deviceId, appId, tableId, ipv6MulticastCriterion, setMcastGroupAction);
    // Insert rules.
    flowRuleService.applyFlowRules(rule1, rule2);
}
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)

Example 7 with FlowRule

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

the class Srv6Component method setUpMySidTable.

// --------------------------------------------------------------------------
// METHODS TO COMPLETE.
// 
// Complete the implementation wherever you see TODO.
// --------------------------------------------------------------------------
/**
 * Populate the My SID table from the network configuration for the
 * specified device.
 *
 * @param deviceId the device Id
 */
private void setUpMySidTable(DeviceId deviceId) {
    Ip6Address mySid = getMySid(deviceId);
    log.info("Adding mySid rule on {} (sid {})...", deviceId, mySid);
    // *** TODO EXERCISE 6
    // Fill in the table ID for the SRv6 my segment identifier table
    // ---- START SOLUTION ----
    String tableId = "IngressPipeImpl.srv6_my_sid";
    // ---- END SOLUTION ----
    // *** TODO EXERCISE 6
    // Modify the field and action id to match your P4Info
    // ---- START SOLUTION ----
    PiCriterion match = PiCriterion.builder().matchLpm(PiMatchFieldId.of("hdr.ipv6.dst_addr"), mySid.toOctets(), 128).build();
    PiTableAction action = PiAction.builder().withId(PiActionId.of("IngressPipeImpl.srv6_end")).build();
    // ---- END SOLUTION ----
    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) Ip6Address(org.onlab.packet.Ip6Address) FlowRule(org.onosproject.net.flow.FlowRule)

Example 8 with FlowRule

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

the class Srv6Component method insertSrv6InsertRule.

/**
 * Insert a SRv6 transit insert policy that will inject an SRv6 header for
 * packets destined to destIp.
 *
 * @param deviceId     device ID
 * @param destIp       target IP address for the SRv6 policy
 * @param prefixLength prefix length for the target IP
 * @param segmentList  list of SRv6 SIDs that make up the path
 */
public void insertSrv6InsertRule(DeviceId deviceId, Ip6Address destIp, int prefixLength, List<Ip6Address> segmentList) {
    if (segmentList.size() < 2 || segmentList.size() > 3) {
        throw new RuntimeException("List of " + segmentList.size() + " segments is not supported");
    }
    // *** TODO EXERCISE 6
    // Fill in the table ID for the SRv6 transit table.
    // ---- START SOLUTION ----
    String tableId = "IngressPipeImpl.srv6_transit";
    // ---- END SOLUTION ----
    // *** TODO EXERCISE 6
    // Modify match field, action id, and action parameters to match your P4Info.
    // ---- START SOLUTION ----
    PiCriterion match = PiCriterion.builder().matchLpm(PiMatchFieldId.of("hdr.ipv6.dst_addr"), destIp.toOctets(), prefixLength).build();
    List<PiActionParam> actionParams = Lists.newArrayList();
    for (int i = 0; i < segmentList.size(); i++) {
        PiActionParamId paramId = PiActionParamId.of("s" + (i + 1));
        PiActionParam param = new PiActionParam(paramId, segmentList.get(i).toOctets());
        actionParams.add(param);
    }
    PiAction action = PiAction.builder().withId(PiActionId.of("IngressPipeImpl.srv6_t_insert_" + segmentList.size())).withParameters(actionParams).build();
    // ---- END SOLUTION ----
    final FlowRule rule = Utils.buildFlowRule(deviceId, appId, tableId, match, action);
    flowRuleService.applyFlowRules(rule);
}
Also used : PiActionParamId(org.onosproject.net.pi.model.PiActionParamId) 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)

Example 9 with FlowRule

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

the class Ipv6SimpleRoutingComponent method setSwitchId.

private void setSwitchId(DeviceId deviceId, int sw_id) {
    log.info("Setting sw_id {}", sw_id);
    final String tableId = "IngressPipeImpl.sw_id_table";
    final int ETHERTYPE_IPV4 = 0x0800;
    final int MASK = 0xFFFF;
    final PiCriterion match = PiCriterion.builder().matchTernary(PiMatchFieldId.of("hdr.ethernet.ether_type"), ETHERTYPE_IPV4, MASK).build();
    final PiAction action = PiAction.builder().withId(PiActionId.of("IngressPipeImpl.set_sw_id")).withParameter(new PiActionParam(PiActionParamId.of("sw_id"), sw_id)).build();
    FlowRule flowRuleSwID = Utils.buildFlowRule(deviceId, appId, tableId, match, action);
    flowRuleService.applyFlowRules(flowRuleSwID);
}
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)

Example 10 with FlowRule

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

the class Ipv6SimpleRoutingComponent method setUpPath.

private void setUpPath(HostId srcId, HostId dstId) {
    Host src = hostService.getHost(srcId);
    Host dst = hostService.getHost(dstId);
    // Check if hosts are located at the same switch
    log.info("Src switch id={} and Dst switch id={}", src.location().deviceId(), dst.location().deviceId());
    if (src.location().deviceId().toString().equals(dst.location().deviceId().toString())) {
        PortNumber outPort = dst.location().port();
        DeviceId devId = dst.location().deviceId();
        FlowRule nextHopRule = createL2NextHopRule(devId, dst.mac(), outPort);
        flowRuleService.applyFlowRules(nextHopRule);
        log.info("Hosts in the same switch");
        return;
    }
    // Get all the available paths between two given hosts
    // A path is a collection of links
    Set<Path> paths = topologyService.getPaths(topologyService.currentTopology(), src.location().deviceId(), dst.location().deviceId());
    if (paths.isEmpty()) {
        // If there are no paths, display a warn and exit
        log.warn("No path found");
        return;
    }
    // Pick a path that does not lead back to where we
    // came from; if no such path,display a warn and exit
    Path path = pickForwardPathIfPossible(paths, src.location().port());
    if (path == null) {
        log.warn("Don't know where to go from here {} for {} -> {}", src.location(), srcId, dstId);
        return;
    }
    // Install rules in the path
    List<Link> pathLinks = path.links();
    for (Link l : pathLinks) {
        PortNumber outPort = l.src().port();
        DeviceId devId = l.src().deviceId();
        FlowRule nextHopRule = createL2NextHopRule(devId, dst.mac(), outPort);
        flowRuleService.applyFlowRules(nextHopRule);
    }
    // Install rule in the last device (where dst is located)
    PortNumber outPort = dst.location().port();
    DeviceId devId = dst.location().deviceId();
    FlowRule nextHopRule = createL2NextHopRule(devId, dst.mac(), outPort);
    flowRuleService.applyFlowRules(nextHopRule);
}
Also used : Path(org.onosproject.net.Path) DeviceId(org.onosproject.net.DeviceId) Host(org.onosproject.net.Host) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber) Link(org.onosproject.net.Link)

Aggregations

FlowRule (org.onosproject.net.flow.FlowRule)432 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)279 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)226 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)225 TrafficSelector (org.onosproject.net.flow.TrafficSelector)193 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)189 Test (org.junit.Test)173 List (java.util.List)101 DeviceId (org.onosproject.net.DeviceId)101 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)90 Intent (org.onosproject.net.intent.Intent)88 Collection (java.util.Collection)75 Collectors (java.util.stream.Collectors)75 CoreService (org.onosproject.core.CoreService)72 Collections (java.util.Collections)70 VlanId (org.onlab.packet.VlanId)65 FlowEntry (org.onosproject.net.flow.FlowEntry)63 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)61 PortNumber (org.onosproject.net.PortNumber)57 ArrayList (java.util.ArrayList)56