private OFPortStatsEntry portStatsEntry(PortStatistics portStatistic) { OFPortStatsEntry ofPortStatsEntry = FACTORY.buildPortStatsEntry() .setPortNo(OFPort.of(portStatistic.port())) .setTxBytes(U64.of(portStatistic.bytesSent())) .setTxPackets(U64.of(portStatistic.packetsSent())) .setTxDropped(U64.of(portStatistic.packetsTxDropped())) .setTxErrors(U64.of(portStatistic.packetsTxErrors())) .setRxBytes(U64.of(portStatistic.bytesReceived())) .setRxPackets(U64.of(portStatistic.packetsReceived())) .setRxDropped(U64.of(portStatistic.packetsRxDropped())) .setRxErrors(U64.of(portStatistic.packetsRxErrors())) .setDurationSec(portStatistic.durationSec()) .setDurationNsec(portStatistic.durationNano()) .build(); return ofPortStatsEntry; }
private synchronized Collection<OFPortStatsEntry> publishPortStats(Dpid dpid, OFPortStatsReply reply) { fullPortStats.putAll(dpid, reply.getEntries()); if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { return fullPortStats.removeAll(dpid); } return null; }
private Collection<PortStatistics> buildPortStatistics(DeviceId deviceId, List<OFPortStatsEntry> entries) { HashSet<PortStatistics> stats = Sets.newHashSet(); for (OFPortStatsEntry entry : entries) { try { if (entry == null || entry.getPortNo() == null || entry.getPortNo().getPortNumber() < 0) { continue; } DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder(); DefaultPortStatistics stat = builder.setDeviceId(deviceId) .setPort(entry.getPortNo().getPortNumber()) .setPacketsReceived(entry.getRxPackets().getValue()) .setPacketsSent(entry.getTxPackets().getValue()) .setBytesReceived(entry.getRxBytes().getValue()) .setBytesSent(entry.getTxBytes().getValue()) .setPacketsRxDropped(entry.getRxDropped().getValue()) .setPacketsTxDropped(entry.getTxDropped().getValue()) .setPacketsRxErrors(entry.getRxErrors().getValue()) .setPacketsTxErrors(entry.getTxErrors().getValue()) .setDurationSec(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationSec()) .setDurationNano(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationNsec()) .build(); stats.add(stat); } catch (Exception e) { LOG.warn("Unable to process port stats", e); } } return Collections.unmodifiableSet(stats); }
@Override public void handleMessage(Dpid dpid, OFMessage msg) { if (isDisabled) { return; } try { switch (msg.getType()) { case STATS_REPLY: if (((OFStatsReply) msg).getStatsType() == OFStatsType.PORT) { OFPortStatsReply portStatsReply = (OFPortStatsReply) msg; List<OFPortStatsEntry> portStatsReplyList = portStatsReplies.get(dpid); if (portStatsReplyList == null) { portStatsReplyList = Lists.newCopyOnWriteArrayList(); } portStatsReplyList.addAll(portStatsReply.getEntries()); portStatsReplies.put(dpid, portStatsReplyList); if (!portStatsReply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { List<OFPortStatsEntry> statsEntries = portStatsReplies.get(dpid); if (statsEntries != null) { pushPortMetrics(dpid, statsEntries); statsEntries.clear(); } } } break; case ERROR: if (((OFErrorMsg) msg).getErrType() == OFErrorType.PORT_MOD_FAILED) { LOG.error("port mod failed"); } default: break; } } catch (IllegalStateException e) { // system is shutting down and the providerService is no longer // valid. Messages cannot be processed. } }
@Override public void portStatsProcess(Dpid dpid, OFPortStatsReply reply) { //magic number if (reply.getXid() != 1128) { return; } PortStatisticsFeature psf = new PortStatisticsFeature(); List<OFPortStatsEntry> opse = reply.getEntries(); Date date = new java.sql.Timestamp(Calendar.getInstance().getTime().getTime()); for (OFPortStatsEntry p : opse) { UnitPortStatistics ups = new UnitPortStatistics(p.getRxPackets().getValue(), p.getTxPackets().getValue(), p.getRxBytes().getValue(), p.getTxBytes().getValue(), p.getRxDropped().getValue(), p.getTxDropped().getValue(), p.getRxErrors().getValue(), p.getTxErrors().getValue(), p.getRxFrameErr().getValue(), p.getRxOverErr().getValue(), p.getRxCrcErr().getValue(), p.getCollisions().getValue()); ups.setDate(date); FeatureIndex fi = new FeatureIndex(); fi.setSwitchDatapathId((dpid.value())); fi.setSwitchPortId(p.getPortNo().getPortNumber()); // extract rich feature -> store to UnitFlowstatistics ups = (UnitPortStatistics) extractRichFeature(fi, ups, AthenaFeatureField.PORT_STATS); psf.addFeatureData(fi, ups); } // to print LFT // printPortStatsLFT(pStatisticsLF); providerService.portStatsHandler(psf); }
public static void serializePortReply(List<OFPortStatsReply> portReplies, JsonGenerator jGen) throws IOException, JsonProcessingException{ jGen.writeFieldName("port_reply"); jGen.writeStartArray(); for (OFPortStatsReply portReply : portReplies) { jGen.writeStartObject(); jGen.writeStringField("version", portReply.getVersion().toString()); //return the enum name jGen.writeFieldName("port"); jGen.writeStartArray(); for(OFPortStatsEntry entry : portReply.getEntries()) { jGen.writeStartObject(); jGen.writeStringField("portNumber",entry.getPortNo().toString()); jGen.writeNumberField("receivePackets", entry.getRxPackets().getValue()); jGen.writeNumberField("transmitPackets", entry.getTxPackets().getValue()); jGen.writeNumberField("receiveBytes", entry.getRxBytes().getValue()); jGen.writeNumberField("transmitBytes", entry.getTxBytes().getValue()); jGen.writeNumberField("receiveDropped", entry.getRxDropped().getValue()); jGen.writeNumberField("transmitDropped", entry.getTxDropped().getValue()); jGen.writeNumberField("receiveErrors", entry.getRxErrors().getValue()); jGen.writeNumberField("transmitErrors", entry.getTxErrors().getValue()); jGen.writeNumberField("receiveFrameErrors", entry.getRxFrameErr().getValue()); jGen.writeNumberField("receiveOverrunErrors", entry.getRxOverErr().getValue()); jGen.writeNumberField("receiveCRCErrors", entry.getRxCrcErr().getValue()); jGen.writeNumberField("collisions", entry.getCollisions().getValue()); if (OFVersion.OF_13 == entry.getVersion()) { jGen.writeNumberField("durationSec", entry.getDurationSec()); jGen.writeNumberField("durationNsec", entry.getDurationNsec()); } jGen.writeEndObject(); } jGen.writeEndArray(); jGen.writeEndObject(); } jGen.writeEndArray(); }
public static void serializePortReply(List<OFPortStatsReply> portReplies, JsonGenerator jGen) throws IOException, JsonProcessingException{ OFPortStatsReply portReply = portReplies.get(0); // we will get only one PortReply and it will contains many OFPortStatsEntry ? jGen.writeStringField("version", portReply.getVersion().toString()); //return the enum name jGen.writeFieldName("port"); jGen.writeStartArray(); for(OFPortStatsEntry entry : portReply.getEntries()) { jGen.writeStartObject(); jGen.writeStringField("portNumber",entry.getPortNo().toString()); jGen.writeNumberField("receivePackets", entry.getRxPackets().getValue()); jGen.writeNumberField("transmitPackets", entry.getTxPackets().getValue()); jGen.writeNumberField("receiveBytes", entry.getRxBytes().getValue()); jGen.writeNumberField("transmitBytes", entry.getTxBytes().getValue()); jGen.writeNumberField("receiveDropped", entry.getRxDropped().getValue()); jGen.writeNumberField("transmitDropped", entry.getTxDropped().getValue()); jGen.writeNumberField("receiveErrors", entry.getRxErrors().getValue()); jGen.writeNumberField("transmitErrors", entry.getTxErrors().getValue()); jGen.writeNumberField("receiveFrameErrors", entry.getRxFrameErr().getValue()); jGen.writeNumberField("receiveOverrunErrors", entry.getRxOverErr().getValue()); jGen.writeNumberField("receiveCRCErrors", entry.getRxCrcErr().getValue()); jGen.writeNumberField("collisions", entry.getCollisions().getValue()); if (OFVersion.OF_13 == entry.getVersion()) { jGen.writeNumberField("durationSec", entry.getDurationSec()); jGen.writeNumberField("durationNsec", entry.getDurationNsec()); } jGen.writeEndObject(); } jGen.writeEndArray(); }
private Collection<PortStatistics> buildPortStatistics(DeviceId deviceId, OFPortStatsReply msg) { HashSet<PortStatistics> stats = Sets.newHashSet(); for (OFPortStatsEntry entry: msg.getEntries()) { if (entry.getPortNo().getPortNumber() < 0) { continue; } DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder(); DefaultPortStatistics stat = builder.setDeviceId(deviceId) .setPort(entry.getPortNo().getPortNumber()) .setPacketsReceived(entry.getRxPackets().getValue()) .setPacketsSent(entry.getTxPackets().getValue()) .setBytesReceived(entry.getRxBytes().getValue()) .setBytesSent(entry.getTxBytes().getValue()) .setPacketsRxDropped(entry.getRxDropped().getValue()) .setPacketsTxDropped(entry.getTxDropped().getValue()) .setPacketsRxErrors(entry.getRxErrors().getValue()) .setPacketsTxErrors(entry.getTxErrors().getValue()) .setDurationSec(entry.getDurationSec()) .setDurationNano(entry.getDurationNsec()) .build(); stats.add(stat); } return Collections.unmodifiableSet(stats); }
@Override public void serialize(OFPortStatsEntryMod portStatModEntry, JsonGenerator jGen, SerializerProvider sp) throws IOException, JsonGenerationException { IOFSwitch sw = portStatModEntry.getSwitch(); OFPortStatsEntry portStatEntry = portStatModEntry.getPortStatsEntry(); jGen.writeStartObject(); jGen.writeNumberField("portNumber", portStatEntry.getPortNo().getPortNumber()); jGen.writeStringField("portStatus", ((OFSwitchImplBase) sw).portEnabled( portStatEntry.getPortNo().getPortNumber()) ? "up" : "down"); jGen.writeNumberField("receivePackets", portStatEntry.getRxPackets().getValue()); jGen.writeNumberField("transmitPackets", portStatEntry.getTxPackets().getValue()); jGen.writeNumberField("receiveBytes", portStatEntry.getRxBytes().getValue()); jGen.writeNumberField("transmitBytes", portStatEntry.getTxBytes().getValue()); jGen.writeNumberField("receiveDropped", portStatEntry.getRxDropped().getValue()); jGen.writeNumberField("transmitDropped", portStatEntry.getTxDropped().getValue()); jGen.writeNumberField("receiveErrors", portStatEntry.getRxErrors().getValue()); jGen.writeNumberField("transmitErrors", portStatEntry.getTxErrors().getValue()); jGen.writeNumberField("receiveFrameErrors", portStatEntry.getRxFrameErr() .getValue()); jGen.writeNumberField("receiveOverrunErrors", portStatEntry.getRxOverErr() .getValue()); jGen.writeNumberField("receiveCRCErrors", portStatEntry.getRxCrcErr().getValue()); jGen.writeNumberField("collisions", portStatEntry.getCollisions().getValue()); jGen.writeEndObject(); }
private void pushPortMetrics(Dpid dpid, List<OFPortStatsEntry> portStatsEntries) { DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid)); Collection<PortStatistics> stats = buildPortStatistics(deviceId, portStatsEntries); providerService.updatePortStatistics(deviceId, stats); }
public OFPortStatsEntryMod(OFPortStatsEntry portStatsEntry, IOFSwitch switch1) { this.portStatsEntry = portStatsEntry; this.sw = switch1; }
public OFPortStatsEntry getPortStatsEntry() { return portStatsEntry; }
private void pushPortMetrics(Dpid dpid, List<OFPortStatsEntry> portStatsEntries) { DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid)); Collection<PortStatistics> stats = buildPortStatistics(deviceId, ImmutableList.copyOf(portStatsEntries)); providerService.updatePortStatistics(deviceId, stats); }
@Override public void handleMessage(Dpid dpid, OFMessage msg) { if (isDisabled) { return; } try { switch (msg.getType()) { case STATS_REPLY: if (((OFStatsReply) msg).getStatsType() == OFStatsType.PORT) { OFPortStatsReply portStatsReply = (OFPortStatsReply) msg; List<OFPortStatsEntry> portStatsReplyList = portStatsReplies.get(dpid); if (portStatsReplyList == null) { portStatsReplyList = Lists.newCopyOnWriteArrayList(); } portStatsReplyList.addAll(portStatsReply.getEntries()); portStatsReplies.put(dpid, portStatsReplyList); if (!portStatsReply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { List<OFPortStatsEntry> statsEntries = portStatsReplies.get(dpid); if (statsEntries != null) { pushPortMetrics(dpid, statsEntries); statsEntries.clear(); } } } else if (((OFStatsReply) msg).getStatsType() == OFStatsType.EXPERIMENTER) { OpenFlowSwitch sw = controller.getSwitch(dpid); if (sw == null) { LOG.error("Switch {} is not found", dpid); break; } if (sw instanceof OpenFlowOpticalSwitch) { // Optical switch uses experimenter stats message to update power List<PortDescription> portDescs = ((OpenFlowOpticalSwitch) sw).processExpPortStats(msg); if (!portDescs.isEmpty()) { providerService.updatePorts(DeviceId.deviceId(Dpid.uri(dpid)), portDescs); } } } break; case ERROR: if (((OFErrorMsg) msg).getErrType() == OFErrorType.PORT_MOD_FAILED) { LOG.error("port mod failed"); } break; default: break; } } catch (IllegalStateException e) { // system is shutting down and the providerService is no longer // valid. Messages cannot be processed. } }