A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
zigbee-stack.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Tokushima University, Japan
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author:
7 * Alberto Gallegos Ramonet <alramonet@is.tokushima-u.ac.jp>
8 */
9
10#include "zigbee-stack.h"
11
12#include "ns3/channel.h"
13#include "ns3/log.h"
14#include "ns3/node.h"
15#include "ns3/packet.h"
16#include "ns3/pointer.h"
17#include "ns3/simulator.h"
18
19using namespace ns3::lrwpan;
20
21namespace ns3
22{
23namespace zigbee
24{
25NS_LOG_COMPONENT_DEFINE("ZigbeeStack");
27
28TypeId
30{
31 static TypeId tid = TypeId("ns3::zigbee::ZigbeeStack")
33 .SetGroupName("Zigbee")
34 .AddConstructor<ZigbeeStack>();
35 return tid;
36}
37
48
53
54void
56{
57 NS_LOG_FUNCTION(this);
58
59 m_netDevice = nullptr;
60 m_node = nullptr;
61 m_aps = nullptr;
62 m_nwk = nullptr;
63 m_groupTable = nullptr;
64 m_mac = nullptr;
66}
67
68void
70{
71 NS_LOG_FUNCTION(this);
72
74 "Invalid NetDevice found when attempting to install ZigbeeStack");
75
76 // Make sure the NetDevice is previously initialized
77 // before using ZigbeeStack (PHY and MAC are initialized)
78 m_netDevice->Initialize();
79
82 "Invalid LrWpanMacBase found in this NetDevice, cannot use ZigbeeStack");
83
84 m_nwk->Initialize();
86
87 // Set NWK callback hooks with the MAC
88 m_nwk->SetMac(m_mac);
89 m_mac->SetMcpsDataIndicationCallback(MakeCallback(&ZigbeeNwk::McpsDataIndication, m_nwk));
90 m_mac->SetMlmeOrphanIndicationCallback(MakeCallback(&ZigbeeNwk::MlmeOrphanIndication, m_nwk));
91 m_mac->SetMlmeCommStatusIndicationCallback(
93 m_mac->SetMlmeBeaconNotifyIndicationCallback(
95 m_mac->SetMlmeAssociateIndicationCallback(
97 m_mac->SetMcpsDataConfirmCallback(MakeCallback(&ZigbeeNwk::McpsDataConfirm, m_nwk));
98 m_mac->SetMlmeScanConfirmCallback(MakeCallback(&ZigbeeNwk::MlmeScanConfirm, m_nwk));
99 m_mac->SetMlmeStartConfirmCallback(MakeCallback(&ZigbeeNwk::MlmeStartConfirm, m_nwk));
100 m_mac->SetMlmeSetConfirmCallback(MakeCallback(&ZigbeeNwk::MlmeSetConfirm, m_nwk));
101 m_mac->SetMlmeGetConfirmCallback(MakeCallback(&ZigbeeNwk::MlmeGetConfirm, m_nwk));
102 m_mac->SetMlmeAssociateConfirmCallback(MakeCallback(&ZigbeeNwk::MlmeAssociateConfirm, m_nwk));
103 // TODO: complete other callback hooks with the MAC
104
105 if (!m_nwkOnly)
106 {
107 // Set APS callback hooks with NWK (i.e., NLDE primitives only)
108 m_nwk->SetNldeDataConfirmCallback(MakeCallback(&ZigbeeAps::NldeDataConfirm, m_aps));
109 m_nwk->SetNldeDataIndicationCallback(MakeCallback(&ZigbeeAps::NldeDataIndication, m_aps));
110
111 m_nwk->SetGroupTable(m_groupTable);
112 m_aps->SetGroupTable(m_groupTable);
113
114 m_aps->Initialize();
115 m_aps->SetNwk(m_nwk);
117 }
118 else
119 {
120 m_nwk->SetGroupTable(m_groupTable);
121 }
122
123 // Obtain Extended address as soon as NWK is set to begin operations
125
127}
128
131{
132 return m_netDevice->GetChannel();
133}
134
137{
138 return m_node;
139}
140
143{
144 return m_netDevice;
145}
146
147void
149{
150 NS_LOG_FUNCTION(this << netDevice);
151 m_netDevice = netDevice;
152 m_node = m_netDevice->GetNode();
153}
154
155void
160
163{
164 return m_nwk;
165}
166
167void
169{
170 NS_LOG_FUNCTION(this);
171 NS_ABORT_MSG_IF(ZigbeeStack::IsInitialized(), "NWK layer cannot be set after initialization");
172 m_nwk = nwk;
173}
174
177{
178 return m_aps;
179}
180
181void
183{
184 NS_LOG_FUNCTION(this);
185 NS_ABORT_MSG_IF(ZigbeeStack::IsInitialized(), "APS layer cannot be set after initialization");
186 m_aps = aps;
187}
188
189} // namespace zigbee
190} // namespace ns3
virtual void DoInitialize()
Initialize() implementation.
Definition object.cc:440
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition object.cc:298
Object()
Constructor.
Definition object.cc:96
virtual void DoDispose()
Destructor implementation.
Definition object.cc:433
bool IsInitialized() const
Check if the object has been initialized.
Definition object.cc:240
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:67
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Lr-wpan MAC layer abstraction.
void NldeDataIndication(NldeDataIndicationParams params, Ptr< Packet > nsdu)
Zigbee Specification r22.1.0, Section 3.2.1.3 NLDE-DATA.indication Used to report to the APS the rece...
void NldeDataConfirm(NldeDataConfirmParams params)
Zigbee Specification r22.1.0, Section 3.2.1.2 NLDE-DATA.confirm Used to report to the APS the transmi...
void MlmeOrphanIndication(lrwpan::MlmeOrphanIndicationParams params)
IEEE 802.15.4-2011 sections 6.2.7.1, Zigbee Specification r22.1.0 Section 3.6.1.4....
void McpsDataConfirm(lrwpan::McpsDataConfirmParams params)
IEEE 802.15.4-2011 section 6.3.2 MCPS-DATA.confirm Reports the results of a request to a transfer dat...
void MlmeSetConfirm(lrwpan::MlmeSetConfirmParams params)
IEEE 802.15.4-2011 section 6.2.11.2 MLME-SET.confirm Reports the result of an attempt to change a MAC...
void MlmeCommStatusIndication(lrwpan::MlmeCommStatusIndicationParams params)
IEEE 802.15.4-2011 section 6.2.4.2 MLME-COMM-STATUS.indication Allows the MAC MLME to indicate a comm...
void MlmeBeaconNotifyIndication(lrwpan::MlmeBeaconNotifyIndicationParams params)
IEEE 802.15.4-2011, Section 6.2.4.1 MLME-BEACON-NOTIFY.indication Allows the MAC MLME to indicate the...
void MlmeAssociateConfirm(lrwpan::MlmeAssociateConfirmParams params)
IEEE 802.15.4-2011 section MlME-ASSOCIATE.confirm Report the results of an associate request attempt.
void MlmeStartConfirm(lrwpan::MlmeStartConfirmParams params)
IEEE 802.15.4-2011 section 7.1.14.2 MLME-START.confirm Reports the results of a network start request...
void MlmeAssociateIndication(lrwpan::MlmeAssociateIndicationParams params)
IEEE 802.15.4-2011, Section 6.2.2.2.
void MlmeScanConfirm(lrwpan::MlmeScanConfirmParams params)
IEEE 802.15.4-2011 section 6.2.10.2 MLME-SCAN.confirm Reports the results of a scan request.
void McpsDataIndication(lrwpan::McpsDataIndicationParams params, Ptr< Packet > msdu)
IEEE 802.15.4-2011 section 6.3.3 MCPS-DATA.indication Indicates the reception of an MSDU from MAC to ...
void MlmeGetConfirm(lrwpan::MacStatus status, lrwpan::MacPibAttributeIdentifier id, Ptr< lrwpan::MacPibAttributes > attribute)
IEEE 802.15.4-2011 section 6.2.5.1 MLME-GET.confirm Reports the result of an attempt to obtain a MAC ...
Zigbee protocol stack to device interface.
static TypeId GetTypeId()
Get the type ID.
Ptr< ZigbeeGroupTable > m_groupTable
The Zigbee Group Table used by both NWK and APS layers.
void SetNwk(Ptr< ZigbeeNwk > nwk)
Set the NWK layer used by this ZigbeeStack.
Ptr< NetDevice > m_netDevice
Smart pointer to the underlying NetDevice.
void SetAps(Ptr< ZigbeeAps > aps)
Set the APS layer used by this ZigbeeStack.
Ptr< lrwpan::LrWpanMacBase > m_mac
The underlying LrWpan MAC connected to this Zigbee Stack.
void SetNetDevice(Ptr< NetDevice > netDevice)
Setup Zigbee to be the next set of higher layers for the specified NetDevice.
Ptr< Channel > GetChannel() const
Get the Channel object of the underlying LrWpanNetDevice.
bool m_nwkOnly
Indicates that only the NWK layer is present in the Zigbee stack.
ZigbeeStack()
Default constructor.
Ptr< ZigbeeAps > GetAps() const
Get the APS layer used by this ZigbeeStack.
Ptr< ZigbeeNwk > GetNwk() const
Get the NWK layer used by this ZigbeeStack.
Ptr< Node > GetNode() const
Get the node currently using this ZigbeeStack.
Ptr< ZigbeeAps > m_aps
The Zigbee Application Support Sub-layer.
Ptr< ZigbeeNwk > m_nwk
The Zigbee Network layer.
Ptr< Node > m_node
The node associated with this NetDevice.
void DoDispose() override
Dispose of the Objects used by the ZigbeeStack.
Ptr< NetDevice > GetNetDevice() const
Returns a smart pointer to the underlying NetDevice.
void SetOnlyNwkLayer()
Inticates to the Zigbee stack that only the NWK layer should be present.
void DoInitialize() override
Initialize of the Objects used by the ZigbeeStack.
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
Definition abort.h:133
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:97
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
@ macExtendedAddress
The extended address of the device (64 bit address).
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:439
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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...
Definition callback.h:684