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 
24 #include "ns3/satellite-point-to-point-isl-channel.h"
25 
26 #include "ns3/core-module.h"
27 #include "ns3/satellite-const-variables.h"
28 
29 NS_LOG_COMPONENT_DEFINE("PointToPointIslChannel");
30 
31 namespace ns3
32 {
33 
34 NS_OBJECT_ENSURE_REGISTERED(PointToPointIslChannel);
35 
36 TypeId
38 {
39  static TypeId tid =
40  TypeId("ns3::PointToPointIslChannel")
41  .SetParent<Channel>()
42  .AddConstructor<PointToPointIslChannel>()
43  .AddAttribute("PropagationSpeed",
44  "Propagation speed through the channel",
46  MakeDoubleAccessor(&PointToPointIslChannel::m_propagationSpeed),
47  MakeDoubleChecker<double>());
48  return tid;
49 }
50 
52  : Channel(),
53  m_nDevices(0)
54 {
55  NS_LOG_FUNCTION(this);
56 }
57 
58 void
59 PointToPointIslChannel::Attach(Ptr<PointToPointIslNetDevice> device)
60 {
61  NS_LOG_FUNCTION(this << device);
62 
63  NS_ASSERT_MSG(m_nDevices < N_DEVICES, "Only two devices permitted");
64  NS_ASSERT(device != nullptr);
65 
66  m_link[m_nDevices++].m_src = device;
67  //
68  // If we have both devices connected to the channel, then finish introducing
69  // the two halves and set the links to IDLE.
70  //
71  if (m_nDevices == N_DEVICES)
72  {
73  m_link[0].m_dst = m_link[1].m_src;
74  m_link[1].m_dst = m_link[0].m_src;
75  m_link[0].m_state = IDLE;
76  m_link[1].m_state = IDLE;
77  }
78 }
79 
80 bool
82  Ptr<PointToPointIslNetDevice> src,
83  Ptr<Node> dst,
84  Time txTime)
85 {
86  NS_LOG_FUNCTION(this << p << src);
87  NS_LOG_LOGIC("UID is " << p->GetUid() << ")");
88 
89  NS_ASSERT(m_link[0].m_state != INITIALIZING);
90  NS_ASSERT(m_link[1].m_state != INITIALIZING);
91 
92  Ptr<MobilityModel> senderMobility = src->GetNode()->GetObject<MobilityModel>();
93  Ptr<MobilityModel> receiverMobility = dst->GetObject<MobilityModel>();
94  Time delay = this->GetDelay(senderMobility, receiverMobility);
95 
96  uint32_t wire = src == m_link[0].m_src ? 0 : 1;
97 
98  Simulator::ScheduleWithContext(m_link[wire].m_dst->GetNode()->GetId(),
99  txTime + delay,
101  m_link[wire].m_dst,
102  p->Copy());
103 
104  return true;
105 }
106 
107 std::size_t
109 {
110  NS_LOG_FUNCTION(this);
111 
112  return m_nDevices;
113 }
114 
115 Ptr<PointToPointIslNetDevice>
117 {
118  NS_LOG_FUNCTION(this);
119 
120  NS_ASSERT(i < 2);
121  return m_link[i].m_src;
122 }
123 
124 Ptr<NetDevice>
126 {
127  NS_LOG_FUNCTION(this);
128 
129  return GetPointToPointIslDevice(i);
130 }
131 
132 Time
133 PointToPointIslChannel::GetDelay(Ptr<MobilityModel> a, Ptr<MobilityModel> b) const
134 {
135  NS_LOG_FUNCTION(this << a << b);
136 
137  double distance = a->GetDistanceFrom(b);
138  double seconds = distance / m_propagationSpeed;
139  return Seconds(seconds);
140 }
141 
142 Ptr<PointToPointIslNetDevice>
144 {
145  NS_LOG_FUNCTION(this << i);
146 
147  return m_link[i].m_src;
148 }
149 
150 Ptr<PointToPointIslNetDevice>
152 {
153  NS_LOG_FUNCTION(this << i);
154 
155  return m_link[i].m_dst;
156 }
157 
158 bool
160 {
161  NS_LOG_FUNCTION(this);
162 
163  NS_ASSERT(m_link[0].m_state != INITIALIZING);
164  NS_ASSERT(m_link[1].m_state != INITIALIZING);
165  return true;
166 }
167 
168 } // 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.