Ejemplo n.º 1
0
def ltesession(opt):
    """
    Run a test LTE session.
    """
    nodeutils.set_node_map(nodemaps.NODES)
    session = Ns3Session(1, persistent=True, duration=opt.duration)
    lte = session.create_node(cls=Ns3LteNet, name="wlan1")
    lte.setsubchannels(range(25), range(50, 100))
    if opt.verbose:
        ascii_helper = ns.network.AsciiTraceHelper()
        stream = ascii_helper.CreateFileStream('/tmp/ns3lte.tr')
        lte.lte.EnableAsciiAll(stream)

    prefix = ipaddress.Ipv4Prefix("10.0.0.0/16")
    mobb = None
    nodes = []
    for i in xrange(1, opt.numnodes + 1):
        node = session.addnode(name="n%d" % i)
        mob = ns.mobility.ConstantPositionMobilityModel()
        mob.SetPosition(ns.core.Vector3D(10.0 * i, 0.0, 0.0))
        if i == 1:
            # first node is nodeb
            lte.setnodeb(node)
            mobb = mob
        node.newnetif(lte, ["%s/%s" % (prefix.addr(i), prefix.prefixlen)])
        nodes.append(node)
        if i == 1:
            _tmp, ns3dev = lte.findns3dev(node)
            lte.lte.AddMobility(ns3dev.GetPhy(), mob)
        if i > 1:
            lte.linknodeb(node, nodes[0], mob, mobb)

    session.thread = session.run(vis=opt.visualize)
    return session
Ejemplo n.º 2
0
def wifisession(opt):
    """
    Run a test wifi session.
    """
    nodeutils.set_node_map(nodemaps.NODES)
    session = Ns3Session(1, persistent=True, duration=opt.duration)
    session.name = "ns3wifi"
    session.filename = session.name + ".py"
    session.node_count = str(opt.numnodes + 1)
    add_to_server(session)

    wifi = session.create_node(cls=Ns3WifiNet, name="wlan1")
    wifi.setposition(30, 30, 0)
    wifi.phy.Set("RxGain", ns.core.DoubleValue(18.0))

    prefix = ipaddress.Ipv4Prefix("10.0.0.0/16")
    nodes = []
    for i in xrange(1, opt.numnodes + 1):
        node = session.addnode(name="n%d" % i)
        node.newnetif(wifi, ["%s/%s" % (prefix.addr(i), prefix.prefixlen)])
        nodes.append(node)
    session.setupconstantmobility()
    wifi.usecorepositions()
    # PHY tracing
    # wifi.phy.EnableAsciiAll("ns3wifi")
    session.thread = session.run(vis=False)
    return session
Ejemplo n.º 3
0
    def __init__(self, config=None):
        """
        Create a CoreEmu object.

        :param dict config: configuration options
        """
        # set umask 0
        os.umask(0)

        # configuration
        if not config:
            config = {}
        self.config = config

        # session management
        self.session_id_gen = IdGen(_id=0)
        self.sessions = {}

        # set default nodes
        node_map = nodemaps.NODES
        nodeutils.set_node_map(node_map)

        # load services
        self.service_errors = []
        self.load_services()

        # catch exit event
        atexit.register(self.shutdown)
Ejemplo n.º 4
0
def wifisession(opt):
    """
    Run a random walk wifi session.
    """
    nodeutils.set_node_map(nodemaps.NODES)
    session = Ns3Session(1, persistent=True, duration=opt.duration)
    session.name = "ns3wifirandomwalk"
    session.filename = session.name + ".py"
    session.node_count = str(opt.numnodes + 1)
    add_to_server(session)
    wifi = session.create_node(cls=Ns3WifiNet, name="wlan1", rate="OfdmRate12Mbps")
    wifi.setposition(30, 30, 0)
    # for improved connectivity
    wifi.phy.Set("RxGain", ns.core.DoubleValue(18.0))

    prefix = ipaddress.Ipv4Prefix("10.0.0.0/16")
    services_str = "zebra|OSPFv3MDR|IPForward"
    nodes = []
    for i in xrange(1, opt.numnodes + 1):
        node = session.addnode(name="n%d" % i)
        node.newnetif(wifi, ["%s/%s" % (prefix.addr(i), prefix.prefixlen)])
        nodes.append(node)
        session.services.add_services(node, "router", services_str.split("|"))
        session.services.boot_services(node)
    session.setuprandomwalkmobility(bounds=(1000.0, 750.0, 0))

    # PHY tracing
    # wifi.phy.EnableAsciiAll("ns3wifirandomwalk")

    # mobility tracing
    # session.setupmobilitytracing(wifi, "ns3wifirandomwalk.mob.tr",
    #                             nodes, verbose=True)
    session.startns3mobility(refresh_ms=150)

    # start simulation
    # session.instantiate() ?
    session.thread = session.run(vis=opt.viz)
    return session