use of org.onosproject.driver.extensions.Ofdpa3SetMplsType in project onos by opennetworkinglab.
the class Ofdpa2Pipeline method processEthTypeSpecificInternal.
/**
* Internal implementation of processEthTypeSpecific.
* <p>
* Wildcarded IPv4_DST is not supported in OFDPA i12. Therefore, we break
* the rule into 0.0.0.0/1 and 128.0.0.0/1.
* The allowDefaultRoute must be set to false for OFDPA i12.
* </p>
*
* @param fwd the forwarding objective
* @param allowDefaultRoute allow wildcarded IPv4_DST or not
* @param mplsNextTable next MPLS table
* @return A collection of flow rules, or an empty set
*/
protected Collection<FlowRule> processEthTypeSpecificInternal(ForwardingObjective fwd, boolean allowDefaultRoute, int mplsNextTable) {
TrafficSelector selector = fwd.selector();
EthTypeCriterion ethType = (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
boolean emptyGroup = false;
int forTableId;
TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder();
TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
TrafficSelector.Builder complementarySelector = DefaultTrafficSelector.builder();
if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
if (buildIpv4Selector(filteredSelector, complementarySelector, fwd, allowDefaultRoute) < 0) {
return Collections.emptyList();
}
// We need to set properly the next table
IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip();
if (ipv4Dst.isMulticast()) {
forTableId = MULTICAST_ROUTING_TABLE;
} else {
forTableId = UNICAST_ROUTING_TABLE;
}
// TODO decrementing IP ttl is done automatically for routing, this
// action is ignored or rejected in ofdpa as it is not fully implemented
// if (fwd.treatment() != null) {
// for (Instruction instr : fwd.treatment().allInstructions()) {
// if (instr instanceof L3ModificationInstruction &&
// ((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) {
// tb.deferred().add(instr);
// }
// }
// }
} else if (ethType.ethType().toShort() == Ethernet.TYPE_IPV6) {
if (buildIpv6Selector(filteredSelector, fwd) < 0) {
return Collections.emptyList();
}
// We need to set the proper next table
IpPrefix ipv6Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV6_DST)).ip();
if (ipv6Dst.isMulticast()) {
forTableId = MULTICAST_ROUTING_TABLE;
} else {
forTableId = UNICAST_ROUTING_TABLE;
}
// TODO decrementing IP ttl is done automatically for routing, this
// action is ignored or rejected in ofdpa as it is not fully implemented
// if (fwd.treatment() != null) {
// for (Instruction instr : fwd.treatment().allInstructions()) {
// if (instr instanceof L3ModificationInstruction &&
// ((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) {
// tb.deferred().add(instr);
// }
// }
// }
} else {
filteredSelector.matchEthType(Ethernet.MPLS_UNICAST).matchMplsLabel(((MplsCriterion) selector.getCriterion(Criterion.Type.MPLS_LABEL)).label());
MplsBosCriterion bos = (MplsBosCriterion) selector.getCriterion(MPLS_BOS);
if (bos != null && requireMplsBosMatch()) {
filteredSelector.matchMplsBos(bos.mplsBos());
}
forTableId = MPLS_TABLE_1;
log.debug("processing MPLS specific forwarding objective {} -> next:{}" + " in dev {}", fwd.id(), fwd.nextId(), deviceId);
if (fwd.treatment() != null) {
for (Instruction instr : fwd.treatment().allInstructions()) {
if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2SubType.MPLS_POP) {
// setting the MPLS_TYPE so pop can happen down the pipeline
if (requireMplsPop()) {
if (mplsNextTable == MPLS_TYPE_TABLE && isNotMplsBos(selector)) {
tb.immediate().popMpls();
}
} else {
// Skip mpls pop action for mpls_unicast label
if (instr instanceof ModMplsHeaderInstruction && !((ModMplsHeaderInstruction) instr).ethernetType().equals(EtherType.MPLS_UNICAST.ethType())) {
tb.immediate().add(instr);
}
}
}
if (requireMplsTtlModification()) {
if (instr instanceof L3ModificationInstruction && ((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) {
// FIXME Should modify the app to send the correct DEC_MPLS_TTL instruction
tb.immediate().decMplsTtl();
}
if (instr instanceof L3ModificationInstruction && ((L3ModificationInstruction) instr).subtype() == L3SubType.TTL_IN) {
tb.immediate().add(instr);
}
}
}
}
}
if (fwd.nextId() != null) {
NextGroup next = getGroupForNextObjective(fwd.nextId());
if (next != null) {
List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
// we only need the top level group's key to point the flow to it
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(), fwd.nextId(), deviceId);
fail(fwd, ObjectiveError.GROUPMISSING);
return Collections.emptySet();
}
if (isNotMplsBos(selector) && group.type().equals(SELECT)) {
log.warn("SR CONTINUE case cannot be handled as MPLS ECMP " + "is not implemented in OF-DPA yet. Aborting flow {} -> next:{} " + "in this device {}", fwd.id(), fwd.nextId(), deviceId);
fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
return Collections.emptySet();
}
tb.deferred().group(group.id());
// retrying flows may be necessary due to bug CORD-554
if (gkeys.size() == 1 && gkeys.get(0).size() == 1) {
if (shouldRetry()) {
log.warn("Found empty group 0x{} in dev:{} .. will retry fwd:{}", Integer.toHexString(group.id().id()), deviceId, fwd.id());
emptyGroup = true;
}
}
} else {
log.warn("Cannot find group for nextId:{} in dev:{}. Aborting fwd:{}", fwd.nextId(), deviceId, fwd.id());
fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
return Collections.emptySet();
}
}
if (forTableId == MPLS_TABLE_1) {
if (mplsNextTable == MPLS_L3_TYPE_TABLE) {
Ofdpa3SetMplsType setMplsType = new Ofdpa3SetMplsType(Ofdpa3MplsType.L3_PHP);
// set mpls type as apply_action
tb.immediate().extension(setMplsType, deviceId);
}
tb.transition(mplsNextTable);
} else {
tb.transition(ACL_TABLE);
}
if (fwd.treatment() != null && fwd.treatment().clearedDeferred()) {
if (supportsUnicastBlackHole()) {
tb.wipeDeferred();
} else {
log.warn("Clear Deferred is not supported Unicast Routing Table on device {}", deviceId);
return Collections.emptySet();
}
}
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(filteredSelector.build()).withTreatment(tb.build()).forTable(forTableId);
if (fwd.permanent()) {
ruleBuilder.makePermanent();
} else {
ruleBuilder.makeTemporary(fwd.timeout());
}
Collection<FlowRule> flowRuleCollection = new ArrayList<>();
flowRuleCollection.add(ruleBuilder.build());
if (!allowDefaultRoute) {
flowRuleCollection.add(defaultRoute(fwd, complementarySelector, forTableId, tb));
log.debug("Default rule 0.0.0.0/0 is being installed two rules");
}
if (emptyGroup) {
retryExecutorService.schedule(new RetryFlows(fwd, flowRuleCollection), RETRY_MS, TimeUnit.MILLISECONDS);
}
return flowRuleCollection;
}
use of org.onosproject.driver.extensions.Ofdpa3SetMplsType in project onos by opennetworkinglab.
the class Ofdpa3Pipeline method processPwFilter.
/**
* Method to process the pw related filtering objectives.
*
* @param portCriterion the in port match
* @param innerVlanIdCriterion the inner vlan match
* @param outerVlanIdCriterion the outer vlan match
* @param tunnelId the tunnel id
* @param applicationId the application id
* @param egressVlan the vlan to modify, was passed in metadata
* @return a list of flow rules to install
*/
private List<FlowRule> processPwFilter(PortCriterion portCriterion, VlanIdCriterion innerVlanIdCriterion, VlanIdCriterion outerVlanIdCriterion, long tunnelId, ApplicationId applicationId, VlanId egressVlan) {
FlowRule vlan1FlowRule;
int mplsLogicalPort = ((int) portCriterion.port().toLong());
// We have to match on the inner vlan and outer vlan at the same time.
// Ofdpa supports this through the OVID meta-data type.
ImmutableList<FlowRule> toReturn;
// pseudowire configured with double tagged vlans
if (!(innerVlanIdCriterion.vlanId().equals(VlanId.NONE)) && !(outerVlanIdCriterion.vlanId().equals(VlanId.NONE))) {
log.info("Installing filter objective for double tagged CE for tunnel {}", tunnelId);
TrafficSelector.Builder vlan1Selector = DefaultTrafficSelector.builder().matchInPort(portCriterion.port()).matchVlanId(innerVlanIdCriterion.vlanId()).extension(new Ofdpa3MatchOvid(outerVlanIdCriterion.vlanId()), deviceId);
// TODO understand for the future how to manage the vlan rewrite.
TrafficTreatment.Builder vlan1Treatment = DefaultTrafficTreatment.builder().pushVlan().setVlanId(egressVlan).extension(new Ofdpa3SetMplsType(VPWS), deviceId).extension(new Ofdpa3SetMplsL2Port(mplsLogicalPort), deviceId).setTunnelId(tunnelId).transition(MPLS_L2_PORT_FLOW_TABLE);
vlan1FlowRule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(vlan1Selector.build()).withTreatment(vlan1Treatment.build()).withPriority(DEFAULT_PRIORITY).fromApp(applicationId).makePermanent().forTable(VLAN_1_TABLE).build();
// Finally we create the flow rule for the vlan table.
FlowRule vlanFlowRule;
// We have to match on the outer vlan.
TrafficSelector.Builder vlanSelector = DefaultTrafficSelector.builder().matchInPort(portCriterion.port()).matchVlanId(outerVlanIdCriterion.vlanId());
// TODO understand for the future how to manage the vlan rewrite.
TrafficTreatment.Builder vlanTreatment = DefaultTrafficTreatment.builder().popVlan().extension(new Ofdpa3SetOvid(outerVlanIdCriterion.vlanId()), deviceId).transition(VLAN_1_TABLE);
vlanFlowRule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(vlanSelector.build()).withTreatment(vlanTreatment.build()).withPriority(DEFAULT_PRIORITY).fromApp(applicationId).makePermanent().forTable(VLAN_TABLE).build();
return ImmutableList.of(vlan1FlowRule, vlanFlowRule);
} else if (!(innerVlanIdCriterion.vlanId().equals(VlanId.NONE)) && (outerVlanIdCriterion.vlanId().equals(VlanId.NONE))) {
log.info("Installing filter objective for single tagged CE for tunnel {}", tunnelId);
TrafficSelector.Builder singleVlanSelector = DefaultTrafficSelector.builder().matchInPort(portCriterion.port()).matchVlanId(innerVlanIdCriterion.vlanId());
TrafficTreatment.Builder singleVlanTreatment = DefaultTrafficTreatment.builder().extension(new Ofdpa3SetMplsType(VPWS), deviceId).extension(new Ofdpa3SetMplsL2Port(mplsLogicalPort), deviceId).setTunnelId(tunnelId).transition(MPLS_L2_PORT_FLOW_TABLE);
vlan1FlowRule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(singleVlanSelector.build()).withTreatment(singleVlanTreatment.build()).withPriority(DEFAULT_PRIORITY).fromApp(applicationId).makePermanent().forTable(VLAN_TABLE).build();
return ImmutableList.of(vlan1FlowRule);
} else if ((innerVlanIdCriterion.vlanId().equals(VlanId.NONE)) && (outerVlanIdCriterion.vlanId().equals(VlanId.NONE))) {
TrafficSelector.Builder singleVlanSelector = DefaultTrafficSelector.builder().matchInPort(portCriterion.port()).matchVlanId(innerVlanIdCriterion.vlanId());
TrafficTreatment.Builder singleVlanTreatment = DefaultTrafficTreatment.builder().extension(new Ofdpa3SetMplsType(VPWS), deviceId).extension(new Ofdpa3SetMplsL2Port(mplsLogicalPort), deviceId).setTunnelId(tunnelId).transition(MPLS_L2_PORT_FLOW_TABLE);
vlan1FlowRule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(singleVlanSelector.build()).withTreatment(singleVlanTreatment.build()).withPriority(DEFAULT_PRIORITY).fromApp(applicationId).makePermanent().forTable(VLAN_TABLE).build();
return ImmutableList.of(vlan1FlowRule);
} else {
// failure...
return Collections.emptyList();
}
}
use of org.onosproject.driver.extensions.Ofdpa3SetMplsType in project onos by opennetworkinglab.
the class Ofdpa3Pipeline method processTermPwVersatile.
private Collection<FlowRule> processTermPwVersatile(ForwardingObjective forwardingObjective, ModTunnelIdInstruction modTunnelIdInstruction, OutputInstruction outputInstruction) {
TrafficTreatment.Builder flowTreatment;
TrafficSelector.Builder flowSelector;
// We divide the mpls actions from the tunnel actions. We need
// this to order the actions in the final treatment.
TrafficTreatment.Builder mplsTreatment = DefaultTrafficTreatment.builder();
createMplsTreatment(forwardingObjective.treatment(), mplsTreatment);
// The match of the forwarding objective is ready to go.
flowSelector = DefaultTrafficSelector.builder(forwardingObjective.selector());
// We verify the tunnel id and mpls port are correct.
long tunnelId = MPLS_TUNNEL_ID_BASE | modTunnelIdInstruction.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();
}
// 0x0002XXXX is NNI interface.
int mplsLogicalPort = ((int) outputInstruction.port().toLong()) | MPLS_NNI_PORT_BASE;
if (mplsLogicalPort > MPLS_NNI_PORT_MAX) {
log.error("Pw Versatile Forwarding Objective invalid logical port {}", mplsLogicalPort);
fail(forwardingObjective, ObjectiveError.BADPARAMS);
return Collections.emptySet();
}
// Next id cannot be null.
if (forwardingObjective.nextId() == null) {
log.error("Pw Versatile Forwarding Objective must contain nextId ", forwardingObjective.nextId());
fail(forwardingObjective, ObjectiveError.BADPARAMS);
return Collections.emptySet();
}
// We retrieve the l2 interface group and point the mpls
// flow 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 treatment for the mpls flow table.
// The order of the actions has to be strictly this
// according to the OFDPA 2.0 specification.
flowTreatment = DefaultTrafficTreatment.builder(mplsTreatment.build());
flowTreatment.extension(new Ofdpa3PopCw(), deviceId);
// Even though the specification and the xml/json files
// specify is allowed, the switch rejects the flow. In the
// OFDPA 3.0 EA0 version was necessary
// flowTreatment.popVlan();
flowTreatment.extension(new Ofdpa3PopL2Header(), deviceId);
flowTreatment.setTunnelId(tunnelId);
flowTreatment.extension(new Ofdpa3SetMplsL2Port(mplsLogicalPort), deviceId);
flowTreatment.extension(new Ofdpa3SetMplsType(VPWS), deviceId);
flowTreatment.transition(MPLS_TYPE_TABLE);
flowTreatment.deferred().group(group.id());
// We prepare the flow rule for the mpls table.
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(forwardingObjective.appId()).withPriority(forwardingObjective.priority()).forDevice(deviceId).withSelector(flowSelector.build()).withTreatment(flowTreatment.build()).makePermanent().forTable(MPLS_TABLE_1);
return Collections.singletonList(ruleBuilder.build());
}
use of org.onosproject.driver.extensions.Ofdpa3SetMplsType in project onos by opennetworkinglab.
the class FlowViewMessageHandlerTest method renderExtensionInstruction.
@Test
public void renderExtensionInstruction() {
title("renderExtensionInstruction");
ExtensionTreatment extn = new Ofdpa3SetMplsType((short) 32);
DeviceId devid = deviceId(DEV_OF_204);
instr = Instructions.extension(extn, devid);
string = instr.toString();
render = handler.renderInstructionForDisplay(instr);
print(string);
print(render);
assertEquals("unexpected toString", EXT_FULL_STR, string);
assertEquals("unexpected short string", EXT_NO_DPID, render);
}
Aggregations