|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
25 #include <ns3/random-variable-stream.h>
26 #include <ns3/simulator.h>
30 #undef NS_LOG_APPEND_CONTEXT
31 #define NS_LOG_APPEND_CONTEXT \
32 std::clog << "[address " << m_mac->GetShortAddress () << "] ";
45 .SetGroupName (
"LrWpan")
63 m_random = CreateObject<UniformRandomVariable> ();
191 Time elapsedSuperframe;
193 double symbolsToBoundary;
195 uint64_t elapsedSuperframeSymbols;
203 symbolRate = (uint64_t)
m_mac->GetPhy ()->GetDataOrSymbolRate (
false);
208 elapsedSuperframe = currentTime -
m_mac->m_macBeaconRxTime;
210 beaconTime =
Seconds ((
double)
m_mac->m_rxBeaconSymbols / symbolRate);
211 elapsedCap = elapsedSuperframe - beaconTime;
219 elapsedSuperframe = currentTime -
m_mac->m_macBeaconTxTime;
223 elapsedSuperframeSymbols = elapsedSuperframe.
GetSeconds () * symbolRate;
226 timeAtBoundary =
Seconds ((
double)(elapsedSuperframeSymbols + symbolsToBoundary) / symbolRate);
229 nextBoundary = timeAtBoundary - elapsedSuperframe;
231 NS_LOG_DEBUG (
"Elapsed Superframe symbols: " << elapsedSuperframeSymbols <<
" ("
232 << elapsedSuperframe.As (
Time::S) <<
")");
234 NS_LOG_DEBUG (
"Next backoff period boundary in approx. " << nextBoundary.
GetSeconds () * symbolRate <<
" symbols ("
298 uint64_t upperBound = (uint64_t) pow (2,
m_BE) - 1;
303 symbolRate = (uint64_t)
m_mac->GetPhy ()->GetDataOrSymbolRate (
false);
317 " periods (" << randomBackoff.
As (
Time::S) <<
")");
327 " periods (" << (randomBackoff.
GetSeconds () * symbolRate) <<
" symbols or " << randomBackoff.
As (
Time::S) <<
")");
333 << (timeLeftInCap.
GetSeconds () * symbolRate) <<
" symbols or "
337 if (randomBackoff > timeLeftInCap)
341 NS_LOG_DEBUG (
"No time in CAP to complete backoff delay, deferring to the next CAP");
366 symbolRate = (uint64_t)
m_mac->GetPhy ()->GetDataOrSymbolRate (
false);
371 activeSlot =
m_mac->m_incomingSuperframeDuration / 16;
372 capSymbols = activeSlot * (
m_mac->m_incomingFnlCapSlot + 1);
373 endCapTime =
m_mac->m_macBeaconRxTime +
374 Seconds ((
double) capSymbols / symbolRate);
378 activeSlot =
m_mac->m_superframeDuration / 16;
379 capSymbols = activeSlot * (
m_mac->m_fnlCapSlot + 1);
380 endCapTime =
m_mac->m_macBeaconTxTime +
381 Seconds ((
double) capSymbols / symbolRate);
384 return (endCapTime - currentTime);
395 uint32_t transactionSymbols;
396 Time transactionTime;
401 symbolRate = (uint64_t)
m_mac->GetPhy ()->GetDataOrSymbolRate (
false);
415 ccaSymbols += 8 *
m_CW;
422 transactionSymbols = ccaSymbols +
m_mac->GetTxPacketSymbols ();
424 if (
m_mac->isTxAckReq ())
427 transactionSymbols +=
m_mac->GetMacAckWaitDuration ();
432 transactionSymbols += (
m_mac->GetPhy ()->aTurnaroundTime *2);
434 transactionSymbols +=
m_mac->GetIfsSize ();
442 transactionTime =
Seconds ((
double) transactionSymbols / symbolRate);
443 NS_LOG_DEBUG (
"Total required transaction: " << transactionSymbols <<
" symbols (" << transactionTime.
As (
Time::S) <<
")");
445 if (transactionTime > timeLeftInCap)
447 NS_LOG_DEBUG (
"Transaction of " << transactionSymbols <<
" symbols " <<
448 "cannot be completed in CAP, deferring transmission to the next CAP");
453 " (" << timeLeftInCap.
As (
Time::S) <<
")");
469 m_mac->GetPhy ()->PlmeCcaRequest ();
534 NS_LOG_LOGIC (
"Notifying MAC of Channel access failure");
541 NS_LOG_DEBUG (
"Perform another backoff; m_NB = " <<
static_cast<uint16_t
> (
m_NB));
a unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
EventId m_requestCcaEvent
Scheduler event when to start the CCA after a random backoff.
uint8_t GetMacMinBE(void) const
Get the minimum backoff exponent value.
EventId m_endCapEvent
Scheduler event for the end of the current CAP.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
void PlmeCcaConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.2 PLME-CCA.confirm status.
static Time Now(void)
Return the current simulation virtual time.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool IsNull(void) const
Check for null implementation.
uint8_t m_macMaxCSMABackoffs
Maximum number of backoffs.
void SetMacMinBE(uint8_t macMinBE)
Set the minimum backoff exponent value.
void SetBatteryLifeExtension(bool batteryLifeExtension)
Set the value of the Battery Life Extension.
LrWpanMacStateCallback m_lrWpanMacStateCallback
The callback to inform the configured MAC of the CSMA/CA result.
uint64_t m_randomBackoffPeriodsLeft
Count the number of remaining random backoff periods left to delay.
void SetLrWpanMacTransCostCallback(LrWpanMacTransCostCallback trans)
Set the callback function to report a transaction cost in slotted CSMA-CA.
void SetUnitBackoffPeriod(uint64_t unitBackoffPeriod)
Set the number of symbols forming the basic time period used by the CSMA-CA algorithm.
LrWpanMacTransCostCallback m_lrWpanMacTransCostCallback
The callback to inform the cost of a transaction in slotted CSMA-CA.
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Time GetTimeLeftInCap()
Get the time left in the CAP portion of the Outgoing or Incoming superframe.
void SetMacMaxBE(uint8_t macMaxBE)
Set the maximum backoff exponent value.
void SetUnSlottedCsmaCa(void)
Configure for the use of the unslotted CSMA/CA version.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
bool m_macBattLifeExt
Battery Life Extension.
void SetMac(Ptr< LrWpanMac > mac)
Set the MAC to which this CSMA/CA implementation is attached to.
virtual void DoDispose(void)
Destructor implementation.
uint8_t GetMacMaxBE(void) const
Get the maximum backoff exponent value.
void Start(void)
Start CSMA-CA algorithm (step 1), initialize NB, BE for both slotted and unslotted CSMA-CA.
uint8_t m_NB
Number of backoffs for the current transmission.
uint8_t m_macMinBE
Minimum backoff exponent.
Smart pointer class similar to boost::intrusive_ptr.
uint8_t GetMacMaxCSMABackoffs(void) const
Get the maximum number of backoffs.
uint64_t m_aUnitBackoffPeriod
Number of symbols per CSMA/CA time unit, default 20 symbols.
uint8_t GetNB(void)
Get the number of CSMA retries.
void RequestCCA(void)
Request the Phy to perform CCA (Step 3)
LrWpanCsmaCa(void)
Default constructor.
Ptr< UniformRandomVariable > m_random
Uniform random variable stream.
void RandomBackoffDelay(void)
In step 2 of the CSMA-CA, perform a random backoff in the range of 0 to 2^BE -1.
Time GetTimeToNextSlot(void) const
Locates the time to the next backoff period boundary in the SUPERFRAME and returns the amount of time...
A base class which provides memory management and object aggregation.
@ MAC_CSMA_DEFERRED
MAC_CSMA_DEFERRED.
bool m_isSlotted
Beacon-enabled slotted or nonbeacon-enabled unslotted CSMA-CA.
void DeferCsmaTimeout(void)
The CSMA algorithm call this function at the end of the CAP to return the MAC state back to to IDLE a...
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
#define NS_UNUSED(x)
Mark a local variable as unused.
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
@ CHANNEL_ACCESS_FAILURE
CHANNEL_ACCESS_FAILURE.
Simulation virtual time values and global simulation resolution.
Ptr< LrWpanMac > m_mac
The MAC instance for which this CSMA/CA implemenation is configured.
bool IsUnSlottedCsmaCa(void) const
Check if the unslotted CSMA/CA version is being used.
void Cancel(void)
Cancel CSMA-CA algorithm.
bool m_ccaRequestRunning
Flag indicating that the PHY is currently running a CCA.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
uint8_t m_BE
Backoff exponent.
void SetSlottedCsmaCa(void)
Configure for the use of the slotted CSMA/CA version.
uint64_t GetUnitBackoffPeriod(void) const
Get the number of symbols forming the basic time period used by the CSMA-CA algorithm.
EventId m_randomBackoffEvent
Scheduler event for the start of the next random backoff/slot.
void SetLrWpanMacStateCallback(LrWpanMacStateCallback macState)
Set the callback function to the MAC.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
void CanProceed(void)
In the slotted CSMA-CA, after random backoff, determine if the remaining CSMA-CA operation can procee...
Time Seconds(double value)
Construct a Time in the indicated unit.
bool m_coorDest
Indicates whether the CSMA procedure is targeted for a message to be sent to the coordinator.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
uint8_t m_macMaxBE
Maximum backoff exponent.
bool GetBatteryLifeExtension(void)
Get the value of the Battery Life Extension.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
virtual ~LrWpanCsmaCa(void)
Ptr< LrWpanMac > GetMac(void) const
Get the MAC to which this CSMA/CA implementation is attached to.
static TypeId GetTypeId(void)
Get the type ID.
bool IsSlottedCsmaCa(void) const
Check if the slotted CSMA/CA version is being used.
@ CHANNEL_IDLE
CHANNEL_IDLE.
This class is a helper for the LrWpanMac to manage the Csma/CA state machine according to IEEE 802....
EventId m_canProceedEvent
Scheduler event for checking if we can complete the transmission before the end of the CAP.
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
void SetMacMaxCSMABackoffs(uint8_t macMaxCSMABackoffs)
Set the maximum number of backoffs.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
uint8_t m_CW
Contention window length (used in slotted ver only).