Subnet Broadcast Tests added.
[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 ${PACKET_COUNT_CMB}    10
37 ${PACKET_DIFF}    0
38 ${PACKET_DIFF_CMB}    5
39 ${BCAST_IP}       255.255.255.255
40 ${SUBNET1_BCAST_IP}    55.0.0.255
41 ${SUBNET2_BCAST_IP}    56.0.0.255
42 ${ENABLE_BCAST}    echo 0 | sudo tee /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
43
44 *** Test case ***
45 Verify Network Broadcast traffic between the VMs hosted in Single Network
46     [Documentation]    This TC is to verify Network Broadcast traffic between the VMs hosted in Same Network on same/different compute node
47     Wait Until Keyword Succeeds    30s    5s    Verify L3Broadcast With Antispoofing Table    ${OS_COMPUTE1_IP}    ${EGRESS_ACL_TABLE}    ${BCAST_IP}
48     ...    @{VM_IPS}[0]    same    pingsuccess
49
50 Verify Network Broadcast traffic between the VMs hosted in Multi Network
51     [Documentation]    This TC is to verify Network Broadcast traffic between the VMs hosted in Different Network on same/different compute node.
52     Wait Until Keyword Succeeds    30s    5s    Verify L3Broadcast With Antispoofing Table    ${OS_COMPUTE1_IP}    ${EGRESS_ACL_TABLE}    ${BCAST_IP}
53     ...    @{VM_IPS}[3]    different    pingsuccess
54
55 Verify Subnet Broadcast traffic between the VMs hosted on same compute node in Single Network
56     [Documentation]    Verify L3-Subnet Broadcast traffic between the VMs hosted on same compute node in Single Network
57     Wait Until Keyword Succeeds    30s    5s    Verify L3Broadcast With Antispoofing Table    ${OS_COMPUTE1_IP}    ${EGRESS_ACL_TABLE}    ${SUBNET1_BCAST_IP}
58     ...    @{VM_IPS}[0]    same    pingsuccess    ${VM2_SUBMETA}    additional_args=| grep ${VM2_SUBMETA}
59
60 Verify Subnet Broadcast traffic between the VMs hosted on Different compute node in Single Network
61     [Documentation]    Verify L3-Subnet Broadcast traffic between the VMs hosted on same compute node in Single Network
62     Wait Until Keyword Succeeds    30s    5s    Verify L3Broadcast With Antispoofing Table    ${OS_COMPUTE2_IP}    ${EGRESS_ACL_TABLE}    ${SUBNET1_BCAST_IP}
63     ...    @{VM_IPS}[0]    same    pingsuccess    ${VM3_SUBMETA}    additional_args=| grep ${VM3_SUBMETA}
64
65 Verify Subnet Broadcast traffic between the VMs hosted on same compute node in Multi Network
66     [Documentation]    Verify L3-Subnet Broadcast traffic between the VMs hosted on same compute node in Multi Network
67     Wait Until Keyword Succeeds    30s    5s    Verify L3Broadcast With Antispoofing Table    ${OS_COMPUTE1_IP}    ${EGRESS_ACL_TABLE}    ${SUBNET2_BCAST_IP}
68     ...    @{VM_IPS}[0]    different    nosuccess    ${VM4_SUBMETA}    additional_args=| grep ${VM4_SUBMETA}
69
70 Verify Subnet Broadcast traffic between the VMs hosted on Different compute node in Multi Network
71     [Documentation]    Verify L3-Subnet Broadcast traffic between the VMs hosted on Different compute node in Multi Network
72     Wait Until Keyword Succeeds    30s    5s    Verify L3Broadcast With Antispoofing Table    ${OS_COMPUTE2_IP}    ${EGRESS_ACL_TABLE}    ${SUBNET2_BCAST_IP}
73     ...    @{VM_IPS}[0]    different    nosuccess    ${VM5_SUBMETA}    additional_args=| grep ${VM5_SUBMETA}
74
75 *** Keywords ***
76 Start Suite
77     [Documentation]    Test Suite for Network and Subnet Broadcast with security group
78     OpenStackOperations.OpenStack Suite Setup
79     Create Setup
80     OpenStackOperations.Show Debugs    @{NET_1_VMS}    @{NET_2_VMS}
81     OpenStackOperations.Get Suite Debugs
82
83 Create Setup
84     : FOR    ${network}    IN    @{NETWORKS}
85     \    OpenStackOperations.Create Network    ${network}
86     : FOR    ${i}    IN RANGE    len(${NETWORKS})
87     \    OpenStackOperations.Create SubNet    @{NETWORKS}[${i}]    @{SUBNETS}[${i}]    @{SUBNET_CIDRS}[${i}]
88     OpenStackOperations.Create Allow All SecurityGroup    @{SECURITY_GROUP}[0]
89     OpenStackOperations.Create Router    ${ROUTER}
90     : FOR    ${interface}    IN    @{SUBNETS}
91     \    OpenStackOperations.Add Router Interface    ${ROUTER}    ${interface}
92     : FOR    ${port_net1}    IN    @{NET_1_PORTS}
93     \    OpenStackOperations.Create Port    @{NETWORKS}[0]    ${port_net1}    sg=@{SECURITY_GROUP}[0]
94     : FOR    ${port_net2}    IN    @{NET_2_PORTS}
95     \    OpenStackOperations.Create Port    @{NETWORKS}[1]    ${port_net2}    sg=@{SECURITY_GROUP}[0]
96     @{ports} =    BuiltIn.Create List    @{NET_1_PORTS}[0]    @{NET_1_PORTS}[1]    @{NET_1_PORTS}[2]    @{NET_2_PORTS}[0]    @{NET_2_PORTS}[1]
97     @{vms} =    BuiltIn.Create List    @{NET_1_VMS}[0]    @{NET_1_VMS}[1]    @{NET_1_VMS}[2]    @{NET_2_VMS}[0]    @{NET_2_VMS}[1]
98     @{nodes} =    BuiltIn.Create List    ${OS_CMP1_HOSTNAME}    ${OS_CMP1_HOSTNAME}    ${OS_CMP2_HOSTNAME}    ${OS_CMP1_HOSTNAME}    ${OS_CMP2_HOSTNAME}
99     : FOR    ${port}    ${vm}    ${node}    IN ZIP    ${ports}    ${vms}
100     ...    ${nodes}
101     \    OpenStackOperations.Create Vm Instance With Port On Compute Node    ${port}    ${vm}    ${node}    sg=@{SECURITY_GROUP}[0]
102     @{vms} =    Collections.Combine Lists    ${NET_1_VMS}    ${NET_2_VMS}
103     @{VM_IPS} =    OpenStackOperations.Get VM IPs    @{vms}
104     BuiltIn.Should Not Contain    ${VM_IPS}    None
105     BuiltIn.Set Suite Variable    @{VM_IPS}
106     OpenStackOperations.Execute Command on VM Instance    ${NETWORKS[0]}    @{VM_IPS}[0]    ${ENABLE_BCAST}
107     OpenStackOperations.Execute Command on VM Instance    ${NETWORKS[1]}    @{VM_IPS}[3]    ${ENABLE_BCAST}
108     ${vm1_in_port}    ${vm1_meta} =    BuiltIn.Wait Until Keyword Succeeds    60s    10s    Get VMs Metadata and In Port    @{NET_1_PORTS}[0]
109     ...    ${OS_CMP1_IP}
110     ${vm2_in_port}    ${vm2_meta} =    BuiltIn.Wait Until Keyword Succeeds    60s    10s    Get VMs Metadata and In Port    @{NET_1_PORTS}[1]
111     ...    ${OS_CMP1_IP}
112     ${vm3_in_port}    ${vm3_meta} =    BuiltIn.Wait Until Keyword Succeeds    60s    10s    Get VMs Metadata and In Port    @{NET_1_PORTS}[2]
113     ...    ${OS_CMP2_IP}
114     ${vm4_in_port}    ${vm4_meta} =    BuiltIn.Wait Until Keyword Succeeds    60s    10s    Get VMs Metadata and In Port    @{NET_2_PORTS}[0]
115     ...    ${OS_CMP1_IP}
116     ${vm5_in_port}    ${vm5_meta} =    BuiltIn.Wait Until Keyword Succeeds    60s    10s    Get VMs Metadata and In Port    @{NET_2_PORTS}[1]
117     ...    ${OS_CMP2_IP}
118     ${VM1_SUBMETA} =    Get Submetadata    ${vm1_meta}
119     ${VM2_SUBMETA} =    Get Submetadata    ${vm2_meta}
120     ${VM3_SUBMETA} =    Get Submetadata    ${vm3_meta}
121     ${VM4_SUBMETA} =    Get Submetadata    ${vm4_meta}
122     ${VM5_SUBMETA} =    Get Submetadata    ${vm5_meta}
123     BuiltIn.Set Suite Variable    ${VM1_SUBMETA}
124     BuiltIn.Set Suite Variable    ${VM2_SUBMETA}
125     BuiltIn.Set Suite Variable    ${VM3_SUBMETA}
126     BuiltIn.Set Suite Variable    ${VM4_SUBMETA}
127     BuiltIn.Set Suite Variable    ${VM5_SUBMETA}
128
129 Get VMs Metadata and In Port
130     [Arguments]    ${portname}    ${OS_COMPUTE_IP}
131     [Documentation]    This keyword is to get the VM metadata and the in_port Id of the VM
132     ${subport} =    OpenStackOperations.Get Sub Port Id    ${portname}
133     ${get_vm_in_port} =    Utils.Run Command On Remote System And Log    ${OS_COMPUTE_IP}    ${DUMP_PORT_DESC} | grep ${subport} | awk '{print$1}'
134     ${vms_in_port} =    BuiltIn.Should Match Regexp    ${get_vm_in_port}    [0-9]+
135     ${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}'
136     @{metadata} =    String.Split string    ${grep_metadata}    ,
137     ${get_write_metadata} =    Collections.get from list    ${metadata}    0
138     @{complete_metadata} =    String.Split string    ${get_write_metadata}    :
139     ${extract_metadata} =    Collections.get from list    ${complete_metadata}    1
140     @{split_metadata} =    String.Split string    ${extract_metadata}    /
141     ${vm_metadata} =    Collections.Get From List    ${split_metadata}    0
142     [Return]    ${vms_in_port}    ${vm_metadata}
143
144 Get Submetadata
145     [Arguments]    ${vm_metadata}
146     [Documentation]    Get the submetadata of the VM
147     ${cmd1} =    Utils.Run Command On Remote System And Log    ${OS_CMP1_IP}    ${DUMP_FLOW} | grep ${EGRESS_LPORT_DISPATCHER_TABLE} | grep write_metadata:
148     ${output1} =    String.Get Regexp Matches    ${cmd1}    reg6=(\\w+)    1
149     ${cmd2} =    Utils.Run Command On Remote System And Log    ${OS_CMP2_IP}    ${DUMP_FLOW} | grep ${EGRESS_LPORT_DISPATCHER_TABLE} | grep write_metadata:
150     ${output2} =    String.Get Regexp Matches    ${cmd2}    reg6=(\\w+)    1
151     ${metalist} =    Collections.Combine Lists    ${output1}    ${output2}
152     : FOR    ${meta}    IN    @{metalist}
153     \    ${metadata_check_status} =    Run Keyword And Return Status    should contain    ${vm_metadata}    ${meta}
154     \    Return From Keyword if    ${metadata_check_status} == True    ${meta}
155
156 Verify L3Broadcast With Antispoofing Table
157     [Arguments]    ${OS_COMPUTE_IP}    ${EGRESS_ACL_TABLE}    ${BCAST_IP}    ${vm_ip}    ${subnet_var}    ${ping_response}='pingsuccess'
158     ...    ${vm_submeta}=''    ${additional_args}=${EMPTY}
159     [Documentation]    Verify the l3 broadcast requests are hitting to antispoofing table in same subnet
160     ${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}
161     ${output} =    OpenStackOperations.Execute Command on VM Instance    @{NETWORKS}[0]    ${vm_ip}    ping -c ${PACKET_COUNT} ${BCAST_IP}
162     BuiltIn.Run Keyword If    '${ping_response}'=='pingsuccess'    BuiltIn.Should Contain    ${output}    ${PING_REGEXP}
163     ...    ELSE    BuiltIn.Should Contain    ${output}    ${NO_PING_REGEXP}
164     ${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}
165     ${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}
166     ${pkt_diff} =    Evaluate    int(${get_pkt_count_after_bcast})-int(${get_pkt_count_before_bcast})
167     BuiltIn.Run Keyword If    '${subnet_var}' == 'same'    Should Be Equal As Numbers    ${pkt_diff}    ${PACKET_COUNT}
168     ...    ELSE    Should Be True    ${pkt_diff}==0