經過這段時間對官方文檔的學習和理解,把對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);