author | Gustavo J. A. M. Carneiro <gjc@inescporto.pt> |
Fri, 03 Jul 2009 11:17:38 +0100 | |
changeset 4651 | 0f97d2edf425 |
parent 4616 | a84f60b6cd12 |
permissions | -rw-r--r-- |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
2 |
/* |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
3 |
* This program is free software; you can redistribute it and/or modify |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
4 |
* it under the terms of the GNU General Public License version 2 as |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
5 |
* published by the Free Software Foundation; |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
6 |
* |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
7 |
* This program is distributed in the hope that it will be useful, |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
10 |
* GNU General Public License for more details. |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
11 |
* |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
12 |
* You should have received a copy of the GNU General Public License |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
13 |
* along with this program; if not, write to the Free Software |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
15 |
* |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
16 |
* Based on simple-global-routing.cc |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
17 |
* ns-2 simple.tcl script (ported from ns-2) |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
18 |
* Originally authored by Steve McCanne, 12/19/1996 |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
19 |
*/ |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
20 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
21 |
// Network topology |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
22 |
// |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
23 |
// n0 |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
24 |
// \ 5 Mb/s, 2ms |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
25 |
// \ 1.5Mb/s, 10ms |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
26 |
// n2 -------------------------n3 |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
27 |
// / |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
28 |
// / 5 Mb/s, 2ms |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
29 |
// n1 |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
30 |
// |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
31 |
// - all links are point-to-point links with indicated one-way BW/delay |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
32 |
// - CBR/UDP flows from n0 to n3, and from n3 to n1 |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
33 |
// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec. |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
34 |
// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec. |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
35 |
// (i.e., DataRate of 448,000 bps) |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
36 |
// - DropTail queues |
4542
5644bae99850
cleanup virtual netdevice example
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4541
diff
changeset
|
37 |
// - Tracing of queues and packet receptions to file "virtual-net-device.tr" |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
38 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
39 |
// Tunneling changes (relative to the simple-global-routing example): |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
40 |
// n0 will receive an extra virtual interface with address 11.0.0.1 |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
41 |
// n1 will also receive an extra virtual interface with the same address 11.0.0.1 |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
42 |
// n3 will receive an extra virtual interface with address 11.0.0.254 |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
43 |
// The flows will be between 11.0.0.x (tunnel) addresses instead of 10.1.x.y ones |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
44 |
// n3 will decide, on a per-packet basis, via random number, whether to |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
45 |
// send the packet to n0 or to n1. |
4542
5644bae99850
cleanup virtual netdevice example
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4541
diff
changeset
|
46 |
// |
5644bae99850
cleanup virtual netdevice example
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4541
diff
changeset
|
47 |
// Note: here we create a tunnel where IP packets are tunneled over |
5644bae99850
cleanup virtual netdevice example
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4541
diff
changeset
|
48 |
// UDP/IP, but tunneling directly IP-over-IP would also be possible; |
5644bae99850
cleanup virtual netdevice example
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4541
diff
changeset
|
49 |
// see src/node/ipv4-raw-socket-factory.h. |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
50 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
51 |
#include <iostream> |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
52 |
#include <fstream> |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
53 |
#include <string> |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
54 |
#include <cassert> |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
55 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
56 |
#include "ns3/core-module.h" |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
57 |
#include "ns3/simulator-module.h" |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
58 |
#include "ns3/node-module.h" |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
59 |
#include "ns3/helper-module.h" |
4541
e943b94bf523
Rename TapNetDevice to VirtualNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4538
diff
changeset
|
60 |
#include "ns3/virtual-net-device.h" |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
61 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
62 |
using namespace ns3; |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
63 |
|
4541
e943b94bf523
Rename TapNetDevice to VirtualNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4538
diff
changeset
|
64 |
NS_LOG_COMPONENT_DEFINE ("VirtualNetDeviceExample"); |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
65 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
66 |
class Tunnel |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
67 |
{ |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
68 |
Ptr<Socket> m_n3Socket; |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
69 |
Ptr<Socket> m_n0Socket; |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
70 |
Ptr<Socket> m_n1Socket; |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
71 |
Ipv4Address m_n3Address; |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
72 |
Ipv4Address m_n0Address; |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
73 |
Ipv4Address m_n1Address; |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
74 |
UniformVariable m_rng; |
4541
e943b94bf523
Rename TapNetDevice to VirtualNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4538
diff
changeset
|
75 |
Ptr<VirtualNetDevice> m_n0Tap; |
e943b94bf523
Rename TapNetDevice to VirtualNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4538
diff
changeset
|
76 |
Ptr<VirtualNetDevice> m_n1Tap; |
e943b94bf523
Rename TapNetDevice to VirtualNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4538
diff
changeset
|
77 |
Ptr<VirtualNetDevice> m_n3Tap; |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
78 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
79 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
80 |
bool |
4651
0f97d2edf425
Fix the virtual-net-device.cc example; thanks Antti M?kel?.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4616
diff
changeset
|
81 |
N0VirtualSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber) |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
82 |
{ |
4651
0f97d2edf425
Fix the virtual-net-device.cc example; thanks Antti M?kel?.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4616
diff
changeset
|
83 |
m_n0Socket->SendTo (packet, 0, InetSocketAddress (m_n3Address, 667)); |
0f97d2edf425
Fix the virtual-net-device.cc example; thanks Antti M?kel?.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4616
diff
changeset
|
84 |
return true; |
0f97d2edf425
Fix the virtual-net-device.cc example; thanks Antti M?kel?.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4616
diff
changeset
|
85 |
} |
0f97d2edf425
Fix the virtual-net-device.cc example; thanks Antti M?kel?.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4616
diff
changeset
|
86 |
|
0f97d2edf425
Fix the virtual-net-device.cc example; thanks Antti M?kel?.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4616
diff
changeset
|
87 |
bool |
0f97d2edf425
Fix the virtual-net-device.cc example; thanks Antti M?kel?.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4616
diff
changeset
|
88 |
N1VirtualSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber) |
0f97d2edf425
Fix the virtual-net-device.cc example; thanks Antti M?kel?.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4616
diff
changeset
|
89 |
{ |
0f97d2edf425
Fix the virtual-net-device.cc example; thanks Antti M?kel?.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4616
diff
changeset
|
90 |
m_n1Socket->SendTo (packet, 0, InetSocketAddress (m_n3Address, 667)); |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
91 |
return true; |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
92 |
} |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
93 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
94 |
bool |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
95 |
N3VirtualSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber) |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
96 |
{ |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
97 |
if (m_rng.GetValue () < 0.25) |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
98 |
{ |
4651
0f97d2edf425
Fix the virtual-net-device.cc example; thanks Antti M?kel?.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4616
diff
changeset
|
99 |
m_n3Socket->SendTo (packet, 0, InetSocketAddress (m_n0Address, 667)); |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
100 |
} |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
101 |
else |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
102 |
{ |
4651
0f97d2edf425
Fix the virtual-net-device.cc example; thanks Antti M?kel?.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4616
diff
changeset
|
103 |
m_n3Socket->SendTo (packet, 0, InetSocketAddress (m_n1Address, 667)); |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
104 |
} |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
105 |
return true; |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
106 |
} |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
107 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
108 |
void N3SocketRecv (Ptr<Socket> socket) |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
109 |
{ |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
110 |
Ptr<Packet> packet = socket->Recv (65535, 0); |
4548
e883e2df59af
Don't remove all tags, only the SocketAddressTag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4547
diff
changeset
|
111 |
SocketAddressTag socketAddressTag; |
e883e2df59af
Don't remove all tags, only the SocketAddressTag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4547
diff
changeset
|
112 |
packet->RemovePacketTag (socketAddressTag); |
4545
8566a9f6725a
VirtualNetDevice: Single Receive() (promisc. one); add trace sources to align better with CsmaNetDevice. Add SetAddress()
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4542
diff
changeset
|
113 |
m_n3Tap->Receive (packet, 0x0800, m_n3Tap->GetAddress (), m_n3Tap->GetAddress (), NetDevice::PACKET_HOST); |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
114 |
} |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
115 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
116 |
void N0SocketRecv (Ptr<Socket> socket) |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
117 |
{ |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
118 |
Ptr<Packet> packet = socket->Recv (65535, 0); |
4548
e883e2df59af
Don't remove all tags, only the SocketAddressTag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4547
diff
changeset
|
119 |
SocketAddressTag socketAddressTag; |
e883e2df59af
Don't remove all tags, only the SocketAddressTag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4547
diff
changeset
|
120 |
packet->RemovePacketTag (socketAddressTag); |
4545
8566a9f6725a
VirtualNetDevice: Single Receive() (promisc. one); add trace sources to align better with CsmaNetDevice. Add SetAddress()
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4542
diff
changeset
|
121 |
m_n0Tap->Receive (packet, 0x0800, m_n0Tap->GetAddress (), m_n0Tap->GetAddress (), NetDevice::PACKET_HOST); |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
122 |
} |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
123 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
124 |
void N1SocketRecv (Ptr<Socket> socket) |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
125 |
{ |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
126 |
Ptr<Packet> packet = socket->Recv (65535, 0); |
4548
e883e2df59af
Don't remove all tags, only the SocketAddressTag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4547
diff
changeset
|
127 |
SocketAddressTag socketAddressTag; |
e883e2df59af
Don't remove all tags, only the SocketAddressTag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4547
diff
changeset
|
128 |
packet->RemovePacketTag (socketAddressTag); |
4545
8566a9f6725a
VirtualNetDevice: Single Receive() (promisc. one); add trace sources to align better with CsmaNetDevice. Add SetAddress()
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4542
diff
changeset
|
129 |
m_n1Tap->Receive (packet, 0x0800, m_n1Tap->GetAddress (), m_n1Tap->GetAddress (), NetDevice::PACKET_HOST); |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
130 |
} |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
131 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
132 |
public: |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
133 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
134 |
Tunnel (Ptr<Node> n3, Ptr<Node> n0, Ptr<Node> n1, |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
135 |
Ipv4Address n3Addr, Ipv4Address n0Addr, Ipv4Address n1Addr) |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
136 |
: m_n3Address (n3Addr), m_n0Address (n0Addr), m_n1Address (n1Addr) |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
137 |
{ |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
138 |
m_n3Socket = Socket::CreateSocket (n3, TypeId::LookupByName ("ns3::UdpSocketFactory")); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
139 |
m_n3Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
140 |
m_n3Socket->SetRecvCallback (MakeCallback (&Tunnel::N3SocketRecv, this)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
141 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
142 |
m_n0Socket = Socket::CreateSocket (n0, TypeId::LookupByName ("ns3::UdpSocketFactory")); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
143 |
m_n0Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
144 |
m_n0Socket->SetRecvCallback (MakeCallback (&Tunnel::N0SocketRecv, this)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
145 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
146 |
m_n1Socket = Socket::CreateSocket (n1, TypeId::LookupByName ("ns3::UdpSocketFactory")); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
147 |
m_n1Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
148 |
m_n1Socket->SetRecvCallback (MakeCallback (&Tunnel::N1SocketRecv, this)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
149 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
150 |
// n0 tap device |
4541
e943b94bf523
Rename TapNetDevice to VirtualNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4538
diff
changeset
|
151 |
m_n0Tap = CreateObject<VirtualNetDevice> (); |
4545
8566a9f6725a
VirtualNetDevice: Single Receive() (promisc. one); add trace sources to align better with CsmaNetDevice. Add SetAddress()
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4542
diff
changeset
|
152 |
m_n0Tap->SetAddress (Mac48Address ("11:00:01:02:03:01")); |
4651
0f97d2edf425
Fix the virtual-net-device.cc example; thanks Antti M?kel?.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4616
diff
changeset
|
153 |
m_n0Tap->SetSendCallback (MakeCallback (&Tunnel::N0VirtualSend, this)); |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
154 |
n0->AddDevice (m_n0Tap); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
155 |
Ptr<Ipv4> ipv4 = n0->GetObject<Ipv4> (); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
156 |
uint32_t i = ipv4->AddInterface (m_n0Tap); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
157 |
ipv4->AddAddress (i, Ipv4InterfaceAddress (Ipv4Address ("11.0.0.1"), Ipv4Mask ("255.255.255.0"))); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
158 |
ipv4->SetUp (i); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
159 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
160 |
// n1 tap device |
4541
e943b94bf523
Rename TapNetDevice to VirtualNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4538
diff
changeset
|
161 |
m_n1Tap = CreateObject<VirtualNetDevice> (); |
4545
8566a9f6725a
VirtualNetDevice: Single Receive() (promisc. one); add trace sources to align better with CsmaNetDevice. Add SetAddress()
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4542
diff
changeset
|
162 |
m_n1Tap->SetAddress (Mac48Address ("11:00:01:02:03:02")); |
4651
0f97d2edf425
Fix the virtual-net-device.cc example; thanks Antti M?kel?.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4616
diff
changeset
|
163 |
m_n1Tap->SetSendCallback (MakeCallback (&Tunnel::N1VirtualSend, this)); |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
164 |
n1->AddDevice (m_n1Tap); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
165 |
ipv4 = n1->GetObject<Ipv4> (); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
166 |
i = ipv4->AddInterface (m_n1Tap); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
167 |
ipv4->AddAddress (i, Ipv4InterfaceAddress (Ipv4Address ("11.0.0.1"), Ipv4Mask ("255.255.255.0"))); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
168 |
ipv4->SetUp (i); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
169 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
170 |
// n3 tap device |
4541
e943b94bf523
Rename TapNetDevice to VirtualNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4538
diff
changeset
|
171 |
m_n3Tap = CreateObject<VirtualNetDevice> (); |
4545
8566a9f6725a
VirtualNetDevice: Single Receive() (promisc. one); add trace sources to align better with CsmaNetDevice. Add SetAddress()
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4542
diff
changeset
|
172 |
m_n3Tap->SetAddress (Mac48Address ("11:00:01:02:03:04")); |
8566a9f6725a
VirtualNetDevice: Single Receive() (promisc. one); add trace sources to align better with CsmaNetDevice. Add SetAddress()
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4542
diff
changeset
|
173 |
m_n3Tap->SetSendCallback (MakeCallback (&Tunnel::N3VirtualSend, this)); |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
174 |
n3->AddDevice (m_n3Tap); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
175 |
ipv4 = n3->GetObject<Ipv4> (); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
176 |
i = ipv4->AddInterface (m_n3Tap); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
177 |
ipv4->AddAddress (i, Ipv4InterfaceAddress (Ipv4Address ("11.0.0.254"), Ipv4Mask ("255.255.255.0"))); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
178 |
ipv4->SetUp (i); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
179 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
180 |
} |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
181 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
182 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
183 |
}; |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
184 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
185 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
186 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
187 |
int |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
188 |
main (int argc, char *argv[]) |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
189 |
{ |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
190 |
// Users may find it convenient to turn on explicit debugging |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
191 |
// for selected modules; the below lines suggest how to do this |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
192 |
#if 0 |
4542
5644bae99850
cleanup virtual netdevice example
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4541
diff
changeset
|
193 |
LogComponentEnable ("VirtualNetDeviceExample", LOG_LEVEL_INFO); |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
194 |
#endif |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
195 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
196 |
// Set up some default values for the simulation. Use the |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
197 |
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
198 |
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s")); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
199 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
200 |
//DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
201 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
202 |
// Allow the user to override any of the defaults and the above |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
203 |
// DefaultValue::Bind ()s at run-time, via command-line arguments |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
204 |
CommandLine cmd; |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
205 |
cmd.Parse (argc, argv); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
206 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
207 |
// Here, we will explicitly create four nodes. In more sophisticated |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
208 |
// topologies, we could configure a node factory. |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
209 |
NS_LOG_INFO ("Create nodes."); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
210 |
NodeContainer c; |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
211 |
c.Create (4); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
212 |
NodeContainer n0n2 = NodeContainer (c.Get(0), c.Get (2)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
213 |
NodeContainer n1n2 = NodeContainer (c.Get(1), c.Get (2)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
214 |
NodeContainer n3n2 = NodeContainer (c.Get(3), c.Get (2)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
215 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
216 |
InternetStackHelper internet; |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
217 |
internet.Install (c); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
218 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
219 |
// We create the channels first without any IP addressing information |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
220 |
NS_LOG_INFO ("Create channels."); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
221 |
PointToPointHelper p2p; |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
222 |
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
223 |
p2p.SetChannelAttribute ("Delay", StringValue ("2ms")); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
224 |
NetDeviceContainer d0d2 = p2p.Install (n0n2); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
225 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
226 |
NetDeviceContainer d1d2 = p2p.Install (n1n2); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
227 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
228 |
p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps")); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
229 |
p2p.SetChannelAttribute ("Delay", StringValue ("10ms")); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
230 |
NetDeviceContainer d3d2 = p2p.Install (n3n2); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
231 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
232 |
// Later, we add IP addresses. |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
233 |
NS_LOG_INFO ("Assign IP Addresses."); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
234 |
Ipv4AddressHelper ipv4; |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
235 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
236 |
Ipv4InterfaceContainer i0i2 = ipv4.Assign (d0d2); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
237 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
238 |
ipv4.SetBase ("10.1.2.0", "255.255.255.0"); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
239 |
Ipv4InterfaceContainer i1i2 = ipv4.Assign (d1d2); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
240 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
241 |
ipv4.SetBase ("10.1.3.0", "255.255.255.0"); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
242 |
Ipv4InterfaceContainer i3i2 = ipv4.Assign (d3d2); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
243 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
244 |
// Create router nodes, initialize routing database and set up the routing |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
245 |
// tables in the nodes. |
4616
a84f60b6cd12
bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4548
diff
changeset
|
246 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
247 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
248 |
// Add the tunnels |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
249 |
Tunnel tunnel (c.Get (3), c.Get (0), c.Get (1), |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
250 |
i3i2.GetAddress (0), i0i2.GetAddress (0), i1i2.GetAddress (0)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
251 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
252 |
// Create the OnOff application to send UDP datagrams of size |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
253 |
// 210 bytes at a rate of 448 Kb/s |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
254 |
NS_LOG_INFO ("Create Applications."); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
255 |
uint16_t port = 9; // Discard port (RFC 863) |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
256 |
OnOffHelper onoff ("ns3::UdpSocketFactory", |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
257 |
Address (InetSocketAddress (Ipv4Address ("11.0.0.254"), port))); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
258 |
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
259 |
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
260 |
ApplicationContainer apps = onoff.Install (c.Get (0)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
261 |
apps.Start (Seconds (1.0)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
262 |
apps.Stop (Seconds (10.0)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
263 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
264 |
// Create a packet sink to receive these packets |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
265 |
PacketSinkHelper sink ("ns3::UdpSocketFactory", |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
266 |
Address (InetSocketAddress (Ipv4Address::GetAny (), port))); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
267 |
apps = sink.Install (c.Get (3)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
268 |
apps.Start (Seconds (1.0)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
269 |
apps.Stop (Seconds (10.0)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
270 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
271 |
// Create a similar flow from n3 to n1, starting at time 1.1 seconds |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
272 |
onoff.SetAttribute ("Remote", |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
273 |
AddressValue (InetSocketAddress (Ipv4Address ("11.0.0.2"), port))); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
274 |
apps = onoff.Install (c.Get (3)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
275 |
apps.Start (Seconds (1.1)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
276 |
apps.Stop (Seconds (10.0)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
277 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
278 |
// Create a packet sink to receive these packets |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
279 |
apps = sink.Install (c.Get (1)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
280 |
apps.Start (Seconds (1.1)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
281 |
apps.Stop (Seconds (10.0)); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
282 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
283 |
std::ofstream ascii; |
4542
5644bae99850
cleanup virtual netdevice example
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4541
diff
changeset
|
284 |
ascii.open ("virtual-net-device.tr"); |
5644bae99850
cleanup virtual netdevice example
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
4541
diff
changeset
|
285 |
PointToPointHelper::EnablePcapAll ("virtual-net-device"); |
4538
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
286 |
PointToPointHelper::EnableAsciiAll (ascii); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
287 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
288 |
NS_LOG_INFO ("Run Simulation."); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
289 |
Simulator::Run (); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
290 |
Simulator::Destroy (); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
291 |
NS_LOG_INFO ("Done."); |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
292 |
|
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
293 |
return 0; |
3048bd67e5cf
Add an example for TapNetDevice
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
294 |
} |