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));
}
}
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();
}
}
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);
}
}
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);
}
}
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);
}
}
}
}
Aggregations