[Python-modules-commits] [mrtparse] 01/05: Imported Upstream version 1.4
Vincent Bernat
bernat at moszumanska.debian.org
Mon Jul 11 09:20:14 UTC 2016
This is an automated email from the git hooks/post-receive script.
bernat pushed a commit to branch master
in repository mrtparse.
commit 0fd0563cabe4c0b5f9bd05f3d91baaa90722ee6b
Author: Vincent Bernat <bernat at debian.org>
Date: Mon Jul 11 10:33:11 2016 +0200
Imported Upstream version 1.4
---
MANIFEST.in | 1 +
PKG-INFO | 24 +
mrtparse.egg-info/PKG-INFO | 24 +
mrtparse.egg-info/SOURCES.txt | 26 +
mrtparse.egg-info/dependency_links.txt | 1 +
mrtparse.egg-info/top_level.txt | 1 +
mrtparse/__init__.py | 1 +
mrtparse/examples/README-ja.md | 231 ++++++
mrtparse/examples/README.md | 236 ++++++
mrtparse/examples/mrt2bgpdump.py | 301 ++++++++
mrtparse/examples/mrt2exabgp.py | 286 +++++++
mrtparse/examples/print_all.py | 455 +++++++++++
mrtparse/examples/slice.py | 101 +++
mrtparse/examples/summary.py | 146 ++++
mrtparse/mrtparse.py | 1322 ++++++++++++++++++++++++++++++++
mrtparse/samples/README-ja.md | 25 +
mrtparse/samples/README.md | 25 +
mrtparse/samples/bird6_bgp | Bin 0 -> 3166 bytes
mrtparse/samples/bird_bgp | Bin 0 -> 4610 bytes
mrtparse/samples/openbgpd_bgp | Bin 0 -> 8200 bytes
mrtparse/samples/openbgpd_rib_table | Bin 0 -> 2698 bytes
mrtparse/samples/openbgpd_rib_table-mp | Bin 0 -> 2805 bytes
mrtparse/samples/openbgpd_rib_table-v2 | Bin 0 -> 2143 bytes
mrtparse/samples/quagga_bgp | Bin 0 -> 6606 bytes
mrtparse/samples/quagga_rib | Bin 0 -> 1685 bytes
setup.cfg | 8 +
setup.py | 43 ++
27 files changed, 3257 insertions(+)
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..d3debd2
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1 @@
+graft mrtparse
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..0253d4a
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,24 @@
+Metadata-Version: 1.1
+Name: mrtparse
+Version: 1.4
+Summary: mrtparse is a module to read and analyze the MRT format data.
+Home-page: https://github.com/YoshiyukiYamauchi/mrtparse
+Author: Tetsumune KISO, Yoshiyuki YAMAUCHI, Nobuhiro ITOU
+Author-email: t2mune at gmail.com, info at greenhippo.co.jp, js333123 at gmail.com
+License: Apache License 2.0
+Description: UNKNOWN
+Keywords: mrt,bgp
+Platform: any
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: Intended Audience :: Developers
+Classifier: Topic :: System :: Networking
+Classifier: License :: OSI Approved :: Apache Software License
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.2
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: Implementation :: PyPy
diff --git a/mrtparse.egg-info/PKG-INFO b/mrtparse.egg-info/PKG-INFO
new file mode 100644
index 0000000..0253d4a
--- /dev/null
+++ b/mrtparse.egg-info/PKG-INFO
@@ -0,0 +1,24 @@
+Metadata-Version: 1.1
+Name: mrtparse
+Version: 1.4
+Summary: mrtparse is a module to read and analyze the MRT format data.
+Home-page: https://github.com/YoshiyukiYamauchi/mrtparse
+Author: Tetsumune KISO, Yoshiyuki YAMAUCHI, Nobuhiro ITOU
+Author-email: t2mune at gmail.com, info at greenhippo.co.jp, js333123 at gmail.com
+License: Apache License 2.0
+Description: UNKNOWN
+Keywords: mrt,bgp
+Platform: any
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: Intended Audience :: Developers
+Classifier: Topic :: System :: Networking
+Classifier: License :: OSI Approved :: Apache Software License
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.2
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: Implementation :: PyPy
diff --git a/mrtparse.egg-info/SOURCES.txt b/mrtparse.egg-info/SOURCES.txt
new file mode 100644
index 0000000..d013776
--- /dev/null
+++ b/mrtparse.egg-info/SOURCES.txt
@@ -0,0 +1,26 @@
+MANIFEST.in
+setup.cfg
+setup.py
+mrtparse/__init__.py
+mrtparse/mrtparse.py
+mrtparse.egg-info/PKG-INFO
+mrtparse.egg-info/SOURCES.txt
+mrtparse.egg-info/dependency_links.txt
+mrtparse.egg-info/top_level.txt
+mrtparse/examples/README-ja.md
+mrtparse/examples/README.md
+mrtparse/examples/mrt2bgpdump.py
+mrtparse/examples/mrt2exabgp.py
+mrtparse/examples/print_all.py
+mrtparse/examples/slice.py
+mrtparse/examples/summary.py
+mrtparse/samples/README-ja.md
+mrtparse/samples/README.md
+mrtparse/samples/bird6_bgp
+mrtparse/samples/bird_bgp
+mrtparse/samples/openbgpd_bgp
+mrtparse/samples/openbgpd_rib_table
+mrtparse/samples/openbgpd_rib_table-mp
+mrtparse/samples/openbgpd_rib_table-v2
+mrtparse/samples/quagga_bgp
+mrtparse/samples/quagga_rib
\ No newline at end of file
diff --git a/mrtparse.egg-info/dependency_links.txt b/mrtparse.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/mrtparse.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/mrtparse.egg-info/top_level.txt b/mrtparse.egg-info/top_level.txt
new file mode 100644
index 0000000..bc1e635
--- /dev/null
+++ b/mrtparse.egg-info/top_level.txt
@@ -0,0 +1 @@
+mrtparse
diff --git a/mrtparse/__init__.py b/mrtparse/__init__.py
new file mode 100644
index 0000000..23c36c7
--- /dev/null
+++ b/mrtparse/__init__.py
@@ -0,0 +1 @@
+from mrtparse import *
diff --git a/mrtparse/examples/README-ja.md b/mrtparse/examples/README-ja.md
new file mode 100644
index 0000000..1a3e68d
--- /dev/null
+++ b/mrtparse/examples/README-ja.md
@@ -0,0 +1,231 @@
+##スクリプトの作成例
+###print_all.py
+####内容
+MRT形式のファイルの内容を出力する
+####使用方法
+ print_all.py ファイルへのパス
+####出力例
+ ---------------------------------------------------------------
+ MRT Header
+ Timestamp: 1392828028(2014-02-20 01:40:28)
+ Type: 16(BGP4MP)
+ Subtype: 5(BGP4MP_STATE_CHANGE_AS4)
+ Length: 24
+ BGP4MP_STATE_CHANGE_AS4
+ Peer AS Number: 100
+ Local AS Number: 64512
+ Interface Index: 0
+ Address Family: 1(AFI_IPv4)
+ Peer IP Address: 192.168.1.21
+ Local IP Address: 192.168.1.100
+ Old State: 5(OpenConfirm)
+ New State: 6(Established)
+ ---------------------------------------------------------------
+ MRT Header
+ Timestamp: 1392828028(2014-02-20 01:40:28)
+ Type: 16(BGP4MP)
+ Subtype: 4(BGP4MP_MESSAGE_AS4)
+ ...
+
+エラーが発生した場合、以下のようにデータをバイトで表示する。
+
+ ---------------------------------------------------------------
+ MRT Header
+ Timestamp: 1442843462(2015-09-21 22:51:02)
+ Type: 16(BGP4MP)
+ Subtype: 5(BGP4MP_STATE_CHANGE_AS4)
+ Length: 12
+ MRT Data Error: Unsupported AFI 8(Unknown)
+ 00 00 00 00 00 00 00 00 00 01 00 08
+ ...
+ ---------------------------------------------------------------
+ MRT Header
+ Timestamp: 1443251615(2015-09-26 16:13:35)
+ Type: 16(BGP4MP)
+ Subtype: 2(BGP4MP_ENTRY)
+ Length: 80
+ MRT Data Error: Unsupported BGP4MP subtype 2(BGP4MP_ENTRY)
+ fd e8 fd e8 00 00 00 01 c0 a8 01 66 c0 a8 01 0a
+ 00 00 00 01 56 06 43 5f 00 01 01 04 c0 a8 00 0b
+ 10 c0 a8 00 2b 40 01 01 00 40 02 04 02 01 fd f3
+ 40 05 04 00 00 00 64 c0 07 08 00 00 fd e8 c0 a8
+ 00 0b 80 09 04 c0 a8 00 0b 80 0a 04 c0 a8 00 0a
+
+
+###mrt2exabgp.py (旧exabgp_conf.py)
+####内容
+MRT形式のファイルを[exabgp][exabgp_git]用のコンフィグ形式に変換して出力する。
+Exa-BGPのAPIに関して詳しく知りたい場合は、[Wiki][wiki]を読んで下さい。
+[exabgp_git]: https://github.com/Exa-Networks/exabgp
+[wiki]: https://github.com/YoshiyukiYamauchi/mrtparse/wiki
+####使用方法
+ 使用方法: mrt2exabgp.py [-h] [-r ルータID] [-l ローカルAS] [-p ピアAS]
+ [-L ローカルアドレス] [-n ネイバーのアドレス] [-4 [ネクストホップ]]
+ [-6 [ネクストホップ]] [-a] [-A] [-G [数値]]
+ ファイルのパス
+
+ このスクリプトはExaBGPのフォーマットに変換する
+
+ オプションなし引数:
+ ファイルのパス MRT形式のファイルのパスを指定する
+
+ オプションあり引数:
+ -h, --help ヘルプメッセージを表示して終了する
+ -r ルータID ルータIDを指定する (デフォルト: 192.168.0.1)
+ -l ローカルAS ローカルASを指定する (デフォルト: 64512)
+ -p ピアAS ピアASを指定する (デフォルト: 65000)
+ -L ローカルアドレス ローカルアドレスを指定する (デフォルト: 192.168.1.1)
+ -n ネイバーのアドレス ネイバーのアドレスを指定する (デフォルト: 192.168.1.100)
+ -4 [ネクストホップ] IPv4のエントリーを変換して、指定されていればそのネクストホップを使用する
+ -6 [ネクストホップ] IPv6のエントリーを変換して、指定されていればそのネクストホップを使用する
+ -a 全エントリを変換する (デフォルト: プレフィックスごとに最初のエントリーのみ)
+ -A ExaBGPのAPIのフォーマットに変換する
+ -G [数値] ExaBGPのAPIのフォーマットに変換して、指定されたプレフィックス数ごとに同じアトリビュートでグルーピングする
+ (デフォルト: 1000000)
+
+####出力例 (コンフィグフォーマット)
+ neighbor 192.168.1.1 {
+ router-id 192.168.0.2;
+ local-address 192.168.1.2;
+ local-as 64512;
+ peer-as 65000;
+ graceful-restart;
+ aigp enable;
+
+ static {
+ route 1.0.0.0/24 origin IGP as-path [57821 12586 13101 15169 ] community [12586:147 12586:13000 64587:13101] next-hop 192.168.1.254;
+ route 1.0.4.0/24 origin IGP as-path [57821 6939 4826 56203 ] next-hop 192.168.1.254;
+ route 1.0.5.0/24 origin IGP as-path [57821 6939 4826 56203 ] next-hop 192.168.1.254;
+ route 1.0.6.0/24 origin IGP as-path [57821 6939 4826 56203 ] next-hop 192.168.1.254;
+ route 1.0.7.0/24 origin IGP as-path [57821 6939 4826 56203 56203 56203 ] next-hop 192.168.1.254;
+ route 1.0.64.0/18 origin IGP as-path [57821 6939 4725 4725 7670 7670 7670 18144 ] atomic-aggregate aggregator (18144:219.118.225.189) next-hop 192.168.1.254;
+ route 1.0.128.0/17 origin IGP as-path [57821 12586 3257 38040 9737 ] atomic-aggregate aggregator (9737:203.113.12.254) community [12586:145 12586:12000 64587:3257] next-hop 192.168.1.254;
+ route 1.0.128.0/18 origin IGP as-path [57821 12586 3257 38040 9737 ] atomic-aggregate aggregator (9737:203.113.12.254) community [12586:145 12586:12000 64587:3257] next-hop 192.168.1.254;
+ ...
+ }
+ }
+
+####出力例 (APIフォーマット)
+ announce route 1.0.0.0/24 origin IGP as-path [57821 12586 13101 15169 ] community [12586:147 12586:13000 64587:13101] next-hop 192.168.1.254
+ announce route 1.0.4.0/24 origin IGP as-path [57821 6939 4826 56203 ] next-hop 192.168.1.254
+ announce route 1.0.5.0/24 origin IGP as-path [57821 6939 4826 56203 ] next-hop 192.168.1.254
+ announce route 1.0.6.0/24 origin IGP as-path [57821 6939 4826 56203 ] next-hop 192.168.1.254
+ announce route 1.0.7.0/24 origin IGP as-path [57821 6939 4826 56203 56203 56203 ] next-hop 192.168.1.254
+ announce route 1.0.64.0/18 origin IGP as-path [57821 6939 4725 4725 7670 7670 7670 18144 ] atomic-aggregate aggregator (18144:219.118.225.189) next-hop 192.168.1.254
+ announce route 1.0.128.0/17 origin IGP as-path [57821 12586 3257 38040 9737 ] atomic-aggregate aggregator (9737:203.113.12.254) community [12586:145 12586:12000 64587:3257] next-hop 192.168.1.254
+ announce route 1.0.128.0/18 origin IGP as-path [57821 12586 3257 38040 9737 ] atomic-aggregate aggregator (9737:203.113.12.254) community [12586:145 12586:12000 64587:3257] next-hop 192.168.1.254
+ ...
+
+####出力例 (APIグルーピングフォーマット)
+ announce attribute origin IGP as-path [57821 6939 4826 56203 ] next-hop 192.168.1.254 nlri 1.0.4.0/24 1.0.5.0/24 1.0.6.0/24 103.2.176.0/24 103.2.177.0/24 103.2.178.0/24 103.2.179.0/24
+ announce attribute origin IGP as-path [57821 6939 4826 56203 56203 56203 ] next-hop 192.168.1.254 nlri 1.0.7.0/24
+ announce attribute origin IGP as-path [57821 6939 4725 4725 7670 7670 7670 18144 ] atomic-aggregate aggregator (18144:219.118.225.189) next-hop 192.168.1.254 nlri 1.0.64.0/18 58.183.0.0/16 222.231.64.0/18
+ announce attribute origin IGP as-path [57821 12586 3257 38040 9737 ] atomic-aggregate aggregator (9737:203.113.12.254) community [12586:145 12586:12000 64587:3257] next-hop 192.168.1.254 nlri 1.0.128.0/17 1.0.128.0/18 1.0.192.0/18 1.2.128.0/17 1.4.128.0/17 1.4.128.0/18 1.179.128.0/17 101.51.0.0/16 101.51.64.0/18 113.53.0.0/16 113.53.0.0/18 118.172.0.0/16 118.173.0.0/16 118.173.192.0/18 118.174.0.0/16 118.175.0.0/16 118.175.0.0/18 125.25.0.0/16 125.25.128.0/18 180.180.0.0/16 182.52.0. [...]
+ announce attribute origin IGP as-path [4608 1221 4637 4651 9737 23969 ] next-hop 192.168.1.254 nlri 1.0.128.0/24
+ announce attribute origin IGP as-path [57821 12586 3257 1299 38040 9737 ] atomic-aggregate aggregator (9737:203.113.12.254) community [12586:145 12586:12000 64587:3257] next-hop 192.168.1.254 nlri 1.0.160.0/19 1.0.224.0/19 118.173.64.0/19 118.173.192.0/19 118.174.128.0/19 118.174.192.0/19 118.175.160.0/19 125.25.0.0/19 125.25.128.0/19 182.53.0.0/19 203.113.0.0/19 203.113.96.0/19
+ announce attribute origin IGP as-path [57821 12586 3257 4134 ] community [12586:145 12586:12000 64587:3257] next-hop 192.168.1.254 nlri 1.1.8.0/24 36.106.0.0/16 36.108.0.0/16 36.109.0.0/16 101.248.0.0/16 106.0.4.0/22 106.7.0.0/16 118.85.204.0/24 118.85.215.0/24 120.88.8.0/21 122.198.64.0/18 171.44.0.0/16 183.91.56.0/24 183.91.57.0/24 202.80.192.0/22 221.231.151.0/24
+ announce attribute origin IGP as-path [57821 12586 13101 15412 17408 58730 ] community [12586:147 12586:13000 64587:13101] next-hop 192.168.1.254 nlri 1.1.32.0/24 1.2.1.0/24 1.10.8.0/24 14.0.7.0/24 27.34.239.0/24 27.109.63.0/24 36.37.0.0/24 42.0.8.0/24 49.128.2.0/24 49.246.249.0/24 101.102.104.0/24 106.3.174.0/24 118.91.255.0/24 123.108.143.0/24 180.200.252.0/24 183.182.9.0/24 202.6.6.0/24 202.12.98.0/24 202.85.202.0/24 202.131.63.0/24 211.155.79.0/24 211.156.109.0/24 218.98.224.0/24 [...]
+ ...
+
+
+###slice.py
+####内容
+MRT形式のファイルについて、下記データをファイル出力する
+1. 指定された開始時間から終了時間までの指定された秒単位の間隔についてのデータ
+2. 指定された開始時間から終了時間までのデータ
+3. 指定された秒単位の間隔についてのデータ
+####使用方法
+ 使用方法: slice.py [-h] [-s 開始時間] [-e 終了時間] [-i 間隔] [-c {gz,bz2}]
+ ファイルのパス
+
+ このスクリプトはMRT形式のファイルを分割する
+
+ オプションなし引数:
+ ファイルのパス MRT形式のファイルのパスを指定する
+
+ オプションあり引数:
+ -h, --help ヘルプメッセージを表示して終了する
+ -s 開始時間 開始時間を YYYY-MM-DD HH:MM:SS の形式で指定する
+ -e 終了時間 終了時間を YYYY-MM-DD HH:MM:SS の形式で指定する
+ -i 間隔 ファイルを分割する間隔(秒)を指定する
+ -c {gz,bz2} 分割ファイルの圧縮形式(gz, bz2)を指定する
+####出力例
+ # slice.py -s '2015-04-26 03:26:00' -e '2014-04-26 03:27:00' -i 10 -c bz2 -f latest-update.gz
+ # ls
+ latest-update-20150426-032600.bz2
+ latest-update-20150426-032610.bz2
+ latest-update-20150426-032620.bz2
+ latest-update-20150426-032630.bz2
+ latest-update-20150426-032640.bz2
+ latest-update-20150426-032650.bz2
+
+
+###summary.py
+####内容
+MRT形式のファイルのサマリーを出力する
+####使用方法
+ summary.py ファイルへのパス
+####出力例
+ [2014-08-11 03:45:00 - 2014-08-11 03:49:59]
+ BGP4MP: 5973
+ BGP4MP_MESSAGE: 34
+ UPDATE: 24
+ KEEPALIVE: 10
+ BGP4MP_MESSAGE_AS4: 5896
+ UPDATE: 5825
+ KEEPALIVE: 71
+ BGP4MP_STATE_CHANGE_AS4: 43
+ Idle: 1
+ Connect: 20
+ Active: 18
+ OpenSent: 4
+
+
+###mrt2bgpdump.py
+####内容
+このスクリプトは[bgpdump][bgpdump]のフォーマットに変換する
+[bgpdump]: https://bitbucket.org/ripencc/bgpdump/wiki/Home
+####使用方法
+ 使用方法: mrt2bgpdump.py [-h] [-m] [-M] [-O [file]] [-s] [-v] [-t {dump,change}]
+ [-p] ファイルのパス
+
+ このスクリプトはbgpdumpのフォーマットに変換する
+
+ オプションなし引数:
+ ファイルのパス MRT形式のファイルのパスを指定する
+
+ オプションあり引数:
+ -h, --help ヘルプメッセージを表示して終了する
+ -m 1エントリに対して1行ずつUNIX時間で出力する
+ -M 1エントリに対して1行ずつわかりやすい時間形式で出力する(デフォルト動作)
+ -O [ファイル] 出力ファイルを指定する
+ -s 標準出力に出力する(デフォルト動作)
+ -v 標準エラー出力に出力する
+ -t {dump,change} MRTデータが出力された時間(dump)、または経路が追加された時間(change)で出力するかをを選択する
+ (デフォルト: dump)
+ -p 2番目のカラムにパケットのインデックスを追加する
+####出力例
+ BGP4MP|0|1438386900|A|193.0.0.56|3333|204.80.242.0/24|3333 1273 7922 33667 54169 54169 54169 54169 54169 54169 54169 54169|IGP|193.0.0.56|0|0|1273:21000|NAG||
+ BGP4MP|1|1438386900|A|2405:fc00::6|37989|2001:4c0:2001::/48|37989 4844 2914 174 855|IGP|2405:fc00::6|0|0||NAG||
+ BGP4MP|1|1438386900|A|2405:fc00::6|37989|2001:4c0:6002::/48|37989 4844 2914 174 855|IGP|2405:fc00::6|0|0||NAG||
+ BGP4MP|2|1438386900|A|146.228.1.3|1836|189.127.0.0/21|1836 174 12956 262589 27693|IGP|146.228.1.3|0|0|1836:110 1836:6000 1836:6031|NAG|27693 189.127.15.253|
+ BGP4MP|4|1438386900|A|2405:fc00::6|37989|2406:e400:1a::/48|37989 4844 7642|INCOMPLETE|2405:fc00::6|0|0||NAG||
+ BGP4MP|5|1438386900|A|2001:8e0:0:ffff::9|8758|2c0f:fe90::/32|8758 174 2914 30844 37105 37105 37105 36943|IGP|2001:8e0:0:ffff::9|0|0|174:21100 174:22005 8758:110 8758:301|NAG||
+ BGP4MP|6|1438386900|A|213.200.87.254|3257|187.110.144.0/20|3257 174 16735 27693 53117|IGP|213.200.87.254|0|10|3257:8093 3257:30235 3257:50002 3257:51100 3257:51102|NAG||
+ BGP4MP|7|1438386900|A|213.200.87.254|3257|187.95.16.0/20|3257 174 16735 27693 53081|IGP|213.200.87.254|0|10|3257:8063 3257:30252 3257:50002 3257:51300 3257:51302|NAG||
+ BGP4MP|8|1438386900|A|213.200.87.254|3257|189.127.208.0/21|3257 174 16735 27693 28235|IGP|213.200.87.254|0|10|3257:8093 3257:30235 3257:50002 3257:51100 3257:51102|NAG||
+ BGP4MP|8|1438386900|A|213.200.87.254|3257|189.127.216.0/21|3257 174 16735 27693 28235|IGP|213.200.87.254|0|10|3257:8093 3257:30235 3257:50002 3257:51100 3257:51102|NAG||
+ ...
+
+
+##作者
+Tetsumune KISO <t2mune at gmail.com>
+Yoshiyuki YAMAUCHI <info at greenhippo.co.jp>
+Nobuhiro ITOU <js333123 at gmail.com>
+
+ライセンス
+----------
+Licensed under the [Apache License, Version 2.0][Apache]
+Copyright © 2015 [greenHippo, LLC.][greenHippo]
+[Apache]: http://www.apache.org/licenses/LICENSE-2.0
+[greenHippo]: http://greenhippo.co.jp
diff --git a/mrtparse/examples/README.md b/mrtparse/examples/README.md
new file mode 100644
index 0000000..81d4125
--- /dev/null
+++ b/mrtparse/examples/README.md
@@ -0,0 +1,236 @@
+##Example Scripts
+###print_all.py
+####Description
+This script displays the contents of a MRT format file.
+####Usage
+ print_all.py <path to the file>
+####Result
+ ---------------------------------------------------------------
+ MRT Header
+ Timestamp: 1392828028(2014-02-20 01:40:28)
+ Type: 16(BGP4MP)
+ Subtype: 5(BGP4MP_STATE_CHANGE_AS4)
+ Length: 24
+ BGP4MP_STATE_CHANGE_AS4
+ Peer AS Number: 100
+ Local AS Number: 64512
+ Interface Index: 0
+ Address Family: 1(AFI_IPv4)
+ Peer IP Address: 192.168.1.21
+ Local IP Address: 192.168.1.100
+ Old State: 5(OpenConfirm)
+ New State: 6(Established)
+ ---------------------------------------------------------------
+ MRT Header
+ Timestamp: 1392828028(2014-02-20 01:40:28)
+ Type: 16(BGP4MP)
+ Subtype: 4(BGP4MP_MESSAGE_AS4)
+ ...
+
+If error occurred, it displays data in byte as below.
+
+ ---------------------------------------------------------------
+ MRT Header
+ Timestamp: 1442843462(2015-09-21 22:51:02)
+ Type: 16(BGP4MP)
+ Subtype: 5(BGP4MP_STATE_CHANGE_AS4)
+ Length: 12
+ MRT Data Error: Unsupported AFI 8(Unknown)
+ 00 00 00 00 00 00 00 00 00 01 00 08
+ ...
+ ---------------------------------------------------------------
+ MRT Header
+ Timestamp: 1443251615(2015-09-26 16:13:35)
+ Type: 16(BGP4MP)
+ Subtype: 2(BGP4MP_ENTRY)
+ Length: 80
+ MRT Data Error: Unsupported BGP4MP subtype 2(BGP4MP_ENTRY)
+ fd e8 fd e8 00 00 00 01 c0 a8 01 66 c0 a8 01 0a
+ 00 00 00 01 56 06 43 5f 00 01 01 04 c0 a8 00 0b
+ 10 c0 a8 00 2b 40 01 01 00 40 02 04 02 01 fd f3
+ 40 05 04 00 00 00 64 c0 07 08 00 00 fd e8 c0 a8
+ 00 0b 80 09 04 c0 a8 00 0b 80 0a 04 c0 a8 00 0a
+
+
+###mrt2exabgp.py (formerly exabgp_conf.py)
+####Description
+This script converts MRT format to [ExaBGP][exabgp_git] config/API format and displays it.
+If you want to know how to use ExaBGP API, please read [the wiki][wiki].
+[exabgp_git]: https://github.com/Exa-Networks/exabgp
+[wiki]: https://github.com/YoshiyukiYamauchi/mrtparse/wiki
+####Usage
+ usage: mrt2exabgp.py [-h] [-r ROUTER_ID] [-l LOCAL_AS] [-p PEER_AS]
+ [-L LOCAL_ADDR] [-n NEIGHBOR] [-4 [NEXT_HOP]]
+ [-6 [NEXT_HOP]] [-a] [-A] [-G [NUM]]
+ path_to_file
+
+ This script converts to ExaBGP format config.
+
+ positional arguments:
+ path_to_file specify path to MRT format file
+
+ optional arguments:
+ -h, --help show this help message and exit
+ -r ROUTER_ID specify router-id (default: 192.168.0.1)
+ -l LOCAL_AS specify local AS number (default: 64512)
+ -p PEER_AS specify peer AS number (default: 65000)
+ -L LOCAL_ADDR specify local address (default: 192.168.1.1)
+ -n NEIGHBOR specify neighbor address (default: 192.168.1.100)
+ -4 [NEXT_HOP] convert IPv4 entries and use IPv4 next-hop if specified
+ -6 [NEXT_HOP] convert IPv6 entries and use IPv6 next-hop if specified
+ -a convert all entries (default: convert only first entry per
+ one prefix)
+ -A convert to ExaBGP API format
+ -G [NUM] convert to ExaBGP API format and group updates with the same
+ attributes for each spceified the number of prefixes
+ (default: 1000000)
+
+####Result (Config format)
+ neighbor 192.168.1.1 {
+ router-id 192.168.0.2;
+ local-address 192.168.1.2;
+ local-as 64512;
+ peer-as 65000;
+ graceful-restart;
+ aigp enable;
+
+ static {
+ route 1.0.0.0/24 origin IGP as-path [57821 12586 13101 15169 ] community [12586:147 12586:13000 64587:13101] next-hop 192.168.1.254;
+ route 1.0.4.0/24 origin IGP as-path [57821 6939 4826 56203 ] next-hop 192.168.1.254;
+ route 1.0.5.0/24 origin IGP as-path [57821 6939 4826 56203 ] next-hop 192.168.1.254;
+ route 1.0.6.0/24 origin IGP as-path [57821 6939 4826 56203 ] next-hop 192.168.1.254;
+ route 1.0.7.0/24 origin IGP as-path [57821 6939 4826 56203 56203 56203 ] next-hop 192.168.1.254;
+ route 1.0.64.0/18 origin IGP as-path [57821 6939 4725 4725 7670 7670 7670 18144 ] atomic-aggregate aggregator (18144:219.118.225.189) next-hop 192.168.1.254;
+ route 1.0.128.0/17 origin IGP as-path [57821 12586 3257 38040 9737 ] atomic-aggregate aggregator (9737:203.113.12.254) community [12586:145 12586:12000 64587:3257] next-hop 192.168.1.254;
+ route 1.0.128.0/18 origin IGP as-path [57821 12586 3257 38040 9737 ] atomic-aggregate aggregator (9737:203.113.12.254) community [12586:145 12586:12000 64587:3257] next-hop 192.168.1.254;
+ ...
+ }
+ }
+
+####Result (API format)
+ announce route 1.0.0.0/24 origin IGP as-path [57821 12586 13101 15169 ] community [12586:147 12586:13000 64587:13101] next-hop 192.168.1.254
+ announce route 1.0.4.0/24 origin IGP as-path [57821 6939 4826 56203 ] next-hop 192.168.1.254
+ announce route 1.0.5.0/24 origin IGP as-path [57821 6939 4826 56203 ] next-hop 192.168.1.254
+ announce route 1.0.6.0/24 origin IGP as-path [57821 6939 4826 56203 ] next-hop 192.168.1.254
+ announce route 1.0.7.0/24 origin IGP as-path [57821 6939 4826 56203 56203 56203 ] next-hop 192.168.1.254
+ announce route 1.0.64.0/18 origin IGP as-path [57821 6939 4725 4725 7670 7670 7670 18144 ] atomic-aggregate aggregator (18144:219.118.225.189) next-hop 192.168.1.254
+ announce route 1.0.128.0/17 origin IGP as-path [57821 12586 3257 38040 9737 ] atomic-aggregate aggregator (9737:203.113.12.254) community [12586:145 12586:12000 64587:3257] next-hop 192.168.1.254
+ announce route 1.0.128.0/18 origin IGP as-path [57821 12586 3257 38040 9737 ] atomic-aggregate aggregator (9737:203.113.12.254) community [12586:145 12586:12000 64587:3257] next-hop 192.168.1.254
+ ...
+
+####Result (API grouping format)
+ announce attribute origin IGP as-path [57821 6939 4826 56203 ] next-hop 192.168.1.254 nlri 1.0.4.0/24 1.0.5.0/24 1.0.6.0/24 103.2.176.0/24 103.2.177.0/24 103.2.178.0/24 103.2.179.0/24
+ announce attribute origin IGP as-path [57821 6939 4826 56203 56203 56203 ] next-hop 192.168.1.254 nlri 1.0.7.0/24
+ announce attribute origin IGP as-path [57821 6939 4725 4725 7670 7670 7670 18144 ] atomic-aggregate aggregator (18144:219.118.225.189) next-hop 192.168.1.254 nlri 1.0.64.0/18 58.183.0.0/16 222.231.64.0/18
+ announce attribute origin IGP as-path [57821 12586 3257 38040 9737 ] atomic-aggregate aggregator (9737:203.113.12.254) community [12586:145 12586:12000 64587:3257] next-hop 192.168.1.254 nlri 1.0.128.0/17 1.0.128.0/18 1.0.192.0/18 1.2.128.0/17 1.4.128.0/17 1.4.128.0/18 1.179.128.0/17 101.51.0.0/16 101.51.64.0/18 113.53.0.0/16 113.53.0.0/18 118.172.0.0/16 118.173.0.0/16 118.173.192.0/18 118.174.0.0/16 118.175.0.0/16 118.175.0.0/18 125.25.0.0/16 125.25.128.0/18 180.180.0.0/16 182.52.0. [...]
+ announce attribute origin IGP as-path [4608 1221 4637 4651 9737 23969 ] next-hop 192.168.1.254 nlri 1.0.128.0/24
+ announce attribute origin IGP as-path [57821 12586 3257 1299 38040 9737 ] atomic-aggregate aggregator (9737:203.113.12.254) community [12586:145 12586:12000 64587:3257] next-hop 192.168.1.254 nlri 1.0.160.0/19 1.0.224.0/19 118.173.64.0/19 118.173.192.0/19 118.174.128.0/19 118.174.192.0/19 118.175.160.0/19 125.25.0.0/19 125.25.128.0/19 182.53.0.0/19 203.113.0.0/19 203.113.96.0/19
+ announce attribute origin IGP as-path [57821 12586 3257 4134 ] community [12586:145 12586:12000 64587:3257] next-hop 192.168.1.254 nlri 1.1.8.0/24 36.106.0.0/16 36.108.0.0/16 36.109.0.0/16 101.248.0.0/16 106.0.4.0/22 106.7.0.0/16 118.85.204.0/24 118.85.215.0/24 120.88.8.0/21 122.198.64.0/18 171.44.0.0/16 183.91.56.0/24 183.91.57.0/24 202.80.192.0/22 221.231.151.0/24
+ announce attribute origin IGP as-path [57821 12586 13101 15412 17408 58730 ] community [12586:147 12586:13000 64587:13101] next-hop 192.168.1.254 nlri 1.1.32.0/24 1.2.1.0/24 1.10.8.0/24 14.0.7.0/24 27.34.239.0/24 27.109.63.0/24 36.37.0.0/24 42.0.8.0/24 49.128.2.0/24 49.246.249.0/24 101.102.104.0/24 106.3.174.0/24 118.91.255.0/24 123.108.143.0/24 180.200.252.0/24 183.182.9.0/24 202.6.6.0/24 202.12.98.0/24 202.85.202.0/24 202.131.63.0/24 211.155.79.0/24 211.156.109.0/24 218.98.224.0/24 [...]
+ ...
+
+
+###slice.py
+####Description
+This script outputs the following data of a MRT format file.
+1. The data for the interval of the specified seconds from the specified start time to the specified end time.
+2. The data from the specified start time to the specified end time.
+3. The data for the interval of the specified seconds.
+####Usage
+ usage: slice.py [-h] [-s START_TIME] [-e END_TIME] [-i INTERVAL] [-c {gz,bz2}]
+ path_to_file
+
+ This script slices MRT format data.
+
+ positional arguments:
+ path_to_file specify path to MRT format file
+
+ optional arguments:
+ -h, --help show this help message and exit
+ -s START_TIME specify start time in format YYYY-MM-DD HH:MM:SS
+ -e END_TIME specify end time in format YYYY-MM-DD HH:MM:SS
+ -i INTERVAL specify interval in seconds
+ -c {gz,bz2} specify compress type (gz, bz2)
+
+####Result
+ # slice.py -s '2015-04-26 03:26:00' -e '2014-04-26 03:27:00' -i 10 -c bz2 -f latest-update.gz
+ # ls
+ latest-update-20150426-032600.bz2
+ latest-update-20150426-032610.bz2
+ latest-update-20150426-032620.bz2
+ latest-update-20150426-032630.bz2
+ latest-update-20150426-032640.bz2
+ latest-update-20150426-032650.bz2
+
+
+###summary.py
+####Description
+This script displays the summary of a MRT format file.
+####Usage
+ summary.py <path to the file>
+####Result
+ [2014-08-11 03:45:00 - 2014-08-11 03:49:59]
+ BGP4MP: 5973
+ BGP4MP_MESSAGE: 34
+ UPDATE: 24
+ KEEPALIVE: 10
+ BGP4MP_MESSAGE_AS4: 5896
+ UPDATE: 5825
+ KEEPALIVE: 71
+ BGP4MP_STATE_CHANGE_AS4: 43
+ Idle: 1
+ Connect: 20
+ Active: 18
+ OpenSent: 4
+
+
+###mrt2bgpdump.py
+####Description
+This script converts to [bgpdump][bgpdump] format.
+[bgpdump]: https://bitbucket.org/ripencc/bgpdump/wiki/Home
+####Usage
+ usage: mrt2bgpdump.py [-h] [-m] [-M] [-O [file]] [-s] [-v] [-t {dump,change}]
+ [-p]
+ path_to_file
+
+ This script converts to bgpdump format.
+
+ positional arguments:
+ path_to_file specify path to MRT format file
+
+ optional arguments:
+ -h, --help show this help message and exit
+ -m one-line per entry with unix timestamps
+ -M one-line per entry with human readable timestamps(default
+ format)
+ -O [file] output to a specified file
+ -s output to STDOUT(default output)
+ -v output to STDERR
+ -t {dump,change} timestamps for RIB dumps reflect the time of the dump or
+ the last route modification(default: dump)
+ -p show packet index at second position
+####Result
+ BGP4MP|0|1438386900|A|193.0.0.56|3333|204.80.242.0/24|3333 1273 7922 33667 54169 54169 54169 54169 54169 54169 54169 54169|IGP|193.0.0.56|0|0|1273:21000|NAG||
+ BGP4MP|1|1438386900|A|2405:fc00::6|37989|2001:4c0:2001::/48|37989 4844 2914 174 855|IGP|2405:fc00::6|0|0||NAG||
+ BGP4MP|1|1438386900|A|2405:fc00::6|37989|2001:4c0:6002::/48|37989 4844 2914 174 855|IGP|2405:fc00::6|0|0||NAG||
+ BGP4MP|2|1438386900|A|146.228.1.3|1836|189.127.0.0/21|1836 174 12956 262589 27693|IGP|146.228.1.3|0|0|1836:110 1836:6000 1836:6031|NAG|27693 189.127.15.253|
+ BGP4MP|4|1438386900|A|2405:fc00::6|37989|2406:e400:1a::/48|37989 4844 7642|INCOMPLETE|2405:fc00::6|0|0||NAG||
+ BGP4MP|5|1438386900|A|2001:8e0:0:ffff::9|8758|2c0f:fe90::/32|8758 174 2914 30844 37105 37105 37105 36943|IGP|2001:8e0:0:ffff::9|0|0|174:21100 174:22005 8758:110 8758:301|NAG||
+ BGP4MP|6|1438386900|A|213.200.87.254|3257|187.110.144.0/20|3257 174 16735 27693 53117|IGP|213.200.87.254|0|10|3257:8093 3257:30235 3257:50002 3257:51100 3257:51102|NAG||
+ BGP4MP|7|1438386900|A|213.200.87.254|3257|187.95.16.0/20|3257 174 16735 27693 53081|IGP|213.200.87.254|0|10|3257:8063 3257:30252 3257:50002 3257:51300 3257:51302|NAG||
+ BGP4MP|8|1438386900|A|213.200.87.254|3257|189.127.208.0/21|3257 174 16735 27693 28235|IGP|213.200.87.254|0|10|3257:8093 3257:30235 3257:50002 3257:51100 3257:51102|NAG||
+ BGP4MP|8|1438386900|A|213.200.87.254|3257|189.127.216.0/21|3257 174 16735 27693 28235|IGP|213.200.87.254|0|10|3257:8093 3257:30235 3257:50002 3257:51100 3257:51102|NAG||
+ ...
+
+
+##Authors
+Tetsumune KISO <t2mune at gmail.com>
+Yoshiyuki YAMAUCHI <info at greenhippo.co.jp>
+Nobuhiro ITOU <js333123 at gmail.com>
+
+License
+----------
+Licensed under the [Apache License, Version 2.0][Apache]
+Copyright © 2015 [greenHippo, LLC.][greenHippo]
+[Apache]: http://www.apache.org/licenses/LICENSE-2.0
+[greenHippo]: http://greenhippo.co.jp
diff --git a/mrtparse/examples/mrt2bgpdump.py b/mrtparse/examples/mrt2bgpdump.py
new file mode 100755
index 0000000..de6ea94
--- /dev/null
+++ b/mrtparse/examples/mrt2bgpdump.py
@@ -0,0 +1,301 @@
+#!/usr/bin/env python
+'''
+mrt2bgpdump.py - a script to convert MRT format to bgpdump format.
+
+Copyright (C) 2015 greenHippo, LLC.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Authors:
+ Tetsumune KISO <t2mune at gmail.com>
+ Yoshiyuki YAMAUCHI <info at greenhippo.co.jp>
+ Nobuhiro ITOU <js333123 at gmail.com>
+'''
+
+import sys, argparse, copy
+from datetime import *
+from mrtparse import *
+
+peer = None
+
+def parse_args():
+ p = argparse.ArgumentParser(
+ description='This script converts to bgpdump format.')
+ p.add_argument(
+ '-m', dest='verbose', default=False, action='store_true',
+ help='one-line per entry with unix timestamps')
+ p.add_argument(
+ '-M', dest='verbose', action='store_false',
+ help='one-line per entry with human readable timestamps(default format)')
+ p.add_argument(
+ '-O', dest='output', default=sys.stdout, nargs='?', metavar='file',
+ type=argparse.FileType('w'),
+ help='output to a specified file')
+ p.add_argument(
+ '-s', dest='output', action='store_const', const=sys.stdout,
+ help='output to STDOUT(default output)')
+ p.add_argument(
+ '-v', dest='output', action='store_const', const=sys.stderr,
+ help='output to STDERR')
+ p.add_argument(
+ '-t', dest='ts_format', default='dump', choices=['dump', 'change'],
+ help='timestamps for RIB dumps reflect the time of the dump \
+ or the last route modification(default: dump)')
+ p.add_argument(
+ '-p', dest='pkt_num', default=False, action='store_true',
+ help='show packet index at second position')
+ p.add_argument(
+ 'path_to_file',
+ help='specify path to MRT format file')
+ return p.parse_args()
+
+class BgpDump:
+ __slots__ = [
+ 'verbose', 'output', 'ts_format', 'pkt_num', 'type', 'num', 'ts',
+ 'org_time', 'flag', 'peer_ip', 'peer_as', 'nlri', 'withdrawn',
+ 'as_path', 'origin', 'next_hop', 'local_pref', 'med', 'comm',
+ 'atomic_aggr', 'aggr', 'as4_path', 'as4_aggr', 'old_state', 'new_state',
+ ]
+
+ def __init__(self, args):
+ self.verbose = args.verbose
+ self.output = args.output
+ self.ts_format = args.ts_format
+ self.pkt_num = args.pkt_num
+ self.type = ''
+ self.num = 0
+ self.ts = 0
+ self.org_time = 0
+ self.flag = ''
+ self.peer_ip = ''
+ self.peer_as = 0
+ self.nlri = []
+ self.withdrawn = []
+ self.as_path = []
+ self.origin = ''
+ self.next_hop = []
+ self.local_pref = 0
+ self.med = 0
+ self.comm = ''
+ self.atomic_aggr = 'NAG'
+ self.aggr = ''
+ self.as4_path = []
+ self.as4_aggr = ''
+ self.old_state = 0
+ self.new_state = 0
+
+ def print_line(self, prefix, next_hop):
+ if self.ts_format == 'dump':
+ d = self.ts
+ else:
+ d = self.org_time
+
+ if self.verbose:
+ d = str(d)
+ else:
+ d = datetime.utcfromtimestamp(d).\
+ strftime('%m/%d/%y %H:%M:%S')
+
+ if self.pkt_num == True:
+ d = '%d|%s' % (self.num, d)
+
+ if self.flag == 'B' or self.flag == 'A':
+ self.output.write('%s|%s|%s|%s|%s|%s|%s|%s' % (
+ self.type, d, self.flag, self.peer_ip, self.peer_as, prefix,
+ self.merge_as_path(), self.origin))
+ if self.verbose == True:
+ self.output.write('|%s|%d|%d|%s|%s|%s|\n' % (
+ next_hop, self.local_pref, self.med, self.comm,
+ self.atomic_aggr, self.merge_aggr()))
+ else:
+ self.output.write('\n')
+ elif self.flag == 'W':
+ self.output.write('%s|%s|%s|%s|%s|%s\n' % (
+ self.type, d, self.flag, self.peer_ip, self.peer_as,
+ prefix))
+ elif self.flag == 'STATE':
+ self.output.write('%s|%s|%s|%s|%s|%d|%d\n' % (
+ self.type, d, self.flag, self.peer_ip, self.peer_as,
+ self.old_state, self.new_state))
+
+ def print_routes(self):
+ for withdrawn in self.withdrawn:
+ if self.type == 'BGP4MP':
+ self.flag = 'W'
+ self.print_line(withdrawn, '')
+ for nlri in self.nlri:
+ if self.type == 'BGP4MP':
+ self.flag = 'A'
+ for next_hop in self.next_hop:
+ self.print_line(nlri, next_hop)
+
+ def td(self, m, count):
+ self.type = 'TABLE_DUMP'
+ self.flag = 'B'
+ self.ts = m.ts
+ self.num = count
+ self.org_time = m.td.org_time
+ self.peer_ip = m.td.peer_ip
+ self.peer_as = m.td.peer_as
+ self.nlri.append('%s/%d' % (m.td.prefix, m.td.plen))
+ for attr in m.td.attr:
+ self.bgp_attr(attr)
+ self.print_routes()
+
+ def td_v2(self, m):
+ global peer
+ self.type = 'TABLE_DUMP2'
+ self.flag = 'B'
+ self.ts = m.ts
+ if m.subtype == TD_V2_ST['PEER_INDEX_TABLE']:
+ peer = copy.copy(m.peer.entry)
+ elif (m.subtype == TD_V2_ST['RIB_IPV4_UNICAST']
+ or m.subtype == TD_V2_ST['RIB_IPV4_MULTICAST']
+ or m.subtype == TD_V2_ST['RIB_IPV6_UNICAST']
+ or m.subtype == TD_V2_ST['RIB_IPV6_MULTICAST']):
+ self.num = m.rib.seq
+ self.nlri.append('%s/%d' % (m.rib.prefix, m.rib.plen))
+ for entry in m.rib.entry:
+ self.org_time = entry.org_time
+ self.peer_ip = peer[entry.peer_index].ip
+ self.peer_as = peer[entry.peer_index].asn
+ self.as_path = []
+ self.origin = ''
+ self.next_hop = []
+ self.local_pref = 0
+ self.med = 0
+ self.comm = ''
+ self.atomic_aggr = 'NAG'
+ self.aggr = ''
+ self.as4_path = []
+ self.as4_aggr = ''
+ for attr in entry.attr:
+ self.bgp_attr(attr)
+ self.print_routes()
+
+ def bgp4mp(self, m, count):
+ self.type = 'BGP4MP'
+ self.ts = m.ts
+ self.num = count
+ self.org_time = m.ts
+ self.peer_ip = m.bgp.peer_ip
+ self.peer_as = m.bgp.peer_as
+ if (m.subtype == BGP4MP_ST['BGP4MP_STATE_CHANGE']
+ or m.subtype == BGP4MP_ST['BGP4MP_STATE_CHANGE_AS4']):
+ self.flag = 'STATE'
+ self.old_state = m.bgp.old_state
+ self.new_state = m.bgp.new_state
+ self.print_line([], '')
+ elif (m.subtype == BGP4MP_ST['BGP4MP_MESSAGE']
+ or m.subtype == BGP4MP_ST['BGP4MP_MESSAGE_AS4']
+ or m.subtype == BGP4MP_ST['BGP4MP_MESSAGE_LOCAL']
+ or m.subtype == BGP4MP_ST['BGP4MP_MESSAGE_AS4_LOCAL']):
+ if m.bgp.msg.type != BGP_MSG_T['UPDATE']:
+ return
+ for attr in m.bgp.msg.attr:
+ self.bgp_attr(attr)
+ for withdrawn in m.bgp.msg.withdrawn:
+ self.withdrawn.append(
+ '%s/%d' % (withdrawn.prefix, withdrawn.plen))
+ for nlri in m.bgp.msg.nlri:
+ self.nlri.append('%s/%d' % (nlri.prefix, nlri.plen))
+ self.print_routes()
+
+ def bgp_attr(self, attr):
+ if attr.type == BGP_ATTR_T['ORIGIN']:
+ self.origin = ORIGIN_T[attr.origin]
+ elif attr.type == BGP_ATTR_T['NEXT_HOP']:
+ self.next_hop.append(attr.next_hop)
+ elif attr.type == BGP_ATTR_T['AS_PATH']:
+ self.as_path = []
+ for seg in attr.as_path:
+ if seg['type'] == AS_PATH_SEG_T['AS_SET']:
+ self.as_path.append('{%s}' % ','.join(seg['val']))
+ elif seg['type'] == AS_PATH_SEG_T['AS_CONFED_SEQUENCE']:
+ self.as_path.append('(' + seg['val'][0])
+ self.as_path += seg['val'][1:-1]
+ self.as_path.append(seg['val'][-1] + ')')
+ elif seg['type'] == AS_PATH_SEG_T['AS_CONFED_SET']:
+ self.as_path.append('[%s]' % ','.join(seg['val']))
+ else:
+ self.as_path += seg['val']
+ elif attr.type == BGP_ATTR_T['MULTI_EXIT_DISC']:
+ self.med = attr.med
+ elif attr.type == BGP_ATTR_T['LOCAL_PREF']:
+ self.local_pref = attr.local_pref
+ elif attr.type == BGP_ATTR_T['ATOMIC_AGGREGATE']:
+ self.atomic_aggr = 'AG'
+ elif attr.type == BGP_ATTR_T['AGGREGATOR']:
+ self.aggr = '%s %s' % (attr.aggr['asn'], attr.aggr['id'])
+ elif attr.type == BGP_ATTR_T['COMMUNITY']:
+ self.comm = ' '.join(attr.comm)
+ elif attr.type == BGP_ATTR_T['MP_REACH_NLRI']:
+ self.next_hop = attr.mp_reach['next_hop']
+ if self.type != 'BGP4MP':
+ return
+ for nlri in attr.mp_reach['nlri']:
+ self.nlri.append('%s/%d' % (nlri.prefix, nlri.plen))
+ elif attr.type == BGP_ATTR_T['MP_UNREACH_NLRI']:
+ if self.type != 'BGP4MP':
+ return
+ for withdrawn in attr.mp_unreach['withdrawn']:
+ self.withdrawn.append(
+ '%s/%d' % (withdrawn.prefix, withdrawn.plen))
+ elif attr.type == BGP_ATTR_T['AS4_PATH']:
+ self.as4_path = []
+ for seg in attr.as4_path:
+ if seg['type'] == AS_PATH_SEG_T['AS_SET']:
+ self.as4_path.append('{%s}' % ','.join(seg['val']))
+ elif seg['type'] == AS_PATH_SEG_T['AS_CONFED_SEQUENCE']:
+ self.as4_path.append('(' + seg['val'][0])
+ self.as4_path += seg['val'][1:-1]
+ self.as4_path.append(seg['val'][-1] + ')')
+ elif seg['type'] == AS_PATH_SEG_T['AS_CONFED_SET']:
+ self.as4_path.append('[%s]' % ','.join(seg['val']))
+ else:
+ self.as4_path += seg['val']
+ elif attr.type == BGP_ATTR_T['AS4_AGGREGATOR']:
+ self.as4_aggr = '%d %s' % (attr.as4_aggr['asn'], attr.as4_aggr['ip'])
+
+ def merge_as_path(self):
+ if len(self.as4_path):
+ n = len(self.as_path) - len(self.as4_path)
+ return ' '.join(self.as_path[:n] + self.as4_path)
+ else:
+ return ' '.join(self.as_path)
+
+ def merge_aggr(self):
+ if len(self.as4_aggr):
+ return self.as4_aggr
+ else:
+ return self.aggr
+
+def main():
+ args = parse_args()
+ d = Reader(args.path_to_file)
+ count = 0
+ for m in d:
+ m = m.mrt
+ if m.err:
+ continue
+ b = BgpDump(args)
+ if m.type == MRT_T['TABLE_DUMP']:
+ b.td(m, count)
+ elif m.type == MRT_T['TABLE_DUMP_V2']:
+ b.td_v2(m)
+ elif m.type == MRT_T['BGP4MP']:
+ b.bgp4mp(m, count)
+ count += 1
+
+if __name__ == '__main__':
+ main()
diff --git a/mrtparse/examples/mrt2exabgp.py b/mrtparse/examples/mrt2exabgp.py
new file mode 100755
index 0000000..dcc4d55
--- /dev/null
+++ b/mrtparse/examples/mrt2exabgp.py
@@ -0,0 +1,286 @@
+#!/usr/bin/env python
+'''
+mrt2exabgp.py - a script to convert MRT format to ExaBGP format.
+
+Copyright (C) 2015 greenHippo, LLC.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Authors:
+ Tetsumune KISO <t2mune at gmail.com>
+ Yoshiyuki YAMAUCHI <info at greenhippo.co.jp>
+ Nobuhiro ITOU <js333123 at gmail.com>
+'''
+
+from mrtparse import *
+import sys, re, argparse, time
+
+flags = 0x00
+FLAG_T = {
+ 'IPv4': 0x01,
+ 'IPv6': 0x02,
+ 'ALL' : 0x04,
+ 'API' : 0x08,
+ 'API-GROUP' : 0x10,
+}
+
+def parse_args():
+ global flags
+
+ if '-4' in sys.argv:
+ flags |= FLAG_T['IPv4']
+ if '-6' in sys.argv:
+ flags |= FLAG_T['IPv6']
+ if '-4' not in sys.argv and '-6' not in sys.argv:
+ flags = FLAG_T['IPv4'] | FLAG_T['IPv6']
+ if '-a' in sys.argv:
+ flags |= FLAG_T['ALL']
+ if '-A' in sys.argv:
+ flags |= FLAG_T['API']
+ if '-G' in sys.argv:
+ flags |= FLAG_T['API'] | FLAG_T['API-GROUP']
+
... 2439 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/mrtparse.git
More information about the Python-modules-commits
mailing list