我正在与Ubuntu一起实施BGP实现,出于测试目的,我希望获得指示“可选属性错误”的“通知消息”。
#!/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-keepalive的响应,而不是发送keepalive在Router-A和DUT之间建立bgp会话。
无论如何,建立连接后,我正在发送格式错误的更新包(可选属性中包含格式错误),它应该发送带有错误“可选属性错误”的通知消息,但没有发送该错误消息。现在我关心的是如何接收带有错误代码“ Optional Attribute Error”的“ Notification Message”。
......