satellite-interference.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Magister Solutions Ltd.
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: Sami Rantanen <sami.rantanen@magister.fi>
19  */
20 
21 #include "satellite-interference.h"
22 
23 #include <ns3/log.h>
24 #include <ns3/simulator.h>
25 
26 #include <map>
27 #include <utility>
28 #include <vector>
29 
30 NS_LOG_COMPONENT_DEFINE("SatInterference");
31 
32 namespace ns3
33 {
34 
36  Time rxDuration,
37  double rxPower,
38  Address satEarthStationAddress)
39  : m_startTime(Simulator::Now()),
40  m_endTime(m_startTime + rxDuration),
41  m_rxPower(rxPower),
42  m_id(id),
43  m_satEarthStationAddress(satEarthStationAddress)
44 {
45 }
46 
48 {
49 }
50 
51 uint32_t
53 {
54  NS_LOG_FUNCTION(this);
55 
56  return m_id;
57 }
58 
59 Time
61 {
62  NS_LOG_FUNCTION(this);
63 
64  return m_endTime - m_startTime;
65 }
66 
67 Time
69 {
70  NS_LOG_FUNCTION(this);
71 
72  return m_startTime;
73 }
74 
75 Time
77 {
78  NS_LOG_FUNCTION(this);
79 
80  return m_endTime;
81 }
82 
83 double
85 {
86  NS_LOG_FUNCTION(this);
87 
88  return m_rxPower;
89 }
90 
91 Address
93 {
94  NS_LOG_FUNCTION(this);
95 
96  return m_satEarthStationAddress;
97 }
98 
99 /****************************************************************
100  * The actual SatInterference
101  ****************************************************************/
102 
103 NS_OBJECT_ENSURE_REGISTERED(SatInterference);
104 
105 TypeId
107 {
108  static TypeId tid = TypeId("ns3::SatInterference").SetParent<Object>();
109 
110  return tid;
111 }
112 
113 TypeId
115 {
116  return GetTypeId();
117 }
118 
121 {
122 }
123 
125 {
126 }
127 
128 Ptr<SatInterference::InterferenceChangeEvent>
129 SatInterference::Add(Time duration, double power, Address rxAddress)
130 {
131  NS_LOG_FUNCTION(this << duration.GetSeconds() << power << rxAddress);
132 
133  return DoAdd(duration, power, rxAddress);
134 }
135 
136 std::vector<std::pair<double, double>>
137 SatInterference::Calculate(Ptr<SatInterference::InterferenceChangeEvent> event)
138 {
139  NS_LOG_FUNCTION(this);
140 
141  if (m_currentlyReceiving > 1)
142  {
143  std::map<Ptr<SatInterference::InterferenceChangeEvent>, bool>::iterator iter;
144  bool wasCollisionReported = true;
145 
146  for (iter = m_packetCollisions.begin(); iter != m_packetCollisions.end(); iter++)
147  {
148  if (!iter->second)
149  {
150  wasCollisionReported = false;
151  }
152  iter->second = true;
153  }
154  if (!wasCollisionReported)
155  {
156  NS_LOG_INFO("Packet collision!");
157  }
158  }
159 
160  return DoCalculate(event);
161 }
162 
163 void
165 {
166  NS_LOG_FUNCTION(this);
167 
168  m_packetCollisions.clear();
170 
171  DoReset();
172 }
173 
174 void
175 SatInterference::NotifyRxStart(Ptr<SatInterference::InterferenceChangeEvent> event)
176 {
177  NS_LOG_FUNCTION(this);
178 
180 
181  std::pair<std::map<Ptr<SatInterference::InterferenceChangeEvent>, bool>::iterator, bool> result;
182  result = m_packetCollisions.insert(std::make_pair(event, false));
183 
184  if (!result.second)
185  {
186  NS_FATAL_ERROR("SatInterference::NotifyRxStart - Event already exists");
187  }
188 
189  DoNotifyRxStart(event);
190 }
191 
192 void
193 SatInterference::NotifyRxEnd(Ptr<SatInterference::InterferenceChangeEvent> event)
194 {
195  NS_LOG_FUNCTION(this);
196 
197  if (m_currentlyReceiving > 0)
198  {
200  }
201 
202  m_packetCollisions.erase(event);
203 
204  DoNotifyRxEnd(event);
205 }
206 
207 bool
208 SatInterference::HasCollision(Ptr<SatInterference::InterferenceChangeEvent> event)
209 {
210  NS_LOG_FUNCTION(this);
211 
212  std::map<Ptr<SatInterference::InterferenceChangeEvent>, bool>::iterator result =
213  m_packetCollisions.find(event);
214 
215  if (result == m_packetCollisions.end())
216  {
217  NS_FATAL_ERROR("SatInterference::HasCollision - Event not found");
218  }
219 
220  return result->second;
221 }
222 
223 } // namespace ns3
224 
225 // namespace ns3
~InterferenceChangeEvent()
Destructor of Event for satellite interference.
InterferenceChangeEvent(uint32_t id, Time duration, double rxPower, Address satEarthStationAddress)
Constructor of Event for satellite interference.
Abstract class defining interface for interference calculations objects.
TypeId GetInstanceTypeId(void) const
Derived from Object.
virtual void DoNotifyRxStart(Ptr< SatInterference::InterferenceChangeEvent > event)=0
Notifies that RX is started by a receiver.
void Reset(void)
Resets current interference.
virtual std::vector< std::pair< double, double > > DoCalculate(Ptr< SatInterference::InterferenceChangeEvent > event)=0
Calculates interference power for the given reference Sets final power at end time to finalPower.
Ptr< SatInterference::InterferenceChangeEvent > Add(Time rxDuration, double rxPower, Address rxAddress)
Adds interference power to interference object.
~SatInterference()
Destructor for Satellite interference base class.
virtual Ptr< SatInterference::InterferenceChangeEvent > DoAdd(Time rxDuration, double rxPower, Address rxAddress)=0
Adds interference power to interference object.
static TypeId GetTypeId(void)
Derived from Object.
virtual void DoNotifyRxEnd(Ptr< SatInterference::InterferenceChangeEvent > event)=0
Notifies that RX is ended by a receiver.
virtual void NotifyRxEnd(Ptr< SatInterference::InterferenceChangeEvent > event)
Notifies that RX is ended by a receiver.
virtual void DoReset(void)=0
Resets current interference.
virtual void NotifyRxStart(Ptr< SatInterference::InterferenceChangeEvent > event)
Notifies that RX is started by a receiver.
virtual bool HasCollision(Ptr< SatInterference::InterferenceChangeEvent > event)
Checks whether the packet has collided.
std::vector< std::pair< double, double > > Calculate(Ptr< SatInterference::InterferenceChangeEvent > event)
Calculates interference power for the given reference.
SatInterference()
Constructor for Satellite interference base class.
std::map< Ptr< SatInterference::InterferenceChangeEvent >, bool > m_packetCollisions
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.