removed ns3 related code
This commit is contained in:
parent
0a37a583ab
commit
4aeb16b866
18 changed files with 14 additions and 1574 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -54,7 +54,6 @@ coverage.xml
|
|||
# ignore built input files
|
||||
netns/setup.py
|
||||
daemon/setup.py
|
||||
ns3/setup.py
|
||||
|
||||
# ignore corefx build
|
||||
corefx/target
|
||||
|
|
|
@ -15,7 +15,7 @@ if WANT_DAEMON
|
|||
endif
|
||||
|
||||
if WANT_NETNS
|
||||
NETNS = netns ns3
|
||||
NETNS = netns
|
||||
endif
|
||||
|
||||
# keep docs last due to dependencies on binaries
|
||||
|
@ -185,7 +185,6 @@ change-files:
|
|||
$(call change-files,scripts/core-daemon.service)
|
||||
$(call change-files,scripts/core-daemon)
|
||||
$(call change-files,daemon/core/constants.py)
|
||||
$(call change-files,ns3/setup.py)
|
||||
$(call change-files,netns/setup.py)
|
||||
$(call change-files,daemon/setup.py)
|
||||
|
||||
|
|
|
@ -262,8 +262,7 @@ AC_CONFIG_FILES([Makefile
|
|||
daemon/doc/conf.py
|
||||
daemon/proto/Makefile
|
||||
netns/Makefile
|
||||
netns/version.h
|
||||
ns3/Makefile],)
|
||||
netns/version.h],)
|
||||
AC_OUTPUT
|
||||
|
||||
# Summary text
|
||||
|
|
|
@ -690,7 +690,7 @@ class WayPointMobility(WirelessModel):
|
|||
self.setnodeposition(node, x2, y2, z2)
|
||||
del self.points[node.id]
|
||||
return True
|
||||
# speed can be a velocity vector (ns3 mobility) or speed value
|
||||
# speed can be a velocity vector or speed value
|
||||
if isinstance(speed, (float, int)):
|
||||
# linear speed value
|
||||
alpha = math.atan2(y2 - y1, x2 - x1)
|
||||
|
|
|
@ -15,7 +15,6 @@ Current development focuses on the Python modules and daemon. Here is a brief de
|
|||
|gui|Tcl/Tk GUI|
|
||||
|man|Template files for creating man pages for various CORE command line utilities|
|
||||
|netns|Python C extension modules for creating CORE containers|
|
||||
|ns3|Experimental python ns3 script support for running CORE|
|
||||
|scripts|Template files used for running CORE as a service|
|
||||
|
||||
## Getting started
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
# Experimental Features
|
||||
|
||||
Below are current features that are considered experimental and will likely have issues.
|
||||
|
||||
# NS3
|
||||
|
||||
Experimental support for scripting CORE nodes with NS3.
|
||||
|
||||
[NS# Overview](ns3.md)
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
## Introduction
|
||||
|
||||
CORE (Common Open Research Emulator) is a tool for building virtual networks. As an emulator, CORE builds a
|
||||
representation of a real computer network that runs in real time, as opposed to simulation, where abstract models are
|
||||
used. The live-running emulation can be connected to physical networks and routers. It provides an environment for
|
||||
CORE (Common Open Research Emulator) is a tool for building virtual networks. As an emulator, CORE builds a
|
||||
representation of a real computer network that runs in real time, as opposed to simulation, where abstract models are
|
||||
used. The live-running emulation can be connected to physical networks and routers. It provides an environment for
|
||||
running real applications and protocols, taking advantage of virtualization provided by the Linux operating system.
|
||||
|
||||
CORE is typically used for network and protocol research, demonstrations, application and platform testing, evaluating
|
||||
CORE is typically used for network and protocol research, demonstrations, application and platform testing, evaluating
|
||||
networking scenarios, security studies, and increasing the size of physical test networks.
|
||||
|
||||
### Key Features
|
||||
|
@ -21,7 +21,7 @@ networking scenarios, security studies, and increasing the size of physical test
|
|||
| Topic | Description|
|
||||
|-------|------------|
|
||||
|[Architecture](architecture.md)|Overview of the architecture|
|
||||
|[Installation](install.md)|Installing from source, packages, & other dependencies|
|
||||
|[Installation](install.md)|Installing from source, packages, & other dependencies|
|
||||
|[Using the GUI](usage.md)|Details on the different node types and options in the GUI|
|
||||
|[Distributed](distributed.md)|Overview and detals for running CORE across multiple servers|
|
||||
|[Python Scripting](scripting.md)|How to write python scripts for creating a CORE session|
|
||||
|
@ -32,18 +32,17 @@ networking scenarios, security studies, and increasing the size of physical test
|
|||
|[EMANE](emane.md)|Overview of EMANE integration and integrating custom EMANE models|
|
||||
|[Performance](performance.md)|Notes on performance when using CORE|
|
||||
|[Developers Guide](devguide.md)|Overview of topics when developing CORE|
|
||||
|[Experimental](experimental.md)|Experimental features for use with or within CORE|
|
||||
|
||||
## Credits
|
||||
|
||||
The CORE project was derived from the open source IMUNES project from the University of Zagreb in 2004. In 2006,
|
||||
changes for CORE were released back to that project, some items of which were adopted. Marko Zec <zec@fer.hr> is the
|
||||
primary developer from the University of Zagreb responsible for the IMUNES (GUI) and VirtNet (kernel) projects. Ana
|
||||
The CORE project was derived from the open source IMUNES project from the University of Zagreb in 2004. In 2006,
|
||||
changes for CORE were released back to that project, some items of which were adopted. Marko Zec <zec@fer.hr> is the
|
||||
primary developer from the University of Zagreb responsible for the IMUNES (GUI) and VirtNet (kernel) projects. Ana
|
||||
Kukec and Miljenko Mikuc are known contributors.
|
||||
|
||||
Jeff Ahrenholz has been the primary Boeing developer of CORE, and has written this manual. Tom Goff designed the
|
||||
Python framework and has made significant contributions. Claudiu Danilov, Rod Santiago, Kevin Larson, Gary Pei,
|
||||
Phil Spagnolo, and Ian Chakeres have contributed code to CORE. Dan Mackley helped develop the CORE API, originally to
|
||||
Jeff Ahrenholz has been the primary Boeing developer of CORE, and has written this manual. Tom Goff designed the
|
||||
Python framework and has made significant contributions. Claudiu Danilov, Rod Santiago, Kevin Larson, Gary Pei,
|
||||
Phil Spagnolo, and Ian Chakeres have contributed code to CORE. Dan Mackley helped develop the CORE API, originally to
|
||||
interface with a simulator. Jae Kim and Tom Henderson have supervised the project and provided direction.
|
||||
|
||||
Copyright (c) 2005-2018, the Boeing Company.
|
||||
|
|
171
docs/ns3.md
171
docs/ns3.md
|
@ -1,171 +0,0 @@
|
|||
# CORE / NS3
|
||||
|
||||
* Table of Contents
|
||||
{:toc}
|
||||
|
||||
**NOTE: Support for ns-3 is limited and not currently being developed.**
|
||||
|
||||
## What is ns-3?
|
||||
|
||||
[ns-3 network simulator](http://www.nsnam.org) is a discrete-event network simulator for Internet systems, targeted primarily for research and educational use. By default, ns-3 simulates entire networks, from applications down to channels, and it does so in simulated time, instead of real (wall-clock) time.
|
||||
|
||||
CORE can run in conjunction with ns-3 to simulate some types of networks. CORE network namespace virtual nodes can have virtual TAP interfaces installed using the simulator for communication. The simulator needs to run at wall clock time with the real-time scheduler. In this type of configuration, the CORE namespaces are used to provide packets to the ns-3 devices and channels. This allows, for example, wireless models developed for ns-3 to be used in an emulation context.
|
||||
|
||||
Users simulate networks with ns-3 by writing C++ programs or Python scripts that import the ns-3 library. Simulation models are objects instantiated in these scripts. Combining the CORE Python modules with ns-3 Python bindings allow a script to easily set up and manage an emulation + simulation environment.
|
||||
|
||||
## ns-3 Scripting
|
||||
|
||||
Currently, ns-3 is supported by writing Python scripts, but not through drag-and-drop actions within the GUI. If you have a copy of the CORE source, look under *ns3/examples/* for example scripts; a CORE installation package puts these under */usr/share/core/examples/corens3*.
|
||||
|
||||
To run these scripts, install CORE so the CORE Python libraries are accessible, and download and build ns-3. This has been tested using ns-3 releases starting with 3.11 (and through 3.16 as of this writing).
|
||||
|
||||
The first step is to open an ns-3 waf shell. [waf](http://code.google.com/p/waf/) is the build system for ns-3. Opening a waf shell as root will merely set some environment variables useful for finding python modules and ns-3 executables. The following environment variables are extended or set by issuing *waf shell*:
|
||||
|
||||
```shell
|
||||
PATH
|
||||
PYTHONPATH
|
||||
LD_LIBRARY_PATH
|
||||
NS3_MODULE_PATH
|
||||
NS3_EXECUTABLE_PATH
|
||||
```
|
||||
|
||||
Open a waf shell as root, so that network namespaces may be instantiated by the script with root permissions. For an example, run the *ns3wifi.py* program, which simply instantiates 10 nodes (by default) and places them on an ns-3 WiFi channel. That is, the script will instantiate 10 namespace nodes, and create a special tap device that sends packets between the namespace node and a special ns-3 simulation node, where the tap device is bridged to an ns-3 WiFi network device, and attached to an ns-3 WiFi channel.
|
||||
|
||||
```shell
|
||||
cd ns-allinone-3.16/ns-3.16
|
||||
sudo ./waf shell
|
||||
# use '/usr/local' below if installed from source
|
||||
cd /usr/share/core/examples/corens3/
|
||||
```
|
||||
|
||||
```python
|
||||
python -i ns3wifi.py
|
||||
# running ns-3 simulation for 600 seconds
|
||||
print session
|
||||
<corens3.obj.Ns3Session object at 0x1963e50>
|
||||
```
|
||||
|
||||
The interactive Python shell allows some interaction with the Python objects for the emulation.
|
||||
|
||||
In another terminal, nodes can be accessed using *vcmd*:
|
||||
|
||||
```shell
|
||||
vcmd -c /tmp/pycore.10781/n1 -- bash
|
||||
root@n1:/tmp/pycore.10781/n1.conf#
|
||||
root@n1:/tmp/pycore.10781/n1.conf# ping 10.0.0.3
|
||||
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
|
||||
64 bytes from 10.0.0.3: icmp_req=1 ttl=64 time=7.99 ms
|
||||
64 bytes from 10.0.0.3: icmp_req=2 ttl=64 time=3.73 ms
|
||||
64 bytes from 10.0.0.3: icmp_req=3 ttl=64 time=3.60 ms
|
||||
^C
|
||||
--- 10.0.0.3 ping statistics ---
|
||||
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
|
||||
rtt min/avg/max/mdev = 3.603/5.111/7.993/2.038 ms
|
||||
root@n1:/tmp/pycore.10781/n1.conf#
|
||||
```
|
||||
|
||||
The ping packets shown above are traversing an ns-3 ad-hoc Wifi simulated network.
|
||||
|
||||
To clean up the session, use the Session.shutdown() method from the Python terminal.
|
||||
|
||||
```python
|
||||
print session
|
||||
<corens3.obj.Ns3Session object at 0x1963e50>
|
||||
session.shutdown()
|
||||
```
|
||||
|
||||
A CORE/ns-3 Python script will instantiate an Ns3Session, which is a CORE Session having CoreNs3Nodes, an ns-3 MobilityHelper, and a fixed duration. The CoreNs3Node inherits from both the CoreNode and the ns-3 Node classes -- it is a network namespace having an associated simulator object. The CORE TunTap interface is used, represented by a ns-3 TapBridge in *CONFIGURE_LOCAL* mode, where ns-3 creates and configures the tap device. An event is scheduled to install the taps at time 0.
|
||||
|
||||
**NOTE: The GUI can be used to run the *ns3wifi.py* and *ns3wifirandomwalk.py* scripts directly. First, *core-daemon* must be stopped and run within the waf root shell. Then the GUI may be run as a normal user, and the *Execute Python Script...* option may be used from the *File* menu. Dragging nodes around in the *ns3wifi.py* example will cause their ns-3 positions to be updated.**
|
||||
|
||||
Users may find the files *ns3wimax.py* and *ns3lte.py* in that example directory; those files were similarly configured, but the underlying ns-3 support is not present as of ns-3.16, so they will not work. Specifically, the ns-3 has to be extended to support bridging the Tap device to an LTE and a WiMax device.
|
||||
|
||||
## Integration details
|
||||
|
||||
The previous example *ns3wifi.py* used Python API from the special Python objects *Ns3Session* and *Ns3WifiNet*. The example program does not import anything directly from the ns-3 python modules; rather, only the above two objects are used, and the API available to configure the underlying ns-3 objects is constrained. For example, *Ns3WifiNet* instantiates a constant-rate 802.11a-based ad hoc network, using a lot of ns-3 defaults.
|
||||
|
||||
However, programs may be written with a blend of ns-3 API and CORE Python API calls. This section examines some of the fundamental objects in the CORE ns-3 support. Source code can be found in *ns3/corens3/obj.py* and example code in *ns3/corens3/examples/*.
|
||||
|
||||
## Ns3Session
|
||||
|
||||
The *Ns3Session* class is a CORE Session that starts an ns-3 simulation thread. ns-3 actually runs as a separate process on the same host as the CORE daemon, and the control of starting and stopping this process is performed by the *Ns3Session* class.
|
||||
|
||||
Example:
|
||||
|
||||
```python
|
||||
session = Ns3Session(persistent=True, duration=opt.duration)
|
||||
```
|
||||
|
||||
Note the use of the duration attribute to control how long the ns-3 simulation should run. By default, the duration is 600 seconds.
|
||||
|
||||
Typically, the session keeps track of the ns-3 nodes (holding a node container for references to the nodes). This is accomplished via the ```addnode()``` method, e.g.:
|
||||
|
||||
```python
|
||||
for i in xrange(1, opt.numnodes + 1):
|
||||
node = session.addnode(name = "n%d" % i)
|
||||
```
|
||||
|
||||
```addnode()``` creates instances of a *CoreNs3Node*, which we'll cover next.
|
||||
|
||||
## CoreNs3Node
|
||||
|
||||
A *CoreNs3Node* is both a CoreNode and an ns-3 node:
|
||||
|
||||
```python
|
||||
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.
|
||||
"""
|
||||
```
|
||||
|
||||
## CoreNs3Net
|
||||
|
||||
A *CoreNs3Net* derives from *PyCoreNet*. This network exists entirely in simulation, using the TunTap device to interact between the emulated and the simulated realm. *Ns3WifiNet* is a specialization of this.
|
||||
|
||||
As an example, this type of code would be typically used to add a WiFi network to a session:
|
||||
|
||||
```python
|
||||
wifi = session.addobj(cls=Ns3WifiNet, name="wlan1", rate="OfdmRate12Mbps")
|
||||
wifi.setposition(30, 30, 0)
|
||||
```
|
||||
|
||||
The above two lines will create a wlan1 object and set its initial canvas position. Later in the code, the newnetif method of the CoreNs3Node can be used to add interfaces on particular nodes to this network; e.g.:
|
||||
|
||||
```python
|
||||
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)])
|
||||
```
|
||||
|
||||
## Mobility
|
||||
|
||||
Mobility in ns-3 is handled by an object (a MobilityModel) aggregated to an ns-3 node. The MobilityModel is able to report the position of the object in the ns-3 space. This is a slightly different model from, for instance, EMANE, where location is associated with an interface, and the CORE GUI, where mobility is configured by right-clicking on a WiFi cloud.
|
||||
|
||||
The CORE GUI supports the ability to render the underlying ns-3 mobility model, if one is configured, on the CORE canvas. For example, the example program :file:`ns3wifirandomwalk.py` uses five nodes (by default) in a random walk mobility model. This can be executed by starting the core daemon from an ns-3 waf shell:
|
||||
|
||||
```shell
|
||||
sudo bash
|
||||
cd /path/to/ns-3
|
||||
./waf shell
|
||||
core-daemon
|
||||
```
|
||||
|
||||
and in a separate window, starting the CORE GUI (not from a waf shell) and selecting the *Execute Python script...* option from the File menu, selecting the *ns3wifirandomwalk.py* script.
|
||||
|
||||
The program invokes ns-3 mobility through the following statement:
|
||||
|
||||
```python
|
||||
session.setuprandomwalkmobility(bounds=(1000.0, 750.0, 0))
|
||||
```
|
||||
|
||||
This can be replaced by a different mode of mobility, in which nodes are placed according to a constant mobility model, and a special API call to the CoreNs3Net object is made to use the CORE canvas positions.
|
||||
|
||||
```python
|
||||
session.setuprandomwalkmobility(bounds=(1000.0, 750.0, 0))
|
||||
session.setupconstantmobility()
|
||||
wifi.usecorepositions()
|
||||
```
|
||||
|
||||
In this mode, the user dragging around the nodes on the canvas will cause CORE to update the position of the underlying ns-3 nodes.
|
1
ns3/.gitignore
vendored
1
ns3/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
build
|
339
ns3/LICENSE
339
ns3/LICENSE
|
@ -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,53 +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.
|
||||
#
|
||||
|
||||
if WANT_PYTHON
|
||||
|
||||
SETUPPY = setup.py
|
||||
SETUPPYFLAGS = -v
|
||||
|
||||
# Python package build
|
||||
noinst_SCRIPTS = build
|
||||
build:
|
||||
$(PYTHON) $(SETUPPY) $(SETUPPYFLAGS) build
|
||||
|
||||
# Python package install
|
||||
install-exec-hook:
|
||||
$(PYTHON) $(SETUPPY) $(SETUPPYFLAGS) install \
|
||||
--root=/$(DESTDIR) \
|
||||
--prefix=$(prefix) \
|
||||
--single-version-externally-managed \
|
||||
--no-compile
|
||||
|
||||
# Python package uninstall
|
||||
uninstall-hook:
|
||||
-rm -rf core_ns3.egg-info
|
||||
-rm -rf $(DESTDIR)/$(pythondir)/core_ns3-$(PACKAGE_VERSION)-py$(PYTHON_VERSION).egg-info
|
||||
-rm -rf $(DESTDIR)/$(pythondir)/corens3
|
||||
-rm -rf $(DESTDIR)/$(datadir)/corens3
|
||||
|
||||
# Python package cleanup
|
||||
clean-local:
|
||||
-rm -rf build
|
||||
|
||||
# because we include entire directories with EXTRA_DIST, we need to clean up
|
||||
# the source control files
|
||||
dist-hook:
|
||||
-rm -rf `find $(distdir)/ -name '*.pyc'`
|
||||
|
||||
distclean-local:
|
||||
-rm -rf core_ns3.egg-info
|
||||
|
||||
DISTCLEANFILES = Makefile.in
|
||||
|
||||
# files to include with distribution tarball
|
||||
EXTRA_DIST = LICENSE $(SETUPPY) corens3 examples
|
||||
|
||||
endif
|
||||
# endif WANT_PYTHON
|
|
@ -1,9 +0,0 @@
|
|||
"""
|
||||
corens3
|
||||
|
||||
Python package containing CORE components for use
|
||||
with the ns-3 simulator.
|
||||
|
||||
See http://code.google.com/p/coreemu/
|
||||
for more information on CORE.
|
||||
"""
|
|
@ -1,550 +0,0 @@
|
|||
"""
|
||||
ns3.py: defines classes for running emulations with ns-3 simulated networks.
|
||||
"""
|
||||
|
||||
import logging
|
||||
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.emulator.enumerations import EventTypes
|
||||
from core.emulator.enumerations import LinkTypes
|
||||
from core.emulator.enumerations import NodeTypes
|
||||
from core.utils import make_tuple
|
||||
from core.location.mobility import WayPointMobility
|
||||
from core.nodes.base import CoreNode, CoreNetworkBase
|
||||
from core.emulator.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
|
||||
_id = self.GetId() + 1
|
||||
if '_id' not in kwds:
|
||||
kwds['_id'] = _id
|
||||
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, ifname)
|
||||
self.attachnet(ifindex, net)
|
||||
netif = self.netif(ifindex)
|
||||
netif.sethwaddr(hwaddr)
|
||||
for addr in make_tuple(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(f"/{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
|
||||
mm.SetPosition(ns.core.Vector(x, y, z))
|
||||
except AttributeError:
|
||||
self.warn("ns-3 mobility model not found, not setting position")
|
||||
|
||||
|
||||
class CoreNs3Net(CoreNetworkBase):
|
||||
"""
|
||||
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, _id=None, name=None, start=True, server=None
|
||||
):
|
||||
CoreNetworkBase.__init__(self, session, _id, name, start, server)
|
||||
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):
|
||||
logging.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)
|
||||
logging.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, _id, persistent=False, duration=600):
|
||||
self.duration = duration
|
||||
self.nodes = ns.network.NodeContainer()
|
||||
self.mobhelper = ns.mobility.MobilityHelper()
|
||||
Session.__init__(self, _id)
|
||||
|
||||
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))
|
||||
logging.info("running ns-3 simulation for %d seconds", self.duration)
|
||||
if vis:
|
||||
try:
|
||||
import visualizer
|
||||
except ImportError:
|
||||
logging.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, 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.create_node(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)
|
||||
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.id, 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, _id=net.id)
|
||||
net.mobility.setendtime()
|
||||
net.mobility.refresh_ms = 300
|
||||
net.mobility.empty_queue_stop = False
|
||||
of = ns.network.OutputStreamWrapper(filename, filemode=0o777)
|
||||
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
|
||||
|
||||
logging.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(x.split("=") for x in line.split())
|
||||
logging.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.id, 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:
|
||||
logging.exception("mobilitytrace error opening: %s", filename)
|
||||
finally:
|
||||
if f:
|
||||
f.close()
|
|
@ -1,94 +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 logging
|
||||
import optparse
|
||||
import sys
|
||||
|
||||
import netaddr
|
||||
import ns.core
|
||||
import ns.mobility
|
||||
from corens3.obj import Ns3LteNet
|
||||
from corens3.obj import Ns3Session
|
||||
|
||||
|
||||
def ltesession(opt):
|
||||
"""
|
||||
Run a test LTE session.
|
||||
"""
|
||||
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 = netaddr.IPNetwork("10.0.0.0/16")
|
||||
mobb = None
|
||||
nodes = []
|
||||
for i in range(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[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:
|
||||
logging.warn("ignoring command line argument: '%s'", a)
|
||||
|
||||
return ltesession(opt)
|
||||
|
||||
|
||||
def cleanup():
|
||||
logging.info("shutting down session")
|
||||
session.shutdown()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
session = main()
|
|
@ -1,111 +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 logging
|
||||
import optparse
|
||||
import sys
|
||||
|
||||
import netaddr
|
||||
import ns.core
|
||||
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.
|
||||
"""
|
||||
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 = netaddr.IPNetwork("10.0.0.0/16")
|
||||
nodes = []
|
||||
for i in range(1, opt.numnodes + 1):
|
||||
node = session.addnode(name="n%d" % i)
|
||||
node.newnetif(wifi, ["%s/%s" % (prefix[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:
|
||||
logging.warn("ignoring command line argument: '%s'", a)
|
||||
|
||||
return wifisession(opt)
|
||||
|
||||
|
||||
if __name__ == "__main__" or __name__ == "__builtin__":
|
||||
session = main()
|
||||
logging.info("\nsession =%s", session)
|
|
@ -1,116 +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 logging
|
||||
import optparse
|
||||
import sys
|
||||
from builtins import range
|
||||
|
||||
import netaddr
|
||||
import ns.core
|
||||
import ns.network
|
||||
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.
|
||||
"""
|
||||
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 = netaddr.IPNetwork("10.0.0.0/16")
|
||||
services_str = "zebra|OSPFv3MDR|IPForward"
|
||||
nodes = []
|
||||
for i in range(1, opt.numnodes + 1):
|
||||
node = session.addnode(name="n%d" % i)
|
||||
node.newnetif(wifi, ["%s/%s" % (prefix[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
|
||||
|
||||
|
||||
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:
|
||||
logging.warn("ignoring command line argument: '%s'", a)
|
||||
|
||||
return wifisession(opt)
|
||||
|
||||
|
||||
if __name__ == "__main__" or __name__ == "__builtin__":
|
||||
session = main()
|
||||
logging.info("\nsession =%s", session)
|
|
@ -1,83 +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 logging
|
||||
import optparse
|
||||
import sys
|
||||
from builtins import range
|
||||
|
||||
import netaddr
|
||||
from corens3.obj import Ns3Session
|
||||
from corens3.obj import Ns3WimaxNet
|
||||
|
||||
|
||||
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 = netaddr.IPNetwork("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[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:
|
||||
logging.warn("ignoring command line argument: '%s'", a)
|
||||
|
||||
return wimaxsession(opt)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
session = main()
|
|
@ -1,19 +0,0 @@
|
|||
import glob
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
_EXAMPLES_DIR = "share/corens3/examples"
|
||||
|
||||
setup(
|
||||
name="core-ns3",
|
||||
version="@PACKAGE_VERSION@",
|
||||
packages=[
|
||||
"corens3",
|
||||
],
|
||||
data_files=[(_EXAMPLES_DIR, glob.glob("examples/*"))],
|
||||
description="Python ns-3 components of CORE",
|
||||
url="https://github.com/coreemu/core",
|
||||
author="Boeing Research & Technology",
|
||||
license="GPLv2",
|
||||
long_description="Python scripts and modules for building virtual simulated networks."
|
||||
)
|
Loading…
Reference in a new issue