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());
96 if (params.m_status == MacStatus::SUCCESS)
100 else if (params.m_status == MacStatus::CHANNEL_ACCESS_FAILURE)
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 "
175 channel->AddPropagationLossModel(propModel);
176 channel->SetPropagationDelayModel(delayModel);
178 dev0->SetChannel(channel);
179 dev1->SetChannel(channel);
180 dev2->SetChannel(channel);
185 interferenceNode->AddDevice(dev2);
188 dev0->GetPhy()->TraceConnect(
190 std::string(
"[address 00:01]"),
192 dev2->GetPhy()->TraceConnect(
194 std::string(
"[address 00:03]"),
199 sender0Mobility->SetPosition(Vector(0, 0, 0));
200 dev0->GetPhy()->SetMobility(sender0Mobility);
204 sender1Mobility->SetPosition(Vector(0, 1, 0));
205 dev1->GetPhy()->SetMobility(sender1Mobility);
210 sender3Mobility->SetPosition(Vector(0, 2, 0));
211 dev2->GetPhy()->SetMobility(sender3Mobility);
215 dev0->GetMac()->SetMcpsDataConfirmCallback(cb0);
219 dev0->GetMac()->SetMcpsDataIndicationCallback(cb1);
223 dev1->GetMac()->SetMcpsDataConfirmCallback(cb2);
227 dev1->GetMac()->SetMcpsDataIndicationCallback(cb3);
229 dev0->GetMac()->SetRxOnWhenIdle(
false);
230 dev1->GetMac()->SetRxOnWhenIdle(
false);
233 dev0->GetCsmaCa()->SetMacMinBE(0);
234 dev2->GetCsmaCa()->SetMacMinBE(0);
237 dev0->GetCsmaCa()->SetMacMaxCSMABackoffs(0);
238 dev2->GetCsmaCa()->SetMacMaxCSMABackoffs(0);
245 params.m_dstPanId = 0;
251 params.m_msduHandle = 0;
272 NS_LOG_DEBUG(
"----------- Start of TestRxOffWhenIdleAfterCsmaFailure -------------------");
276 PhyEnumeration::IEEE_802_15_4_PHY_TRX_OFF,
277 "Error, dev0 [00:01] PHY should be in TRX_OFF after CSMA failure");
309 void DoRun()
override;
318 :
TestCase(
"Test the reception of PAN descriptors while performing an active scan")
329 if (params.m_status == MacStatus::SUCCESS)
375 coord1NetDevice->GetMac()->SetExtendedAddress(
"00:00:00:00:00:00:CA:FE");
376 coord1NetDevice->GetMac()->SetShortAddress(
Mac16Address(
"00:00"));
378 coord2NetDevice->GetMac()->SetExtendedAddress(
"00:00:00:00:00:00:BE:BE");
379 coord2NetDevice->GetMac()->SetShortAddress(
Mac16Address(
"00:00"));
382 endNodeNetDevice->GetMac()->SetExtendedAddress(
"00:00:00:00:00:00:00:03");
383 endNodeNetDevice->GetMac()->SetShortAddress(
Mac16Address(
"ff:ff"));
391 channel->AddPropagationLossModel(propModel);
392 channel->SetPropagationDelayModel(delayModel);
394 coord1NetDevice->SetChannel(channel);
395 endNodeNetDevice->SetChannel(channel);
396 coord2NetDevice->SetChannel(channel);
398 coord1->AddDevice(coord1NetDevice);
399 endNode->AddDevice(endNodeNetDevice);
400 coord2->AddDevice(coord2NetDevice);
405 coord1Mobility->SetPosition(Vector(0, 0, 0));
406 coord1NetDevice->GetPhy()->SetMobility(coord1Mobility);
410 endNodeMobility->SetPosition(Vector(100, 0, 0));
411 endNodeNetDevice->GetPhy()->SetMobility(endNodeMobility);
415 coord2Mobility->SetPosition(Vector(206, 0, 0));
416 coord2NetDevice->GetPhy()->SetMobility(coord2Mobility);
421 endNodeNetDevice->GetMac()->SetMlmeScanConfirmCallback(cb0);
425 endNodeNetDevice->GetMac()->SetMlmeBeaconNotifyIndicationCallback(cb1);
434 params.m_panCoor =
true;
436 params.m_bcnOrd = 15;
437 params.m_sfrmOrd = 15;
442 coord1NetDevice->GetMac(),
449 std::vector<uint8_t> payload;
450 payload.emplace_back(1);
451 payload.emplace_back(2);
452 pibAttribute->macBeaconPayload = payload;
453 coord2NetDevice->GetMac()->MlmeSetRequest(MacPibAttributeIdentifier::macBeaconPayload,
465 coord2NetDevice->GetMac(),
482 endNodeNetDevice->GetMac(),
486 NS_LOG_DEBUG(
"----------- Start of TestActiveScanPanDescriptors -------------------");
491 "Error, Beacons not received or PAN descriptors not found");
497 "Error, Coordinator 1 (PAN 5) LQI value should be less than 255.");
500 "Error, Coordinator 2 (PAN 7) LQI value should be less than 255.");
503 "Error, Coordinator 1 (PAN 5) LQI value should be greater than 0.");
506 "Error, Coordinator 2 (PAN 7) LQI value should be greater than 0.");
510 "Error, Coordinator 2 (PAN 7) LQI value should"
511 " be less than Coordinator 1 (PAN 5).");
515 "Error, Beacon Payload not received or incorrect size (2 bytes)");
549 void DoRun()
override;
557 :
TestCase(
"Test an orphan scan and the reception of the commands involved")
569 if (params.m_status == MacStatus::SUCCESS)
584 if (params.m_orphanAddr ==
Mac64Address(
"00:00:00:00:00:00:00:02"))
622 channel->AddPropagationLossModel(propModel);
623 channel->SetPropagationDelayModel(delayModel);
634 coord1Mobility->SetPosition(Vector(0, 0, 0));
639 endNodeMobility->SetPosition(Vector(100, 0, 0));
657 params.m_panCoor =
true;
659 params.m_bcnOrd = 15;
660 params.m_sfrmOrd = 15;
688 NS_LOG_DEBUG(
"----------- Start of TestOrphanScan -------------------");
693 "Error, no coordinator realignment commands"
694 " received during orphan scan");
699 "Error, end device did not receive short address"
700 " 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.
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.
#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.
PhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
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.
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...
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.
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.