无法获取具有可选属性E的BGP通知

2024-05-15 10:57:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用Ubuntu使用BGP实现,出于测试的目的,我想得到指示“optional attribbute 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()

我正在使用python套接字编程。在这里在我的代码中,我首先发送open消息,然后得到open keepalive的响应,然后发送keepalive在Router-A和DUT之间建立bgp会话。你知道吗

不管怎样,在建立连接之后,我正在发送格式错误的更新包(可选属性中有畸形),它应该发送错误为'optional attribute error'的通知消息,但它没有发送该错误消息。现在我关心的是如何接收错误代码为“Optional Attribute error”的“通知消息”。你知道吗

。。。。。。你知道吗


Tags: 消息timeerrorsocketopenoptionalsockbgp