Difference between revisions of "Ns-3-Network-Simulator/C3/Infrastructure-based-Wireless-Network/English"
(Created page with "{| border="1" |- || '''Visual Cue''' || '''Narration''' |- || Show Slide: '''Title Slide''' || Welcome to Spoken tutorial on '''Infrastructure''' '''based''' '''wireless netwo...") |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 6: | Line 6: | ||
|| Show Slide: '''Title Slide''' | || Show Slide: '''Title Slide''' | ||
|| Welcome to Spoken tutorial on '''Infrastructure''' '''based''' '''wireless network'''. | || Welcome to Spoken tutorial on '''Infrastructure''' '''based''' '''wireless network'''. | ||
− | |- | + | |- |
|| Show Slide: | || Show Slide: | ||
'''Learning Objectives''' | '''Learning Objectives''' | ||
|| In this tutorial, we will learn to | || In this tutorial, we will learn to | ||
− | * | + | * Create an '''infrastructure''' based '''wireless network'''. |
− | * | + | * Create three '''UDP flows''' in the channels. |
− | * | + | * Analyze the flow using a '''flow monitor'''. |
− | * | + | * Visualize the network using '''NetAnim'''. |
|- | |- | ||
− | |- | + | |- |
|| Show Slide: | || Show Slide: | ||
'''System Requirements''' | '''System Requirements''' | ||
|| To record this tutorial, I am using | || To record this tutorial, I am using | ||
− | * | + | * '''Ubuntu Linux OS version 22.04.''' |
− | * | + | * '''ns-3 version '''3.38. |
− | * | + | * '''NetAnim''' visualizer tool. |
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
'''Pre-requisites''' | '''Pre-requisites''' | ||
|| To follow this tutorial: | || To follow this tutorial: | ||
− | * | + | * The learner must have basic knowledge of ns-3 software |
− | * | + | * For pre-requisite ns-3 tutorials, please visit this website [https://spoken-tutorial.org/ https://spoken-tutorial.org] |
− | |- | + | |- |
− | || | + | || Show Slide: |
− | + | '''Code Files''' | |
|| | || | ||
− | * | + | * The files used in this tutorial are provided in the'''Code files''' link. |
− | * | + | * Please download and extract the files. |
− | * | + | * Make a copy and then use them while practicing. |
− | |- | + | |- |
|| Show Slide: | || Show Slide: | ||
Line 49: | Line 49: | ||
|| For this tutorial, we would be creating the below infrastructure. | || For this tutorial, we would be creating the below infrastructure. | ||
− | In this diagram, the '''nodes 0, 2 | + | In this diagram, the '''nodes''' 0, 2 and 3 are '''station nodes.''' |
− | '''Node 1''' is the '''access point '''of the '''infrastructure'''. | + | '''Node 1''' is the '''access point ''' of the '''infrastructure'''. |
− | |- | + | |- |
|| | || | ||
|| Now, let us learn about '''DSSS'''. | || Now, let us learn about '''DSSS'''. | ||
− | |- | + | |- |
|| Show Slide: | || Show Slide: | ||
'''About DSSS''' | '''About DSSS''' | ||
− | || '''DSSS rate''' is '''data rate''' in a Wifi system. | + | || '''DSSS rate''' is '''data rate''' in a '''Wifi''' system. |
It uses '''Direct Sequence Spread Spectrum modulation'''. | It uses '''Direct Sequence Spread Spectrum modulation'''. | ||
− | In a '''DSSS system''', data is spread over a ''' | + | In a '''DSSS system''', data is spread over a wider '''bandwidth''' using a '''spreading code'''. |
− | |- | + | |- |
|| Show Slide: | || Show Slide: | ||
Line 72: | Line 72: | ||
'''DSSS rate '''represents the speed of information transmitted after spreading. | '''DSSS rate '''represents the speed of information transmitted after spreading. | ||
− | '''DSSS''' can transfer up to''' | + | '''DSSS''' can transfer up to 11 '''Mbps''' of '''data.''' |
− | |- | + | |- |
|| Open code editor | || Open code editor | ||
|| I have created the source file '''wifi-simple-infra.cc''' for this program. | || I have created the source file '''wifi-simple-infra.cc''' for this program. | ||
Line 80: | Line 80: | ||
Now we will go through the source code in the text editor. | Now we will go through the source code in the text editor. | ||
− | |- | + | |- |
|| Highlight '''std::string phyMode("DsssRate1Mbps");''' | || Highlight '''std::string phyMode("DsssRate1Mbps");''' | ||
− | || We set the '''dsss rate''' of the '''physical layer''' to ''' | + | || We set the '''dsss rate''' of the '''physical layer''' to 1 ''' Mbps'''. |
− | |- | + | |- |
|| Highlight '''double rss = -80''' | || Highlight '''double rss = -80''' | ||
− | || Next, | + | || Next, we will set the ''' Received Signal Strength ''' or ''' RSS''' to -80 '''dBm'''. |
− | |- | + | |- |
|| Highlight '''uint32_t packetSize = 1000;''' | || Highlight '''uint32_t packetSize = 1000;''' | ||
Line 92: | Line 92: | ||
|| Now we shall set the '''packet size''' to '''1000 bytes'''. | || Now we shall set the '''packet size''' to '''1000 bytes'''. | ||
− | Then | + | Then we will set the number of '''packets''' to be transmitted as 100. |
− | |- | + | |- |
|| Highlight '''Time interval = Seconds(0.003);''' | || Highlight '''Time interval = Seconds(0.003);''' | ||
− | || Further, we set the '''time interval''' between the '''packet transfer''' as | + | || Further, we set the '''time interval''' between the '''packet transfer''' as 0.003 seconds. |
− | |- | + | |- |
|| Highlight '''uint32_t sinkNode = 1;''' | || Highlight '''uint32_t sinkNode = 1;''' | ||
'''uint32_t sourceNode = 0;''' | '''uint32_t sourceNode = 0;''' | ||
− | || Let us set up the '''source''' and''' sink nodes''' for the | + | || Let us set up the '''source''' and''' sink nodes''' for the flow that we are yet to create. |
− | |- | + | |- |
|| Highlight '''Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue(phyMode));''' | || Highlight '''Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue(phyMode));''' | ||
Line 109: | Line 109: | ||
'''Non-unicast mode''' means that the data may be sent from one node to many nodes. | '''Non-unicast mode''' means that the data may be sent from one node to many nodes. | ||
− | |- | + | |- |
|| Highlight '''NodeContainer c;''' | || Highlight '''NodeContainer c;''' | ||
'''c.Create(4);''' | '''c.Create(4);''' | ||
− | || Now, let us create a '''node container''' with ''' | + | || Now, let us create a '''node container''' with four '''nodes'''. |
− | |- | + | |- |
|| Highlight '''WifiHelper wifi;''' | || Highlight '''WifiHelper wifi;''' | ||
Line 126: | Line 126: | ||
Using '''Wifi-helper''' class, we '''enable logging components''' and '''set the wifi standard'''. | Using '''Wifi-helper''' class, we '''enable logging components''' and '''set the wifi standard'''. | ||
− | Here, the | + | Here, the standard set is '''IEEE 802.11b.''' |
− | |- | + | |- |
|| Highlight '''YansWifiPhyHelper wifiPhy;''' | || Highlight '''YansWifiPhyHelper wifiPhy;''' | ||
'''wifiPhy.Set("RxGain", DoubleValue(0));''' | '''wifiPhy.Set("RxGain", DoubleValue(0));''' | ||
− | || Then we shall use '''YansWifiPhyHelper class '''to set the '''RxGain attribute''' to | + | || Then we shall use '''YansWifiPhyHelper class '''to set the '''RxGain attribute''' to zero. |
'''RxGain''' is used to adjust the sensitivity of the receiving signal. | '''RxGain''' is used to adjust the sensitivity of the receiving signal. | ||
− | |- | + | |- |
− | || Highlight ''' | + | || Highlight '''YaifiChannelHelper wifiChannel;''' |
'''wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");''' | '''wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");''' | ||
Line 144: | Line 144: | ||
Let us set the '''Propagation delay''' and '''add '''the '''propagation loss''' to our model. | Let us set the '''Propagation delay''' and '''add '''the '''propagation loss''' to our model. | ||
− | |- | + | |- |
|| Highlight '''wifiPhy.SetChannel(wifiChannel.Create());''' | || Highlight '''wifiPhy.SetChannel(wifiChannel.Create());''' | ||
|| Next, we connect the''' wifi physical layer '''to the '''wifi-channel'''. | || Next, we connect the''' wifi physical layer '''to the '''wifi-channel'''. | ||
− | |- | + | |- |
|| Highlight '''WifiMacHelper wifiMac;''' | || Highlight '''WifiMacHelper wifiMac;''' | ||
'''wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager","DataMode", StringValue(phyMode), "ControlMode", StringValue(phyMode));''' | '''wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager","DataMode", StringValue(phyMode), "ControlMode", StringValue(phyMode));''' | ||
− | || Now let us add | + | || Now let us add ''' MAC protocol '''to the '''Network Interface Cards''' that we installed. |
− | Then we set a | + | Then we set a constant rate for '''data''' and '''control modes '''of '''wifi stations.''' |
− | |- | + | |- |
|| Highlight '''Ssid ssid = Ssid("wifi-default");''' | || Highlight '''Ssid ssid = Ssid("wifi-default");''' | ||
|| Then, we assign '''SSID '''to the network. | || Then, we assign '''SSID '''to the network. | ||
'''SSID''' or '''Service Set Identifier''' is a sequence of characters uniquely identifying a network. | '''SSID''' or '''Service Set Identifier''' is a sequence of characters uniquely identifying a network. | ||
− | |- | + | |- |
|| Highlight '''wifiMac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));''' | || Highlight '''wifiMac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));''' | ||
Line 168: | Line 168: | ||
|| Let us now set up the '''station node '''by setting up''' MAC protocol '''and installing''' NIC.''' | || Let us now set up the '''station node '''by setting up''' MAC protocol '''and installing''' NIC.''' | ||
− | We create a container '''staDevice '''to | + | We create a container '''staDevice '''to hold the '''installed Wifi devices'''. |
As a next step, we shall take a copy of '''staDevice container '''in '''devices container.''' | As a next step, we shall take a copy of '''staDevice container '''in '''devices container.''' | ||
− | |- | + | |- |
|| Highlight | || Highlight | ||
Line 182: | Line 182: | ||
|| Similarly, we shall set up the '''Access Point''' of the '''wireless network'''. | || Similarly, we shall set up the '''Access Point''' of the '''wireless network'''. | ||
− | We have set up the '''AP node '''of the | + | We have set up the '''AP node '''of the wireless network using '''ApWifiMac protocol'''. |
We are also installing '''wifiphy''' to the '''node1''' of the wireless network. | We are also installing '''wifiphy''' to the '''node1''' of the wireless network. | ||
Then '''ssid''' is assigned to the '''AP node''' of the network. | Then '''ssid''' is assigned to the '''AP node''' of the network. | ||
− | |- | + | |- |
|| Highlight '''MobilityHelper mobility;''' | || Highlight '''MobilityHelper mobility;''' | ||
Line 195: | Line 195: | ||
'''mobility.SetPositionAllocator(positionAlloc);''' | '''mobility.SetPositionAllocator(positionAlloc);''' | ||
− | || Now set up | + | || Now set up mobility for the nodes by allocating positions for the '''nodes''' created. |
− | |- | + | |- |
|| Highlight '''mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");''' | || Highlight '''mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");''' | ||
'''mobility.Install(c);''' | '''mobility.Install(c);''' | ||
− | || Let us | + | || Let us set the model to be '''ConstantPositionMobilityModel.''' |
− | It represents the | + | It represents the 'stationary or '''static nodes''' in a '''network simulation.''' |
− | Also, '''install '''the | + | Also, '''install '''the model that we set, to all the '''nodes''' that we created. |
− | |- | + | |- |
|| Highlight '''InternetStackHelper internet;''' | || Highlight '''InternetStackHelper internet;''' | ||
'''internet.Install(c);''' | '''internet.Install(c);''' | ||
− | || Then let us install the''' internet stack''' on all the nodes. | + | || Then let us install the ''' internet stack''' on all the nodes. |
− | |- | + | |- |
|| Highlight '''Ipv4AddressHelper ipv4;''' | || Highlight '''Ipv4AddressHelper ipv4;''' | ||
Line 220: | Line 220: | ||
|| Now, we shall '''assign IP addresses''' to the '''nodes''' that we created | || Now, we shall '''assign IP addresses''' to the '''nodes''' that we created | ||
− | |- | + | |- |
|| Highlight '''TypeId tid = TypeId::LookupByName("ns3::UdpSocketFactory");''' | || Highlight '''TypeId tid = TypeId::LookupByName("ns3::UdpSocketFactory");''' | ||
− | || The highlighted command is used to get the '''TypeId''' of '''UdpSocketFactory | + | || The highlighted command is used to get the '''TypeId''' of '''UdpSocketFactory'''. |
− | |- | + | |- |
|| Highlight '''Ptr<Socket> recvSink = Socket::CreateSocket(c.Get(sinkNode), tid);''' | || Highlight '''Ptr<Socket> recvSink = Socket::CreateSocket(c.Get(sinkNode), tid);''' | ||
|| We shall create a receiving '''socket''' for the '''UDP Flow'''. | || We shall create a receiving '''socket''' for the '''UDP Flow'''. | ||
− | |- | + | |- |
|| Highlight '''InetSocketAddress local = InetSocketAddress(Ipv4Address::GetAny(), 80);''' | || Highlight '''InetSocketAddress local = InetSocketAddress(Ipv4Address::GetAny(), 80);''' | ||
|| Let us create an '''internet socket''' '''address''' using any '''IPv4 address''' and '''port 80.''' | || Let us create an '''internet socket''' '''address''' using any '''IPv4 address''' and '''port 80.''' | ||
− | |- | + | |- |
|| Highlight '''recvSink->Bind(local);''' | || Highlight '''recvSink->Bind(local);''' | ||
− | || Then | + | || Then bind the '''receiving socket''' to the '''local address''' and to the '''port 80'''. |
− | |- | + | |- |
− | || Highlight <span style="background-color:#ffffff;">'''recvSink->SetRecvCallback(MakeCallback(&ReceivePacket));''' | + | || Highlight <span style="background-color:#ffffff;">'''recvSink->SetRecvCallback(MakeCallback(&ReceivePacket));''' |
|| Now set the '''receive''' '''callback function''' for the '''receiving socket'''. | || Now set the '''receive''' '''callback function''' for the '''receiving socket'''. | ||
When the '''packet '''is received in the '''sinknode''', we call '''RecievePacket function'''. | When the '''packet '''is received in the '''sinknode''', we call '''RecievePacket function'''. | ||
− | |- | + | |- |
|| Highlight '''Ptr<Socket> source = Socket::CreateSocket(c.Get(sourceNode), tid);''' | || Highlight '''Ptr<Socket> source = Socket::CreateSocket(c.Get(sourceNode), tid);''' | ||
− | || Let us then | + | || Let us then create an '''UDP socket''' on '''node''' 0, which is our '''sourceNode'''. |
− | |- | + | |- |
|| Highlight '''InetSocketAddress remote = InetSocketAddress(i.GetAddress(sinkNode, 0), 80);''' | || Highlight '''InetSocketAddress remote = InetSocketAddress(i.GetAddress(sinkNode, 0), 80);''' | ||
− | || We shall create an''' internet socket '''using '''Ipv4 address''' of '''sinknode''' and '''port 80'''. | + | || We shall create an''' internet socket ''' using '''Ipv4 address''' of '''sinknode''' and '''port 80'''. |
− | |- | + | |- |
|| Highlight '''source->Connect(remote);''' | || Highlight '''source->Connect(remote);''' | ||
− | || Let us connect the '''source socket '''to the '''remote address''' and '''port 80.''' | + | || Let us connect the '''source socket ''' to the '''remote address''' and '''port 80.''' |
− | |- | + | |- |
|| Highlight '''void''' | || Highlight '''void''' | ||
Line 262: | Line 262: | ||
Here, we are invoking the '''receive functionality''' of the '''socket'''. | Here, we are invoking the '''receive functionality''' of the '''socket'''. | ||
− | |- | + | |- |
|| Highlight '''static void''' | || Highlight '''static void''' | ||
Line 268: | Line 268: | ||
|| Then we define a '''function '''called '''generate packet traffic'''. | || Then we define a '''function '''called '''generate packet traffic'''. | ||
− | |- | + | |- |
|| Highlight '''if (pktCount > 0)''' | || Highlight '''if (pktCount > 0)''' | ||
Line 296: | Line 296: | ||
'''}''' | '''}''' | ||
− | || When the | + | || When the number of packets is not zero, we invoke the '''send '''function. |
− | We also schedule the '''simulator '''to | + | We also schedule the '''simulator '''to invoke the''' GenerateTraffic function.''' |
− | When the | + | When the number of packets is zero, we close the '''socket'''. |
Then, we '''stop invoking send function'''. | Then, we '''stop invoking send function'''. | ||
− | |- | + | |- |
|| Only Narration | || Only Narration | ||
− | || We have created | + | || We have created two other '''UDP''' flows as well. |
− | |- | + | |- |
|| Highlight '''Simulator::Schedule(Seconds(''' | || Highlight '''Simulator::Schedule(Seconds(''' | ||
'''10),&GenerateTraffic,source,packetSize,numPackets,interval);''' | '''10),&GenerateTraffic,source,packetSize,numPackets,interval);''' | ||
− | || Let us | + | || Let us schedule the '''simulator''' to '''callback''' the '''generate_traffic function.''' |
− | This procedure happens after | + | This procedure happens after ten seconds from the start of execution. |
− | |- | + | |- |
|| Highlight '''Ptr<FlowMonitor> flowMonitor;''' | || Highlight '''Ptr<FlowMonitor> flowMonitor;''' | ||
− | || Then, | + | || Then, Initialize '''flow monitor''' for '''tracing'''. |
− | |- | + | |- |
|| HIghlight '''FlowMonitorHelper flowHelper;''' | || HIghlight '''FlowMonitorHelper flowHelper;''' | ||
Line 323: | Line 323: | ||
|| We shall then install a '''flow monitor''' on all the '''nodes'''. | || We shall then install a '''flow monitor''' on all the '''nodes'''. | ||
− | |- | + | |- |
|| Highlight '''AnimationInterface anim ("animationwifi-infra-2.xml"); ''' | || Highlight '''AnimationInterface anim ("animationwifi-infra-2.xml"); ''' | ||
|| Let us create the''' XML output''' of the program. | || Let us create the''' XML output''' of the program. | ||
− | |- | + | |- |
|| HIghlight '''Ptr<Ipv4FlowClassifier> classifier=DynamicCast<Ipv4FlowClassifier> (flowHelper.GetClassifier());''' | || HIghlight '''Ptr<Ipv4FlowClassifier> classifier=DynamicCast<Ipv4FlowClassifier> (flowHelper.GetClassifier());''' | ||
|| Let us further create an object of the '''Ipv4FlowClassifier class.''' | || Let us further create an object of the '''Ipv4FlowClassifier class.''' | ||
Line 332: | Line 332: | ||
The created '''object '''returns a''' pointer''' to the '''flow classifier.''' | The created '''object '''returns a''' pointer''' to the '''flow classifier.''' | ||
− | |- | + | |- |
|| Highlight '''std::map<FlowId,FlowMonitor::FlowStats> stats=flowMonitor->GetFlowStats();''' | || Highlight '''std::map<FlowId,FlowMonitor::FlowStats> stats=flowMonitor->GetFlowStats();''' | ||
− | || To store the information about the '''network flow | + | || To store the information about the '''network flow''', let us use this command. |
− | |- | + | |- |
|| Highlight the '''entire for loop.''' | || Highlight the '''entire for loop.''' | ||
− | || Let’s retrieve the details of the flow using a '''for loop | + | || Let’s retrieve the details of the flow using a '''for loop'''. |
'''iter arrow first '''is used to collect the '''ID''' of the '''flow.''' | '''iter arrow first '''is used to collect the '''ID''' of the '''flow.''' | ||
Line 345: | Line 345: | ||
We will analyze the '''type of flow''' and '''print''' the''' delay''' and '''throughput'''. | We will analyze the '''type of flow''' and '''print''' the''' delay''' and '''throughput'''. | ||
− | |- | + | |- |
|| Highlight '''Simulator::Destroy()''' | || Highlight '''Simulator::Destroy()''' | ||
− | || The '''Destroy() '''function ends the simulation. | + | || The '''Destroy() ''' function ends the simulation. |
− | |- | + | |- |
|| Press '''Ctrl, Alt '''and '''T keys''' simultaneously | || Press '''Ctrl, Alt '''and '''T keys''' simultaneously | ||
Line 357: | Line 357: | ||
|| Now we will observe the simulation. | || Now we will observe the simulation. | ||
− | Open the terminal by pressing '''Ctrl, Alt''' and '''T keys''' simultaneously. | + | Open the terminal by pressing '''Ctrl''', '''Alt''' and '''T keys''' simultaneously. |
Using the '''cd '''command, navigate to the installation directory of '''ns-3'''. | Using the '''cd '''command, navigate to the installation directory of '''ns-3'''. | ||
Line 363: | Line 363: | ||
Go to the '''ns-3.38''' directory. | Go to the '''ns-3.38''' directory. | ||
− | Move your '''source file''' to the '''scratch '''directory within the '''ns-3.38''' '''directory'''. | + | Move your '''source file''' to the '''scratch ''' directory within the '''ns-3.38''' '''directory'''. |
− | |- | + | |- |
|| Type ./'''ns3 run scratch/wifi-simple-infra.cc''' | || Type ./'''ns3 run scratch/wifi-simple-infra.cc''' | ||
− | || Run the command ./'''ns3 run scratch/wifi-simple-infra.cc ''' | + | || Run the command ./'''ns3 space run space scratch/wifi-simple-infra.cc ''' |
'''wifi-simple-infra.cc '''is the name of the source file. | '''wifi-simple-infra.cc '''is the name of the source file. | ||
− | |- | + | |- |
|| Keep the terminal open and show the output of the command | || Keep the terminal open and show the output of the command | ||
|| After compilation, we get the details of each '''packet transfer'''. | || After compilation, we get the details of each '''packet transfer'''. | ||
Line 377: | Line 377: | ||
We also see the '''average end to end delay''' and '''throughput''' of the '''wireless network'''. | We also see the '''average end to end delay''' and '''throughput''' of the '''wireless network'''. | ||
− | |- | + | |- |
|| Navigate to '''netanim '''directory under '''ns-allinone-3.38''' | || Navigate to '''netanim '''directory under '''ns-allinone-3.38''' | ||
Line 390: | Line 390: | ||
Then type '''cd netanim''' | Then type '''cd netanim''' | ||
− | |- | + | |- |
|| Type ./'''NetAnim''' | || Type ./'''NetAnim''' | ||
|| Now type '''./NetAnim. ''' | || Now type '''./NetAnim. ''' | ||
The '''NetAnim''' window should open. | The '''NetAnim''' window should open. | ||
− | |- | + | |- |
|| Click on the Open''' XML trace file '''icon on the top left corner of the window. | || Click on the Open''' XML trace file '''icon on the top left corner of the window. | ||
|| Click on the Open''' XML trace file '''icon on the top left corner of the window. | || Click on the Open''' XML trace file '''icon on the top left corner of the window. | ||
− | |- | + | |- |
|| In the file picker, navigate to the '''ns-allinone-3.38/ns3.38 '''directory and select the '''animationwifi-infra-2.xml '''file. | || In the file picker, navigate to the '''ns-allinone-3.38/ns3.38 '''directory and select the '''animationwifi-infra-2.xml '''file. | ||
− | || In the file picker, '''navigate''' to the '''ns-allinone-3.38, '''then to''' ns3.38 '''directory. | + | || In the '''file picker''', '''navigate''' to the '''ns-allinone-3.38, '''then to''' ns3.38 '''directory. |
Then select the''' animationwifi-infra-2.xml '''file. | Then select the''' animationwifi-infra-2.xml '''file. | ||
− | |- | + | |- |
|| On the toolbar, click on the '''play button''' | || On the toolbar, click on the '''play button''' | ||
Line 411: | Line 411: | ||
We see the '''flow details''' of the''' wireless network.''' | We see the '''flow details''' of the''' wireless network.''' | ||
− | + | ||
− | |- | + | |- |
|| Show Slide: '''Summary''' | || Show Slide: '''Summary''' | ||
− | || | + | || This brings us to the end of this tutorial. Let us summarize. |
− | + | In this tutorial, we have | |
− | * | + | * Created an '''infrastructure''' based '''wireless network'''. |
− | * | + | * Created three '''UDP flows''' in the channels. |
− | * | + | * Analyzed the flow using a '''flow monitor'''. |
− | * | + | * Visualized the network using '''NetAnim'''. |
− | |- | + | |- |
|| Show Slide : '''Assignment''' | || Show Slide : '''Assignment''' | ||
|| As an assignment, please do the following | || As an assignment, please do the following | ||
− | * | + | * Create a '''simulation''' for a ''' wireless network''' with three '''nodes'''. |
− | * | + | * Create one ''' access point (AP)''' and two '''stations'''. |
− | * | + | * The '''AP '''and '''stations''' should use an '''802.11g physical layer'''. |
− | * | + | * Implement''' UDP traffic''' between the''' stations''' and the '''AP'''. |
− | * | + | * Set '''packet size''' as '''1500 bytes''' and send '''200 packets''' from each '''station''' to the''' AP.''' |
− | * | + | * Set the''' RSS''' at the '''AP''' to''' -70 dBm'''. |
− | * | + | * Set the''' interval''' between '''packets''' to '''0.005 seconds.''' |
− | * | + | * Analyze the '''flow''' using '''flow monitor'''. |
− | * | + | * '''Visualize''' the '''network''' using '''NetAnim'''. |
− | |- | + | |- |
|| Show Slide: | || Show Slide: | ||
Line 443: | Line 443: | ||
|| In the terminal window, you will get the following output. | || In the terminal window, you will get the following output. | ||
− | |- | + | |- |
|| Show Slide: | || Show Slide: | ||
'''Assignment- Observation''' | '''Assignment- Observation''' | ||
− | || In the NetAnim window, you would observe the following network. | + | || In the '''NetAnim''' window, you would observe the following network. |
Observe the packet transfer. | Observe the packet transfer. | ||
− | |- | + | |- |
− | || | + | || Show Slide: |
− | + | '''About Spoken Tutorial Project''' | |
− | || | + | || The video at the following link summarizes the'''Spoken Tutorial project'''. |
− | + | Please download and watch it. | |
− | |- | + | |- |
− | || | + | || Show Slide: |
− | + | '''Spoken Tutorial Workshops''' | |
− | || | + | || The'''Spoken Tutorial Project''' team conducts workshops and gives certificates. |
− | + | For more details, please write to us. | |
− | |- | + | |- |
− | || | + | || Show Slide: |
− | + | '''Answers for THIS Spoken Tutorial''' | |
− | | | + | || Please post your timed queries in this forum. |
− | |- | + | |- |
− | || | + | || Show Slide: |
− | + | '''FOSSEE Forum''' | |
− | || | + | || For any general or technical questions on'''ns-3''', visit the''' FOSSEE forum''' and post your question. |
− | |- | + | |- |
− | || | + | || Show Slide:'''Acknowledgement''' |
− | || | + | || '''Spoken Tutorial''' Project was established by the'''Ministry of Education, Government of India'''. |
− | |- | + | |- |
|| Show Slide: '''Acknowledgement''' | || Show Slide: '''Acknowledgement''' | ||
− | || | + | || We thank'''Dr.Moyukh Laha''' from'''IIT Kharagpur''' for his domain support. |
+ | |||
+ | We would also like to thank'''Dr. R. Radha, Dr. X. Anita, and Dr.T.Subbulakshmi '''from''' VIT, Chennai '''for their support. | ||
+ | |- | ||
+ | || Show Slide: Thank you | ||
− | |||
− | |||
− | |||
− | + | || This is'''Arun Santhosh''',a FOSSEE Summer Fellow 2023, IIT Bombay signing off. | |
− | || | + | Thank you for joining. |
− | + | ||
|- | |- | ||
|} | |} |
Latest revision as of 12:27, 12 April 2024
Visual Cue | Narration |
Show Slide: Title Slide | Welcome to Spoken tutorial on Infrastructure based wireless network. |
Show Slide:
Learning Objectives |
In this tutorial, we will learn to
|
Show Slide:
System Requirements |
To record this tutorial, I am using
|
Show slide:
Pre-requisites |
To follow this tutorial:
|
Show Slide:
Code Files |
|
Show Slide:
Infrastructure based Wifi network |
For this tutorial, we would be creating the below infrastructure.
In this diagram, the nodes 0, 2 and 3 are station nodes. Node 1 is the access point of the infrastructure. |
Now, let us learn about DSSS. | |
Show Slide:
About DSSS |
DSSS rate is data rate in a Wifi system.
It uses Direct Sequence Spread Spectrum modulation. In a DSSS system, data is spread over a wider bandwidth using a spreading code. |
Show Slide:
About DSSS |
The spreading code is a sequence of chips that modulates the data signal.
DSSS rate represents the speed of information transmitted after spreading. DSSS can transfer up to 11 Mbps of data. |
Open code editor | I have created the source file wifi-simple-infra.cc for this program.
The source code contains the required functions to create an infrastructure based wireless network. Now we will go through the source code in the text editor. |
Highlight std::string phyMode("DsssRate1Mbps"); | We set the dsss rate of the physical layer to 1 Mbps. |
Highlight double rss = -80 | Next, we will set the Received Signal Strength or RSS to -80 dBm. |
Highlight uint32_t packetSize = 1000;
uint32_t numPackets = 100; |
Now we shall set the packet size to 1000 bytes.
Then we will set the number of packets to be transmitted as 100. |
Highlight Time interval = Seconds(0.003); | Further, we set the time interval between the packet transfer as 0.003 seconds. |
Highlight uint32_t sinkNode = 1;
uint32_t sourceNode = 0; |
Let us set up the source and sink nodes for the flow that we are yet to create. |
Highlight Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue(phyMode)); | Then we configure non-unicast mode of the wifi channel.
Non-unicast mode means that the data may be sent from one node to many nodes. |
Highlight NodeContainer c;
c.Create(4); |
Now, let us create a node container with four nodes. |
Highlight WifiHelper wifi;
if (verbose) { WifiHelper::EnableLogComponents(); } wifi.SetStandard(WIFI_STANDARD_80211b); |
We shall now put the wifi network interface cards together.
For that, let us use the WifiHelper class. Using Wifi-helper class, we enable logging components and set the wifi standard. Here, the standard set is IEEE 802.11b. |
Highlight YansWifiPhyHelper wifiPhy;
wifiPhy.Set("RxGain", DoubleValue(0)); |
Then we shall use YansWifiPhyHelper class to set the RxGain attribute to zero.
RxGain is used to adjust the sensitivity of the receiving signal. |
Highlight YaifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel"); wifiChannel.AddPropagationLoss("ns3::FixedRssLossModel", "Rss", DoubleValue(rss)); |
We use YansWifiChannelHelper class to set attributes of the transmitting channel.
Let us set the Propagation delay and add the propagation loss to our model. |
Highlight wifiPhy.SetChannel(wifiChannel.Create()); | Next, we connect the wifi physical layer to the wifi-channel. |
Highlight WifiMacHelper wifiMac;
wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager","DataMode", StringValue(phyMode), "ControlMode", StringValue(phyMode)); |
Now let us add MAC protocol to the Network Interface Cards that we installed.
Then we set a constant rate for data and control modes of wifi stations. |
Highlight Ssid ssid = Ssid("wifi-default"); | Then, we assign SSID to the network.
SSID or Service Set Identifier is a sequence of characters uniquely identifying a network. |
Highlight wifiMac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));
NetDeviceContainer staDevice = wifi.Install(wifiPhy, wifiMac, c); NetDeviceContainer devices = staDevice; |
Let us now set up the station node by setting up MAC protocol and installing NIC.
We create a container staDevice to hold the installed Wifi devices. As a next step, we shall take a copy of staDevice container in devices container. |
Highlight
wifiMac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid)); NetDeviceContainer apDevice = wifi.Install(wifiPhy, wifiMac, c.Get(1)); devices.Add(apDevice); |
Similarly, we shall set up the Access Point of the wireless network.
We have set up the AP node of the wireless network using ApWifiMac protocol. We are also installing wifiphy to the node1 of the wireless network. Then ssid is assigned to the AP node of the network. |
Highlight MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>(); positionAlloc->Add(Vector(3.0, 4.0, 3.0)); mobility.SetPositionAllocator(positionAlloc); |
Now set up mobility for the nodes by allocating positions for the nodes created. |
Highlight mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
mobility.Install(c); |
Let us set the model to be ConstantPositionMobilityModel.
It represents the 'stationary or static nodes in a network simulation. Also, install the model that we set, to all the nodes that we created. |
Highlight InternetStackHelper internet;
internet.Install(c); |
Then let us install the internet stack on all the nodes. |
Highlight Ipv4AddressHelper ipv4;
ipv4.SetBase("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer i = ipv4.Assign(devices); |
Now, we shall assign IP addresses to the nodes that we created |
Highlight TypeId tid = TypeId::LookupByName("ns3::UdpSocketFactory"); | The highlighted command is used to get the TypeId of UdpSocketFactory. |
Highlight Ptr<Socket> recvSink = Socket::CreateSocket(c.Get(sinkNode), tid); | We shall create a receiving socket for the UDP Flow. |
Highlight InetSocketAddress local = InetSocketAddress(Ipv4Address::GetAny(), 80); | Let us create an internet socket address using any IPv4 address and port 80. |
Highlight recvSink->Bind(local); | Then bind the receiving socket to the local address and to the port 80. |
Highlight recvSink->SetRecvCallback(MakeCallback(&ReceivePacket)); | Now set the receive callback function for the receiving socket.
When the packet is received in the sinknode, we call RecievePacket function. |
Highlight Ptr<Socket> source = Socket::CreateSocket(c.Get(sourceNode), tid); | Let us then create an UDP socket on node 0, which is our sourceNode. |
Highlight InetSocketAddress remote = InetSocketAddress(i.GetAddress(sinkNode, 0), 80); | We shall create an internet socket using Ipv4 address of sinknode and port 80. |
Highlight source->Connect(remote); | Let us connect the source socket to the remote address and port 80. |
Highlight void
ReceivePacket(Ptr<Socket> socket) { while (socket->Recv()){ } } |
Now let’s define the function to call when the packets are received.
Here, we are invoking the receive functionality of the socket. |
Highlight static void
GenerateTraffic(Ptr<Socket> socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval) |
Then we define a function called generate packet traffic. |
Highlight if (pktCount > 0)
{ socket->Send(Create<Packet>(pktSize)); Simulator::Schedule(pktInterval, &GenerateTraffic, socket, pktSize, pktCount - 1, pktInterval); } else { socket->Close(); } |
When the number of packets is not zero, we invoke the send function.
We also schedule the simulator to invoke the GenerateTraffic function. When the number of packets is zero, we close the socket. Then, we stop invoking send function. |
Only Narration | We have created two other UDP flows as well. |
Highlight Simulator::Schedule(Seconds(
10),&GenerateTraffic,source,packetSize,numPackets,interval); |
Let us schedule the simulator to callback the generate_traffic function.
This procedure happens after ten seconds from the start of execution. |
Highlight Ptr<FlowMonitor> flowMonitor; | Then, Initialize flow monitor for tracing. |
HIghlight FlowMonitorHelper flowHelper;
flowMonitor= flowHelper.InstallAll(); |
We shall then install a flow monitor on all the nodes. |
Highlight AnimationInterface anim ("animationwifi-infra-2.xml"); | Let us create the XML output of the program. |
HIghlight Ptr<Ipv4FlowClassifier> classifier=DynamicCast<Ipv4FlowClassifier> (flowHelper.GetClassifier()); | Let us further create an object of the Ipv4FlowClassifier class.
The created object returns a pointer to the flow classifier. |
Highlight std::map<FlowId,FlowMonitor::FlowStats> stats=flowMonitor->GetFlowStats(); | To store the information about the network flow, let us use this command. |
Highlight the entire for loop. | Let’s retrieve the details of the flow using a for loop.
iter arrow first is used to collect the ID of the flow. iter arrow second is used to collect the data associated with the flow. We will analyze the type of flow and print the delay and throughput. |
Highlight Simulator::Destroy() | The Destroy() function ends the simulation. |
Press Ctrl, Alt and T keys simultaneously
Navigate to the ns-allinone-3.38/ns3.38 directory Type mv ~/Downloads/wifi-simple-infra.cc scratch/wifi-simple-infra.cc to move the source file to scratch directory. |
Now we will observe the simulation.
Open the terminal by pressing Ctrl, Alt and T keys simultaneously. Using the cd command, navigate to the installation directory of ns-3. Go to the ns-3.38 directory. Move your source file to the scratch directory within the ns-3.38 directory. |
Type ./ns3 run scratch/wifi-simple-infra.cc | Run the command ./ns3 space run space scratch/wifi-simple-infra.cc
wifi-simple-infra.cc is the name of the source file. |
Keep the terminal open and show the output of the command | After compilation, we get the details of each packet transfer.
TxPackets refers to the packets sent whereas RxPackets refers to the packets received. We also see the average end to end delay and throughput of the wireless network. |
Navigate to netanim directory under ns-allinone-3.38
Type cd .. Type cd netanim |
Now, to visualize the network, we will use NetAnim.
Navigate to the netanim directory under ns-allinone-3.38. For that, type cd .. in the terminal window. Then type cd netanim |
Type ./NetAnim | Now type ./NetAnim.
The NetAnim window should open. |
Click on the Open XML trace file icon on the top left corner of the window. | Click on the Open XML trace file icon on the top left corner of the window. |
In the file picker, navigate to the ns-allinone-3.38/ns3.38 directory and select the animationwifi-infra-2.xml file. | In the file picker, navigate to the ns-allinone-3.38, then to ns3.38 directory.
Then select the animationwifi-infra-2.xml file. |
On the toolbar, click on the play button
Close the NetAnim window |
On the toolbar, click on the play button to view the simulation.
We see the flow details of the wireless network.
|
Show Slide: Summary | This brings us to the end of this tutorial. Let us summarize.
In this tutorial, we have
|
Show Slide : Assignment | As an assignment, please do the following
|
Show Slide:
Assignment- Observation |
In the terminal window, you will get the following output. |
Show Slide:
Assignment- Observation |
In the NetAnim window, you would observe the following network.
Observe the packet transfer. |
Show Slide:
About Spoken Tutorial Project |
The video at the following link summarizes theSpoken Tutorial project.
Please download and watch it. |
Show Slide:
Spoken Tutorial Workshops |
TheSpoken Tutorial Project team conducts workshops and gives certificates.
For more details, please write to us. |
Show Slide:
Answers for THIS Spoken Tutorial |
Please post your timed queries in this forum. |
Show Slide:
FOSSEE Forum |
For any general or technical questions onns-3, visit the FOSSEE forum and post your question. |
Show Slide:Acknowledgement | Spoken Tutorial Project was established by theMinistry of Education, Government of India. |
Show Slide: Acknowledgement | We thankDr.Moyukh Laha fromIIT Kharagpur for his domain support.
We would also like to thankDr. R. Radha, Dr. X. Anita, and Dr.T.Subbulakshmi from VIT, Chennai for their support. |
Show Slide: Thank you
|
This isArun Santhosh,a FOSSEE Summer Fellow 2023, IIT Bombay signing off.
Thank you for joining. |