Added a library and test case for capwap project.
authorVaibhav Bhatnagar <vbhatnag@brocade.com>
Wed, 3 Jun 2015 19:37:39 +0000 (01:07 +0530)
committerGerrit Code Review <gerrit@opendaylight.org>
Sat, 6 Jun 2015 16:00:09 +0000 (16:00 +0000)
Change-Id: Ibd1e8cc7a1f6a5366e7aac2fac379851d537d4fd
Signed-off-by: Vaibhav Bhatnagar <vbhatnag@brocade.com>
Signed-off-by: Jamo Luhrsen <james.luhrsen@hp.com>
test/csit/libraries/CapwapLibrary.py [new file with mode: 0644]
test/csit/suites/capwap/basic/capwap_session.robot

diff --git a/test/csit/libraries/CapwapLibrary.py b/test/csit/libraries/CapwapLibrary.py
new file mode 100644 (file)
index 0000000..89a123a
--- /dev/null
@@ -0,0 +1,36 @@
+"""
+Library for the robot based system test tool of the OpenDaylight project.
+Authors: Vaibhav Bhatnagar@Brocade
+Updated: 2015-06-01
+"""
+import socket
+
+from robot.libraries.BuiltIn import BuiltIn
+
+
+class CapwapLibrary(object):
+    """Provide many methods to simulate WTPs and their functions."""
+
+    def __init__(self):
+        self.builtin = BuiltIn()
+
+    def send_discover(self, ac_ip, wtp_ip='', ip='ip', port=5246):
+        """Send Discover CAPWAP Packet from a WTP."""
+        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])
+        self.builtin.log('Sending Discover Packet to: %s' % ac_ip, 'DEBUG')
+        session = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
+        session.sendto(data, (ac_ip, port))
+        self.builtin.log('Packet Sent', 'DEBUG')
+
+    def get_hostip(self):
+        """Get Host IP Address."""
+        ip_addr = socket.gethostbyname(socket.gethostname())
+        return ip_addr
+
+    def get_simulated_wtpip(self, controller):
+        """Get the Simulated WTP ip based on the controller."""
+        if controller == '127.0.0.1':
+            exp_ip = controller
+        else:
+            exp_ip = self.get_hostip()
+        return exp_ip
index 6b4057e675b4e6f8c35ef88266a097ecf196988d..014c8b864cfa3e6fa57b00eab05b293697e34b2c 100644 (file)
@@ -2,13 +2,16 @@
 Documentation     Test suite for capwap discover functionality
 Suite Setup       Create Session    session    http://${CONTROLLER}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS_XML}
 Suite Teardown    Delete All Sessions
-Library           ../../../libraries/RequestsLibrary.py
+Library           RequestsLibrary
 Library           ../../../libraries/Common.py
 Variables         ../../../variables/Variables.py
 Resource          ../../../libraries/Utils.txt
+Library           Collections
+Library           ../../../libraries/CapwapLibrary.py
 
 *** Variables ***
 ${REST_CONTEXT}    /restconf/modules
+${DISC_WTP_REST}    /restconf/operational/capwap-impl:capwap-ac-root/
 
 *** Test Cases ***
 Get Controller Modules
@@ -18,3 +21,23 @@ Get Controller Modules
     Should Be Equal As Strings    ${resp.status_code}    200
     Should Contain    ${resp.content}    ietf-restconf
 
+Get Discovered WTPs
+    [Documentation]    Get the WTP Discoverd
+    send discover    ${CONTROLLER}
+    Wait Until Keyword Succeeds    10s    5s    Run Test Get Discovered WTP
+
+*** Keywords ***
+Run Test Get Discovered WTP
+    ${resp}    RequestsLibrary.Get    session    ${DISC_WTP_REST}
+    Log    ${resp.content}
+    Should Be Equal As Strings    ${resp.status_code}    200
+    ${result}    TO JSON    ${resp.content}
+    ${ac_Root}    Get From Dictionary    ${result}    capwap-ac-root
+    @{wtp_discovered}    Get From Dictionary    ${ac_Root}    discovered-wtps
+    ${expected_ip_addr}    get simulated wtpip    ${CONTROLLER}
+    ${wtp_ip_list}    Create List    ''
+    : FOR    ${wtp}    IN    @{wtp_discovered}
+    \    ${wtp_ip}    Get From Dictionary    ${wtp}    ipv4-addr
+    \    Append to List    ${wtp_ip_list}    ${wtp_ip}
+    Log    ${wtp_ip_list}
+    List Should Contain Value    ${wtp_ip_list}    ${expected_ip_addr}