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
39{
40 NS_LOG_FUNCTION(this);
41
43 // TODO: Create APS layer here.
44 // m_aps = CreateObject<zigbee::ZigbeeAps> ();
45}
46
51
52void
54{
55 NS_LOG_FUNCTION(this);
56
57 m_netDevice = nullptr;
58 m_node = nullptr;
59 m_nwk = nullptr;
60 m_mac = nullptr;
62}
63
64void
66{
67 NS_LOG_FUNCTION(this);
68
70
72 "Invalid NetDevice found when attempting to install ZigbeeStack");
73
74 // Make sure the NetDevice is previously initialized
75 // before using ZigbeeStack
76 m_netDevice->Initialize();
77
80 "No valid LrWpanMacBase found in this NetDevice, cannot use ZigbeeStack");
81
82 // Set NWK callback hooks with the MAC
83 m_nwk->SetMac(m_mac);
84 m_mac->SetMcpsDataIndicationCallback(MakeCallback(&ZigbeeNwk::McpsDataIndication, m_nwk));
85 m_mac->SetMlmeOrphanIndicationCallback(MakeCallback(&ZigbeeNwk::MlmeOrphanIndication, m_nwk));
86 m_mac->SetMlmeCommStatusIndicationCallback(
88 m_mac->SetMlmeBeaconNotifyIndicationCallback(
90 m_mac->SetMlmeAssociateIndicationCallback(
92 m_mac->SetMcpsDataConfirmCallback(MakeCallback(&ZigbeeNwk::McpsDataConfirm, m_nwk));
93 m_mac->SetMlmeScanConfirmCallback(MakeCallback(&ZigbeeNwk::MlmeScanConfirm, m_nwk));
94 m_mac->SetMlmeStartConfirmCallback(MakeCallback(&ZigbeeNwk::MlmeStartConfirm, m_nwk));
95 m_mac->SetMlmeSetConfirmCallback(MakeCallback(&ZigbeeNwk::MlmeSetConfirm, m_nwk));
96 m_mac->SetMlmeGetConfirmCallback(MakeCallback(&ZigbeeNwk::MlmeGetConfirm, m_nwk));
97 m_mac->SetMlmeAssociateConfirmCallback(MakeCallback(&ZigbeeNwk::MlmeAssociateConfirm, m_nwk));
98 // TODO: complete other callback hooks with the MAC
99
100 // Obtain Extended address as soon as NWK is set to begin operations
101 m_mac->MlmeGetRequest(MacPibAttributeIdentifier::macExtendedAddress);
102
103 // TODO: Set APS callback hooks with NWK when support for APS layer is added.
104 // For example:
105 // m_aps->SetNwk (m_nwk);
106 // m_nwk->SetNldeDataIndicationCallback (MakeCallback (&ZigbeeAps::NldeDataIndication, m_aps));
107
109}
110
113{
114 return m_netDevice->GetChannel();
115}
116
119{
120 return m_node;
121}
122
125{
126 return m_netDevice;
127}
128
129void
131{
132 NS_LOG_FUNCTION(this << netDevice);
133 m_netDevice = netDevice;
134 m_node = m_netDevice->GetNode();
135}
136
139{
140 return m_nwk;
141}
142
143void
145{
146 NS_LOG_FUNCTION(this);
147 NS_ABORT_MSG_IF(ZigbeeStack::IsInitialized(), "NWK layer cannot be set after initialization");
148 m_nwk = nwk;
149}
150
151} // namespace zigbee
152} // 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 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.
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.
ZigbeeStack()
Default constructor.
Ptr< ZigbeeNwk > GetNwk() const
Get the NWK layer used by this ZigbeeStack.
Ptr< Node > GetNode() const
Get the node currently using this ZigbeeStack.
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 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