Search in sources :

Example 16 with Group

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

the class PointToPointIntentCompiler method updateFailoverGroup.

// Removes buckets whose treatments rely on disabled ports from the
// failover group.
private void updateFailoverGroup(PointToPointIntent pointIntent) {
    DeviceId deviceId = pointIntent.filteredIngressPoint().connectPoint().deviceId();
    GroupKey groupKey = makeGroupKey(pointIntent.id());
    Group group = waitForGroup(deviceId, groupKey);
    Iterator<GroupBucket> groupIterator = group.buckets().buckets().iterator();
    while (groupIterator.hasNext()) {
        GroupBucket bucket = groupIterator.next();
        Instruction individualInstruction = bucket.treatment().allInstructions().get(0);
        if (individualInstruction instanceof Instructions.OutputInstruction) {
            Instructions.OutputInstruction outInstruction = (Instructions.OutputInstruction) individualInstruction;
            Port port = deviceService.getPort(deviceId, outInstruction.port());
            if (port == null || !port.isEnabled()) {
                GroupBuckets removeBuckets = new GroupBuckets(Collections.singletonList(bucket));
                groupService.removeBucketsFromGroup(deviceId, groupKey, removeBuckets, groupKey, pointIntent.appId());
            }
        }
    }
}
Also used : Group(org.onosproject.net.group.Group) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) Instructions(org.onosproject.net.flow.instructions.Instructions) Instruction(org.onosproject.net.flow.instructions.Instruction) GroupBuckets(org.onosproject.net.group.GroupBuckets)

Example 17 with Group

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

the class P4RuntimeActionGroupProgrammable method performGroupOperation.

@Override
public void performGroupOperation(DeviceId deviceId, GroupOperations groupOps) {
    if (!setupBehaviour("performGroupOperation()")) {
        return;
    }
    groupOps.operations().forEach(op -> {
        // ONOS-7785 We need the group app cookie (which includes
        // the action profile ID) but this is not part of the
        // GroupDescription.
        Group groupOnStore = groupStore.getGroup(deviceId, op.groupId());
        if (groupOnStore == null) {
            log.warn("Unable to find group {} in store, aborting {} operation [{}]", op.groupId(), op.opType(), op);
            return;
        }
        GroupDescription groupDesc = new DefaultGroupDescription(deviceId, groupOnStore.type(), groupOnStore.buckets(), groupOnStore.appCookie(), groupOnStore.id().id(), groupOnStore.appId());
        DefaultGroup groupToApply = new DefaultGroup(op.groupId(), groupDesc);
        processPdGroup(groupToApply, op.opType());
    });
}
Also used : DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group) PiActionProfileGroup(org.onosproject.net.pi.runtime.PiActionProfileGroup) DefaultGroup(org.onosproject.net.group.DefaultGroup) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription)

Example 18 with Group

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

the class DefaultOFSwitch method processStatsRequest.

@Override
public void processStatsRequest(Channel channel, OFMessage msg) {
    if (msg.getType() != OFType.STATS_REQUEST) {
        log.warn("Ignoring message of type {}.", msg.getType());
        return;
    }
    OFStatsRequest ofStatsRequest = (OFStatsRequest) msg;
    OFStatsReply ofStatsReply = null;
    switch(ofStatsRequest.getStatsType()) {
        case PORT_DESC:
            List<OFPortDesc> portDescs = new ArrayList<>();
            Set<Port> ports = ofSwitchService.ports(networkId, deviceId);
            ports.forEach(port -> {
                OFPortDesc ofPortDesc = portDesc(port);
                portDescs.add(ofPortDesc);
            });
            ofStatsReply = FACTORY.buildPortDescStatsReply().setXid(msg.getXid()).setEntries(portDescs).build();
            break;
        case PORT:
            OFPortStatsRequest portStatsRequest = (OFPortStatsRequest) msg;
            OFPort ofPort = portStatsRequest.getPortNo();
            List<OFPortStatsEntry> portStatsEntries = new ArrayList<>();
            List<PortStatistics> portStatistics = ofSwitchService.getPortStatistics(networkId, deviceId);
            if (ofPort.equals(OFPort.ANY)) {
                portStatistics.forEach(portStatistic -> {
                    OFPortStatsEntry ofPortStatsEntry = portStatsEntry(portStatistic);
                    portStatsEntries.add(ofPortStatsEntry);
                });
            }
            ofStatsReply = FACTORY.buildPortStatsReply().setEntries(portStatsEntries).setXid(msg.getXid()).build();
            break;
        case METER_FEATURES:
            OFMeterFeatures ofMeterFeatures = FACTORY.buildMeterFeatures().build();
            ofStatsReply = FACTORY.buildMeterFeaturesStatsReply().setXid(msg.getXid()).setFeatures(ofMeterFeatures).build();
            break;
        case FLOW:
            List<OFFlowStatsEntry> flowStatsEntries = new ArrayList<>();
            List<FlowEntry> flowStats = ofSwitchService.getFlowEntries(networkId, deviceId);
            flowStats.forEach(flowEntry -> {
                OFFlowStatsEntry ofFlowStatsEntry = ofFlowStatsEntry(flowEntry);
                flowStatsEntries.add(ofFlowStatsEntry);
            });
            ofStatsReply = FACTORY.buildFlowStatsReply().setEntries(flowStatsEntries).setXid(msg.getXid()).build();
            break;
        case TABLE:
            List<OFTableStatsEntry> ofTableStatsEntries = new ArrayList<>();
            List<TableStatisticsEntry> tableStats = ofSwitchService.getFlowTableStatistics(networkId, deviceId);
            tableStats.forEach(tableStatisticsEntry -> {
                OFTableStatsEntry ofFlowStatsEntry = ofFlowTableStatsEntry(tableStatisticsEntry);
                ofTableStatsEntries.add(ofFlowStatsEntry);
            });
            ofStatsReply = FACTORY.buildTableStatsReply().setEntries(ofTableStatsEntries).setXid(msg.getXid()).build();
            break;
        case GROUP:
            List<Group> groupStats = ofSwitchService.getGroups(networkId, deviceId);
            List<OFGroupStatsEntry> ofGroupStatsEntries = new ArrayList<>();
            groupStats.forEach(group -> {
                OFGroupStatsEntry entry = ofGroupStatsEntry(group);
                ofGroupStatsEntries.add(entry);
            });
            ofStatsReply = FACTORY.buildGroupStatsReply().setEntries(ofGroupStatsEntries).setXid(msg.getXid()).build();
            break;
        case GROUP_DESC:
            List<OFGroupDescStatsEntry> ofGroupDescStatsEntries = new ArrayList<>();
            List<Group> groupStats2 = ofSwitchService.getGroups(networkId, deviceId);
            groupStats2.forEach(group -> {
                OFGroupDescStatsEntry entry = ofGroupDescStatsEntry(group);
                ofGroupDescStatsEntries.add(entry);
            });
            ofStatsReply = FACTORY.buildGroupDescStatsReply().setEntries(ofGroupDescStatsEntries).setXid(msg.getXid()).build();
            break;
        case DESC:
            ofStatsReply = FACTORY.buildDescStatsReply().setXid(msg.getXid()).build();
            break;
        default:
            log.debug("Functionality not yet supported for type {} statsType{} msg {}", msg.getType(), ofStatsRequest.getStatsType(), msg);
            break;
    }
    if (ofStatsReply != null) {
        log.trace("request {}; reply {}", msg, ofStatsReply);
        channel.writeAndFlush(Collections.singletonList(ofStatsReply));
    }
}
Also used : OFStatsReply(org.projectfloodlight.openflow.protocol.OFStatsReply) OFGroup(org.projectfloodlight.openflow.types.OFGroup) Group(org.onosproject.net.group.Group) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) Port(org.onosproject.net.Port) OFPort(org.projectfloodlight.openflow.types.OFPort) ArrayList(java.util.ArrayList) OFPortStatsRequest(org.projectfloodlight.openflow.protocol.OFPortStatsRequest) FlowEntry(org.onosproject.net.flow.FlowEntry) OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) OFStatsRequest(org.projectfloodlight.openflow.protocol.OFStatsRequest) PortStatistics(org.onosproject.net.device.PortStatistics) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) OFGroupStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupStatsEntry) OFTableStatsEntry(org.projectfloodlight.openflow.protocol.OFTableStatsEntry) OFPort(org.projectfloodlight.openflow.types.OFPort) OFPortStatsEntry(org.projectfloodlight.openflow.protocol.OFPortStatsEntry) OFMeterFeatures(org.projectfloodlight.openflow.protocol.OFMeterFeatures)

Example 19 with Group

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

the class DistributedGroupStore 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) {
    log.debug("In storeGroupDescription id {} for dev {}", groupDesc.givenGroupId() != null ? "0x" + Integer.toHexString(groupDesc.givenGroupId()) : "N/A", groupDesc.deviceId());
    // Check if a group is existing with the same key
    Group existingGroup = getGroup(groupDesc.deviceId(), groupDesc.appCookie());
    if (existingGroup != null) {
        log.debug("Group already exists with the same key {} in dev:{} with id:{}", groupDesc.appCookie(), groupDesc.deviceId(), Integer.toHexString(existingGroup.id().id()));
        return;
    }
    // Check if group to be created by a remote instance
    if (mastershipService.getLocalRole(groupDesc.deviceId()) != MastershipRole.MASTER) {
        log.debug("storeGroupDescription: Device {} local role is not MASTER", groupDesc.deviceId());
        if (mastershipService.getMasterFor(groupDesc.deviceId()) == null) {
            log.debug("No Master for device {}..." + "Queuing Group id {} ADD request", groupDesc.deviceId(), groupDesc.givenGroupId() != null ? "0x" + Integer.toHexString(groupDesc.givenGroupId()) : "N/A");
            addToPendingAudit(groupDesc);
            return;
        }
        GroupStoreMessage groupOp = GroupStoreMessage.createGroupAddRequestMsg(groupDesc.deviceId(), groupDesc);
        clusterCommunicator.unicast(groupOp, GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST, clusterMsgSerializer::serialize, mastershipService.getMasterFor(groupDesc.deviceId())).whenComplete((result, error) -> {
            if (error != null) {
                log.warn("Failed to send request to master: id {} to {}", groupDesc.givenGroupId() != null ? "0x" + Integer.toHexString(groupDesc.givenGroupId()) : "N/A", mastershipService.getMasterFor(groupDesc.deviceId()));
            // TODO: Send Group operation failure event
            } else {
                log.debug("Sent Group operation id {} request for device {} " + "to remote MASTER {}", groupDesc.givenGroupId() != null ? "0x" + Integer.toHexString(groupDesc.givenGroupId()) : "N/A", groupDesc.deviceId(), mastershipService.getMasterFor(groupDesc.deviceId()));
            }
        });
        return;
    }
    log.debug("Store group id {} for device {} is getting handled locally", groupDesc.givenGroupId() != null ? "0x" + Integer.toHexString(groupDesc.givenGroupId()) : "N/A", groupDesc.deviceId());
    storeGroupDescriptionInternal(groupDesc);
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group)

Example 20 with Group

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

the class GroupsListCommand method json.

private JsonNode json(Map<Device, List<Group>> sortedGroups) {
    ArrayNode result = mapper().createArrayNode();
    sortedGroups.forEach((device, groups) -> groups.forEach(group -> result.add(jsonForEntity(group, Group.class))));
    return result;
}
Also used : Comparators(org.onosproject.utils.Comparators) DeviceService(org.onosproject.net.device.DeviceService) GroupBucket(org.onosproject.net.group.GroupBucket) Command(org.apache.karaf.shell.api.action.Command) Group(org.onosproject.net.group.Group) Lists(com.google.common.collect.Lists) GroupState(org.onosproject.net.group.Group.GroupState) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) Device(org.onosproject.net.Device) GroupService(org.onosproject.net.group.GroupService) Argument(org.apache.karaf.shell.api.action.Argument) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Optional(java.util.Optional) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) GroupDescription(org.onosproject.net.group.GroupDescription) Collections(java.util.Collections) SortedMap(java.util.SortedMap) Group(org.onosproject.net.group.Group) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

Group (org.onosproject.net.group.Group)120 DefaultGroup (org.onosproject.net.group.DefaultGroup)57 GroupKey (org.onosproject.net.group.GroupKey)56 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)45 GroupBucket (org.onosproject.net.group.GroupBucket)44 GroupBuckets (org.onosproject.net.group.GroupBuckets)42 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)38 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)38 NextGroup (org.onosproject.net.behaviour.NextGroup)37 ArrayList (java.util.ArrayList)36 GroupDescription (org.onosproject.net.group.GroupDescription)36 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)30 PortNumber (org.onosproject.net.PortNumber)27 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)26 DeviceId (org.onosproject.net.DeviceId)24 TrafficSelector (org.onosproject.net.flow.TrafficSelector)24 GroupId (org.onosproject.core.GroupId)23 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)21 FlowRule (org.onosproject.net.flow.FlowRule)20 Instruction (org.onosproject.net.flow.instructions.Instruction)20