2023-12-27 12:52:48 +01:00
|
|
|
|
#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"
|
2023-12-27 13:25:23 +01:00
|
|
|
|
#include "ns3/mobility-module.h"
|
|
|
|
|
#include "ns3/network-module.h"
|
|
|
|
|
#include "ns3/ssid.h"
|
|
|
|
|
#include "ns3/yans-wifi-helper.h"
|
2023-12-27 12:52:48 +01:00
|
|
|
|
|
|
|
|
|
using namespace ns3;
|
|
|
|
|
|
|
|
|
|
NS_LOG_COMPONENT_DEFINE("Task_2001600");
|
|
|
|
|
|
|
|
|
|
NetDeviceContainer createP2P(NodeContainer nodes, StringValue DataRate, StringValue Delay);
|
2023-12-27 13:25:23 +01:00
|
|
|
|
NetDeviceContainer createCSMA(NodeContainer nodes, StringValue DataRate, StringValue Delay);
|
2023-12-27 12:52:48 +01:00
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
// Hello
|
|
|
|
|
NS_LOG_UNCOND("Hello Task_2001600");
|
|
|
|
|
|
|
|
|
|
/* ### Creazione della Rete ### */
|
2023-12-27 13:25:23 +01:00
|
|
|
|
|
|
|
|
|
/* ######################################################## */
|
2023-12-27 12:52:48 +01:00
|
|
|
|
/* 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);
|
|
|
|
|
|
2023-12-27 13:25:23 +01:00
|
|
|
|
/* Topologia della Rete*/
|
|
|
|
|
|
|
|
|
|
// Reti PTP
|
2023-12-27 12:52:48 +01:00
|
|
|
|
/* SOTTORETE PTP Node 0,2 */
|
|
|
|
|
NodeContainer nodes02;
|
|
|
|
|
nodes02.Add(allNodes.Get(0));
|
|
|
|
|
nodes02.Add(allNodes.Get(2));
|
2023-12-27 13:25:23 +01:00
|
|
|
|
NetDeviceContainer ptp02 = createP2P(nodes02, StringValue("10Mbps"), StringValue("200ms"));
|
2023-12-27 12:52:48 +01:00
|
|
|
|
/* SOTTORETE PTP Node 1,2 */
|
|
|
|
|
NodeContainer nodes12;
|
|
|
|
|
nodes12.Add(allNodes.Get(1));
|
|
|
|
|
nodes12.Add(allNodes.Get(2));
|
2023-12-27 13:25:23 +01:00
|
|
|
|
NetDeviceContainer ptp12 = createP2P(nodes12, StringValue("10Mbps"), StringValue("200ms"));
|
2023-12-27 12:52:48 +01:00
|
|
|
|
/* SOTTORETE PTP Node 2,4 */
|
|
|
|
|
NodeContainer nodes24;
|
|
|
|
|
nodes24.Add(allNodes.Get(2));
|
|
|
|
|
nodes24.Add(allNodes.Get(4));
|
2023-12-27 13:25:23 +01:00
|
|
|
|
NetDeviceContainer ptp24 = createP2P(nodes24, StringValue("100Mbps"), StringValue("20ms"));
|
2023-12-27 12:52:48 +01:00
|
|
|
|
/* SOTTORETE PTP Node 3,5 */
|
|
|
|
|
NodeContainer nodes35;
|
|
|
|
|
nodes35.Add(allNodes.Get(3));
|
|
|
|
|
nodes35.Add(allNodes.Get(5));
|
2023-12-27 13:25:23 +01:00
|
|
|
|
NetDeviceContainer ptp35 = createP2P(nodes35, StringValue("100Mbps"), StringValue("20ms"));
|
2023-12-27 12:52:48 +01:00
|
|
|
|
/* SOTTORETE PTP Node 4,5 */
|
|
|
|
|
NodeContainer nodes45;
|
|
|
|
|
nodes45.Add(allNodes.Get(4));
|
|
|
|
|
nodes45.Add(allNodes.Get(5));
|
2023-12-27 13:25:23 +01:00
|
|
|
|
NetDeviceContainer ptp45 = createP2P(nodes45, StringValue("100Mbps"), StringValue("20ms"));
|
2023-12-27 12:52:48 +01:00
|
|
|
|
/* SOTTORETE PTP Node 3,9 */
|
|
|
|
|
NodeContainer nodes39;
|
|
|
|
|
nodes39.Add(allNodes.Get(3));
|
|
|
|
|
nodes39.Add(allNodes.Get(9));
|
2023-12-27 13:25:23 +01:00
|
|
|
|
NetDeviceContainer ptp39 = createP2P(nodes39, StringValue("100Mbps"), StringValue("20ms"));
|
2023-12-27 12:52:48 +01:00
|
|
|
|
/* SOTTORETE PTP Node 4,9 */
|
|
|
|
|
NodeContainer nodes49;
|
|
|
|
|
nodes49.Add(allNodes.Get(4));
|
|
|
|
|
nodes49.Add(allNodes.Get(9));
|
2023-12-27 13:25:23 +01:00
|
|
|
|
NetDeviceContainer ptp49 = createP2P(nodes49, StringValue("100Mbps"), StringValue("20ms"));
|
|
|
|
|
|
|
|
|
|
// Reti CSMA
|
|
|
|
|
/* SOTTORETE CSMA Nodi 3,4 */
|
|
|
|
|
NodeContainer nodes34;
|
|
|
|
|
nodes34.Add(allNodes.Get(3));
|
|
|
|
|
nodes34.Add(allNodes.Get(4));
|
|
|
|
|
NetDeviceContainer csma34 = createCSMA(nodes34, StringValue("10Mbps"), StringValue("200ms"));
|
|
|
|
|
/* SOTTORETE CSMA Nodi 5,6,7,8 */
|
|
|
|
|
NodeContainer nodes5678;
|
|
|
|
|
nodes5678.Add(allNodes.Get(5));
|
|
|
|
|
nodes5678.Add(allNodes.Get(6));
|
|
|
|
|
nodes5678.Add(allNodes.Get(7));
|
|
|
|
|
nodes5678.Add(allNodes.Get(8));
|
|
|
|
|
NetDeviceContainer csma5678 = createCSMA(nodes5678, StringValue("5Mbps"), StringValue("20ms"));
|
|
|
|
|
|
|
|
|
|
// Rete Wi-Fi AARF 802.11g
|
|
|
|
|
/*
|
|
|
|
|
Wi-Fi operating in Infrastructure mode, AP is stationary, Stations nodes move with random walk mobility pattern over a bounded square of 30 meters for each side
|
|
|
|
|
*/
|
|
|
|
|
// Channel
|
|
|
|
|
YansWifiChannelHelper channel = YansWifiChannelHelper::Default();
|
|
|
|
|
YansWifiPhyHelper phy;
|
|
|
|
|
phy.SetChannel(channel.Create());
|
|
|
|
|
|
|
|
|
|
// AP
|
|
|
|
|
NodeContainer wifiApNode;
|
|
|
|
|
wifiApNode.Add(allNodes.Get(9));
|
|
|
|
|
|
|
|
|
|
// Station devices
|
|
|
|
|
NodeContainer wifiStationNodes;
|
|
|
|
|
wifiStationNodes.Add(allNodes.Get(10));
|
|
|
|
|
wifiStationNodes.Add(allNodes.Get(11));
|
|
|
|
|
wifiStationNodes.Add(allNodes.Get(12));
|
|
|
|
|
wifiStationNodes.Add(allNodes.Get(13));
|
|
|
|
|
wifiStationNodes.Add(allNodes.Get(14));
|
|
|
|
|
wifiStationNodes.Add(allNodes.Get(15));
|
|
|
|
|
|
|
|
|
|
WifiHelper wifi;
|
|
|
|
|
wifi.SetStandard(WIFI_STANDARD_80211g);
|
|
|
|
|
wifi.SetRemoteStationManager("ns3::AarfWifiManager");
|
|
|
|
|
|
|
|
|
|
WifiMacHelper mac;
|
|
|
|
|
Ssid ssid = Ssid("2001600"); // Ssid matricola regerent
|
|
|
|
|
|
|
|
|
|
// Stations
|
|
|
|
|
NetDeviceContainer staDevice;
|
|
|
|
|
mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid), "ActiveProbing", BooleanValue(false));
|
|
|
|
|
staDevice = wifi.Install(phy, mac, wifiStationNodes);
|
|
|
|
|
|
|
|
|
|
// AccessPoint
|
|
|
|
|
mac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid));
|
|
|
|
|
staDevice = wifi.Install(phy, mac, wifiApNode);
|
|
|
|
|
|
|
|
|
|
// Mobility helper
|
|
|
|
|
MobilityHelper mobility;
|
|
|
|
|
|
|
|
|
|
// Actually needed?
|
|
|
|
|
/*mobility.SetPositionAllocator("ns3::GridPositionAllocator",
|
|
|
|
|
"MinX",
|
|
|
|
|
DoubleValue(0.0),
|
|
|
|
|
"MinY",
|
|
|
|
|
DoubleValue(0.0),
|
|
|
|
|
"DeltaX",
|
|
|
|
|
DoubleValue(5.0),
|
|
|
|
|
"DeltaY",
|
|
|
|
|
DoubleValue(10.0),
|
|
|
|
|
"GridWidth",
|
|
|
|
|
UintegerValue(3),
|
|
|
|
|
"LayoutType",
|
|
|
|
|
StringValue("RowFirst"));
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Stations move with random walk over a square of 30 meters each side
|
|
|
|
|
mobility.SetMobilityModel("ns3::RandomWalk2dMobilityModel",
|
|
|
|
|
"Bounds",
|
|
|
|
|
RectangleValue(Rectangle(-30, 30, -30, 30)));
|
|
|
|
|
mobility.Install(wifiStationNodes);
|
|
|
|
|
|
|
|
|
|
// AP is stationary
|
|
|
|
|
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
|
|
|
|
|
mobility.Install(wifiApNode);
|
2023-12-27 12:52:48 +01:00
|
|
|
|
|
2023-12-27 13:25:23 +01:00
|
|
|
|
|
|
|
|
|
/* ######################################################## */
|
|
|
|
|
/* IP Addresses*/
|
|
|
|
|
// TODO: assign IP address to subnets
|
|
|
|
|
|
|
|
|
|
/* ######################################################## */
|
|
|
|
|
/* Applications*/
|
|
|
|
|
// InternetStackHelper for everyone!
|
2023-12-27 12:52:48 +01:00
|
|
|
|
InternetStackHelper stack;
|
|
|
|
|
stack.Install(allNodes);
|
2023-12-27 13:25:23 +01:00
|
|
|
|
// TODO: applications (Tcp burst, udp echo)
|
|
|
|
|
// TCP Burst
|
|
|
|
|
// UDP Echo server
|
|
|
|
|
|
|
|
|
|
/* ######################################################## */
|
|
|
|
|
/* Pcap tracing*/
|
|
|
|
|
// TODO: enable pcap tracing
|
2023-12-27 12:52:48 +01:00
|
|
|
|
|
2023-12-27 13:25:23 +01:00
|
|
|
|
/* ######################################################## */
|
2023-12-27 12:52:48 +01:00
|
|
|
|
Simulator::Run();
|
|
|
|
|
Simulator::Destroy();
|
2023-12-27 13:25:23 +01:00
|
|
|
|
|
2023-12-27 12:52:48 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NetDeviceContainer createP2P(NodeContainer nodes, StringValue DataRate, StringValue Delay){
|
|
|
|
|
PointToPointHelper pointToPoint;
|
|
|
|
|
pointToPoint.SetDeviceAttribute("DataRate", DataRate);
|
|
|
|
|
pointToPoint.SetChannelAttribute("Delay", Delay);
|
|
|
|
|
return pointToPoint.Install(nodes);
|
2023-12-27 13:25:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetDeviceContainer createCSMA(NodeContainer nodes, StringValue DataRate, StringValue Delay){
|
|
|
|
|
CsmaHelper csma;
|
|
|
|
|
csma.SetDeviceAttribute("DataRate", DataRate);
|
|
|
|
|
csma.SetChannelAttribute("Delay", Delay);
|
|
|
|
|
return csma.Install(nodes);
|
|
|
|
|
|
2023-12-27 12:52:48 +01:00
|
|
|
|
}
|