Loading...
Searching...
No Matches
satellite-point-to-point-isl-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 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 * (Based on point-to-point channel)
19 * Author: Andre Aguas March 2020
20 * Adapted to SNS-3 by: Bastien Tauran <bastien.tauran@viveris.fr>
21 *
22 */
23
25
27
28#include "ns3/core-module.h"
29
30#include <cstddef>
31
32NS_LOG_COMPONENT_DEFINE("PointToPointIslChannel");
33
34namespace ns3
35{
36
37NS_OBJECT_ENSURE_REGISTERED(PointToPointIslChannel);
38
39TypeId
41{
42 static TypeId tid =
43 TypeId("ns3::PointToPointIslChannel")
44 .SetParent<Channel>()
45 .AddConstructor<PointToPointIslChannel>()
46 .AddAttribute("PropagationSpeed",
47 "Propagation speed through the channel",
50 MakeDoubleChecker<double>());
51 return tid;
52}
53
55 : Channel(),
56 m_nDevices(0)
57{
58 NS_LOG_FUNCTION(this);
59}
60
61void
62PointToPointIslChannel::Attach(Ptr<PointToPointIslNetDevice> device)
63{
64 NS_LOG_FUNCTION(this << device);
65
66 NS_ASSERT_MSG(m_nDevices < N_DEVICES, "Only two devices permitted");
67 NS_ASSERT(device != nullptr);
68
69 m_link[m_nDevices++].m_src = device;
70 //
71 // If we have both devices connected to the channel, then finish introducing
72 // the two halves and set the links to IDLE.
73 //
74 if (m_nDevices == N_DEVICES)
75 {
76 m_link[0].m_dst = m_link[1].m_src;
77 m_link[1].m_dst = m_link[0].m_src;
78 m_link[0].m_state = IDLE;
79 m_link[1].m_state = IDLE;
80 }
81}
82
83bool
85 Ptr<PointToPointIslNetDevice> src,
86 Ptr<Node> dst,
87 Time txTime)
88{
89 NS_LOG_FUNCTION(this << p << src);
90 NS_LOG_LOGIC("UID is " << p->GetUid() << ")");
91
92 NS_ASSERT(m_link[0].m_state != INITIALIZING);
93 NS_ASSERT(m_link[1].m_state != INITIALIZING);
94
95 Ptr<MobilityModel> senderMobility = src->GetNode()->GetObject<MobilityModel>();
96 Ptr<MobilityModel> receiverMobility = dst->GetObject<MobilityModel>();
97 Time delay = this->GetDelay(senderMobility, receiverMobility);
98
99 uint32_t wire = src == m_link[0].m_src ? 0 : 1;
100
101 Simulator::ScheduleWithContext(m_link[wire].m_dst->GetNode()->GetId(),
102 txTime + delay,
104 m_link[wire].m_dst,
105 p->Copy());
106
107 return true;
108}
109
110std::size_t
112{
113 NS_LOG_FUNCTION(this);
114
115 return m_nDevices;
116}
117
118Ptr<PointToPointIslNetDevice>
120{
121 NS_LOG_FUNCTION(this);
122
123 NS_ASSERT(i < 2);
124 return m_link[i].m_src;
125}
126
127Ptr<NetDevice>
129{
130 NS_LOG_FUNCTION(this);
131
132 return GetPointToPointIslDevice(i);
133}
134
135Time
136PointToPointIslChannel::GetDelay(Ptr<MobilityModel> a, Ptr<MobilityModel> b) const
137{
138 NS_LOG_FUNCTION(this << a << b);
139
140 double distance =
141 DynamicCast<SatMobilityModel>(a)->GetDistanceFrom(DynamicCast<SatMobilityModel>(b));
142 double seconds = distance / m_propagationSpeed;
143 return Seconds(seconds);
144}
145
146Ptr<PointToPointIslNetDevice>
148{
149 NS_LOG_FUNCTION(this << i);
150
151 return m_link[i].m_src;
152}
153
154Ptr<PointToPointIslNetDevice>
156{
157 NS_LOG_FUNCTION(this << i);
158
159 return m_link[i].m_dst;
160}
161
162bool
164{
165 NS_LOG_FUNCTION(this);
166
167 NS_ASSERT(m_link[0].m_state != INITIALIZING);
168 NS_ASSERT(m_link[1].m_state != INITIALIZING);
169 return true;
170}
171
172} // namespace ns3
static TypeId GetTypeId(void)
Get the TypeId.
@ IDLE
Idle state (no transmission from NetDevice).
Time GetDelay(Ptr< MobilityModel > senderMobility, Ptr< MobilityModel > receiverMobility) const
Get the delay between two nodes on this channel.
bool IsInitialized(void) const
Check to make sure the link is initialized.
double m_propagationSpeed
propagation speed on the channel
PointToPointIslChannel()
Create a PointToPointIslChannel.
virtual bool TransmitStart(Ptr< const Packet > p, Ptr< PointToPointIslNetDevice > src, Ptr< Node > dst, Time txTime)
Transmit a packet over this channel.
virtual std::size_t GetNDevices(void) const
Get number of devices on this channel.
Ptr< PointToPointIslNetDevice > GetDestination(uint32_t i) const
Get the destination net-device.
Ptr< PointToPointIslNetDevice > GetSource(uint32_t i) const
Get the source net-device.
void Attach(Ptr< PointToPointIslNetDevice > device)
Attach a given netdevice to this channel.
std::size_t m_nDevices
Devices of this channel.
static const std::size_t N_DEVICES
Each point to point link has exactly two net devices.
Ptr< PointToPointIslNetDevice > GetPointToPointIslDevice(std::size_t i) const
Get PointToPointIslNetDevice corresponding to index i on this channel.
virtual Ptr< NetDevice > GetDevice(std::size_t i) const
Get NetDevice corresponding to index i on this channel.
void Receive(Ptr< Packet > p)
Receive a packet from a connected PointToPointIslChannel.
constexpr double SPEED_OF_LIGHT
Constant definition for the speed of light in m/s.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.