Skip to content

Commit a606065

Browse files
author
Sebastian Forstner
committed
Merge branch '7-bgp-table-dump-spport' into 'main'
Resolve "BGP Table Dump Spport" Closes #7 See merge request imprj/01-bgp-testbed/zettabgp!11
2 parents cb33b50 + a83c53c commit a606065

File tree

6 files changed

+369
-6
lines changed

6 files changed

+369
-6
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
mrt_library/
2-
src/ui/
32
local/
43

54
# Byte-compiled / optimized / DLL files

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,23 @@ The WebApp will be exposed on port `8000` by default.\
167167
You can access the ui using this link: http://127.0.0.1:8000/ \
168168
For the management of the MRT Library refer to this section above. [Local MRT Library](#local-mrt-library)
169169

170+
#### `rib-load`
171+
This command lets you import the contents of rib files, similar to the `mrt-simulation`.\
172+
A path to a rib file is mandatory for this command.\
173+
This command uses a part of the options as `mrt-simulation` does.
174+
```
175+
Arguments:
176+
RIB_FILE
177+
178+
Options:
179+
-d, --no-rabbitmq-direct
180+
-g, --rabbitmq-grouped INTEGER Queue group interval in minutes. [default: (5)]
181+
-l, --no-mongodb-log
182+
-s, --no-mongodb-state
183+
-t, --no-mongodb-statistics
184+
-c, --clear-mongodb
185+
```
186+
170187
## Debugging
171188
Some sample json messages for debugging purposes from ExaBGP can be found in the `samples` directory.
172189

src/adapters/mongodb.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def __init__(self, parser: RouteUpdateParser, no_mongodb_log: bool, no_mongodb_s
7575

7676
@parser.on_update
7777
def on_update(message: RouteUpdate):
78-
7978
# Saves optional, non-base-type attributes for later use; required to guarantee save use of mongodb
8079
if message.path_attributes.origin:
8180
origins = message.path_attributes.origin.value
@@ -105,7 +104,7 @@ def on_update(message: RouteUpdate):
105104
extended_community = [str(ext_com)]
106105
else:
107106
extended_community.append(str(ext_com))
108-
107+
109108
# Creates dict for message with _id and other unique attributes, that don't change
110109
new_message_id = {
111110
'timestamp' : message.timestamp,
@@ -206,7 +205,7 @@ def on_update(message: RouteUpdate):
206205
if statistics_object:
207206
new_values = {
208207
'$set': {
209-
'change_count' : (statistics_object['change_count'] + 1),
208+
'change_count' : statistics_object['change_count'] + 1,
210209
'current_timestamp' : message.timestamp,
211210
'last_timestamp' : statistics_object['current_timestamp'],
212211
}
@@ -220,5 +219,5 @@ def on_update(message: RouteUpdate):
220219
'nlri' : new_message_id['nlri'],
221220
'_id' : ObjectId(),
222221
}
223-
}
224-
statistics_announce = statistics_collection.update_one(statistics_filter, new_values, upsert=True)
222+
}
223+
statistics_announce = statistics_collection.update_one(statistics_filter, new_values, upsert=True)

src/main.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
Sebastian Forstner <sef9869@thi.de>
1212
'''
1313
import src.services.mrt_simulation as mrt_simulation_service
14+
from src.adapters.rabbitmq import RabbitMQAdapter
15+
from src.adapters.mongodb import MongoDBAdapter
1416
import src.services.exabgp as exabgp_service
17+
from src.parsers.rib import RibParser
1518
from src.webapp import start_webapp
19+
from mrtparse import Reader
1620
import click
1721

1822
@click.group()
@@ -204,3 +208,93 @@ def webapp(reload: bool):
204208
start_webapp(
205209
reload=reload,
206210
)
211+
212+
@cli.command(
213+
name='rib-load',
214+
help='Load a rib-file in ZettaBGP.',
215+
)
216+
@click.option(
217+
'--no-rabbitmq-direct',
218+
'-d',
219+
is_flag=True,
220+
)
221+
@click.option(
222+
'--rabbitmq-grouped',
223+
'-g',
224+
type=int,
225+
default=None,
226+
show_default='5',
227+
is_flag=False,
228+
flag_value=5,
229+
help='Queue group interval in minutes.',
230+
)
231+
@click.option(
232+
'--no-mongodb-log',
233+
'-l',
234+
is_flag=True,
235+
)
236+
@click.option(
237+
'--no-mongodb-state',
238+
'-s',
239+
is_flag=True,
240+
)
241+
@click.option(
242+
'--no-mongodb-statistics',
243+
'-t',
244+
is_flag=True,
245+
)
246+
@click.option(
247+
'--clear-mongodb',
248+
'-c',
249+
is_flag=True,
250+
)
251+
@click.argument(
252+
'rib_file',
253+
type=click.Path(
254+
exists=True,
255+
resolve_path=True,
256+
),
257+
)
258+
def rib_load(no_rabbitmq_direct: bool, rabbitmq_grouped: int, no_mongodb_log: bool, no_mongodb_state: bool, no_mongodb_statistics: bool, clear_mongodb: bool, rib_file: str):
259+
'''
260+
RIB Load command for retrieving BGP routes from RIB files and loading them.
261+
262+
Author:
263+
Sebastian Forstner <sef9869@thi.de>
264+
265+
Args:
266+
no_rabbitmq_direct (bool): Disable direct RabbitMQ direct queue..
267+
rabbitmq_grouped (int): Queue group interval in minutes.
268+
no_mongodb_log (bool): Disable logging to MongoDB.
269+
no_mongodb_state (bool): Disable state storage to MongoDB.
270+
no_mongodb_statistics (bool): Disable statistics storage to MongoDB.
271+
clear_mongodb (bool): Clear MongoDB collections.
272+
rib_file (str): RIB file to process.
273+
'''
274+
parser = RibParser()
275+
276+
if not no_rabbitmq_direct or rabbitmq_grouped:
277+
RabbitMQAdapter(
278+
parser=parser,
279+
no_direct=no_rabbitmq_direct,
280+
queue_interval=rabbitmq_grouped,
281+
)
282+
283+
if not no_mongodb_log or not no_mongodb_state or not no_mongodb_statistics:
284+
MongoDBAdapter(
285+
parser=parser,
286+
no_mongodb_log=no_mongodb_log,
287+
no_mongodb_state=no_mongodb_state,
288+
no_mongodb_statistics=no_mongodb_statistics,
289+
clear_mongodb=clear_mongodb,
290+
)
291+
292+
for message in Reader(rib_file):
293+
if message.data['type'] != {13: 'TABLE_DUMP_V2'}:
294+
print('[dark_orange]\[WARN][/] Skipping unsupported MRT type: ', end='')
295+
print(message.data['type'])
296+
continue
297+
298+
parser.parse(
299+
statement=message.data,
300+
)

0 commit comments

Comments
 (0)