utils/flowmon/flowmon-bench.py
changeset 3976 d875e681c296
parent 3974 e07e80606b90
child 3980 6d5f4185ecfb
--- a/utils/flowmon/flowmon-bench.py	Mon May 11 17:43:35 2009 +0100
+++ b/utils/flowmon/flowmon-bench.py	Mon May 11 17:59:53 2009 +0100
@@ -18,70 +18,11 @@
 
 import sys
 import ns3
-from xml.dom import minidom
 
 DISTANCE = 150 # (m)
 NUM_NODES_SIDE = 3
 
 
-def write_flowmon_results_to_file(file_name, flow_monitor, flow_classifier):
-    results_file = open(file_name, "wb")
-    domimpl = minidom.getDOMImplementation()
-    doc = domimpl.createDocument(None, "flow-monitor", None)
-    results = doc.documentElement
-
-    flows_el = results.appendChild(doc.createElement('flows'))
-
-    for flow_id, stats in flow_monitor.GetFlowStats():
-        flow_el = flows_el.appendChild(doc.createElement('flow'))
-        flow_el.setAttribute('flow-id', str(flow_id))
-        
-        #Time     timeFirstTxPacket;
-        flow_el.setAttribute("time-first-tx-packet", str(stats.timeFirstTxPacket))
-        
-        #Time     timeFirstRxPacket;
-        flow_el.setAttribute("time-first-rx-packet", str(stats.timeFirstRxPacket))
-
-        #Time     timeLastTxPacket;
-        flow_el.setAttribute("time-last-tx-packet", str(stats.timeLastTxPacket))
-
-        #Time     timeLastRxPacket;
-        flow_el.setAttribute("time-last-rx-packet", str(stats.timeLastRxPacket))
-
-        #Time     delaySum;
-        flow_el.setAttribute("delay-sum", str(stats.delaySum))
-
-        #uint64_t txBytes;
-        flow_el.setAttribute("tx-bytes", str(stats.txBytes))
-
-        #uint64_t rxBytes;
-        flow_el.setAttribute("rx-bytes", str(stats.rxBytes))
-
-        #uint32_t txPackets;
-        flow_el.setAttribute("tx-packets", str(stats.txPackets))
-
-        #uint32_t rxPackets;
-        flow_el.setAttribute("rx-packets", str(stats.rxPackets))
-
-        #uint32_t lostPackets;
-        flow_el.setAttribute("lost-packets", str(stats.lostPackets))
-
-        #uint32_t timesForwarded;
-        flow_el.setAttribute("times-forwarded", str(stats.timesForwarded))
-
-        # -- add ipv4 flow filtering information
-        five_tuple = flow_classifier.FindFlow(flow_id)
-        five_tuple_el = flow_el.appendChild(doc.createElement('five-tuple'))
-        five_tuple_el.setAttribute("protocol", str(five_tuple.protocol))
-        five_tuple_el.setAttribute("source-address", str(five_tuple.sourceAddress))
-        five_tuple_el.setAttribute("destination-address", str(five_tuple.destinationAddress))
-        five_tuple_el.setAttribute("source-port", str(five_tuple.sourcePort))
-        five_tuple_el.setAttribute("destination-port", str(five_tuple.destinationPort))
-        
-    doc.writexml(results_file, addindent='  ', newl='\n', encoding='utf-8')
-    results_file.close()
-
-
 def main(argv):
 
     cmd = ns3.CommandLine()
@@ -221,7 +162,7 @@
 
     if enable_monitor:
         if hasattr(cmd, "Results"):
-            write_flowmon_results_to_file(cmd.Results, monitor, classifier)
+            monitor.SerializeToXmlFile(cmd.Results, True, True)
         else:
             print_stats(sys.stdout, monitor, classifier)