A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
wimax-simple.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007,2008, 2009 INRIA, UDcast
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
19  * <amine.ismail@udcast.com>
20  */
21 
22 //
23 // Default network topology includes a base station (BS) and 2
24 // subscriber station (SS).
25 
26 // +-----+
27 // | SS0 |
28 // +-----+
29 // 10.1.1.1
30 // -------
31 // ((*))
32 //
33 // 10.1.1.7
34 // +------------+
35 // |Base Station| ==((*))
36 // +------------+
37 //
38 // ((*))
39 // -------
40 // 10.1.1.2
41 // +-----+
42 // | SS1 |
43 // +-----+
44 
45 #include "ns3/core-module.h"
46 #include "ns3/network-module.h"
47 #include "ns3/applications-module.h"
48 #include "ns3/mobility-module.h"
49 #include "ns3/config-store-module.h"
50 #include "ns3/wimax-module.h"
51 #include "ns3/internet-module.h"
52 #include "ns3/global-route-manager.h"
53 #include "ns3/ipcs-classifier-record.h"
54 #include "ns3/service-flow.h"
55 #include <iostream>
56 
57 NS_LOG_COMPONENT_DEFINE ("WimaxSimpleExample");
58 
59 using namespace ns3;
60 
61 int main (int argc, char *argv[])
62 {
63  bool verbose = false;
64 
65  int duration = 7, schedType = 0;
67 
68  CommandLine cmd;
69  cmd.AddValue ("scheduler", "type of scheduler to use with the network devices", schedType);
70  cmd.AddValue ("duration", "duration of the simulation in seconds", duration);
71  cmd.AddValue ("verbose", "turn on all WimaxNetDevice log components", verbose);
72  cmd.Parse (argc, argv);
73  LogComponentEnable ("UdpClient", LOG_LEVEL_INFO);
74  LogComponentEnable ("UdpServer", LOG_LEVEL_INFO);
75  switch (schedType)
76  {
77  case 0:
79  break;
80  case 1:
82  break;
83  case 2:
84  scheduler = WimaxHelper::SCHED_TYPE_RTPS;
85  break;
86  default:
88  }
89 
90  NodeContainer ssNodes;
91  NodeContainer bsNodes;
92 
93  ssNodes.Create (2);
94  bsNodes.Create (1);
95 
96  WimaxHelper wimax;
97 
98  NetDeviceContainer ssDevs, bsDevs;
99 
100  ssDevs = wimax.Install (ssNodes,
103  scheduler);
105 
106  wimax.EnableAscii ("bs-devices", bsDevs);
107  wimax.EnableAscii ("ss-devices", ssDevs);
108 
110 
111  for (int i = 0; i < 2; i++)
112  {
113  ss[i] = ssDevs.Get (i)->GetObject<SubscriberStationNetDevice> ();
115  }
116 
118 
119  bs = bsDevs.Get (0)->GetObject<BaseStationNetDevice> ();
120 
121  InternetStackHelper stack;
122  stack.Install (bsNodes);
123  stack.Install (ssNodes);
124 
125  Ipv4AddressHelper address;
126  address.SetBase ("10.1.1.0", "255.255.255.0");
127 
128  Ipv4InterfaceContainer SSinterfaces = address.Assign (ssDevs);
129  Ipv4InterfaceContainer BSinterface = address.Assign (bsDevs);
130 
131  if (verbose)
132  {
133  wimax.EnableLogComponents (); // Turn on all wimax logging
134  }
135  /*------------------------------*/
136  UdpServerHelper udpServer;
137  ApplicationContainer serverApps;
138  UdpClientHelper udpClient;
139  ApplicationContainer clientApps;
140 
141  udpServer = UdpServerHelper (100);
142 
143  serverApps = udpServer.Install (ssNodes.Get (0));
144  serverApps.Start (Seconds (6));
145  serverApps.Stop (Seconds (duration));
146 
147  udpClient = UdpClientHelper (SSinterfaces.GetAddress (0), 100);
148  udpClient.SetAttribute ("MaxPackets", UintegerValue (1200));
149  udpClient.SetAttribute ("Interval", TimeValue (Seconds (0.5)));
150  udpClient.SetAttribute ("PacketSize", UintegerValue (1024));
151 
152  clientApps = udpClient.Install (ssNodes.Get (1));
153  clientApps.Start (Seconds (6));
154  clientApps.Stop (Seconds (duration));
155 
156  Simulator::Stop (Seconds (duration + 0.1));
157 
158  wimax.EnablePcap ("wimax-simple-ss0", ssNodes.Get (0)->GetId (), ss[0]->GetIfIndex ());
159  wimax.EnablePcap ("wimax-simple-ss1", ssNodes.Get (1)->GetId (), ss[1]->GetIfIndex ());
160  wimax.EnablePcap ("wimax-simple-bs0", bsNodes.Get (0)->GetId (), bs->GetIfIndex ());
161 
162  IpcsClassifierRecord DlClassifierUgs (Ipv4Address ("0.0.0.0"),
163  Ipv4Mask ("0.0.0.0"),
164  SSinterfaces.GetAddress (0),
165  Ipv4Mask ("255.255.255.255"),
166  0,
167  65000,
168  100,
169  100,
170  17,
171  1);
174  DlClassifierUgs);
175 
176  IpcsClassifierRecord UlClassifierUgs (SSinterfaces.GetAddress (1),
177  Ipv4Mask ("255.255.255.255"),
178  Ipv4Address ("0.0.0.0"),
179  Ipv4Mask ("0.0.0.0"),
180  0,
181  65000,
182  100,
183  100,
184  17,
185  1);
188  UlClassifierUgs);
189  ss[0]->AddServiceFlow (DlServiceFlowUgs);
190  ss[1]->AddServiceFlow (UlServiceFlowUgs);
191 
192  NS_LOG_INFO ("Starting simulation.....");
193  Simulator::Run ();
194 
195  ss[0] = 0;
196  ss[1] = 0;
197  bs = 0;
198 
200  NS_LOG_INFO ("Done.");
201 
202  return 0;
203 }