Пример #1
0
    def test_simulation(self):    
        def simulation(network):
            ns3_lib.udp_echo_app(network, client_node="Urcos", server_node="Ccatcca", 
                server_device="Josjo2-wimax2", start=1.0, stop=9.0, packets=2, interval=1.0)
            ns3_lib.add_wimax_service_flow(network, install=("Ccatcca", "Josjo2-wimax2"), 
                source=("Urcos", "Huiracochan-wifi1", None), dest=("Ccatcca", "Josjo2-wimax2", 9), 
                protocol="udp", direction="down", scheduling="rtps", priority=0)
                
            monitor_info = ns3_lib.enable_monitor(network, interval=0.1)
            
            ns3.LogComponentEnable("UdpEchoClientApplication", ns3.LOG_LEVEL_INFO)
            ns3.LogComponentEnable("UdpEchoServerApplication", ns3.LOG_LEVEL_INFO)
            ns3_lib.run_simulation(network, 5.0)
            
            return monitor_info
            
        expected_debug = """
Sent 1024 bytes to 10.1.3.1
Received 1024 bytes from 10.1.0.1
Received 1024 bytes from 10.1.3.1
Sent 1024 bytes to 10.1.3.1
Received 1024 bytes from 10.1.0.1
Received 1024 bytes from 10.1.3.1""".strip()
        path = self._get_report_file()
        debug_data, monitor_info = capture_stderr(ns3_lib.simulation_main, 
            [path], simulation, "UDP server/client")
        self.assertEqual(debug_data.strip(), expected_debug)
        
        # Check monitor_info
        self.assertEqual(monitor_info["flow_stats_steps"].keys(), [1, 2])
        steps = monitor_info["flow_stats_steps"][1]
        time1, flow_stats1 = steps[0]
        time2, flow_stats2 = steps[1]
        self.assert_((time2-time1) - 0.1 < 0.01)
        self.assertEqual(len(steps), int((5.0 - 1.0) / 0.1) - 1)
        
        # Check print_monitor
        
        stream = StringIO()
        ns3_lib.print_monitor_results(monitor_info, show_histograms=True, stream=stream)
        results = stream.getvalue()        
         
        re_flow1 = r"^Flow 1 \(UDP\) - 10.1.0.1/\d+ \(Urcos:Huiracochan-wifi1\) --> 10.1.3.1/9 \(Ccatcca:Josjo2-wimax2\)"
        re_flow2 = r"^Flow 2 \(UDP\) - 10.1.3.1/9 \(Ccatcca:Josjo2-wimax2\) --> 10.1.0.1/\d+ \(Urcos:Huiracochan-wifi1\)"
        self.assert_(re.search(re_flow1, results, re.M))
        self.assert_(re.search(re_flow2, results, re.M))       
Пример #2
0
def simulation(network):
    ns3.LogComponentEnable("PacketSink",
                           ns3.LOG_LEVEL_ALL | ns3.LOG_PREFIX_TIME)

    # Applications
    ns3_lib.onoff_app(network,
                      client_node="Urcos",
                      server_node="Huiracochan",
                      server_device="Josjo1-wifi1",
                      start=1.0,
                      stop=9.0,
                      rate="1Mbps",
                      access_class="ac_vo")
    ns3_lib.onoff_app(network,
                      client_node="Urpay",
                      server_node="Ccatcca",
                      server_device="Josjo2-wimax2",
                      start=1.0,
                      stop=9.0,
                      rate="0.5Mbps")
    ns3_lib.add_wimax_service_flow(network,
                                   install=("Ccatcca", "Josjo2-wimax2"),
                                   source=("Urpay", "Josjo1-wifi1", None),
                                   dest=("Ccatcca", "Josjo2-wimax2", 9),
                                   protocol="udp",
                                   direction="down",
                                   scheduling="rtps",
                                   priority=0)

    # Tracing
    #device = network.nodes["Josjojauarina 1"].devices["Josjo1-wifi1"]
    #device.phy_helper.EnablePcap("onoff", device.ns3_device)

    monitor_info = ns3_lib.enable_monitor(network, interval=0.1)

    # Run simulation
    ns3_lib.run_simulation(network, 3.0)
    ns3_lib.print_monitor_results(monitor_info)
    ns3_lib.save_monitor_xmldata(monitor_info, "onoff.flowmon.xml")
    ns3_lib.create_througput_gnuplot(monitor_info, "Urcos-Huiracochan 1Mbps",
                                     "onoff")
Пример #3
0
def simulation(network):
    ns3.LogComponentEnable("PacketSink", ns3.LOG_LEVEL_ALL | ns3.LOG_PREFIX_TIME)
    
    # Applications    
    ns3_lib.onoff_app(network, client_node="Urcos", 
        server_node="Huiracochan", server_device="Josjo1-wifi1", 
        start=1.0, stop=9.0, rate="1Mbps", access_class="ac_vo")
    ns3_lib.onoff_app(network, client_node="Urpay", 
        server_node="Ccatcca", server_device="Josjo2-wimax2", start=1.0, stop=9.0, rate="0.5Mbps")
    ns3_lib.add_wimax_service_flow(network, install=("Ccatcca", "Josjo2-wimax2"), 
        source=("Urpay", "Josjo1-wifi1", None), dest=("Ccatcca", "Josjo2-wimax2", 9), 
        protocol="udp", direction="down", scheduling="rtps", priority=0)

    # Tracing    
    #device = network.nodes["Josjojauarina 1"].devices["Josjo1-wifi1"]
    #device.phy_helper.EnablePcap("onoff", device.ns3_device)

    monitor_info = ns3_lib.enable_monitor(network, interval=0.1)
    
    # Run simulation
    ns3_lib.run_simulation(network, 3.0)
    ns3_lib.print_monitor_results(monitor_info)
    ns3_lib.save_monitor_xmldata(monitor_info, "onoff.flowmon.xml")
    ns3_lib.create_througput_gnuplot(monitor_info, "Urcos-Huiracochan 1Mbps", "onoff")
Пример #4
0
def siminfo(filename, stream=sys.stdout):
    """Run a simulation YML file."""
    logging.debug("Open simulation file: %s" % filename)
    config = yaml.load(open(filename).read())
    logging.info("Simulation: %s (%s)" % (config["description"], config["version"]))
    logging.debug("Simulation YAML:")
    for line in pprint.pformat(config).splitlines(): 
        logging.debug(line)
        
    assert "netinfo" in config, "missing compulsory variable: netinfo"
    siminfo_dir = os.path.dirname(os.path.abspath(filename))
    netinfo_path = os.path.join(siminfo_dir, config["netinfo"])
    network = wwnetwork.create_network_from_yaml_file(netinfo_path)
    
    # Enable Logs    
    for name, string_flags in (config["logs"] or {}).iteritems():
        attrs = ["LOG_" + s.upper() for s in string_flags.split("|")]
        flags = reduce(operator.or_, [getattr(ns3, attr) for attr in attrs])
        logging.debug("Log enabled: %s=%s" % (name, flags))
        ns3.LogComponentEnable(name, flags)
        
    # Add applications
    assert "apps" in config
    for app in config["apps"]:
        available_applications = ns3_lib.get_available_applications()
        assert (app["type"] in available_applications), \
            "Application type '%s' not found, available: %s" % \
            (app["type"], ", ".join(available_applications.keys()))
        app_kwargs = filter_dict_by_keys(app, ["type"])
        app_func = available_applications[app["type"]]
        logging.debug("Add application: %s (%s)" % (app["type"], app_kwargs))
        app_func(network, **app_kwargs)

    for flow in config.get("wimax_service_flows", []):
        logging.debug("Add service flow: %s" % flow)
        ns3_lib.add_wimax_service_flow(network, **flow)
    
    # Enable flow-monitor & tracking    
    interval = config["simulation"].get("interval", 0.1)
    logging.debug("Flow monitor interval: %s seconds" % interval)
    monitor_info = ns3_lib.enable_monitor(network, interval)

    for options in config["results"].get("save_pcap", []):
        device = network.nodes[options["node"]].devices[options["device"]]
        device.phy_helper.EnablePcap(options["filename"], device.ns3_device)
        logging.debug("Enable pcap for %s:%s" % (options["node"], options["device"]))

    # Start simulation        
    duration = config["simulation"].get("duration")
    ns3_lib.run_simulation(network, duration)
            
    # Results
    ns3_lib.print_monitor_results(monitor_info, stream=stream)    
    if "monitor" in config["results"]:
        xmlfile = results["monitor"].get("save_xml")
        if xmlfile:
            ns3_lib.save_monitor_xmldata(monitor_info, xmlfile)

    for plot in config["results"].get("plots", []):
        available_plots = ns3_lib.get_available_plots()
        assert (plot["type"] in available_plots), \
            "Plot type '%s' not found, available: %s" % \
            (plot["type"], ", ".join(available_plots.keys()))
        plot_func = available_plots[plot["type"]]
        plot_kwargs = filter_dict_by_keys(plot, ["type"])
        plot_func(monitor_info, **plot_kwargs)
Пример #5
0
def siminfo(filename, stream=sys.stdout):
    """Run a simulation YML file."""
    logging.debug("Open simulation file: %s" % filename)
    config = yaml.load(open(filename).read())
    logging.info("Simulation: %s (%s)" %
                 (config["description"], config["version"]))
    logging.debug("Simulation YAML:")
    for line in pprint.pformat(config).splitlines():
        logging.debug(line)

    assert "netinfo" in config, "missing compulsory variable: netinfo"
    siminfo_dir = os.path.dirname(os.path.abspath(filename))
    netinfo_path = os.path.join(siminfo_dir, config["netinfo"])
    network = wwnetwork.create_network_from_yaml_file(netinfo_path)

    # Enable Logs
    for name, string_flags in (config["logs"] or {}).iteritems():
        attrs = ["LOG_" + s.upper() for s in string_flags.split("|")]
        flags = reduce(operator.or_, [getattr(ns3, attr) for attr in attrs])
        logging.debug("Log enabled: %s=%s" % (name, flags))
        ns3.LogComponentEnable(name, flags)

    # Add applications
    assert "apps" in config
    for app in config["apps"]:
        available_applications = ns3_lib.get_available_applications()
        assert (app["type"] in available_applications), \
            "Application type '%s' not found, available: %s" % \
            (app["type"], ", ".join(available_applications.keys()))
        app_kwargs = filter_dict_by_keys(app, ["type"])
        app_func = available_applications[app["type"]]
        logging.debug("Add application: %s (%s)" % (app["type"], app_kwargs))
        app_func(network, **app_kwargs)

    for flow in config.get("wimax_service_flows", []):
        logging.debug("Add service flow: %s" % flow)
        ns3_lib.add_wimax_service_flow(network, **flow)

    # Enable flow-monitor & tracking
    interval = config["simulation"].get("interval", 0.1)
    logging.debug("Flow monitor interval: %s seconds" % interval)
    monitor_info = ns3_lib.enable_monitor(network, interval)

    for options in config["results"].get("save_pcap", []):
        device = network.nodes[options["node"]].devices[options["device"]]
        device.phy_helper.EnablePcap(options["filename"], device.ns3_device)
        logging.debug("Enable pcap for %s:%s" %
                      (options["node"], options["device"]))

    # Start simulation
    duration = config["simulation"].get("duration")
    ns3_lib.run_simulation(network, duration)

    # Results
    ns3_lib.print_monitor_results(monitor_info, stream=stream)
    if "monitor" in config["results"]:
        xmlfile = results["monitor"].get("save_xml")
        if xmlfile:
            ns3_lib.save_monitor_xmldata(monitor_info, xmlfile)

    for plot in config["results"].get("plots", []):
        available_plots = ns3_lib.get_available_plots()
        assert (plot["type"] in available_plots), \
            "Plot type '%s' not found, available: %s" % \
            (plot["type"], ", ".join(available_plots.keys()))
        plot_func = available_plots[plot["type"]]
        plot_kwargs = filter_dict_by_keys(plot, ["type"])
        plot_func(monitor_info, **plot_kwargs)