View | Details | Raw Unified | Return to bug 3026
Collapse All | Expand All

(-)79acdbc949f6 (+240 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 */
16
17
// Network topology
18
//
19
//
20
//        10.1.1.0/24    10.1.2.0/24
21
//
22
//     n0-------------n1--------------n2
23
//       ============================
24
//              Tunnel n0 <=> n2
25
//
26
// - The Tunnel class adds virtual interfaces to n0 and n2,
27
//   with inner tunnel IP adresses 11.0.0.1 (n0) and 11.0.0.2 (n2)
28
// - For n0 and n2 these interfaces behave like connected to a direct link (tunnel) to each other
29
// - n0 has installed an application sending UDP traffic to n2, via the tunnel, using inner-tunnel IP adresses
30
// - On a lower level, these interfaces use UDP sockets to encapsulate their packets and send them
31
//   via the regular Point-to-Point interface. However, n1 only sees a regular UDP packet.
32
//
33
// Note: here we create a tunnel where IP packets are tunneled over
34
// UDP/IP, but tunneling directly IP-over-IP would also be possible;
35
// see src/node/ipv4-raw-socket-factory.h.
36
37
38
39
#include <iostream>
40
#include <fstream>
41
#include <string>
42
#include <cassert>
43
44
#include "ns3/core-module.h"
45
#include "ns3/network-module.h"
46
#include "ns3/internet-module.h"
47
#include "ns3/point-to-point-module.h"
48
#include "ns3/applications-module.h"
49
#include "ns3/virtual-net-device.h"
50
#include "ns3/ipv4-global-routing-helper.h"
51
52
using namespace ns3;
53
54
NS_LOG_COMPONENT_DEFINE ("VirtualNetDeviceExample");
55
56
class Tunnel
57
{
58
  Ptr<Socket> m_n0Socket;
59
  Ptr<Socket> m_n2Socket;
60
  Ipv4Address m_n0Address;
61
  Ipv4Address m_n2Address;
62
  Ptr<VirtualNetDevice> m_n0Tap;
63
  Ptr<VirtualNetDevice> m_n2Tap;
64
65
66
  bool
67
  N0VirtualSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
68
  {
69
    NS_LOG_DEBUG ("Send to " << m_n2Address << ": " << *packet);
70
    m_n0Socket->SendTo (packet, 0, InetSocketAddress (m_n2Address, 667));
71
    return true;
72
  }
73
74
  bool
75
  N2VirtualSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
76
  {
77
    NS_LOG_DEBUG ("Send to " << m_n0Address << ": " << *packet);
78
    m_n2Socket->SendTo (packet, 0, InetSocketAddress (m_n0Address, 667));
79
    return true;
80
  }
81
82
  void N0SocketRecv (Ptr<Socket> socket)
83
  {
84
    Ptr<Packet> packet = socket->Recv (65535, 0);
85
    NS_LOG_DEBUG ("N0SocketRecv: " << *packet);
86
    m_n0Tap->Receive (packet, 0x0800, m_n0Tap->GetAddress (), m_n0Tap->GetAddress (), NetDevice::PACKET_HOST);
87
  }
88
89
  void N2SocketRecv (Ptr<Socket> socket)
90
  {
91
    Ptr<Packet> packet = socket->Recv (65535, 0);
92
    NS_LOG_DEBUG ("N1SocketRecv: " << *packet);
93
    m_n2Tap->Receive (packet, 0x0800, m_n2Tap->GetAddress (), m_n2Tap->GetAddress (), NetDevice::PACKET_HOST);
94
  }
95
96
public:
97
98
  Tunnel (Ptr<Node> n0, Ptr<Node> n2,
99
          Ipv4Address n0Addr, Ipv4Address n2Addr)
100
    : m_n0Address (n0Addr), m_n2Address (n2Addr)
101
  {
102
    m_n0Socket = Socket::CreateSocket (n0, TypeId::LookupByName ("ns3::UdpSocketFactory"));
103
    m_n0Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667));
104
    m_n0Socket->SetRecvCallback (MakeCallback (&Tunnel::N0SocketRecv, this));
105
106
    m_n2Socket = Socket::CreateSocket (n2, TypeId::LookupByName ("ns3::UdpSocketFactory"));
107
    m_n2Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667));
108
    m_n2Socket->SetRecvCallback (MakeCallback (&Tunnel::N2SocketRecv, this));
109
110
    // n0 tap device
111
    m_n0Tap = CreateObject<VirtualNetDevice> ();
112
    m_n0Tap->SetAddress (Mac48Address ("11:00:01:02:03:01"));
113
    m_n0Tap->SetSendCallback (MakeCallback (&Tunnel::N0VirtualSend, this));
114
    n0->AddDevice (m_n0Tap);
115
    Ptr<Ipv4> ipv4 = n0->GetObject<Ipv4> ();
116
    uint32_t interface_id = ipv4->AddInterface (m_n0Tap);
117
    ipv4->AddAddress (interface_id, Ipv4InterfaceAddress (Ipv4Address ("11.0.0.1"), Ipv4Mask ("255.255.255.0")));
118
    ipv4->SetUp (interface_id);
119
120
    // n2 tap device
121
    m_n2Tap = CreateObject<VirtualNetDevice> ();
122
    m_n2Tap->SetAddress (Mac48Address ("11:00:01:02:03:02"));
123
    m_n2Tap->SetSendCallback (MakeCallback (&Tunnel::N2VirtualSend, this));
124
    n2->AddDevice (m_n2Tap);
125
    ipv4 = n2->GetObject<Ipv4> ();
126
    interface_id = ipv4->AddInterface (m_n2Tap);
127
    ipv4->AddAddress (interface_id, Ipv4InterfaceAddress (Ipv4Address ("11.0.0.2"), Ipv4Mask ("255.255.255.0")));
128
    ipv4->SetUp (interface_id);
129
130
  }
131
132
133
};
134
135
136
137
int 
138
main (int argc, char *argv[])
139
{
140
  // Users may find it convenient to turn on explicit logging
141
  // for selected modules; the below lines suggest how to do this
142
#if 0 
143
  LogComponentEnable ("VirtualNetDeviceExample", LOG_LEVEL_INFO);
144
#endif
145
  Packet::EnablePrinting ();
146
147
  /* ::::     Step 1: Setup Config values ::::::*/
148
149
  // Set up some default values for the simulation.  Use the 
150
  Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
151
  Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
152
153
  // Allow the user to override any of the defaults via command-line arguments
154
  CommandLine cmd;
155
  cmd.Parse (argc, argv);
156
157
  /* ::::::     Step 2:  Setup nodes and Channels   :::::::     */
158
  NS_LOG_INFO ("Create nodes.");
159
  NodeContainer nodes;
160
  nodes.Create (3);
161
  NodeContainer n0n1 = NodeContainer (nodes.Get (0), nodes.Get (1));
162
  NodeContainer n1n2 = NodeContainer (nodes.Get (1), nodes.Get (2));
163
164
  InternetStackHelper internet;
165
  internet.Install (nodes);
166
167
  // We create the channels first without any IP addressing information
168
  NS_LOG_INFO ("Create channels.");
169
  PointToPointHelper p2p;
170
  p2p.SetDeviceAttribute ("DataRate", StringValue ("50Mbps"));
171
  p2p.SetChannelAttribute ("Delay", StringValue ("20ms"));
172
  NetDeviceContainer d0d1 = p2p.Install (n0n1);
173
  NetDeviceContainer d1d2 = p2p.Install (n1n2);
174
175
  /*    :::::   Step 3: Setup IP adresses and Routing   :::::: */
176
  NS_LOG_INFO ("Assign IP Addresses.");
177
  Ipv4AddressHelper ipv4;
178
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
179
  Ipv4InterfaceContainer i0i1 = ipv4.Assign (d0d1);
180
181
  ipv4.SetBase ("10.1.2.0", "255.255.255.0");
182
  Ipv4InterfaceContainer i1i2 = ipv4.Assign (d1d2);
183
184
  // Set up the routing tables in the nodes.
185
  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
186
187
  /*   ::::::: Step 4: Setup the tunnel      ::::::::: */
188
189
  Tunnel tunnel (nodes.Get (0), nodes.Get (2),
190
                 i0i1.GetAddress (0), i1i2.GetAddress (1));
191
192
  /*  ::::: Optional Step 4.5: For Using tunnel for a VPN or internet gateway: Setup routing tables   */
193
  // If you intend to simulate a VPN or internet gateway with this tunnel you need to adapt the routing tables:
194
  // 1. You have to add a route to the servers network via the tunnel to the "VPN client" tunnel side routing table
195
  // 2. You have to add a route to the "clients" network via the tunnel to the VPN server tunnel side routing table
196
197
  // The following is an rough example how to do this, of course your specifics may vary
198
199
  //  Ipv4StaticRoutingHelper ipv4RoutingHelper;
200
  //  Ptr<Ipv4> n0_IPv4_module = nodes.Get(0)->GetObject<Ipv4>();
201
  //  Ptr<Ipv4StaticRouting> n2_routing_table = ipv4RoutingHelper.GetStaticRouting(n0_IPv4_module);
202
  //  n2_routing_table->AddNetworkRouteTo( Ipv4Address("<Your-server-net-ip-range>"), Ipv4Mask("255.255.255.0"), Ipv4Address("11.0.0.2"), 1, 0);
203
204
  //  Ptr<Ipv4> n2_IPv4_module = nodes.Get(2)->GetObject<Ipv4>();
205
  //  Ptr<Ipv4StaticRouting> n2_routing_table = ipv4RoutingHelper.GetStaticRouting(n2_IPv4_module);
206
  //  n2_routing_table->AddNetworkRouteTo( Ipv4Address("<Your-clients-net-ip-range>"), Ipv4Mask("255.255.255.0"), Ipv4Address("11.0.0.1"), 1, 0);
207
208
209
  /*   ::::::: Step 5: Setup applications ::::::: */
210
211
  // Create the OnOff application on n0 to send UDP datagrams of size
212
  // 210 bytes at a rate of 448 Kb/s to n2
213
  NS_LOG_INFO ("Create Applications.");
214
  uint16_t port = 9;   // Discard port (RFC 863)
215
  OnOffHelper onoff ("ns3::UdpSocketFactory",   // send to n2 via tunnel (use inner tunnel-ip)
216
                     Address (InetSocketAddress (Ipv4Address ("11.0.0.2"), port)));
217
  onoff.SetConstantRate (DataRate ("448kb/s"));
218
  ApplicationContainer apps = onoff.Install (nodes.Get (0));
219
  apps.Start (Seconds (1.0));
220
  apps.Stop (Seconds (10.0));
221
222
  // Create a packet sink on n2 to receive these packets
223
  PacketSinkHelper sink ("ns3::UdpSocketFactory",
224
                         Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
225
  apps = sink.Install (nodes.Get (2));
226
  apps.Start (Seconds (1.0));
227
  apps.Stop (Seconds(10));
228
229
  /* :::: Step 6: Setup tracing and start simulation engine :::::: */
230
  AsciiTraceHelper ascii;
231
  p2p.EnableAsciiAll (ascii.CreateFileStream ("direct-tunnel.tr"));
232
  // p2p.EnablePcapAll ("direct-tunnel");  // optional pcap capturing
233
234
  NS_LOG_INFO ("Run Simulation.");
235
  Simulator::Run ();
236
  Simulator::Destroy ();
237
  NS_LOG_INFO ("Done.");
238
239
  return 0;
240
}
(-)a/src/virtual-net-device/examples/virtual-net-device.cc (-287 lines)
Removed Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 *
16
 * Based on simple-global-routing.cc
17
 * The Tunnel class adds two tunnels, n0<=>n3 and n1<=>n3
18
 */
19
20
// Network topology
21
//
22
//  n0
23
//     \ 5 Mb/s, 2ms
24
//      \          1.5Mb/s, 10ms
25
//       n2 -------------------------n3
26
//      /
27
//     / 5 Mb/s, 2ms
28
//   n1
29
//
30
// - all links are point-to-point links with indicated one-way BW/delay
31
// - Tracing of queues and packet receptions to file "virtual-net-device.tr"
32
33
// Tunneling changes (relative to the simple-global-routing example):
34
// - n0 will receive an extra virtual interface with hardcoded inner-tunnel address 11.0.0.1
35
// - n1 will also receive an extra virtual interface with the same inner-tunnel address 11.0.0.1
36
// - n3 will receive an extra virtual interface with inner-tunnel address 11.0.0.254
37
// - The flows will be between 11.0.0.x (inner-tunnel) addresses instead of 10.1.x.y ones
38
// - n3 will decide, on a per-packet basis, via random number, whether to
39
//   send the packet to n0 or to n1.
40
//
41
// Note: here we create a tunnel where IP packets are tunneled over
42
// UDP/IP, but tunneling directly IP-over-IP would also be possible;
43
// see src/node/ipv4-raw-socket-factory.h.
44
45
#include <iostream>
46
#include <fstream>
47
#include <string>
48
#include <cassert>
49
50
#include "ns3/core-module.h"
51
#include "ns3/network-module.h"
52
#include "ns3/internet-module.h"
53
#include "ns3/point-to-point-module.h"
54
#include "ns3/applications-module.h"
55
#include "ns3/virtual-net-device.h"
56
57
using namespace ns3;
58
59
NS_LOG_COMPONENT_DEFINE ("VirtualNetDeviceExample");
60
61
class Tunnel
62
{
63
  Ptr<Socket> m_n3Socket;
64
  Ptr<Socket> m_n0Socket;
65
  Ptr<Socket> m_n1Socket;
66
  Ipv4Address m_n3Address;
67
  Ipv4Address m_n0Address;
68
  Ipv4Address m_n1Address;
69
  Ptr<UniformRandomVariable> m_rng;
70
  Ptr<VirtualNetDevice> m_n0Tap;
71
  Ptr<VirtualNetDevice> m_n1Tap;
72
  Ptr<VirtualNetDevice> m_n3Tap;
73
74
75
  bool
76
  N0VirtualSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
77
  {
78
    NS_LOG_DEBUG ("Send to " << m_n3Address << ": " << *packet);
79
    m_n0Socket->SendTo (packet, 0, InetSocketAddress (m_n3Address, 667));
80
    return true;
81
  }
82
83
  bool
84
  N1VirtualSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
85
  {
86
    NS_LOG_DEBUG ("Send to " << m_n3Address << ": " << *packet);
87
    m_n1Socket->SendTo (packet, 0, InetSocketAddress (m_n3Address, 667));
88
    return true;
89
  }
90
91
  bool
92
  N3VirtualSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
93
  {
94
    if (m_rng->GetValue () < 0.25)
95
      {
96
        NS_LOG_DEBUG ("Send to " << m_n0Address << ": " << *packet);
97
        m_n3Socket->SendTo (packet, 0, InetSocketAddress (m_n0Address, 667));
98
      }
99
    else 
100
      {
101
        NS_LOG_DEBUG ("Send to " << m_n1Address << ": " << *packet);
102
        m_n3Socket->SendTo (packet, 0, InetSocketAddress (m_n1Address, 667));
103
      }
104
    return true;
105
  }
106
107
  void N3SocketRecv (Ptr<Socket> socket)
108
  {
109
    Ptr<Packet> packet = socket->Recv (65535, 0);
110
    NS_LOG_DEBUG ("N3SocketRecv: " << *packet);
111
    m_n3Tap->Receive (packet, 0x0800, m_n3Tap->GetAddress (), m_n3Tap->GetAddress (), NetDevice::PACKET_HOST);
112
  }
113
114
  void N0SocketRecv (Ptr<Socket> socket)
115
  {
116
    Ptr<Packet> packet = socket->Recv (65535, 0);
117
    NS_LOG_DEBUG ("N0SocketRecv: " << *packet);
118
    m_n0Tap->Receive (packet, 0x0800, m_n0Tap->GetAddress (), m_n0Tap->GetAddress (), NetDevice::PACKET_HOST);
119
  }
120
121
  void N1SocketRecv (Ptr<Socket> socket)
122
  {
123
    Ptr<Packet> packet = socket->Recv (65535, 0);
124
    NS_LOG_DEBUG ("N1SocketRecv: " << *packet);
125
    m_n1Tap->Receive (packet, 0x0800, m_n1Tap->GetAddress (), m_n1Tap->GetAddress (), NetDevice::PACKET_HOST);
126
  }
127
128
public:
129
130
  Tunnel (Ptr<Node> n3, Ptr<Node> n0, Ptr<Node> n1,
131
          Ipv4Address n3Addr, Ipv4Address n0Addr, Ipv4Address n1Addr)
132
    : m_n3Address (n3Addr), m_n0Address (n0Addr), m_n1Address (n1Addr)
133
  {
134
    m_rng = CreateObject<UniformRandomVariable> ();
135
    m_n3Socket = Socket::CreateSocket (n3, TypeId::LookupByName ("ns3::UdpSocketFactory"));
136
    m_n3Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667));
137
    m_n3Socket->SetRecvCallback (MakeCallback (&Tunnel::N3SocketRecv, this));
138
139
    m_n0Socket = Socket::CreateSocket (n0, TypeId::LookupByName ("ns3::UdpSocketFactory"));
140
    m_n0Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667));
141
    m_n0Socket->SetRecvCallback (MakeCallback (&Tunnel::N0SocketRecv, this));
142
143
    m_n1Socket = Socket::CreateSocket (n1, TypeId::LookupByName ("ns3::UdpSocketFactory"));
144
    m_n1Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667));
145
    m_n1Socket->SetRecvCallback (MakeCallback (&Tunnel::N1SocketRecv, this));
146
147
    // n0 tap device
148
    m_n0Tap = CreateObject<VirtualNetDevice> ();
149
    m_n0Tap->SetAddress (Mac48Address ("11:00:01:02:03:01"));
150
    m_n0Tap->SetSendCallback (MakeCallback (&Tunnel::N0VirtualSend, this));
151
    n0->AddDevice (m_n0Tap);
152
    Ptr<Ipv4> ipv4 = n0->GetObject<Ipv4> ();
153
    uint32_t i = ipv4->AddInterface (m_n0Tap);
154
    ipv4->AddAddress (i, Ipv4InterfaceAddress (Ipv4Address ("11.0.0.1"), Ipv4Mask ("255.255.255.0")));
155
    ipv4->SetUp (i);
156
157
    // n1 tap device
158
    m_n1Tap = CreateObject<VirtualNetDevice> ();
159
    m_n1Tap->SetAddress (Mac48Address ("11:00:01:02:03:02"));
160
    m_n1Tap->SetSendCallback (MakeCallback (&Tunnel::N1VirtualSend, this));
161
    n1->AddDevice (m_n1Tap);
162
    ipv4 = n1->GetObject<Ipv4> ();
163
    i = ipv4->AddInterface (m_n1Tap);
164
    ipv4->AddAddress (i, Ipv4InterfaceAddress (Ipv4Address ("11.0.0.1"), Ipv4Mask ("255.255.255.0")));
165
    ipv4->SetUp (i);
166
167
    // n3 tap device
168
    m_n3Tap = CreateObject<VirtualNetDevice> ();
169
    m_n3Tap->SetAddress (Mac48Address ("11:00:01:02:03:04"));
170
    m_n3Tap->SetSendCallback (MakeCallback (&Tunnel::N3VirtualSend, this));
171
    n3->AddDevice (m_n3Tap);
172
    ipv4 = n3->GetObject<Ipv4> ();
173
    i = ipv4->AddInterface (m_n3Tap);
174
    ipv4->AddAddress (i, Ipv4InterfaceAddress (Ipv4Address ("11.0.0.254"), Ipv4Mask ("255.255.255.0")));
175
    ipv4->SetUp (i);
176
177
  }
178
179
180
};
181
182
183
184
int 
185
main (int argc, char *argv[])
186
{
187
  // Users may find it convenient to turn on explicit logging
188
  // for selected modules; the below lines suggest how to do this
189
#if 0 
190
  LogComponentEnable ("VirtualNetDeviceExample", LOG_LEVEL_INFO);
191
#endif
192
  Packet::EnablePrinting ();
193
194
195
  // Set up some default values for the simulation.  Use the 
196
  Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
197
  Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
198
199
  // Allow the user to override any of the defaults and the above
200
  // Config::SetDefault ()s at run-time, via command-line arguments
201
  CommandLine cmd;
202
  cmd.Parse (argc, argv);
203
204
  NS_LOG_INFO ("Create nodes.");
205
  NodeContainer c;
206
  c.Create (4);
207
  NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2));
208
  NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2));
209
  NodeContainer n3n2 = NodeContainer (c.Get (3), c.Get (2));
210
211
  InternetStackHelper internet;
212
  internet.Install (c);
213
214
  // We create the channels first without any IP addressing information
215
  NS_LOG_INFO ("Create channels.");
216
  PointToPointHelper p2p;
217
  p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
218
  p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
219
  NetDeviceContainer d0d2 = p2p.Install (n0n2);
220
221
  NetDeviceContainer d1d2 = p2p.Install (n1n2);
222
223
  p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
224
  p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
225
  NetDeviceContainer d3d2 = p2p.Install (n3n2);
226
227
  // Later, we add IP addresses.
228
  NS_LOG_INFO ("Assign IP Addresses.");
229
  Ipv4AddressHelper ipv4;
230
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
231
  Ipv4InterfaceContainer i0i2 = ipv4.Assign (d0d2);
232
233
  ipv4.SetBase ("10.1.2.0", "255.255.255.0");
234
  Ipv4InterfaceContainer i1i2 = ipv4.Assign (d1d2);
235
236
  ipv4.SetBase ("10.1.3.0", "255.255.255.0");
237
  Ipv4InterfaceContainer i3i2 = ipv4.Assign (d3d2);
238
239
  // Create router nodes, initialize routing database and set up the routing
240
  // tables in the nodes.
241
  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
242
243
  // Add the tunnels n0<=>n3 and n1<=>n3
244
  Tunnel tunnel (c.Get (3), c.Get (0), c.Get (1),
245
                 i3i2.GetAddress (0), i0i2.GetAddress (0), i1i2.GetAddress (0));
246
247
  // Create the OnOff application to send UDP datagrams of size
248
  // 210 bytes at a rate of 448 Kb/s
249
  NS_LOG_INFO ("Create Applications.");
250
  uint16_t port = 9;   // Discard port (RFC 863)
251
  OnOffHelper onoff ("ns3::UdpSocketFactory", 
252
                     Address (InetSocketAddress (Ipv4Address ("11.0.0.254"), port)));
253
  onoff.SetConstantRate (DataRate ("448kb/s"));
254
  ApplicationContainer apps = onoff.Install (c.Get (0));
255
  apps.Start (Seconds (1.0));
256
  apps.Stop (Seconds (10.0));
257
258
  // Create a packet sink to receive these packets
259
  PacketSinkHelper sink ("ns3::UdpSocketFactory",
260
                         Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
261
  apps = sink.Install (c.Get (3));
262
  apps.Start (Seconds (1.0));
263
  //apps.Stop (Seconds (10.0));
264
265
  // Create a similar flow from n3 to n1, starting at time 1.1 seconds
266
  onoff.SetAttribute ("Remote", 
267
                      AddressValue (InetSocketAddress (Ipv4Address ("11.0.0.1"), port)));
268
  apps = onoff.Install (c.Get (3));
269
  apps.Start (Seconds (1.1));
270
  apps.Stop (Seconds (10.0));
271
272
  // Create a packet sink to receive these packets
273
  apps = sink.Install (c.Get (1));
274
  apps.Start (Seconds (1.1));
275
  //apps.Stop (Seconds (10.0));
276
277
  AsciiTraceHelper ascii;
278
  p2p.EnableAsciiAll (ascii.CreateFileStream ("virtual-net-device.tr"));
279
  p2p.EnablePcapAll ("virtual-net-device");
280
281
  NS_LOG_INFO ("Run Simulation.");
282
  Simulator::Run ();
283
  Simulator::Destroy ();
284
  NS_LOG_INFO ("Done.");
285
286
  return 0;
287
}
(-)a/src/virtual-net-device/examples/wscript (-2 / +2 lines)
 Lines 2-7    Link Here 
2
2
3
def build(bld):
3
def build(bld):
4
4
5
    obj = bld.create_ns3_program('virtual-net-device', ['virtual-net-device', 'point-to-point', 'internet', 'applications'])
5
    obj = bld.create_ns3_program('direct-tunnel', ['virtual-net-device', 'point-to-point', 'internet', 'applications'])
6
    obj.source = 'virtual-net-device.cc'
6
    obj.source = 'direct-tunnel.cc'
7
    
7
    

Return to bug 3026