真是不能忍呀,弄NS3从安装到现在好久了,磨磨唧唧一个代码都http://没写出来。
现在计划把http://www.nsnam.org/下载的“ns-3 Tutorial”研读一下,可能会在这里把读的时候有意思的东西写出来,也可能不会。。。因为我懒。。。
1.NS3主要是用C++和Python编写,我就是这两个都不会,wonderful!
2.http://www.nsnam.org/wiki/Contributed_Code这个网址是用来给NS3作贡献用的,虽然我啥都不会,但是我还是想做贡献,我就是这么无私,3Q~
3.官方学习建议:
• Try to download and build a copy;
• Try to run a few sample programs;
• Look at simulation output, and try to adjust it.
我现在就是卡在第三步了,怎么改啊,改完了怎么编译啊之类的。。。
注:NS3的编译不是使用Make,而是使用waf(Python),这个让我很是困扰。。。For those interested in the gory(血淋淋) details of Waf, the main web site can be found athttp://code.google.com/p/waf/. 关于怎么使用waf,我决定另起一篇,“waf编译浅学”,这篇怎么办呢。。。我不管了 我先闪人了 去写那篇去
额 我又回来了,发现刚才那个是有特殊兴趣的人关注一下,我暂时还是保住我对NS3的兴趣吧。。。
这么周到,竟然提供了一个C++的学习网站,http://www.cplusplus.com/doc/tutorial/,好吧,我脸皮厚,我就是不看。
4.主要支持的环境实在Linux下。
The ns-3 system as a whole is a fairly complex system. 不能同意的更多。
5.安装文档已经写好啦,就在这里->xxxxxx,我还没有上传,因为我还在纠结要不要积分呢。。。
6.用优化方式编译,暂时不知道有什么用。。。
$ ./waf clean
$ ./waf --build-profile=optimized --enable-examples --enable-tests configure
7.debug模式
$ ./waf clean
$ ./waf --build-profile=debug --enable-examples --enable-tests configure
8.one waf
There is only one Waf script, at the top level of the ns-3 source tree. As you work, you may find yourself spending a lot of time in scratch/, or deep in src/..., and needing to invoke Waf.真理啊
9.运行方法
To run a program, simply use the --run option in Waf.
10.优化模式和debug模式的区别
参考6.7 debug模式开启log Component,可以看到程序中输出的log信息,优化模式关闭log Component。
11.节点作为基础操作单元
In ns-3 the basic computing device abstraction is called the node. This abstraction is represented in C++ by the class Node. The Node class provides methods for managing the representations of computing devices in simulations.
12.channel截图以太网的方式
The Channel class provides methods for managing communication subnetwork objects and connecting nodes to them.
13.Net Device网卡及驱动
A net device is “installed” in a Node in order to enable the Node to communicate with other Nodes in the simulation via Channels.不同的网络设备对应着不同的channel。
14.first.cc从这个程序以管窥豹一番
This is a script that will create a simple point-to-point link between two nodes and echo a single packet between the nodes.
对first.cc增加了英文注释,要说弄个这有啥用,可能只能让初学者(比如我)看到有人在一点一点的看代码吧。。。
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//give you the ability to load a group of files at a large granularity
#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"
//Compared to the using namespace std
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
int
main (int argc, char *argv[])
{
//The resolution to one nanosecond, which happens to be default value
Time::SetResolution (Time::NS);
//Enable two logging components that are built into the Echo Client and
//Echo Server applications
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
//Now we will get directly to the business of creating a topology
//and running a simulation. We use the topology helper objects to
//make this job as easy as possible.
//Declares a NodeContainer which we call nodes.
NodeContainer nodes;
//Call the Create method on the nodes object and asks the container
//to create two nodes.
//The container calls down into the ns-3 system proper to create two
//Node objects and stores pointers to those objects internally
nodes.Create (2);
//The next step in constructing a topology is to connect out nodes together into a network.
//In the real world, these terms correspond roughly to peripheral cards
//and network cables. Typically these two things are intimately tied
//together and one cannot expect to interchange, for example, Ethernet
//devices and wireless channels. Our Topology Helpers follow this intimate
//coupling and therefore you will use a single PointToPointHelper to
//configure and connect ns-3 PointToPointNetDevice and PointToPointChannel
//objects in this script.
//Instantiate a PointToPointHelper object on the stack.
PointToPointHelper pointToPoint;
//Most user-visible ns-3 objects have similar lists of Attributes.
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
//We will need to have a list of all of the NetDevice objects that are created,
//so we are a NetDeviceContainer to hold them just as we used a NodeContainer to
//hold the node we created.
//After executing the pointTopoint.Install (nodes) call we will have two node,
//each with an installed point-to-point net device and a single point-to-point
//channel between them. Both devices will be configured to transmit data at five
//megabits per second over the channel which has a two millisecond transmission delay.
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes);
//have some protocol stacks installed on our nodes.
InternetStackHelper stack;
stack.Install (nodes);
//By default the addresses allocated will start at one and increase monotonically,
//so the first address allocated from this base will be 10.1.1.1, followed by 10.1.1.2, etc.
//The low level ns-3 system actually remembers all of the IP address allocated.
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
//Performs the actual address assignment.
Ipv4InterfaceContainer interfaces = address.Assign (devices);
//Now we have a point-to-point network built, with stacks installed and IP address assigned.
//What we need at this point are applications to generate traffic.
//Port number
UdpEchoServerHelper echoServer (9);
//Install will return a container that holds pointers to all of the applications
ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
//Set the "RemoteAddress" and "RemotePort"
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
//Only send one packet.
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
//Change the start time.
//Schedule events.
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}