private synchronized Collection<OFTableStatsEntry> publishTableStats(Dpid dpid, OFTableStatsReply reply) { //TODO: Get rid of synchronized fullTableStats.putAll(dpid, reply.getEntries()); if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { return fullTableStats.removeAll(dpid); } return null; }
private void pushTableStatistics(Dpid dpid, OFTableStatsReply replies) { DeviceId did = DeviceId.deviceId(Dpid.uri(dpid)); List<TableStatisticsEntry> tableStatsEntries = replies.getEntries().stream() .map(entry -> buildTableStatistics(did, entry)) .filter(Objects::nonNull) .collect(Collectors.toList()); providerService.pushTableStatistics(did, tableStatsEntries); }
@Override public void tableStatsProcess(Dpid dpid, OFTableStatsReply reply) { //magic number if (reply.getXid() != 1130) { return; } TableStatisticsFeature tsf = new TableStatisticsFeature(); List<OFTableStatsEntry> otse = reply.getEntries(); Date date = new java.sql.Timestamp(Calendar.getInstance().getTime().getTime()); for (OFTableStatsEntry t : otse) { if (t.getActiveCount() == 0) { break; } UnitTableStatistics uts = new UnitTableStatistics(t.getMaxEntries(), t.getActiveCount(), t.getLookupCount().getValue(), t.getMatchedCount().getValue()); uts.setDate(date); FeatureIndex fi = new FeatureIndex(); fi.setSwitchDatapathId(dpid.value()); fi.setSwitchTableId(t.getTableId().getValue()); // extract rich feature -> store to UnitTablestatistics uts = (UnitTableStatistics) extractRichFeature(fi, uts, AthenaFeatureField.TABLE_STATS); tsf.addFeatureData(fi, uts); } // printTableStatsLFT(tStatisticsLFT); providerService.tableStatsHandler(tsf); }
/*** * Serializes Table Statistics * @author Naveen * @param tableReplies * @param jGen * @throws IOException * @throws JsonProcessingException */ public static void serializeTableReply(List<OFTableStatsReply> tableReplies, JsonGenerator jGen) throws IOException, JsonProcessingException{ OFTableStatsReply tableReply = tableReplies.get(0); // we will get only one tableReply and it will contains many OFTableStatsEntry ? jGen.writeStringField("version", tableReply.getVersion().toString()); //return the enum name jGen.writeFieldName("table"); jGen.writeStartArray(); for(OFTableStatsEntry entry : tableReply.getEntries()) { jGen.writeStartObject(); //Fields common to all OF versions //For OF 1.3, only these fields are applicable jGen.writeStringField("tableId",entry.getTableId().toString()); jGen.writeNumberField("activeCount", entry.getActiveCount()); jGen.writeNumberField("lookUpCount", entry.getLookupCount().getValue()); jGen.writeNumberField("matchCount", entry.getMatchedCount().getValue()); //Fields Applicable only for specific Versions switch (entry.getVersion()) { case OF_12: //Fields applicable only to OF 1.2 jGen.writeNumberField("writeSetFields", entry.getWriteSetfields().getValue()); jGen.writeNumberField("applySetFields", entry.getApplySetfields().getValue()); jGen.writeNumberField("metaDataMatch", entry.getMetadataMatch().getValue()); jGen.writeNumberField("metaDataWrite", entry.getMetadataWrite().getValue()); case OF_11: //Fields applicable to OF 1.1 & 1.2 jGen.writeStringField("match", entry.getMatch().toString()); jGen.writeNumberField("instructions", entry.getInstructions()); jGen.writeNumberField("writeActions", entry.getWriteActions()); jGen.writeNumberField("applyActions", entry.getApplyActions()); jGen.writeNumberField("config", entry.getConfig()); case OF_10: //Fields applicable to OF 1.0, 1.1 & 1.2 jGen.writeStringField("name",entry.getName()); jGen.writeNumberField("wildcards", entry.getWildcards()); jGen.writeNumberField("maxEntries", entry.getMaxEntries()); break; default: //no extra fields for OF_13 break; }//End of switch case jGen.writeEndObject(); }//End of for loop jGen.writeEndArray(); }
@Override public void handleMessage(Dpid dpid, OFMessage msg) { if (providerService == null) { // We are shutting down, nothing to be done return; } DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid)); switch (msg.getType()) { case FLOW_REMOVED: OFFlowRemoved removed = (OFFlowRemoved) msg; FlowEntry fr = new FlowEntryBuilder(deviceId, removed, getDriver(deviceId)).build(); providerService.flowRemoved(fr); break; case STATS_REPLY: if (((OFStatsReply) msg).getStatsType() == OFStatsType.FLOW) { pushFlowMetrics(dpid, (OFFlowStatsReply) msg, getDriver(deviceId)); } else if (((OFStatsReply) msg).getStatsType() == OFStatsType.TABLE) { pushTableStatistics(dpid, (OFTableStatsReply) msg); } else if (((OFStatsReply) msg).getStatsType() == OFStatsType.FLOW_LIGHTWEIGHT) { pushFlowLightWeightMetrics(dpid, (OFFlowLightweightStatsReply) msg); } break; case BARRIER_REPLY: try { InternalCacheEntry entry = pendingBatches.getIfPresent(msg.getXid()); if (entry != null) { providerService .batchOperationCompleted(msg.getXid(), entry.completed()); } else { log.warn("Received unknown Barrier Reply: {}", msg.getXid()); } } finally { pendingBatches.invalidate(msg.getXid()); } break; case ERROR: // TODO: This needs to get suppressed in a better way. if (msg instanceof OFBadRequestErrorMsg && ((OFBadRequestErrorMsg) msg).getCode() == OFBadRequestCode.BAD_TYPE) { log.debug("Received error message {} from {}", msg, dpid); } else { log.warn("Received error message {} from {}", msg, dpid); } handleErrorMsg(deviceId, msg); break; default: log.debug("Unhandled message type: {}", msg.getType()); } }
/** * Notify that the table statistics event is arrived. * @param dpid the switch where the event occured. * @param reply the table statistics. */ void tableStatsProcess(Dpid dpid, OFTableStatsReply reply);