Modify FT script for portmap test using mininet 89/3989/2
authorbalakrishnan <balakrishnan.ka@hcl.com>
Wed, 1 Jan 2014 11:16:58 +0000 (16:46 +0530)
committerbalakrishnan <balakrishnan.ka@hcl.com>
Wed, 1 Jan 2014 11:23:38 +0000 (16:53 +0530)
Change-Id: Id36a320411dce3795d77e6b7a44c327a58fe34fd
Signed-off-by: balakrishnan <balakrishnan.ka@hcl.com>
coordinator/test/vtn_ft/README
coordinator/test/vtn_ft/mininet_test.data [new file with mode: 0644]
coordinator/test/vtn_ft/mininet_test.py [new file with mode: 0644]
coordinator/test/vtn_ft/vbrif_portmap.py
coordinator/test/vtn_ft/vtn_testconfig.py
coordinator/test/vtn_ft/vtn_vbr_vbrif.data

index f241f3e169f3b12060f1cc2fc560cc0d5d8cbd19..b1eecf17423e2329bc672f2d7c74a808f3a3d876 100644 (file)
@@ -13,6 +13,7 @@ Pre-Requisites
     * VTN Coordinator must be running
     * Instance of Controller with VTN Mananger is running
     * Please run "yum install python-requests" to run the tests
+    * Please run "yum install pexpect" to run the mininet related tests
 
 
 Configuration
@@ -21,6 +22,7 @@ Configuration
     * The controller related details can be edited in controller.data
     * The VTN VBR attributes can be edited in vtn_vbr.data
     * The coordinator Port and other details can be modified in vtn_testconfig.py
+    * The mininet related details can be edited in mininet_test.data
 
 
 Execution
@@ -55,3 +57,8 @@ MULTI-CONTROLLER TEST CASES
       python vbrif_portmap_audit_multi_controller.py
     * To execute VLANMAP multi-controler Cases
       python vtn_vbr_vlanmap_multi_controller.py
+
+SINGLE-CONTROLLER MININET TEST CASE
+   * Please ensure the pre-requisites.
+   * To execute mininet related test cases
+     python mininet_test.py
diff --git a/coordinator/test/vtn_ft/mininet_test.data b/coordinator/test/vtn_ft/mininet_test.data
new file mode 100644 (file)
index 0000000..ee441d8
--- /dev/null
@@ -0,0 +1,9 @@
+[MININET]
+mininet_ipaddr=10.100.9.151
+mininet_username=mininet
+ctr_id = 172.16.1.61
+ssh = ssh -l
+ctr_remote = sudo mn --controller=remote,ip=
+topo_tree = --topo tree,
+
+
diff --git a/coordinator/test/vtn_ft/mininet_test.py b/coordinator/test/vtn_ft/mininet_test.py
new file mode 100644 (file)
index 0000000..6120674
--- /dev/null
@@ -0,0 +1,384 @@
+#
+# Copyright (c) 2013 NEC Corporation
+# All rights reserved.
+#
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v1.0 which accompanies this
+# distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
+#
+
+
+#! /usr/bin/python
+
+import requests, json, collections, time, controller, vtn_vbr
+import vbrif_portmap, vtn_testconfig, pexpect
+
+VTNVBRDATA = vtn_testconfig.VTNVBRDATA
+CONTROLLERDATA = vtn_testconfig.CONTROLLERDATA
+MININETDATA = vtn_testconfig.MININETDATA
+
+coordinator_url = vtn_testconfig.coordinator_url
+def_header = vtn_testconfig.coordinator_headers
+controller_headers = vtn_testconfig.controller_headers
+controller_url_part = vtn_testconfig.controller_url_part
+
+
+
+def create_mininet_topology(mininet_blockname, controller_blockname, topology_depth_str):
+
+    mininet_ip = vtn_testconfig.ReadValues(MININETDATA, mininet_blockname)['mininet_ipaddr']
+    mininet_user = vtn_testconfig.ReadValues(MININETDATA, mininet_blockname)['mininet_username']
+    ssh  = vtn_testconfig.ReadValues(MININETDATA, mininet_blockname)['ssh']
+    ctr_remote  = vtn_testconfig.ReadValues(MININETDATA, mininet_blockname)['ctr_remote']
+    topo_tree  = vtn_testconfig.ReadValues(MININETDATA, mininet_blockname)['topo_tree']
+    controller_ipaddr = vtn_testconfig.ReadValues(CONTROLLERDATA, controller_blockname)['ipaddr']
+
+    topology = ssh +' ' +  mininet_user +' '+ mininet_ip +' '+ ctr_remote +controller_ipaddr +' '+ topo_tree +topology_depth_str
+    ssh_newkey = 'Are you sure you want to continue connecting'
+    print topology
+
+    child = pexpect.spawn(topology)
+    index = child.expect([ssh_newkey, 'password:', pexpect.EOF, pexpect.TIMEOUT])
+    if index == 0:
+        print "I say yes"
+        child.sendline('yes')
+        index = child.expect([ssh_newkey, 'password:', pexpect.EOF, pexpect.TIMEOUT])
+    if index == 1:
+        print "sending password"
+        child.sendline('mininet')
+        print "connection OK"
+        return child
+    elif index == 2:
+        print "2:connection timeout"
+        return child
+    elif index == 3:
+        print "3:connection timeout"
+        return child
+
+def close_topology(child):
+    if child.isalive() == True :
+        print "process alive\n"
+        child.sendline('exit')
+        child.sendline('exit')
+        print "Exiting Topology"
+        child.close()
+    else:
+        print "child process already closed"
+
+def ping_mininet(child, src_host_str, dst_host_str):
+    ping_cmd = src_host_str +' '+'ping -c5'+' '+dst_host_str
+    if child.isalive() == True :
+        print "process alive\n"
+        child.sendline(ping_cmd)
+        index = child.expect(['Unreachable', '64 bytes'])
+        if index == 0:
+            print "PING FAIL"
+            return 1
+        else:
+            print "PING PASS"
+            return 0
+    else:
+        print "child process closed cannot ping"
+        return 1
+
+def test_vtn_mininet_ping_demo1():
+
+    print """TEST 1 : One vtn and one VBridge with Two Interfaces one Portmap each
+    send packets between two configured host(H1,H3)"""
+    print "CREATE Controller"
+    print "VTNONE->VBRONE->VBRIFONE->PORTMAP"
+    print "VTNONE->VBRONE->VBRIFTWO->PORTMAP"
+
+    child = create_mininet_topology('MININET', 'ControllerFirst', '2')
+    if child.isalive() == True :
+        print "Topology creation Success!!!"
+    else:
+        print "Topology creation Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = controller.add_controller_ex('ControllerFirst')
+    if retval != 0:
+        print "TEST 1 :Controller Create Failed"
+        close_topology(child)
+        exit(1)
+  # Delay for AUDIT
+    controller.wait_until_state('ControllerFirst', "up")
+
+    retval = vtn_vbr.create_vtn('VtnOne')
+    if retval != 0:
+        print "VTN Create Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = vtn_vbr.create_vbr('VtnOne', 'VbrOne', 'ControllerFirst')
+    if retval != 0:
+        print "VBR Create Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = vbrif_portmap.create_vbrif('VtnOne', 'VbrOne', 'VbrIfOne')
+    if retval != 0:
+        print "VBRIFONE Create Failed"
+        close_topology(child)
+        exit(1)
+    retval = vbrif_portmap.validate_vbrif_at_controller('VtnOne', 'VbrOne', 'VbrIfOne', 'ControllerFirst', position=0)
+    if retval != 0:
+        print "VBRIFONE Validate Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = vbrif_portmap.create_vbrif('VtnOne', 'VbrOne', 'VbrIfTwo')
+    if retval != 0:
+        print "VBRIFTWO Create Failed"
+        close_topology(child)
+        exit(1)
+    retval = vbrif_portmap.validate_vbrif_at_controller('VtnOne', 'VbrOne', 'VbrIfTwo', 'ControllerFirst', position=1)
+    if retval != 0:
+        print "VBRIFTWO Validate Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = vbrif_portmap.create_portmap('VtnOne', 'VbrOne', 'VbrIfOne', vlan_tagged=0);
+    if retval != 0:
+        print "VBRIF1 Portmap Create Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = vbrif_portmap.create_portmap('VtnOne', 'VbrOne', 'VbrIfTwo', vlan_tagged=0);
+    if retval != 0:
+        print "VBRIF2 Portmap Create Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = vbrif_portmap.validate_vbrif_portmap_at_controller('VtnOne', 'VbrOne', 'VbrIfOne', 'ControllerFirst', presence="yes");
+    if retval != 0:
+        print "VBRIF1 Portmap Validate Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = vbrif_portmap.validate_vbrif_portmap_at_controller('VtnOne', 'VbrOne', 'VbrIfTwo', 'ControllerFirst', presence="yes");
+    if retval != 0:
+        print "VBRIF2 Portmap Validate Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = ping_mininet (child,'h1','h3')
+    if retval != 0:
+        print "MININET PING FAILED"
+
+    close_topology(child)
+
+    retval = vtn_vbr.validate_vbr_at_controller('VtnOne', 'VbrOne', 'ControllerFirst')
+    if retval != 0:
+        print "VBR Validate Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = vtn_vbr.validate_vtn_at_controller('VtnOne', 'ControllerFirst')
+    if retval != 0:
+        print "VTN Validate Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = vbrif_portmap.delete_vbrif('VtnOne', 'VbrOne', 'VbrIfOne')
+    if retval != 0:
+        print "VTN1->VBR1->VBRIF1 Delete Failed"
+        exit(1)
+
+    retval = vbrif_portmap.validate_vbrif_at_controller('VtnOne', 'VbrOne', 'VbrIfOne', 'ControllerFirst', presence="no", position=0)
+    if retval != 0:
+        print "After Delete VBRIFONE Validate Failed"
+        exit(1)
+
+    retval = vbrif_portmap.delete_vbrif('VtnOne', 'VbrOne', 'VbrIfTwo')
+    if retval != 0:
+        print "VTN1->VBR1->VBRIF1 Delete Failed"
+        exit(1)
+
+    retval = vbrif_portmap.validate_vbrif_at_controller('VtnOne', 'VbrOne', 'VbrIfTwo', 'ControllerFirst', presence="no", position=1)
+    if retval != 0:
+        print "After Delete VBRIFTWO Validate Failed"
+        exit(1)
+
+    retval = vtn_vbr.delete_vbr('VtnOne', 'VbrOne')
+    if retval != 0:
+        print "VBR/VTN Delete Failed"
+        exit(1)
+
+    retval = vtn_vbr.validate_vbr_at_controller('VtnOne', 'VbrOne', 'ControllerFirst', presence="no")
+    if retval != 0:
+        print "After Delete VBR Validate Failed"
+        exit(1)
+
+    retval = vtn_vbr.validate_vtn_at_controller('VtnOne', 'ControllerFirst', presence="no")
+    if retval != 0:
+        print "VTN Validate Failed"
+        exit(1)
+
+    retval = vtn_vbr.delete_vtn('VtnOne')
+    if retval != 0:
+        print "VTN Delete Failed in coordinator"
+        exit(1)
+
+    print "DELETE CONTROLLER"
+    retval = controller.delete_controller_ex('ControllerFirst')
+    if retval != 0:
+        print "CONTROLLER delete failed"
+        exit(1)
+    print "MININET PING DEMO 1 TEST SUCCESS"
+
+def test_vtn_mininet_ping_demo2():
+
+    print """TEST 2 : One vtn and one VBridge with Two Interfaces one Portmap each
+    send packets between two configured host(H2,H4)"""
+    print "CREATE Controller"
+    print "VTNONE->VBRONE->VBRIFONE->PORTMAP"
+    print "VTNONE->VBRONE->VBRIFTWO->PORTMAP"
+
+    child = create_mininet_topology('MININET', 'ControllerFirst', '2')
+    if child.isalive() == True :
+        print "Topology creation Success!!!"
+    else:
+        print "Topology creation Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = controller.add_controller_ex('ControllerFirst')
+    if retval != 0:
+        print "TEST 1 :Controller Create Failed"
+        close_topology(child)
+        exit(1)
+  # Delay for AUDIT
+    controller.wait_until_state('ControllerFirst', "up")
+
+    retval = vtn_vbr.create_vtn('VtnOne')
+    if retval != 0:
+        print "VTN Create Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = vtn_vbr.create_vbr('VtnOne', 'VbrOne', 'ControllerFirst')
+    if retval != 0:
+        print "VBR Create Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = vbrif_portmap.create_vbrif('VtnOne', 'VbrOne', 'VbrIfThree')
+    if retval != 0:
+        print "VBRIFONE Create Failed"
+        close_topology(child)
+        exit(1)
+    retval = vbrif_portmap.validate_vbrif_at_controller('VtnOne', 'VbrOne', 'VbrIfThree', 'ControllerFirst', position=0)
+    if retval != 0:
+        print "VBRIFONE Validate Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = vbrif_portmap.create_vbrif('VtnOne', 'VbrOne', 'VbrIfFour')
+    if retval != 0:
+        print "VBRIFTWO Create Failed"
+        close_topology(child)
+        exit(1)
+    retval = vbrif_portmap.validate_vbrif_at_controller('VtnOne', 'VbrOne', 'VbrIfFour', 'ControllerFirst', position=0)
+    if retval != 0:
+        print "VBRIFTWO Validate Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = vbrif_portmap.create_portmap('VtnOne', 'VbrOne', 'VbrIfThree', vlan_tagged=0);
+    if retval != 0:
+        print "VBRIF1 Portmap Create Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = vbrif_portmap.create_portmap('VtnOne', 'VbrOne', 'VbrIfFour', vlan_tagged=0);
+    if retval != 0:
+        print "VBRIF2 Portmap Create Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = vbrif_portmap.validate_vbrif_portmap_at_controller('VtnOne', 'VbrOne', 'VbrIfThree', 'ControllerFirst', presence="yes");
+    if retval != 0:
+        print "VBRIF1 Portmap Validate Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = vbrif_portmap.validate_vbrif_portmap_at_controller('VtnOne', 'VbrOne', 'VbrIfFour', 'ControllerFirst', presence="yes");
+    if retval != 0:
+        print "VBRIF2 Portmap Validate Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = ping_mininet (child,'h2','h4')
+    if retval != 0:
+        print "MININET PING FAILED"
+
+    close_topology(child)
+
+    retval = vtn_vbr.validate_vbr_at_controller('VtnOne', 'VbrOne', 'ControllerFirst')
+    if retval != 0:
+        print "VBR Validate Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = vtn_vbr.validate_vtn_at_controller('VtnOne', 'ControllerFirst')
+    if retval != 0:
+        print "VTN Validate Failed"
+        close_topology(child)
+        exit(1)
+
+    retval = vbrif_portmap.delete_vbrif('VtnOne', 'VbrOne', 'VbrIfThree')
+    if retval != 0:
+        print "VTN1->VBR1->VBRIF1 Delete Failed"
+        exit(1)
+
+    retval = vbrif_portmap.validate_vbrif_at_controller('VtnOne', 'VbrOne', 'VbrIfThree', 'ControllerFirst', presence="no", position=0)
+    if retval != 0:
+        print "After Delete VBRIFONE Validate Failed"
+        exit(1)
+
+    retval = vbrif_portmap.delete_vbrif('VtnOne', 'VbrOne', 'VbrIfFour')
+    if retval != 0:
+        print "VTN1->VBR1->VBRIF1 Delete Failed"
+        exit(1)
+
+    retval = vbrif_portmap.validate_vbrif_at_controller('VtnOne', 'VbrOne', 'VbrIfFour', 'ControllerFirst', presence="no", position=0)
+    if retval != 0:
+        print "After Delete VBRIFTWO Validate Failed"
+        exit(1)
+
+    retval = vtn_vbr.delete_vbr('VtnOne', 'VbrOne')
+    if retval != 0:
+        print "VBR/VTN Delete Failed"
+        exit(1)
+
+    retval = vtn_vbr.validate_vbr_at_controller('VtnOne', 'VbrOne', 'ControllerFirst', presence="no")
+    if retval != 0:
+        print "After Delete VBR Validate Failed"
+        exit(1)
+
+    retval = vtn_vbr.validate_vtn_at_controller('VtnOne', 'ControllerFirst', presence="no")
+    if retval != 0:
+        print "VTN Validate Failed"
+        exit(1)
+
+    retval = vtn_vbr.delete_vtn('VtnOne')
+    if retval != 0:
+        print "VTN Delete Failed in coordinator"
+        exit(1)
+
+    print "DELETE CONTROLLER"
+    retval = controller.delete_controller_ex('ControllerFirst')
+    if retval != 0:
+        print "CONTROLLER delete failed"
+        exit(1)
+    print "MININET PING DEMO 2 TEST SUCCESS"
+
+# Main Block
+if __name__ == '__main__':
+    print '*****MININET TESTS******'
+    test_vtn_mininet_ping_demo1()
+    test_vtn_mininet_ping_demo2()
+else:
+    print "MININET Loaded as Module"
index 08a57d2493d5487bb4866ee3cceaa95351102c83..5bc06bbe23a73b45c51d6ed2c5c4d6711c8bcab5 100644 (file)
@@ -123,7 +123,7 @@ def validate_vbrif_at_controller(vtn_blockname, vbr_blockname, vbrif_blockname,
 
 
 
-def create_portmap(vtn_blockname,vbr_blockname,vbrif_blockname):
+def create_portmap(vtn_blockname,vbr_blockname,vbrif_blockname,vlan_tagged=1):
     test_vtn_name=vtn_testconfig.ReadValues(VTNVBRDATA,vtn_blockname)['vtn_name']
     vtn_url=vtn_testconfig.ReadValues(VTNVBRDATA,vtn_blockname)['vtn_url']
     vbr_url=vtn_testconfig.ReadValues(VTNVBRDATA,vbr_blockname)['vbr_url']
@@ -144,8 +144,9 @@ def create_portmap(vtn_blockname,vbr_blockname,vbrif_blockname):
     vbrif_add = collections.defaultdict(dict)
 
     vbrif_add['portmap']['logical_port_id']=logical_port_id
-    vbrif_add['portmap']['vlan_id']=vlan_id
-    vbrif_add['portmap']['tagged']=tagged
+    if vlan_tagged == 1:
+      vbrif_add['portmap']['vlan_id']=vlan_id
+      vbrif_add['portmap']['tagged']=tagged
     print json.dumps(vbrif_add)
     r = requests.put(url,data=json.dumps(vbrif_add),headers=def_header)
     print r.status_code
index 610fab7f066d84561d1ccc144d667a866e5dafa5..8236a90703ba6016ab1fab433578662abfa6b217 100644 (file)
@@ -43,7 +43,7 @@ VTNVBRDATA = "vtn_vbr.data"
 VBRIFDATA = "vtn_vbr_vbrif.data"
 VLANMAPDATA = "vtn_vbr_vlanmap.data"
 CONTROLLERDATA = "controller.data"
-
+MININETDATA = "mininet_test.data"
 
 if __name__ == '__main__':
   print 'Cannot Run this module as it holds only methods'
index 56236742bf726842989248bf689e3bf5fe36d98c..00dd2a5b8349fe364d67b5b1d590b211384531b5 100644 (file)
@@ -4,8 +4,8 @@ description=first vbrif for vbrone
 admin_status=true
 controller_url=/interfaces/vbrifone
 vbrif_url=/interfaces/vbrifone
-logical_port_id=PP-00:00:00:00:00:00:00:01-s1-eth2
-node_id=00:00:00:00:00:00:00:01
+logical_port_id=PP-00:00:00:00:00:00:00:03-s3-eth1
+node_id=00:00:00:00:00:00:00:03
 vlan_id=1
 tagged=true
 
@@ -15,7 +15,7 @@ description=second vbrif for vbrone
 admin_status=false
 controller_url=/interfaces/vbriftwo
 vbrif_url=/interfaces/vbriftwo
-logical_port_id=PP-00:00:00:00:00:00:00:02-s2-eth2
+logical_port_id=PP-00:00:00:00:00:00:00:02-s2-eth1
 node_id=00:00:00:00:00:00:00:02
 vlan_id=1
 vlan_id=2
@@ -39,8 +39,8 @@ description=second vbrif for vbrtwo
 admin_status=false
 controller_url=/interfaces/vbriffour
 vbrif_url=/interfaces/vbriffour
-logical_port_id=PP-00:00:00:00:00:00:00:04-s4-eth2
-node_id=00:00:00:00:00:00:00:04
+logical_port_id=PP-00:00:00:00:00:00:00:02-s2-eth2
+node_id=00:00:00:00:00:00:00:02
 vlan_id=1
 vlan_id=4
 tagged=true