Skip to content

Commit 09cac01

Browse files
committed
add tool rtrclient
1 parent 2a7bf17 commit 09cac01

File tree

3 files changed

+79
-13
lines changed

3 files changed

+79
-13
lines changed

README.rst

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
=============
12
rtrlib-python
23
=============
34

@@ -9,17 +10,6 @@ Sphinx docs can be found in the docs directory and build with ``make html``.
910

1011
for usage examples see the tools directory
1112

12-
13-
Requirements
14-
''''''''''''
15-
- python 2.7 or python 3
16-
- cffi>=1.4.0
17-
- enum34
18-
- six
19-
20-
and a c compiler for install.
21-
22-
2313
Features
2414
--------
2515
Features supported so far:
@@ -32,4 +22,13 @@ Features supported so far:
3222
Install Instructions
3323
--------------------
3424
rtrlib-python is not on pypi yet, but you can just run ``python setup.py install``.
35-
I is probably a good idea to use a virtualenv.
25+
It is probably a good idea to use a virtualenv.
26+
27+
Requirements
28+
''''''''''''
29+
- python 2.7 or python 3
30+
- cffi>=1.4.0
31+
- enum34
32+
- six
33+
34+
and a c compiler for building the module.

tools/cli-validator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def __init__(self):
2222
self.error = False
2323

2424
def connection_status_collback(rtr_mgr_group, group_status, rtr_socket, data):
25-
#print(group_status)
2625
if group_status == ManagerGroupStatus.ERROR:
2726
data.error = True
2827

tools/rtrclient.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf8 -*-
3+
4+
import argparse
5+
import signal
6+
7+
from rtrlib import RTRManager, register_pfx_update_callback, register_spki_update_callback
8+
9+
def pfx_callback(pfx_record, added):
10+
if added:
11+
c = '+'
12+
else:
13+
c = '-'
14+
15+
print("{sign} {prefix:40} {max:3} - {min:3} {asn:10}".format(
16+
sign=c,
17+
prefix=pfx_record.prefix,
18+
max=pfx_record.max_len,
19+
min=pfx_record.min_len,
20+
asn=pfx_record.asn
21+
)
22+
)
23+
24+
def spki_callback(spki_table, spki_record, added):
25+
if added:
26+
c = '+'
27+
else:
28+
c = '-'
29+
30+
print("{sign} {asn}".format(sign=c, asn=spki_record.asn))
31+
32+
33+
def main():
34+
parser = argparse.ArgumentParser()
35+
parser.add_argument("protocol", choices=('tcp', ))
36+
parser.add_argument("hostname")
37+
parser.add_argument("port", type=int)
38+
parser.add_argument(
39+
"-k",
40+
default=False,
41+
action="store_true",
42+
help="Print information about SPKI updates"
43+
)
44+
parser.add_argument(
45+
"-p",
46+
default=False,
47+
action="store_true",
48+
help="Print information about PFX updates"
49+
)
50+
args = parser.parse_args()
51+
52+
if args.p:
53+
register_pfx_update_callback(pfx_callback)
54+
55+
if args.k:
56+
register_spki_update_callback(spki_callback)
57+
58+
print("{:40} {:3} {:4}".format("Prefix", "Prefix Length", "ASN"))
59+
with RTRManager(args.hostname, args.port) as mgr:
60+
signal.pause()
61+
62+
63+
64+
65+
66+
67+
if __name__ == '__main__':
68+
main()

0 commit comments

Comments
 (0)