moved ns3 from under daemon to the root of the project and updated references
This commit is contained in:
parent
3da4c32825
commit
77be7f5c30
16 changed files with 11 additions and 14 deletions
|
@ -10,10 +10,6 @@
|
|||
SETUPPY = setup.py
|
||||
SETUPPYFLAGS = -v
|
||||
|
||||
if WANT_NETNS
|
||||
SUBDIRS = ns3
|
||||
endif
|
||||
|
||||
SBIN_FILES = \
|
||||
sbin/core-cleanup \
|
||||
sbin/core-daemon \
|
||||
|
|
|
@ -1,339 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
|
@ -1,59 +0,0 @@
|
|||
# CORE
|
||||
# (c)2012 the Boeing Company.
|
||||
# See the LICENSE file included in this directory.
|
||||
#
|
||||
# author: Jeff Ahrenholz <jeffrey.m.ahrenholz@boeing.com>
|
||||
#
|
||||
# Makefile for building corens3 components.
|
||||
#
|
||||
|
||||
SETUPPY = setup.py
|
||||
SETUPPYFLAGS = -v
|
||||
|
||||
EXAMPLE_FILES = \
|
||||
examples/ns3lte.py \
|
||||
examples/ns3wifi.py \
|
||||
examples/ns3wifirandomwalk.py \
|
||||
examples/ns3wimax.py
|
||||
|
||||
coreexampledir = $(datadir)/core/examples/corens3
|
||||
dist_coreexample_SCRIPTS= $(EXAMPLE_FILES)
|
||||
|
||||
# Python package build
|
||||
noinst_SCRIPTS = build
|
||||
build:
|
||||
$(PYTHON) $(SETUPPY) $(SETUPPYFLAGS) build
|
||||
|
||||
# Python package install
|
||||
install-exec-hook:
|
||||
$(MKDIR_P) ${DESTDIR}/${pythondir}
|
||||
$(MKDIR_P) ${DESTDIR}/${pyexecdir}
|
||||
PYTHONPATH=${DESTDIR}/${pythondir} $(PYTHON) $(SETUPPY) $(SETUPPYFLAGS) install \
|
||||
--prefix=${DESTDIR}/${pyprefix} \
|
||||
--install-purelib=${DESTDIR}/${pythondir} \
|
||||
--install-platlib=${DESTDIR}/${pyexecdir} \
|
||||
--no-compile
|
||||
|
||||
# Python package uninstall
|
||||
uninstall-hook:
|
||||
rm -f ${pythondir}/corens3_python-${COREDPY_VERSION}-py${PYTHON_VERSION}.egg-info
|
||||
rm -rf ${pythondir}/corens3
|
||||
rmdir -p $(coreexampledir) || true
|
||||
|
||||
# Python package cleanup
|
||||
clean-local:
|
||||
-rm -rf build
|
||||
|
||||
# Python RPM package
|
||||
rpm:
|
||||
$(PYTHON) $(SETUPPY) $(SETUPPYFLAGS) bdist_rpm
|
||||
|
||||
# because we include entire directories with EXTRA_DIST, we need to clean up
|
||||
# the source control files
|
||||
dist-hook:
|
||||
rm -rf `find $(distdir)/ -name .svn` `find $(distdir)/ -name '*.pyc'`
|
||||
|
||||
DISTCLEANFILES = Makefile.in *.pyc corens3/*.pyc MANIFEST
|
||||
|
||||
# files to include with distribution tarball
|
||||
EXTRA_DIST = LICENSE $(SETUPPY) corens3
|
1
daemon/ns3/corens3/.gitignore
vendored
1
daemon/ns3/corens3/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
constants.py
|
|
@ -1,9 +0,0 @@
|
|||
"""
|
||||
corens3
|
||||
|
||||
Python package containing CORE components for use
|
||||
with the ns-3 simulator.
|
||||
|
||||
See http://www.nrl.navy.mil/itd/ncs/products/core and
|
||||
http://code.google.com/p/coreemu/ for more information on CORE.
|
||||
"""
|
|
@ -1,18 +0,0 @@
|
|||
# Constants created by autoconf ./configure script
|
||||
COREDPY_VERSION = "@COREDPY_VERSION@"
|
||||
CORE_STATE_DIR = "@CORE_STATE_DIR@"
|
||||
CORE_CONF_DIR = "@CORE_CONF_DIR@"
|
||||
CORE_DATA_DIR = "@CORE_DATA_DIR@"
|
||||
CORE_LIB_DIR = "@CORE_LIB_DIR@"
|
||||
CORE_SBIN_DIR = "@SBINDIR@"
|
||||
|
||||
BRCTL_BIN = "@brctl_path@/brctl"
|
||||
IP_BIN = "@ip_path@/ip"
|
||||
TC_BIN = "@tc_path@/tc"
|
||||
EBTABLES_BIN = "@ebtables_path@/ebtables"
|
||||
IFCONFIG_BIN = "@ifconfig_path@/ifconfig"
|
||||
NGCTL_BIN = "@ngctl_path@/ngctl"
|
||||
VIMAGE_BIN = "@vimage_path@/vimage"
|
||||
QUAGGA_STATE_DIR = "@CORE_STATE_DIR@/run/quagga"
|
||||
MOUNT_BIN = "@mount_path@/mount"
|
||||
UMOUNT_BIN = "@umount_path@/umount"
|
|
@ -1,550 +0,0 @@
|
|||
"""
|
||||
ns3.py: defines classes for running emulations with ns-3 simulated networks.
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import threading
|
||||
import time
|
||||
|
||||
import ns.core
|
||||
import ns.internet
|
||||
import ns.lte
|
||||
import ns.mobility
|
||||
import ns.network
|
||||
import ns.tap_bridge
|
||||
import ns.wifi
|
||||
import ns.wimax
|
||||
|
||||
from core import constants
|
||||
from core import logger
|
||||
from core.coreobj import PyCoreNet
|
||||
from core.enumerations import EventTypes
|
||||
from core.enumerations import LinkTypes
|
||||
from core.enumerations import NodeTypes
|
||||
from core.misc.utils import maketuple
|
||||
from core.mobility import WayPointMobility
|
||||
from core.netns.nodes import CoreNode
|
||||
from core.session import Session
|
||||
|
||||
ns.core.GlobalValue.Bind(
|
||||
"SimulatorImplementationType",
|
||||
ns.core.StringValue("ns3::RealtimeSimulatorImpl")
|
||||
)
|
||||
ns.core.GlobalValue.Bind(
|
||||
"ChecksumEnabled",
|
||||
ns.core.BooleanValue("true")
|
||||
)
|
||||
|
||||
|
||||
class CoreNs3Node(CoreNode, ns.network.Node):
|
||||
"""
|
||||
The CoreNs3Node is both a CoreNode backed by a network namespace and
|
||||
an ns-3 Node simulator object. When linked to simulated networks, the TunTap
|
||||
device will be used.
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwds):
|
||||
ns.network.Node.__init__(self)
|
||||
# ns-3 ID starts at 0, CORE uses 1
|
||||
objid = self.GetId() + 1
|
||||
if 'objid' not in kwds:
|
||||
kwds['objid'] = objid
|
||||
CoreNode.__init__(self, *args, **kwds)
|
||||
|
||||
def newnetif(self, net=None, addrlist=None, hwaddr=None, ifindex=None, ifname=None):
|
||||
"""
|
||||
Add a network interface. If we are attaching to a CoreNs3Net, this
|
||||
will be a TunTap. Otherwise dispatch to CoreNode.newnetif().
|
||||
"""
|
||||
if not addrlist:
|
||||
addrlist = []
|
||||
|
||||
if not isinstance(net, CoreNs3Net):
|
||||
return CoreNode.newnetif(self, net, addrlist, hwaddr, ifindex, ifname)
|
||||
ifindex = self.newtuntap(ifindex=ifindex, ifname=ifname, net=net)
|
||||
self.attachnet(ifindex, net)
|
||||
netif = self.netif(ifindex)
|
||||
netif.sethwaddr(hwaddr)
|
||||
for addr in maketuple(addrlist):
|
||||
netif.addaddr(addr)
|
||||
|
||||
addrstr = netif.addrlist[0]
|
||||
(addr, mask) = addrstr.split('/')
|
||||
tap = net._tapdevs[netif]
|
||||
tap.SetAttribute(
|
||||
"IpAddress",
|
||||
ns.network.Ipv4AddressValue(ns.network.Ipv4Address(addr))
|
||||
)
|
||||
tap.SetAttribute(
|
||||
"Netmask",
|
||||
ns.network.Ipv4MaskValue(ns.network.Ipv4Mask("/" + mask))
|
||||
)
|
||||
ns.core.Simulator.Schedule(ns.core.Time('0'), netif.install)
|
||||
return ifindex
|
||||
|
||||
def getns3position(self):
|
||||
"""
|
||||
Return the ns-3 (x, y, z) position of a node.
|
||||
"""
|
||||
try:
|
||||
mm = self.GetObject(ns.mobility.MobilityModel.GetTypeId())
|
||||
pos = mm.GetPosition()
|
||||
return pos.x, pos.y, pos.z
|
||||
except AttributeError:
|
||||
self.warn("ns-3 mobility model not found")
|
||||
return 0, 0, 0
|
||||
|
||||
def setns3position(self, x, y, z):
|
||||
"""
|
||||
Set the ns-3 (x, y, z) position of a node.
|
||||
"""
|
||||
try:
|
||||
mm = self.GetObject(ns.mobility.MobilityModel.GetTypeId())
|
||||
if z is None:
|
||||
z = 0.0
|
||||
pos = mm.SetPosition(ns.core.Vector(x, y, z))
|
||||
except AttributeError:
|
||||
self.warn("ns-3 mobility model not found, not setting position")
|
||||
|
||||
|
||||
class CoreNs3Net(PyCoreNet):
|
||||
"""
|
||||
The CoreNs3Net is a helper PyCoreNet object. Networks are represented
|
||||
entirely in simulation with the TunTap device bridging the emulated and
|
||||
simulated worlds.
|
||||
"""
|
||||
apitype = NodeTypes.WIRELESS_LAN.value
|
||||
linktype = LinkTypes.WIRELESS.value
|
||||
# icon used
|
||||
type = "wlan"
|
||||
|
||||
def __init__(self, session, objid=None, name=None, start=True, policy=None):
|
||||
PyCoreNet.__init__(self, session, objid, name)
|
||||
self.tapbridge = ns.tap_bridge.TapBridgeHelper()
|
||||
self._ns3devs = {}
|
||||
self._tapdevs = {}
|
||||
|
||||
def attach(self, netif):
|
||||
"""
|
||||
Invoked from netif.attach(). Create a TAP device using the TapBridge
|
||||
object. Call getns3dev() to get model-specific device.
|
||||
"""
|
||||
self._netif[netif] = netif
|
||||
self._linked[netif] = {}
|
||||
ns3dev = self.getns3dev(netif.node)
|
||||
tap = self.tapbridge.Install(netif.node, ns3dev)
|
||||
tap.SetMode(ns.tap_bridge.TapBridge.CONFIGURE_LOCAL)
|
||||
tap.SetAttribute(
|
||||
"DeviceName",
|
||||
ns.core.StringValue(netif.localname)
|
||||
)
|
||||
self._ns3devs[netif] = ns3dev
|
||||
self._tapdevs[netif] = tap
|
||||
|
||||
def getns3dev(self, node):
|
||||
"""
|
||||
Implement depending on network helper. Install this network onto
|
||||
the given node and return the device. Register the ns3 device into
|
||||
self._ns3devs
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def findns3dev(self, node):
|
||||
"""
|
||||
Given a node, return the interface and ns3 device associated with
|
||||
this network.
|
||||
"""
|
||||
for netif in node.netifs():
|
||||
if netif in self._ns3devs:
|
||||
return netif, self._ns3devs[netif]
|
||||
return None, None
|
||||
|
||||
def shutdown(self):
|
||||
"""
|
||||
Session.shutdown() will invoke this.
|
||||
"""
|
||||
pass
|
||||
|
||||
def usecorepositions(self):
|
||||
"""
|
||||
Set position callbacks for interfaces on this net so the CORE GUI
|
||||
can update the ns-3 node position when moved with the mouse.
|
||||
"""
|
||||
for netif in self.netifs():
|
||||
netif.poshook = self.setns3position
|
||||
|
||||
def setns3position(self, netif, x, y, z):
|
||||
logger.info("setns3position: %s (%s, %s, %s)", netif.node.name, x, y, z)
|
||||
netif.node.setns3position(x, y, z)
|
||||
|
||||
|
||||
class Ns3LteNet(CoreNs3Net):
|
||||
def __init__(self, *args, **kwds):
|
||||
"""
|
||||
Uses a LteHelper to create an ns-3 based LTE network.
|
||||
"""
|
||||
CoreNs3Net.__init__(self, *args, **kwds)
|
||||
self.lte = ns.lte.LteHelper()
|
||||
# enhanced NodeB node list
|
||||
self.enbnodes = []
|
||||
self.dlsubchannels = None
|
||||
self.ulsubchannels = None
|
||||
|
||||
def setsubchannels(self, downlink, uplink):
|
||||
"""
|
||||
Set the downlink/uplink subchannels, which are a list of ints.
|
||||
These should be set prior to using CoreNs3Node.newnetif().
|
||||
"""
|
||||
self.dlsubchannels = downlink
|
||||
self.ulsubchannels = uplink
|
||||
|
||||
def setnodeb(self, node):
|
||||
"""
|
||||
Mark the given node as a nodeb (base transceiver station)
|
||||
"""
|
||||
self.enbnodes.append(node)
|
||||
|
||||
def linknodeb(self, node, nodeb, mob, mobb):
|
||||
"""
|
||||
Register user equipment with a nodeb.
|
||||
Optionally install mobility model while we have the ns-3 devs handy.
|
||||
"""
|
||||
tmp, nodebdev = self.findns3dev(nodeb)
|
||||
tmp, dev = self.findns3dev(node)
|
||||
if nodebdev is None or dev is None:
|
||||
raise KeyError, "ns-3 device for node not found"
|
||||
self.lte.RegisterUeToTheEnb(dev, nodebdev)
|
||||
if mob:
|
||||
self.lte.AddMobility(dev.GetPhy(), mob)
|
||||
if mobb:
|
||||
self.lte.AddDownlinkChannelRealization(mobb, mob, dev.GetPhy())
|
||||
|
||||
def getns3dev(self, node):
|
||||
"""
|
||||
Get the ns3 NetDevice using the LteHelper.
|
||||
"""
|
||||
if node in self.enbnodes:
|
||||
devtype = ns.lte.LteHelper.DEVICE_TYPE_ENODEB
|
||||
else:
|
||||
devtype = ns.lte.LteHelper.DEVICE_TYPE_USER_EQUIPMENT
|
||||
nodes = ns.network.NodeContainer(node)
|
||||
devs = self.lte.Install(nodes, devtype)
|
||||
devs.Get(0).GetPhy().SetDownlinkSubChannels(self.dlsubchannels)
|
||||
devs.Get(0).GetPhy().SetUplinkSubChannels(self.ulsubchannels)
|
||||
return devs.Get(0)
|
||||
|
||||
def attach(self, netif):
|
||||
"""
|
||||
Invoked from netif.attach(). Create a TAP device using the TapBridge
|
||||
object. Call getns3dev() to get model-specific device.
|
||||
"""
|
||||
self._netif[netif] = netif
|
||||
self._linked[netif] = {}
|
||||
ns3dev = self.getns3dev(netif.node)
|
||||
self.tapbridge.SetAttribute("Mode", ns.core.StringValue("UseLocal"))
|
||||
# self.tapbridge.SetAttribute("Mode",
|
||||
# ns.core.IntegerValue(ns.tap_bridge.TapBridge.USE_LOCAL))
|
||||
tap = self.tapbridge.Install(netif.node, ns3dev)
|
||||
# tap.SetMode(ns.tap_bridge.TapBridge.USE_LOCAL)
|
||||
logger.info("using TAP device %s for %s/%s", netif.localname, netif.node.name, netif.name)
|
||||
subprocess.check_call(['tunctl', '-t', netif.localname, '-n'])
|
||||
# check_call([IP_BIN, 'link', 'set', 'dev', netif.localname, \
|
||||
# 'address', '%s' % netif.hwaddr])
|
||||
subprocess.check_call([constants.IP_BIN, 'link', 'set', netif.localname, 'up'])
|
||||
tap.SetAttribute("DeviceName", ns.core.StringValue(netif.localname))
|
||||
self._ns3devs[netif] = ns3dev
|
||||
self._tapdevs[netif] = tap
|
||||
|
||||
|
||||
class Ns3WifiNet(CoreNs3Net):
|
||||
def __init__(self, *args, **kwds):
|
||||
"""
|
||||
Uses a WifiHelper to create an ns-3 based Wifi network.
|
||||
"""
|
||||
rate = kwds.pop('rate', 'OfdmRate54Mbps')
|
||||
CoreNs3Net.__init__(self, *args, **kwds)
|
||||
self.wifi = ns.wifi.WifiHelper().Default()
|
||||
self.wifi.SetStandard(ns.wifi.WIFI_PHY_STANDARD_80211a)
|
||||
self.wifi.SetRemoteStationManager(
|
||||
"ns3::ConstantRateWifiManager",
|
||||
"DataMode",
|
||||
ns.core.StringValue(rate),
|
||||
"NonUnicastMode",
|
||||
ns.core.StringValue(rate)
|
||||
)
|
||||
self.mac = ns.wifi.NqosWifiMacHelper.Default()
|
||||
self.mac.SetType("ns3::AdhocWifiMac")
|
||||
|
||||
channel = ns.wifi.YansWifiChannelHelper.Default()
|
||||
self.phy = ns.wifi.YansWifiPhyHelper.Default()
|
||||
self.phy.SetChannel(channel.Create())
|
||||
|
||||
def getns3dev(self, node):
|
||||
"""
|
||||
Get the ns3 NetDevice using the WifiHelper.
|
||||
"""
|
||||
devs = self.wifi.Install(self.phy, self.mac, node)
|
||||
return devs.Get(0)
|
||||
|
||||
|
||||
class Ns3WimaxNet(CoreNs3Net):
|
||||
def __init__(self, *args, **kwds):
|
||||
CoreNs3Net.__init__(self, *args, **kwds)
|
||||
self.wimax = ns.wimax.WimaxHelper()
|
||||
self.scheduler = ns.wimax.WimaxHelper.SCHED_TYPE_SIMPLE
|
||||
self.phy = ns.wimax.WimaxHelper.SIMPLE_PHY_TYPE_OFDM
|
||||
# base station node list
|
||||
self.bsnodes = []
|
||||
|
||||
def setbasestation(self, node):
|
||||
self.bsnodes.append(node)
|
||||
|
||||
def getns3dev(self, node):
|
||||
if node in self.bsnodes:
|
||||
devtype = ns.wimax.WimaxHelper.DEVICE_TYPE_BASE_STATION
|
||||
else:
|
||||
devtype = ns.wimax.WimaxHelper.DEVICE_TYPE_SUBSCRIBER_STATION
|
||||
nodes = ns.network.NodeContainer(node)
|
||||
devs = self.wimax.Install(nodes, devtype, self.phy, self.scheduler)
|
||||
if node not in self.bsnodes:
|
||||
devs.Get(0).SetModulationType(ns.wimax.WimaxPhy.MODULATION_TYPE_QAM16_12)
|
||||
# debug
|
||||
self.wimax.EnableAscii("wimax-device-%s" % node.name, devs)
|
||||
return devs.Get(0)
|
||||
|
||||
@staticmethod
|
||||
def ipv4netifaddr(netif):
|
||||
for addr in netif.addrlist:
|
||||
if ':' in addr:
|
||||
# skip ipv6
|
||||
continue
|
||||
ip = ns.network.Ipv4Address(addr.split('/')[0])
|
||||
mask = ns.network.Ipv4Mask('/' + addr.split('/')[1])
|
||||
return ip, mask
|
||||
return None, None
|
||||
|
||||
def addflow(self, node1, node2, upclass, downclass):
|
||||
"""
|
||||
Add a Wimax service flow between two nodes.
|
||||
"""
|
||||
netif1, ns3dev1 = self.findns3dev(node1)
|
||||
netif2, ns3dev2 = self.findns3dev(node2)
|
||||
if not netif1 or not netif2:
|
||||
raise ValueError, "interface not found"
|
||||
addr1, mask1 = self.ipv4netifaddr(netif1)
|
||||
addr2, mask2 = self.ipv4netifaddr(netif2)
|
||||
clargs1 = (addr1, mask1, addr2, mask2) + downclass
|
||||
clargs2 = (addr2, mask2, addr1, mask1) + upclass
|
||||
clrec1 = ns.wimax.IpcsClassifierRecord(*clargs1)
|
||||
clrec2 = ns.wimax.IpcsClassifierRecord(*clargs2)
|
||||
ns3dev1.AddServiceFlow(self.wimax.CreateServiceFlow(
|
||||
ns.wimax.ServiceFlow.SF_DIRECTION_DOWN,
|
||||
ns.wimax.ServiceFlow.SF_TYPE_RTPS, clrec1)
|
||||
)
|
||||
ns3dev1.AddServiceFlow(self.wimax.CreateServiceFlow(
|
||||
ns.wimax.ServiceFlow.SF_DIRECTION_UP,
|
||||
ns.wimax.ServiceFlow.SF_TYPE_RTPS, clrec2)
|
||||
)
|
||||
ns3dev2.AddServiceFlow(self.wimax.CreateServiceFlow(
|
||||
ns.wimax.ServiceFlow.SF_DIRECTION_DOWN,
|
||||
ns.wimax.ServiceFlow.SF_TYPE_RTPS, clrec2)
|
||||
)
|
||||
ns3dev2.AddServiceFlow(self.wimax.CreateServiceFlow(
|
||||
ns.wimax.ServiceFlow.SF_DIRECTION_UP,
|
||||
ns.wimax.ServiceFlow.SF_TYPE_RTPS, clrec1)
|
||||
)
|
||||
|
||||
|
||||
class Ns3Session(Session):
|
||||
"""
|
||||
A Session that starts an ns-3 simulation thread.
|
||||
"""
|
||||
|
||||
def __init__(self, session_id, persistent=False, duration=600):
|
||||
self.duration = duration
|
||||
self.nodes = ns.network.NodeContainer()
|
||||
self.mobhelper = ns.mobility.MobilityHelper()
|
||||
Session.__init__(self, session_id, persistent=persistent)
|
||||
|
||||
def run(self, vis=False):
|
||||
"""
|
||||
Run the ns-3 simulation and return the simulator thread.
|
||||
"""
|
||||
|
||||
def runthread():
|
||||
ns.core.Simulator.Stop(ns.core.Seconds(self.duration))
|
||||
logger.info("running ns-3 simulation for %d seconds", self.duration)
|
||||
if vis:
|
||||
try:
|
||||
import visualizer
|
||||
except ImportError:
|
||||
logger.exception("visualizer is not available")
|
||||
ns.core.Simulator.Run()
|
||||
else:
|
||||
visualizer.start()
|
||||
else:
|
||||
ns.core.Simulator.Run()
|
||||
|
||||
# self.evq.run() # event queue may have WayPointMobility events
|
||||
self.set_state(EventTypes.RUNTIME_STATE.value, send_event=True)
|
||||
t = threading.Thread(target=runthread)
|
||||
t.daemon = True
|
||||
t.start()
|
||||
return t
|
||||
|
||||
def shutdown(self):
|
||||
# TODO: the following line tends to segfault ns-3 (and therefore core-daemon)
|
||||
ns.core.Simulator.Destroy()
|
||||
Session.shutdown(self)
|
||||
|
||||
def addnode(self, name):
|
||||
"""
|
||||
A convenience helper for Session.addobj(), for adding CoreNs3Nodes
|
||||
to this session. Keeps a NodeContainer for later use.
|
||||
"""
|
||||
n = self.add_object(cls=CoreNs3Node, name=name)
|
||||
self.nodes.Add(n)
|
||||
return n
|
||||
|
||||
def setupconstantmobility(self):
|
||||
"""
|
||||
Install a ConstantPositionMobilityModel.
|
||||
"""
|
||||
palloc = ns.mobility.ListPositionAllocator()
|
||||
for i in xrange(self.nodes.GetN()):
|
||||
(x, y, z) = ((100.0 * i) + 50, 200.0, 0.0)
|
||||
palloc.Add(ns.core.Vector(x, y, z))
|
||||
node = self.nodes.Get(i)
|
||||
node.position.set(x, y, z)
|
||||
self.mobhelper.SetPositionAllocator(palloc)
|
||||
self.mobhelper.SetMobilityModel("ns3::ConstantPositionMobilityModel")
|
||||
self.mobhelper.Install(self.nodes)
|
||||
|
||||
def setuprandomwalkmobility(self, bounds, time=10, speed=25.0):
|
||||
"""
|
||||
Set up the random walk mobility model within a bounding box.
|
||||
- bounds is the max (x, y, z) boundary
|
||||
- time is the number of seconds to maintain the current speed
|
||||
and direction
|
||||
- speed is the maximum speed, with node speed randomly chosen
|
||||
from [0, speed]
|
||||
"""
|
||||
x, y, z = map(float, bounds)
|
||||
self.mobhelper.SetPositionAllocator(
|
||||
"ns3::RandomBoxPositionAllocator",
|
||||
"X",
|
||||
ns.core.StringValue("ns3::UniformRandomVariable[Min=0|Max=%s]" % x),
|
||||
"Y",
|
||||
ns.core.StringValue("ns3::UniformRandomVariable[Min=0|Max=%s]" % y),
|
||||
"Z",
|
||||
ns.core.StringValue("ns3::UniformRandomVariable[Min=0|Max=%s]" % z)
|
||||
)
|
||||
self.mobhelper.SetMobilityModel(
|
||||
"ns3::RandomWalk2dMobilityModel",
|
||||
"Mode", ns.core.StringValue("Time"),
|
||||
"Time", ns.core.StringValue("%ss" % time),
|
||||
"Speed",
|
||||
ns.core.StringValue("ns3::UniformRandomVariable[Min=0|Max=%s]" % speed),
|
||||
"Bounds", ns.core.StringValue("0|%s|0|%s" % (x, y))
|
||||
)
|
||||
self.mobhelper.Install(self.nodes)
|
||||
|
||||
def startns3mobility(self, refresh_ms=300):
|
||||
"""
|
||||
Start a thread that updates CORE nodes based on their ns-3
|
||||
positions.
|
||||
"""
|
||||
self.set_state(EventTypes.INSTANTIATION_STATE.value)
|
||||
self.mobilitythread = threading.Thread(
|
||||
target=self.ns3mobilitythread,
|
||||
args=(refresh_ms,))
|
||||
self.mobilitythread.daemon = True
|
||||
self.mobilitythread.start()
|
||||
|
||||
def ns3mobilitythread(self, refresh_ms):
|
||||
"""
|
||||
Thread target that updates CORE nodes every refresh_ms based on
|
||||
their ns-3 positions.
|
||||
"""
|
||||
valid_states = (
|
||||
EventTypes.RUNTIME_STATE.value,
|
||||
EventTypes.INSTANTIATION_STATE.value
|
||||
)
|
||||
while self.state in valid_states:
|
||||
for i in xrange(self.nodes.GetN()):
|
||||
node = self.nodes.Get(i)
|
||||
x, y, z = node.getns3position()
|
||||
if (x, y, z) == node.position.get():
|
||||
continue
|
||||
# from WayPointMobility.setnodeposition(node, x, y, z)
|
||||
node.position.set(x, y, z)
|
||||
node_data = node.data(0)
|
||||
self.broadcast_node(node_data)
|
||||
self.sdt.updatenode(node.objid, flags=0, x=x, y=y, z=z)
|
||||
time.sleep(0.001 * refresh_ms)
|
||||
|
||||
def setupmobilitytracing(self, net, filename, nodes):
|
||||
"""
|
||||
Start a tracing thread using the ASCII output from the ns3
|
||||
mobility helper.
|
||||
"""
|
||||
net.mobility = WayPointMobility(session=self, object_id=net.objid, values=None)
|
||||
net.mobility.setendtime()
|
||||
net.mobility.refresh_ms = 300
|
||||
net.mobility.empty_queue_stop = False
|
||||
of = ns.network.OutputStreamWrapper(filename, filemode=777)
|
||||
self.mobhelper.EnableAsciiAll(of)
|
||||
self.mobilitytracethread = threading.Thread(
|
||||
target=self.mobilitytrace,
|
||||
args=(net, filename, nodes)
|
||||
)
|
||||
self.mobilitytracethread.daemon = True
|
||||
self.mobilitytracethread.start()
|
||||
|
||||
def mobilitytrace(self, net, filename, nodes, verbose):
|
||||
nodemap = {}
|
||||
# move nodes to initial positions
|
||||
for node in nodes:
|
||||
x, y, z = node.getns3position()
|
||||
net.mobility.setnodeposition(node, x, y, z)
|
||||
nodemap[node.GetId()] = node
|
||||
|
||||
logger.info("mobilitytrace opening '%s'", filename)
|
||||
|
||||
f = None
|
||||
try:
|
||||
f = open(filename)
|
||||
f.seek(0, 2)
|
||||
|
||||
sleep = 0.001
|
||||
kickstart = True
|
||||
while True:
|
||||
if self.state != EventTypes.RUNTIME_STATE.value:
|
||||
break
|
||||
line = f.readline()
|
||||
if not line:
|
||||
time.sleep(sleep)
|
||||
if sleep < 1.0:
|
||||
sleep += 0.001
|
||||
continue
|
||||
sleep = 0.001
|
||||
items = dict(map(lambda x: x.split('='), line.split()))
|
||||
logger.info("trace: %s %s %s", items['node'], items['pos'], items['vel'])
|
||||
x, y, z = map(float, items['pos'].split(':'))
|
||||
vel = map(float, items['vel'].split(':'))
|
||||
node = nodemap[int(items['node'])]
|
||||
net.mobility.addwaypoint(time=0, nodenum=node.objid,
|
||||
x=x, y=y, z=z, speed=vel)
|
||||
if kickstart:
|
||||
kickstart = False
|
||||
self.event_loop.add_event(0, net.mobility.start)
|
||||
self.event_loop.run()
|
||||
else:
|
||||
if net.mobility.state != net.mobility.STATE_RUNNING:
|
||||
net.mobility.state = net.mobility.STATE_RUNNING
|
||||
self.event_loop.add_event(0, net.mobility.runround)
|
||||
except IOError:
|
||||
logger.exception("mobilitytrace error opening '%s': %s", filename)
|
||||
finally:
|
||||
if f:
|
||||
f.close()
|
|
@ -1,101 +0,0 @@
|
|||
"""
|
||||
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
|
||||
"""
|
||||
|
||||
import optparse
|
||||
import sys
|
||||
|
||||
import ns.core
|
||||
import ns.mobility
|
||||
|
||||
from core import logger
|
||||
from core.misc import ipaddress
|
||||
from core.misc import nodemaps
|
||||
from core.misc import nodeutils
|
||||
from corens3.obj import Ns3LteNet
|
||||
from corens3.obj import Ns3Session
|
||||
|
||||
|
||||
def ltesession(opt):
|
||||
"""
|
||||
Run a test LTE session.
|
||||
"""
|
||||
nodeutils.set_node_map(nodemaps.NODES)
|
||||
session = Ns3Session(1, persistent=True, duration=opt.duration)
|
||||
lte = session.add_object(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 = 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
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Main routine when running from command-line.
|
||||
"""
|
||||
usagestr = "usage: %prog [-h] [options] [args]"
|
||||
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):
|
||||
sys.stdout.write("\n")
|
||||
if msg:
|
||||
sys.stdout.write(msg + "\n\n")
|
||||
parser.print_help()
|
||||
sys.exit(err)
|
||||
|
||||
opt, args = parser.parse_args()
|
||||
|
||||
if opt.numnodes < 2:
|
||||
usage("invalid numnodes: %s" % opt.numnodes)
|
||||
|
||||
for a in args:
|
||||
logger.warn("ignoring command line argument: '%s'", a)
|
||||
|
||||
return ltesession(opt)
|
||||
|
||||
|
||||
def cleanup():
|
||||
logger.info("shutting down session")
|
||||
session.shutdown()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
session = main()
|
|
@ -1,115 +0,0 @@
|
|||
"""
|
||||
ns3wifi.py - This script demonstrates using CORE with the ns-3 Wifi model.
|
||||
|
||||
How to run this:
|
||||
|
||||
pushd ~/ns-allinone-3.16/ns-3.16
|
||||
sudo ./waf shell
|
||||
popd
|
||||
python -i ns3wifi.py
|
||||
|
||||
To run with the CORE GUI:
|
||||
|
||||
pushd ~/ns-allinone-3.16/ns-3.16
|
||||
sudo ./waf shell
|
||||
core-daemon
|
||||
|
||||
# in another terminal
|
||||
core-daemon -e ./ns3wifi.py
|
||||
# in a third terminal
|
||||
core-gui
|
||||
# now select the running session
|
||||
|
||||
"""
|
||||
|
||||
import optparse
|
||||
import sys
|
||||
|
||||
import ns.core
|
||||
|
||||
from core import logger
|
||||
from core.misc import ipaddress
|
||||
from core.misc import nodeutils
|
||||
from core.misc import nodemaps
|
||||
from corens3.obj import Ns3Session
|
||||
from corens3.obj import Ns3WifiNet
|
||||
|
||||
|
||||
def add_to_server(session):
|
||||
"""
|
||||
Add this session to the server's list if this script is executed from
|
||||
the core-daemon server.
|
||||
"""
|
||||
global server
|
||||
try:
|
||||
server.add_session(session)
|
||||
return True
|
||||
except NameError:
|
||||
return False
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Main routine when running from command-line.
|
||||
"""
|
||||
usagestr = "usage: %prog [-h] [options] [args]"
|
||||
parser = optparse.OptionParser(usage=usagestr)
|
||||
parser.set_defaults(numnodes=10, duration=600, verbose=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("-v", "--verbose", dest="verbose",
|
||||
action="store_true", help="be more verbose")
|
||||
|
||||
def usage(msg=None, err=0):
|
||||
sys.stdout.write("\n")
|
||||
if msg:
|
||||
sys.stdout.write(msg + "\n\n")
|
||||
parser.print_help()
|
||||
sys.exit(err)
|
||||
|
||||
opt, args = parser.parse_args()
|
||||
|
||||
if opt.numnodes < 2:
|
||||
usage("invalid numnodes: %s" % opt.numnodes)
|
||||
|
||||
for a in args:
|
||||
logger.warn("ignoring command line argument: '%s'", a)
|
||||
|
||||
return wifisession(opt)
|
||||
|
||||
|
||||
if __name__ == "__main__" or __name__ == "__builtin__":
|
||||
session = main()
|
||||
logger.info("\nsession =%s", session)
|
|
@ -1,119 +0,0 @@
|
|||
"""
|
||||
ns3wifirandomwalk.py - This script demonstrates using CORE with the ns-3 Wifi
|
||||
model and random walk mobility.
|
||||
Patterned after the ns-3 example 'main-random-walk.cc'.
|
||||
|
||||
How to run this:
|
||||
|
||||
pushd ~/ns-allinone-3.16/ns-3.16
|
||||
sudo ./waf shell
|
||||
popd
|
||||
python -i ns3wifirandomwalk.py
|
||||
"""
|
||||
|
||||
import optparse
|
||||
import sys
|
||||
|
||||
import ns.core
|
||||
import ns.network
|
||||
|
||||
from core import logger
|
||||
from core.misc import ipaddress
|
||||
from core.misc import nodemaps
|
||||
from core.misc import nodeutils
|
||||
from corens3.obj import Ns3Session
|
||||
from corens3.obj import Ns3WifiNet
|
||||
|
||||
|
||||
def add_to_server(session):
|
||||
"""
|
||||
Add this session to the server's list if this script is executed from
|
||||
the core-daemon server.
|
||||
"""
|
||||
global server
|
||||
try:
|
||||
server.add_session(session)
|
||||
return True
|
||||
except NameError:
|
||||
return False
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Main routine when running from command-line.
|
||||
"""
|
||||
usagestr = "usage: %prog [-h] [options] [args]"
|
||||
parser = optparse.OptionParser(usage=usagestr)
|
||||
parser.set_defaults(numnodes=5, duration=600, verbose=False, viz=False)
|
||||
opt = {'numnodes': 5, 'duration': 600, 'verbose': False, 'viz': 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("-v", "--verbose", dest="verbose",
|
||||
action="store_true", help="be more verbose")
|
||||
parser.add_option("-V", "--visualize", dest="viz",
|
||||
action="store_true", help="enable PyViz ns-3 visualizer")
|
||||
|
||||
def usage(msg=None, err=0):
|
||||
sys.stdout.write("\n")
|
||||
if msg:
|
||||
sys.stdout.write(msg + "\n\n")
|
||||
parser.print_help()
|
||||
sys.exit(err)
|
||||
|
||||
opt, args = parser.parse_args()
|
||||
|
||||
if opt.numnodes < 2:
|
||||
usage("invalid numnodes: %s" % opt.numnodes)
|
||||
|
||||
for a in args:
|
||||
logger.warn("ignoring command line argument: '%s'", a)
|
||||
|
||||
return wifisession(opt)
|
||||
|
||||
|
||||
if __name__ == "__main__" or __name__ == "__builtin__":
|
||||
session = main()
|
||||
logger.info("\nsession =%s", session)
|
|
@ -1,85 +0,0 @@
|
|||
"""
|
||||
ns3wimax.py - This script demonstrates using CORE with the ns-3 Wimax model.
|
||||
*** Note that this script is not currently functional, see notes below. ***
|
||||
Current issues:
|
||||
- large amount of base station chatter; huge trace files, 70% CPU usage
|
||||
- PCAP files unreadable
|
||||
- base station causes segfault if it sends packet; due to missing service flows
|
||||
(but AddFlow() is not available for bs devices)
|
||||
- no packets are sent between nodes - no connection?
|
||||
"""
|
||||
|
||||
import optparse
|
||||
import sys
|
||||
|
||||
from core import logger
|
||||
from core.misc import ipaddress
|
||||
from core.misc import nodemaps
|
||||
from core.misc import nodeutils
|
||||
from corens3.obj import Ns3Session
|
||||
from corens3.obj import Ns3WimaxNet
|
||||
|
||||
|
||||
def wimaxsession(opt):
|
||||
"""
|
||||
Run a test wimax session.
|
||||
"""
|
||||
nodeutils.set_node_map(nodemaps.NODES)
|
||||
session = Ns3Session(1, persistent=True, duration=opt.duration)
|
||||
wimax = session.add_object(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 xrange(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
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Main routine when running from command-line.
|
||||
"""
|
||||
usagestr = "usage: %prog [-h] [options] [args]"
|
||||
parser = optparse.OptionParser(usage=usagestr)
|
||||
parser.set_defaults(numnodes=3, duration=600, verbose=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("-v", "--verbose", dest="verbose",
|
||||
action="store_true", help="be more verbose")
|
||||
|
||||
def usage(msg=None, err=0):
|
||||
sys.stdout.write("\n")
|
||||
if msg:
|
||||
sys.stdout.write(msg + "\n\n")
|
||||
parser.print_help()
|
||||
sys.exit(err)
|
||||
|
||||
opt, args = parser.parse_args()
|
||||
|
||||
if opt.numnodes < 2:
|
||||
usage("invalid numnodes: %s" % opt.numnodes)
|
||||
|
||||
for a in args:
|
||||
logger.warn("ignoring command line argument: '%s'", a)
|
||||
|
||||
return wimaxsession(opt)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
session = main()
|
|
@ -1,15 +0,0 @@
|
|||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name="core-ns3",
|
||||
version="5.0",
|
||||
packages=[
|
||||
"corens3",
|
||||
],
|
||||
description="Python ns-3 components of CORE",
|
||||
url="http://www.nrl.navy.mil/itd/ncs/products/core",
|
||||
author="Boeing Research & Technology",
|
||||
author_email="core-dev@nrl.navy.mil",
|
||||
license="GPLv2",
|
||||
long_description="Python scripts and modules for building virtual simulated networks."
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue