Presentation is loading. Please wait.

Presentation is loading. Please wait.

 شبیه سازی شبکه توسط نرم افزار NS2  ارائه دهنده : حسین معمارزاده.

Similar presentations


Presentation on theme: " شبیه سازی شبکه توسط نرم افزار NS2  ارائه دهنده : حسین معمارزاده."— Presentation transcript:

1  شبیه سازی شبکه توسط نرم افزار NS2  ارائه دهنده : حسین معمارزاده

2 NS یک شبیه ساز شبکه است  NS می تواند سناریوهای متفاوت شبکه را شبیه سازی کند  NS می تواند ترافیکهای متفاوتی را شبیه سازی کند و خروجی مورد نیاز برای اندازه گیری پارامترهایی مثل تاخیر و میزان گم شدن بسته ها را فراهم کند  NS مورد نیاز است زیرا  نیاز به صحت و اندازه گیری کارآیی الگوریتهمای جدید  شبیه سازی در محیط واقعی هزینه بر و خطا پذیر است

3

4  C++ برای پردازش بسته ها ، OTcl برای سناریوها  100K خط کد C++ ، 70 K خط کد Otcl   نسخه فعلی 2.32  قابل نصب در بیشتر UNIX ها (Linux,Solaris,Freebsd) و ویندوز (9x/NT/2000/2003)

5

6

7

8  اجزاء NS  NS  Nam(Network animator) خروجی NS را می توان مشاهده کرد مراحل پردازش پیش از شبیه سازی مراحل پردازش پس از شبیه سازی

9  NS شبکه را بصورت اتفاقات گسسته شبیه سازی می کند  زمانبند NS اتفاقات را پشت سرهم اجرا می کند  زمان وقوع هر اتفاق مجازی است

10

11

12  C++ برای اطلاعات  پردازش هر بسته – هسته مرکزی NS  سرعت بالا ، کاملا شی گرا  OTCL برای کنترل  ایجاد سناریوهای شبیه سازی  راحتی برای کاربر  عملیات دوره ای یا تحریک شده

13

14

15  Tcl/Tk Download source: A modestly up to date Tcl/Tk version Tcl Tk Tcl Tk  web page: Tcl Developer Xchange resources. Note that while more up to date versions of Tcl/Tk are available and may work, we have only tested up through version Tcl Developer Xchange resources  otcl Download source: version 1.13 (released Mar 10, 2007)version 1.13 (released Mar 10, 2007)  daily snapshot daily snapshot  anonymous CVS (package "otcl") anonymous CVS  web page:  TclCL (the package formerly known as libTcl) Download source: The latest version tclcl-1.19 (released Mar 10, 2007)tclcl-1.19 (released Mar 10, 2007)  daily snapshot daily snapshot  anonymous CVS (package "tclcl") anonymous CVS  web page:  ns-2 Download source: most recent release (ns-2.34 released Jun )most recent release  daily snapshot, daily snapshot  anonymous cvs (module "ns-2"). anonymous cvs  There may be known problems with the current version of ns; please check the ns installation problems web page for patches. nam-1 (optional) Download source: most recent release (nam-1.14 released Jun )ns installation problems web pagemost recent release  daily snapshot, daily snapshot  anonymous cvs (module "nam-1"). anonymous cvs  web page:

16

17

18

19

20  4 گره wireless  این گره ها در یک صفحه به مساحت 400*400 حرکت می کنند  پروتکل روتینگ DSR  شبیه سازی مکانیزم IEEE PS

21 ATIM Window Beacon Interval ATIM Window Host A Host B Beacon BT A =2, BT B =5 power saving mode Beacon ATIM ACK active state data frame ACK Target Beacon Transmission Time (TBTT) No ATIM means no data to send or to receive

22  فایلهایی که باید تغییر کنند  Mac-802_11.cc  Mac-802_11.h  Mac-timers.cc  Mac-timers.h  Mac.cc  Mac.h

23  #include   // #define DEBUG  //#include  #include  /*  * Force timers to expire on slottime boundries.  */  // #define USE_SLOT_TIME  // change wrt Mike's code  #ifdef USE_SLOT_TIME  #error "Incorrect slot time implementation - don't use USE_SLOT_TIME..."  #endif  #define ROUND_TIME()\  { \  assert(slottime);\  double rmd = remainder(s.clock() + rtime, slottime);\  if(rmd > 0.0)\  rtime += (slottime - rmd);\  else \  rtime += (-rmd);\  }

24  void  MacTimer::start(double time)  {  Scheduler &s = Scheduler::instance();  assert(busy_ == 0);  busy_ = 1;  paused_ = 0;  stime = s.clock();  rtime = time;  assert(rtime >= 0.0);  s.schedule(this, &intr, rtime);  }  void  MacTimer::stop(void)  {  Scheduler &s = Scheduler::instance();  assert(busy_);  if(paused_ == 0)  s.cancel(&intr);  busy_ = 0;  paused_ = 0;  stime = 0.0;  rtime = 0.0;  }

25  void  BeaconIntervalTimer::handle(Event *)  {  busy_ = 0;  paused_ = 0;  stime = 0.0;  rtime = 0.0;  mac->beaconIntervalHandler();  }  void  ATIMWindowTimer::handle(Event *)  {  busy_ = 0;  paused_ = 0;  stime = 0.0;  rtime = 0.0;  mac->atimWindowHandler();  }  void  InitialBeaconIntervalTimer::handle(Event *)  {  busy_ = 0;  paused_ = 0;  stime = 0.0;  rtime = 0.0;  mac->initialBeaconIntervalHandler();  }

26  Mac802_11::beaconIntervalHandler()  {  in_atim_=true;  totalBi_++;  EnergyModel *em = netif_->node()->energy_model();  if(em != NULL && !netif_->is_on())  netif_->node_wake();  atim_tx_=true;  EnergyModel *em = netif_->node()->energy_model();  if(em != NULL && !netif_->is_on())  netif_->node_wake();  }  // Schedule the next beacon interval  double bi_time = msec2sec(macmib_.BeaconInterval);  mhBeaconInterval_.start(bi_time);  mhAtimWindow_.start(msec2sec(macmib_.ATIMWindowSize));  got_beacon_=false;  sendBeacon();  stay_awake_=false;  bufferEntry *tmp = NULL;  bufferEntry *cur = pktBuffer_.firstElement();  while(cur != NULL) {  Host *h = NULL;  if(cur->addr() != MAC_BROADCAST)  h = &cache_[cur->addr()];  if(false && cur->age_ >= MAX_PKT_BUFFER_AGE &&  ( h == NULL )) { 

27  if(!cur->sent_data_ && cur->p_ != 0) {  hdr_cmn *ch = HDR_CMN(cur->p_);  if (ch->xmit_failure_) {  //ch->size() -= ETHER_HDR_LEN11;  // ch->xmit_reason_ = XMIT_REASON_BUF;  ch->xmit_failure_(cur->p_->copy(), ch- >xmit_failure_data_);  }  discard(cur->p_, DROP_MAC_RETRY_COUNT_EXCEEDED);  }  tmp = cur;  cur = pktBuffer_.nextElement(cur);  pktBuffer_.removeElement(tmp);  }  else {  // otherwise, update the age and reset interval info  //cur->age_ += static_atim_thresh_ + 1;  cur->age_++;  cur->sent_atim_ = false;  cur->recv_ack_ = false;  cur = pktBuffer_.nextElement(cur);  }

28  // Reset all of these variables at the beginning of the  // beacon epoch  rst_cw();  if( atim_tx_) {  atim_scan();  }  if((pktATIM_ != 0) || atim_to_send())  if(!netif_->is_on())  netif_->node_wake();  if(!mhBackoff_.busy() && !mhSend_.busy() && !mhDefer_.busy() &&  tx_state_ == MAC_IDLE && atim_tx_)  if(( pktATIM_ != 0)) {  // If the synch_err is true, we can't send for the first DELTA  // of last DELTA of the ATIM  mhBackoff_.start(2 * phymib_.CWMin, is_idle());}

29  set val(chan) Channel/WirelessChannel  set val(prop) Propagation/TwoRayGround  set val(netif) Phy/WirelessPhy  set val(mac) Mac/802_11  set val(ifq) CMUPriQueue  set val(ll) LL  set val(ant) Antenna/OmniAntenna  set val(x) 400 ;# X dimension of the topography  set val(y) 400 ;# Y dimension of the topography  set val(ifqlen) 1000 ;# max packet in ifq  set val(seed) 1.0  set val(adhocRouting) DSR  set val(nn) 4 ;# how many nodes are simulated  set val(cp) "../mobility/scene/cbr-4"  set val(sc) "../mobility/scene/scen-4"  set val(stop) 400 ;# simulation time  set ns_[new Simulator]  # setup topography object  set topo[new Topography]

30  set tracefd[open wireless1-out.tr w]  set namtrace [open wireless1-out.nam w]  $ns_ trace-all $tracefd  $ns_ namtrace-all-wireless $namtrace $val(x) $val(y)  # define topology  $topo load_flatgrid $val(x) $val(y)  set god_ [create-god $val(nn)]  #  # define how node should be created  #  #global node setting  $ns_ node-config -adhocRouting $val(adhocRouting) \  -llType $val(ll) \  -macType $val(mac) \  -ifqType $val(ifq) \  -ifqLen $val(ifqlen) \  -antType $val(ant) \  -propType $val(prop) \  -phyType $val(netif) \  -channelType $val(chan) \  # -energyModel EnergyModel \  # -initialEnergy 1000 \  # -txpower 1 \  # -rxpower 1.2 \  # -idlepower 1.0 \

31  # -sleepower \  -topoInstance $topo \  -agentTrace ON \  -routerTrace OFF \  -macTrace ON  #  # Create the specified number of nodes [$val(nn)] and "attach" them  # to the channel.  for {set i 0} {$i < $val(nn) } {incr i} {  set node_($i) [$ns_ node]  $node_($i) random-motion 0;# disable random motion  }  #  # Define node movement model  #  #puts "Loading connection pattern..."  source $val(cp)  #  # Define traffic model  #  puts "Loading scenario file..."  source $val(sc)  # Define node initial position in nam 

32  for {set i 0} {$i < $val(nn)} {incr i} {  # 20 defines the node size in nam, must adjust it according to your scenario  # The function must be called after mobility model is defined  $ns_ initial_node_pos $node_($i) 20  }  #11  # Tell nodes when the simulation ends  #  for {set i 0} {$i < $val(nn) } {incr i} {  $ns_ at $val(stop).0 "$node_($i) reset";  }  $ns_ at $val(stop).0002 "puts \"NS EXITING...\" ; $ns_ halt"  puts $tracefd "M 0.0 nn $val(nn) x $val(x) y $val(y) rp $val(adhocRouting)"  puts $tracefd "M 0.0 sc $val(sc) cp $val(cp) seed $val(seed)"  puts $tracefd "M 0.0 prop $val(prop) ant $val(ant)"  puts "Starting Simulation..."  $ns_ run

33  #  # nodes: 4, max conn: 3, send rate: , seed: 1  #  # 1 connecting to 2 at time  #  set udp_(0) [new Agent/UDP]  $ns_ attach-agent $node_(1) $udp_(0)  set null_(0) [new Agent/Null]  $ns_ attach-agent $node_(2) $null_(0)  set cbr_(0) [new Application/Traffic/Pareto]  $cbr_(0) set packetSize_ 200  $cbr_(0) set idle_time_ 50ms  $cbr_(0) set burst_time_ 500ms  $cbr_(0) set rate_ [expr 64*4]k  $cbr_(0) attach-agent $udp_(0)  $ns_ connect $udp_(0) $null_(0)  $ns_ at "$cbr_(0) start“

34  s _1_ AGT pareto 210 [ ] [1:0 2:0 32 0]  s _1_ MAC AODV 106 [0 ffffffff 1 800] [1:255 -1: ] [0x2 1 1 [2 0] [1 4]] (REQUEST)  r _15_ MAC AODV 48 [0 ffffffff 1 800] [1:255 -1: ] [0x2 1 1 [2 0] [1 4]] (REQUEST)  r _4_ MAC AODV 48 [0 ffffffff 1 800] [1:255 -1: ] [0x2 1 1 [2 0] [1 4]] (REQUEST)  r _0_ MAC AODV 48 [0 ffffffff 1 800] [1:255 -1: ] [0x2 1 1 [2 0] [1 4]] (REQUEST)  r _2_ MAC AODV 48 [0 ffffffff 1 800] [1:255 -1: ] [0x2 1 1 [2 0] [1 4]] (REQUEST)  r _10_ MAC AODV 48 [0 ffffffff 1 800] [1:255 -1: ] [0x2 1 1 [2 0] [1 4]] (REQUEST)  r _19_ MAC AODV 48 [0 ffffffff 1 800] [1:255 -1: ] [0x2 1 1 [2 0] [1 4]] (REQUEST)  r _14_ MAC AODV 48 [0 ffffffff 1 800] [1:255 -1: ] [0x2 1 1 [2 0] [1 4]] (REQUEST)  r _6_ MAC AODV 48 [0 ffffffff 1 800] [1:255 -1: ] [0x2 1 1 [2 0] [1 4]] (REQUEST)  r _18_ MAC AODV 48 [0 ffffffff 1 800] [1:255 -1: ] [0x2 1 1 [2 0] [1 4]] (REQUEST)  s _2_ MAC ARP 86 [0 ffffffff 2 806] [REQUEST 2/2 0/1]  r _5_ MAC ARP 28 [0 ffffffff 2 806] [REQUEST 2/2 0/1]  r _1_ MAC ARP 28 [0 ffffffff 2 806] [REQUEST 2/2 0/1]  r _15_ MAC ARP 28 [0 ffffffff 2 806] [REQUEST 2/2 0/1]  s _1_ MAC pareto 288 [13a ] [1:0 2:0 30 2]  r _2_ MAC pareto 230 [13a ] [1:0 2:0 30 2]  s _2_ MAC ACK 38 [ ]  r _2_ AGT pareto 230 [13a ] [1:0 2:0 30 2]  r _1_ MAC ACK 38 [ ]

35  #!/usr/local/bin/perl  if < 2)  {  print "Usage: packetloss.pl \n";  exit;  }  $infile = $ARGV[0];  $kind = $ARGV[1];  $sum_sent = 0;  $num_dropped = 0;  open (DATA, "<$infile") || die "Can't open $infile $!";  while ( ) {  $line = $_; = split(' ');  last if ($x[4] =~ /END/);  if ($x[0] eq 's' && $x[6] =~ /$kind/)  {  $num_sent++;  #print $line;  }

36  if ($x[0] eq 'D' && $line =~ /IFQ/ && $x[6] =~ /$kind/ && $x[4]!=~ /END/)  {  $num_dropped++;  print $line;  }   $dropped_ratio = 100*($num_dropped/$num_sent);  print STDOUT "Percentage of $kind packets that were dropped: ${dropped_ratio}%\n";  close DATA;  exit(0);


Download ppt " شبیه سازی شبکه توسط نرم افزار NS2  ارائه دهنده : حسین معمارزاده."

Similar presentations


Ads by Google