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