A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
point-to-point
test
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
:
42
PointToPointTest
();
43
47
virtual
void
DoRun (
void
);
48
49
private
:
55
void
SendOnePacket
(
Ptr<PointToPointNetDevice>
device);
56
};
57
58
PointToPointTest::PointToPointTest
()
59
:
TestCase
(
"PointToPoint"
)
60
{
61
}
62
63
void
64
PointToPointTest::SendOnePacket
(
Ptr<PointToPointNetDevice>
device)
65
{
66
Ptr<Packet>
p = Create<Packet> ();
67
device->
Send
(p, device->
GetBroadcast
(), 0x800);
68
}
69
70
71
void
72
PointToPointTest::DoRun
(
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
Ptr<NetDeviceQueueInterface>
ifaceA = CreateObject<NetDeviceQueueInterface> ();
91
devA->AggregateObject (ifaceA);
92
ifaceA->
CreateTxQueues
();
93
Ptr<NetDeviceQueueInterface>
ifaceB = CreateObject<NetDeviceQueueInterface> ();
94
devB->AggregateObject (ifaceB);
95
ifaceB->
CreateTxQueues
();
96
97
Simulator::Schedule (
Seconds
(1.0), &
PointToPointTest::SendOnePacket
,
this
, devA);
98
99
Simulator::Run ();
100
101
Simulator::Destroy ();
102
}
103
107
class
PointToPointTestSuite
:
public
TestSuite
108
{
109
public
:
113
PointToPointTestSuite
();
114
};
115
116
PointToPointTestSuite::PointToPointTestSuite
()
117
:
TestSuite
(
"devices-point-to-point"
, UNIT)
118
{
119
AddTestCase
(
new
PointToPointTest
, TestCase::QUICK);
120
}
121
122
static
PointToPointTestSuite
g_pointToPointTestSuite
;
PointToPointTest::DoRun
virtual void DoRun(void)
Run the test.
Definition:
point-to-point-test.cc:72
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:73
PointToPointTest
Test class for PointToPoint model.
Definition:
point-to-point-test.cc:36
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1342
ns3::PointToPointNetDevice::GetBroadcast
virtual Address GetBroadcast(void) const
Definition:
point-to-point-net-device.cc:501
ns3::TestCase
encapsulates test code
Definition:
test.h:1155
third.channel
channel
Definition:
third.py:85
PointToPointTest::SendOnePacket
void SendOnePacket(Ptr< PointToPointNetDevice > device)
Send one packet to the device specified.
Definition:
point-to-point-test.cc:64
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:299
g_pointToPointTestSuite
static PointToPointTestSuite g_pointToPointTestSuite
The testsuite.
Definition:
point-to-point-test.cc:122
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
SendOnePacket
void SendOnePacket(Ptr< LrWpanPhy > sender, Ptr< LrWpanPhy > receiver)
Definition:
lr-wpan-phy-test.cc:48
PointToPointTestSuite
TestSuite for PointToPoint module.
Definition:
point-to-point-test.cc:107
ns3::PointToPointNetDevice::Send
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Definition:
point-to-point-net-device.cc:543
ns3::Node::AddDevice
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition:
node.cc:128
PointToPointTestSuite::PointToPointTestSuite
PointToPointTestSuite()
Constructor.
Definition:
point-to-point-test.cc:116
ns3::NetDeviceQueueInterface::CreateTxQueues
void CreateTxQueues(void)
Create the device transmission queues.
Definition:
net-device-queue-interface.cc:221
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1014
ns3::DropTailQueue< Packet >
ns3::CreateObject
Ptr< T > CreateObject(void)
Create an object by type, with varying number of constructor parameters.
Definition:
object.h:528
PointToPointTest::PointToPointTest
PointToPointTest()
Create the test.
Definition:
point-to-point-test.cc:58
Generated on Wed Nov 7 2018 10:02:09 for ns-3 by
1.8.14