use of org.onosproject.driver.extensions.Ofdpa3CopyField.OXM_ID_PACKET_REG_1 in project onos by opennetworkinglab.
the class Ofdpa2Pipeline method processEgress.
/**
* In the OF-DPA 2.0 pipeline, egress forwarding objectives go to the
* egress tables.
* @param fwd the forwarding objective of type 'egress'
* @return a collection of flow rules to be sent to the switch. An empty
* collection may be returned if there is a problem in processing
* the flow rule
*/
protected Collection<FlowRule> processEgress(ForwardingObjective fwd) {
log.debug("Processing egress forwarding objective:{} in dev:{}", fwd, deviceId);
List<FlowRule> rules = new ArrayList<>();
// Build selector
TrafficSelector.Builder sb = DefaultTrafficSelector.builder();
VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) fwd.selector().getCriterion(Criterion.Type.VLAN_VID);
if (vlanIdCriterion == null) {
log.error("Egress forwarding objective:{} must include vlanId", fwd.id());
fail(fwd, ObjectiveError.BADPARAMS);
return rules;
}
Optional<Instruction> outInstr = fwd.treatment().allInstructions().stream().filter(instruction -> instruction instanceof OutputInstruction).findFirst();
if (!outInstr.isPresent()) {
log.error("Egress forwarding objective:{} must include output port", fwd.id());
fail(fwd, ObjectiveError.BADPARAMS);
return rules;
}
PortNumber portNumber = ((OutputInstruction) outInstr.get()).port();
sb.matchVlanId(vlanIdCriterion.vlanId());
OfdpaMatchActsetOutput actsetOutput = new OfdpaMatchActsetOutput(portNumber);
sb.extension(actsetOutput, deviceId);
sb.extension(new OfdpaMatchAllowVlanTranslation(ALLOW_VLAN_TRANSLATION), deviceId);
// Build a flow rule for Egress VLAN Flow table
TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
tb.transition(EGRESS_DSCP_PCP_REMARK_FLOW_TABLE);
if (fwd.treatment() != null) {
for (Instruction instr : fwd.treatment().allInstructions()) {
if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2SubType.VLAN_ID) {
tb.immediate().add(instr);
}
if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2SubType.VLAN_PUSH) {
tb.immediate().pushVlan();
EthType ethType = ((L2ModificationInstruction.ModVlanHeaderInstruction) instr).ethernetType();
if (ethType.equals(EtherType.QINQ.ethType())) {
// Build a flow rule for Egress TPID Flow table
TrafficSelector tpidSelector = DefaultTrafficSelector.builder().extension(actsetOutput, deviceId).matchVlanId(VlanId.ANY).build();
TrafficTreatment tpidTreatment = DefaultTrafficTreatment.builder().extension(new Ofdpa3CopyField(COPY_FIELD_NBITS, COPY_FIELD_OFFSET, COPY_FIELD_OFFSET, OXM_ID_VLAN_VID, OXM_ID_PACKET_REG_1), deviceId).popVlan().pushVlan(EtherType.QINQ.ethType()).extension(new Ofdpa3CopyField(COPY_FIELD_NBITS, COPY_FIELD_OFFSET, COPY_FIELD_OFFSET, OXM_ID_PACKET_REG_1, OXM_ID_VLAN_VID), deviceId).build();
FlowRule.Builder tpidRuleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(tpidSelector).withTreatment(tpidTreatment).makePermanent().forTable(EGRESS_TPID_FLOW_TABLE);
rules.add(tpidRuleBuilder.build());
}
}
}
}
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(sb.build()).withTreatment(tb.build()).makePermanent().forTable(EGRESS_VLAN_FLOW_TABLE);
rules.add(ruleBuilder.build());
return rules;
}
Aggregations