|
| 1 | + |
| 2 | +Usage Examples |
| 3 | +============== |
| 4 | + |
| 5 | +Validation |
| 6 | +---------- |
| 7 | + |
| 8 | +:: |
| 9 | + |
| 10 | + from rtrlib import RTRManager, PfxvState |
| 11 | + |
| 12 | + mgr = RTRManager('rpki-validator.realmv6.org', 8282) |
| 13 | + mgr.start() |
| 14 | + result = mgr.validate(12345, '10.10.0.0', 24) |
| 15 | + |
| 16 | + if result == PfxvState.valid: |
| 17 | + print('Prefix Valid') |
| 18 | + elif result == PfxvState.invalid: |
| 19 | + print('Prefix Invalid') |
| 20 | + elif result == PfxvState.not_found: |
| 21 | + print('Prefix not found') |
| 22 | + else: |
| 23 | + print('Invalid response') |
| 24 | + |
| 25 | + mgr.stop() |
| 26 | + |
| 27 | + |
| 28 | +PFX Table iteration (with iterator) |
| 29 | +----------------------------------- |
| 30 | + |
| 31 | +:: |
| 32 | + |
| 33 | + from rtrlib import RTRManager, PfxvState |
| 34 | + |
| 35 | + mgr = RTRManager('rpki-validator.realmv6.org', 8282) |
| 36 | + mgr.start() |
| 37 | + result = mgr.validate(12345, '10.10.0.0', 24) |
| 38 | + |
| 39 | + for recordv4 in mgr.ipv4_records(): |
| 40 | + print(recordv4) |
| 41 | + |
| 42 | + mgr.stop() |
| 43 | + |
| 44 | + |
| 45 | +PFX Table iteration (with callback) |
| 46 | +----------------------------------- |
| 47 | + |
| 48 | +:: |
| 49 | + |
| 50 | + from rtrlib import RTRManager, PfxvState |
| 51 | + |
| 52 | + def callback(pfx_record, data): |
| 53 | + print(pfx_record) |
| 54 | + |
| 55 | + mgr = RTRManager('rpki-validator.realmv6.org', 8282) |
| 56 | + mgr.start() |
| 57 | + result = mgr.validate(12345, '10.10.0.0', 24) |
| 58 | + |
| 59 | + mgr.for_each_ipv4_record(callback, None) |
| 60 | + |
| 61 | + mgr.stop() |
| 62 | + |
| 63 | + |
| 64 | +Print PFX updates |
| 65 | +------------------- |
| 66 | + |
| 67 | +:: |
| 68 | + |
| 69 | + from rtrlib import RTRManager, register_pfx_update_callback |
| 70 | + |
| 71 | + def callback(pfx_record, added): |
| 72 | + print('%s %s' % ('+' if added else '-', pfx_record)) |
| 73 | + |
| 74 | + register_pfx_update_callback(callback) |
| 75 | + |
| 76 | + mgr = RTRManager('rpki-validator.realmv6.org', 8282) |
| 77 | + mgr.start() |
| 78 | + |
| 79 | + mgr.stop() |
| 80 | + |
0 commit comments