Cơ sở truyền số liệu: Băng thông công bằng giữa các luồng

31 410 0
Cơ sở truyền số liệu: Băng thông công bằng giữa các luồng

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Băng thông công bằng giữa các luồng Đề bài: Cho một mạng gồm 5 nút như hình vẽ. Nút 1, 2, 3, 4, 5 là các hàng đợi đơn hoạt động theo nguyên tắc FIFO với độ lớn hàng đợi K = 10 gói. Có 3 luồng dữ liệu được gửi qua mạng tương ứng là (S1, D1), (S2, D2) và (S3, D3). Trong đó Si là nguồn phát dữ liệu còn Di là đích. Đường nối L1 có dung lượng 1,5 Mbs trễ lan truyền 150ms; L2 có dung lượng là 1Mbs trễ lan truyền 100ms; đường L3 có dung lượng 0,6 Mbs, trễ lan truyền 50ms; và L4 có dung lượng 0,5 Mbs, trễ lan truyền 100ms. Các nguồn Si đều phát gói với độ dài cố định là 125byte, khoảng thời gian giữa các gói tuân theo phân bố Poisson. Các bước thực hiện: 1. Lập kế hoạch phân công công việc 2. Tìm hiểu về giao thức TCP, UDP, và Tracing, Xgraph trong NS2, thuật toán MaxMin Fairness 3. Tiến hành mô phỏng trên công cụ NS2 4. Phụ lục code tham khảo

TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI VIỆN ĐIỆN TỬ - VIỄN THÔNG BÀI TẬP LỚN MÔN CƠ SỞ TRUYỀN SỐ LIỆU Đề tài: BĂNG THÔNG CÔNG BẰNG GIỮA CÁC LUỒNG Giảng viên hướng dẫn: PGS.TS Nguyễn Hữu Thanh Sinh viên thực hiện: Nguyễn Văn Trọng 20122606 Phùng Văn Thông 20122522 Hà Nội, 12/2015 Contents LỜI MỞ ĐẦU Mạng viễn thông với tài nguyên băng thông khan nhiều luồng liệu truy cập dẫn đến tìn trạng tắc nghẽn phân chia công mặt băng thông cho nhiều người sử dụng lúc Vì vậy, nhóm em chọn đề tài: “Băng thông công luồng hệ thống mạng thông tin“ để thực tập lớn I Đề Cho mạng gồm nút hình vẽ Nút 1, 2, 3, 4, hàng đợi đơn hoạt động theo nguyên tắc FIFO với độ lớn hàng đợi K = 10 gói Có luồng liệu gửi qua mạng tương ứng (S1, D1), (S2, D2) (S3, D3) Trong Si nguồn phát liệu Di đích Đường nối L1 có dung lượng 1,5 Mb/s trễ lan truyền 150ms; L2 có dung lượng 1Mb/s trễ lan truyền 100ms; đường L3 có dung lượng 0,6 Mb/s, trễ lan truyền 50ms; L4 có dung lượng 0,5 Mb/s, trễ lan truyền 100ms Các nguồn Si phát gói với độ dài cố định 125byte, khoảng thời gian gói tuân theo phân bố Poisson Giả thiết băng thông đối đa tổng cộng mà luồng chiếm kênh truyền vật lý 95% dung lượng kênh truyền Tính tốc độ λS1, λS2, λS3 (kbit/s) để luồng chia sẻ băng thông kênh truyền theo nguyên lý công cực đại - cực tiểu (max – fairness) Dựng kịch mô mạng với tốc độ luồng λS1, λS2, λS3 tính toán câu Chạy mô 100s Vẽ đồ thị băng thông ri(t) mà luồng (S1, D1), (S2, D2) (S3, D3) sử dụng Vẽ đồ thị tốc độ gói ei(t) (số gói mất/đơn vị thời gian) luồng (S1, D1), (S2, D2) (S3, D3) nút Thay luồng theo phân bố Poisson luồng TCP Lặp lại câu Có nhận xét gì? II Lập kế hoạch phân công công việc 2.1 Lập kế hoạch Bài tập lớn thực vòng tuần • Tuần 1: Cài đặt hệ điều hành Linux(Ubuntu) cài NS2 Hai thành viên nhóm tìm hiểu yêu cầu đề phân công việc cho người • Tuần 2: Tìm hiểu cách chạy mô NS2, quan tâm đến cú pháp file tcl để thực mô • Tuần 3: Tìm hiểu cách xây dựng topo mạng vẽ đồ thị xgraph NS2 • Tuần 4: Tìm hiểu giao thức truyền thông mạng UDP, phát gói tin có khoảng thời gian thep phân bố Poisson Thực mô số project mẫu đơn giản NS2 • Tuần 5: Tìm hiểu giao thức truyền thông mạng TCP Thực mô số project mẫu đơn giản NS2 • Tuần 6: Tìm hiểu thuật toán Max-Min Fairness để giải yêu cầu 1: Tính λS1, λS2, λS3 • Tuần 7: Kết nối nguồn liệu vào topo mạng qua giao thức UDP TCP Xây dựng kịch mô vẽ đồ thị • Tuần 8: Kiểm tra lại code lần cuối viết báo cáo 2.2 Phân công công việc STT Họ tên Nguyễn Văn Trọng Phùng Văn Thông Công việc Tìm hiểu giao thức UDP, mô phỏng, xgraph, viết báo cáo, thuật toán max – fairness Tìm hiểu giao thức TCP, mô phỏng, xgraph, thuật toán max – fairness III Quá trình thực 3.1 Chuẩn bị kiến thức để thực mô 3.1.1 Tìm hiểu giao thức UDP Giao thức UDP (User Datagram Protocol) hay gọi giao thức gói người dùng hai giao thức cốt lõi giao thức TCP/IP, cho phép người dùng gửi liệu ngắn gọi datagram từ máy tính đến máy tính khác UDP không đảm bảo tin cậy thứ tự truyền nhận, gói liệu đến không thứ tự bị mà thông báo Tuy nhiên, UDP nhanh hiệu mục tiêu kích thước nhỏ yêu cầu khắt khe thời gian, giao thức hữu dụng việc trả lời truy vấn với số lượng lớn người yêu cầu Những ứng dụng phổ biến sử dụ ng UDP DNS (Domain Name System), ứng dụng streaming media, Voice over IP, Trivial File Transfer Protocol (TFTP), game trực tuyến 3.1.2 Tìm hiểu giao thức TCP Giao thức TCP (Transmission Control Ptotocol) giao thức cốt lõi giao thức TCP/IP, cho phép ứng dụng máy chủ trao đổi liệu gói tin Giao thức đảm bảo chuyển giao liệu tới nơi nhận cách tin cậy thứ tự TCP hỗ trợ nhiều ứng dụng phổ biến Internet WWW, Mail Secure Shell 3.1.3 Tracing Trong NS, kiện xảy trace (lưu vết) simplex link Nếu mô trỏ đến hoạt động trace (bằng lệnh $ns trace-all file hay $ns namtrace-all file) link có đối tượng trace chèn thêm vào Khi đối tượng chèn thêm đối tượng trace nhận package, ghi vào file trace xác định mà không thời gian mô Sau đó, package truyền đến dối tượng Định dạng chuẩn file trace NS-2: • • • • • • • • • • • • event: thao tác thực mô time: thời gian xuất kiện from node: nốt nguồn to node: nốt đích pkt type: loại packet pkt size: kích cỡ packet flags: cờ fid: mã luồng src addr: địa node nguồn dst addr: địa node đích seq num: số trình tự pkt id: mã packet 3.1.4 Xgraph Xgraph công cụ vẽ đồ thị cấp sẵn NS Xgraph cho phép tạo file ảnh số định dạng khác cách ấn vào “Hdcpy” câu lệnh gọi Xgraph khai báo kịch TCL xuất đồ thị kết thúc mô Đầu vào Xgraph nhiều file chứa cặp giá trị x-y dòng (mỗi dòng chứa tọa độ điểm đồ thị ) Ví dụ lệnh : Xgraph f1 f2 vẽ đồ thị file f1,f2 Một số lựa chọn sử dụng Xgraph : • • • • • Tên đồ thị: -t “Title” Kích thước: -geometry xsize x ysize Tiêu đề cho trục: -x “xtitle” –y “ytitle” Màu chữ lưới: – v Màu nền: – bg 3.1.5 Thuật toán Max-Min Fairness B1 Khởi tạo tất kết nối với tốc độ = B2 Tăng tốc độ tất kết nối lượng ε = min( Cchannel _ i − CDataFlow _( S , D ) Li n ) n số luồng xét qua liên kết Tìm kênh đạt giá trị băng thông cực đại Khi đó: + Tất luồng chia sẻ liên kết sử dụng băng thông + Liên kết gây tắc nghẽn với tất kết nối sử dụng liên kết + Ngưng việc tăng băng thông cho liên kết đạt cân cực đại- cực tiểu B3 Lặp lại B2 cho kết nối khác chưa đạt đến trạng thái cân cực đại – cực tiểu B4 n = 0, kết thúc 3.2 Tiến hành mô Tính tốc độ phát gói Theo đề bài, ta có giả thiết: • • • • Đường nối L1 có dung lượng C1 = 1.5 Mbps, trễ lan truyền 150ms Đường nối L2 có dung lượng C2 = Mbps, trễ lan truyền 100ms Đường nối L3 có dung lượng C3 = 0.6 Mbps, trễ lan truyền 50ms Đường nối L4 có dung lượng C4 = 0.5 Mbps, trễ lan truyền 100ms Nút 1, 2, 3, 4, hàng đợi đơn hoạt động theo nguyên tắc FIFO với độ lớn hàng đợi K = 10 gói Băng thông tối đa tổng cộng mà luồng chiếm kênh truyền vật lý 95% dung lượng kênh truyền Tính λS1, λS2, λS3 Bài giải: • Các đường nối L1 = (1, 2), L2 = (2, 3), L3 = (3, 4), L4 = (4, 5) • Các luồng (S1, D1), (S2, D2), (S3, D3) Ta có bảng thực bước thuật toán Max – Min Fairness Luồng (S1, D1) (S2, D2) (S3, D3) Thực Bước 0 Khởi tạo Bước 0.3 0.3 0.3 Bước 0.3 0.3 0.3 Bước 0.3 0.7 0.3 L2 đạt cực đại C2 = Mbps (S2, D2) = 0.7 Mbps Bước 0.3 0.7 0.3 Kết thúc Loại bỏ Bước ε= 1.5 − − 0.6 − 0.5 − ( , , , ) = 0.3 L∈( L1, L 2, L 3, L 4) 2 L3 đạt cực đại C3 = 0.6 Mbps (S1, D1) = (S3, D3) = 0.3 Mbps ε = ( L∈( L1, L 2) (S1, D1); (S3, D3) L3, L4 1.5 − 0.3 − , ) = 0.4 1 (S2, D2) L1, L2 Theo giả thiết băng thông tối đa tổng cộng mà luồng chiếm kênh truyền vật lý 95% dung lượng kênh truyền nên tốc độ phát gói nguồn S1, S2, S3 là: S1 = 0.3*0.95 = 0.285 (Mbps) = 285 (kbps) S2 = 0.7*0.95 = 0.665 (Mbps) = 665 (kbps) S3 = 0.3*0.95 = 0.285 (Mbps) = 285 (kbps) Mỗi gói có độ dài 125 byte = 1000 bit Ta viết: S1 = 285 (gói/s) S2 = 665 (gói/s) S3 = 285 (gói/s) Dựng kịch mô với tốc độ luồng S1, S2, S3 Mô với tốc độ phát gói 4.1 Dựng kịch mô sau: #Đặt tốc độ đến trung bình (gói/s) set lambda1 285.0 set lambda2 665.0 set lambda3 285.0 #Độ dài gói: 125 byte/gói set pksize 125.0 Các nút 0, 1, 2, 3, (màu xanh) : nút n1, n2, n3, n4, n5 Các nút 5, 6, (màu đỏ) : nguồn S1, S2, S3 Các nút 8, 9, 10 (màu đen) : nút đích D1, D2, D3 Vẽ đồ thị băng thông Ri(t) tốc độ gói Ei(t) luồng Đồ thị băng thông ri(t) luồng (S1, D1), (S2, D2), (S3, D3) Đồ thị tốc độ gói luồng Thay luồng theo phân bố Poisson luồng TCP Đồ thị băng thông: Tốc độ gói: IV Kết luận • Sau lần chạy mô ta thu kết lần giống • Băng thông luồng mô hoàn toàn phù hợp với kết tính toán lý thuyết Cụ thể, băng thông luồng (S1, D1) dao động khoảng từ 600kbps – 700 kbps; băng thông luồng (S2, D2) (S3, D3) gần nhau, dao động khoảng từ 250kbps – 300 kbps $ns run Câu 4.3 #Create a simulator object set ns [new Simulator] #Define different colors for data flows $ns color Red $ns color Green $ns color Blue #Set lambda value (packet/s) set lambda1 285.0 set lambda2 665.0 set lambda3 285.0 #Set packet size set pksize 125.0 #Time to send packet set ArrivalTime1 [new RandomVariable/Exponential] $ArrivalTime1 set avg_ [expr 1/$lambda1] set ArrivalTime2 [new RandomVariable/Exponential] $ArrivalTime2 set avg_ [expr 1/$lambda2] set ArrivalTime3 [new RandomVariable/Exponential] $ArrivalTime3 set avg_ [expr 1/$lambda3] #Open the Trace file set f0 [open BandWidth(S1,D1).tr w] set f1 [open BandWidth(S2,D2).tr w] set f2 [open BandWidth(S3,D3).tr w] set l0 [open Lost(S1,D1).tr w] set l1 [open Lost(S2,D2).tr w] set l2 [open Lost(S3,D3).tr w] #Open the nam trace file set nf [open BTL4.3.nam w] $ns namtrace-all $nf #Define 'finish' process proc finish {} { global ns f0 f1 f2 nf l0 l1 l2 $ns flush-trace #Close the output files close $f0 close $f1 close $f2 close $nf close $l0 close $l1 close $l2 #Execute nam on the trace file exec nam BTL4.3.nam & #Call xgraph to display the results exec xgraph BandWidth(S1,D1).tr BandWidth(S2,D2).tr BandWidth(S3,D3).tr -geometry 800x400 -t "BandWidth Ri(t)" -x "s" -y "Mbit/s" & exec xgraph Lost(S1,D1).tr Lost(S2,D2).tr Lost(S3,D3).tr -geometry 800x400 -t "LostPacket Ei(t)" -x "s" -y "Packet" & exit } #Create nodes: n1, n2, n3, n4, n5 set n1 [$ns node] $n1 color Blue set n2 [$ns node] $n2 color Blue set n3 [$ns node] $n3 color Blue set n4 [$ns node] $n4 color Blue set n5 [$ns node] $n5 color Blue #Create soures: s1, s2, s3 set s1 [$ns node] $s1 color Red set s2 [$ns node] $s2 color Red set s3 [$ns node] $s3 color Red #Create destinations: d1, d2, d3 set d1 [$ns node] $d1 color Black set d2 [$ns node] $d2 color Black set d3 [$ns node] $d3 color Black #Create links between the nodes, sources and destinations $ns duplex-link $n1 $n2 1.5Mb 150ms DropTail $ns duplex-link $n2 $n3 1Mb 100ms DropTail $ns duplex-link $n3 $n4 0.6Mb 50ms DropTail $ns duplex-link $n4 $n5 0.5Mb 100ms DropTail $ns duplex-link $s2 $n1 1Mb 10ms DropTail $ns duplex-link $s1 $n2 1Mb 10ms DropTail $ns duplex-link $d2 $n3 1Mb 10ms DropTail $ns duplex-link $s3 $n3 1Mb 10ms DropTail $ns duplex-link $d1 $n4 1Mb 10ms DropTail $ns duplex-link $d3 $n5 1Mb 10ms DropTail #Set position of nodes $ns duplex-link-op $s2 $n1 orient up $ns duplex-link-op $n1 $n2 orient right-up $ns duplex-link-op $s1 $n2 orient right $ns duplex-link-op $n2 $n3 orient right $ns duplex-link-op $s3 $n3 orient down $ns duplex-link-op $d2 $n3 orient up $ns duplex-link-op $n4 $n3 orient left $ns duplex-link-op $d1 $n4 orient left $ns duplex-link-op $n4 $n5 orient right-up $ns duplex-link-op $d3 $n5 orient down #Set position of queues $ns duplex-link-op $n2 $n1 queuePos 1.5 $ns duplex-link-op $n3 $n2 queuePos 1.5 $ns duplex-link-op $n4 $n3 queuePos 1.5 $ns duplex-link-op $n5 $n4 queuePos 1.5 #Set queue size $ns queue-limit $n1 $n2 10 $ns queue-limit $n2 $n3 10 $ns queue-limit $n3 $n4 10 $ns queue-limit $n4 $n5 10 #Create a UDP agent and attach it to node s1 set udp0 [new Agent/UDP] $udp0 set class_ $ns attach-agent $s1 $udp0 #Create a UDP agent and attach it to node s2 set udp1 [new Agent/UDP] $udp1 set class_ $ns attach-agent $s2 $udp1 #Create a UDP agent and attach it to node s3 set udp2 [new Agent/UDP] $udp2 set class_ $ns attach-agent $s3 $udp2 #Create a Sink agent (a traffic sink) and attach it to node d1, d2, d3 set sink0 [new Agent/LossMonitor] $ns attach-agent $d1 $sink0 set sink1 [new Agent/LossMonitor] $ns attach-agent $d2 $sink1 set sink2 [new Agent/LossMonitor] $ns attach-agent $d3 $sink2 #Connect the traffic sources with the traffic sink $ns connect $udp0 $sink0 $ns connect $udp1 $sink1 $ns connect $udp2 $sink2 #Send packet proc sendpacket0 {} { global ns udp0 ArrivalTime1 pksize set time [$ns now] $ns at [expr $time + [$ArrivalTime1 value]] "sendpacket0" $udp0 send $pksize } proc sendpacket1 {} { global ns udp1 ArrivalTime2 pksize set time [$ns now] $ns at [expr $time + [$ArrivalTime2 value]] "sendpacket1" $udp1 send $pksize } proc sendpacket2 {} { global ns udp2 ArrivalTime3 pksize set time [$ns now] $ns at [expr $time + [$ArrivalTime3 value]] "sendpacket2" $udp2 send $pksize } proc recordbw {} { global sink0 sink1 sink2 f0 f1 f2 #Get an instance of the simulator set ns [Simulator instance] #Set the time after which the procedure should be called again set time 0.5 #How many bytes have been received by the traffic sinks? set bw0 [$sink0 set bytes_] set bw1 [$sink1 set bytes_] set bw2 [$sink2 set bytes_] #Get the current time set now [$ns now] #Calculate the bandwidth (in MBit/s) and write it to the files puts $f0 "$now [expr $bw0/$time*8/1000000]" puts $f1 "$now [expr $bw1/$time*8/1000000]" puts $f2 "$now [expr $bw2/$time*8/1000000]" #Reset the bytes_ values on the traffic sinks $sink0 set bytes_ $sink1 set bytes_ $sink2 set bytes_ #Re-schedule the procedure $ns at [expr $now+$time] "recordbw" } proc recordlost {} { global sink0 sink1 sink2 l0 l1 l2 #Get an instance of the simulator set ns [Simulator instance] #Set the time after which the procedure should be called again set time 0.5 #How many packet have been lost? set lost0 [$sink0 set nlost_] set lost1 [$sink1 set nlost_] set lost2 [$sink2 set nlost_] #Get the current time set now [$ns now] #Calculate number of packet lost puts $l0 "$now [expr $lost0]" puts $l1 "$now [expr $lost1]" puts $l2 "$now [expr $lost2]" #Reset the nlost_ values on the traffic sinks $sink0 set nlost_ $sink1 set nlost_ $sink2 set nlost_ #Re-schedule the procedure $ns at [expr $now+$time] "recordlost" } # -Finish -puts "\nBAI TAP LON MON CO SO TRUYEN SO LIEU \n" puts " De tai:BANG THONG CONG BANG GIUA CAC LUONG \n" puts " Bai 4.3 \n" puts " GVHD: PGS TS Nguyen Huu Thanh\n" puts " Sinh vien thuc hien: Nguyen Van Trong 20122606\n" puts "\n Phung Van Thong 20122522\n" puts " Please wait \n" #Schedule events for the CBR agents $ns at 0.0 "$s1 label \"S1\"" $ns at 0.0 "$s2 label \"S2\"" $ns at 0.0 "$s3 label \"S3\"" $ns at 0.0 "$n1 label \"N1\"" $ns at 0.0 "$n2 label \"N2\"" $ns at 0.0 "$n3 label \"N3\"" $ns at 0.0 "$n4 label \"N4\"" $ns at 0.0 "$n5 label \"N5\"" $ns at 0.0 "$d1 label \"D1\"" $ns at 0.0 "$d2 label \"D2\"" $ns at 0.0 "$d3 label \"D3\"" $ns at 0.0 "recordbw" $ns at 0.0 "recordlost" $ns at 0.5 "sendpacket0" $ns at 0.5 "sendpacket1" $ns at 0.5 "sendpacket2" #Call the finish procedure $ns at 100 "finish" #Run the simulation $ns run Câu 4.4 #Create a simulator object set ns [new Simulator] #Define different colors for data flows $ns color Red $ns color Green $ns color Blue #Set lambda value (packet/s) set lambda1 285.0 set lambda2 665.0 set lambda3 285.0 #Set packet size set pksize 125.0 #Open the Trace file set f0 [open BandWidth(S1,D1).tr w] set f1 [open BandWidth(S2,D2).tr w] set f2 [open BandWidth(S3,D3).tr w] set l0 [open Lost(S1,D1).tr w] set l1 [open Lost(S2,D2).tr w] set l2 [open Lost(S3,D3).tr w] #Open the nam trace file set nf [open BTL4.4.nam w] $ns namtrace-all $nf #Dinh nghia thu tuc 'finish' proc finish {} { global ns nf f0 f1 f2 $ns flush-trace #Close the output files close $f0 close $f1 close $f2 close $nf #Execute nam on the trace file exec nam BTL4.4.nam & #Call xgraph to display the results exec xgraph BandWidth(S1,D1).tr BandWidth(S2,D2).tr BandWidth(S3,D3).tr -geometry 800x400 -t "BandWidth Ri(t)" -x "s" -y "Mbit/s" & exec xgraph lost0.tr lost1.tr lost2.tr -geometry 800x400 -t "LostPacket Ei(t)" -x "s" -y "Packet" & exit } #Create nodes set n1 [$ns node] $n1 color Blue set n2 [$ns node] $n2 color Blue set n3 [$ns node] $n3 color Blue set n4 [$ns node] $n4 color Blue set n5 [$ns node] $n5 color Blue #Create soures set s1 [$ns node] $s1 color Red set s2 [$ns node] $s2 color Red set s3 [$ns node] $s3 color Red #Create destinations set d1 [$ns node] $d1 color Black set d2 [$ns node] $d2 color Black set d3 [$ns node] $d3 color Black #Create links between the nodes $ns duplex-link $n1 $n2 1.5Mb 150ms DropTail $ns duplex-link $n2 $n3 1Mb 100ms DropTail $ns duplex-link $n3 $n4 0.6Mb 50ms DropTail $ns duplex-link $n4 $n5 0.5Mb 100ms DropTail $ns duplex-link $s2 $n1 1Mb 10ms DropTail $ns duplex-link $s1 $n2 1Mb 10ms DropTail $ns duplex-link $d2 $n3 1Mb 10ms DropTail $ns duplex-link $s3 $n3 1Mb 10ms DropTail $ns duplex-link $d1 $n4 1Mb 10ms DropTail $ns duplex-link $d3 $n5 1Mb 10ms DropTail #Set position of nodes $ns duplex-link-op $s2 $n1 orient up $ns duplex-link-op $n1 $n2 orient right-up $ns duplex-link-op $s1 $n2 orient right $ns duplex-link-op $n2 $n3 orient right $ns duplex-link-op $s3 $n3 orient down $ns duplex-link-op $d2 $n3 orient up $ns duplex-link-op $n4 $n3 orient left $ns duplex-link-op $d1 $n4 orient left $ns duplex-link-op $n4 $n5 orient right-up $ns duplex-link-op $d3 $n5 orient down #Set position of queues $ns duplex-link-op $n2 $n1 queuePos 1.5 $ns duplex-link-op $n3 $n2 queuePos 1.5 $ns duplex-link-op $n4 $n3 queuePos 1.5 $ns duplex-link-op $n5 $n4 queuePos 1.5 #Set queue size $ns queue-limit $n1 $n2 10 $ns queue-limit $n2 $n3 10 $ns queue-limit $n3 $n4 10 $ns queue-limit $n4 $n5 10 #Create a TCP agent and attach it to node s1 set tcp0 [new Agent/TCP] $ns attach-agent $n2 $tcp0 set ftp0 [new Application/FTP] $ftp0 attach-agent $tcp0 $tcp0 set packet_size_ 125.0 #Create a TCP agent and attach it to node s2 set tcp1 [new Agent/TCP] $ns attach-agent $n1 $tcp1 set ftp1 [new Application/FTP] $ftp1 attach-agent $tcp1 $tcp1 set packet_size_ 125.0 #Create a TCP agent and attach it to node s3 set tcp2 [new Agent/TCP] $ns attach-agent $n3 $tcp2 set ftp2 [new Application/FTP] $ftp2 attach-agent $tcp2 $tcp2 set packet_size_ 125.0 #Create a Sink agent (a traffic sink) and attach it to node d1, d2, d3 set sink0 [new Agent/TCPSink] $ns attach-agent $n4 $sink0 set sink1 [new Agent/TCPSink] $ns attach-agent $n3 $sink1 set sink2 [new Agent/TCPSink] $ns attach-agent $n5 $sink2 #Connect the traffic sources with the traffic sink $ns connect $tcp0 $sink0 $ns connect $tcp1 $sink1 $ns connect $tcp2 $sink2 #Send packet #Record bandwidth to draw graph proc recordbw {} { global sink0 sink1 sink2 f0 f1 f2 #Get an instance of the simulator set ns [Simulator instance] #Set the time after which the procedure should be called again set time 0.5 #How many bytes have been received by the traffic sinks? set bw0 [$sink0 set bytes_] set bw1 [$sink1 set bytes_] set bw2 [$sink2 set bytes_] #Get the current time set now [$ns now] #Calculate the bandwidth (in MBit/s) and write it to the files puts $f0 "$now [expr $bw0/$time*8/1000000]" puts $f1 "$now [expr $bw1/$time*8/1000000]" puts $f2 "$now [expr $bw2/$time*8/1000000]" #Reset the bytes_ values on the traffic sinks $sink0 set bytes_ $sink1 set bytes_ $sink2 set bytes_ #Re-schedule the procedure $ns at [expr $now+$time] "recordbw" } #proc recordlost {} { # global sink0 sink1 sink2 l0 l1 l2 # #Get an instance of the simulator # set ns [Simulator instance] # #Set the time after which the procedure should be called again # set time 0.1 # #How many packet have been lost? # set lost0 [$sink0 set nlost_] # set lost1 [$sink1 set nlost_] # set lost2 [$sink2 set nlost_] # #Get the current time # set now [$ns now] # #Calculate number of packet lost # puts $l0 "$now [expr $lost0]" # puts $l1 "$now [expr $lost1]" # puts $l2 "$now [expr $lost2]" # #Reset the nlost_ values on the traffic sinks # $sink0 set nlost_ # $sink1 set nlost_ # $sink2 set nlost_ #Re-schedule the procedure # $ns at [expr $now+$time] "recordlost" #} # -Finish -puts "\nBAI TAP LON MON CO SO TRUYEN SO LIEU \n" puts " De tai:BANG THONG CONG BANG GIUA CAC LUONG \n" puts " Bai 4.3 \n" puts " GVHD: PGS TS Nguyen Huu Thanh\n" puts " Sinh vien thuc hien: Nguyen Van Trong 20122606\n" puts "\n Phung Van Thong 20122522\n" puts " Please wait \n" #Schedule events for the CBR agents $ns at 0.0 "$s1 label \"S1\"" $ns at 0.0 "$s2 label \"S2\"" $ns at 0.0 "$s3 label \"S3\"" $ns at 0.0 "$n1 label \"N1\"" $ns at 0.0 "$n2 label \"N2\"" $ns at 0.0 "$n3 label \"N3\"" $ns at 0.0 "$n4 label \"N4\"" $ns at 0.0 "$n5 label \"N5\"" $ns at 0.0 "$d1 label \"D1\"" $ns at 0.0 "$d2 label \"D2\"" $ns at 0.0 "$d3 label \"D3\"" $ns at 0.0 "recordbw" #$ns at 0.0 "recordlost" $ns at 0.5 "$ftp0 start" $ns at 0.5 "$ftp1 start" $ns at 0.5 "$ftp2 start" #Call the finish procedure $ns at 100 "finish" #Run the simulation $ns run [...]...• Tốc độ mất gói trung bình của luồng (S3, D3) là thấp nhất và tốc độ mất gói của luồng (S1, D1) là cao nhất • Qua bài 4.4, ta thấy rằng giao thức TCP cho phép truyền dữ liệu một cách hiệu quả hơn giao thức UDP, ít mất gói hơn UDP do cơ chế phát hiện và thông báo lỗi khi truyền Tài liệu tham khảo • • • • • • http://forum.cntt2a2.com/Thread-cai-dat-ns-2-tren-ubuntu

Ngày đăng: 29/04/2016, 16:49

Từ khóa liên quan

Mục lục

  • LỜI MỞ ĐẦU

  • I. Đề bài

  • II. Lập kế hoạch phân công công việc

    • 2.1 Lập kế hoạch

    • 2.2 Phân công công việc

    • III. Quá trình thực hiện

      • 3.1 Chuẩn bị kiến thức để thực hiện mô phỏng

        • 3.1.1 Tìm hiểu về giao thức UDP

        • 3.1.2 Tìm hiểu về giao thức TCP

        • 3.1.3 Tracing

        • 3.1.4 Xgraph

        • 3.1.5 Thuật toán Max-Min Fairness

        • 3.2 Tiến hành mô phỏng

          • 1. Tính tốc độ phát gói

          • 2. Dựng kịch bản mô phỏng với tốc độ các luồng S1, S2, S3

          • 3. Vẽ đồ thị băng thông Ri(t) và tốc độ mất gói Ei(t) của các luồng

          • 4. Thay các luồng theo phân bố Poisson như trên bằng các luồng TCP

          • IV. Kết luận

          • Tài liệu tham khảo

          • Phụ lục

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan