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