/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2007,2008, 2009 INRIA, UDcast * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation; * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Author: Mohamed Amine Ismail * */ // // Default network topology includes a base station (BS) and 2 // subscriber station (SS). // +-----+ // | SS0 | // +-----+ // 10.1.1.1 // ------- // ((*)) // // 10.1.1.7 // +------------+ // |Base Station| ==((*)) // +------------+ // // ((*)) // ------- // 10.1.1.2 // +-----+ // | SS1 | // +-----+ // July 5: Modified for N users (SS) send to base station (BS). No Downlink yet. // #include "ns3/core-module.h" #include "ns3/network-module.h" #include "ns3/applications-module.h" #include "ns3/mobility-module.h" #include "ns3/config-store-module.h" #include "ns3/point-to-point-module.h" #include "ns3/wimax-module.h" #include "ns3/internet-module.h" #include "ns3/global-route-manager.h" #include "ns3/ipcs-classifier-record.h" #include "assert.h" #include "ns3/service-flow.h" #include #define MAX_USERS 1000 NS_LOG_COMPONENT_DEFINE ("WimaxSimpleExample"); using namespace ns3; //uplink udp: UdpServerHelper udpServerUL[MAX_USERS]; ApplicationContainer serverAppsUL[MAX_USERS]; UdpClientHelper udpClientUL[MAX_USERS]; ApplicationContainer clientAppsUL[MAX_USERS]; IpcsClassifierRecord UlClassifierUgs[MAX_USERS]; ServiceFlow UlServiceFlowUgs[MAX_USERS]; //downlink udp: UdpServerHelper udpServerDL[MAX_USERS]; ApplicationContainer serverAppsDL[MAX_USERS]; UdpClientHelper udpClientDL[MAX_USERS]; ApplicationContainer clientAppsDL[MAX_USERS]; IpcsClassifierRecord DlClassifierUgs[MAX_USERS]; ServiceFlow DlServiceFlowUgs[MAX_USERS]; void NodeConfigurationCommonSetupUDP(WimaxHelper &wimax, int numUsers, InternetStackHelper &stack, Ipv4AddressHelper &address, WimaxHelper::SchedulerType scheduler, /*inputs*/ NodeContainer &ssNodes, Ptr *ss, Ipv4InterfaceContainer &SSinterfaces /*outputs*/) { } void NodeConfigurationCommonSetupTCP(WimaxHelper &wimax, int numUsers, int &created_nodes, InternetStackHelper &stack, Ipv4AddressHelper &address, WimaxHelper::SchedulerType scheduler, NetDeviceContainer bsDevs, NodeContainer bsNodes, /*inputs*/ NodeContainer &ssNodes, Ptr ss[], std::vector &interfaceAdjacencyList) //Ipv4InterfaceContainer &SSinterfaces /*outputs*/) { ssNodes.Create (numUsers); NetDeviceContainer ssDevs = wimax.Install (ssNodes,WimaxHelper::DEVICE_TYPE_SUBSCRIBER_STATION,WimaxHelper::SIMPLE_PHY_TYPE_OFDM,scheduler); stack.Install (ssNodes); std::vector MonnodeAdjacencyList (numUsers); for(uint32_t i=0; i MondeviceAdjacencyList (numUsers); for(uint32_t i=0; i* ss = new Ptr[numUsers]; // MondeviceAdjacencyList[i].Add(dev); MondeviceAdjacencyList[i] = p2p.Install (MonnodeAdjacencyList[i]); ss[i] =ssDevs.Get (i)->GetObject (); //dev.Get(0)-> if (ss[i] == NULL) NS_LOG_UNCOND("ss[i] is null."); ss[i]->SetModulationType (WimaxPhy::MODULATION_TYPE_QAM16_12); } // Later, we add IP addresses. NS_LOG_UNCOND ("Assigning a subnet IP Address for TCP nodes " << created_nodes << " to " << created_nodes+numUsers-1 << "..."); Ipv4AddressHelper ipv4; for( uint32_t i=0; i ss[]) { int port1 = port; for (int i = 0; i < numUsers; i++) { port = port+10; udpServerUL[i] = UdpServerHelper (port); serverAppsUL[i] = udpServerUL[i].Install (bsNodes.Get (0)); serverAppsUL[i].Start (Seconds (0)); serverAppsUL[i].Stop (Seconds (duration)); udpClientUL[i] = UdpClientHelper (BSinterface.GetAddress (0), port); udpClientUL[i].SetAttribute ("MaxPackets", UintegerValue (1200)); udpClientUL[i].SetAttribute ("Interval", TimeValue (Seconds (2)));//0.01 udpClientUL[i].SetAttribute("FlowId", UintegerValue(2)); udpClientUL[i].SetAttribute ("PacketSize", UintegerValue (128)); clientAppsUL[i] = udpClientUL[i].Install (ssNodes.Get(i)); clientAppsUL[i].Start (Seconds (1.5)); clientAppsUL[i].Stop (Seconds (duration)); } //classifier for (int i = 0; i < numUsers; i++) { UlClassifierUgs[i] = IpcsClassifierRecord (SSinterfaces.GetAddress (i), Ipv4Mask ("255.255.255.255"), Ipv4Address ("0.0.0.0"), Ipv4Mask ("0.0.0.0"), 0, 65000, port1+10*i, port1+10*i, 17, 1); UlServiceFlowUgs[i] = wimax.CreateServiceFlow (ServiceFlow::SF_DIRECTION_UP, ServiceFlow::SF_TYPE_UGS, UlClassifierUgs[i]); ss[i]->AddServiceFlow (UlServiceFlowUgs[i]); } return port; } int Downlink_UDP_Traffic(WimaxHelper &wimax, int port,int numUsers,int duration, Ipv4InterfaceContainer SSinterfaces, NodeContainer bsNodes, NodeContainer ssNodes , Ptr ss[]) { int port1 = port; for (int i = 0; i < numUsers; i++) { port=port+10; //create applications whose servers are on ssNodes udpServerDL[i] = UdpServerHelper (port); serverAppsDL[i] = udpServerDL[i].Install(ssNodes.Get(i)); serverAppsDL[i].Start (Seconds (0)); serverAppsDL[i].Stop (Seconds (duration)); //create clients on BS for each application udpClientDL[i] = UdpClientHelper (SSinterfaces.GetAddress (i), port); udpClientDL[i].SetAttribute ("MaxPackets", UintegerValue (1200)); udpClientDL[i].SetAttribute ("Interval", TimeValue (Seconds (2)));//0.01 udpClientDL[i].SetAttribute("FlowId", UintegerValue(6)); udpClientDL[i].SetAttribute ("PacketSize", UintegerValue (128)); clientAppsDL[i] = udpClientDL[i].Install (bsNodes.Get(0)); clientAppsDL[i].Start (Seconds (1.5)); clientAppsDL[i].Stop (Seconds (duration)); } //classifier for (int i = 0; i < numUsers; i++) { DlClassifierUgs[i] = IpcsClassifierRecord (Ipv4Address ("0.0.0.0"), Ipv4Mask ("0.0.0.0"), SSinterfaces.GetAddress (i), Ipv4Mask ("255.255.255.255"), 0, 65000, port1+10*i, port1+10*i, 17, 1); DlServiceFlowUgs[i] = wimax.CreateServiceFlow (ServiceFlow::SF_DIRECTION_DOWN, ServiceFlow::SF_TYPE_UGS, DlClassifierUgs[i]); ss[i]->AddServiceFlow (DlServiceFlowUgs[i]); } return port; } int main (int argc, char *argv[]) { bool verbose = false; int duration = 7, numUDPUsers=1, enableUplink = false, enableDownlink=false, port=100, sched=4; WimaxHelper::SchedulerType scheduler = WimaxHelper::SCHED_TYPE_SIMPLE; CommandLine cmd; cmd.AddValue ("duration", "duration of the simulation in seconds", duration); cmd.AddValue ("verbose", "turn on all WimaxNetDevice log components", verbose); cmd.AddValue ("NUDP", "Number of UDP.", numUDPUsers); cmd.AddValue ("DL", "Enable DL transmission?",enableDownlink); cmd.AddValue ("UL", "Enable UL transmission?",enableUplink); cmd.AddValue ("sched","Scheduling Type.",sched); cmd.Parse (argc, argv); ServiceFlow::SchedulingType st; switch (sched){ case 6: st = ServiceFlow::SF_TYPE_UGS; break; case 4:default: st = ServiceFlow::SF_TYPE_RTPS; break; } // enum SchedulingType // { // SF_TYPE_NONE = 0, SF_TYPE_UNDEF = 1, SF_TYPE_BE = 2, SF_TYPE_NRTPS = 3, // SF_TYPE_RTPS = 4, SF_TYPE_UGS = 6, SF_TYPE_ALL = 255 // }; // se NodeContainer bsNodes; bsNodes.Create (1); WimaxHelper wimax; NetDeviceContainer bsDevs; bsDevs = wimax.Install (bsNodes, WimaxHelper::DEVICE_TYPE_BASE_STATION, WimaxHelper::SIMPLE_PHY_TYPE_OFDM, scheduler); Ptr bs; bs = bsDevs.Get (0)->GetObject (); InternetStackHelper stack; stack.Install (bsNodes); Ipv4AddressHelper address; address.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer BSinterface = address.Assign (bsDevs); if (verbose) { wimax.EnableLogComponents (); // Turn on all wimax logging } /*COMMON*/ NS_LOG_UNCOND("Common UDP Setup."); NodeContainer ssNodesUDP; Ptr ssUDP[numUDPUsers]; Ipv4InterfaceContainer SSinterfacesUDP; /*------------------------------*/ //For each application, we need to create common variables here (common part between UL and DL of each application): //ssNodes = new NodeContainer; ssNodesUDP.Create (numUDPUsers); NetDeviceContainer ssDevs; ssDevs = wimax.Install (ssNodesUDP, WimaxHelper::DEVICE_TYPE_SUBSCRIBER_STATION, WimaxHelper::SIMPLE_PHY_TYPE_OFDM, scheduler); stack.Install (ssNodesUDP); SSinterfacesUDP = address.Assign (ssDevs); for (int i = 0; i < numUDPUsers; i++) { ssUDP[i] = ssDevs.Get (i)->GetObject (); ssUDP[i]->SetModulationType (WimaxPhy::MODULATION_TYPE_QAM16_12); } //NS_LOG_UNCOND("UL="<AddServiceFlow (UlServiceFlowUgs[i]); } } if (enableDownlink) { NS_LOG_UNCOND("UDP DL."); int port1 = port; for (int i = 0; i < numUDPUsers; i++) { port=port+10; //create applications whose servers are on ssNodes udpServerDL[i] = UdpServerHelper (port); serverAppsDL[i] = udpServerDL[i].Install(ssNodesUDP.Get(i)); serverAppsDL[i].Start (Seconds (0)); serverAppsDL[i].Stop (Seconds (duration)); //create clients on BS for each application udpClientDL[i] = UdpClientHelper (SSinterfacesUDP.GetAddress (i), port); udpClientDL[i].SetAttribute ("MaxPackets", UintegerValue (1200)); udpClientDL[i].SetAttribute ("Interval", TimeValue (Seconds (2)));//0.01 udpClientDL[i].SetAttribute("FlowId", UintegerValue(6)); udpClientDL[i].SetAttribute ("PacketSize", UintegerValue (128)); clientAppsDL[i] = udpClientDL[i].Install (bsNodes.Get(0)); clientAppsDL[i].Start (Seconds (1.5)); clientAppsDL[i].Stop (Seconds (duration)); } //DL classifier for (int i = 0; i < numUDPUsers; i++) { DlClassifierUgs[i] = IpcsClassifierRecord (Ipv4Address ("0.0.0.0"), Ipv4Mask ("0.0.0.0"), SSinterfacesUDP.GetAddress (i), Ipv4Mask ("255.255.255.255"), 0, 65000, port1+10*i, port1+10*i, 17, 1); DlServiceFlowUgs[i] = wimax.CreateServiceFlow (ServiceFlow::SF_DIRECTION_DOWN, st, DlClassifierUgs[i]); ssUDP[i]->AddServiceFlow (DlServiceFlowUgs[i]); } //return port; } //run Simulator::Stop (Seconds (duration + 0.1)); NS_LOG_UNCOND ("Starting simulation ... "); Simulator::Run (); return 0; }