89a123a9e72c505ace4f4a4b0b73804f58c9d05b
[integration/test.git] / test / csit / libraries / CapwapLibrary.py
1 """
2 Library for the robot based system test tool of the OpenDaylight project.
3 Authors: Vaibhav Bhatnagar@Brocade
4 Updated: 2015-06-01
5 """
6 import socket
7
8 from robot.libraries.BuiltIn import BuiltIn
9
10
11 class CapwapLibrary(object):
12     """Provide many methods to simulate WTPs and their functions."""
13
14     def __init__(self):
15         self.builtin = BuiltIn()
16
17     def send_discover(self, ac_ip, wtp_ip='', ip='ip', port=5246):
18         """Send Discover CAPWAP Packet from a WTP."""
19         data = ''.join(chr(x) for x in [0x00, 0x20, 0x01, 0x02, 0x03, 0x04, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
20         self.builtin.log('Sending Discover Packet to: %s' % ac_ip, 'DEBUG')
21         session = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
22         session.sendto(data, (ac_ip, port))
23         self.builtin.log('Packet Sent', 'DEBUG')
24
25     def get_hostip(self):
26         """Get Host IP Address."""
27         ip_addr = socket.gethostbyname(socket.gethostname())
28         return ip_addr
29
30     def get_simulated_wtpip(self, controller):
31         """Get the Simulated WTP ip based on the controller."""
32         if controller == '127.0.0.1':
33             exp_ip = controller
34         else:
35             exp_ip = self.get_hostip()
36         return exp_ip