A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
point-to-point-test.cc
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 
9 class PointToPointTest : public TestCase
10 {
11 public:
13 
14  virtual void DoRun (void);
15 
16 private:
17  void SendOnePacket (Ptr<PointToPointNetDevice> device);
18 };
19 
20 PointToPointTest::PointToPointTest ()
21  : TestCase ("PointToPoint")
22 {
23 }
24 
25 void
26 PointToPointTest::SendOnePacket (Ptr<PointToPointNetDevice> device)
27 {
28  Ptr<Packet> p = Create<Packet> ();
29  device->Send (p, device->GetBroadcast (), 0x800);
30 }
31 
32 
33 void
35 {
36  Ptr<Node> a = CreateObject<Node> ();
37  Ptr<Node> b = CreateObject<Node> ();
38  Ptr<PointToPointNetDevice> devA = CreateObject<PointToPointNetDevice> ();
39  Ptr<PointToPointNetDevice> devB = CreateObject<PointToPointNetDevice> ();
40  Ptr<PointToPointChannel> channel = CreateObject<PointToPointChannel> ();
41 
42  devA->Attach (channel);
43  devA->SetAddress (Mac48Address::Allocate ());
44  devA->SetQueue (CreateObject<DropTailQueue> ());
45  devB->Attach (channel);
46  devB->SetAddress (Mac48Address::Allocate ());
47  devB->SetQueue (CreateObject<DropTailQueue> ());
48 
49  a->AddDevice (devA);
50  b->AddDevice (devB);
51 
52  Simulator::Schedule (Seconds (1.0), &PointToPointTest::SendOnePacket, this, devA);
53 
54  Simulator::Run ();
55 
56  Simulator::Destroy ();
57 }
58 //-----------------------------------------------------------------------------
60 {
61 public:
63 };
64 
65 PointToPointTestSuite::PointToPointTestSuite ()
66  : TestSuite ("devices-point-to-point", UNIT)
67 {
68  AddTestCase (new PointToPointTest, TestCase::QUICK);
69 }
70 
71 static PointToPointTestSuite g_pointToPointTestSuite;
virtual void DoRun(void)
Implementation to actually run this test case.
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
A suite of tests to run.
Definition: test.h:962
encapsulates test code
Definition: test.h:834
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
Definition: test.cc:172
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
uint32_t AddDevice(Ptr< NetDevice > device)
Definition: node.cc:119
virtual Address GetBroadcast(void) const