blob: 183388f2301e431e8fa741d6c0257edda7ff3b02 [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"""
AntonySilvestera1080f22016-04-26 13:05:57 +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
AntonySilvestera1080f22016-04-26 13:05:57 +053030from Nbdata import BgpLs
31
32obj = BgpLs()
33returnlist = obj.Constants()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070034peerIp = returnlist[ 0 ][ 0 ]
AntonySilvestera1080f22016-04-26 13:05:57 +053035
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070036load_contrib( 'bgp' )
AntonySilvestera1080f22016-04-26 13:05:57 +053037s = socket.socket() # Create a socket object
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070038host = peerIp # Get local machine name
AntonySilvestera1080f22016-04-26 13:05:57 +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_all.pcap" )
42pkts[ 69 ][ BGPOpen ].bgp_id = peerIp
AntonySilvestera1080f22016-04-26 13:05:57 +053043
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070044s.listen( 5 ) # Now wait for client connection.
AntonySilvestera1080f22016-04-26 13:05:57 +053045
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070046print( "starting Connecting to ONOS peer" )
AntonySilvestera1080f22016-04-26 13:05:57 +053047c, addr = s.accept() # Establish connection with client.
48print 'Got connection from ONOS :', addr
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070049c.send( str( pkts[ 69 ][ BGPHeader ] ) ) # OPEN MESSAGE
50c.recv( 4096 )
51c.send( str( pkts[ 71 ][ BGPHeader ] ) ) # KEEPALIVE MESSAGE
52c.recv( 4096 )
53c.send( str( pkts[ 72 ][ BGPHeader ] ) ) # UPDATE MESSAGES
54c.send( str( pkts[ 74 ][ BGPHeader ] ) )
55c.send( str( pkts[ 71 ][ BGPHeader ] ) )
AntonySilvestera1080f22016-04-26 13:05:57 +053056
57while True:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070058 c.recv( 4096 )
59 c.send( str( pkts[ 71 ][ BGPHeader ] ) )
60 # c.close() # Close the connection