A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
wimax-ipv4.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 some number of
24 // subscriber station (SS) specified by the variable nbSS (defaults to six).
25 // The SSs are grouped into two groups: senders and receivers. SSs from 0 to
26 // nbSS/2 are designed as senders and SSs from (nbSS/2 + 1) to nbSS-1 will
27 // designed as receivers.
28 // Each SS creates 3 transport connection with the BS. the fist one has as QoS
29 // scheduling type UGS, the second one rtPS and the third one BE.
30 // Senders SSs send some stamped IP packets with variable bitrate to receiver SSs
31 // through the BS station. receiver SSs receive the IP packets analyze them and
32 // based on a sequnece number decide if all the packets are coorectly received
33 
34 // +-----+ +-----+ +-----+
35 // | SS0 | | SS1 | | SS2 |
36 // +-----+ +-----+ +-----+
37 // 10.1.1.1 10.1.1.2 10.1.1.3
38 // -------- -------- -------
39 // ((*)) ((*)) ((*))
40 //
41 // 10.1.1.7
42 // +------------+
43 // |Base Station| ==((*))
44 // +------------+
45 //
46 // ((*)) ((*)) ((*))
47 // ------- -------- --------
48 // 10.1.1.4 10.1.1.5 10.1.1.6
49 // +-----+ +-----+ +-----+
50 // | SS3 | | SS4 | | SS5 |
51 // +-----+ +-----+ +-----+
52 
53 #include "ns3/core-module.h"
54 #include "ns3/network-module.h"
55 #include "ns3/applications-module.h"
56 #include "ns3/mobility-module.h"
57 #include "ns3/config-store-module.h"
58 #include "ns3/wimax-module.h"
59 #include "ns3/internet-module.h"
60 #include "ns3/global-route-manager.h"
61 #include <iostream>
62 
63 NS_LOG_COMPONENT_DEFINE ("wimaxIpV4Simulation");
64 
65 using namespace ns3;
66 
67 int main (int argc, char *argv[])
68 {
69  // default values
70  int nbSS = 4, duration = 7, schedType = 0;
71  bool verbose = false;
73  LogComponentEnable ("UdpClient", LOG_LEVEL_INFO);
74  LogComponentEnable ("UdpServer", LOG_LEVEL_INFO);
75 
76 
77  CommandLine cmd;
78  cmd.AddValue ("nbSS", "number of subscriber station to create", nbSS);
79  cmd.AddValue ("scheduler", "type of scheduler to use with the network devices", schedType);
80  cmd.AddValue ("duration", "duration of the simulation in seconds", duration);
81  cmd.AddValue ("verbose", "turn on all WimaxNetDevice log components", verbose);
82  cmd.Parse (argc, argv);
83 
84  switch (schedType)
85  {
86  case 0:
88  break;
89  case 1:
91  break;
92  case 2:
93  scheduler = WimaxHelper::SCHED_TYPE_RTPS;
94  break;
95  default:
97  }
98 
99  NodeContainer ssNodes;
100  NodeContainer bsNodes;
101 
102  ssNodes.Create (nbSS);
103  bsNodes.Create (1);
104 
105  WimaxHelper wimax;
106 
107  NetDeviceContainer ssDevs, bsDevs;
108 
109  ssDevs = wimax.Install (ssNodes,
112  scheduler);
114 
116 
117  for (int i = 0; i < nbSS; i++)
118  {
119  ss[i] = ssDevs.Get (i)->GetObject<SubscriberStationNetDevice> ();
121  }
122 
124  bs = bsDevs.Get (0)->GetObject<BaseStationNetDevice> ();
125 
126  MobilityHelper mobility;
127  mobility.Install (bsNodes);
128  mobility.Install (ssNodes);
129 
130  InternetStackHelper stack;
131  stack.Install (bsNodes);
132  stack.Install (ssNodes);
133 
134  Ipv4AddressHelper address;
135  address.SetBase ("10.1.1.0", "255.255.255.0");
136 
137  Ipv4InterfaceContainer SSinterfaces = address.Assign (ssDevs);
138  Ipv4InterfaceContainer BSinterface = address.Assign (bsDevs);
139  if (verbose)
140  {
141  wimax.EnableLogComponents (); // Turn on all wimax logging
142  }
143  /*------------------------------*/
144  UdpServerHelper* udpServer = new UdpServerHelper[nbSS / 2];
145  ApplicationContainer* serverApps = new ApplicationContainer[nbSS / 2];
146  UdpClientHelper* udpClient = new UdpClientHelper[nbSS / 2];
147  ApplicationContainer* clientApps = new ApplicationContainer[nbSS / 2];
148 
149  for (int i = 0; i < nbSS / 2; i++)
150  {
151  // set server port to 100+(i*10)
152  udpServer[i] = UdpServerHelper (100 + (i * 10));
153  serverApps[i] = udpServer[i].Install (ssNodes.Get (i));
154  serverApps[i].Start (Seconds (6));
155  serverApps[i].Stop (Seconds (duration));
156 
157  udpClient[i] = UdpClientHelper (SSinterfaces.GetAddress (i), 100 + (i * 10));
158  udpClient[i].SetAttribute ("MaxPackets", UintegerValue (1200));
159  udpClient[i].SetAttribute ("Interval", TimeValue (Seconds (0.12)));
160  udpClient[i].SetAttribute ("PacketSize", UintegerValue (800));
161 
162  clientApps[i] = udpClient[i].Install (ssNodes.Get (i + (nbSS / 2)));
163  clientApps[i].Start (Seconds (6));
164  clientApps[i].Stop (Seconds (duration));
165  }
166 
167  Simulator::Stop (Seconds (duration + 0.1));
168  /*
169  * Setup 1 transport connections between each SS and the BS
170  */
171  for (int i = 0; i < nbSS / 2; i++)
172  {
173  IpcsClassifierRecord DlClassifierBe (Ipv4Address ("0.0.0.0"),
174  Ipv4Mask ("0.0.0.0"),
175  SSinterfaces.GetAddress (i),
176  Ipv4Mask ("255.255.255.255"),
177  0,
178  65000,
179  100 + (i * 10),
180  100 + (i * 10),
181  17,
182  1);
185  DlClassifierBe);
186  ss[i]->AddServiceFlow (DlServiceFlowBe);
187  IpcsClassifierRecord ulClassifierBe (SSinterfaces.GetAddress (i + (nbSS / 2)),
188  Ipv4Mask ("255.255.255.255"),
189  Ipv4Address ("0.0.0.0"),
190  Ipv4Mask ("0.0.0.0"),
191  0,
192  65000,
193  100 + (i * 10),
194  100 + (i * 10),
195  17,
196  1);
199  ulClassifierBe);
200  ss[i + (nbSS / 2)]->AddServiceFlow (ulServiceFlowBe);
201 
202  }
203 
204  NS_LOG_INFO ("Starting simulation.....");
205  Simulator::Run ();
206 
207  delete[] clientApps;
208  delete[] udpClient;
209  delete[] serverApps;
210  delete[] udpServer;
211  for (int i = 0; i < nbSS; i++)
212  {
213  ss[i] = 0;
214  }
215  delete[] ss;
216 
217  bs = 0;
218 
220  NS_LOG_INFO ("Done.");
221 
222  return 0;
223 }