Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2014 Universita' di Firenze | 3 * Copyright (c) 2014 Universita' di Firenze |
4 *· | 4 *· |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with this program; if not, write to the Free Software | 15 * along with this program; if not, write to the Free Software |
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it> | 18 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it> |
19 */ | 19 */ |
20 | 20 |
21 #include "ns3/test.h" | 21 #include "ns3/test.h" |
22 #include "ns3/core-module.h" | 22 #include "ns3/core-module.h" |
23 #include "ns3/network-module.h" | 23 #include "ns3/network-module.h" |
Tom Henderson
2014/09/09 20:36:29
do not use "-module" variants here
| |
24 | 24 |
25 using namespace ns3; | 25 using namespace ns3; |
26 | 26 |
27 | 27 |
28 class SimpleAppsTest : public TestCase | 28 class PacketSocketAppsTest : public TestCase |
29 { | 29 { |
30 uint32_t m_receivedPacketSize; | 30 uint32_t m_receivedPacketSize; |
31 uint32_t m_receivedPacketNumber; | 31 uint32_t m_receivedPacketNumber; |
32 | 32 |
33 public: | 33 public: |
34 virtual void DoRun (void); | 34 virtual void DoRun (void); |
35 SimpleAppsTest (); | 35 PacketSocketAppsTest (); |
36 | 36 |
37 void ReceivePkt (Ptr<const Packet> packet, const Address &from); | 37 void ReceivePkt (Ptr<const Packet> packet, const Address &from); |
38 }; | 38 }; |
39 | 39 |
40 SimpleAppsTest::SimpleAppsTest () | 40 PacketSocketAppsTest::PacketSocketAppsTest () |
41 : TestCase ("Simple Apps test") | 41 : TestCase ("Simple Apps test") |
42 { | 42 { |
43 m_receivedPacketSize = 0; | 43 m_receivedPacketSize = 0; |
44 m_receivedPacketNumber = 0; | 44 m_receivedPacketNumber = 0; |
45 } | 45 } |
46 | 46 |
47 void SimpleAppsTest::ReceivePkt (Ptr<const Packet> packet, const Address &from) | 47 void PacketSocketAppsTest::ReceivePkt (Ptr<const Packet> packet, const Address & from) |
48 { | 48 { |
49 if (packet) | 49 if (packet) |
50 { | 50 { |
51 m_receivedPacketSize = packet->GetSize (); | 51 m_receivedPacketSize = packet->GetSize (); |
52 m_receivedPacketNumber++; | 52 m_receivedPacketNumber++; |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 | 56 |
57 void | 57 void |
58 SimpleAppsTest::DoRun (void) | 58 PacketSocketAppsTest::DoRun (void) |
59 { | 59 { |
60 // Create topology | 60 // Create topology |
61 | 61 |
62 NodeContainer nodes; | 62 NodeContainer nodes; |
63 nodes.Create (2); | 63 nodes.Create (2); |
64 | 64 |
65 PacketSocketHelper packetSocket; | 65 PacketSocketHelper packetSocket; |
66 | 66 |
67 // give packet socket powers to nodes. | 67 // give packet socket powers to nodes. |
68 packetSocket.Install (nodes); | 68 packetSocket.Install (nodes); |
(...skipping 11 matching lines...) Expand all Loading... | |
80 rxDev->SetChannel (channel); | 80 rxDev->SetChannel (channel); |
81 txDev->SetNode (nodes.Get (0)); | 81 txDev->SetNode (nodes.Get (0)); |
82 rxDev->SetNode (nodes.Get (1)); | 82 rxDev->SetNode (nodes.Get (1)); |
83 | 83 |
84 | 84 |
85 PacketSocketAddress socketAddr; | 85 PacketSocketAddress socketAddr; |
86 socketAddr.SetSingleDevice (txDev->GetIfIndex ()); | 86 socketAddr.SetSingleDevice (txDev->GetIfIndex ()); |
87 socketAddr.SetPhysicalAddress (rxDev->GetAddress ()); | 87 socketAddr.SetPhysicalAddress (rxDev->GetAddress ()); |
88 socketAddr.SetProtocol (1); | 88 socketAddr.SetProtocol (1); |
89 | 89 |
90 Ptr<SimpleClient> client = CreateObject<SimpleClient> (); | 90 Ptr<PacketSocketClient> client = CreateObject<PacketSocketClient> (); |
91 client->SetRemote (socketAddr); | 91 client->SetRemote (socketAddr); |
92 client->SetAttribute ("PacketSize", UintegerValue (1000)); | 92 client->SetAttribute ("PacketSize", UintegerValue (1000)); |
93 client->SetAttribute ("MaxPackets", UintegerValue (3)); | 93 client->SetAttribute ("MaxPackets", UintegerValue (3)); |
94 nodes.Get (0)->AddApplication (client); | 94 nodes.Get (0)->AddApplication (client); |
95 | 95 |
96 Ptr<SimpleServer> server = CreateObject<SimpleServer> (); | 96 Ptr<PacketSocketServer> server = CreateObject<PacketSocketServer> (); |
97 server->TraceConnectWithoutContext ("Rx", MakeCallback (&SimpleAppsTest::Recei vePkt, this)); | 97 server->TraceConnectWithoutContext ("Rx", MakeCallback (&PacketSocketAppsTest: :ReceivePkt, this)); |
98 server->SetLocal (socketAddr); | |
98 nodes.Get (1)->AddApplication (server); | 99 nodes.Get (1)->AddApplication (server); |
99 | 100 |
100 | 101 |
101 Simulator::Run (); | 102 Simulator::Run (); |
102 Simulator::Destroy (); | 103 Simulator::Destroy (); |
103 | 104 |
104 NS_TEST_EXPECT_MSG_EQ (m_receivedPacketNumber, 3, "Number of packet received") ; | 105 NS_TEST_EXPECT_MSG_EQ (m_receivedPacketNumber, 3, "Number of packet received") ; |
105 NS_TEST_EXPECT_MSG_EQ (m_receivedPacketSize, 1000, "Size of packet received"); | 106 NS_TEST_EXPECT_MSG_EQ (m_receivedPacketSize, 1000, "Size of packet received"); |
106 | 107 |
107 Simulator::Destroy (); | 108 Simulator::Destroy (); |
Tom Henderson
2014/09/09 20:36:28
redundant Destroy() statements.
| |
108 | 109 |
109 } | 110 } |
110 | 111 |
111 | 112 |
112 //----------------------------------------------------------------------------- | 113 //----------------------------------------------------------------------------- |
113 //----------------------------------------------------------------------------- | 114 //----------------------------------------------------------------------------- |
114 class SimpleAppsTestSuite : public TestSuite | 115 class PacketSocketAppsTestSuite : public TestSuite |
115 { | 116 { |
116 public: | 117 public: |
117 SimpleAppsTestSuite () : TestSuite ("simple-apps", UNIT) | 118 PacketSocketAppsTestSuite () : TestSuite ("packet-socket-apps", UNIT) |
118 { | 119 { |
119 AddTestCase (new SimpleAppsTest, TestCase::QUICK); | 120 AddTestCase (new PacketSocketAppsTest, TestCase::QUICK); |
120 } | 121 } |
121 } g_simpleAppsTestSuite; | 122 } g_packetSocketAppsTestSuite; |
LEFT | RIGHT |