use of org.onosproject.net.flow.instructions.Instruction in project onos by opennetworkinglab.
the class SoftRouterPipeline method processVersatile.
/**
* SoftRouter has a single versatile table - the filter table.
* This table can be used to filter entries that reach the next table (FIB table).
* It can also be used to punt packets to the controller and/or bypass
* the FIB table to forward out of a port.
*
* @param fwd The forwarding objective of type versatile
* @return A collection of flow rules meant to be delivered to the flowrule
* subsystem. May return empty collection in case of failures.
*/
private Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
log.debug("Received versatile fwd: to next:{}", fwd.nextId());
Collection<FlowRule> flowrules = new ArrayList<>();
if (fwd.nextId() == null && fwd.treatment() == null) {
log.error("Forwarding objective {} from {} must contain " + "nextId or Treatment", fwd.selector(), fwd.appId());
return Collections.emptySet();
}
int tableId = FILTER_TABLE;
// so that it only takes effect if the packet misses the FIB rules
if (fwd.treatment() != null && containsPunt(fwd.treatment()) && fwd.selector() != null && matchesIp(fwd.selector()) && !matchesControlTraffic(fwd.selector())) {
tableId = FIB_TABLE;
}
TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder();
if (fwd.treatment() != null) {
fwd.treatment().immediate().forEach(ins -> ttBuilder.add(ins));
}
// convert nextId to flow actions
if (fwd.nextId() != null) {
// only acceptable value is output to port
NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
if (next == null) {
log.error("next-id {} does not exist in store", fwd.nextId());
return Collections.emptySet();
}
TrafficTreatment nt = appKryo.deserialize(next.data());
if (nt == null) {
log.error("Error in deserializing next-id {}", fwd.nextId());
return Collections.emptySet();
}
for (Instruction ins : nt.allInstructions()) {
if (ins instanceof OutputInstruction) {
ttBuilder.add(ins);
}
}
}
FlowRule rule = DefaultFlowRule.builder().withSelector(fwd.selector()).withTreatment(ttBuilder.build()).forTable(tableId).makePermanent().forDevice(deviceId).fromApp(fwd.appId()).withPriority(fwd.priority()).build();
flowrules.add(rule);
return flowrules;
}
use of org.onosproject.net.flow.instructions.Instruction in project onos by opennetworkinglab.
the class SpringOpenTTP method processEthTypeSpecificObjective.
protected Collection<FlowRule> processEthTypeSpecificObjective(ForwardingObjective fwd) {
TrafficSelector selector = fwd.selector();
EthTypeCriterion ethType = (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
TrafficSelector.Builder filteredSelectorBuilder = DefaultTrafficSelector.builder();
int forTableId = -1;
if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
filteredSelectorBuilder = filteredSelectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip());
forTableId = ipv4UnicastTableId;
log.debug("processing IPv4 specific forwarding objective:{} in dev:{}", fwd.id(), deviceId);
} else {
filteredSelectorBuilder = filteredSelectorBuilder.matchEthType(Ethernet.MPLS_UNICAST).matchMplsLabel(((MplsCriterion) selector.getCriterion(Criterion.Type.MPLS_LABEL)).label());
if (selector.getCriterion(Criterion.Type.MPLS_BOS) != null) {
filteredSelectorBuilder.matchMplsBos(((MplsBosCriterion) selector.getCriterion(Type.MPLS_BOS)).mplsBos());
}
forTableId = mplsTableId;
log.debug("processing MPLS specific forwarding objective:{} in dev:{}", fwd.id(), deviceId);
}
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
if (fwd.treatment() != null) {
for (Instruction i : fwd.treatment().allInstructions()) {
treatmentBuilder.add(i);
}
}
if (fwd.nextId() != null) {
NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
if (next != null) {
SpringOpenGroup soGroup = appKryo.deserialize(next.data());
if (soGroup.dummy) {
log.debug("Adding {} flow-actions for fwd. obj. {} -> next:{} " + "in dev: {}", soGroup.treatment.allInstructions().size(), fwd.id(), fwd.nextId(), deviceId);
for (Instruction ins : soGroup.treatment.allInstructions()) {
treatmentBuilder.add(ins);
}
} else {
GroupKey key = soGroup.key;
Group group = groupService.getGroup(deviceId, key);
if (group == null) {
log.warn("The group left!");
fail(fwd, ObjectiveError.GROUPMISSING);
return Collections.emptySet();
}
treatmentBuilder.deferred().group(group.id());
log.debug("Adding OUTGROUP action to group:{} for fwd. obj. {} " + "for next:{} in dev: {}", group.id(), fwd.id(), fwd.nextId(), deviceId);
}
} else {
log.warn("processSpecific: No associated next objective object");
fail(fwd, ObjectiveError.GROUPMISSING);
return Collections.emptySet();
}
}
TrafficSelector filteredSelector = filteredSelectorBuilder.build();
TrafficTreatment treatment = treatmentBuilder.transition(aclTableId).build();
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(filteredSelector).withTreatment(treatment);
if (fwd.permanent()) {
ruleBuilder.makePermanent();
} else {
ruleBuilder.makeTemporary(fwd.timeout());
}
ruleBuilder.forTable(forTableId);
return Collections.singletonList(ruleBuilder.build());
}
use of org.onosproject.net.flow.instructions.Instruction in project onos by opennetworkinglab.
the class SpringOpenTTP method processVersatile.
private Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
log.debug("Processing versatile forwarding objective in dev:{}", deviceId);
TrafficSelector selector = fwd.selector();
EthTypeCriterion ethType = (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
if (ethType == null) {
log.error("Versatile forwarding objective must include ethType");
fail(fwd, ObjectiveError.UNKNOWN);
return Collections.emptySet();
}
if (fwd.treatment() == null && fwd.nextId() == null) {
log.error("VERSATILE forwarding objective needs next objective ID " + "or treatment.");
return Collections.emptySet();
}
// emulation of ACL table (for versatile fwd objective) requires
// overriding any previous instructions
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
treatmentBuilder.wipeDeferred();
if (fwd.nextId() != null) {
NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
if (next != null) {
SpringOpenGroup soGroup = appKryo.deserialize(next.data());
if (soGroup.dummy) {
// need to convert to flow-actions
for (Instruction ins : soGroup.treatment.allInstructions()) {
treatmentBuilder.add(ins);
}
} else {
GroupKey key = soGroup.key;
Group group = groupService.getGroup(deviceId, key);
if (group == null) {
log.warn("The group left!");
fail(fwd, ObjectiveError.GROUPMISSING);
return Collections.emptySet();
}
treatmentBuilder.deferred().group(group.id());
log.debug("Adding OUTGROUP action");
}
}
}
if (fwd.treatment() != null) {
if (fwd.treatment().allInstructions().size() == 1 && fwd.treatment().allInstructions().get(0).type() == Instruction.Type.OUTPUT) {
OutputInstruction o = (OutputInstruction) fwd.treatment().allInstructions().get(0);
if (o.port() == PortNumber.CONTROLLER) {
treatmentBuilder.popVlan();
treatmentBuilder.punt();
} else {
treatmentBuilder.add(o);
}
} else {
for (Instruction ins : fwd.treatment().allInstructions()) {
treatmentBuilder.add(ins);
}
}
}
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(fwd.selector()).withTreatment(treatmentBuilder.build());
if (fwd.permanent()) {
ruleBuilder.makePermanent();
} else {
ruleBuilder.makeTemporary(fwd.timeout());
}
ruleBuilder.forTable(aclTableId);
return Collections.singletonList(ruleBuilder.build());
}
use of org.onosproject.net.flow.instructions.Instruction in project onos by opennetworkinglab.
the class SpringOpenTTPDell method processSpecific.
@Override
protected // ETH_DST match condition while pushing IP table flow rules
Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
log.debug("Processing specific");
TrafficSelector selector = fwd.selector();
EthTypeCriterion ethType = (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
if ((ethType == null) || (ethType.ethType().toShort() != Ethernet.TYPE_IPV4) && (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST)) {
log.debug("processSpecific: Unsupported " + "forwarding objective criteraia");
fail(fwd, ObjectiveError.UNSUPPORTED);
return Collections.emptySet();
}
TrafficSelector.Builder filteredSelectorBuilder = DefaultTrafficSelector.builder();
int forTableId = -1;
if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
if (deviceTMac == null) {
log.debug("processSpecific: ETH_DST filtering " + "objective is not set which is required " + "before sending a IPv4 forwarding objective");
// TODO: Map the error to more appropriate error code.
fail(fwd, ObjectiveError.DEVICEMISSING);
return Collections.emptySet();
}
filteredSelectorBuilder = filteredSelectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchEthDst(deviceTMac).matchIPDst(((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip());
forTableId = ipv4UnicastTableId;
log.debug("processing IPv4 specific forwarding objective");
} else {
filteredSelectorBuilder = filteredSelectorBuilder.matchEthType(Ethernet.MPLS_UNICAST).matchMplsLabel(((MplsCriterion) selector.getCriterion(Criterion.Type.MPLS_LABEL)).label());
if (selector.getCriterion(Criterion.Type.MPLS_BOS) != null) {
filteredSelectorBuilder.matchMplsBos(((MplsBosCriterion) selector.getCriterion(Criterion.Type.MPLS_BOS)).mplsBos());
}
forTableId = mplsTableId;
log.debug("processing MPLS specific forwarding objective");
}
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
if (fwd.treatment() != null) {
for (Instruction i : fwd.treatment().allInstructions()) {
treatmentBuilder.add(i);
}
}
if (fwd.nextId() != null) {
NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
if (next != null) {
SpringOpenGroup soGroup = appKryo.deserialize(next.data());
if (soGroup.dummy()) {
log.debug("Adding {} flow-actions for fwd. obj. {} -> next:{} " + "in dev: {}", soGroup.treatment().allInstructions().size(), fwd.id(), fwd.nextId(), deviceId);
for (Instruction ins : soGroup.treatment().allInstructions()) {
treatmentBuilder.add(ins);
}
} else {
Group group = groupService.getGroup(deviceId, soGroup.key());
if (group == null) {
log.warn("The group left!");
fail(fwd, ObjectiveError.GROUPMISSING);
return Collections.emptySet();
}
treatmentBuilder.group(group.id());
log.debug("Adding OUTGROUP action to group:{} for fwd. obj. {} " + "for next:{} in dev: {}", group.id(), fwd.id(), fwd.nextId(), deviceId);
}
} else {
log.warn("processSpecific: No associated next objective object");
fail(fwd, ObjectiveError.GROUPMISSING);
return Collections.emptySet();
}
}
TrafficSelector filteredSelector = filteredSelectorBuilder.build();
TrafficTreatment treatment = treatmentBuilder.transition(aclTableId).build();
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(filteredSelector).withTreatment(treatment);
if (fwd.permanent()) {
ruleBuilder.makePermanent();
} else {
ruleBuilder.makeTemporary(fwd.timeout());
}
ruleBuilder.forTable(forTableId);
return Collections.singletonList(ruleBuilder.build());
}
use of org.onosproject.net.flow.instructions.Instruction in project onos by opennetworkinglab.
the class CentecV350Pipeline method next.
@Override
public void next(NextObjective nextObjective) {
switch(nextObjective.type()) {
case SIMPLE:
Collection<TrafficTreatment> treatments = nextObjective.next();
if (treatments.size() == 1) {
TrafficTreatment treatment = treatments.iterator().next();
// Since we do not support strip_vlan in PORT_VLAN table, we use mod_vlan
// to modify the packet to desired vlan.
// Note: if we use push_vlan here, the switch will add a second VLAN tag to the outgoing
// packet, which is not what we want.
TrafficTreatment.Builder treatmentWithoutPushVlan = DefaultTrafficTreatment.builder();
VlanId modVlanId;
for (Instruction ins : treatment.allInstructions()) {
if (ins.type() == Instruction.Type.L2MODIFICATION) {
L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
switch(l2ins.subtype()) {
case ETH_DST:
treatmentWithoutPushVlan.setEthDst(((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
break;
case ETH_SRC:
treatmentWithoutPushVlan.setEthSrc(((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
break;
case VLAN_ID:
modVlanId = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId();
treatmentWithoutPushVlan.setVlanId(modVlanId);
break;
default:
break;
}
} else if (ins.type() == Instruction.Type.OUTPUT) {
// long portNum = ((Instructions.OutputInstruction) ins).port().toLong();
treatmentWithoutPushVlan.add(ins);
} else {
// Ignore the vlan_pcp action since it's does matter much.
log.warn("Driver does not handle this type of TrafficTreatment" + " instruction in nextObjectives: {}", ins.type());
}
}
GroupBucket bucket = DefaultGroupBucket.createIndirectGroupBucket(treatmentWithoutPushVlan.build());
final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
GroupDescription groupDescription = new DefaultGroupDescription(deviceId, GroupDescription.Type.INDIRECT, new GroupBuckets(Collections.singletonList(bucket)), key, // let group service determine group id
null, nextObjective.appId());
groupService.addGroup(groupDescription);
pendingGroups.put(key, nextObjective);
}
break;
case HASHED:
case BROADCAST:
case FAILOVER:
fail(nextObjective, ObjectiveError.UNSUPPORTED);
log.warn("Unsupported next objective type {}", nextObjective.type());
break;
default:
fail(nextObjective, ObjectiveError.UNKNOWN);
log.warn("Unknown next objective type {}", nextObjective.type());
}
}
Aggregations