2017-08-17 21:29:19 +01:00
|
|
|
"""
|
2013-08-29 15:21:13 +01:00
|
|
|
ns3lte.py - This script demonstrates using CORE with the ns-3 LTE model.
|
|
|
|
*** Note that this script is not currently functional, see notes below. ***
|
|
|
|
- issues connecting TapBridge with LteNetDevice
|
2017-08-17 21:29:19 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
import optparse
|
|
|
|
import sys
|
2013-08-29 15:21:13 +01:00
|
|
|
|
|
|
|
import ns.core
|
|
|
|
import ns.mobility
|
|
|
|
|
2017-08-17 21:29:19 +01:00
|
|
|
from core import logger
|
|
|
|
from core.misc import ipaddress
|
2017-08-18 16:48:33 +01:00
|
|
|
from core.misc import nodemaps
|
|
|
|
from core.misc import nodeutils
|
2017-08-17 21:29:19 +01:00
|
|
|
from corens3.obj import Ns3LteNet
|
|
|
|
from corens3.obj import Ns3Session
|
|
|
|
|
|
|
|
|
2013-08-29 15:21:13 +01:00
|
|
|
def ltesession(opt):
|
2017-08-17 21:29:19 +01:00
|
|
|
"""
|
|
|
|
Run a test LTE session.
|
|
|
|
"""
|
2017-08-18 16:48:33 +01:00
|
|
|
nodeutils.set_node_map(nodemaps.NODES)
|
|
|
|
session = Ns3Session(1, persistent=True, duration=opt.duration)
|
2017-08-17 21:29:19 +01:00
|
|
|
lte = session.add_object(cls=Ns3LteNet, name="wlan1")
|
2013-08-29 15:21:13 +01:00
|
|
|
lte.setsubchannels(range(25), range(50, 100))
|
|
|
|
if opt.verbose:
|
|
|
|
ascii = ns.network.AsciiTraceHelper()
|
|
|
|
stream = ascii.CreateFileStream('/tmp/ns3lte.tr')
|
|
|
|
lte.lte.EnableAsciiAll(stream)
|
2017-08-17 21:29:19 +01:00
|
|
|
# ns.core.LogComponentEnable("EnbNetDevice", ns.core.LOG_LEVEL_INFO)
|
|
|
|
# ns.core.LogComponentEnable("UeNetDevice", ns.core.LOG_LEVEL_INFO)
|
|
|
|
# lte.lte.EnableLogComponents()
|
2013-08-29 15:21:13 +01:00
|
|
|
|
2017-08-17 21:29:19 +01:00
|
|
|
prefix = ipaddress.Ipv4Prefix("10.0.0.0/16")
|
2013-08-29 15:21:13 +01:00
|
|
|
mobb = None
|
|
|
|
nodes = []
|
|
|
|
for i in xrange(1, opt.numnodes + 1):
|
2017-08-17 21:29:19 +01:00
|
|
|
node = session.addnode(name="n%d" % i)
|
2013-08-29 15:21:13 +01:00
|
|
|
mob = ns.mobility.ConstantPositionMobilityModel()
|
2017-08-17 21:29:19 +01:00
|
|
|
mob.SetPosition(ns.core.Vector3D(10.0 * i, 0.0, 0.0))
|
2013-08-29 15:21:13 +01:00
|
|
|
if i == 1:
|
2017-08-17 21:29:19 +01:00
|
|
|
# first node is nodeb
|
|
|
|
lte.setnodeb(node)
|
2013-08-29 15:21:13 +01:00
|
|
|
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)
|
2017-08-17 21:29:19 +01:00
|
|
|
|
2013-08-29 15:21:13 +01:00
|
|
|
session.thread = session.run(vis=opt.visualize)
|
|
|
|
return session
|
2017-08-17 21:29:19 +01:00
|
|
|
|
|
|
|
|
2013-08-29 15:21:13 +01:00
|
|
|
def main():
|
2017-08-17 21:29:19 +01:00
|
|
|
"""
|
|
|
|
Main routine when running from command-line.
|
|
|
|
"""
|
2013-08-29 15:21:13 +01:00
|
|
|
usagestr = "usage: %prog [-h] [options] [args]"
|
2017-08-17 21:29:19 +01:00
|
|
|
parser = optparse.OptionParser(usage=usagestr)
|
|
|
|
parser.set_defaults(numnodes=4, duration=600, verbose=False, visualize=False)
|
|
|
|
|
|
|
|
parser.add_option("-d", "--duration", dest="duration", type=int,
|
|
|
|
help="number of seconds to run the simulation")
|
|
|
|
parser.add_option("-n", "--numnodes", dest="numnodes", type=int,
|
|
|
|
help="number of nodes")
|
|
|
|
parser.add_option("-z", "--visualize", dest="visualize",
|
|
|
|
action="store_true", help="enable visualizer")
|
|
|
|
parser.add_option("-v", "--verbose", dest="verbose",
|
|
|
|
action="store_true", help="be more verbose")
|
|
|
|
|
|
|
|
def usage(msg=None, err=0):
|
2013-08-29 15:21:13 +01:00
|
|
|
sys.stdout.write("\n")
|
|
|
|
if msg:
|
|
|
|
sys.stdout.write(msg + "\n\n")
|
|
|
|
parser.print_help()
|
|
|
|
sys.exit(err)
|
|
|
|
|
2017-08-17 21:29:19 +01:00
|
|
|
opt, args = parser.parse_args()
|
2013-08-29 15:21:13 +01:00
|
|
|
|
|
|
|
if opt.numnodes < 2:
|
|
|
|
usage("invalid numnodes: %s" % opt.numnodes)
|
|
|
|
|
|
|
|
for a in args:
|
2017-08-17 21:29:19 +01:00
|
|
|
logger.warn("ignoring command line argument: '%s'", a)
|
2013-08-29 15:21:13 +01:00
|
|
|
|
|
|
|
return ltesession(opt)
|
|
|
|
|
2017-08-17 21:29:19 +01:00
|
|
|
|
2013-08-29 15:21:13 +01:00
|
|
|
def cleanup():
|
2017-08-17 21:29:19 +01:00
|
|
|
logger.info("shutting down session")
|
2013-08-29 15:21:13 +01:00
|
|
|
session.shutdown()
|
2017-08-17 21:29:19 +01:00
|
|
|
|
2013-08-29 15:21:13 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
session = main()
|