28 #include "ns3/assert.h"
30 #include "ns3/trace-source-accessor.h"
31 #include "ns3/nstime.h"
32 #include "ns3/double.h"
33 #include "ns3/uinteger.h"
87 std::map<UanAddress, AckData>::iterator it =
m_ackData.begin ();
90 it->second.rxFrames.clear ();
108 .AddConstructor<UanMacRcGw> ()
109 .AddAttribute (
"MaxReservations",
110 "Maximum number of reservations to accept per cycle.",
113 MakeUintegerChecker<uint32_t> ())
114 .AddAttribute (
"NumberOfRates",
115 "Number of rates per Phy layer.",
118 MakeUintegerChecker<uint32_t> ())
119 .AddAttribute (
"MaxPropDelay",
120 "Maximum propagation delay between gateway and non-gateway nodes.",
124 .AddAttribute (
"SIFS",
125 "Spacing between frames to account for timing error and processing delay.",
129 .AddAttribute (
"NumberOfNodes",
130 "Number of non-gateway nodes in this gateway's neighborhood.",
133 MakeUintegerChecker<uint32_t> ())
134 .AddAttribute (
"MinRetryRate",
135 "Smallest allowed RTS retry rate.",
138 MakeDoubleChecker<double> ())
139 .AddAttribute (
"RetryStep",
140 "Retry rate increment.",
143 MakeDoubleChecker<double> ())
144 .AddAttribute (
"TotalRate",
145 "Total available channel rate in bps (for a single channel, without splitting reservation channel).",
148 MakeUintegerChecker<uint32_t> ())
149 .AddAttribute (
"RateStep",
150 "Increments available for rate assignment in bps.",
153 MakeUintegerChecker<uint32_t> ())
154 .AddAttribute (
"FrameSize",
155 "Size of data frames in bytes.",
158 MakeUintegerChecker<uint32_t> ())
159 .AddTraceSource (
"RX",
160 "A packet was destined for and received at this MAC layer.",
162 .AddTraceSource (
"Cycle",
163 "Trace cycle statistics.",
186 NS_LOG_WARN (
"RCMAC Gateway transmission to acoustic nodes is not yet implemented");
289 NS_FATAL_ERROR (
"Received CTS at GW. Currently only support single GW network!");
292 NS_FATAL_ERROR (
"Received ACK at GW. Currently only support single GW network!");
314 uint32_t totalBytes = 0;
315 uint32_t totalFrames = 0;
319 std::map<UanAddress, Request>::iterator rit =
m_requests.begin ();
322 totalBytes += (*rit).second.length;
323 totalFrames += (*rit).second.numFrames;
325 pDelay = 2 *
m_sortedRes.begin ()->first.GetSeconds ();
340 double temprate = (thCtlRate - minRate) / ((
double)
m_rateStep) + 0.5;
347 NS_LOG_DEBUG (
"Found theoretical alpha: " << thAlpha <<
" Found associated rate = " << thCtlRate <<
" Giving rate number: " << temprate);
355 NS_LOG_WARN (
"Gateway found optimum RTS retry rate is below minimum");
368 double winSize = (double)(totalBytes) * 8.0 / dataRate +
m_sifs.
GetSeconds () * totalFrames + pDelay;
380 Time ctsTxTimeTotal = Seconds (
m_ctsSizeN * 8.0 * numRts / dataRate) + ctsTxTimeG;
407 std::set<std::pair<Time, UanAddress> >::iterator it =
m_sortedRes.begin ();
408 Time minPdelay = (*it).first;
414 Time pdelay = (*it).first;
420 m_ackData.insert (std::make_pair (dest, newData));
422 Time earliestArr = ctsTxTimeTotal + pdelay + pdelay +
m_sifs;
423 Time arrivalTime = std::max (earliestArr, nextEarliest);
425 nextEarliest = arrivalTime + Seconds (req.
length * 8.0 / dataRate) + Seconds (m_sifs.GetSeconds () * req.
numFrames);
429 ctsh.SetRtsTimeStamp (req.
rxTime);
432 ctsh.SetDelayToTx (arrivalTime);
470 Time nextAck = Seconds (0);
474 std::map<UanAddress, AckData>::iterator it =
m_ackData.begin ();
480 std::list<uint32_t> toNack;
481 for (uint32_t i = 0; i < data.
expFrames; i++)
485 toNack.push_back (i);
494 std::list<uint32_t>::iterator nit = toNack.begin ();
495 for (; nit != toNack.end (); nit++)
504 nextAck = nextAck + ackTime +
m_sifs;
538 m_phy->SendPacket (pkt, rate);
547 double lrae =
m_rtsSize * 8.0 * a * std::exp (1.0);
548 if (totalFrames == 0)
564 if (alpha < 0 || alpha > 1)
569 NS_ASSERT_MSG (alpha > 0 && alpha < 1,
"Error computing alpha. Alpha out of valid range!");
577 std::vector<double> pds;
578 std::map<UanAddress, Time>::iterator pdit =
m_propDelay.begin ();
582 pds.push_back (pdit->second.GetSeconds ());
589 std::sort (pds.begin (), pds.end ());
591 std::vector<double> exppdk;
593 for (uint32_t k = 1; k <= n; k++)
596 exppdk.push_back (pds[ind]);
608 double expk = n * (1 - std::exp (-((
double) a) / (
double) n));
612 double expdata = 8 * ld * expk;
619 for (uint32_t i = 1; i <= n; i++)
640 for (uint32_t i = 1; i <= n - k + 1; i++)
643 double p = (nChK > 0) ? (
NchooseK (n - i, k - 1) / nChK) : DBL_MAX;
646 return (uint32_t)(sum + 0.5);
652 double nck = (double)
NchooseK (n, k);
653 return nck * std::pow ( (std::exp ( (
double) a / (
double) n) - 1.0), (
double) k) * std::exp (-( (
double) a));
662 for (uint32_t k = 1; k <= n; k++)
667 double term = pik * num / denom;
689 for (uint32_t i = 1; i <= k; i++)
691 accum = accum * (n - k + i) / i;
694 return (uint64_t)(accum + 0.5);
std::set< std::pair< Time, UanAddress > > m_sortedRes
Queued request times.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
double m_retryStep
Retry rate increment.
keep track of time values and allow control of global simulation resolution
virtual void AttachPhy(Ptr< UanPhy > phy)
Attach PHY layer to this MAC.
#define NS_LOG_FUNCTION(parameters)
Time rxTime
Time request received.
uint32_t CompExpMinIndex(uint32_t n, uint32_t k)
Index to the k'th expected delay among n nodes.
TracedCallback< Time, Time, uint32_t, uint32_t, double, uint32_t, double > m_cycleLogger
A packet was destined for and received at this MAC layer.
uint32_t m_ctsSizeG
Size of UanHeaderCommon and UanHeaderRcCtsGlobal.
bool m_cleared
Flag when we've been cleared.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
uint32_t m_numRates
Number of rates per Phy layer.
Time m_sifs
Spacing between frames to account for timing error and processing delay.
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
Channel is IDLE, no packet is being transmitted.
std::map< UanAddress, Time > m_propDelay
Propagation delay to each node.
uint32_t GetSize(void) const
uint16_t m_currentRetryRate
Retry rate number for current cycle.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
double m_minRetryRate
Smallest allowed RTS retry rate.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
virtual void Clear(void)
Clears all pointer references.
virtual Address GetBroadcast(void) const
Get the broadcast address.
State m_state
Gateway processing state.
Callback< void, Ptr< Packet >, const UanAddress & > m_forwardUpCb
Forwarding up callback.
virtual ~UanMacRcGw()
Dummy destructor, see DoDispose.
#define NS_FATAL_ERROR(msg)
fatal error handling
a polymophic address class
uint8_t numFrames
Number of frames.
std::vector< double > GetExpPdk(void)
Get the expected propagation delay to each node.
void ReceiveError(Ptr< Packet > pkt, double sinr)
PHY receive error callback.
double GetSeconds(void) const
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.
void SendPacket(Ptr< Packet > pkt, uint32_t rate)
Send packet on PHY.
Virtual base class for all UAN MAC protocols.
virtual Address GetAddress(void)
Get the MAC Address.
uint64_t NchooseK(uint32_t n, uint32_t k)
Binomial coefficient.
hold objects of type ns3::Time
A class used for addressing UAN MAC's.
Hold an unsigned integer type.
uint32_t m_numNodes
Number of non-gateway nodes in this gateway's neighborhood.
Abstraction of packet modulation information.
void ReceivePacket(Ptr< Packet > pkt, double sinr, UanTxMode mode)
PHY recieve ok callback.
uint8_t frameNo
Current frame number.
virtual void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
uint32_t m_rateStep
Increments available for rate assignment in bps.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
virtual void SetAddress(UanAddress addr)
Set the address.
uint16_t length
Request header length.
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet was destined for and received at this MAC layer.
uint32_t m_currentRateNum
Rate number corresponding to data rate of current cycle.
static UanAddress GetBroadcast(void)
Get the broadcast address (255).
uint32_t FindOptA(void)
Compute the optimum maximum number of reservations to accept per cycle.
uint8_t expFrames
Expected number of frames.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
uint32_t m_ctsSizeN
Size of UanHeaderRcCts.
static TypeId GetTypeId(void)
Register this type.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
static Time Now(void)
Return the "current simulation time".
uint8_t frameNo
Frame number being ACK'ed.
std::map< UanAddress, Request > m_requests
Request for each node.
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
#define NS_ASSERT_MSG(condition, message)
uint32_t m_frameSize
Size of data frames in bytes.
uint32_t m_totalRate
Total available channel rate in bps (for a single channel, without splitting reservation channel)...
void StartCycle(void)
Cycle through pending requests.
uint32_t m_maxRes
Maximum number of reservations to accept per cycle.
#define NS_LOG_DEBUG(msg)
void CycleStarted(void)
Set state to INCYCLE.
double ComputePiK(uint32_t a, uint32_t n, uint32_t k)
Numeric function.
uint32_t m_rtsSize
Size of UanHeaderCommon and UanHeaderRcRts.
void EndCycle(void)
End cycle by scheduling pending ACKs.
NS_LOG_COMPONENT_DEFINE("UanMacRcGw")
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
std::map< UanAddress, AckData > m_ackData
AckData for each node.
UanAddress m_address
The MAC address.
uint8_t retryNo
Retry number.
virtual bool Enqueue(Ptr< Packet > pkt, const Address &dest, uint16_t protocolNumber)
Enqueue packet to be transmitted.
double ComputeAlpha(uint32_t totalFrames, uint32_t totalBytes, uint32_t n, uint32_t a, double deltaK)
Compute alpha parameter.
Hold a floating point type.
std::set< uint8_t > rxFrames
Received frames.
a unique identifier for an interface.
uint32_t m_ackSize
Size of UanHeaderCommon and UanHeaderRcAck.
TypeId SetParent(TypeId tid)
double ComputeExpBOverA(uint32_t n, uint32_t a, uint32_t ldlh, std::vector< double > deltaK)
Numeric function.
void AddHeader(const Header &header)
Add header to this packet.
virtual void SetForwardUpCb(Callback< void, Ptr< Packet >, const UanAddress & > cb)
Set the callback to forward packets up to higher layers.