tc-homework2/scratch/task_2001600.cc

113 lines
4.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <iostream>
#include <string>
#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 luso 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);
}