blob: b00a60f1848f228e6db3074e186493d9703445ea [file] [log] [blame]
Shad Ansari2dda4f32018-05-17 07:16:07 +00001#
2# Copyright 2018 the original author or authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -040016import copy
17from twisted.internet import reactor
Nicolas Palpacuer3d0878d2018-08-17 11:29:42 -040018import grpc
Girish Gowdruab836e92018-10-25 01:17:57 -070019from google.protobuf.json_format import MessageToDict
Girish Gowdrub761bc12018-11-29 02:22:18 -080020import hashlib
Girish Gowdru841708f2019-02-08 04:29:48 -080021import ast
Girish Gowdrub761bc12018-11-29 02:22:18 -080022from simplejson import dumps
Shad Ansari2dda4f32018-05-17 07:16:07 +000023
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -040024from voltha.protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, \
Shad Ansari7a5d2172019-02-26 13:35:36 -080025 ofp_flow_stats, OFPMT_OXM, Flows, FlowGroups, \
Jonathan Hart5b435642018-08-20 08:50:05 -070026 OFPXMT_OFB_VLAN_VID
Nicolas Palpacuer5780e152018-09-05 17:25:42 -040027from voltha.protos.device_pb2 import Port
Shad Ansari2dda4f32018-05-17 07:16:07 +000028import voltha.core.flow_decomposer as fd
Shad Ansari2dda4f32018-05-17 07:16:07 +000029from voltha.adapters.openolt.protos import openolt_pb2
Girish Gowdru841708f2019-02-08 04:29:48 -080030from voltha.protos import tech_profile_pb2
Nicolas Palpacuer61815162018-06-20 18:12:04 -040031from voltha.registry import registry
Girish Gowdru841708f2019-02-08 04:29:48 -080032from common.tech_profile.tech_profile import Direction, TechProfile
Girish Gowdruab836e92018-10-25 01:17:57 -070033
34# Flow categories
35HSIA_FLOW = "HSIA_FLOW"
Nicolas Palpacuer61815162018-06-20 18:12:04 -040036
37EAP_ETH_TYPE = 0x888e
Jonathan Hart5b435642018-08-20 08:50:05 -070038LLDP_ETH_TYPE = 0x88cc
Girish Gowdru841708f2019-02-08 04:29:48 -080039IPV4_ETH_TYPE = 0x800
40IPv6_ETH_TYPE = 0x86dd
Shad Ansari2dda4f32018-05-17 07:16:07 +000041
Girish Gowdruab836e92018-10-25 01:17:57 -070042IGMP_PROTO = 2
43
Shad Ansari2dda4f32018-05-17 07:16:07 +000044# FIXME - see also BRDCM_DEFAULT_VLAN in broadcom_onu.py
45DEFAULT_MGMT_VLAN = 4091
Thiyagarajan Subramani3b62d6c2019-02-15 08:48:01 -080046RESERVED_VLAN = 4095
Shad Ansari2dda4f32018-05-17 07:16:07 +000047
Nicolas Palpacuer2789f042018-09-17 09:10:29 -040048# Openolt Flow
Girish Gowdruab836e92018-10-25 01:17:57 -070049UPSTREAM = "upstream"
50DOWNSTREAM = "downstream"
51PACKET_TAG_TYPE = "pkt_tag_type"
52UNTAGGED = "untagged"
53SINGLE_TAG = "single_tag"
54DOUBLE_TAG = "double_tag"
Nicolas Palpacuer2789f042018-09-17 09:10:29 -040055
56# Classifier
57ETH_TYPE = 'eth_type'
58TPID = 'tpid'
59IP_PROTO = 'ip_proto'
60IN_PORT = 'in_port'
61VLAN_VID = 'vlan_vid'
62VLAN_PCP = 'vlan_pcp'
63UDP_DST = 'udp_dst'
64UDP_SRC = 'udp_src'
65IPV4_DST = 'ipv4_dst'
66IPV4_SRC = 'ipv4_src'
67METADATA = 'metadata'
68OUTPUT = 'output'
69# Action
70POP_VLAN = 'pop_vlan'
71PUSH_VLAN = 'push_vlan'
72TRAP_TO_HOST = 'trap_to_host'
73
Nicolas Palpacuer2789f042018-09-17 09:10:29 -040074
Shad Ansari2dda4f32018-05-17 07:16:07 +000075class OpenOltFlowMgr(object):
76
Shad Ansarif9b9b892019-02-27 17:10:27 -080077 def __init__(self, log, stub, device_id, logical_device_id,
78 platform, resource_mgr, data_model):
79 self.data_model = data_model
Shad Ansari2dda4f32018-05-17 07:16:07 +000080 self.log = log
81 self.stub = stub
Nicolas Palpacuer61815162018-06-20 18:12:04 -040082 self.device_id = device_id
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -040083 self.logical_device_id = logical_device_id
Shad Ansaricd20a6d2018-10-02 14:36:33 +000084 self.platform = platform
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -040085 self.logical_flows_proxy = registry('core').get_proxy(
86 '/logical_devices/{}/flows'.format(self.logical_device_id))
87 self.flows_proxy = registry('core').get_proxy(
Nicolas Palpacuer61815162018-06-20 18:12:04 -040088 '/devices/{}/flows'.format(self.device_id))
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -040089 self.root_proxy = registry('core').get_proxy('/')
Girish Gowdru1e77ea02018-09-24 09:10:35 -070090 self.resource_mgr = resource_mgr
Girish Gowdruab836e92018-10-25 01:17:57 -070091 self.tech_profile = dict()
92 self._populate_tech_profile_per_pon_port()
Scott Bakerbe5a9ea2018-11-19 19:24:21 -080093 self.retry_add_flow_list = []
Shad Ansari2dda4f32018-05-17 07:16:07 +000094
Shad Ansari4f9a9732019-03-08 16:47:08 -080095 def update_logical_flows(self, flows_to_add, flows_to_remove,
96 device_rules_map):
97 try:
98 self.update_children_flows(device_rules_map)
99 except Exception as e:
100 self.log.error('Error updating children flows', error=e)
101
102 self.log.debug('logical flows update', flows_to_add=flows_to_add,
103 flows_to_remove=flows_to_remove)
104
105 for flow in flows_to_add:
106
107 try:
108 self.add_flow(flow)
109 except Exception as e:
110 self.log.error('failed to add flow', flow=flow, e=e)
111
112 for flow in flows_to_remove:
113
114 try:
115 self.remove_flow(flow)
116 except Exception as e:
117 self.log.error('failed to remove flow', flow=flow, e=e)
118
119 self.repush_all_different_flows()
120
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400121 def add_flow(self, flow):
122 self.log.debug('add flow', flow=flow)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000123 classifier_info = dict()
124 action_info = dict()
Girish Gowdru841708f2019-02-08 04:29:48 -0800125 us_meter_id = None
126 ds_meter_id = None
Shad Ansari2dda4f32018-05-17 07:16:07 +0000127
Shad Ansari2dda4f32018-05-17 07:16:07 +0000128 for field in fd.get_ofb_fields(flow):
129 if field.type == fd.ETH_TYPE:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400130 classifier_info[ETH_TYPE] = field.eth_type
Shad Ansarie048aaa2018-05-18 18:27:21 +0000131 self.log.debug('field-type-eth-type',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400132 eth_type=classifier_info[ETH_TYPE])
Girish Gowdru841708f2019-02-08 04:29:48 -0800133 if classifier_info[ETH_TYPE] == IPv6_ETH_TYPE:
134 self.log.debug('Not handling IPv6 flows')
135 return
Shad Ansari2dda4f32018-05-17 07:16:07 +0000136 elif field.type == fd.IP_PROTO:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400137 classifier_info[IP_PROTO] = field.ip_proto
Shad Ansarie048aaa2018-05-18 18:27:21 +0000138 self.log.debug('field-type-ip-proto',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400139 ip_proto=classifier_info[IP_PROTO])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000140 elif field.type == fd.IN_PORT:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400141 classifier_info[IN_PORT] = field.port
Shad Ansarie048aaa2018-05-18 18:27:21 +0000142 self.log.debug('field-type-in-port',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400143 in_port=classifier_info[IN_PORT])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000144 elif field.type == fd.VLAN_VID:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400145 classifier_info[VLAN_VID] = field.vlan_vid & 0xfff
Shad Ansarie048aaa2018-05-18 18:27:21 +0000146 self.log.debug('field-type-vlan-vid',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400147 vlan=classifier_info[VLAN_VID])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000148 elif field.type == fd.VLAN_PCP:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400149 classifier_info[VLAN_PCP] = field.vlan_pcp
Shad Ansarie048aaa2018-05-18 18:27:21 +0000150 self.log.debug('field-type-vlan-pcp',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400151 pcp=classifier_info[VLAN_PCP])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000152 elif field.type == fd.UDP_DST:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400153 classifier_info[UDP_DST] = field.udp_dst
Shad Ansarie048aaa2018-05-18 18:27:21 +0000154 self.log.debug('field-type-udp-dst',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400155 udp_dst=classifier_info[UDP_DST])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000156 elif field.type == fd.UDP_SRC:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400157 classifier_info[UDP_SRC] = field.udp_src
Shad Ansarie048aaa2018-05-18 18:27:21 +0000158 self.log.debug('field-type-udp-src',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400159 udp_src=classifier_info[UDP_SRC])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000160 elif field.type == fd.IPV4_DST:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400161 classifier_info[IPV4_DST] = field.ipv4_dst
Shad Ansarie048aaa2018-05-18 18:27:21 +0000162 self.log.debug('field-type-ipv4-dst',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400163 ipv4_dst=classifier_info[IPV4_DST])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000164 elif field.type == fd.IPV4_SRC:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400165 classifier_info[IPV4_SRC] = field.ipv4_src
Shad Ansarie048aaa2018-05-18 18:27:21 +0000166 self.log.debug('field-type-ipv4-src',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400167 ipv4_dst=classifier_info[IPV4_SRC])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000168 else:
169 raise NotImplementedError('field.type={}'.format(
170 field.type))
171
172 for action in fd.get_actions(flow):
173 if action.type == fd.OUTPUT:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400174 action_info[OUTPUT] = action.output.port
Shad Ansarie048aaa2018-05-18 18:27:21 +0000175 self.log.debug('action-type-output',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400176 output=action_info[OUTPUT],
177 in_port=classifier_info[IN_PORT])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000178 elif action.type == fd.POP_VLAN:
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400179 if fd.get_goto_table_id(flow) is None:
180 self.log.debug('being taken care of by ONU', flow=flow)
181 return
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400182 action_info[POP_VLAN] = True
Jonathan Hart5b435642018-08-20 08:50:05 -0700183 self.log.debug('action-type-pop-vlan',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400184 in_port=classifier_info[IN_PORT])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000185 elif action.type == fd.PUSH_VLAN:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400186 action_info[PUSH_VLAN] = True
187 action_info[TPID] = action.push.ethertype
Shad Ansarie048aaa2018-05-18 18:27:21 +0000188 self.log.debug('action-type-push-vlan',
Shad Ansari7a5d2172019-02-26 13:35:36 -0800189 push_tpid=action_info[TPID],
190 in_port=classifier_info[IN_PORT])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000191 if action.push.ethertype != 0x8100:
192 self.log.error('unhandled-tpid',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000193 ethertype=action.push.ethertype)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000194 elif action.type == fd.SET_FIELD:
195 # action_info['action_type'] = 'set_field'
196 _field = action.set_field.field.ofb_field
197 assert (action.set_field.field.oxm_class ==
198 OFPXMC_OPENFLOW_BASIC)
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400199 self.log.debug('action-type-set-field',
200 field=_field, in_port=classifier_info[IN_PORT])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000201 if _field.type == fd.VLAN_VID:
Shad Ansarie048aaa2018-05-18 18:27:21 +0000202 self.log.debug('set-field-type-vlan-vid',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000203 vlan_vid=_field.vlan_vid & 0xfff)
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400204 action_info[VLAN_VID] = (_field.vlan_vid & 0xfff)
Girish Gowdru841708f2019-02-08 04:29:48 -0800205 elif _field.type == fd.VLAN_PCP:
206 self.log.debug('set-field-type-vlan-pcp',
207 vlan_pcp=_field.vlan_pcp & 0x7)
208 action_info[VLAN_PCP] = (_field.vlan_pcp & 0x7)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000209 else:
210 self.log.error('unsupported-action-set-field-type',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000211 field_type=_field.type)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000212 else:
213 self.log.error('unsupported-action-type',
Shad Ansari7a5d2172019-02-26 13:35:36 -0800214 action_type=action.type,
215 in_port=classifier_info[IN_PORT])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000216
Shad Ansari7a5d2172019-02-26 13:35:36 -0800217 if fd.get_goto_table_id(flow) is not None \
218 and POP_VLAN not in action_info:
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400219 self.log.debug('being taken care of by ONU', flow=flow)
Nicolas Palpacuer856d3af2018-09-12 15:04:51 -0400220 return
Shad Ansari2dda4f32018-05-17 07:16:07 +0000221
Girish Gowdru841708f2019-02-08 04:29:48 -0800222 flow_metadata = fd.get_metadata_from_write_metadata(flow)
223
224 if OUTPUT not in action_info and flow_metadata is not None:
Girish Gowdruab836e92018-10-25 01:17:57 -0700225 # find flow in the next table
Girish Gowdru841708f2019-02-08 04:29:48 -0800226 next_flow = self.find_next_flow(flow, flow_metadata)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400227 if next_flow is None:
228 return
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400229 action_info[OUTPUT] = fd.get_out_port(next_flow)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400230 for field in fd.get_ofb_fields(next_flow):
231 if field.type == fd.VLAN_VID:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400232 classifier_info[METADATA] = field.vlan_vid & 0xfff
233
Shad Ansari7a5d2172019-02-26 13:35:36 -0800234 self.log.debug('flow-ports',
235 classifier_inport=classifier_info[IN_PORT],
236 action_output=action_info[OUTPUT])
237 (port_no, intf_id, onu_id, uni_id) \
238 = self.platform.extract_access_from_flow(
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400239 classifier_info[IN_PORT], action_info[OUTPUT])
240
Girish Gowdru841708f2019-02-08 04:29:48 -0800241 # LLDP flow has nothing to do with any particular subscriber.
242 # So, lets not care about the Tech-profile, meters etc.
243 # Just add the flow and return.
244 if ETH_TYPE in classifier_info and \
245 classifier_info[ETH_TYPE] == LLDP_ETH_TYPE:
246 self.log.debug('lldp flow add')
247 self.add_lldp_flow(flow, port_no)
248 return
249
250 if ETH_TYPE in classifier_info and \
251 classifier_info[ETH_TYPE] == IPV4_ETH_TYPE and \
252 IP_PROTO in classifier_info and \
253 classifier_info[IP_PROTO] == 2:
254 self.log.debug('igmp flow add ignored, not implemented yet')
255 return
256
257 if IP_PROTO in classifier_info and \
258 classifier_info[IP_PROTO] == 17 and \
259 UDP_SRC in classifier_info and \
260 classifier_info[UDP_SRC] == 67:
261 self.log.debug('trap-dhcp-from-nni-flow')
262 self.add_dhcp_trap_nni(flow, classifier_info, port_no,
263 network_intf_id=0)
264 return
265
266 # Metadata 8 bytes:
267 # Most Significant 2 Bytes = Inner VLAN
268 # Next 2 Bytes = Tech Profile ID(TPID)
269 # Least Significant 4 Bytes = Port ID
270 # Flow METADATA carries Tech-Profile (TP) ID and is mandatory in all
271 # subscriber related flows.
272 # Note: If we are here, assert that the flow_metadata is not None
273 assert flow_metadata is not None
274
275 # Retrieve the TP-ID if one exists for the subscriber already
276 tp_id = self.resource_mgr.get_tech_profile_id_for_onu(intf_id, onu_id, uni_id)
277
278 if tp_id is not None:
279 # Assert that the tp_id received in flow metadata is same is the tp_id in use
280 # TODO:
281 # For now, tp_id updates, require that we tear down the service and
282 # and re-provision the service, i.e., dynamic TP updates not supported.
283
284 assert tp_id == fd.get_tp_id_from_metadata(flow_metadata), \
285 "tp-updates-not-supported"
286 else:
287 tp_id = fd.get_tp_id_from_metadata(flow_metadata)
288 self.log.info("received-tp-id-from-flow", tp_id=tp_id)
289
290 if self.platform.is_upstream(action_info[OUTPUT]):
291 us_meter_id = fd.get_meter_id_from_flow(flow)
292 else:
293 ds_meter_id = fd.get_meter_id_from_flow(flow)
294
Shad Ansari7a5d2172019-02-26 13:35:36 -0800295 self.divide_and_add_flow(intf_id, onu_id, uni_id, port_no,
Girish Gowdru841708f2019-02-08 04:29:48 -0800296 classifier_info, action_info, flow, tp_id, us_meter_id, ds_meter_id)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400297
Girish Gowdruab836e92018-10-25 01:17:57 -0700298 def _clear_flow_id_from_rm(self, flow, flow_id, flow_direction):
Shad Ansarif9b9b892019-02-27 17:10:27 -0800299 try:
300 pon_intf, onu_id, uni_id \
Shad Ansarie497ad42019-03-11 21:11:38 -0700301 = self.platform.flow_extract_info(flow, flow_direction)
Shad Ansarif9b9b892019-02-27 17:10:27 -0800302 except ValueError:
Girish Gowdru841708f2019-02-08 04:29:48 -0800303 self.log.error("failure extracting pon_intf, onu_id, uni_id info from flow")
Shad Ansarif9b9b892019-02-27 17:10:27 -0800304 else:
Girish Gowdru841708f2019-02-08 04:29:48 -0800305 flows = self.resource_mgr.get_flow_id_info(pon_intf, onu_id, uni_id, flow_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700306 assert (isinstance(flows, list))
307 self.log.debug("retrieved-flows", flows=flows)
308 for idx in range(len(flows)):
309 if flow_direction == flows[idx]['flow_type']:
310 flows.pop(idx)
Shad Ansari7a5d2172019-02-26 13:35:36 -0800311 self.update_flow_info_to_kv_store(pon_intf, onu_id,
312 uni_id, flow_id, flows)
Girish Gowdruab836e92018-10-25 01:17:57 -0700313 if len(flows) > 0:
314 # There are still flows referencing the same flow_id.
315 # So the flow should not be freed yet.
316 # For ex: Case of HSIA where same flow is shared
317 # between DS and US.
318 return
319
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800320 self.resource_mgr.free_flow_id(pon_intf, onu_id, uni_id, flow_id)
Girish Gowdru841708f2019-02-08 04:29:48 -0800321 flow_list = self.resource_mgr.get_current_flow_ids(pon_intf, onu_id, uni_id)
322 if flow_list is None:
323 tp_id = self.resource_mgr.get_tech_profile_id_for_onu(pon_intf, onu_id, uni_id)
324 tp_instance = self.get_tech_profile_instance(pon_intf, onu_id, uni_id, tp_id)
325 self.log.info("all-flows-cleared-for-onu")
326 self.log.info("initiate-sched-queue-teardown")
327 self.remove_us_scheduler_queues(pon_intf, onu_id, uni_id, tp_instance)
328 self.remove_ds_scheduler_queues(pon_intf, onu_id, uni_id, tp_instance)
Girish Gowdruab836e92018-10-25 01:17:57 -0700329
Scott Bakerbe5a9ea2018-11-19 19:24:21 -0800330 def retry_add_flow(self, flow):
331 self.log.debug("retry-add-flow")
332 if flow.id in self.retry_add_flow_list:
333 self.retry_add_flow_list.remove(flow.id)
334 self.add_flow(flow)
335
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400336 def remove_flow(self, flow):
337 self.log.debug('trying to remove flows from logical flow :',
Jonathan Hart5b435642018-08-20 08:50:05 -0700338 logical_flow=flow)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400339 device_flows_to_remove = []
340 device_flows = self.flows_proxy.get('/').items
341 for f in device_flows:
342 if f.cookie == flow.id:
343 device_flows_to_remove.append(f)
344
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400345 for f in device_flows_to_remove:
346 (id, direction) = self.decode_stored_id(f.id)
347 flow_to_remove = openolt_pb2.Flow(flow_id=id, flow_type=direction)
Nicolas Palpacuer3d0878d2018-08-17 11:29:42 -0400348 try:
349 self.stub.FlowRemove(flow_to_remove)
350 except grpc.RpcError as grpc_e:
351 if grpc_e.code() == grpc.StatusCode.NOT_FOUND:
352 self.log.debug('This flow does not exist on the switch, '
Jonathan Hart5b435642018-08-20 08:50:05 -0700353 'normal after an OLT reboot',
354 flow=flow_to_remove)
Nicolas Palpacuer3d0878d2018-08-17 11:29:42 -0400355 else:
356 raise grpc_e
357
Girish Gowdruab836e92018-10-25 01:17:57 -0700358 # once we have successfully deleted the flow on the device
359 # release the flow_id on resource pool and also clear any
360 # data associated with the flow_id on KV store.
361 self._clear_flow_id_from_rm(f, id, direction)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400362 self.log.debug('flow removed from device', flow=f,
363 flow_key=flow_to_remove)
364
365 if len(device_flows_to_remove) > 0:
366 new_flows = []
367 flows_ids_to_remove = [f.id for f in device_flows_to_remove]
368 for f in device_flows:
369 if f.id not in flows_ids_to_remove:
370 new_flows.append(f)
371
372 self.flows_proxy.update('/', Flows(items=new_flows))
373 self.log.debug('flows removed from the data store',
374 flow_ids_removed=flows_ids_to_remove,
375 number_of_flows_removed=(len(device_flows) - len(
376 new_flows)), expected_flows_removed=len(
Girish Gowdru841708f2019-02-08 04:29:48 -0800377 device_flows_to_remove))
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400378 else:
379 self.log.debug('no device flow to remove for this flow (normal '
380 'for multi table flows)', flow=flow)
381
Thiyagarajan Subramani353af122019-02-20 23:14:24 -0800382 def get_tp_path(self, intf_id, ofp_port_name, techprofile_id):
Girish Gowdrub761bc12018-11-29 02:22:18 -0800383 return self.tech_profile[intf_id]. \
Thiyagarajan Subramani353af122019-02-20 23:14:24 -0800384 get_tp_path(techprofile_id,
Girish Gowdrub761bc12018-11-29 02:22:18 -0800385 ofp_port_name)
386
Shad Ansari7a5d2172019-02-26 13:35:36 -0800387 def delete_tech_profile_instance(self, intf_id, onu_id, uni_id,
Girish Gowdru841708f2019-02-08 04:29:48 -0800388 ofp_port_name=None):
Girish Gowdrub761bc12018-11-29 02:22:18 -0800389 # Remove the TP instance associated with the ONU
Thiyagarajan Subramani353af122019-02-20 23:14:24 -0800390 if ofp_port_name is None:
Shad Ansarie497ad42019-03-11 21:11:38 -0700391 ofp_port_name = self.data_model.serial_number(intf_id, onu_id)
392
Shad Ansari7a5d2172019-02-26 13:35:36 -0800393 tp_id = self.resource_mgr.get_tech_profile_id_for_onu(intf_id, onu_id,
394 uni_id)
Thiyagarajan Subramani353af122019-02-20 23:14:24 -0800395 tp_path = self.get_tp_path(intf_id, ofp_port_name, tp_id)
Shad Ansari7a5d2172019-02-26 13:35:36 -0800396 self.log.debug(" tp-path-in-delete", tp_path=tp_path)
Girish Gowdrub761bc12018-11-29 02:22:18 -0800397 return self.tech_profile[intf_id].delete_tech_profile_instance(tp_path)
398
Craig Lutgenabd9c842018-11-15 23:58:27 +0000399 def divide_and_add_flow(self, intf_id, onu_id, uni_id, port_no, classifier,
Girish Gowdru841708f2019-02-08 04:29:48 -0800400 action, flow, tp_id, us_meter_id, ds_meter_id):
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400401
Shad Ansari7a5d2172019-02-26 13:35:36 -0800402 self.log.debug('sorting flow', intf_id=intf_id, onu_id=onu_id,
Girish Gowdru841708f2019-02-08 04:29:48 -0800403 uni_id=uni_id, port_no=port_no,
404 classifier=classifier, action=action,
405 tp_id=tp_id, us_meter=us_meter_id,
406 ds_meter=ds_meter_id)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400407
Girish Gowdru841708f2019-02-08 04:29:48 -0800408 tp_instance = self.get_tech_profile_instance(intf_id, onu_id, uni_id, tp_id)
409 if tp_instance is None:
410 self.log.error("flow-not-added--tp-instance-unavailable")
Girish Gowdruab836e92018-10-25 01:17:57 -0700411 return
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400412
Girish Gowdru841708f2019-02-08 04:29:48 -0800413 pon_intf_onu_id = (intf_id, onu_id, uni_id)
414 alloc_id = \
415 self.resource_mgr.get_current_alloc_ids_for_onu(pon_intf_onu_id)
416 gem_ports = \
417 self.resource_mgr.get_current_gemport_ids_for_onu(pon_intf_onu_id)
418
419 if alloc_id is None or gem_ports is None:
420 self.log.error("alloc-id-or-gem-ports-unavailable",
421 alloc_id=alloc_id, gem_ports=gem_ports)
422 return
423
424 self.create_us_scheduler_queues(intf_id, onu_id, uni_id, tp_instance, us_meter_id)
425 self.create_ds_scheduler_queues(intf_id, onu_id, uni_id, tp_instance, ds_meter_id)
426
Girish Gowdruab836e92018-10-25 01:17:57 -0700427 self.log.debug('Generated required alloc and gemport ids',
428 alloc_id=alloc_id, gemports=gem_ports)
429
Girish Gowdru841708f2019-02-08 04:29:48 -0800430 ds_gem_port_attr_list = tp_instance.downstream_gem_port_attribute_list
431 us_gem_port_attr_list = tp_instance.upstream_gem_port_attribute_list
432 kwargs = dict()
433 kwargs['intf_id'] = intf_id
434 kwargs['onu_id'] = onu_id
435 kwargs['uni_id'] = uni_id
436 kwargs['port_no'] = port_no
437 kwargs['classifier'] = classifier
438 kwargs['action'] = action
439 kwargs['logical_flow'] = flow
440 kwargs['alloc_id'] = alloc_id
441
442 if IP_PROTO in classifier:
443 if classifier[IP_PROTO] == 17:
444 self.log.debug('dhcp flow add')
445 if VLAN_PCP in classifier:
446 gemport_id = self._get_gem_port_for_pcp(
447 classifier[VLAN_PCP], us_gem_port_attr_list
448 )
449 self.add_dhcp_trap_uni(intf_id, onu_id, uni_id, port_no,
450 classifier, action, flow, alloc_id,
451 gemport_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700452 else:
Girish Gowdru841708f2019-02-08 04:29:48 -0800453 self._install_flow_on_all_gemports(self.add_dhcp_trap_uni,
454 kwargs,
455 us_gem_port_attr_list)
Girish Gowdruab836e92018-10-25 01:17:57 -0700456
Girish Gowdru841708f2019-02-08 04:29:48 -0800457 elif classifier[IP_PROTO] == 2:
458 self.log.warn('igmp flow add ignored, not implemented yet')
Girish Gowdruab836e92018-10-25 01:17:57 -0700459 else:
Girish Gowdru841708f2019-02-08 04:29:48 -0800460 self.log.warn("Invalid-Classifier-to-handle",
461 classifier=classifier,
462 action=action)
463 elif ETH_TYPE in classifier:
464 if classifier[ETH_TYPE] == EAP_ETH_TYPE:
465 self.log.debug('eapol flow add')
466 vlan_id = classifier[VLAN_VID]
Girish Gowdruab836e92018-10-25 01:17:57 -0700467
Girish Gowdru841708f2019-02-08 04:29:48 -0800468 if vlan_id is None:
469 vlan_id = DEFAULT_MGMT_VLAN
Girish Gowdrub761bc12018-11-29 02:22:18 -0800470
Girish Gowdru841708f2019-02-08 04:29:48 -0800471 if VLAN_PCP in classifier:
472 gemport_id = self._get_gem_port_for_pcp(
473 classifier[VLAN_PCP], us_gem_port_attr_list
474 )
475 self.add_eapol_flow(
476 intf_id, onu_id, uni_id, port_no, flow, alloc_id, gemport_id,
477 vlan_id=vlan_id)
478 else:
479 kwargs['vlan_id'] = vlan_id
480 self._install_flow_on_all_gemports(self.add_eapol_flow,
481 kwargs,
482 us_gem_port_attr_list)
Girish Gowdrub761bc12018-11-29 02:22:18 -0800483
Girish Gowdru841708f2019-02-08 04:29:48 -0800484 (ofp_port_name, ofp_port_no) = \
485 self.data_model.get_ofp_port_name(intf_id, onu_id, uni_id)
486 if ofp_port_name is None:
487 self.log.error("port-name-not-found")
488 return
489
490 tp_id = self.resource_mgr.get_tech_profile_id_for_onu(intf_id, onu_id, uni_id)
491 tp_path = self.get_tp_path(intf_id, ofp_port_name, tp_id)
492
493 self.log.debug('Load-tech-profile-request-to-brcm-handler',
494 tp_path=tp_path)
495 self.data_model.onu_download_tech_profile(
496 intf_id, onu_id, uni_id, tp_path)
497 elif PUSH_VLAN in action:
498 if VLAN_PCP in classifier:
499 gemport_id = self._get_gem_port_for_pcp(
500 classifier[VLAN_PCP], us_gem_port_attr_list
501 )
502 self.add_upstream_data_flow(intf_id, onu_id, uni_id, port_no, classifier,
503 action, flow, alloc_id, gemport_id)
504 else:
505 self._install_flow_on_all_gemports(self.add_upstream_data_flow,
506 kwargs, us_gem_port_attr_list
507 )
508 elif POP_VLAN in action:
509 if VLAN_PCP in classifier:
510 gemport_id = self._get_gem_port_for_pcp(
Girish Gowdru80f8e402019-05-07 00:22:59 -0700511 classifier[VLAN_PCP], ds_gem_port_attr_list
Girish Gowdru841708f2019-02-08 04:29:48 -0800512 )
513 self.add_downstream_data_flow(intf_id, onu_id, uni_id, port_no, classifier,
514 action, flow, alloc_id, gemport_id)
515 else:
516 self._install_flow_on_all_gemports(self.add_downstream_data_flow,
517 kwargs, ds_gem_port_attr_list
518 )
519 else:
520 self.log.debug('Invalid-flow-type-to-handle',
521 classifier=classifier,
522 action=action, flow=flow)
523
524 def get_scheduler(self, tech_profile_instance, direction, meter_id):
525 if direction == Direction.UPSTREAM:
526 scheduler = tech_profile_instance.us_scheduler
527 elif direction == Direction.DOWNSTREAM:
528 scheduler = tech_profile_instance.ds_scheduler
529 else:
530 raise Exception("invalid-direction")
531
532 meter_band = self.data_model.meter_band(meter_id)
533
534 traffic_shaping_info = None
535
536 if meter_band is not None:
537 cir = meter_band.bands[0].rate
538 cbs = meter_band.bands[0].burst_size
539 eir = meter_band.bands[1].rate
540 ebs = meter_band.bands[1].burst_size
541 pir = cir + eir
542 pbs = cbs + ebs
543
544 traffic_shaping_info = tech_profile_pb2.TrafficShapingInfo(
545 cir=cir,
546 cbs=cbs,
547 pir=pir,
548 pbs=pbs
549 )
550
551 scheduler_config = tech_profile_pb2.SchedulerConfig(
552 direction=TechProfile.get_parameter(
553 'direction', scheduler.direction),
554 additional_bw=TechProfile.get_parameter(
555 'additional_bw', scheduler.additional_bw),
556 priority=scheduler.priority,
557 weight=scheduler.weight,
558 sched_policy=TechProfile.get_parameter(
559 'q_sched_policy', scheduler.q_sched_policy)
560 )
561
562 traffic_scheduler = tech_profile_pb2.TrafficScheduler(
563 direction=scheduler.direction,
564 scheduler=scheduler_config,
565 alloc_id=scheduler.alloc_id,
566 traffic_shaping_info=traffic_shaping_info
567 )
568
569 return traffic_scheduler
570
571 @staticmethod
572 def get_traffic_queues(tech_profile_instance, direction):
573 if direction == Direction.UPSTREAM:
574 gemport_attribute_list = tech_profile_instance. \
575 upstream_gem_port_attribute_list
576 tp_scheduler_direction = tech_profile_instance.us_scheduler.direction
577 elif direction == Direction.DOWNSTREAM:
578 gemport_attribute_list = tech_profile_instance. \
579 downstream_gem_port_attribute_list
580 tp_scheduler_direction = tech_profile_instance.ds_scheduler.direction
581 else:
582 raise Exception("invalid-direction")
583 traffic_queues = list()
584 for i in range(len(gemport_attribute_list)):
585 traffic_queues.append(tech_profile_pb2.TrafficQueue(
586 direction=TechProfile.get_parameter('direction',
587 tp_scheduler_direction),
588 gemport_id=gemport_attribute_list[i].gemport_id,
589 pbit_map=gemport_attribute_list[i].pbit_map,
590 aes_encryption=ast.literal_eval(gemport_attribute_list[i].
591 aes_encryption),
592 sched_policy=TechProfile.get_parameter(
593 'sched_policy', gemport_attribute_list[i].
594 scheduling_policy),
595 priority=gemport_attribute_list[i].priority_q,
596 weight=gemport_attribute_list[i].weight,
597 discard_policy=TechProfile.get_parameter(
598 'discard_policy', gemport_attribute_list[i].
599 discard_policy)))
600
601 return traffic_queues
602
603 def create_us_scheduler_queues(self, intf_id, onu_id, uni_id, tp_instance, us_meter_id):
604 if us_meter_id is None:
605 self.log.debug("us-meter-unavailable--no-action")
606 return
607
608 kv_store_meter_id = self.resource_mgr.get_meter_id_for_onu(UPSTREAM,
609 intf_id,
610 onu_id, uni_id)
611
612 # Lets make a simple assumption that if the meter-id is present on the KV store,
613 # then the scheduler and queues configuration is applied on the OLT device
614 # in the given direction.
615 if kv_store_meter_id is not None:
616 # TODO: Dynamic meter update not supported for now
617 # TODO: The subscriber has to be un-provisioned and re-provisioned for meter update
618 assert kv_store_meter_id == us_meter_id
619 self.log.debug("scheduler-already-created-in-us")
620 return
621
622 traffic_sched = self.get_scheduler(tp_instance, Direction.UPSTREAM, us_meter_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700623 try:
Shad Ansarie497ad42019-03-11 21:11:38 -0700624 ofp_port_no = self.platform.mk_uni_port_num(intf_id,
625 onu_id, uni_id)
626
Girish Gowdru841708f2019-02-08 04:29:48 -0800627 self.stub.CreateTrafficSchedulers(
628 tech_profile_pb2.TrafficSchedulers(
629 intf_id=intf_id,
630 onu_id=onu_id,
631 uni_id=uni_id,
632 port_no=ofp_port_no,
633 traffic_scheds=[traffic_sched]
634 ))
635 except grpc.RpcError as grpc_e:
636 if grpc_e.code() == grpc.StatusCode.ALREADY_EXISTS:
637 self.log.warn("us-scheduler-already-exists")
Girish Gowdruab836e92018-10-25 01:17:57 -0700638 else:
Girish Gowdru841708f2019-02-08 04:29:48 -0800639 self.log.error("failure-to-create-us-scheduler")
640 return
Girish Gowdruab836e92018-10-25 01:17:57 -0700641
Girish Gowdru841708f2019-02-08 04:29:48 -0800642 # On receiving the CreateTrafficQueues request, the driver should create corresponding
643 # downstream queues.
644 try:
645 self.stub.CreateTrafficQueues(
646 tech_profile_pb2.TrafficQueues(
647 intf_id=intf_id,
648 onu_id=onu_id,
649 uni_id=uni_id,
650 port_no=ofp_port_no,
651 traffic_queues=
652 OpenOltFlowMgr.get_traffic_queues(tp_instance, Direction.UPSTREAM)
653 ))
654 except grpc.RpcError as grpc_e:
655 if grpc_e.code() == grpc.StatusCode.ALREADY_EXISTS:
656 self.log.warn("ds-queues-already-exists")
657 else:
658 self.log.error("failure-to-create-ds-queues")
659 return
Girish Gowdrub761bc12018-11-29 02:22:18 -0800660
Girish Gowdru841708f2019-02-08 04:29:48 -0800661 # After we succesfully applied the scheduler configuration on the OLT device,
662 # store the meter id on the KV store, for further reference
663 self.resource_mgr.update_meter_id_for_onu(UPSTREAM, intf_id, onu_id, uni_id, us_meter_id)
664
665 def create_ds_scheduler_queues(self, intf_id, onu_id, uni_id, tp_instance, ds_meter_id):
666 if ds_meter_id is None:
667 self.log.debug("ds-meter-unavailable--no-action")
668 return
669
670 kv_store_meter_id = self.resource_mgr.get_meter_id_for_onu(DOWNSTREAM,
671 intf_id,
672 onu_id, uni_id)
673 # Lets make a simple assumption that if the meter-id is present on the KV store,
674 # then the scheduler and queues configuration is applied on the OLT device
675 if kv_store_meter_id is not None:
676 # TODO: Dynamic meter update not supported for now
677 # TODO: The subscriber has to be un-provisioned and re-provisioned for meter update
678 assert kv_store_meter_id == ds_meter_id
679 self.log.debug("scheduler-already-created-in-ds")
680 return
681
682 traffic_sched = self.get_scheduler(tp_instance, Direction.DOWNSTREAM, ds_meter_id)
683 _, ofp_port_no = self.data_model.get_ofp_port_name(intf_id, onu_id, uni_id)
684 try:
685 self.stub.CreateTrafficSchedulers(
686 tech_profile_pb2.TrafficSchedulers(
687 intf_id=intf_id,
688 onu_id=onu_id,
689 uni_id=uni_id,
690 port_no=ofp_port_no,
691 traffic_scheds=[traffic_sched]
692 ))
693 except grpc.RpcError as grpc_e:
694 if grpc_e.code() == grpc.StatusCode.ALREADY_EXISTS:
695 self.log.warn("ds-scheduler-already-exists")
696 else:
697 self.log.error("failure-to-create-ds-scheduler")
698 return
699
700 # On receiving the CreateTrafficQueues request, the driver should create corresponding
701 # downstream queues.
702 try:
703 self.stub.CreateTrafficQueues(
704 tech_profile_pb2.TrafficQueues(
705 intf_id=intf_id,
706 onu_id=onu_id,
707 uni_id=uni_id,
708 port_no=ofp_port_no,
709 traffic_queues=
710 OpenOltFlowMgr.get_traffic_queues(tp_instance, Direction.DOWNSTREAM)
711 ))
712 except grpc.RpcError as grpc_e:
713 if grpc_e.code() == grpc.StatusCode.ALREADY_EXISTS:
714 self.log.warn("ds-queues-already-exists")
715 else:
716 self.log.error("failure-to-create-ds-queues")
717 return
718
719 # After we successfully applied the scheduler configuration on the OLT device,
720 # store the meter id on the KV store, for further reference
721 self.resource_mgr.update_meter_id_for_onu(DOWNSTREAM, intf_id, onu_id, uni_id, ds_meter_id)
722
723 def remove_us_scheduler_queues(self, intf_id, onu_id, uni_id, tp_instance):
724 us_meter_id = self.resource_mgr.get_meter_id_for_onu(UPSTREAM,
725 intf_id,
726 onu_id, uni_id)
727 traffic_sched = self.get_scheduler(tp_instance, Direction.UPSTREAM, us_meter_id)
728 _, ofp_port_no = self.data_model.get_ofp_port_name(intf_id, onu_id, uni_id)
729
730 try:
731 self.stub.RemoveTrafficQueues(
732 tech_profile_pb2.TrafficQueues(
733 intf_id=intf_id,
734 onu_id=onu_id,
735 uni_id=uni_id,
736 port_no=ofp_port_no,
737 traffic_queues=
738 OpenOltFlowMgr.get_traffic_queues(tp_instance, Direction.UPSTREAM)
739 ))
740 self.log.debug("removed-upstream-Queues")
741 except grpc.RpcError as e:
742 self.log.error("failure-to-remove-us-queues", e=e)
743
744 try:
745 self.stub.RemoveTrafficSchedulers(
746 tech_profile_pb2.TrafficSchedulers(
747 intf_id=intf_id,
748 onu_id=onu_id,
749 uni_id=uni_id,
750 port_no=ofp_port_no,
751 traffic_scheds=[traffic_sched]
752 ))
753 self.log.debug("removed-upstream-Schedulers")
754 except grpc.RpcError as e:
755 self.log.error("failure-to-remove-us-scheduler", e=e)
756
757 self.resource_mgr.remove_meter_id_for_onu(UPSTREAM, intf_id, onu_id, uni_id)
758
759 def remove_ds_scheduler_queues(self, intf_id, onu_id, uni_id, tp_instance):
760 ds_meter_id = self.resource_mgr.get_meter_id_for_onu(DOWNSTREAM,
761 intf_id,
762 onu_id, uni_id)
763
764 traffic_sched = self.get_scheduler(tp_instance, Direction.DOWNSTREAM, ds_meter_id)
765 _, ofp_port_no = self.data_model.get_ofp_port_name(intf_id, onu_id, uni_id)
766
767 try:
768 self.stub.RemoveTrafficQueues(
769 tech_profile_pb2.TrafficQueues(
770 intf_id=intf_id,
771 onu_id=onu_id,
772 uni_id=uni_id,
773 port_no=ofp_port_no,
774 traffic_queues=
775 OpenOltFlowMgr.get_traffic_queues(tp_instance, Direction.DOWNSTREAM)
776 ))
777 self.log.debug("removed-downstream-Queues")
778 except grpc.RpcError as grpc_e:
779 self.log.error("failure-to-remove-ds-queues")
780
781 try:
782 self.stub.RemoveTrafficSchedulers(
783 tech_profile_pb2.TrafficSchedulers(
784 intf_id=intf_id,
785 onu_id=onu_id,
786 uni_id=uni_id,
787 port_no=ofp_port_no,
788 traffic_scheds=[traffic_sched]
789 ))
790 self.log.debug("removed-downstream-Schedulers")
791 except grpc.RpcError as grpc_e:
792 self.log.error("failure-to-remove-ds-scheduler")
793
794 self.resource_mgr.remove_meter_id_for_onu(DOWNSTREAM, intf_id, onu_id, uni_id)
795
796 def get_tech_profile_instance(self, intf_id, onu_id, uni_id, tp_id):
797 (ofp_port_name, ofp_port_no) \
798 = self.data_model.get_ofp_port_name(intf_id, onu_id, uni_id)
799 if ofp_port_name is None:
800 self.log.error("port-name-not-found")
801 return None
802
803 # Check tech profile instance already exists for derived port name
804 tech_profile_instance = self.tech_profile[intf_id]. \
805 get_tech_profile_instance(tp_id, ofp_port_name)
806
807 if tech_profile_instance is None:
808 # create tech profile instance
809 tech_profile_instance = self.tech_profile[intf_id]. \
810 create_tech_profile_instance(tp_id, ofp_port_name,
811 intf_id)
812 if tech_profile_instance is None:
813 raise Exception('Tech-profile-instance-creation-failed')
814
815 self.resource_mgr.update_tech_profile_id_for_onu(intf_id, onu_id,
816 uni_id, tp_id)
Girish Gowdrub761bc12018-11-29 02:22:18 -0800817
Girish Gowdruab836e92018-10-25 01:17:57 -0700818 # Fetch alloc id and gemports from tech profile instance
819 alloc_id = tech_profile_instance.us_scheduler.alloc_id
820 gem_port_ids = []
Girish Gowdru841708f2019-02-08 04:29:48 -0800821
Girish Gowdruab836e92018-10-25 01:17:57 -0700822 for i in range(len(
823 tech_profile_instance.upstream_gem_port_attribute_list)):
824 gem_port_ids.append(
825 tech_profile_instance.upstream_gem_port_attribute_list[i].
Girish Gowdru841708f2019-02-08 04:29:48 -0800826 gemport_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700827
Girish Gowdru841708f2019-02-08 04:29:48 -0800828 # Update the allocated alloc_id and gem_port_id for the ONU/UNI to KV
829 # store
830 pon_intf_onu_id = (intf_id, onu_id, uni_id)
831 self.resource_mgr.resource_mgrs[intf_id].update_alloc_ids_for_onu(
832 pon_intf_onu_id,
833 list([alloc_id])
834 )
835 self.resource_mgr.resource_mgrs[intf_id].update_gemport_ids_for_onu(
836 pon_intf_onu_id,
837 gem_port_ids
838 )
Girish Gowdruab836e92018-10-25 01:17:57 -0700839
Girish Gowdru841708f2019-02-08 04:29:48 -0800840 self.resource_mgr.update_gemports_ponport_to_onu_map_on_kv_store(
841 gem_port_ids, intf_id, onu_id, uni_id
842 )
Girish Gowdruab836e92018-10-25 01:17:57 -0700843
Girish Gowdru841708f2019-02-08 04:29:48 -0800844 for gemport_id in gem_port_ids:
845 self.data_model.gemport_id_add(intf_id, onu_id, gemport_id)
846 else:
847 self.log.debug(
848 'Tech-profile-instance-already-exist-for-given port-name',
849 ofp_port_name=ofp_port_name)
Shad Ansari4f9a9732019-03-08 16:47:08 -0800850
Girish Gowdru841708f2019-02-08 04:29:48 -0800851 return tech_profile_instance
852
853 def get_alloc_id_gem_port(self, intf_id, onu_id):
854 pon_intf_onu_id = (intf_id, onu_id)
855 # If we already have allocated alloc_id and gem_ports earlier, render them
856 alloc_id = \
857 self.resource_mgr.get_current_alloc_ids_for_onu(pon_intf_onu_id)
858 gem_port_ids = \
859 self.resource_mgr.get_current_gemport_ids_for_onu(pon_intf_onu_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700860 return alloc_id, gem_port_ids
Shad Ansari2dda4f32018-05-17 07:16:07 +0000861
Girish Gowdru841708f2019-02-08 04:29:48 -0800862 def add_upstream_data_flow(self, intf_id, onu_id, uni_id, port_no, classifier,
863 action, logical_flow, alloc_id, gemport_id):
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400864
Girish Gowdru841708f2019-02-08 04:29:48 -0800865 classifier[PACKET_TAG_TYPE] = SINGLE_TAG
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400866
Girish Gowdru841708f2019-02-08 04:29:48 -0800867 self.add_hsia_flow(intf_id, onu_id, uni_id, port_no, classifier,
868 action, UPSTREAM,
Girish Gowdruab836e92018-10-25 01:17:57 -0700869 logical_flow, alloc_id, gemport_id)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000870
Girish Gowdru841708f2019-02-08 04:29:48 -0800871 def add_downstream_data_flow(self, intf_id, onu_id, uni_id, port_no, classifier,
872 action, logical_flow, alloc_id, gemport_id):
873 classifier[PACKET_TAG_TYPE] = DOUBLE_TAG
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400874 # Needed ???? It should be already there
Girish Gowdru841708f2019-02-08 04:29:48 -0800875 action[POP_VLAN] = True
876 action[VLAN_VID] = classifier[VLAN_VID]
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400877
Girish Gowdru841708f2019-02-08 04:29:48 -0800878 self.add_hsia_flow(intf_id, onu_id, uni_id, port_no, classifier,
879 action, DOWNSTREAM,
880 logical_flow, alloc_id, gemport_id)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400881
Shad Ansari7a5d2172019-02-26 13:35:36 -0800882 def add_hsia_flow(self, intf_id, onu_id, uni_id, port_no, classifier,
883 action, direction, logical_flow, alloc_id, gemport_id):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000884
Girish Gowdrub761bc12018-11-29 02:22:18 -0800885 flow_store_cookie = self._get_flow_store_cookie(classifier,
886 gemport_id)
887
Shad Ansari7a5d2172019-02-26 13:35:36 -0800888 if self.resource_mgr.is_flow_cookie_on_kv_store(intf_id, onu_id,
889 uni_id,
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800890 flow_store_cookie):
891 self.log.debug('flow-exists--not-re-adding')
892 else:
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800893 # One of the OLT platform (Broadcom BAL) requires that symmetric
894 # flows require the same flow_id to be used across UL and DL.
895 # Since HSIA flow is the only symmetric flow currently, we need to
896 # re-use the flow_id across both direction. The 'flow_category'
897 # takes priority over flow_cookie to find any available HSIA_FLOW
898 # id for the ONU.
Girish Gowdru841708f2019-02-08 04:29:48 -0800899
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800900 flow_id = self.resource_mgr.get_flow_id(intf_id, onu_id, uni_id,
Girish Gowdru841708f2019-02-08 04:29:48 -0800901 flow_category=HSIA_FLOW,
902 flow_pcp=classifier[VLAN_PCP])
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800903 if flow_id is None:
904 self.log.error("hsia-flow-unavailable")
905 return
906
907 flow = openolt_pb2.Flow(
Shad Ansari7a5d2172019-02-26 13:35:36 -0800908 access_intf_id=intf_id, onu_id=onu_id, uni_id=uni_id,
909 flow_id=flow_id, flow_type=direction, alloc_id=alloc_id,
Shad Ansarif9b9b892019-02-27 17:10:27 -0800910 network_intf_id=self.data_model.olt_nni_intf_id(),
911 gemport_id=gemport_id,
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800912 classifier=self.mk_classifier(classifier),
Shad Ansari7a5d2172019-02-26 13:35:36 -0800913 action=self.mk_action(action), priority=logical_flow.priority,
914 port_no=port_no, cookie=logical_flow.cookie)
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800915
916 if self.add_flow_to_device(flow, logical_flow):
917 flow_info = self._get_flow_info_as_json_blob(flow,
918 flow_store_cookie,
919 HSIA_FLOW)
920 self.update_flow_info_to_kv_store(flow.access_intf_id,
921 flow.onu_id, flow.uni_id,
922 flow.flow_id, flow_info)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000923
Girish Gowdru841708f2019-02-08 04:29:48 -0800924 def add_dhcp_trap_uni(self, intf_id, onu_id, uni_id, port_no, classifier,
925 action, logical_flow, alloc_id, gemport_id):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000926
Shad Ansari47e0c392018-07-17 23:55:07 +0000927 self.log.debug('add dhcp upstream trap', classifier=classifier,
Shad Ansari7a5d2172019-02-26 13:35:36 -0800928 intf_id=intf_id, onu_id=onu_id, uni_id=uni_id,
929 action=action)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000930
931 action.clear()
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400932 action[TRAP_TO_HOST] = True
Girish Gowdruab836e92018-10-25 01:17:57 -0700933 classifier[UDP_SRC] = 68
934 classifier[UDP_DST] = 67
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400935 classifier[PACKET_TAG_TYPE] = SINGLE_TAG
936 classifier.pop(VLAN_VID, None)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000937
Girish Gowdrub761bc12018-11-29 02:22:18 -0800938 flow_store_cookie = self._get_flow_store_cookie(classifier,
939 gemport_id)
Girish Gowdru841708f2019-02-08 04:29:48 -0800940
Shad Ansari7a5d2172019-02-26 13:35:36 -0800941 if self.resource_mgr.is_flow_cookie_on_kv_store(intf_id, onu_id,
942 uni_id,
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800943 flow_store_cookie):
944 self.log.debug('flow-exists--not-re-adding')
945 else:
946 flow_id = self.resource_mgr.get_flow_id(
Girish Gowdru841708f2019-02-08 04:29:48 -0800947 intf_id, onu_id, uni_id,
948 flow_store_cookie=flow_store_cookie,
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800949 )
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800950 dhcp_flow = openolt_pb2.Flow(
Shad Ansari7a5d2172019-02-26 13:35:36 -0800951 onu_id=onu_id, uni_id=uni_id, flow_id=flow_id,
952 flow_type=UPSTREAM, access_intf_id=intf_id,
953 gemport_id=gemport_id, alloc_id=alloc_id,
Shad Ansarif9b9b892019-02-27 17:10:27 -0800954 network_intf_id=self.data_model.olt_nni_intf_id(),
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800955 priority=logical_flow.priority,
956 classifier=self.mk_classifier(classifier),
957 action=self.mk_action(action),
958 port_no=port_no,
959 cookie=logical_flow.cookie)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000960
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800961 if self.add_flow_to_device(dhcp_flow, logical_flow):
Shad Ansari7a5d2172019-02-26 13:35:36 -0800962 flow_info = self._get_flow_info_as_json_blob(dhcp_flow,
963 flow_store_cookie)
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800964 self.update_flow_info_to_kv_store(dhcp_flow.access_intf_id,
965 dhcp_flow.onu_id,
966 dhcp_flow.uni_id,
967 dhcp_flow.flow_id,
968 flow_info)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400969
Shad Ansari7a5d2172019-02-26 13:35:36 -0800970 def add_eapol_flow(self, intf_id, onu_id, uni_id, port_no, logical_flow,
Girish Gowdru841708f2019-02-08 04:29:48 -0800971 alloc_id, gemport_id, vlan_id=DEFAULT_MGMT_VLAN, classifier=None, action=None):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000972
Girish Gowdruab836e92018-10-25 01:17:57 -0700973 uplink_classifier = dict()
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400974 uplink_classifier[ETH_TYPE] = EAP_ETH_TYPE
975 uplink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG
976 uplink_classifier[VLAN_VID] = vlan_id
Girish Gowdru841708f2019-02-08 04:29:48 -0800977 if classifier is not None:
978 uplink_classifier[VLAN_PCP] = classifier[VLAN_PCP]
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400979
Girish Gowdruab836e92018-10-25 01:17:57 -0700980 uplink_action = dict()
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400981 uplink_action[TRAP_TO_HOST] = True
Shad Ansari2dda4f32018-05-17 07:16:07 +0000982
Girish Gowdrub761bc12018-11-29 02:22:18 -0800983 flow_store_cookie = self._get_flow_store_cookie(uplink_classifier,
984 gemport_id)
Shad Ansari7a5d2172019-02-26 13:35:36 -0800985 if self.resource_mgr.is_flow_cookie_on_kv_store(intf_id, onu_id,
986 uni_id,
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800987 flow_store_cookie):
988 self.log.debug('flow-exists--not-re-adding')
989 else:
990 # Add Upstream EAPOL Flow.
991 uplink_flow_id = self.resource_mgr.get_flow_id(
Girish Gowdru841708f2019-02-08 04:29:48 -0800992 intf_id, onu_id, uni_id,
993 flow_store_cookie=flow_store_cookie
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800994 )
Shad Ansari2dda4f32018-05-17 07:16:07 +0000995
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800996 upstream_flow = openolt_pb2.Flow(
Shad Ansari7a5d2172019-02-26 13:35:36 -0800997 access_intf_id=intf_id, onu_id=onu_id, uni_id=uni_id,
998 flow_id=uplink_flow_id, flow_type=UPSTREAM, alloc_id=alloc_id,
Shad Ansarif9b9b892019-02-27 17:10:27 -0800999 network_intf_id=self.data_model.olt_nni_intf_id(),
1000 gemport_id=gemport_id,
Girish Gowdru50f62fb2019-02-04 22:16:15 -08001001 classifier=self.mk_classifier(uplink_classifier),
1002 action=self.mk_action(uplink_action),
1003 priority=logical_flow.priority,
1004 port_no=port_no,
1005 cookie=logical_flow.cookie)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001006
Girish Gowdru50f62fb2019-02-04 22:16:15 -08001007 logical_flow = copy.deepcopy(logical_flow)
1008 logical_flow.match.oxm_fields.extend(fd.mk_oxm_fields([fd.vlan_vid(
1009 vlan_id | 0x1000)]))
1010 logical_flow.match.type = OFPMT_OXM
1011
1012 if self.add_flow_to_device(upstream_flow, logical_flow):
1013 flow_info = self._get_flow_info_as_json_blob(upstream_flow,
1014 flow_store_cookie)
1015 self.update_flow_info_to_kv_store(upstream_flow.access_intf_id,
1016 upstream_flow.onu_id,
1017 upstream_flow.uni_id,
1018 upstream_flow.flow_id,
1019 flow_info)
Shad Ansari2dda4f32018-05-17 07:16:07 +00001020
Girish Gowdru841708f2019-02-08 04:29:48 -08001021 # Add Downstream EAPOL Flow, Only for first EAP flow (BAL
1022 # requirement)
1023 # On one of the platforms (Broadcom BAL), when same DL classifier
1024 # vlan was used across multiple ONUs, eapol flow re-adds after
1025 # flow delete (cases of onu reboot/disable) fails.
1026 # In order to generate unique vlan, a combination of intf_id
1027 # onu_id and uni_id is used.
1028 # uni_id defaults to 0, so add 1 to it.
1029 special_vlan_downstream_flow = 4090 - intf_id * onu_id * (uni_id + 1)
1030 # Assert that we do not generate invalid vlans under no condition
1031 assert special_vlan_downstream_flow >= 2
Shad Ansari2dda4f32018-05-17 07:16:07 +00001032
Girish Gowdru841708f2019-02-08 04:29:48 -08001033 downlink_classifier = dict()
1034 downlink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG
1035 downlink_classifier[ETH_TYPE] = EAP_ETH_TYPE
1036 downlink_classifier[VLAN_VID] = special_vlan_downstream_flow
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001037
Girish Gowdru841708f2019-02-08 04:29:48 -08001038 downlink_action = dict()
1039 downlink_action[PUSH_VLAN] = True
1040 downlink_action[VLAN_VID] = vlan_id
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001041
Girish Gowdru841708f2019-02-08 04:29:48 -08001042 flow_store_cookie = self._get_flow_store_cookie(
1043 downlink_classifier, gemport_id)
1044 if self.resource_mgr.is_flow_cookie_on_kv_store(
1045 intf_id, onu_id, uni_id, flow_store_cookie):
1046 self.log.debug('flow-exists--not-re-adding')
1047 else:
1048 downlink_flow_id = self.resource_mgr.get_flow_id(
1049 intf_id, onu_id, uni_id,
1050 flow_store_cookie=flow_store_cookie
1051 )
Girish Gowdrub761bc12018-11-29 02:22:18 -08001052
Girish Gowdru841708f2019-02-08 04:29:48 -08001053 downstream_flow = openolt_pb2.Flow(
1054 access_intf_id=intf_id, onu_id=onu_id, uni_id=uni_id,
1055 flow_id=downlink_flow_id, flow_type=DOWNSTREAM,
1056 alloc_id=alloc_id,
1057 network_intf_id=self.data_model.olt_nni_intf_id(),
1058 gemport_id=gemport_id,
1059 classifier=self.mk_classifier(downlink_classifier),
1060 action=self.mk_action(downlink_action),
1061 priority=logical_flow.priority,
1062 port_no=port_no,
1063 cookie=logical_flow.cookie)
Nicolas Palpacuer6152a322018-09-05 10:52:15 -04001064
Girish Gowdru841708f2019-02-08 04:29:48 -08001065 downstream_logical_flow = ofp_flow_stats(
1066 id=logical_flow.id, cookie=logical_flow.cookie,
1067 table_id=logical_flow.table_id,
1068 priority=logical_flow.priority, flags=logical_flow.flags)
Nicolas Palpacuer6152a322018-09-05 10:52:15 -04001069
Girish Gowdru841708f2019-02-08 04:29:48 -08001070 downstream_logical_flow.match.oxm_fields.extend(
1071 fd.mk_oxm_fields(
1072 [fd.in_port(fd.get_out_port(logical_flow)),
1073 fd.vlan_vid(special_vlan_downstream_flow | 0x1000)]))
1074 downstream_logical_flow.match.type = OFPMT_OXM
Nicolas Palpacuer6152a322018-09-05 10:52:15 -04001075
Girish Gowdru841708f2019-02-08 04:29:48 -08001076 downstream_logical_flow.instructions.extend(
1077 fd.mk_instructions_from_actions([fd.output(
1078 self.platform.mk_uni_port_num(intf_id, onu_id,
1079 uni_id))]))
Nicolas Palpacuer6152a322018-09-05 10:52:15 -04001080
Girish Gowdru841708f2019-02-08 04:29:48 -08001081 if self.add_flow_to_device(downstream_flow,
1082 downstream_logical_flow):
1083 flow_info = self._get_flow_info_as_json_blob(
1084 downstream_flow, flow_store_cookie)
1085 self.update_flow_info_to_kv_store(
1086 downstream_flow.access_intf_id, downstream_flow.onu_id,
1087 downstream_flow.uni_id, downstream_flow.flow_id,
1088 flow_info)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001089
Nicolas Palpacuer41141352018-08-31 14:11:38 -04001090 def repush_all_different_flows(self):
1091 # Check if the device is supposed to have flows, if so add them
1092 # Recover static flows after a reboot
1093 logical_flows = self.logical_flows_proxy.get('/').items
1094 devices_flows = self.flows_proxy.get('/').items
1095 logical_flows_ids_provisioned = [f.cookie for f in devices_flows]
1096 for logical_flow in logical_flows:
1097 try:
1098 if logical_flow.id not in logical_flows_ids_provisioned:
1099 self.add_flow(logical_flow)
1100 except Exception as e:
Craig Lutgenabd9c842018-11-15 23:58:27 +00001101 self.log.exception('Problem reading this flow', e=e)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001102
Nicolas Palpacuer41141352018-08-31 14:11:38 -04001103 def reset_flows(self):
Girish Gowdru75962292019-05-03 04:33:34 -07001104 self.flows_proxy.update('/', Flows(items=[]))
1105 self.log.debug("purged-all-device-flows")
1106
1107 self.logical_flows_proxy.update('/', Flows(items=[]))
1108 self.log.debug("purged-all-logical-flows")
Nicolas Palpacuer61815162018-06-20 18:12:04 -04001109
Girish Gowdru841708f2019-02-08 04:29:48 -08001110 """ Add a downstream DHCP trap flow on the NNI interface
Shad Ansarifd0111d2018-09-13 21:33:06 +00001111 """
Girish Gowdru841708f2019-02-08 04:29:48 -08001112 def add_dhcp_trap_nni(self, logical_flow, classifier,
1113 port_no, network_intf_id=0):
1114 self.log.info("trap-dhcp-of-nni-flow")
1115 classifier[PACKET_TAG_TYPE] = DOUBLE_TAG
1116 action = dict()
1117 action[TRAP_TO_HOST] = True
1118
1119 # We manage flow_id resource pool on per PON port basis.
1120 # Since this situation is tricky, as a hack, we pass the NNI port
1121 # index (network_intf_id) as PON port Index for the flow_id resource
1122 # pool. Also, there is no ONU Id available for trapping LLDP packets
1123 # on NNI port, use onu_id as -1 (invalid)
1124 # ****************** CAVEAT *******************
1125 # This logic works if the NNI Port Id falls within the same valid
1126 # range of PON Port Ids. If this doesn't work for some OLT Vendor
1127 # we need to have a re-look at this.
1128 # *********************************************
1129 onu_id = -1
1130 uni_id = -1
1131 flow_store_cookie = self._get_flow_store_cookie(classifier)
1132
1133 if self.resource_mgr.is_flow_cookie_on_kv_store(
1134 network_intf_id, onu_id, uni_id, flow_store_cookie):
1135 self.log.debug('flow-exists--not-re-adding')
1136 else:
1137 flow_id = self.resource_mgr.get_flow_id(
1138 network_intf_id, onu_id, uni_id,
1139 flow_store_cookie=flow_store_cookie)
1140
1141 downstream_flow = openolt_pb2.Flow(
1142 access_intf_id=-1, # access_intf_id not required
1143 onu_id=onu_id, # onu_id not required
1144 uni_id=uni_id, # uni_id not used
1145 flow_id=flow_id,
1146 flow_type=DOWNSTREAM,
1147 network_intf_id=network_intf_id,
1148 gemport_id=-1, # gemport_id not required
1149 classifier=self.mk_classifier(classifier),
1150 action=self.mk_action(action),
1151 priority=logical_flow.priority,
1152 port_no=port_no,
1153 cookie=logical_flow.cookie)
1154
1155 self.log.debug('add dhcp downstream trap', classifier=classifier,
1156 action=action, flow=downstream_flow,
1157 port_no=port_no)
1158 if self.add_flow_to_device(downstream_flow, logical_flow):
1159 flow_info = self._get_flow_info_as_json_blob(downstream_flow,
1160 flow_store_cookie)
1161 self.update_flow_info_to_kv_store(
1162 network_intf_id, onu_id, uni_id, flow_id, flow_info)
Girish Gowdruab836e92018-10-25 01:17:57 -07001163
Craig Lutgenabd9c842018-11-15 23:58:27 +00001164 def add_lldp_flow(self, logical_flow, port_no, network_intf_id=0):
Jonathan Hart5b435642018-08-20 08:50:05 -07001165
Girish Gowdruab836e92018-10-25 01:17:57 -07001166 classifier = dict()
Shad Ansarifd0111d2018-09-13 21:33:06 +00001167 classifier[ETH_TYPE] = LLDP_ETH_TYPE
Nicolas Palpacuer2789f042018-09-17 09:10:29 -04001168 classifier[PACKET_TAG_TYPE] = UNTAGGED
Girish Gowdruab836e92018-10-25 01:17:57 -07001169 action = dict()
Shad Ansarifd0111d2018-09-13 21:33:06 +00001170 action[TRAP_TO_HOST] = True
Jonathan Hart5b435642018-08-20 08:50:05 -07001171
Girish Gowdruab836e92018-10-25 01:17:57 -07001172 # LLDP flow is installed to trap LLDP packets on the NNI port.
1173 # We manage flow_id resource pool on per PON port basis.
1174 # Since this situation is tricky, as a hack, we pass the NNI port
1175 # index (network_intf_id) as PON port Index for the flow_id resource
1176 # pool. Also, there is no ONU Id available for trapping LLDP packets
1177 # on NNI port, use onu_id as -1 (invalid)
1178 # ****************** CAVEAT *******************
1179 # This logic works if the NNI Port Id falls within the same valid
1180 # range of PON Port Ids. If this doesn't work for some OLT Vendor
1181 # we need to have a re-look at this.
1182 # *********************************************
1183 onu_id = -1
Craig Lutgenabd9c842018-11-15 23:58:27 +00001184 uni_id = -1
Girish Gowdrub761bc12018-11-29 02:22:18 -08001185 flow_store_cookie = self._get_flow_store_cookie(classifier)
Jonathan Hart5b435642018-08-20 08:50:05 -07001186
Shad Ansari7a5d2172019-02-26 13:35:36 -08001187 if self.resource_mgr.is_flow_cookie_on_kv_store(
1188 network_intf_id, onu_id, uni_id, flow_store_cookie):
Girish Gowdru50f62fb2019-02-04 22:16:15 -08001189 self.log.debug('flow-exists--not-re-adding')
1190 else:
Shad Ansari7a5d2172019-02-26 13:35:36 -08001191 flow_id = self.resource_mgr.get_flow_id(
Girish Gowdru841708f2019-02-08 04:29:48 -08001192 network_intf_id, onu_id, uni_id, flow_store_cookie=flow_store_cookie)
Jonathan Hart5b435642018-08-20 08:50:05 -07001193
Girish Gowdru50f62fb2019-02-04 22:16:15 -08001194 downstream_flow = openolt_pb2.Flow(
1195 access_intf_id=-1, # access_intf_id not required
Shad Ansari7a5d2172019-02-26 13:35:36 -08001196 onu_id=onu_id, # onu_id not required
1197 uni_id=uni_id, # uni_id not used
Girish Gowdru50f62fb2019-02-04 22:16:15 -08001198 flow_id=flow_id,
1199 flow_type=DOWNSTREAM,
1200 network_intf_id=network_intf_id,
1201 gemport_id=-1, # gemport_id not required
1202 classifier=self.mk_classifier(classifier),
1203 action=self.mk_action(action),
1204 priority=logical_flow.priority,
1205 port_no=port_no,
1206 cookie=logical_flow.cookie)
1207
1208 self.log.debug('add lldp downstream trap', classifier=classifier,
Shad Ansari7a5d2172019-02-26 13:35:36 -08001209 action=action, flow=downstream_flow,
1210 port_no=port_no)
Girish Gowdru50f62fb2019-02-04 22:16:15 -08001211 if self.add_flow_to_device(downstream_flow, logical_flow):
1212 flow_info = self._get_flow_info_as_json_blob(downstream_flow,
1213 flow_store_cookie)
Shad Ansari7a5d2172019-02-26 13:35:36 -08001214 self.update_flow_info_to_kv_store(
1215 network_intf_id, onu_id, uni_id, flow_id, flow_info)
Jonathan Hart5b435642018-08-20 08:50:05 -07001216
Girish Gowdru841708f2019-02-08 04:29:48 -08001217 @staticmethod
1218 def mk_classifier(classifier_info):
Shad Ansari2dda4f32018-05-17 07:16:07 +00001219
1220 classifier = openolt_pb2.Classifier()
1221
Nicolas Palpacuer2789f042018-09-17 09:10:29 -04001222 if ETH_TYPE in classifier_info:
1223 classifier.eth_type = classifier_info[ETH_TYPE]
1224 if IP_PROTO in classifier_info:
1225 classifier.ip_proto = classifier_info[IP_PROTO]
Thiyagarajan Subramani3b62d6c2019-02-15 08:48:01 -08001226 if VLAN_VID in classifier_info and \
1227 classifier_info[VLAN_VID] != RESERVED_VLAN:
Shad Ansari7a5d2172019-02-26 13:35:36 -08001228 classifier.o_vid = classifier_info[VLAN_VID]
Thiyagarajan Subramani3b62d6c2019-02-15 08:48:01 -08001229 if METADATA in classifier_info and \
1230 classifier_info[METADATA] != RESERVED_VLAN:
Shad Ansari7a5d2172019-02-26 13:35:36 -08001231 classifier.i_vid = classifier_info[METADATA]
Nicolas Palpacuer2789f042018-09-17 09:10:29 -04001232 if VLAN_PCP in classifier_info:
1233 classifier.o_pbits = classifier_info[VLAN_PCP]
1234 if UDP_SRC in classifier_info:
1235 classifier.src_port = classifier_info[UDP_SRC]
1236 if UDP_DST in classifier_info:
1237 classifier.dst_port = classifier_info[UDP_DST]
1238 if IPV4_DST in classifier_info:
1239 classifier.dst_ip = classifier_info[IPV4_DST]
1240 if IPV4_SRC in classifier_info:
1241 classifier.src_ip = classifier_info[IPV4_SRC]
1242 if PACKET_TAG_TYPE in classifier_info:
1243 if classifier_info[PACKET_TAG_TYPE] == SINGLE_TAG:
1244 classifier.pkt_tag_type = SINGLE_TAG
1245 elif classifier_info[PACKET_TAG_TYPE] == DOUBLE_TAG:
1246 classifier.pkt_tag_type = DOUBLE_TAG
1247 elif classifier_info[PACKET_TAG_TYPE] == UNTAGGED:
1248 classifier.pkt_tag_type = UNTAGGED
Shad Ansari2dda4f32018-05-17 07:16:07 +00001249 else:
1250 classifier.pkt_tag_type = 'none'
1251
1252 return classifier
1253
1254 def mk_action(self, action_info):
1255 action = openolt_pb2.Action()
1256
Nicolas Palpacuer2789f042018-09-17 09:10:29 -04001257 if POP_VLAN in action_info:
1258 action.o_vid = action_info[VLAN_VID]
Shad Ansari2dda4f32018-05-17 07:16:07 +00001259 action.cmd.remove_outer_tag = True
Nicolas Palpacuer2789f042018-09-17 09:10:29 -04001260 elif PUSH_VLAN in action_info:
1261 action.o_vid = action_info[VLAN_VID]
Shad Ansari2dda4f32018-05-17 07:16:07 +00001262 action.cmd.add_outer_tag = True
Girish Gowdru841708f2019-02-08 04:29:48 -08001263 if VLAN_PCP in action_info:
1264 action.o_pbits = action_info[VLAN_PCP]
Nicolas Palpacuer2789f042018-09-17 09:10:29 -04001265 elif TRAP_TO_HOST in action_info:
Shad Ansari2dda4f32018-05-17 07:16:07 +00001266 action.cmd.trap_to_host = True
Shad Ansarif9d2d102018-06-13 02:15:26 +00001267 else:
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -04001268 self.log.info('Invalid-action-field', action_info=action_info)
Shad Ansarif9d2d102018-06-13 02:15:26 +00001269 return
Shad Ansari2dda4f32018-05-17 07:16:07 +00001270 return action
Nicolas Palpacuer61815162018-06-20 18:12:04 -04001271
Craig Lutgenabd9c842018-11-15 23:58:27 +00001272 def is_eap_enabled(self, intf_id, onu_id, uni_id):
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001273 flows = self.logical_flows_proxy.get('/').items
Nicolas Palpacuer61815162018-06-20 18:12:04 -04001274
1275 for flow in flows:
1276 eap_flow = False
1277 eap_intf_id = None
1278 eap_onu_id = None
Craig Lutgenabd9c842018-11-15 23:58:27 +00001279 eap_uni_id = None
Nicolas Palpacuer61815162018-06-20 18:12:04 -04001280 for field in fd.get_ofb_fields(flow):
1281 if field.type == fd.ETH_TYPE:
1282 if field.eth_type == EAP_ETH_TYPE:
1283 eap_flow = True
1284 if field.type == fd.IN_PORT:
Shad Ansaricd20a6d2018-10-02 14:36:33 +00001285 eap_intf_id = self.platform.intf_id_from_uni_port_num(
Shad Ansari47e0c392018-07-17 23:55:07 +00001286 field.port)
Shad Ansaricd20a6d2018-10-02 14:36:33 +00001287 eap_onu_id = self.platform.onu_id_from_port_num(field.port)
Craig Lutgenabd9c842018-11-15 23:58:27 +00001288 eap_uni_id = self.platform.uni_id_from_port_num(field.port)
Nicolas Palpacuer61815162018-06-20 18:12:04 -04001289
1290 if eap_flow:
Shad Ansari7a5d2172019-02-26 13:35:36 -08001291 self.log.debug('eap flow detected', onu_id=onu_id,
1292 uni_id=uni_id, intf_id=intf_id,
1293 eap_intf_id=eap_intf_id, eap_onu_id=eap_onu_id,
Craig Lutgenabd9c842018-11-15 23:58:27 +00001294 eap_uni_id=eap_uni_id)
Shad Ansari7a5d2172019-02-26 13:35:36 -08001295 if eap_flow and intf_id == eap_intf_id \
1296 and onu_id == eap_onu_id and uni_id == eap_uni_id:
Girish Gowdruab836e92018-10-25 01:17:57 -07001297 return True, flow
Nicolas Palpacuer61815162018-06-20 18:12:04 -04001298
Girish Gowdruab836e92018-10-25 01:17:57 -07001299 return False, None
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001300
Nicolas Palpacuer41141352018-08-31 14:11:38 -04001301 def get_subscriber_vlan(self, port):
1302 self.log.debug('looking from subscriber flow for port', port=port)
1303
1304 flows = self.logical_flows_proxy.get('/').items
1305 for flow in flows:
1306 in_port = fd.get_in_port(flow)
1307 out_port = fd.get_out_port(flow)
Girish Gowdrub761bc12018-11-29 02:22:18 -08001308 if in_port == port and out_port is not None and \
Girish Gowdruab836e92018-10-25 01:17:57 -07001309 self.platform.intf_id_to_port_type_name(out_port) \
Shad Ansarifd0111d2018-09-13 21:33:06 +00001310 == Port.ETHERNET_NNI:
Nicolas Palpacuer41141352018-08-31 14:11:38 -04001311 fields = fd.get_ofb_fields(flow)
1312 self.log.debug('subscriber flow found', fields=fields)
1313 for field in fields:
1314 if field.type == OFPXMT_OFB_VLAN_VID:
1315 self.log.debug('subscriber vlan found',
1316 vlan_id=field.vlan_vid)
1317 return field.vlan_vid & 0x0fff
1318 self.log.debug('No subscriber flow found', port=port)
1319 return None
1320
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001321 def add_flow_to_device(self, flow, logical_flow):
1322 self.log.debug('pushing flow to device', flow=flow)
Nicolas Palpacuer2789f042018-09-17 09:10:29 -04001323 try:
1324 self.stub.FlowAdd(flow)
1325 except grpc.RpcError as grpc_e:
1326 if grpc_e.code() == grpc.StatusCode.ALREADY_EXISTS:
1327 self.log.warn('flow already exists', e=grpc_e, flow=flow)
1328 else:
1329 self.log.error('failed to add flow',
1330 logical_flow=logical_flow, flow=flow,
1331 grpc_error=grpc_e)
Girish Gowdru58b1d382019-05-08 23:35:39 -07001332 # If the flow addition failed on the device, immediately
1333 # free up the flow_id resource from the pool
1334 intf_id = flow.access_intf_id if flow.access_intf_id > 0 else flow.network_intf_id
1335 onu_id = flow.onu_id
1336 uni_id = flow.uni_id
1337 flow_id = flow.flow_id
1338 self.resource_mgr.free_flow_id(intf_id, onu_id, uni_id, flow_id)
1339
Girish Gowdruab836e92018-10-25 01:17:57 -07001340 return False
Nicolas Palpacuer2789f042018-09-17 09:10:29 -04001341 else:
1342 self.register_flow(logical_flow, flow)
Girish Gowdruab836e92018-10-25 01:17:57 -07001343 return True
1344
Shad Ansari7a5d2172019-02-26 13:35:36 -08001345 def update_flow_info_to_kv_store(self, intf_id, onu_id, uni_id, flow_id,
1346 flow):
Girish Gowdru50f62fb2019-02-04 22:16:15 -08001347 self.resource_mgr.update_flow_id_info(intf_id, onu_id, uni_id,
1348 flow_id, flow)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001349
1350 def register_flow(self, logical_flow, device_flow):
1351 self.log.debug('registering flow in device',
1352 logical_flow=logical_flow, device_flow=device_flow)
1353 stored_flow = copy.deepcopy(logical_flow)
1354 stored_flow.id = self.generate_stored_id(device_flow.flow_id,
1355 device_flow.flow_type)
1356 self.log.debug('generated device flow id', id=stored_flow.id,
1357 flow_id=device_flow.flow_id,
1358 direction=device_flow.flow_type)
1359 stored_flow.cookie = logical_flow.id
1360 flows = self.flows_proxy.get('/')
1361 flows.items.extend([stored_flow])
1362 self.flows_proxy.update('/', flows)
1363
Girish Gowdru841708f2019-02-08 04:29:48 -08001364 def find_next_flow(self, flow, metadata):
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001365 table_id = fd.get_goto_table_id(flow)
Shad Ansari7a5d2172019-02-26 13:35:36 -08001366 # Prior to ONOS 1.13.5, Metadata contained the UNI output port number.
1367 # In 1.13.5 and later, the lower 32-bits is the output port number and
1368 # the # upper 32-bits is the inner-vid we are looking for. Use just the
1369 # lower 32 # bits. Allows this code to work with pre- and post-1.13.5
1370 # ONOS OltPipeline
Chip Boling41f795a2018-10-04 15:45:34 -05001371
Girish Gowdru841708f2019-02-08 04:29:48 -08001372 port = metadata & 0xFFFFFFFF
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001373 if table_id is None:
1374 return None
1375 flows = self.logical_flows_proxy.get('/').items
1376 next_flows = []
1377 for f in flows:
1378 if f.table_id == table_id:
Jonathan Hart5b435642018-08-20 08:50:05 -07001379 # FIXME
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001380 if fd.get_in_port(f) == fd.get_in_port(flow) and \
Girish Gowdru841708f2019-02-08 04:29:48 -08001381 fd.get_out_port(f) == port:
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001382 next_flows.append(f)
1383
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001384 if len(next_flows) == 0:
1385 self.log.warning('no next flow found, it may be a timing issue',
1386 flow=flow, number_of_flows=len(flows))
Scott Bakerbe5a9ea2018-11-19 19:24:21 -08001387 if flow.id in self.retry_add_flow_list:
Shad Ansari7a5d2172019-02-26 13:35:36 -08001388 self.log.debug('flow is already in retry list',
1389 flow_id=flow.id)
Scott Bakerbe5a9ea2018-11-19 19:24:21 -08001390 else:
1391 self.retry_add_flow_list.append(flow.id)
1392 reactor.callLater(5, self.retry_add_flow, flow)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001393 return None
1394
Jonathan Hart5b435642018-08-20 08:50:05 -07001395 next_flows.sort(key=lambda f: f.priority, reverse=True)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001396
1397 return next_flows[0]
1398
1399 def update_children_flows(self, device_rules_map):
1400
1401 for device_id, (flows, groups) in device_rules_map.iteritems():
1402 if device_id != self.device_id:
1403 self.root_proxy.update('/devices/{}/flows'.format(device_id),
1404 Flows(items=flows.values()))
1405 self.root_proxy.update('/devices/{}/flow_groups'.format(
1406 device_id), FlowGroups(items=groups.values()))
1407
Shad Ansari7a5d2172019-02-26 13:35:36 -08001408 def clear_flows_and_scheduler_for_logical_port(self, child_device,
1409 logical_port):
Girish Gowdruab836e92018-10-25 01:17:57 -07001410 ofp_port_name = logical_port.ofp_port.name
Craig Lutgenabd9c842018-11-15 23:58:27 +00001411 port_no = logical_port.ofp_port.port_no
Girish Gowdruab836e92018-10-25 01:17:57 -07001412 pon_port = child_device.proxy_address.channel_id
1413 onu_id = child_device.proxy_address.onu_id
Thiyagarajan Subramani353af122019-02-20 23:14:24 -08001414 uni_id = self.platform.uni_id_from_port_num(port_no)
Craig Lutgenabd9c842018-11-15 23:58:27 +00001415
Shad Ansari7a5d2172019-02-26 13:35:36 -08001416 tp_id = self.resource_mgr.get_tech_profile_id_for_onu(pon_port, onu_id,
1417 uni_id)
Girish Gowdruab836e92018-10-25 01:17:57 -07001418 tech_profile_instance = self.tech_profile[pon_port]. \
1419 get_tech_profile_instance(
Thiyagarajan Subramani353af122019-02-20 23:14:24 -08001420 tp_id,
Girish Gowdruab836e92018-10-25 01:17:57 -07001421 ofp_port_name)
Shad Ansari7a5d2172019-02-26 13:35:36 -08001422 flow_ids = self.resource_mgr.get_current_flow_ids(pon_port, onu_id,
1423 uni_id)
Girish Gowdruab836e92018-10-25 01:17:57 -07001424 self.log.debug("outstanding-flows-to-be-cleared", flow_ids=flow_ids)
Girish Gowdru841708f2019-02-08 04:29:48 -08001425 if flow_ids:
1426 for flow_id in flow_ids:
1427 flow_infos = self.resource_mgr.get_flow_id_info(pon_port, onu_id,
1428 uni_id, flow_id)
1429 for flow_info in flow_infos:
1430 direction = flow_info['flow_type']
1431 flow_to_remove = openolt_pb2.Flow(flow_id=flow_id,
1432 flow_type=direction)
1433 try:
1434 self.stub.FlowRemove(flow_to_remove)
1435 except grpc.RpcError as grpc_e:
1436 if grpc_e.code() == grpc.StatusCode.NOT_FOUND:
1437 self.log.debug('This flow does not exist on switch, '
1438 'normal after an OLT reboot',
1439 flow=flow_to_remove)
1440 else:
1441 raise grpc_e
Girish Gowdruab836e92018-10-25 01:17:57 -07001442
Girish Gowdru841708f2019-02-08 04:29:48 -08001443 self.remove_us_scheduler_queues(pon_port, onu_id, uni_id, tech_profile_instance)
1444 self.remove_ds_scheduler_queues(pon_port, onu_id, uni_id, tech_profile_instance)
Girish Gowdruab836e92018-10-25 01:17:57 -07001445
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001446 def generate_stored_id(self, flow_id, direction):
Nicolas Palpacuer2789f042018-09-17 09:10:29 -04001447 if direction == UPSTREAM:
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001448 self.log.debug('upstream flow, shifting id')
1449 return 0x1 << 15 | flow_id
Nicolas Palpacuer2789f042018-09-17 09:10:29 -04001450 elif direction == DOWNSTREAM:
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001451 self.log.debug('downstream flow, not shifting id')
1452 return flow_id
1453 else:
1454 self.log.warn('Unrecognized direction', direction=direction)
1455 return flow_id
1456
1457 def decode_stored_id(self, id):
1458 if id >> 15 == 0x1:
Girish Gowdruab836e92018-10-25 01:17:57 -07001459 return id & 0x7fff, UPSTREAM
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001460 else:
Girish Gowdruab836e92018-10-25 01:17:57 -07001461 return id, DOWNSTREAM
1462
1463 def _populate_tech_profile_per_pon_port(self):
1464 for arange in self.resource_mgr.device_info.ranges:
1465 for intf_id in arange.intf_ids:
1466 self.tech_profile[intf_id] = \
1467 self.resource_mgr.resource_mgrs[intf_id].tech_profile
1468
1469 # Make sure we have as many tech_profiles as there are pon ports on
1470 # the device
Shad Ansari7a5d2172019-02-26 13:35:36 -08001471 assert len(self.tech_profile) \
Girish Gowdru841708f2019-02-08 04:29:48 -08001472 == self.resource_mgr.device_info.pon_ports
Girish Gowdruab836e92018-10-25 01:17:57 -07001473
Girish Gowdrub761bc12018-11-29 02:22:18 -08001474 def _get_flow_info_as_json_blob(self, flow, flow_store_cookie,
1475 flow_category=None):
Girish Gowdruab836e92018-10-25 01:17:57 -07001476 json_blob = MessageToDict(message=flow,
1477 preserving_proto_field_name=True)
1478 self.log.debug("flow-info", json_blob=json_blob)
Girish Gowdrub761bc12018-11-29 02:22:18 -08001479 json_blob['flow_store_cookie'] = flow_store_cookie
1480 if flow_category is not None:
1481 json_blob['flow_category'] = flow_category
Girish Gowdru50f62fb2019-02-04 22:16:15 -08001482
Shad Ansari7a5d2172019-02-26 13:35:36 -08001483 # For flows which trap out of the NNI, the access_intf_id is invalid
1484 # (set to -1). In such cases, we need to refer to the network_intf_id.
Girish Gowdru50f62fb2019-02-04 22:16:15 -08001485 if flow.access_intf_id != -1:
Shad Ansari7a5d2172019-02-26 13:35:36 -08001486 flow_info = self.resource_mgr.get_flow_id_info(
1487 flow.access_intf_id, flow.onu_id, flow.uni_id, flow.flow_id)
Girish Gowdru50f62fb2019-02-04 22:16:15 -08001488 else:
Shad Ansari7a5d2172019-02-26 13:35:36 -08001489 # Case of LLDP trap flow from the NNI. We can't use
1490 # flow.access_intf_id in that case, as it is invalid.
1491 # We use flow.network_intf_id.
1492 flow_info = self.resource_mgr.get_flow_id_info(
1493 flow.network_intf_id, flow.onu_id, flow.uni_id, flow.flow_id)
Girish Gowdruab836e92018-10-25 01:17:57 -07001494
1495 if flow_info is None:
1496 flow_info = list()
1497 flow_info.append(json_blob)
1498 else:
1499 assert (isinstance(flow_info, list))
1500 flow_info.append(json_blob)
1501
1502 return flow_info
Girish Gowdrub761bc12018-11-29 02:22:18 -08001503
1504 @staticmethod
1505 def _get_flow_store_cookie(classifier, gem_port=None):
1506 assert isinstance(classifier, dict)
1507 # We need unique flows per gem_port
1508 if gem_port is not None:
1509 to_hash = dumps(classifier, sort_keys=True) + str(gem_port)
1510 else:
1511 to_hash = dumps(classifier, sort_keys=True)
1512 return hashlib.md5(to_hash).hexdigest()[:12]
Girish Gowdru841708f2019-02-08 04:29:48 -08001513
1514 @staticmethod
1515 def _get_gem_port_for_pcp(pcp, get_gem_port_for_pcp):
1516 """
1517 Return gem_port id corresponding to a given pcp bit
1518
1519 :param pcp: Represents the p_bit
1520 :param get_gem_port_for_pcp: Represents a list of gemport_attributes (DS or US)
1521 :return: Gemport ID servicing the given pcp if found, else None
1522 """
1523 for gem_port_attr in get_gem_port_for_pcp:
1524 # The pbit_map appears as "0b00011010" in the Tech-Profile instance.
1525 # The initial '0b' has to be stripped.
1526 # The remaining string is reversed, then enumerated and matched against pcp index.
1527 for i, p in enumerate(reversed(gem_port_attr.pbit_map[2:])):
1528 if i == pcp and p == '1':
1529 return gem_port_attr.gemport_id
1530 return None
1531
1532 @staticmethod
1533 def _install_flow_on_all_gemports(func, kwargs, gem_attr_list):
1534 for gem_attr in gem_attr_list:
1535 # The pbit_map appears as "0b00011010" in the Tech-Profile instance.
1536 # The initial '0b' has to be stripped.
1537 # The remaining string is reversed, then enumerated and matched against pbit 1.
1538 for i, p in enumerate(reversed(gem_attr.pbit_map[2:])):
1539 if p == '1':
1540 kwargs['classifier'][VLAN_PCP] = i
1541 # Add the gemport corresponding to this PCP
1542 kwargs['gemport_id'] = gem_attr.gemport_id
1543 func(**kwargs)
1544