macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 1 | import logging |
| 2 | |
| 3 | from oftest import config |
| 4 | import oftest.base_tests as base_tests |
| 5 | import ofp |
| 6 | import time |
| 7 | from oftest.testutils import * |
| 8 | |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 9 | from ncclient import manager |
| 10 | import ncclient |
| 11 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 12 | OFDPA_GROUP_TYPE_SHIFT=28 |
| 13 | OFDPA_VLAN_ID_SHIFT =16 |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 14 | OFDPA_TUNNEL_ID_SHIFT =12 |
| 15 | OFDPA_TUNNEL_SUBTYPE_SHIFT=10 |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 16 | |
| 17 | #VLAN_TABLE_FLAGS |
| 18 | VLAN_TABLE_FLAG_ONLY_UNTAG=1 |
| 19 | VLAN_TABLE_FLAG_ONLY_TAG =2 |
| 20 | VLAN_TABLE_FLAG_ONLY_BOTH =3 |
| 21 | |
macauley | e8b140e | 2015-08-03 13:35:45 +0800 | [diff] [blame] | 22 | PORT_FLOW_TABLE=0 |
| 23 | VLAN_FLOW_TABLE=10 |
| 24 | TERMINATION_FLOW_TABLE=20 |
| 25 | UCAST_ROUTING_FLOW_TABLE=30 |
| 26 | MCAST_ROUTING_FLOW_TABLE=40 |
| 27 | BRIDGE_FLOW_TABLE=50 |
| 28 | ACL_FLOW_TABLE=60 |
| 29 | |
| 30 | def convertIP4toStr(ip_addr): |
| 31 | a=(ip_addr&0xff000000)>>24 |
| 32 | b=(ip_addr&0x00ff0000)>>16 |
| 33 | c=(ip_addr&0x0000ff00)>>8 |
| 34 | d=(ip_addr&0x000000ff) |
| 35 | return str(a)+"."+str(b)+"."+str(c)+"."+str(d) |
| 36 | |
| 37 | def convertMACtoStr(mac): |
| 38 | if not isinstance(mac, list): |
| 39 | assert(0) |
| 40 | |
| 41 | return ':'.join(['%02X' % x for x in mac]) |
| 42 | |
macauley | 7f89d96 | 2015-08-06 18:13:48 +0800 | [diff] [blame] | 43 | def getSwitchCpuMACFromDPID(dpid): |
| 44 | str_datapath_id_f= "{:016x}".format(dpid) |
| 45 | str_datapath_id=':'.join([str_datapath_id_f[i:i+2] for i in range(0, len(str_datapath_id_f), 2)]) |
| 46 | switch_cpu_mac_str=str_datapath_id[6:] |
| 47 | switch_cpu_mac = switch_cpu_mac_str.split(":") |
| 48 | switch_cpu_mac=[int(switch_cpu_mac[i],16) for i in range(0, len(switch_cpu_mac))] |
| 49 | |
| 50 | return switch_cpu_mac_str, switch_cpu_mac |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 51 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 52 | def DumpGroup(stats, verify_group_stats, always_show=True): |
| 53 | if(len(stats) > len(verify_group_stats)): |
| 54 | min_len = len(verify_group_stats) |
| 55 | print "Stats Len is not the same, stats>verify_group_stats" |
| 56 | if(len(stats)< len(verify_group_stats)): |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 57 | min_len = len(stats) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 58 | print "Stats Len is not the same, stats<verify_group_stats" |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 59 | else: |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 60 | min_len = len(stats) |
macauley | e8b140e | 2015-08-03 13:35:45 +0800 | [diff] [blame] | 61 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 62 | print "\r\n" |
| 63 | for i in range(min_len): |
| 64 | gs = stats[i] |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 65 | gv = verify_group_stats[i] |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 66 | print "FromSwtich:(GID=%lx, TYPE=%lx)\r\nVerify :(GID=%lx, TYPE=%lx)"%(gs.group_id, gs.group_type, gv.group_id, gv.group_type) |
| 67 | if(len(gs.buckets) != len(gv.buckets)): |
| 68 | print "buckets len is not the same gs %lx, gv %lx",(len(gs.buckets), len(gv.buckets)) |
| 69 | |
| 70 | for j in range(len(gs.buckets)): |
| 71 | b1=gs.buckets[j] |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 72 | b2=gv.buckets[j] |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 73 | if(len(b1.actions) != len(b2.actions)): |
| 74 | print "action len is not the same" |
| 75 | |
| 76 | for k in range(len(b1.actions)): |
| 77 | a1=b1.actions[k] |
| 78 | a2=b2.actions[k] |
| 79 | if(always_show == True): |
| 80 | print "a1:"+a1.show() |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 81 | print "a2:"+a2.show() |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 82 | |
| 83 | def AssertGroup(self, stats, verify_group_stats): |
| 84 | self.assertTrue(len(stats) ==len(verify_group_stats), "stats len is not the same") |
| 85 | |
| 86 | for i in range(len(stats)): |
| 87 | gs = stats[i] |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 88 | gv = verify_group_stats[i] |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 89 | self.assertTrue(len(gs.buckets) == len(gv.buckets), "buckets len is not the same") |
| 90 | |
| 91 | for j in range(len(gs.buckets)): |
| 92 | b1=gs.buckets[j] |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 93 | b2=gv.buckets[j] |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 94 | self.assertTrue(len(b1.actions) == len(b2.actions), "action len is not the same") |
| 95 | |
| 96 | for k in range(len(b1.actions)): |
| 97 | a1=b1.actions[k] |
| 98 | a2=b2.actions[k] |
| 99 | self.assertEquals(a1, a2, "action is not the same") |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 100 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 101 | def encode_l2_interface_group_id(vlan, id): |
| 102 | return id + (vlan << OFDPA_VLAN_ID_SHIFT) |
| 103 | |
| 104 | def encode_l2_rewrite_group_id(id): |
| 105 | return id + (1 << OFDPA_GROUP_TYPE_SHIFT) |
| 106 | |
| 107 | def encode_l3_unicast_group_id(id): |
| 108 | return id + (2 << OFDPA_GROUP_TYPE_SHIFT) |
| 109 | |
| 110 | def encode_l2_mcast_group_id(vlan, id): |
| 111 | return id + (vlan << OFDPA_VLAN_ID_SHIFT) + (3 << OFDPA_GROUP_TYPE_SHIFT) |
| 112 | |
| 113 | def encode_l2_flood_group_id(vlan, id): |
| 114 | return id + (vlan << OFDPA_VLAN_ID_SHIFT) + (4 << OFDPA_GROUP_TYPE_SHIFT) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 115 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 116 | def encode_l3_interface_group_id(id): |
| 117 | return id + (5 << OFDPA_GROUP_TYPE_SHIFT) |
| 118 | |
| 119 | def encode_l3_mcast_group_id(vlan, id): |
| 120 | return id + (vlan << OFDPA_VLAN_ID_SHIFT)+(6 << OFDPA_GROUP_TYPE_SHIFT) |
| 121 | |
| 122 | def encode_l3_ecmp_group_id(id): |
| 123 | return id + (7 << OFDPA_GROUP_TYPE_SHIFT) |
| 124 | |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 125 | def encode_l2_overlay_group_id(tunnel_id, subtype, index): |
| 126 | tunnel_id=tunnel_id&0xffff #16 bits |
| 127 | subtype = subtype&3 #2 bits |
| 128 | index = index & 0x3f #10 bits |
| 129 | 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] | 130 | |
Flavio Castro | d4c44d1 | 2015-12-08 14:44:18 -0500 | [diff] [blame] | 131 | 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] | 132 | # group table |
| 133 | # set up untag groups for each port |
macauley | 41904ed | 2015-07-16 17:38:35 +0800 | [diff] [blame] | 134 | group_id_list=[] |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 135 | msgs=[] |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 136 | for of_port in ports: |
| 137 | # do stuff |
| 138 | group_id = encode_l2_interface_group_id(vlan_id, of_port) |
macauley | 41904ed | 2015-07-16 17:38:35 +0800 | [diff] [blame] | 139 | group_id_list.append(group_id) |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 140 | if is_tagged: |
| 141 | actions = [ |
| 142 | ofp.action.output(of_port), |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 143 | ] |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 144 | else: |
| 145 | actions = [ |
| 146 | ofp.action.pop_vlan(), |
| 147 | ofp.action.output(of_port), |
| 148 | ] |
| 149 | |
| 150 | buckets = [ |
| 151 | ofp.bucket(actions=actions), |
| 152 | ] |
| 153 | |
| 154 | request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT, |
| 155 | group_id=group_id, |
| 156 | buckets=buckets |
| 157 | ) |
| 158 | ctrl.message_send(request) |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 159 | msgs.append(request) |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 160 | |
| 161 | if send_barrier: |
| 162 | do_barrier(ctrl) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 163 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 164 | return group_id_list, msgs |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 165 | |
Flavio Castro | d4c44d1 | 2015-12-08 14:44:18 -0500 | [diff] [blame] | 166 | 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] | 167 | # group table |
| 168 | # set up untag groups for each port |
| 169 | group_id = encode_l2_interface_group_id(vlan_id, port) |
| 170 | |
| 171 | if is_tagged: |
| 172 | actions = [ |
| 173 | ofp.action.output(port), |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 174 | ] |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 175 | else: |
| 176 | actions = [ |
| 177 | ofp.action.pop_vlan(), |
| 178 | ofp.action.output(port), |
| 179 | ] |
| 180 | |
| 181 | buckets = [ |
| 182 | ofp.bucket(actions=actions), |
| 183 | ] |
| 184 | |
| 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 | |
| 191 | if send_barrier: |
| 192 | do_barrier(ctrl) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 193 | |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 194 | return group_id, request |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 195 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 196 | def add_l2_mcast_group(ctrl, ports, vlanid, mcast_grp_index): |
| 197 | buckets=[] |
| 198 | for of_port in ports: |
| 199 | group_id = encode_l2_interface_group_id(vlanid, of_port) |
| 200 | action=[ofp.action.group(group_id)] |
| 201 | buckets.append(ofp.bucket(actions=action)) |
| 202 | |
| 203 | group_id =encode_l2_mcast_group_id(vlanid, mcast_grp_index) |
| 204 | request = ofp.message.group_add(group_type=ofp.OFPGT_ALL, |
| 205 | group_id=group_id, |
| 206 | buckets=buckets |
| 207 | ) |
| 208 | ctrl.message_send(request) |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 209 | return request |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 210 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 211 | def add_l2_flood_group(ctrl, ports, vlanid, id): |
| 212 | buckets=[] |
| 213 | for of_port in ports: |
| 214 | group_id = encode_l2_interface_group_id(vlanid, of_port) |
| 215 | action=[ofp.action.group(group_id)] |
| 216 | buckets.append(ofp.bucket(actions=action)) |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 217 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 218 | group_id =encode_l2_flood_group_id(vlanid, id) |
| 219 | request = ofp.message.group_add(group_type=ofp.OFPGT_ALL, |
| 220 | group_id=group_id, |
| 221 | buckets=buckets |
| 222 | ) |
| 223 | ctrl.message_send(request) |
| 224 | return request |
| 225 | |
| 226 | def add_l2_rewrite_group(ctrl, port, vlanid, id, src_mac, dst_mac): |
| 227 | group_id = encode_l2_interface_group_id(vlanid, port) |
| 228 | |
| 229 | action=[] |
| 230 | if src_mac is not None: |
| 231 | action.append(ofp.action.set_field(ofp.oxm.eth_src(src_mac))) |
| 232 | |
| 233 | if dst_mac is not None: |
| 234 | action.append(ofp.action.set_field(ofp.oxm.eth_dst(dst_mac))) |
| 235 | |
macauley_cheng | 93f3fa5 | 2015-09-02 17:57:31 +0800 | [diff] [blame] | 236 | action.append(ofp.action.set_field(ofp.oxm.vlan_vid(vlanid))) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 237 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 238 | action.append(ofp.action.group(group_id)) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 239 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 240 | buckets = [ofp.bucket(actions=action)] |
| 241 | |
| 242 | group_id =encode_l2_rewrite_group_id(id) |
| 243 | request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT, |
| 244 | group_id=group_id, |
| 245 | buckets=buckets |
| 246 | ) |
| 247 | ctrl.message_send(request) |
| 248 | return request |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 249 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 250 | def add_l3_unicast_group(ctrl, port, vlanid, id, src_mac, dst_mac): |
| 251 | group_id = encode_l2_interface_group_id(vlanid, port) |
| 252 | |
| 253 | action=[] |
| 254 | if src_mac is not None: |
| 255 | action.append(ofp.action.set_field(ofp.oxm.eth_src(src_mac))) |
| 256 | |
| 257 | if dst_mac is not None: |
| 258 | action.append(ofp.action.set_field(ofp.oxm.eth_dst(dst_mac))) |
| 259 | |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame] | 260 | action.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlanid))) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 261 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 262 | action.append(ofp.action.group(group_id)) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 263 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 264 | buckets = [ofp.bucket(actions=action)] |
| 265 | |
| 266 | group_id =encode_l3_unicast_group_id(id) |
| 267 | request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT, |
| 268 | group_id=group_id, |
| 269 | buckets=buckets |
| 270 | ) |
| 271 | ctrl.message_send(request) |
| 272 | return request |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 273 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 274 | def add_l3_interface_group(ctrl, port, vlanid, id, src_mac): |
| 275 | group_id = encode_l2_interface_group_id(vlanid, port) |
| 276 | |
| 277 | action=[] |
| 278 | action.append(ofp.action.set_field(ofp.oxm.eth_src(src_mac))) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 279 | action.append(ofp.action.set_field(ofp.oxm.vlan_vid(vlanid))) |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 280 | action.append(ofp.action.group(group_id)) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 281 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 282 | buckets = [ofp.bucket(actions=action)] |
| 283 | |
| 284 | group_id =encode_l3_interface_group_id(id) |
| 285 | request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT, |
| 286 | group_id=group_id, |
| 287 | buckets=buckets |
| 288 | ) |
| 289 | ctrl.message_send(request) |
| 290 | return request |
| 291 | |
| 292 | def add_l3_ecmp_group(ctrl, id, l3_ucast_groups): |
| 293 | buckets=[] |
| 294 | for group in l3_ucast_groups: |
| 295 | buckets.append(ofp.bucket(actions=[ofp.action.group(group)])) |
| 296 | |
| 297 | group_id =encode_l3_ecmp_group_id(id) |
| 298 | request = ofp.message.group_add(group_type=ofp.OFPGT_SELECT, |
| 299 | group_id=group_id, |
| 300 | buckets=buckets |
| 301 | ) |
| 302 | ctrl.message_send(request) |
| 303 | return request |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 304 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 305 | def add_l3_mcast_group(ctrl, vid, mcast_group_id, groups_on_buckets): |
| 306 | buckets=[] |
| 307 | for group in groups_on_buckets: |
| 308 | buckets.append(ofp.bucket(actions=[ofp.action.group(group)])) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 309 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 310 | group_id =encode_l3_mcast_group_id(vid, mcast_group_id) |
| 311 | request = ofp.message.group_add(group_type=ofp.OFPGT_ALL, |
| 312 | group_id=group_id, |
| 313 | buckets=buckets |
| 314 | ) |
| 315 | ctrl.message_send(request) |
| 316 | return request |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 317 | |
| 318 | def add_l2_overlay_flood_over_unicast_tunnel_group(ctrl, tunnel_id, ports, index): |
| 319 | buckets=[] |
| 320 | for port in ports: |
| 321 | buckets.append(ofp.bucket(actions=[ofp.action.output(port)])) |
| 322 | |
| 323 | group_id=encode_l2_overlay_group_id(tunnel_id, 0, index) |
| 324 | request = ofp.message.group_add(group_type=ofp.OFPGT_ALL, |
| 325 | group_id=group_id, |
| 326 | buckets=buckets |
| 327 | ) |
| 328 | ctrl.message_send(request) |
| 329 | return request |
| 330 | |
| 331 | def add_l2_overlay_flood_over_mcast_tunnel_group(ctrl, tunnel_id, ports, index): |
| 332 | buckets=[] |
| 333 | for port in ports: |
| 334 | buckets.append(ofp.bucket(actions=[ofp.action.output(port)])) |
| 335 | |
| 336 | group_id=encode_l2_overlay_group_id(tunnel_id, 1, index) |
| 337 | request = ofp.message.group_add(group_type=ofp.OFPGT_ALL, |
| 338 | group_id=group_id, |
| 339 | buckets=buckets |
| 340 | ) |
| 341 | ctrl.message_send(request) |
| 342 | return request |
| 343 | |
| 344 | def add_l2_overlay_mcast_over_unicast_tunnel_group(ctrl, tunnel_id, ports, index): |
| 345 | buckets=[] |
| 346 | for port in ports: |
| 347 | buckets.append(ofp.bucket(actions=[ofp.action.output(port)])) |
| 348 | |
| 349 | group_id=encode_l2_overlay_group_id(tunnel_id, 2, index) |
| 350 | request = ofp.message.group_add(group_type=ofp.OFPGT_ALL, |
| 351 | group_id=group_id, |
| 352 | buckets=buckets |
| 353 | ) |
| 354 | ctrl.message_send(request) |
| 355 | return request |
| 356 | |
| 357 | def add_l2_overlay_mcast_over_mcast_tunnel_group(ctrl, tunnel_id, ports, index): |
| 358 | buckets=[] |
| 359 | for port in ports: |
| 360 | buckets.append(ofp.bucket(actions=[ofp.action.output(port)])) |
| 361 | |
| 362 | group_id=encode_l2_overlay_group_id(tunnel_id, 3, index) |
| 363 | request = ofp.message.group_add(group_type=ofp.OFPGT_ALL, |
| 364 | group_id=group_id, |
| 365 | buckets=buckets |
| 366 | ) |
| 367 | ctrl.message_send(request) |
| 368 | return request |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 369 | |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 370 | def add_port_table_flow(ctrl, is_overlay=True): |
| 371 | match = ofp.match() |
| 372 | |
| 373 | if is_overlay == True: |
| 374 | match.oxm_list.append(ofp.oxm.in_port(0x10000)) |
macauley | dbff327 | 2015-07-30 14:07:16 +0800 | [diff] [blame] | 375 | NEXT_TABLE=50 |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 376 | else: |
| 377 | match.oxm_list.append(ofp.oxm.in_port(0)) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 378 | NEXT_TABLE=10 |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 379 | |
| 380 | request = ofp.message.flow_add( |
| 381 | table_id=0, |
| 382 | cookie=42, |
| 383 | match=match, |
| 384 | instructions=[ |
macauley | dbff327 | 2015-07-30 14:07:16 +0800 | [diff] [blame] | 385 | ofp.instruction.goto_table(NEXT_TABLE) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 386 | ], |
| 387 | priority=0) |
| 388 | logging.info("Add port table, match port %lx" % 0x10000) |
| 389 | ctrl.message_send(request) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 390 | |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 391 | |
| 392 | def pop_vlan_flow(ctrl, ports, vlan_id=1): |
| 393 | # table 10: vlan |
| 394 | # goto to table 20 |
| 395 | msgs=[] |
| 396 | for of_port in ports: |
| 397 | match = ofp.match() |
| 398 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 399 | match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlan_id)) |
| 400 | request = ofp.message.flow_add( |
| 401 | table_id=10, |
| 402 | cookie=42, |
| 403 | match=match, |
| 404 | instructions=[ |
| 405 | ofp.instruction.apply_actions( |
| 406 | actions=[ |
| 407 | ofp.action.pop_vlan() |
| 408 | ] |
| 409 | ), |
| 410 | ofp.instruction.goto_table(20) |
| 411 | ], |
| 412 | priority=0) |
| 413 | logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port)) |
| 414 | ctrl.message_send(request) |
| 415 | |
| 416 | |
| 417 | return msgs |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 418 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 419 | def add_vlan_table_flow(ctrl, ports, vlan_id=1, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False): |
| 420 | # table 10: vlan |
| 421 | # goto to table 20 |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 422 | msgs=[] |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 423 | for of_port in ports: |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 424 | 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] | 425 | match = ofp.match() |
| 426 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 427 | match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlan_id)) |
| 428 | request = ofp.message.flow_add( |
| 429 | table_id=10, |
| 430 | cookie=42, |
| 431 | match=match, |
| 432 | instructions=[ |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 433 | ofp.instruction.apply_actions( |
| 434 | actions=[ |
| 435 | ofp.action.pop_vlan() |
| 436 | ] |
| 437 | ), |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 438 | ofp.instruction.goto_table(20) |
| 439 | ], |
| 440 | priority=0) |
| 441 | logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port)) |
| 442 | ctrl.message_send(request) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 443 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 444 | if (flag == VLAN_TABLE_FLAG_ONLY_UNTAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH): |
| 445 | match = ofp.match() |
| 446 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 447 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0, 0x1fff)) |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 448 | request = ofp.message.flow_add( |
| 449 | table_id=10, |
| 450 | cookie=42, |
| 451 | match=match, |
| 452 | instructions=[ |
| 453 | ofp.instruction.apply_actions( |
| 454 | actions=[ |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame] | 455 | ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id)) |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 456 | ] |
| 457 | ), |
| 458 | ofp.instruction.goto_table(20) |
| 459 | ], |
| 460 | priority=0) |
| 461 | logging.info("Add vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port)) |
| 462 | ctrl.message_send(request) |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 463 | msgs.append(request) |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 464 | |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 465 | if (flag == 4) : |
| 466 | match = ofp.match() |
| 467 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 468 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000, 0x1fff)) |
| 469 | request = ofp.message.flow_add( |
| 470 | table_id=10, |
| 471 | cookie=42, |
| 472 | match=match, |
| 473 | instructions=[ |
| 474 | ofp.instruction.apply_actions( |
| 475 | actions=[ |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame] | 476 | ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id)) |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 477 | ] |
| 478 | ), |
| 479 | ofp.instruction.goto_table(20) |
| 480 | ], |
| 481 | priority=0) |
| 482 | logging.info("Add vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port)) |
| 483 | ctrl.message_send(request) |
| 484 | msgs.append(request) |
| 485 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 486 | if send_barrier: |
| 487 | do_barrier(ctrl) |
| 488 | |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 489 | return msgs |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 490 | |
macauley_cheng | 6e6a612 | 2015-11-16 14:19:18 +0800 | [diff] [blame] | 491 | def del_vlan_table_flow(ctrl, ports, vlan_id=1, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False): |
| 492 | # table 10: vlan |
| 493 | # goto to table 20 |
| 494 | msgs=[] |
| 495 | for of_port in ports: |
| 496 | if (flag == VLAN_TABLE_FLAG_ONLY_TAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH): |
| 497 | match = ofp.match() |
| 498 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 499 | match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlan_id)) |
| 500 | request = ofp.message.flow_delete( |
| 501 | table_id=10, |
| 502 | cookie=42, |
| 503 | match=match, |
| 504 | priority=0) |
| 505 | logging.info("Del vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port)) |
| 506 | ctrl.message_send(request) |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 507 | |
macauley_cheng | 6e6a612 | 2015-11-16 14:19:18 +0800 | [diff] [blame] | 508 | if (flag == VLAN_TABLE_FLAG_ONLY_UNTAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH): |
| 509 | match = ofp.match() |
| 510 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 511 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0, 0xfff)) |
| 512 | request = ofp.message.flow_delete( |
| 513 | table_id=10, |
| 514 | cookie=42, |
| 515 | match=match, |
| 516 | priority=0) |
| 517 | logging.info("Del vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port)) |
| 518 | ctrl.message_send(request) |
| 519 | msgs.append(request) |
| 520 | |
| 521 | if send_barrier: |
| 522 | do_barrier(ctrl) |
| 523 | |
| 524 | return msgs |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 525 | |
macauley_cheng | 6b31161 | 2015-09-04 11:32:27 +0800 | [diff] [blame] | 526 | def add_vlan_table_flow_pvid(ctrl, in_port, match_vid=None, pvid=1, send_barrier=False): |
| 527 | """it will tag pack as untagged packet wether it has tagg or not""" |
| 528 | match = ofp.match() |
| 529 | match.oxm_list.append(ofp.oxm.in_port(in_port)) |
| 530 | actions=[] |
| 531 | if match_vid == None: |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 532 | match.oxm_list.append(ofp.oxm.vlan_vid(0)) |
macauley_cheng | 6b31161 | 2015-09-04 11:32:27 +0800 | [diff] [blame] | 533 | actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+pvid))) |
| 534 | goto_table=20 |
| 535 | else: |
| 536 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+match_vid, 0x1fff)) |
| 537 | actions.append(ofp.action.push_vlan(0x8100)) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 538 | actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+pvid))) |
macauley_cheng | 6b31161 | 2015-09-04 11:32:27 +0800 | [diff] [blame] | 539 | goto_table=20 |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 540 | |
macauley_cheng | 6b31161 | 2015-09-04 11:32:27 +0800 | [diff] [blame] | 541 | request = ofp.message.flow_add( |
| 542 | table_id=10, |
| 543 | cookie=42, |
| 544 | match=match, |
| 545 | instructions=[ |
| 546 | ofp.instruction.apply_actions(actions=actions) |
| 547 | ,ofp.instruction.goto_table(goto_table) |
| 548 | ], |
| 549 | priority=0) |
| 550 | logging.info("Add PVID %d on port %d and go to table %ld" %( pvid, in_port, goto_table)) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 551 | ctrl.message_send(request) |
| 552 | |
macauley_cheng | 6b31161 | 2015-09-04 11:32:27 +0800 | [diff] [blame] | 553 | if send_barrier: |
| 554 | do_barrier(ctrl) |
| 555 | |
| 556 | def add_vlan_table_flow_allow_all_vlan(ctrl, in_port, send_barrier=False): |
| 557 | """it st flow allow all vlan tag on this port""" |
| 558 | match = ofp.match() |
| 559 | match.oxm_list.append(ofp.oxm.in_port(in_port)) |
| 560 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000, 0x1000)) |
| 561 | request = ofp.message.flow_add( |
| 562 | table_id=10, |
| 563 | cookie=42, |
| 564 | match=match, |
| 565 | instructions=[ |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 566 | ofp.instruction.goto_table(20) |
macauley_cheng | 6b31161 | 2015-09-04 11:32:27 +0800 | [diff] [blame] | 567 | ], |
| 568 | priority=0) |
| 569 | logging.info("Add allow all vlan on port %d " %(in_port)) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 570 | ctrl.message_send(request) |
macauley_cheng | 6b31161 | 2015-09-04 11:32:27 +0800 | [diff] [blame] | 571 | |
Pier | be3db05 | 2016-08-24 17:35:43 -0700 | [diff] [blame] | 572 | 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): |
Pier | 7330291 | 2016-09-06 15:55:06 -0700 | [diff] [blame^] | 573 | # Insert a VLAN translation flow |
| 574 | # in VLAN flows table |
| 575 | # table 10: vlan |
Pier | be3db05 | 2016-08-24 17:35:43 -0700 | [diff] [blame] | 576 | # goto to table 20 |
| 577 | if (flag == VLAN_TABLE_FLAG_ONLY_TAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH) or (flag == 4): |
| 578 | match = ofp.match() |
| 579 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 580 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+vlan_id,0x1fff)) |
| 581 | |
| 582 | actions=[] |
| 583 | if vrf!=0: |
| 584 | actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf))) |
| 585 | if new_vlan_id != -1: |
| 586 | actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(new_vlan_id))) |
| 587 | |
| 588 | request = ofp.message.flow_add( |
| 589 | table_id=10, |
| 590 | cookie=42, |
| 591 | match=match, |
| 592 | instructions=[ |
| 593 | ofp.instruction.apply_actions( |
| 594 | actions=actions |
| 595 | ), |
| 596 | ofp.instruction.goto_table(20) |
| 597 | ], |
| 598 | priority=0) |
| 599 | logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port)) |
| 600 | ctrl.message_send(request) |
| 601 | |
macauley | 53d90fe | 2015-08-04 17:34:22 +0800 | [diff] [blame] | 602 | def add_one_vlan_table_flow(ctrl, of_port, vlan_id=1, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False): |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 603 | # table 10: vlan |
| 604 | # goto to table 20 |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 605 | 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] | 606 | match = ofp.match() |
| 607 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 608 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+vlan_id,0x1fff)) |
macauley | 7f89d96 | 2015-08-06 18:13:48 +0800 | [diff] [blame] | 609 | |
| 610 | actions=[] |
| 611 | if vrf!=0: |
| 612 | actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf))) |
Pier | 7330291 | 2016-09-06 15:55:06 -0700 | [diff] [blame^] | 613 | |
Flavio Castro | 6d49852 | 2015-12-15 14:05:04 -0500 | [diff] [blame] | 614 | #actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(value=vlan_id))) |
macauley | 7f89d96 | 2015-08-06 18:13:48 +0800 | [diff] [blame] | 615 | |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 616 | request = ofp.message.flow_add( |
| 617 | table_id=10, |
| 618 | cookie=42, |
| 619 | match=match, |
| 620 | instructions=[ |
macauley | 53d90fe | 2015-08-04 17:34:22 +0800 | [diff] [blame] | 621 | ofp.instruction.apply_actions( |
macauley | 7f89d96 | 2015-08-06 18:13:48 +0800 | [diff] [blame] | 622 | actions=actions |
macauley | 53d90fe | 2015-08-04 17:34:22 +0800 | [diff] [blame] | 623 | ), |
| 624 | ofp.instruction.goto_table(20) |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 625 | ], |
| 626 | priority=0) |
| 627 | logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port)) |
| 628 | ctrl.message_send(request) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 629 | |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 630 | if (flag == VLAN_TABLE_FLAG_ONLY_UNTAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH): |
| 631 | match = ofp.match() |
| 632 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
Flavio Castro | 1229631 | 2015-12-15 17:48:26 -0500 | [diff] [blame] | 633 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0, 0x1fff)) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 634 | |
macauley | 7f89d96 | 2015-08-06 18:13:48 +0800 | [diff] [blame] | 635 | actions=[] |
| 636 | if vrf!=0: |
| 637 | actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf))) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 638 | |
Flavio Castro | 89933f2 | 2016-02-03 15:53:16 -0500 | [diff] [blame] | 639 | actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(vlan_id))) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 640 | |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 641 | request = ofp.message.flow_add( |
| 642 | table_id=10, |
| 643 | cookie=42, |
| 644 | match=match, |
| 645 | instructions=[ |
| 646 | ofp.instruction.apply_actions( |
macauley | 7f89d96 | 2015-08-06 18:13:48 +0800 | [diff] [blame] | 647 | actions=actions |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 648 | ), |
| 649 | ofp.instruction.goto_table(20) |
| 650 | ], |
| 651 | priority=0) |
| 652 | logging.info("Add vlan %d untagged packets on port %d and go to table 20" % (vlan_id, of_port)) |
| 653 | ctrl.message_send(request) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 654 | |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 655 | if (flag == 4) : |
| 656 | match = ofp.match() |
| 657 | match.oxm_list.append(ofp.oxm.in_port(of_port)) |
| 658 | match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000,0x1fff)) |
| 659 | |
| 660 | actions=[] |
| 661 | if vrf!=0: |
| 662 | actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf))) |
| 663 | |
Flavio Castro | 89933f2 | 2016-02-03 15:53:16 -0500 | [diff] [blame] | 664 | actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(value=vlan_id))) |
Flavio Castro | 932014b | 2016-01-05 18:29:15 -0500 | [diff] [blame] | 665 | |
| 666 | request = ofp.message.flow_add( |
| 667 | table_id=10, |
| 668 | cookie=42, |
| 669 | match=match, |
| 670 | instructions=[ |
| 671 | ofp.instruction.apply_actions( |
| 672 | actions=actions |
| 673 | ), |
| 674 | ofp.instruction.goto_table(20) |
| 675 | ], |
| 676 | priority=0) |
| 677 | logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port)) |
| 678 | ctrl.message_send(request) |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 679 | |
| 680 | if send_barrier: |
| 681 | do_barrier(ctrl) |
| 682 | |
| 683 | return request |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 684 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 685 | def add_bridge_flow(ctrl, dst_mac, vlanid, group_id, send_barrier=False): |
| 686 | match = ofp.match() |
castroflavio | 2189448 | 2015-12-08 15:29:55 -0500 | [diff] [blame] | 687 | priority=500 |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 688 | if dst_mac!=None: |
castroflavio | 2189448 | 2015-12-08 15:29:55 -0500 | [diff] [blame] | 689 | priority=1000 |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 690 | match.oxm_list.append(ofp.oxm.eth_dst(dst_mac)) |
| 691 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 692 | match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlanid)) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 693 | |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 694 | request = ofp.message.flow_add( |
| 695 | table_id=50, |
| 696 | cookie=42, |
| 697 | match=match, |
| 698 | instructions=[ |
| 699 | ofp.instruction.write_actions( |
| 700 | actions=[ |
| 701 | ofp.action.group(group_id)]), |
| 702 | ofp.instruction.goto_table(60) |
| 703 | ], |
| 704 | buffer_id=ofp.OFP_NO_BUFFER, |
castroflavio | 2189448 | 2015-12-08 15:29:55 -0500 | [diff] [blame] | 705 | priority=priority) |
macauley | 9755723 | 2015-07-16 17:28:07 +0800 | [diff] [blame] | 706 | |
| 707 | logging.info("Inserting Brdige flow vlan %d, mac %s", vlanid, dst_mac) |
| 708 | ctrl.message_send(request) |
| 709 | |
| 710 | if send_barrier: |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 711 | do_barrier(ctrl) |
macauley | 15909e7 | 2015-07-17 15:58:57 +0800 | [diff] [blame] | 712 | |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 713 | return request |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 714 | |
| 715 | def add_overlay_bridge_flow(ctrl, dst_mac, vnid, group_id, is_group=True, send_barrier=False): |
| 716 | match = ofp.match() |
| 717 | if dst_mac!=None: |
| 718 | match.oxm_list.append(ofp.oxm.eth_dst(dst_mac)) |
| 719 | |
| 720 | match.oxm_list.append(ofp.oxm.tunnel_id(vnid)) |
| 721 | if is_group == True: |
| 722 | actions=[ofp.action.group(group_id)] |
| 723 | else: |
| 724 | actions=[ofp.action.output(group_id)] |
| 725 | |
| 726 | request = ofp.message.flow_add( |
| 727 | table_id=50, |
| 728 | cookie=42, |
| 729 | match=match, |
| 730 | instructions=[ |
| 731 | ofp.instruction.write_actions( |
| 732 | actions=actions), |
| 733 | ofp.instruction.goto_table(60) |
| 734 | ], |
| 735 | buffer_id=ofp.OFP_NO_BUFFER, |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 736 | priority=1000) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 737 | |
| 738 | logging.info("Inserting Brdige flow vnid %d, mac %s", vnid, dst_mac) |
| 739 | ctrl.message_send(request) |
| 740 | |
| 741 | if send_barrier: |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 742 | do_barrier(ctrl) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 743 | |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 744 | return request |
| 745 | |
macauley_cheng | 6b13366 | 2015-11-09 13:52:39 +0800 | [diff] [blame] | 746 | 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] | 747 | match = ofp.match() |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 748 | match.oxm_list.append(ofp.oxm.eth_type(eth_type)) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 749 | if dst_mac[0]&0x01 == 0x01: |
| 750 | match.oxm_list.append(ofp.oxm.eth_dst_masked(dst_mac, [0xff, 0xff, 0xff, 0x80, 0x00, 0x00])) |
| 751 | goto_table=40 |
| 752 | else: |
macauley | 53d90fe | 2015-08-04 17:34:22 +0800 | [diff] [blame] | 753 | if in_port!=0: |
| 754 | match.oxm_list.append(ofp.oxm.in_port(in_port)) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 755 | match.oxm_list.append(ofp.oxm.eth_dst(dst_mac)) |
| 756 | match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlanid)) |
macauley_cheng | 6b13366 | 2015-11-09 13:52:39 +0800 | [diff] [blame] | 757 | if goto_table == None: |
| 758 | goto_table=30 |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 759 | |
| 760 | request = ofp.message.flow_add( |
| 761 | table_id=20, |
| 762 | cookie=42, |
| 763 | match=match, |
| 764 | instructions=[ |
| 765 | ofp.instruction.goto_table(goto_table) |
| 766 | ], |
| 767 | buffer_id=ofp.OFP_NO_BUFFER, |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 768 | priority=1) |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 769 | |
| 770 | logging.info("Inserting termination flow inport %d, eth_type %lx, vlan %d, mac %s", in_port, eth_type, vlanid, dst_mac) |
| 771 | ctrl.message_send(request) |
| 772 | |
| 773 | if send_barrier: |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 774 | do_barrier(ctrl) |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 775 | |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 776 | return request |
| 777 | |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame] | 778 | def add_unicast_routing_flow(ctrl, eth_type, dst_ip, mask, action_group_id, vrf=0, send_ctrl=False, send_barrier=False): |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 779 | match = ofp.match() |
| 780 | match.oxm_list.append(ofp.oxm.eth_type(eth_type)) |
macauley | 53d90fe | 2015-08-04 17:34:22 +0800 | [diff] [blame] | 781 | if vrf != 0: |
| 782 | 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] | 783 | |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame] | 784 | match.oxm_list.append(ofp.oxm.ipv4_dst_masked(dst_ip, mask)) |
| 785 | |
| 786 | instructions = [] |
| 787 | instructions.append(ofp.instruction.goto_table(60)) |
| 788 | if send_ctrl: |
| 789 | instructions.append(ofp.instruction.apply_actions( |
| 790 | actions=[ofp.action.output( port=ofp.OFPP_CONTROLLER, |
| 791 | max_len=ofp.OFPCML_NO_BUFFER)])) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 792 | else: |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame] | 793 | instructions.append(ofp.instruction.write_actions( |
| 794 | actions=[ofp.action.group(action_group_id)])) |
macauley | 53d90fe | 2015-08-04 17:34:22 +0800 | [diff] [blame] | 795 | |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 796 | request = ofp.message.flow_add( |
| 797 | table_id=30, |
| 798 | cookie=42, |
| 799 | match=match, |
Flavio Castro | af2b450 | 2016-02-02 17:41:32 -0500 | [diff] [blame] | 800 | instructions=instructions, |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 801 | buffer_id=ofp.OFP_NO_BUFFER, |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 802 | priority=1) |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 803 | |
| 804 | logging.info("Inserting unicast routing flow eth_type %lx, dip %ld",eth_type, dst_ip) |
| 805 | ctrl.message_send(request) |
| 806 | |
| 807 | if send_barrier: |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 808 | do_barrier(ctrl) |
macauley | 0f91a3e | 2015-07-17 18:09:59 +0800 | [diff] [blame] | 809 | |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 810 | return request |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 811 | |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame] | 812 | def add_mpls_flow(ctrl, action_group_id, label=100 ,ethertype=0x0800, bos=1, send_barrier=False): |
Flavio Castro | d8f8af2 | 2015-12-02 18:19:26 -0500 | [diff] [blame] | 813 | match = ofp.match() |
| 814 | match.oxm_list.append(ofp.oxm.eth_type(0x8847)) |
| 815 | match.oxm_list.append(ofp.oxm.mpls_label(label)) |
| 816 | match.oxm_list.append(ofp.oxm.mpls_bos(bos)) |
| 817 | actions = [ofp.action.dec_mpls_ttl(), |
| 818 | ofp.action.copy_ttl_in(), |
| 819 | ofp.action.pop_mpls(ethertype)] |
| 820 | request = ofp.message.flow_add( |
| 821 | table_id=24, |
| 822 | cookie=43, |
| 823 | match=match, |
| 824 | instructions=[ |
| 825 | ofp.instruction.apply_actions( |
| 826 | actions=actions |
| 827 | ), |
| 828 | ofp.instruction.write_actions( |
| 829 | actions=[ofp.action.group(action_group_id)]), |
| 830 | ofp.instruction.goto_table(60) |
| 831 | ], |
| 832 | buffer_id=ofp.OFP_NO_BUFFER, |
| 833 | priority=1) |
| 834 | |
| 835 | logging.info("Inserting MPLS flow , label %ld", label) |
| 836 | ctrl.message_send(request) |
| 837 | |
| 838 | if send_barrier: |
| 839 | do_barrier(ctrl) |
| 840 | |
| 841 | return request |
| 842 | |
| 843 | |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 844 | def add_mcast4_routing_flow(ctrl, vlan_id, src_ip, src_ip_mask, dst_ip, action_group_id, send_barrier=False): |
| 845 | match = ofp.match() |
| 846 | match.oxm_list.append(ofp.oxm.eth_type(0x0800)) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 847 | match.oxm_list.append(ofp.oxm.vlan_vid(vlan_id)) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 848 | if src_ip_mask!=0: |
| 849 | match.oxm_list.append(ofp.oxm.ipv4_src_masked(src_ip, src_ip_mask)) |
| 850 | else: |
| 851 | match.oxm_list.append(ofp.oxm.ipv4_src(src_ip)) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 852 | |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 853 | match.oxm_list.append(ofp.oxm.ipv4_dst(dst_ip)) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 854 | |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 855 | request = ofp.message.flow_add( |
| 856 | table_id=40, |
| 857 | cookie=42, |
| 858 | match=match, |
| 859 | instructions=[ |
| 860 | ofp.instruction.write_actions( |
| 861 | actions=[ofp.action.group(action_group_id)]), |
| 862 | ofp.instruction.goto_table(60) |
| 863 | ], |
| 864 | buffer_id=ofp.OFP_NO_BUFFER, |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 865 | priority=1) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 866 | |
| 867 | logging.info("Inserting mcast routing flow eth_type %lx, dip %lx, sip %lx, sip_mask %lx",0x0800, dst_ip, src_ip, src_ip_mask) |
| 868 | ctrl.message_send(request) |
| 869 | |
| 870 | if send_barrier: |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 871 | do_barrier(ctrl) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 872 | |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 873 | return request |
macauley_cheng | 6b13366 | 2015-11-09 13:52:39 +0800 | [diff] [blame] | 874 | |
| 875 | #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] | 876 | 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] | 877 | match = ofp.match() |
| 878 | match.oxm_list.append(ofp.oxm.eth_type(eth_type)) |
| 879 | match.oxm_list.append(ofp.oxm.ipv4_dst(ip_dst)) |
| 880 | match.oxm_list.append(ofp.oxm.ip_proto(ip_proto)) |
| 881 | match.oxm_list.append(ofp.oxm.tcp_dst(tcp_dst)) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 882 | |
macauley_cheng | 6b13366 | 2015-11-09 13:52:39 +0800 | [diff] [blame] | 883 | request = ofp.message.flow_add( |
| 884 | table_id=28, |
| 885 | cookie=42, |
| 886 | match=match, |
| 887 | instructions=[ |
| 888 | ofp.instruction.write_actions( |
| 889 | actions=[ofp.action.set_field(ofp.oxm.ipv4_dst(set_ip_dst)), |
| 890 | ofp.action.set_field(ofp.oxm.tcp_dst(set_tcp_dst)), |
| 891 | ofp.action.group(action_group_id)]), |
| 892 | ofp.instruction.goto_table(60) |
| 893 | ], |
| 894 | buffer_id=ofp.OFP_NO_BUFFER, |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 895 | priority=1) |
macauley_cheng | 6b13366 | 2015-11-09 13:52:39 +0800 | [diff] [blame] | 896 | 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) |
| 897 | ctrl.message_send(request) |
| 898 | return request |
macauley_cheng | effc20a | 2015-11-09 16:14:56 +0800 | [diff] [blame] | 899 | |
| 900 | #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 |
| 901 | def add_snat_flow(ctrl, eth_type, ip_src, ip_proto, tcp_src, set_ip_src, set_tcp_src): |
| 902 | match = ofp.match() |
| 903 | match.oxm_list.append(ofp.oxm.eth_type(eth_type)) |
| 904 | match.oxm_list.append(ofp.oxm.ipv4_src(ip_src)) |
| 905 | match.oxm_list.append(ofp.oxm.ip_proto(ip_proto)) |
| 906 | match.oxm_list.append(ofp.oxm.tcp_src(tcp_src)) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 907 | |
macauley_cheng | effc20a | 2015-11-09 16:14:56 +0800 | [diff] [blame] | 908 | request = ofp.message.flow_add( |
| 909 | table_id=29, |
| 910 | cookie=42, |
| 911 | match=match, |
| 912 | instructions=[ |
| 913 | ofp.instruction.write_actions( |
| 914 | actions=[ofp.action.set_field(ofp.oxm.ipv4_src(set_ip_src)), |
| 915 | ofp.action.set_field(ofp.oxm.tcp_src(set_tcp_src))]), |
| 916 | ofp.instruction.goto_table(30) |
| 917 | ], |
| 918 | buffer_id=ofp.OFP_NO_BUFFER, |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 919 | priority=1) |
macauley_cheng | effc20a | 2015-11-09 16:14:56 +0800 | [diff] [blame] | 920 | 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) |
| 921 | ctrl.message_send(request) |
| 922 | return request |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 923 | |
| 924 | 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] | 925 | """ |
| 926 | Command Example: |
| 927 | of-agent vtap 10001 ethernet 1/1 vid 1 |
| 928 | of-agent vtp 10001 vni 10 |
| 929 | """ |
| 930 | if vlan != 0: |
| 931 | config_vtap_xml=""" |
| 932 | <config> |
| 933 | <capable-switch xmlns="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"> |
| 934 | <id>capable-switch-1</id> |
| 935 | <resources> |
| 936 | <port xc:operation="OPERATION"> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 937 | <resource-id >LPORT</resource-id> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 938 | <features> |
| 939 | <current> |
| 940 | <rate>10Gb</rate> |
| 941 | <medium>fiber</medium> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 942 | <pause>symmetric</pause> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 943 | </current> |
| 944 | <advertised> |
| 945 | <rate>10Gb</rate> |
| 946 | <rate>100Gb</rate> |
| 947 | <medium>fiber</medium> |
| 948 | <pause>symmetric</pause> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 949 | </advertised> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 950 | <supported> |
| 951 | <rate>10Gb</rate> |
| 952 | <rate>100Gb</rate> |
| 953 | <medium>fiber</medium> |
| 954 | <pause>symmetric</pause> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 955 | </supported> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 956 | <advertised-peer> |
| 957 | <rate>10Gb</rate> |
| 958 | <rate>100Gb</rate> |
| 959 | <medium>fiber</medium> |
| 960 | <pause>symmetric</pause> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 961 | </advertised-peer> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 962 | </features> |
| 963 | <ofdpa10:vtap xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION"> |
| 964 | <ofdpa10:phy-port>PHY_PORT</ofdpa10:phy-port> |
| 965 | <ofdpa10:vid>VLAN_ID</ofdpa10:vid> |
| 966 | <ofdpa10:vni>VNID</ofdpa10:vni> |
| 967 | </ofdpa10:vtap> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 968 | </port> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 969 | </resources> |
| 970 | <logical-switches> |
| 971 | <switch> |
| 972 | <id>DATAPATH_ID</id> |
| 973 | <datapath-id>DATAPATH_ID</datapath-id> |
| 974 | <resources> |
| 975 | <port xc:operation="OPERATION">LPORT</port> |
| 976 | </resources> |
| 977 | </switch> |
| 978 | </logical-switches> |
| 979 | </capable-switch> |
| 980 | </config> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 981 | """ |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 982 | else: |
| 983 | config_vtap_xml=""" |
| 984 | <config> |
| 985 | <capable-switch xmlns="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"> |
| 986 | <id>capable-switch-1</id> |
| 987 | <resources> |
| 988 | <port xc:operation="OPERATION"> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 989 | <resource-id >LPORT</resource-id> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 990 | <features> |
| 991 | <current> |
| 992 | <rate>10Gb</rate> |
| 993 | <medium>fiber</medium> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 994 | <pause>symmetric</pause> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 995 | </current> |
| 996 | <advertised> |
| 997 | <rate>10Gb</rate> |
| 998 | <rate>100Gb</rate> |
| 999 | <medium>fiber</medium> |
| 1000 | <pause>symmetric</pause> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1001 | </advertised> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1002 | <supported> |
| 1003 | <rate>10Gb</rate> |
| 1004 | <rate>100Gb</rate> |
| 1005 | <medium>fiber</medium> |
| 1006 | <pause>symmetric</pause> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1007 | </supported> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1008 | <advertised-peer> |
| 1009 | <rate>10Gb</rate> |
| 1010 | <rate>100Gb</rate> |
| 1011 | <medium>fiber</medium> |
| 1012 | <pause>symmetric</pause> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1013 | </advertised-peer> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1014 | </features> |
| 1015 | <ofdpa10:vtap xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION"> |
| 1016 | <ofdpa10:phy-port>PHY_PORT</ofdpa10:phy-port> |
| 1017 | <ofdpa10:vni>VNID</ofdpa10:vni> |
| 1018 | </ofdpa10:vtap> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1019 | </port> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1020 | </resources> |
| 1021 | <logical-switches> |
| 1022 | <switch> |
| 1023 | <id>DATAPATH_ID</id> |
| 1024 | <datapath-id>DATAPATH_ID</datapath-id> |
| 1025 | <resources> |
| 1026 | <port xc:operation="OPERATION">LPORT</port> |
| 1027 | </resources> |
| 1028 | </switch> |
| 1029 | </logical-switches> |
| 1030 | </capable-switch> |
| 1031 | </config> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1032 | """ |
| 1033 | str_datapath_id_f= "{:016x}".format(dp_id) |
| 1034 | str_datapath_id=':'.join([str_datapath_id_f[i:i+2] for i in range(0, len(str_datapath_id_f), 2)]) |
| 1035 | config_vtap_xml=config_vtap_xml.replace("DATAPATH_ID", str_datapath_id) |
| 1036 | config_vtap_xml=config_vtap_xml.replace("LPORT", str(int(lport))) |
| 1037 | config_vtap_xml=config_vtap_xml.replace("PHY_PORT", str(phy_port)) |
| 1038 | config_vtap_xml=config_vtap_xml.replace("VLAN_ID", str(vlan)) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1039 | config_vtap_xml=config_vtap_xml.replace("VNID", str(vnid)) |
| 1040 | config_vtap_xml=config_vtap_xml.replace("OPERATION", str(operation)) |
| 1041 | return config_vtap_xml |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1042 | |
| 1043 | 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] | 1044 | """ |
| 1045 | Command Example: |
| 1046 | of-agent vtep 10002 source user-input-src-ip destination user-input-dst-ip udp-source-port 6633 nexthop 2 ttl 25 |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1047 | of-agent vtp 10001 vni 10 |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1048 | """ |
| 1049 | |
| 1050 | config_vtep_xml=""" |
| 1051 | <config> |
| 1052 | <capable-switch xmlns="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"> |
| 1053 | <id>capable-switch-1</id> |
| 1054 | <resources> |
| 1055 | <port xc:operation="OPERATION"> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1056 | <resource-id>LPORT</resource-id> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1057 | <features> |
| 1058 | <current> |
| 1059 | <rate>10Gb</rate> |
| 1060 | <medium>fiber</medium> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1061 | <pause>symmetric</pause> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1062 | </current> |
| 1063 | <advertised> |
| 1064 | <rate>10Gb</rate> |
| 1065 | <rate>100Gb</rate> |
| 1066 | <medium>fiber</medium> |
| 1067 | <pause>symmetric</pause> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1068 | </advertised> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1069 | <supported> |
| 1070 | <rate>10Gb</rate> |
| 1071 | <rate>100Gb</rate> |
| 1072 | <medium>fiber</medium> |
| 1073 | <pause>symmetric</pause> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1074 | </supported> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1075 | <advertised-peer> |
| 1076 | <rate>10Gb</rate> |
| 1077 | <rate>100Gb</rate> |
| 1078 | <medium>fiber</medium> |
| 1079 | <pause>symmetric</pause> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1080 | </advertised-peer> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1081 | </features> |
| 1082 | <ofdpa10:vtep xmlns:ofdpa10="urn:bcm:ofdpa10:accton01"> |
| 1083 | <ofdpa10:src-ip>SRC_IP</ofdpa10:src-ip> |
| 1084 | <ofdpa10:dest-ip>DST_IP</ofdpa10:dest-ip> |
| 1085 | <ofdpa10:udp-src-port>UDP_SRC_PORT</ofdpa10:udp-src-port> |
macauley | 25999cf | 2015-08-07 17:03:24 +0800 | [diff] [blame] | 1086 | <ofdpa10:vni xc:operation="OPERATION"> |
| 1087 | <ofdpa10:id>VNID</ofdpa10:id> |
| 1088 | </ofdpa10:vni> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1089 | <ofdpa10:nexthop-id>NEXT_HOP_ID</ofdpa10:nexthop-id> |
| 1090 | <ofdpa10:ttl>TTL</ofdpa10:ttl> |
| 1091 | </ofdpa10:vtep> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1092 | </port> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1093 | </resources> |
| 1094 | <logical-switches> |
| 1095 | <switch> |
| 1096 | <id>DATAPATH_ID</id> |
| 1097 | <datapath-id>DATAPATH_ID</datapath-id> |
| 1098 | <resources> |
| 1099 | <port xc:operation="OPERATION">LPORT</port> |
| 1100 | </resources> |
| 1101 | </switch> |
| 1102 | </logical-switches> |
| 1103 | </capable-switch> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1104 | </config> |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1105 | """ |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1106 | str_datapath_id_f= "{:016x}".format(dp_id) |
| 1107 | str_datapath_id=':'.join([str_datapath_id_f[i:i+2] for i in range(0, len(str_datapath_id_f), 2)]) |
| 1108 | config_vtep_xml=config_vtep_xml.replace("DATAPATH_ID", str_datapath_id) |
macauley | 25999cf | 2015-08-07 17:03:24 +0800 | [diff] [blame] | 1109 | config_vtep_xml=config_vtep_xml.replace("LPORT", str(int(lport))) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1110 | config_vtep_xml=config_vtep_xml.replace("SRC_IP", str(src_ip)) |
| 1111 | config_vtep_xml=config_vtep_xml.replace("DST_IP", str(dst_ip)) |
| 1112 | config_vtep_xml=config_vtep_xml.replace("UDP_SRC_PORT", str(udp_src_port)) |
| 1113 | config_vtep_xml=config_vtep_xml.replace("NEXT_HOP_ID", str(next_hop_id)) |
| 1114 | config_vtep_xml=config_vtep_xml.replace("TTL", str(ttl)) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1115 | config_vtep_xml=config_vtep_xml.replace("VNID", str(vnid)) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1116 | config_vtep_xml=config_vtep_xml.replace("OPERATION", str(operation)) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1117 | |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1118 | return config_vtep_xml |
| 1119 | |
| 1120 | 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] | 1121 | #of-agent nexthop 2 destination user-input-dst-mac ethernet 1/2 vid 2 |
| 1122 | config_nexthop_xml=""" |
| 1123 | <config> |
| 1124 | <of11-config:capable-switch xmlns:of11-config="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"> |
| 1125 | <ofdpa10:next-hop xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION"> |
| 1126 | <ofdpa10:id>NEXT_HOP_ID</ofdpa10:id> |
| 1127 | <ofdpa10:dest-mac>DST_MAC</ofdpa10:dest-mac> |
| 1128 | <ofdpa10:phy-port>PHY_PORT</ofdpa10:phy-port> |
| 1129 | <ofdpa10:vid>VLAN_ID</ofdpa10:vid> |
| 1130 | </ofdpa10:next-hop> |
| 1131 | </of11-config:capable-switch> |
| 1132 | </config> |
| 1133 | """ |
| 1134 | config_nexthop_xml=config_nexthop_xml.replace("VLAN_ID", str(vlan)) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1135 | config_nexthop_xml=config_nexthop_xml.replace("PHY_PORT", str(phy_port)) |
| 1136 | config_nexthop_xml=config_nexthop_xml.replace("NEXT_HOP_ID", str(next_hop_id)) |
| 1137 | config_nexthop_xml=config_nexthop_xml.replace("DST_MAC", str(dst_mac)) |
| 1138 | config_nexthop_xml=config_nexthop_xml.replace("OPERATION", str(operation)) |
| 1139 | return config_nexthop_xml |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1140 | |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1141 | 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] | 1142 | #of-agent vni 10 multicast 224.1.1.1 nexthop 20 |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1143 | if mcast_ipv4!=None: |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1144 | config_vni_xml=""" |
| 1145 | <config> |
| 1146 | <of11-config:capable-switch xmlns:of11-config="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"> |
| 1147 | <ofdpa10:vni xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION"> |
| 1148 | <ofdpa10:id>VNID</ofdpa10:id> |
| 1149 | <ofdpa10:vni-multicast-group>MCAST_IP</ofdpa10:vni-multicast-group> |
| 1150 | <ofdpa10:multicast-group-nexthop-id>NEXT_HOP_ID</ofdpa10:multicast-group-nexthop-id> |
| 1151 | </ofdpa10:vni> |
| 1152 | </of11-config:capable-switch> |
| 1153 | </config> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1154 | """ |
| 1155 | config_vni_xml=config_vni_xml.replace("NEXT_HOP_ID", str(next_hop_id)) |
| 1156 | config_vni_xml=config_vni_xml.replace("MCAST_IP", str(mcast_ipv4)) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1157 | else: |
| 1158 | config_vni_xml=""" |
| 1159 | <config> |
| 1160 | <of11-config:capable-switch xmlns:of11-config="urn:onf:of111:config:yang" xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"> |
| 1161 | <ofdpa10:vni xmlns:ofdpa10="urn:bcm:ofdpa10:accton01" xc:operation="OPERATION"> |
| 1162 | <ofdpa10:id>VNID</ofdpa10:id> |
| 1163 | </ofdpa10:vni> |
| 1164 | </of11-config:capable-switch> |
| 1165 | </config> |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1166 | """ |
| 1167 | |
| 1168 | config_vni_xml=config_vni_xml.replace("VNID", str(vni_id)) |
| 1169 | config_vni_xml=config_vni_xml.replace("OPERATION", str(operation)) |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1170 | return config_vni_xml |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1171 | |
| 1172 | def get_featureReplay(self): |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1173 | req = ofp.message.features_request() |
| 1174 | res, raw = self.controller.transact(req) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1175 | self.assertIsNotNone(res, "Did not receive a response from the DUT.") |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1176 | self.assertEqual(res.type, ofp.OFPT_FEATURES_REPLY, |
| 1177 | ("Unexpected packet type %d received in response to " |
| 1178 | "OFPT_FEATURES_REQUEST") % res.type) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1179 | return res |
| 1180 | |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1181 | def send_edit_config(switch_ip, xml, target='runing'): |
| 1182 | NETCONF_ACCOUNT="netconfuser" |
| 1183 | NETCONF_PASSWD="netconfuser" |
| 1184 | with manager.connect_ssh(host=switch_ip, port=830, username=NETCONF_ACCOUNT, password=NETCONF_PASSWD, hostkey_verify=False ) as m: |
| 1185 | try: |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1186 | m.edit_config(target='running', |
| 1187 | config=xml, |
| 1188 | default_operation='merge', |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1189 | error_option='stop-on-error') |
| 1190 | |
| 1191 | except Exception as e: |
| 1192 | logging.info("Fail to set xml %s", xml) |
| 1193 | return False |
| 1194 | |
| 1195 | #return m.get_config(source='running').data_xml |
| 1196 | return True |
| 1197 | |
| 1198 | def send_delete_config(switch_ip, xml, target='runing'): |
| 1199 | NETCONF_ACCOUNT="netconfuser" |
| 1200 | NETCONF_PASSWD="netconfuser" |
| 1201 | with manager.connect_ssh(host=switch_ip, port=830, username=NETCONF_ACCOUNT, password=NETCONF_PASSWD, hostkey_verify=False ) as m: |
| 1202 | try: |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1203 | m.edit_config(target='running', |
| 1204 | config=xml, |
| 1205 | default_operation='delete', |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1206 | error_option='stop-on-error') |
| 1207 | |
| 1208 | except Exception as e: |
| 1209 | logging.info("Fail to set xml %s", xml) |
| 1210 | return False |
| 1211 | |
| 1212 | #return m.get_config(source='running').data_xml |
| 1213 | return True |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1214 | |
macauley | fddc466 | 2015-07-27 17:40:30 +0800 | [diff] [blame] | 1215 | def get_edit_config(switch_ip, target='runing'): |
| 1216 | NETCONF_ACCOUNT="netconfuser" |
| 1217 | NETCONF_PASSWD="netconfuser" |
| 1218 | with manager.connect_ssh(host=switch_ip, port=830, username=NETCONF_ACCOUNT, password=NETCONF_PASSWD, hostkey_verify=False ) as m: |
macauley | 6f6ceb2 | 2015-08-07 09:37:12 +0800 | [diff] [blame] | 1219 | return m.get_config(source='running').data_xml |
macauley | dbff327 | 2015-07-30 14:07:16 +0800 | [diff] [blame] | 1220 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1221 | |
| 1222 | """ |
| 1223 | MPLS |
| 1224 | """ |
| 1225 | |
| 1226 | OFDPA_MPLS_SUBTYPE_SHIFT=24 |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1227 | OFDPA_MPLS_GROUP_SUBTYPE_L2_VPN_LABEL=1 |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1228 | OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL=2 |
| 1229 | OFDPA_MPLS_GROUP_SUBTYPE_TUNNEL_LABEL1=3 |
| 1230 | OFDPA_MPLS_GROUP_SUBTYPE_TUNNEL_LABEL2=4 |
| 1231 | OFDPA_MPLS_GROUP_SUBTYPE_SWAP_LABEL=5 |
| 1232 | OFDPA_MPLS_GROUP_SUBTYPE_FAST_FAILOVER_GROUP=6 |
| 1233 | OFDPA_MPLS_GROUP_SUBTYPE_ECMP=8 |
| 1234 | OFDPA_MPLS_GROUP_SUBTYPE_L2_TAG=10 |
| 1235 | |
| 1236 | def encode_mpls_interface_group_id(subtype, index): |
| 1237 | index=index&0x00ffffff |
| 1238 | assert(subtype==0) |
| 1239 | return index + (9 << OFDPA_GROUP_TYPE_SHIFT)+(subtype<<OFDPA_MPLS_SUBTYPE_SHIFT) |
| 1240 | |
| 1241 | def encode_mpls_label_group_id(subtype, index): |
| 1242 | index=index&0x00ffffff |
| 1243 | assert(subtype <=5 or subtype==0) |
| 1244 | #1: l2 vpn label |
| 1245 | #2: l3 vpn label |
| 1246 | #3: mpls tunnel label 1 |
| 1247 | #4: mpls tunnel lable 2 |
| 1248 | #5: mpls swap label |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1249 | return index + (9 << OFDPA_GROUP_TYPE_SHIFT)+(subtype<<OFDPA_MPLS_SUBTYPE_SHIFT) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1250 | |
| 1251 | def encode_mpls_forwarding_group_id(subtype, index): |
| 1252 | index=index&0x00ffffff |
| 1253 | assert(subtype==6 or subtype==8 or subtype==10) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1254 | return index + (10 << OFDPA_GROUP_TYPE_SHIFT)+(subtype<<OFDPA_MPLS_SUBTYPE_SHIFT) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1255 | |
| 1256 | |
| 1257 | def add_mpls_intf_group(ctrl, ref_gid, dst_mac, src_mac, vid, index, subtype=0): |
| 1258 | action=[] |
| 1259 | action.append(ofp.action.set_field(ofp.oxm.eth_src(src_mac))) |
| 1260 | action.append(ofp.action.set_field(ofp.oxm.eth_dst(dst_mac))) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1261 | action.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vid))) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1262 | action.append(ofp.action.group(ref_gid)) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1263 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1264 | buckets = [ofp.bucket(actions=action)] |
| 1265 | |
| 1266 | mpls_group_id =encode_mpls_interface_group_id(subtype, index) |
| 1267 | request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT, |
| 1268 | group_id=mpls_group_id, |
| 1269 | buckets=buckets |
| 1270 | ) |
| 1271 | ctrl.message_send(request) |
| 1272 | return mpls_group_id, request |
| 1273 | |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1274 | def add_mpls_label_group(ctrl, subtype, index, ref_gid, |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1275 | lmep_id=-1, |
| 1276 | qos_index=-1, |
| 1277 | push_l2_header=False, |
| 1278 | push_vlan=False, |
| 1279 | push_mpls_header=False, |
| 1280 | push_cw=False, |
| 1281 | set_mpls_label=None, |
| 1282 | set_bos=None, |
| 1283 | set_tc=None, |
| 1284 | set_tc_from_table=False, |
| 1285 | cpy_tc_outward=False, |
| 1286 | set_ttl=None, |
| 1287 | cpy_ttl_outward=False, |
| 1288 | oam_lm_tx_count=False, |
| 1289 | set_pri_from_table=False |
| 1290 | ): |
| 1291 | """ |
| 1292 | @ref_gid: only can be mpls intf group or mpls tunnel label 1/2 group |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1293 | """ |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1294 | action=[] |
| 1295 | |
| 1296 | if push_vlan== True: |
| 1297 | action.append(ofp.action.push_vlan(0x8100)) |
| 1298 | if push_mpls_header== True: |
| 1299 | action.append(ofp.action.push_mpls(0x8847)) |
| 1300 | if set_mpls_label != None: |
| 1301 | action.append(ofp.action.set_field(ofp.oxm.mpls_label(set_mpls_label))) |
| 1302 | if set_bos != None: |
| 1303 | action.append(ofp.action.set_field(ofp.oxm.mpls_bos(set_bos))) |
| 1304 | if set_tc != None: |
| 1305 | assert(set_tc_from_table==False) |
| 1306 | action.append(ofp.action.set_field(ofp.oxm.mpls_tc(set_tc))) |
| 1307 | if set_ttl != None: |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1308 | action.append(ofp.action.set_mpls_ttl(set_ttl)) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1309 | if cpy_ttl_outward == True: |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1310 | action.append(ofp.action.copy_ttl_out()) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1311 | """ |
| 1312 | ofdpa experimenter |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1313 | """ |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1314 | if push_l2_header== True: |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1315 | action.append(ofp.action.ofdpa_push_l2_header()) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1316 | if set_tc_from_table== True: |
| 1317 | assert(qos_index>=0) |
| 1318 | assert(set_tc == None) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1319 | action.append(ofp.action.ofdpa_set_tc_from_table(qos_index)) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1320 | if cpy_tc_outward == True: |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1321 | action.append(ofp.action.ofdpa_copy_tc_out()) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1322 | if oam_lm_tx_count == True: |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1323 | assert(qos_index>=0 and lmep_id>=0) |
| 1324 | 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] | 1325 | if set_pri_from_table == True: |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1326 | assert(qos_index>=0) |
| 1327 | action.append(ofp.action.ofdpa_set_qos_from_table(qos_index)) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1328 | if push_cw == True: |
| 1329 | action.append(ofp.action.ofdpa_push_cw()) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1330 | |
| 1331 | action.append(ofp.action.group(ref_gid)) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1332 | buckets = [ofp.bucket(actions=action)] |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1333 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1334 | mpls_group_id = encode_mpls_label_group_id(subtype, index) |
| 1335 | request = ofp.message.group_add(group_type=ofp.OFPGT_INDIRECT, |
| 1336 | group_id=mpls_group_id, |
| 1337 | buckets=buckets |
| 1338 | ) |
| 1339 | ctrl.message_send(request) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1340 | |
| 1341 | return mpls_group_id, request |
| 1342 | |
| 1343 | def add_mpls_forwarding_group(ctrl, subtype, index, ref_gids, |
| 1344 | watch_port=None, |
| 1345 | watch_group=ofp.OFPP_ANY, |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1346 | push_vlan=None, |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1347 | pop_vlan=None, |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1348 | set_vid=None): |
| 1349 | assert(subtype == OFDPA_MPLS_GROUP_SUBTYPE_FAST_FAILOVER_GROUP |
| 1350 | or subtype == OFDPA_MPLS_GROUP_SUBTYPE_ECMP |
| 1351 | or subtype == OFDPA_MPLS_GROUP_SUBTYPE_L2_TAG) |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1352 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1353 | buckets=[] |
| 1354 | if subtype == OFDPA_MPLS_GROUP_SUBTYPE_FAST_FAILOVER_GROUP: |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1355 | group_type = ofp.OFPGT_FF |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1356 | for gid in ref_gids: |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1357 | action=[] |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1358 | action.append(ofp.action.group(gid)) |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1359 | buckets.append(ofp.bucket(watch_port=watch_port, watch_group=watch_group,actions=action)) |
| 1360 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1361 | elif subtype == OFDPA_MPLS_GROUP_SUBTYPE_ECMP: |
| 1362 | group_type = ofp.OFPGT_SELECT |
| 1363 | for gid in ref_gids: |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1364 | action=[] |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1365 | action.append(ofp.action.group(gid)) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1366 | buckets.append(ofp.bucket(actions=action)) |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1367 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1368 | elif subtype == OFDPA_MPLS_GROUP_SUBTYPE_L2_TAG: |
| 1369 | group_type = ofp.OFPGT_INDIRECT |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1370 | action=[] |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1371 | if set_vid!=None: |
| 1372 | action.append(ofp.action.set_field(ofp.oxm.vlan_vid(set_vid))) |
| 1373 | if push_vlan!=None: |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1374 | action.append(ofp.action.push_vlan(push_vlan)) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1375 | if pop_vlan!=None: |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1376 | action.append(ofp.action.pop_vlan()) |
| 1377 | action.append(ofp.action.group(ref_gids[0])) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1378 | buckets.append(ofp.bucket(actions=action)) |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1379 | |
| 1380 | mpls_group_id = encode_mpls_forwarding_group_id(subtype, index) |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1381 | request = ofp.message.group_add(group_type=group_type, |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1382 | group_id=mpls_group_id, |
| 1383 | buckets=buckets |
| 1384 | ) |
| 1385 | ctrl.message_send(request) |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1386 | return mpls_group_id, request |
macauley_cheng | d17ce51 | 2015-08-31 17:45:51 +0800 | [diff] [blame] | 1387 | |
| 1388 | |
macauley_cheng | 67da926 | 2015-08-31 15:18:41 +0800 | [diff] [blame] | 1389 | """ |
| 1390 | dislay |
Pier | baa8a18 | 2016-08-24 16:59:20 -0700 | [diff] [blame] | 1391 | """ |
macauley | dbff327 | 2015-07-30 14:07:16 +0800 | [diff] [blame] | 1392 | def print_current_table_flow_stat(ctrl, table_id=0xff): |
| 1393 | stat_req=ofp.message.flow_stats_request() |
| 1394 | response, pkt = ctrl.transact(stat_req) |
| 1395 | if response == None: |
| 1396 | print "no response" |
| 1397 | return None |
| 1398 | print len(response.entries) |
| 1399 | for obj in response.entries: |
| 1400 | print "match ", obj.match |
| 1401 | print "cookie", obj.cookie |
| 1402 | print "priority", obj.priority |
| 1403 | print "idle_timeout", obj.idle_timeout |
| 1404 | print "hard_timeout", obj.hard_timeout |
| 1405 | #obj.actions |
Flavio Castro | 167f5bd | 2015-12-02 19:33:53 -0500 | [diff] [blame] | 1406 | print "packet count: %lx"%obj.packet_count |