A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
network-server.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 University of Padova
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Davide Magrin <magrinda@dei.unipd.it>
7 * Martina Capuzzo <capuzzom@dei.unipd.it>
8 */
9
10#include "network-server.h"
11
13#include "lora-device-address.h"
14#include "lora-frame-header.h"
15#include "lorawan-mac-header.h"
16#include "mac-command.h"
17#include "network-status.h"
18
19#include "ns3/net-device.h"
20#include "ns3/node-container.h"
21#include "ns3/packet.h"
22#include "ns3/point-to-point-net-device.h"
23
24namespace ns3
25{
26namespace lorawan
27{
28
29NS_LOG_COMPONENT_DEFINE("NetworkServer");
30
31NS_OBJECT_ENSURE_REGISTERED(NetworkServer);
32
33TypeId
35{
36 static TypeId tid =
37 TypeId("ns3::NetworkServer")
39 .AddConstructor<NetworkServer>()
40 .AddTraceSource(
41 "ReceivedPacket",
42 "Trace source that is fired when a packet arrives at the network server",
44 "ns3::Packet::TracedCallback")
45 .SetGroupName("lorawan");
46 return tid;
47}
48
50 : m_status(Create<NetworkStatus>()),
51 m_controller(Create<NetworkController>(m_status)),
52 m_scheduler(Create<NetworkScheduler>(m_status, m_controller))
53{
55}
56
61
62void
67
68void
73
74void
76{
77 NS_LOG_FUNCTION(this << gateway);
78
79 // Get the PointToPointNetDevice
80 Ptr<PointToPointNetDevice> p2pNetDevice;
81 for (uint32_t i = 0; i < gateway->GetNDevices(); i++)
82 {
83 p2pNetDevice = DynamicCast<PointToPointNetDevice>(gateway->GetDevice(i));
84 if (p2pNetDevice)
85 {
86 // We found a p2pNetDevice on the gateway
87 break;
88 }
89 }
90
91 // Get the gateway's LoRa MAC layer (assumes gateway's MAC is configured as first device)
93 DynamicCast<GatewayLorawanMac>(DynamicCast<LoraNetDevice>(gateway->GetDevice(0))->GetMac());
94 NS_ASSERT(gwMac);
95
96 // Get the Address
97 Address gatewayAddress = p2pNetDevice->GetAddress();
98
99 // Create new gatewayStatus
100 Ptr<GatewayStatus> gwStatus = Create<GatewayStatus>(gatewayAddress, netDevice, gwMac);
101
102 m_status->AddGateway(gatewayAddress, gwStatus);
103}
104
105void
107{
109
110 // For each node in the container, call the function to add that single node
112 for (it = nodes.Begin(); it != nodes.End(); it++)
113 {
114 AddNode(*it);
115 }
116}
117
118void
120{
121 NS_LOG_FUNCTION(this << node);
122
123 // Get the LoraNetDevice
124 Ptr<LoraNetDevice> loraNetDevice;
125 for (uint32_t i = 0; i < node->GetNDevices(); i++)
126 {
127 loraNetDevice = DynamicCast<LoraNetDevice>(node->GetDevice(i));
128 if (loraNetDevice)
129 {
130 // We found a LoraNetDevice on the node
131 break;
132 }
133 }
134
135 // Get the MAC
136 Ptr<ClassAEndDeviceLorawanMac> edLorawanMac =
137 DynamicCast<ClassAEndDeviceLorawanMac>(loraNetDevice->GetMac());
138
139 // Update the NetworkStatus about the existence of this node
140 m_status->AddNode(edLorawanMac);
141}
142
143bool
145 Ptr<const Packet> packet,
146 uint16_t protocol,
147 const Address& address)
148{
149 NS_LOG_FUNCTION(this << packet << protocol << address);
150
151 // Create a copy of the packet
152 Ptr<Packet> myPacket = packet->Copy();
153
154 // Fire the trace source
155 m_receivedPacket(packet);
156
157 // Inform the scheduler of the newly arrived packet
158 m_scheduler->OnReceivedPacket(packet);
159
160 // Inform the status of the newly arrived packet
161 m_status->OnReceivedPacket(packet, address);
162
163 // Inform the controller of the newly arrived packet
164 m_controller->OnNewPacket(packet);
165
166 return true;
167}
168
169void
171{
172 NS_LOG_FUNCTION(this << component);
173
174 m_controller->Install(component);
175}
176
182
183} // namespace lorawan
184} // namespace ns3
a polymophic address class
Definition address.h:90
The base class for all ns3 applications.
Definition application.h:51
keep track of a set of node pointers.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
This class collects a series of components that deal with various aspects of managing the network,...
Network server component in charge of scheduling downling packets onto devices' reception windows.
void AddNode(Ptr< Node > node)
Inform the NetworkServer application that this node is connected to the network.
NetworkServer()
Default constructor.
Ptr< NetworkStatus > GetNetworkStatus()
Get the NetworkStatus object of this NetworkServer application.
void AddGateway(Ptr< Node > gateway, Ptr< NetDevice > netDevice)
Add the gateway to the list of gateways connected to this network server.
TracedCallback< Ptr< const Packet > > m_receivedPacket
The ReceivedPacket trace source.
bool Receive(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &sender)
Receive a packet from a gateway.
void StopApplication() override
Stop the network server application.
static TypeId GetTypeId()
Register this type.
Ptr< NetworkScheduler > m_scheduler
Ptr to the NetworkScheduler object.
Ptr< NetworkStatus > m_status
Ptr to the NetworkStatus object.
void AddNodes(NodeContainer nodes)
Inform the NetworkServer application that these nodes are connected to the network.
~NetworkServer() override
Destructor.
void AddComponent(Ptr< NetworkControllerComponent > component)
Add a NetworkControllerComponent to this NetworkServer application.
void StartApplication() override
Start the network server application.
Ptr< NetworkController > m_controller
Ptr to the NetworkController object.
This class represents the knowledge about the state of the network that is available at the network s...
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#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:436
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580