blob: 4bf11878f9a745ca721041b9f726d611fd731f92 [file] [log] [blame]
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07001# !/usr/bin/python # This is server.py file
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07002"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07003Copyright 2016 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07004
5Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
6the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
7or 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 Ronquillo23fb2162017-09-15 14:59:57 -070012 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070013
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"""
AntonySilvester02652382016-07-13 16:44:45 +053022from scapy.all import *
23import socket # Import socket module
24import time # Import Time module
25import sys
26import os
27
28path = os.getcwd()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070029sys.path.append( 'OnosSystemTest/TestON/tests/FUNC/FUNCbgpls/dependencies' ) # Setting the path for BgpLS
AntonySilvester02652382016-07-13 16:44:45 +053030from Nbdata import BgpLs
31
32obj = BgpLs()
33returnlist = obj.Constants()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070034peerIp = returnlist[ 0 ][ 0 ]
AntonySilvester02652382016-07-13 16:44:45 +053035
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070036load_contrib( 'bgp' )
AntonySilvester02652382016-07-13 16:44:45 +053037s = socket.socket() # Create a socket object
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070038host = peerIp # Get local machine name
AntonySilvester02652382016-07-13 16:44:45 +053039port = 179 # Reserve a port for your service.
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070040s.bind( ( host, port ) ) # Bind to the port
41pkts = rdpcap( path + "/OnosSystemTest/TestON/tests/FUNC/FUNCbgpls/dependencies/Bgpls_packets/bgpls.pcap" )
42time.sleep( 15 )
43pkts[ 759 ][ BGPOpen ].bgp_id = peerIp
AntonySilvester02652382016-07-13 16:44:45 +053044
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070045s.listen( 5 ) # Now wait for client connection.
AntonySilvester02652382016-07-13 16:44:45 +053046
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070047print( "starting Connecting to ONOS peer" )
AntonySilvester02652382016-07-13 16:44:45 +053048c, addr = s.accept() # Establish connection with client.
49print 'Got connection from ONOS :', addr
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070050c.send( str( pkts[ 759 ][ BGPHeader ] ) ) # OPEN MESSAGE
51c.recv( 4096 )
52c.send( str( pkts[ 765 ][ BGPHeader ] ) ) # KEEPALIVE MESSAGE
53c.recv( 4096 )
54c.send( str( pkts[ 768 ][ BGPHeader ] ) ) # UPDATE MESSAGES
55c.send( str( pkts[ 771 ][ BGPHeader ] ) )
56c.send( str( pkts[ 773 ][ BGPHeader ] ) )
57c.send( str( pkts[ 775 ][ BGPHeader ] ) )
58c.send( str( pkts[ 778 ][ BGPHeader ] ) )
59c.send( str( pkts[ 765 ][ BGPHeader ] ) )
AntonySilvester02652382016-07-13 16:44:45 +053060
61while True:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070062 c.recv( 4096 )
63 c.send( str( pkts[ 765 ][ BGPHeader ] ) )
64 # c.close() # Close the connection