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();
318 void DoRun()
override;
327 :
TestCase(
"Test the reception of PAN descriptors while performing an active scan")
376 Ptr<Node> endNode = CreateObject<Node>();
390 CreateObject<LogDistancePropagationLossModel>();
392 CreateObject<ConstantSpeedPropagationDelayModel>();
393 channel->AddPropagationLossModel(propModel);
394 channel->SetPropagationDelayModel(delayModel);
406 CreateObject<ConstantPositionMobilityModel>();
407 coord1Mobility->SetPosition(Vector(0, 0, 0));
408 coord1NetDevice->
GetPhy()->SetMobility(coord1Mobility);
411 CreateObject<ConstantPositionMobilityModel>();
412 endNodeMobility->SetPosition(Vector(100, 0, 0));
413 endNodeNetDevice->
GetPhy()->SetMobility(endNodeMobility);
416 CreateObject<ConstantPositionMobilityModel>();
417 coord2Mobility->SetPosition(Vector(206, 0, 0));
418 coord2NetDevice->
GetPhy()->SetMobility(coord2Mobility);
423 endNodeNetDevice->
GetMac()->SetMlmeScanConfirmCallback(cb0);
427 endNodeNetDevice->
GetMac()->SetMlmeBeaconNotifyIndicationCallback(cb1);
441 Simulator::ScheduleWithContext(1,
443 &LrWpanMac::MlmeStartRequest,
444 coord1NetDevice->
GetMac(),
451 pibAttribute->macBeaconPayload = Create<Packet>(25);
461 Simulator::ScheduleWithContext(2,
463 &LrWpanMac::MlmeStartRequest,
464 coord2NetDevice->
GetMac(),
478 Simulator::ScheduleWithContext(1,
480 &LrWpanMac::MlmeScanRequest,
481 endNodeNetDevice->
GetMac(),
484 Simulator::Stop(
Seconds(2000));
485 NS_LOG_DEBUG(
"----------- Start of TestActiveScanPanDescriptors -------------------");
490 "Error, Beacons not received or PAN descriptors not found");
493 "Error, Coordinator 1 (PAN 5) LQI value should be less than 255.");
496 "Error, Coordinator 2 (PAN 7) LQI value should be less than 255.");
499 "Error, Coordinator 1 (PAN 5) LQI value should be greater than 0.");
502 "Error, Coordinator 2 (PAN 7) LQI value should be greater than 0.");
507 "Error, Coordinator 2 (PAN 7) LQI value should be less than Coordinator 1 (PAN 5).");
511 "Error, Beacon Payload not received or incorrect size (25 bytes)");
513 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 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.
@ IEEE_802_15_4_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-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
A value used to calculate the length of time to spend scanning [aBaseSuperframeDuration * (2^m_scanDu...
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.