21
Ns(network simulator)- 3 2014/5/20 報報報 : 報報報 1

Ns(network simulator)-3

  • Upload
    olympe

  • View
    50

  • Download
    5

Embed Size (px)

DESCRIPTION

Ns(network simulator)-3. 2014/5/20 報告者 : 蘇宏仁. Programming languages: C++, Python Manage: Mercurial Compile: Waf Project started around mid 2006. Mercurial. 分散式控制系統 以 PYTHON 實作 - 容易擴充 有免費的線上資料庫可以使用 Bitbucket.org. Key Abstractions. Node Application Channel Net Device - PowerPoint PPT Presentation

Citation preview

Page 1: Ns(network simulator)-3

Ns(network simulator)-3

2014/5/20報告者 :蘇宏仁

1

Page 2: Ns(network simulator)-3

• Programming languages: C++, Python

• Manage: Mercurial

• Compile: Waf

• Project started around mid 2006

2

Page 3: Ns(network simulator)-3

Mercurial

• 分散式控制系統• 以 PYTHON實作 -容易擴充• 有免費的線上資料庫可以使用– Bitbucket.org

3

Page 4: Ns(network simulator)-3

Key Abstractions

• Node• Application• Channel• Net Device• Topology Helpers

4

Page 5: Ns(network simulator)-3

標準寫法• http://www.nsnam.org/developers/

contributing-code/coding-style/

5

Page 6: Ns(network simulator)-3

First.cc

• #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"

6

Page 7: Ns(network simulator)-3

• using namespace ns3;

• NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");

7

Page 8: Ns(network simulator)-3

Main Function

• Time::SetResolution (Time::NS);

• LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);

• LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);

8

Page 9: Ns(network simulator)-3

Topology Helpers

9

Page 10: Ns(network simulator)-3

NodeContainer

• NodeContainer nodes;• nodes.Create (2);

10

Page 11: Ns(network simulator)-3

PointToPointHelper

• PointToPointHelper pointToPoint;• pointToPoint.SetDeviceAttribute ("DataRate",

StringValue ("5Mbps"));• pointToPoint.SetChannelAttribute ("Delay",

StringValue ("2ms"));

11

Page 12: Ns(network simulator)-3

NetDeviceContainer

• NetDeviceContainer devices;• devices = pointToPoint.Install (nodes);

12

Page 13: Ns(network simulator)-3

InternetStackHelper

• InternetStackHelper stack;• stack.Install (nodes);

13

Page 14: Ns(network simulator)-3

Ipv4AddressHelper

• Ipv4AddressHelper address;• address.SetBase ("10.1.1.0", "255.255.255.0");• Ipv4InterfaceContainer interfaces =

address.Assign (devices);

14

Page 15: Ns(network simulator)-3

Applications

15

Page 16: Ns(network simulator)-3

UdpEchoServerHelper

• UdpEchoServerHelper echoServer (9);• ApplicationContainer serverApps =

echoServer.Install (nodes.Get (1));• serverApps.Start (Seconds (1.0));• serverApps.Stop (Seconds (10.0));

16

Page 17: Ns(network simulator)-3

UdpEchoClientHelper-1

• UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);

• echoClient.SetAttribute ("MaxPackets", UintegerValue (1));

• echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));

17

Page 18: Ns(network simulator)-3

UdpEchoClientHelper-2

• echoClient.SetAttribute ("PacketSize", UintegerValue (1024));

• ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));

• clientApps.Start (Seconds (2.0));• clientApps.Stop (Seconds (10.0));

18

Page 19: Ns(network simulator)-3

Simulator

19

Page 20: Ns(network simulator)-3

Simulator

• Simulator::Run ();• Simulator::Destroy ();• return 0;

20

Page 21: Ns(network simulator)-3

result

• 執行範例之後,會產生 .pcap的檔案• Tcpdump 可觀看 .pcap檔案內容• 代表真實封包的樣子

21