blob: c372cf519558723c6bf3d4fb0f87de8a79f6f959 [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
21from simplejson import dumps
Shad Ansari2dda4f32018-05-17 07:16:07 +000022
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -040023from voltha.protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC, \
Jonathan Hart5b435642018-08-20 08:50:05 -070024 ofp_flow_stats, OFPMT_OXM, Flows, FlowGroups, OFPXMT_OFB_IN_PORT, \
25 OFPXMT_OFB_VLAN_VID
Nicolas Palpacuer5780e152018-09-05 17:25:42 -040026from voltha.protos.device_pb2 import Port
Shad Ansari2dda4f32018-05-17 07:16:07 +000027import voltha.core.flow_decomposer as fd
Shad Ansari2dda4f32018-05-17 07:16:07 +000028from voltha.adapters.openolt.protos import openolt_pb2
Nicolas Palpacuer61815162018-06-20 18:12:04 -040029from voltha.registry import registry
Shad Ansari2dda4f32018-05-17 07:16:07 +000030
Girish Gowdruab836e92018-10-25 01:17:57 -070031from common.tech_profile.tech_profile import DEFAULT_TECH_PROFILE_TABLE_ID
32
33# Flow categories
34HSIA_FLOW = "HSIA_FLOW"
Nicolas Palpacuer61815162018-06-20 18:12:04 -040035
36EAP_ETH_TYPE = 0x888e
Jonathan Hart5b435642018-08-20 08:50:05 -070037LLDP_ETH_TYPE = 0x88cc
Shad Ansari2dda4f32018-05-17 07:16:07 +000038
Girish Gowdruab836e92018-10-25 01:17:57 -070039IGMP_PROTO = 2
40
Shad Ansari2dda4f32018-05-17 07:16:07 +000041# FIXME - see also BRDCM_DEFAULT_VLAN in broadcom_onu.py
42DEFAULT_MGMT_VLAN = 4091
43
Nicolas Palpacuer2789f042018-09-17 09:10:29 -040044# Openolt Flow
Girish Gowdruab836e92018-10-25 01:17:57 -070045UPSTREAM = "upstream"
46DOWNSTREAM = "downstream"
47PACKET_TAG_TYPE = "pkt_tag_type"
48UNTAGGED = "untagged"
49SINGLE_TAG = "single_tag"
50DOUBLE_TAG = "double_tag"
Nicolas Palpacuer2789f042018-09-17 09:10:29 -040051
52# Classifier
53ETH_TYPE = 'eth_type'
54TPID = 'tpid'
55IP_PROTO = 'ip_proto'
56IN_PORT = 'in_port'
57VLAN_VID = 'vlan_vid'
58VLAN_PCP = 'vlan_pcp'
59UDP_DST = 'udp_dst'
60UDP_SRC = 'udp_src'
61IPV4_DST = 'ipv4_dst'
62IPV4_SRC = 'ipv4_src'
63METADATA = 'metadata'
64OUTPUT = 'output'
65# Action
66POP_VLAN = 'pop_vlan'
67PUSH_VLAN = 'push_vlan'
68TRAP_TO_HOST = 'trap_to_host'
69
Nicolas Palpacuer2789f042018-09-17 09:10:29 -040070
Shad Ansari2dda4f32018-05-17 07:16:07 +000071class OpenOltFlowMgr(object):
72
Girish Gowdruab836e92018-10-25 01:17:57 -070073 def __init__(self, adapter_agent, log, stub, device_id, logical_device_id,
Girish Gowdru1e77ea02018-09-24 09:10:35 -070074 platform, resource_mgr):
Girish Gowdruab836e92018-10-25 01:17:57 -070075 self.adapter_agent = adapter_agent
Shad Ansari2dda4f32018-05-17 07:16:07 +000076 self.log = log
77 self.stub = stub
Nicolas Palpacuer61815162018-06-20 18:12:04 -040078 self.device_id = device_id
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -040079 self.logical_device_id = logical_device_id
Shad Ansaricd20a6d2018-10-02 14:36:33 +000080 self.platform = platform
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -040081 self.logical_flows_proxy = registry('core').get_proxy(
82 '/logical_devices/{}/flows'.format(self.logical_device_id))
83 self.flows_proxy = registry('core').get_proxy(
Nicolas Palpacuer61815162018-06-20 18:12:04 -040084 '/devices/{}/flows'.format(self.device_id))
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -040085 self.root_proxy = registry('core').get_proxy('/')
Girish Gowdru1e77ea02018-09-24 09:10:35 -070086 self.resource_mgr = resource_mgr
Girish Gowdruab836e92018-10-25 01:17:57 -070087 self.tech_profile = dict()
88 self._populate_tech_profile_per_pon_port()
Scott Bakerbe5a9ea2018-11-19 19:24:21 -080089 self.retry_add_flow_list = []
Shad Ansari2dda4f32018-05-17 07:16:07 +000090
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -040091 def add_flow(self, flow):
92 self.log.debug('add flow', flow=flow)
Shad Ansari2dda4f32018-05-17 07:16:07 +000093 classifier_info = dict()
94 action_info = dict()
95
Shad Ansari2dda4f32018-05-17 07:16:07 +000096 for field in fd.get_ofb_fields(flow):
97 if field.type == fd.ETH_TYPE:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -040098 classifier_info[ETH_TYPE] = field.eth_type
Shad Ansarie048aaa2018-05-18 18:27:21 +000099 self.log.debug('field-type-eth-type',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400100 eth_type=classifier_info[ETH_TYPE])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000101 elif field.type == fd.IP_PROTO:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400102 classifier_info[IP_PROTO] = field.ip_proto
Shad Ansarie048aaa2018-05-18 18:27:21 +0000103 self.log.debug('field-type-ip-proto',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400104 ip_proto=classifier_info[IP_PROTO])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000105 elif field.type == fd.IN_PORT:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400106 classifier_info[IN_PORT] = field.port
Shad Ansarie048aaa2018-05-18 18:27:21 +0000107 self.log.debug('field-type-in-port',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400108 in_port=classifier_info[IN_PORT])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000109 elif field.type == fd.VLAN_VID:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400110 classifier_info[VLAN_VID] = field.vlan_vid & 0xfff
Shad Ansarie048aaa2018-05-18 18:27:21 +0000111 self.log.debug('field-type-vlan-vid',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400112 vlan=classifier_info[VLAN_VID])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000113 elif field.type == fd.VLAN_PCP:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400114 classifier_info[VLAN_PCP] = field.vlan_pcp
Shad Ansarie048aaa2018-05-18 18:27:21 +0000115 self.log.debug('field-type-vlan-pcp',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400116 pcp=classifier_info[VLAN_PCP])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000117 elif field.type == fd.UDP_DST:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400118 classifier_info[UDP_DST] = field.udp_dst
Shad Ansarie048aaa2018-05-18 18:27:21 +0000119 self.log.debug('field-type-udp-dst',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400120 udp_dst=classifier_info[UDP_DST])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000121 elif field.type == fd.UDP_SRC:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400122 classifier_info[UDP_SRC] = field.udp_src
Shad Ansarie048aaa2018-05-18 18:27:21 +0000123 self.log.debug('field-type-udp-src',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400124 udp_src=classifier_info[UDP_SRC])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000125 elif field.type == fd.IPV4_DST:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400126 classifier_info[IPV4_DST] = field.ipv4_dst
Shad Ansarie048aaa2018-05-18 18:27:21 +0000127 self.log.debug('field-type-ipv4-dst',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400128 ipv4_dst=classifier_info[IPV4_DST])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000129 elif field.type == fd.IPV4_SRC:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400130 classifier_info[IPV4_SRC] = field.ipv4_src
Shad Ansarie048aaa2018-05-18 18:27:21 +0000131 self.log.debug('field-type-ipv4-src',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400132 ipv4_dst=classifier_info[IPV4_SRC])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000133 elif field.type == fd.METADATA:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400134 classifier_info[METADATA] = field.table_metadata
Shad Ansarie048aaa2018-05-18 18:27:21 +0000135 self.log.debug('field-type-metadata',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400136 metadata=classifier_info[METADATA])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000137 else:
138 raise NotImplementedError('field.type={}'.format(
139 field.type))
140
141 for action in fd.get_actions(flow):
142 if action.type == fd.OUTPUT:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400143 action_info[OUTPUT] = action.output.port
Shad Ansarie048aaa2018-05-18 18:27:21 +0000144 self.log.debug('action-type-output',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400145 output=action_info[OUTPUT],
146 in_port=classifier_info[IN_PORT])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000147 elif action.type == fd.POP_VLAN:
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400148 if fd.get_goto_table_id(flow) is None:
149 self.log.debug('being taken care of by ONU', flow=flow)
150 return
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400151 action_info[POP_VLAN] = True
Jonathan Hart5b435642018-08-20 08:50:05 -0700152 self.log.debug('action-type-pop-vlan',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400153 in_port=classifier_info[IN_PORT])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000154 elif action.type == fd.PUSH_VLAN:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400155 action_info[PUSH_VLAN] = True
156 action_info[TPID] = action.push.ethertype
Shad Ansarie048aaa2018-05-18 18:27:21 +0000157 self.log.debug('action-type-push-vlan',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400158 push_tpid=action_info[TPID], in_port=classifier_info[IN_PORT])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000159 if action.push.ethertype != 0x8100:
160 self.log.error('unhandled-tpid',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000161 ethertype=action.push.ethertype)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000162 elif action.type == fd.SET_FIELD:
163 # action_info['action_type'] = 'set_field'
164 _field = action.set_field.field.ofb_field
165 assert (action.set_field.field.oxm_class ==
166 OFPXMC_OPENFLOW_BASIC)
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400167 self.log.debug('action-type-set-field',
168 field=_field, in_port=classifier_info[IN_PORT])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000169 if _field.type == fd.VLAN_VID:
Shad Ansarie048aaa2018-05-18 18:27:21 +0000170 self.log.debug('set-field-type-vlan-vid',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000171 vlan_vid=_field.vlan_vid & 0xfff)
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400172 action_info[VLAN_VID] = (_field.vlan_vid & 0xfff)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000173 else:
174 self.log.error('unsupported-action-set-field-type',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000175 field_type=_field.type)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000176 else:
177 self.log.error('unsupported-action-type',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400178 action_type=action.type, in_port=classifier_info[IN_PORT])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000179
Girish Gowdruab836e92018-10-25 01:17:57 -0700180 if fd.get_goto_table_id(flow) is not None and POP_VLAN not in action_info:
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400181 self.log.debug('being taken care of by ONU', flow=flow)
Nicolas Palpacuer856d3af2018-09-12 15:04:51 -0400182 return
Shad Ansari2dda4f32018-05-17 07:16:07 +0000183
Girish Gowdruab836e92018-10-25 01:17:57 -0700184 if OUTPUT not in action_info and METADATA in classifier_info:
185 # find flow in the next table
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400186 next_flow = self.find_next_flow(flow)
187 if next_flow is None:
188 return
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400189 action_info[OUTPUT] = fd.get_out_port(next_flow)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400190 for field in fd.get_ofb_fields(next_flow):
191 if field.type == fd.VLAN_VID:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400192 classifier_info[METADATA] = field.vlan_vid & 0xfff
193
Craig Lutgenabd9c842018-11-15 23:58:27 +0000194 self.log.debug('flow-ports', classifier_inport=classifier_info[IN_PORT], action_output=action_info[OUTPUT])
195 (port_no, intf_id, onu_id, uni_id) = self.platform.extract_access_from_flow(
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400196 classifier_info[IN_PORT], action_info[OUTPUT])
197
Craig Lutgenabd9c842018-11-15 23:58:27 +0000198 self.divide_and_add_flow(intf_id, onu_id, uni_id, port_no, classifier_info,
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400199 action_info, flow)
200
Girish Gowdruab836e92018-10-25 01:17:57 -0700201 def _is_uni_port(self, port_no):
202 try:
203 port = self.adapter_agent.get_logical_port(self.logical_device_id,
204 'uni-{}'.format(port_no))
205 if port is not None:
206 return (not port.root_port), port.device_id
207 else:
208 return False, None
209 except Exception as e:
210 self.log.error("error-retrieving-port", e=e)
211 return False, None
212
213 def _clear_flow_id_from_rm(self, flow, flow_id, flow_direction):
214 uni_port_no = None
Girish Gowdruab836e92018-10-25 01:17:57 -0700215 child_device_id = None
216 if flow_direction == UPSTREAM:
217 for field in fd.get_ofb_fields(flow):
218 if field.type == fd.IN_PORT:
219 is_uni, child_device_id = self._is_uni_port(field.port)
220 if is_uni:
221 uni_port_no = field.port
Girish Gowdruab836e92018-10-25 01:17:57 -0700222 elif flow_direction == DOWNSTREAM:
223 for field in fd.get_ofb_fields(flow):
224 if field.type == fd.METADATA:
225 uni_port = field.table_metadata & 0xFFFFFFFF
226 is_uni, child_device_id = self._is_uni_port(uni_port)
227 if is_uni:
228 uni_port_no = field.port
229
230 if uni_port_no is None:
231 for action in fd.get_actions(flow):
232 if action.type == fd.OUTPUT:
233 is_uni, child_device_id = \
234 self._is_uni_port(action.output.port)
235 if is_uni:
236 uni_port_no = action.output.port
237
Girish Gowdrub761bc12018-11-29 02:22:18 -0800238 if child_device_id:
Girish Gowdruab836e92018-10-25 01:17:57 -0700239 child_device = self.adapter_agent.get_device(child_device_id)
240 pon_intf = child_device.proxy_address.channel_id
241 onu_id = child_device.proxy_address.onu_id
Craig Lutgenabd9c842018-11-15 23:58:27 +0000242 uni_id = self.platform.uni_id_from_port_num(uni_port_no) if uni_port_no is not None else None
243 flows = self.resource_mgr.get_flow_id_info(pon_intf, onu_id, uni_id, flow_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700244 assert (isinstance(flows, list))
245 self.log.debug("retrieved-flows", flows=flows)
246 for idx in range(len(flows)):
247 if flow_direction == flows[idx]['flow_type']:
248 flows.pop(idx)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000249 self.update_flow_info_to_kv_store(pon_intf, onu_id, uni_id, flow_id, flows)
Girish Gowdruab836e92018-10-25 01:17:57 -0700250 if len(flows) > 0:
251 # There are still flows referencing the same flow_id.
252 # So the flow should not be freed yet.
253 # For ex: Case of HSIA where same flow is shared
254 # between DS and US.
255 return
256
Craig Lutgenabd9c842018-11-15 23:58:27 +0000257 self.resource_mgr.free_flow_id_for_uni(pon_intf, onu_id, uni_id, flow_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700258 else:
259 self.log.error("invalid-info", uni_port_no=uni_port_no,
Girish Gowdruab836e92018-10-25 01:17:57 -0700260 child_device_id=child_device_id)
261
Scott Bakerbe5a9ea2018-11-19 19:24:21 -0800262 def retry_add_flow(self, flow):
263 self.log.debug("retry-add-flow")
264 if flow.id in self.retry_add_flow_list:
265 self.retry_add_flow_list.remove(flow.id)
266 self.add_flow(flow)
267
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400268 def remove_flow(self, flow):
269 self.log.debug('trying to remove flows from logical flow :',
Jonathan Hart5b435642018-08-20 08:50:05 -0700270 logical_flow=flow)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400271 device_flows_to_remove = []
272 device_flows = self.flows_proxy.get('/').items
273 for f in device_flows:
274 if f.cookie == flow.id:
275 device_flows_to_remove.append(f)
276
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400277 for f in device_flows_to_remove:
278 (id, direction) = self.decode_stored_id(f.id)
279 flow_to_remove = openolt_pb2.Flow(flow_id=id, flow_type=direction)
Nicolas Palpacuer3d0878d2018-08-17 11:29:42 -0400280 try:
281 self.stub.FlowRemove(flow_to_remove)
282 except grpc.RpcError as grpc_e:
283 if grpc_e.code() == grpc.StatusCode.NOT_FOUND:
284 self.log.debug('This flow does not exist on the switch, '
Jonathan Hart5b435642018-08-20 08:50:05 -0700285 'normal after an OLT reboot',
286 flow=flow_to_remove)
Nicolas Palpacuer3d0878d2018-08-17 11:29:42 -0400287 else:
288 raise grpc_e
289
Girish Gowdruab836e92018-10-25 01:17:57 -0700290 # once we have successfully deleted the flow on the device
291 # release the flow_id on resource pool and also clear any
292 # data associated with the flow_id on KV store.
293 self._clear_flow_id_from_rm(f, id, direction)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400294 self.log.debug('flow removed from device', flow=f,
295 flow_key=flow_to_remove)
296
297 if len(device_flows_to_remove) > 0:
298 new_flows = []
299 flows_ids_to_remove = [f.id for f in device_flows_to_remove]
300 for f in device_flows:
301 if f.id not in flows_ids_to_remove:
302 new_flows.append(f)
303
304 self.flows_proxy.update('/', Flows(items=new_flows))
305 self.log.debug('flows removed from the data store',
306 flow_ids_removed=flows_ids_to_remove,
307 number_of_flows_removed=(len(device_flows) - len(
308 new_flows)), expected_flows_removed=len(
Girish Gowdruab836e92018-10-25 01:17:57 -0700309 device_flows_to_remove))
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400310 else:
311 self.log.debug('no device flow to remove for this flow (normal '
312 'for multi table flows)', flow=flow)
313
Craig Lutgenabd9c842018-11-15 23:58:27 +0000314 def _get_ofp_port_name(self, intf_id, onu_id, uni_id):
Girish Gowdruab836e92018-10-25 01:17:57 -0700315 parent_port_no = self.platform.intf_id_to_port_no(intf_id, Port.PON_OLT)
316 child_device = self.adapter_agent.get_child_device(self.device_id,
317 parent_port_no=parent_port_no, onu_id=onu_id)
318 if child_device is None:
319 self.log.error("could-not-find-child-device",
320 parent_port_no=intf_id, onu_id=onu_id)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000321 return (None, None)
Girish Gowdruab836e92018-10-25 01:17:57 -0700322 ports = self.adapter_agent.get_ports(child_device.id, Port.ETHERNET_UNI)
323 logical_port = self.adapter_agent.get_logical_port(
Craig Lutgenabd9c842018-11-15 23:58:27 +0000324 self.logical_device_id, ports[uni_id].label)
325 ofp_port_name = (logical_port.ofp_port.name, logical_port.ofp_port.port_no)
Girish Gowdruab836e92018-10-25 01:17:57 -0700326 return ofp_port_name
327
Girish Gowdrub761bc12018-11-29 02:22:18 -0800328 def get_tp_path(self, intf_id, ofp_port_name):
329 # FIXME Should get Table id form the flow, as of now hardcoded to
330 # DEFAULT_TECH_PROFILE_TABLE_ID (64)
331 # 'tp_path' contains the suffix part of the tech_profile_instance path.
332 # The prefix to the 'tp_path' should be set to \
333 # TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX by the ONU adapter.
334 return self.tech_profile[intf_id]. \
335 get_tp_path(DEFAULT_TECH_PROFILE_TABLE_ID,
336 ofp_port_name)
337
338 def delete_tech_profile_instance(self, intf_id, onu_id, uni_id):
339 # Remove the TP instance associated with the ONU
340 ofp_port_name = self._get_ofp_port_name(intf_id, onu_id, uni_id)
341 tp_path = self.get_tp_path(intf_id, ofp_port_name)
342 return self.tech_profile[intf_id].delete_tech_profile_instance(tp_path)
343
Craig Lutgenabd9c842018-11-15 23:58:27 +0000344 def divide_and_add_flow(self, intf_id, onu_id, uni_id, port_no, classifier,
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400345 action, flow):
346
Craig Lutgenabd9c842018-11-15 23:58:27 +0000347 self.log.debug('sorting flow', intf_id=intf_id, onu_id=onu_id, uni_id=uni_id, port_no=port_no,
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400348 classifier=classifier, action=action)
349
Craig Lutgenabd9c842018-11-15 23:58:27 +0000350 alloc_id, gem_ports = self.create_tcont_gemport(intf_id, onu_id, uni_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700351 flow.table_id)
352 if alloc_id is None or gem_ports is None:
353 self.log.error("alloc-id-gem-ports-unavailable", alloc_id=alloc_id,
354 gem_ports=gem_ports)
355 return
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400356
Girish Gowdruab836e92018-10-25 01:17:57 -0700357 self.log.debug('Generated required alloc and gemport ids',
358 alloc_id=alloc_id, gemports=gem_ports)
359
360 # Flows can't be added specific to gemport unless p-bits are received.
361 # Hence adding flows for all gemports
362 for gemport_id in gem_ports:
363 if IP_PROTO in classifier:
364 if classifier[IP_PROTO] == 17:
365 self.log.debug('dhcp flow add')
Craig Lutgenabd9c842018-11-15 23:58:27 +0000366 self.add_dhcp_trap(intf_id, onu_id, uni_id, port_no, classifier,
Girish Gowdruab836e92018-10-25 01:17:57 -0700367 action, flow, alloc_id, gemport_id)
368 elif classifier[IP_PROTO] == 2:
369 self.log.warn('igmp flow add ignored, not implemented yet')
370 else:
371 self.log.warn("Invalid-Classifier-to-handle",
372 classifier=classifier,
373 action=action)
374 elif ETH_TYPE in classifier:
375 if classifier[ETH_TYPE] == EAP_ETH_TYPE:
376 self.log.debug('eapol flow add')
Craig Lutgenabd9c842018-11-15 23:58:27 +0000377 self.add_eapol_flow(intf_id, onu_id, uni_id, port_no, flow, alloc_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700378 gemport_id)
379 vlan_id = self.get_subscriber_vlan(fd.get_in_port(flow))
380 if vlan_id is not None:
381 self.add_eapol_flow(
Craig Lutgenabd9c842018-11-15 23:58:27 +0000382 intf_id, onu_id, uni_id, port_no, flow, alloc_id, gemport_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700383 vlan_id=vlan_id)
384 parent_port_no = self.platform.intf_id_to_port_no(intf_id, Port.PON_OLT)
385 onu_device = self.adapter_agent.get_child_device(self.device_id,
386 onu_id=onu_id,
387 parent_port_no=parent_port_no)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000388 (ofp_port_name, ofp_port_no) = self._get_ofp_port_name(intf_id, onu_id, uni_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700389 if ofp_port_name is None:
390 self.log.error("port-name-not-found")
391 return
392
Girish Gowdrub761bc12018-11-29 02:22:18 -0800393 tp_path = self.get_tp_path(intf_id, ofp_port_name)
Girish Gowdruab836e92018-10-25 01:17:57 -0700394
395 self.log.debug('Load-tech-profile-request-to-brcm-handler',
396 tp_path=tp_path)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000397 msg = {'proxy_address': onu_device.proxy_address, 'uni_id': uni_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700398 'event': 'download_tech_profile', 'event_data': tp_path}
399
400 # Send the event message to the ONU adapter
401 self.adapter_agent.publish_inter_adapter_message(onu_device.id,
402 msg)
403
404 if classifier[ETH_TYPE] == LLDP_ETH_TYPE:
405 self.log.debug('lldp flow add')
Craig Lutgenabd9c842018-11-15 23:58:27 +0000406 self.add_lldp_flow(flow, port_no)
Girish Gowdruab836e92018-10-25 01:17:57 -0700407
408 elif PUSH_VLAN in action:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000409 self.add_upstream_data_flow(intf_id, onu_id, uni_id, port_no, classifier,
Girish Gowdruab836e92018-10-25 01:17:57 -0700410 action, flow, alloc_id, gemport_id)
411 elif POP_VLAN in action:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000412 self.add_downstream_data_flow(intf_id, onu_id, uni_id, port_no, classifier,
Girish Gowdruab836e92018-10-25 01:17:57 -0700413 action, flow, alloc_id, gemport_id)
414 else:
415 self.log.debug('Invalid-flow-type-to-handle',
416 classifier=classifier,
417 action=action, flow=flow)
418
Craig Lutgenabd9c842018-11-15 23:58:27 +0000419 def create_tcont_gemport(self, intf_id, onu_id, uni_id, table_id):
Girish Gowdruab836e92018-10-25 01:17:57 -0700420 alloc_id, gem_port_ids = None, None
Girish Gowdrub761bc12018-11-29 02:22:18 -0800421 pon_intf_onu_id = (intf_id, onu_id)
422
423 # If we already have allocated alloc_id and gem_ports earlier, render them
424 alloc_id = \
425 self.resource_mgr.get_current_alloc_ids_for_onu(pon_intf_onu_id)
426 gem_port_ids = \
427 self.resource_mgr.get_current_gemport_ids_for_onu(pon_intf_onu_id)
428 if alloc_id is not None and gem_port_ids is not None:
429 return alloc_id, gem_port_ids
430
Girish Gowdruab836e92018-10-25 01:17:57 -0700431 try:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000432 (ofp_port_name, ofp_port_no) = self._get_ofp_port_name(intf_id, onu_id, uni_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700433 if ofp_port_name is None:
434 self.log.error("port-name-not-found")
435 return alloc_id, gem_port_ids
436 # FIXME: If table id is <= 63 using 64 as table id
437 if table_id < DEFAULT_TECH_PROFILE_TABLE_ID:
438 table_id = DEFAULT_TECH_PROFILE_TABLE_ID
439
440 # Check tech profile instance already exists for derived port name
441 tech_profile_instance = self.tech_profile[intf_id]. \
442 get_tech_profile_instance(table_id, ofp_port_name)
443 self.log.debug('Get-tech-profile-instance-status', tech_profile_instance=tech_profile_instance)
444
445 if tech_profile_instance is None:
446 # create tech profile instance
447 tech_profile_instance = self.tech_profile[intf_id]. \
448 create_tech_profile_instance(table_id, ofp_port_name,
449 intf_id)
Girish Gowdrub761bc12018-11-29 02:22:18 -0800450 if tech_profile_instance is None:
Girish Gowdruab836e92018-10-25 01:17:57 -0700451 raise Exception('Tech-profile-instance-creation-failed')
452 else:
453 self.log.debug(
454 'Tech-profile-instance-already-exist-for-given port-name',
455 ofp_port_name=ofp_port_name)
456
Girish Gowdrub761bc12018-11-29 02:22:18 -0800457 # upstream scheduler
458 us_scheduler = self.tech_profile[intf_id].get_us_scheduler(
459 tech_profile_instance)
460 # downstream scheduler
461 ds_scheduler = self.tech_profile[intf_id].get_ds_scheduler(
462 tech_profile_instance)
463 # create Tcont
464 tconts = self.tech_profile[intf_id].get_tconts(tech_profile_instance,
465 us_scheduler,
466 ds_scheduler)
467
468 self.stub.CreateTconts(openolt_pb2.Tconts(intf_id=intf_id,
469 onu_id=onu_id,
470 uni_id=uni_id,
471 port_no=ofp_port_no,
472 tconts=tconts))
473
Girish Gowdruab836e92018-10-25 01:17:57 -0700474 # Fetch alloc id and gemports from tech profile instance
475 alloc_id = tech_profile_instance.us_scheduler.alloc_id
476 gem_port_ids = []
477 for i in range(len(
478 tech_profile_instance.upstream_gem_port_attribute_list)):
479 gem_port_ids.append(
480 tech_profile_instance.upstream_gem_port_attribute_list[i].
Girish Gowdrub761bc12018-11-29 02:22:18 -0800481 gemport_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700482 except BaseException as e:
483 self.log.exception(exception=e)
484
Craig Lutgenabd9c842018-11-15 23:58:27 +0000485 # Update the allocated alloc_id and gem_port_id for the ONU/UNI to KV store
486 pon_intf_onu_id = (intf_id, onu_id, uni_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700487 self.resource_mgr.resource_mgrs[intf_id].update_alloc_ids_for_onu(
488 pon_intf_onu_id,
489 list([alloc_id])
490 )
491 self.resource_mgr.resource_mgrs[intf_id].update_gemport_ids_for_onu(
492 pon_intf_onu_id,
493 gem_port_ids
494 )
495
496 self.resource_mgr.update_gemports_ponport_to_onu_map_on_kv_store(
Craig Lutgenabd9c842018-11-15 23:58:27 +0000497 gem_port_ids, intf_id, onu_id, uni_id
Girish Gowdruab836e92018-10-25 01:17:57 -0700498 )
499
500 return alloc_id, gem_port_ids
Shad Ansari2dda4f32018-05-17 07:16:07 +0000501
Craig Lutgenabd9c842018-11-15 23:58:27 +0000502 def add_upstream_data_flow(self, intf_id, onu_id, uni_id, port_no, uplink_classifier,
Girish Gowdruab836e92018-10-25 01:17:57 -0700503 uplink_action, logical_flow, alloc_id,
504 gemport_id):
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400505
506 uplink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG
507
Craig Lutgenabd9c842018-11-15 23:58:27 +0000508 self.add_hsia_flow(intf_id, onu_id, uni_id, port_no, uplink_classifier,
Girish Gowdruab836e92018-10-25 01:17:57 -0700509 uplink_action, UPSTREAM,
510 logical_flow, alloc_id, gemport_id)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000511
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400512 # Secondary EAP on the subscriber vlan
Craig Lutgenabd9c842018-11-15 23:58:27 +0000513 (eap_active, eap_logical_flow) = self.is_eap_enabled(intf_id, onu_id, uni_id)
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400514 if eap_active:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000515 self.add_eapol_flow(intf_id, onu_id, uni_id, port_no, eap_logical_flow, alloc_id,
Girish Gowdrub761bc12018-11-29 02:22:18 -0800516 gemport_id, vlan_id=uplink_classifier[VLAN_VID])
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400517
Craig Lutgenabd9c842018-11-15 23:58:27 +0000518 def add_downstream_data_flow(self, intf_id, onu_id, uni_id, port_no, downlink_classifier,
Girish Gowdruab836e92018-10-25 01:17:57 -0700519 downlink_action, flow, alloc_id, gemport_id):
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400520 downlink_classifier[PACKET_TAG_TYPE] = DOUBLE_TAG
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400521 # Needed ???? It should be already there
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400522 downlink_action[POP_VLAN] = True
523 downlink_action[VLAN_VID] = downlink_classifier[VLAN_VID]
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400524
Craig Lutgenabd9c842018-11-15 23:58:27 +0000525 self.add_hsia_flow(intf_id, onu_id, uni_id, port_no, downlink_classifier,
Girish Gowdruab836e92018-10-25 01:17:57 -0700526 downlink_action, DOWNSTREAM,
527 flow, alloc_id, gemport_id)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400528
Craig Lutgenabd9c842018-11-15 23:58:27 +0000529 def add_hsia_flow(self, intf_id, onu_id, uni_id, port_no, classifier, action,
Girish Gowdruab836e92018-10-25 01:17:57 -0700530 direction, logical_flow, alloc_id, gemport_id):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000531
Girish Gowdrub761bc12018-11-29 02:22:18 -0800532 flow_store_cookie = self._get_flow_store_cookie(classifier,
533 gemport_id)
534
535 # One of the OLT platform (Broadcom BAL) requires that symmetric
536 # flows require the same flow_id to be used across UL and DL.
537 # Since HSIA flow is the only symmetric flow currently, we need to
538 # re-use the flow_id across both direction. The 'flow_category'
539 # takes priority over flow_cookie to find any available HSIA_FLOW
540 # id for the ONU.
541 flow_id = self.resource_mgr.get_flow_id(intf_id, onu_id, uni_id,
542 flow_store_cookie,
543 HSIA_FLOW)
Girish Gowdruab836e92018-10-25 01:17:57 -0700544 if flow_id is None:
545 self.log.error("hsia-flow-unavailable")
546 return
Shad Ansari2dda4f32018-05-17 07:16:07 +0000547
Shad Ansari2dda4f32018-05-17 07:16:07 +0000548 flow = openolt_pb2.Flow(
Craig Lutgenabd9c842018-11-15 23:58:27 +0000549 access_intf_id=intf_id, onu_id=onu_id, uni_id=uni_id, flow_id=flow_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700550 flow_type=direction, alloc_id=alloc_id, network_intf_id=0,
551 gemport_id=gemport_id,
552 classifier=self.mk_classifier(classifier),
553 action=self.mk_action(action),
Craig Lutgenabd9c842018-11-15 23:58:27 +0000554 priority=logical_flow.priority,
555 port_no=port_no,
556 cookie=logical_flow.cookie)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000557
Girish Gowdruab836e92018-10-25 01:17:57 -0700558 if self.add_flow_to_device(flow, logical_flow):
Girish Gowdrub761bc12018-11-29 02:22:18 -0800559 flow_info = self._get_flow_info_as_json_blob(flow,
560 flow_store_cookie,
561 HSIA_FLOW)
562 self.update_flow_info_to_kv_store(flow.access_intf_id,
563 flow.onu_id, flow.uni_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700564 flow.flow_id, flow_info)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000565
Craig Lutgenabd9c842018-11-15 23:58:27 +0000566 def add_dhcp_trap(self, intf_id, onu_id, uni_id, port_no, classifier, action, logical_flow,
Girish Gowdruab836e92018-10-25 01:17:57 -0700567 alloc_id, gemport_id):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000568
Shad Ansari47e0c392018-07-17 23:55:07 +0000569 self.log.debug('add dhcp upstream trap', classifier=classifier,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000570 intf_id=intf_id, onu_id=onu_id, uni_id=uni_id, action=action)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000571
572 action.clear()
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400573 action[TRAP_TO_HOST] = True
Girish Gowdruab836e92018-10-25 01:17:57 -0700574 classifier[UDP_SRC] = 68
575 classifier[UDP_DST] = 67
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400576 classifier[PACKET_TAG_TYPE] = SINGLE_TAG
577 classifier.pop(VLAN_VID, None)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000578
Girish Gowdrub761bc12018-11-29 02:22:18 -0800579 flow_store_cookie = self._get_flow_store_cookie(classifier,
580 gemport_id)
581
582 flow_id = self.resource_mgr.get_flow_id(
583 intf_id, onu_id, uni_id, flow_store_cookie
584 )
Shad Ansari2dda4f32018-05-17 07:16:07 +0000585
Matteo Scandolodf583282018-11-02 16:18:19 -0700586 dhcp_flow = openolt_pb2.Flow(
Craig Lutgenabd9c842018-11-15 23:58:27 +0000587 onu_id=onu_id, uni_id=uni_id, flow_id=flow_id, flow_type=UPSTREAM,
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400588 access_intf_id=intf_id, gemport_id=gemport_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700589 alloc_id=alloc_id, network_intf_id=0,
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400590 priority=logical_flow.priority,
591 classifier=self.mk_classifier(classifier),
Craig Lutgenabd9c842018-11-15 23:58:27 +0000592 action=self.mk_action(action),
593 port_no=port_no,
594 cookie=logical_flow.cookie)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000595
Girish Gowdruab836e92018-10-25 01:17:57 -0700596 if self.add_flow_to_device(dhcp_flow, logical_flow):
Girish Gowdrub761bc12018-11-29 02:22:18 -0800597 flow_info = self._get_flow_info_as_json_blob(dhcp_flow, flow_store_cookie)
Girish Gowdruab836e92018-10-25 01:17:57 -0700598 self.update_flow_info_to_kv_store(dhcp_flow.access_intf_id,
599 dhcp_flow.onu_id,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000600 dhcp_flow.uni_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700601 dhcp_flow.flow_id,
602 flow_info)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400603
Craig Lutgenabd9c842018-11-15 23:58:27 +0000604 def add_eapol_flow(self, intf_id, onu_id, uni_id, port_no, logical_flow, alloc_id,
Girish Gowdrub761bc12018-11-29 02:22:18 -0800605 gemport_id, vlan_id=DEFAULT_MGMT_VLAN):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000606
Girish Gowdruab836e92018-10-25 01:17:57 -0700607 uplink_classifier = dict()
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400608 uplink_classifier[ETH_TYPE] = EAP_ETH_TYPE
609 uplink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG
610 uplink_classifier[VLAN_VID] = vlan_id
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400611
Girish Gowdruab836e92018-10-25 01:17:57 -0700612 uplink_action = dict()
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400613 uplink_action[TRAP_TO_HOST] = True
Shad Ansari2dda4f32018-05-17 07:16:07 +0000614
Girish Gowdrub761bc12018-11-29 02:22:18 -0800615 flow_store_cookie = self._get_flow_store_cookie(uplink_classifier,
616 gemport_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700617 # Add Upstream EAPOL Flow.
Girish Gowdrub761bc12018-11-29 02:22:18 -0800618 uplink_flow_id = self.resource_mgr.get_flow_id(
619 intf_id, onu_id, uni_id, flow_store_cookie
620 )
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400621
Shad Ansari2dda4f32018-05-17 07:16:07 +0000622 upstream_flow = openolt_pb2.Flow(
Craig Lutgenabd9c842018-11-15 23:58:27 +0000623 access_intf_id=intf_id, onu_id=onu_id, uni_id=uni_id, flow_id=uplink_flow_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700624 flow_type=UPSTREAM, alloc_id=alloc_id, network_intf_id=0,
625 gemport_id=gemport_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000626 classifier=self.mk_classifier(uplink_classifier),
Girish Gowdruab836e92018-10-25 01:17:57 -0700627 action=self.mk_action(uplink_action),
Craig Lutgenabd9c842018-11-15 23:58:27 +0000628 priority=logical_flow.priority,
629 port_no=port_no,
630 cookie=logical_flow.cookie)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000631
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400632 logical_flow = copy.deepcopy(logical_flow)
633 logical_flow.match.oxm_fields.extend(fd.mk_oxm_fields([fd.vlan_vid(
634 vlan_id | 0x1000)]))
635 logical_flow.match.type = OFPMT_OXM
636
Girish Gowdruab836e92018-10-25 01:17:57 -0700637 if self.add_flow_to_device(upstream_flow, logical_flow):
Girish Gowdrub761bc12018-11-29 02:22:18 -0800638 flow_info = self._get_flow_info_as_json_blob(upstream_flow,
639 flow_store_cookie)
640 self.update_flow_info_to_kv_store(upstream_flow.access_intf_id,
641 upstream_flow.onu_id,
642 upstream_flow.uni_id,
643 upstream_flow.flow_id,
644 flow_info)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000645
Nicolas Palpacuer6152a322018-09-05 10:52:15 -0400646 if vlan_id == DEFAULT_MGMT_VLAN:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400647 # Add Downstream EAPOL Flow, Only for first EAP flow (BAL
648 # requirement)
Girish Gowdrub761bc12018-11-29 02:22:18 -0800649 # On one of the platforms (Broadcom BAL), when same DL classifier
650 # vlan was used across multiple ONUs, eapol flow re-adds after
651 # flow delete (cases of onu reboot/disable) fails.
652 # In order to generate unique vlan, a combination of intf_id
653 # onu_id and uni_id is used.
654 # uni_id defaults to 0, so add 1 to it.
655 special_vlan_downstream_flow = 4090 - intf_id * onu_id * (uni_id+1)
656 # Assert that we do not generate invalid vlans under no condition
657 assert (special_vlan_downstream_flow >= 2, 'invalid-vlan-generated')
Shad Ansari2dda4f32018-05-17 07:16:07 +0000658
Girish Gowdruab836e92018-10-25 01:17:57 -0700659 downlink_classifier = dict()
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400660 downlink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG
661 downlink_classifier[VLAN_VID] = special_vlan_downstream_flow
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400662
Girish Gowdruab836e92018-10-25 01:17:57 -0700663 downlink_action = dict()
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400664 downlink_action[PUSH_VLAN] = True
665 downlink_action[VLAN_VID] = vlan_id
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400666
Girish Gowdrub761bc12018-11-29 02:22:18 -0800667
668 flow_store_cookie = self._get_flow_store_cookie(downlink_classifier,
669 gemport_id)
670
671 downlink_flow_id = self.resource_mgr.get_flow_id(
672 intf_id, onu_id, uni_id, flow_store_cookie
673 )
Nicolas Palpacuer6152a322018-09-05 10:52:15 -0400674
675 downstream_flow = openolt_pb2.Flow(
Craig Lutgenabd9c842018-11-15 23:58:27 +0000676 access_intf_id=intf_id, onu_id=onu_id, uni_id=uni_id, flow_id=downlink_flow_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700677 flow_type=DOWNSTREAM, alloc_id=alloc_id, network_intf_id=0,
678 gemport_id=gemport_id,
Nicolas Palpacuer6152a322018-09-05 10:52:15 -0400679 classifier=self.mk_classifier(downlink_classifier),
Girish Gowdruab836e92018-10-25 01:17:57 -0700680 action=self.mk_action(downlink_action),
Craig Lutgenabd9c842018-11-15 23:58:27 +0000681 priority=logical_flow.priority,
682 port_no=port_no,
683 cookie=logical_flow.cookie)
Nicolas Palpacuer6152a322018-09-05 10:52:15 -0400684
Shad Ansarifd0111d2018-09-13 21:33:06 +0000685 downstream_logical_flow = ofp_flow_stats(
686 id=logical_flow.id, cookie=logical_flow.cookie,
687 table_id=logical_flow.table_id, priority=logical_flow.priority,
688 flags=logical_flow.flags)
Nicolas Palpacuer6152a322018-09-05 10:52:15 -0400689
690 downstream_logical_flow.match.oxm_fields.extend(fd.mk_oxm_fields([
691 fd.in_port(fd.get_out_port(logical_flow)),
Girish Gowdruab836e92018-10-25 01:17:57 -0700692 fd.vlan_vid(special_vlan_downstream_flow | 0x1000)]))
Nicolas Palpacuer6152a322018-09-05 10:52:15 -0400693 downstream_logical_flow.match.type = OFPMT_OXM
694
695 downstream_logical_flow.instructions.extend(
696 fd.mk_instructions_from_actions([fd.output(
Craig Lutgenabd9c842018-11-15 23:58:27 +0000697 self.platform.mk_uni_port_num(intf_id, onu_id, uni_id))]))
Nicolas Palpacuer6152a322018-09-05 10:52:15 -0400698
Girish Gowdruab836e92018-10-25 01:17:57 -0700699 if self.add_flow_to_device(downstream_flow, downstream_logical_flow):
700 flow_info = self._get_flow_info_as_json_blob(downstream_flow,
Girish Gowdrub761bc12018-11-29 02:22:18 -0800701 flow_store_cookie)
Girish Gowdruab836e92018-10-25 01:17:57 -0700702 self.update_flow_info_to_kv_store(downstream_flow.access_intf_id,
703 downstream_flow.onu_id,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000704 downstream_flow.uni_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700705 downstream_flow.flow_id,
706 flow_info)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400707
Nicolas Palpacuer41141352018-08-31 14:11:38 -0400708 def repush_all_different_flows(self):
709 # Check if the device is supposed to have flows, if so add them
710 # Recover static flows after a reboot
711 logical_flows = self.logical_flows_proxy.get('/').items
712 devices_flows = self.flows_proxy.get('/').items
713 logical_flows_ids_provisioned = [f.cookie for f in devices_flows]
714 for logical_flow in logical_flows:
715 try:
716 if logical_flow.id not in logical_flows_ids_provisioned:
717 self.add_flow(logical_flow)
718 except Exception as e:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000719 self.log.exception('Problem reading this flow', e=e)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400720
Nicolas Palpacuer41141352018-08-31 14:11:38 -0400721 def reset_flows(self):
722 self.flows_proxy.update('/', Flows())
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400723
Shad Ansarifd0111d2018-09-13 21:33:06 +0000724 """ Add a downstream LLDP trap flow on the NNI interface
725 """
Girish Gowdruab836e92018-10-25 01:17:57 -0700726
Craig Lutgenabd9c842018-11-15 23:58:27 +0000727 def add_lldp_flow(self, logical_flow, port_no, network_intf_id=0):
Jonathan Hart5b435642018-08-20 08:50:05 -0700728
Girish Gowdruab836e92018-10-25 01:17:57 -0700729 classifier = dict()
Shad Ansarifd0111d2018-09-13 21:33:06 +0000730 classifier[ETH_TYPE] = LLDP_ETH_TYPE
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400731 classifier[PACKET_TAG_TYPE] = UNTAGGED
Girish Gowdruab836e92018-10-25 01:17:57 -0700732 action = dict()
Shad Ansarifd0111d2018-09-13 21:33:06 +0000733 action[TRAP_TO_HOST] = True
Jonathan Hart5b435642018-08-20 08:50:05 -0700734
Girish Gowdruab836e92018-10-25 01:17:57 -0700735 # LLDP flow is installed to trap LLDP packets on the NNI port.
736 # We manage flow_id resource pool on per PON port basis.
737 # Since this situation is tricky, as a hack, we pass the NNI port
738 # index (network_intf_id) as PON port Index for the flow_id resource
739 # pool. Also, there is no ONU Id available for trapping LLDP packets
740 # on NNI port, use onu_id as -1 (invalid)
741 # ****************** CAVEAT *******************
742 # This logic works if the NNI Port Id falls within the same valid
743 # range of PON Port Ids. If this doesn't work for some OLT Vendor
744 # we need to have a re-look at this.
745 # *********************************************
746 onu_id = -1
Craig Lutgenabd9c842018-11-15 23:58:27 +0000747 uni_id = -1
Girish Gowdrub761bc12018-11-29 02:22:18 -0800748 flow_store_cookie = self._get_flow_store_cookie(classifier)
749 flow_id = self.resource_mgr.get_flow_id(network_intf_id, onu_id, uni_id,
750 flow_store_cookie)
Jonathan Hart5b435642018-08-20 08:50:05 -0700751
752 downstream_flow = openolt_pb2.Flow(
Shad Ansarifd0111d2018-09-13 21:33:06 +0000753 access_intf_id=-1, # access_intf_id not required
Craig Lutgenabd9c842018-11-15 23:58:27 +0000754 onu_id=onu_id, # onu_id not required
755 uni_id=uni_id, # uni_id not used
Shad Ansarifd0111d2018-09-13 21:33:06 +0000756 flow_id=flow_id,
757 flow_type=DOWNSTREAM,
Shad Ansarifd0111d2018-09-13 21:33:06 +0000758 network_intf_id=network_intf_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700759 gemport_id=-1, # gemport_id not required
Jonathan Hart5b435642018-08-20 08:50:05 -0700760 classifier=self.mk_classifier(classifier),
Girish Gowdruab836e92018-10-25 01:17:57 -0700761 action=self.mk_action(action),
Craig Lutgenabd9c842018-11-15 23:58:27 +0000762 priority=logical_flow.priority,
763 port_no=port_no,
764 cookie=logical_flow.cookie)
Jonathan Hart5b435642018-08-20 08:50:05 -0700765
Shad Ansarifd0111d2018-09-13 21:33:06 +0000766 self.log.debug('add lldp downstream trap', classifier=classifier,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000767 action=action, flow=downstream_flow, port_no=port_no)
Girish Gowdruab836e92018-10-25 01:17:57 -0700768 if self.add_flow_to_device(downstream_flow, logical_flow):
Craig Lutgenabd9c842018-11-15 23:58:27 +0000769 self.update_flow_info_to_kv_store(network_intf_id, onu_id, uni_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700770 flow_id, downstream_flow)
Jonathan Hart5b435642018-08-20 08:50:05 -0700771
Shad Ansari2dda4f32018-05-17 07:16:07 +0000772 def mk_classifier(self, classifier_info):
773
774 classifier = openolt_pb2.Classifier()
775
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400776 if ETH_TYPE in classifier_info:
777 classifier.eth_type = classifier_info[ETH_TYPE]
778 if IP_PROTO in classifier_info:
779 classifier.ip_proto = classifier_info[IP_PROTO]
780 if VLAN_VID in classifier_info:
781 classifier.o_vid = classifier_info[VLAN_VID]
782 if METADATA in classifier_info:
783 classifier.i_vid = classifier_info[METADATA]
784 if VLAN_PCP in classifier_info:
785 classifier.o_pbits = classifier_info[VLAN_PCP]
786 if UDP_SRC in classifier_info:
787 classifier.src_port = classifier_info[UDP_SRC]
788 if UDP_DST in classifier_info:
789 classifier.dst_port = classifier_info[UDP_DST]
790 if IPV4_DST in classifier_info:
791 classifier.dst_ip = classifier_info[IPV4_DST]
792 if IPV4_SRC in classifier_info:
793 classifier.src_ip = classifier_info[IPV4_SRC]
794 if PACKET_TAG_TYPE in classifier_info:
795 if classifier_info[PACKET_TAG_TYPE] == SINGLE_TAG:
796 classifier.pkt_tag_type = SINGLE_TAG
797 elif classifier_info[PACKET_TAG_TYPE] == DOUBLE_TAG:
798 classifier.pkt_tag_type = DOUBLE_TAG
799 elif classifier_info[PACKET_TAG_TYPE] == UNTAGGED:
800 classifier.pkt_tag_type = UNTAGGED
Shad Ansari2dda4f32018-05-17 07:16:07 +0000801 else:
802 classifier.pkt_tag_type = 'none'
803
804 return classifier
805
806 def mk_action(self, action_info):
807 action = openolt_pb2.Action()
808
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400809 if POP_VLAN in action_info:
810 action.o_vid = action_info[VLAN_VID]
Shad Ansari2dda4f32018-05-17 07:16:07 +0000811 action.cmd.remove_outer_tag = True
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400812 elif PUSH_VLAN in action_info:
813 action.o_vid = action_info[VLAN_VID]
Shad Ansari2dda4f32018-05-17 07:16:07 +0000814 action.cmd.add_outer_tag = True
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400815 elif TRAP_TO_HOST in action_info:
Shad Ansari2dda4f32018-05-17 07:16:07 +0000816 action.cmd.trap_to_host = True
Shad Ansarif9d2d102018-06-13 02:15:26 +0000817 else:
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400818 self.log.info('Invalid-action-field', action_info=action_info)
Shad Ansarif9d2d102018-06-13 02:15:26 +0000819 return
Shad Ansari2dda4f32018-05-17 07:16:07 +0000820 return action
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400821
Craig Lutgenabd9c842018-11-15 23:58:27 +0000822 def is_eap_enabled(self, intf_id, onu_id, uni_id):
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400823 flows = self.logical_flows_proxy.get('/').items
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400824
825 for flow in flows:
826 eap_flow = False
827 eap_intf_id = None
828 eap_onu_id = None
Craig Lutgenabd9c842018-11-15 23:58:27 +0000829 eap_uni_id = None
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400830 for field in fd.get_ofb_fields(flow):
831 if field.type == fd.ETH_TYPE:
832 if field.eth_type == EAP_ETH_TYPE:
833 eap_flow = True
834 if field.type == fd.IN_PORT:
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000835 eap_intf_id = self.platform.intf_id_from_uni_port_num(
Shad Ansari47e0c392018-07-17 23:55:07 +0000836 field.port)
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000837 eap_onu_id = self.platform.onu_id_from_port_num(field.port)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000838 eap_uni_id = self.platform.uni_id_from_port_num(field.port)
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400839
840 if eap_flow:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000841 self.log.debug('eap flow detected', onu_id=onu_id, uni_id=uni_id,
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400842 intf_id=intf_id, eap_intf_id=eap_intf_id,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000843 eap_onu_id=eap_onu_id,
844 eap_uni_id=eap_uni_id)
845 if eap_flow and intf_id == eap_intf_id and onu_id == eap_onu_id and uni_id == eap_uni_id:
Girish Gowdruab836e92018-10-25 01:17:57 -0700846 return True, flow
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400847
Girish Gowdruab836e92018-10-25 01:17:57 -0700848 return False, None
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400849
Nicolas Palpacuer41141352018-08-31 14:11:38 -0400850 def get_subscriber_vlan(self, port):
851 self.log.debug('looking from subscriber flow for port', port=port)
852
853 flows = self.logical_flows_proxy.get('/').items
854 for flow in flows:
855 in_port = fd.get_in_port(flow)
856 out_port = fd.get_out_port(flow)
Girish Gowdrub761bc12018-11-29 02:22:18 -0800857 if in_port == port and out_port is not None and \
Girish Gowdruab836e92018-10-25 01:17:57 -0700858 self.platform.intf_id_to_port_type_name(out_port) \
Shad Ansarifd0111d2018-09-13 21:33:06 +0000859 == Port.ETHERNET_NNI:
Nicolas Palpacuer41141352018-08-31 14:11:38 -0400860 fields = fd.get_ofb_fields(flow)
861 self.log.debug('subscriber flow found', fields=fields)
862 for field in fields:
863 if field.type == OFPXMT_OFB_VLAN_VID:
864 self.log.debug('subscriber vlan found',
865 vlan_id=field.vlan_vid)
866 return field.vlan_vid & 0x0fff
867 self.log.debug('No subscriber flow found', port=port)
868 return None
869
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400870 def add_flow_to_device(self, flow, logical_flow):
871 self.log.debug('pushing flow to device', flow=flow)
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400872 try:
873 self.stub.FlowAdd(flow)
874 except grpc.RpcError as grpc_e:
875 if grpc_e.code() == grpc.StatusCode.ALREADY_EXISTS:
876 self.log.warn('flow already exists', e=grpc_e, flow=flow)
877 else:
878 self.log.error('failed to add flow',
879 logical_flow=logical_flow, flow=flow,
880 grpc_error=grpc_e)
Girish Gowdruab836e92018-10-25 01:17:57 -0700881 return False
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400882 else:
883 self.register_flow(logical_flow, flow)
Girish Gowdruab836e92018-10-25 01:17:57 -0700884 return True
885
Craig Lutgenabd9c842018-11-15 23:58:27 +0000886 def update_flow_info_to_kv_store(self, intf_id, onu_id, uni_id, flow_id, flow):
887 self.resource_mgr.update_flow_id_info_for_uni(intf_id, onu_id, uni_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700888 flow_id, flow)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400889
890 def register_flow(self, logical_flow, device_flow):
891 self.log.debug('registering flow in device',
892 logical_flow=logical_flow, device_flow=device_flow)
893 stored_flow = copy.deepcopy(logical_flow)
894 stored_flow.id = self.generate_stored_id(device_flow.flow_id,
895 device_flow.flow_type)
896 self.log.debug('generated device flow id', id=stored_flow.id,
897 flow_id=device_flow.flow_id,
898 direction=device_flow.flow_type)
899 stored_flow.cookie = logical_flow.id
900 flows = self.flows_proxy.get('/')
901 flows.items.extend([stored_flow])
902 self.flows_proxy.update('/', flows)
903
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400904 def find_next_flow(self, flow):
905 table_id = fd.get_goto_table_id(flow)
906 metadata = 0
Chip Boling41f795a2018-10-04 15:45:34 -0500907 # Prior to ONOS 1.13.5, Metadata contained the UNI output port number. In
908 # 1.13.5 and later, the lower 32-bits is the output port number and the
909 # upper 32-bits is the inner-vid we are looking for. Use just the lower 32
910 # bits. Allows this code to work with pre- and post-1.13.5 ONOS OltPipeline
911
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400912 for field in fd.get_ofb_fields(flow):
913 if field.type == fd.METADATA:
Chip Boling41f795a2018-10-04 15:45:34 -0500914 metadata = field.table_metadata & 0xFFFFFFFF
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400915 if table_id is None:
916 return None
917 flows = self.logical_flows_proxy.get('/').items
918 next_flows = []
919 for f in flows:
920 if f.table_id == table_id:
Jonathan Hart5b435642018-08-20 08:50:05 -0700921 # FIXME
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400922 if fd.get_in_port(f) == fd.get_in_port(flow) and \
923 fd.get_out_port(f) == metadata:
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400924 next_flows.append(f)
925
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400926 if len(next_flows) == 0:
927 self.log.warning('no next flow found, it may be a timing issue',
928 flow=flow, number_of_flows=len(flows))
Scott Bakerbe5a9ea2018-11-19 19:24:21 -0800929 if flow.id in self.retry_add_flow_list:
930 self.log.debug('flow is already in retry list', flow_id=flow.id)
931 else:
932 self.retry_add_flow_list.append(flow.id)
933 reactor.callLater(5, self.retry_add_flow, flow)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400934 return None
935
Jonathan Hart5b435642018-08-20 08:50:05 -0700936 next_flows.sort(key=lambda f: f.priority, reverse=True)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400937
938 return next_flows[0]
939
940 def update_children_flows(self, device_rules_map):
941
942 for device_id, (flows, groups) in device_rules_map.iteritems():
943 if device_id != self.device_id:
944 self.root_proxy.update('/devices/{}/flows'.format(device_id),
945 Flows(items=flows.values()))
946 self.root_proxy.update('/devices/{}/flow_groups'.format(
947 device_id), FlowGroups(items=groups.values()))
948
Girish Gowdruab836e92018-10-25 01:17:57 -0700949 def clear_flows_and_scheduler_for_logical_port(self, child_device, logical_port):
950 ofp_port_name = logical_port.ofp_port.name
Craig Lutgenabd9c842018-11-15 23:58:27 +0000951 port_no = logical_port.ofp_port.port_no
Girish Gowdruab836e92018-10-25 01:17:57 -0700952 pon_port = child_device.proxy_address.channel_id
953 onu_id = child_device.proxy_address.onu_id
Craig Lutgenabd9c842018-11-15 23:58:27 +0000954 uni_id = self.platform.uni_id_from_port_num(logical_port)
955
Girish Gowdruab836e92018-10-25 01:17:57 -0700956 # TODO: The DEFAULT_TECH_PROFILE_ID is assumed. Right way to do,
957 # is probably to maintain a list of Tech-profile table IDs associated
958 # with the UNI logical_port. This way, when the logical port is deleted,
959 # all the associated tech-profile configuration with the UNI logical_port
960 # can be cleared.
961 tech_profile_instance = self.tech_profile[pon_port]. \
962 get_tech_profile_instance(
963 DEFAULT_TECH_PROFILE_TABLE_ID,
964 ofp_port_name)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000965 flow_ids = self.resource_mgr.get_current_flow_ids_for_uni(pon_port, onu_id, uni_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700966 self.log.debug("outstanding-flows-to-be-cleared", flow_ids=flow_ids)
967 for flow_id in flow_ids:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000968 flow_infos = self.resource_mgr.get_flow_id_info(pon_port, onu_id, uni_id, flow_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700969 for flow_info in flow_infos:
970 direction = flow_info['flow_type']
971 flow_to_remove = openolt_pb2.Flow(flow_id=flow_id,
972 flow_type=direction)
973 try:
974 self.stub.FlowRemove(flow_to_remove)
975 except grpc.RpcError as grpc_e:
976 if grpc_e.code() == grpc.StatusCode.NOT_FOUND:
977 self.log.debug('This flow does not exist on the switch, '
978 'normal after an OLT reboot',
979 flow=flow_to_remove)
980 else:
981 raise grpc_e
982
Craig Lutgenabd9c842018-11-15 23:58:27 +0000983 self.resource_mgr.free_flow_id_for_uni(pon_port, onu_id, uni_id, flow_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700984
985 try:
986 tconts = self.tech_profile[pon_port].get_tconts(tech_profile_instance)
987 self.stub.RemoveTconts(openolt_pb2.Tconts(intf_id=pon_port,
988 onu_id=onu_id,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000989 uni_id=uni_id,
990 port_no=port_no,
Girish Gowdruab836e92018-10-25 01:17:57 -0700991 tconts=tconts))
992 except grpc.RpcError as grpc_e:
993 self.log.error('error-removing-tcont-scheduler-queues',
994 err=grpc_e)
995
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400996 def generate_stored_id(self, flow_id, direction):
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400997 if direction == UPSTREAM:
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400998 self.log.debug('upstream flow, shifting id')
999 return 0x1 << 15 | flow_id
Nicolas Palpacuer2789f042018-09-17 09:10:29 -04001000 elif direction == DOWNSTREAM:
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001001 self.log.debug('downstream flow, not shifting id')
1002 return flow_id
1003 else:
1004 self.log.warn('Unrecognized direction', direction=direction)
1005 return flow_id
1006
1007 def decode_stored_id(self, id):
1008 if id >> 15 == 0x1:
Girish Gowdruab836e92018-10-25 01:17:57 -07001009 return id & 0x7fff, UPSTREAM
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -04001010 else:
Girish Gowdruab836e92018-10-25 01:17:57 -07001011 return id, DOWNSTREAM
1012
1013 def _populate_tech_profile_per_pon_port(self):
1014 for arange in self.resource_mgr.device_info.ranges:
1015 for intf_id in arange.intf_ids:
1016 self.tech_profile[intf_id] = \
1017 self.resource_mgr.resource_mgrs[intf_id].tech_profile
1018
1019 # Make sure we have as many tech_profiles as there are pon ports on
1020 # the device
1021 assert len(self.tech_profile) == self.resource_mgr.device_info.pon_ports
1022
Girish Gowdrub761bc12018-11-29 02:22:18 -08001023 def _get_flow_info_as_json_blob(self, flow, flow_store_cookie,
1024 flow_category=None):
Girish Gowdruab836e92018-10-25 01:17:57 -07001025 json_blob = MessageToDict(message=flow,
1026 preserving_proto_field_name=True)
1027 self.log.debug("flow-info", json_blob=json_blob)
Girish Gowdrub761bc12018-11-29 02:22:18 -08001028 json_blob['flow_store_cookie'] = flow_store_cookie
1029 if flow_category is not None:
1030 json_blob['flow_category'] = flow_category
Girish Gowdruab836e92018-10-25 01:17:57 -07001031 flow_info = self.resource_mgr.get_flow_id_info(flow.access_intf_id,
Craig Lutgenabd9c842018-11-15 23:58:27 +00001032 flow.onu_id, flow.uni_id, flow.flow_id)
Girish Gowdruab836e92018-10-25 01:17:57 -07001033
1034 if flow_info is None:
1035 flow_info = list()
1036 flow_info.append(json_blob)
1037 else:
1038 assert (isinstance(flow_info, list))
1039 flow_info.append(json_blob)
1040
1041 return flow_info
Girish Gowdrub761bc12018-11-29 02:22:18 -08001042
1043 @staticmethod
1044 def _get_flow_store_cookie(classifier, gem_port=None):
1045 assert isinstance(classifier, dict)
1046 # We need unique flows per gem_port
1047 if gem_port is not None:
1048 to_hash = dumps(classifier, sort_keys=True) + str(gem_port)
1049 else:
1050 to_hash = dumps(classifier, sort_keys=True)
1051 return hashlib.md5(to_hash).hexdigest()[:12]