author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Thu, 13 Mar 2008 12:56:49 -0700 | |
changeset 2602 | d9262bff6df2 |
parent 2600 | 6c389d0c717d |
child 2815 | 6d39cd4aef81 |
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" |
|
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
30 |
#include "ns3/inet-socket-address.h" |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
31 |
#include "ns3/uinteger.h" |
1529 | 32 |
|
33 |
NS_LOG_COMPONENT_DEFINE ("UdpEchoSimulation"); |
|
34 |
||
35 |
using namespace ns3; |
|
36 |
||
37 |
int |
|
38 |
main (int argc, char *argv[]) |
|
39 |
{ |
|
40 |
LogComponentEnable ("UdpEchoSimulation", LOG_LEVEL_INFO); |
|
41 |
||
42 |
NS_LOG_INFO ("UDP Echo Simulation"); |
|
43 |
||
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
|
44 |
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
|
45 |
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
|
46 |
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
|
47 |
Ptr<Node> n3 = CreateObject<InternetNode> (); |
1529 | 48 |
|
49 |
Ptr<CsmaChannel> lan = |
|
50 |
CsmaTopology::CreateCsmaChannel (DataRate (5000000), MilliSeconds (2)); |
|
51 |
||
52 |
uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan, |
|
53 |
"08:00:2e:00:00:00"); |
|
54 |
||
55 |
uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan, |
|
56 |
"08:00:2e:00:00:01"); |
|
57 |
||
58 |
uint32_t nd2 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan, |
|
59 |
"08:00:2e:00:00:02"); |
|
60 |
||
61 |
uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan, |
|
62 |
"08:00:2e:00:00:03"); |
|
63 |
||
64 |
CsmaIpv4Topology::AddIpv4Address (n0, nd0, "10.1.1.1", "255.255.255.0"); |
|
65 |
CsmaIpv4Topology::AddIpv4Address (n1, nd1, "10.1.1.2", "255.255.255.0"); |
|
66 |
CsmaIpv4Topology::AddIpv4Address (n2, nd2, "10.1.1.3", "255.255.255.0"); |
|
67 |
CsmaIpv4Topology::AddIpv4Address (n3, nd3, "10.1.1.4", "255.255.255.0"); |
|
68 |
||
69 |
uint16_t port = 7; |
|
70 |
||
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
71 |
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
|
72 |
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
|
73 |
"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
|
74 |
"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
|
75 |
"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
|
76 |
"PacketSize", Uinteger (1024)); |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
77 |
n0->AddApplication (client); |
1529 | 78 |
|
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
79 |
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
|
80 |
CreateObject<UdpEchoServer> ("Port", Uinteger (port)); |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
81 |
n1->AddApplication (server); |
1529 | 82 |
|
83 |
server->Start(Seconds(1.)); |
|
84 |
client->Start(Seconds(2.)); |
|
85 |
||
86 |
server->Stop (Seconds(10.)); |
|
87 |
client->Stop (Seconds(10.)); |
|
88 |
||
89 |
AsciiTrace asciitrace ("tutorial.tr"); |
|
90 |
asciitrace.TraceAllQueues (); |
|
91 |
asciitrace.TraceAllNetDeviceRx (); |
|
92 |
||
93 |
Simulator::Run (); |
|
94 |
Simulator::Destroy (); |
|
95 |
} |