mrt-rs

Crates.iomrt-rs
lib.rsmrt-rs
version2.0.1
sourcesrc
created_at2019-01-24 10:17:27.821179
updated_at2020-06-20 17:57:24.001593
descriptionA library for parsing Multi-Threaded Routing Toolkit (MRT) formatted streams.
homepagehttps://github.com/DevQps/mrt-rs
repositoryhttps://github.com/DevQps/mrt-rs
max_upload_size
id110396
size95,670
Christian Veenman (DevQps)

documentation

https://docs.rs/mrt-rs

README

Multi-Threaded Routing Toolkit in Rust (mrt-rs)

Build Status codecov Crates

A library for parsing Multi-Threaded Routing Toolkit (MRT) formatted streams in Rust.

Examples & Documentation

If not using Rust 2018 edition add the following in order to use mrt_rs:

extern mrt_rs;

Reading a MRT file containing BPG messages:

use std::fs::File;
use std::io::Cursor;
use std::io::Read;
use std::io::BufReader;
use mrt_rs::{Reader, Record};
use mrt_rs::bgp4mp::BGP4MP;
use libflate::gzip::Decoder;

fn main() {
    // Open an MRT-formatted file.
    let file = File::open("myfile.mrt").unwrap();

    // Decode the GZIP stream using BufReader for better performance.
    let mut decoder = Decoder::new(BufReader::new(file)).unwrap();

    // Create a new Reader with a Cursor such that we can keep track of the position.
    let mut reader = Reader { stream: decoder };

    // Keep reading (Header, Record) tuples till the end of the file has been reached.
    while let Ok(Some((_, record))) = reader.read() {
        match record {
            Record::BGP4MP(x) => match x {
                BGP4MP::MESSAGE(y) => println!("{:?}", y),
                BGP4MP::MESSAGE_AS4(y) => println!("{:?}", y),
                _ => continue,
            },
            _ => continue,
        }
    }
}

Note: MRT data is often compressed to reduce size, make sure to decompress the files first before attempting to parse them.

For full documentation look here. If one seeks to ultimately parse BGP messages bgp-rs can be used to do so. Examples on how bgp-rs and mrt-rs interact are provided here.

Full support

All MRT record types, including deprecated types, that are mentioned in RFC6396 and RFC8050 are supported. It should be noted that not all code is tested. This is due to the fact that I do not have MRT-formatted streams for other protocols.

Supported MRT types:

  • NULL
  • START,
  • DIE,
  • I_AM_DEAD,
  • PEER_DOWN,
  • BGP
  • RIP
  • IDRP,
  • RIPNG
  • BGP4PLUS
  • BGP4PLUS_01
  • OSPFv2
  • [Tested] TABLE_DUMP
  • [Tested] TABLE_DUMP_V2
  • [Tested] BGP4MP
  • [Tested] BGP4MP_ET
  • ISIS
  • ISIS_ET
  • OSPFv3
  • OSPFv3_ET

Help needed!

Do you have MRT files for MRT types that are currently not tested? Please let me know so I can add new tests for these types as well. Any bug reports or requests for additional features are always welcome and can be submitted at the Issue Tracker.

Commit count: 23

cargo fmt