AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 1 | #!/usr/bin/python # This is server.py file |
| 2 | from scapy.all import * |
| 3 | import socket # Import socket module |
| 4 | import time # Import Time module |
| 5 | import sys |
| 6 | import os |
| 7 | |
| 8 | path = os.getcwd() |
| 9 | sys.path.append('OnosSystemTest/TestON/tests/FUNC/FUNCbgpls/dependencies') #Setting the path for BgpLS |
| 10 | from Nbdata import BgpLs |
| 11 | |
| 12 | obj = BgpLs() |
| 13 | returnlist = obj.Constants() |
| 14 | peerIp = returnlist[0][0] |
| 15 | |
| 16 | load_contrib('bgp') |
| 17 | s = socket.socket() # Create a socket object |
| 18 | host = peerIp # Get local machine name |
| 19 | port = 179 # Reserve a port for your service. |
| 20 | s.bind((host, port)) # Bind to the port |
AntonySilvester | 0265238 | 2016-07-13 16:44:45 +0530 | [diff] [blame] | 21 | pkts = rdpcap(path + "/OnosSystemTest/TestON/tests/FUNC/FUNCbgpls/dependencies/Bgpls_packets/bgpls.pcap") |
| 22 | time.sleep(15) |
| 23 | pkts[759][BGPOpen].bgp_id = peerIp |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 24 | |
| 25 | s.listen(5) # Now wait for client connection. |
| 26 | |
| 27 | print("starting Connecting to ONOS peer") |
| 28 | c, addr = s.accept() # Establish connection with client. |
| 29 | print 'Got connection from ONOS :', addr |
AntonySilvester | 0265238 | 2016-07-13 16:44:45 +0530 | [diff] [blame] | 30 | c.send(str(pkts[759][BGPHeader])) # OPEN MESSAGE |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 31 | c.recv(4096) |
AntonySilvester | 0265238 | 2016-07-13 16:44:45 +0530 | [diff] [blame] | 32 | c.send(str(pkts[765][BGPHeader]))# KEEPALIVE MESSAGE |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 33 | c.recv(4096) |
AntonySilvester | 0265238 | 2016-07-13 16:44:45 +0530 | [diff] [blame] | 34 | c.send(str(pkts[768][BGPHeader])) # UPDATE MESSAGES |
| 35 | c.send(str(pkts[771][BGPHeader])) |
| 36 | c.send(str(pkts[773][BGPHeader])) |
| 37 | c.send(str(pkts[775][BGPHeader])) |
| 38 | c.send(str(pkts[778][BGPHeader])) |
| 39 | c.send(str(pkts[765][BGPHeader])) |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 40 | |
AntonySilvester | 0265238 | 2016-07-13 16:44:45 +0530 | [diff] [blame] | 41 | time.sleep(15) |
| 42 | c.send(str(pkts[1168][BGPHeader])) |
| 43 | c.send(str(pkts[1250][BGPHeader])) |
| 44 | c.send(str(pkts[1354][BGPHeader])) |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 45 | print ("Node Delete msg sent") |
| 46 | |
| 47 | |
| 48 | while True: |
| 49 | c.recv(4096) |
AntonySilvester | 0265238 | 2016-07-13 16:44:45 +0530 | [diff] [blame] | 50 | c.send(str(pkts[765][BGPHeader])) |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 51 | |
| 52 | # c.close() # Close the connection |