Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format all files to current ns-3 .clang-format rules #136

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
507 changes: 258 additions & 249 deletions examples/adr-example.cc

Large diffs are not rendered by default.

478 changes: 243 additions & 235 deletions examples/aloha-throughput.cc

Large diffs are not rendered by default.

487 changes: 249 additions & 238 deletions examples/complete-network-example.cc

Large diffs are not rendered by default.

358 changes: 178 additions & 180 deletions examples/frame-counter-update.cc

Large diffs are not rendered by default.

285 changes: 143 additions & 142 deletions examples/lorawan-energy-model-example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,191 +3,192 @@
* works.
*/

#include "ns3/basic-energy-source-helper.h"
#include "ns3/class-a-end-device-lorawan-mac.h"
#include "ns3/command-line.h"
#include "ns3/constant-position-mobility-model.h"
#include "ns3/end-device-lora-phy.h"
#include "ns3/file-helper.h"
#include "ns3/gateway-lora-phy.h"
#include "ns3/class-a-end-device-lorawan-mac.h"
#include "ns3/gateway-lorawan-mac.h"
#include "ns3/simulator.h"
#include "ns3/log.h"
#include "ns3/constant-position-mobility-model.h"
#include "ns3/lora-helper.h"
#include "ns3/lora-radio-energy-model-helper.h"
#include "ns3/mobility-helper.h"
#include "ns3/names.h"
#include "ns3/node-container.h"
#include "ns3/position-allocator.h"
#include "ns3/periodic-sender-helper.h"
#include "ns3/command-line.h"
#include "ns3/basic-energy-source-helper.h"
#include "ns3/lora-radio-energy-model-helper.h"
#include "ns3/file-helper.h"
#include "ns3/names.h"
#include "ns3/position-allocator.h"
#include "ns3/simulator.h"

#include <algorithm>
#include <ctime>

using namespace ns3;
using namespace lorawan;

NS_LOG_COMPONENT_DEFINE ("LoraEnergyModelExample");
NS_LOG_COMPONENT_DEFINE("LoraEnergyModelExample");

int main (int argc, char *argv[])
int
main(int argc, char* argv[])
{
// Set up logging
LogComponentEnable("LoraEnergyModelExample", LOG_LEVEL_ALL);
// LogComponentEnable ("LoraRadioEnergyModel", LOG_LEVEL_ALL);
// LogComponentEnable ("LoraChannel", LOG_LEVEL_INFO);
// LogComponentEnable ("LoraPhy", LOG_LEVEL_ALL);
// LogComponentEnable ("EndDeviceLoraPhy", LOG_LEVEL_ALL);
// LogComponentEnable ("GatewayLoraPhy", LOG_LEVEL_ALL);
// LogComponentEnable ("LoraInterferenceHelper", LOG_LEVEL_ALL);
// LogComponentEnable ("LorawanMac", LOG_LEVEL_ALL);
// LogComponentEnable ("EndDeviceLorawanMac", LOG_LEVEL_ALL);
// LogComponentEnable ("ClassAEndDeviceLorawanMac", LOG_LEVEL_ALL);
// LogComponentEnable ("GatewayLorawanMac", LOG_LEVEL_ALL);
// LogComponentEnable ("LogicalLoraChannelHelper", LOG_LEVEL_ALL);
// LogComponentEnable ("LogicalLoraChannel", LOG_LEVEL_ALL);
// LogComponentEnable ("LoraHelper", LOG_LEVEL_ALL);
// LogComponentEnable ("LoraPhyHelper", LOG_LEVEL_ALL);
// LogComponentEnable ("LorawanMacHelper", LOG_LEVEL_ALL);
// LogComponentEnable ("OneShotSenderHelper", LOG_LEVEL_ALL);
// LogComponentEnable ("OneShotSender", LOG_LEVEL_ALL);
// LogComponentEnable ("LorawanMacHeader", LOG_LEVEL_ALL);
// LogComponentEnable ("LoraFrameHeader", LOG_LEVEL_ALL);
LogComponentEnableAll(LOG_PREFIX_FUNC);
LogComponentEnableAll(LOG_PREFIX_NODE);
LogComponentEnableAll(LOG_PREFIX_TIME);

/************************
* Create the channel *
************************/

NS_LOG_INFO("Creating the channel...");

// Create the lora channel object
Ptr<LogDistancePropagationLossModel> loss = CreateObject<LogDistancePropagationLossModel>();
loss->SetPathLossExponent(3.76);
loss->SetReference(1, 7.7);

Ptr<PropagationDelayModel> delay = CreateObject<ConstantSpeedPropagationDelayModel>();

Ptr<LoraChannel> channel = CreateObject<LoraChannel>(loss, delay);

/************************
* Create the helpers *
************************/

NS_LOG_INFO("Setting up helpers...");

MobilityHelper mobility;
Ptr<ListPositionAllocator> allocator = CreateObject<ListPositionAllocator>();
allocator->Add(Vector(100, 0, 0));
allocator->Add(Vector(0, 0, 0));
mobility.SetPositionAllocator(allocator);
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");

// Create the LoraPhyHelper
LoraPhyHelper phyHelper = LoraPhyHelper();
phyHelper.SetChannel(channel);

// Create the LorawanMacHelper
LorawanMacHelper macHelper = LorawanMacHelper();

// Set up logging
LogComponentEnable ("LoraEnergyModelExample", LOG_LEVEL_ALL);
// LogComponentEnable ("LoraRadioEnergyModel", LOG_LEVEL_ALL);
// LogComponentEnable ("LoraChannel", LOG_LEVEL_INFO);
// LogComponentEnable ("LoraPhy", LOG_LEVEL_ALL);
// LogComponentEnable ("EndDeviceLoraPhy", LOG_LEVEL_ALL);
// LogComponentEnable ("GatewayLoraPhy", LOG_LEVEL_ALL);
// LogComponentEnable ("LoraInterferenceHelper", LOG_LEVEL_ALL);
// LogComponentEnable ("LorawanMac", LOG_LEVEL_ALL);
// LogComponentEnable ("EndDeviceLorawanMac", LOG_LEVEL_ALL);
// LogComponentEnable ("ClassAEndDeviceLorawanMac", LOG_LEVEL_ALL);
// LogComponentEnable ("GatewayLorawanMac", LOG_LEVEL_ALL);
// LogComponentEnable ("LogicalLoraChannelHelper", LOG_LEVEL_ALL);
// LogComponentEnable ("LogicalLoraChannel", LOG_LEVEL_ALL);
// LogComponentEnable ("LoraHelper", LOG_LEVEL_ALL);
// LogComponentEnable ("LoraPhyHelper", LOG_LEVEL_ALL);
// LogComponentEnable ("LorawanMacHelper", LOG_LEVEL_ALL);
// LogComponentEnable ("OneShotSenderHelper", LOG_LEVEL_ALL);
// LogComponentEnable ("OneShotSender", LOG_LEVEL_ALL);
// LogComponentEnable ("LorawanMacHeader", LOG_LEVEL_ALL);
// LogComponentEnable ("LoraFrameHeader", LOG_LEVEL_ALL);
LogComponentEnableAll (LOG_PREFIX_FUNC);
LogComponentEnableAll (LOG_PREFIX_NODE);
LogComponentEnableAll (LOG_PREFIX_TIME);

/************************
* Create the channel *
************************/

NS_LOG_INFO ("Creating the channel...");

// Create the lora channel object
Ptr<LogDistancePropagationLossModel> loss = CreateObject<LogDistancePropagationLossModel> ();
loss->SetPathLossExponent (3.76);
loss->SetReference (1, 7.7);

Ptr<PropagationDelayModel> delay = CreateObject<ConstantSpeedPropagationDelayModel> ();

Ptr<LoraChannel> channel = CreateObject<LoraChannel> (loss, delay);

/************************
* Create the helpers *
************************/

NS_LOG_INFO ("Setting up helpers...");

MobilityHelper mobility;
Ptr<ListPositionAllocator> allocator = CreateObject<ListPositionAllocator> ();
allocator->Add (Vector (100,0,0));
allocator->Add (Vector (0,0,0));
mobility.SetPositionAllocator (allocator);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");

// Create the LoraPhyHelper
LoraPhyHelper phyHelper = LoraPhyHelper ();
phyHelper.SetChannel (channel);

// Create the LorawanMacHelper
LorawanMacHelper macHelper = LorawanMacHelper ();

// Create the LoraHelper
LoraHelper helper = LoraHelper ();

/************************
* Create End Devices *
************************/
// Create the LoraHelper
LoraHelper helper = LoraHelper();

NS_LOG_INFO ("Creating the end device...");
/************************
* Create End Devices *
************************/

// Create a set of nodes
NodeContainer endDevices;
endDevices.Create (1);
NS_LOG_INFO("Creating the end device...");

// Assign a mobility model to the node
mobility.Install (endDevices);
// Create a set of nodes
NodeContainer endDevices;
endDevices.Create(1);

// Create the LoraNetDevices of the end devices
phyHelper.SetDeviceType (LoraPhyHelper::ED);
macHelper.SetDeviceType (LorawanMacHelper::ED_A);
NetDeviceContainer endDevicesNetDevices = helper.Install (phyHelper, macHelper, endDevices);
// Assign a mobility model to the node
mobility.Install(endDevices);

/*********************
* Create Gateways *
*********************/
// Create the LoraNetDevices of the end devices
phyHelper.SetDeviceType(LoraPhyHelper::ED);
macHelper.SetDeviceType(LorawanMacHelper::ED_A);
NetDeviceContainer endDevicesNetDevices = helper.Install(phyHelper, macHelper, endDevices);

NS_LOG_INFO ("Creating the gateway...");
NodeContainer gateways;
gateways.Create (1);
/*********************
* Create Gateways *
*********************/

mobility.SetPositionAllocator (allocator);
mobility.Install (gateways);
NS_LOG_INFO("Creating the gateway...");
NodeContainer gateways;
gateways.Create(1);

// Create a netdevice for each gateway
phyHelper.SetDeviceType (LoraPhyHelper::GW);
macHelper.SetDeviceType (LorawanMacHelper::GW);
helper.Install (phyHelper, macHelper, gateways);
mobility.SetPositionAllocator(allocator);
mobility.Install(gateways);

macHelper.SetSpreadingFactorsUp (endDevices, gateways, channel);
// Create a netdevice for each gateway
phyHelper.SetDeviceType(LoraPhyHelper::GW);
macHelper.SetDeviceType(LorawanMacHelper::GW);
helper.Install(phyHelper, macHelper, gateways);

/*********************************************
* Install applications on the end devices *
*********************************************/
macHelper.SetSpreadingFactorsUp(endDevices, gateways, channel);

// OneShotSenderHelper oneShotSenderHelper;
// oneShotSenderHelper.SetSendTime (Seconds (10));
/*********************************************
* Install applications on the end devices *
*********************************************/

// oneShotSenderHelper.Install (endDevices);
// OneShotSenderHelper oneShotSenderHelper;
// oneShotSenderHelper.SetSendTime (Seconds (10));

PeriodicSenderHelper periodicSenderHelper;
periodicSenderHelper.SetPeriod (Seconds (5));
// oneShotSenderHelper.Install (endDevices);

periodicSenderHelper.Install (endDevices);
PeriodicSenderHelper periodicSenderHelper;
periodicSenderHelper.SetPeriod(Seconds(5));

/************************
* Install Energy Model *
************************/
periodicSenderHelper.Install(endDevices);

BasicEnergySourceHelper basicSourceHelper;
LoraRadioEnergyModelHelper radioEnergyHelper;
/************************
* Install Energy Model *
************************/

// configure energy source
basicSourceHelper.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (10000)); // Energy in J
basicSourceHelper.Set ("BasicEnergySupplyVoltageV", DoubleValue (3.3));
BasicEnergySourceHelper basicSourceHelper;
LoraRadioEnergyModelHelper radioEnergyHelper;

radioEnergyHelper.Set ("StandbyCurrentA", DoubleValue (0.0014));
radioEnergyHelper.Set ("TxCurrentA", DoubleValue (0.028));
radioEnergyHelper.Set ("SleepCurrentA", DoubleValue (0.0000015));
radioEnergyHelper.Set ("RxCurrentA", DoubleValue (0.0112));
// configure energy source
basicSourceHelper.Set("BasicEnergySourceInitialEnergyJ", DoubleValue(10000)); // Energy in J
basicSourceHelper.Set("BasicEnergySupplyVoltageV", DoubleValue(3.3));

radioEnergyHelper.SetTxCurrentModel ("ns3::ConstantLoraTxCurrentModel",
"TxCurrent", DoubleValue (0.028));
radioEnergyHelper.Set("StandbyCurrentA", DoubleValue(0.0014));
radioEnergyHelper.Set("TxCurrentA", DoubleValue(0.028));
radioEnergyHelper.Set("SleepCurrentA", DoubleValue(0.0000015));
radioEnergyHelper.Set("RxCurrentA", DoubleValue(0.0112));

// install source on EDs' nodes
EnergySourceContainer sources = basicSourceHelper.Install (endDevices);
Names::Add ("/Names/EnergySource", sources.Get (0));
radioEnergyHelper.SetTxCurrentModel("ns3::ConstantLoraTxCurrentModel",
"TxCurrent",
DoubleValue(0.028));

// install device model
DeviceEnergyModelContainer deviceModels = radioEnergyHelper.Install
(endDevicesNetDevices, sources);
// install source on EDs' nodes
EnergySourceContainer sources = basicSourceHelper.Install(endDevices);
Names::Add("/Names/EnergySource", sources.Get(0));

/**************
* Get output *
**************/
FileHelper fileHelper;
fileHelper.ConfigureFile ("battery-level", FileAggregator::SPACE_SEPARATED);
fileHelper.WriteProbe ("ns3::DoubleProbe", "/Names/EnergySource/RemainingEnergy", "Output");
// install device model
DeviceEnergyModelContainer deviceModels =
radioEnergyHelper.Install(endDevicesNetDevices, sources);

/**************
* Get output *
**************/
FileHelper fileHelper;
fileHelper.ConfigureFile("battery-level", FileAggregator::SPACE_SEPARATED);
fileHelper.WriteProbe("ns3::DoubleProbe", "/Names/EnergySource/RemainingEnergy", "Output");

/****************
* Simulation *
****************/
/****************
* Simulation *
****************/

Simulator::Stop (Hours (24));
Simulator::Stop(Hours(24));

Simulator::Run ();
Simulator::Run();

Simulator::Destroy ();
Simulator::Destroy();

return 0;
return 0;
}
Loading