author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Thu, 13 Mar 2008 11:10:38 -0700 | |
changeset 2600 | 6c389d0c717d |
parent 2592 | 3ebf97150166 |
child 2816 | 23c5900c3fdc |
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 |
||
17 |
#include "ns3/log.h" |
|
18 |
#include "ns3/ptr.h" |
|
19 |
#include "ns3/internet-node.h" |
|
20 |
#include "ns3/csma-channel.h" |
|
21 |
#include "ns3/mac48-address.h" |
|
22 |
#include "ns3/csma-net-device.h" |
|
23 |
#include "ns3/csma-topology.h" |
|
24 |
#include "ns3/csma-ipv4-topology.h" |
|
25 |
#include "ns3/udp-echo-client.h" |
|
26 |
#include "ns3/udp-echo-server.h" |
|
27 |
#include "ns3/simulator.h" |
|
28 |
#include "ns3/nstime.h" |
|
29 |
#include "ns3/ascii-trace.h" |
|
30 |
#include "ns3/pcap-trace.h" |
|
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
31 |
#include "ns3/inet-socket-address.h" |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
32 |
#include "ns3/uinteger.h" |
1529 | 33 |
|
34 |
NS_LOG_COMPONENT_DEFINE ("UdpEchoSimulation"); |
|
35 |
||
36 |
using namespace ns3; |
|
37 |
||
38 |
int |
|
39 |
main (int argc, char *argv[]) |
|
40 |
{ |
|
41 |
LogComponentEnable ("UdpEchoSimulation", LOG_LEVEL_INFO); |
|
42 |
||
43 |
NS_LOG_INFO ("UDP Echo Simulation"); |
|
44 |
||
2230
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1539
diff
changeset
|
45 |
Ptr<Node> n0 = CreateObject<InternetNode> (); |
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1539
diff
changeset
|
46 |
Ptr<Node> n1 = CreateObject<InternetNode> (); |
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1539
diff
changeset
|
47 |
Ptr<Node> n2 = CreateObject<InternetNode> (); |
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1539
diff
changeset
|
48 |
Ptr<Node> n3 = CreateObject<InternetNode> (); |
1529 | 49 |
|
50 |
Ptr<CsmaChannel> lan = |
|
51 |
CsmaTopology::CreateCsmaChannel (DataRate (5000000), MilliSeconds (2)); |
|
52 |
||
53 |
uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan, |
|
54 |
"08:00:2e:00:00:00"); |
|
55 |
||
56 |
uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan, |
|
57 |
"08:00:2e:00:00:01"); |
|
58 |
||
59 |
uint32_t nd2 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan, |
|
60 |
"08:00:2e:00:00:02"); |
|
61 |
||
62 |
uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan, |
|
63 |
"08:00:2e:00:00:03"); |
|
64 |
||
65 |
CsmaIpv4Topology::AddIpv4Address (n0, nd0, "10.1.1.1", "255.255.255.0"); |
|
66 |
CsmaIpv4Topology::AddIpv4Address (n1, nd1, "10.1.1.2", "255.255.255.0"); |
|
67 |
CsmaIpv4Topology::AddIpv4Address (n2, nd2, "10.1.1.3", "255.255.255.0"); |
|
68 |
CsmaIpv4Topology::AddIpv4Address (n3, nd3, "10.1.1.4", "255.255.255.0"); |
|
69 |
||
70 |
uint16_t port = 7; |
|
71 |
||
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
72 |
Ptr<UdpEchoClient> client = |
2600
6c389d0c717d
add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2592
diff
changeset
|
73 |
CreateObject<UdpEchoClient> ("RemoteIpv4", Ipv4Address ("10.1.1.2"), |
6c389d0c717d
add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2592
diff
changeset
|
74 |
"RemotePort", Uinteger (port), |
6c389d0c717d
add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2592
diff
changeset
|
75 |
"MaxPackets", Uinteger (1), |
6c389d0c717d
add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2592
diff
changeset
|
76 |
"Interval", Seconds(1.), |
6c389d0c717d
add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2592
diff
changeset
|
77 |
"PacketSize", Uinteger (1024)); |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
78 |
n0->AddApplication (client); |
1529 | 79 |
|
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
80 |
Ptr<UdpEchoServer> server = |
2600
6c389d0c717d
add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2592
diff
changeset
|
81 |
CreateObject<UdpEchoServer> ("Port", Uinteger (port)); |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
82 |
n1->AddApplication (server); |
1529 | 83 |
|
84 |
server->Start(Seconds(1.)); |
|
85 |
client->Start(Seconds(2.)); |
|
86 |
||
87 |
server->Stop (Seconds(10.)); |
|
88 |
client->Stop (Seconds(10.)); |
|
89 |
||
90 |
AsciiTrace asciitrace ("tutorial.tr"); |
|
91 |
asciitrace.TraceAllQueues (); |
|
2221
8a6f9a7d8c48
Split tutorial.texi into multiple files; some work on the tracing section
Tom Henderson <tomh@tomh.org>
parents:
1539
diff
changeset
|
92 |
#if 0 |
1529 | 93 |
asciitrace.TraceAllNetDeviceRx (); |
2221
8a6f9a7d8c48
Split tutorial.texi into multiple files; some work on the tracing section
Tom Henderson <tomh@tomh.org>
parents:
1539
diff
changeset
|
94 |
#endif |
1529 | 95 |
|
96 |
PcapTrace pcaptrace ("tutorial.pcap"); |
|
97 |
pcaptrace.TraceAllIp (); |
|
98 |
||
99 |
Simulator::Run (); |
|
100 |
Simulator::Destroy (); |
|
101 |
} |