alshabib
Committed by Gerrit Code Review

adding group garbage collection functionality

If a group has a reference count of zero for more than
a configurable timeout, it is garbage collected.

This feature can be deactivated by component config.

Change-Id: I254d62a90ef7ac8d2ce2f406b67957455a5bf4d0
......@@ -35,6 +35,7 @@ public class DefaultGroup extends DefaultGroupDescription
private long bytes;
private long referenceCount;
private GroupId id;
private int age;
/**
* Initializes default values.
......@@ -48,6 +49,7 @@ public class DefaultGroup extends DefaultGroupDescription
packets = 0;
bytes = 0;
referenceCount = 0;
age = 0;
}
/**
......@@ -128,6 +130,11 @@ public class DefaultGroup extends DefaultGroupDescription
return this.bytes;
}
@Override
public int age() {
return age;
}
/**
* Sets the new state for this entry.
*
......@@ -171,6 +178,11 @@ public class DefaultGroup extends DefaultGroupDescription
@Override
public void setReferenceCount(long referenceCount) {
this.referenceCount = referenceCount;
if (referenceCount == 0) {
age++;
} else {
age = 0;
}
}
@Override
......@@ -214,6 +226,7 @@ public class DefaultGroup extends DefaultGroupDescription
.add("description", super.toString())
.add("groupid", id)
.add("state", state)
.add("age", age)
.toString();
}
......
......@@ -96,4 +96,12 @@ public interface Group extends GroupDescription {
* @return number of flow rules or other groups pointing to this group
*/
long referenceCount();
/**
* Obtains the age of a group. The age reflects the number of polling rounds
* the group has had a reference count of zero.
*
* @return the age of the group as an integer
*/
int age();
}
......
......@@ -23,6 +23,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.junit.TestUtils;
import org.onosproject.cfg.ComponentConfigAdapter;
import org.onosproject.cluster.NodeId;
import org.onosproject.core.DefaultGroupId;
import org.onosproject.core.GroupId;
......@@ -129,6 +130,7 @@ public class DistributedGroupStoreTest {
groupStoreImpl.storageService = new TestStorageService();
groupStoreImpl.clusterCommunicator = new ClusterCommunicationServiceAdapter();
groupStoreImpl.mastershipService = new MasterOfAll();
groupStoreImpl.cfgService = new ComponentConfigAdapter();
groupStoreImpl.activate();
groupStore = groupStoreImpl;
auditPendingReqQueue =
......
......@@ -156,6 +156,11 @@ public class GroupsResourceTest extends ResourceTest {
}
@Override
public int age() {
return 0;
}
@Override
public Type type() {
return GroupDescription.Type.ALL;
}
......