WAVE模块使用

一. Helpers

helpers包括:a)较低级别的MAC和PHY channel helpers,以及b)处理基本安全消息(BSM)的发送和接收的较高级application helpers。

较低级别的helpers包括ns3 :: YansWavePhyHelper,ns3 :: NqosWaveMacHelper,ns3 :: QosWaveMacHelper,ns3 :: Wifi80211pHelper和ns3 :: WaveHelper。

Wifi80211pHelper用于创建符合802.11p-2010标准的802.11p设备。 WaveHelper用于创建符合802.11p-2010和1609.4-2010标准(WAVE体系结构的MAC和PHY层)的WAVE设备。

ns3 :: NqosWaveMacHelper,ns3 :: QosWaveMacHelper和ns3 :: Wifi80211pHelper的关系如下所示:

从上面的图中,有两个Mac助手类都从WifiMacHelper继承; 当WAVE模块最初写入时,WifiMacHelper的专用版本(QoS和Nqos)已经从Wifi代码库中删除,但是WAVE助手仍然保留其区别。 WiFi 802.11p设备的功能可以通过WaveNetDevice的ContinuousAccess分配来实现,如果不需要多通道操作,建议使用Wifi80211pHelper。 用法如下:

NodeContainer nodes;
NetDeviceContainer devices;
nodes.Create (2);
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
NqosWave80211pMacHelper wifi80211pMac = NqosWaveMacHelper::Default();
Wifi80211pHelper 80211pHelper = Wifi80211pHelper::Default ();
devices = 80211pHelper.Install (wifiPhy, wifi80211pMac, nodes);

ns3 :: YansWavePhyHelper,ns3 :: QosWaveMacHelper和ns3 :: WaveHelper的关系如下所述:

从上图中可以看出,WaveHelper不是WifiHelper的子类,只能使用QosWaveMacHelper,因为WAVE MAC层是基于QoS机制的。 但是如果需要多通道操作的话,WaveHelper是推荐的。 用法如下:

NodeContainer nodes;
NetDeviceContainer devices;
nodes.Create (2);
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
YansWavePhyHelper wavePhy =  YansWavePhyHelper::Default ();
wavePhy.SetChannel (wifiChannel.Create ());
QosWaveMacHelper waveMac = QosWaveMacHelper::Default ();
WaveHelper waveHelper = WaveHelper::Default ();
devices = waveHelper.Install (wavePhy, waveMac, nodes);

更高级别的helpers包括ns3 :: WaveBsmStats和ns3 :: WaveBsmHelper。

WaveBsmStats用于收集和管理有关WAVE BSM数据包发送和接收的统计信息,例如数据包和字节数以及数据包传输率(PDR)。 WaveBsmHelper是被希望发送和接收BSM的应用程序使用。

ns3 :: WaveBsmHelper和WaveBsmStats的关系如下所述:

从<Your Vanet Routing Application>,用法如下:

//声明WAVE BSM helper实例
WaveBsmHelper m_waveBsmHelper
//接下来的这些都会被传递给WaveBsmHelpe::Install()
//NodeContainer m_adhocTxNodes(container of network node)
//NetDeviceContainer m_adhocTxDevices((transmitting) devices (1 per node) )
//Ipv4InterfaceContainer m_adhocTxInterfaces(IPv4 interfaces (1 per device))
//double m_TotalSimTime(total simulation time (in seconds))
//double m_waveInterval(WAVE BSM broadcast interval(seconds))
//double m_gpsAccuracyNs(time-synchronization accuracy of GPS devices,E.g., +/- 40ns)
//std::vector <double> m_txSafetyRanges(array of distances (m) at which safety PDR shall be determined)
//int64_t m_streamIndex(used to get consistent random numbers across scenarios)
m_waveBsmHelper.Install (m_adhocTxNodes,m_adhocTxDevices, m_adhocTxInterfaces,Seconds(m_TotalSimTime),m_wavePacketSize, Seconds(m_waveInterval), Time Seconds(m_gpsAccuracyNs / 1000000.0), m_txSafetyRanges);
//fix random number streams
m_streamIndex += m_waveBsmHelper.AssignStreams (m_streamIndex)

BSM statistics的使用方法如下:

//Get the cumulative PDR of the first safety Tx range
double bsm_pdr1 = m_waveBsmHelper.GetWaveBsmStats ()->GetBsmPdr (1);
//total WAVE BSM bytes sent
uint32_t cumulativeWaveBsmBytes = m_waveBsmHelper.GetWaveBsmStats ()->GetTxByteCount ();
//get number of WAVE BSM packets sent
int wavePktsSent = m_waveBsmHelper.GetWaveBsmStats ()->GetTxPktCount ();
// get number of WAVE BSM packets received 
int wavePktsReceived = m_waveBsmHelper.GetWaveBsmStats ()->GetRxPktCount ();
// reset count of WAVE BSM packets received 
m_waveBsmHelper.GetWaveBsmStats ()->SetRxPktCount (0);
// reset count of WAVE BSM packets sent 
m_waveBsmHelper.GetWaveBsmStats ()->SetTxPktCount (0);
// indicate that a node (nodeId) is moving. (set to 0 to “stop” node) 
WaveBsmHelper::GetNodesMoving()[nodeId] = 1;

二.APIs

MAC layer

802.11p设备可以通过使用不同的OrganizationIdentifier字段来识别差异,从而允许上层通过VSA管理帧来发送不同的信息。
1.创建一些Node对象和WifiNetDevice对象,例如一个sender一个receiver
2.receiver定义一个OrganizationIdentifier

uint8_t oi_bytes[5] = {0x00, 0x50, 0xC2, 0x4A, 0x40};
OrganizationIdentifier oi(oi_bytes,5);

3.receiver为OrganizationIdentifier定义一个Callback

VscCallback vsccall = MakeCallback(&VsaExample::GetWsaAndOi, this);

4.receiver注册这个标识符和功能

Ptr<WifiNetDevice> device1 = DynamicCast<WifiNetDevice>(nodes.Get (i)->GetDevice (0));
Ptr<OcbWifiMac> ocb1 = DynamicCast<OcbWifiMac>(device->GetMac ());
ocb1->AddReceiveVscCallback (oi, vsccall);

5.sender通过VAS帧传送管理信息

Ptr<Packet> vsc = Create<Packet> ();
ocb2->SendVsc (vsc, Mac48Address::GetBroadcast (), m_16093oi);

6.接着在receiver中被注册的callbacks会被调用。

MAC extension layer

WAVE设备允许上层用不同的控制方式进行路由。但是应遵循专用的API和调用顺序; 否则,报文可能会被设备丢弃。
1.创建一些Node对象和WifiNetDevice对象,例如一个sender一个receiver
2.如果是接受WSMP和IP-based消息,则receiver注册接受callback

// the class ``ns3::WaveNetDeviceExample``here will has a receive method "Receive" to be registered.
receiver->SetReceiveCallback (MakeCallback (&WaveNetDeviceExample::Receive, this));

3.如果是接受WSA帧,则receiver注册callback

// the class ``ns3::WaveNetDeviceExample``here will has a receive method "ReceiveVsa" to be registered.
receiver->SetWaveVsaCallback (MakeCallback  (&WaveNetDeviceExample::ReceiveVsa, this));

4.sender和receiver通过StartSch方法安排信道接入

// in this case that alternating access with non-immediate mode is assigned for sender and receiver devices.
//非即时模式的交替访问
const SchInfo schInfo = SchInfo (SCH1, false, EXTENDED_ALTERNATING);
Simulator::Schedule (Seconds (0.0), &WaveNetDevice::StartSch, sender, schInfo);
Simulator::Schedule (Seconds (0.0), &WaveNetDevice::StartSch, receiver, schInfo);

or

// in this case that continuous access with immediate mode is assigned for sender and receiver devices.
//即时模式的连续访问
const SchInfo schInfo = SchInfo (SCH1, true, EXTENDED_CONTINUOUS);
Simulator::Schedule (Seconds (0.0), &WaveNetDevice::StartSch, sender, schInfo);
Simulator::Schedule (Seconds (0.0), &WaveNetDevice::StartSch, receiver, schInfo)

or

// in this case that extended access with non-immediate mode is assigned for sender and receiver devices.
//非即时模式的扩展接入
const SchInfo schInfo = SchInfo (SCH1, false, 100);
Simulator::Schedule (Seconds (0.0), &WaveNetDevice::StartSch, sender, schInfo);
Simulator::Schedule (Seconds (0.0), &WaveNetDevice::StartSch, receiver, schInfo)

5.如果传送对的是IP-based消息,sender注册tx配置文件

// the IP-based packets will be transmitted in SCH1 with 6Mbps and 4 txPowerLevel with adaptable mode.
const TxProfile txProfile = TxProfile (SCH1, true, 4, WifiMode("OfdmRate6MbpsBW10MHz"));
Simulator::Schedule (Seconds (2.0), &WaveNetDevice::RegisterTxProfile, sender, txProfile);

6.sender通过SendX方法传输WSMP包

// the data rate and txPowerLevel is controlled by the high layer which are 6Mbps and 0 level here.
const TxInfo txInfo = TxInfo (CCH, 7, WifiMode("OfdmRate6MbpsBW10MHz"),  0);
// this packet will contain WSMP header when IEEE 1609.3 model is implemented
const static uint16_t WSMP_PROT_NUMBER = 0x88DC;
Ptr<Packet> wsaPacket  = Create<Packet> (100);
const Address dest = receiver->GetAddress ();
Simulator::Schedule (Seconds (2.0),  &WaveNetDevice::SendX, sender, wsaPacket, dest, WSMP_PROT_NUMBER, txInfo);

or

// the data rate and txPowerLevel is controlled by the MAC layer which are decided by WifiRemoteStationManager
const TxInfo txInfo = TxInfo (CCH, 7, WifiMode(),  8);
// this packet will contain WSMP header when IEEE 1609.3 model is implemented
const static uint16_t WSMP_PROT_NUMBER = 0x88DC;
Ptr<Packet> wsaPacket  = Create<Packet> (100);
const Address dest = receiver->GetAddress ();
Simulator::Schedule (Seconds (2.0),  &WaveNetDevice::SendX, sender, wsaPacket, dest, WSMP_PROT_NUMBER, txInfo);

7.sender通过Send方法传送IP-based包

const static uint16_t IPv6_PROT_NUMBER = 0x86DD;
Ptr<Packet> packet  = Create<Packet> (100);
const Address dest = receiver->GetAddress ();
Simulator::Schedule (Seconds (2.0),  &WaveNetDevice::Send, sender, packet, dest, IPv6_PROT_NUMBER);

8.sender通过StartVsa方法重复传送WSA帧

 // this packet will contain WSA management information when IEEE 1609.3 model is implemented
Ptr<Packet> wsaPacket = Create<Packet> (100);
Mac48Address dest = Mac48Address::GetBroadcast ();
const VsaInfo vsaInfo = VsaInfo (dest, OrganizationIdentifier (), 0, wsaPacket, SCH1, 100, VSA_TRANSMIT_IN_BOTHI);
Simulator::Schedule (Seconds (2.0), &WaveNetDevice::StartVsa, sender, vsaInfo);

9.sender通过StopVsa方法停止WSA帧的重复传送

Simulator::Schedule (Seconds (3.0), &WaveNetDevice::StopVsa, sender, SCH1);

10.sender和receiver通过StopSch方法释放信道

Simulator::Schedule (Seconds (4.0), &WaveNetDevice::StopSch, sender, SCH1);
Simulator::Schedule (Seconds (4.0), &WaveNetDevice::StopSch, receiver, SCH1);

11.sender和receiver通过ChangeAddress方法改变目前的MAC地址

Address newAddress = Mac48Address::Allocate ();
Simulator::Schedule (Seconds (4.0), &WaveNetDevice::ChangeAddress, sender, newAddress);

12.sender通过CancelTx方法取消特定类别和信道的所有传送

Simulator::Schedule (Seconds (4.0), &WaveNetDevice::CancelTx, sender, CCH,  AC_BE);

为了成功发送和接收这些数据包,应该执行正常和适当的调用过程。
A.对于WSMP,信道访问应分配给发送和接收。 如果不需要在另一个通道中传输,则通道访问释放操作可以是可选的。

StartSch -------------> SendX / ReceiveCallback -------------->  StopSch

B.对于IP,tx配置文件必须在传送和接收前被注册。如果不需要使用别的tx参数进行传送则删除tx配置文件的操作是可选的。信道接入和释放操作和WSMP是一样的。

StartSch -------------> RegisterTxProfile ----------> Send / ReceiveCallback -------------->  DeleteTxProfile -------------> StopSch

C.对于WSA,StartVsa在传送时需要被调用,而StopVsa是用于取消重复发送的可选操作。 频道访问分配和释放可选用法在这里也与WSMP相同。 为了接收VSA,WaveVsaCallback应该被注册; 否则,接收到的VSA帧将被MAC扩展层丢弃,无法传递到上层。

StartSch -------------> StartVsa / WaveVsaCallback -------------->  StopVsa ---------------> StopSch

D.如果上层想要在CCH中传递这些包,则不需要通过StartSch方法请求CCH,这意味着StartSch可以是可选的或者这里应该避免。原因是在WAVE设备被创建和初始化之后,默认的连续CCH访问已被自动分配。 因此,如果使用CCH作为参数调用StartSch和StopSch方法,则请求将被设备丢弃,并且方法将返回false以指示失败。

三.Attributes

通道间隔时间的默认值是在标准中定义的。 但是,当前的实现允许用户使用其他值配置这些属性。 这些属性包含在ns3 :: ChannelCoodinator类中,其配置路径如下所示。 建议使用IsValidConfig方法测试新配置是否遵循标准。

/NodeList/[i]/DeviceList/[i]/$ns3::WaveNetDevice/ChannelCoordinator/$ns3::ChannelCoordinator/CchInterval
/NodeList/[i]/DeviceList/[i]/$ns3::WaveNetDevice/ChannelCoordinator/$ns3::ChannelCoordinator/SchInterval
/NodeList/[i]/DeviceList/[i]/$ns3::WaveNetDevice/ChannelCoordinator/$ns3::ChannelCoordinator/GuardInterval

ns3 :: WaveNetDevice是一个包装类,它包含支持多通道操作的类。 要设置或获取这些对象的指针,用户还可以通过下面显示的配置路径来使用它们。

/NodeList/[i]/DeviceList/[i]/$ns3::WaveNetDevice/Mtu
/NodeList/[i]/DeviceList/[i]/$ns3::WaveNetDevice/Channel
/NodeList/[i]/DeviceList/[i]/$ns3::WaveNetDevice/PhyEntities
/NodeList/[i]/DeviceList/[i]/$ns3::WaveNetDevice/MacEntities
/NodeList/[i]/DeviceList/[i]/$ns3::WaveNetDevice/ChannelScheduler
/NodeList/[i]/DeviceList/[i]/$ns3::WaveNetDevice/ChannelManager
/NodeList/[i]/DeviceList/[i]/$ns3::WaveNetDevice/ChannelCoordinator
/NodeList/[i]/DeviceList/[i]/$ns3::WaveNetDevice/VsaManager

四.Output

对于802.11p设备,当前类别提供与WiFi设备相同类型的输出; 即ASCII和pcap跟踪和日志输出。 802.11p日志记录组件可以通过调用:

Wifi80211pHelper::EnableLogComponents ();

WAVE日志记录组件可以通过调用:

WaveHelper::EnableLogComponents ();

五.Advanced Usage

Advanced WaveHelper configuration

如果用户可以明确WAVE设备在哪个信道工作,可以设置明确的信道来节约资源。

// in this case, the MAC entities for SCH2 to SCH6 will not be created
WaveHelper helper = WaveHelper::Default ();
uint32_t channels[] = {CCH, SCH1};
std::vector<uint32_t> channelsVector (channels, channels + 2);
helper.CreateMacForChannel (channelsVector);

如果用户可以创建其他频道访问分配机制,例如 在可能被称为“ns3 :: AnotherScheduler”的更多PHY实体的情况下,他们可以使用这个帮助器来创建具有新分配机制的WAVE设备。 用法如下:

WaveHelper helper = WaveHelper::Default ();
helper.helper.CreateMacForChannel (ChannelManager::GetWaveChannels ());    // create all 7 MAC entites for WAVE
helper.CreatePhys (2);        // or other number which should be less than 7
helper.SetChannelScheduler ("ns3::AnotherScheduler");    // The AnotherScheduler should be implemented by users.
helper.SetRemoteStationManager ("ns3::ConstantRateWifiManager");    // or other  rate control algorithms
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,084评论 6 503
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,623评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,450评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,322评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,370评论 6 390
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,274评论 1 300
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,126评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,980评论 0 275
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,414评论 1 313
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,599评论 3 334
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,773评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,470评论 5 344
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,080评论 3 327
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,713评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,852评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,865评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,689评论 2 354

推荐阅读更多精彩内容

  • ns3-model-library.pdf wifi-model 翻译 wifi-model 33.1 Desig...
    shawn168阅读 12,372评论 0 9
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,654评论 18 139
  • Guide to BluetoothSecurity原文 本出版物可免费从以下网址获得:https://doi.o...
    公子小水阅读 7,984评论 0 6
  • WAVE是由IEEE规定的用于基于无线的车辆通信的系统架构。 本章介绍了ns-3中WAVE的可用模型。 重点是由i...
    Olivia_SHEN阅读 1,855评论 0 1
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,097评论 25 707