Matteo Scandolo | a229eca | 2017-08-08 13:05:28 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 17 | import logging |
| 18 | |
| 19 | from oftest import config |
| 20 | import oftest.base_tests as base_tests |
| 21 | import ofp |
| 22 | import time |
| 23 | from oftest.testutils import * |
Pier | 1e4e98e | 2016-10-26 14:36:05 -0700 | [diff] [blame] | 24 | from oftest.parse import parse_ipv6 |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 25 | |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 26 | from ncclient import manager |
| 27 | import ncclient |
| 28 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 29 | OFDPA_GROUP_TYPE_SHIFT=28 |
| 30 | OFDPA_VLAN_ID_SHIFT =16 |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 31 | OFDPA_TUNNEL_ID_SHIFT =12 |
| 32 | OFDPA_TUNNEL_SUBTYPE_SHIFT=10 |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 33 | |
| 34 | #VLAN_TABLE_FLAGS |
| 35 | VLAN_TABLE_FLAG_ONLY_UNTAG=1 |
| 36 | VLAN_TABLE_FLAG_ONLY_TAG =2 |
| 37 | VLAN_TABLE_FLAG_ONLY_BOTH =3 |
Pier | e130876 | 2016-09-12 15:29:56 -0700 | [diff] [blame] | 38 | VLAN_TABLE_FLAG_ONLY_STACKED=5 |
| 39 | VLAN_TABLE_FLAG_PRIORITY=6 |
| 40 | VLAN_TABLE_FLAG_ONLY_UNTAG_PRIORITY=7 |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 41 | |
macauley | e8b140e | 2015-08-03 13:35:45 +0800 | [diff] [blame] | 42 | PORT_FLOW_TABLE=0 |
| 43 | VLAN_FLOW_TABLE=10 |
Pier | e130876 | 2016-09-12 15:29:56 -0700 | [diff] [blame] | 44 | VLAN_1_FLOW_TABLE=11 |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 45 | MPLS_L2_PORT_FLOW_TABLE=13 |
| 46 | MPLS_L2_PORT_DSCP_TRUST_FLOW_TABLE=15 |
| 47 | MPLS_L2_PORT_PCP_TRUST_FLOW_TABLE=16 |
macauley | e8b140e | 2015-08-03 13:35:45 +0800 | [diff] [blame] | 48 | TERMINATION_FLOW_TABLE=20 |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 49 | MPLS_TYPE_FLOW_TABLE=29 |
macauley | e8b140e | 2015-08-03 13:35:45 +0800 | [diff] [blame] | 50 | UCAST_ROUTING_FLOW_TABLE=30 |
| 51 | MCAST_ROUTING_FLOW_TABLE=40 |
| 52 | BRIDGE_FLOW_TABLE=50 |
| 53 | ACL_FLOW_TABLE=60 |
| 54 | |
| 55 | def convertIP4toStr(ip_addr): |
| 56 | a=(ip_addr&0xff000000)>>24 |
| 57 | b=(ip_addr&0x00ff0000)>>16 |
| 58 | c=(ip_addr&0x0000ff00)>>8 |
| 59 | d=(ip_addr&0x000000ff) |
| 60 | return str(a)+"."+str(b)+"."+str(c)+"."+str(d) |
| 61 | |
| 62 | def convertMACtoStr(mac): |
| 63 | if not isinstance(mac, list): |
| 64 | assert(0) |
| 65 | |
| 66 | return ':'.join(['%02X' % x for x in mac]) |
| 67 | |
macauley | 7f89d96 | 2015-08-06 18:13:48 +0800 | [diff] [blame] | 68 | def getSwitchCpuMACFromDPID(dpid): |
| 69 | str_datapath_id_f= "{:016x}".format(dpid) |
| 70 | str_datapath_id=':'.join([str_datapath_id_f[i:i+2] for i in range(0, len(str_datapath_id_f), 2)]) |
| 71 | switch_cpu_mac_str=str_datapath_id[6:] |
| 72 | switch_cpu_mac = switch_cpu_mac_str.split(":") |
| 73 | switch_cpu_mac=[int(switch_cpu_mac[i],16) for i in range(0, len(switch_cpu_mac))] |
| 74 | |
| 75 | return switch_cpu_mac_str, switch_cpu_mac |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 76 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 77 | def DumpGroup(stats, verify_group_stats, always_show=True): |
| 78 | if(len(stats) > len(verify_group_stats)): |
| 79 | min_len = len(verify_group_stats) |
| 80 | print "Stats Len is not the same, stats>verify_group_stats" |
| 81 | if(len(stats)< len(verify_group_stats)): |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 82 | min_len = len(stats) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 83 | print "Stats Len is not the same, stats<verify_group_stats" |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 84 | else: |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 85 | min_len = len(stats) |
macauley | e8b140e | 2015-08-03 13:35:45 +0800 | [diff] [blame] | 86 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 87 | print "\r\n" |
| 88 | for i in range(min_len): |
| 89 | gs = stats[i] |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 90 | gv = verify_group_stats[i] |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 91 | print "FromSwtich:(GID=%lx, TYPE=%lx)\r\nVerify :(GID=%lx, TYPE=%lx)"%(gs.group_id, gs.group_type, gv.group_id, gv.group_type) |
| 92 | if(len(gs.buckets) != len(gv.buckets)): |
| 93 | print "buckets len is not the same gs %lx, gv %lx",(len(gs.buckets), len(gv.buckets)) |
| 94 | |
| 95 | for j in range(len(gs.buckets)): |
| 96 | b1=gs.buckets[j] |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 97 | b2=gv.buckets[j] |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 98 | if(len(b1.actions) != len(b2.actions)): |
| 99 | print "action len is not the same" |
| 100 | |
| 101 | for k in range(len(b1.actions)): |
| 102 | a1=b1.actions[k] |
| 103 | a2=b2.actions[k] |
| 104 | if(always_show == True): |
| 105 | print "a1:"+a1.show() |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 106 | print "a2:"+a2.show() |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 107 | |
| 108 | def AssertGroup(self, stats, verify_group_stats): |
| 109 | self.assertTrue(len(stats) ==len(verify_group_stats), "stats len is not the same") |
| 110 | |
| 111 | for i in range(len(stats)): |
| 112 | gs = stats[i] |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 113 | gv = verify_group_stats[i] |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 114 | self.assertTrue(len(gs.buckets) == len(gv.buckets), "buckets len is not the same") |
| 115 | |
| 116 | for j in range(len(gs.buckets)): |
| 117 | b1=gs.buckets[j] |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 118 | b2=gv.buckets[j] |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 119 | self.assertTrue(len(b1.actions) == len(b2.actions), "action len is not the same") |
| 120 | |
| 121 | for k in range(len(b1.actions)): |
| 122 | a1=b1.actions[k] |
| 123 | a2=b2.actions[k] |
| 124 | self.assertEquals(a1, a2, "action is not the same") |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 125 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 126 | def encode_l2_interface_group_id(vlan, id): |
| 127 | return id + (vlan << OFDPA_VLAN_ID_SHIFT) |
| 128 | |
| 129 | def encode_l2_rewrite_group_id(id): |
| 130 | return id + (1 << OFDPA_GROUP_TYPE_SHIFT) |
| 131 | |
| 132 | def encode_l3_unicast_group_id(id): |
| 133 | return id + (2 << OFDPA_GROUP_TYPE_SHIFT) |
| 134 | |
| 135 | def encode_l2_mcast_group_id(vlan, id): |
| 136 | return id + (vlan << OFDPA_VLAN_ID_SHIFT) + (3 << OFDPA_GROUP_TYPE_SHIFT) |
| 137 | |
| 138 | def encode_l2_flood_group_id(vlan, id): |
| 139 | return id + (vlan << OFDPA_VLAN_ID_SHIFT) + (4 << OFDPA_GROUP_TYPE_SHIFT) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 140 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 141 | def encode_l3_interface_group_id(id): |
| 142 | return id + (5 << OFDPA_GROUP_TYPE_SHIFT) |
| 143 | |
| 144 | def encode_l3_mcast_group_id(vlan, id): |
| 145 | return id + (vlan << OFDPA_VLAN_ID_SHIFT)+(6 << OFDPA_GROUP_TYPE_SHIFT) |
| 146 | |
| 147 | def encode_l3_ecmp_group_id(id): |
| 148 | return id + (7 << OFDPA_GROUP_TYPE_SHIFT) |
| 149 | |
Flavio Castro | 91d1a55 | 2016-05-17 16:59:44 -0700 | [diff] [blame] | 150 | def encode_l2_unfiltered_group_id(id): |
| 151 | return id + (11 << OFDPA_GROUP_TYPE_SHIFT) |
| 152 | |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 153 | def encode_l2_overlay_group_id(tunnel_id, subtype, index): |
| 154 | tunnel_id=tunnel_id&0xffff #16 bits |
| 155 | subtype = subtype&3 #2 bits |
| 156 | index = index & 0x3f #10 bits |
| 157 | return index + (tunnel_id << OFDPA_TUNNEL_ID_SHIFT)+ (subtype<<OFDPA_TUNNEL_SUBTYPE_SHIFT)+(8 << OFDPA_GROUP_TYPE_SHIFT) |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 158 | |
Flavio Castro | 91d1a55 | 2016-05-17 16:59:44 -0700 | [diff] [blame] | 159 | def add_l2_unfiltered_group(ctrl, ports, send_barrier=False): |
| 160 | # group table |
| 161 | # set up untag groups for each port |
| 162 | group_id_list=[] |
| 163 | msgs=[] |
| 164 | for of_port in ports: |
| 165 | # do stuff |
| 166 | group_id = encode_l2_unfiltered_group_id(of_port) |
| 167 | group_id_list.append(group_id) |
| 168 | actions = [ofp.action.output(of_port)] |
| 169 | actions.append(ofp.action.set_field(ofp.oxm.exp1ByteValue(exp_type=24, value=1))) |
| 170 | |
| 171 | buckets = [ofp.bucket(actions=actions)] |
| 172 | request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT, |
| 173 | group_id=group_id, |
| 174 | buckets=buckets |
| 175 | ) |
| 176 | ctrl.message_send(request) |
| 177 | msgs.append(request) |
| 178 | |
| 179 | if send_barrier: |
| 180 | do_barrier(ctrl) |
| 181 | |
| 182 | return group_id_list, msgs |
| 183 | |
Pier | f6f2816 | 2016-09-22 16:30:52 -0700 | [diff] [blame] | 184 | def add_one_l2_unfiltered_group(ctrl, of_port, send_barrier=False): |
| 185 | # group table |
| 186 | # set up untag groups for each port |
| 187 | group_id = encode_l2_unfiltered_group_id(of_port) |
| 188 | actions = [ofp.action.output(of_port)] |
| 189 | actions.append(ofp.action.set_field(ofp.oxm.exp1ByteValue(exp_type=24, value=1))) |
| 190 | |
| 191 | buckets = [ofp.bucket(actions=actions)] |
| 192 | request = ofp.message.group_add( |
| 193 | group_type=ofp.OFPGT_INDIRECT, |
| 194 | group_id=group_id, |
| 195 | buckets=buckets |
| 196 | ) |
| 197 | ctrl.message_send(request) |
| 198 | |
| 199 | if send_barrier: |
| 200 | do_barrier(ctrl) |
| 201 | |
| 202 | return group_id, request |
| 203 | |
Flavio Castro | d4c44d1 | 2015-12-08 14:44:18 -0500 | [diff] [blame] | 204 | def add_l2_interface_group(ctrl, ports, vlan_id=1, is_tagged=False, send_barrier=False): |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 205 | # group table |
| 206 | # set up untag groups for each port |
macauley | 41904ed | 2015-07-16 17:38:35 +0800 | [diff] [blame] | 207 | group_id_list=[] |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 208 | msgs=[] |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 209 | for of_port in ports: |
| 210 | # do stuff |
| 211 | group_id = encode_l2_interface_group_id(vlan_id, of_port) |
macauley | 41904ed | 2015-07-16 17:38:35 +0800 | [diff] [blame] | 212 | group_id_list.append(group_id) |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 213 | if is_tagged: |
| 214 | actions = [ |
| 215 | ofp.action.output(of_port), |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 216 | ] |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 217 | else: |
| 218 | actions = [ |
| 219 | ofp.action.pop_vlan(), |
| 220 | ofp.action.output(of_port), |
| 221 | ] |
| 222 | |
| 223 | buckets = [ |
| 224 | ofp.bucket(actions=actions), |
| 225 | ] |
| 226 | |
| 227 | request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT, |
| 228 | group_id=group_id, |
| 229 | buckets=buckets |
| 230 | ) |
| 231 | ctrl.message_send(request) |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 232 | msgs.append(request) |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 233 | |
| 234 | if send_barrier: |
| 235 | do_barrier(ctrl) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 236 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 237 | return group_id_list, msgs |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 238 | |
Flavio Castro | d4c44d1 | 2015-12-08 14:44:18 -0500 | [diff] [blame] | 239 | def add_one_l2_interface_group(ctrl, port, vlan_id=1, is_tagged=False, send_barrier=False): |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 240 | # group table |
| 241 | # set up untag groups for each port |
| 242 | group_id = encode_l2_interface_group_id(vlan_id, port) |
| 243 | |
| 244 | if is_tagged: |
| 245 | actions = [ |
| 246 | ofp.action.output(port), |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 247 | ] |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 248 | else: |
| 249 | actions = [ |
| 250 | ofp.action.pop_vlan(), |
| 251 | ofp.action.output(port), |
| 252 | ] |
| 253 | |
| 254 | buckets = [ |
| 255 | ofp.bucket(actions=actions), |
| 256 | ] |
| 257 | |
| 258 | request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT, |
| 259 | group_id=group_id, |
| 260 | buckets=buckets |
| 261 | ) |
| 262 | ctrl.message_send(request) |
| 263 | |
| 264 | if send_barrier: |
| 265 | do_barrier(ctrl) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 266 | |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 267 | return group_id, request |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 268 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 269 | def add_l2_mcast_group(ctrl, ports, vlanid, mcast_grp_index): |
| 270 | buckets=[] |
| 271 | for of_port in ports: |
| 272 | group_id = encode_l2_interface_group_id(vlanid, of_port) |
| 273 | action=[ofp.action.group(group_id)] |
| 274 | buckets.append(ofp.bucket(actions=action)) |
| 275 | |
| 276 | group_id =encode_l2_mcast_group_id(vlanid, mcast_grp_index) |
| 277 | request = ofp.message.group_add(group_type=ofp.OFPGT_ALL, |
| 278 | group_id=group_id, |
| 279 | buckets=buckets |
| 280 | ) |
| 281 | ctrl.message_send(request) |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 282 | return request |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 283 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 284 | def add_l2_flood_group(ctrl, ports, vlanid, id): |
| 285 | buckets=[] |
| 286 | for of_port in ports: |
| 287 | group_id = encode_l2_interface_group_id(vlanid, of_port) |
| 288 | action=[ofp.action.group(group_id)] |
| 289 | buckets.append(ofp.bucket(actions=action)) |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 290 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 291 | group_id =encode_l2_flood_group_id(vlanid, id) |
| 292 | request = ofp.message.group_add(group_type=ofp.OFPGT_ALL, |
| 293 | group_id=group_id, |
| 294 | buckets=buckets |
| 295 | ) |
| 296 | ctrl.message_send(request) |
| 297 | return request |
| 298 | |
Flavio Castro | a7162bb | 2016-07-25 17:30:30 -0700 | [diff] [blame] | 299 | def mod_l2_flood_group(ctrl, ports, vlanid, id): |
| 300 | buckets=[] |
| 301 | for of_port in ports: |
| 302 | group_id = encode_l2_interface_group_id(vlanid, of_port) |
| 303 | action=[ofp.action.group(group_id)] |
| 304 | buckets.append(ofp.bucket(actions=action)) |
| 305 | |
| 306 | group_id =encode_l2_flood_group_id(vlanid, id) |
| 307 | request = ofp.message.group_modify(group_type=ofp.OFPGT_ALL, |
| 308 | group_id=group_id, |
| 309 | buckets=buckets |
| 310 | ) |
| 311 | ctrl.message_send(request) |
| 312 | return request |
| 313 | |
| 314 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 315 | def add_l2_rewrite_group(ctrl, port, vlanid, id, src_mac, dst_mac): |
| 316 | group_id = encode_l2_interface_group_id(vlanid, port) |
| 317 | |
| 318 | action=[] |
| 319 | if src_mac is not None: |
| 320 | action.append(ofp.action.set_field(ofp.oxm.eth_src(src_mac))) |
| 321 | |
| 322 | if dst_mac is not None: |
| 323 | action.append(ofp.action.set_field(ofp.oxm.eth_dst(dst_mac))) |
| 324 | |
Flavio Castro | 91d1a55 | 2016-05-17 16:59:44 -0700 | [diff] [blame] | 325 | action.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlanid))) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 326 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 327 | action.append(ofp.action.group(group_id)) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 328 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 329 | buckets = [ofp.bucket(actions=action)] |
| 330 | |
| 331 | group_id =encode_l2_rewrite_group_id(id) |
| 332 | request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT, |
| 333 | group_id=group_id, |
| 334 | buckets=buckets |
| 335 | ) |
| 336 | ctrl.message_send(request) |
| 337 | return request |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 338 | |
Pier | 1e4e98e | 2016-10-26 14:36:05 -0700 | [diff] [blame] | 339 | def add_l3_unicast_group(ctrl, port, vlanid, id, src_mac, dst_mac, send_barrier=False): |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 340 | group_id = encode_l2_interface_group_id(vlanid, port) |
| 341 | |
| 342 | action=[] |
| 343 | if src_mac is not None: |
| 344 | action.append(ofp.action.set_field(ofp.oxm.eth_src(src_mac))) |
| 345 | |
| 346 | if dst_mac is not None: |
| 347 | action.append(ofp.action.set_field(ofp.oxm.eth_dst(dst_mac))) |
| 348 | |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame] | 349 | action.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlanid))) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 350 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 351 | action.append(ofp.action.group(group_id)) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 352 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 353 | buckets = [ofp.bucket(actions=action)] |
| 354 | |
| 355 | group_id =encode_l3_unicast_group_id(id) |
| 356 | request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT, |
| 357 | group_id=group_id, |
| 358 | buckets=buckets |
| 359 | ) |
| 360 | ctrl.message_send(request) |
Pier | 1e4e98e | 2016-10-26 14:36:05 -0700 | [diff] [blame] | 361 | |
| 362 | if send_barrier: |
| 363 | do_barrier(ctrl) |
| 364 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 365 | return request |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 366 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 367 | def add_l3_interface_group(ctrl, port, vlanid, id, src_mac): |
| 368 | group_id = encode_l2_interface_group_id(vlanid, port) |
| 369 | |
| 370 | action=[] |
| 371 | action.append(ofp.action.set_field(ofp.oxm.eth_src(src_mac))) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 372 | action.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlanid))) |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 373 | action.append(ofp.action.group(group_id)) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 374 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 375 | buckets = [ofp.bucket(actions=action)] |
| 376 | |
| 377 | group_id =encode_l3_interface_group_id(id) |
| 378 | request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT, |
| 379 | group_id=group_id, |
| 380 | buckets=buckets |
| 381 | ) |
| 382 | ctrl.message_send(request) |
| 383 | return request |
| 384 | |
Pier | 1e4e98e | 2016-10-26 14:36:05 -0700 | [diff] [blame] | 385 | def add_l3_ecmp_group(ctrl, id, l3_ucast_groups, send_barrier=False): |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 386 | buckets=[] |
| 387 | for group in l3_ucast_groups: |
| 388 | buckets.append(ofp.bucket(actions=[ofp.action.group(group)])) |
| 389 | |
| 390 | group_id =encode_l3_ecmp_group_id(id) |
| 391 | request = ofp.message.group_add(group_type=ofp.OFPGT_SELECT, |
| 392 | group_id=group_id, |
| 393 | buckets=buckets |
| 394 | ) |
| 395 | ctrl.message_send(request) |
Pier | 1e4e98e | 2016-10-26 14:36:05 -0700 | [diff] [blame] | 396 | |
| 397 | if send_barrier: |
| 398 | do_barrier(ctrl) |
| 399 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 400 | return request |
Flavio Castro | a7162bb | 2016-07-25 17:30:30 -0700 | [diff] [blame] | 401 | |
| 402 | def mod_l3_ecmp_group(ctrl, id, l3_ucast_groups): |
| 403 | buckets=[] |
| 404 | for group in l3_ucast_groups: |
| 405 | buckets.append(ofp.bucket(actions=[ofp.action.group(group)])) |
| 406 | |
| 407 | group_id =encode_l3_ecmp_group_id(id) |
| 408 | request = ofp.message.group_modify(group_type=ofp.OFPGT_SELECT, |
| 409 | group_id=group_id, |
| 410 | buckets=buckets |
| 411 | ) |
| 412 | ctrl.message_send(request) |
| 413 | return request |
| 414 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 415 | def add_l3_mcast_group(ctrl, vid, mcast_group_id, groups_on_buckets): |
| 416 | buckets=[] |
| 417 | for group in groups_on_buckets: |
| 418 | buckets.append(ofp.bucket(actions=[ofp.action.group(group)])) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 419 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 420 | group_id =encode_l3_mcast_group_id(vid, mcast_group_id) |
| 421 | request = ofp.message.group_add(group_type=ofp.OFPGT_ALL, |
| 422 | group_id=group_id, |
| 423 | buckets=buckets |
| 424 | ) |
| 425 | ctrl.message_send(request) |
| 426 | return request |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 427 | |
| 428 | def add_l2_overlay_flood_over_unicast_tunnel_group(ctrl, tunnel_id, ports, index): |
| 429 | buckets=[] |
| 430 | for port in ports: |
| 431 | buckets.append(ofp.bucket(actions=[ofp.action.output(port)])) |
| 432 | |
| 433 | group_id=encode_l2_overlay_group_id(tunnel_id, 0, index) |
| 434 | request = ofp.message.group_add(group_type=ofp.OFPGT_ALL, |
| 435 | group_id=group_id, |
| 436 | buckets=buckets |
| 437 | ) |
| 438 | ctrl.message_send(request) |
| 439 | return request |
| 440 | |
| 441 | def add_l2_overlay_flood_over_mcast_tunnel_group(ctrl, tunnel_id, ports, index): |
| 442 | buckets=[] |
| 443 | for port in ports: |
| 444 | buckets.append(ofp.bucket(actions=[ofp.action.output(port)])) |
| 445 | |
| 446 | group_id=encode_l2_overlay_group_id(tunnel_id, 1, index) |
| 447 | request = ofp.message.group_add(group_type=ofp.OFPGT_ALL, |
| 448 | group_id=group_id, |
| 449 | buckets=buckets |
| 450 | ) |
| 451 | ctrl.message_send(request) |
| 452 | return request |
| 453 | |
| 454 | def add_l2_overlay_mcast_over_unicast_tunnel_group(ctrl, tunnel_id, ports, index): |
| 455 | buckets=[] |
| 456 | for port in ports: |
| 457 | buckets.append(ofp.bucket(actions=[ofp.action.output(port)])) |
| 458 | |
| 459 | group_id=encode_l2_overlay_group_id(tunnel_id, 2, index) |
| 460 | request = ofp.message.group_add(group_type=ofp.OFPGT_ALL, |
| 461 | group_id=group_id, |
| 462 | buckets=buckets |
| 463 | ) |
| 464 | ctrl.message_send(request) |
| 465 | return request |
| 466 | |
| 467 | def add_l2_overlay_mcast_over_mcast_tunnel_group(ctrl, tunnel_id, ports, index): |
| 468 | buckets=[] |
| 469 | for port in ports: |
| 470 | buckets.append(ofp.bucket(actions=[ofp.action.output(port)])) |
| 471 | |
| 472 | group_id=encode_l2_overlay_group_id(tunnel_id, 3, index) |
| 473 | request = ofp.message.group_add(group_type=ofp.OFPGT_ALL, |
| 474 | group_id=group_id, |
| 475 | buckets=buckets |
| 476 | ) |
| 477 | ctrl.message_send(request) |
| 478 | return request |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 479 | |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 480 | def add_port_table_flow(ctrl, is_overlay=True): |
| 481 | match = ofp.match() |
| 482 | |
| 483 | if is_overlay == True: |
| 484 | match.oxm_list.append(ofp.oxm.in_port(0x10000)) |
macauley | dbff327 | 2015-07-30 14:07:16 +0800 | [diff] [blame] | 485 | NEXT_TABLE=50 |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 486 | else: |
| 487 | match.oxm_list.append(ofp.oxm.in_port(0)) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 488 | NEXT_TABLE=10 |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 489 | |
| 490 | request = ofp.message.flow_add( |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 491 | table_id=0, |
| 492 | cookie=42, |
| 493 | match=match, |
| 494 | instructions=[ |
| 495 | ofp.instruction.goto_table(NEXT_TABLE) |
| 496 | ], |
| 497 | priority=0) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 498 | logging.info("Add port table, match port %lx" % 0x10000) |
| 499 | ctrl.message_send(request) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 500 | |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 501 | def pop_vlan_flow(ctrl, ports, vlan_id=1): |
| 502 | # table 10: vlan |
| 503 | # goto to table 20 |
| 504 | msgs=[] |
| 505 | for of_port in ports: |
| 506 | match = ofp.match() |
| 507 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 508 | match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlan_id)) |
| 509 | request = ofp.message.flow_add( |
| 510 | table_id=10, |
| 511 | cookie=42, |
| 512 | match=match, |
| 513 | instructions=[ |
| 514 | ofp.instruction.apply_actions( |
| 515 | actions=[ |
| 516 | ofp.action.pop_vlan() |
| 517 | ] |
| 518 | ), |
| 519 | ofp.instruction.goto_table(20) |
| 520 | ], |
| 521 | priority=0) |
| 522 | logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port)) |
| 523 | ctrl.message_send(request) |
| 524 | |
| 525 | |
| 526 | return msgs |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 527 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 528 | def add_vlan_table_flow(ctrl, ports, vlan_id=1, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False): |
| 529 | # table 10: vlan |
| 530 | # goto to table 20 |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 531 | msgs=[] |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 532 | for of_port in ports: |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 533 | if (flag == VLAN_TABLE_FLAG_ONLY_TAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH) or (flag == 4): |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 534 | match = ofp.match() |
| 535 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 536 | match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlan_id)) |
| 537 | request = ofp.message.flow_add( |
| 538 | table_id=10, |
| 539 | cookie=42, |
| 540 | match=match, |
| 541 | instructions=[ |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 542 | ofp.instruction.apply_actions( |
| 543 | actions=[ |
| 544 | ofp.action.pop_vlan() |
| 545 | ] |
| 546 | ), |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 547 | ofp.instruction.goto_table(20) |
| 548 | ], |
| 549 | priority=0) |
| 550 | logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port)) |
| 551 | ctrl.message_send(request) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 552 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 553 | if (flag == VLAN_TABLE_FLAG_ONLY_UNTAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH): |
| 554 | match = ofp.match() |
| 555 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 556 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0, 0x1fff)) |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 557 | request = ofp.message.flow_add( |
| 558 | table_id=10, |
| 559 | cookie=42, |
| 560 | match=match, |
| 561 | instructions=[ |
| 562 | ofp.instruction.apply_actions( |
| 563 | actions=[ |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame] | 564 | ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id)) |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 565 | ] |
| 566 | ), |
| 567 | ofp.instruction.goto_table(20) |
| 568 | ], |
| 569 | priority=0) |
| 570 | logging.info("Add vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port)) |
| 571 | ctrl.message_send(request) |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 572 | msgs.append(request) |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 573 | |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 574 | if (flag == 4) : |
| 575 | match = ofp.match() |
| 576 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 577 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000, 0x1fff)) |
| 578 | request = ofp.message.flow_add( |
| 579 | table_id=10, |
| 580 | cookie=42, |
| 581 | match=match, |
| 582 | instructions=[ |
| 583 | ofp.instruction.apply_actions( |
| 584 | actions=[ |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame] | 585 | ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id)) |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 586 | ] |
| 587 | ), |
| 588 | ofp.instruction.goto_table(20) |
| 589 | ], |
| 590 | priority=0) |
| 591 | logging.info("Add vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port)) |
| 592 | ctrl.message_send(request) |
| 593 | msgs.append(request) |
| 594 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 595 | if send_barrier: |
| 596 | do_barrier(ctrl) |
| 597 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 598 | return msgs |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 599 | |
macauley_cheng | 6e6a612 | 2015-11-16 14:19:18 +0800 | [diff] [blame] | 600 | def del_vlan_table_flow(ctrl, ports, vlan_id=1, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False): |
| 601 | # table 10: vlan |
| 602 | # goto to table 20 |
| 603 | msgs=[] |
| 604 | for of_port in ports: |
| 605 | if (flag == VLAN_TABLE_FLAG_ONLY_TAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH): |
| 606 | match = ofp.match() |
| 607 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 608 | match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlan_id)) |
| 609 | request = ofp.message.flow_delete( |
| 610 | table_id=10, |
| 611 | cookie=42, |
| 612 | match=match, |
| 613 | priority=0) |
| 614 | logging.info("Del vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port)) |
| 615 | ctrl.message_send(request) |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 616 | |
macauley_cheng | 6e6a612 | 2015-11-16 14:19:18 +0800 | [diff] [blame] | 617 | if (flag == VLAN_TABLE_FLAG_ONLY_UNTAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH): |
| 618 | match = ofp.match() |
| 619 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 620 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0, 0xfff)) |
| 621 | request = ofp.message.flow_delete( |
| 622 | table_id=10, |
| 623 | cookie=42, |
| 624 | match=match, |
| 625 | priority=0) |
| 626 | logging.info("Del vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port)) |
| 627 | ctrl.message_send(request) |
| 628 | msgs.append(request) |
| 629 | |
| 630 | if send_barrier: |
| 631 | do_barrier(ctrl) |
| 632 | |
| 633 | return msgs |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 634 | |
macauley_cheng | 6b31161 | 2015-09-04 11:32:27 +0800 | [diff] [blame] | 635 | def add_vlan_table_flow_pvid(ctrl, in_port, match_vid=None, pvid=1, send_barrier=False): |
| 636 | """it will tag pack as untagged packet wether it has tagg or not""" |
| 637 | match = ofp.match() |
| 638 | match.oxm_list.append(ofp.oxm.in_port(in_port)) |
| 639 | actions=[] |
| 640 | if match_vid == None: |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 641 | match.oxm_list.append(ofp.oxm.vlan_vid(0)) |
macauley_cheng | 6b31161 | 2015-09-04 11:32:27 +0800 | [diff] [blame] | 642 | actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+pvid))) |
| 643 | goto_table=20 |
| 644 | else: |
| 645 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+match_vid, 0x1fff)) |
| 646 | actions.append(ofp.action.push_vlan(0x8100)) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 647 | actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+pvid))) |
macauley_cheng | 6b31161 | 2015-09-04 11:32:27 +0800 | [diff] [blame] | 648 | goto_table=20 |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 649 | |
macauley_cheng | 6b31161 | 2015-09-04 11:32:27 +0800 | [diff] [blame] | 650 | request = ofp.message.flow_add( |
| 651 | table_id=10, |
| 652 | cookie=42, |
| 653 | match=match, |
| 654 | instructions=[ |
| 655 | ofp.instruction.apply_actions(actions=actions) |
| 656 | ,ofp.instruction.goto_table(goto_table) |
| 657 | ], |
| 658 | priority=0) |
| 659 | logging.info("Add PVID %d on port %d and go to table %ld" %( pvid, in_port, goto_table)) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 660 | ctrl.message_send(request) |
| 661 | |
macauley_cheng | 6b31161 | 2015-09-04 11:32:27 +0800 | [diff] [blame] | 662 | if send_barrier: |
| 663 | do_barrier(ctrl) |
| 664 | |
| 665 | def add_vlan_table_flow_allow_all_vlan(ctrl, in_port, send_barrier=False): |
| 666 | """it st flow allow all vlan tag on this port""" |
| 667 | match = ofp.match() |
| 668 | match.oxm_list.append(ofp.oxm.in_port(in_port)) |
| 669 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000, 0x1000)) |
| 670 | request = ofp.message.flow_add( |
| 671 | table_id=10, |
| 672 | cookie=42, |
| 673 | match=match, |
| 674 | instructions=[ |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 675 | ofp.instruction.goto_table(20) |
macauley_cheng | 6b31161 | 2015-09-04 11:32:27 +0800 | [diff] [blame] | 676 | ], |
| 677 | priority=0) |
| 678 | logging.info("Add allow all vlan on port %d " %(in_port)) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 679 | ctrl.message_send(request) |
macauley_cheng | 6b31161 | 2015-09-04 11:32:27 +0800 | [diff] [blame] | 680 | |
Pier | 7b031af | 2016-08-25 15:00:22 -0700 | [diff] [blame] | 681 | def add_one_vlan_table_flow_translation(ctrl, of_port, vlan_id=1, new_vlan_id=-1, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False): |
| 682 | # Install a flow for VLAN translation |
| 683 | # in VLAN table. |
| 684 | # table 10: vlan |
| 685 | # goto to table 20 |
| 686 | if (flag == VLAN_TABLE_FLAG_ONLY_TAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH) or (flag == 4): |
| 687 | match = ofp.match() |
| 688 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 689 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+vlan_id,0x1fff)) |
| 690 | |
| 691 | actions=[] |
| 692 | if vrf!=0: |
| 693 | actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf))) |
| 694 | if new_vlan_id != -1: |
| 695 | actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+new_vlan_id))) |
| 696 | |
| 697 | request = ofp.message.flow_add( |
| 698 | table_id=10, |
| 699 | cookie=42, |
| 700 | match=match, |
| 701 | instructions=[ |
| 702 | ofp.instruction.apply_actions( |
| 703 | actions=actions |
| 704 | ), |
| 705 | ofp.instruction.goto_table(20) |
| 706 | ], |
| 707 | priority=0) |
| 708 | logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port)) |
| 709 | ctrl.message_send(request) |
| 710 | |
Pier | e130876 | 2016-09-12 15:29:56 -0700 | [diff] [blame] | 711 | def add_one_vlan_table_flow(ctrl, of_port, out_vlan_id=1, vlan_id=1, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False): |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 712 | # table 10: vlan |
| 713 | # goto to table 20 |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 714 | if (flag == VLAN_TABLE_FLAG_ONLY_TAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH) or (flag == 4): |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 715 | match = ofp.match() |
| 716 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 717 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+vlan_id,0x1fff)) |
macauley | 7f89d96 | 2015-08-06 18:13:48 +0800 | [diff] [blame] | 718 | |
| 719 | actions=[] |
Alex Yashchuk | 9f44946 | 2017-12-09 18:27:19 +0200 | [diff] [blame] | 720 | if config["switch_type"] != 'xpliant' and vrf != 0: |
| 721 | actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf))) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 722 | |
Flavio Castro | 6d49852 | 2015-12-15 14:05:04 -0500 | [diff] [blame] | 723 | #actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(value=vlan_id))) |
macauley | 7f89d96 | 2015-08-06 18:13:48 +0800 | [diff] [blame] | 724 | |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 725 | request = ofp.message.flow_add( |
| 726 | table_id=10, |
| 727 | cookie=42, |
| 728 | match=match, |
| 729 | instructions=[ |
macauley | 53d90fe | 2015-08-04 17:34:22 +0800 | [diff] [blame] | 730 | ofp.instruction.apply_actions( |
macauley | 7f89d96 | 2015-08-06 18:13:48 +0800 | [diff] [blame] | 731 | actions=actions |
macauley | 53d90fe | 2015-08-04 17:34:22 +0800 | [diff] [blame] | 732 | ), |
| 733 | ofp.instruction.goto_table(20) |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 734 | ], |
| 735 | priority=0) |
| 736 | logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port)) |
| 737 | ctrl.message_send(request) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 738 | |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 739 | if (flag == VLAN_TABLE_FLAG_ONLY_UNTAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH): |
| 740 | match = ofp.match() |
| 741 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 742 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0, 0x1fff)) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 743 | |
macauley | 7f89d96 | 2015-08-06 18:13:48 +0800 | [diff] [blame] | 744 | actions=[] |
| 745 | if vrf!=0: |
| 746 | actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf))) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 747 | |
Flavio Castro | 91d1a55 | 2016-05-17 16:59:44 -0700 | [diff] [blame] | 748 | actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id))) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 749 | |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 750 | request = ofp.message.flow_add( |
| 751 | table_id=10, |
| 752 | cookie=42, |
| 753 | match=match, |
| 754 | instructions=[ |
| 755 | ofp.instruction.apply_actions( |
macauley | 7f89d96 | 2015-08-06 18:13:48 +0800 | [diff] [blame] | 756 | actions=actions |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 757 | ), |
| 758 | ofp.instruction.goto_table(20) |
| 759 | ], |
| 760 | priority=0) |
| 761 | logging.info("Add vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port)) |
| 762 | ctrl.message_send(request) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 763 | |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 764 | if (flag == 4) : |
| 765 | match = ofp.match() |
| 766 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 767 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000,0x1fff)) |
| 768 | |
| 769 | actions=[] |
| 770 | if vrf!=0: |
| 771 | actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf))) |
| 772 | |
Flavio Castro | 91d1a55 | 2016-05-17 16:59:44 -0700 | [diff] [blame] | 773 | actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id))) |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 774 | |
| 775 | request = ofp.message.flow_add( |
| 776 | table_id=10, |
| 777 | cookie=42, |
| 778 | match=match, |
| 779 | instructions=[ |
| 780 | ofp.instruction.apply_actions( |
| 781 | actions=actions |
| 782 | ), |
| 783 | ofp.instruction.goto_table(20) |
| 784 | ], |
| 785 | priority=0) |
| 786 | logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port)) |
| 787 | ctrl.message_send(request) |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 788 | |
Pier | e130876 | 2016-09-12 15:29:56 -0700 | [diff] [blame] | 789 | if (flag == VLAN_TABLE_FLAG_ONLY_STACKED): |
| 790 | # This flag is meant to managed stacked vlan packtes |
| 791 | # Matches on outer VLAN_ID, set OVID with outer VLAN. |
| 792 | # Finally expose inner VLAN_ID with a pop action and |
| 793 | # goto VLAN_1_FLOW_TABLE |
| 794 | match = ofp.match() |
| 795 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 796 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+vlan_id,0x1fff)) |
| 797 | |
| 798 | actions=[] |
| 799 | actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_OVID, value=0x1000+vlan_id))) |
| 800 | actions.append(ofp.action.pop_vlan()) |
| 801 | |
| 802 | request = ofp.message.flow_add( |
| 803 | table_id=10, |
| 804 | cookie=42, |
| 805 | match=match, |
| 806 | instructions=[ |
| 807 | ofp.instruction.apply_actions( |
| 808 | actions=actions |
| 809 | ), |
| 810 | ofp.instruction.goto_table(VLAN_1_FLOW_TABLE) |
| 811 | ], |
| 812 | priority=0) |
| 813 | logging.info("Add vlan %d tagged packets on port %d and go to table %d" %( vlan_id, of_port, VLAN_1_FLOW_TABLE)) |
| 814 | ctrl.message_send(request) |
| 815 | |
| 816 | if (flag == VLAN_TABLE_FLAG_PRIORITY) : |
| 817 | match = ofp.match() |
| 818 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 819 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000, 0x1fff)) |
| 820 | request = ofp.message.flow_add( |
| 821 | table_id=10, |
| 822 | cookie=42, |
| 823 | match=match, |
| 824 | instructions=[ |
| 825 | ofp.instruction.apply_actions( |
| 826 | actions=[ |
| 827 | ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id)), |
| 828 | ofp.action.push_vlan(0x8100), |
| 829 | ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+out_vlan_id)), |
| 830 | ] |
| 831 | ), |
| 832 | ofp.instruction.goto_table(20) |
| 833 | ], |
| 834 | priority=0) |
| 835 | logging.info("Add vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port)) |
| 836 | ctrl.message_send(request) |
| 837 | |
| 838 | if send_barrier: |
| 839 | do_barrier(ctrl) |
| 840 | |
| 841 | return request |
| 842 | |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 843 | def add_one_vlan_table_flow_pw(ctrl, of_port, tunnel_index, new_vlan_id=1, vlan_id=1, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_TAG, send_barrier=False): |
| 844 | # table 10: vlan |
| 845 | # goto to table 13 |
| 846 | if flag == VLAN_TABLE_FLAG_ONLY_TAG: |
| 847 | match = ofp.match() |
| 848 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 849 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+vlan_id, 0x1fff)) |
| 850 | |
| 851 | actions=[] |
| 852 | if vlan_id == -1: |
| 853 | actions.append(ofp.action.pop_vlan()) |
| 854 | if new_vlan_id > 1: |
| 855 | actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+new_vlan_id))) |
| 856 | actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_TYPE, value=ofp.oxm.VPWS))) |
| 857 | actions.append(ofp.action.set_field(ofp.oxm.tunnel_id(tunnel_index + ofp.oxm.TUNNEL_ID_BASE))) |
| 858 | # 0x0000nnnn is for UNI interfaces |
| 859 | actions.append(ofp.action.set_field(ofp.oxm.exp4ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_L2_PORT, value=0x00000000 + of_port))) |
| 860 | |
| 861 | request = ofp.message.flow_add( |
| 862 | table_id=10, |
| 863 | cookie=42, |
| 864 | match=match, |
| 865 | instructions=[ |
| 866 | ofp.instruction.apply_actions( |
| 867 | actions=actions |
| 868 | ), |
| 869 | ofp.instruction.goto_table(MPLS_L2_PORT_FLOW_TABLE) |
| 870 | ], |
| 871 | priority=0) |
| 872 | logging.info("Add vlan %d tagged packets on port %d and go to table %d" % (vlan_id, of_port, MPLS_L2_PORT_FLOW_TABLE)) |
| 873 | ctrl.message_send(request) |
| 874 | |
| 875 | if flag == VLAN_TABLE_FLAG_ONLY_UNTAG: |
| 876 | match = ofp.match() |
| 877 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 878 | match.oxm_list.append(ofp.oxm.vlan_vid(0)) |
| 879 | |
| 880 | actions=[] |
| 881 | if vlan_id > 1: |
Charles Chan | c85f156 | 2018-01-18 15:44:29 -0800 | [diff] [blame] | 882 | # actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id))) |
| 883 | # actions.append(ofp.action.set_field(ofp.action.push_vlan(0x8100))) |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 884 | actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id))) |
Charles Chan | c85f156 | 2018-01-18 15:44:29 -0800 | [diff] [blame] | 885 | |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 886 | actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_TYPE, value=ofp.oxm.VPWS))) |
| 887 | actions.append(ofp.action.set_field(ofp.oxm.tunnel_id(tunnel_index + ofp.oxm.TUNNEL_ID_BASE))) |
| 888 | # 0x0000nnnn is for UNI interfaces |
| 889 | actions.append(ofp.action.set_field(ofp.oxm.exp4ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_L2_PORT, value=0x00000000 + of_port))) |
| 890 | |
| 891 | request = ofp.message.flow_add( |
| 892 | table_id=10, |
| 893 | cookie=42, |
| 894 | match=match, |
| 895 | instructions=[ |
| 896 | ofp.instruction.apply_actions( |
| 897 | actions=actions |
| 898 | ), |
| 899 | ofp.instruction.goto_table(MPLS_L2_PORT_FLOW_TABLE) |
| 900 | ], |
| 901 | priority=0) |
| 902 | logging.info("Add vlan %d untagged packets on port %d and go to table %d" % (vlan_id, of_port, MPLS_L2_PORT_FLOW_TABLE)) |
| 903 | ctrl.message_send(request) |
| 904 | |
| 905 | if send_barrier: |
| 906 | do_barrier(ctrl) |
| 907 | |
| 908 | return request |
| 909 | |
Pier | e130876 | 2016-09-12 15:29:56 -0700 | [diff] [blame] | 910 | def add_one_vlan_1_table_flow(ctrl, of_port, new_outer_vlan_id=-1, outer_vlan_id=1, inner_vlan_id=1, flag=VLAN_TABLE_FLAG_ONLY_TAG, send_barrier=False): |
| 911 | # table 11: vlan 1 table |
| 912 | # goto to table 20 |
| 913 | if flag == VLAN_TABLE_FLAG_ONLY_TAG: |
| 914 | match = ofp.match() |
| 915 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 916 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+inner_vlan_id,0x1fff)) |
| 917 | match.oxm_list.append(ofp.oxm.exp2ByteValue(ofp.oxm.OFDPA_EXP_TYPE_OVID, 0x1000+outer_vlan_id)) |
| 918 | |
| 919 | actions=[] |
| 920 | actions.append(ofp.action.push_vlan(0x8100)) |
| 921 | if new_outer_vlan_id != -1: |
| 922 | actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+new_outer_vlan_id))) |
| 923 | else: |
| 924 | actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+outer_vlan_id))) |
| 925 | |
| 926 | request = ofp.message.flow_add( |
| 927 | table_id=11, |
| 928 | cookie=42, |
| 929 | match=match, |
| 930 | instructions=[ |
| 931 | ofp.instruction.apply_actions( |
| 932 | actions=actions |
| 933 | ), |
| 934 | ofp.instruction.goto_table(TERMINATION_FLOW_TABLE) |
| 935 | ], |
| 936 | priority=0) |
| 937 | logging.info("Add vlan 1 double tagged %d-%d packets on port %d and go to table %d" %( outer_vlan_id, inner_vlan_id, of_port, TERMINATION_FLOW_TABLE)) |
| 938 | ctrl.message_send(request) |
| 939 | |
| 940 | if flag == VLAN_TABLE_FLAG_ONLY_UNTAG: |
| 941 | match = ofp.match() |
| 942 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 943 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+inner_vlan_id,0x1fff)) |
| 944 | match.oxm_list.append(ofp.oxm.exp2ByteValue(ofp.oxm.OFDPA_EXP_TYPE_OVID, 0x1000+outer_vlan_id)) |
| 945 | |
| 946 | actions=[] |
| 947 | request = ofp.message.flow_add( |
| 948 | table_id=11, |
| 949 | cookie=42, |
| 950 | match=match, |
| 951 | instructions=[ |
| 952 | ofp.instruction.apply_actions( |
| 953 | actions=actions |
| 954 | ), |
| 955 | ofp.instruction.goto_table(TERMINATION_FLOW_TABLE) |
| 956 | ], |
| 957 | priority=0) |
| 958 | logging.info("Add vlan 1 double tagged %d-%d packets on port %d and go to table %d" %( outer_vlan_id, inner_vlan_id, of_port, TERMINATION_FLOW_TABLE)) |
| 959 | ctrl.message_send(request) |
| 960 | |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 961 | if send_barrier: |
| 962 | do_barrier(ctrl) |
| 963 | |
| 964 | return request |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 965 | |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 966 | def add_one_vlan_1_table_flow_pw(ctrl, of_port, tunnel_index, new_outer_vlan_id=-1, outer_vlan_id=1, inner_vlan_id=1, flag=VLAN_TABLE_FLAG_ONLY_TAG, send_barrier=False): |
Charles Chan | c85f156 | 2018-01-18 15:44:29 -0800 | [diff] [blame] | 967 | |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 968 | # table 11: vlan 1 table |
| 969 | # goto to table 13 |
| 970 | match = ofp.match() |
| 971 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 972 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+inner_vlan_id,0x1fff)) |
| 973 | match.oxm_list.append(ofp.oxm.exp2ByteValue(ofp.oxm.OFDPA_EXP_TYPE_OVID, 0x1000+outer_vlan_id)) |
| 974 | |
| 975 | actions=[] |
| 976 | actions.append(ofp.action.push_vlan(0x8100)) |
| 977 | if new_outer_vlan_id != -1: |
Charles Chan | c85f156 | 2018-01-18 15:44:29 -0800 | [diff] [blame] | 978 | actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+new_outer_vlan_id))) |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 979 | else: |
Charles Chan | c85f156 | 2018-01-18 15:44:29 -0800 | [diff] [blame] | 980 | actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+outer_vlan_id))) |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 981 | |
| 982 | actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_TYPE, value=ofp.oxm.VPWS))) |
| 983 | actions.append(ofp.action.set_field(ofp.oxm.tunnel_id(tunnel_index + ofp.oxm.TUNNEL_ID_BASE))) |
| 984 | # 0x0000nnnn is for UNI interfaces |
| 985 | actions.append(ofp.action.set_field(ofp.oxm.exp4ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_L2_PORT, value=0x00000000 + of_port))) |
| 986 | |
| 987 | request = ofp.message.flow_add( |
Charles Chan | c85f156 | 2018-01-18 15:44:29 -0800 | [diff] [blame] | 988 | table_id=11, |
| 989 | cookie=42, |
| 990 | match=match, |
| 991 | instructions=[ |
| 992 | ofp.instruction.apply_actions( |
| 993 | actions=actions |
| 994 | ), |
| 995 | ofp.instruction.goto_table(MPLS_L2_PORT_FLOW_TABLE) |
| 996 | ], |
| 997 | priority=0) |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 998 | logging.info("Add vlan 1 double tagged %d-%d packets on port %d and go to table %d" %( outer_vlan_id, inner_vlan_id, of_port, MPLS_L2_PORT_FLOW_TABLE)) |
| 999 | ctrl.message_send(request) |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 1000 | if send_barrier: |
| 1001 | do_barrier(ctrl) |
| 1002 | |
| 1003 | return request |
| 1004 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 1005 | def add_bridge_flow(ctrl, dst_mac, vlanid, group_id, send_barrier=False): |
| 1006 | match = ofp.match() |
castroflavio | 2189448 | 2015-12-08 15:29:55 -0500 | [diff] [blame] | 1007 | priority=500 |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1008 | if dst_mac!=None: |
castroflavio | 2189448 | 2015-12-08 15:29:55 -0500 | [diff] [blame] | 1009 | priority=1000 |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1010 | match.oxm_list.append(ofp.oxm.eth_dst(dst_mac)) |
| 1011 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 1012 | match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlanid)) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1013 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 1014 | request = ofp.message.flow_add( |
| 1015 | table_id=50, |
| 1016 | cookie=42, |
| 1017 | match=match, |
| 1018 | instructions=[ |
| 1019 | ofp.instruction.write_actions( |
| 1020 | actions=[ |
| 1021 | ofp.action.group(group_id)]), |
| 1022 | ofp.instruction.goto_table(60) |
| 1023 | ], |
| 1024 | buffer_id=ofp.OFP_NO_BUFFER, |
castroflavio | 2189448 | 2015-12-08 15:29:55 -0500 | [diff] [blame] | 1025 | priority=priority) |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 1026 | |
| 1027 | logging.info("Inserting Brdige flow vlan %d, mac %s", vlanid, dst_mac) |
| 1028 | ctrl.message_send(request) |
| 1029 | |
| 1030 | if send_barrier: |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1031 | do_barrier(ctrl) |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 1032 | |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1033 | return request |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1034 | |
| 1035 | def add_overlay_bridge_flow(ctrl, dst_mac, vnid, group_id, is_group=True, send_barrier=False): |
| 1036 | match = ofp.match() |
| 1037 | if dst_mac!=None: |
| 1038 | match.oxm_list.append(ofp.oxm.eth_dst(dst_mac)) |
| 1039 | |
| 1040 | match.oxm_list.append(ofp.oxm.tunnel_id(vnid)) |
| 1041 | if is_group == True: |
| 1042 | actions=[ofp.action.group(group_id)] |
| 1043 | else: |
| 1044 | actions=[ofp.action.output(group_id)] |
| 1045 | |
| 1046 | request = ofp.message.flow_add( |
| 1047 | table_id=50, |
| 1048 | cookie=42, |
| 1049 | match=match, |
| 1050 | instructions=[ |
| 1051 | ofp.instruction.write_actions( |
| 1052 | actions=actions), |
| 1053 | ofp.instruction.goto_table(60) |
| 1054 | ], |
| 1055 | buffer_id=ofp.OFP_NO_BUFFER, |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1056 | priority=1000) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1057 | |
| 1058 | logging.info("Inserting Brdige flow vnid %d, mac %s", vnid, dst_mac) |
| 1059 | ctrl.message_send(request) |
| 1060 | |
| 1061 | if send_barrier: |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1062 | do_barrier(ctrl) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1063 | |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1064 | return request |
| 1065 | |
macauley_cheng | 6b13366 | 2015-11-09 13:52:39 +0800 | [diff] [blame] | 1066 | def add_termination_flow(ctrl, in_port, eth_type, dst_mac, vlanid, goto_table=None, send_barrier=False): |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 1067 | match = ofp.match() |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 1068 | match.oxm_list.append(ofp.oxm.eth_type(eth_type)) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1069 | if dst_mac[0]&0x01 == 0x01: |
| 1070 | match.oxm_list.append(ofp.oxm.eth_dst_masked(dst_mac, [0xff, 0xff, 0xff, 0x80, 0x00, 0x00])) |
| 1071 | goto_table=40 |
| 1072 | else: |
macauley | 53d90fe | 2015-08-04 17:34:22 +0800 | [diff] [blame] | 1073 | if in_port!=0: |
| 1074 | match.oxm_list.append(ofp.oxm.in_port(in_port)) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1075 | match.oxm_list.append(ofp.oxm.eth_dst(dst_mac)) |
| 1076 | match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlanid)) |
macauley_cheng | 6b13366 | 2015-11-09 13:52:39 +0800 | [diff] [blame] | 1077 | if goto_table == None: |
| 1078 | goto_table=30 |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 1079 | |
| 1080 | request = ofp.message.flow_add( |
| 1081 | table_id=20, |
| 1082 | cookie=42, |
| 1083 | match=match, |
| 1084 | instructions=[ |
| 1085 | ofp.instruction.goto_table(goto_table) |
| 1086 | ], |
| 1087 | buffer_id=ofp.OFP_NO_BUFFER, |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1088 | priority=1) |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 1089 | |
| 1090 | logging.info("Inserting termination flow inport %d, eth_type %lx, vlan %d, mac %s", in_port, eth_type, vlanid, dst_mac) |
| 1091 | ctrl.message_send(request) |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 1092 | if send_barrier: |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1093 | do_barrier(ctrl) |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 1094 | |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1095 | return request |
| 1096 | |
Alex Yashchuk | 9f44946 | 2017-12-09 18:27:19 +0200 | [diff] [blame] | 1097 | def add_unicast_routing_flow(ctrl, eth_type, dst_ip, mask, action_group_id, vrf=0, send_ctrl=False, send_barrier=False, priority = 1): |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 1098 | match = ofp.match() |
| 1099 | match.oxm_list.append(ofp.oxm.eth_type(eth_type)) |
Alex Yashchuk | 9f44946 | 2017-12-09 18:27:19 +0200 | [diff] [blame] | 1100 | if config["switch_type"] != 'xpliant' and vrf != 0: |
macauley | 53d90fe | 2015-08-04 17:34:22 +0800 | [diff] [blame] | 1101 | match.oxm_list.append(ofp.oxm.exp2ByteValue(ofp.oxm.OFDPA_EXP_TYPE_VRF, vrf)) |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 1102 | |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame] | 1103 | match.oxm_list.append(ofp.oxm.ipv4_dst_masked(dst_ip, mask)) |
| 1104 | |
| 1105 | instructions = [] |
| 1106 | instructions.append(ofp.instruction.goto_table(60)) |
| 1107 | if send_ctrl: |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1108 | instructions.append(ofp.instruction.write_actions( |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame] | 1109 | actions=[ofp.action.output( port=ofp.OFPP_CONTROLLER, |
| 1110 | max_len=ofp.OFPCML_NO_BUFFER)])) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1111 | else: |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame] | 1112 | instructions.append(ofp.instruction.write_actions( |
| 1113 | actions=[ofp.action.group(action_group_id)])) |
macauley | 53d90fe | 2015-08-04 17:34:22 +0800 | [diff] [blame] | 1114 | |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 1115 | request = ofp.message.flow_add( |
| 1116 | table_id=30, |
| 1117 | cookie=42, |
| 1118 | match=match, |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame] | 1119 | instructions=instructions, |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 1120 | buffer_id=ofp.OFP_NO_BUFFER, |
Alex Yashchuk | 9f44946 | 2017-12-09 18:27:19 +0200 | [diff] [blame] | 1121 | priority=priority) |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 1122 | |
| 1123 | logging.info("Inserting unicast routing flow eth_type %lx, dip %ld",eth_type, dst_ip) |
| 1124 | ctrl.message_send(request) |
| 1125 | |
| 1126 | if send_barrier: |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1127 | do_barrier(ctrl) |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 1128 | |
Flavio Castro | 9debaaa | 2016-07-26 19:37:50 -0700 | [diff] [blame] | 1129 | return request |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 1130 | |
Pier | 1e4e98e | 2016-10-26 14:36:05 -0700 | [diff] [blame] | 1131 | def add_unicast_v6_routing_flow(ctrl, eth_type, dst_ip, mask, action_group_id, vrf=0, send_ctrl=False, send_barrier=False): |
| 1132 | match = ofp.match() |
| 1133 | match.oxm_list.append(ofp.oxm.eth_type(eth_type)) |
| 1134 | if vrf != 0: |
| 1135 | match.oxm_list.append(ofp.oxm.exp2ByteValue(ofp.oxm.OFDPA_EXP_TYPE_VRF, vrf)) |
| 1136 | |
| 1137 | match.oxm_list.append(ofp.oxm.ipv6_dst_masked(parse_ipv6(dst_ip), parse_ipv6(mask))) |
| 1138 | |
| 1139 | instructions = [] |
| 1140 | instructions.append(ofp.instruction.goto_table(60)) |
| 1141 | if send_ctrl: |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1142 | instructions.append(ofp.instruction.write_actions( |
Pier | 1e4e98e | 2016-10-26 14:36:05 -0700 | [diff] [blame] | 1143 | actions=[ofp.action.output( port=ofp.OFPP_CONTROLLER, |
| 1144 | max_len=ofp.OFPCML_NO_BUFFER)])) |
| 1145 | else: |
| 1146 | instructions.append(ofp.instruction.write_actions( |
| 1147 | actions=[ofp.action.group(action_group_id)])) |
| 1148 | |
| 1149 | request = ofp.message.flow_add( |
| 1150 | table_id=30, |
| 1151 | cookie=42, |
| 1152 | match=match, |
| 1153 | instructions=instructions, |
| 1154 | buffer_id=ofp.OFP_NO_BUFFER, |
| 1155 | priority=1) |
| 1156 | |
| 1157 | logging.info("Inserting unicast routing flow eth_type %lx, dip %s",eth_type, dst_ip) |
| 1158 | ctrl.message_send(request) |
| 1159 | |
| 1160 | if send_barrier: |
| 1161 | do_barrier(ctrl) |
| 1162 | |
| 1163 | return request |
| 1164 | |
Andreas Pantelopoulos | 6c76b94 | 2018-01-22 10:03:02 -0800 | [diff] [blame^] | 1165 | def add_mpls_flow(ctrl, action_group_id=0x0, label=100 ,ethertype=0x0800, bos=1, vrf=1, goto_table=27, dec_ttl=False, send_barrier=False): |
Flavio Castro | b702a2f | 2016-04-10 22:01:48 -0400 | [diff] [blame] | 1166 | match = ofp.match() |
| 1167 | match.oxm_list.append(ofp.oxm.eth_type(0x8847)) |
| 1168 | match.oxm_list.append(ofp.oxm.mpls_label(label)) |
| 1169 | match.oxm_list.append(ofp.oxm.mpls_bos(bos)) |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1170 | write_actions = [] |
| 1171 | write_actions.append(ofp.action.group(action_group_id)) |
| 1172 | apply_actions = [] |
| 1173 | apply_actions = [ofp.action.dec_mpls_ttl(), |
Flavio Castro | 8ca5254 | 2016-04-11 11:24:49 -0400 | [diff] [blame] | 1174 | ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf))] |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1175 | if (goto_table != 29): |
| 1176 | apply_actions.append(ofp.action.set_field( |
Flavio Castro | d80fbc3 | 2016-07-25 15:54:26 -0700 | [diff] [blame] | 1177 | ofp.oxm.exp2ByteValue(exp_type=23, value=32))) |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1178 | apply_actions.append(ofp.action.copy_ttl_in()) |
Flavio Castro | 9debaaa | 2016-07-26 19:37:50 -0700 | [diff] [blame] | 1179 | |
Flavio Castro | b702a2f | 2016-04-10 22:01:48 -0400 | [diff] [blame] | 1180 | request = ofp.message.flow_add( |
| 1181 | table_id=24, |
| 1182 | cookie=43, |
| 1183 | match=match, |
| 1184 | instructions=[ |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1185 | ofp.instruction.apply_actions(actions=apply_actions), |
| 1186 | ofp.instruction.write_actions(actions=write_actions), |
Flavio Castro | 8ca5254 | 2016-04-11 11:24:49 -0400 | [diff] [blame] | 1187 | ofp.instruction.goto_table(goto_table) |
Flavio Castro | b702a2f | 2016-04-10 22:01:48 -0400 | [diff] [blame] | 1188 | ], |
| 1189 | buffer_id=ofp.OFP_NO_BUFFER, |
| 1190 | priority=1) |
Flavio Castro | b702a2f | 2016-04-10 22:01:48 -0400 | [diff] [blame] | 1191 | logging.info("Inserting MPLS flow , label %ld", label) |
| 1192 | ctrl.message_send(request) |
| 1193 | |
| 1194 | if send_barrier: |
| 1195 | do_barrier(ctrl) |
| 1196 | |
| 1197 | return request |
| 1198 | |
Alex Yashchuk | 9f44946 | 2017-12-09 18:27:19 +0200 | [diff] [blame] | 1199 | def xpliant_add_mpls_flow(ctrl, action_group_id=0x0, label=100 ,ethertype=0x0800, bos=1, vrf=1, goto_table=27, send_barrier=False): |
| 1200 | match = ofp.match() |
| 1201 | match.oxm_list.append(ofp.oxm.eth_type(0x8847)) |
| 1202 | match.oxm_list.append(ofp.oxm.mpls_label(label)) |
| 1203 | |
| 1204 | apply_actions = [] |
| 1205 | apply_actions.append(ofp.action.group(action_group_id)) |
| 1206 | apply_actions.append(ofp.action.dec_mpls_ttl()) |
| 1207 | if (goto_table != 29): |
| 1208 | apply_actions.append(ofp.action.pop_mpls(ethertype)) |
| 1209 | |
| 1210 | request = ofp.message.flow_add( |
| 1211 | table_id=24, |
| 1212 | cookie=43, |
| 1213 | match=match, |
| 1214 | instructions=[ |
| 1215 | ofp.instruction.apply_actions(actions=apply_actions), |
| 1216 | ], |
| 1217 | buffer_id=ofp.OFP_NO_BUFFER, |
| 1218 | priority=1) |
| 1219 | logging.info("Inserting MPLS flow , label %ld", label) |
| 1220 | ctrl.message_send(request) |
| 1221 | |
| 1222 | if send_barrier: |
| 1223 | do_barrier(ctrl) |
| 1224 | |
| 1225 | return request |
| 1226 | |
Andreas Pantelopoulos | 6c76b94 | 2018-01-22 10:03:02 -0800 | [diff] [blame^] | 1227 | def add_mpls_flow_swap(ctrl, action_group_id, label, ethertype, bos, goto_table=MPLS_TYPE_FLOW_TABLE, of_port=0, send_barrier=False): |
| 1228 | match = ofp.match() |
| 1229 | match.oxm_list.append(ofp.oxm.eth_type(0x8847)) |
| 1230 | match.oxm_list.append(ofp.oxm.mpls_label(label)) |
| 1231 | match.oxm_list.append(ofp.oxm.mpls_bos(1)) |
| 1232 | |
| 1233 | apply_actions = [] |
| 1234 | write_actions = [] |
| 1235 | apply_actions.append(ofp.action.dec_mpls_ttl()) |
| 1236 | write_actions.append(ofp.action.group(action_group_id)) |
| 1237 | |
| 1238 | request = ofp.message.flow_add( |
| 1239 | table_id=24, |
| 1240 | cookie=43, |
| 1241 | match=match, |
| 1242 | instructions=[ |
| 1243 | ofp.instruction.apply_actions(actions=apply_actions), |
| 1244 | ofp.instruction.write_actions(actions=write_actions), |
| 1245 | ofp.instruction.goto_table(goto_table) |
| 1246 | ], |
| 1247 | buffer_id=ofp.OFP_NO_BUFFER, |
| 1248 | priority=1) |
| 1249 | |
| 1250 | logging.info("Inserting MPLS flow , label %ld", label) |
| 1251 | ctrl.message_send(request) |
| 1252 | |
| 1253 | if send_barrier: |
| 1254 | do_barrier(ctrl) |
| 1255 | |
| 1256 | return request |
| 1257 | |
| 1258 | |
Pier | f6f2816 | 2016-09-22 16:30:52 -0700 | [diff] [blame] | 1259 | def add_mpls_flow_pw(ctrl, action_group_id, label, ethertype, bos, tunnel_index, goto_table=MPLS_TYPE_FLOW_TABLE, popMPLS=True, popL2=False, of_port=0, send_barrier=False): |
Pier | b5da4c9 | 2016-09-21 11:23:35 -0700 | [diff] [blame] | 1260 | match = ofp.match() |
| 1261 | match.oxm_list.append(ofp.oxm.eth_type(0x8847)) |
| 1262 | match.oxm_list.append(ofp.oxm.mpls_label(label)) |
| 1263 | match.oxm_list.append(ofp.oxm.mpls_bos(bos)) |
| 1264 | |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1265 | apply_actions = [] |
| 1266 | write_actions = [] |
| 1267 | apply_actions.append(ofp.action.dec_mpls_ttl()) |
Pier | f6f2816 | 2016-09-22 16:30:52 -0700 | [diff] [blame] | 1268 | if popMPLS == True: |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1269 | apply_actions.append(ofp.action.copy_ttl_in()) |
| 1270 | apply_actions.append(ofp.action.pop_mpls(ethertype)) |
Pier | f6f2816 | 2016-09-22 16:30:52 -0700 | [diff] [blame] | 1271 | if bos==1 and popL2 == True: |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1272 | apply_actions.append(ofp.action.ofdpa_pop_l2_header()) |
| 1273 | apply_actions.append(ofp.action.ofdpa_pop_cw()) |
| 1274 | apply_actions.append(ofp.action.set_field(ofp.oxm.tunnel_id(tunnel_index + ofp.oxm.TUNNEL_ID_BASE))) |
Pier | f6f2816 | 2016-09-22 16:30:52 -0700 | [diff] [blame] | 1275 | # 0x0002nnnn is for UNI interfaces |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1276 | apply_actions.append(ofp.action.set_field(ofp.oxm.exp4ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_L2_PORT, value=0x00020000 + of_port))) |
| 1277 | apply_actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_TYPE, value=ofp.oxm.VPWS))) |
| 1278 | write_actions.append(ofp.action.group(action_group_id)) |
Pier | b5da4c9 | 2016-09-21 11:23:35 -0700 | [diff] [blame] | 1279 | |
| 1280 | request = ofp.message.flow_add( |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1281 | table_id=24, |
| 1282 | cookie=43, |
| 1283 | match=match, |
| 1284 | instructions=[ |
| 1285 | ofp.instruction.apply_actions(actions=apply_actions), |
| 1286 | ofp.instruction.write_actions(actions=write_actions), |
| 1287 | ofp.instruction.goto_table(goto_table) |
| 1288 | ], |
| 1289 | buffer_id=ofp.OFP_NO_BUFFER, |
| 1290 | priority=1) |
Pier | b5da4c9 | 2016-09-21 11:23:35 -0700 | [diff] [blame] | 1291 | logging.info("Inserting MPLS flow , label %ld", label) |
| 1292 | ctrl.message_send(request) |
| 1293 | |
| 1294 | if send_barrier: |
| 1295 | do_barrier(ctrl) |
| 1296 | |
| 1297 | return request |
| 1298 | |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1299 | def add_mcast4_routing_flow(ctrl, vlan_id, src_ip, src_ip_mask, dst_ip, action_group_id, send_barrier=False): |
| 1300 | match = ofp.match() |
| 1301 | match.oxm_list.append(ofp.oxm.eth_type(0x0800)) |
Alex Yashchuk | 9f44946 | 2017-12-09 18:27:19 +0200 | [diff] [blame] | 1302 | match.oxm_list.append(ofp.oxm.vlan_vid(0x1000 + vlan_id)) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1303 | if src_ip_mask!=0: |
| 1304 | match.oxm_list.append(ofp.oxm.ipv4_src_masked(src_ip, src_ip_mask)) |
| 1305 | else: |
| 1306 | match.oxm_list.append(ofp.oxm.ipv4_src(src_ip)) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1307 | |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1308 | match.oxm_list.append(ofp.oxm.ipv4_dst(dst_ip)) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1309 | |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1310 | request = ofp.message.flow_add( |
| 1311 | table_id=40, |
| 1312 | cookie=42, |
| 1313 | match=match, |
| 1314 | instructions=[ |
| 1315 | ofp.instruction.write_actions( |
| 1316 | actions=[ofp.action.group(action_group_id)]), |
| 1317 | ofp.instruction.goto_table(60) |
| 1318 | ], |
| 1319 | buffer_id=ofp.OFP_NO_BUFFER, |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1320 | priority=1) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1321 | |
| 1322 | logging.info("Inserting mcast routing flow eth_type %lx, dip %lx, sip %lx, sip_mask %lx",0x0800, dst_ip, src_ip, src_ip_mask) |
| 1323 | ctrl.message_send(request) |
| 1324 | |
| 1325 | if send_barrier: |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1326 | do_barrier(ctrl) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1327 | |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1328 | return request |
macauley_cheng | 6b13366 | 2015-11-09 13:52:39 +0800 | [diff] [blame] | 1329 | |
Pier | 1e4e98e | 2016-10-26 14:36:05 -0700 | [diff] [blame] | 1330 | def add_acl_rule(ctrl, eth_type=None, ip_proto=None, send_barrier=False): |
| 1331 | match = ofp.match() |
| 1332 | if eth_type != None: |
| 1333 | match.oxm_list.append(ofp.oxm.eth_type(eth_type)) |
| 1334 | if ip_proto != None: |
| 1335 | match.oxm_list.append(ofp.oxm.ip_proto(ip_proto)) |
| 1336 | |
| 1337 | request = ofp.message.flow_add( |
| 1338 | table_id=60, |
| 1339 | cookie=42, |
| 1340 | match=match, |
| 1341 | instructions=[ |
| 1342 | ofp.instruction.apply_actions( |
| 1343 | actions=[ofp.action.output(port=ofp.OFPP_CONTROLLER, max_len=ofp.OFPCML_NO_BUFFER)] |
| 1344 | ), |
| 1345 | ], |
| 1346 | buffer_id=ofp.OFP_NO_BUFFER, |
| 1347 | priority=1 |
| 1348 | ) |
| 1349 | |
| 1350 | logging.info("Inserting ACL flow eth_type %lx, ip_proto %ld", eth_type, ip_proto) |
| 1351 | ctrl.message_send(request) |
| 1352 | |
| 1353 | if send_barrier: |
| 1354 | do_barrier(ctrl) |
| 1355 | |
| 1356 | return request |
| 1357 | |
macauley_cheng | 6b13366 | 2015-11-09 13:52:39 +0800 | [diff] [blame] | 1358 | #dpctl tcp:192.168.1.1:6633 flow-mod table=28,cmd=add,prio=281 eth_type=0x800,ip_dst=100.0.0.1,ip_proto=6,tcp_dst=5000 write:set_field=ip_dst:10.0.0.1,set_field=tcp_dst:2000,group=0x71000001 goto:60 |
macauley_cheng | effc20a | 2015-11-09 16:14:56 +0800 | [diff] [blame] | 1359 | def add_dnat_flow(ctrl, eth_type, ip_dst, ip_proto, tcp_dst, set_ip_dst, set_tcp_dst, action_group_id): |
macauley_cheng | 6b13366 | 2015-11-09 13:52:39 +0800 | [diff] [blame] | 1360 | match = ofp.match() |
| 1361 | match.oxm_list.append(ofp.oxm.eth_type(eth_type)) |
| 1362 | match.oxm_list.append(ofp.oxm.ipv4_dst(ip_dst)) |
| 1363 | match.oxm_list.append(ofp.oxm.ip_proto(ip_proto)) |
| 1364 | match.oxm_list.append(ofp.oxm.tcp_dst(tcp_dst)) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1365 | |
macauley_cheng | 6b13366 | 2015-11-09 13:52:39 +0800 | [diff] [blame] | 1366 | request = ofp.message.flow_add( |
| 1367 | table_id=28, |
| 1368 | cookie=42, |
| 1369 | match=match, |
| 1370 | instructions=[ |
| 1371 | ofp.instruction.write_actions( |
| 1372 | actions=[ofp.action.set_field(ofp.oxm.ipv4_dst(set_ip_dst)), |
| 1373 | ofp.action.set_field(ofp.oxm.tcp_dst(set_tcp_dst)), |
| 1374 | ofp.action.group(action_group_id)]), |
| 1375 | ofp.instruction.goto_table(60) |
| 1376 | ], |
| 1377 | buffer_id=ofp.OFP_NO_BUFFER, |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1378 | priority=1) |
macauley_cheng | 6b13366 | 2015-11-09 13:52:39 +0800 | [diff] [blame] | 1379 | logging.info("Inserting DNAT flow eth_type %lx, dip %lx, ip_proto %ld, tcp_dst %ld, SetFeild: Dip %lx, tcp_dst %ld, action_gorup=%lx",eth_type, ip_dst, ip_proto, tcp_dst, set_ip_dst, set_tcp_dst, action_group_id) |
| 1380 | ctrl.message_send(request) |
| 1381 | return request |
macauley_cheng | effc20a | 2015-11-09 16:14:56 +0800 | [diff] [blame] | 1382 | |
| 1383 | #dpctl tcp:192.168.1.1:6633 flow-mod table=29,cmd=add,prio=291 eth_type=0x800,ip_src=10.0.0.1,ip_proto=6,tcp_src=2000 write:set_field=ip_src:100.0.0.1,set_field=tcp_src:5000 goto:30 |
| 1384 | def add_snat_flow(ctrl, eth_type, ip_src, ip_proto, tcp_src, set_ip_src, set_tcp_src): |
| 1385 | match = ofp.match() |
| 1386 | match.oxm_list.append(ofp.oxm.eth_type(eth_type)) |
| 1387 | match.oxm_list.append(ofp.oxm.ipv4_src(ip_src)) |
| 1388 | match.oxm_list.append(ofp.oxm.ip_proto(ip_proto)) |
| 1389 | match.oxm_list.append(ofp.oxm.tcp_src(tcp_src)) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1390 | |
macauley_cheng | effc20a | 2015-11-09 16:14:56 +0800 | [diff] [blame] | 1391 | request = ofp.message.flow_add( |
| 1392 | table_id=29, |
| 1393 | cookie=42, |
| 1394 | match=match, |
| 1395 | instructions=[ |
| 1396 | ofp.instruction.write_actions( |
| 1397 | actions=[ofp.action.set_field(ofp.oxm.ipv4_src(set_ip_src)), |
| 1398 | ofp.action.set_field(ofp.oxm.tcp_src(set_tcp_src))]), |
| 1399 | ofp.instruction.goto_table(30) |
| 1400 | ], |
| 1401 | buffer_id=ofp.OFP_NO_BUFFER, |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1402 | priority=1) |
macauley_cheng | effc20a | 2015-11-09 16:14:56 +0800 | [diff] [blame] | 1403 | logging.info("Inserting DNAT flow eth_type %lx, sip %lx, ip_proto %ld, tcp_src %ld, SetFeild: sip %lx, tcp_src %ld",eth_type, ip_src, ip_proto, tcp_src, set_ip_src, set_tcp_src) |
| 1404 | ctrl.message_send(request) |
| 1405 | return request |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1406 | |
| 1407 | def get_vtap_lport_config_xml(dp_id, lport, phy_port, vlan, vnid, operation='merge'): |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1408 | """ |
| 1409 | Command Example: |
| 1410 | of-agent vtap 10001 ethernet 1/1 vid 1 |
| 1411 | of-agent vtp 10001 vni 10 |
| 1412 | """ |
| 1413 | if vlan != 0: |
| 1414 | config_vtap_xml=""" |
| 1415 | <config> |
| 1416 | <capable-switch xmlns="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"> |
| 1417 | <id>capable-switch-1</id> |
| 1418 | <resources> |
| 1419 | <port xc:operation="OPERATION"> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1420 | <resource-id >LPORT</resource-id> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1421 | <features> |
| 1422 | <current> |
| 1423 | <rate>10Gb</rate> |
| 1424 | <medium>fiber</medium> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1425 | <pause>symmetric</pause> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1426 | </current> |
| 1427 | <advertised> |
| 1428 | <rate>10Gb</rate> |
| 1429 | <rate>100Gb</rate> |
| 1430 | <medium>fiber</medium> |
| 1431 | <pause>symmetric</pause> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1432 | </advertised> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1433 | <supported> |
| 1434 | <rate>10Gb</rate> |
| 1435 | <rate>100Gb</rate> |
| 1436 | <medium>fiber</medium> |
| 1437 | <pause>symmetric</pause> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1438 | </supported> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1439 | <advertised-peer> |
| 1440 | <rate>10Gb</rate> |
| 1441 | <rate>100Gb</rate> |
| 1442 | <medium>fiber</medium> |
| 1443 | <pause>symmetric</pause> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1444 | </advertised-peer> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1445 | </features> |
| 1446 | <ofdpa10:vtap xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION"> |
| 1447 | <ofdpa10:phy-port>PHY_PORT</ofdpa10:phy-port> |
| 1448 | <ofdpa10:vid>VLAN_ID</ofdpa10:vid> |
| 1449 | <ofdpa10:vni>VNID</ofdpa10:vni> |
| 1450 | </ofdpa10:vtap> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1451 | </port> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1452 | </resources> |
| 1453 | <logical-switches> |
| 1454 | <switch> |
| 1455 | <id>DATAPATH_ID</id> |
| 1456 | <datapath-id>DATAPATH_ID</datapath-id> |
| 1457 | <resources> |
| 1458 | <port xc:operation="OPERATION">LPORT</port> |
| 1459 | </resources> |
| 1460 | </switch> |
| 1461 | </logical-switches> |
| 1462 | </capable-switch> |
| 1463 | </config> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1464 | """ |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1465 | else: |
| 1466 | config_vtap_xml=""" |
| 1467 | <config> |
| 1468 | <capable-switch xmlns="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"> |
| 1469 | <id>capable-switch-1</id> |
| 1470 | <resources> |
| 1471 | <port xc:operation="OPERATION"> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1472 | <resource-id >LPORT</resource-id> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1473 | <features> |
| 1474 | <current> |
| 1475 | <rate>10Gb</rate> |
| 1476 | <medium>fiber</medium> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1477 | <pause>symmetric</pause> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1478 | </current> |
| 1479 | <advertised> |
| 1480 | <rate>10Gb</rate> |
| 1481 | <rate>100Gb</rate> |
| 1482 | <medium>fiber</medium> |
| 1483 | <pause>symmetric</pause> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1484 | </advertised> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1485 | <supported> |
| 1486 | <rate>10Gb</rate> |
| 1487 | <rate>100Gb</rate> |
| 1488 | <medium>fiber</medium> |
| 1489 | <pause>symmetric</pause> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1490 | </supported> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1491 | <advertised-peer> |
| 1492 | <rate>10Gb</rate> |
| 1493 | <rate>100Gb</rate> |
| 1494 | <medium>fiber</medium> |
| 1495 | <pause>symmetric</pause> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1496 | </advertised-peer> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1497 | </features> |
| 1498 | <ofdpa10:vtap xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION"> |
| 1499 | <ofdpa10:phy-port>PHY_PORT</ofdpa10:phy-port> |
| 1500 | <ofdpa10:vni>VNID</ofdpa10:vni> |
| 1501 | </ofdpa10:vtap> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1502 | </port> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1503 | </resources> |
| 1504 | <logical-switches> |
| 1505 | <switch> |
| 1506 | <id>DATAPATH_ID</id> |
| 1507 | <datapath-id>DATAPATH_ID</datapath-id> |
| 1508 | <resources> |
| 1509 | <port xc:operation="OPERATION">LPORT</port> |
| 1510 | </resources> |
| 1511 | </switch> |
| 1512 | </logical-switches> |
| 1513 | </capable-switch> |
| 1514 | </config> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1515 | """ |
| 1516 | str_datapath_id_f= "{:016x}".format(dp_id) |
| 1517 | str_datapath_id=':'.join([str_datapath_id_f[i:i+2] for i in range(0, len(str_datapath_id_f), 2)]) |
| 1518 | config_vtap_xml=config_vtap_xml.replace("DATAPATH_ID", str_datapath_id) |
| 1519 | config_vtap_xml=config_vtap_xml.replace("LPORT", str(int(lport))) |
| 1520 | config_vtap_xml=config_vtap_xml.replace("PHY_PORT", str(phy_port)) |
| 1521 | config_vtap_xml=config_vtap_xml.replace("VLAN_ID", str(vlan)) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1522 | config_vtap_xml=config_vtap_xml.replace("VNID", str(vnid)) |
| 1523 | config_vtap_xml=config_vtap_xml.replace("OPERATION", str(operation)) |
| 1524 | return config_vtap_xml |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1525 | |
| 1526 | def get_vtep_lport_config_xml(dp_id, lport, src_ip, dst_ip, next_hop_id, vnid, udp_src_port=6633, ttl=25, operation='merge'): |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1527 | """ |
| 1528 | Command Example: |
| 1529 | of-agent vtep 10002 source user-input-src-ip destination user-input-dst-ip udp-source-port 6633 nexthop 2 ttl 25 |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1530 | of-agent vtp 10001 vni 10 |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1531 | """ |
| 1532 | |
| 1533 | config_vtep_xml=""" |
| 1534 | <config> |
| 1535 | <capable-switch xmlns="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"> |
| 1536 | <id>capable-switch-1</id> |
| 1537 | <resources> |
| 1538 | <port xc:operation="OPERATION"> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1539 | <resource-id>LPORT</resource-id> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1540 | <features> |
| 1541 | <current> |
| 1542 | <rate>10Gb</rate> |
| 1543 | <medium>fiber</medium> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1544 | <pause>symmetric</pause> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1545 | </current> |
| 1546 | <advertised> |
| 1547 | <rate>10Gb</rate> |
| 1548 | <rate>100Gb</rate> |
| 1549 | <medium>fiber</medium> |
| 1550 | <pause>symmetric</pause> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1551 | </advertised> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1552 | <supported> |
| 1553 | <rate>10Gb</rate> |
| 1554 | <rate>100Gb</rate> |
| 1555 | <medium>fiber</medium> |
| 1556 | <pause>symmetric</pause> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1557 | </supported> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1558 | <advertised-peer> |
| 1559 | <rate>10Gb</rate> |
| 1560 | <rate>100Gb</rate> |
| 1561 | <medium>fiber</medium> |
| 1562 | <pause>symmetric</pause> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1563 | </advertised-peer> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1564 | </features> |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1565 | <ofdpa10:vtep xmlns:ofdpa10="urn:bcm:ofdpa10:accton01"> |
| 1566 | <ofdpa10:src-ip>SRC_IP</ofdpa10:src-ip> |
| 1567 | <ofdpa10:dest-ip>DST_IP</ofdpa10:dest-ip> |
| 1568 | <ofdpa10:udp-src-port>UDP_SRC_PORT</ofdpa10:udp-src-port> |
| 1569 | <ofdpa10:vni xc:operation="OPERATION"> |
macauley | 25999cf | 2015-08-07 17:03:24 +0800 | [diff] [blame] | 1570 | <ofdpa10:id>VNID</ofdpa10:id> |
| 1571 | </ofdpa10:vni> |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1572 | <ofdpa10:nexthop-id>NEXT_HOP_ID</ofdpa10:nexthop-id> |
| 1573 | <ofdpa10:ttl>TTL</ofdpa10:ttl> |
| 1574 | </ofdpa10:vtep> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1575 | </port> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1576 | </resources> |
| 1577 | <logical-switches> |
| 1578 | <switch> |
| 1579 | <id>DATAPATH_ID</id> |
| 1580 | <datapath-id>DATAPATH_ID</datapath-id> |
| 1581 | <resources> |
| 1582 | <port xc:operation="OPERATION">LPORT</port> |
| 1583 | </resources> |
| 1584 | </switch> |
| 1585 | </logical-switches> |
| 1586 | </capable-switch> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1587 | </config> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1588 | """ |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1589 | str_datapath_id_f= "{:016x}".format(dp_id) |
| 1590 | str_datapath_id=':'.join([str_datapath_id_f[i:i+2] for i in range(0, len(str_datapath_id_f), 2)]) |
| 1591 | config_vtep_xml=config_vtep_xml.replace("DATAPATH_ID", str_datapath_id) |
macauley | 25999cf | 2015-08-07 17:03:24 +0800 | [diff] [blame] | 1592 | config_vtep_xml=config_vtep_xml.replace("LPORT", str(int(lport))) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1593 | config_vtep_xml=config_vtep_xml.replace("SRC_IP", str(src_ip)) |
| 1594 | config_vtep_xml=config_vtep_xml.replace("DST_IP", str(dst_ip)) |
| 1595 | config_vtep_xml=config_vtep_xml.replace("UDP_SRC_PORT", str(udp_src_port)) |
| 1596 | config_vtep_xml=config_vtep_xml.replace("NEXT_HOP_ID", str(next_hop_id)) |
| 1597 | config_vtep_xml=config_vtep_xml.replace("TTL", str(ttl)) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1598 | config_vtep_xml=config_vtep_xml.replace("VNID", str(vnid)) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1599 | config_vtep_xml=config_vtep_xml.replace("OPERATION", str(operation)) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1600 | |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1601 | return config_vtep_xml |
| 1602 | |
| 1603 | def get_next_hop_config_xml(next_hop_id, dst_mac, phy_port, vlan, operation='merge'): |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1604 | #of-agent nexthop 2 destination user-input-dst-mac ethernet 1/2 vid 2 |
| 1605 | config_nexthop_xml=""" |
| 1606 | <config> |
| 1607 | <of11-config:capable-switch xmlns:of11-config="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"> |
| 1608 | <ofdpa10:next-hop xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION"> |
| 1609 | <ofdpa10:id>NEXT_HOP_ID</ofdpa10:id> |
| 1610 | <ofdpa10:dest-mac>DST_MAC</ofdpa10:dest-mac> |
| 1611 | <ofdpa10:phy-port>PHY_PORT</ofdpa10:phy-port> |
| 1612 | <ofdpa10:vid>VLAN_ID</ofdpa10:vid> |
| 1613 | </ofdpa10:next-hop> |
| 1614 | </of11-config:capable-switch> |
| 1615 | </config> |
| 1616 | """ |
| 1617 | config_nexthop_xml=config_nexthop_xml.replace("VLAN_ID", str(vlan)) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1618 | config_nexthop_xml=config_nexthop_xml.replace("PHY_PORT", str(phy_port)) |
| 1619 | config_nexthop_xml=config_nexthop_xml.replace("NEXT_HOP_ID", str(next_hop_id)) |
| 1620 | config_nexthop_xml=config_nexthop_xml.replace("DST_MAC", str(dst_mac)) |
| 1621 | config_nexthop_xml=config_nexthop_xml.replace("OPERATION", str(operation)) |
| 1622 | return config_nexthop_xml |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1623 | |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1624 | def get_vni_config_xml(vni_id, mcast_ipv4, next_hop_id, operation='merge'): |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1625 | #of-agent vni 10 multicast 224.1.1.1 nexthop 20 |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1626 | if mcast_ipv4!=None: |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1627 | config_vni_xml=""" |
| 1628 | <config> |
| 1629 | <of11-config:capable-switch xmlns:of11-config="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"> |
| 1630 | <ofdpa10:vni xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION"> |
| 1631 | <ofdpa10:id>VNID</ofdpa10:id> |
| 1632 | <ofdpa10:vni-multicast-group>MCAST_IP</ofdpa10:vni-multicast-group> |
| 1633 | <ofdpa10:multicast-group-nexthop-id>NEXT_HOP_ID</ofdpa10:multicast-group-nexthop-id> |
| 1634 | </ofdpa10:vni> |
| 1635 | </of11-config:capable-switch> |
| 1636 | </config> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1637 | """ |
| 1638 | config_vni_xml=config_vni_xml.replace("NEXT_HOP_ID", str(next_hop_id)) |
| 1639 | config_vni_xml=config_vni_xml.replace("MCAST_IP", str(mcast_ipv4)) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1640 | else: |
| 1641 | config_vni_xml=""" |
| 1642 | <config> |
| 1643 | <of11-config:capable-switch xmlns:of11-config="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"> |
| 1644 | <ofdpa10:vni xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION"> |
| 1645 | <ofdpa10:id>VNID</ofdpa10:id> |
| 1646 | </ofdpa10:vni> |
| 1647 | </of11-config:capable-switch> |
| 1648 | </config> |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1649 | """ |
| 1650 | |
| 1651 | config_vni_xml=config_vni_xml.replace("VNID", str(vni_id)) |
| 1652 | config_vni_xml=config_vni_xml.replace("OPERATION", str(operation)) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1653 | return config_vni_xml |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1654 | |
| 1655 | def get_featureReplay(self): |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1656 | req = ofp.message.features_request() |
| 1657 | res, raw = self.controller.transact(req) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1658 | self.assertIsNotNone(res, "Did not receive a response from the DUT.") |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1659 | self.assertEqual(res.type, ofp.OFPT_FEATURES_REPLY, |
| 1660 | ("Unexpected packet type %d received in response to " |
| 1661 | "OFPT_FEATURES_REQUEST") % res.type) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1662 | return res |
| 1663 | |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1664 | def send_edit_config(switch_ip, xml, target='runing'): |
| 1665 | NETCONF_ACCOUNT="netconfuser" |
| 1666 | NETCONF_PASSWD="netconfuser" |
| 1667 | with manager.connect_ssh(host=switch_ip, port=830, username=NETCONF_ACCOUNT, password=NETCONF_PASSWD, hostkey_verify=False ) as m: |
| 1668 | try: |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1669 | m.edit_config(target='running', |
| 1670 | config=xml, |
| 1671 | default_operation='merge', |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1672 | error_option='stop-on-error') |
| 1673 | |
| 1674 | except Exception as e: |
| 1675 | logging.info("Fail to set xml %s", xml) |
| 1676 | return False |
| 1677 | |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1678 | #return m.get_config(source='running').data_xml |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1679 | return True |
| 1680 | |
| 1681 | def send_delete_config(switch_ip, xml, target='runing'): |
| 1682 | NETCONF_ACCOUNT="netconfuser" |
| 1683 | NETCONF_PASSWD="netconfuser" |
| 1684 | with manager.connect_ssh(host=switch_ip, port=830, username=NETCONF_ACCOUNT, password=NETCONF_PASSWD, hostkey_verify=False ) as m: |
| 1685 | try: |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1686 | m.edit_config(target='running', |
| 1687 | config=xml, |
| 1688 | default_operation='delete', |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1689 | error_option='stop-on-error') |
| 1690 | |
| 1691 | except Exception as e: |
| 1692 | logging.info("Fail to set xml %s", xml) |
| 1693 | return False |
| 1694 | |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1695 | #return m.get_config(source='running').data_xml |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1696 | return True |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1697 | |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1698 | def get_edit_config(switch_ip, target='runing'): |
| 1699 | NETCONF_ACCOUNT="netconfuser" |
| 1700 | NETCONF_PASSWD="netconfuser" |
| 1701 | with manager.connect_ssh(host=switch_ip, port=830, username=NETCONF_ACCOUNT, password=NETCONF_PASSWD, hostkey_verify=False ) as m: |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1702 | return m.get_config(source='running').data_xml |
macauley | dbff327 | 2015-07-30 14:07:16 +0800 | [diff] [blame] | 1703 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1704 | |
| 1705 | """ |
| 1706 | MPLS |
| 1707 | """ |
| 1708 | |
| 1709 | OFDPA_MPLS_SUBTYPE_SHIFT=24 |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1710 | OFDPA_MPLS_GROUP_SUBTYPE_L2_VPN_LABEL=1 |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1711 | OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL=2 |
| 1712 | OFDPA_MPLS_GROUP_SUBTYPE_TUNNEL_LABEL1=3 |
| 1713 | OFDPA_MPLS_GROUP_SUBTYPE_TUNNEL_LABEL2=4 |
| 1714 | OFDPA_MPLS_GROUP_SUBTYPE_SWAP_LABEL=5 |
| 1715 | OFDPA_MPLS_GROUP_SUBTYPE_FAST_FAILOVER_GROUP=6 |
| 1716 | OFDPA_MPLS_GROUP_SUBTYPE_ECMP=8 |
| 1717 | OFDPA_MPLS_GROUP_SUBTYPE_L2_TAG=10 |
| 1718 | |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 1719 | |
| 1720 | |
| 1721 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1722 | def encode_mpls_interface_group_id(subtype, index): |
| 1723 | index=index&0x00ffffff |
| 1724 | assert(subtype==0) |
| 1725 | return index + (9 << OFDPA_GROUP_TYPE_SHIFT)+(subtype<<OFDPA_MPLS_SUBTYPE_SHIFT) |
| 1726 | |
| 1727 | def encode_mpls_label_group_id(subtype, index): |
| 1728 | index=index&0x00ffffff |
| 1729 | assert(subtype <=5 or subtype==0) |
| 1730 | #1: l2 vpn label |
| 1731 | #2: l3 vpn label |
| 1732 | #3: mpls tunnel label 1 |
| 1733 | #4: mpls tunnel lable 2 |
| 1734 | #5: mpls swap label |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1735 | return index + (9 << OFDPA_GROUP_TYPE_SHIFT)+(subtype<<OFDPA_MPLS_SUBTYPE_SHIFT) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1736 | |
| 1737 | def encode_mpls_forwarding_group_id(subtype, index): |
| 1738 | index=index&0x00ffffff |
| 1739 | assert(subtype==6 or subtype==8 or subtype==10) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1740 | return index + (10 << OFDPA_GROUP_TYPE_SHIFT)+(subtype<<OFDPA_MPLS_SUBTYPE_SHIFT) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1741 | |
| 1742 | |
Pier | 1e4e98e | 2016-10-26 14:36:05 -0700 | [diff] [blame] | 1743 | def add_mpls_intf_group(ctrl, ref_gid, dst_mac, src_mac, vid, index, subtype=0, send_barrier=False): |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1744 | action=[] |
| 1745 | action.append(ofp.action.set_field(ofp.oxm.eth_src(src_mac))) |
| 1746 | action.append(ofp.action.set_field(ofp.oxm.eth_dst(dst_mac))) |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1747 | action.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vid))) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1748 | action.append(ofp.action.group(ref_gid)) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1749 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1750 | buckets = [ofp.bucket(actions=action)] |
| 1751 | |
| 1752 | mpls_group_id =encode_mpls_interface_group_id(subtype, index) |
| 1753 | request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT, |
| 1754 | group_id=mpls_group_id, |
| 1755 | buckets=buckets |
| 1756 | ) |
Andreas Pantelopoulos | 6c76b94 | 2018-01-22 10:03:02 -0800 | [diff] [blame^] | 1757 | |
| 1758 | logging.debug("Adding MPLS interface group %02x, src_mac %s , dst_mac %s , vid %d", mpls_group_id, src_mac, dst_mac, vid) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1759 | ctrl.message_send(request) |
Pier | 1e4e98e | 2016-10-26 14:36:05 -0700 | [diff] [blame] | 1760 | |
| 1761 | if send_barrier: |
| 1762 | do_barrier(ctrl) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1763 | return mpls_group_id, request |
| 1764 | |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 1765 | def add_mpls_tunnel_label_group( |
| 1766 | ctrl, |
| 1767 | ref_gid, |
| 1768 | subtype, |
| 1769 | index, |
| 1770 | label, |
| 1771 | ): |
| 1772 | |
| 1773 | action=[] |
| 1774 | action.append(ofp.action.push_mpls(0x8847)) |
| 1775 | action.append(ofp.action.set_field(ofp.oxm.mpls_label(label))) |
| 1776 | action.append(ofp.action.group(ref_gid)) |
| 1777 | buckets = [ofp.bucket(actions=action)] |
| 1778 | |
| 1779 | mpls_group_id = encode_mpls_label_group_id(subtype, index) |
| 1780 | request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT, |
| 1781 | group_id=mpls_group_id, |
| 1782 | buckets=buckets |
| 1783 | ) |
| 1784 | ctrl.message_send(request) |
| 1785 | |
| 1786 | return mpls_group_id, request |
| 1787 | |
Pier | b5da4c9 | 2016-09-21 11:23:35 -0700 | [diff] [blame] | 1788 | def add_mpls_swap_label_group( |
| 1789 | ctrl, |
| 1790 | ref_gid, |
| 1791 | subtype, |
| 1792 | index, |
| 1793 | label, |
| 1794 | ): |
| 1795 | |
| 1796 | action=[] |
| 1797 | action.append(ofp.action.set_field(ofp.oxm.mpls_label(label))) |
| 1798 | action.append(ofp.action.group(ref_gid)) |
| 1799 | buckets = [ofp.bucket(actions=action)] |
| 1800 | |
| 1801 | mpls_group_id = encode_mpls_label_group_id(subtype, index) |
| 1802 | request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT, |
| 1803 | group_id=mpls_group_id, |
| 1804 | buckets=buckets |
| 1805 | ) |
Andreas Pantelopoulos | 6c76b94 | 2018-01-22 10:03:02 -0800 | [diff] [blame^] | 1806 | logging.debug("Adding MPLS Swap group %02x, label %d", mpls_group_id, label) |
Pier | b5da4c9 | 2016-09-21 11:23:35 -0700 | [diff] [blame] | 1807 | ctrl.message_send(request) |
| 1808 | |
| 1809 | return mpls_group_id, request |
| 1810 | |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1811 | def add_mpls_label_group(ctrl, subtype, index, ref_gid, |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1812 | lmep_id=-1, |
| 1813 | qos_index=-1, |
| 1814 | push_l2_header=False, |
| 1815 | push_vlan=False, |
| 1816 | push_mpls_header=False, |
| 1817 | push_cw=False, |
| 1818 | set_mpls_label=None, |
| 1819 | set_bos=None, |
| 1820 | set_tc=None, |
| 1821 | set_tc_from_table=False, |
| 1822 | cpy_tc_outward=False, |
| 1823 | set_ttl=None, |
| 1824 | cpy_ttl_outward=False, |
| 1825 | oam_lm_tx_count=False, |
Pier | 1e4e98e | 2016-10-26 14:36:05 -0700 | [diff] [blame] | 1826 | set_pri_from_table=False, |
| 1827 | send_barrier=False |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1828 | ): |
| 1829 | """ |
| 1830 | @ref_gid: only can be mpls intf group or mpls tunnel label 1/2 group |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1831 | """ |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1832 | action=[] |
| 1833 | |
| 1834 | if push_vlan== True: |
| 1835 | action.append(ofp.action.push_vlan(0x8100)) |
| 1836 | if push_mpls_header== True: |
| 1837 | action.append(ofp.action.push_mpls(0x8847)) |
| 1838 | if set_mpls_label != None: |
| 1839 | action.append(ofp.action.set_field(ofp.oxm.mpls_label(set_mpls_label))) |
| 1840 | if set_bos != None: |
| 1841 | action.append(ofp.action.set_field(ofp.oxm.mpls_bos(set_bos))) |
| 1842 | if set_tc != None: |
| 1843 | assert(set_tc_from_table==False) |
| 1844 | action.append(ofp.action.set_field(ofp.oxm.mpls_tc(set_tc))) |
| 1845 | if set_ttl != None: |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1846 | action.append(ofp.action.set_mpls_ttl(set_ttl)) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1847 | if cpy_ttl_outward == True: |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1848 | action.append(ofp.action.copy_ttl_out()) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1849 | """ |
| 1850 | ofdpa experimenter |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1851 | """ |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1852 | if push_l2_header== True: |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1853 | action.append(ofp.action.ofdpa_push_l2_header()) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1854 | if set_tc_from_table== True: |
| 1855 | assert(qos_index>=0) |
| 1856 | assert(set_tc == None) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1857 | action.append(ofp.action.ofdpa_set_tc_from_table(qos_index)) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1858 | if cpy_tc_outward == True: |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1859 | action.append(ofp.action.ofdpa_copy_tc_out()) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1860 | if oam_lm_tx_count == True: |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1861 | assert(qos_index>=0 and lmep_id>=0) |
| 1862 | action.append(ofp.action.ofdpa_oam_lm_tx_count(lmep_id, qos_index)) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1863 | if set_pri_from_table == True: |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1864 | assert(qos_index>=0) |
| 1865 | action.append(ofp.action.ofdpa_set_qos_from_table(qos_index)) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1866 | if push_cw == True: |
| 1867 | action.append(ofp.action.ofdpa_push_cw()) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1868 | |
| 1869 | action.append(ofp.action.group(ref_gid)) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1870 | buckets = [ofp.bucket(actions=action)] |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1871 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1872 | mpls_group_id = encode_mpls_label_group_id(subtype, index) |
| 1873 | request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT, |
| 1874 | group_id=mpls_group_id, |
| 1875 | buckets=buckets |
| 1876 | ) |
| 1877 | ctrl.message_send(request) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1878 | |
Pier | 1e4e98e | 2016-10-26 14:36:05 -0700 | [diff] [blame] | 1879 | if send_barrier: |
| 1880 | do_barrier(ctrl) |
| 1881 | |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1882 | return mpls_group_id, request |
| 1883 | |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 1884 | def add_mpls_l2_port_flow(ctrl, of_port, mpls_l2_port, tunnel_index, ref_gid, qos_index=0): |
| 1885 | """ |
| 1886 | Only action is Group, which must indicate one of: |
| 1887 | MPLS L2 VPN Label or Fast Failover Protection Group. |
| 1888 | ref_gid contains this information |
| 1889 | """ |
| 1890 | tunnel_id = tunnel_index + ofp.oxm.TUNNEL_ID_BASE |
| 1891 | |
| 1892 | match = ofp.match() |
| 1893 | match.oxm_list.append(ofp.oxm.exp4ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_MPLS_L2_PORT, value=0x00000000 + of_port)) |
| 1894 | match.oxm_list.append(ofp.oxm.tunnel_id(tunnel_index + ofp.oxm.TUNNEL_ID_BASE)) |
| 1895 | |
Pier | 23784aa | 2016-09-19 20:08:21 -0700 | [diff] [blame] | 1896 | |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1897 | write_actions = [] |
| 1898 | write_actions.append(ofp.action.group(ref_gid)) |
| 1899 | apply_actions = [] |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 1900 | assert(qos_index>=0) |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1901 | apply_actions.append(ofp.action.set_field(ofp.oxm.exp1ByteValue(exp_type=ofp.oxm.OFDPA_EXP_TYPE_QOS_INDEX, value=qos_index))) |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 1902 | |
| 1903 | request = ofp.message.flow_add( |
| 1904 | table_id=MPLS_L2_PORT_FLOW_TABLE, |
| 1905 | cookie=42, |
| 1906 | match=match, |
| 1907 | instructions=[ |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1908 | ofp.instruction.apply_actions(actions=apply_actions), |
| 1909 | ofp.instruction.write_actions(actions=write_actions), |
| 1910 | ofp.instruction.goto_table(MPLS_L2_PORT_PCP_TRUST_FLOW_TABLE) |
| 1911 | ], |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 1912 | buffer_id=ofp.OFP_NO_BUFFER, |
| 1913 | priority=1) |
| 1914 | logging.info("Inserting flow %d mpls_l2_port, %d tunnel_id, action %x group and go to table %d", mpls_l2_port, tunnel_id, ref_gid, MPLS_L2_PORT_DSCP_TRUST_FLOW_TABLE) |
| 1915 | ctrl.message_send(request) |
| 1916 | return request |
| 1917 | |
| 1918 | return |
| 1919 | |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1920 | def add_mpls_forwarding_group(ctrl, subtype, index, ref_gids, |
| 1921 | watch_port=None, |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1922 | watch_group=ofp.OFPP_ANY, |
| 1923 | push_vlan=None, |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1924 | pop_vlan=None, |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1925 | set_vid=None): |
| 1926 | assert(subtype == OFDPA_MPLS_GROUP_SUBTYPE_FAST_FAILOVER_GROUP |
Pier | 265ad5f | 2017-02-28 17:46:28 +0100 | [diff] [blame] | 1927 | or subtype == OFDPA_MPLS_GROUP_SUBTYPE_ECMP |
| 1928 | or subtype == OFDPA_MPLS_GROUP_SUBTYPE_L2_TAG) |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1929 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1930 | buckets=[] |
| 1931 | if subtype == OFDPA_MPLS_GROUP_SUBTYPE_FAST_FAILOVER_GROUP: |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1932 | group_type = ofp.OFPGT_FF |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1933 | for gid in ref_gids: |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1934 | action=[] |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1935 | action.append(ofp.action.group(gid)) |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1936 | buckets.append(ofp.bucket(watch_port=watch_port, watch_group=watch_group,actions=action)) |
| 1937 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1938 | elif subtype == OFDPA_MPLS_GROUP_SUBTYPE_ECMP: |
| 1939 | group_type = ofp.OFPGT_SELECT |
| 1940 | for gid in ref_gids: |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1941 | action=[] |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1942 | action.append(ofp.action.group(gid)) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1943 | buckets.append(ofp.bucket(actions=action)) |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1944 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1945 | elif subtype == OFDPA_MPLS_GROUP_SUBTYPE_L2_TAG: |
| 1946 | group_type = ofp.OFPGT_INDIRECT |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1947 | action=[] |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1948 | if set_vid!=None: |
Flavio Castro | 91d1a55 | 2016-05-17 16:59:44 -0700 | [diff] [blame] | 1949 | action.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+set_vid))) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1950 | if push_vlan!=None: |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1951 | action.append(ofp.action.push_vlan(push_vlan)) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1952 | if pop_vlan!=None: |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1953 | action.append(ofp.action.pop_vlan()) |
| 1954 | action.append(ofp.action.group(ref_gids[0])) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1955 | buckets.append(ofp.bucket(actions=action)) |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1956 | |
| 1957 | mpls_group_id = encode_mpls_forwarding_group_id(subtype, index) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1958 | request = ofp.message.group_add(group_type=group_type, |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1959 | group_id=mpls_group_id, |
| 1960 | buckets=buckets |
| 1961 | ) |
| 1962 | ctrl.message_send(request) |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1963 | return mpls_group_id, request |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1964 | |
| 1965 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1966 | """ |
Pier | cf76e80 | 2016-09-19 20:16:35 -0700 | [diff] [blame] | 1967 | display |
Pier | bbdf378 | 2016-08-22 17:58:26 -0700 | [diff] [blame] | 1968 | """ |
macauley | dbff327 | 2015-07-30 14:07:16 +0800 | [diff] [blame] | 1969 | def print_current_table_flow_stat(ctrl, table_id=0xff): |
| 1970 | stat_req=ofp.message.flow_stats_request() |
| 1971 | response, pkt = ctrl.transact(stat_req) |
| 1972 | if response == None: |
| 1973 | print "no response" |
| 1974 | return None |
| 1975 | print len(response.entries) |
| 1976 | for obj in response.entries: |
| 1977 | print "match ", obj.match |
| 1978 | print "cookie", obj.cookie |
| 1979 | print "priority", obj.priority |
| 1980 | print "idle_timeout", obj.idle_timeout |
| 1981 | print "hard_timeout", obj.hard_timeout |
| 1982 | #obj.actions |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame] | 1983 | print "packet count: %lx"%obj.packet_count |