A Discrete-Event Network Simulator
API
point-to-point-test.cc
Go to the documentation of this file.
1 #include "ns3/test.h"
2 #include "ns3/drop-tail-queue.h"
3 #include "ns3/simulator.h"
4 #include "ns3/point-to-point-net-device.h"
5 #include "ns3/point-to-point-channel.h"
6 
7 using namespace ns3;
8 
15 class PointToPointTest : public TestCase
16 {
17 public:
22 
26  virtual void DoRun (void);
27 
28 private:
35 };
36 
38  : TestCase ("PointToPoint")
39 {
40 }
41 
42 void
44 {
45  Ptr<Packet> p = Create<Packet> ();
46  device->Send (p, device->GetBroadcast (), 0x800);
47 }
48 
49 
50 void
52 {
53  Ptr<Node> a = CreateObject<Node> ();
54  Ptr<Node> b = CreateObject<Node> ();
55  Ptr<PointToPointNetDevice> devA = CreateObject<PointToPointNetDevice> ();
56  Ptr<PointToPointNetDevice> devB = CreateObject<PointToPointNetDevice> ();
57  Ptr<PointToPointChannel> channel = CreateObject<PointToPointChannel> ();
58 
59  devA->Attach (channel);
60  devA->SetAddress (Mac48Address::Allocate ());
61  devA->SetQueue (CreateObject<DropTailQueue> ());
62  devB->Attach (channel);
63  devB->SetAddress (Mac48Address::Allocate ());
64  devB->SetQueue (CreateObject<DropTailQueue> ());
65 
66  a->AddDevice (devA);
67  b->AddDevice (devB);
68 
69  Simulator::Schedule (Seconds (1.0), &PointToPointTest::SendOnePacket, this, devA);
70 
71  Simulator::Run ();
72 
73  Simulator::Destroy ();
74 }
75 
80 {
81 public:
86 };
87 
89  : TestSuite ("devices-point-to-point", UNIT)
90 {
91  AddTestCase (new PointToPointTest, TestCase::QUICK);
92 }
93 
virtual void DoRun(void)
Run the test.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Test class for PointToPoint model.
A suite of tests to run.
Definition: test.h:1276
encapsulates test code
Definition: test.h:1108
void SendOnePacket(Ptr< PointToPointNetDevice > device)
Send one packet to the device specified.
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:190
static PointToPointTestSuite g_pointToPointTestSuite
The testsuite.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SendOnePacket(Ptr< LrWpanPhy > sender, Ptr< LrWpanPhy > receiver)
TestSuite for PointToPoint module.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:121
PointToPointTestSuite()
Constructor.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:866
PointToPointTest()
Create the test.
virtual Address GetBroadcast(void) const