Search in sources :

Example 1 with DefaultGroup

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

the class SimpleVirtualGroupStore method storeGroupDescriptionInternal.

private void storeGroupDescriptionInternal(NetworkId networkId, GroupDescription groupDesc) {
    // Check if a group is existing with the same key
    if (getGroup(networkId, groupDesc.deviceId(), groupDesc.appCookie()) != null) {
        return;
    }
    GroupId id = null;
    if (groupDesc.givenGroupId() == null) {
        // Get a new group identifier
        id = new GroupId(getFreeGroupIdValue(networkId, 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(networkId, groupDesc.deviceId());
    keyTable.put(groupDesc.appCookie(), group);
    ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(networkId, groupDesc.deviceId());
    idTable.put(id, group);
    notifyDelegate(networkId, 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 2 with DefaultGroup

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

the class SimpleVirtualGroupStore method storeGroupDescription.

@Override
public void storeGroupDescription(NetworkId networkId, GroupDescription groupDesc) {
    // Check if a group is existing with the same key
    if (getGroup(networkId, groupDesc.deviceId(), groupDesc.appCookie()) != null) {
        return;
    }
    if (deviceAuditStatus.get(networkId) == null || deviceAuditStatus.get(networkId).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(Group.GroupState.WAITING_AUDIT_COMPLETE);
        ConcurrentMap<GroupKey, StoredGroupEntry> pendingKeyTable = getPendingGroupKeyTable(networkId, groupDesc.deviceId());
        pendingKeyTable.put(groupDesc.appCookie(), group);
        return;
    }
    storeGroupDescriptionInternal(networkId, groupDesc);
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupKey(org.onosproject.net.group.GroupKey) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry)

Example 3 with DefaultGroup

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

the class VirtualNetworkGroupManagerTest method testAuditWithConfirmedGroups.

// Test AUDIT with confirmed groups
private void testAuditWithConfirmedGroups(NetworkId networkId, DeviceId deviceId) {
    VirtualNetworkGroupManager groupManager;
    VirtualGroupProviderService providerService;
    TestGroupListener listener;
    if (networkId.id() == 1) {
        groupManager = groupManager1;
        providerService = providerService1;
        listener = listener1;
    } else {
        groupManager = groupManager2;
        providerService = providerService2;
        listener = listener2;
    }
    GroupKey key = new DefaultGroupKey("group1BeforeAudit".getBytes());
    Group createdGroup = groupManager.getGroup(deviceId, key);
    createdGroup = new DefaultGroup(createdGroup.id(), deviceId, Group.Type.SELECT, createdGroup.buckets());
    List<Group> groupEntries = Collections.singletonList(createdGroup);
    providerService.pushGroupMetrics(deviceId, groupEntries);
    listener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_ADDED));
}
Also used : VirtualGroupProviderService(org.onosproject.incubator.net.virtual.provider.VirtualGroupProviderService) DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) DefaultGroup(org.onosproject.net.group.DefaultGroup)

Example 4 with DefaultGroup

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

the class VirtualNetworkGroupManagerTest method createSouthboundGroupEntry.

private Group createSouthboundGroupEntry(GroupId gId, List<PortNumber> ports, long referenceCount, DeviceId deviceId) {
    List<PortNumber> outPorts = new ArrayList<>();
    outPorts.addAll(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);
    StoredGroupEntry group = new DefaultGroup(gId, deviceId, Group.Type.SELECT, groupBuckets);
    group.setReferenceCount(referenceCount);
    return group;
}
Also used : ArrayList(java.util.ArrayList) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry)

Example 5 with DefaultGroup

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

the class GroupCodec method decode.

@Override
public Group decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    final JsonCodec<GroupBucket> groupBucketCodec = context.codec(GroupBucket.class);
    CoreService coreService = context.getService(CoreService.class);
    // parse uInt Group id from the ID field
    JsonNode idNode = json.get(ID);
    Long id = (null == idNode) ? // use GROUP_ID for the corresponding Group id if ID is not supplied
    nullIsIllegal(json.get(GROUP_ID), ID + MISSING_MEMBER_MESSAGE).asLong() : idNode.asLong();
    GroupId groupId = GroupId.valueOf(id.intValue());
    // parse uInt Group id given by caller. see the GroupDescription javadoc
    JsonNode givenGroupIdNode = json.get(GIVEN_GROUP_ID);
    // if GIVEN_GROUP_ID is not supplied, set null so the group subsystem
    // to choose the Group id (which is the value of ID indeed).
    // else, must be same with ID to show both originate from the same source
    Integer givenGroupIdInt = (null == givenGroupIdNode) ? null : new Long(json.get(GIVEN_GROUP_ID).asLong()).intValue();
    if (givenGroupIdInt != null && !givenGroupIdInt.equals(groupId.id())) {
        throw new IllegalArgumentException(GIVEN_GROUP_ID + " must be same with " + ID);
    }
    // parse group key (appCookie)
    String groupKeyStr = nullIsIllegal(json.get(APP_COOKIE), APP_COOKIE + MISSING_MEMBER_MESSAGE).asText();
    if (!groupKeyStr.startsWith("0x")) {
        throw new IllegalArgumentException("APP_COOKIE must be a hex string starts with 0x");
    }
    GroupKey groupKey = new DefaultGroupKey(HexString.fromHexString(groupKeyStr.split("0x")[1], ""));
    // parse device id
    DeviceId deviceId = DeviceId.deviceId(nullIsIllegal(json.get(DEVICE_ID), DEVICE_ID + MISSING_MEMBER_MESSAGE).asText());
    // application id
    ApplicationId appId = coreService.registerApplication(REST_APP_ID);
    // parse group type
    String type = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText();
    GroupDescription.Type groupType = null;
    switch(type) {
        case "SELECT":
            groupType = Group.Type.SELECT;
            break;
        case "INDIRECT":
            groupType = Group.Type.INDIRECT;
            break;
        case "ALL":
            groupType = Group.Type.ALL;
            break;
        case "CLONE":
            groupType = Group.Type.CLONE;
            break;
        case "FAILOVER":
            groupType = Group.Type.FAILOVER;
            break;
        default:
            nullIsIllegal(groupType, "The requested group type " + type + " is not valid");
    }
    // parse group buckets
    GroupBuckets buckets = null;
    List<GroupBucket> groupBucketList = new ArrayList<>();
    JsonNode bucketsJson = json.get(BUCKETS);
    checkNotNull(bucketsJson);
    if (bucketsJson != null) {
        IntStream.range(0, bucketsJson.size()).forEach(i -> {
            ObjectNode bucketJson = get(bucketsJson, i);
            bucketJson.put("type", type);
            groupBucketList.add(groupBucketCodec.decode(bucketJson, context));
        });
        buckets = new GroupBuckets(groupBucketList);
    }
    GroupDescription groupDescription = new DefaultGroupDescription(deviceId, groupType, buckets, groupKey, givenGroupIdInt, appId);
    return new DefaultGroup(groupId, groupDescription);
}
Also used : 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) DefaultGroup(org.onosproject.net.group.DefaultGroup) CoreService(org.onosproject.core.CoreService) JsonNode(com.fasterxml.jackson.databind.JsonNode) HexString(org.onlab.util.HexString) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupId(org.onosproject.core.GroupId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) GroupBucket(org.onosproject.net.group.GroupBucket) ApplicationId(org.onosproject.core.ApplicationId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Aggregations

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