Search in sources :

Example 1 with Ofdpa3MatchMplsL2Port

use of org.onosproject.driver.extensions.Ofdpa3MatchMplsL2Port in project onos by opennetworkinglab.

the class Ofdpa3Pipeline method processInitPwVersatile.

/**
 * Helper method to process the pw forwarding objectives.
 *
 * @param forwardingObjective the fw objective to process
 * @return a singleton list of flow rule
 */
private Collection<FlowRule> processInitPwVersatile(ForwardingObjective forwardingObjective) {
    // We retrieve the matching criteria for mpls l2 port.
    TunnelIdCriterion tunnelIdCriterion = (TunnelIdCriterion) forwardingObjective.selector().getCriterion(TUNNEL_ID);
    PortCriterion portCriterion = (PortCriterion) forwardingObjective.selector().getCriterion(IN_PORT);
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    int mplsLogicalPort;
    long tunnelId;
    // Mpls tunnel ids according to the OFDPA manual have to be
    // in the range [2^17-1, 2^16].
    tunnelId = MPLS_TUNNEL_ID_BASE | tunnelIdCriterion.tunnelId();
    if (tunnelId > MPLS_TUNNEL_ID_MAX) {
        log.error("Pw Versatile Forwarding Objective must include tunnel id < {}", MPLS_TUNNEL_ID_MAX);
        fail(forwardingObjective, ObjectiveError.BADPARAMS);
        return Collections.emptySet();
    }
    // Port has not been null.
    if (portCriterion == null) {
        log.error("Pw Versatile Forwarding Objective must include port");
        fail(forwardingObjective, ObjectiveError.BADPARAMS);
        return Collections.emptySet();
    }
    // 0x0000XXXX is UNI interface.
    if (portCriterion.port().toLong() > MPLS_UNI_PORT_MAX) {
        log.error("Pw Versatile Forwarding Objective invalid logical port {}", portCriterion.port().toLong());
        fail(forwardingObjective, ObjectiveError.BADPARAMS);
        return Collections.emptySet();
    }
    mplsLogicalPort = ((int) portCriterion.port().toLong());
    if (forwardingObjective.nextId() == null) {
        log.error("Pw Versatile Forwarding Objective must contain nextId ", forwardingObjective.nextId());
        fail(forwardingObjective, ObjectiveError.BADPARAMS);
        return Collections.emptySet();
    }
    // We don't expect a treatment.
    if (forwardingObjective.treatment() != null && !forwardingObjective.treatment().equals(DefaultTrafficTreatment.emptyTreatment())) {
        log.error("Pw Versatile Forwarding Objective cannot contain a treatment ", forwardingObjective.nextId());
        fail(forwardingObjective, ObjectiveError.BADPARAMS);
        return Collections.emptySet();
    }
    // We retrieve the l2 vpn group and point the mpls
    // l2 port to this.
    NextGroup next = getGroupForNextObjective(forwardingObjective.nextId());
    if (next == null) {
        log.warn("next-id:{} not found in dev:{}", forwardingObjective.nextId(), deviceId);
        fail(forwardingObjective, ObjectiveError.GROUPMISSING);
        return Collections.emptySet();
    }
    List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
    Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
    if (group == null) {
        log.warn("Group with key:{} for next-id:{} not found in dev:{}", gkeys.get(0).peekFirst(), forwardingObjective.nextId(), deviceId);
        fail(forwardingObjective, ObjectiveError.GROUPMISSING);
        return Collections.emptySet();
    }
    // We prepare the flow rule for the mpls l2 port table.
    selector.matchTunnelId(tunnelId);
    selector.extension(new Ofdpa3MatchMplsL2Port(mplsLogicalPort), deviceId);
    // This should not be necessary but without we receive an error
    treatment.extension(new Ofdpa3SetQosIndex(0), deviceId);
    treatment.transition(MPLS_L2_PORT_PCP_TRUST_FLOW_TABLE);
    treatment.deferred().group(group.id());
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(forwardingObjective.appId()).withPriority(MPLS_L2_PORT_PRIORITY).forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).makePermanent().forTable(MPLS_L2_PORT_FLOW_TABLE);
    return Collections.singletonList(ruleBuilder.build());
}
Also used : NextGroup(org.onosproject.net.behaviour.NextGroup) NextGroup(org.onosproject.net.behaviour.NextGroup) Group(org.onosproject.net.group.Group) TunnelIdCriterion(org.onosproject.net.flow.criteria.TunnelIdCriterion) Ofdpa3MatchMplsL2Port(org.onosproject.driver.extensions.Ofdpa3MatchMplsL2Port) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Deque(java.util.Deque) Ofdpa3SetQosIndex(org.onosproject.driver.extensions.Ofdpa3SetQosIndex) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule)

Aggregations

Deque (java.util.Deque)1 Ofdpa3MatchMplsL2Port (org.onosproject.driver.extensions.Ofdpa3MatchMplsL2Port)1 Ofdpa3SetQosIndex (org.onosproject.driver.extensions.Ofdpa3SetQosIndex)1 NextGroup (org.onosproject.net.behaviour.NextGroup)1 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)1 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)1 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)1 FlowRule (org.onosproject.net.flow.FlowRule)1 TrafficSelector (org.onosproject.net.flow.TrafficSelector)1 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)1 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)1 TunnelIdCriterion (org.onosproject.net.flow.criteria.TunnelIdCriterion)1 Group (org.onosproject.net.group.Group)1