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