A Discrete-Event Network Simulator
API
point-to-point-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include "ns3/test.h"
22 #include "ns3/drop-tail-queue.h"
23 #include "ns3/simulator.h"
24 #include "ns3/point-to-point-net-device.h"
25 #include "ns3/point-to-point-channel.h"
26 #include "ns3/net-device-queue-interface.h"
27 
28 using namespace ns3;
29 
36 class PointToPointTest : public TestCase
37 {
38 public:
43 
47  virtual void DoRun (void);
48 
49 private:
56 };
57 
59  : TestCase ("PointToPoint")
60 {
61 }
62 
63 void
65 {
66  Ptr<Packet> p = Create<Packet> ();
67  device->Send (p, device->GetBroadcast (), 0x800);
68 }
69 
70 
71 void
73 {
74  Ptr<Node> a = CreateObject<Node> ();
75  Ptr<Node> b = CreateObject<Node> ();
76  Ptr<PointToPointNetDevice> devA = CreateObject<PointToPointNetDevice> ();
77  Ptr<PointToPointNetDevice> devB = CreateObject<PointToPointNetDevice> ();
78  Ptr<PointToPointChannel> channel = CreateObject<PointToPointChannel> ();
79 
80  devA->Attach (channel);
81  devA->SetAddress (Mac48Address::Allocate ());
82  devA->SetQueue (CreateObject<DropTailQueue<Packet> > ());
83  devB->Attach (channel);
84  devB->SetAddress (Mac48Address::Allocate ());
85  devB->SetQueue (CreateObject<DropTailQueue<Packet> > ());
86 
87  a->AddDevice (devA);
88  b->AddDevice (devB);
89 
90  Simulator::Schedule (Seconds (1.0), &PointToPointTest::SendOnePacket, this, devA);
91 
92  Simulator::Run ();
93 
94  Simulator::Destroy ();
95 }
96 
101 {
102 public:
107 };
108 
110  : TestSuite ("devices-point-to-point", UNIT)
111 {
112  AddTestCase (new PointToPointTest, TestCase::QUICK);
113 }
114 
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:1342
virtual Address GetBroadcast(void) const
encapsulates test code
Definition: test.h:1155
channel
Definition: third.py:92
void SendOnePacket(Ptr< PointToPointNetDevice > device)
Send one packet to the device specified.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
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:128
PointToPointTestSuite()
Constructor.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
Ptr< T > CreateObject(void)
Create an object by type, with varying number of constructor parameters.
Definition: object.h:528
PointToPointTest()
Create the test.