NS-TRACING

TRACING

The *ns-3 *tracing system is built on the concepts of independent tracing sources and tracing sinks, along with a uniformmechanism for connecting sources to sinks.

Trace sources are entities that can signal events that happen in a simulation and provide access to interesting underlyingdata. For example, a trace source could indicate when a packet is received by a net device and provide access to thepacket contents for interested trace sinks. A trace source might also indicate when an interesting state change happensin a model. For example, the congestion window of a TCP model is a prime candidate for a trace source. Every timethe congestion window changes connected trace sinks are notified with the old and new value.

Trace sources are not useful by themselves; they must be connected to other pieces of code that actually do somethinguseful with the information provided by the source. The entities that consume trace information are called trace sinks.Trace sources are generators of data and trace sinks are consumers. This explicit division allows for large numbers oftrace sources to be scattered around the system in places which model authors believe might be useful. Inserting tracesources introduces a very small execution overhead.

There can be zero or more consumers of trace events generated by a trace source. One can think of a trace source as akind of point-to-multipoint information link. Your code looking for trace events from a particular piece of core codecould happily coexist with other code doing something entirely different from the same information.

Unless a user connects a trace sink to one of these sources, nothing is output. By using the tracing system, both youand other people hooked to the same trace source are getting exactly what they want and only what they want out ofthe system. Neither of you are impacting any other user by changing what information is output by the system. If youhappen to add a trace source, your work as a good open-source citizen may allow other users to provide new utilitiesthat are perhaps very useful overall, without making any changes to the *ns-3 *core.

Callbacks

允許某處代碼訪問C++中某個函數(shù)和方法無需具體模塊之間的依賴。
根本上是你把訪問函數(shù)的地址視為變量漾根,函數(shù)指針搂抒。
每個trace source維護一個internal list of Callbacks戴涝。

class MyObject : public Object
{
public:
  /**
   * Register this type.
   * \return The TypeId.
   */
  static TypeId GetTypeId (void)
  {
    static TypeId tid = TypeId ("MyObject")
      .SetParent<Object> ()
      .SetGroupName ("Tutorial")
      .AddConstructor<MyObject> ()
      .AddTraceSource ("MyInteger",
                       "An integer value to trace.",
                       MakeTraceSourceAccessor (&MyObject::m_myInt),
                       "ns3::TracedValueCallback::Int32")
    ;
    return tid;
  }

  MyObject () {}
  TracedValue<int32_t> m_myInt;
};
void
IntTrace (int32_t oldValue, int32_t newValue)
{
  std::cout << "Traced " << oldValue << " to " << newValue << std::endl;
}
int
main (int argc, char *argv[])
{
  Ptr<MyObject> myObject = CreateObject<MyObject> ();
  myObject->TraceConnectWithoutContext ("MyInteger", MakeCallback (&IntTrace));

  myObject->m_myInt = 1234;
}

.AddTraceSource第一個屬性是trace source的名字声旺,在config system中可見钻蹬;
第二個屬性是幫助信息珠闰;
第三個屬性,使用要追蹤的TracedValue生成函數(shù)特征調用

The TracedValue<> declaration provides the infrastructure that drives the callback process. Any time the underlying value is changed the TracedValue mechanism will provide both the old and the new value of that variable, in thiscase an int32_t value. The trace sink function traceSink for this TracedValue will need the signature


Connect with Config

TraceConnectWithoutContext這種函數(shù)其實用的時候很少,大多數(shù)用Config來連接,底層調用合適的TraceConnect染乌。
Config系統(tǒng)用Config path來選擇trace source.

void ns3::Config::Connect
(
std::string path,
const CallbackBase & cb
)

Parameters
[in]path
A path to match trace sources.
[in]cb
The callback to connect to the matching trace sources.

This function will attempt to find all trace sources which match the input path and will then connect the input callback to them in such a way that the callback will receive an extra context string upon trace event notification.
通過TracedCallback類中重載的操作符()calls any registered trace sinks

拿CourseChange的例子更加深入底層的講了ns3的底層代碼如何構建TraceSource,以及Trace工作原理

Finding Sources

Okay, I know that there must be trace sources in the simulation core, but how do I find out what trace sources areavailable to me?

Finding Sources.png

Config Paths

Okay, I found a trace source, how do I figure out the Config path to use when I connect to it?

Detailed Description.png

/NodeList/[i]/$ns3::MobilityModel"
還可以使用命令搜索文件

find . -name '*.cc' | xargs grep CourseChange | grep Connect

找到實例 自己模仿著寫

Callback Signatures

Okay, I found a trace source and the Config path, how do I figure out what the return type and formal arguments ofmy callback function need to be?
一種方法去用上面的命令找到實例
一種方法是在API文檔里找
實在找不到的就找TracedCallback定義的變量

總結 自己寫一個trace source需要注冊.AddTraceSource,申明一個想要關注的TracedValue變量山孔,然后寫一個trace sink函數(shù)用來接收source發(fā)出的信息,在程序運行前把sink綁定到source上荷憋,這樣TracedValue在變化時執(zhí)行callback返回新舊兩個TracedValue值台颠。

To summarize, a trace source is, in essence, a variable that holds a list of callbacks. A trace sink is a function usedas the target of a callback. The Attribute and object type information systems are used to provide a way to connecttrace sources to trace sinks. The act of “hitting” a trace source is executing an operator on the trace source which firescallbacks. This results in the trace sink callbacks registering interest in the source being called with the parametersprovided by the source.

看了好幾天ns3的回調實現(xiàn),最后在ns3group里找到了答案勒庄,
https://groups.google.com/forum/#!topic/ns-3-users/xty2I8JV3_c
3.24 ps:想要看C++如何通過模板類實現(xiàn)回調 還要買書學習一下

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末串前,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子实蔽,更是在濱河造成了極大的恐慌荡碾,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,214評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件局装,死亡現(xiàn)場離奇詭異坛吁,居然都是意外死亡,警方通過查閱死者的電腦和手機铐尚,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,307評論 2 382
  • 文/潘曉璐 我一進店門拨脉,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人宣增,你說我怎么就攤上這事玫膀。” “怎么了统舀?”我有些...
    開封第一講書人閱讀 152,543評論 0 341
  • 文/不壞的土叔 我叫張陵匆骗,是天一觀的道長。 經(jīng)常有香客問我誉简,道長碉就,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,221評論 1 279
  • 正文 為了忘掉前任闷串,我火速辦了婚禮瓮钥,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己碉熄,他們只是感情好桨武,可當我...
    茶點故事閱讀 64,224評論 5 371
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著锈津,像睡著了一般呀酸。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上琼梆,一...
    開封第一講書人閱讀 49,007評論 1 284
  • 那天性誉,我揣著相機與錄音,去河邊找鬼茎杂。 笑死错览,一個胖子當著我的面吹牛,可吹牛的內容都是我干的煌往。 我是一名探鬼主播倾哺,決...
    沈念sama閱讀 38,313評論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼刽脖!你這毒婦竟也來了羞海?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 36,956評論 0 259
  • 序言:老撾萬榮一對情侶失蹤曲管,失蹤者是張志新(化名)和其女友劉穎扣猫,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體翘地,經(jīng)...
    沈念sama閱讀 43,441評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡申尤,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 35,925評論 2 323
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了衙耕。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片昧穿。...
    茶點故事閱讀 38,018評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖橙喘,靈堂內的尸體忽然破棺而出时鸵,到底是詐尸還是另有隱情,我是刑警寧澤厅瞎,帶...
    沈念sama閱讀 33,685評論 4 322
  • 正文 年R本政府宣布饰潜,位于F島的核電站,受9級特大地震影響和簸,放射性物質發(fā)生泄漏彭雾。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,234評論 3 307
  • 文/蒙蒙 一锁保、第九天 我趴在偏房一處隱蔽的房頂上張望薯酝。 院中可真熱鬧半沽,春花似錦、人聲如沸吴菠。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,240評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽做葵。三九已至占哟,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間酿矢,已是汗流浹背重挑。 一陣腳步聲響...
    開封第一講書人閱讀 31,464評論 1 261
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留棠涮,地道東北人。 一個月前我還...
    沈念sama閱讀 45,467評論 2 352
  • 正文 我出身青樓刺覆,卻偏偏與公主長得像严肪,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子谦屑,可洞房花燭夜當晚...
    茶點故事閱讀 42,762評論 2 345

推薦閱讀更多精彩內容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,389評論 0 23
  • 一直羨慕有厚一點兒的嘴唇 涂口紅也比較好看 一日在電視上看到泰勒 斯威夫特 指著和爸爸說 我也想要這樣的厚嘴唇 我...
    柳澤ESTHER閱讀 193評論 0 0
  • 本文參照一起學nodejs進行總結驳糯。 開始 下載mongodb,robomongo氢橙,webstorm酝枢,nodejs...
    WolfSheller閱讀 397評論 0 0
  • 我是江雄英,我堅持記錄最真實的自己悍手,這是我的原創(chuàng)日記第66天帘睦,show計劃第23天,我的每天越來越豐富坦康。 今天到市...
    阿英說保閱讀 272評論 0 0
  • 那天竣付,在一個朋友家里吃到特別美味的鹵牛肉,我連聲贊嘆好吃滞欠,問她是在哪里買的古胆。朋友微笑著有點小得意地說是她自己做的。...
    鳳舞清林閱讀 402評論 0 0