A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
point-to-point-channel.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007, 2008 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
8
10
11#include "ns3/log.h"
12#include "ns3/packet.h"
13#include "ns3/simulator.h"
14#include "ns3/trace-source-accessor.h"
15
16namespace ns3
17{
18
19NS_LOG_COMPONENT_DEFINE("PointToPointChannel");
20
21NS_OBJECT_ENSURE_REGISTERED(PointToPointChannel);
22
23TypeId
25{
26 static TypeId tid =
27 TypeId("ns3::PointToPointChannel")
29 .SetGroupName("PointToPoint")
30 .AddConstructor<PointToPointChannel>()
31 .AddAttribute("Delay",
32 "Propagation delay through the channel",
36 .AddTraceSource("TxRxPointToPoint",
37 "Trace source indicating transmission of packet "
38 "from the PointToPointChannel, used by the Animation "
39 "interface.",
41 "ns3::PointToPointChannel::TxRxAnimationCallback");
42 return tid;
43}
44
45//
46// By default, you get a channel that
47// has an "infitely" fast transmission speed and zero delay.
49 : Channel(),
50 m_delay(Seconds(0.)),
51 m_nDevices(0)
52{
54}
55
56void
58{
59 NS_LOG_FUNCTION(this << device);
60 NS_ASSERT_MSG(m_nDevices < N_DEVICES, "Only two devices permitted");
61 NS_ASSERT(device);
62
63 m_link[m_nDevices++].m_src = device;
64 //
65 // If we have both devices connected to the channel, then finish introducing
66 // the two halves and set the links to IDLE.
67 //
68 if (m_nDevices == N_DEVICES)
69 {
70 m_link[0].m_dst = m_link[1].m_src;
71 m_link[1].m_dst = m_link[0].m_src;
72 m_link[0].m_state = IDLE;
73 m_link[1].m_state = IDLE;
74 }
75}
76
77bool
79{
80 NS_LOG_FUNCTION(this << p << src);
81 NS_LOG_LOGIC("UID is " << p->GetUid() << ")");
82
83 NS_ASSERT(m_link[0].m_state != INITIALIZING);
84 NS_ASSERT(m_link[1].m_state != INITIALIZING);
85
86 uint32_t wire = src == m_link[0].m_src ? 0 : 1;
87
88 Simulator::ScheduleWithContext(m_link[wire].m_dst->GetNode()->GetId(),
89 txTime + m_delay,
91 m_link[wire].m_dst,
92 p->Copy());
93
94 // Call the tx anim callback on the net device
95 m_txrxPointToPoint(p, src, m_link[wire].m_dst, txTime, txTime + m_delay);
96 return true;
97}
98
99std::size_t
105
108{
110 NS_ASSERT(i < 2);
111 return m_link[i].m_src;
112}
113
116{
118 return GetPointToPointDevice(i);
119}
120
121Time
123{
124 return m_delay;
125}
126
129{
130 return m_link[i].m_src;
131}
132
138
139bool
141{
142 NS_ASSERT(m_link[0].m_state != INITIALIZING);
143 NS_ASSERT(m_link[1].m_state != INITIALIZING);
144 return true;
145}
146
147} // namespace ns3
Abstract Channel Base Class.
Definition channel.h:34
Simple Point To Point Channel.
Time GetDelay() const
Get the delay associated with this channel.
static TypeId GetTypeId()
Get the TypeId.
Link m_link[N_DEVICES]
Link model.
std::size_t m_nDevices
Devices of this channel.
void Attach(Ptr< PointToPointNetDevice > device)
Attach a given netdevice to this channel.
Ptr< PointToPointNetDevice > GetSource(uint32_t i) const
Get the net-device source.
std::size_t GetNDevices() const override
Get number of devices on this channel.
Ptr< NetDevice > GetDevice(std::size_t i) const override
Get NetDevice corresponding to index i on this channel.
PointToPointChannel()
Create a PointToPointChannel.
Ptr< PointToPointNetDevice > GetDestination(uint32_t i) const
Get the net-device destination.
@ IDLE
Idle state (no transmission from NetDevice)
@ INITIALIZING
Initializing state.
Ptr< PointToPointNetDevice > GetPointToPointDevice(std::size_t i) const
Get PointToPointNetDevice corresponding to index i on this channel.
bool IsInitialized() const
Check to make sure the link is initialized.
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.
Time m_delay
Propagation delay.
virtual bool TransmitStart(Ptr< const Packet > p, Ptr< PointToPointNetDevice > src, Time txTime)
Transmit a packet over this channel.
static const std::size_t N_DEVICES
Each point to point link has exactly two net devices.
void Receive(Ptr< Packet > p)
Receive a packet from a connected PointToPointChannel.
Smart pointer class similar to boost::intrusive_ptr.
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition simulator.h:577
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#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:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition nstime.h:1396
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1416