use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class SpringOpenTTP method removeBucketFromGroup.
private void removeBucketFromGroup(NextObjective nextObjective) {
log.debug("removeBucketFromGroup in {}: for next objective id {}", deviceId, nextObjective.id());
NextGroup nextGroup = flowObjectiveStore.getNextGroup(nextObjective.id());
if (nextGroup != null) {
Collection<TrafficTreatment> treatments = nextObjective.next();
TrafficTreatment treatment = treatments.iterator().next();
final GroupKey key = new DefaultGroupKey(appKryo.serialize(nextObjective.id()));
Group group = groupService.getGroup(deviceId, key);
if (group == null) {
log.warn("Group is not found in {} for {}", deviceId, key);
return;
}
GroupBucket bucket;
if (group.type() == GroupDescription.Type.INDIRECT) {
bucket = DefaultGroupBucket.createIndirectGroupBucket(treatment);
} else if (group.type() == GroupDescription.Type.SELECT) {
bucket = DefaultGroupBucket.createSelectGroupBucket(treatment);
} else if (group.type() == GroupDescription.Type.ALL) {
bucket = DefaultGroupBucket.createAllGroupBucket(treatment);
} else {
log.warn("Unsupported Group type {}", group.type());
return;
}
GroupBuckets removeBuckets = new GroupBuckets(Collections.singletonList(bucket));
log.debug("Removing buckets from group id {} of next objective id {} in device {}", group.id(), nextObjective.id(), deviceId);
groupService.removeBucketsFromGroup(deviceId, key, removeBuckets, key, appId);
}
}
use of org.onosproject.net.flow.TrafficTreatment 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.TrafficTreatment 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());
}
}
use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class CiscoN9kPipeliner method forwardingObjectiveWithoutCleardDef.
private Optional<ForwardingObjective> forwardingObjectiveWithoutCleardDef(ForwardingObjective forwardingObjective) {
TrafficTreatment treatment = trafficTreatmentWithoutClearedDeffered(forwardingObjective.treatment());
DefaultForwardingObjective.Builder foBuilder = (DefaultForwardingObjective.Builder) forwardingObjective.copy();
foBuilder.withTreatment(treatment);
switch(forwardingObjective.op()) {
case ADD:
return Optional.of(foBuilder.add(forwardingObjective.context().orElse(null)));
case REMOVE:
return Optional.of(foBuilder.remove(forwardingObjective.context().orElse(null)));
default:
log.warn("Driver does not support other operations for forwarding objective");
return Optional.empty();
}
}
use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.
the class KubevirtFloatingIpHandler method setFloatingIpUpstreamRules.
private void setFloatingIpUpstreamRules(KubevirtRouter router, KubevirtFloatingIp floatingIp, KubevirtPort port, KubevirtNode electedGw, boolean install) {
MacAddress peerMacAddress = router.peerRouter().macAddress();
if (peerMacAddress == null) {
log.warn("Failed to install floating Ip rules for floating ip {} and router {}" + "because there's no peer router mac address", floatingIp.floatingIp(), router.name());
return;
}
MacAddress routerMacAddress = getRouterMacAddress(router);
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchEthSrc(port.macAddress()).matchEthDst(routerMacAddress).matchIPSrc(IpPrefix.valueOf(floatingIp.fixedIp(), 32)).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setEthDst(peerMacAddress).setEthSrc(port.macAddress()).setIpSrc(floatingIp.floatingIp()).setOutput(externalPatchPortNum(deviceService, electedGw)).build();
flowService.setRule(appId, electedGw.intgBridge(), selector, treatment, PRIORITY_FLOATING_IP_UPSTREAM_RULE, GW_ENTRY_TABLE, install);
}
Aggregations