ns-3脚本初识——CSMA有线网络:second脚本
ps:本文所有文件和目录的默认根目录均为ns-3.29/。
该脚本默认拓扑结构如下:
10.1.1.0
n0 -------------- n1 n2 n3 n4
point-to-point | | | |
===================
LAN 10.1.2.0
n0和n1实现点到点通信(与first.cc中相似),n1~n4是个CSMA有线局域网。网络可以实现n0经由n1,和n4进行通信。
1.代码规范
/* -*- 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
*/
2.头文件
#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"
3.命名空间
using namespace ns3;
4.日志
NS_LOG_COMPONENT_DEFINE ("SecondScriptExample");
5.主函数声明
int
main (int argc, char *argv[])
{
…
}