28 #include "ns3/assert.h"
29 #include "ns3/double.h"
31 #include "ns3/nstime.h"
32 #include "ns3/trace-source-accessor.h"
33 #include "ns3/uinteger.h"
90 it->second.rxFrames.clear();
112 .AddAttribute(
"MaxReservations",
113 "Maximum number of reservations to accept per cycle.",
116 MakeUintegerChecker<uint32_t>())
117 .AddAttribute(
"NumberOfRates",
118 "Number of rates per Phy layer.",
121 MakeUintegerChecker<uint32_t>())
122 .AddAttribute(
"MaxPropDelay",
123 "Maximum propagation delay between gateway and non-gateway nodes.",
129 "Spacing between frames to account for timing error and processing delay.",
133 .AddAttribute(
"NumberOfNodes",
134 "Number of non-gateway nodes in this gateway's neighborhood.",
137 MakeUintegerChecker<uint32_t>())
138 .AddAttribute(
"MinRetryRate",
139 "Smallest allowed RTS retry rate.",
142 MakeDoubleChecker<double>())
143 .AddAttribute(
"RetryStep",
144 "Retry rate increment.",
147 MakeDoubleChecker<double>())
148 .AddAttribute(
"TotalRate",
149 "Total available channel rate in bps (for a single channel, without "
150 "splitting reservation channel).",
153 MakeUintegerChecker<uint32_t>())
154 .AddAttribute(
"RateStep",
155 "Increments available for rate assignment in bps.",
158 MakeUintegerChecker<uint32_t>())
159 .AddAttribute(
"FrameSize",
160 "Size of data frames in bytes.",
163 MakeUintegerChecker<uint32_t>())
164 .AddTraceSource(
"RX",
165 "A packet was destined for and received at this MAC layer.",
167 "ns3::UanMac::PacketModeTracedCallback")
168 .AddTraceSource(
"Cycle",
169 "Trace cycle statistics.",
171 "ns3::UanMacRcGw::CycleCallback")
183 NS_LOG_WARN(
"RCMAC Gateway transmission to acoustic nodes is not yet implemented");
237 <<
" length = " << pkt->
GetSize());
263 <<
" with length " << req.
length);
282 NS_FATAL_ERROR(
"Received CTS at GW. Currently only support single GW network!");
285 NS_FATAL_ERROR(
"Received ACK at GW. Currently only support single GW network!");
295 auto numRts =
static_cast<uint32_t
>(
m_sortedRes.size());
307 uint32_t totalBytes = 0;
308 uint32_t totalFrames = 0;
315 totalBytes += (*rit).second.length;
316 totalFrames += (*rit).second.numFrames;
333 double temprate = (thCtlRate - minRate) / ((
double)
m_rateStep) + 0.5;
340 NS_LOG_DEBUG(
"Found theoretical alpha: " << thAlpha <<
" Found associated rate = " << thCtlRate
341 <<
" Giving rate number: " << temprate);
348 NS_LOG_WARN(
"Gateway found optimum RTS retry rate is below minimum");
360 Time winSize =
Seconds(totalBytes * 8.0 / dataRate) +
m_sifs * totalFrames + pDelay;
371 Time cycleSeconds = winSize + ((totalFrames + 1.0) *
m_sifs) + ctsTxTimeG +
412 Time minPdelay = (*it).first;
418 Time pdelay = (*it).first;
424 m_ackData.insert(std::make_pair(dest, newData));
426 Time earliestArr = ctsTxTimeTotal + pdelay + pdelay +
m_sifs;
429 <<
" GW: Scheduling request for prop. delay " << pdelay.
As(
Time::S) <<
" for "
430 << (*it).second <<
" Earliest possible arrival=" << earliestArr.
As(
Time::S)
431 <<
" Next arrival time=" << nextEarliest.
As(
Time::S));
443 <<
" GW Scheduling reception for " << (uint32_t)req.
numFrames <<
" frames at "
446 <<
" with txtime " << req.
length * 8 / dataRate <<
" seconds");
496 std::list<uint32_t> toNack;
497 for (uint8_t i = 0; i <
data.expFrames; i++)
499 if (
data.rxFrames.find(i) ==
data.rxFrames.end())
510 auto nit = toNack.begin();
511 for (; nit != toNack.end(); nit++)
520 nextAck = nextAck + ackTime +
m_sifs;
554 <<
" GW sending " <<
type <<
" packet with size " << pkt->
GetSize() <<
" to "
555 << ch.
GetDest() <<
" at rate " << rate);
556 m_phy->SendPacket(pkt, rate);
567 double lrae =
m_rtsSize * 8.0 * a * std::exp(1.0);
568 if (totalFrames == 0)
583 alpha = -gamma + std::sqrt(gamma * gamma +
586 if (alpha < 0 || alpha > 1)
588 alpha = -gamma - std::sqrt(gamma * gamma +
592 NS_ASSERT_MSG(alpha > 0 && alpha < 1,
"Error computing alpha. Alpha out of valid range!");
600 std::vector<double> pds;
605 pds.push_back(pdit->second.GetSeconds());
612 std::sort(pds.begin(), pds.end());
614 std::vector<double> exppdk;
616 for (uint32_t
k = 1;
k <= n;
k++)
619 exppdk.push_back(pds[ind]);
631 double expk = n * (1 - std::exp(-((
double)a) / (
double)n));
635 double expdata = 8 * ld * expk;
643 for (uint32_t i = 1; i <= n; i++)
650 double s = (1.0 /
m_totalRate) * expdata / exptime;
665 for (uint32_t i = 1; i <= n -
k + 1; i++)
667 auto nChK =
static_cast<double>(
NchooseK(n,
k));
668 double p = (nChK > 0) ? (
static_cast<double>(
NchooseK(n - i,
k - 1)) / nChK) : DBL_MAX;
671 return (uint32_t)(sum + 0.5);
678 return nck * std::pow((std::exp((
double)a / (
double)n) - 1.0), (
double)
k) *
679 std::exp(-((
double)a));
687 for (uint32_t
k = 1;
k <= n;
k++)
692 double term = pik *
num / denom;
714 for (uint32_t i = 1; i <=
k; i++)
716 accum = accum * (n -
k + i) / i;
719 return (uint64_t)(accum + 0.5);
a polymophic address class
This class can be used to hold variables of floating point type such as 'double' or 'float'.
A class used for addressing MAC8 MAC's.
static Mac8Address GetBroadcast()
Get the broadcast address (255).
static Mac8Address ConvertFrom(const Address &address)
Convert a generic address to a Mac8Address.
virtual void DoDispose()
Destructor implementation.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
void AddHeader(const Header &header)
Add header to this packet.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Virtual base class for all UAN MAC protocols.
virtual Address GetAddress()
Get the MAC Address.
uint32_t m_numNodes
Number of non-gateway nodes in this gateway's neighborhood.
void ReceiveError(Ptr< Packet > pkt, double sinr)
PHY receive error callback.
void SendPacket(Ptr< Packet > pkt, uint32_t rate)
Send packet on PHY.
uint32_t m_maxRes
Maximum number of reservations to accept per cycle.
double ComputeAlpha(uint32_t totalFrames, uint32_t totalBytes, uint32_t n, uint32_t a, double deltaK)
Compute alpha parameter.
double m_minRetryRate
Smallest allowed RTS retry rate.
void Clear() override
Clears all pointer references.
uint16_t m_currentRetryRate
Retry rate number for current cycle.
~UanMacRcGw() override
Dummy destructor, see DoDispose.
uint32_t m_ctsSizeN
Size of UanHeaderRcCts.
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet was destined for and received at this MAC layer.
void EndCycle()
End cycle by scheduling pending ACKs.
uint32_t m_rateStep
Increments available for rate assignment in bps.
uint32_t FindOptA()
Compute the optimum maximum number of reservations to accept per cycle.
std::map< Mac8Address, AckData > m_ackData
AckData for each node.
void StartCycle()
Cycle through pending requests.
TracedCallback< Time, Time, uint32_t, uint32_t, double, uint32_t, double > m_cycleLogger
A packet was destined for and received at this MAC layer.
std::set< std::pair< Time, Mac8Address > > m_sortedRes
Queued request times.
void AttachPhy(Ptr< UanPhy > phy) override
Attach PHY layer to this MAC.
Time m_maxDelta
Maximum propagation delay between gateway and non-gateway nodes .
double ComputeExpS(uint32_t a, uint32_t ld, std::vector< double > exppdk)
Throughput for a reservations with framesize ld, given expected delays exppdk.
Time m_sifs
Spacing between frames to account for timing error and processing delay.
void DoDispose() override
Destructor implementation.
static TypeId GetTypeId()
Register this type.
bool m_cleared
Flag when we've been cleared.
uint32_t m_ctsSizeG
Size of UanHeaderCommon and UanHeaderRcCtsGlobal.
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
@ INCYCLE
Cycling through nodes.
@ IDLE
Initial idle state.
uint32_t m_frameSize
Size of data frames in bytes.
uint64_t NchooseK(uint32_t n, uint32_t k)
Binomial coefficient.
uint32_t m_numRates
Number of rates per Phy layer.
bool Enqueue(Ptr< Packet > pkt, uint16_t protocolNumber, const Address &dest) override
Enqueue packet to be transmitted.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
void CycleStarted()
Set state to INCYCLE.
void ReceivePacket(Ptr< Packet > pkt, double sinr, UanTxMode mode)
PHY receive ok callback.
Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > m_forwardUpCb
Forwarding up callback.
uint32_t m_currentRateNum
Rate number corresponding to data rate of current cycle.
double ComputePiK(uint32_t a, uint32_t n, uint32_t k)
Numeric function.
std::vector< double > GetExpPdk()
Get the expected propagation delay to each node.
uint32_t m_totalRate
Total available channel rate in bps (for a single channel, without splitting reservation channel).
uint32_t m_rtsSize
Size of UanHeaderCommon and UanHeaderRcRts.
State m_state
Gateway processing state.
std::map< Mac8Address, Request > m_requests
Request for each node.
double m_retryStep
Retry rate increment.
double ComputeExpBOverA(uint32_t n, uint32_t a, uint32_t ldlh, std::vector< double > deltaK)
Numeric function.
std::map< Mac8Address, Time > m_propDelay
Propagation delay to each node.
void SetForwardUpCb(Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > cb) override
Set the callback to forward packets up to higher layers.
uint32_t m_ackSize
Size of UanHeaderCommon and UanHeaderRcAck.
uint32_t CompExpMinIndex(uint32_t n, uint32_t k)
Index to the k'th expected delay among n nodes.
@ TYPE_GWPING
Gateway ping.
Abstraction of packet modulation information.
Hold an unsigned integer type.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Now()
create an ns3::Time instance which contains the current simulation time.
Time Seconds(double value)
Construct a Time in the indicated unit.
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)
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
@ IDLE
Channel is IDLE, no packet is being transmitted.
uint8_t expFrames
Expected number of frames.
uint8_t frameNo
Frame number being ACK'ed.
uint8_t retryNo
Retry number.
uint16_t length
Request header length.
uint8_t frameNo
Current frame number.
uint8_t numFrames
Number of frames.
Time rxTime
Time request received.