Search in sources :

Example 31 with GroupDescription

use of org.onosproject.net.group.GroupDescription in project onos by opennetworkinglab.

the class SimpleGroupStore method updateGroupDescription.

/**
 * Updates the existing group entry with the information
 * from group description.
 *
 * @param deviceId the device ID
 * @param oldAppCookie the current group key
 * @param type update type
 * @param newBuckets group buckets for updates
 * @param newAppCookie optional new group key
 */
@Override
public void updateGroupDescription(DeviceId deviceId, GroupKey oldAppCookie, UpdateType type, GroupBuckets newBuckets, GroupKey newAppCookie) {
    // Check if a group is existing with the provided key
    Group oldGroup = getGroup(deviceId, oldAppCookie);
    if (oldGroup == null) {
        return;
    }
    List<GroupBucket> newBucketList = getUpdatedBucketList(oldGroup, type, newBuckets);
    if (newBucketList != null) {
        // Create a new group object from the old group
        GroupBuckets updatedBuckets = new GroupBuckets(newBucketList);
        GroupKey newCookie = (newAppCookie != null) ? newAppCookie : oldAppCookie;
        GroupDescription updatedGroupDesc = new DefaultGroupDescription(oldGroup.deviceId(), oldGroup.type(), updatedBuckets, newCookie, oldGroup.givenGroupId(), oldGroup.appId());
        StoredGroupEntry newGroup = new DefaultGroup(oldGroup.id(), updatedGroupDesc);
        newGroup.setState(GroupState.PENDING_UPDATE);
        newGroup.setLife(oldGroup.life());
        newGroup.setPackets(oldGroup.packets());
        newGroup.setBytes(oldGroup.bytes());
        // Remove the old entry from maps and add new entry using new key
        ConcurrentMap<GroupKey, StoredGroupEntry> keyTable = getGroupKeyTable(oldGroup.deviceId());
        ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(oldGroup.deviceId());
        keyTable.remove(oldGroup.appCookie());
        idTable.remove(oldGroup.id());
        keyTable.put(newGroup.appCookie(), newGroup);
        idTable.put(newGroup.id(), newGroup);
        notifyDelegate(new GroupEvent(Type.GROUP_UPDATE_REQUESTED, newGroup));
    }
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBuckets(org.onosproject.net.group.GroupBuckets) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupEvent(org.onosproject.net.group.GroupEvent) GroupId(org.onosproject.core.GroupId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Example 32 with GroupDescription

use of org.onosproject.net.group.GroupDescription 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);
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) PortNumber(org.onosproject.net.PortNumber) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Example 33 with GroupDescription

use of org.onosproject.net.group.GroupDescription 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);
    }
}
Also used : DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) Group(org.onosproject.net.group.Group) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) GroupService(org.onosproject.net.group.GroupService) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 34 with GroupDescription

use of org.onosproject.net.group.GroupDescription 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;
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Ethernet(org.onlab.packet.Ethernet) FlowRuleService(org.onosproject.net.flow.FlowRuleService) SharedExecutors(org.onlab.util.SharedExecutors) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) PipelinerContext(org.onosproject.net.behaviour.PipelinerContext) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Collection(java.util.Collection) PORT_TYPE_INTERNAL(org.onosproject.pipelines.fabric.impl.behaviour.Constants.PORT_TYPE_INTERNAL) Set(java.util.Set) FlowObjectiveStore(org.onosproject.net.flowobjective.FlowObjectiveStore) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) Objects(java.util.Objects) List(java.util.List) FabricUtils.outputPort(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.outputPort) FlowRule(org.onosproject.net.flow.FlowRule) GroupBuckets(org.onosproject.net.group.GroupBuckets) DeviceId(org.onosproject.net.DeviceId) GroupDescription(org.onosproject.net.group.GroupDescription) ONE(org.onosproject.pipelines.fabric.impl.behaviour.FabricInterpreter.ONE) Pipeliner(org.onosproject.net.behaviour.Pipeliner) FWD_IPV4_ROUTING(org.onosproject.pipelines.fabric.impl.behaviour.Constants.FWD_IPV4_ROUTING) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBucket(org.onosproject.net.group.GroupBucket) KryoNamespace(org.onlab.util.KryoNamespace) NextGroup(org.onosproject.net.behaviour.NextGroup) GroupKey(org.onosproject.net.group.GroupKey) Group(org.onosproject.net.group.Group) ZERO(org.onosproject.pipelines.fabric.impl.behaviour.FabricInterpreter.ZERO) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExecutorService(java.util.concurrent.ExecutorService) FabricCapabilities(org.onosproject.pipelines.fabric.impl.behaviour.FabricCapabilities) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) SIMPLE(org.onosproject.net.flowobjective.NextObjective.Type.SIMPLE) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Logger(org.slf4j.Logger) GroupService(org.onosproject.net.group.GroupService) FabricConstants(org.onosproject.pipelines.fabric.FabricConstants) Maps(com.google.common.collect.Maps) IdNextTreatment(org.onosproject.net.flowobjective.IdNextTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction) FabricPipeconfLoader(org.onosproject.pipelines.fabric.impl.FabricPipeconfLoader) AbstractFabricHandlerBehavior(org.onosproject.pipelines.fabric.impl.behaviour.AbstractFabricHandlerBehavior) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) Collections(java.util.Collections) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) IdNextTreatment(org.onosproject.net.flowobjective.IdNextTreatment)

Example 35 with GroupDescription

use of org.onosproject.net.group.GroupDescription in project onos by opennetworkinglab.

the class ForwardingObjectiveTranslatorTest method testAclNext.

/**
 * Test versatile flag of forwarding objective with next step.
 */
@Test
public void testAclNext() {
    // ACL 8-tuples
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IPV4_UNICAST_ADDR).build();
    ForwardingObjective fwd = DefaultForwardingObjective.builder().withSelector(selector).withPriority(PRIORITY).fromApp(APP_ID).makePermanent().withFlag(ForwardingObjective.Flag.VERSATILE).nextStep(NEXT_ID_1).add();
    ObjectiveTranslation result = translator.translate(fwd);
    List<FlowRule> flowRulesInstalled = (List<FlowRule>) result.flowRules();
    List<GroupDescription> groupsInstalled = (List<GroupDescription>) result.groups();
    assertEquals(1, flowRulesInstalled.size());
    assertTrue(groupsInstalled.isEmpty());
    FlowRule actualFlowRule = flowRulesInstalled.get(0);
    PiAction piAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_ACL_SET_NEXT_ID_ACL).withParameter(new PiActionParam(FabricConstants.NEXT_ID, NEXT_ID_1)).build();
    FlowRule expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(FabricConstants.FABRIC_INGRESS_ACL_ACL).withPriority(PRIORITY).makePermanent().withSelector(selector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piAction).build()).fromApp(APP_ID).build();
    assertTrue(expectedFlowRule.exactMatch(actualFlowRule));
}
Also used : DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction) Test(org.junit.Test)

Aggregations

GroupDescription (org.onosproject.net.group.GroupDescription)82 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)66 GroupBuckets (org.onosproject.net.group.GroupBuckets)51 GroupBucket (org.onosproject.net.group.GroupBucket)48 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)46 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)44 GroupKey (org.onosproject.net.group.GroupKey)44 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)39 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)39 FlowRule (org.onosproject.net.flow.FlowRule)28 List (java.util.List)26 TrafficSelector (org.onosproject.net.flow.TrafficSelector)26 PiAction (org.onosproject.net.pi.runtime.PiAction)26 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)25 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)23 Group (org.onosproject.net.group.Group)23 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)20 GroupId (org.onosproject.core.GroupId)20 PortNumber (org.onosproject.net.PortNumber)19