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