LoginSignup
0
0

More than 5 years have passed since last update.

パケットトレースにTCPヘッダ情報を表示する

Last updated at Posted at 2016-07-01

ネットワークシミュレータns-2の話です。

パケットトレースファイルに、TCPのヘッダ情報(シーケンス番号やACK番号など)が記載されると便利。

表示方法

そういうときは、以下のようにシナリオファイルに以下の1行を追加すればOK

シナリオファイル
# ↓ポイント
Trace set show_tcphdr_ 1; # trace-all shows tcp headers(default: 0)

set nf [open out.ns w]
$ns trace-all $nf

proc finish {} {
    global ns
    $ns flush-trace
    close $nf
    exit 0
}

変更前出力

r 1.000089 0 1 tcp 40 ------- 0 2.1 1.256 0 2
r 1.000166 0 1 tcp 40 ------- 0 2.1 1.256 1 4
r 1.00019 0 1 tcp 1500 ------- 0 2.1 1.256 1 5
r 1.000202 0 1 tcp 1500 ------- 0 2.1 1.256 1461 6
r 1.00029 0 1 tcp 1500 ------- 0 2.1 1.256 2921 9
r 1.000314 0 1 tcp 1500 ------- 0 2.1 1.256 4381 10
r 1.000326 0 1 tcp 1500 ------- 0 2.1 1.256 5841 12

変更後出力

osada@share1% grep 'r.*0\ 1\ tcp' out.ns
r 1.000089 0 1 tcp 40 ------- 0 2.1 1.256 0 2 -1 0xa 40 0
r 1.000166 0 1 tcp 40 ------- 0 2.1 1.256 1 4 1 0x10 40 0
r 1.00019 0 1 tcp 1500 ------- 0 2.1 1.256 1 5 1 0x10 40 0
r 1.000202 0 1 tcp 1500 ------- 0 2.1 1.256 1461 6 1 0x10 40 0
r 1.00029 0 1 tcp 1500 ------- 0 2.1 1.256 2921 9 1 0x10 40 0
r 1.000314 0 1 tcp 1500 ------- 0 2.1 1.256 4381 10 1 0x10 40 0
r 1.000326 0 1 tcp 1500 ------- 0 2.1 1.256 5841 12 1 0x10 40 0

シーケンス番号だけでなく、確認応答番号が見えて、ありがたい。

読み方

'-----'(フラグ)のあとから順番に、
* フロー番号:iph->flowid()
* 送信元ノード番号.ポート番号:src_nodeaddr.src_portaddr
* 送信先ノード番号.ポート番号:dst_nodeaddr.dst_portaddr
* シーケンス番号:seqno
* UID:th->uid()
* ACK番号:tcph->ackno()
* フラグ情報:tcph->flags()
* ヘッダ長:tcph->hlen()
* SA(SelectiveACK?)長:tcph->sa_length()

フラグは以下。OR演算した結果が入っている。例えば"0xa = TH_SYN | TH_PUSH"

#define TH_FIN  0x01        /* FIN: closing a connection */
#define TH_SYN  0x02        /* SYN: starting a connection */
#define TH_PUSH 0x08        /* PUSH: used here to "deliver" data */
#define TH_ACK  0x10        /* ACK: ack number is valid */
#define TH_ECE  0x40        /* ECE: CE echo flag */
#define TH_CWR  0x80        /* CWR: congestion window reduced */

実行環境

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0