Skip to content

Is it possible to unbuffer sys.stdin for a node's shell process #126

@olafayomi

Description

@olafayomi

Hi,
I'm experiencing a situation with exaBGP daemon in IPMininet. In my IPMininet topology, I've configured one of the nodes with
exaBGP. The exaBGP daemon has two processes announce-routes and receive-routes which both have two python scripts sender.py and receiver.py respectively. sender.py announce the routes to the exaBGP peer and receiver.py receives and parses all BGP messages while receiver.py receives and processes the BGP messages generated.

sender.py looks somewhat like this

import sys
import time

if __name__ == '__main__':
     while True:
            # get route 
            sys.stdout.write('neighbor 172.16.2.20 announce attribute next-hop self med 150 origin incomplete nlri 100.30.0.0/16 100.40.0.0/16'
            sys.stdout.flush()
            time.sleep(0.1)

receiver.py looks somewhat like this

import sys
import time
import json

 if __name__ == '__main__':
     sys.stderr = open('/tmp/exabgp-receiver.log', 'a+') 
     unbuffered_stdin = os.fdopen(sys.stdin.fileno(), 'r', buffering=1)
     while True:
           line = unbuffered_stdin.readline().strip()
           try:
                 jsonline = json.loads(line)
           except json.decoder.JSONDecodeError as e:
                sys.stderr.write("Error\n")
           else:
                  # process and write actual BGP message
                  sys.stderr.write(str(jsonline) + '\n')
           sys.stderr.flush()

If I run the network/topology and I trigger a link failure about four times which causes a bunch of BGP updates and withdrawal, the receiver.py script hangs and does not process any message again. However, if I run the topology with IPCLI() and run exabgp from the shell of the host with xterm, the script does not hang. This makes me think there is something buffering sys.stdin and sys.stdout when the topology is not run in interactive CLI mode. I was wondering if there is a way to turn off buffering or get around this ? Or if this has been encountered before ?

IPMininet version is 0.9, python version 3.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions