@Test public void groupStatsEvent() { TestOpenFlowGroupProviderService testProviderService = (TestOpenFlowGroupProviderService) providerService; OFGroupStatsReply.Builder rep1 = OFFactories.getFactory(OFVersion.OF_13).buildGroupStatsReply(); rep1.setXid(1); controller.processPacket(dpid1, rep1.build()); OFGroupDescStatsReply.Builder rep2 = OFFactories.getFactory(OFVersion.OF_13).buildGroupDescStatsReply(); assertNull("group entries is not set yet", testProviderService.getGroupEntries()); rep2.setXid(2); controller.processPacket(dpid1, rep2.build()); assertNotNull("group entries should be set", testProviderService.getGroupEntries()); }
private synchronized Collection<OFGroupStatsEntry> publishGroupStats(Dpid dpid, OFGroupStatsReply reply) { //TODO: Get rid of synchronized fullGroupStats.putAll(dpid, reply.getEntries()); if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { return fullGroupStats.removeAll(dpid); } return null; }
/*** * Serializes the Group Statistics Reply * @author Naveen * @param groupReplies * @param jGen * @throws IOException * @throws JsonProcessingException */ public static void serializeGroupReply(List<OFGroupStatsReply> groupReplies, JsonGenerator jGen) throws IOException, JsonProcessingException{ OFGroupStatsReply groupReply = groupReplies.get(0); // we will get only one GroupReply and it will contains many OFGroupStatsEntry jGen.writeStringField("version", groupReply.getVersion().toString()); //return the enum name jGen.writeFieldName("group"); jGen.writeStartArray(); for(OFGroupStatsEntry entry : groupReply.getEntries()) { jGen.writeStartObject(); jGen.writeStringField("groupNumber",entry.getGroup().toString()); jGen.writeNumberField("refCount", entry.getRefCount()); jGen.writeNumberField("packetCount", entry.getPacketCount().getValue()); jGen.writeNumberField("byteCount", entry.getByteCount().getValue()); jGen.writeFieldName("bucketCounters"); jGen.writeStartArray(); for(OFBucketCounter bCounter : entry.getBucketStats()) { jGen.writeStartObject(); jGen.writeNumberField("packetCount", bCounter.getPacketCount().getValue()); jGen.writeNumberField("byteCount", bCounter.getByteCount().getValue()); jGen.writeEndObject(); }//end of for loop - BucketCounter jGen.writeEndArray(); if (OFVersion.OF_13 == entry.getVersion()) { jGen.writeNumberField("durationSec", entry.getDurationSec()); jGen.writeNumberField("durationNsec", entry.getDurationNsec()); } jGen.writeEndObject(); }//end of for loop - groupStats jGen.writeEndArray(); }
protected Object getSwitchGroupStats(String switchId, OFStatsType statType, Integer groupId) { IFloodlightProviderService floodlightProvider = (IFloodlightProviderService) getContext().getAttributes(). get(IFloodlightProviderService.class.getCanonicalName()); IOFSwitch sw = floodlightProvider.getSwitches().get(HexString.toLong(switchId)); Future<List<OFStatsReply>> future; List<OFStatsReply> values = null; if (sw != null){ log.debug("Switch Group Stats: req sent for groupId {} " + "in switch {}",groupId, sw.getStringId()); OFStatsRequest<?> req = null; req = sw.getFactory().buildGroupStatsRequest().setXid (sw.getNextTransactionId()).setGroup(OFGroup.of(groupId)).build(); List<OFGroupStatsEntryMod> groupStats = new ArrayList<OFGroupStatsEntryMod>(); try { future = sw.getStatistics(req); values = future.get(10, TimeUnit.SECONDS); if(values.isEmpty()){ log.warn("group with groupId {} not found", groupId); return null; } for(OFStatsReply value : values){ for (OFGroupStatsEntry entry : ((OFGroupStatsReply)value).getEntries()) { OFGroupStatsEntryMod entryMod = new OFGroupStatsEntryMod(entry); groupStats.add(entryMod); } } log.debug("Switch Group Stats Entries from switch {} are {}", sw.getStringId(), groupStats); } catch (Exception e) { log.error("Failure retrieving statistics from switch " + sw, e); } return groupStats; } return null; }