def setup(self):
        BaseClass.setup(self)
        # net_settings = self.load_net_settings()
        net_settings = self.load_para(f_name=settings.ROOT + '/' +
                                      self.options.net_settings, )
        self.load_exper_settings(net_settings)

        # Generate dot file that describe the background traffic.
        dot_file = self.gen_back_traf_dot(net_settings)

        ns3.LogComponentEnable("OnOffApplication", ns3.LOG_LEVEL_INFO)
        ns3.LogComponentEnable("V4PingApplication", ns3.LOG_LEVEL_INFO)
        self.load_exper_settings(net_settings)

        self.net = ManualTopologyNet(
            # os.path.abspath(self.options.topology_file),
            settings.ROOT + '/' + self.options.topology_file,
            self.options.topology_type,
            self.NodeCreator,
            net_settings,
        )
        bg_cofig = BackgroundTrafficConfig(dot_file, self.net)
        bg_cofig.config_onoff_app()

        self.net.set_trace()
        self._install_cmds(srv_addr=self.SERVER_ADDR)
        self.print_srv_addr()
        self._set_server_info()
        self.start_nodes()
Beispiel #2
0
 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
Beispiel #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")
Beispiel #4
0
#!/usr/bin/python
import sys
import ns3
from wwplan import ns3_lib

ns3.LogComponentEnable("UdpEchoClientApplication",
                       ns3.LOG_LEVEL_INFO | ns3.LOG_PREFIX_TIME)
ns3.LogComponentEnable("UdpEchoServerApplication",
                       ns3.LOG_LEVEL_INFO | ns3.LOG_PREFIX_TIME)


def simulation(network):
    # Applications
    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=("Urpay", "Josjo1-wifi1", None),
                                   dest=("Ccatcca", "Josjo2-wimax2", 9),
                                   protocol="udp",
                                   direction="down",
                                   scheduling="rtps",
                                   priority=0)

    # Tracing
#!/usr/bin/python
import sys
import ns3
import optparse
from pprint import pprint

import radiomobile_ns3 as rmw_ns3

ns3.LogComponentEnable("UdpEchoClientApplication", ns3.LOG_LEVEL_INFO)
ns3.LogComponentEnable("UdpEchoServerApplication", ns3.LOG_LEVEL_INFO)


def run_simulation(network):
    #print "distance between CCATCCA and URCOS", distance
    # Applications
    server = network.nodes["CCATCCA"]
    server_address = server.devices["Uuario Final PCMCIA"].interfaces[
        0].address
    echoServer = ns3.UdpEchoServerHelper(9)
    serverApps = echoServer.Install(server.ns3_node)
    serverApps.Start(ns3.Seconds(1.0))
    serverApps.Stop(ns3.Seconds(10.0))

    client = network.nodes["URCOS"]
    echoClient = ns3.UdpEchoClientHelper(server_address, 9)
    echoClient.SetAttribute("MaxPackets", ns3.UintegerValue(1))
    echoClient.SetAttribute("Interval", ns3.TimeValue(ns3.Seconds(1.0)))
    echoClient.SetAttribute("PacketSize", ns3.UintegerValue(1024))
    clientApps = echoClient.Install(client.ns3_node)
    clientApps.Start(ns3.Seconds(2.0))
    clientApps.Stop(ns3.Seconds(10.0))
Beispiel #6
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)
Beispiel #7
0
import ns3
import visualizer

#ns3.LogComponentEnable("OnOffApplication", ns3.LOG_LEVEL_ALL)
ns3.LogComponentEnable("PacketSink", ns3.LOG_LEVEL_ALL)
nodes = ns3.NodeContainer()
nodes.Create(3)

wifihelper = ns3.WifiHelper()
wifihelper.SetStandard(ns3.WIFI_PHY_STANDARD_80211b)
wifiphyhelper = ns3.YansWifiPhyHelper()
wifiphy = wifiphyhelper.Default()
wifiphy.Set("TxGain", ns3.DoubleValue(25))
wifiphy.Set("RxGain", ns3.DoubleValue(90))
wifichannel = ns3.YansWifiChannelHelper()
wifi_chan = wifichannel.Default()
wifi_chan.AddPropagationLoss("ns3::FriisPropagationLossModel")
wifiphy.SetChannel(wifi_chan.Create())

mac = ns3.NqosWifiMacHelper.Default()
mac.SetType("ns3::AdhocWifiMac")

wifihelper.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode",
                                   ns3.StringValue("DsssRate1Mbps"),
                                   "ControlMode",
                                   ns3.StringValue("DsssRate1Mbps"))
devices = wifihelper.Install(wifiphy, mac, nodes)

olsr = ns3.OlsrHelper()

#Add the IPv4 protocol stack to the nodes in our container