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