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 "gateway-lorawan-mac.h"
14#include "lora-net-device.h"
16#include "network-controller.h"
17#include "network-scheduler.h"
18#include "network-status.h"
19
20#include "ns3/log.h"
21
22namespace ns3
23{
24namespace lorawan
25{
26
27NS_LOG_COMPONENT_DEFINE("NetworkServer");
28
30
31TypeId
33{
34 static TypeId tid =
35 TypeId("ns3::NetworkServer")
37 .AddConstructor<NetworkServer>()
38 .AddTraceSource(
39 "ReceivedPacket",
40 "Trace source that is fired when a packet arrives at the network server",
42 "ns3::Packet::TracedCallback")
43 .SetGroupName("lorawan");
44 return tid;
45}
46
54
59
60void
65
66void
71
72void
74{
75 NS_LOG_FUNCTION(this << gateway);
76
77 // Get the PointToPointNetDevice
78 Ptr<PointToPointNetDevice> p2pNetDevice;
79 for (uint32_t i = 0; i < gateway->GetNDevices(); i++)
80 {
81 p2pNetDevice = DynamicCast<PointToPointNetDevice>(gateway->GetDevice(i));
82 if (p2pNetDevice)
83 {
84 // We found a p2pNetDevice on the gateway
85 break;
86 }
87 }
88
89 // Get the gateway's LoRa MAC layer (assumes gateway's MAC is configured as first device)
91 DynamicCast<GatewayLorawanMac>(DynamicCast<LoraNetDevice>(gateway->GetDevice(0))->GetMac());
92 NS_ASSERT(gwMac);
93
94 // Get the Address
95 Address gatewayAddress = p2pNetDevice->GetAddress();
96
97 // Create new gatewayStatus
98 Ptr<GatewayStatus> gwStatus = CreateObject<GatewayStatus>(gatewayAddress, netDevice, gwMac);
99
100 m_status->AddGateway(gatewayAddress, gwStatus);
101}
102
103void
105{
107
108 // For each node in the container, call the function to add that single node
110 for (it = nodes.Begin(); it != nodes.End(); it++)
111 {
112 AddNode(*it);
113 }
114}
115
116void
118{
119 NS_LOG_FUNCTION(this << node);
120
121 // Get the LoraNetDevice
122 Ptr<LoraNetDevice> loraNetDevice;
123 for (uint32_t i = 0; i < node->GetNDevices(); i++)
124 {
125 loraNetDevice = DynamicCast<LoraNetDevice>(node->GetDevice(i));
126 if (loraNetDevice)
127 {
128 // We found a LoraNetDevice on the node
129 break;
130 }
131 }
132
133 // Get the MAC
134 Ptr<ClassAEndDeviceLorawanMac> edLorawanMac =
135 DynamicCast<ClassAEndDeviceLorawanMac>(loraNetDevice->GetMac());
136
137 // Update the NetworkStatus about the existence of this node
138 m_status->AddNode(edLorawanMac);
139}
140
141bool
143 Ptr<const Packet> packet,
144 uint16_t protocol,
145 const Address& address)
146{
147 NS_LOG_FUNCTION(this << packet << protocol << address);
148
149 // Create a copy of the packet
150 Ptr<Packet> myPacket = packet->Copy();
151
152 // Fire the trace source
153 m_receivedPacket(packet);
154
155 // Inform the scheduler of the newly arrived packet
156 m_scheduler->OnReceivedPacket(packet);
157
158 // Inform the status of the newly arrived packet
159 m_status->OnReceivedPacket(packet, address);
160
161 // Inform the controller of the newly arrived packet
162 m_controller->OnNewPacket(packet);
163
164 return true;
165}
166
167void
169{
170 NS_LOG_FUNCTION(this << component);
171
172 m_controller->Install(component);
173}
174
180
181} // namespace lorawan
182} // namespace ns3
a polymophic address class
Definition address.h:114
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.
Definition ptr.h:70
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1003
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.
The NetworkServer is an application standing on top of a node equipped with links that connect it wit...
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:201
#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 ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
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:643