#!/usr/bin/env python3

import os
import sys
import time

messages = [
    'neighbor 127.0.0.1 announce route 1.1.0.0/24 next-hop 101.1.101.1',
    'neighbor 127.0.0.1 router-id 1.2.3.4, neighbor 127.0.0.1 announce route 1.1.0.0/25 next-hop 101.1.101.1',
    'withdraw route 1.1.0.0/24 next-hop 101.1.101.1',
]

while messages:
    message = messages.pop(0)
    sys.stdout.write(message + '\n')
    sys.stdout.flush()
    time.sleep(0.2)

try:
    now = time.time()
    while os.getppid() != 1 and time.time() < now + 5:
        line = sys.stdin.readline().strip()
        if not line or 'shutdown' in line:
            break
        time.sleep(1)
except IOError:
    pass
