Fixed some known issues, mainly in the consumer

This commit is contained in:
Lv
2022-03-12 08:39:03 +08:00
parent 431bb31362
commit 03156c4857
6 changed files with 131 additions and 41 deletions
+75
View File
@@ -0,0 +1,75 @@
{
"files.associations": {
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"hash_map": "cpp",
"strstream": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"codecvt": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp"
}
}
@@ -392,7 +392,7 @@ GenericLinkService::decodeInterest(const Block& netPkt, const lp::Packet& firstP
}
if (firstPkt.has<lp::PathidTagField>()) {
interest->setTag(make_shared<lp::PathidTag>(firstPkt.get<lp::PahtidField>()));
interest->setTag(make_shared<lp::PathidTag>(firstPkt.get<lp::PathidTagField>()));
}
if (firstPkt.has<lp::RpTagField>()) {
+31 -19
View File
@@ -20,7 +20,7 @@ namespace ndn {
NS_OBJECT_ENSURE_REGISTERED(ConsumerMIRCC);
TypeId
ConsumerCbr::GetTypeId(void)
ConsumerMIRCC::GetTypeId(void)
{
static TypeId tid =
TypeId("ns3::ndn::ConsumerMIRCC")
@@ -49,20 +49,22 @@ ConsumerMIRCC::~ConsumerMIRCC()
{
}
void
ConsumerCbr::ScheduleNextPacket()
ConsumerMIRCC::ScheduleNextPacket()
{
std::printf("a");
// double mean = 8.0 * m_payloadSize / m_desiredRate.GetBitRate ();
// std::cout << "next: " << Simulator::Now().ToDouble(Time::S) + mean << "s\n";
/*
if (m_firstTime) {
m_sendEvent = Simulator::Schedule(Seconds(0.0), &Consumer::SendPacket, this);
m_sendEvent = Simulator::Schedule(Seconds(0.0), &Consumer::, this);
m_firstTime = false;
}
else if (!m_sendEvent.IsRunning())
m_sendEvent = Simulator::Schedule((m_random == 0) ? Seconds(1.0 / m_frequency)
: Seconds(m_random->GetValue()),
&Consumer::SendPacket, this);
&Consumer::SendPacket, this);*/
}
void
@@ -75,7 +77,8 @@ ConsumerMIRCC:: StopApplication()
while(it != pathId2EventId.end())
{
//取消发送事件
Simulator::Cancel(*it);
EventId tmp = it->second;
Simulator::Cancel(tmp);
//迭代器后移
it++;
@@ -91,7 +94,7 @@ ConsumerMIRCC:: StartApplication()
{
// 调用父类开启face等接口服务
App::Start=Application();
App::StartApplication();
// 调用路径探索
if (pathId2RandomId.size() == 0)
@@ -119,6 +122,7 @@ void
ConsumerMIRCC ::recordSeq(uint64_t seq,uint64_t randId)
{//记录seq到当时使用的randId
seq2RandomId[seq] = randId;
return;
}
void
@@ -171,11 +175,11 @@ ConsumerMIRCC ::SendPacket(uint64_t pathId,uint64_t classId)
//获取对应PathId(子流)对应的RandId。
uint64_t tmpRandId = pathId2RandomId[pathId];
//将RandId作为Tag设置到interest包中。
interest->setTag(make_shared<lp::RandomId>(tmpRandId));
interest->setTag(make_shared<lp::PathidTag>(tmpRandId));
interest->setTag(make_shared<lp::PTag>(classId));
//如果判断发现是随机数探索,则记录seq和随机数,用来收到data后把随机数和pathid绑定。
if (pathId == -1)
if (pathId == 0)
{
recordSeq(seq,tmpRandId);
}
@@ -190,7 +194,7 @@ ConsumerMIRCC ::SendPacket(uint64_t pathId,uint64_t classId)
//ScheduleNextPacket();
}
void
uint64_t
ConsumerMIRCC:: SumRp()
{
//获取遍历所有Rp的迭代器
@@ -199,13 +203,13 @@ ConsumerMIRCC:: SumRp()
//遍历所有Rp的迭代器
while (it != pathId2Rp.end())
{
res += *it;
res += it->second;
it++;
}
return res;
}
void
uint64_t
ConsumerMIRCC:: MaxRp()
{
//获取遍历所有Rp的迭代器
@@ -214,7 +218,7 @@ ConsumerMIRCC:: MaxRp()
//遍历所有Rp的迭代器
while (it != pathId2Rp.end())
{
res = max(res,*it);
res = std::max(res,it->second);
it++;
}
return res;
@@ -231,15 +235,16 @@ ConsumerMIRCC:: SchedulePacketForPathId(uint64_t pathId,uint64_t classId)
//发送
SendPacket(pathId,classId);
//预定下一次发送事件
pathId2EventId[pathId] = Simulator::Schedule(time::seconds(INTEREST_SIZE / max(tmpRp,INTEREST_SIZE), std::bind(&consumerMIRCC::SchedulePacketForPathId, this, pathId,classId));
//pathId2EventId[pathId] = Simulator::Schedule(time::seconds(INTEREST_SIZE / std::max(tmpRp,INTEREST_SIZE)), bind(&ConsumerMIRCC::SchedulePacketForPathId,this, pathId,classId));
pathId2EventId[pathId] = Simulator::Schedule(Seconds((double)INTEREST_SIZE / std::max(tmpRp,INTEREST_SIZE)), &ConsumerMIRCC::SchedulePacketForPathId,this, pathId,classId);
}else
{//发送第二类兴趣包
uint64_t tmpRp = pathId2Rs[pathId];
uint64_t tmpRs = pathId2Rs[pathId];
//发送
SendPacket(pathId,classId);
//预定下一次发送事件
pathId2EventId[pathId] = Simulator::Schedule(time::seconds(INTEREST_SIZE / max(tmpRs,INTEREST_SIZE), std::bind(&consumerMIRCC::SchedulePacketForPathId, this, pathId,classId));
//pathId2EventId[pathId] = Simulator::Schedule(time::seconds(INTEREST_SIZE / std::max(tmpRs,INTEREST_SIZE)), bind(&ConsumerMIRCC::SchedulePacketForPathId, this, pathId,classId));
pathId2EventId[pathId] = Simulator::Schedule(Seconds((double)INTEREST_SIZE / std::max(tmpRs,INTEREST_SIZE)), &ConsumerMIRCC::SchedulePacketForPathId, this, pathId,classId);
}
@@ -253,7 +258,7 @@ ConsumerMIRCC:: PathExplorate()
pathId2RandomId[-1] = m_rand->GetValue(0, std::numeric_limits<uint32_t>::max());
//PathId为-1表示正在进行路径探索
SendPacket(-1,1);
SendPacket(0,1);
//我们需要记录一下这个随机数用来探索路径了,记录其对应的seq编号
//用于在收到data时,将新的路径记录下来。
@@ -301,7 +306,14 @@ ConsumerMIRCC::OnData(shared_ptr<const Data> data)
NS_LOG_INFO("< DATA for " << seq);
//查看当前数据包是否有探索兴趣包产生,如果是的话将探索出的pathid和对应的randId绑定
tryBindRandId(seq, data->getTag<lp::PathidTag>());
auto tmpPathid = data->getTag<lp::PathidTag>();
if (tmpPathid != nullptr)
{
tryBindRandId(seq, *tmpPathid);
}
int hopCount = 0;
auto hopCountTag = data->getTag<lp::HopCountTag>();
+19 -16
View File
@@ -6,8 +6,8 @@
#include "ns3/ndnSIM/model/ndn-common.hpp"
#include "ndn-consumer.hpp"
#include "unorder"
#include <unordered_map>
#include <ndn-cxx/lp/tags.hpp>
namespace ns3 {
namespace ndn {
@@ -25,8 +25,8 @@ public:
* \brief Default constructor
* Sets up randomizer function and packet sequence number
*/
ConsumerCbr();
virtual ~ConsumerCbr();
ConsumerMIRCC();
virtual ~ConsumerMIRCC();
protected:
/**
@@ -45,12 +45,11 @@ protected:
StartApplication() override;
//相比原有的consumer,MIRCC第一步为先探索路径,而非直接发送
void
SendPacket(uint64_t pathId) override;
//void
//SendPacket(uint64_t pathId) override;
void
Ondata
OnData(shared_ptr<const Data> data) override;
protected:
//这两个目前没有用处
@@ -62,19 +61,19 @@ protected:
private:
//路径id到发送事件id的一一映射关系
unordered_map <uint64_t,EventId> pathId2EventId;
std:: unordered_map <uint64_t,EventId> pathId2EventId;
//路径id到路径随机数的一一映射关系(使用对应路径随机数使得路由器按该路径转发)
unordered_map <uint64_t,uint64_t> pathId2RandomId;
std:: unordered_map <uint64_t,uint64_t> pathId2RandomId;
//路径id到该路径Rp的一一映射关系
unorderer_map <uint64_t,uint64_t> pathId2Rp;
std:: unordered_map <uint64_t,uint64_t> pathId2Rp;
//路径id到该路径Rs的一一映射关系
unorderer_map <uint64_t,uint64_t> pahtId2Rs;
std:: unordered_map <uint64_t,uint64_t> pathId2Rs;
//
unorderer_map <uint64_t,uint64_t> seq2RandomId;
std:: unordered_map <uint64_t,uint64_t> seq2RandomId;
const uint64_t INTEREST_SIZE = 300;
@@ -83,19 +82,23 @@ private:
void PathExplorate();
//使用pathId发送
void SchedulePacketForPathId(uint64_t pathId);
void SchedulePacketForPathId(uint64_t pathId,uint64_t classId);
//计算所有Rp的速率之和
void SumRp();
uint64_t SumRp();
//计算所有Rp的速率最大值
void MaxRp();
uint64_t MaxRp();
//记录seq号和随机数,用于绑定pathid和randid。
void recordSeq();
void tryBindRandId(uint64_t seq, uint64_t pathId);
void recordSeq(uint64_t seq,uint64_t randId);
void SendPacket(uint64_t pathId,uint64_t classId);
};
@@ -180,10 +180,10 @@ typedef boost::mpl::set<
PrefixAnnouncementField,
HopCountTagField,
GeoTagField,
RsTag,
RpTag,
PathidTag,
PTag
RsTagField,
RpTagField,
PathidTagField,
PTagField
> FieldSet;
} // namespace lp
+1 -1
View File
@@ -332,7 +332,7 @@ namespace nfd {
//靠近producer的为hash值的高位
uint64_t hashNew = (hashOld * hashNum % hashMo + ingress.getFace().getId() % hashMo) % hashMo;
//给data设置新的hash值
data.setTag(make_shared<lp::HopCountTag>(hashNew));
data.setTag(make_shared<lp::PathidTag>(hashNew));
}