A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
netanim-test.cc
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  {
115  AddTestCase (new AnimationInterfaceTestCase (), TestCase::QUICK);
116  }
117 } g_animationInterfaceTestSuite;
118 
119 } // namespace ns3
holds a vector of ns3::Application pointers.
virtual ~AnimationInterfaceTestCase()
Destructor.
Definition: netanim-test.cc:58
holds a vector of std::pair of Ptr<Ipv4> and interface index.
hold variables of type string
Definition: string.h:19
A suite of tests to run.
Definition: test.h:962
create an application which sends a udp packet and waits for an echo of this packet ...
static void Run(void)
Definition: simulator.cc:157
aggregate IP/TCP/UDP functionality to existing Nodes.
Build a set of PointToPointNetDevice objects.
encapsulates test code
Definition: test.h:834
void SetDeviceAttribute(std::string name, const AttributeValue &value)
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
Definition: test.cc:354
ApplicationContainer Install(Ptr< Node > node) const
static void SetConstantPosition(Ptr< Node > n, double x, double y, double z=0)
Helper function to set Constant Position for a given node.
Create a server application which waits for input udp packets and sends them back to the original sen...
hold objects of type ns3::Time
Definition: nstime.h:700
AnimationInterfaceTestCase()
Constructor.
Definition: netanim-test.cc:53
Hold an unsigned integer type.
Definition: uinteger.h:46
holds a vector of ns3::NetDevice pointers
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
static void Destroy(void)
Definition: simulator.cc:121
virtual void DoRun(void)
Run unit tests for this class.
Definition: netanim-test.cc:62
keep track of a set of node pointers.
void Install(std::string nodeName) const
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
Definition: test.cc:172
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Interface to network animator.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void SetAttribute(std::string name, const AttributeValue &value)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const