author | Tom Henderson <tomh@tomh.org> |
Tue, 22 Apr 2008 21:19:39 -0700 | |
changeset 2997 | caf9d364c6fc |
parent 2996 | a83b94e277d4 |
parent 2965 | 4b28e9740e3b |
child 3257 | ba198dad54a2 |
permissions | -rw-r--r-- |
1529 | 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 |
||
2816
23c5900c3fdc
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
17 |
#include "ns3/core-module.h" |
23c5900c3fdc
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
18 |
#include "ns3/simulator-module.h" |
23c5900c3fdc
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
19 |
#include "ns3/helper-module.h" |
1529 | 20 |
|
21 |
NS_LOG_COMPONENT_DEFINE ("UdpEchoSimulation"); |
|
22 |
||
23 |
using namespace ns3; |
|
24 |
||
25 |
int |
|
26 |
main (int argc, char *argv[]) |
|
27 |
{ |
|
28 |
LogComponentEnable ("UdpEchoSimulation", LOG_LEVEL_INFO); |
|
29 |
||
30 |
NS_LOG_INFO ("UDP Echo Simulation"); |
|
31 |
||
2816
23c5900c3fdc
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
32 |
NodeContainer n; |
23c5900c3fdc
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
33 |
n.Create (4); |
1529 | 34 |
|
2816
23c5900c3fdc
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
35 |
InternetStackHelper internet; |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2837
diff
changeset
|
36 |
internet.Install (n); |
1529 | 37 |
|
2816
23c5900c3fdc
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
38 |
CsmaHelper csma; |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2888
diff
changeset
|
39 |
csma.SetChannelParameter ("BitRate", StringValue ("5Mbps")); |
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2888
diff
changeset
|
40 |
csma.SetChannelParameter ("Delay", StringValue ("2ms")); |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2837
diff
changeset
|
41 |
NetDeviceContainer nd = csma.Install (n); |
1529 | 42 |
|
2816
23c5900c3fdc
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
43 |
Ipv4AddressHelper ipv4; |
23c5900c3fdc
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
44 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
2888
872dc8466352
Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2887
diff
changeset
|
45 |
Ipv4InterfaceContainer i = ipv4.Assign (nd); |
1529 | 46 |
|
47 |
uint16_t port = 7; |
|
48 |
||
2816
23c5900c3fdc
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
49 |
UdpEchoClientHelper client; |
23c5900c3fdc
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
50 |
client.SetRemote (i.GetAddress (1), port); |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2888
diff
changeset
|
51 |
client.SetAppAttribute ("MaxPackets", UintegerValue (1)); |
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2888
diff
changeset
|
52 |
client.SetAppAttribute ("Interval", StringValue ("2s")); |
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2888
diff
changeset
|
53 |
client.SetAppAttribute ("PacketSize", UintegerValue (1024)); |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2837
diff
changeset
|
54 |
ApplicationContainer apps = client.Install (n.Get (0)); |
2816
23c5900c3fdc
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
55 |
apps.Start (Seconds (2.0)); |
23c5900c3fdc
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
56 |
apps.Stop (Seconds (10.0)); |
1529 | 57 |
|
2816
23c5900c3fdc
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
58 |
UdpEchoServerHelper server; |
23c5900c3fdc
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
59 |
server.SetPort (port); |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2837
diff
changeset
|
60 |
apps = server.Install (n.Get (1)); |
2816
23c5900c3fdc
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
61 |
apps.Start (Seconds (1.0)); |
23c5900c3fdc
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
62 |
apps.Stop (Seconds (10.0)); |
1529 | 63 |
|
2996
a83b94e277d4
EnablePcap()->EnablePcapAll(); EnableAscii()->EnableAsciiAll()
Tom Henderson <tomh@tomh.org>
parents:
2888
diff
changeset
|
64 |
CsmaHelper::EnablePcapAll ("tutorial"); |
2816
23c5900c3fdc
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2600
diff
changeset
|
65 |
|
1529 | 66 |
Simulator::Run (); |
67 |
Simulator::Destroy (); |
|
68 |
} |