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
20namespace ns3
21{
22namespace lorawan
23{
24
25NS_LOG_COMPONENT_DEFINE("NetworkServer");
26
28
29TypeId
31{
32 static TypeId tid =
33 TypeId("ns3::NetworkServer")
35 .AddConstructor<NetworkServer>()
36 .AddTraceSource(
37 "ReceivedPacket",
38 "Trace source that is fired when a packet arrives at the network server",
40 "ns3::Packet::TracedCallback")
41 .SetGroupName("lorawan");
42 return tid;
43}
44
52
57
58void
63
64void
69
70void
72{
73 NS_LOG_FUNCTION(this << gateway);
74
75 // Get the PointToPointNetDevice
76 Ptr<PointToPointNetDevice> p2pNetDevice;
77 for (uint32_t i = 0; i < gateway->GetNDevices(); i++)
78 {
79 p2pNetDevice = DynamicCast<PointToPointNetDevice>(gateway->GetDevice(i));
80 if (p2pNetDevice)
81 {
82 // We found a p2pNetDevice on the gateway
83 break;
84 }
85 }
86
87 // Get the gateway's LoRa MAC layer (assumes gateway's MAC is configured as first device)
89 DynamicCast<GatewayLorawanMac>(DynamicCast<LoraNetDevice>(gateway->GetDevice(0))->GetMac());
90 NS_ASSERT(gwMac);
91
92 // Get the Address
93 Address gatewayAddress = p2pNetDevice->GetAddress();
94
95 // Create new gatewayStatus
96 Ptr<GatewayStatus> gwStatus = CreateObject<GatewayStatus>(gatewayAddress, netDevice, gwMac);
97
98 m_status->AddGateway(gatewayAddress, gwStatus);
99}
100
101void
103{
105
106 // For each node in the container, call the function to add that single node
108 for (it = nodes.Begin(); it != nodes.End(); it++)
109 {
110 AddNode(*it);
111 }
112}
113
114void
116{
117 NS_LOG_FUNCTION(this << node);
118
119 // Get the LoraNetDevice
120 Ptr<LoraNetDevice> loraNetDevice;
121 for (uint32_t i = 0; i < node->GetNDevices(); i++)
122 {
123 loraNetDevice = DynamicCast<LoraNetDevice>(node->GetDevice(i));
124 if (loraNetDevice)
125 {
126 // We found a LoraNetDevice on the node
127 break;
128 }
129 }
130
131 // Get the MAC
132 Ptr<ClassAEndDeviceLorawanMac> edLorawanMac =
133 DynamicCast<ClassAEndDeviceLorawanMac>(loraNetDevice->GetMac());
134
135 // Update the NetworkStatus about the existence of this node
136 m_status->AddNode(edLorawanMac);
137}
138
139bool
141 Ptr<const Packet> packet,
142 uint16_t protocol,
143 const Address& address)
144{
145 NS_LOG_FUNCTION(this << packet << protocol << address);
146
147 // Create a copy of the packet
148 Ptr<Packet> myPacket = packet->Copy();
149
150 // Fire the trace source
151 m_receivedPacket(packet);
152
153 // Inform the scheduler of the newly arrived packet
154 m_scheduler->OnReceivedPacket(packet);
155
156 // Inform the status of the newly arrived packet
157 m_status->OnReceivedPacket(packet, address);
158
159 // Inform the controller of the newly arrived packet
160 m_controller->OnNewPacket(packet);
161
162 return true;
163}
164
165void
167{
168 NS_LOG_FUNCTION(this << component);
169
170 m_controller->Install(component);
171}
172
178
179} // namespace lorawan
180} // 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:999
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:194
#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:605