Search in sources :

Example 11 with DefaultGroup

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

the class SimpleGroupStore method storeGroupDescriptionInternal.

private void storeGroupDescriptionInternal(GroupDescription groupDesc) {
    // Check if a group is existing with the same key
    if (getGroup(groupDesc.deviceId(), groupDesc.appCookie()) != null) {
        return;
    }
    GroupId id = null;
    if (groupDesc.givenGroupId() == null) {
        // Get a new group identifier
        id = new GroupId(getFreeGroupIdValue(groupDesc.deviceId()));
    } else {
        id = new GroupId(groupDesc.givenGroupId());
    }
    // Create a group entry object
    StoredGroupEntry group = new DefaultGroup(id, groupDesc);
    // Insert the newly created group entry into concurrent key and id maps
    ConcurrentMap<GroupKey, StoredGroupEntry> keyTable = getGroupKeyTable(groupDesc.deviceId());
    keyTable.put(groupDesc.appCookie(), group);
    ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(groupDesc.deviceId());
    idTable.put(id, group);
    notifyDelegate(new GroupEvent(GroupEvent.Type.GROUP_ADD_REQUESTED, group));
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupKey(org.onosproject.net.group.GroupKey) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry) GroupEvent(org.onosproject.net.group.GroupEvent) GroupId(org.onosproject.core.GroupId)

Example 12 with DefaultGroup

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

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

the class SimpleGroupStore method storeGroupDescription.

/**
 * Stores a new group entry using the information from group description.
 *
 * @param groupDesc group description to be used to create group entry
 */
@Override
public void storeGroupDescription(GroupDescription groupDesc) {
    // Check if a group is existing with the same key
    if (getGroup(groupDesc.deviceId(), groupDesc.appCookie()) != null) {
        return;
    }
    if (deviceAuditStatus.get(groupDesc.deviceId()) == null) {
        // Device group audit has not completed yet
        // Add this group description to pending group key table
        // Create a group entry object with Dummy Group ID
        StoredGroupEntry group = new DefaultGroup(dummyGroupId, groupDesc);
        group.setState(GroupState.WAITING_AUDIT_COMPLETE);
        ConcurrentMap<GroupKey, StoredGroupEntry> pendingKeyTable = getPendingGroupKeyTable(groupDesc.deviceId());
        pendingKeyTable.put(groupDesc.appCookie(), group);
        return;
    }
    storeGroupDescriptionInternal(groupDesc);
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupKey(org.onosproject.net.group.GroupKey) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry)

Example 14 with DefaultGroup

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

use of org.onosproject.net.group.DefaultGroup 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

DefaultGroup (org.onosproject.net.group.DefaultGroup)26 Group (org.onosproject.net.group.Group)12 GroupBuckets (org.onosproject.net.group.GroupBuckets)12 GroupKey (org.onosproject.net.group.GroupKey)12 StoredGroupEntry (org.onosproject.net.group.StoredGroupEntry)11 GroupId (org.onosproject.core.GroupId)10 GroupBucket (org.onosproject.net.group.GroupBucket)10 GroupDescription (org.onosproject.net.group.GroupDescription)10 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)8 GroupEvent (org.onosproject.net.group.GroupEvent)6 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)5 ArrayList (java.util.ArrayList)4 PortNumber (org.onosproject.net.PortNumber)4 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)4 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)4 ApplicationId (org.onosproject.core.ApplicationId)3 CoreService (org.onosproject.core.CoreService)3 DeviceId (org.onosproject.net.DeviceId)3 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2