Hcmute tìm hiểu ns (network simulator) ứng dụng mô phỏng mạng máy tính

70 25 0
Hcmute tìm hiểu ns (network simulator) ứng dụng mô phỏng mạng máy tính

Đ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Ộ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT THÀNH PHỐ HỒ CHÍ MINH BÁO CÁO TỔNG KẾT ÐỀ TÀI KH&CN CẤP TRƯỜNG TRỌNG ÐIỂM TÌM HIỂU NS (NETWORK SIMULATOR) ỨNG DỤNG MÔ PHỎNG MẠNG MÁY TÍNH Mã số: T2014-156 Chủ nhiệm đề tài: ThS NGUYỄN ÐANG QUANG S K C0 5 6 Tp Hồ Chí Minh, tháng 11/2014 Luan van BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT THÀNH PHỐ HỒ CHÍ MINH BÁO CÁO TỔNG KẾT ĐỀ TÀI KH&CN CẤP TRƯỜNG TÌM HIỂU NS (NETWORK SIMULATOR) ỨNG DỤNG MƠ PHỎNG MẠNG MÁY TÍNH Mã số: T2014-156 Chủ nhiệm đề tài: ThS NGUYỄN ĐĂNG QUANG TP HCM, 11 / 2014 Luan van Luan van Đề tài NCKH cấp trường T2014-156 MỤC LỤC CHƯƠNG 1: MỞ ĐẦU 1.1 Tổng quan 1.2 Đối tượng phạm vi nghiên cứu 1.3 Giới hạn phạm vi đề tài CHƯƠNG 2: TỔNG QUAN VỀ MƠ PHỎNG 2.1 2.2 Mơ biến cố rời rạc Xây dựng mơ hình mơ máy tính 12 CHƯƠNG 3: CÔNG CỤ MÔ PHỎNG NS-3 3.1 Tổng quan 14 3.2 Mơ hình thành phần mạng ns-3 15 3.3 Mô mạng ns-3 16 3.4 Một chương trình ví dụ 17 3.5 Con trỏ thông minh 18 3.6 Biểu diễn Packet ns-3 19 3.7 Biến cố ns-3 20 3.8 Biên dịch chạy mô 21 3.9 Phân tích kết 22 CHƯƠNG 4: THƯ VIỆN MƠ HÌNH MẠNG 4.1 Packets 25 4.2 Socket API 34 CHƯƠNG 5: CÀI ĐẶT VÀ MÔ PHỎNG VỚI NS-3 5.1 Cài đặt ns-3 37 5.2 Kiến trúc mô mạng ns-3 40 5.3 Một số chương trình mơ kết 43 CHƯƠNG 6: KẾT LUẬN 6.1 Những vấn đề thực 55 6.2 Hướng phát triển 55 TÀI LIỆU THAM KHẢO 56 Tìm hiều NS mơ mạng máy tính Luan van Đề tài NCKH cấp trường T2014-156 PHỤ LỤC A: Chương trình mơ mạng Point-To-Point 57 PHỤ LỤC B: Chương trình mơ mạng Point-To-Point (Python) 59 PHỤ LỤC C: Chương trình mơ mạng Ethernet 61 PHỤ LỤC D: Chương trình mơ mạng khơng dây 64 Tìm hiều NS mơ mạng máy tính Luan van Đề tài NCKH cấp trường T2014-156 DANH MỤC CHỮ VIẾT TẮT CSMA/CD Carrier Sense Multiple Access with Collision Detection FEL Future Event List NIC Network Interface Card NS Network Simulator Tìm hiều NS mơ mạng máy tính Luan van Đề tài NCKH cấp trường T2014-156 DANH MỤC HÌNH ẢNH Hình 1.1 Ngun lý mơ biến cố rời rạc Hình 1.2 Lưu đồ mơ biến cố rời rạc Hình 3.1 Tổ chức phần mềm ns-3 Hình 4.1 Lớp Packet Hình 4.2 Packet byte buffer Hình 4.3 Tổng quan native socket API Hình 5.1 Kiến trúc mơ mạng ns-3 Hình 5.2 Kết mơ Hình 5.3 Kết mô sau điều chỉnh thời gian trễ Hình 5.4 Kết mơ sau tăng số gói tin gửi thành Hình 5.5 Khơng có phản hồi từ server gói tin gửi đến cổng 11 thay Hình 5.6 Xem nội dung tracefile PCAP tcpdump Hình 5.7 Sơ đồ mạng mơ Hình 5.8 Kết mơ mạng CSMA Hình 5.9 Nội dung file second-0-0.pcap Hình 5.10 Nội dung file second-1-0.pcap Hình 5.11 Nội dung file second-2-0.pcap Hình 5.12 Sơ đồ mơ mạng khơng dây Hình 5.13 Kết mơ 5.2.3 Hình 5.14 Hình 5.15 Nội dung promicuous trace từ mạng wifi (third-0-1.pcap) Nội dung promicuous trace từ mạng CSMA (third-1-1.pcap) Tìm hiều NS mơ mạng máy tính Luan van Đề tài NCKH cấp trường T2014-156 ĐH SPKT TP HCM Đơn vị: Khoa Đào tạo Chất lượng cao THÔNG TIN KẾT QUẢ NGHIÊN CỨU Thơng tin chung: - Tên đề tài: Tìm hiểu NS (Network simulator) ứng dụng mơ mạng máy tính Mã số: T2014-156 Chủ nhiệm: GVC ThS Nguyễn Đăng Quang Cơ quan chủ trì: Trường Đại học Sư phạm Kỹ thuật TP.HCM Thời gian thực hiện: 1/2014-11/2013 Mục tiêu: Tìm hiểu ns-3 xây dựng số thực nghiệm mô mạng máy tính Tính sáng tạo: Kết nghiên cứu: - Báo cáo Sản phẩm: - Báo cáo khoa học, kết mô Hiệu quả, phương thức chuyển giao kết nghiên cứu khả áp dụng: - Tài liệu tham khảo mơ mạng máy tính Ngày tháng 11 năm 2014 Trưởng Đơn vị Chủ nhiệm đề tài (ký, họ tên, đóng dấu) (ký, họ tên) Tìm hiều NS mơ mạng máy tính Luan van Đề tài NCKH cấp trường T2014-156 INFORMATION ON RESEARCH RESULTS General information: Project title: A Study on NS (Network simulator) and Application to Computer Network Simulation Code number: T2014-156 Coordinator: Senior Lecturer, M.Eng Nguyễn Đăng Quang Implementing institution: University of Technical Education, HCMC Duration: from March 2014 to November 2014 Objective(s): - Study ns3 and practice on computer network simulation Creativeness and innovativeness: Research results: Report on simulation Products: Report and simulation results Effects, transfer alternatives of reserach results and applicability: To be used as reference materials on Computer Network Simulation Tìm hiều NS mơ mạng máy tính Luan van Đề tài NCKH cấp trường T2014-156 Chương 1: MỞ ĐẦU 1.1 Tổng quan Mô phương pháp thiếu để đặc tả, thiết kế phân tích mạng máy tính mạng truyền thơng Kỹ thuật sử dụng nhiều cấp độ từ nghiên cứu phần cứng đến mạng máy tính Tuy nhiên, để kết thu thập dự báo chinh xác đáp ứng hệ thống thực, tất tác động liên quan phải cung cấp đầy đủ mô hình mơ Tác vụ ln thách thức lớn khó mơ hình hóa mô nhiều mức khác cách độc lập Ngồi ra, việc tối ưu hóa hệ thống mức cao làm cho cấp độ hệ thống phụ thuộc lẫn Để nhận tất kết thống kê có liên quan phủ hết tất trường hợp – thời gian mô phải đủ dài Tuy nhiên, để tránh kéo dài thời gian mơ chí máy tính mạnh, việc mơ hình hóa khơng phải hợp lý mà cịn cần phải hiệu Tìm kiếm cách thức đắn để kết hợp mơ hình mô nhiều tầng vấn đề chinh để giải yêu cầu Việc sử dụng hệ thống xử lý song song cho phép thực mô đồng thời để đạt độ chinh xác cao nhiên, thời gian mô chưa đủ nhanh cho mô phức tạp Việc trừu tượng hóa ảnh hưởng từ tầng khác việc mơ hình hóa cách hiệu nhân tố để đạt tốc độ mơ cao, nhiên cần lưu ý thu thập đủ tất liệu liên quan để cung cấp cho hệ thống mơ Chính lý trên, nhà nghiên cứu nhà khoa học cần hiểu rõ khái niệm mơ hình hóa mơ áp dụng cho tầng hệ thống mạng Kết đề tài làm tài liệu tham khảo cho nghiên cứu viên thực nghiên cứu lý thuyết hệ thống mạng làm tài liệu tham khảo cho nghiên cứu sinh chuyên ngành hệ thống mạng 1.2 Đối tượng phạm vi nghiên cứu Đối tượng nghiên cứu Tìm hiều NS mơ mạng máy tính Luan van Đề tài NCKH cấp trường T2014-156 Hình 5.14: Nội dung promicuous trace từ mạng wifi (third-0-1.pcap) Nội dung promicuous trace từ mạng CSMA Hình 5.15: Nội dung promicuous trace từ mạng CSMA (third-1-1.pcap) Tìm hiều NS mơ mạng máy tính Luan van 53 Đề tài NCKH cấp trường T2014-156 CHƯƠNG 6: KẾT LUẬN 6.1 Những vấn đề thực Đề tài “Tìm hiểu NS (Network Simulator) ứng dụng mơ mạng máy tính” hồn thành mục tiêu đề ban đầu Những nội dung thực được:  Tìm hiểu lý thuyết mơ biến cố rời rạc,  Hệ thống phần mềm ns-3,  Thư viện mơ hình mạng ns-3,  Viết script mơ số mơ hình đơn giản Point-To-Point link, Mạng Ethernet, Mạng không dây sử dụng Access Point C++ Python,  Phân tích kết mơ từ PCAP Trace file tcpdump Wireshark 6.2 Hướng phát triển Tìm hiểu đầy đủ thư viện mơ hình, thực hiên mơ sơ đồ mạng phức tạp Tìm hiều NS mơ mạng máy tính Luan van 54 Đề tài NCKH cấp trường T2014-156 TÀI LIỆU THAM KHẢO Klaus Wehrle, Mesut Güne, James Gross , Modeling and Tools for Network Simulation, Springer ISBN 978-3-642-12330-6 http://www.nsnam.org/docs/release/3.14/tutorial/singlehtml/index.html# http://www.nsnam.org/documentation/ http://www.nsnam.org/doxygen Tìm hiều NS mơ mạng máy tính Luan van 55 Đề tài NCKH cấp trường T2014-156 PHỤ LỤC A Chương trình mô mạng Point-To-Point (C++) #include "ns3/core-module.h" #include "ns3/network-module.h" #include "ns3/internet-module.h" #include "ns3/point-to-point-module.h" #include "ns3/applications-module.h" using namespace ns3; NS_LOG_COMPONENT_DEFINE ("FirstScriptExample"); Int main (int argc, char *argv[]) { Time::SetResolution (Time::NS); LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO); LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO); NodeContainer nodes; nodes.Create (2); PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); NetDeviceContainer devices; devices = pointToPoint.Install (nodes); InternetStackHelper stack; stack.Install (nodes); Ipv4AddressHelper address; address.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer interfaces = address.Assign (devices); UdpEchoServerHelper echoServer (9); ApplicationContainer serverApps = echoServer.Install (nodes.Get (1)); serverApps.Start (Seconds (1.0)); serverApps.Stop (Seconds (10.0)); Tìm hiều NS mơ mạng máy tính Luan van 56 Đề tài NCKH cấp trường T2014-156 UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9); echoClient.SetAttribute ("MaxPackets", UintegerValue (1)); echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0))); echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); ApplicationContainer clientApps = echoClient.Install (nodes.Get (0)); clientApps.Start (Seconds (2.0)); clientApps.Stop (Seconds (10.0)); Simulator::Run (); Simulator::Destroy (); return 0; } Tìm hiều NS mơ mạng máy tính Luan van 57 Đề tài NCKH cấp trường T2014-156 PHỤ LỤC B Chương trình mơ mạng Point-To-Point (Python) import ns.applications import ns.core import ns.internet import ns.network import ns.point_to_point ns.core.LogComponentEnable("UdpEchoClientApplication", ns.core.LOG_LEVEL_INFO) ns.core.LogComponentEnable("UdpEchoServerApplication", ns.core.LOG_LEVEL_INFO) nodes = ns.network.NodeContainer() nodes.Create(2) pointToPoint = ns.point_to_point.PointToPointHelper() pointToPoint.SetDeviceAttribute("DataRate", ns.core.StringValue("5Mbps")) pointToPoint.SetChannelAttribute("Delay", ns.core.StringValue("2ms")) devices = pointToPoint.Install(nodes) stack = ns.internet.InternetStackHelper() stack.Install(nodes) address = ns.internet.Ipv4AddressHelper() address.SetBase(ns.network.Ipv4Address("10.1.1.0"), ns.network.Ipv4Mask("255.255.255.0")) interfaces = address.Assign (devices); echoServer = ns.applications.UdpEchoServerHelper(9) serverApps = echoServer.Install(nodes.Get(1)) serverApps.Start(ns.core.Seconds(1.0)) Tìm hiều NS mơ mạng máy tính Luan van 58 Đề tài NCKH cấp trường T2014-156 serverApps.Stop(ns.core.Seconds(10.0)) echoClient = ns.applications.UdpEchoClientHelper(interfaces.GetAddress(1), 9) echoClient.SetAttribute("MaxPackets", ns.core.UintegerValue(1)) echoClient.SetAttribute("Interval", ns.core.TimeValue(ns.core.Seconds (1.0))) echoClient.SetAttribute("PacketSize", ns.core.UintegerValue(1024)) clientApps = echoClient.Install(nodes.Get(0)) clientApps.Start(ns.core.Seconds(2.0)) clientApps.Stop(ns.core.Seconds(10.0)) ns.core.Simulator.Run() ns.core.Simulator.Destroy() Tìm hiều NS mơ mạng máy tính Luan van 59 Đề tài NCKH cấp trường T2014-156 PHỤ LỤC C Chương trình mơ mạng Ethernet #include "ns3/core-module.h" #include "ns3/network-module.h" #include "ns3/csma-module.h" #include "ns3/internet-module.h" #include "ns3/point-to-point-module.h" #include "ns3/applications-module.h" #include "ns3/ipv4-global-routing-helper.h" // Default Network Topology // // 10.1.1.0 // n0 n1 n2 n3 n4 // point-to-point | | | | // ================ // LAN 10.1.2.0 using namespace ns3; NS_LOG_COMPONENT_DEFINE ("SecondScriptExample"); int main (int argc, char *argv[]) { bool verbose = true; uint32_t nCsma = 3; CommandLine cmd; cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma); cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose); cmd.Parse (argc,argv); if (verbose) { LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO); Tìm hiều NS mơ mạng máy tính Luan van 60 Đề tài NCKH cấp trường T2014-156 LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO); } nCsma = nCsma == ? : nCsma; NodeContainer p2pNodes; p2pNodes.Create (2); NodeContainer csmaNodes; csmaNodes.Add (p2pNodes.Get (1)); csmaNodes.Create (nCsma); PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); NetDeviceContainer p2pDevices; p2pDevices = pointToPoint.Install (p2pNodes); CsmaHelper csma; csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps")); csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560))); NetDeviceContainer csmaDevices; csmaDevices = csma.Install (csmaNodes); InternetStackHelper stack; stack.Install (p2pNodes.Get (0)); stack.Install (csmaNodes); Ipv4AddressHelper address; address.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer p2pInterfaces; p2pInterfaces = address.Assign (p2pDevices); address.SetBase ("10.1.2.0", "255.255.255.0"); Ipv4InterfaceContainer csmaInterfaces; csmaInterfaces = address.Assign (csmaDevices); UdpEchoServerHelper echoServer (9); ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma)); Tìm hiều NS mơ mạng máy tính Luan van 61 Đề tài NCKH cấp trường T2014-156 serverApps.Start (Seconds (1.0)); serverApps.Stop (Seconds (10.0)); UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9); echoClient.SetAttribute ("MaxPackets", UintegerValue (1)); echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0))); echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); ApplicationContainer clientApps = echoClient.Install (p2pNodes.Get (0)); clientApps.Start (Seconds (2.0)); clientApps.Stop (Seconds (10.0)); Ipv4GlobalRoutingHelper::PopulateRoutingTables (); pointToPoint.EnablePcapAll ("second"); csma.EnablePcap ("second", csmaDevices.Get (1), true); Simulator::Run (); Simulator::Destroy (); return 0; } Tìm hiều NS mơ mạng máy tính Luan van 62 Đề tài NCKH cấp trường T2014-156 PHỤ LỤC D #include "ns3/core-module.h" #include "ns3/point-to-point-module.h" #include "ns3/network-module.h" #include "ns3/applications-module.h" #include "ns3/wifi-module.h" #include "ns3/mobility-module.h" #include "ns3/csma-module.h" #include "ns3/internet-module.h" // Default Network Topology // // Wifi 10.1.3.0 // AP // * * * * // | | | | 10.1.1.0 // n5 n6 n7 n0 n1 n2 n3 n4 // point-to-point | | | | // ================ // LAN 10.1.2.0 using namespace ns3; NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample"); Int main (int argc, char *argv[]) { bool verbose = true; uint32_t nCsma = 3; uint32_t nWifi = 3; CommandLine cmd; cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma); cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi); cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose); cmd.Parse (argc,argv); if (nWifi > 18) { std::cout

Ngày đăng: 02/02/2023, 10:17

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

Tài liệu liên quan