author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Mon, 07 Apr 2008 10:41:21 -0700 | |
changeset 2888 | 872dc8466352 |
parent 2887 | 9a637e6daee0 |
child 2965 | 4b28e9740e3b |
child 2996 | a83b94e277d4 |
permissions | -rw-r--r-- |
1844 | 1 |
|
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 |
||
2811
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
17 |
#include <fstream> |
1844 | 18 |
|
2811
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
19 |
#include "ns3/core-module.h" |
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
20 |
#include "ns3/node-module.h" |
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
21 |
#include "ns3/helper-module.h" |
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
22 |
#include "ns3/simulator-module.h" |
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
23 |
#include "ns3/global-route-manager.h" |
1844 | 24 |
|
25 |
NS_LOG_COMPONENT_DEFINE ("BusNetworkSimulation"); |
|
26 |
||
27 |
using namespace ns3; |
|
28 |
||
29 |
int |
|
30 |
main (int argc, char *argv[]) |
|
31 |
{ |
|
32 |
LogComponentEnable ("BusNetworkSimulation", LOG_LEVEL_ALL); |
|
33 |
||
34 |
NS_LOG_INFO ("Bus Network Simulation"); |
|
35 |
||
2811
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
36 |
NodeContainer n; |
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
37 |
n.Create (10); |
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
38 |
|
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
39 |
InternetStackHelper internet; |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2811
diff
changeset
|
40 |
internet.Install (n); |
2811
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
41 |
|
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
42 |
CsmaHelper csma; |
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
43 |
csma.SetChannelParameter ("BitRate", DataRate(10000000)); |
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
44 |
csma.SetChannelParameter ("Delay", MilliSeconds(20)); |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2811
diff
changeset
|
45 |
NetDeviceContainer nd = csma.Install (n); |
2811
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
46 |
|
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
47 |
Ipv4AddressHelper ipv4; |
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
48 |
ipv4.SetBase ("10.1.0.0", "255.255.0.0", "0.0.0.3"); |
2888
872dc8466352
Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2887
diff
changeset
|
49 |
Ipv4InterfaceContainer i = ipv4.Assign (nd); |
1844 | 50 |
|
51 |
uint32_t port = 7; |
|
2811
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
52 |
UdpEchoClientHelper client; |
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
53 |
client.SetRemote (i.GetAddress (1), port); |
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
54 |
client.SetAppAttribute ("MaxPackets", Uinteger (1)); |
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
55 |
client.SetAppAttribute ("Interval", Seconds (1.0)); |
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
56 |
client.SetAppAttribute ("PacketSize", Uinteger (1024)); |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2811
diff
changeset
|
57 |
ApplicationContainer apps = client.Install (n.Get (0)); |
2811
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
58 |
apps.Start (Seconds (2.0)); |
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
59 |
apps.Stop (Seconds (10.0)); |
1844 | 60 |
|
2811
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
61 |
UdpEchoServerHelper server; |
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
62 |
server.SetPort (port); |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2811
diff
changeset
|
63 |
apps = server.Install (n.Get (1)); |
2811
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
64 |
apps.Start (Seconds (1.0)); |
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
65 |
apps.Stop (Seconds (10.0)); |
1844 | 66 |
|
2811
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
67 |
GlobalRouteManager::PopulateRoutingTables (); |
1844 | 68 |
|
2811
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
69 |
std::ofstream ascii; |
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
70 |
ascii.open ("tutorial.tr"); |
80ad195c1770
port to helper API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
71 |
CsmaHelper::EnableAscii (ascii); |
1844 | 72 |
|
73 |
Simulator::Run (); |
|
74 |
Simulator::Destroy (); |
|
75 |
} |