lr-wpan: (fixes #636) Ext address, short address and manual assoc adjustments

This commit is contained in:
Alberto Gallegos Ramonet
2023-02-13 16:08:18 +09:00
parent 5d0948a7c7
commit c85819b502
13 changed files with 186 additions and 110 deletions

View File

@@ -23,6 +23,7 @@ Changes from ns-3.37 to ns-3.38
* (core) Added several macros in **warnings.h** to silence compiler warnings in specific sections of code. Their use is discouraged, unless really necessary.
* (internet-apps) Add class `Ping` for a ping model that works for both IPv4 and IPv6.
* In `src/spectrum`, a new fast-fading model `TwoRaySpectrumPropagationLossModel` has been added. This model serves as a performance-oriented alternative to the `ThreeGppSpectrumPropagationLossModel` and `ThreeGppChannelModel` classes, and it has been designed with the goal of providing end-to-end channel samples which are statistically close to the ones generated by the latter.
* (lr-wpan) `LrWpanNetDevice::SetPanAssociation` is introduced to create more complex topologies (multi-hop) using a manual association.
### Changes to existing API
@@ -35,6 +36,7 @@ Changes from ns-3.37 to ns-3.38
* (lr-wpan) Adds beacon payload handle support (MLME-SET.request) in **LrWpanMac**.
* (core) Now test-runner exits if no TestSuite is specified.
* (lr-wpan) Adds the possibility to modify the Rx sensitivity in **LrWpanPhy**.
* (lr-wpan) `LrWpanHelper::CreateAssociatedPan` replace `LrWpanHelper::AssociateToPan` and is able to create an associated PAN of the devices with both short addresses (16-bits) and extended addresses (EUI-64 bits).
### Changes to build system

View File

@@ -43,6 +43,7 @@ Release 3-dev
- (core) !1236 - Deprecation warnings are silenced while calling `NS_OBJECT_ENSURE_REGISTERED`
- (wifi) Fixed multiple issues about setting the TXOP holder
- (wifi) #861 - bianchi validation script can't run with 11ax
- (lr-wpan) #636 - Ext address, short address and manual assoc adjustments
Release 3.37
------------

View File

@@ -88,7 +88,7 @@ main(int argc, char** argv)
// Add and install the LrWpanNetDevice for each node
// lrWpanHelper.EnableLogComponents();
NetDeviceContainer devContainer = lrWpanHelper.Install(nodes);
lrWpanHelper.AssociateToPan(devContainer, 10);
lrWpanHelper.CreateAssociatedPan(devContainer, 10);
std::cout << "Created " << devContainer.GetN() << " devices" << std::endl;
std::cout << "There are " << nodes.GetN() << " nodes" << std::endl;

View File

@@ -30,6 +30,9 @@
* on the LQI results of the scan. A node may not find any beacons if the coordinator is outside its
* communication range. An association request may not be send if LQI is too low for an association.
*
* The coordinator in PAN 5 runs in extended addressing mode and do not assign short addresses.
* The coordinator in PAN 7 runs in short addressing mode and assign short addresses.
*
* At the end of the simulation, an animation is generated (lrwpan-bootstrap.xml), showing the
* results of the association with each coordinator. This simulation can take a few seconds to
* complete.
@@ -104,11 +107,22 @@ ScanConfirm(Ptr<LrWpanNetDevice> device, MlmeScanConfirmParams params)
// Only request association if the coordinator is permitting association at this moment.
if (params.m_panDescList[panDescIndex].m_superframeSpec.IsAssocPermit())
{
std::string addressing;
if (params.m_panDescList[panDescIndex].m_coorAddrMode == SHORT_ADDR)
{
addressing = "Short";
}
else if (params.m_panDescList[panDescIndex].m_coorAddrMode == EXT_ADDR)
{
addressing = "Ext";
}
std::cout << Simulator::Now().As(Time::S) << " Node " << device->GetNode()->GetId()
<< " [" << device->GetMac()->GetShortAddress() << " | "
<< device->GetMac()->GetExtendedAddress() << "]"
<< " MLME-scan.confirm: Selected PAN ID "
<< params.m_panDescList[panDescIndex].m_coorPanId << " | LQI "
<< params.m_panDescList[panDescIndex].m_coorPanId
<< "| Coord addressing mode: " << addressing << " | LQI "
<< static_cast<int>(params.m_panDescList[panDescIndex].m_linkQuality)
<< "\n";
@@ -126,6 +140,7 @@ ScanConfirm(Ptr<LrWpanNetDevice> device, MlmeScanConfirmParams params)
assocParams.m_coordAddrMode = LrWpanAddressMode::SHORT_ADDR;
assocParams.m_coordShortAddr =
params.m_panDescList[panDescIndex].m_coorShortAddr;
assocParams.m_capabilityInfo.SetShortAddrAllocOn(true);
}
else if (assocParams.m_coordAddrMode == LrWpanAddressMode::EXT_ADDR)
{
@@ -133,6 +148,7 @@ ScanConfirm(Ptr<LrWpanNetDevice> device, MlmeScanConfirmParams params)
assocParams.m_coordExtAddr =
params.m_panDescList[panDescIndex].m_coorExtAddr;
assocParams.m_coordShortAddr = Mac16Address("ff:fe");
assocParams.m_capabilityInfo.SetShortAddrAllocOn(false);
}
Simulator::ScheduleNow(&LrWpanMac::MlmeAssociateRequest,
@@ -169,13 +185,14 @@ ScanConfirm(Ptr<LrWpanNetDevice> device, MlmeScanConfirmParams params)
static void
AssociateIndication(Ptr<LrWpanNetDevice> device, MlmeAssociateIndicationParams params)
{
// This is typically implemented by the Coordinator next layer (3rd layer or higher).
// This is typically implemented by the coordinator next layer (3rd layer or higher).
// The steps described below are out of the scope of the standard.
// Here the 3rd layer should check:
// a) Whether or not the device was previously associated with this PAN (the coordinator
// keeps a list). b) The coordinator have sufficient resources available to allow the
// association.
// a) Whether or not the device was previously associated with this PAN
// (the coordinator keeps a list).
// b) The coordinator have sufficient resources available to allow the
// association.
// If the association fails, status = 1 or 2 and assocShortAddr = FFFF.
// In this example, the coordinator accepts every association request and have no association
@@ -360,7 +377,8 @@ main(int argc, char* argv[])
NetDeviceContainer lrwpanDevices = lrWpanHelper.Install(nodes);
lrwpanDevices.Add(lrWpanHelper.Install(coordinators));
lrWpanHelper.AssociateToPan(lrwpanDevices, 0xffff);
// Set the extended address to all devices (EUI-64)
lrWpanHelper.SetExtendedAddresses(lrwpanDevices);
// Devices hooks & MAC MLME-scan primitive set
for (NodeContainer::Iterator i = nodes.Begin(); i != nodes.End(); i++)
@@ -417,6 +435,16 @@ main(int argc, char* argv[])
Ptr<NetDevice> netDeviceCoor2 = coor2->GetDevice(0);
Ptr<LrWpanNetDevice> coor2Device = DynamicCast<LrWpanNetDevice>(netDeviceCoor2);
// Coordinators require that their short address is explicitly set.
// Either FF:FE to indicate that only extended addresses will be used in the following
// data communications or any other value (except for FF:FF) to indicate that the coordinator
// will use the short address in these communications.
// The default short address for all devices is FF:FF (unassigned/no associated).
// coor1 (PAN 5) = extended addressing mode coor2 (PAN 7) = short addressing mode
coor1Device->GetMac()->SetShortAddress(Mac16Address("FF:FE"));
coor2Device->GetMac()->SetShortAddress(Mac16Address("CA:FE"));
// PAN coordinator 1 (PAN 5) transmits beacons on channel 12
MlmeStartRequestParams params;
params.m_panCoor = true;

View File

@@ -231,85 +231,80 @@ LrWpanHelper::AssignStreams(NetDeviceContainer c, int64_t stream)
}
void
LrWpanHelper::AssociateToPan(NetDeviceContainer c, uint16_t panId)
LrWpanHelper::CreateAssociatedPan(NetDeviceContainer c, uint16_t panId)
{
NetDeviceContainer devices;
uint16_t id = 1;
uint8_t idBuf[2];
uint8_t idBuf[2] = {0, 0};
uint8_t idBuf2[8] = {0, 0, 0, 0, 0, 0, 0, 0};
Mac16Address address16;
Mac64Address address64;
Mac16Address coordShortAddr;
Mac64Address coordExtAddr;
for (NetDeviceContainer::Iterator i = c.Begin(); i != c.End(); i++)
{
if (id < 0x0001 || id > 0xFFFD)
{
NS_ABORT_MSG("Only 65533 addresses supported. Range [00:01]-[FF:FD]");
}
Ptr<LrWpanNetDevice> device = DynamicCast<LrWpanNetDevice>(*i);
if (device)
{
idBuf[0] = (id >> 8) & 0xff;
idBuf[1] = (id >> 0) & 0xff;
Mac16Address address;
address.CopyFrom(idBuf);
address16.CopyFrom(idBuf);
idBuf2[6] = (id >> 8) & 0xff;
idBuf2[7] = (id >> 0) & 0xff;
address64.CopyFrom(idBuf2);
if (address64 == Mac64Address("00:00:00:00:00:00:00:01"))
{
// We use the first device in the container as coordinator
coordShortAddr = address16;
coordExtAddr = address64;
}
// TODO: Change this to device->GetAddress() if GetAddress can guarantee a
// an extended address (currently only gives 48 address or 16 bits addresses)
device->GetMac()->SetExtendedAddress(address64);
device->SetPanAssociation(panId, coordExtAddr, coordShortAddr, address16);
device->GetMac()->SetPanId(panId);
device->GetMac()->SetShortAddress(address);
id++;
}
}
}
void
LrWpanHelper::AssociateToBeaconPan(NetDeviceContainer c,
uint16_t panId,
Mac16Address coor,
uint8_t bcnOrd,
uint8_t sfrmOrd)
LrWpanHelper::SetExtendedAddresses(NetDeviceContainer c)
{
NetDeviceContainer devices;
uint16_t id = 1;
uint8_t idBuf[2];
Mac16Address address;
if (bcnOrd > 14)
{
NS_LOG_DEBUG("The Beacon Order must be an int between 0 and 14");
return;
}
if ((sfrmOrd > 14) || (sfrmOrd > bcnOrd))
{
NS_LOG_DEBUG("The Superframe Order must be an int between 0 and 14, and less or equal to "
"Beacon Order");
return;
}
uint64_t id = 1;
uint8_t idBuf[8] = {0, 0, 0, 0, 0, 0, 0, 0};
Mac64Address address64;
for (NetDeviceContainer::Iterator i = c.Begin(); i != c.End(); i++)
{
Ptr<LrWpanNetDevice> device = DynamicCast<LrWpanNetDevice>(*i);
if (device)
{
idBuf[0] = (id >> 8) & 0xff;
idBuf[1] = (id >> 0) & 0xff;
address.CopyFrom(idBuf);
idBuf[0] = (id >> 56) & 0xff;
idBuf[1] = (id >> 48) & 0xff;
idBuf[2] = (id >> 40) & 0xff;
idBuf[3] = (id >> 32) & 0xff;
idBuf[4] = (id >> 24) & 0xff;
idBuf[5] = (id >> 16) & 0xff;
idBuf[6] = (id >> 8) & 0xff;
idBuf[7] = (id >> 0) & 0xff;
device->GetMac()->SetShortAddress(address);
address64.CopyFrom(idBuf);
if (address == coor)
{
MlmeStartRequestParams params;
params.m_panCoor = true;
params.m_PanId = panId;
params.m_bcnOrd = bcnOrd;
params.m_sfrmOrd = sfrmOrd;
// TODO: Change this to device->SetAddress() if GetAddress can guarantee
// to set only extended addresses
device->GetMac()->SetExtendedAddress(address64);
Ptr<UniformRandomVariable> uniformRandomVariable =
CreateObject<UniformRandomVariable>();
;
Time jitter = Time(MilliSeconds(uniformRandomVariable->GetInteger(0, 10)));
Simulator::Schedule(jitter, &LrWpanMac::MlmeStartRequest, device->GetMac(), params);
}
else
{
device->GetMac()->SetPanId(panId);
device->GetMac()->SetAssociatedCoor(coor);
}
id++;
}
}

View File

@@ -109,29 +109,23 @@ class LrWpanHelper : public PcapHelperForDevice, public AsciiTraceHelperForDevic
NetDeviceContainer Install(NodeContainer c);
/**
* \brief Associate the nodes to the same PAN
* \brief Creates an PAN with associated nodes and assigned addresses(16 and 64)
* from the nodes in the node container.
* The first node in the container becomes the PAN coordinator.
*
* \param c a set of nodes
* \param panId the PAN Id
* \param c a The node container with the nodes that will form the PAN.
* \param panId The PAN identifier.
*/
void AssociateToPan(NetDeviceContainer c, uint16_t panId);
void CreateAssociatedPan(NetDeviceContainer c, uint16_t panId);
/**
* \brief Associate the nodes to the same PAN and initiate beacon enabled mode.
* \brief Set the extended 64 bit addresses (EUI-64) for a group of
* LrWpanNetDevices
*
* \param c The NetDevice container.
*
* \param c a set of nodes
* \param panId the PAN id
* \param coor the address of the PAN coordinator
* \param bcnOrd indicates the interval between beacons.
* The value must be an int between 0 and 14.
* \param sfrmOrd indicates the length of the superframe.
* The value must be an int between 0 and 14 and less or equal to the bcnOrd
*/
void AssociateToBeaconPan(NetDeviceContainer c,
uint16_t panId,
Mac16Address coor,
uint8_t bcnOrd,
uint8_t sfrmOrd);
void SetExtendedAddresses(NetDeviceContainer c);
/**
* Helper to enable all LrWpan log components with one statement

View File

@@ -216,7 +216,7 @@ LrWpanMac::LrWpanMac()
m_macBsn = SequenceNumber8(uniformVar->GetValue());
m_macBeaconPayload = nullptr;
m_macBeaconPayloadLength = 0;
m_shortAddress = Mac16Address("00:00");
m_shortAddress = Mac16Address("FF:FF"); // FF:FF = The address is not assigned.
}
LrWpanMac::~LrWpanMac()
@@ -2894,12 +2894,12 @@ LrWpanMac::PdDataConfirm(LrWpanPhyEnumeration status)
case CommandPayloadHeader::SUCCESSFUL:
confirmParams.m_status =
LrWpanMlmeAssociateConfirmStatus::MLMEASSOC_SUCCESS;
confirmParams.m_assocShortAddr =
GetShortAddress(); // the original short address used in the association
// request
SetShortAddress(
receivedMacPayload
.GetShortAddr()); // the assigned short address by the coordinator
// The original short address used in the association
// used in the association request
confirmParams.m_assocShortAddr = GetShortAddress();
// The assigned short address by the coordinator
SetShortAddress(receivedMacPayload.GetShortAddr());
m_macPanId = receivedMacHdr.GetSrcPanId();
break;
case CommandPayloadHeader::FULL_CAPACITY:

View File

@@ -1990,7 +1990,7 @@ class LrWpanMac : public Object
/**
* The packet which is currently being sent by the MAC layer.
*/
Ptr<Packet> m_txPkt; // XXX need packet buffer instead of single packet
Ptr<Packet> m_txPkt;
/**
* The command request packet received. Briefly stored to proceed with operations
@@ -1999,15 +1999,14 @@ class LrWpanMac : public Object
Ptr<Packet> m_rxPkt;
/**
* The short address used by this MAC. Currently we do not have complete
* extended address support in the MAC, nor do we have the association
* primitives, so this address has to be configured manually.
* The short address (16 bit address) used by this MAC. If supported,
* the short address must be assigned to the device by the coordinator
* during the association process.
*/
Mac16Address m_shortAddress;
/**
* The extended address used by this MAC. Extended addresses are currently not
* really supported.
* The extended 64 address (IEEE EUI-64) used by this MAC.
*/
Mac64Address m_selfExt;

View File

@@ -257,6 +257,10 @@ LrWpanNetDevice::SetAddress(Address address)
{
m_mac->SetShortAddress(Mac16Address::ConvertFrom(address));
}
else if (Mac64Address::IsMatchingType(address))
{
m_mac->SetExtendedAddress(Mac64Address::ConvertFrom(address));
}
else if (Mac48Address::IsMatchingType(address))
{
uint8_t buf[6];
@@ -292,6 +296,19 @@ LrWpanNetDevice::GetAddress() const
return pseudoAddress;
}
void
LrWpanNetDevice::SetPanAssociation(uint16_t panId,
Mac64Address coordExtAddr,
Mac16Address coordShortAddr,
Mac16Address assignedShortAddr)
{
NS_LOG_FUNCTION(this);
m_mac->SetPanId(panId);
m_mac->SetAssociatedCoor(coordExtAddr);
m_mac->SetAssociatedCoor(coordShortAddr);
m_mac->SetShortAddress(assignedShortAddr);
}
bool
LrWpanNetDevice::SetMtu(const uint16_t mtu)
{

View File

@@ -135,6 +135,36 @@ class LrWpanNetDevice : public NetDevice
* \returns The short address.
*/
Address GetAddress() const override;
/**
* This method is use to manually configure the coordinator through
* which the device or coordinator is associated. When assigning a short address
* the extended address must also be present.
*
* \param panId The id of the PAN used by the coordinator device.
*
* \param coordExtAddr The coordinator extended address (EUI-64) through which this
* device or coordinator is associated.
*
* \param coordShortAddr The coordinator assigned short address through which this
* device or coordinator is associated.
* [FF:FF] address indicates that the value is unknown.
* [FF:FE] indicates that the associated coordinator is using only
* its extended address.
*
*
* \param assignedShortAddr The assigned short address for this device.
* [FF:FF] address indicates that the device have no short address
* and is not associated.
* [FF:FE] address indicates that the devices has associated but
* has not been allocated a short address.
*
*/
void SetPanAssociation(uint16_t panId,
Mac64Address coordExtAddr,
Mac16Address coordShortAddr,
Mac16Address assignedShortAddr);
bool SetMtu(const uint16_t mtu) override;
uint16_t GetMtu() const override;
bool IsLinkUp() const override;

View File

@@ -31,14 +31,14 @@
using namespace ns3;
static void
dataSentMacConfirm(McpsDataConfirmParams params)
DataSentMacConfirm(Ptr<LrWpanNetDevice> device, McpsDataConfirmParams params)
{
// In the case of transmissions with the Ack flag activated, the transaction is only
// successful if the Ack was received.
if (params.m_status == LrWpanMcpsDataConfirmStatus::IEEE_802_15_4_SUCCESS)
{
NS_LOG_UNCOND("**********" << Simulator::Now().As(Time::S)
<< " | Transmission successfully sent");
std::cout << Simulator::Now().As(Time::S) << " | Node " << device->GetNode()->GetId()
<< " | Transmission successfully sent\n";
}
}
@@ -53,8 +53,7 @@ main(int argc, char** argv)
if (verbose)
{
LogComponentEnableAll(LOG_PREFIX_TIME);
LogComponentEnableAll(LOG_PREFIX_FUNC);
LogComponentEnableAll(LogLevel(LOG_PREFIX_TIME | LOG_PREFIX_FUNC | LOG_PREFIX_NODE));
LogComponentEnable("LrWpanMac", LOG_LEVEL_INFO);
LogComponentEnable("LrWpanCsmaCa", LOG_LEVEL_INFO);
LogComponentEnable("LrWpanHelper", LOG_LEVEL_ALL);
@@ -89,15 +88,13 @@ main(int argc, char** argv)
Ptr<LrWpanNetDevice> dev1 = lrwpanDevices.Get(0)->GetObject<LrWpanNetDevice>();
Ptr<LrWpanNetDevice> dev2 = lrwpanDevices.Get(1)->GetObject<LrWpanNetDevice>();
McpsDataConfirmCallback cb1;
cb1 = MakeCallback(&dataSentMacConfirm);
dev1->GetMac()->SetMcpsDataConfirmCallback(cb1);
dev2->GetMac()->SetMcpsDataConfirmCallback(cb1);
dev1->GetMac()->SetMcpsDataConfirmCallback(MakeBoundCallback(&DataSentMacConfirm, dev1));
// Fake PAN association, coordinator assignment, short address assignment and initialization
dev2->GetMac()->SetMcpsDataConfirmCallback(MakeBoundCallback(&DataSentMacConfirm, dev2));
// Manual PAN association, coordinator assignment, short address assignment and initialization
// of beacon-enabled mode in 802.15.4-2011.
// This is needed because the lr-wpan module does not provide (yet)
// a full PAN association procedure.
// Association using the MAC functions can also be used instead of a manual association.
// AssociateToBeaconPan (devices, PAN ID, Coordinator Address, Beacon Order, Superframe Order)
@@ -113,7 +110,22 @@ main(int argc, char** argv)
// Beacon Interval = 251.65 secs
// |-----------------------------------------------------------------------------------------|
lrWpanHelper.AssociateToBeaconPan(lrwpanDevices, 0, Mac16Address("00:01"), 14, 13);
// Manually set an associated PAN, Pan id = 1 the first device (dev1) is used as coordinator
lrWpanHelper.CreateAssociatedPan(lrwpanDevices, 5);
// Start the beacon mode from the MAC layer of the coordinator (dev1)
MlmeStartRequestParams params;
params.m_panCoor = true;
params.m_PanId = 5;
params.m_bcnOrd = 14;
params.m_sfrmOrd = 13;
params.m_logCh = 11;
Simulator::ScheduleWithContext(dev1->GetNode()->GetId(),
Seconds(0),
&LrWpanMac::MlmeStartRequest,
dev1->GetMac(),
params);
InternetStackHelper internetv6;
internetv6.Install(nodes);
@@ -140,13 +152,13 @@ main(int argc, char** argv)
ApplicationContainer apps = ping.Install(nodes.Get(0));
apps.Start(Seconds(2.0));
apps.Stop(Seconds(20.0));
apps.Stop(Seconds(7.0));
AsciiTraceHelper ascii;
lrWpanHelper.EnableAsciiAll(ascii.CreateFileStream("Ping-6LoW-lr-wpan-beacon.tr"));
lrWpanHelper.EnablePcapAll(std::string("Ping-6LoW-lr-wpan-beacon"), true);
Simulator::Stop(Seconds(600));
Simulator::Stop(Seconds(7));
Simulator::Run();
Simulator::Destroy();

View File

@@ -81,10 +81,9 @@ main(int argc, char** argv)
// Add and install the LrWpanNetDevice for each node
NetDeviceContainer lrwpanDevices = lrWpanHelper.Install(wsnNodes);
// Fake PAN association and short address assignment.
// This is needed because the lr-wpan module does not provide (yet)
// a full PAN association procedure.
lrWpanHelper.AssociateToPan(lrwpanDevices, 0);
// Manual PAN association and extended and short address assignment.
// Association using the MAC functions can also be used instead of this step.
lrWpanHelper.CreateAssociatedPan(lrwpanDevices, 0);
InternetStackHelper internetv6;
internetv6.Install(wsnNodes);

View File

@@ -81,10 +81,9 @@ main(int argc, char** argv)
// Add and install the LrWpanNetDevice for each node
NetDeviceContainer lrwpanDevices = lrWpanHelper.Install(nodes);
// Fake PAN association and short address assignment.
// This is needed because the lr-wpan module does not provide (yet)
// a full PAN association procedure.
lrWpanHelper.AssociateToPan(lrwpanDevices, 1);
// Manual PAN association and extended and short address assignment.
// Association using the MAC functions can also be used instead of this step.
lrWpanHelper.CreateAssociatedPan(lrwpanDevices, 1);
InternetStackHelper internetv6;
internetv6.Install(nodes);