可能用到的部分api功能
记录一下,以防下次使用时忘记,查找麻烦
ns3::Ptr<ns3::Node> node = ns3::NodeList::GetNode(ns3::Simulator::GetContext());//获得节点
node->GetId();//节点ID
node->GetNDevices();//节点设备数量
node->GetDevice(i);//获得第I个设备
ns3::Ptr<ns3::WifiNetDevice> wifiDev=NetDevice->GetObject<ns3::WifiNetDevice>();//获得wifiNetDevice
ns3::Mac48Address addr=wifiDev->GetMac()->GetAddress();//获得mac地址
uint8_t buffer[6];
addr.CopyTo(buffer);//copy mac到buffer
addr.CopyFrom(buffer);//copy buffer到mac
ns3::Ptr<ns3::Channel> channel = Dev->GetChannel ();//获得channel
channel->GetNDevices ();//获得设备数量
channel->GetDevice (channelDeviceId);//获得第i个设备
Dev->GetNode();//获得设备对应的节点
利用ndnSIM仿真Vanet
ndnSIM中wifi全部用一个接口(face),所以直接仿真有问题
链接1: [ndnSIM] Fwd: Forwarding strategy for wireless network.
链接2: How to Implement NDN MANET over ndnSIM Simulator.
链接3: 高实时性命名数据移动自组织网络转发策略研究
pit-entry中加入mac地址
node中接入mac地址
fib-entry中加入mac地址
修改forwarder
目前实现(Vanet):
1.通过在pit-entry中的InRecord加入发送兴趣包的上一个节点的mac地址,并修改Entry::insertOrUpdateInRecord
,保证不同节点发送产生的InRecord不同
InRecordCollection::iterator
Entry::insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest)
{
auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
[&face,&interest] (const InRecord& inRecord) { return inRecord.getFace() == face&&inRecord.Mac48Addr==interest.getFromMac48(); });
if (it == m_inRecords.end()) {
InRecord tmp=InRecord(face);
uint8_t buffer[6];
interest.getFromMac48().CopyTo(buffer);//interest中也加入了mac地址,用的Mac48Address,用Address更好
tmp.Mac48Addr.CopyFrom(buffer);
m_inRecords.emplace_front(tmp);
it = m_inRecords.begin();
}
it->update(interest);
return it;
}
2.注释掉forwarder中onIncomingData的代码(因为在无线仿真中接口只有一个,不注释掉肯定发不出去)
if (pendingDownstream.get() == &inFace) {
continue;
}
3.策略中把canforwardto改为!violateScope,(此处参考链接: link.暂时未弄明白canforwarto部分作用)
// if (pitEntry->canForwardTo(*outFace))
if(!pitEntry->violatesScope(*outFace))
{
this->sendInterest(pitEntry, outFace);
return;
}
目前每个节点都会向周围广播,但已经能够发送兴趣包,接受数据包了