Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 1 | #!/usr/bin/python # This is server.py file |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 2 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 3 | Copyright 2016 Open Networking Foundation ( ONF ) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 4 | |
| 5 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 6 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 7 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 8 | |
| 9 | TestON is free software: you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation, either version 2 of the License, or |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 12 | ( at your option ) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 13 | |
| 14 | TestON is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 21 | """ |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 22 | from scapy.all import * |
| 23 | import socket # Import socket module |
| 24 | import time # Import Time module |
| 25 | import sys |
| 26 | import os |
| 27 | |
| 28 | path = os.getcwd() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 29 | sys.path.append( 'OnosSystemTest/TestON/tests/FUNC/FUNCbgpls/dependencies' ) # Setting the path for BgpLS |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 30 | from Nbdata import BgpLs |
| 31 | |
| 32 | obj = BgpLs() |
| 33 | returnlist = obj.Constants() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 34 | peerIp = returnlist[ 0 ][ 0 ] |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 35 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 36 | load_contrib( 'bgp' ) |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 37 | s = socket.socket() # Create a socket object |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 38 | host = peerIp # Get local machine name |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 39 | port = 179 # Reserve a port for your service. |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 40 | s.bind( ( host, port ) ) # Bind to the port |
| 41 | pkts = rdpcap( path + "/OnosSystemTest/TestON/tests/FUNC/FUNCbgpls/dependencies/Bgpls_packets/bgpls_all.pcap" ) |
| 42 | pkts[ 69 ][ BGPOpen ].bgp_id = peerIp |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 43 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 44 | s.listen( 5 ) # Now wait for client connection. |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 45 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 46 | print( "starting Connecting to ONOS peer" ) |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 47 | c, addr = s.accept() # Establish connection with client. |
| 48 | print 'Got connection from ONOS :', addr |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 49 | c.send( str( pkts[ 69 ][ BGPHeader ] ) ) # OPEN MESSAGE |
| 50 | c.recv( 4096 ) |
| 51 | c.send( str( pkts[ 71 ][ BGPHeader ] ) ) # KEEPALIVE MESSAGE |
| 52 | c.recv( 4096 ) |
| 53 | c.send( str( pkts[ 72 ][ BGPHeader ] ) ) # UPDATE MESSAGES |
| 54 | c.send( str( pkts[ 74 ][ BGPHeader ] ) ) |
| 55 | c.send( str( pkts[ 71 ][ BGPHeader ] ) ) |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 56 | |
| 57 | while True: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 58 | c.recv( 4096 ) |
| 59 | c.send( str( pkts[ 71 ][ BGPHeader ] ) ) |
| 60 | # c.close() # Close the connection |