#message-parser #mrt #bgp #parser

mrt-rs

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

12 个版本 (稳定版)

2.0.1 2020年6月20日
2.0.0 2020年5月27日
1.1.3 2019年3月1日
1.1.2 2019年2月22日
0.1.0 2019年1月24日

#1319 in 网络编程

每月下载量 43
bgp-rs 中使用

GPL-3.0 许可证

60KB
1K SLoC

Rust (mrt-rs) 多线程路由工具包

Build Status codecov Crates

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

示例 & 文档

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

extern mrt_rs;

读取包含BPG消息的MRT文件

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,
        }
    }
}

注意: MRT数据通常被压缩以减小大小,在尝试解析之前请确保先解压缩文件。

完整文档请查看这里。如果最终目的是解析BGP消息,可以使用bgp-rs。有关bgp-rsmrt-rs如何交互的示例,请查看这里

全面支持

支持所有在RFC6396RFC8050中提到的MRT记录类型,包括已弃用的类型。需要注意的是,并非所有代码都经过测试。这是由于我没有其他协议的MRT格式流。

支持的MRT类型

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

需要帮助!

您是否有尚未测试的MRT类型文件?请告诉我,以便我可以为这些类型添加新的测试。任何错误报告或新增功能请求都始终欢迎,并可以在问题追踪器中提交。

依赖关系

~120KB