still making both branches closer
[nepi.git] / examples / ccn_emu_live / dce.py
index 3386e79..ef56243 100644 (file)
@@ -1,13 +1,11 @@
 #!/usr/bin/env python
-
-###############################################################################
 #
 #    NEPI, a framework to manage network experiments
+#    Copyright (C) 2013 INRIA
 #
 #    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation, either version 3 of the License, or
-#    (at your option) any later version.
+#    it under the terms of the GNU General Public License version 2 as
+#    published by the Free Software Foundation;
 #
 #    This program is distributed in the hope that it will be useful,
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,8 +16,8 @@
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
-#
-###############################################################################
+
+from __future__ import print_function
 
 from nepi.execution.ec import ExperimentController 
 from nepi.execution.runner import ExperimentRunner
@@ -38,13 +36,15 @@ repofile = os.path.join(
         os.path.dirname(os.path.realpath(__file__)), "repoFile1.0.8.2")
 
 def get_simulator(ec):
-    simulator = ec.filter_resources("LinuxNS3Simulation")
+    simulator = ec.filter_resources("linux::ns3::Simulation")
 
     if not simulator:
-        node = ec.register_resource("LinuxNode")
+        node = ec.register_resource("linux::Node")
         ec.set(node, "hostname", "localhost")
 
-        simu = ec.register_resource("LinuxNS3Simulation")
+        simu = ec.register_resource("linux::ns3::Simulation")
+        ec.set(simu, "enableDump", True)
+        ec.set(simu, "StopTime", STOP_TIME)
         ec.register_connection(simu, node)
         return simu
 
@@ -74,12 +74,11 @@ def add_dce_ccnd(ec, nid):
     host = ec.netgraph.node_annotation(nid, "host")
     
     # Add dce ccnd to the dce node
-    ccnd = ec.register_resource("ns3::LinuxDceCCND")
+    ccnd = ec.register_resource("linux::ns3::dce::CCND")
     ec.set (ccnd, "stackSize", 1<<20)
     ec.set (ccnd, "debug", 7)
     ec.set (ccnd, "capacity", 50000)
     ec.set (ccnd, "StartTime", "1s")
-    ec.set (ccnd, "StopTime", STOP_TIME)
     ec.register_connection(ccnd, host)
 
     # Collector to retrieve ccnd log
@@ -94,34 +93,21 @@ def add_dce_ccnr(ec, nid):
     host = ec.netgraph.node_annotation(nid, "host")
     
     # Add a CCN content repository to the dce node
-    ccnr = ec.register_resource("ns3::LinuxDceCCNR")
+    ccnr = ec.register_resource("linux::ns3::dce::CCNR")
     ec.set (ccnr, "repoFile1", repofile) 
     ec.set (ccnr, "stackSize", 1<<20)
     ec.set (ccnr, "StartTime", "2s")
-    ec.set (ccnr, "StopTime", STOP_TIME)
     ec.register_connection(ccnr, host)
 
 def add_dce_ccncat(ec, nid):
     # Retrieve annotation from netgraph
     host = ec.netgraph.node_annotation(nid, "host")
    
-    ccnpeek = ec.register_resource("ns3::LinuxDceCCNPeek")
-    #ec.set (ccnpeek, "contentName", "ccnx:/chunk0")
-    ec.set (ccnpeek, "contentName", content_name)
-    ec.set (ccnpeek, "stackSize", 1<<20)
-    ec.set (ccnpeek, "StartTime", "5s")
-    ec.set (ccnpeek, "StopTime", STOP_TIME)
-    ec.register_connection(ccnpeek, host)
-
-    collector = add_collector(ec, "stdout", nid, "peek")
-    ec.register_connection(collector, ccnpeek)
-
     # Add a ccncat application to the dce host
-    ccncat = ec.register_resource("ns3::LinuxDceCCNCat")
+    ccncat = ec.register_resource("linux::ns3::dce::CCNCat")
     ec.set (ccncat, "contentName", content_name)
     ec.set (ccncat, "stackSize", 1<<20)
     ec.set (ccncat, "StartTime", "8s")
-    ec.set (ccncat, "StopTime", STOP_TIME)
     ec.register_connection(ccncat, host)
 
 def add_dce_fib_entry(ec, nid1, nid2):
@@ -131,13 +117,12 @@ def add_dce_fib_entry(ec, nid1, nid2):
     ip2 = net[nid2]
 
     # Add FIB entry between peer hosts
-    ccndc = ec.register_resource("ns3::LinuxDceFIBEntry")
+    ccndc = ec.register_resource("linux::ns3::dce::FIBEntry")
     ec.set (ccndc, "protocol", "udp") 
     ec.set (ccndc, "uri", "ccnx:/") 
     ec.set (ccndc, "host", ip2)
     ec.set (ccndc, "stackSize", 1<<20)
-    ec.set (ccndc, "StartTime", "2s")
-    ec.set (ccndc, "StopTime", STOP_TIME)
+    ec.set (ccndc, "StartTime", "4s")
     ec.register_connection(ccndc, host1)
 
 def add_dce_net_iface(ec, nid1, nid2):
@@ -177,16 +162,15 @@ def avg_interests(ec, run):
 
     ### Compute metric: Avg number of Interests seen per content name
     ###                 normalized by the number of nodes in the shortest path
-    content_name_count = len(content_names.values())
+    content_name_count = len(content_names)
     nodes_in_shortest_path = len(shortest_path) - 1
     metric = interest_count / (float(content_name_count) * float(nodes_in_shortest_path))
 
     # TODO: DUMP RESULTS TO FILE
     # TODO: DUMP GRAPH DELAYS!
-    f = open("/tmp/metric", "w+")
-    f.write("%.2f\n" % metric)
-    f.close()
-    print " METRIC", metric
+    with open("/tmp/metric", "a+") as f: 
+        f.write("%.2f\n" % metric)
+    print(" METRIC", metric)
 
     return metric
 
@@ -222,16 +206,16 @@ if __name__ == '__main__':
     #### Create NEPI Experiment Description with LINEAR topology 
     ec = ExperimentController("dce_ccn", 
             topo_type = TopologyType.LINEAR, 
-            node_count = 4,
+            node_count = 2,
             assign_st = True,
             assign_ips = True,
             add_node_callback = add_dce_node, 
             add_edge_callback = add_dce_edge)
     
-    print "Results stored at", ec.exp_dir
+    print("Results stored at", ec.exp_dir)
 
     #### Retrieve the consumer to wait for ot to finish
-    ccncat = ec.filter_resources("ns3::LinuxDceCCNCat")
+    ccncat = ec.filter_resources("linux::ns3::dce::CCNCat")
    
     #### Run experiment until metric convergences
     rnr = ExperimentRunner()