Translator
exceptions
Define all of the exceptions we want to raise in our translators.
ASNError
Bases: TypeError
ASNError provides an error class to use when there is an issue with an Autonomous System Number.
Source code in translator/exceptions.py
4 5 |
|
gobgp
A translator interface for GoBGP (https://github.com/osrg/gobgp).
GoBGP
Represents a GoBGP instance.
Source code in translator/gobgp.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
__init__(url)
Configure the channel used for communication.
Source code in translator/gobgp.py
28 29 30 31 |
|
add_path(ip, event_data)
Announce a single route.
Source code in translator/gobgp.py
128 129 130 131 132 133 134 135 136 137 138 139 |
|
del_all_paths()
Remove all routes from being announced.
Source code in translator/gobgp.py
141 142 143 144 145 |
|
del_path(ip, event_data)
Remove a single route from being announced.
Source code in translator/gobgp.py
147 148 149 150 151 152 153 154 155 156 157 |
|
get_prefixes(ip)
Retrieve the routes that match a prefix and are announced.
Returns:
Name | Type | Description |
---|---|---|
list |
The routes that overlap with the prefix and are currently announced. |
Source code in translator/gobgp.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
is_blocked(ip)
Return True if at least one route matching the prefix is being announced.
Source code in translator/gobgp.py
177 178 179 |
|
shared
Provide a location for code that we want to share between all translators.
asn_is_valid(asn)
asn_is_valid makes sure that an ASN passed in is a valid 2 or 4 Byte ASN.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
asn
|
int
|
The Autonomous System Number that we want to validate |
required |
Raises:
Type | Description |
---|---|
ASNError
|
If the ASN is not between 0 and 4294967295 or is not an integer. |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
description |
Source code in translator/shared.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
tests
acceptance
environment
Configure the test environment before executing acceptance tests.
before_all(context)
Create a GoBGP object.
Source code in translator/tests/acceptance/environment.py
6 7 8 9 |
|
steps
actions
Define the steps used by Behave.
add_block(context, route, asn, community)
Block a single IP.
Source code in translator/tests/acceptance/steps/actions.py
13 14 15 16 17 18 |
|
asn_validation_fails(context, route, asn, community)
Ensure the ASN was invalid.
Source code in translator/tests/acceptance/steps/actions.py
43 44 45 46 47 48 |
|
check_block(context, ip)
Ensure that the IP is currently blocked.
Source code in translator/tests/acceptance/steps/actions.py
51 52 53 54 |
|
check_unblock(context, ip)
Ensure that the IP is currently unblocked.
Source code in translator/tests/acceptance/steps/actions.py
57 58 59 60 |
|
del_block(context, route, asn, community)
Remove a single IP.
Source code in translator/tests/acceptance/steps/actions.py
21 22 23 24 25 26 |
|
get_block_status(context, ip)
Check if the IP is currently blocked.
Returns:
Name | Type | Description |
---|---|---|
bool |
The return value. True if the IP is currently blocked, False otherwise. |
Source code in translator/tests/acceptance/steps/actions.py
29 30 31 32 33 34 35 36 37 38 39 40 |
|
translator
Define the main event loop for the translator.
install_deps()
Install necessary dependencies for debuggers.
Because of how we build translator currently, we don't have a great way to selectively install things at build, so we just do it here! Right now this also includes base.txt, which is unecessary, but in the future when we build a little better, it'll already be setup.
Source code in translator/translator.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
main()
async
Connect to the websocket and start listening for messages.
Source code in translator/translator.py
119 120 121 122 123 124 125 126 |
|
process(message, websocket, g)
async
Take a single message form the websocket and hand it off to the appropriate function.
Source code in translator/translator.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
websocket_loop()
async
Connect to the websocket and start listening for messages for Gobgp.
Source code in translator/translator.py
108 109 110 111 112 113 114 115 116 |
|