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 
27 using namespace ns3;
28 
35 class PointToPointTest : public TestCase
36 {
37 public:
42 
46  virtual void DoRun (void);
47 
48 private:
55 };
56 
58  : TestCase ("PointToPoint")
59 {
60 }
61 
62 void
64 {
65  Ptr<Packet> p = Create<Packet> ();
66  device->Send (p, device->GetBroadcast (), 0x800);
67 }
68 
69 
70 void
72 {
73  Ptr<Node> a = CreateObject<Node> ();
74  Ptr<Node> b = CreateObject<Node> ();
75  Ptr<PointToPointNetDevice> devA = CreateObject<PointToPointNetDevice> ();
76  Ptr<PointToPointNetDevice> devB = CreateObject<PointToPointNetDevice> ();
77  Ptr<PointToPointChannel> channel = CreateObject<PointToPointChannel> ();
78 
79  devA->Attach (channel);
80  devA->SetAddress (Mac48Address::Allocate ());
81  devA->SetQueue (CreateObject<DropTailQueue> ());
82  devB->Attach (channel);
83  devB->SetAddress (Mac48Address::Allocate ());
84  devB->SetQueue (CreateObject<DropTailQueue> ());
85 
86  a->AddDevice (devA);
87  b->AddDevice (devB);
88 
89  Ptr<NetDeviceQueueInterface> ifaceA = CreateObject<NetDeviceQueueInterface> ();
90  devA->AggregateObject (ifaceA);
91  ifaceA->CreateTxQueues ();
92  Ptr<NetDeviceQueueInterface> ifaceB = CreateObject<NetDeviceQueueInterface> ();
93  devB->AggregateObject (ifaceB);
94  ifaceB->CreateTxQueues ();
95 
96  Simulator::Schedule (Seconds (1.0), &PointToPointTest::SendOnePacket, this, devA);
97 
98  Simulator::Run ();
99 
100  Simulator::Destroy ();
101 }
102 
107 {
108 public:
113 };
114 
116  : TestSuite ("devices-point-to-point", UNIT)
117 {
118  AddTestCase (new PointToPointTest, TestCase::QUICK);
119 }
120 
tuple channel
Definition: third.py:85
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:1333
encapsulates test code
Definition: test.h:1147
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:298
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.
void CreateTxQueues(void)
Create the device transmission queues.
Definition: net-device.cc:242
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
PointToPointTest()
Create the test.
virtual Address GetBroadcast(void) const