finish network infrastructure: csma+wifi
parent
06c62dc1fb
commit
f3ce08f0f8
|
@ -8,12 +8,17 @@
|
|||
#include "ns3/point-to-point-module.h"
|
||||
#include "ns3/applications-module.h"
|
||||
#include "ns3/ipv4-global-routing-helper.h"
|
||||
#include "ns3/mobility-module.h"
|
||||
#include "ns3/network-module.h"
|
||||
#include "ns3/ssid.h"
|
||||
#include "ns3/yans-wifi-helper.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE("Task_2001600");
|
||||
|
||||
NetDeviceContainer createP2P(NodeContainer nodes, StringValue DataRate, StringValue Delay);
|
||||
NetDeviceContainer createCSMA(NodeContainer nodes, StringValue DataRate, StringValue Delay);
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
@ -21,6 +26,8 @@ int main(int argc, char* argv[])
|
|||
NS_LOG_UNCOND("Hello Task_2001600");
|
||||
|
||||
/* ### Creazione della Rete ### */
|
||||
|
||||
/* ######################################################## */
|
||||
/* PARAMETRI */
|
||||
/*
|
||||
Parametro obbligatorio di nome “studentId” che rappresenta la stringa della matricola referente. Se
|
||||
|
@ -59,48 +66,148 @@ int main(int argc, char* argv[])
|
|||
NodeContainer allNodes;
|
||||
allNodes.Create(15);
|
||||
|
||||
/* Topologia della Rete*/
|
||||
|
||||
// Reti PTP
|
||||
/* 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"));
|
||||
NetDeviceContainer ptp02 = 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"));
|
||||
NetDeviceContainer ptp12 = 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"));
|
||||
NetDeviceContainer ptp24 = 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"));
|
||||
NetDeviceContainer ptp35 = 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"));
|
||||
NetDeviceContainer ptp45 = 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"));
|
||||
NetDeviceContainer ptp39 = 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"));
|
||||
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");
|
||||
|
||||
// InternetStackHelper per tutti
|
||||
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);
|
||||
|
||||
|
||||
/* ######################################################## */
|
||||
/* IP Addresses*/
|
||||
// TODO: assign IP address to subnets
|
||||
|
||||
/* ######################################################## */
|
||||
/* Applications*/
|
||||
// InternetStackHelper for everyone!
|
||||
InternetStackHelper stack;
|
||||
stack.Install(allNodes);
|
||||
// TODO: applications (Tcp burst, udp echo)
|
||||
// TCP Burst
|
||||
// UDP Echo server
|
||||
|
||||
/* ######################################################## */
|
||||
/* Pcap tracing*/
|
||||
// TODO: enable pcap tracing
|
||||
|
||||
/* ######################################################## */
|
||||
Simulator::Run();
|
||||
Simulator::Destroy();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -110,4 +217,12 @@ NetDeviceContainer createP2P(NodeContainer nodes, StringValue DataRate, StringVa
|
|||
pointToPoint.SetDeviceAttribute("DataRate", DataRate);
|
||||
pointToPoint.SetChannelAttribute("Delay", Delay);
|
||||
return pointToPoint.Install(nodes);
|
||||
}
|
||||
|
||||
NetDeviceContainer createCSMA(NodeContainer nodes, StringValue DataRate, StringValue Delay){
|
||||
CsmaHelper csma;
|
||||
csma.SetDeviceAttribute("DataRate", DataRate);
|
||||
csma.SetChannelAttribute("Delay", Delay);
|
||||
return csma.Install(nodes);
|
||||
|
||||
}
|
Loading…
Reference in New Issue