A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
simple-point-to-point-olsr.cc
Go to the documentation of this file.
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
18
//
19
// Simple example of OLSR routing over some point-to-point links
20
//
21
// Network topology
22
//
23
// n0
24
// \ 5 Mb/s, 2ms
25
// \ 1.5Mb/s, 10ms
26
// n2 -------------------------n3---------n4
27
// /
28
// / 5 Mb/s, 2ms
29
// n1
30
//
31
// - all links are point-to-point links with indicated one-way BW/delay
32
// - CBR/UDP flows from n0 to n4, and from n3 to n1
33
// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec.
34
// (i.e., DataRate of 448,000 bps)
35
// - DropTail queues
36
// - Tracing of queues and packet receptions to file "simple-point-to-point-olsr.tr"
37
38
#include <iostream>
39
#include <fstream>
40
#include <string>
41
#include <cassert>
42
43
#include "ns3/core-module.h"
44
#include "ns3/network-module.h"
45
#include "ns3/internet-module.h"
46
#include "ns3/point-to-point-module.h"
47
#include "ns3/applications-module.h"
48
#include "ns3/olsr-helper.h"
49
#include "ns3/ipv4-static-routing-helper.h"
50
#include "ns3/ipv4-list-routing-helper.h"
51
52
using namespace
ns3;
53
54
NS_LOG_COMPONENT_DEFINE
(
"SimplePointToPointOlsrExample"
);
55
56
int
57
main
(
int
argc,
char
*argv[])
58
{
59
// Users may find it convenient to turn on explicit debugging
60
// for selected modules; the below lines suggest how to do this
61
#if 0
62
LogComponentEnable
(
"SimpleGlobalRoutingExample"
,
LOG_LEVEL_INFO
);
63
#endif
64
65
// Set up some default values for the simulation. Use the
66
67
Config::SetDefault
(
"ns3::OnOffApplication::PacketSize"
,
UintegerValue
(210));
68
Config::SetDefault
(
"ns3::OnOffApplication::DataRate"
,
StringValue
(
"448kb/s"
));
69
70
//DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
71
72
// Allow the user to override any of the defaults and the above
73
// DefaultValue::Bind ()s at run-time, via command-line arguments
74
CommandLine
cmd;
75
cmd.
Parse
(argc, argv);
76
77
// Here, we will explicitly create four nodes. In more sophisticated
78
// topologies, we could configure a node factory.
79
NS_LOG_INFO
(
"Create nodes."
);
80
NodeContainer
c;
81
c.
Create
(5);
82
NodeContainer
n02 =
NodeContainer
(c.
Get
(0), c.
Get
(2));
83
NodeContainer
n12 =
NodeContainer
(c.
Get
(1), c.
Get
(2));
84
NodeContainer
n32 =
NodeContainer
(c.
Get
(3), c.
Get
(2));
85
NodeContainer
n34 =
NodeContainer
(c.
Get
(3), c.
Get
(4));
86
87
// Enable OLSR
88
NS_LOG_INFO
(
"Enabling OLSR Routing."
);
89
OlsrHelper
olsr;
90
91
Ipv4StaticRoutingHelper
staticRouting;
92
93
Ipv4ListRoutingHelper
list
;
94
list.
Add
(staticRouting, 0);
95
list.
Add
(olsr, 10);
96
97
InternetStackHelper
internet;
98
internet.
SetRoutingHelper
(list);
// has effect on the next Install ()
99
internet.
Install
(c);
100
101
// We create the channels first without any IP addressing information
102
NS_LOG_INFO
(
"Create channels."
);
103
PointToPointHelper
p2p;
104
p2p.
SetDeviceAttribute
(
"DataRate"
,
StringValue
(
"5Mbps"
));
105
p2p.
SetChannelAttribute
(
"Delay"
,
StringValue
(
"2ms"
));
106
NetDeviceContainer
nd02 = p2p.
Install
(n02);
107
NetDeviceContainer
nd12 = p2p.
Install
(n12);
108
p2p.
SetDeviceAttribute
(
"DataRate"
,
StringValue
(
"1500kbps"
));
109
p2p.
SetChannelAttribute
(
"Delay"
,
StringValue
(
"10ms"
));
110
NetDeviceContainer
nd32 = p2p.
Install
(n32);
111
NetDeviceContainer
nd34 = p2p.
Install
(n34);
112
113
// Later, we add IP addresses.
114
NS_LOG_INFO
(
"Assign IP Addresses."
);
115
Ipv4AddressHelper
ipv4;
116
ipv4.
SetBase
(
"10.1.1.0"
,
"255.255.255.0"
);
117
Ipv4InterfaceContainer
i02 = ipv4.
Assign
(nd02);
118
119
ipv4.
SetBase
(
"10.1.2.0"
,
"255.255.255.0"
);
120
Ipv4InterfaceContainer
i12 = ipv4.
Assign
(nd12);
121
122
ipv4.
SetBase
(
"10.1.3.0"
,
"255.255.255.0"
);
123
Ipv4InterfaceContainer
i32 = ipv4.
Assign
(nd32);
124
125
ipv4.
SetBase
(
"10.1.4.0"
,
"255.255.255.0"
);
126
Ipv4InterfaceContainer
i34 = ipv4.
Assign
(nd34);
127
128
// Create the OnOff application to send UDP datagrams of size
129
// 210 bytes at a rate of 448 Kb/s from n0 to n4
130
NS_LOG_INFO
(
"Create Applications."
);
131
uint16_t
port
= 9;
// Discard port (RFC 863)
132
133
OnOffHelper
onoff (
"ns3::UdpSocketFactory"
,
134
InetSocketAddress
(i34.
GetAddress
(1),
port
));
135
onoff.
SetConstantRate
(
DataRate
(
"448kb/s"
));
136
137
ApplicationContainer
apps = onoff.
Install
(c.
Get
(0));
138
apps.
Start
(
Seconds
(1.0));
139
apps.
Stop
(
Seconds
(10.0));
140
141
// Create a packet sink to receive these packets
142
PacketSinkHelper
sink (
"ns3::UdpSocketFactory"
,
143
InetSocketAddress
(
Ipv4Address::GetAny
(), port));
144
145
apps = sink.
Install
(c.
Get
(3));
146
apps.
Start
(
Seconds
(1.0));
147
apps.
Stop
(
Seconds
(10.0));
148
149
// Create a similar flow from n3 to n1, starting at time 1.1 seconds
150
onoff.
SetAttribute
(
"Remote"
,
151
AddressValue
(
InetSocketAddress
(i12.
GetAddress
(0),
port
)));
152
apps = onoff.
Install
(c.
Get
(3));
153
apps.
Start
(
Seconds
(1.1));
154
apps.
Stop
(
Seconds
(10.0));
155
156
// Create a packet sink to receive these packets
157
apps = sink.
Install
(c.
Get
(1));
158
apps.
Start
(
Seconds
(1.1));
159
apps.
Stop
(
Seconds
(10.0));
160
161
AsciiTraceHelper
ascii;
162
p2p.
EnableAsciiAll
(ascii.
CreateFileStream
(
"simple-point-to-point-olsr.tr"
));
163
p2p.
EnablePcapAll
(
"simple-point-to-point-olsr"
);
164
165
Simulator::Stop
(
Seconds
(30));
166
167
NS_LOG_INFO
(
"Run Simulation."
);
168
Simulator::Run
();
169
Simulator::Destroy
();
170
NS_LOG_INFO
(
"Done."
);
171
172
return
0;
173
}
src
olsr
examples
simple-point-to-point-olsr.cc
Generated on Fri Dec 21 2012 19:00:45 for ns-3 by
1.8.1.2