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 |
| 21 | pkts = rdpcap(path + "/OnosSystemTest/TestON/tests/FUNC/FUNCbgpls/dependencies/Bgpls_packets/bgpls_all.pcap") |
| 22 | pkts[69][BGPOpen].bgp_id = peerIp |
| 23 | |
| 24 | s.listen(5) # Now wait for client connection. |
| 25 | |
| 26 | print("starting Connecting to ONOS peer") |
| 27 | c, addr = s.accept() # Establish connection with client. |
| 28 | print 'Got connection from ONOS :', addr |
| 29 | c.send(str(pkts[69][BGPHeader])) # OPEN MESSAGE |
| 30 | c.recv(4096) |
| 31 | c.send(str(pkts[71][BGPHeader]))# KEEPALIVE MESSAGE |
| 32 | c.recv(4096) |
| 33 | c.send(str(pkts[72][BGPHeader])) # UPDATE MESSAGES |
| 34 | c.send(str(pkts[74][BGPHeader])) |
| 35 | c.send(str(pkts[71][BGPHeader])) |
| 36 | |
| 37 | time.sleep(10) # Waiting for 120 seconds for update message. |
| 38 | |
| 39 | c.send(str(pkts[298][BGPHeader])) |
| 40 | c.send(str(pkts[860][BGPHeader])) # UPDATE MESSAGES with new node |
| 41 | c.send(str(pkts[865][BGPHeader])) |
| 42 | print ("New Node update msg sent") |
| 43 | |
| 44 | while True: |
| 45 | c.recv(4096) |
| 46 | c.send(str(pkts[71][BGPHeader])) |
| 47 | |
| 48 | # c.close() # Close the connection |