当前位置: 首页>>代码示例>>Python>>正文


Python ExperimentController.save方法代码示例

本文整理汇总了Python中nepi.execution.ec.ExperimentController.save方法的典型用法代码示例。如果您正苦于以下问题:Python ExperimentController.save方法的具体用法?Python ExperimentController.save怎么用?Python ExperimentController.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nepi.execution.ec.ExperimentController的用法示例。


在下文中一共展示了ExperimentController.save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_serialize

# 需要导入模块: from nepi.execution.ec import ExperimentController [as 别名]
# 或者: from nepi.execution.ec.ExperimentController import save [as 别名]
    def test_serialize(self):
        node_count = 4
        app_count = 2

        dirpath = tempfile.mkdtemp()

        ec = ExperimentController(exp_id = "serialize-test")
       
        # Add simulated nodes and applications
        nodes = list()
        apps = list()
        ifaces = list()

        for i in xrange(node_count):
            node = ec.register_resource("dummy::Node")
            nodes.append(node)
            
            iface = ec.register_resource("dummy::Interface")
            ec.register_connection(node, iface)
            ifaces.append(iface)

            for i in xrange(app_count):
                app = ec.register_resource("dummy::Application")
                ec.register_connection(node, app)
                apps.append(app)

        link = ec.register_resource("dummy::Link")

        for iface in ifaces:
            ec.register_connection(link, iface)

        filepath = ec.save(dirpath)

        ec.deploy()

        # Wait until nodes and apps are deployed
        ec.wait_finished(apps)

        # Do the experiment controller shutdown
        ec.shutdown()

        # Load serialized experiment
        ec2 = ExperimentController.load(filepath)
        apps = ec2.filter_resources("dummy::Application")
        ec2.deploy()
        ec2.wait_finished(apps)
        ec2.shutdown()
        
        self.assertEquals(len(ec.resources), len(ec2.resources))

        shutil.rmtree(dirpath)
开发者ID:phiros,项目名称:nepi,代码行数:53,代码来源:serializer.py

示例2: t_dce_serialize

# 需要导入模块: from nepi.execution.ec import ExperimentController [as 别名]
# 或者: from nepi.execution.ec.ExperimentController import save [as 别名]
    def t_dce_serialize(self, host, user = None, identity = None):
        dirpath = tempfile.mkdtemp()
        
        ec = ExperimentController(exp_id = "test-ns3-dce")
        
        node = ec.register_resource("linux::Node")
        if host == "localhost":
            ec.set(node, "hostname", host)
        else:
            ec.set(node, "hostname", host)
            ec.set(node, "username", user)
            ec.set(node, "identity", identity)

        ec.set(node, "cleanProcesses", True)
        #ec.set(node, "cleanHome", True)

        simu = ec.register_resource("linux::ns3::Simulation")
        ec.set(simu, "verbose", True)
        ec.register_connection(simu, node)

        nsnode1 = add_ns3_node(ec, simu)
        p2p1 = add_point2point_device(ec, nsnode1, "10.0.0.1", "30")
        ec.set(p2p1, "DataRate", "5Mbps")

        nsnode2 = add_ns3_node(ec, simu)
        p2p2 = add_point2point_device(ec, nsnode2, "10.0.0.2", "30")
        ec.set(p2p2, "DataRate", "5Mbps")

        # Create channel
        chan = ec.register_resource("ns3::PointToPointChannel")
        ec.set(chan, "Delay", "2ms")

        ec.register_connection(chan, p2p1)
        ec.register_connection(chan, p2p2)

        ### create applications
        udp_perf = ec.register_resource("linux::ns3::dce::Application")
        ec.set (udp_perf, "binary", "udp-perf")
        ec.set (udp_perf, "stackSize", 1<<20)
        ec.set (udp_perf, "arguments", "--duration=10;--nodes=2")
        ec.set (udp_perf, "StartTime", "1s")
        ec.set (udp_perf, "StopTime", "20s")
        ec.register_connection(udp_perf, nsnode1)

        udp_perf_client = ec.register_resource("linux::ns3::dce::Application")
        ec.set (udp_perf_client, "binary", "udp-perf")
        ec.set (udp_perf_client, "stackSize", 1<<20)
        ec.set (udp_perf_client, "arguments", "--client;--nodes=2;--host=10.0.0.1;--duration=10")
        ec.set (udp_perf_client, "StartTime", "2s")
        ec.set (udp_perf_client, "StopTime", "20s")
        ec.register_connection(udp_perf_client, nsnode2)

        filepath = ec.save(dirpath)
        
        ec.deploy()

        ec.wait_finished([udp_perf_client])

        # Give time to flush the streams
        import time
        time.sleep(5) 

        expected = "udp-perf --duration=10 --nodes=2"
        cmdline = ec.trace(udp_perf, "cmdline")
        self.assertTrue(cmdline.find(expected) > -1, cmdline)

        expected = "Start Time: NS3 Time:          1s ("
        status = ec.trace(udp_perf, "status")
        self.assertTrue(status.find(expected) > -1, status)

        expected = "received=1500 bytes, 1 reads (@1500 bytes) 1500"
        stdout = ec.trace(udp_perf, "stdout")
        self.assertTrue(stdout.find(expected) > -1, stdout)

        ec.shutdown()

        # Load serialized experiment
        ec2 = ExperimentController.load(filepath)
        
        ec2.deploy()
        ec2.wait_finished([udp_perf_client])

        # Give time to flush the streams
        time.sleep(5) 
       
        self.assertEquals(len(ec.resources), len(ec2.resources))
 
        expected = "udp-perf --duration=10 --nodes=2"
        cmdline = ec2.trace(udp_perf, "cmdline")
        self.assertTrue(cmdline.find(expected) > -1, cmdline)

        expected = "Start Time: NS3 Time:          1s ("
        status = ec2.trace(udp_perf, "status")
        self.assertTrue(status.find(expected) > -1, status)

        expected = "received=1500 bytes, 1 reads (@1500 bytes) 1500"
        stdout = ec2.trace(udp_perf, "stdout")
        self.assertTrue(stdout.find(expected) > -1, stdout)

        ec2.shutdown()
#.........这里部分代码省略.........
开发者ID:phiros,项目名称:nepi,代码行数:103,代码来源:serialization.py

示例3: t_routing_serialize

# 需要导入模块: from nepi.execution.ec import ExperimentController [as 别名]
# 或者: from nepi.execution.ec.ExperimentController import save [as 别名]

#.........这里部分代码省略.........
        csma3 = add_csma_device(ec, nsnode3, "10.0.1.2", "24")

        nsnode4 = add_ns3_node(ec, simu)
        csma4 = add_csma_device(ec, nsnode4, "10.0.1.3", "24")

        nsnode5 = add_ns3_node(ec, simu)
        p2p56 = add_point2point_device(ec, nsnode5, "10.0.2.1", "30")
        csma5 = add_csma_device(ec, nsnode5, "10.0.1.4", "24")

        nsnode6 = add_ns3_node(ec, simu)
        p2p65 = add_point2point_device(ec, nsnode6, "10.0.2.2", "30")

        # P2P chan1
        p2p_chan1 = ec.register_resource("ns3::PointToPointChannel")
        ec.set(p2p_chan1, "Delay", "0s")
        ec.register_connection(p2p_chan1, p2p12)
        ec.register_connection(p2p_chan1, p2p21)

        # CSMA chan
        csma_chan = ec.register_resource("ns3::CsmaChannel")
        ec.set(csma_chan, "Delay", "0s")
        ec.register_connection(csma_chan, csma2)
        ec.register_connection(csma_chan, csma3)
        ec.register_connection(csma_chan, csma4)
        ec.register_connection(csma_chan, csma5)

        # P2P chan2
        p2p_chan2 = ec.register_resource("ns3::PointToPointChannel")
        ec.set(p2p_chan2, "Delay", "0s")
        ec.register_connection(p2p_chan2, p2p56)
        ec.register_connection(p2p_chan2, p2p65)

        # Add routes - n1 - n6
        r1 = ec.register_resource("ns3::Route")
        ec.set(r1, "network", "10.0.2.0")
        ec.set(r1, "prefix", "30")
        ec.set(r1, "nexthop", "10.0.0.2")
        ec.register_connection(r1, nsnode1)

        # Add routes - n2 - n6
        r2 = ec.register_resource("ns3::Route")
        ec.set(r2, "network", "10.0.2.0")
        ec.set(r2, "prefix", "30")
        ec.set(r2, "nexthop", "10.0.1.4")
        ec.register_connection(r2, nsnode2)

        # Add routes - n5 - n1
        r5 = ec.register_resource("ns3::Route")
        ec.set(r5, "network", "10.0.0.0")
        ec.set(r5, "prefix", "30")
        ec.set(r5, "nexthop", "10.0.1.1")
        ec.register_connection(r5, nsnode5)

        # Add routes - n6 - n1
        r6 = ec.register_resource("ns3::Route")
        ec.set(r6, "network", "10.0.0.0")
        ec.set(r6, "prefix", "30")
        ec.set(r6, "nexthop", "10.0.2.1")
        ec.register_connection(r6, nsnode6)

        ### create pinger
        ping = ec.register_resource("ns3::V4Ping")
        ec.set (ping, "Remote", "10.0.2.2")
        ec.set (ping, "Interval", "1s")
        ec.set (ping, "Verbose", True)
        ec.set (ping, "StartTime", "1s")
        ec.set (ping, "StopTime", "21s")
        ec.register_connection(ping, nsnode1)

        filepath = ec.save(dirpath)
        print filepath
        
        ec.deploy()

        ec.wait_finished([ping])
        
        stdout = ec.trace(simu, "stdout")

        expected = "20 packets transmitted, 20 received, 0% packet loss"
        self.assertTrue(stdout.find(expected) > -1)

        ec.shutdown()

        # Load serialized experiment
        ec2 = ExperimentController.load(filepath)
        
        ec2.deploy()

        ec2.wait_finished([ping])
        
        self.assertEquals(len(ec.resources), len(ec2.resources))
        
        stdout = ec2.trace(simu, "stdout")
 
        expected = "20 packets transmitted, 20 received, 0% packet loss"
        self.assertTrue(stdout.find(expected) > -1)
        
        ec2.shutdown()

        shutil.rmtree(dirpath)
开发者ID:phiros,项目名称:nepi,代码行数:104,代码来源:serialization.py

示例4: t_wifi_serialize

# 需要导入模块: from nepi.execution.ec import ExperimentController [as 别名]
# 或者: from nepi.execution.ec.ExperimentController import save [as 别名]
    def t_wifi_serialize(self, host, user = None, identity = None):
        bounds_width = bounds_height = 200
        x = y = 100
        speed = 1

        dirpath = tempfile.mkdtemp()
        
        ec = ExperimentController(exp_id = "test-ns3-wifi-ping")
        
        node = ec.register_resource("linux::Node")
        if host == "localhost":
            ec.set(node, "hostname", "localhost")
        else:
            ec.set(node, "hostname", host)
            ec.set(node, "username", user)
            ec.set(node, "identity", identity)

        ec.set(node, "cleanProcesses", True)
        #ec.set(node, "cleanHome", True)

        simu = ec.register_resource("linux::ns3::Simulation")
        ec.set(simu, "verbose", True)
        ec.register_connection(simu, node)

        nsnode1 = add_ns3_node(ec, simu)
        dev1, phy1 = add_wifi_device(ec, nsnode1, "10.0.0.1", "24", access_point = True)
        mobility1 = add_constant_mobility(ec, nsnode1, x, y, 0)

        nsnode2 = add_ns3_node(ec, simu)
        dev2, phy2 = add_wifi_device(ec, nsnode2, "10.0.0.2", "24", access_point = False)
        mobility1 = add_constant_mobility(ec, nsnode2, x, y, 0)
        #mobility2 = add_random_mobility(ec, nsnode2, x, y, 0, speed, bounds_width, bounds_height)

        # Create channel
        chan = add_wifi_channel(ec)
        ec.register_connection(chan, phy1)
        ec.register_connection(chan, phy2)

        ### create pinger
        ping = ec.register_resource("ns3::V4Ping")
        ec.set (ping, "Remote", "10.0.0.1")
        ec.set (ping, "Interval", "1s")
        ec.set (ping, "Verbose", True)
        ec.set (ping, "StartTime", "1s")
        ec.set (ping, "StopTime", "21s")
        ec.register_connection(ping, nsnode2)

        filepath = ec.save(dirpath)
        print filepath
        
        ec.deploy()

        ec.wait_finished([ping])
        
        stdout = ec.trace(simu, "stdout")

        expected = "20 packets transmitted, 20 received, 0% packet loss"
        self.assertTrue(stdout.find(expected) > -1)

        ec.shutdown()

        # Load serialized experiment
        ec2 = ExperimentController.load(filepath)
        
        ec2.deploy()

        ec2.wait_finished([ping])
        
        self.assertEquals(len(ec.resources), len(ec2.resources))
        
        stdout = ec2.trace(simu, "stdout")
 
        expected = "20 packets transmitted, 20 received, 0% packet loss"
        self.assertTrue(stdout.find(expected) > -1)
        
        ec2.shutdown()

        shutil.rmtree(dirpath)
开发者ID:phiros,项目名称:nepi,代码行数:80,代码来源:serialization.py


注:本文中的nepi.execution.ec.ExperimentController.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。