the result tell me my node wasn't move at all. can some body help me?
the program:
#include "ns3/core-module.h"
#include "ns3/simulator-module.h"
#include "ns3/node-module.h"
#include "ns3/helper-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
// Handoff Network Topology
//
// ʘ (Mobile_Station)⇛⇛⇛⇛⇛⇛⇛⇛⇛⇛⇛⇛⇛⇛ (向这个方向移动) (WIFI 10.1.3.0)(0,0,0 ----> )
//
//
//
// AP之间要保持距离,处于不能相互通信的距离内部。
//
//
//
// * (AP) *(AP)
// \ /
// \ /
// \ /
// \ /
// \ /
// \ /
// \ /
// \/
// ●
// Static_Node
using namespace ns3;
NS_LOG_COMPONENT_DEFINE("Hand-Off");
void CourseChange(std::string context, Ptr<const MobilityModel> model)
{
Vector position = model -> GetPosition();
NS_LOG_UNCOND(context << "x = " << position.x << ", y = " << position.y );
}
int main(int argc, char *argv[])
{
bool verbose = true;
uint32_t numAPs = 2;
CommandLine cmd;
cmd.AddValue("numAPs", "The number of APs", numAPs);
cmd.AddValue("verbose", "Tell Application to log if true", verbose);
cmd.Parse(argc, argv);
if (verbose) {
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
}
NodeContainer wifiStationNodes; //生成一个wifiStation节点
wifiStationNodes.Create(1);
NodeContainer wifiAPNodes; //生成numAPs数量的AP节点
wifiAPNodes.Create(numAPs);
NodeContainer p2pNodes; //生成三个p2p节点。
p2pNodes.Create(3);
PointToPointHelper p2pHelper; //生成p2p的链接helper
p2pHelper.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
p2pHelper.SetChannelAttribute("Delay", StringValue("2ms"));
NetDeviceContainer p2pDevices_AP1, p2pDevices_AP2; //出错了,这里要求必须是install的数量为两个
p2pDevices_AP1 = p2pHelper.Install(p2pNodes.Get(0), p2pNodes.Get(1));
p2pDevices_AP2 = p2pHelper.Install(p2pNodes.Get(0), p2pNodes.Get(2));
wifiAPNodes.Add(p2pNodes.Get(2)); //将p2pNodes的2号作为一个AP
wifiAPNodes.Add(p2pNodes.Get(1)); //将p2pNodes的1号作为一个AP
NodeContainer Static_Node; //将p2pNodes的2号作为固定的节点
Static_Node.Add(p2pNodes.Get(0));
YansWifiChannelHelper channel = YansWifiChannelHelper::Default(); //设置好物理层
YansWifiPhyHelper phy = YansWifiPhyHelper::Default();
phy.SetChannel(channel.Create());
WifiHelper wifi = WifiHelper::Default();
wifi.SetRemoteStationManager("ns3::AarfWifiManager");
NqosWifiMacHelper mac = NqosWifiMacHelper::Default (); //设置好Mac层
Ssid ssid = Ssid("Hand-Off-ns3");
mac.SetType("ns3::NqstaWifiMac", "Ssid", SsidValue(ssid), "ActiveProbing", BooleanValue(false));
NetDeviceContainer stationDevices; //将
stationDevices = wifi.Install(phy, mac, wifiStationNodes);
mac.SetType("ns3::NqapWifiMac", "Ssid", SsidValue(ssid));
NetDeviceContainer apDevices;
apDevices = wifi.Install(phy, mac, wifiAPNodes);
//下面是设置AP和station的位置
Vector AP1_Position(300.0, 200.0, 0.0); //第一个AP的位置
Vector AP2_Position(1000.0, 200.0, 0.0); //第二个AP的位置
Vector Static_Node_Position(700.0, 200.0, 0.0); //固定节点的位置
ListPositionAllocator myListPositionAllocator;
myListPositionAllocator.Add(AP1_Position);
myListPositionAllocator.Add(AP2_Position);
myListPositionAllocator.Add(Static_Node_Position);
MobilityHelper mobility;
mobility.SetPositionAllocator(&myListPositionAllocator);
/*
先设置一下固定的位置
*/
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); //将AP的位置固定,先设置为固定位置模型
mobility.Install(wifiAPNodes);
MobilityHelper stationMobilityHelper;
Ptr<ListPositionAllocator> stationPositionAlloc = CreateObject<ListPositionAllocator>();
stationPositionAlloc -> Add(Vector(0.0, 0.0, 0.0)); //it is the starting position
stationPositionAlloc -> Add(Vector(2000.0, 0.0, 0.0)); // it is the ending position that the station moves, i thought
stationMobilityHelper.SetPositionAllocator(stationPositionAlloc);
stationMobilityHelper.SetMobilityModel("ns3::ConstantVelocityMobilityModel");
stationMobilityHelper.Install(wifiStationNodes);
(wifiStationNodes.Get(0) -> GetObject<ConstantVelocityMobilityModel>()) -> SetVelocity(Vector(10.0, 0.0, 0.0));
mobility.Install(wifiStationNodes);
//上面是设置AP和station的位置
InternetStackHelper stack;
stack.Install(wifiStationNodes);
stack.Install(wifiAPNodes);
stack.Install(Static_Node);
Ipv4AddressHelper address;
address.SetBase("10.1.1.0", "255.255.255.0"); //将Point-2-Point部分的IP设置为 10.1.1.0
Ipv4InterfaceContainer p2pInterfaces_AP1, p2pInterfaces_AP2;
p2pInterfaces_AP1 = address.Assign(p2pDevices_AP1);
p2pInterfaces_AP2 = address.Assign(p2pDevices_AP2);
UdpEchoServerHelper echoServer(9);
ApplicationContainer servApps = echoServer.Install(Static_Node);
servApps.Start(Seconds(1.0));
servApps.Stop(Seconds(50.0));
Ipv4Address remoteAddress = Ipv4Address("10.1.4.1");
UdpEchoClientHelper echoClient(remoteAddress, 9);
ApplicationContainer clientApps = echoClient.Install(wifiStationNodes);
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(200.0));
Ipv4GlobalRoutingHelper::PopulateRoutingTables();
Simulator::Stop(Seconds(200.0));
AsciiTraceHelper ascii;
phy.EnableAsciiAll(ascii.CreateFileStream(
"phy.tr"));
std::ostringstream oss;
oss << "/NodeList/" << wifiStationNodes.Get(0)-> GetId() << "/$ns3::MobilityModel/CourseChange";
Config::Connect(oss.str(), MakeCallback(&CourseChange));
Simulator::Run();
Simulator::Destroy();
return 0;
}
[ Steve@bogon#/Applications/ns-allinone-3.9/ns-3.9 ] $:./waf --run scratch/Handoff-2nd-normal
Waf: Entering directory `/Applications/ns-allinone-3.9/ns-3.9/build'
[ 509/1059] cxx: scratch/Handoff-2nd-normal.cc -> build/debug/scratch/Handoff-2nd-normal_2.o
[1059/1059] cxx_link: build/debug/scratch/Handoff-2nd-normal_2.o -> build/debug/scratch/Handoff-2nd-normal
Waf: Leaving directory `/Applications/ns-allinone-3.9/ns-3.9/build'
'build' finished successfully (2.590s)
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
Sent 100 bytes to 10.1.4.1
the static node i put among the 2 AP seems don't get the message send from the mobile station. and the show position method seems don't called
what is wrong with my simulation?