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