20#include <ns3/constant-position-mobility-model.h>
21#include <ns3/core-module.h>
23#include <ns3/lr-wpan-module.h>
24#include <ns3/packet.h>
25#include <ns3/propagation-delay-model.h>
26#include <ns3/propagation-loss-model.h>
27#include <ns3/simulator.h>
28#include <ns3/single-model-spectrum-channel.h>
84 void DoRun()
override;
90 :
TestCase(
"Test PHY going to TRX_OFF state after CSMA failure")
101 NS_LOG_DEBUG(
"Received packet of size " << p->GetSize());
107 if (params.m_status == MacStatus::SUCCESS)
111 else if (params.m_status == MacStatus::CHANNEL_ACCESS_FAILURE)
113 NS_LOG_DEBUG(
"LrWpanMcpsDataConfirmStatus = Channel Access Failure");
124 << context <<
"PHY state change at " << now.
As(
Time::S) <<
" from "
138 << context <<
"PHY state change at " << now.
As(
Time::S) <<
" from "
170 Ptr<Node> interferenceNode = CreateObject<Node>();
183 CreateObject<LogDistancePropagationLossModel>();
185 CreateObject<ConstantSpeedPropagationDelayModel>();
186 channel->AddPropagationLossModel(propModel);
187 channel->SetPropagationDelayModel(delayModel);
189 dev0->SetChannel(channel);
190 dev1->SetChannel(channel);
191 dev2->SetChannel(channel);
196 interferenceNode->AddDevice(dev2);
199 dev0->GetPhy()->TraceConnect(
201 std::string(
"[address 00:01]"),
203 dev2->GetPhy()->TraceConnect(
205 std::string(
"[address 00:03]"),
209 CreateObject<ConstantPositionMobilityModel>();
210 sender0Mobility->SetPosition(Vector(0, 0, 0));
211 dev0->GetPhy()->SetMobility(sender0Mobility);
213 CreateObject<ConstantPositionMobilityModel>();
215 sender1Mobility->SetPosition(Vector(0, 1, 0));
216 dev1->GetPhy()->SetMobility(sender1Mobility);
219 CreateObject<ConstantPositionMobilityModel>();
221 sender3Mobility->SetPosition(Vector(0, 2, 0));
222 dev2->GetPhy()->SetMobility(sender3Mobility);
226 dev0->GetMac()->SetMcpsDataConfirmCallback(cb0);
230 dev0->GetMac()->SetMcpsDataIndicationCallback(cb1);
234 dev1->GetMac()->SetMcpsDataConfirmCallback(cb2);
238 dev1->GetMac()->SetMcpsDataIndicationCallback(cb3);
240 dev0->GetMac()->SetRxOnWhenIdle(
false);
241 dev1->GetMac()->SetRxOnWhenIdle(
false);
244 dev0->GetCsmaCa()->SetMacMinBE(0);
245 dev2->GetCsmaCa()->SetMacMinBE(0);
248 dev0->GetCsmaCa()->SetMacMaxCSMABackoffs(0);
249 dev2->GetCsmaCa()->SetMacMaxCSMABackoffs(0);
256 params.m_dstPanId = 0;
262 params.m_msduHandle = 0;
283 NS_LOG_DEBUG(
"----------- Start of TestRxOffWhenIdleAfterCsmaFailure -------------------");
287 PhyEnumeration::IEEE_802_15_4_PHY_TRX_OFF,
288 "Error, dev0 [00:01] PHY should be in TRX_OFF after CSMA failure");
320 void DoRun()
override;
329 :
TestCase(
"Test the reception of PAN descriptors while performing an active scan")
340 if (params.m_status == MacStatus::SUCCESS)
378 Ptr<Node> endNode = CreateObject<Node>();
386 coord1NetDevice->GetMac()->SetExtendedAddress(
"00:00:00:00:00:00:CA:FE");
387 coord1NetDevice->GetMac()->SetShortAddress(
Mac16Address(
"00:00"));
389 coord2NetDevice->GetMac()->SetExtendedAddress(
"00:00:00:00:00:00:BE:BE");
390 coord2NetDevice->GetMac()->SetShortAddress(
Mac16Address(
"00:00"));
393 endNodeNetDevice->GetMac()->SetExtendedAddress(
"00:00:00:00:00:00:00:03");
394 endNodeNetDevice->GetMac()->SetShortAddress(
Mac16Address(
"ff:ff"));
399 CreateObject<LogDistancePropagationLossModel>();
401 CreateObject<ConstantSpeedPropagationDelayModel>();
402 channel->AddPropagationLossModel(propModel);
403 channel->SetPropagationDelayModel(delayModel);
405 coord1NetDevice->SetChannel(channel);
406 endNodeNetDevice->SetChannel(channel);
407 coord2NetDevice->SetChannel(channel);
409 coord1->AddDevice(coord1NetDevice);
410 endNode->AddDevice(endNodeNetDevice);
411 coord2->AddDevice(coord2NetDevice);
415 CreateObject<ConstantPositionMobilityModel>();
416 coord1Mobility->SetPosition(Vector(0, 0, 0));
417 coord1NetDevice->GetPhy()->SetMobility(coord1Mobility);
420 CreateObject<ConstantPositionMobilityModel>();
421 endNodeMobility->SetPosition(Vector(100, 0, 0));
422 endNodeNetDevice->GetPhy()->SetMobility(endNodeMobility);
425 CreateObject<ConstantPositionMobilityModel>();
426 coord2Mobility->SetPosition(Vector(206, 0, 0));
427 coord2NetDevice->GetPhy()->SetMobility(coord2Mobility);
432 endNodeNetDevice->GetMac()->SetMlmeScanConfirmCallback(cb0);
436 endNodeNetDevice->GetMac()->SetMlmeBeaconNotifyIndicationCallback(cb1);
445 params.m_panCoor =
true;
447 params.m_bcnOrd = 15;
448 params.m_sfrmOrd = 15;
453 coord1NetDevice->GetMac(),
460 pibAttribute->macBeaconPayload = Create<Packet>(25);
461 coord2NetDevice->GetMac()->MlmeSetRequest(MacPibAttributeIdentifier::macBeaconPayload,
473 coord2NetDevice->GetMac(),
490 endNodeNetDevice->GetMac(),
494 NS_LOG_DEBUG(
"----------- Start of TestActiveScanPanDescriptors -------------------");
499 "Error, Beacons not received or PAN descriptors not found");
505 "Error, Coordinator 1 (PAN 5) LQI value should be less than 255.");
508 "Error, Coordinator 2 (PAN 7) LQI value should be less than 255.");
511 "Error, Coordinator 1 (PAN 5) LQI value should be greater than 0.");
514 "Error, Coordinator 2 (PAN 7) LQI value should be greater than 0.");
518 "Error, Coordinator 2 (PAN 7) LQI value should"
519 " be less than Coordinator 1 (PAN 5).");
523 "Error, Beacon Payload not received or incorrect size (25 bytes)");
557 void DoRun()
override;
565 :
TestCase(
"Test an orphan scan and the reception of the commands involved")
577 if (params.m_status == MacStatus::SUCCESS)
592 if (params.m_orphanAddr ==
Mac64Address(
"00:00:00:00:00:00:00:02"))
610 Ptr<Node> endNode = CreateObject<Node>();
627 CreateObject<LogDistancePropagationLossModel>();
629 CreateObject<ConstantSpeedPropagationDelayModel>();
630 channel->AddPropagationLossModel(propModel);
631 channel->SetPropagationDelayModel(delayModel);
641 CreateObject<ConstantPositionMobilityModel>();
642 coord1Mobility->SetPosition(Vector(0, 0, 0));
646 CreateObject<ConstantPositionMobilityModel>();
647 endNodeMobility->SetPosition(Vector(100, 0, 0));
665 params.m_panCoor =
true;
667 params.m_bcnOrd = 15;
668 params.m_sfrmOrd = 15;
696 NS_LOG_DEBUG(
"----------- Start of TestOrphanScan -------------------");
701 "Error, no coordinator realignment commands"
702 " received during orphan scan");
707 "Error, end device did not receive short address"
708 " 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.
Ptr< LrWpanMac > GetMac() const
Get the MAC used by this NetDevice.
void SetChannel(Ptr< SpectrumChannel > channel)
Set the channel to which the NetDevice, and therefore the PHY, should be attached to.
Ptr< LrWpanPhy > GetPhy() const
Get the PHY used by this NetDevice.
#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.
#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.