Search in sources :

Example 76 with GroupBuckets

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

the class SimpleGroupStoreTest method testSetBuckets.

// Testing updateGroupDescription for SET operation from northbound
private void testSetBuckets(GroupKey currKey, GroupKey setKey) {
    List<GroupBucket> toSetBuckets = new ArrayList<>();
    short weight = 5;
    PortNumber portNumber = PortNumber.portNumber(42);
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    tBuilder.setOutput(portNumber).setEthDst(MacAddress.valueOf("00:00:00:00:00:03")).setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")).pushMpls().setMpls(MplsLabel.mplsLabel(106));
    toSetBuckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build(), weight));
    GroupBuckets toSetGroupBuckets = new GroupBuckets(toSetBuckets);
    InternalGroupStoreDelegate updateGroupDescDelegate = new InternalGroupStoreDelegate(setKey, toSetGroupBuckets, GroupEvent.Type.GROUP_UPDATE_REQUESTED);
    simpleGroupStore.setDelegate(updateGroupDescDelegate);
    simpleGroupStore.updateGroupDescription(D1, currKey, UpdateType.SET, toSetGroupBuckets, setKey);
    simpleGroupStore.unsetDelegate(updateGroupDescDelegate);
}
Also used : ArrayList(java.util.ArrayList) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets)

Example 77 with GroupBuckets

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

the class SimpleGroupStoreTest method testAddBuckets.

// Testing updateGroupDescription for ADD operation from northbound
private void testAddBuckets(GroupKey currKey, GroupKey addKey) {
    Group existingGroup = simpleGroupStore.getGroup(D1, currKey);
    List<GroupBucket> buckets = new ArrayList<>();
    buckets.addAll(existingGroup.buckets().buckets());
    PortNumber[] newNeighborPorts = { PortNumber.portNumber(41), PortNumber.portNumber(42) };
    List<PortNumber> newOutPorts = new ArrayList<>();
    newOutPorts.addAll(Collections.singletonList(newNeighborPorts[0]));
    List<GroupBucket> toAddBuckets = new ArrayList<>();
    for (PortNumber portNumber : newOutPorts) {
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
        tBuilder.setOutput(portNumber).setEthDst(MacAddress.valueOf("00:00:00:00:00:03")).setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")).pushMpls().setMpls(MplsLabel.mplsLabel(106));
        toAddBuckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
    }
    GroupBuckets toAddGroupBuckets = new GroupBuckets(toAddBuckets);
    buckets.addAll(toAddBuckets);
    GroupBuckets updatedGroupBuckets = new GroupBuckets(buckets);
    InternalGroupStoreDelegate updateGroupDescDelegate = new InternalGroupStoreDelegate(addKey, updatedGroupBuckets, GroupEvent.Type.GROUP_UPDATE_REQUESTED);
    simpleGroupStore.setDelegate(updateGroupDescDelegate);
    simpleGroupStore.updateGroupDescription(D1, currKey, UpdateType.ADD, toAddGroupBuckets, addKey);
    simpleGroupStore.unsetDelegate(updateGroupDescDelegate);
    short weight = 5;
    toAddBuckets = new ArrayList<>();
    for (PortNumber portNumber : newOutPorts) {
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
        tBuilder.setOutput(portNumber).setEthDst(MacAddress.valueOf("00:00:00:00:00:03")).setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")).pushMpls().setMpls(MplsLabel.mplsLabel(106));
        toAddBuckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build(), weight));
    }
    toAddGroupBuckets = new GroupBuckets(toAddBuckets);
    buckets = new ArrayList<>();
    buckets.addAll(existingGroup.buckets().buckets());
    buckets.addAll(toAddBuckets);
    updatedGroupBuckets = new GroupBuckets(buckets);
    updateGroupDescDelegate = new InternalGroupStoreDelegate(addKey, updatedGroupBuckets, GroupEvent.Type.GROUP_UPDATE_REQUESTED);
    simpleGroupStore.setDelegate(updateGroupDescDelegate);
    simpleGroupStore.updateGroupDescription(D1, addKey, UpdateType.ADD, toAddGroupBuckets, addKey);
    simpleGroupStore.unsetDelegate(updateGroupDescDelegate);
}
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) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) PortNumber(org.onosproject.net.PortNumber)

Example 78 with GroupBuckets

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

the class GroupsWebResource method updateGroupBuckets.

/**
 * Adds buckets to a group using the group service.
 *
 * @param deviceIdString device Id
 * @param appCookieString application cookie
 * @param stream JSON stream
 */
private void updateGroupBuckets(String deviceIdString, String appCookieString, InputStream stream) throws IOException {
    GroupService groupService = get(GroupService.class);
    DeviceId deviceId = DeviceId.deviceId(deviceIdString);
    final GroupKey groupKey = createKey(appCookieString);
    Group group = nullIsNotFound(groupService.getGroup(deviceId, groupKey), GROUP_NOT_FOUND);
    ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
    GroupBuckets buckets = null;
    List<GroupBucket> groupBucketList = new ArrayList<>();
    JsonNode bucketsJson = jsonTree.get("buckets");
    final JsonCodec<GroupBucket> groupBucketCodec = codec(GroupBucket.class);
    if (bucketsJson != null) {
        IntStream.range(0, bucketsJson.size()).forEach(i -> {
            ObjectNode bucketJson = (ObjectNode) bucketsJson.get(i);
            groupBucketList.add(groupBucketCodec.decode(bucketJson, this));
        });
        buckets = new GroupBuckets(groupBucketList);
    }
    groupService.addBucketsToGroup(deviceId, groupKey, buckets, groupKey, group.appId());
}
Also used : Group(org.onosproject.net.group.Group) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) ArrayList(java.util.ArrayList) GroupBucket(org.onosproject.net.group.GroupBucket) JsonNode(com.fasterxml.jackson.databind.JsonNode) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupService(org.onosproject.net.group.GroupService)

Example 79 with GroupBuckets

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

the class GroupsWebResource method removeGroupBuckets.

/**
 * Removes buckets from a group using the group service.
 *
 * @param deviceIdString device Id
 * @param appCookieString application cookie
 * @param bucketIds comma separated list of bucket Ids to remove
 */
private void removeGroupBuckets(String deviceIdString, String appCookieString, String bucketIds) {
    DeviceId deviceId = DeviceId.deviceId(deviceIdString);
    final GroupKey groupKey = createKey(appCookieString);
    GroupService groupService = get(GroupService.class);
    Group group = nullIsNotFound(groupService.getGroup(deviceId, groupKey), GROUP_NOT_FOUND);
    List<GroupBucket> groupBucketList = new ArrayList<>();
    List<String> bucketsToRemove = ImmutableList.copyOf(bucketIds.split(","));
    bucketsToRemove.forEach(bucketIdToRemove -> {
        group.buckets().buckets().stream().filter(bucket -> Integer.toString(bucket.hashCode()).equals(bucketIdToRemove)).forEach(groupBucketList::add);
    });
    groupService.removeBucketsFromGroup(deviceId, groupKey, new GroupBuckets(groupBucketList), groupKey, group.appId());
}
Also used : IntStream(java.util.stream.IntStream) PathParam(javax.ws.rs.PathParam) AbstractWebResource(org.onosproject.rest.AbstractWebResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) DeviceService(org.onosproject.net.device.DeviceService) Path(javax.ws.rs.Path) GroupBucket(org.onosproject.net.group.GroupBucket) GroupKey(org.onosproject.net.group.GroupKey) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) MediaType(javax.ws.rs.core.MediaType) ImmutableList(com.google.common.collect.ImmutableList) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) Consumes(javax.ws.rs.Consumes) JsonNode(com.fasterxml.jackson.databind.JsonNode) UriBuilder(javax.ws.rs.core.UriBuilder) DELETE(javax.ws.rs.DELETE) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) Tools.nullIsNotFound(org.onlab.util.Tools.nullIsNotFound) Device(org.onosproject.net.Device) GroupService(org.onosproject.net.group.GroupService) IOException(java.io.IOException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) List(java.util.List) HexString(org.onlab.util.HexString) Response(javax.ws.rs.core.Response) JsonCodec(org.onosproject.codec.JsonCodec) GroupBuckets(org.onosproject.net.group.GroupBuckets) UriInfo(javax.ws.rs.core.UriInfo) DeviceId(org.onosproject.net.DeviceId) Tools.readTreeFromStream(org.onlab.util.Tools.readTreeFromStream) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) InputStream(java.io.InputStream) Group(org.onosproject.net.group.Group) DeviceId(org.onosproject.net.DeviceId) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) ArrayList(java.util.ArrayList) GroupBucket(org.onosproject.net.group.GroupBucket) HexString(org.onlab.util.HexString) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupService(org.onosproject.net.group.GroupService)

Example 80 with GroupBuckets

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

the class KubevirtGroupRuleManager method setRule.

@Override
public void setRule(ApplicationId appId, DeviceId deviceId, int groupId, GroupDescription.Type type, List<GroupBucket> buckets, boolean install) {
    Group group = groupService.getGroup(deviceId, getGroupKey(groupId));
    if (install) {
        if (group == null) {
            GroupDescription groupDesc = new DefaultGroupDescription(deviceId, type, new GroupBuckets(buckets), getGroupKey(groupId), groupId, appId);
            groupService.addGroup(groupDesc);
            log.debug("Adding group table rule {}", groupId);
        }
    } else {
        if (group != null) {
            groupService.removeGroup(deviceId, getGroupKey(groupId), appId);
            log.debug("Removing group table rule {}", groupId);
        }
    }
}
Also used : DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) Group(org.onosproject.net.group.Group) GroupBuckets(org.onosproject.net.group.GroupBuckets) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Aggregations

GroupBuckets (org.onosproject.net.group.GroupBuckets)90 GroupBucket (org.onosproject.net.group.GroupBucket)82 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)69 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)63 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)58 GroupKey (org.onosproject.net.group.GroupKey)58 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)57 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)56 GroupDescription (org.onosproject.net.group.GroupDescription)53 Group (org.onosproject.net.group.Group)35 ArrayList (java.util.ArrayList)31 GroupId (org.onosproject.core.GroupId)28 PortNumber (org.onosproject.net.PortNumber)27 DefaultGroup (org.onosproject.net.group.DefaultGroup)22 OfdpaGroupHandlerUtility.l2MulticastGroupKey (org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.l2MulticastGroupKey)17 ArrayDeque (java.util.ArrayDeque)15 Deque (java.util.Deque)15 TrafficSelector (org.onosproject.net.flow.TrafficSelector)15 PiGroupKey (org.onosproject.net.pi.runtime.PiGroupKey)14 NextObjective (org.onosproject.net.flowobjective.NextObjective)13