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);
}
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;
}
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);
}
Aggregations