Search in sources :

Example 6 with OfdpaMatchVlanVid

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

the class Ofdpa2Pipeline method processVlanIdFilter.

/**
 * Internal implementation of processVlanIdFilter.
 * <p>
 * The is_present bit in set_vlan_vid action is required to be 0 in OFDPA i12.
 * Since it is non-OF spec, we need an extension treatment for that.
 * The useVlanExtension must be set to false for OFDPA i12.
 * </p>
 * <p>
 * NOTE: Separate VLAN filtering rules and assignment rules
 * into different stages in order to guarantee that filtering rules
 * always go first, as required by OFDPA.
 * </p>
 *
 * @param portCriterion       port on device for which this filter is programmed
 * @param vidCriterion        vlan assigned to port, or NONE for untagged
 * @param assignedVlan        assigned vlan-id for untagged packets
 * @param applicationId       for application programming this filter
 * @param install   indicates whether to add or remove the objective
 * @return stages of flow rules for port-vlan filters
 */
protected List<List<FlowRule>> processVlanIdFilter(PortCriterion portCriterion, VlanIdCriterion vidCriterion, VlanId assignedVlan, ApplicationId applicationId, boolean install) {
    List<FlowRule> filteringRules = new ArrayList<>();
    List<FlowRule> assignmentRules = new ArrayList<>();
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    TrafficSelector.Builder preSelector = null;
    TrafficTreatment.Builder preTreatment = null;
    treatment.transition(TMAC_TABLE);
    if (vidCriterion.vlanId() == VlanId.NONE) {
        // untagged packets are assigned vlans
        preSelector = DefaultTrafficSelector.builder();
        if (requireVlanExtensions()) {
            OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(VlanId.NONE);
            selector.extension(ofdpaMatchVlanVid, deviceId);
            OfdpaSetVlanVid ofdpaSetVlanVid = new OfdpaSetVlanVid(assignedVlan);
            treatment.extension(ofdpaSetVlanVid, deviceId);
            OfdpaMatchVlanVid preOfdpaMatchVlanVid = new OfdpaMatchVlanVid(assignedVlan);
            preSelector.extension(preOfdpaMatchVlanVid, deviceId);
        } else {
            selector.matchVlanId(VlanId.NONE);
            treatment.setVlanId(assignedVlan);
            preSelector.matchVlanId(assignedVlan);
        }
        preTreatment = DefaultTrafficTreatment.builder().transition(TMAC_TABLE);
    } else {
        if (requireVlanExtensions()) {
            OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vidCriterion.vlanId());
            selector.extension(ofdpaMatchVlanVid, deviceId);
        } else {
            selector.matchVlanId(vidCriterion.vlanId());
        }
        if (!assignedVlan.equals(vidCriterion.vlanId())) {
            if (requireVlanExtensions()) {
                OfdpaSetVlanVid ofdpaSetVlanVid = new OfdpaSetVlanVid(assignedVlan);
                treatment.extension(ofdpaSetVlanVid, deviceId);
            } else {
                treatment.setVlanId(assignedVlan);
            }
        }
    }
    // ofdpa cannot match on ALL portnumber, so we need to use separate
    // rules for each port.
    List<PortNumber> portnums = new ArrayList<>();
    if (portCriterion != null) {
        if (PortNumber.ALL.equals(portCriterion.port())) {
            for (Port port : deviceService.getPorts(deviceId)) {
                if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) {
                    portnums.add(port.number());
                }
            }
        } else {
            portnums.add(portCriterion.port());
        }
    } else {
        log.warn("Filtering Objective missing Port Criterion . " + "VLAN Table cannot be programmed for {}", deviceId);
    }
    for (PortNumber pnum : portnums) {
        // create rest of flowrule
        selector.matchInPort(pnum);
        FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(DEFAULT_PRIORITY).fromApp(applicationId).makePermanent().forTable(VLAN_TABLE).build();
        assignmentRules.add(rule);
        if (preSelector != null) {
            preSelector.matchInPort(pnum);
            FlowRule preRule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(preSelector.build()).withTreatment(preTreatment.build()).withPriority(DEFAULT_PRIORITY).fromApp(applicationId).makePermanent().forTable(VLAN_TABLE).build();
            filteringRules.add(preRule);
        }
    }
    return install ? ImmutableList.of(filteringRules, assignmentRules) : ImmutableList.of(assignmentRules, filteringRules);
}
Also used : OfdpaSetVlanVid(org.onosproject.driver.extensions.OfdpaSetVlanVid) Port(org.onosproject.net.Port) ArrayList(java.util.ArrayList) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PortNumber(org.onosproject.net.PortNumber) OfdpaMatchVlanVid(org.onosproject.driver.extensions.OfdpaMatchVlanVid)

Example 7 with OfdpaMatchVlanVid

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

the class Ofdpa2Pipeline method buildTmacRuleForMcastFromUnicast.

private FlowRule buildTmacRuleForMcastFromUnicast(FlowRule tmacRuleForUnicast, ApplicationId applicationId) {
    final TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    final TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    FlowRule rule;
    // Build the selector
    for (Criterion criterion : tmacRuleForUnicast.selector().criteria()) {
        if (criterion instanceof VlanIdCriterion) {
            if (requireVlanExtensions()) {
                OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(((VlanIdCriterion) criterion).vlanId());
                selector.extension(ofdpaMatchVlanVid, deviceId);
            } else {
                selector.add(criterion);
            }
        } else if (criterion instanceof EthTypeCriterion) {
            selector.add(criterion);
            if (Objects.equals(((EthTypeCriterion) criterion).ethType(), EtherType.IPV4.ethType())) {
                selector.matchEthDstMasked(IPV4_MULTICAST, IPV4_MULTICAST_MASK);
            } else if (Objects.equals(((EthTypeCriterion) criterion).ethType(), EtherType.IPV6.ethType())) {
                selector.matchEthDstMasked(IPV6_MULTICAST, IPV6_MULTICAST_MASK);
            } else {
                // We don't need for mpls rules
                return null;
            }
        }
    }
    // Build the treatment
    treatment.transition(MULTICAST_ROUTING_TABLE);
    // Build the flowrule
    rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(DEFAULT_PRIORITY).fromApp(applicationId).makePermanent().forTable(TMAC_TABLE).build();
    log.debug("Building TMac Mcast flowRule {}", rule);
    return rule;
}
Also used : EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) Icmpv6CodeCriterion(org.onosproject.net.flow.criteria.Icmpv6CodeCriterion) MplsBosCriterion(org.onosproject.net.flow.criteria.MplsBosCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Icmpv6TypeCriterion(org.onosproject.net.flow.criteria.Icmpv6TypeCriterion) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OfdpaMatchVlanVid(org.onosproject.driver.extensions.OfdpaMatchVlanVid) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Example 8 with OfdpaMatchVlanVid

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

the class Ofdpa3Pipeline method processDoubleVlanIdFilter.

/**
 * Internal implementation of processDoubleVlanIdFilter.
 *
 * @param portCriterion       port on device for which this filter is programmed
 * @param innerVidCriterion   inner vlan
 * @param outerVidCriterion   outer vlan
 * @param popVlan             true if outer vlan header needs to be removed
 * @param applicationId       for application programming this filter
 * @return flow rules for port-vlan filters
 */
private List<FlowRule> processDoubleVlanIdFilter(PortCriterion portCriterion, VlanIdCriterion innerVidCriterion, VlanIdCriterion outerVidCriterion, boolean popVlan, ApplicationId applicationId) {
    TrafficSelector.Builder outerSelector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder outerTreatment = DefaultTrafficTreatment.builder();
    TrafficSelector.Builder innerSelector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder innerTreatment = DefaultTrafficTreatment.builder();
    VlanId outerVlanId = outerVidCriterion.vlanId();
    VlanId innerVlanId = innerVidCriterion.vlanId();
    PortNumber portNumber = portCriterion.port();
    // Check arguments
    if (PortNumber.ALL.equals(portNumber) || outerVlanId.equals(VlanId.NONE) || innerVlanId.equals(VlanId.NONE)) {
        log.warn("Incomplete Filtering Objective. " + "VLAN Table cannot be programmed for {}", deviceId);
        return ImmutableList.of();
    } else {
        outerSelector.matchInPort(portNumber);
        innerSelector.matchInPort(portNumber);
        outerTreatment.transition(VLAN_1_TABLE);
        innerTreatment.transition(TMAC_TABLE);
        if (requireVlanExtensions()) {
            OfdpaMatchVlanVid ofdpaOuterMatchVlanVid = new OfdpaMatchVlanVid(outerVlanId);
            outerSelector.extension(ofdpaOuterMatchVlanVid, deviceId);
            OfdpaMatchVlanVid ofdpaInnerMatchVlanVid = new OfdpaMatchVlanVid(innerVlanId);
            innerSelector.extension(ofdpaInnerMatchVlanVid, deviceId);
        } else {
            outerSelector.matchVlanId(outerVlanId);
            innerSelector.matchVlanId(innerVlanId);
        }
        innerSelector.extension(new Ofdpa3MatchOvid(outerVlanId), deviceId);
        outerTreatment.extension(new Ofdpa3SetOvid(outerVlanId), deviceId);
        if (popVlan) {
            outerTreatment.popVlan();
        }
    }
    FlowRule outerRule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(outerSelector.build()).withTreatment(outerTreatment.build()).withPriority(DEFAULT_PRIORITY).fromApp(applicationId).makePermanent().forTable(VLAN_TABLE).build();
    FlowRule innerRule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(innerSelector.build()).withTreatment(innerTreatment.build()).withPriority(DEFAULT_PRIORITY).fromApp(applicationId).makePermanent().forTable(VLAN_1_TABLE).build();
    return ImmutableList.of(outerRule, innerRule);
}
Also used : Ofdpa3SetOvid(org.onosproject.driver.extensions.Ofdpa3SetOvid) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PortNumber(org.onosproject.net.PortNumber) VlanId(org.onlab.packet.VlanId) OfdpaMatchVlanVid(org.onosproject.driver.extensions.OfdpaMatchVlanVid) Ofdpa3MatchOvid(org.onosproject.driver.extensions.Ofdpa3MatchOvid)

Aggregations

OfdpaMatchVlanVid (org.onosproject.driver.extensions.OfdpaMatchVlanVid)8 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)7 TrafficSelector (org.onosproject.net.flow.TrafficSelector)7 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)6 FlowRule (org.onosproject.net.flow.FlowRule)6 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)5 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)5 ArrayList (java.util.ArrayList)4 VlanId (org.onlab.packet.VlanId)4 PortNumber (org.onosproject.net.PortNumber)3 IPCriterion (org.onosproject.net.flow.criteria.IPCriterion)3 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)3 IpPrefix (org.onlab.packet.IpPrefix)2 Port (org.onosproject.net.Port)2 EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)2 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)2 Icmpv6CodeCriterion (org.onosproject.net.flow.criteria.Icmpv6CodeCriterion)2 Icmpv6TypeCriterion (org.onosproject.net.flow.criteria.Icmpv6TypeCriterion)2 TcpPortCriterion (org.onosproject.net.flow.criteria.TcpPortCriterion)2 UdpPortCriterion (org.onosproject.net.flow.criteria.UdpPortCriterion)2