use of org.onosproject.net.group.DefaultGroupDescription in project onos by opennetworkinglab.
the class SimpleGroupStoreTest method testStoreAndGetGroup.
// Testing storeGroup operation
private void testStoreAndGetGroup(GroupKey key) {
PortNumber[] ports = { PortNumber.portNumber(31), PortNumber.portNumber(32) };
List<PortNumber> outPorts = new ArrayList<>();
outPorts.addAll(Arrays.asList(ports));
List<GroupBucket> buckets = new ArrayList<>();
for (PortNumber portNumber : outPorts) {
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
tBuilder.setOutput(portNumber).setEthDst(MacAddress.valueOf("00:00:00:00:00:02")).setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")).pushMpls().setMpls(MplsLabel.mplsLabel(106));
buckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
}
GroupBuckets groupBuckets = new GroupBuckets(buckets);
GroupDescription groupDesc = new DefaultGroupDescription(D1, Group.Type.SELECT, groupBuckets, key, null, appId);
InternalGroupStoreDelegate checkStoreGroupDelegate = new InternalGroupStoreDelegate(key, groupBuckets, GroupEvent.Type.GROUP_ADD_REQUESTED);
simpleGroupStore.setDelegate(checkStoreGroupDelegate);
// Testing storeGroup operation
simpleGroupStore.storeGroupDescription(groupDesc);
// Testing getGroupCount operation
assertEquals(1, simpleGroupStore.getGroupCount(D1));
// Testing getGroup operation
Group createdGroup = simpleGroupStore.getGroup(D1, key);
checkStoreGroupDelegate.verifyGroupId(createdGroup.id());
// Testing getGroups operation
Iterable<Group> createdGroups = simpleGroupStore.getGroups(D1);
int groupCount = 0;
for (Group group : createdGroups) {
checkStoreGroupDelegate.verifyGroupId(group.id());
groupCount++;
}
assertEquals(1, groupCount);
simpleGroupStore.unsetDelegate(checkStoreGroupDelegate);
}
use of org.onosproject.net.group.DefaultGroupDescription in project onos by opennetworkinglab.
the class GroupsWebResource method createGroup.
/**
* Create new group rule. Creates and installs a new group rule for the
* specified device.
*
* @param deviceId device identifier
* @param stream group rule JSON
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel GroupsPost
*/
@POST
@Path("{deviceId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createGroup(@PathParam("deviceId") String deviceId, InputStream stream) {
GroupService groupService = get(GroupService.class);
try {
ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode specifiedDeviceId = jsonTree.get("deviceId");
if (specifiedDeviceId != null && !specifiedDeviceId.asText().equals(deviceId)) {
throw new IllegalArgumentException(DEVICE_INVALID);
}
jsonTree.put("deviceId", deviceId);
Group group = codec(Group.class).decode(jsonTree, this);
GroupDescription description = new DefaultGroupDescription(group.deviceId(), group.type(), group.buckets(), group.appCookie(), group.id().id(), group.appId());
groupService.addGroup(description);
UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path("groups").path(deviceId).path(Long.toString(group.id().id()));
return Response.created(locationBuilder.build()).build();
} catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
}
use of org.onosproject.net.group.DefaultGroupDescription in project onos by opennetworkinglab.
the class ForwardingObjectiveTranslator method aclRule.
private void aclRule(ForwardingObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
if (obj.nextId() == null && obj.treatment() != null) {
final TrafficTreatment treatment = obj.treatment();
final PortNumber outPort = outputPort(treatment);
if (outPort != null && outPort.equals(PortNumber.CONTROLLER) && treatment.allInstructions().size() == 1) {
final PiAction aclAction;
if (treatment.clearedDeferred()) {
aclAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_ACL_PUNT_TO_CPU).build();
} else {
// Action is SET_CLONE_SESSION_ID
if (obj.op() == Objective.Operation.ADD) {
// Action is ADD, create clone group
final DefaultGroupDescription cloneGroup = createCloneGroup(obj.appId(), CLONE_TO_CPU_ID, outPort);
resultBuilder.addGroup(cloneGroup);
}
aclAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_ACL_SET_CLONE_SESSION_ID).withParameter(new PiActionParam(FabricConstants.CLONE_ID, CLONE_TO_CPU_ID)).build();
}
final TrafficTreatment piTreatment = DefaultTrafficTreatment.builder().piTableAction(aclAction).build();
resultBuilder.addFlowRule(flowRule(obj, FabricConstants.FABRIC_INGRESS_ACL_ACL, obj.selector(), piTreatment));
return;
}
}
TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(obj.selector());
// Meta are used to signal the port type which can be edge or infra
Byte portType = portType(obj);
if (portType != null && !isSrMetadataSet(obj, PAIR_PORT)) {
if (portType == PORT_TYPE_EDGE || portType == PORT_TYPE_INFRA) {
selectorBuilder.matchPi(PiCriterion.builder().matchTernary(FabricConstants.HDR_PORT_TYPE, (long) portType, PORT_TYPE_MASK).build());
} else {
throw new FabricPipelinerException(format("Port type '%s' is not allowed for table '%s'", portType, FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN), ObjectiveError.UNSUPPORTED);
}
}
resultBuilder.addFlowRule(flowRule(obj, FabricConstants.FABRIC_INGRESS_ACL_ACL, selectorBuilder.build()));
}
use of org.onosproject.net.group.DefaultGroupDescription in project onos by opennetworkinglab.
the class NextObjectiveTranslator method allGroup.
private int allGroup(NextObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
final Collection<DefaultNextTreatment> defaultNextTreatments = defaultNextTreatments(obj.nextTreatments(), true);
// multicast entries is based solely on the output port.
for (DefaultNextTreatment t : defaultNextTreatments) {
handleEgress(obj, t.treatment(), resultBuilder, true);
}
// FIXME: this implementation supports only the case in which each
// switch interface is associated with only one VLAN, otherwise we would
// need to support replicating multiple times the same packet for the
// same port while setting different VLAN IDs. Hence, collect in a set.
final Set<PortNumber> outPorts = defaultNextTreatments.stream().map(DefaultNextTreatment::treatment).map(FabricUtils::outputPort).filter(Objects::nonNull).collect(Collectors.toSet());
if (outPorts.size() != defaultNextTreatments.size()) {
throw new FabricPipelinerException(format("Found BROADCAST NextObjective with %d treatments but " + "found only %d distinct OUTPUT port numbers, cannot " + "translate to ALL groups", defaultNextTreatments.size(), outPorts.size()), ObjectiveError.UNSUPPORTED);
}
final List<GroupBucket> bucketList = outPorts.stream().map(p -> DefaultTrafficTreatment.builder().setOutput(p).build()).map(DefaultGroupBucket::createAllGroupBucket).collect(Collectors.toList());
final int groupId = obj.id();
// Use DefaultGroupKey instead of PiGroupKey as we don't have any
// action profile to apply to the groups of ALL type.
final GroupKey groupKey = getGroupKey(obj);
resultBuilder.addGroup(new DefaultGroupDescription(deviceId, GroupDescription.Type.ALL, new GroupBuckets(bucketList), groupKey, groupId, obj.appId()));
return groupId;
}
use of org.onosproject.net.group.DefaultGroupDescription in project onos by opennetworkinglab.
the class NextObjectiveTranslator method selectGroup.
private int selectGroup(NextObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
final PiTableId hashedTableId = FabricConstants.FABRIC_INGRESS_NEXT_HASHED;
final List<DefaultNextTreatment> defaultNextTreatments = defaultNextTreatments(obj.nextTreatments(), true);
final List<TrafficTreatment> piTreatments = Lists.newArrayList();
for (DefaultNextTreatment t : defaultNextTreatments) {
// Map treatment to PI...
piTreatments.add(mapTreatmentToPiIfNeeded(t.treatment(), hashedTableId));
// ...and handle egress if necessary.
handleEgress(obj, t.treatment(), resultBuilder, false);
}
final List<GroupBucket> bucketList = piTreatments.stream().map(DefaultGroupBucket::createSelectGroupBucket).collect(Collectors.toList());
final int groupId = obj.id();
final PiGroupKey groupKey = (PiGroupKey) getGroupKey(obj);
resultBuilder.addGroup(new DefaultGroupDescription(deviceId, GroupDescription.Type.SELECT, new GroupBuckets(bucketList), groupKey, groupId, obj.appId()));
return groupId;
}
Aggregations