Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1 | import Queue |
| 2 | |
| 3 | from oftest.testutils import * |
| 4 | from accton_util import * |
| 5 | |
Pier | 7b031af | 2016-08-25 15:00:22 -0700 | [diff] [blame] | 6 | def fill_mcast_pipeline_L3toL2( |
| 7 | controller, |
| 8 | logging, |
| 9 | ports, |
| 10 | is_ingress_tagged, |
| 11 | is_egress_tagged, |
| 12 | is_vlan_translated, |
| 13 | is_max_vlan |
| 14 | ): |
| 15 | """ |
| 16 | This method, according to the scenario, fills properly |
| 17 | the pipeline. The method generates using ports data the |
| 18 | necessary information to fill the multicast pipeline and |
| 19 | fills properly the pipeline which consists in this scenario: |
| 20 | |
| 21 | i) to create l2 interface groups; |
| 22 | ii) to create l3 multicast groups; |
| 23 | iii) to add multicast flows; |
| 24 | iv) to add termination; flows; |
| 25 | v) to add vlan flows |
| 26 | |
| 27 | Scenarios: |
| 28 | 1) ingress untagged, egress untagged |
| 29 | 2) ingress untagged, egress tagged |
| 30 | 3) ingress tagged, egress untagged |
| 31 | 4) ingress tagged, egress tagged, no translation |
| 32 | 5) ingress tagged, egress tagged, translation |
| 33 | """ |
| 34 | |
| 35 | MAX_INTERNAL_VLAN = 4094 |
| 36 | # Used for no translation |
| 37 | FIXED_VLAN = 300 |
| 38 | Groups = Queue.LifoQueue( ) |
| 39 | L2_Groups = [] |
| 40 | port_to_in_vlan = {} |
| 41 | port_to_out_vlan = {} |
| 42 | port_to_src_mac = {} |
| 43 | port_to_src_mac_str = {} |
| 44 | port_to_dst_mac = {} |
| 45 | port_to_dst_mac_str = {} |
| 46 | port_to_src_ip = {} |
| 47 | port_to_src_ip_str = {} |
| 48 | src_ip_0 = 0xc0a80100 |
| 49 | src_ip_0_str = "192.168.1.%s" |
| 50 | dst_ip = 0xe0000001 |
| 51 | switch_mac = [ 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 ] |
| 52 | |
| 53 | for port in ports: |
| 54 | in_vlan_id = port + 1 |
| 55 | out_vlan_id = MAX_INTERNAL_VLAN - port |
| 56 | if is_max_vlan and not is_vlan_translated: |
| 57 | in_vlan_id = MAX_INTERNAL_VLAN |
| 58 | out_vlan_id = MAX_INTERNAL_VLAN |
| 59 | elif not is_max_vlan and not is_vlan_translated: |
| 60 | in_vlan_id = FIXED_VLAN |
| 61 | out_vlan_id = FIXED_VLAN |
| 62 | src_mac = [ 0x00, 0x11, 0x11, 0x11, 0x11, port ] |
| 63 | src_mac_str = ':'.join( [ '%02X' % x for x in src_mac ] ) |
| 64 | dst_mac = [ 0x01, 0x00, 0x5e, 0x01, 0x01, port ] |
| 65 | dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] ) |
| 66 | src_ip = src_ip_0 + port |
| 67 | src_ip_str = src_ip_0_str % port |
| 68 | port_to_in_vlan[port] = in_vlan_id |
| 69 | port_to_out_vlan[port] = out_vlan_id |
| 70 | port_to_src_mac[port] = src_mac |
| 71 | port_to_src_mac_str[port] = src_mac_str |
| 72 | port_to_dst_mac[port] = dst_mac |
| 73 | port_to_dst_mac_str[port] = dst_mac_str |
| 74 | port_to_src_ip[port] = src_ip |
| 75 | port_to_src_ip_str[port] = src_ip_str |
| 76 | |
| 77 | for in_port in ports: |
| 78 | |
| 79 | L2_Groups = [] |
| 80 | # add vlan flows table |
| 81 | add_one_vlan_table_flow( controller, in_port, port_to_in_vlan[in_port], flag=VLAN_TABLE_FLAG_ONLY_TAG ) |
| 82 | if not is_ingress_tagged: |
| 83 | add_one_vlan_table_flow( controller, in_port, port_to_in_vlan[in_port], flag=VLAN_TABLE_FLAG_ONLY_UNTAG ) |
| 84 | elif is_vlan_translated: |
| 85 | add_one_vlan_table_flow_translation( controller, in_port, port_to_in_vlan[in_port], port_to_out_vlan[in_port], flag=VLAN_TABLE_FLAG_ONLY_TAG) |
| 86 | # add termination flow |
| 87 | if not is_vlan_translated: |
| 88 | add_termination_flow( controller, in_port, 0x0800, switch_mac, port_to_in_vlan[in_port] ) |
| 89 | else: |
| 90 | add_termination_flow( controller, in_port, 0x0800, switch_mac, port_to_out_vlan[in_port] ) |
| 91 | |
| 92 | for out_port in ports: |
| 93 | if out_port == in_port: |
| 94 | continue |
| 95 | # add l2 interface group, vlan_id equals for each port and must coincide with mcast_group vlan_id |
| 96 | if not is_vlan_translated: |
| 97 | l2gid, msg = add_one_l2_interface_group( controller, out_port, vlan_id=port_to_in_vlan[in_port], |
| 98 | is_tagged=is_egress_tagged, send_barrier=True ) |
| 99 | else: |
| 100 | l2gid, msg = add_one_l2_interface_group( controller, out_port, vlan_id=port_to_out_vlan[in_port], |
| 101 | is_tagged=is_egress_tagged, send_barrier=True ) |
| 102 | Groups._put( l2gid ) |
| 103 | L2_Groups.append( l2gid ) |
| 104 | |
| 105 | # add l3 mcast group |
| 106 | if not is_vlan_translated: |
| 107 | mcat_group_msg = add_l3_mcast_group( controller, port_to_in_vlan[in_port], in_port, L2_Groups ) |
| 108 | else: |
| 109 | mcat_group_msg = add_l3_mcast_group( controller, port_to_out_vlan[in_port], in_port, L2_Groups ) |
| 110 | Groups._put( mcat_group_msg.group_id ) |
| 111 | # add mcast routing flow |
| 112 | if not is_vlan_translated: |
| 113 | add_mcast4_routing_flow( controller, port_to_in_vlan[in_port], port_to_src_ip[in_port], 0, dst_ip, mcat_group_msg.group_id ) |
| 114 | else: |
| 115 | add_mcast4_routing_flow( controller, port_to_out_vlan[in_port], port_to_src_ip[in_port], 0, dst_ip, mcat_group_msg.group_id ) |
| 116 | |
| 117 | return ( |
| 118 | port_to_in_vlan, |
| 119 | port_to_out_vlan, |
| 120 | port_to_src_mac_str, |
| 121 | port_to_dst_mac_str, |
| 122 | port_to_src_ip_str, |
| 123 | Groups |
| 124 | ) |
| 125 | |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 126 | def fill_mcast_pipeline_L3toL3( |
| 127 | controller, |
| 128 | logging, |
| 129 | ports, |
| 130 | is_ingress_tagged, |
| 131 | is_egress_tagged, |
| 132 | is_vlan_translated, |
| 133 | is_max_vlan |
| 134 | ): |
| 135 | """ |
| 136 | This method, according to the scenario, fills properly |
| 137 | the pipeline. The method generates using ports data the |
| 138 | necessary information to fill the multicast pipeline and |
| 139 | fills properly the pipeline which consists in this scenario: |
| 140 | |
| 141 | i) to create l2 interface groups; |
| 142 | ii)to create l3 interface groups; |
| 143 | iii) to create l3 multicast groups; |
| 144 | iv) to add multicast flows; |
| 145 | v) to add termination; flows; |
| 146 | vi) to add vlan flows |
| 147 | |
| 148 | Scenarios: |
| 149 | 1) ingress tagged, egress tagged, translation |
| 150 | """ |
| 151 | |
| 152 | Groups = Queue.LifoQueue( ) |
| 153 | MAX_INTERNAL_VLAN = 4094 |
| 154 | port_to_in_vlan = {} |
| 155 | port_to_out_vlan = {} |
| 156 | port_to_src_mac = {} |
| 157 | port_to_src_mac_str = {} |
| 158 | port_to_dst_mac = {} |
| 159 | port_to_dst_mac_str = {} |
| 160 | port_to_src_ip = {} |
| 161 | port_to_src_ip_str = {} |
| 162 | port_to_intf_src_mac = {} |
| 163 | port_to_intf_src_mac_str = {} |
| 164 | src_ip_0 = 0xc0a80100 |
| 165 | src_ip_0_str = "192.168.1.%s" |
| 166 | dst_ip = 0xe0000001 |
| 167 | switch_mac = [ 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 ] |
| 168 | |
| 169 | for port in ports: |
| 170 | in_vlan_id = port + 1 |
| 171 | out_vlan_id = MAX_INTERNAL_VLAN - port |
| 172 | src_mac = [ 0x00, 0x11, 0x11, 0x11, 0x11, port ] |
| 173 | src_mac_str = ':'.join( [ '%02X' % x for x in src_mac ] ) |
| 174 | dst_mac = [ 0x01, 0x00, 0x5e, 0x01, 0x01, port ] |
| 175 | dst_mac_str = ':'.join( [ '%02X' % x for x in dst_mac ] ) |
| 176 | src_ip = src_ip_0 + port |
| 177 | src_ip_str = src_ip_0_str % port |
| 178 | intf_src_mac = [ 0x00, 0x00, 0x00, 0xcc, 0xcc, port ] |
| 179 | intf_src_mac_str = ':'.join( [ '%02X' % x for x in intf_src_mac ] ) |
| 180 | port_to_in_vlan[port] = in_vlan_id |
| 181 | port_to_out_vlan[port] = out_vlan_id |
| 182 | port_to_src_mac[port] = src_mac |
| 183 | port_to_src_mac_str[port] = src_mac_str |
| 184 | port_to_dst_mac[port] = dst_mac |
| 185 | port_to_dst_mac_str[port] = dst_mac_str |
| 186 | port_to_src_ip[port] = src_ip |
| 187 | port_to_src_ip_str[port] = src_ip_str |
| 188 | port_to_intf_src_mac[port] = intf_src_mac |
| 189 | port_to_intf_src_mac_str[port] = intf_src_mac_str |
| 190 | |
| 191 | for port in ports: |
| 192 | L3_Groups = [] |
| 193 | for other_port in ports: |
| 194 | # add l2 interface group |
| 195 | l2gid, msg = add_one_l2_interface_group( controller, other_port, vlan_id=port_to_out_vlan[other_port], |
| 196 | is_tagged=True, send_barrier=False ) |
| 197 | Groups._put( l2gid ) |
| 198 | # add l3 interface group |
| 199 | l3group_ucast_msg = add_l3_interface_group( controller, other_port, port_to_out_vlan[other_port], port_to_in_vlan[other_port], |
| 200 | port_to_intf_src_mac[other_port] ) |
| 201 | L3_Groups.append(l3group_ucast_msg.group_id) |
| 202 | Groups._put( l3group_ucast_msg.group_id ) |
| 203 | |
| 204 | # add mcast group |
| 205 | mcat_group_msg = add_l3_mcast_group( controller, port_to_in_vlan[port], port_to_in_vlan[port], L3_Groups ) |
| 206 | Groups._put( mcat_group_msg.group_id ) |
| 207 | # add mcast flow |
| 208 | add_mcast4_routing_flow( controller, port_to_in_vlan[port], port_to_src_ip[port], 0, dst_ip, mcat_group_msg.group_id ) |
| 209 | # add termination flow |
| 210 | add_termination_flow( controller, port, 0x0800, switch_mac, port_to_in_vlan[port] ) |
| 211 | # add vlan flow table |
| 212 | add_one_vlan_table_flow( controller, port, port_to_in_vlan[port], flag=VLAN_TABLE_FLAG_ONLY_TAG ) |
| 213 | |
| 214 | return ( |
| 215 | port_to_in_vlan, |
| 216 | port_to_out_vlan, |
| 217 | port_to_src_mac_str, |
| 218 | port_to_dst_mac_str, |
| 219 | port_to_src_ip_str, |
| 220 | port_to_intf_src_mac_str, |
| 221 | Groups |
| 222 | ) |