Fix netconf csit looking up nonexistant version
[integration/test.git] / 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(
20             chr(x)
21             for x in [
22                 0x00,
23                 0x20,
24                 0x01,
25                 0x02,
26                 0x03,
27                 0x04,
28                 5,
29                 6,
30                 7,
31                 8,
32                 9,
33                 10,
34                 11,
35                 12,
36                 13,
37                 14,
38                 15,
39                 16,
40             ]
41         )
42         self.builtin.log("Sending Discover Packet to: %s" % ac_ip, "DEBUG")
43         session = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
44         session.sendto(data, (ac_ip, port))
45         self.builtin.log("Packet Sent", "DEBUG")
46
47     def get_hostip(self):
48         """Get Host IP Address."""
49         ip_addr = socket.gethostbyname(socket.gethostname())
50         return ip_addr
51
52     def get_simulated_wtpip(self, controller):
53         """Get the Simulated WTP ip based on the controller."""
54         if controller == "127.0.0.1":
55             exp_ip = controller
56         else:
57             exp_ip = self.get_hostip()
58         return exp_ip