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>
67 void StateChangeNotificationDev0(std::string context,
78 void StateChangeNotificationDev2(std::string context,
83 void DoRun()
override;
89 :
TestCase(
"Test PHY going to TRX_OFF state after CSMA failure")
112 NS_LOG_DEBUG(
"LrWpanMcpsDataConfirmStatus = Channel Access Failure");
123 << context <<
"PHY state change at " << now.
As(Time::S) <<
" from "
124 << LrWpanHelper::LrWpanPhyEnumerationPrinter(oldState) <<
" to "
125 << LrWpanHelper::LrWpanPhyEnumerationPrinter(newState));
137 << context <<
"PHY state change at " << now.
As(Time::S) <<
" from "
138 << LrWpanHelper::LrWpanPhyEnumerationPrinter(oldState) <<
" to "
139 << LrWpanHelper::LrWpanPhyEnumerationPrinter(newState));
169 Ptr<Node> interferenceNode = CreateObject<Node>();
182 CreateObject<LogDistancePropagationLossModel>();
184 CreateObject<ConstantSpeedPropagationDelayModel>();
185 channel->AddPropagationLossModel(propModel);
186 channel->SetPropagationDelayModel(delayModel);
198 dev0->
GetPhy()->TraceConnect(
200 std::string(
"[address 00:01]"),
202 dev2->
GetPhy()->TraceConnect(
204 std::string(
"[address 00:03]"),
208 CreateObject<ConstantPositionMobilityModel>();
209 sender0Mobility->SetPosition(Vector(0, 0, 0));
210 dev0->
GetPhy()->SetMobility(sender0Mobility);
212 CreateObject<ConstantPositionMobilityModel>();
214 sender1Mobility->SetPosition(Vector(0, 1, 0));
215 dev1->
GetPhy()->SetMobility(sender1Mobility);
218 CreateObject<ConstantPositionMobilityModel>();
220 sender3Mobility->SetPosition(Vector(0, 2, 0));
221 dev2->
GetPhy()->SetMobility(sender3Mobility);
225 dev0->
GetMac()->SetMcpsDataConfirmCallback(cb0);
229 dev0->
GetMac()->SetMcpsDataIndicationCallback(cb1);
233 dev1->
GetMac()->SetMcpsDataConfirmCallback(cb2);
237 dev1->
GetMac()->SetMcpsDataIndicationCallback(cb3);
239 dev0->
GetMac()->SetRxOnWhenIdle(
false);
240 dev1->
GetMac()->SetRxOnWhenIdle(
false);
247 dev0->
GetCsmaCa()->SetMacMaxCSMABackoffs(0);
248 dev2->
GetCsmaCa()->SetMacMaxCSMABackoffs(0);
264 Simulator::ScheduleWithContext(1,
266 &LrWpanMac::McpsDataRequest,
275 Simulator::ScheduleWithContext(2,
277 &LrWpanMac::McpsDataRequest,
282 NS_LOG_DEBUG(
"----------- Start of TestRxOffWhenIdleAfterCsmaFailure -------------------");
287 "Error, dev0 [00:01] PHY should be in TRX_OFF after CSMA failure");
289 Simulator::Destroy();
319 void DoRun()
override;
328 :
TestCase(
"Test the reception of PAN descriptors while performing an active scan")
377 Ptr<Node> endNode = CreateObject<Node>();
385 coord1NetDevice->
GetMac()->SetExtendedAddress(
"00:00:00:00:00:00:CA:FE");
388 coord2NetDevice->
GetMac()->SetExtendedAddress(
"00:00:00:00:00:00:BE:BE");
392 endNodeNetDevice->
GetMac()->SetExtendedAddress(
"00:00:00:00:00:00:00:03");
398 CreateObject<LogDistancePropagationLossModel>();
400 CreateObject<ConstantSpeedPropagationDelayModel>();
401 channel->AddPropagationLossModel(propModel);
402 channel->SetPropagationDelayModel(delayModel);
414 CreateObject<ConstantPositionMobilityModel>();
415 coord1Mobility->SetPosition(Vector(0, 0, 0));
416 coord1NetDevice->
GetPhy()->SetMobility(coord1Mobility);
419 CreateObject<ConstantPositionMobilityModel>();
420 endNodeMobility->SetPosition(Vector(100, 0, 0));
421 endNodeNetDevice->
GetPhy()->SetMobility(endNodeMobility);
424 CreateObject<ConstantPositionMobilityModel>();
425 coord2Mobility->SetPosition(Vector(206, 0, 0));
426 coord2NetDevice->
GetPhy()->SetMobility(coord2Mobility);
431 endNodeNetDevice->
GetMac()->SetMlmeScanConfirmCallback(cb0);
435 endNodeNetDevice->
GetMac()->SetMlmeBeaconNotifyIndicationCallback(cb1);
449 Simulator::ScheduleWithContext(1,
451 &LrWpanMac::MlmeStartRequest,
452 coord1NetDevice->
GetMac(),
459 pibAttribute->macBeaconPayload = Create<Packet>(25);
469 Simulator::ScheduleWithContext(2,
471 &LrWpanMac::MlmeStartRequest,
472 coord2NetDevice->
GetMac(),
486 Simulator::ScheduleWithContext(1,
488 &LrWpanMac::MlmeScanRequest,
489 endNodeNetDevice->
GetMac(),
492 Simulator::Stop(
Seconds(2000));
493 NS_LOG_DEBUG(
"----------- Start of TestActiveScanPanDescriptors -------------------");
498 "Error, Beacons not received or PAN descriptors not found");
504 "Error, Coordinator 1 (PAN 5) LQI value should be less than 255.");
507 "Error, Coordinator 2 (PAN 7) LQI value should be less than 255.");
510 "Error, Coordinator 1 (PAN 5) LQI value should be greater than 0.");
513 "Error, Coordinator 2 (PAN 7) LQI value should be greater than 0.");
517 "Error, Coordinator 2 (PAN 7) LQI value should"
518 " be less than Coordinator 1 (PAN 5).");
522 "Error, Beacon Payload not received or incorrect size (25 bytes)");
525 Simulator::Destroy();
556 void DoRun()
override;
564 :
TestCase(
"Test an orphan scan and the reception of the commands involved")
598 Simulator::ScheduleNow(&LrWpanMac::MlmeOrphanResponse,
609 Ptr<Node> endNode = CreateObject<Node>();
626 CreateObject<LogDistancePropagationLossModel>();
628 CreateObject<ConstantSpeedPropagationDelayModel>();
629 channel->AddPropagationLossModel(propModel);
630 channel->SetPropagationDelayModel(delayModel);
640 CreateObject<ConstantPositionMobilityModel>();
641 coord1Mobility->SetPosition(Vector(0, 0, 0));
645 CreateObject<ConstantPositionMobilityModel>();
646 endNodeMobility->SetPosition(Vector(100, 0, 0));
669 Simulator::ScheduleWithContext(1,
671 &LrWpanMac::MlmeStartRequest,
688 Simulator::ScheduleWithContext(1,
690 &LrWpanMac::MlmeScanRequest,
694 Simulator::Stop(
Seconds(4000));
695 NS_LOG_DEBUG(
"----------- Start of TestOrphanScan -------------------");
700 "Error, no coordinator realignment commands"
701 " received during orphan scan");
706 "Error, end device did not receive short address"
707 " during orphan scan");
710 Simulator::Destroy();
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)
LrWpanPhyEnumeration m_dev0State
Stores the PHY state of device 0 [00:01].
~TestRxOffWhenIdleAfterCsmaFailure() override
TestRxOffWhenIdleAfterCsmaFailure()
void StateChangeNotificationDev2(std::string context, Time now, LrWpanPhyEnumeration oldState, LrWpanPhyEnumeration newState)
Function called when a the PHY state changes in Dev2 [00:03].
void DoRun() override
Implementation to actually run this TestCase.
void StateChangeNotificationDev0(std::string context, Time now, LrWpanPhyEnumeration oldState, LrWpanPhyEnumeration newState)
Function called when a the PHY state changes in Dev0 [00:01].
void DataIndication(McpsDataIndicationParams params, Ptr< Packet > p)
Function called when a Data indication is invoked.
void SetChannel(Ptr< SpectrumChannel > channel)
Set the channel to which the NetDevice, and therefore the PHY, should be attached to.
Ptr< LrWpanMac > GetMac() const
Get the MAC used by this NetDevice.
Ptr< LrWpanPhy > GetPhy() const
Get the PHY used by this NetDevice.
void SetAddress(Address address) override
This method indirects to LrWpanMac::SetShortAddress ()
Ptr< LrWpanCsmaCa > GetCsmaCa() const
Get the CSMA/CA implementation used by this NetDevice.
This class can contain 16 bit addresses.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
void AddTestCase(TestCase *testCase, TestDuration 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.
#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.
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
@ CHANNEL_ACCESS_FAILURE
CHANNEL_ACCESS_FAILURE.
@ IEEE_802_15_4_PHY_TRX_OFF
Time Now()
create an ns3::Time instance which contains the current simulation time.
#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 void DataConfirm(McpsDataConfirmParams params)
Function called when a Data confirm is invoked.
static LrWpanMacTestSuite g_lrWpanMacTestSuite
Static variable for test initialization.
void DataIndication(McpsDataIndicationParams params, Ptr< Packet > p)
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.
params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.
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.
Mac16Address m_shortAddr
The short address allocated.
Mac64Address m_orphanAddr
The address of the orphaned device.
bool m_assocMember
T = allocated with this coord | F = otherwise.
MLME-SCAN.confirm params.
MLME-SCAN.request params.
uint32_t m_scanChannels
The channel numbers to be scanned.
uint32_t m_chPage
The channel page on which to perform scan.
uint8_t m_scanDuration
The factor (0-14) used to calculate the length of time to spend scanning.
LrWpanMlmeScanType m_scanType
Indicates the type of scan performed as described in IEEE 802.15.4-2011 (5.1.2.1).
MLME-START.request params.
uint8_t m_logCh
Logical channel on which to start using the new superframe configuration.
bool m_panCoor
On true this device will become coordinator.
uint8_t m_bcnOrd
Beacon Order, Used to calculate the beacon interval, a value of 15 indicates no periodic beacons will...
uint16_t m_PanId
Pan Identifier used by the device.
uint8_t m_sfrmOrd
Superframe Order, indicates the length of the CAP in time slots.