|
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/point-to-point-channel.h" |
|
21 #include "ns3/mac48-address.h" |
|
22 #include "ns3/point-to-point-net-device.h" |
|
23 #include "ns3/point-to-point-topology.h" |
|
24 #include "ns3/udp-echo-client.h" |
|
25 #include "ns3/udp-echo-server.h" |
|
26 #include "ns3/simulator.h" |
|
27 #include "ns3/nstime.h" |
|
28 #include "ns3/ascii-trace.h" |
|
29 #include "ns3/pcap-trace.h" |
|
30 #include "ns3/global-route-manager.h" |
|
31 |
|
32 NS_LOG_COMPONENT_DEFINE ("PointToPointSimulation"); |
|
33 |
|
34 using namespace ns3; |
|
35 |
|
36 // Network topology |
|
37 // |
|
38 // point to point |
|
39 // +--------------+ |
|
40 // | | |
|
41 // n0 n1 |
|
42 // |
|
43 int |
|
44 main (int argc, char *argv[]) |
|
45 { |
|
46 LogComponentEnable ("PointToPointSimulation", LOG_LEVEL_INFO); |
|
47 |
|
48 NS_LOG_INFO ("Point to Point Topology Simulation"); |
|
49 |
|
50 Ptr<Node> n0 = Create<InternetNode> (); |
|
51 Ptr<Node> n1 = Create<InternetNode> (); |
|
52 |
|
53 Ptr<PointToPointChannel> link = PointToPointTopology::AddPointToPointLink ( |
|
54 n0, n1, DataRate (38400), MilliSeconds (20)); |
|
55 |
|
56 PointToPointTopology::AddIpv4Addresses (link, n0, "10.1.1.1", |
|
57 n1, "10.1.1.2"); |
|
58 |
|
59 uint16_t port = 7; |
|
60 |
|
61 Ptr<UdpEchoClient> client = Create<UdpEchoClient> (n0, "10.1.1.2", port, |
|
62 1, Seconds(1.), 1024); |
|
63 |
|
64 Ptr<UdpEchoServer> server = Create<UdpEchoServer> (n1, port); |
|
65 |
|
66 server->Start(Seconds(1.)); |
|
67 client->Start(Seconds(2.)); |
|
68 |
|
69 server->Stop (Seconds(10.)); |
|
70 client->Stop (Seconds(10.)); |
|
71 |
|
72 AsciiTrace asciitrace ("tutorial.tr"); |
|
73 asciitrace.TraceAllQueues (); |
|
74 asciitrace.TraceAllNetDeviceRx (); |
|
75 |
|
76 Simulator::Run (); |
|
77 Simulator::Destroy (); |
|
78 } |