Skip to content

Commit

Permalink
Expose p2p connection of gateways to server (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
non-det-alle committed Feb 9, 2024
1 parent be7884b commit 686e547
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 51 deletions.
10 changes: 9 additions & 1 deletion examples/adr-example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,17 @@ main(int argc, char* argv[])
NodeContainer networkServers;
networkServers.Create(1);

// PointToPoint links between gateways and server
PointToPointHelper p2p;
p2p.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
p2p.SetChannelAttribute("Delay", StringValue("2ms"));
for (auto gw = gateways.Begin(); gw != gateways.End(); ++gw)
{
p2p.Install(networkServers.Get(0), *gw);
}

// Install the NetworkServer application on the network server
NetworkServerHelper networkServerHelper;
networkServerHelper.SetGateways(gateways);
networkServerHelper.SetEndDevices(endDevices);
networkServerHelper.EnableAdr(adrEnabled);
networkServerHelper.SetAdr(adrType);
Expand Down
10 changes: 9 additions & 1 deletion examples/aloha-throughput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,17 @@ main(int argc, char* argv[])
NodeContainer networkServer;
networkServer.Create(1);

// PointToPoint links between gateways and server
PointToPointHelper p2p;
p2p.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
p2p.SetChannelAttribute("Delay", StringValue("2ms"));
for (auto gw = gateways.Begin(); gw != gateways.End(); ++gw)
{
p2p.Install(networkServer.Get(0), *gw);
}

// Create a NS for the network
nsHelper.SetEndDevices(endDevices);
nsHelper.SetGateways(gateways);
nsHelper.Install(networkServer);

// Create a forwarder for each gateway
Expand Down
10 changes: 9 additions & 1 deletion examples/complete-network-example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,17 @@ main(int argc, char* argv[])
NodeContainer networkServer;
networkServer.Create(1);

// PointToPoint links between gateways and server
PointToPointHelper p2p;
p2p.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
p2p.SetChannelAttribute("Delay", StringValue("2ms"));
for (auto gw = gateways.Begin(); gw != gateways.End(); ++gw)
{
p2p.Install(networkServer.Get(0), *gw);
}

// Create a NS for the network
nsHelper.SetEndDevices(endDevices);
nsHelper.SetGateways(gateways);
nsHelper.Install(networkServer);

// Create a forwarder for each gateway
Expand Down
10 changes: 9 additions & 1 deletion examples/frame-counter-update.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,17 @@ main(int argc, char* argv[])
NodeContainer networkServer;
networkServer.Create(1);

// PointToPoint links between gateways and server
PointToPointHelper p2p;
p2p.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
p2p.SetChannelAttribute("Delay", StringValue("2ms"));
for (auto gw = gateways.Begin(); gw != gateways.End(); ++gw)
{
p2p.Install(networkServer.Get(0), *gw);
}

// Create a NS for the network
nsHelper.SetEndDevices(endDevices);
nsHelper.SetGateways(gateways);
nsHelper.Install(networkServer);

// Create a forwarder for each gateway
Expand Down
10 changes: 9 additions & 1 deletion examples/network-server-example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,17 @@ main(int argc, char* argv[])
NodeContainer networkServers;
networkServers.Create(1);

// PointToPoint links between gateways and server
PointToPointHelper p2p;
p2p.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
p2p.SetChannelAttribute("Delay", StringValue("2ms"));
for (auto gw = gateways.Begin(); gw != gateways.End(); ++gw)
{
p2p.Install(networkServers.Get(0), *gw);
}

// Install the NetworkServer application on the network server
NetworkServerHelper networkServerHelper;
networkServerHelper.SetGateways(gateways);
networkServerHelper.SetEndDevices(endDevices);
networkServerHelper.Install(networkServers);

Expand Down
26 changes: 13 additions & 13 deletions helper/forwarder-helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Davide Magrin <magrinda@dei.unipd.it>
*
* Modified: Alessandro Aimi <alessandro.aimi@unibo.it> (12/02/2024)
*/

#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"
Expand Down Expand Up @@ -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>();

Expand All @@ -80,22 +85,17 @@ 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 != nullptr)
{
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 != nullptr)
{
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
{
Expand Down
2 changes: 2 additions & 0 deletions helper/forwarder-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Davide Magrin <magrinda@dei.unipd.it>
*
* Modified: Alessandro Aimi <alessandro.aimi@unibo.it> (12/02/2024)
*/

#ifndef FORWARDER_HELPER_H
Expand Down
42 changes: 22 additions & 20 deletions helper/network-server-helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Davide Magrin <magrinda@dei.unipd.it>
*
* Modified: Alessandro Aimi <alessandro.aimi@unibo.it> (12/02/2024)
*/

#include "network-server-helper.h"
Expand All @@ -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"
Expand All @@ -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");
}

Expand All @@ -52,12 +54,6 @@ NetworkServerHelper::SetAttribute(std::string name, const AttributeValue& value)
m_factory.Set(name, value);
}

void
NetworkServerHelper::SetGateways(NodeContainer gateways)
{
m_gateways = gateways;
}

void
NetworkServerHelper::SetEndDevices(NodeContainer endDevices)
{
Expand Down Expand Up @@ -86,28 +82,34 @@ 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++)
{
// Link the NetworkServer app to its NetDevices
Ptr<NetDevice> currentNetDevice = node->GetDevice(i);
currentNetDevice->SetReceiveCallback(MakeCallback(&NetworkServer::Receive, app));

// Register gateways
Ptr<Channel> channel = currentNetDevice->GetChannel();
NS_ASSERT_MSG(DynamicCast<PointToPointChannel>(channel),
"Connection with gateways is not PointToPoint");
for (uint32_t j = 0; j < channel->GetNDevices(); ++j)
{
Ptr<Node> gwNode = channel->GetDevice(j)->GetNode();
// Point to point, so channel only holds 2 devices
if (gwNode->GetId() != node->GetId())
{
// Add the gateway to the NS list
app->AddGateway(gwNode, currentNetDevice);
break;
}
}
}

// Add the end devices
Expand Down
11 changes: 2 additions & 9 deletions helper/network-server-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Davide Magrin <magrinda@dei.unipd.it>
*
* * Modified: Alessandro Aimi <alessandro.aimi@unibo.it> (12/02/2024)
*/

#ifndef NETWORK_SERVER_HELPER_H
Expand Down Expand Up @@ -53,11 +55,6 @@ class NetworkServerHelper

ApplicationContainer Install(Ptr<Node> node);

/**
* Set which gateways will need to be connected to this NS.
*/
void SetGateways(NodeContainer gateways);

/**
* Set which end devices will be managed by this NS.
*/
Expand All @@ -81,12 +78,8 @@ class NetworkServerHelper

ObjectFactory m_factory;

NodeContainer m_gateways; //!< Set of gateways to connect to this NS

NodeContainer m_endDevices; //!< Set of endDevices to connect to this NS

PointToPointHelper p2pHelper; //!< Helper to create PointToPoint links

bool m_adrEnabled;

ObjectFactory m_adrSupportFactory;
Expand Down
18 changes: 14 additions & 4 deletions test/utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,22 @@ CreateGateways(int nGateways, MobilityHelper mobility, Ptr<LoraChannel> channel)
Ptr<Node>
CreateNetworkServer(NodeContainer endDevices, NodeContainer gateways)
{
// Create the NetworkServer
// Create the NetworkServer node
Ptr<Node> nsNode = CreateObject<Node>();

// PointToPoint links between gateways and server
PointToPointHelper p2p;
p2p.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
p2p.SetChannelAttribute("Delay", StringValue("2ms"));
for (auto gw = gateways.Begin(); gw != gateways.End(); ++gw)
{
p2p.Install(nsNode, *gw);
}

// Install server application
NetworkServerHelper networkServerHelper = NetworkServerHelper();
networkServerHelper.SetEndDevices(endDevices);
networkServerHelper.SetGateways(gateways);
Ptr<Node> nsNode = CreateObject<Node>();
networkServerHelper.Install(nsNode); // This connects NS and GWs
networkServerHelper.Install(nsNode);

// Install a forwarder on the gateways
ForwarderHelper forwarderHelper;
Expand Down

0 comments on commit 686e547

Please sign in to comment.