WAVE模块使用

2017-11-21  本文已影响0人  Olivia_SHEN

一. 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
上一篇下一篇

猜你喜欢

热点阅读