Search in sources :

Example 96 with GroupBucket

use of org.onosproject.net.group.GroupBucket 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 97 with GroupBucket

use of org.onosproject.net.group.GroupBucket 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 98 with GroupBucket

use of org.onosproject.net.group.GroupBucket 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 99 with GroupBucket

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

the class GroupsListCommand method printGroups.

private void printGroups(DeviceId deviceId, List<Group> groups) {
    print("deviceId=%s, groupCount=%s", deviceId, groups.size());
    if (countOnly) {
        return;
    }
    for (Group group : groups) {
        print(FORMAT, Integer.toHexString(group.id().id()), group.state(), group.type(), group.bytes(), group.packets(), group.appId().name(), group.referenceCount());
        int i = 0;
        for (GroupBucket bucket : group.buckets().buckets()) {
            print(BUCKET_FORMAT, Integer.toHexString(group.id().id()), ++i, bucket.bytes(), bucket.packets(), bucket.weight(), bucket.treatment().allInstructions());
        }
    }
}
Also used : Group(org.onosproject.net.group.Group) GroupBucket(org.onosproject.net.group.GroupBucket)

Example 100 with GroupBucket

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

the class KubevirtLbHandler method setBucketsToGroup.

private void setBucketsToGroup(KubevirtLoadBalancer loadBalancer, KubevirtNode gateway, boolean install) {
    int groupId = loadBalancer.hashCode();
    KubevirtNetwork network = networkService.network(loadBalancer.networkId());
    Set<KubevirtPort> ports = portService.ports(loadBalancer.networkId());
    List<GroupBucket> bkts = Lists.newArrayList();
    loadBalancer.members().forEach(ip -> {
        ports.stream().filter(port -> port.ipAddress().equals(ip) && port.macAddress() != null).findAny().ifPresent(port -> bkts.add(buildGroupBucket(port)));
    });
    groupRuleService.setBuckets(appId, gateway.intgBridge(), groupId, bkts, install);
}
Also used : KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) KubevirtNetworkingUtil.getRouterForKubevirtNetwork(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.getRouterForKubevirtNetwork) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) KubevirtPort(org.onosproject.kubevirtnetworking.api.KubevirtPort)

Aggregations

GroupBucket (org.onosproject.net.group.GroupBucket)108 GroupBuckets (org.onosproject.net.group.GroupBuckets)87 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)75 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)66 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)66 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)62 GroupKey (org.onosproject.net.group.GroupKey)62 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)56 GroupDescription (org.onosproject.net.group.GroupDescription)55 ArrayList (java.util.ArrayList)42 Group (org.onosproject.net.group.Group)40 GroupId (org.onosproject.core.GroupId)35 PortNumber (org.onosproject.net.PortNumber)32 DefaultGroup (org.onosproject.net.group.DefaultGroup)26 List (java.util.List)21 DeviceId (org.onosproject.net.DeviceId)20 TrafficSelector (org.onosproject.net.flow.TrafficSelector)20 OfdpaGroupHandlerUtility.l2MulticastGroupKey (org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.l2MulticastGroupKey)17 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)16 ArrayDeque (java.util.ArrayDeque)15