A Discrete-Event Network Simulator
API
point-to-point-channel.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007, 2008 University of Washington
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 
19 #include "point-to-point-channel.h"
21 #include "ns3/trace-source-accessor.h"
22 #include "ns3/packet.h"
23 #include "ns3/simulator.h"
24 #include "ns3/log.h"
25 
26 namespace ns3 {
27 
28 NS_LOG_COMPONENT_DEFINE ("PointToPointChannel");
29 
30 NS_OBJECT_ENSURE_REGISTERED (PointToPointChannel);
31 
32 TypeId
34 {
35  static TypeId tid = TypeId ("ns3::PointToPointChannel")
36  .SetParent<Channel> ()
37  .SetGroupName ("PointToPoint")
38  .AddConstructor<PointToPointChannel> ()
39  .AddAttribute ("Delay", "Propagation delay through the channel",
40  TimeValue (Seconds (0)),
42  MakeTimeChecker ())
43  .AddTraceSource ("TxRxPointToPoint",
44  "Trace source indicating transmission of packet "
45  "from the PointToPointChannel, used by the Animation "
46  "interface.",
48  "ns3::PointToPointChannel::TxRxAnimationCallback")
49  ;
50  return tid;
51 }
52 
53 //
54 // By default, you get a channel that
55 // has an "infitely" fast transmission speed and zero delay.
57  :
58  Channel (),
59  m_delay (Seconds (0.)),
60  m_nDevices (0)
61 {
63 }
64 
65 void
67 {
68  NS_LOG_FUNCTION (this << device);
69  NS_ASSERT_MSG (m_nDevices < N_DEVICES, "Only two devices permitted");
70  NS_ASSERT (device != 0);
71 
72  m_link[m_nDevices++].m_src = device;
73 //
74 // If we have both devices connected to the channel, then finish introducing
75 // the two halves and set the links to IDLE.
76 //
77  if (m_nDevices == N_DEVICES)
78  {
79  m_link[0].m_dst = m_link[1].m_src;
80  m_link[1].m_dst = m_link[0].m_src;
81  m_link[0].m_state = IDLE;
82  m_link[1].m_state = IDLE;
83  }
84 }
85 
86 bool
90  Time txTime)
91 {
92  NS_LOG_FUNCTION (this << p << src);
93  NS_LOG_LOGIC ("UID is " << p->GetUid () << ")");
94 
95  NS_ASSERT (m_link[0].m_state != INITIALIZING);
96  NS_ASSERT (m_link[1].m_state != INITIALIZING);
97 
98  uint32_t wire = src == m_link[0].m_src ? 0 : 1;
99 
100  Simulator::ScheduleWithContext (m_link[wire].m_dst->GetNode ()->GetId (),
102  m_link[wire].m_dst, p->Copy ());
103 
104  // Call the tx anim callback on the net device
105  m_txrxPointToPoint (p, src, m_link[wire].m_dst, txTime, txTime + m_delay);
106  return true;
107 }
108 
109 std::size_t
111 {
113  return m_nDevices;
114 }
115 
118 {
120  NS_ASSERT (i < 2);
121  return m_link[i].m_src;
122 }
123 
125 PointToPointChannel::GetDevice (std::size_t i) const
126 {
128  return GetPointToPointDevice (i);
129 }
130 
131 Time
133 {
134  return m_delay;
135 }
136 
139 {
140  return m_link[i].m_src;
141 }
142 
145 {
146  return m_link[i].m_dst;
147 }
148 
149 bool
151 {
152  NS_ASSERT (m_link[0].m_state != INITIALIZING);
153  NS_ASSERT (m_link[1].m_state != INITIALIZING);
154  return true;
155 }
156 
157 } // namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::PointToPointChannel::Attach
void Attach(Ptr< PointToPointNetDevice > device)
Attach a given netdevice to this channel.
Definition: point-to-point-channel.cc:66
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
NS_ASSERT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
ns3::MakeTimeChecker
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:533
ns3::Simulator::ScheduleWithContext
static void ScheduleWithContext(uint32_t context, Time const &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition: simulator.h:571
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::PointToPointChannel::GetTypeId
static TypeId GetTypeId(void)
Get the TypeId.
Definition: point-to-point-channel.cc:33
ns3::PointToPointChannel::IDLE
@ IDLE
Idle state (no transmission from NetDevice)
Definition: point-to-point-channel.h:181
ns3::PointToPointChannel
Simple Point To Point Channel.
Definition: point-to-point-channel.h:51
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::PointToPointChannel::m_delay
Time m_delay
Propagation delay.
Definition: point-to-point-channel.h:152
ns3::PointToPointChannel::GetDevice
virtual Ptr< NetDevice > GetDevice(std::size_t i) const
Get NetDevice corresponding to index i on this channel.
Definition: point-to-point-channel.cc:125
ns3::MakeTraceSourceAccessor
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Definition: trace-source-accessor.h:202
ns3::PointToPointChannel::INITIALIZING
@ INITIALIZING
Initializing state.
Definition: point-to-point-channel.h:179
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::PointToPointChannel::GetNDevices
virtual std::size_t GetNDevices(void) const
Get number of devices on this channel.
Definition: point-to-point-channel.cc:110
ns3::PointToPointChannel::GetDelay
Time GetDelay(void) const
Get the delay associated with this channel.
Definition: point-to-point-channel.cc:132
point-to-point-net-device.h
ns3::PointToPointChannel::m_txrxPointToPoint
TracedCallback< Ptr< const Packet >, Ptr< NetDevice >, Ptr< NetDevice >, Time, Time > m_txrxPointToPoint
The trace source for the packet transmission animation events that the device can fire.
Definition: point-to-point-channel.h:171
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
NS_ASSERT_MSG
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
ns3::PointToPointChannel::GetPointToPointDevice
Ptr< PointToPointNetDevice > GetPointToPointDevice(std::size_t i) const
Get PointToPointNetDevice corresponding to index i on this channel.
Definition: point-to-point-channel.cc:117
ns3::PointToPointNetDevice::Receive
void Receive(Ptr< Packet > p)
Receive a packet from a connected PointToPointChannel.
Definition: point-to-point-net-device.cc:332
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition: log-macros-enabled.h:209
ns3::PointToPointChannel::GetDestination
Ptr< PointToPointNetDevice > GetDestination(uint32_t i) const
Get the net-device destination.
Definition: point-to-point-channel.cc:144
ns3::PointToPointChannel::m_nDevices
std::size_t m_nDevices
Devices of this channel.
Definition: point-to-point-channel.h:153
ns3::PointToPointChannel::PointToPointChannel
PointToPointChannel()
Create a PointToPointChannel.
Definition: point-to-point-channel.cc:56
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::PointToPointChannel::IsInitialized
bool IsInitialized(void) const
Check to make sure the link is initialized.
Definition: point-to-point-channel.cc:150
ns3::Packet::Copy
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
point-to-point-channel.h
ns3::Channel
Abstract Channel Base Class.
Definition: channel.h:44
ns3::TimeValue
AttributeValue implementation for Time.
Definition: nstime.h:1353
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::PointToPointChannel::N_DEVICES
static const std::size_t N_DEVICES
Each point to point link has exactly two net devices.
Definition: point-to-point-channel.h:150
ns3::PointToPointChannel::GetSource
Ptr< PointToPointNetDevice > GetSource(uint32_t i) const
Get the net-device source.
Definition: point-to-point-channel.cc:138
ns3::PointToPointChannel::TransmitStart
virtual bool TransmitStart(Ptr< const Packet > p, Ptr< PointToPointNetDevice > src, Time txTime)
Transmit a packet over this channel.
Definition: point-to-point-channel.cc:87
ns3::MakeTimeAccessor
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: nstime.h:1354
ns3::Packet::GetUid
uint64_t GetUid(void) const
Returns the packet's Uid.
Definition: packet.cc:390
ns3::PointToPointChannel::m_link
Link m_link[N_DEVICES]
Link model.
Definition: point-to-point-channel.h:204