author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Wed, 02 Jan 2008 09:09:24 +0100 | |
changeset 2230 | 9f13ac3291e0 |
parent 1539 | 69d32521f6b8 |
child 2311 | a7dbe3cba7de |
permissions | -rw-r--r-- |
1527 | 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 |
||
30 |
NS_LOG_COMPONENT_DEFINE ("UdpEchoSimulation"); |
|
31 |
||
32 |
using namespace ns3; |
|
33 |
||
34 |
int |
|
35 |
main (int argc, char *argv[]) |
|
36 |
{ |
|
37 |
LogComponentEnable ("UdpEchoSimulation", LOG_LEVEL_INFO); |
|
38 |
||
39 |
NS_LOG_INFO ("UDP Echo Simulation"); |
|
40 |
||
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
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
Ptr<Node> n3 = CreateObject<InternetNode> (); |
1527 | 45 |
|
46 |
Ptr<CsmaChannel> lan = |
|
47 |
CsmaTopology::CreateCsmaChannel (DataRate (5000000), MilliSeconds (2)); |
|
48 |
||
49 |
uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan, |
|
1529 | 50 |
"08:00:2e:00:00:00"); |
1527 | 51 |
|
52 |
uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan, |
|
1529 | 53 |
"08:00:2e:00:00:01"); |
1527 | 54 |
|
55 |
uint32_t nd2 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan, |
|
1529 | 56 |
"08:00:2e:00:00:02"); |
1527 | 57 |
|
58 |
uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan, |
|
1529 | 59 |
"08:00:2e:00:00:03"); |
1527 | 60 |
|
1529 | 61 |
CsmaIpv4Topology::AddIpv4Address (n0, nd0, "10.1.1.1", "255.255.255.0"); |
62 |
CsmaIpv4Topology::AddIpv4Address (n1, nd1, "10.1.1.2", "255.255.255.0"); |
|
63 |
CsmaIpv4Topology::AddIpv4Address (n2, nd2, "10.1.1.3", "255.255.255.0"); |
|
64 |
CsmaIpv4Topology::AddIpv4Address (n3, nd3, "10.1.1.4", "255.255.255.0"); |
|
1527 | 65 |
|
66 |
uint16_t port = 7; |
|
67 |
||
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
|
68 |
Ptr<UdpEchoClient> client = CreateObject<UdpEchoClient> (n0, "10.1.1.2", port, |
1529 | 69 |
1, Seconds(1.), 1024); |
1527 | 70 |
|
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
|
71 |
Ptr<UdpEchoServer> server = CreateObject<UdpEchoServer> (n1, port); |
1527 | 72 |
|
73 |
server->Start(Seconds(1.)); |
|
74 |
client->Start(Seconds(2.)); |
|
75 |
||
76 |
server->Stop (Seconds(10.)); |
|
77 |
client->Stop (Seconds(10.)); |
|
78 |
||
79 |
Simulator::Run (); |
|
80 |
Simulator::Destroy (); |
|
81 |
} |