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.pcap" ) |
| 42 | time.sleep( 15 ) |
| 43 | pkts[ 759 ][ BGPOpen ].bgp_id = peerIp |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 44 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 45 | s.listen( 5 ) # Now wait for client connection. |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 46 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 47 | print( "starting Connecting to ONOS peer" ) |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 48 | c, addr = s.accept() # Establish connection with client. |
| 49 | print 'Got connection from ONOS :', addr |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 50 | c.send( str( pkts[ 759 ][ BGPHeader ] ) ) # OPEN MESSAGE |
| 51 | c.recv( 4096 ) |
| 52 | c.send( str( pkts[ 765 ][ BGPHeader ] ) ) # KEEPALIVE MESSAGE |
| 53 | c.recv( 4096 ) |
| 54 | c.send( str( pkts[ 768 ][ BGPHeader ] ) ) # UPDATE MESSAGES |
| 55 | c.send( str( pkts[ 771 ][ BGPHeader ] ) ) |
| 56 | c.send( str( pkts[ 773 ][ BGPHeader ] ) ) |
| 57 | c.send( str( pkts[ 775 ][ BGPHeader ] ) ) |
| 58 | c.send( str( pkts[ 778 ][ BGPHeader ] ) ) |
| 59 | c.send( str( pkts[ 765 ][ BGPHeader ] ) ) |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 60 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 61 | time.sleep( 15 ) |
| 62 | c.send( str( pkts[ 1168 ][ BGPHeader ] ) ) |
| 63 | c.send( str( pkts[ 1250 ][ BGPHeader ] ) ) |
| 64 | c.send( str( pkts[ 1354 ][ BGPHeader ] ) ) |
| 65 | print ( "Node Delete msg sent" ) |
AntonySilvester | a1080f2 | 2016-04-26 13:05:57 +0530 | [diff] [blame] | 66 | |
| 67 | |
| 68 | while True: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 69 | c.recv( 4096 ) |
| 70 | c.send( str( pkts[ 765 ][ BGPHeader ] ) ) |
| 71 | # c.close() # Close the connection |