آموزش شبیه سازی ns2
آموزش شبیه سازی ns2 و نرم افزار ns3 برای کسانی که با ان اس ۲ (یک ابزار محبوب قبل از نرم افزار ns3) آشنا هستند، یک تغییر ظاهری قابل رویت در انتخاب زبان برنامه نویسی است. آموزش شبیه سازی ns2 (شبیه ساز ان اس ۲ )در OTcl اسکریپت شده و نتایج شبیه سازی با استفاده از انیماتور شبکه قابل مشاهده می باشد. اجرای یک شبیه سازی در شبیه سازی ns2 از ++C (به عنوان مثال، به عنوان یک main() بدون هیچ گونه OTcl) امکان پذیر نمی باشد. برخی از اجزای نرم افزار شبیه ساز ns2 (ان اس ۲) در ++C و برخی دیگر در OTcl نوشته شده است. آموزش شبیه سازی ns2 و نرم افزار ns3 (ان اس ۳)، به طور کامل در ++C و با ساختار Python اختیاری نوشته شده است. در نتیجه اسکریپت شبیه سازی می تواند در ++C و یا در Python نوشته شود. انیماتورها و ویژوالایزر های جدید در نسخه در حال توسعه موجود می باشند. از آنجا که ns3 ، بسته ردیابی فایل PCAP را در شبکه تولید می کند، دیگر ابزار های کاربردی می توانند از آن برای تجزیه و ردیابی استفاده کنند. شباهت هایی هم وجود دارد (به عنوان مثال هر دو مبتنی بر شی ++C و همچنین برخی از کد های ان اس ۲ در حال حاضر به شبیه ساز ns3 منتقل شده اند). سوالی که ما اغلب می شنویم این است که “من باید هنوز از ان اس ۲ استفاده کنم یا شروع به استفاده از شبیه ساز ns3(ان اس ۳) کنم؟” به نظر ما، استفاده از شبیه ساز ns3 به دلایل ریز سازنده تر خواهد بود. به منظور آموزش شبیه سازی ns2 این نرم افزار بر روی چندین نوع سیستم عامل سازگار با یونیکس (همچون FreeBSD, لینوکس Linux, سانSunOS, سولاریسSolaris ) تولید و گسترش یافته است و بنابرین بر روی این سیستمها به راحتی نصب خواهد شد. نرم افزار ان اس ۲ بر روی سیستم عامل ویندوز نیز قابل نصب است اما به Cygwin نیاز دارد. به منظور آموزش شبیه سازی ns2 از راهنمایی تیم ما می توانید بهره بگیرید.
انجام پروژه ns2
انجام پروژه ns2 این نرم افزار با توجه به سابقه طولانی که دارد، مجموعه متنوع تری از ماژول های مختلف نسبت به انجام پروژه ns3 را دارا می باشد. با این حال، شبیه ساز ns3 دارای مدل های دقیق تری در حوزه های محبوب پژوهش (شامل LTE و مدل های WiFi پیچیده) می باشد و پشتیبانی آن از کد های پیاده سازی، طیف بسیار گسترده ای از مدل های کاربر پسند را شامل می شود. کاربران ممکن است راغب به یادگیری تمام شبکه لینوکس پشته محصور شده در یک گره NS3 با استفاده از چارچوب اجرای کد مستقیم (DCE) باشند. انجام پروژه ns2 گاهی اوقات می تواند به انجام پروژه ns3 منتقل شود، به خصوص اگر در ++C پیاده سازی شود. اگر شک دارید، از طریق یک راهنمای خوب نگاهی به هر دو شبیه ساز و انجام پروژه ns2 (و همچنین سایر شبیه سازها) و خصوصا مدل های موجود برای تحقیقات خود بیندازید، اما به خاطر داشته باشید که تجربه شما در استفاده از ابزار منجر به توسعه و نگهداری بهینه تری خواهد شد. انجام پروژه ns2 در مقطع ارشد و دکترا یکی از الزامات گرایشات شبکه رشته های فنی و مهندسی می باشد.
آموزش ns2
آموزش ns2 یکی از کاربردی ترین ابزارها در رشته های فنی و مهندسی به منظور شبیه سازی می باشد. برای کامپایل و نصب نرم افزار ns2 به سیستمی نیاز است که کامپایلر C++ بر روی آن وجود داشته باشد. از مزایای آموزش ns2 بهره گیری از پروتکلهایی نظیر ، UDP ، TCP رفتار منابع مولد ترافیک نظیر پروتکلهای ، VBR ، CBR ، WEB ، FTP ، Telnet مکانیزمهای مدیریت صف در مسیریابها مانند ، RED ، Drop Tail و CBQ و الگوریتمهای مسیریابی نظیر دایجسترا و امثالهم را مهیا می نماید . علاوه بر اینها آموزش ns2 مکانیزم های چندپراکنی و برخی از پروتکل های دسترسی به رسانه برای شبیه سازی شبکه های محلی را نیز در اختیار می گذارد . نرم افزار ns2 در حال حاضر به عنوان بخشی از پروژه VINT است. در حال حاضر نگارش دوم نرم افزار NS2 با بهره گیری از قابلیتهای زبان برنامه نویسی ++C و زبان برنامه نویسی OTcl طراحی وپیاده سازی شده است که زبان برنامه نویسی OTcl زبانی اسکریپتی با ساختار نگارشی زبان برنامه نویسی Tcl بعلاوه امکانات و تواناییهای شی گرایی است . قابلیتهای شی گرایی و افزوده شده به زبان برنامه نویسی Tcl در دانشگاه MIT طراحی و پیاده سازی گردیده است . در یک نگاه ساده شده از دید کاربر ، این شبیه ساز (ان اس ۲) یک مفسر اسکریپت های OTcl است که از کتابخانه اشیاء و اجزاء شبکه، زمانبند رخدادهای شبیه سازی، و واحدهای کتابخانه ای برپایی شبکه تشکیل شده است. شبیه ساز NS3 به طور فعال، در لیست پستی کاربران به صورت پاسخگو و فعال نگهداری می شود، در حالی که آموزش ns2 تنها در درخت کد اصلی خود در کمتر از یک دهه قرار داده شده است. از مزایای نرم افزار NS3 در مقایسه با شبیه ساز (ان اس ۲) این است که ویژگی هایی را فراهم می کند در آموزش ns2 در دسترس نمی باشد. مانند پیاده سازی یک محیط اجرای کد. (به کاربران امکان اجرای کد پیاده سازی واقعی در شبیه ساز را فراهم می سازد). نرم افزار NS3 سطح پایین تری از انتزاع را در مقایسه با شبیه ساز (ان اس ۲) ارائه می دهد که آن را در تراز بهتری با سیستم های واقعی قرار می دهد. برخی از محدودیت های موجود در آموزش ns2 (مانند پشتیبانی از انواع مختلف از رابط ها در گره ها) در شبیه ساز NS3 اصلاح شده است.
شبیه سازی پایان نامه ns2
شبیه سازی پایان نامه ns2 یک ابزار قدرتمند در زمینه شبکه می باشد. در نسخه جدید شبیه سازی پایان نامه ns2 برای شبیه سازی شبکه های کامپیوتری است که یک پروژه منبع باز و در حال توسعه می باشد که از سال ۲۰۰۶ شروع شده است. نرم افزار شبیه ساز NS3 برای پلتفرم های شبیه سازی شبکه باز قابل توسعه بوده و ارائه شده به منظور پژوهش و آموزش در حوضه شبکه می باشد. شبیه ساز NS3 مدل کار بسته های اطلاعاتی شبکه را ارائه داده و یک موتور شبیه سازی قوی را برای انجام آنالیز های شبیه سازی فراهم می سازد. پروژه NS3 به عنوان یک سیستم کتابخانه نرم افزار که با یکدیگر کار می کنند ساخته شده است. برنامه های کاربر می تواند به این کتابخانه ها لینک (یا import) شود. برنامه های کاربر همچنین می تواند در زبان برنامه نویسی ++C و یا Python نوشته شود. شبیه سازی پایان نامه ns2 به عنوان کد منبع توزیع شده می باشد به این معنی که سیستم هدف نیاز به یک محیط توسعه نرم افزار برای ساخت کتابخانه برای اولین بار، سپس ایجاد برنامه کاربر می باشد. شبیه سازی پایان نامه ns2 ممکن است در اصل به عنوان کتابخانه های از پیش ساخته شده برای توزیع سیستم های انتخاب شده باشد و در آینده نیز ممکن است به همان طریق توزیع شود، اما در حال حاضر، بسیاری از کاربران در واقع کار خود را با ویرایش شبیه ساز NS3 انجام می دهند، بنابراین داشتن کد منبع برای بازسازی کتابخانه مفید می باشد.
Basics of NS2 and Otcl/tcl script
Simulation is the process of learning by doing. Whenever there is something new in the world, we try to analyse it first by examining it and in the process get to learn a lot of things. This entire course is called as Simulation. Correlating to this process, in order to understand all the complexities one need to model the entire role-play in form of computer simulation, the need is to build artificial objects and assign them roles dynamically. Computer simulation is the designing of a theoretical physical system on a digital computer with emphasis on model designing, execution and analysis. After creation of the mathematical model the most important step is to create a computer program for updating the state and event variables through time (by time slicing or event scheduling). If this simulation is carried out successively in parallel computers, it is called Parallel or Distributed simulation. Network simulation (NS) is one of the types of simulation, which is used to simulate the networks such as in MANETs, VANETs etc. It provides simulation for routing and multicast protocols for both wired and wireless networks. NS is licensed for use under version 2 of the GNU (General Public License) and is popularly known as NS2. It is an object-oriented, discrete event-driven simulator written in C++ and Otcl/tcl. NS-2 can be used to implement network protocols such as TCP and UPD, traffic source behavior such as FTP, Telnet, Web, CBR and VBR, router queue management mechanism such as Drop Tail, RED and CBQ, routing algorithms and many more. In ns2, C++ is used for detailed protocol implementation and Otcl is used for the setup. The compiled C++ objects are made available to the Otcl interpreter and in this way, the ready-made C++ objects can be controlled from the OTcl level.
Install NS-2 using this command
sudo apt-get install ns2
Nam is also needed to install. Nam (Network Animator) is an animation tool to graphically represent the network and packet traces. Use this comman
sudo apt-get install nam
Some basic Otcl script syntax
Basic Command
filter_none
brightness_4
seta 8
setb [expr $a/8]
Explanation : In the first line, the variable a is assigned the value 8. In the second line, the result of the command [expr $a/8], which equals 1, is then used as an argument to another command, which in turn assigns a value to the variable b. The “$” sign is used to obtain a value contained in a variable and square brackets are an indication of a command substitution. Define new procedures with proc command
filter_none
brightness_4
proc factorial fact {
if {$fact <= 1} {
return 1
}
expr $fact * [factorial [expr $fact-1]]
{
To open a file for reading
filter_none
brightness_4
set testfile [open hello.dat r]
Similarly, put command is used to write data into the file
filter_none
brightness_4
set testfile [open hello.dat w]
puts $testfile “hello”
To call subprocesses within another process, exec is used, which creates a subprocess and waits for it to complete
filter_none
brightness_4
exec rm $testfile
To be able to run a simulation scenario, a network topology must first be created. In ns2, the topology consists of a collection of nodes and links
filter_none
brightness_4
set ns [new Simulator]
The simulator object has member functions which enables to create the nodes and define the links between them. The class simulator contains all the basic functions. Since ns was defined to handle the Simulator object, the command $ns is used for using the functions belonging to the simulator class.In the network topology nodes can be added in the following manner
filter_none
brightness_4
set n0 [$ns node]
set n1 [$ns node]
Traffic agents (TCP, UDP etc.) and traffic sources (FTP, CBR etc.) must be set up if the node is not a router. It enables to create CBR traffic source using UDP as transport protocol or an FTP traffic source using TCP as a transport protocol.CBR traffic source using UDP
filter_none
brightness_4
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packet_size_ 512
FTP traffic source using TCP
filter_none
brightness_4
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$tcp0 set packet_size_ 512
Below is the implementation of creating links between the source and destination using both ftp and tcp
filter_none
brightness_4
Create a simulator object
set ns [new Simulator]
# Define different colors
# for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
# Open the NAM trace file
set nf [open out.nam w]
$ns namtrace-all $nf
# Define a ‘finish’ procedure
proc finish {}
{
global ns nf
$ns flush-trace
# Close the NAM trace file
close $nf
# Execute NAM on the trace file
exec nam out.nam &
exit 0
}
# Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
# Create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail
# Set Queue Size of link (n2-n3) to 10
$ns queue-limit $n2 $n3 10
# Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
# Monitor the queue for link (n2-n3). (for NAM)
$ns duplex-link-op $n2 $n3 queuePos 0.5
# Setup a TCP connection
set tcp [new Agent/TCP]
$tcp set class_ 2
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
# Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
# Setup a UDP connection
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
$udp set fid_ 2
# Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 1mb
$cbr set random_ false
# Schedule events for the CBR and FTP agents
$ns at 0.1 “$cbr start”
$ns at 1.0 “$ftp start”
$ns at 4.0 “$ftp stop”
$ns at 4.5 “$cbr stop”
# Detach tcp and sink agents
# (not really necessary)
$ns at 4.5 “$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink”
# Call the finish procedure after
# ۵ seconds of simulation time
$ns at 5.0 “finish”
# Print CBR packet size and interval
puts “CBR packet size = [$cbr set packet_size_]”
puts “CBR interval = [$cbr set interval_]”
# Run the simulation
$ns run
ns-1
The first version of ns, known as ns-1, was developed at Lawrence Berkeley National Laboratory (LBNL) in the 1995-97 timeframe by Steve McCanne, Sally Floyd, Kevin Fall, and other contributors. This was known as the LBNL Network Simulator, and derived in 1989 from an earlier simulator known as REAL by S. Keshav.
ns-2
Ns-2 began as a revision of ns-1. From 1997-2000, ns development was supported by DARPA through the VINT project at LBL, Xerox PARC, UCB, and USC/ISI. In 2000, ns-2 development was supported through DARPA with SAMAN and through NSF with CONSER, both at USC/ISI, in collaboration with other researchers including ACIRI. Ns-2 incorporates substantial contributions from third parties, including wireless code from the UCB Daedelus and CMU Monarch projects and Sun Microsystems.
ns-3
In 2006, a team led by Tom Henderson, George Riley, Sally Floyd, and Sumit Roy, applied for and received funding from the U.S. National Science Foundation (NSF) to build a replacement for ns-2, called ns-3. This team collaborated with the Planete project of INRIA at Sophia Antipolis, with Mathieu Lacage as the software lead, and formed a new open source project. In the process of developing ns-3, it was decided to completely abandon backward-compatibility with ns-2. The new simulator would be written from scratch, using the C++ programming language. Development of ns-3 began in July 2006.
Current status of the three versions is
ns-1 development stopped when ns-2 was founded. It is no longer developed nor maintained.
ns-2 development stopped around 2010. It is no longer developed nor maintained.
ns-3 is actively being developed and maintained.