Search in sources :

Example 36 with GroupBuckets

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

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

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

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

Example 40 with GroupBuckets

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

the class GroupBucketEntryBuilder method build.

/**
 * Builds a GroupBuckets.
 *
 * @return GroupBuckets object, a list of GroupBuckets
 */
public GroupBuckets build() {
    List<GroupBucket> bucketList = Lists.newArrayList();
    for (OFBucket bucket : ofBuckets) {
        TrafficTreatment treatment = buildTreatment(bucket.getActions());
        // TODO: Use GroupBucketEntry
        GroupBucket groupBucket = null;
        switch(type) {
            case INDIRECT:
                groupBucket = DefaultGroupBucket.createIndirectGroupBucket(treatment);
                break;
            case SELECT:
                groupBucket = DefaultGroupBucket.createSelectGroupBucket(treatment, (short) bucket.getWeight());
                break;
            case FF:
                PortNumber port = PortNumber.portNumber(bucket.getWatchPort().getPortNumber());
                GroupId groupId = new GroupId(bucket.getWatchGroup().getGroupNumber());
                groupBucket = DefaultGroupBucket.createFailoverGroupBucket(treatment, port, groupId);
                break;
            case ALL:
                groupBucket = DefaultGroupBucket.createAllGroupBucket(treatment);
                break;
            default:
                log.error("Unsupported Group type : {}", type);
        }
        if (groupBucket != null) {
            bucketList.add(groupBucket);
        }
    }
    return new GroupBuckets(bucketList);
}
Also used : OFBucket(org.projectfloodlight.openflow.protocol.OFBucket) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) PortNumber(org.onosproject.net.PortNumber) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupId(org.onosproject.core.GroupId)

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