author | Tom Henderson <tomh@tomh.org> |
Fri, 04 Sep 2009 17:23:34 -0700 | |
changeset 4755 | 04a9a7e9a624 |
parent 4568 | 8a9c81e59c92 |
child 5426 | 7b36d173c490 |
permissions | -rw-r--r-- |
3978
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1 |
@node Emulation |
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
2 |
@chapter Emulation |
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
3 |
@anchor{chap:Emulation} |
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
4 |
|
3979
dee10444d76e
some words about emulation
Craig Dowell <craigdo@ee.washington.edu>
parents:
3978
diff
changeset
|
5 |
ns-3 has been designed for integration into testbed and virtual machine |
3987
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
6 |
environments. We have addressed this need by providing two kinds of |
4411 | 7 |
net devices. The first kind, which we call an @code{Emu} @code{NetDevice} |
3987
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
8 |
allows ns-3 simulations to send data on a ``real'' network. The second kind, |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
9 |
called a @code{Tap} @code{NetDevice} allows a ``real'' host to participate |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
10 |
in an ns-3 simulation as if it were one of the simulated nodes. An ns-3 |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
11 |
simulation may be constructed with any combination of simulated, @code{Emu}, |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
12 |
or @code{Tap} devices. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
13 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
14 |
One of the use-cases we want to support is that of a testbed. A concrete |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
15 |
example of an environment of this kind is the ORBIT testbed. ORBIT is a |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
16 |
laboratory emulator/field trial network arranged as a two dimensional grid of |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
17 |
400 802.11 radio nodes. We integrate with ORBIT by using their ``imaging'' |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
18 |
process to load and run ns-3 simulations on the ORBIT array. We use our |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
19 |
@code{Emu} @code{NetDevice}s to drive the hardware in the testbed and we can |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
20 |
accumulate results either using the ns-3 tracing and logging functions, or the |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
21 |
native ORBIT data gathering techniques. See @uref{http://www.orbit-lab.org/} |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
22 |
for details on the ORBIT testbed. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
23 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
24 |
A simulation of this kind is shown in the following figure: |
3978
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
25 |
|
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
26 |
@float Figure,fig:testbed |
3987
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
27 |
@center @caption{Example Implementation of Testbed Emulation.} |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
28 |
@center @image{figures/testbed, 5in} |
3978
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
29 |
@end float |
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
30 |
|
3987
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
31 |
You can see that there are separate hosts, each running a subset of a ``global'' |
3979
dee10444d76e
some words about emulation
Craig Dowell <craigdo@ee.washington.edu>
parents:
3978
diff
changeset
|
32 |
simulation. Instead of an ns-3 channel connecting the hosts, we use real |
dee10444d76e
some words about emulation
Craig Dowell <craigdo@ee.washington.edu>
parents:
3978
diff
changeset
|
33 |
hardware provided by the testbed. This allows ns-3 applications and protocol |
dee10444d76e
some words about emulation
Craig Dowell <craigdo@ee.washington.edu>
parents:
3978
diff
changeset
|
34 |
stacks attached to a simulation node to communicate over real hardware. |
dee10444d76e
some words about emulation
Craig Dowell <craigdo@ee.washington.edu>
parents:
3978
diff
changeset
|
35 |
|
3987
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
36 |
We expect the primary use for this configuration will be to generate repeatable |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
37 |
experimental results in a real-world network environment that includes all of |
4755
04a9a7e9a624
Manual spelling fixes from Johannes Buchner
Tom Henderson <tomh@tomh.org>
parents:
4568
diff
changeset
|
38 |
the ns-3 tracing, logging, visualization and statistics gathering tools. |
3979
dee10444d76e
some words about emulation
Craig Dowell <craigdo@ee.washington.edu>
parents:
3978
diff
changeset
|
39 |
|
3987
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
40 |
In what can be viewed as essentially an inverse configuration, we allow ``real'' |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
41 |
machines running native applications and protocol stacks to integrate with |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
42 |
an ns-3 simulation. This allows for the simulation of large networks connected |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
43 |
to a real mahince, and also enables virtualization. A simulation of this kind |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
44 |
is shown in the following figure: |
3979
dee10444d76e
some words about emulation
Craig Dowell <craigdo@ee.washington.edu>
parents:
3978
diff
changeset
|
45 |
|
3978
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
46 |
@float Figure,fig:emulated-channel |
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
47 |
@caption{Implementation overview of emulated channel.} |
3987
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
48 |
@image{figures/emulated-channel, 5in} |
3978
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
49 |
@end float |
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
50 |
|
3987
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
51 |
Here, you will see that there is a single host with a number of virtual machines |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
52 |
running on it. An ns-3 simulation is shown running in the virtual machine shown |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
53 |
in the center of the figure. This simulation has a number of nodes with associated |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
54 |
ns-3 applications and protocol stacks that are talking to an ns-3 channel through |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
55 |
native simulated ns-3 net devices. |
3979
dee10444d76e
some words about emulation
Craig Dowell <craigdo@ee.washington.edu>
parents:
3978
diff
changeset
|
56 |
|
dee10444d76e
some words about emulation
Craig Dowell <craigdo@ee.washington.edu>
parents:
3978
diff
changeset
|
57 |
There are also two virtual machines shown at the far left and far right of the |
3987
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
58 |
figure. These VMs are running native (Linux) applications and protocol stacks. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
59 |
The VM is connected into the simulation by a Linux Tap net device. The user-mode |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
60 |
handler for the Tap device is instantiated in the simulation and attached to a |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
61 |
proxy node that represents the native VM in the simulation. These handlers allow |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
62 |
the Tap devices on the native VMs to behave as if they were ns-3 net devices in |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
63 |
the simulation VM. This, in turn, allows the native software and protocol suites |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
64 |
in the native VMs to believe that they are connected to the simulated ns-3 |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
65 |
channel. |
3979
dee10444d76e
some words about emulation
Craig Dowell <craigdo@ee.washington.edu>
parents:
3978
diff
changeset
|
66 |
|
dee10444d76e
some words about emulation
Craig Dowell <craigdo@ee.washington.edu>
parents:
3978
diff
changeset
|
67 |
We expect the typical use case for this environment will be to analyze the |
dee10444d76e
some words about emulation
Craig Dowell <craigdo@ee.washington.edu>
parents:
3978
diff
changeset
|
68 |
behavior of native applications and protocol suites in the presence of large |
3987
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
69 |
simulated ns-3 networks. |
3979
dee10444d76e
some words about emulation
Craig Dowell <craigdo@ee.washington.edu>
parents:
3978
diff
changeset
|
70 |
|
3978
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
71 |
@section Behavior |
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
72 |
|
3987
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
73 |
@subsection Emu Net Device |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
74 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
75 |
The @code{Emu} net device allows a simulation node to send and receive packets |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
76 |
over a real network. The emulated net device relies on a specified interface |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
77 |
being in promiscuous mode. It opens a raw socket and binds to that interface. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
78 |
We perform MAC spoofing to separate simulation network traffic from other |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
79 |
network traffic that may be flowing to and from the host. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
80 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
81 |
Normally, the use case for emulated net devices is in collections of small |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
82 |
simulations that connect to the outside world through specific interfaces. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
83 |
For example, one could construct a number of virtual machines and connect them |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
84 |
via a host-only network. To use the emulated net device, you would need to |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
85 |
set all of the host-only interfaces in promiscuous mode and provide an |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
86 |
appropriate device name, "eth1" for example. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
87 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
88 |
One could also use the @code{Emu} net device in a testbed situation where the |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
89 |
host on which the simulation is running has a specific interface of interest |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
90 |
which drives the testbed hardware. You would also need to set this specific |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
91 |
interface into promiscuous mode and provide an appropriate device name to the |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
92 |
ns-3 emulated net device. An example of this environment is the ORBIT testbed |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
93 |
as described above. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
94 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
95 |
The @code{Emu} net device only works if the underlying interface is up and in |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
96 |
promiscuous mode. Packets will be sent out over the device, but we use MAC |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
97 |
spoofing. The MAC addresses will be generated (by default) using the |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
98 |
Organizationally Unique Identifier (OUI) 00:00:00 as a base. This vendor code |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
99 |
is not assigned to any organization and so should not conflict with any real |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
100 |
hardware. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
101 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
102 |
It is always up to the user to determine that using these MAC addresses is |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
103 |
okay on your network and won't conflict with anything else (including another |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
104 |
simulation using @code{Emu} devices) on your network. If you are using the |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
105 |
emulated net device in separate simulations you must consider global MAC |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
106 |
address assignment issues and ensure that MAC addresses are unique across |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
107 |
all simulations. The emulated net device respects the MAC address provided |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
108 |
in the @code{SetAddress} method so you can do this manually. For larger |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
109 |
simulations, you may want to set the OUI in the MAC address allocation function. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
110 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
111 |
IP addresses corresponding to the emulated net devices are the addresses |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
112 |
generated in the simulation, which are generated in the usual way via helper |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
113 |
functions. Since we are using MAC spoofing, there will not be a conflict |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
114 |
between ns-3 network stacks and any native network stacks. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
115 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
116 |
The emulated net device comes with a helper function as all ns-3 devices do. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
117 |
One unique aspect is that there is no channel associated with the underlying |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
118 |
medium. We really have no idea what this external medium is, and so have not |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
119 |
made an effort to model it abstractly. The primary thing to be aware of is the |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
120 |
implication this has for static global routing. The global router module |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
121 |
attempts to walk the channels looking for adjacent networks. Since there |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
122 |
is no channel, the global router will be unable to do this and you must then |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
123 |
use a dynamic routing protocol such as OLSR to include routing in |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
124 |
@code{Emu}-based networks. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
125 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
126 |
@subsection Tap Net Device |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
127 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
128 |
The @code{Tap} Net Device is scheduled for inclusion in ns-3.4 at the writing |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
129 |
of this section. We will include details as soon as the @code{Tap} device is |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
130 |
merged. |
3978
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
131 |
|
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
132 |
@section Usage |
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
133 |
|
4568
8a9c81e59c92
fix examples and documentation for CalcChecksum changes
Tom Henderson <tomh@tomh.org>
parents:
4411
diff
changeset
|
134 |
Any mixing of ns-3 objects with real objects will typically require that |
8a9c81e59c92
fix examples and documentation for CalcChecksum changes
Tom Henderson <tomh@tomh.org>
parents:
4411
diff
changeset
|
135 |
ns-3 compute checksums in its protocols. By default, checksums are not |
8a9c81e59c92
fix examples and documentation for CalcChecksum changes
Tom Henderson <tomh@tomh.org>
parents:
4411
diff
changeset
|
136 |
computed by ns-3. To enable checksums (e.g. UDP, TCP, IP), users must set |
8a9c81e59c92
fix examples and documentation for CalcChecksum changes
Tom Henderson <tomh@tomh.org>
parents:
4411
diff
changeset
|
137 |
the attribute @code{ChecksumEnabled} to true, such as follows: |
8a9c81e59c92
fix examples and documentation for CalcChecksum changes
Tom Henderson <tomh@tomh.org>
parents:
4411
diff
changeset
|
138 |
@verbatim |
8a9c81e59c92
fix examples and documentation for CalcChecksum changes
Tom Henderson <tomh@tomh.org>
parents:
4411
diff
changeset
|
139 |
GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true)); |
8a9c81e59c92
fix examples and documentation for CalcChecksum changes
Tom Henderson <tomh@tomh.org>
parents:
4411
diff
changeset
|
140 |
@end verbatim |
8a9c81e59c92
fix examples and documentation for CalcChecksum changes
Tom Henderson <tomh@tomh.org>
parents:
4411
diff
changeset
|
141 |
|
3987
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
142 |
@subsection Emu Net Device |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
143 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
144 |
The usage of the @code{Emu} net device is straightforward once the network of |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
145 |
simulations has been configured. Since most of the work involved in working |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
146 |
with this device is in network configuration before even starting a simulation, |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
147 |
you may want to take a moment to review a couple of HOWTO pages on the ns-3 wiki |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
148 |
that describe how to set up a virtual test network using VMware and how to run |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
149 |
a set of example (client server) simulations that use @code{Emu} net devices. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
150 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
151 |
@uref{http://www.nsnam.org/wiki/index.php/HOWTO_use_VMware_to_set_up_virtual_networks_(Windows)} |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
152 |
@uref{http://www.nsnam.org/wiki/index.php/HOWTO_use_ns-3_scripts_to_drive_real_hardware_(experimental)} |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
153 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
154 |
Once you are over the configuration hurdle, the script changes required to use |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
155 |
an @code{Emu} device are trivial. The main structural difference is that you |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
156 |
will need to create an ns-3 simulation script for each node. In the case of |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
157 |
the HOWTOs above, there is one client script and one server script. The only |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
158 |
``challenge'' is to get the addresses set correctly. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
159 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
160 |
Just as with all other ns-3 net devices, we provide a helper class for the |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
161 |
@code{Emu} net device. The following code snippet illustrates how one would |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
162 |
declare an EmuHelper and use it to set the ``DeviceName'' attribute to ``eth1'' |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
163 |
and install @code{Emu} devices on a group of nodes. You would do this on both |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
164 |
the client and server side in the case of the HOWTO seen above. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
165 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
166 |
@verbatim |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
167 |
EmuHelper emu; |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
168 |
emu.SetAttribute ("DeviceName", StringValue ("eth1")); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
169 |
NetDeviceContainer d = emu.Install (n); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
170 |
@end verbatim |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
171 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
172 |
The only other change that may be required is to make sure that the address |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
173 |
spaces (MAC and IP) on the client and server simulations are compatible. First |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
174 |
the MAC address is set to a unique well-known value in both places (illustrated |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
175 |
here for one side). |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
176 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
177 |
@verbatim |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
178 |
// |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
179 |
// We've got the devices in place. Since we're using MAC address |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
180 |
// spoofing under the sheets, we need to make sure that the MAC addresses |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
181 |
// we have assigned to our devices are unique. Ns-3 will happily |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
182 |
// automatically assign the same MAC addresses to the devices in both halves |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
183 |
// of our two-script pair, so let's go ahead and just manually change them |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
184 |
// to something we ensure is unique. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
185 |
// |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
186 |
Ptr<NetDevice> nd = d.Get (0); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
187 |
Ptr<EmuNetDevice> ed = nd->GetObject<EmuNetDevice> (); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
188 |
ed->SetAddress ("00:00:00:00:00:02"); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
189 |
@end verbatim |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
190 |
|
4755
04a9a7e9a624
Manual spelling fixes from Johannes Buchner
Tom Henderson <tomh@tomh.org>
parents:
4568
diff
changeset
|
191 |
And then the IP address of the client or server is set in the usual way using |
3987
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
192 |
helpers. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
193 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
194 |
@verbatim |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
195 |
// |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
196 |
// We've got the "hardware" in place. Now we need to add IP addresses. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
197 |
// This is the server half of a two-script pair. We need to make sure |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
198 |
// that the addressing in both of these applications is consistent, so |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
199 |
// we use provide an initial address in both cases. Here, the client |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
200 |
// will reside on one machine running ns-3 with one node having ns-3 |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
201 |
// with IP address "10.1.1.2" and talk to a server script running in |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
202 |
// another ns-3 on another computer that has an ns-3 node with IP |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
203 |
// address "10.1.1.3" |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
204 |
// |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
205 |
Ipv4AddressHelper ipv4; |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
206 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0", "0.0.0.2"); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
207 |
Ipv4InterfaceContainer i = ipv4.Assign (d); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
208 |
@end verbatim |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
209 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
210 |
You will use application helpers to generate traffic exactly as you do in any |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
211 |
ns-3 simulation script. Note that the server address shown below in a snippet |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
212 |
from the client, must correspond to the IP address assigned to the server node |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
213 |
similarly to the snippet above. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
214 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
215 |
@verbatim |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
216 |
uint32_t packetSize = 1024; |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
217 |
uint32_t maxPacketCount = 2000; |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
218 |
Time interPacketInterval = Seconds (0.001); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
219 |
UdpEchoClientHelper client ("10.1.1.3", 9); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
220 |
client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount)); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
221 |
client.SetAttribute ("Interval", TimeValue (interPacketInterval)); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
222 |
client.SetAttribute ("PacketSize", UintegerValue (packetSize)); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
223 |
ApplicationContainer apps = client.Install (n.Get (0)); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
224 |
apps.Start (Seconds (1.0)); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
225 |
apps.Stop (Seconds (2.0)); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
226 |
@end verbatim |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
227 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
228 |
The @code{Emu} net device and helper provide access to ASCII and pcap tracing |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
229 |
functionality just as other ns-3 net devices to. You enable tracing similarly |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
230 |
to these other net devices: |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
231 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
232 |
@verbatim |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
233 |
EmuHelper::EnablePcapAll ("emu-udp-echo-client"); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
234 |
@end verbatim |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
235 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
236 |
To see an example of a client script using the @code{Emu} net device, see |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
237 |
@code{examples/emu-udp-echo-client.cc} and @code{examples/emu-udp-echo-server.cc} |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
238 |
in the repository @uref{http://code.nsnam.org/craigdo/ns-3-emu/}. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
239 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
240 |
@subsection Tap Net Device |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
241 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
242 |
The @code{Tap} Net Device is scheduled for inclusion in ns-3.4 at the writing |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
243 |
of this section. We will include details as soon as the @code{Tap} device is |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
244 |
merged. |
3978
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
245 |
|
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
246 |
@section Implementation |
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
247 |
|
3987
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
248 |
Perhaps the most unusual part of the @code{Emu} and @code{Tap} device |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
249 |
implementation relates to the requirement for executing some of the code |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
250 |
with super-user permissions. Rather than force the user to execute the entire |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
251 |
simulation as root, we provide a small ``creator'' program that runs as root |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
252 |
and does any required high-permission sockets work. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
253 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
254 |
We do a similar thing for both the @code{Emu} and the @code{Tap} devices. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
255 |
The high-level view is that the @code{CreateSocket} method creates a local |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
256 |
interprocess (Unix) socket, forks, and executes the small creation program. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
257 |
The small program, which runs as suid root, creates a raw socket and sends |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
258 |
back the raw socket file descriptor over the Unix socket that is passed to |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
259 |
it as a parameter. The raw socket is passed as a control message (sometimes |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
260 |
called ancillary data) of type SCM_RIGHTS. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
261 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
262 |
@subsection Emu Net Device |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
263 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
264 |
The @code{Emu} net device uses the ns-3 threading and multithreaded real-time |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
265 |
scheduler extensions. The interesting work in the @code{Emu} device is done |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
266 |
when the net device is started (@code{EmuNetDevice::StartDevice ()}). An |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
267 |
attribute (``Start'') provides a simulation time at which to spin up the |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
268 |
net device. At this specified time (which defaults to t=0), the socket |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
269 |
creation function is called and executes as described above. You may also |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
270 |
specify a time at which to stop the device using the ``Stop'' attribute. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
271 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
272 |
Once the (promiscuous mode) socket is created, we bind it to an interface name |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
273 |
also provided as an attribute (``DeviceName'') that is stored internally as |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
274 |
@code{m_deviceName}: |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
275 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
276 |
@verbatim |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
277 |
struct ifreq ifr; |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
278 |
bzero (&ifr, sizeof(ifr)); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
279 |
strncpy ((char *)ifr.ifr_name, m_deviceName.c_str (), IFNAMSIZ); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
280 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
281 |
int32_t rc = ioctl (m_sock, SIOCGIFINDEX, &ifr); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
282 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
283 |
struct sockaddr_ll ll; |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
284 |
bzero (&ll, sizeof(ll)); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
285 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
286 |
ll.sll_family = AF_PACKET; |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
287 |
ll.sll_ifindex = m_sll_ifindex; |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
288 |
ll.sll_protocol = htons(ETH_P_ALL); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
289 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
290 |
rc = bind (m_sock, (struct sockaddr *)&ll, sizeof (ll)); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
291 |
@end verbatim |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
292 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
293 |
After the promiscuous raw socket is set up, a separate thread is spawned to do |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
294 |
reads from that socket and the link state is set to @code{Up}. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
295 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
296 |
@verbatim |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
297 |
m_readThread = Create<SystemThread> ( |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
298 |
MakeCallback (&EmuNetDevice::ReadThread, this)); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
299 |
m_readThread->Start (); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
300 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
301 |
NotifyLinkUp (); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
302 |
@end verbatim |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
303 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
304 |
The @code{EmuNetDevice::ReadThread} function basically just sits in an infinite |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
305 |
loop reading from the promiscuous mode raw socket and scheduling packet |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
306 |
receptions using the real-time simulator extensions. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
307 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
308 |
@verbatim |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
309 |
for (;;) |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
310 |
{ |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
311 |
... |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
312 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
313 |
len = recvfrom (m_sock, buf, bufferSize, 0, (struct sockaddr *)&addr, |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
314 |
&addrSize); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
315 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
316 |
... |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
317 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
318 |
DynamicCast<RealtimeSimulatorImpl> (Simulator::GetImplementation ())-> |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
319 |
ScheduleRealtimeNow ( |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
320 |
MakeEvent (&EmuNetDevice::ForwardUp, this, buf, len)); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
321 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
322 |
... |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
323 |
} |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
324 |
@end verbatim |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
325 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
326 |
The line starting with our templated DynamicCast function probably deserves a |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
327 |
comment. It gains access to the simulator implementation object using |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
328 |
the @code{Simulator::GetImplementation} method and then casts to the real-time |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
329 |
simulator implementation to use the real-time schedule method |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
330 |
@code{ScheduleRealtimeNow}. This function will cause a handler for the newly |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
331 |
received packet to be scheduled for execution at the current real time clock |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
332 |
value. This will, in turn cause the simulation clock to be advanced to that |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
333 |
real time value when the scheduled event (@code{EmuNetDevice::ForwardUp}) is |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
334 |
fired. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
335 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
336 |
The @code{ForwardUp} function operates as most other similar ns-3 net device |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
337 |
methods do. The packet is first filtered based on the destination address. In |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
338 |
the case of the @code{Emu} device, the MAC destination address will be the |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
339 |
address of the @code{Emu} device and not the hardware address of the real |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
340 |
device. Headers are then stripped off and the trace hooks are hit. Finally, |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
341 |
the packet is passed up the ns-3 protocol stack using the receive callback |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
342 |
function of the net device. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
343 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
344 |
Sending a packet is equally straightforward as shown below. The first thing |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
345 |
we do is to add the ethernet header and trailer to the ns-3 @code{Packet} we |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
346 |
are sending. The source address corresponds to the address of the @code{Emu} |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
347 |
device and not the underlying native device MAC address. This is where the |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
348 |
MAC address spoofing is done. The trailer is added and we enqueue and dequeue |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
349 |
the packet from the net device queue to hit the trace hooks. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
350 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
351 |
@verbatim |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
352 |
header.SetSource (source); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
353 |
header.SetDestination (destination); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
354 |
header.SetLengthType (packet->GetSize ()); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
355 |
packet->AddHeader (header); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
356 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
357 |
EthernetTrailer trailer; |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
358 |
trailer.CalcFcs (packet); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
359 |
packet->AddTrailer (trailer); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
360 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
361 |
m_queue->Enqueue (packet); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
362 |
packet = m_queue->Dequeue (); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
363 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
364 |
struct sockaddr_ll ll; |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
365 |
bzero (&ll, sizeof (ll)); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
366 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
367 |
ll.sll_family = AF_PACKET; |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
368 |
ll.sll_ifindex = m_sll_ifindex; |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
369 |
ll.sll_protocol = htons(ETH_P_ALL); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
370 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
371 |
rc = sendto (m_sock, packet->PeekData (), packet->GetSize (), 0, |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
372 |
reinterpret_cast<struct sockaddr *> (&ll), sizeof (ll)); |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
373 |
@end verbatim |
3978
e1e886e0edec
start of emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
374 |
|
3979
dee10444d76e
some words about emulation
Craig Dowell <craigdo@ee.washington.edu>
parents:
3978
diff
changeset
|
375 |
|
3987
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
376 |
Finally, we simply send the packet to the raw socket which puts it out on the |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
377 |
real network. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
378 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
379 |
@subsection Tap Net Device |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
380 |
|
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
381 |
The @code{Tap} Net Device is scheduled for inclusion in ns-3.4 at the writing |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
382 |
of this section. We will include details as soon as the @code{Tap} device is |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
383 |
merged. |
cfafbc337dbb
finish up a decent emulation chapter in manual
Craig Dowell <craigdo@ee.washington.edu>
parents:
3979
diff
changeset
|
384 |