Search in sources :

Example 1 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 2 with Group

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

the class ScalableGatewayManager method getGatewayGroupId.

@Override
public synchronized GroupId getGatewayGroupId(DeviceId srcDeviceId) {
    GroupKey groupKey = selectGroupHandler.getGroupKey(srcDeviceId);
    Group group = groupService.getGroup(srcDeviceId, groupKey);
    if (group == null) {
        log.info("Created gateway group for {}", srcDeviceId);
        return selectGroupHandler.createGatewayGroup(srcDeviceId, getGatewayNodes());
    } else {
        return group.id();
    }
}
Also used : Group(org.onosproject.net.group.Group) GroupKey(org.onosproject.net.group.GroupKey)

Example 3 with Group

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

the class OpenstackGroupRuleManager method setBuckets.

@Override
public void setBuckets(ApplicationId appId, DeviceId deviceId, int groupId, List<GroupBucket> buckets, boolean install) {
    if (!hasGroup(deviceId, groupId)) {
        return;
    }
    if (install) {
        // we add the buckets into the group, only if the buckets do not exist
        // in the given group
        Group group = groupService.getGroup(deviceId, getGroupKey(groupId));
        if (group.buckets() != null && !group.buckets().buckets().containsAll(buckets)) {
            groupService.addBucketsToGroup(deviceId, getGroupKey(groupId), new GroupBuckets(buckets), getGroupKey(groupId), appId);
            log.debug("Adding buckets for group rule {}", groupId);
        }
    } else {
        groupService.removeBucketsFromGroup(deviceId, getGroupKey(groupId), new GroupBuckets(buckets), getGroupKey(groupId), appId);
        log.debug("Removing buckets for group rule {}", groupId);
    }
}
Also used : Group(org.onosproject.net.group.Group) GroupBuckets(org.onosproject.net.group.GroupBuckets)

Example 4 with Group

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

the class SimpleVirtualGroupStore method pushGroupMetrics.

@Override
public void pushGroupMetrics(NetworkId networkId, DeviceId deviceId, Collection<Group> groupEntries) {
    boolean deviceInitialAuditStatus = deviceInitialAuditStatus(networkId, deviceId);
    Set<Group> southboundGroupEntries = Sets.newHashSet(groupEntries);
    Set<Group> storedGroupEntries = Sets.newHashSet(getGroups(networkId, deviceId));
    Set<Group> extraneousStoredEntries = Sets.newHashSet(getExtraneousGroups(networkId, deviceId));
    if (log.isTraceEnabled()) {
        log.trace("pushGroupMetrics: Displaying all ({}) " + "southboundGroupEntries for device {}", southboundGroupEntries.size(), deviceId);
        for (Group group : southboundGroupEntries) {
            log.trace("Group {} in device {}", group, deviceId);
        }
        log.trace("Displaying all ({}) stored group entries for device {}", storedGroupEntries.size(), deviceId);
        for (Group group : storedGroupEntries) {
            log.trace("Stored Group {} for device {}", group, deviceId);
        }
    }
    for (Iterator<Group> it2 = southboundGroupEntries.iterator(); it2.hasNext(); ) {
        Group group = it2.next();
        if (storedGroupEntries.remove(group)) {
            // we both have the group, let's update some info then.
            log.trace("Group AUDIT: group {} exists " + "in both planes for device {}", group.id(), deviceId);
            groupAdded(networkId, group);
            it2.remove();
        }
    }
    for (Group group : southboundGroupEntries) {
        if (getGroup(networkId, group.deviceId(), group.id()) != null) {
            // in progress while we got a stale info from switch
            if (!storedGroupEntries.remove(getGroup(networkId, group.deviceId(), group.id()))) {
                log.warn("Group AUDIT: Inconsistent state:" + "Group exists in ID based table while " + "not present in key based table");
            }
        } else {
            // there are groups in the switch that aren't in the store
            log.trace("Group AUDIT: extraneous group {} exists " + "in data plane for device {}", group.id(), deviceId);
            extraneousStoredEntries.remove(group);
            extraneousGroup(networkId, group);
        }
    }
    for (Group group : storedGroupEntries) {
        // there are groups in the store that aren't in the switch
        log.trace("Group AUDIT: group {} missing " + "in data plane for device {}", group.id(), deviceId);
        groupMissing(networkId, group);
    }
    for (Group group : extraneousStoredEntries) {
        // there are groups in the extraneous store that
        // aren't in the switch
        log.trace("Group AUDIT: clearing extransoeus group {} " + "from store for device {}", group.id(), deviceId);
        removeExtraneousGroupEntry(networkId, group);
    }
    if (!deviceInitialAuditStatus) {
        log.debug("Group AUDIT: Setting device {} initial " + "AUDIT completed", deviceId);
        deviceInitialAuditCompleted(networkId, deviceId, true);
    }
}
Also used : DefaultGroup(org.onosproject.net.group.DefaultGroup) Group(org.onosproject.net.group.Group)

Example 5 with Group

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

the class SimpleVirtualGroupStore method deviceInitialAuditCompleted.

@Override
public void deviceInitialAuditCompleted(NetworkId networkId, DeviceId deviceId, boolean completed) {
    deviceAuditStatus.computeIfAbsent(networkId, k -> new HashMap<>());
    HashMap<DeviceId, Boolean> deviceAuditStatusByNetwork = deviceAuditStatus.get(networkId);
    synchronized (deviceAuditStatusByNetwork) {
        if (completed) {
            log.debug("deviceInitialAuditCompleted: AUDIT " + "completed for device {}", deviceId);
            deviceAuditStatusByNetwork.put(deviceId, true);
            // Execute all pending group requests
            ConcurrentMap<GroupKey, StoredGroupEntry> pendingGroupRequests = getPendingGroupKeyTable(networkId, deviceId);
            for (Group group : pendingGroupRequests.values()) {
                GroupDescription tmp = new DefaultGroupDescription(group.deviceId(), group.type(), group.buckets(), group.appCookie(), group.givenGroupId(), group.appId());
                storeGroupDescriptionInternal(networkId, tmp);
            }
            getPendingGroupKeyTable(networkId, deviceId).clear();
        } else {
            if (deviceAuditStatusByNetwork.get(deviceId)) {
                log.debug("deviceInitialAuditCompleted: Clearing AUDIT " + "status for device {}", deviceId);
                deviceAuditStatusByNetwork.put(deviceId, false);
            }
        }
    }
}
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) DeviceId(org.onosproject.net.DeviceId) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) StoredGroupEntry(org.onosproject.net.group.StoredGroupEntry)

Aggregations

Group (org.onosproject.net.group.Group)117 DefaultGroup (org.onosproject.net.group.DefaultGroup)55 GroupKey (org.onosproject.net.group.GroupKey)54 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)43 GroupBucket (org.onosproject.net.group.GroupBucket)42 GroupBuckets (org.onosproject.net.group.GroupBuckets)40 ArrayList (java.util.ArrayList)36 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)36 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)36 NextGroup (org.onosproject.net.behaviour.NextGroup)35 GroupDescription (org.onosproject.net.group.GroupDescription)34 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)28 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)26 PortNumber (org.onosproject.net.PortNumber)25 GroupId (org.onosproject.core.GroupId)23 DeviceId (org.onosproject.net.DeviceId)22 TrafficSelector (org.onosproject.net.flow.TrafficSelector)22 Instruction (org.onosproject.net.flow.instructions.Instruction)20 Deque (java.util.Deque)19 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)19