From 06c62dc1fbd9653ae52b7626ad29d8b3615c38e0 Mon Sep 17 00:00:00 2001 From: EmaMaker Date: Wed, 27 Dec 2023 11:52:48 +0000 Subject: [PATCH] command line params + assert --- scratch/task_2001600.cc | 113 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 scratch/task_2001600.cc diff --git a/scratch/task_2001600.cc b/scratch/task_2001600.cc new file mode 100644 index 000000000..fade5b3e0 --- /dev/null +++ b/scratch/task_2001600.cc @@ -0,0 +1,113 @@ +#include +#include + +#include "ns3/core-module.h" +#include "ns3/network-module.h" +#include "ns3/csma-module.h" +#include "ns3/internet-module.h" +#include "ns3/point-to-point-module.h" +#include "ns3/applications-module.h" +#include "ns3/ipv4-global-routing-helper.h" + +using namespace ns3; + +NS_LOG_COMPONENT_DEFINE("Task_2001600"); + +NetDeviceContainer createP2P(NodeContainer nodes, StringValue DataRate, StringValue Delay); + +int main(int argc, char* argv[]) +{ + // Hello + NS_LOG_UNCOND("Hello Task_2001600"); + + /* ### Creazione della Rete ### */ + /* PARAMETRI */ + /* + Parametro obbligatorio di nome “studentId” che rappresenta la stringa della matricola referente. Se + questo parametro non viene passato, la simulazione non deve partire + */ + std::string studentId; + /* + Parametro opzionale di nome “enableRtsCts” che rappresenta un valore booleano con valore di + default uguale a Falso. Quando il suo valore è Vero, deve forzare l’uso del meccanismo RTS/CTS + */ + bool enableRtsCts = false; + /* + Parametro opzionale di nome “tracing” che rappresenta un valore booleano con valore di default + uguale a Falso. Quando il suo valore è Vero, deve abilitare il tracing in modalità promiscua sugli + switch di rete e sul router Wi-Fi. + */ + bool tracing = false; + + // Parse command line arguments + // To be passed `./ns3 run task_2001600 --studentId=2001600 --tracing=true --enableRtsCts=true` + CommandLine cmd; + cmd.AddValue("studentId", "studentId", studentId); + cmd.AddValue("enableRtsCts", "Enable RTS/CTS", enableRtsCts); + cmd.AddValue("tracing", "Enable tracing", tracing); + cmd.Parse(argc, argv); + + // Se studentId vuoto, la simulazione non deve partire + if (studentId.empty() > 18) + { + std::cout << "studentId is empty, simulation will not start. exiting." << std::endl; + return 1; + } + + // All the nodes, each subnet uses a subset of these. + // A node can belong to multiple subnets + NodeContainer allNodes; + allNodes.Create(15); + + /* SOTTORETE PTP Node 0,2 */ + NodeContainer nodes02; + nodes02.Add(allNodes.Get(0)); + nodes02.Add(allNodes.Get(2)); + NetDeviceContainer devices02 = createP2P(nodes02, StringValue("10Mbps"), StringValue("200ms")); + /* SOTTORETE PTP Node 1,2 */ + NodeContainer nodes12; + nodes12.Add(allNodes.Get(1)); + nodes12.Add(allNodes.Get(2)); + NetDeviceContainer devices12 = createP2P(nodes12, StringValue("10Mbps"), StringValue("200ms")); + /* SOTTORETE PTP Node 2,4 */ + NodeContainer nodes24; + nodes24.Add(allNodes.Get(2)); + nodes24.Add(allNodes.Get(4)); + NetDeviceContainer devices24 = createP2P(nodes24, StringValue("100Mbps"), StringValue("20ms")); + /* SOTTORETE PTP Node 3,5 */ + NodeContainer nodes35; + nodes35.Add(allNodes.Get(3)); + nodes35.Add(allNodes.Get(5)); + NetDeviceContainer devices35 = createP2P(nodes35, StringValue("100Mbps"), StringValue("20ms")); + /* SOTTORETE PTP Node 4,5 */ + NodeContainer nodes45; + nodes45.Add(allNodes.Get(4)); + nodes45.Add(allNodes.Get(5)); + NetDeviceContainer devices45 = createP2P(nodes45, StringValue("100Mbps"), StringValue("20ms")); + /* SOTTORETE PTP Node 3,9 */ + NodeContainer nodes39; + nodes39.Add(allNodes.Get(3)); + nodes39.Add(allNodes.Get(9)); + NetDeviceContainer devices39 = createP2P(nodes39, StringValue("100Mbps"), StringValue("20ms")); + /* SOTTORETE PTP Node 4,9 */ + NodeContainer nodes49; + nodes49.Add(allNodes.Get(4)); + nodes49.Add(allNodes.Get(9)); + NetDeviceContainer devices49 = createP2P(nodes49, StringValue("100Mbps"), StringValue("20ms")); + + // InternetStackHelper per tutti + InternetStackHelper stack; + stack.Install(allNodes); + + Simulator::Run(); + Simulator::Destroy(); + return 0; +} + + +NetDeviceContainer createP2P(NodeContainer nodes, StringValue DataRate, StringValue Delay){ + PointToPointHelper pointToPoint; + pointToPoint.SetDeviceAttribute("DataRate", DataRate); + pointToPoint.SetChannelAttribute("Delay", Delay); + return pointToPoint.Install(nodes); +} \ No newline at end of file