A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
netanim-test.cc
Go to the documentation of this file.
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  * Author: John Abraham <john.abraham@gatech.edu>
17  */
18 
19 #include <iostream>
20 #include "unistd.h"
21 
22 #include "ns3/core-module.h"
23 #include "ns3/network-module.h"
24 #include "ns3/internet-module.h"
25 #include "ns3/point-to-point-module.h"
26 #include "ns3/netanim-module.h"
27 #include "ns3/applications-module.h"
28 #include "ns3/point-to-point-layout-module.h"
29 
30 namespace ns3 {
31 
33 {
34 public:
42  virtual
48  virtual void
49  DoRun (void);
50 
51 };
52 
54  TestCase ("Verify AnimationInterface")
55 {
56 }
57 
59 {
60 }
61 void
63 {
64  NodeContainer nodes;
65  nodes.Create (2);
66  AnimationInterface::SetConstantPosition (nodes.Get (0), 0 , 10);
67  AnimationInterface::SetConstantPosition (nodes.Get (1), 1 , 10);
68 
69  PointToPointHelper pointToPoint;
70  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
71  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
72 
73  NetDeviceContainer devices;
74  devices = pointToPoint.Install (nodes);
75 
76  InternetStackHelper stack;
77  stack.Install (nodes);
78 
79  Ipv4AddressHelper address;
80  address.SetBase ("10.1.1.0", "255.255.255.0");
81 
82  Ipv4InterfaceContainer interfaces = address.Assign (devices);
83 
84  UdpEchoServerHelper echoServer (9);
85 
86  ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
87  serverApps.Start (Seconds (1.0));
88  serverApps.Stop (Seconds (10.0));
89 
90  UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
91  echoClient.SetAttribute ("MaxPackets", UintegerValue (100));
92  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
93  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
94 
95  ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
96  clientApps.Start (Seconds (2.0));
97  clientApps.Stop (Seconds (10.0));
98  std::string traceFileName = "netanim-test.xml";
99  AnimationInterface anim(traceFileName.c_str ());
100  Simulator::Run ();
101  NS_TEST_ASSERT_MSG_EQ (anim.GetTracePktCount (), 32, "Expected 32 packets traced");
102  FILE * fp = fopen (traceFileName.c_str (), "r");
103  NS_TEST_ASSERT_MSG_NE (fp, 0, "Trace file was not created");
104  fclose (fp);
105  unlink (traceFileName.c_str ());
107 }
108 
110 {
111 public:
113  TestSuite ("animation-interface", UNIT)
114  {
116  }
118 
119 } // namespace ns3