-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose p2p connection of gateways and server (#151)
* Expose p2p connection of gateways to server (#150) * Expose gw registration to simplify NetworkServerHelper::Install + remove NodeContainer install of NetworkServerHelper + add P2PGwRegistration_t helper structure to facilitate independent instantiation of P2P and server app * Directly pass P2PGwRegistration_t to NetworkServerHelper
- Loading branch information
1 parent
5ce32fa
commit 69cb2e3
Showing
9 changed files
with
147 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,16 @@ | |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
* | ||
* Author: Davide Magrin <[email protected]> | ||
* | ||
* Modified by: Alessandro Aimi <[email protected]> | ||
*/ | ||
|
||
#include "forwarder-helper.h" | ||
|
||
#include "ns3/double.h" | ||
#include "ns3/forwarder.h" | ||
#include "ns3/log.h" | ||
#include "ns3/lora-net-device.h" | ||
#include "ns3/random-variable-stream.h" | ||
#include "ns3/simulator.h" | ||
#include "ns3/string.h" | ||
|
@@ -71,6 +74,8 @@ Ptr<Application> | |
ForwarderHelper::InstallPriv(Ptr<Node> node) const | ||
{ | ||
NS_LOG_FUNCTION(this << node); | ||
NS_ASSERT_MSG(node->GetNDevices() == 2, | ||
"NDevices != 2, the node must have a LoraNetDevice and a PointToPointNetDevice"); | ||
|
||
Ptr<Forwarder> app = m_factory.Create<Forwarder>(); | ||
|
||
|
@@ -80,22 +85,16 @@ ForwarderHelper::InstallPriv(Ptr<Node> node) const | |
// Link the Forwarder to the NetDevices | ||
for (uint32_t i = 0; i < node->GetNDevices(); i++) | ||
{ | ||
Ptr<NetDevice> currentNetDevice = node->GetDevice(i); | ||
if (currentNetDevice->GetObject<LoraNetDevice>()) | ||
Ptr<NetDevice> currNetDev = node->GetDevice(i); | ||
if (auto loraNetDev = DynamicCast<LoraNetDevice>(currNetDev); loraNetDev) | ||
{ | ||
Ptr<LoraNetDevice> loraNetDevice = currentNetDevice->GetObject<LoraNetDevice>(); | ||
app->SetLoraNetDevice(loraNetDevice); | ||
loraNetDevice->SetReceiveCallback(MakeCallback(&Forwarder::ReceiveFromLora, app)); | ||
app->SetLoraNetDevice(loraNetDev); | ||
loraNetDev->SetReceiveCallback(MakeCallback(&Forwarder::ReceiveFromLora, app)); | ||
} | ||
else if (currentNetDevice->GetObject<PointToPointNetDevice>()) | ||
else if (auto p2pNetDev = DynamicCast<PointToPointNetDevice>(currNetDev); p2pNetDev) | ||
{ | ||
Ptr<PointToPointNetDevice> pointToPointNetDevice = | ||
currentNetDevice->GetObject<PointToPointNetDevice>(); | ||
|
||
app->SetPointToPointNetDevice(pointToPointNetDevice); | ||
|
||
pointToPointNetDevice->SetReceiveCallback( | ||
MakeCallback(&Forwarder::ReceiveFromPointToPoint, app)); | ||
app->SetPointToPointNetDevice(p2pNetDev); | ||
p2pNetDev->SetReceiveCallback(MakeCallback(&Forwarder::ReceiveFromPointToPoint, app)); | ||
} | ||
else | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
* | ||
* Author: Davide Magrin <[email protected]> | ||
* | ||
* Modified by: Alessandro Aimi <[email protected]> | ||
*/ | ||
|
||
#include "network-server-helper.h" | ||
|
@@ -23,6 +25,7 @@ | |
#include "ns3/double.h" | ||
#include "ns3/log.h" | ||
#include "ns3/network-controller-components.h" | ||
#include "ns3/point-to-point-channel.h" | ||
#include "ns3/simulator.h" | ||
#include "ns3/string.h" | ||
#include "ns3/trace-source-accessor.h" | ||
|
@@ -35,10 +38,9 @@ namespace lorawan | |
NS_LOG_COMPONENT_DEFINE("NetworkServerHelper"); | ||
|
||
NetworkServerHelper::NetworkServerHelper() | ||
: m_adrEnabled(false) | ||
{ | ||
m_factory.SetTypeId("ns3::NetworkServer"); | ||
p2pHelper.SetDeviceAttribute("DataRate", StringValue("5Mbps")); | ||
p2pHelper.SetChannelAttribute("Delay", StringValue("2ms")); | ||
SetAdr("ns3::AdrComponent"); | ||
} | ||
|
||
|
@@ -53,9 +55,15 @@ NetworkServerHelper::SetAttribute(std::string name, const AttributeValue& value) | |
} | ||
|
||
void | ||
NetworkServerHelper::SetGateways(NodeContainer gateways) | ||
NetworkServerHelper::SetGatewaysP2P(const P2PGwRegistration_t& registration) | ||
{ | ||
m_gateways = gateways; | ||
for (const auto& [serverP2PNetDev, gwNode] : registration) | ||
{ | ||
NS_ASSERT_MSG( | ||
serverP2PNetDev->GetNode()->GetId() != gwNode->GetId(), | ||
"wrong P2P NetDevice detected, please provide the one on the NS's side instead"); | ||
m_gatewayRegistrationList.emplace_back(serverP2PNetDev, gwNode); | ||
} | ||
} | ||
|
||
void | ||
|
@@ -70,44 +78,22 @@ NetworkServerHelper::Install(Ptr<Node> node) | |
return ApplicationContainer(InstallPriv(node)); | ||
} | ||
|
||
ApplicationContainer | ||
NetworkServerHelper::Install(NodeContainer c) | ||
{ | ||
ApplicationContainer apps; | ||
for (auto i = c.Begin(); i != c.End(); ++i) | ||
{ | ||
apps.Add(InstallPriv(*i)); | ||
} | ||
|
||
return apps; | ||
} | ||
|
||
Ptr<Application> | ||
NetworkServerHelper::InstallPriv(Ptr<Node> node) | ||
{ | ||
NS_LOG_FUNCTION(this << node); | ||
NS_ASSERT_MSG(node->GetNDevices() > 0, "No gateways connected to provided node"); | ||
|
||
Ptr<NetworkServer> app = m_factory.Create<NetworkServer>(); | ||
|
||
app->SetNode(node); | ||
node->AddApplication(app); | ||
|
||
// Cycle on each gateway | ||
for (auto i = m_gateways.Begin(); i != m_gateways.End(); i++) | ||
{ | ||
// Add the connections with the gateway | ||
// Create a PointToPoint link between gateway and NS | ||
NetDeviceContainer container = p2pHelper.Install(node, *i); | ||
|
||
// Add the gateway to the NS list | ||
app->AddGateway(*i, container.Get(0)); | ||
} | ||
|
||
// Link the NetworkServer to its NetDevices | ||
for (uint32_t i = 0; i < node->GetNDevices(); i++) | ||
// Connect the net devices receive callback to the app and register the respective gateway | ||
for (const auto& [currentNetDevice, gwNode] : m_gatewayRegistrationList) | ||
{ | ||
Ptr<NetDevice> currentNetDevice = node->GetDevice(i); | ||
currentNetDevice->SetReceiveCallback(MakeCallback(&NetworkServer::Receive, app)); | ||
app->AddGateway(gwNode, currentNetDevice); | ||
} | ||
|
||
// Add the end devices | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
* | ||
* Author: Davide Magrin <[email protected]> | ||
* | ||
* Modified by: Alessandro Aimi <[email protected]> | ||
*/ | ||
|
||
#ifndef NETWORK_SERVER_HELPER_H | ||
|
@@ -37,6 +39,15 @@ namespace ns3 | |
namespace lorawan | ||
{ | ||
|
||
/** | ||
* Store NS app registration details for gateway nodes having a P2P link with the NS. | ||
* | ||
* For each gateway, store in a pair: | ||
* - The Point-to-point net device of the network server; | ||
* - The gateway node connected to the P2P net device. | ||
*/ | ||
typedef std::list<std::pair<Ptr<PointToPointNetDevice>, Ptr<Node>>> P2PGwRegistration_t; | ||
|
||
/** | ||
* This class can install Network Server applications on multiple nodes at once. | ||
*/ | ||
|
@@ -49,14 +60,18 @@ class NetworkServerHelper | |
|
||
void SetAttribute(std::string name, const AttributeValue& value); | ||
|
||
ApplicationContainer Install(NodeContainer c); | ||
|
||
ApplicationContainer Install(Ptr<Node> node); | ||
|
||
/** | ||
* Set which gateways will need to be connected to this NS. | ||
* Register gateways connected with point-to-point to this NS. | ||
* | ||
* \remark For the moment, only P2P connections are supported. | ||
* | ||
* \param registration The gateways registration data. | ||
* | ||
* \see ns3::lorawan::P2PGwRegistration_t | ||
*/ | ||
void SetGateways(NodeContainer gateways); | ||
void SetGatewaysP2P(const P2PGwRegistration_t& registration); | ||
|
||
/** | ||
* Set which end devices will be managed by this NS. | ||
|
@@ -81,12 +96,11 @@ class NetworkServerHelper | |
|
||
ObjectFactory m_factory; | ||
|
||
NodeContainer m_gateways; //!< Set of gateways to connect to this NS | ||
std::list<std::pair<Ptr<NetDevice>, Ptr<Node>>> | ||
m_gatewayRegistrationList; //!< List of gateway nodes to register to this NS net devices | ||
|
||
NodeContainer m_endDevices; //!< Set of endDevices to connect to this NS | ||
|
||
PointToPointHelper p2pHelper; //!< Helper to create PointToPoint links | ||
|
||
bool m_adrEnabled; | ||
|
||
ObjectFactory m_adrSupportFactory; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters