Search in sources :

Example 41 with GroupBucket

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

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

the class SimpleGroupStoreTest method testUpdateGroupEntryFromSB.

// Testing addOrUpdateGroupEntry operation from southbound
private void testUpdateGroupEntryFromSB(GroupKey currKey) {
    Group existingGroup = simpleGroupStore.getGroup(D1, currKey);
    int totalPkts = 0;
    int totalBytes = 0;
    List<GroupBucket> newBucketList = new ArrayList<>();
    for (GroupBucket bucket : existingGroup.buckets().buckets()) {
        StoredGroupBucketEntry newBucket = (StoredGroupBucketEntry) DefaultGroupBucket.createSelectGroupBucket(bucket.treatment());
        newBucket.setPackets(10);
        newBucket.setBytes(10 * 256 * 8);
        totalPkts += 10;
        totalBytes += 10 * 256 * 8;
        newBucketList.add(newBucket);
    }
    GroupBuckets updatedBuckets = new GroupBuckets(newBucketList);
    Group updatedGroup = new DefaultGroup(existingGroup.id(), existingGroup.deviceId(), existingGroup.type(), updatedBuckets);
    ((StoredGroupEntry) updatedGroup).setPackets(totalPkts);
    ((StoredGroupEntry) updatedGroup).setBytes(totalBytes);
    InternalGroupStoreDelegate updateGroupEntryDelegate = new InternalGroupStoreDelegate(currKey, updatedBuckets, GroupEvent.Type.GROUP_UPDATED);
    simpleGroupStore.setDelegate(updateGroupEntryDelegate);
    simpleGroupStore.addOrUpdateGroupEntry(updatedGroup);
    simpleGroupStore.unsetDelegate(updateGroupEntryDelegate);
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) StoredGroupBucketEntry(org.onosproject.net.group.StoredGroupBucketEntry) GroupBuckets(org.onosproject.net.group.GroupBuckets) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry)

Example 43 with GroupBucket

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

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

the class SimpleGroupStoreTest method testRemoveBuckets.

// Testing updateGroupDescription for REMOVE operation from northbound
private void testRemoveBuckets(GroupKey currKey, GroupKey removeKey) {
    Group existingGroup = simpleGroupStore.getGroup(D1, currKey);
    List<GroupBucket> buckets = new ArrayList<>();
    buckets.addAll(existingGroup.buckets().buckets());
    List<GroupBucket> toRemoveBuckets = new ArrayList<>();
    // There should be 4 buckets in the current group
    toRemoveBuckets.add(buckets.remove(0));
    toRemoveBuckets.add(buckets.remove(1));
    GroupBuckets toRemoveGroupBuckets = new GroupBuckets(toRemoveBuckets);
    GroupBuckets remainingGroupBuckets = new GroupBuckets(buckets);
    InternalGroupStoreDelegate removeGroupDescDelegate = new InternalGroupStoreDelegate(removeKey, remainingGroupBuckets, GroupEvent.Type.GROUP_UPDATE_REQUESTED);
    simpleGroupStore.setDelegate(removeGroupDescDelegate);
    simpleGroupStore.updateGroupDescription(D1, currKey, UpdateType.REMOVE, toRemoveGroupBuckets, removeKey);
    simpleGroupStore.unsetDelegate(removeGroupDescDelegate);
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) GroupBuckets(org.onosproject.net.group.GroupBuckets)

Example 45 with GroupBucket

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

the class GroupCodecTest method codecEncodeTest.

@Test
public void codecEncodeTest() {
    GroupBucket bucket1 = DefaultGroupBucket.createAllGroupBucket(DefaultTrafficTreatment.emptyTreatment());
    GroupBucket bucket2 = DefaultGroupBucket.createAllGroupBucket(DefaultTrafficTreatment.emptyTreatment());
    GroupBucket bucket3 = DefaultGroupBucket.createIndirectGroupBucket(DefaultTrafficTreatment.emptyTreatment());
    GroupBuckets allBuckets = new GroupBuckets(ImmutableList.of(bucket1, bucket2));
    GroupBuckets indirectBuckets = new GroupBuckets(ImmutableList.of(bucket3));
    DefaultGroup group = new DefaultGroup(new GroupId(1), NetTestTools.did("d1"), ALL, allBuckets);
    DefaultGroup group1 = new DefaultGroup(new GroupId(2), NetTestTools.did("d2"), INDIRECT, indirectBuckets);
    MockCodecContext context = new MockCodecContext();
    GroupCodec codec = new GroupCodec();
    ObjectNode groupJson = codec.encode(group, context);
    ObjectNode groupJsonIndirect = codec.encode(group1, context);
    assertThat(groupJson, matchesGroup(group));
    assertThat(groupJsonIndirect, matchesGroup(group1));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupId(org.onosproject.core.GroupId) Test(org.junit.Test)

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