Upgrade RF syntax for v3.2 compatibility
[integration/test.git] / csit / suites / openstack / securitygroup / security_group_l3bcast.robot
1 *** Settings ***
2 Documentation     Test Suite for Network and Subnet Broadcast with security group
3 Suite Setup       Start Suite
4 Suite Teardown    OpenStackOperations.OpenStack Suite Teardown
5 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
6 Test Teardown     OpenStackOperations.Get Test Teardown Debugs
7 Library           String
8 Library           RequestsLibrary
9 Library           SSHLibrary
10 Library           Collections
11 Library           json
12 Library           OperatingSystem
13 Resource          ../../../libraries/DevstackUtils.robot
14 Resource          ../../../libraries/KarafKeywords.robot
15 Resource          ../../../libraries/OpenStackOperations.robot
16 Resource          ../../../libraries/OVSDB.robot
17 Resource          ../../../libraries/OvsManager.robot
18 Resource          ../../../libraries/SetupUtils.robot
19 Resource          ../../../libraries/Utils.robot
20 Resource          ../../../variables/Variables.robot
21 Resource          ../../../variables/netvirt/Variables.robot
22
23 *** Variables ***
24 @{SECURITY_GROUP}    sgbcast1    sgbcast2
25 @{NETWORKS}       sgbcast_net_1    sgbcast_net_2
26 @{SUBNETS}        sgbcast_sub_1    sgbcast_sub_2
27 @{SUBNET_CIDRS}    55.0.0.0/24    56.0.0.0/24
28 ${ROUTER}         sgbcast_router
29 @{NET_1_PORTS}    sgbcast_net_1_port_1    sgbcast_net_1_port_2    sgbcast_net_1_port_3
30 @{NET_2_PORTS}    sgbcast_net_2_port_1    sgbcast_net_2_port_2
31 @{NET_1_VMS}      sgbcast_net_1_vm_1    sgbcast_net_1_vm_2    sgbcast_net_1_vm_3
32 @{NET_2_VMS}      sgbcast_net_2_vm_1    sgbcast_net_2_vm_2
33 ${DUMP_FLOW}      sudo ovs-ofctl dump-flows br-int -OOpenflow13
34 ${DUMP_PORT_DESC}    sudo ovs-ofctl dump-ports-desc br-int -OOpenflow13
35 ${PACKET_COUNT}    5
36 ${BCAST_IP}       255.255.255.255
37 ${SUBNET1_BCAST_IP}    55.0.0.255
38 ${SUBNET2_BCAST_IP}    56.0.0.255
39 ${ENABLE_BCAST}    echo 0 | sudo tee /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
40
41 *** Test Case ***
42 Verify Network Broadcast traffic between the VMs hosted in Single Network
43     [Documentation]    This TC is to verify Network Broadcast traffic between the VMs hosted in Same Network on same/different compute node
44     ${pkt_check} =    BuiltIn.Set Variable If    "${OPENSTACK_TOPO}" == "1cmb-0ctl-0cmp"    10    5
45     Wait Until Keyword Succeeds    30s    5s    Verify L3Broadcast With Antispoofing Table    ${OS_CMP1_IP}    ${EGRESS_ACL_TABLE}    ${BCAST_IP}
46     ...    @{VM_IPS}[0]    same    pingsuccess    pkt_check=${pkt_check}
47
48 Verify Network Broadcast traffic between the VMs hosted in Multi Network
49     [Documentation]    This TC is to verify Network Broadcast traffic between the VMs hosted in Different Network on same/different compute node.
50     ${pkt_check} =    BuiltIn.Set Variable If    "${OPENSTACK_TOPO}" == "1cmb-0ctl-0cmp"    5    0
51     Wait Until Keyword Succeeds    30s    5s    Verify L3Broadcast With Antispoofing Table    ${OS_CMP1_IP}    ${EGRESS_ACL_TABLE}    ${BCAST_IP}
52     ...    @{VM_IPS}[3]    different    pingsuccess    pkt_check=${pkt_check}
53
54 Verify Subnet Broadcast traffic between the VMs hosted on same compute node in Single Network
55     [Documentation]    Verify L3-Subnet Broadcast traffic between the VMs hosted on same compute node in Single Network
56     Wait Until Keyword Succeeds    30s    5s    Verify L3Broadcast With Antispoofing Table    ${OS_CMP1_IP}    ${EGRESS_ACL_TABLE}    ${SUBNET1_BCAST_IP}
57     ...    @{VM_IPS}[0]    same    pingsuccess    ${VM2_SUBMETA}    pkt_check=5    additional_args=| grep ${VM2_SUBMETA}
58
59 Verify Subnet Broadcast traffic between the VMs hosted on Different compute node in Single Network
60     [Documentation]    Verify L3-Subnet Broadcast traffic between the VMs hosted on same compute node in Single Network
61     Wait Until Keyword Succeeds    30s    5s    Verify L3Broadcast With Antispoofing Table    ${OS_CMP2_IP}    ${EGRESS_ACL_TABLE}    ${SUBNET1_BCAST_IP}
62     ...    @{VM_IPS}[0]    same    pingsuccess    ${VM3_SUBMETA}    pkt_check=5    additional_args=| grep ${VM3_SUBMETA}
63
64 Verify Subnet Broadcast traffic between the VMs hosted on same compute node in Multi Network
65     [Documentation]    Verify L3-Subnet Broadcast traffic between the VMs hosted on same compute node in Multi Network
66     Wait Until Keyword Succeeds    30s    5s    Verify L3Broadcast With Antispoofing Table    ${OS_CMP1_IP}    ${EGRESS_ACL_TABLE}    ${SUBNET2_BCAST_IP}
67     ...    @{VM_IPS}[0]    different    nosuccess    ${VM4_SUBMETA}    pkt_check=0    additional_args=| grep ${VM4_SUBMETA}
68
69 Verify Subnet Broadcast traffic between the VMs hosted on Different compute node in Multi Network
70     [Documentation]    Verify L3-Subnet Broadcast traffic between the VMs hosted on Different compute node in Multi Network
71     Wait Until Keyword Succeeds    30s    5s    Verify L3Broadcast With Antispoofing Table    ${OS_CMP2_IP}    ${EGRESS_ACL_TABLE}    ${SUBNET2_BCAST_IP}
72     ...    @{VM_IPS}[0]    different    nosuccess    ${VM5_SUBMETA}    pkt_check=0    additional_args=| grep ${VM5_SUBMETA}
73
74 *** Keywords ***
75 Start Suite
76     [Documentation]    Test Suite for Network and Subnet Broadcast with security group
77     OpenStackOperations.OpenStack Suite Setup
78     Create Setup
79     OpenStackOperations.Show Debugs    @{NET_1_VMS}    @{NET_2_VMS}
80     OpenStackOperations.Get Suite Debugs
81
82 Create Setup
83     FOR    ${network}    IN    @{NETWORKS}
84         OpenStackOperations.Create Network    ${network}
85     END
86     FOR    ${i}    IN RANGE    len(${NETWORKS})
87         OpenStackOperations.Create SubNet    @{NETWORKS}[${i}]    @{SUBNETS}[${i}]    @{SUBNET_CIDRS}[${i}]
88     END
89     OpenStackOperations.Create Allow All SecurityGroup    @{SECURITY_GROUP}[0]
90     OpenStackOperations.Create Router    ${ROUTER}
91     FOR    ${interface}    IN    @{SUBNETS}
92         OpenStackOperations.Add Router Interface    ${ROUTER}    ${interface}
93     END
94     FOR    ${port_net1}    IN    @{NET_1_PORTS}
95         OpenStackOperations.Create Port    @{NETWORKS}[0]    ${port_net1}    sg=@{SECURITY_GROUP}[0]
96     END
97     FOR    ${port_net2}    IN    @{NET_2_PORTS}
98         OpenStackOperations.Create Port    @{NETWORKS}[1]    ${port_net2}    sg=@{SECURITY_GROUP}[0]
99     END
100     @{ports} =    BuiltIn.Create List    @{NET_1_PORTS}[0]    @{NET_1_PORTS}[1]    @{NET_1_PORTS}[2]    @{NET_2_PORTS}[0]    @{NET_2_PORTS}[1]
101     @{vms} =    BuiltIn.Create List    @{NET_1_VMS}[0]    @{NET_1_VMS}[1]    @{NET_1_VMS}[2]    @{NET_2_VMS}[0]    @{NET_2_VMS}[1]
102     @{nodes} =    BuiltIn.Create List    ${OS_CMP1_HOSTNAME}    ${OS_CMP1_HOSTNAME}    ${OS_CMP2_HOSTNAME}    ${OS_CMP1_HOSTNAME}    ${OS_CMP2_HOSTNAME}
103     FOR    ${port}    ${vm}    ${node}    IN ZIP    ${ports}    ${vms}
104     ...    ${nodes}
105         OpenStackOperations.Create Vm Instance With Port On Compute Node    ${port}    ${vm}    ${node}    sg=@{SECURITY_GROUP}[0]
106     END
107     @{vms} =    Collections.Combine Lists    ${NET_1_VMS}    ${NET_2_VMS}
108     @{VM_IPS} =    OpenStackOperations.Get VM IPs    @{vms}
109     BuiltIn.Should Not Contain    ${VM_IPS}    None
110     BuiltIn.Set Suite Variable    @{VM_IPS}
111     OpenStackOperations.Execute Command on VM Instance    ${NETWORKS[0]}    @{VM_IPS}[0]    ${ENABLE_BCAST}
112     OpenStackOperations.Execute Command on VM Instance    ${NETWORKS[1]}    @{VM_IPS}[3]    ${ENABLE_BCAST}
113     ${vm1_in_port}    ${vm1_meta} =    BuiltIn.Wait Until Keyword Succeeds    60s    10s    Get VMs Metadata and In Port    @{NET_1_PORTS}[0]
114     ...    ${OS_CMP1_IP}
115     ${vm2_in_port}    ${vm2_meta} =    BuiltIn.Wait Until Keyword Succeeds    60s    10s    Get VMs Metadata and In Port    @{NET_1_PORTS}[1]
116     ...    ${OS_CMP1_IP}
117     ${vm3_in_port}    ${vm3_meta} =    BuiltIn.Wait Until Keyword Succeeds    60s    10s    Get VMs Metadata and In Port    @{NET_1_PORTS}[2]
118     ...    ${OS_CMP2_IP}
119     ${vm4_in_port}    ${vm4_meta} =    BuiltIn.Wait Until Keyword Succeeds    60s    10s    Get VMs Metadata and In Port    @{NET_2_PORTS}[0]
120     ...    ${OS_CMP1_IP}
121     ${vm5_in_port}    ${vm5_meta} =    BuiltIn.Wait Until Keyword Succeeds    60s    10s    Get VMs Metadata and In Port    @{NET_2_PORTS}[1]
122     ...    ${OS_CMP2_IP}
123     ${VM1_SUBMETA} =    Get Submetadata    ${vm1_meta}
124     ${VM2_SUBMETA} =    Get Submetadata    ${vm2_meta}
125     ${VM3_SUBMETA} =    Get Submetadata    ${vm3_meta}
126     ${VM4_SUBMETA} =    Get Submetadata    ${vm4_meta}
127     ${VM5_SUBMETA} =    Get Submetadata    ${vm5_meta}
128     BuiltIn.Set Suite Variable    ${VM1_SUBMETA}
129     BuiltIn.Set Suite Variable    ${VM2_SUBMETA}
130     BuiltIn.Set Suite Variable    ${VM3_SUBMETA}
131     BuiltIn.Set Suite Variable    ${VM4_SUBMETA}
132     BuiltIn.Set Suite Variable    ${VM5_SUBMETA}
133
134 Get VMs Metadata and In Port
135     [Arguments]    ${portname}    ${OS_COMPUTE_IP}
136     [Documentation]    This keyword is to get the VM metadata and the in_port Id of the VM
137     ${subport} =    OpenStackOperations.Get Sub Port Id    ${portname}
138     ${get_vm_in_port} =    Utils.Run Command On Remote System And Log    ${OS_COMPUTE_IP}    ${DUMP_PORT_DESC} | grep ${subport} | awk '{print$1}'
139     ${vms_in_port} =    BuiltIn.Should Match Regexp    ${get_vm_in_port}    [0-9]+
140     ${grep_metadata} =    Utils.Run Command On Remote System And Log    ${OS_COMPUTE_IP}    ${DUMP_FLOW} | grep table=${VLAN_INTERFACE_INGRESS_TABLE} | grep in_port=${vms_in_port} | awk '{print$7}'
141     @{metadata} =    String.Split string    ${grep_metadata}    ,
142     ${get_write_metadata} =    Collections.get from list    ${metadata}    0
143     @{complete_metadata} =    String.Split string    ${get_write_metadata}    :
144     ${extract_metadata} =    Collections.get from list    ${complete_metadata}    1
145     @{split_metadata} =    String.Split string    ${extract_metadata}    /
146     ${vm_metadata} =    Collections.Get From List    ${split_metadata}    0
147     [Return]    ${vms_in_port}    ${vm_metadata}
148
149 Get Submetadata
150     [Arguments]    ${vm_metadata}
151     [Documentation]    Get the submetadata of the VM
152     ${cmd1} =    Utils.Run Command On Remote System And Log    ${OS_CMP1_IP}    ${DUMP_FLOW} | grep ${EGRESS_LPORT_DISPATCHER_TABLE} | grep write_metadata:
153     ${output1} =    String.Get Regexp Matches    ${cmd1}    reg6=(\\w+)    1
154     ${cmd2} =    Utils.Run Command On Remote System And Log    ${OS_CMP2_IP}    ${DUMP_FLOW} | grep ${EGRESS_LPORT_DISPATCHER_TABLE} | grep write_metadata:
155     ${output2} =    String.Get Regexp Matches    ${cmd2}    reg6=(\\w+)    1
156     ${metalist} =    Collections.Combine Lists    ${output1}    ${output2}
157     FOR    ${meta}    IN    @{metalist}
158         ${metadata_check_status} =    Run Keyword And Return Status    should contain    ${vm_metadata}    ${meta}
159         Return From Keyword if    ${metadata_check_status} == True    ${meta}
160     END
161
162 Verify L3Broadcast With Antispoofing Table
163     [Arguments]    ${OS_COMPUTE_IP}    ${EGRESS_ACL_TABLE}    ${BCAST_IP}    ${vm_ip}    ${subnet_var}    ${ping_response}='pingsuccess'
164     ...    ${vm_submeta}=''    ${pkt_check}=0    ${additional_args}=${EMPTY}
165     [Documentation]    Verify the l3 broadcast requests are hitting to antispoofing table in same subnet
166     ${get_pkt_count_before_bcast} =    OvsManager.Get Packet Count In Table For IP    ${OS_COMPUTE_IP}    ${EGRESS_ACL_TABLE}    ${BCAST_IP}    additional_args=| grep ${vm_submeta}
167     ${output} =    OpenStackOperations.Execute Command on VM Instance    @{NETWORKS}[0]    ${vm_ip}    ping -c ${PACKET_COUNT} ${BCAST_IP}
168     BuiltIn.Run Keyword If    '${ping_response}'=='pingsuccess'    BuiltIn.Should Contain    ${output}    ${PING_REGEXP}
169     ...    ELSE    BuiltIn.Should Contain    ${output}    ${NO_PING_REGEXP}
170     ${bcast_egress} =    Utils.Run Command On Remote System And Log    ${OS_COMPUTE_IP}    ${DUMP_FLOW} | grep table=${EGRESS_ACL_TABLE} | grep ${BCAST_IP} ${additional_args}
171     ${get_pkt_count_after_bcast} =    OvsManager.Get Packet Count In Table For IP    ${OS_COMPUTE_IP}    ${EGRESS_ACL_TABLE}    ${BCAST_IP}    additional_args=| grep ${vm_submeta}
172     ${pkt_diff} =    Evaluate    int(${get_pkt_count_after_bcast})-int(${get_pkt_count_before_bcast})
173     BuiltIn.Should Be Equal As Numbers    ${pkt_diff}    ${pkt_check}