0

i am working with BGP implementation with Ubuntu, for the testing purpose i want to get 'notification message' indicating 'optional attribute error'.

i am using python socket programming.here in my code, I am first sending open message than getting a response in terms of open-keepalive and than sending keepalive to establish the BGP session between Router-A and DUT.

anyway, after connection establishment I am sending malformed update packet ( having a malformation in the optional attribute), it supposed to send notification message with error 'optional attribute error', but it is not sending that error message. now my concern is how to receive that 'Notification Message' having error code ' Optional Attribute Error'.

#!/usr/bin/env python3

import socket
import time
BGP_IP = '20.0.0.20'

MSG1 = (b'\xff\xff\xff\xff\xff\xff\xff\xff'
        b'\xff\xff\xff\xff\xff\xff\xff\xff'
        b'\x00\x35'
        b'\x01'                  #open message
        b'\x04'
        b'\x00\x64'
        b'\x00\xb4'
        b'\x01\x01\x01\x01'
        b'\x18'
        b'\x02\x06\x01\x04\x00\x01\x00\x01\x02\x02\x80'
        b'\x00\x02\x02\x02\x00\x02\x06\x41\x04\x00\x00\x00\x64')

MSG2 = (b'\xff\xff\xff\xff\xff\xff\xff\xff'
        b'\xff\xff\xff\xff\xff\xff\xff\xff'
        b'\x00\x13'
        b'\x04')                #keepalive 

MSG3 = (b'\xff\xff\xff\xff\xff\xff\xff\xff'     # First 8 bytes of marker
        b'\xff\xff\xff\xff\xff\xff\xff\xff'     # last 8 bytes
        b'\x00\x36'                             # length
        b'\x02'                                 # update packate
        b'\x00\x00'                             # withdrawn routes
        b'\x00\x1c'
        b'\x40\x01\x01\x00'
        b'\x50\x02\x00\x06\x02\x01\x00\x00\x00\x64'
        b'\x40\x03\x04\x14\x00\x00\x0a'
        b'\x80\x04\x04\x00p\x00\x00\x00'  #(malformed optional attribs)
        b'\x10\x0a\00')


def main():
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     print("Socket created")
     sock.connect((BGP_IP, 179))
     print("Socket connected")
     sock.send(MSG1)   #open message
     time.sleep(5)
     sock.send(MSG2)   #keepalive
     time.sleep(5)
     print("connection has been established")
     sock.send(MSG3)   #malformed update
     while True:
         data = sock.recv(1)
         if data==b'':
             print("Connection closed or reset")
             break
        print("Received:", data)

sock.close()

if __name__ == "__main__":
    main() 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.