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