9#include "ns3/constant-position-mobility-model.h"
10#include "ns3/core-module.h"
12#include "ns3/lr-wpan-module.h"
13#include "ns3/packet.h"
14#include "ns3/propagation-delay-model.h"
15#include "ns3/propagation-loss-model.h"
16#include "ns3/simulator.h"
17#include "ns3/single-model-spectrum-channel.h"
73 void DoRun()
override;
79 :
TestCase(
"Test PHY going to TRX_OFF state after CSMA failure")
90 NS_LOG_DEBUG(
"Received packet of size " << p->GetSize());
102 NS_LOG_DEBUG(
"LrWpanMcpsDataConfirmStatus = Channel Access Failure");
113 << context <<
"PHY state change at " << now.
As(
Time::S) <<
" from "
127 << context <<
"PHY state change at " << now.
As(
Time::S) <<
" from "
176 channel->AddPropagationLossModel(propModel);
177 channel->SetPropagationDelayModel(delayModel);
179 dev0->SetChannel(channel);
180 dev1->SetChannel(channel);
181 dev2->SetChannel(channel);
186 interferenceNode->AddDevice(dev2);
189 dev0->GetPhy()->TraceConnect(
191 std::string(
"[address 00:01]"),
193 dev2->GetPhy()->TraceConnect(
195 std::string(
"[address 00:03]"),
200 sender0Mobility->SetPosition(Vector(0, 0, 0));
201 dev0->GetPhy()->SetMobility(sender0Mobility);
205 sender1Mobility->SetPosition(Vector(0, 1, 0));
206 dev1->GetPhy()->SetMobility(sender1Mobility);
211 sender3Mobility->SetPosition(Vector(0, 2, 0));
212 dev2->GetPhy()->SetMobility(sender3Mobility);
216 dev0->GetMac()->SetMcpsDataConfirmCallback(cb0);
220 dev0->GetMac()->SetMcpsDataIndicationCallback(cb1);
224 dev1->GetMac()->SetMcpsDataConfirmCallback(cb2);
228 dev1->GetMac()->SetMcpsDataIndicationCallback(cb3);
230 dev0->GetMac()->SetRxOnWhenIdle(
false);
231 dev1->GetMac()->SetRxOnWhenIdle(
false);
234 dev0->GetCsmaCa()->SetMacMinBE(0);
235 dev2->GetCsmaCa()->SetMacMinBE(0);
238 dev0->GetCsmaCa()->SetMacMaxCSMABackoffs(0);
239 dev2->GetCsmaCa()->SetMacMaxCSMABackoffs(0);
246 params.m_dstPanId = 0;
252 params.m_msduHandle = 0;
273 NS_LOG_DEBUG(
"----------- Start of TestRxOffWhenIdleAfterCsmaFailure -------------------");
278 "Error, dev0 [00:01] PHY should be in TRX_OFF after CSMA failure");
310 void DoRun()
override;
319 :
TestCase(
"Test the reception of PAN descriptors while performing an active scan")
376 coord1NetDevice->GetMac()->SetExtendedAddress(
"00:00:00:00:00:00:CA:FE");
377 coord1NetDevice->GetMac()->SetShortAddress(
Mac16Address(
"00:00"));
379 coord2NetDevice->GetMac()->SetExtendedAddress(
"00:00:00:00:00:00:BE:BE");
380 coord2NetDevice->GetMac()->SetShortAddress(
Mac16Address(
"00:00"));
383 endNodeNetDevice->GetMac()->SetExtendedAddress(
"00:00:00:00:00:00:00:03");
384 endNodeNetDevice->GetMac()->SetShortAddress(
Mac16Address(
"ff:ff"));
392 channel->AddPropagationLossModel(propModel);
393 channel->SetPropagationDelayModel(delayModel);
395 coord1NetDevice->SetChannel(channel);
396 endNodeNetDevice->SetChannel(channel);
397 coord2NetDevice->SetChannel(channel);
399 coord1->AddDevice(coord1NetDevice);
400 endNode->AddDevice(endNodeNetDevice);
401 coord2->AddDevice(coord2NetDevice);
406 coord1Mobility->SetPosition(Vector(0, 0, 0));
407 coord1NetDevice->GetPhy()->SetMobility(coord1Mobility);
411 endNodeMobility->SetPosition(Vector(90, 0, 0));
412 endNodeNetDevice->GetPhy()->SetMobility(endNodeMobility);
416 coord2Mobility->SetPosition(Vector(188, 0, 0));
417 coord2NetDevice->GetPhy()->SetMobility(coord2Mobility);
422 endNodeNetDevice->GetMac()->SetMlmeScanConfirmCallback(cb0);
426 endNodeNetDevice->GetMac()->SetMlmeBeaconNotifyIndicationCallback(cb1);
435 params.m_panCoor =
true;
437 params.m_bcnOrd = 15;
438 params.m_sfrmOrd = 15;
443 coord1NetDevice->GetMac(),
450 std::vector<uint8_t> payload;
451 payload.emplace_back(1);
452 payload.emplace_back(2);
453 pibAttribute->macBeaconPayload = payload;
466 coord2NetDevice->GetMac(),
483 endNodeNetDevice->GetMac(),
487 NS_LOG_DEBUG(
"----------- Start of TestActiveScanPanDescriptors -------------------");
492 "Error, Beacons not received or PAN descriptors not found");
498 "Error, Coordinator 1 (PAN 5) LQI value should be less than 255.");
501 "Error, Coordinator 2 (PAN 7) LQI value should be less than 255.");
504 "Error, Coordinator 1 (PAN 5) LQI value should be greater than 0.");
507 "Error, Coordinator 2 (PAN 7) LQI value should be greater than 0.");
511 "Error, Coordinator 2 (PAN 7) LQI value should"
512 " be less than Coordinator 1 (PAN 5).");
516 "Error, Beacon Payload not received or incorrect size (2 bytes)");
550 void DoRun()
override;
558 :
TestCase(
"Test an orphan scan and the reception of the commands involved")
585 if (params.m_orphanAddr ==
Mac64Address(
"00:00:00:00:00:00:00:02"))
623 channel->AddPropagationLossModel(propModel);
624 channel->SetPropagationDelayModel(delayModel);
635 coord1Mobility->SetPosition(Vector(0, 0, 0));
640 endNodeMobility->SetPosition(Vector(95, 0, 0));
658 params.m_panCoor =
true;
660 params.m_bcnOrd = 15;
661 params.m_sfrmOrd = 15;
689 NS_LOG_DEBUG(
"----------- Start of TestOrphanScan -------------------");
694 "Error, no coordinator realignment commands"
695 " received during orphan scan");
700 "Error, end device did not receive short address"
701 " during orphan scan");
Test MAC Active Scan PAN descriptor reception and check some of its values.
void ScanConfirm(MlmeScanConfirmParams params)
Function called in response to a MAC scan request.
uint32_t g_beaconPayloadSize
The size of the beacon payload received from a coordinator.
void BeaconNotifyIndication(MlmeBeaconNotifyIndicationParams params)
Function used to notify the reception of a beacon with payload.
TestActiveScanPanDescriptors()
~TestActiveScanPanDescriptors() override
std::vector< PanDescriptor > m_panDescriptorList
The list of PAN descriptors accumulated during the scan.
void DoRun() override
Implementation to actually run this TestCase.
Test MAC Orphan Scan Coordinator Realignment command reception and its values.
void DoRun() override
Implementation to actually run this TestCase.
void ScanConfirm(MlmeScanConfirmParams params)
Function called in response to a MAC scan request.
void OrphanIndicationCoord(MlmeOrphanIndicationParams params)
Function called as a result of receiving an orphan notification command on the coordinator.
~TestOrphanScan() override
Ptr< LrWpanNetDevice > coord1NetDevice
The LrWpanNetDevice of coordinator 1.
Ptr< LrWpanNetDevice > endNodeNetDevice
The LrWpanNetDevice of the end device.
bool m_orphanScanSuccess
Indicates a successful orphan scan.
Test PHY going to TRX_OFF after CSMA failure (MAC->RxOnWhenIdle(false)).
void DataConfirm(McpsDataConfirmParams params)
Function called when a Data confirm is invoked (After Tx Attempt).
void StateChangeNotificationDev0(std::string context, Time now, PhyEnumeration oldState, PhyEnumeration newState)
Function called when a the PHY state changes in Dev0 [00:01].
PhyEnumeration m_dev0State
Stores the PHY state of device 0 [00:01].
~TestRxOffWhenIdleAfterCsmaFailure() override
TestRxOffWhenIdleAfterCsmaFailure()
void StateChangeNotificationDev2(std::string context, Time now, PhyEnumeration oldState, PhyEnumeration newState)
Function called when a the PHY state changes in Dev2 [00:03].
void DoRun() override
Implementation to actually run this TestCase.
void DataIndication(McpsDataIndicationParams params, Ptr< Packet > p)
Function called when a Data indication is invoked.
static std::string LrWpanPhyEnumerationPrinter(lrwpan::PhyEnumeration e)
Transform the LrWpanPhyEnumeration enumeration into a printable string.
This class can contain 16 bit addresses.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
static Time Now()
Return the current simulation virtual time.
static void Run()
Run the simulation.
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
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.
void MlmeStartRequest(MlmeStartRequestParams params) override
IEEE 802.15.4-2006, section 7.1.14.1 MLME-START.request Request to allow a PAN coordinator to initiat...
void MlmeOrphanResponse(MlmeOrphanResponseParams params) override
IEEE 802.15.4-2011, section 6.2.7.2 MLME-ORPHAN.response Primitive used to initiatte a response to an...
void MlmeScanRequest(MlmeScanRequestParams params) override
IEEE 802.15.4-2011, section 6.2.10.1 MLME-SCAN.request Request primitive used to initiate a channel s...
void McpsDataRequest(McpsDataRequestParams params, Ptr< Packet > p) override
IEEE 802.15.4-2006, section 7.1.1.1 MCPS-DATA.request Request to transfer a MSDU.
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...
#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.
Callback< void, McpsDataIndicationParams, Ptr< Packet > > McpsDataIndicationCallback
This callback is called after a Mcps has successfully received a frame and wants to deliver it to the...
Callback< void, MlmeScanConfirmParams > MlmeScanConfirmCallback
This callback is called after a MlmeScanRequest has been called from the higher layer.
Callback< void, MlmeOrphanIndicationParams > MlmeOrphanIndicationCallback
This callback is called by the MLME and issued to its next higher layer following the reception of a ...
PhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
Callback< void, MlmeBeaconNotifyIndicationParams > MlmeBeaconNotifyIndicationCallback
This callback is called after a Mlme has successfully received a beacon frame and wants to deliver it...
Callback< void, McpsDataConfirmParams > McpsDataConfirmCallback
This callback is called after a McpsDataRequest has been called from the higher layer.
@ macBeaconPayload
The contents of the beacon payload.
@ IEEE_802_15_4_PHY_TRX_OFF
@ CHANNEL_ACCESS_FAILURE
A Tx could not take place due to activity in the CH.
@ SUCCESS
The operation was completed successfully.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report and abort if not.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report and abort if not.
Time Seconds(double value)
Construct a Time in the indicated unit.
static LrWpanMacTestSuite g_lrWpanMacTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
LogLevel
Logging severity classes and levels.
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
@ LOG_PREFIX_TIME
Prefix all trace prints with simulation time.
@ LOG_LEVEL_DEBUG
LOG_DEBUG and above.
@ LOG_PREFIX_NODE
Prefix all trace prints with simulation node.
void LogComponentEnableAll(LogLevel level)
Enable the logging output for all registered log components.
MCPS-DATA.confirm params.
MCPS-DATA.indication params.
MCPS-DATA.request params.
MLME-BEACON-NOTIFY.indication params.
MLME-ORPHAN.indication params.
MLME-ORPHAN.response params.
bool m_assocMember
T = allocated with this coord | F = otherwise.
Mac64Address m_orphanAddr
The address of the orphaned device.
Mac16Address m_shortAddr
The short address allocated.
MLME-SCAN.confirm params.
MLME-SCAN.request params.
MlmeScanType m_scanType
Indicates the type of scan performed as described in IEEE 802.15.4-2011 (5.1.2.1).
uint32_t m_scanChannels
The channel numbers to be scanned.
uint8_t m_scanDuration
The factor (0-14) used to calculate the length of time to spend scanning.
uint32_t m_chPage
The channel page on which to perform scan.
MLME-START.request params.
uint8_t m_logCh
Logical channel on which to start using the new superframe configuration.
uint8_t m_bcnOrd
Beacon Order, Used to calculate the beacon interval, a value of 15 indicates no periodic beacons will...
bool m_panCoor
On true this device will become coordinator.
uint8_t m_sfrmOrd
Superframe Order, indicates the length of the CAP in time slots.
uint16_t m_PanId
Pan Identifier used by the device.