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
30{
31 static TypeId tid = TypeId("ns3::zigbee::ZigbeeStack")
33 .SetGroupName("Zigbee")
34 .AddConstructor<ZigbeeStack>();
35 return tid;
36}
37
47
52
53void
55{
56 NS_LOG_FUNCTION(this);
57
58 m_netDevice = nullptr;
59 m_node = nullptr;
60 m_aps = nullptr;
61 m_nwk = nullptr;
62 m_mac = nullptr;
64}
65
66void
68{
69 NS_LOG_FUNCTION(this);
70
71 // AggregateObject(m_aps);
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_aps->Initialize();
112 m_aps->SetNwk(m_nwk);
114 }
115
116 // Obtain Extended address as soon as NWK is set to begin operations
117 m_mac->MlmeGetRequest(MacPibAttributeIdentifier::macExtendedAddress);
118
120}
121
124{
125 return m_netDevice->GetChannel();
126}
127
130{
131 return m_node;
132}
133
136{
137 return m_netDevice;
138}
139
140void
142{
143 NS_LOG_FUNCTION(this << netDevice);
144 m_netDevice = netDevice;
145 m_node = m_netDevice->GetNode();
146}
147
148void
153
156{
157 return m_nwk;
158}
159
160void
162{
163 NS_LOG_FUNCTION(this);
164 NS_ABORT_MSG_IF(ZigbeeStack::IsInitialized(), "NWK layer cannot be set after initialization");
165 m_nwk = nwk;
166}
167
170{
171 return m_aps;
172}
173
174void
176{
177 NS_LOG_FUNCTION(this);
178 NS_ABORT_MSG_IF(ZigbeeStack::IsInitialized(), "APS layer cannot be set after initialization");
179 m_aps = aps;
180}
181
182} // namespace zigbee
183} // namespace ns3
A base class which provides memory management and object aggregation.
Definition object.h:78
virtual void DoInitialize()
Initialize() implementation.
Definition object.cc:440
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition object.cc:298
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.
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.
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 ",...
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
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