MRT file library

MRT file library

Introduction

OS-Ken MRT file library helps you to read/write MRT (Multi-Threaded Routing Toolkit) Routing Information Export Format [RFC6396].

Reading MRT file

For loading the routing information contained in MRT files, you can use mrtlib.Reader.

class os_ken.lib.mrtlib.Reader(f)

MRT format file reader.

Argument Description
f File object which reading MRT format file in binary mode.

Example of Usage:

import bz2
from os_ken.lib import mrtlib

count = 0
for record in mrtlib.Reader(
        bz2.BZ2File('rib.YYYYMMDD.hhmm.bz2', 'rb')):
    print("%d, %s" % (count, record))
    count += 1

Writing MRT file

For dumping the routing information which your OSKenApp generated, you can use mrtlib.Writer.

class os_ken.lib.mrtlib.Writer(f)

MRT format file writer.

Argument Description
f File object which writing MRT format file in binary mode.

Example of usage:

import bz2
import time
from os_ken.lib import mrtlib
from os_ken.lib.packet import bgp

mrt_writer = mrtlib.Writer(
    bz2.BZ2File('rib.YYYYMMDD.hhmm.bz2', 'wb'))

prefix = bgp.IPAddrPrefix(24, '10.0.0.0')

rib_entry = mrtlib.MrtRibEntry(
    peer_index=0,
    originated_time=int(time.time()),
    bgp_attributes=[bgp.BGPPathAttributeOrigin(0)])

message = mrtlib.TableDump2RibIPv4UnicastMrtMessage(
    seq_num=0,
    prefix=prefix,
    rib_entries=[rib_entry])

record = mrtlib.TableDump2MrtRecord(
    message=message)

mrt_writer.write(record)
Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.