def ltesession(opt):
    ''' Run a test LTE session.
    '''
    session = Ns3Session(persistent=True, duration=opt.duration)
    lte = session.addobj(cls=Ns3LteNet, name="wlan1")
    lte.setsubchannels(range(25), range(50, 100))
    if opt.verbose:
        ascii = ns.network.AsciiTraceHelper()
        stream = ascii.CreateFileStream('/tmp/ns3lte.tr')
        lte.lte.EnableAsciiAll(stream)
        #ns.core.LogComponentEnable("EnbNetDevice", ns.core.LOG_LEVEL_INFO)
        #ns.core.LogComponentEnable("UeNetDevice", ns.core.LOG_LEVEL_INFO)
        #lte.lte.EnableLogComponents()

    prefix = ipaddr.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:
            lte.setnodeb(node)  # first node is nodeb
            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
Exemplo n.º 2
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
Exemplo n.º 3
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.add_object(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
Exemplo n.º 4
0
def wimaxsession(opt):
    """
    Run a test wimax session.
    """
    session = Ns3Session(1, persistent=True, duration=opt.duration)
    wimax = session.create_node(cls=Ns3WimaxNet, name="wlan1")
    # wimax.wimax.EnableLogComponents()

    prefix = ipaddress.Ipv4Prefix("10.0.0.0/16")
    # create one classifier for ICMP (protocol 1) traffic
    # src port low/high, dst port low/high, protocol, priority
    # classifier = (0, 65000, 0, 65000, 1, 1)
    classifier = (0, 65000, 0, 65000, 17, 1)
    nodes = []
    for i in range(1, opt.numnodes + 1):
        node = session.addnode(name="n%d" % i)
        if i == 1:
            wimax.setbasestation(node)
        node.newnetif(wimax, ["%s/%s" % (prefix.addr(i), prefix.prefixlen)])
        if i > 2:
            wimax.addflow(nodes[-1], node, classifier, classifier)
        nodes.append(node)
    session.setupconstantmobility()
    session.thread = session.run(vis=False)
    return session
Exemplo n.º 5
0
def wifisession(opt):
    ''' Run a test wifi session.
    '''
    #myservice = "Olsrd4Service"
    myservice = "CcnOlsrNS3Service"
    numWirelessNode = 16
    numWiredNode = 0
    ns.core.Config.SetDefault("ns3::WifiMacQueue::MaxPacketNumber",
                              ns.core.UintegerValue(100))
    session = Ns3Session(persistent=True, duration=opt.duration)
    session.cfg['ccnx_dir'] = '/home/clauz/clone-git/ccnx/'
    session.cfg['olsr_dir'] = '/home/clauz/clone-git/olsrd-ccninfo/'
    session.cfg['rbn_dir'] = '/home/clauz/clone-git/routingbyname/'
    session.name = "ns3ccn"
    session.filename = session.name + ".py"
    session.node_count = str(numWirelessNode + numWiredNode + 1)
    session.services.importcustom("/home/clauz/.core/myservices")
    add_to_server(session)

    wifi = session.addobj(cls=Ns3WifiNet, name="wlan1", rate="OfdmRate54Mbps")
    wifi.setposition(150, 150, 0)
    wifi.phy.Set("RxGain", ns.core.DoubleValue(20.0))

    prefix = ipaddr.IPv4Prefix("10.0.0.0/16")

    def ourmacaddress(n):
        return MacAddr.fromstring("02:02:00:00:00:%02x" % n)

    nodes = []
    for i in range(4):
        for j in range(4):
            k = 1 + i * 4 + j
            node = session.addnode(name="n%d" % k)
            node.newnetif(wifi, ["%s/%s" % (prefix.addr(k), prefix.prefixlen)],
                          hwaddr=ourmacaddress(k))
            session.services.addservicestonode(node,
                                               "router",
                                               myservice,
                                               verbose=True)
            nodes.append(node)

    session.setupconstantmobility()

    for i in range(4):
        for j in range(4):
            k = i * 4 + j
            nodes[k].setns3position(100 * j, 100 * i, 0)
            nodes[k].setposition(100 * j, 100 * i, 0)

    #wifi.usecorepositions()
    # PHY tracing
    #wifi.phy.EnableAsciiAll("ns3wifi")

    session.thread = session.run(vis=False)

    for node in nodes:
        session.services.bootnodeservices(node)

    return session
Exemplo n.º 6
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.add_object(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.addservicestonode(node, "router", services_str)
        session.services.bootnodeservices(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
Exemplo n.º 7
0
def wifisession(opt):
    ''' Run a test wifi session.
    '''
    #myservice = "Olsrd4Service"
    myservice = "OpenvswitchService"
    #myservice = "OpenflowService"
    numWirelessNode = 6
    numWiredNode = 5
    ns.core.Config.SetDefault("ns3::WifiMacQueue::MaxPacketNumber",
                              ns.core.UintegerValue(100))
    session = Ns3Session(persistent=True, duration=opt.duration)
    session.cfg['openvswitch_dir'] = coreconf.openvswitch_dir
    session.cfg['olsr_dir'] = coreconf.olsr_dir
    session.cfg['olsrd_dir'] = coreconf.olsrd_dir
    session.name = "ns3SDN"
    session.filename = session.name + ".py"
    session.node_count = str(numWirelessNode + numWiredNode + 1)
    session.services.importcustom(coreconf.custom_services_dir)
    add_to_server(session)

    wifi = session.addobj(cls=Ns3WifiNet, name="wlan1", rate="OfdmRate54Mbps")
    #wifi.wifi.SetStandard(ns.wifi.WIFI_PHY_STANDARD_80211b)
    #wifi.wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode",ns.core.StringValue("DsssRate11Mbps"), "NonUnicastMode", ns.core.StringValue("DsssRate11Mbps"))
    wifi.setposition(30, 30, 0)
    wifi.phy.Set("RxGain", ns.core.DoubleValue(20.0))
    prefix = ipaddr.IPv4Prefix("10.0.0.0/16")

    hub1 = session.addobj(cls=pycore.nodes.HubNode, name="hub1")
    hub1.setposition(450, 300, 0)
    ptp1 = session.addobj(cls=pycore.nodes.PtpNet, name="ptp1")
    ptp2 = session.addobj(cls=pycore.nodes.PtpNet,
                          name="ptp2")  #controller network

    nodes = []

    def ourmacaddress(n):
        return MacAddr.fromstring("02:02:00:00:00:%02x" % n)

    node = session.addnode(name="n1")
    node.newnetif(wifi, ["%s/%s" % (prefix.addr(1), prefix.prefixlen)],
                  hwaddr=ourmacaddress(1))
    node.newnetif(ptp1, ["192.168.1.2/24"])
    session.services.addservicestonode(node, "router", myservice, verbose=True)
    session.services.bootnodeservices(node)
    nodes.append(node)

    for i in xrange(2, numWirelessNode - 2 + 1):
        node = session.addnode(name="n%d" % i)
        node.newnetif(wifi, ["%s/%s" % (prefix.addr(i), prefix.prefixlen)],
                      hwaddr=ourmacaddress(i))
        if i == 3:  #the wireless node which is attached to the controller
            node.newnetif(ptp2, ["10.100.100.2/24"])
        session.services.addservicestonode(node,
                                           "router",
                                           myservice,
                                           verbose=True)
        session.services.bootnodeservices(node)
        nodes.append(node)

    node = session.addnode(name="gw5")
    node.newnetif(wifi, ["%s/%s" % (prefix.addr(5), prefix.prefixlen)],
                  hwaddr=ourmacaddress(5))
    node.newnetif(hub1, ["192.168.200.5/24"])
    session.services.addservicestonode(node, "router", myservice, verbose=True)
    session.services.bootnodeservices(node)
    nodes.append(node)

    node = session.addnode(name="gw6")
    node.newnetif(wifi, ["%s/%s" % (prefix.addr(6), prefix.prefixlen)],
                  hwaddr=ourmacaddress(6))
    node.newnetif(hub1, ["192.168.200.6/24"])
    session.services.addservicestonode(node, "router", myservice, verbose=True)
    session.services.bootnodeservices(node)
    nodes.append(node)

    node = session.addnode(name="client")
    node.newnetif(hub1, ["192.168.200.1/24"])
    node.addaddr(0, "192.168.200.11/24")
    node.addaddr(0, "192.168.200.12/24")
    node.addaddr(0, "192.168.200.13/24")
    node.addaddr(0, "192.168.200.14/24")
    node.addaddr(0, "192.168.200.15/24")
    nodes.append(node)

    node = session.addnode(name="server")
    node.newnetif(ptp1, ["192.168.1.1/24"])
    nodes.append(node)

    node = session.addnode(name="controller")
    node.newnetif(ptp2, ["10.100.100.100/24"])
    nodes.append(node)

    session.setupconstantmobility()

    #n1
    nodes[0].setns3position(100, 300, 0)
    nodes[0].setposition(100, 300, 0)

    #n2
    nodes[1].setns3position(200, 300, 0)
    nodes[1].setposition(200, 300, 0)

    #n3
    nodes[2].setns3position(300, 300, 0)
    nodes[2].setposition(300, 300, 0)

    #n4
    nodes[3].setns3position(400, 300, 0)
    nodes[3].setposition(400, 300, 0)

    #gw5
    #nodes[4].setns3position(400,400,0)
    #nodes[4].setposition(400,400,0)
    nodes[4].setns3position(300, 400, 0)
    nodes[4].setposition(300, 400, 0)

    #gw6
    nodes[5].setns3position(400, 200, 0)
    nodes[5].setposition(400, 200, 0)

    #client
    nodes[6].setns3position(500, 300, 0)
    nodes[6].setposition(500, 300, 0)

    #server
    nodes[7].setns3position(100, 200, 0)
    nodes[7].setposition(100, 200, 0)

    #wifi.usecorepositions()
    # PHY tracing
    #wifi.phy.EnableAsciiAll("ns3wifi")

    session.thread = session.run(vis=False)

    #nodes[0].icmd(["sh", "./olsrdservice_start.sh", "start"])
    return session