Skip to content

Commit

Permalink
Merge branch '10-echtzeit-mrt-simulation' into 'main'
Browse files Browse the repository at this point in the history
Resolve "Echtzeit MRT Simulation"

Closes #10

See merge request imprj/01-bgp-testbed/zettabgp!8
  • Loading branch information
DlieBG committed Nov 5, 2024
2 parents dc49ef6 + 0da947d commit eb63d84
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,37 @@ Options:
-l, --no-mongodb-log
-s, --no-mongodb-state
-t, --no-mongodb-statistics
-p, --playback-speed INTEGER Playback speed in multiples of real time. [default: (1)]
-o, --playback-interval INTEGER Playback interval in minutes. [default: (5)]
```

##### Playback Speed
Without specifying a playback speed, `mrt-simulation` will replay all route updates at once.\
When defining playback speed, the replay of the updates will be done in multiples of real time.\
For a real time playback, you can use option `-p` without an argument.
```
zettabgp mrt-simulation <mrt-file> -p
```
For a playback speed that is twice as fast as real time, the option `-p` can be used with argument `2` (2x speed of real time).
```
zettabgp mrt-simulation <mrt-file> -p 2
```

##### Playback Interval
For debugging the timebased group update queue, it is very useful to playback all update messages that occur within an interval of for example 5 minutes.\
When you specify option `-o` you can set a playback interval in minutes that defaults to 5 minutes.\
Between the intervals you have to press enter to continue with the replay of the next interval.\
Of course you can combine this option with the playback speed option.\
An 5 minute interval playback looks like that.
```
zettabgp mrt-simulation <mrt-file> -o
```
A 10 minute interval playback looks like that.
```
zettabgp mrt-simulation <mrt-file> -o 10
```
Please keep in mind that most of the mrt files only contain a timeslot of 15 minutes.

## Debugging
Some sample json messages for debugging purposes from ExaBGP can be found in the `samples` directory.

Expand Down
44 changes: 43 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from src.adapters.rabbitmq import RabbitMQAdapter
from src.adapters.mongodb import MongoDBAdapter
from src.parsers.exabgp import ExaBGPParser
from datetime import timedelta, datetime
from mrtparse import Reader
import click, time, sys
from rich import print
Expand Down Expand Up @@ -82,14 +83,34 @@ def exabgp(no_rabbitmq: bool, no_mongodb_log: bool, no_mongodb_state: bool, no_m
'-t',
is_flag=True,
)
@click.option(
'--playback-speed',
'-p',
type=int,
default=None,
show_default='1',
is_flag=False,
flag_value=1,
help='Playback speed in multiples of real time.',
)
@click.option(
'--playback-interval',
'-o',
type=int,
default=None,
show_default='5',
is_flag=False,
flag_value=5,
help='Playback interval in minutes.',
)
@click.argument(
'mrt_file',
type=click.Path(
exists=True,
resolve_path=True,
),
)
def mrt_simulation(no_rabbitmq: bool, no_mongodb_log: bool, no_mongodb_state: bool, no_mongodb_statistics: bool, mrt_file: str):
def mrt_simulation(no_rabbitmq: bool, no_mongodb_log: bool, no_mongodb_state: bool, no_mongodb_statistics: bool, playback_speed: int, playback_interval: int, mrt_file: str):
parser = MrtBgp4MpParser()

if not no_rabbitmq:
Expand All @@ -105,12 +126,33 @@ def mrt_simulation(no_rabbitmq: bool, no_mongodb_log: bool, no_mongodb_state: bo
no_mongodb_statistics=no_mongodb_statistics,
)

playback_speed_reference: datetime = None
playback_interval_stop: datetime = None

for message in Reader(mrt_file):
if message.data['type'] != {16: 'BGP4MP'}:
print('[dark_orange]\[WARN][/] Skipping unsupported MRT type: ', end='')
print(message.data['type'])
continue

current_timestamp: datetime = datetime.fromtimestamp(
timestamp=list(message.data['timestamp'].keys())[0],
)

if playback_speed:
if playback_speed_reference:
time.sleep((current_timestamp - playback_speed_reference).seconds / playback_speed)

playback_speed_reference = current_timestamp

if playback_interval:
if playback_interval_stop:
if current_timestamp > playback_interval_stop:
input('Enter for next interval...')
playback_interval_stop = playback_interval_stop + timedelta(minutes=playback_interval)
else:
playback_interval_stop = current_timestamp + timedelta(minutes=playback_interval)

parser.parse(
bgp4mp_message=message,
)

0 comments on commit eb63d84

Please sign in to comment.