ndnSIM学习(八)——examples之ndn-simple.cpp每个函数逐行剖析

前言

前面的文章ndnSIM学习(四)——examples之ndn-simple.cpp超详细剖析中,我们剖析了 ndn-simple.cpp 的每一行代码的大致功能。在这篇文章中,我将跳每一行代码的子函数里,对于每个子函数进行更加细致地剖析,用于分析每一行代码的工作机理

源代码

把代码还是再复制一遍

// ndn-simple.cpp

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/ndnSIM-module.h"

namespace ns3 {
   
   

int
main(int argc, char* argv[])
{
   
   
  // setting default parameters for PointToPoint links and channels
  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
  Config::SetDefault("ns3::QueueBase::MaxSize", StringValue("20p"));

  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  CommandLine cmd;
  cmd.Parse(argc, argv);

  // Creating nodes
  NodeContainer nodes;
  nodes.Create(3);

  // Connecting nodes using two links
  PointToPointHelper p2p;
  p2p.Install(nodes.Get(0), nodes.Get(1));
  p2p.Install(nodes.Get(1), nodes.Get(2));

  // Install NDN stack on all nodes
  ndn::StackHelper ndnHelper;
  ndnHelper.SetDefaultRoutes(true);
  ndnHelper.InstallAll();

  // Choosing forwarding strategy
  ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/multicast");

  // Installing applications

  // Consumer
  ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
  // Consumer will request /prefix/0, /prefix/1, ...
  consumerHelper.SetPrefix("/prefix");
  consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second
  auto apps = consumerHelper.Install(nodes.Get(0));                        // first node
  apps.Stop(Seconds(10.0)); // stop the consumer app at 10 seconds mark

  // Producer
  ndn::AppHelper producerHelper("ns3::ndn::Producer");
  // Producer will reply to all requests starting with /prefix
  producerHelper.SetPrefix("/prefix");
  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
  producerHelper.Install(nodes.Get(2)); // last node

  Simulator::Stop(Seconds(20.0));

  Simulator::Run();
  Simulator::Destroy();

  return 0;
}

} // namespace ns3

int
main(int argc, char* argv[])
{
   
   
  return ns3::main(argc, argv);
}

0、先聊聊Simulator

整个仿真的核心就在这个 Simulator 上了。其实总的来说,我们可以这么认为:前面的代码是在给 Simulator 配置一些 Config 或者 Event ,到了最后一起执行。

那么以 Simulator::Run() 为例,它是怎么实现的呢?点开一看,瞬间就惊了。好家伙,这家伙搁着玩踢皮球呢,把任务推给了 GetImpl() 返回的 SimulatorImpl * 了。

void 
Simulator
cmake --build . --target help The following are some of the valid targets for this Makefile: ... all (the default if no target is provided) ... clean ... depend ... edit_cache ... install ... install/local ... install/strip ... list_install_components ... rebuild_cache ... test ... Continuous ... ContinuousBuild ... ContinuousConfigure ... ContinuousCoverage ... ContinuousMemCheck ... ContinuousStart ... ContinuousSubmit ... ContinuousTest ... ContinuousUpdate ... Experimental ... ExperimentalBuild ... ExperimentalConfigure ... ExperimentalCoverage ... ExperimentalMemCheck ... ExperimentalStart ... ExperimentalSubmit ... ExperimentalTest ... ExperimentalUpdate ... Nightly ... NightlyBuild ... NightlyConfigure ... NightlyCoverage ... NightlyMemCheck ... NightlyMemoryCheck ... NightlyStart ... NightlySubmit ... NightlyTest ... NightlyUpdate ... build_info ... common ... ggml ... ggml-base ... ggml-cpu ... llama ... llama-batched ... llama-batched-bench ... llama-bench ... llama-cli ... llama-convert-llama2c-to-ggml ... llama-cvector-generator ... llama-diffusion-cli ... llama-embedding ... llama-eval-callback ... llama-export-lora ... llama-finetune ... llama-gemma3-cli ... llama-gen-docs ... llama-gguf ... llama-gguf-hash ... llama-gguf-split ... llama-imatrix ... llama-llava-cli ... llama-logits ... llama-lookahead ... llama-lookup ... llama-lookup-create ... llama-lookup-merge ... llama-lookup-stats ... llama-minicpmv-cli ... llama-mtmd-cli ... llama-parallel ... llama-passkey ... llama-perplexity ... llama-q8dot ... llama-quantize ... llama-qwen2vl-cli ... llama-retrieval ... llama-run ... llama-save-load-state ... llama-server ... llama-simple ... llama-simple-chat ... llama-speculative ... llama-speculative-simple ... llama-tokenize ... llama-tts ... llama-vdot ... mtmd ... sha1 ... sha256 ... test-alloc ... test-arg-parser ... test-autorelease ... test-backend-ops ... test-barrier ... test-c ... test-chat ... test-chat-parser ... test-chat-template ... test-gbnf-validator ... test-gguf ... test-grammar-integration ... test-grammar-parser ... test-json-partial ... test-json-schema-to-grammar ... test-llama-grammar ... test-log ... test-model-load-cancel ... test-mtmd-c-api ... test-opt ... test-quantize-fns ... test-quantize-perf ... test-quantize-stats ... test-regex-partial ... test-rope ... test-sampling ... test-thread-safety ... test-tokenizer-0 ... test-tokenizer-1-bpe ... test-tokenizer-1-spm ... xxhash
最新发布
10-04
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值