use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class DefaultSingleTablePipeline method next.
@Override
public void next(NextObjective nextObjective) {
switch(nextObjective.op()) {
case ADD:
// Check next objective
TrafficTreatment treatment = getTreatment(nextObjective);
if (treatment == null) {
// unsupported next objective
nextObjective.context().ifPresent(context -> context.onError(nextObjective, ObjectiveError.UNSUPPORTED));
return;
}
// We insert the value in the cache
pendingAddNext.put(nextObjective.id(), nextObjective);
// Then in the store, this will unblock the queued fwd obj
flowObjectiveStore.putNextGroup(nextObjective.id(), new SingleGroup(treatment));
break;
case REMOVE:
NextGroup next = flowObjectiveStore.removeNextGroup(nextObjective.id());
if (next == null) {
nextObjective.context().ifPresent(context -> context.onError(nextObjective, ObjectiveError.GROUPMISSING));
return;
}
break;
default:
log.warn("Unsupported operation {}", nextObjective.op());
}
nextObjective.context().ifPresent(context -> context.onSuccess(nextObjective));
}
use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class OpenVSwitchPipeline method processSpecific.
private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
log.debug("Processing specific forwarding objective");
TrafficSelector selector = fwd.selector();
TrafficTreatment tb = fwd.treatment();
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(selector).withTreatment(tb).makeTemporary(TIME_OUT);
ruleBuilder.withPriority(fwd.priority());
if (fwd.permanent()) {
ruleBuilder.makePermanent();
}
Integer transition = null;
Integer forTable = null;
// MAC table flow rules
if (selector.getCriterion(Type.TUNNEL_ID) != null && (selector.getCriterion(Type.ETH_DST) != null || selector.getCriterion(Type.ETH_SRC) != null)) {
forTable = MAC_TABLE;
return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
}
// CLASSIFIER table flow rules
if (selector.getCriterion(Type.IN_PORT) != null) {
forTable = CLASSIFIER_TABLE;
if (selector.getCriterion(Type.ETH_SRC) != null && selector.getCriterion(Type.ETH_DST) != null) {
transition = L3FWD_TABLE;
} else if (selector.getCriterion(Type.ETH_SRC) != null || selector.getCriterion(Type.TUNNEL_ID) != null) {
transition = MAC_TABLE;
} else if (selector.getCriterion(Type.IPV4_DST) != null) {
transition = DNAT_TABLE;
} else if (selector.getCriterion(Type.ETH_TYPE) != null && selector.getCriterion(Type.ETH_TYPE).equals(Criteria.matchEthType(EtherType.ARP.ethType().toShort()))) {
transition = ARP_TABLE;
}
return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
}
// ARP table flow rules
if (selector.getCriterion(Type.ETH_TYPE) != null && selector.getCriterion(Type.ETH_TYPE).equals(Criteria.matchEthType(EtherType.ARP.ethType().toShort()))) {
// CLASSIFIER table arp flow rules
if (selector.getCriterion(Type.TUNNEL_ID) == null) {
if (selector.getCriterion(Type.ARP_OP) != null) {
forTable = CLASSIFIER_TABLE;
return reassemblyFlowRule(ruleBuilder, tb, null, forTable);
}
transition = ARP_TABLE;
forTable = CLASSIFIER_TABLE;
return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
}
forTable = ARP_TABLE;
return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
}
// SNAT table flow rules
if (selector.getCriterion(Type.TUNNEL_ID) != null && selector.getCriterion(Type.IPV4_SRC) != null) {
transition = MAC_TABLE;
forTable = SNAT_TABLE;
return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
}
// L3FWD table flow rules
if (selector.getCriterion(Type.TUNNEL_ID) != null && selector.getCriterion(Type.IPV4_DST) != null) {
transition = MAC_TABLE;
forTable = L3FWD_TABLE;
return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
}
// DNAT table flow rules
if (selector.getCriterion(Type.IPV4_DST) != null) {
IPCriterion ipCriterion = (IPCriterion) selector.getCriterion(Type.IPV4_DST);
IpPrefix ipPrefix = ipCriterion.ip();
// specific CLASSIFIER table flow rules for userdata
if (ipPrefix.address().equals(IpAddress.valueOf(USERDATA_IP))) {
forTable = CLASSIFIER_TABLE;
transition = MAC_TABLE;
return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
}
transition = L3FWD_TABLE;
forTable = DNAT_TABLE;
return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
}
return Collections.singletonList(ruleBuilder.build());
}
use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class OpenVSwitchPipeline method processVersatile.
private Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
log.debug("Processing versatile forwarding objective");
TrafficSelector selector = fwd.selector();
TrafficTreatment tb = fwd.treatment();
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(selector).withTreatment(tb).makeTemporary(TIME_OUT);
ruleBuilder.withPriority(fwd.priority());
if (fwd.priority() == 100) {
ruleBuilder.forTable(ENCAP_OUTPUT_TABLE);
} else if (fwd.priority() == 200) {
ruleBuilder.forTable(TUN_SEND_TABLE);
} else {
ruleBuilder.forTable(CLASSIFIER_TABLE);
}
if (fwd.permanent()) {
ruleBuilder.makePermanent();
}
return Collections.singletonList(ruleBuilder.build());
}
use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class PicaPipeline method next.
@Override
public void next(NextObjective nextObjective) {
switch(nextObjective.type()) {
case SIMPLE:
Collection<TrafficTreatment> treatments = nextObjective.next();
if (treatments.size() != 1) {
log.error("Next Objectives of type Simple should only have a " + "single Traffic Treatment. Next Objective Id:{}", nextObjective.id());
fail(nextObjective, ObjectiveError.BADPARAMS);
return;
}
TrafficTreatment treatment = treatments.iterator().next();
TrafficTreatment.Builder filteredTreatment = 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:
filteredTreatment.setEthDst(((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
break;
case ETH_SRC:
filteredTreatment.setEthSrc(((L2ModificationInstruction.ModEtherInstruction) l2ins).mac());
break;
case VLAN_ID:
modVlanId = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId();
filteredTreatment.setVlanId(modVlanId);
break;
default:
break;
}
} else if (ins.type() == Instruction.Type.OUTPUT) {
// long portNum = ((Instructions.OutputInstruction) ins).port().toLong();
filteredTreatment.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());
}
}
// store for future use
flowObjectiveStore.putNextGroup(nextObjective.id(), new PicaGroup(filteredTreatment.build()));
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());
}
}
use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class PicaPipeline method processSpecific.
private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
log.debug("Processing specific forwarding objective");
TrafficSelector selector = fwd.selector();
EthTypeCriterion ethType = (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
if (ethType == null || ethType.ethType().toShort() != Ethernet.TYPE_IPV4) {
fail(fwd, ObjectiveError.UNSUPPORTED);
return Collections.emptySet();
}
List<FlowRule> ipflows = new ArrayList<FlowRule>();
for (Filter f : filters) {
TrafficSelector filteredSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip()).matchEthDst(f.mac()).matchVlanId(f.vlanId()).build();
TrafficTreatment tt = null;
if (fwd.nextId() != null) {
NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
if (next == null) {
log.error("next-id {} does not exist in store", fwd.nextId());
return Collections.emptySet();
}
tt = appKryo.deserialize(next.data());
if (tt == null) {
log.error("Error in deserializing next-id {}", fwd.nextId());
return Collections.emptySet();
}
}
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(filteredSelector).withTreatment(tt);
if (fwd.permanent()) {
ruleBuilder.makePermanent();
} else {
ruleBuilder.makeTemporary(fwd.timeout());
}
ruleBuilder.forTable(IP_UNICAST_TABLE);
ipflows.add(ruleBuilder.build());
}
return ipflows;
}
Aggregations