NS-3 学习之mobility-trace-example.cc 分析

/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2012 University of Washington
 *
 * 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
 */

// Test that mobility tracing works
#include "ns3/core-module.h"
#include "ns3/mobility-module.h"
#include "ns3/network-module.h"

using namespace ns3;

int main(int argc, char *argv[]) {
	CommandLine cmd(__FILE__);
	cmd.Parse(argc, argv);

	NodeContainer sta;
	sta.Create(9);

	MobilityHelper mobility;
	/*
	 * SetPositionAllocator,设置位置分配器
	 * GridPositionAllocator,网格位置分配器
	 * MinX/MinY/DeltaX/DeltaY/GridWidth/LayoutType/RowFirst 是SetPositionAllocator的属性
	 * MinX/MinY 节点活动区域的起始坐标
	 * DeltaX/DeltaY 节点间的横纵坐标间隔
	 * GridWidth 网格宽度,即节点列数
	 * LayoutType 布局类型,行还是列优先
	 */
	mobility.SetPositionAllocator("ns3::GridPositionAllocator", "MinX",
			DoubleValue(1.0), "MinY", DoubleValue(1.0), "DeltaX",
			DoubleValue(5.0), "DeltaY", DoubleValue(5.0), "GridWidth",
			UintegerValue(3), "LayoutType", StringValue("RowFirst"));

//	mobility.SetMobilityModel("ns3::RandomWalk2dMobilityModel", "Mode",
//			StringValue("Time"), "Time", StringValue("2s"), "Speed",
//			StringValue("ns3::ConstantRandomVariable[Constant=1.0]"), "Bounds",
//			RectangleValue(Rectangle(0.0, 20.0, 0.0, 20.0)));
	/**
	 * SetMobilityModel 设置移动模型
	 * Time 2s,代表各节点每隔两秒改变一次速度和方向
	 * Speed ,速度,值是随机产生的,范围是1到10
	 * Bounds,节点游走边界,矩形区域,从左到右依次为X坐标最小值,X坐标最大值,Y坐标最小值和Y坐标最大值
	 */
	mobility.SetMobilityModel("ns3::RandomWalk2dMobilityModel", "Mode",
			StringValue("Time"), "Time", StringValue("2s"), "Speed",
			StringValue("ns3::UniformRandomVariable[Min=1.0|Max=10.0]"),
			"Bounds", RectangleValue(Rectangle(0.0, 200.0, 0.0, 200.0)));

	mobility.Install(sta);
	// Set mobility random number streams to fixed values
	mobility.AssignStreams(sta, 0);

	AsciiTraceHelper ascii;
	MobilityHelper::EnableAsciiAll(
			ascii.CreateFileStream("mobility-trace-example.mob"));

	Simulator::Stop(Seconds(5.0));
	Simulator::Run();
	Simulator::Destroy();
}

该源码源自NS-3 3.35 src/mobility/examples/mobility-trace-example.cc

该例子的主要意图是输出节点移动模型的跟踪文件mobility-trace-example.mob。我将移动模型的节点移动速率、范围等简单修改了下,主要目的是想看下随机速度运行效果。
1.初始运行效果

 

2.运行一段时间后的效果

 

3.trace 文件部分内容

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值