Search in sources :

Example 46 with GroupId

use of org.onosproject.core.GroupId in project onos by opennetworkinglab.

the class SimpleVirtualGroupStore method updateGroupDescription.

@Override
public void updateGroupDescription(NetworkId networkId, DeviceId deviceId, GroupKey oldAppCookie, UpdateType type, GroupBuckets newBuckets, GroupKey newAppCookie) {
    // Check if a group is existing with the provided key
    Group oldGroup = getGroup(networkId, 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(Group.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(networkId, oldGroup.deviceId());
        ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(networkId, oldGroup.deviceId());
        keyTable.remove(oldGroup.appCookie());
        idTable.remove(oldGroup.id());
        keyTable.put(newGroup.appCookie(), newGroup);
        idTable.put(newGroup.id(), newGroup);
        notifyDelegate(networkId, new GroupEvent(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 47 with GroupId

use of org.onosproject.core.GroupId in project onos by opennetworkinglab.

the class Ofdpa2GroupHandler method createL2L3ChainInternal.

/**
 * Internal implementation of createL2L3Chain.
 * <p>
 * The is_present bit in set_vlan_vid action is required to be 0 in OFDPA i12.
 * Since it is non-OF spec, we need an extension treatment for that.
 * The useSetVlanExtension must be set to false for OFDPA i12.
 * </p>
 *
 * @param treatment that needs to be broken up to create the group chain
 * @param nextId of the next objective that needs this group chain
 * @param appId of the application that sent this next objective
 * @param mpls determines if L3Unicast or MPLSInterface group is created
 * @param meta metadata passed in by the application as part of the nextObjective
 * @param useSetVlanExtension use the setVlanVid extension that has is_present bit set to 0.
 * @return GroupInfo containing the GroupDescription of the
 *         L2Interface group(inner) and the GroupDescription of the (outer)
 *         L3Unicast/MPLSInterface group. May return null if there is an
 *         error in processing the chain
 */
protected GroupInfo createL2L3ChainInternal(TrafficTreatment treatment, int nextId, ApplicationId appId, boolean mpls, TrafficSelector meta, boolean useSetVlanExtension) {
    // for the l2interface group, get vlan and port info
    // for the outer group, get the src/dst mac, and vlan info
    TrafficTreatment.Builder outerTtb = DefaultTrafficTreatment.builder();
    TrafficTreatment.Builder innerTtb = DefaultTrafficTreatment.builder();
    VlanId vlanid = null;
    long portNum = 0;
    boolean setVlan = false, popVlan = false;
    MacAddress srcMac;
    MacAddress dstMac;
    for (Instruction ins : treatment.allInstructions()) {
        if (ins.type() == Instruction.Type.L2MODIFICATION) {
            L2ModificationInstruction l2ins = (L2ModificationInstruction) ins;
            switch(l2ins.subtype()) {
                case ETH_DST:
                    dstMac = ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac();
                    outerTtb.setEthDst(dstMac);
                    break;
                case ETH_SRC:
                    srcMac = ((L2ModificationInstruction.ModEtherInstruction) l2ins).mac();
                    outerTtb.setEthSrc(srcMac);
                    break;
                case VLAN_ID:
                    vlanid = ((L2ModificationInstruction.ModVlanIdInstruction) l2ins).vlanId();
                    if (useSetVlanExtension) {
                        OfdpaSetVlanVid ofdpaSetVlanVid = new OfdpaSetVlanVid(vlanid);
                        outerTtb.extension(ofdpaSetVlanVid, deviceId);
                    } else {
                        outerTtb.setVlanId(vlanid);
                    }
                    setVlan = true;
                    break;
                case VLAN_POP:
                    innerTtb.popVlan();
                    popVlan = true;
                    break;
                case DEC_MPLS_TTL:
                case MPLS_LABEL:
                case MPLS_POP:
                case MPLS_PUSH:
                case VLAN_PCP:
                case VLAN_PUSH:
                default:
                    break;
            }
        } else if (ins.type() == Instruction.Type.OUTPUT) {
            portNum = ((Instructions.OutputInstruction) ins).port().toLong();
            innerTtb.add(ins);
        } else {
            log.debug("Driver does not handle this type of TrafficTreatment" + " instruction in l2l3chain:  {} - {}", ins.type(), ins);
        }
    }
    if (vlanid == null && meta != null) {
        // use metadata if available
        Criterion vidCriterion = meta.getCriterion(VLAN_VID);
        if (vidCriterion != null) {
            vlanid = ((VlanIdCriterion) vidCriterion).vlanId();
        }
        // if vlan is not set, use the vlan in metadata for outerTtb
        if (vlanid != null && !setVlan) {
            if (useSetVlanExtension) {
                OfdpaSetVlanVid ofdpaSetVlanVid = new OfdpaSetVlanVid(vlanid);
                outerTtb.extension(ofdpaSetVlanVid, deviceId);
            } else {
                outerTtb.setVlanId(vlanid);
            }
        }
    }
    if (vlanid == null) {
        log.error("Driver cannot process an L2/L3 group chain without " + "egress vlan information for dev: {} port:{}", deviceId, portNum);
        return null;
    }
    if (!setVlan && !popVlan) {
        // untagged outgoing port
        TrafficTreatment.Builder temp = DefaultTrafficTreatment.builder();
        temp.popVlan();
        innerTtb.build().allInstructions().forEach(temp::add);
        innerTtb = temp;
    }
    // assemble information for ofdpa l2interface group
    int l2groupId = l2GroupId(vlanid, portNum);
    // a globally unique groupkey that is different for ports in the same device,
    // but different for the same portnumber on different devices. Also different
    // for the various group-types created out of the same next objective.
    int l2gk = l2InterfaceGroupKey(deviceId, vlanid, portNum);
    final GroupKey l2groupkey = new DefaultGroupKey(appKryo.serialize(l2gk));
    // assemble information for outer group
    GroupDescription outerGrpDesc;
    if (mpls) {
        // outer group is MPLS Interface
        int mplsInterfaceIndex = getNextAvailableIndex();
        int mplsGroupId = MPLS_INTERFACE_TYPE | (SUBTYPE_MASK & mplsInterfaceIndex);
        final GroupKey mplsGroupKey = new DefaultGroupKey(appKryo.serialize(mplsInterfaceIndex));
        outerTtb.group(new GroupId(l2groupId));
        // create the mpls-interface group description to wait for the
        // l2 interface group to be processed
        GroupBucket mplsinterfaceGroupBucket = DefaultGroupBucket.createIndirectGroupBucket(outerTtb.build());
        outerGrpDesc = new DefaultGroupDescription(deviceId, GroupDescription.Type.INDIRECT, new GroupBuckets(Collections.singletonList(mplsinterfaceGroupBucket)), mplsGroupKey, mplsGroupId, appId);
        log.debug("Trying MPLS-Interface: device:{} gid:{} gkey:{} nextid:{}", deviceId, Integer.toHexString(mplsGroupId), mplsGroupKey, nextId);
    } else {
        // outer group is L3Unicast
        int l3unicastIndex = getNextAvailableIndex();
        int l3groupId = L3_UNICAST_TYPE | (TYPE_MASK & l3unicastIndex);
        final GroupKey l3groupkey = new DefaultGroupKey(appKryo.serialize(l3unicastIndex));
        outerTtb.group(new GroupId(l2groupId));
        // create the l3unicast group description to wait for the
        // l2 interface group to be processed
        GroupBucket l3unicastGroupBucket = DefaultGroupBucket.createIndirectGroupBucket(outerTtb.build());
        outerGrpDesc = new DefaultGroupDescription(deviceId, GroupDescription.Type.INDIRECT, new GroupBuckets(Collections.singletonList(l3unicastGroupBucket)), l3groupkey, l3groupId, appId);
        log.debug("Trying L3Unicast: device:{} gid:{} gkey:{} nextid:{}", deviceId, Integer.toHexString(l3groupId), l3groupkey, nextId);
    }
    // store l2groupkey with the groupChainElem for the outer-group that depends on it
    GroupChainElem gce = new GroupChainElem(outerGrpDesc, 1, false, deviceId);
    updatePendingGroups(l2groupkey, gce);
    // create group description for the inner l2 interface group
    GroupBucket l2InterfaceGroupBucket = DefaultGroupBucket.createIndirectGroupBucket(innerTtb.build());
    GroupDescription l2groupDescription = new DefaultGroupDescription(deviceId, GroupDescription.Type.INDIRECT, new GroupBuckets(Collections.singletonList(l2InterfaceGroupBucket)), l2groupkey, l2groupId, appId);
    log.debug("Trying L2Interface: device:{} gid:{} gkey:{} nextId:{}", deviceId, Integer.toHexString(l2groupId), l2groupkey, nextId);
    return new GroupInfo(l2groupDescription, outerGrpDesc);
}
Also used : OfdpaSetVlanVid(org.onosproject.driver.extensions.OfdpaSetVlanVid) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) OfdpaGroupHandlerUtility.l2MulticastGroupKey(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.l2MulticastGroupKey) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Instructions(org.onosproject.net.flow.instructions.Instructions) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) MacAddress(org.onlab.packet.MacAddress) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) GroupInstruction(org.onosproject.net.flow.instructions.Instructions.GroupInstruction) GroupBuckets(org.onosproject.net.group.GroupBuckets) GroupId(org.onosproject.core.GroupId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) TunnelIdCriterion(org.onosproject.net.flow.criteria.TunnelIdCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) VlanId(org.onlab.packet.VlanId)

Example 48 with GroupId

use of org.onosproject.core.GroupId in project onos by opennetworkinglab.

the class Ofdpa2GroupHandler method processL2HashedNextObjective.

/**
 * Create L2 hash group.
 *
 * @param nextObj next objective
 */
private void processL2HashedNextObjective(NextObjective nextObj) {
    int l2LbIndex = Optional.ofNullable(nextObj.meta().getCriterion(IN_PORT)).map(c -> (PortCriterion) c).map(PortCriterion::port).map(PortNumber::toLong).map(Long::intValue).orElse(-1);
    if (l2LbIndex == -1) {
        log.warn("l2LbIndex is not found in the meta of L2 hash objective. Abort");
        return;
    }
    // Storage for all group keys in the chain of groups created
    List<Deque<GroupKey>> allGroupKeys = new ArrayList<>();
    List<GroupInfo> unsentGroups = new ArrayList<>();
    createL2HashBuckets(nextObj, allGroupKeys, unsentGroups);
    // Create L2 load balancing group
    List<GroupBucket> l2LbGroupBuckets = new ArrayList<>();
    for (GroupInfo gi : unsentGroups) {
        // create load balancing bucket to point to the outer group
        TrafficTreatment.Builder ttb = DefaultTrafficTreatment.builder();
        ttb.group(new GroupId(gi.nextGroupDesc().givenGroupId()));
        GroupBucket sbucket = DefaultGroupBucket.createSelectGroupBucket(ttb.build());
        l2LbGroupBuckets.add(sbucket);
    }
    int l2LbGroupId = L2_LB_TYPE | (TYPE_MASK & l2LbIndex);
    int l2lbgk = l2HashGroupKey(deviceId, l2LbIndex);
    GroupKey l2LbGroupKey = new DefaultGroupKey(appKryo.serialize(l2lbgk));
    GroupDescription l2LbGroupDesc = new DefaultGroupDescription(deviceId, SELECT, new GroupBuckets(l2LbGroupBuckets), l2LbGroupKey, l2LbGroupId, nextObj.appId());
    GroupChainElem l2LbGce = new GroupChainElem(l2LbGroupDesc, l2LbGroupBuckets.size(), false, deviceId);
    // Create objects for local and distributed storage
    allGroupKeys.forEach(gKeyChain -> gKeyChain.addFirst(l2LbGroupKey));
    OfdpaNextGroup ofdpaGrp = new OfdpaNextGroup(allGroupKeys, nextObj);
    // Store l2LbGroupKey with the ofdpaGroupChain for the nextObjective that depends on it
    updatePendingNextObjective(l2LbGroupKey, ofdpaGrp);
    log.debug("Trying L2-LB: device:{} gid:{} gkey:{} nextId:{}", deviceId, Integer.toHexString(l2LbGroupId), l2LbGroupKey, nextObj.id());
    // finally we are ready to send the innermost groups
    for (GroupInfo gi : unsentGroups) {
        log.debug("Sending innermost group {} in group chain on device {} ", Integer.toHexString(gi.innerMostGroupDesc().givenGroupId()), deviceId);
        updatePendingGroups(gi.nextGroupDesc().appCookie(), l2LbGce);
        groupService.addGroup(gi.innerMostGroupDesc());
    }
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) OfdpaGroupHandlerUtility.l2MulticastGroupKey(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.l2MulticastGroupKey) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) Deque(java.util.Deque) ArrayDeque(java.util.ArrayDeque) 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) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) PortNumber(org.onosproject.net.PortNumber) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Example 49 with GroupId

use of org.onosproject.core.GroupId in project onos by opennetworkinglab.

the class Ofdpa2GroupHandler method createMplsSwap.

/**
 * Creates an Mpls group of type swap.
 *
 * @param nextGroupId the next group in the chain
 * @param subtype the mpls swap label group subtype
 * @param index the index of the group
 * @param mplsLabel the mpls label to swap
 * @param applicationId the application id
 * @return the group description
 */
protected GroupDescription createMplsSwap(int nextGroupId, OfdpaMplsGroupSubType subtype, int index, MplsLabel mplsLabel, ApplicationId applicationId) {
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    treatment.setMpls(mplsLabel);
    // We point the group to the next group.
    treatment.group(new GroupId(nextGroupId));
    GroupBucket groupBucket = DefaultGroupBucket.createIndirectGroupBucket(treatment.build());
    // Finally we build the group description.
    int groupId = makeMplsLabelGroupId(subtype, index);
    GroupKey groupKey = new DefaultGroupKey(Ofdpa2Pipeline.appKryo.serialize(index));
    return new DefaultGroupDescription(deviceId, INDIRECT, new GroupBuckets(Collections.singletonList(groupBucket)), groupKey, groupId, applicationId);
}
Also used : GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) OfdpaGroupHandlerUtility.l2MulticastGroupKey(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.l2MulticastGroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupId(org.onosproject.core.GroupId)

Example 50 with GroupId

use of org.onosproject.core.GroupId in project onos by opennetworkinglab.

the class Ofdpa2GroupHandler method createL2MulticastGroup.

private void createL2MulticastGroup(NextObjective nextObj, VlanId vlanId, List<GroupInfo> groupInfos) {
    // Realize & represent L2 multicast group in OFDPA driver layer
    // TODO : Need to identify significance of OfdpaNextGroup.
    Integer l2MulticastGroupId = L2_MULTICAST_TYPE | (vlanId.toShort() << 16);
    final GroupKey l2MulticastGroupKey = l2MulticastGroupKey(vlanId, deviceId);
    List<Deque<GroupKey>> l2MulticastAllGroup = Lists.newArrayList();
    groupInfos.forEach(groupInfo -> {
        Deque<GroupKey> groupKeyChain = new ArrayDeque<>();
        groupKeyChain.addFirst(groupInfo.innerMostGroupDesc().appCookie());
        groupKeyChain.addFirst(l2MulticastGroupKey);
        l2MulticastAllGroup.add(groupKeyChain);
    });
    OfdpaNextGroup ofdpaL2MulticastGroup = new OfdpaNextGroup(l2MulticastAllGroup, nextObj);
    updatePendingNextObjective(l2MulticastGroupKey, ofdpaL2MulticastGroup);
    // Group Chain Hierarchy creation using group service and thus in device level
    List<GroupBucket> l2McastBuckets = new ArrayList<>();
    groupInfos.forEach(groupInfo -> {
        // Points to L2 interface group directly.
        TrafficTreatment.Builder trafficTreatment = DefaultTrafficTreatment.builder();
        trafficTreatment.group(new GroupId(groupInfo.innerMostGroupDesc().givenGroupId()));
        GroupBucket bucket = DefaultGroupBucket.createAllGroupBucket(trafficTreatment.build());
        l2McastBuckets.add(bucket);
    });
    GroupDescription l2MulticastGroupDescription = new DefaultGroupDescription(deviceId, ALL, new GroupBuckets(l2McastBuckets), l2MulticastGroupKey, l2MulticastGroupId, nextObj.appId());
    GroupChainElem l2MulticastGce = new GroupChainElem(l2MulticastGroupDescription, groupInfos.size(), false, deviceId);
    groupInfos.forEach(groupInfo -> {
        updatePendingGroups(groupInfo.innerMostGroupDesc().appCookie(), l2MulticastGce);
        groupService.addGroup(groupInfo.innerMostGroupDesc());
    });
}
Also used : GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) OfdpaGroupHandlerUtility.l2MulticastGroupKey(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.l2MulticastGroupKey) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) Deque(java.util.Deque) ArrayDeque(java.util.ArrayDeque) ArrayDeque(java.util.ArrayDeque) GroupId(org.onosproject.core.GroupId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Aggregations

GroupId (org.onosproject.core.GroupId)59 GroupBucket (org.onosproject.net.group.GroupBucket)30 GroupKey (org.onosproject.net.group.GroupKey)29 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)26 GroupBuckets (org.onosproject.net.group.GroupBuckets)26 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)25 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)24 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)21 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)19 GroupDescription (org.onosproject.net.group.GroupDescription)19 DefaultGroup (org.onosproject.net.group.DefaultGroup)18 Group (org.onosproject.net.group.Group)17 GroupEvent (org.onosproject.net.group.GroupEvent)12 ArrayList (java.util.ArrayList)11 PortNumber (org.onosproject.net.PortNumber)11 Instruction (org.onosproject.net.flow.instructions.Instruction)10 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)10 StoredGroupEntry (org.onosproject.net.group.StoredGroupEntry)10 OfdpaGroupHandlerUtility.l2MulticastGroupKey (org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.l2MulticastGroupKey)9 MacAddress (org.onlab.packet.MacAddress)8