• NDN helper 学习记录


    经过这段时间对官方文档的学习和理解,把对helper内容的学习记录下来,方便后续查看,如有错误,欢迎指正。

    1、StackHelper 主要用于在请求的节点上安装ndnSIM网络堆栈, 提供一种简单的方法来配置NDN模拟的几个重要参数。(官方解释)

      其实就是给结点装上堆栈

    方法:

    全部结点一次性安装(比较常用)
    ndn::StackHelper ndnHelper;
    ndnHelper.InstallAll();
    
    分别给结点安装,三种方式(通常用不到)
    install(const std::string &nodeName)          结点名
    install(Ptr< Node > node)                     结点
    install(const NodeContainer &c)               结点容器

    例1,通过结点容器创建的结点,利用get获得:
    // Creating nodes
    NodeContainer nodes;
    nodes.Create(3);
    ndn::StackHelper ndnHelper;

    ndnHelper.Install(nodes.Get(0));
    ndnHelper.Install(nodes.Get(1));
    ndnHelper.Install(nodes.Get(2));
    例2,在拓扑txt文件中创建的结点,直接寻名获得结点,注意寻名这个方式必须是在txt已经定义好了结点名,如果是例一这种创建结点的方式,是无法通过寻名的

    AnnotatedTopologyReader topologyReader("", 25);
    topologyReader.SetFileName("../ns-3/src/ndnSIM/examples/topologies/topo-grid-3x3.txt");
    topologyReader.Read();

    // Install NDN stack on all nodes
    ndn::StackHelper ndnHelper;
    ndnHelper.Install(Names::Find<Node>("Node0"));
    ndnHelper.Install(Names::Find<Node>("Node1"));
    ndnHelper.Install(Names::Find<Node>("Node2"));
    ndnHelper.Install(Names::Find<Node>("Node3"));

    2、FIB Helper,默认情况下,所有节点的FIB为空。您需要手动配置路由,使用全局路由控制器,或者(不建议)启用默认路由。

    两种方式:

    (1)手动路由

        通过以添加/从FIB表项中删除的下一跳或添加路由手动将FIB(FIB的手动配置)发送特殊兴趣命令给NFD的FIB管理器交互

    官方内容:
    Ptr<Node> node = ...     // some node
    std::string prefix = ... // some prefix
    Ptr<ndn::Face> face = ... // NDN face that belongs to the node and through which prefix is accessible
    int32_t metric = ...     // some routing metric
    FibHelper::AddRoute(node, prefix, face, metric);
    
    实际应用:
    ndn::FibHelper::AddRoute("c1", "/data", "n1", 1); // link to n1
    其中c1和n1是在拓扑文件中定义的结点名,/data是前缀,

    (2)自动最短路径路由

      为了简化大型拓扑中的FIB管理,ndnSIM包含一个全局路由控制器。

      为了利用全局路由控制器,有几个必要步骤:

    1、在节点上安装特殊接口
    NodeContainer nodes;
    GlobalRoutingHelper ndnGlobalRoutingHelper;
    ndnGlobalRoutingHelper.Install(nodes);
    
    2指定哪个节点导出哪个前缀
    Ptr<Node> producer; // producer node that exports prefix
    std::string prefix; // exported prefix
    ndnGlobalRoutingHelper.AddOrigins(prefix, producer);
    
    3、在每个节点上计算和安装FIB
    GlobalRoutingHelper::CalculateRoutes();

    示例见:
    https://ndnsim.net/current/examples.html 中9-node grid example

    3、StrategyChoiceHelper  转发策略

    可以指定单个或全部结点设置转发策略

    单个结点
    StrategyChoiceHelper::Install(nodes, prefix, strategyName);
    全部结点
    StrategyChoiceHelper::InstallAll(prefix, strategyName);
    
    示例
    ndn::StrategyChoiceHelper::InstallAll("/", "/localhost/nfd/strategy/best-route");

    4、Content Store 内容存储

    ndnSIM使用NFD的内容存储实现。

    (1)可以使用StackHelper :: setCsSize()来控制其最大大小 

    除非在模拟方案中指定,否则内容存储库的默认最大大小为100个数据包。

    ndnHelper.setCsSize(<max-size-in-packets>);
    ...
    ndnHelper.Install(nodes);

    (2)使用ndnHelper.setPolicy(<replacement-policy>)设置节点的缓存策略;

    官网实例,足够理解
    要在节点1上设置CS大小100,在节点2上设置大小1000,在所有其他节点上设置大小2000。节点1的LRU替换策略,其余部分的优先级FIFO:
    ndnHelper.setCsSize(100); ndnHelper.setPolicy("nfd::cs::lru"); ndnHelper.Install(node1); ndnHelper.setCsSize(1000); ndnHelper.setPolicy("nfd::cs::priority_fifo"); ndnHelper.Install(node2); NodeContainer allOtherNodes; for (NodeList::Iterator i = NodeList::Begin(); i != NodeList::End(); ++i) { if (*i != node1 && *i != node2) { allOtherNodes.Add(*i); } } ndnHelper.Install(allOtherNodes);

    缓存策略调用官网给的算法有两种方式:

      一种是新版的setPolicy,有两种算法:LRU,FIFO

      一种是旧版的SetOldContentStore,有多种算法,具体参考官网给出。

    5、AppHelper 用来创建应用程序,也就是我们我们所说的消费者和生产者

    1、为特定的应用程序类创建helper:
    // Create helper for the consumer generating Interests with constant rate
    AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
    
    2、使用AppHelper :: SetPrefix()分配在其上运行应用程序的前缀(使用此名称生成兴趣或为此名称满足兴趣):
    consumerHelper.SetPrefix(prefix);
    
    3、使用AppHelper :: SetAttribute()分配应用程序特定的属性:
    // Set frequency parameter
    consumerHelper.SetAttribute("Frequency", StringValue ("10")); // 10 interests a second
    
    4、在一个或多个节点上安装应用程序:
    NodeContainer nodes;
    ...
    consumerHelper.Install(nodes)
    这里只是一个简单的官方示例,具体的内容我会在后面的博客中提到

    6、LinkControlHelper 某些情况要求NDN节点之间的某些链接在某些时间失败。NS-3不提供实际“断开”节点之间链接的功能。但是,它提供了建立损耗模型以模拟通道中数据包丢失的便利。在点对点链路的两侧使用正确设置的损耗模型,可以模拟链路断开。

    允许调度链接故障和故障恢复

    #include "ns3/ndnSIM/helper/ndn-link-control-helper.hpp"
    
    ...
    
    Simulator::Schedule(Seconds(10.0), ndn::LinkControlHelper::FailLink, node1, node2);
    Simulator::Schedule(Seconds(15.0), ndn::LinkControlHelper::UpLink, node1, node2);
  • 相关阅读:
    模板---templates
    django框架基础
    文件操作
    C++异常处理基本句法测试
    模板类在包含友元情况下的分离编写
    C++中构造函数作用
    hex文件和bin文件区别
    Keil MDK 和 IAR 两款ARM开发工具区别比较
    ubuntu下安装stm32开发环境
    IAR安装破解教程
  • 原文地址:https://www.cnblogs.com/liuhui5599/p/11730439.html
Copyright © 2020-2023  润新知