A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
uan-mac-rc-gw.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Leonard Tracy <lentracy@gmail.com>
7 */
8
9#include "uan-mac-rc-gw.h"
10
11#include "uan-header-common.h"
12#include "uan-header-rc.h"
13#include "uan-mac-rc.h"
14#include "uan-phy.h"
15#include "uan-tx-mode.h"
16
17#include "ns3/assert.h"
18#include "ns3/double.h"
19#include "ns3/log.h"
20#include "ns3/nstime.h"
21#include "ns3/trace-source-accessor.h"
22#include "ns3/uinteger.h"
23
24#include <algorithm>
25#include <cfloat>
26#include <map>
27#include <set>
28#include <utility>
29#include <vector>
30
31namespace ns3
32{
33
34NS_LOG_COMPONENT_DEFINE("UanMacRcGw");
35
37
39 : UanMac(),
40 m_state(IDLE),
41 m_currentRateNum(0),
42 m_cleared(false)
43{
49
54
55 NS_LOG_DEBUG("Gateway initialized");
56}
57
61
62void
64{
65 if (m_cleared)
66 {
67 return;
68 }
69 m_cleared = true;
70 if (m_phy)
71 {
72 m_phy->Clear();
73 m_phy = nullptr;
74 }
75 m_propDelay.clear();
76 auto it = m_ackData.begin();
77 for (; it != m_ackData.end(); it++)
78 {
79 it->second.rxFrames.clear();
80 }
81 m_ackData.clear();
82 m_requests.clear();
83 m_sortedRes.clear();
84}
85
86void
92
95{
96 static TypeId tid =
97 TypeId("ns3::UanMacRcGw")
99 .SetGroupName("Uan")
100 .AddConstructor<UanMacRcGw>()
101 .AddAttribute("MaxReservations",
102 "Maximum number of reservations to accept per cycle.",
103 UintegerValue(10),
106 .AddAttribute("NumberOfRates",
107 "Number of rates per Phy layer.",
108 UintegerValue(1023),
111 .AddAttribute("MaxPropDelay",
112 "Maximum propagation delay between gateway and non-gateway nodes.",
113 TimeValue(Seconds(2)),
116 .AddAttribute(
117 "SIFS",
118 "Spacing between frames to account for timing error and processing delay.",
119 TimeValue(Seconds(0.2)),
122 .AddAttribute("NumberOfNodes",
123 "Number of non-gateway nodes in this gateway's neighborhood.",
124 UintegerValue(10),
127 .AddAttribute("MinRetryRate",
128 "Smallest allowed RTS retry rate.",
129 DoubleValue(0.01),
132 .AddAttribute("RetryStep",
133 "Retry rate increment.",
134 DoubleValue(0.01),
137 .AddAttribute("TotalRate",
138 "Total available channel rate in bps (for a single channel, without "
139 "splitting reservation channel).",
140 UintegerValue(4096),
143 .AddAttribute("RateStep",
144 "Increments available for rate assignment in bps.",
145 UintegerValue(4),
148 .AddAttribute("FrameSize",
149 "Size of data frames in bytes.",
150 UintegerValue(1000),
153 .AddTraceSource("RX",
154 "A packet was destined for and received at this MAC layer.",
156 "ns3::UanMac::PacketModeTracedCallback")
157 .AddTraceSource("Cycle",
158 "Trace cycle statistics.",
160 "ns3::UanMacRcGw::CycleCallback")
161
162 ;
163
164 return tid;
165}
166
167bool
169 uint16_t /* protocolNumber */,
170 const Address& /* dest */)
171{
172 NS_LOG_WARN("RCMAC Gateway transmission to acoustic nodes is not yet implemented");
173 return false;
174}
175
176void
178{
179 m_forwardUpCb = cb;
180}
181
182void
184{
185 m_phy = phy;
186 phy->SetReceiveOkCallback(MakeCallback(&UanMacRcGw::ReceivePacket, this));
187 phy->SetReceiveErrorCallback(MakeCallback(&UanMacRcGw::ReceiveError, this));
188}
189
190void
191UanMacRcGw::ReceiveError(Ptr<Packet> /* pkt */, double /* sinr */)
192{
193}
194
195void
197{
199 pkt->PeekHeader(ch);
200
203 {
204 m_rxLogger(pkt, mode);
205 }
206 else
207 {
208 return;
209 }
210
211 pkt->RemoveHeader(ch);
212
213 switch (ch.GetType())
214 {
215 case UanMacRc::TYPE_DATA: {
217 pkt->RemoveHeader(dh);
218 m_propDelay[ch.GetSrc()] = dh.GetPropDelay();
219 if (m_ackData.find(ch.GetSrc()) == m_ackData.end())
220 {
221 NS_LOG_DEBUG(Now().As(Time::S) << " GATEWAY Received unexpected data packet");
222 }
223 else
224 {
225 NS_LOG_DEBUG(Now().As(Time::S) << " GW Received data packet from " << ch.GetSrc()
226 << " length = " << pkt->GetSize());
227 m_ackData[ch.GetSrc()].rxFrames.insert(dh.GetFrameNo());
228 }
229 m_forwardUpCb(pkt, ch.GetProtocolNumber(), ch.GetSrc());
230 }
231 break;
234 if (m_state == CTSING)
235 {
236 return;
237 }
238
239 {
241 pkt->RemoveHeader(rh);
242
243 if (m_requests.find(ch.GetSrc()) == m_requests.end())
244 {
245 Request req;
246 req.numFrames = rh.GetNoFrames();
247 req.rxTime = Simulator::Now();
248 req.frameNo = rh.GetFrameNo();
249 req.retryNo = rh.GetRetryNo();
250 req.length = rh.GetLength();
251 NS_LOG_DEBUG(Now().As(Time::S) << " GW storing reservation from " << ch.GetSrc()
252 << " with length " << req.length);
253 m_requests.insert(std::make_pair(ch.GetSrc(), req));
254 auto it = m_propDelay.find(ch.GetSrc());
255 if (it == m_propDelay.end())
256 {
257 m_sortedRes.insert(std::make_pair(m_maxDelta, ch.GetSrc()));
258 }
259 else
260 {
261 m_sortedRes.insert(std::make_pair((*it).second, ch.GetSrc()));
262 }
263 }
264 }
265 if (m_state == IDLE)
266 {
267 StartCycle();
268 }
269 break;
271 NS_FATAL_ERROR("Received CTS at GW. Currently only support single GW network!");
272 break;
274 NS_FATAL_ERROR("Received ACK at GW. Currently only support single GW network!");
275 break;
276 default:
277 NS_FATAL_ERROR("Received unknown packet at GW!");
278 }
279}
280
281void
283{
284 auto numRts = static_cast<uint32_t>(m_sortedRes.size());
285
286 if (numRts)
287 {
288 NS_LOG_DEBUG(Now().As(Time::S) << " Simulator starting non-empty cycle");
289 }
290 else
291 {
292 NS_LOG_DEBUG(Now().As(Time::S) << " Simulator starting EMPTY cycle");
293 }
294
295 // Calculate dataRate
296 uint32_t totalBytes = 0;
297 uint32_t totalFrames = 0;
298 Time pDelay = Seconds(0);
299 if (numRts > 0)
300 {
301 auto rit = m_requests.begin();
302 for (; rit != m_requests.end(); rit++)
303 {
304 totalBytes += (*rit).second.length;
305 totalFrames += (*rit).second.numFrames;
306 }
307 pDelay = 2 * m_sortedRes.begin()->first;
308 }
309
310 double minRate = m_phy->GetMode(m_numRates).GetDataRateBps();
311
312 uint32_t optA = m_maxRes;
313 if (m_maxRes == 0)
314 {
315 optA = FindOptA();
316 }
317 double thAlpha =
318 ComputeAlpha(totalFrames, totalBytes, m_numNodes, optA, (pDelay / 2.0).GetSeconds());
319
320 double thCtlRate = m_totalRate * thAlpha;
321
322 double temprate = (thCtlRate - minRate) / ((double)m_rateStep) + 0.5;
323 m_currentRateNum = (uint32_t)temprate;
325 {
327 }
328
329 NS_LOG_DEBUG("Found theoretical alpha: " << thAlpha << " Found associated rate = " << thCtlRate
330 << " Giving rate number: " << temprate);
331 double thX = thAlpha * m_totalRate / (2.0 * m_numNodes * m_rtsSize * 8.0);
332
333 double dataRate = m_phy->GetMode(m_currentRateNum).GetDataRateBps();
334
335 if (thX < m_minRetryRate)
336 {
337 NS_LOG_WARN("Gateway found optimum RTS retry rate is below minimum");
339 }
340 else
341 {
342 m_currentRetryRate = (uint16_t)((thX - m_minRetryRate) / m_retryStep + 0.5);
343 }
344
345 double actualX = m_currentRetryRate * m_retryStep + m_minRetryRate;
346
347 uint32_t ctlRate = m_phy->GetMode(m_currentRateNum + m_numRates).GetDataRateBps();
348
349 Time winSize = Seconds(totalBytes * 8.0 / dataRate) + m_sifs * totalFrames + pDelay;
350 if (numRts == 0)
351 {
352 winSize = Seconds((optA * std::exp(1.0) + 0.5) * 2.0 * 8.0 * m_rtsSize /
353 (thAlpha * m_totalRate)) +
354 (2 * m_maxDelta);
355 }
356 Time effWinSize = winSize - Seconds(m_rtsSize * 8.0 / ctlRate) - (2 * m_maxDelta);
357
358 // Before fast CTS/ACK(below)
359 Time ctsTxTimeG = Seconds(m_ctsSizeG * 8.0 / dataRate);
360 Time cycleSeconds = winSize + ((totalFrames + 1.0) * m_sifs) + ctsTxTimeG +
361 Seconds((m_ctsSizeN + m_ackSize) * 8.0 / dataRate);
362
363 Time ctsTxTimeTotal = Seconds(m_ctsSizeN * 8.0 * numRts / dataRate) + ctsTxTimeG;
364 if (numRts == 0)
365 {
367 ctsg.SetWindowTime(effWinSize);
368 ctsg.SetRateNum(static_cast<uint16_t>(m_currentRateNum));
371
376 ch.SetProtocolNumber(0);
377
379 p->AddHeader(ctsg);
380 p->AddHeader(ch);
382
383 Simulator::Schedule(cycleSeconds, &UanMacRcGw::StartCycle, this);
386 Seconds(0),
387 numRts,
388 totalBytes,
389 effWinSize.GetSeconds(),
390 ctlRate,
391 actualX);
392 return;
393 }
394
395 Time nextEarliest = ctsTxTimeTotal + m_sifs;
396
397 m_state = CTSING;
398 Simulator::Schedule(nextEarliest, &UanMacRcGw::CycleStarted, this);
399
400 auto it = m_sortedRes.begin();
401 Time minPdelay = (*it).first;
403
404 for (; it != m_sortedRes.end(); it++)
405 {
406 Request req = m_requests[(*it).second];
407 Time pdelay = (*it).first;
408
409 AckData newData;
410 newData.expFrames = req.numFrames;
411 newData.frameNo = req.frameNo;
412 Mac8Address dest = (*it).second;
413 m_ackData.insert(std::make_pair(dest, newData));
414
415 Time earliestArr = ctsTxTimeTotal + pdelay + pdelay + m_sifs;
416 Time arrivalTime = std::max(earliestArr, nextEarliest);
418 << " GW: Scheduling request for prop. delay " << pdelay.As(Time::S) << " for "
419 << (*it).second << " Earliest possible arrival=" << earliestArr.As(Time::S)
420 << " Next arrival time=" << nextEarliest.As(Time::S));
421 nextEarliest = arrivalTime + Seconds(req.length * 8.0 / dataRate) + m_sifs * req.numFrames;
422
423 UanHeaderRcCts ctsh;
424 ctsh.SetAddress(dest);
425 ctsh.SetRtsTimeStamp(req.rxTime);
426 ctsh.SetFrameNo(req.frameNo);
427 ctsh.SetRetryNo(req.retryNo);
428 ctsh.SetDelayToTx(arrivalTime);
429 cts->AddHeader(ctsh);
430
432 << " GW Scheduling reception for " << (uint32_t)req.numFrames << " frames at "
433 << (Simulator::Now() + arrivalTime).As(Time::S) << " (delaytiltx of "
434 << arrivalTime.As(Time::S) << ") Total length is " << req.length
435 << " with txtime " << req.length * 8 / dataRate << " seconds");
436 }
437
439 ctsg.SetRateNum(static_cast<uint16_t>(m_currentRateNum));
441 ctsg.SetWindowTime(effWinSize);
447 cts->AddHeader(ctsg);
448 cts->AddHeader(ch);
450
451 m_requests.clear();
452 m_sortedRes.clear();
453 Simulator::Schedule(nextEarliest, &UanMacRcGw::EndCycle, this);
454
456 minPdelay,
457 numRts,
458 totalBytes,
459 cycleSeconds.GetSeconds(),
460 ctlRate,
461 actualX);
462}
463
464void
469
470void
472{
473 NS_LOG_DEBUG(Now().As(Time::S) << " GW Ending cycle");
474
475 Time nextAck = Seconds(0);
476
477 Time ackTime = Seconds(m_ackSize * 8.0 / m_phy->GetMode(m_currentRateNum).GetDataRateBps());
478
479 auto it = m_ackData.begin();
480 for (; it != m_ackData.end(); it++)
481 {
482 Mac8Address dest = (*it).first;
483 AckData& data = (*it).second;
484
485 std::list<uint32_t> toNack;
486 for (uint8_t i = 0; i < data.expFrames; i++)
487 {
488 if (data.rxFrames.find(i) == data.rxFrames.end())
489 {
490 toNack.push_back(i);
491 }
492 }
494 ch.SetDest(dest);
498 ah.SetFrameNo(data.frameNo);
499 auto nit = toNack.begin();
500 for (; nit != toNack.end(); nit++)
501 {
502 ah.AddNackedFrame(static_cast<uint8_t>(*nit));
503 }
504
506 ack->AddHeader(ah);
507 ack->AddHeader(ch);
509 nextAck = nextAck + ackTime + m_sifs;
510 }
511 m_ackData.clear();
513}
514
515void
517{
519 pkt->PeekHeader(ch);
520 std::string type;
521 switch (ch.GetType())
522 {
524 type = "DATA";
525 break;
527 type = "RTS";
528 break;
530 type = "CTS";
531 break;
533 type = "ACK";
534 break;
536 type = "GWPING";
537 break;
538 default:
539 type = "UNKNOWN";
540 break;
541 }
543 << " GW sending " << type << " packet with size " << pkt->GetSize() << " to "
544 << ch.GetDest() << " at rate " << rate);
545 m_phy->SendPacket(pkt, rate);
546}
547
548double
550 uint32_t totalBytes,
551 uint32_t /* n */,
552 uint32_t a,
553 double deltaK)
554{
555 double alpha;
556 double lrae = m_rtsSize * 8.0 * a * std::exp(1.0);
557 if (totalFrames == 0)
558 {
559 alpha = (2.0 * lrae + 8.0 * m_rtsSize -
560 std::sqrt(m_ctsSizeG * 8.0 * 8.0 * m_rtsSize +
561 2 * 8.0 * m_ctsSizeG * 8.0 * m_rtsSize * a * std::exp(1.0))) /
562 (2 * lrae + 8.0 * m_rtsSize - 8.0 * m_ctsSizeG);
563 }
564 else
565 {
566 double w = totalBytes * 8.0 + totalFrames * m_sifs.GetSeconds() * m_totalRate;
567 double v = m_rtsSize * 8.0 + 2 * lrae;
568 double u = (2 * m_maxDelta.GetSeconds() - 2 * deltaK) * m_totalRate;
569
570 double gamma = (w - u + v) / (2 * (u - totalFrames * m_sifs.GetSeconds() * m_totalRate));
571
572 alpha = -gamma + std::sqrt(gamma * gamma +
573 v / (u - totalFrames * m_sifs.GetSeconds() * m_totalRate));
574
575 if (alpha < 0 || alpha > 1)
576 {
577 alpha = -gamma - std::sqrt(gamma * gamma +
578 v / (u - totalFrames * m_sifs.GetSeconds() * m_totalRate));
579 }
580 }
581 NS_ASSERT_MSG(alpha > 0 && alpha < 1, "Error computing alpha. Alpha out of valid range!");
582 return alpha;
583}
584
585std::vector<double>
587{
589 std::vector<double> pds;
590 auto pdit = m_propDelay.begin();
591
592 for (; pdit != m_propDelay.end(); pdit++)
593 {
594 pds.push_back(pdit->second.GetSeconds());
595 }
596 while (pds.size() < m_numNodes)
597 {
598 pds.push_back(m_maxDelta.GetSeconds());
599 }
600
601 std::sort(pds.begin(), pds.end());
602 // Find expected min. prop. delay for k nodes
603 std::vector<double> exppdk;
604 exppdk.push_back(m_maxDelta.GetSeconds());
605 for (uint32_t k = 1; k <= n; k++)
606 {
607 uint32_t ind = CompExpMinIndex(n, k) - 1;
608 exppdk.push_back(pds[ind]);
609 }
610 return exppdk;
611}
612
613double
614UanMacRcGw::ComputeExpS(uint32_t a, uint32_t ld, std::vector<double> exppdk)
615{
617 uint32_t lh = ch.GetSerializedSize();
618
620 double expk = n * (1 - std::exp(-((double)a) / (double)n));
621 NS_LOG_DEBUG("expk = " << expk);
622
623 // Compute expected data per cycle
624 double expdata = 8 * ld * expk;
625
626 // Compute expected time per cycle
627 double alpha0 = ComputeAlpha(0, 0, n, a, exppdk[0]);
628 double c0 = 8.0 * m_ctsSizeG / (m_totalRate * (1 - alpha0)) + 2 * m_maxDelta.GetSeconds() +
629 (a * std::exp(1.0) + 0.5) * 2 * m_rtsSize * 8.0 / (alpha0 * m_totalRate);
630 double exptime = ComputePiK(a, n, 0) * c0;
631 double expp = 0;
632 for (uint32_t i = 1; i <= n; i++)
633 {
634 expp += ComputePiK(a, n, i) * exppdk[i - 1];
635 }
636
637 exptime += ComputeExpBOverA(n, a, ld + lh, exppdk) + expk * 2 * m_sifs.GetSeconds() +
638 m_sifs.GetSeconds() + 2 * expp;
639 double s = (1.0 / m_totalRate) * expdata / exptime;
640
641 return s;
642}
643
644double
646{
647 return ComputeExpS(a, ld, GetExpPdk());
648}
649
652{
653 double sum = 0;
654 for (uint32_t i = 1; i <= n - k + 1; i++)
655 {
656 auto nChK = static_cast<double>(NchooseK(n, k));
657 double p = (nChK > 0) ? (static_cast<double>(NchooseK(n - i, k - 1)) / nChK) : DBL_MAX;
658 sum += p * i;
659 }
660 return (uint32_t)(sum + 0.5);
661}
662
663double
665{
666 auto nck = (double)NchooseK(n, k);
667 return nck * std::pow((std::exp((double)a / (double)n) - 1.0), (double)k) *
668 std::exp(-((double)a));
669}
670
671double
672UanMacRcGw::ComputeExpBOverA(uint32_t n, uint32_t a, uint32_t ldlh, std::vector<double> deltaK)
673{
674 double sum = 0;
675 uint32_t lt = 8 * (m_ctsSizeN + ldlh + m_ackSize);
676 for (uint32_t k = 1; k <= n; k++)
677 {
678 double num = 8.0 * m_ctsSizeG + k * lt;
679 double denom = (1.0 - ComputeAlpha(k, k * ldlh, n, a, deltaK[k])) * m_totalRate;
680 double pik = ComputePiK(a, n, k);
681 double term = pik * num / denom;
682
683 sum += term;
684 }
685
686 return sum;
687}
688
689uint64_t
691{
692 if (k > n)
693 {
694 return 0;
695 }
696
697 if (k > n / 2)
698 {
699 k = n - k;
700 }
701
702 double accum = 1;
703 for (uint32_t i = 1; i <= k; i++)
704 {
705 accum = accum * (n - k + i) / i;
706 }
707
708 return (uint64_t)(accum + 0.5);
709}
710
713{
714 double tput = 0;
715 uint32_t a = 1;
716 while (true)
717 {
718 double newtput = ComputeExpS(a, m_frameSize);
719 if (newtput < tput)
720 {
721 a--;
722 break;
723 }
724 else
725 {
726 tput = newtput;
727 a++;
728 }
729 }
730 NS_LOG_DEBUG(Now().As(Time::S) << " GW: Found optimum a = " << a);
731 return a;
732}
733
734int64_t
736{
737 NS_LOG_FUNCTION(this << stream);
738 return 0;
739}
740
741} // namespace ns3
a polymophic address class
Definition address.h:90
Callback template class.
Definition callback.h:422
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
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.
Definition object.cc:433
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:404
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
@ S
second
Definition nstime.h:105
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Common packet header fields.
void SetSrc(Mac8Address src)
Set the source address.
uint32_t GetSerializedSize() const override
uint8_t GetType() const
Get the header type value.
Mac8Address GetDest() const
Get the destination address.
void SetProtocolNumber(uint16_t protocolNumber)
Set the packet type.
Mac8Address GetSrc() const
Get the source address.
void SetDest(Mac8Address dest)
Set the destination address.
void SetType(uint8_t type)
Set the header type.
uint16_t GetProtocolNumber() const
Get the packet type value.
Header used for ACK packets by protocol UanMacRc.
uint32_t GetSerializedSize() const override
void AddNackedFrame(uint8_t frame)
NACK a frame.
void SetFrameNo(uint8_t frameNo)
Set the frame number of the reservation being acknowledged.
Cycle broadcast information.
void SetRateNum(uint16_t rate)
Set the rate number corresponding to data rate of current cycle.
void SetRetryRate(uint16_t rate)
Set the retry rate number for the current cycle.
void SetTxTimeStamp(Time timeStamp)
Set the CTS timestamp.
void SetWindowTime(Time t)
Set the window time (time duration following blocking time to allow RTS transmissions).
uint32_t GetSerializedSize() const override
void SetRtsTimeStamp(Time timeStamp)
Set the timestamp for RTS reception.
void SetFrameNo(uint8_t frameNo)
Set the RTS frame number being cleared.
uint32_t GetSerializedSize() const override
void SetDelayToTx(Time delay)
Set the time delay from CTS transmission to first data frame arrival.
void SetRetryNo(uint8_t no)
Set the retry number of the RTS frame being cleared.
void SetAddress(Mac8Address addr)
Set the destination address, for scheduling info.
Extra data header information.
uint8_t GetFrameNo() const
Get the frame number of the reservation being transmitted.
Time GetPropDelay() const
Get the propagation delay found in handshaking.
uint8_t GetFrameNo() const
Get the frame number.
uint16_t GetLength() const
Get the total number of bytes in the reservation, including headers.
uint8_t GetNoFrames() const
Get the number of data frames in the reservation.
uint32_t GetSerializedSize() const override
uint8_t GetRetryNo() const
Get the retry number of this RTS packet.
Virtual base class for all UAN MAC protocols.
Definition uan-mac.h:35
virtual Address GetAddress()
Get the MAC Address.
Definition uan-mac.cc:41
Gateway side of RC-MAC.
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.
UanMacRcGw()
Constructor.
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.
@ CTSING
Sending CTS.
@ 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_DATA
Data.
Definition uan-mac-rc.h:157
@ TYPE_GWPING
Gateway ping.
Definition uan-mac-rc.h:158
Abstraction of packet modulation information.
Definition uan-tx-mode.h:32
Hold an unsigned integer type.
Definition uinteger.h:34
#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_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.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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.
Definition log.h:250
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:294
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 AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition nstime.h:1396
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...
Definition callback.h:684
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition double.h:32
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1416
@ IDLE
Channel is IDLE, no packet is being transmitted.
uint8_t data[writeSize]
uint8_t expFrames
Expected number of frames.
uint8_t frameNo
Frame number being ACK'ed.
Reservation request.
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.