use of org.onosproject.net.flowobjective.NextTreatment in project onos by opennetworkinglab.
the class FabricPipeliner method getBucketToFlowMapping.
private Map<GroupBucket, FlowRule> getBucketToFlowMapping(NextObjective nextObjective) {
Map<GroupBucket, FlowRule> mapping = Maps.newHashMap();
NextObjective newNextObjective;
ObjectiveTranslation result;
FlowRule dummyFlow = getDummyFlow(nextObjective);
FlowRule egFlow;
GroupBucket groupBucket;
GroupDescription group;
for (NextTreatment nextTreatment : nextObjective.nextTreatments()) {
newNextObjective = DefaultNextObjective.builder().withId(nextObjective.id()).withType(nextObjective.type()).fromApp(nextObjective.appId()).withMeta(nextObjective.meta()).addTreatment(nextTreatment).verify();
result = nextTranslator.translate(newNextObjective);
if ((result.groups().isEmpty() && result.flowRules().isEmpty()) || result.groups().size() > 1) {
return Collections.emptyMap();
}
group = result.groups().iterator().next();
egFlow = result.flowRules().stream().filter(flowRule -> flowRule.table().equals(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN)).findFirst().orElse(null);
if (group.buckets().buckets().isEmpty() || group.buckets().buckets().size() > 1) {
return Collections.emptyMap();
}
groupBucket = group.buckets().buckets().iterator().next();
if (egFlow == null) {
mapping.put(groupBucket, dummyFlow);
} else {
mapping.put(groupBucket, egFlow);
}
}
return mapping;
}
use of org.onosproject.net.flowobjective.NextTreatment in project onos by opennetworkinglab.
the class NextObjectiveCodecTest method testNextObjectiveEncode.
/**
* Tests encoding of a NextObjective object.
*/
@Test
public void testNextObjectiveEncode() {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
NextTreatment nextTreatment = DefaultNextTreatment.of(treatment, 5);
NextObjective nextObj = DefaultNextObjective.builder().makePermanent().withType(NextObjective.Type.HASHED).fromApp(APP_ID).withPriority(60).withId(5).addTreatment(nextTreatment).add();
ObjectNode nextObjJson = nextObjectiveCodec.encode(nextObj, context);
assertThat(nextObjJson, matchesNextObjective(nextObj));
}
use of org.onosproject.net.flowobjective.NextTreatment in project onos by opennetworkinglab.
the class NextObjectiveJsonMatcher method matchesSafely.
@Override
protected boolean matchesSafely(JsonNode jsonNextObj, Description description) {
ObjectiveJsonMatcher.matchesObjective(nextObjective).matchesSafely(jsonNextObj);
// check id
int jsonId = jsonNextObj.get("id").asInt();
int id = nextObjective.id();
if (jsonId != id) {
description.appendText("id was " + jsonId);
return false;
}
// check type
String jsonType = jsonNextObj.get("type").asText();
String type = nextObjective.type().toString();
if (!jsonType.equals(type)) {
description.appendText("type was " + jsonType);
return false;
}
// check size of treatment array
JsonNode jsonTreatments = jsonNextObj.get("treatments");
if (jsonTreatments.size() != nextObjective.next().size()) {
description.appendText("treatments size was " + jsonTreatments.size());
return false;
}
// check the weight
boolean result = true;
List<NextTreatment> nt = new ArrayList(nextObjective.nextTreatments());
for (int i = 0; i < jsonTreatments.size(); i++) {
ObjectNode jsonTreatment = jsonTreatments.path(i).isObject() && !jsonTreatments.path(i).isNull() ? (ObjectNode) jsonTreatments.path(i) : null;
int jsonWeight = jsonTreatment.get("weight").asInt();
if (jsonWeight != nt.get(i).weight()) {
description.appendText("weight of NextTreatment with index " + i + " was " + jsonWeight);
result = false;
}
}
if (!result) {
return false;
}
return true;
}
use of org.onosproject.net.flowobjective.NextTreatment in project onos by opennetworkinglab.
the class NextObjectiveTranslator method defaultNextTreatments.
private List<DefaultNextTreatment> defaultNextTreatments(Collection<NextTreatment> nextTreatments, boolean strict) throws FabricPipelinerException {
final List<DefaultNextTreatment> defaultNextTreatments = Lists.newArrayList();
final List<NextTreatment> unsupportedNextTreatments = Lists.newArrayList();
for (NextTreatment n : nextTreatments) {
if (n.type() == NextTreatment.Type.TREATMENT) {
defaultNextTreatments.add((DefaultNextTreatment) n);
} else {
unsupportedNextTreatments.add(n);
}
}
if (strict && !unsupportedNextTreatments.isEmpty()) {
throw new FabricPipelinerException(format("Unsupported NextTreatments: %s", unsupportedNextTreatments));
}
return defaultNextTreatments;
}
Aggregations