Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | |
Peter Barnes
2014/09/12 20:33:50
(See patch-3 comment.)
mjf.alenazi
2014/09/18 00:34:26
Done.
| |
2 | |
3 // An essential include is test.h | |
4 #include "ns3/epidemic-routing-protocol.h" | |
5 #include <vector> | |
6 #include "ns3/ptr.h" | |
7 #include "ns3/boolean.h" | |
8 #include "ns3/test.h" | |
9 #include "ns3/ipv4-route.h" | |
10 #include "ns3/mesh-helper.h" | |
Peter Barnes
2014/09/12 20:33:50
(See patch-3 comment.)
mjf.alenazi
2014/09/18 00:34:26
Done.
| |
11 #include "ns3/simulator.h" | |
12 #include "ns3/double.h" | |
13 #include "ns3/uinteger.h" | |
14 #include "ns3/string.h" | |
15 #include "ns3/ipv4-address-helper.h" | |
16 #include "ns3/network-module.h" | |
17 #include "ns3/applications-module.h" | |
18 #include "ns3/mobility-module.h" | |
19 #include "ns3/wifi-module.h" | |
20 #include "ns3/internet-module.h" | |
21 #include "ns3/epidemic-helper.h" | |
22 #include "ns3/socket.h" | |
23 #include "ns3/log.h" | |
24 | |
25 | |
26 using namespace ns3; | |
27 using namespace Epidemic; | |
28 | |
29 | |
30 class EpidemicHeaderTestCase : public TestCase | |
31 { | |
32 public: | |
33 EpidemicHeaderTestCase (); | |
34 virtual ~EpidemicHeaderTestCase (); | |
35 | |
36 private: | |
37 virtual void DoRun (void); | |
38 }; | |
39 | |
40 | |
41 EpidemicHeaderTestCase::EpidemicHeaderTestCase () | |
42 : TestCase ("Verifying the Epidemic header") | |
43 { | |
44 } | |
45 | |
46 | |
47 EpidemicHeaderTestCase::~EpidemicHeaderTestCase () | |
48 { | |
49 } | |
50 | |
51 void | |
52 EpidemicHeaderTestCase::DoRun (void) | |
53 { | |
54 Ptr<Packet> packet = Create<Packet> (); | |
55 Time ts1 = Simulator::Now (); | |
56 | |
57 EpidemicHeader header1; | |
58 header1.SetPacketID (12345); | |
59 header1.SetTimeStamp (ts1); | |
60 header1.SetHopCount (10); | |
61 packet->AddHeader (header1); | |
62 | |
63 EpidemicHeader header2; | |
64 packet->RemoveHeader (header2); | |
65 | |
66 NS_TEST_ASSERT_MSG_EQ (header2.GetSerializedSize (),16,"Checking Header Size") ; | |
67 NS_TEST_ASSERT_MSG_EQ (header2.GetPacketID (),12345,"Checking Packet ID"); | |
68 NS_TEST_ASSERT_MSG_EQ (header2.GetTimeStamp (),ts1,"Checking TimeStamp"); | |
69 NS_TEST_ASSERT_MSG_EQ (header2.GetHopCount (),10,"Checking hop count"); | |
Peter Barnes
2014/09/12 20:33:50
(See patch-3 comment.)
mjf.alenazi
2014/09/18 00:34:26
Again, I can not write more because I do not know
| |
70 | |
71 } | |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | |
78 struct EpidemicRqueueTest : public TestCase | |
79 { | |
80 EpidemicRqueueTest () : TestCase ("EpidemicQueue"), | |
81 q (64) | |
82 { | |
83 } | |
84 virtual void DoRun (); | |
85 void Unicast (Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header & header) | |
86 { | |
87 } | |
88 void Error (Ptr<const Packet>, const Ipv4Header &, Socket::SocketErrno) | |
89 { | |
90 } | |
91 void CheckSizeLimit (); | |
92 void CheckTimeout (); | |
93 PacketQueue q; | |
94 }; | |
95 | |
96 void | |
97 EpidemicRqueueTest::DoRun () | |
98 { | |
99 NS_TEST_EXPECT_MSG_EQ (q.GetMaxQueueLen (), 64, "Checking the default size for queue length"); | |
100 q.SetMaxQueueLen (32); | |
101 NS_TEST_EXPECT_MSG_EQ (q.GetMaxQueueLen (), 32, "Checking the set function for queue length"); | |
102 | |
103 | |
104 Ptr<const Packet> packet = Create<Packet> (); | |
105 Ipv4Header h; | |
106 h.SetDestination (Ipv4Address ("1.2.3.4")); | |
107 h.SetSource (Ipv4Address ("4.3.2.1")); | |
108 Ipv4RoutingProtocol::UnicastForwardCallback ucb = MakeCallback (&EpidemicRqueu eTest::Unicast, this); | |
109 Ipv4RoutingProtocol::ErrorCallback ecb = MakeCallback (&EpidemicRqueueTest::Er ror, this); | |
110 | |
111 QueueEntry e1 (packet, h, ucb, ecb, Seconds (1),1111); | |
112 q.Enqueue (e1); | |
113 q.Enqueue (e1); | |
114 q.Enqueue (e1); | |
115 NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 1, "Checking if enqueue removes duplicat es"); | |
116 | |
117 h.SetDestination (Ipv4Address ("2.2.2.2")); | |
118 QueueEntry e2 (packet, h, ucb, ecb, Seconds (1),2222); | |
119 q.Enqueue (e1); | |
120 q.Enqueue (e2); | |
121 Ptr<Packet> packet2 = Create<Packet> (); | |
122 QueueEntry e3 (packet2, h, ucb, ecb, Seconds (1),3333); | |
123 q.Enqueue (e2); | |
124 q.Enqueue (e3); | |
125 NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 3, "Checking the queue size function afte r multiple enqueue"); | |
126 QueueEntry e4; | |
127 q.Dequeue (e4); | |
128 NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 2, "Checking the queue size function afte r dequeue function is called"); | |
129 NS_TEST_EXPECT_MSG_EQ (e4.GetPacketID (), e1.GetPacketID (), "trivial"); | |
130 q.Dequeue (e4); | |
131 NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 1, "Checking the queue size function afte r dequeue function is called"); | |
132 NS_TEST_EXPECT_MSG_EQ (e4.GetPacketID (), e2.GetPacketID (), "Checking the pac ketID for two entries"); | |
133 q.Dequeue (e4); | |
134 NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 0, "Checking if the queue is empty"); | |
135 NS_TEST_EXPECT_MSG_EQ (e4.GetPacketID (), e3.GetPacketID (), "Checking the pac ketID for two entries"); | |
136 NS_TEST_EXPECT_MSG_EQ (q.Dequeue (e4), false, "Checking the dequeue function w ith empty queue"); | |
Peter Barnes
2014/09/12 20:33:50
(See patch-3 comment.)
mjf.alenazi
2014/09/18 00:34:26
Again, I can not write more because I do not know
| |
137 } | |
138 | |
139 | |
140 | |
141 class EpidemicTestSuite : public TestSuite | |
142 { | |
143 public: | |
144 EpidemicTestSuite (); | |
145 }; | |
146 | |
147 EpidemicTestSuite::EpidemicTestSuite () | |
148 : TestSuite ("epidemic", UNIT) | |
149 { | |
150 AddTestCase (new EpidemicHeaderTestCase, TestCase::QUICK); | |
151 AddTestCase (new EpidemicRqueueTest, TestCase::QUICK); | |
Peter Barnes
2014/09/12 20:33:50
(See patch-3 comment.)
mjf.alenazi
2014/09/18 00:34:26
Again, I can not write more because I do not know
| |
152 } | |
153 | |
154 | |
155 static EpidemicTestSuite epidemicTestSuite; | |
156 | |
OLD | NEW |