blob: 3b08edcbb0b903d559e7b20de14332898dfb9b92 [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()
Shad Ansari2dda4f32018-05-17 07:16:07 +000089
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -040090 def add_flow(self, flow):
91 self.log.debug('add flow', flow=flow)
Shad Ansari2dda4f32018-05-17 07:16:07 +000092 classifier_info = dict()
93 action_info = dict()
94
Shad Ansari2dda4f32018-05-17 07:16:07 +000095 for field in fd.get_ofb_fields(flow):
96 if field.type == fd.ETH_TYPE:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -040097 classifier_info[ETH_TYPE] = field.eth_type
Shad Ansarie048aaa2018-05-18 18:27:21 +000098 self.log.debug('field-type-eth-type',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -040099 eth_type=classifier_info[ETH_TYPE])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000100 elif field.type == fd.IP_PROTO:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400101 classifier_info[IP_PROTO] = field.ip_proto
Shad Ansarie048aaa2018-05-18 18:27:21 +0000102 self.log.debug('field-type-ip-proto',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400103 ip_proto=classifier_info[IP_PROTO])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000104 elif field.type == fd.IN_PORT:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400105 classifier_info[IN_PORT] = field.port
Shad Ansarie048aaa2018-05-18 18:27:21 +0000106 self.log.debug('field-type-in-port',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400107 in_port=classifier_info[IN_PORT])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000108 elif field.type == fd.VLAN_VID:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400109 classifier_info[VLAN_VID] = field.vlan_vid & 0xfff
Shad Ansarie048aaa2018-05-18 18:27:21 +0000110 self.log.debug('field-type-vlan-vid',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400111 vlan=classifier_info[VLAN_VID])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000112 elif field.type == fd.VLAN_PCP:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400113 classifier_info[VLAN_PCP] = field.vlan_pcp
Shad Ansarie048aaa2018-05-18 18:27:21 +0000114 self.log.debug('field-type-vlan-pcp',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400115 pcp=classifier_info[VLAN_PCP])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000116 elif field.type == fd.UDP_DST:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400117 classifier_info[UDP_DST] = field.udp_dst
Shad Ansarie048aaa2018-05-18 18:27:21 +0000118 self.log.debug('field-type-udp-dst',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400119 udp_dst=classifier_info[UDP_DST])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000120 elif field.type == fd.UDP_SRC:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400121 classifier_info[UDP_SRC] = field.udp_src
Shad Ansarie048aaa2018-05-18 18:27:21 +0000122 self.log.debug('field-type-udp-src',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400123 udp_src=classifier_info[UDP_SRC])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000124 elif field.type == fd.IPV4_DST:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400125 classifier_info[IPV4_DST] = field.ipv4_dst
Shad Ansarie048aaa2018-05-18 18:27:21 +0000126 self.log.debug('field-type-ipv4-dst',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400127 ipv4_dst=classifier_info[IPV4_DST])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000128 elif field.type == fd.IPV4_SRC:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400129 classifier_info[IPV4_SRC] = field.ipv4_src
Shad Ansarie048aaa2018-05-18 18:27:21 +0000130 self.log.debug('field-type-ipv4-src',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400131 ipv4_dst=classifier_info[IPV4_SRC])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000132 elif field.type == fd.METADATA:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400133 classifier_info[METADATA] = field.table_metadata
Shad Ansarie048aaa2018-05-18 18:27:21 +0000134 self.log.debug('field-type-metadata',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400135 metadata=classifier_info[METADATA])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000136 else:
137 raise NotImplementedError('field.type={}'.format(
138 field.type))
139
140 for action in fd.get_actions(flow):
141 if action.type == fd.OUTPUT:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400142 action_info[OUTPUT] = action.output.port
Shad Ansarie048aaa2018-05-18 18:27:21 +0000143 self.log.debug('action-type-output',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400144 output=action_info[OUTPUT],
145 in_port=classifier_info[IN_PORT])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000146 elif action.type == fd.POP_VLAN:
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400147 if fd.get_goto_table_id(flow) is None:
148 self.log.debug('being taken care of by ONU', flow=flow)
149 return
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400150 action_info[POP_VLAN] = True
Jonathan Hart5b435642018-08-20 08:50:05 -0700151 self.log.debug('action-type-pop-vlan',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400152 in_port=classifier_info[IN_PORT])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000153 elif action.type == fd.PUSH_VLAN:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400154 action_info[PUSH_VLAN] = True
155 action_info[TPID] = action.push.ethertype
Shad Ansarie048aaa2018-05-18 18:27:21 +0000156 self.log.debug('action-type-push-vlan',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400157 push_tpid=action_info[TPID], in_port=classifier_info[IN_PORT])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000158 if action.push.ethertype != 0x8100:
159 self.log.error('unhandled-tpid',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000160 ethertype=action.push.ethertype)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000161 elif action.type == fd.SET_FIELD:
162 # action_info['action_type'] = 'set_field'
163 _field = action.set_field.field.ofb_field
164 assert (action.set_field.field.oxm_class ==
165 OFPXMC_OPENFLOW_BASIC)
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400166 self.log.debug('action-type-set-field',
167 field=_field, in_port=classifier_info[IN_PORT])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000168 if _field.type == fd.VLAN_VID:
Shad Ansarie048aaa2018-05-18 18:27:21 +0000169 self.log.debug('set-field-type-vlan-vid',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000170 vlan_vid=_field.vlan_vid & 0xfff)
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400171 action_info[VLAN_VID] = (_field.vlan_vid & 0xfff)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000172 else:
173 self.log.error('unsupported-action-set-field-type',
Shad Ansarif9d2d102018-06-13 02:15:26 +0000174 field_type=_field.type)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000175 else:
176 self.log.error('unsupported-action-type',
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400177 action_type=action.type, in_port=classifier_info[IN_PORT])
Shad Ansari2dda4f32018-05-17 07:16:07 +0000178
Girish Gowdruab836e92018-10-25 01:17:57 -0700179 if fd.get_goto_table_id(flow) is not None and POP_VLAN not in action_info:
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400180 self.log.debug('being taken care of by ONU', flow=flow)
Nicolas Palpacuer856d3af2018-09-12 15:04:51 -0400181 return
Shad Ansari2dda4f32018-05-17 07:16:07 +0000182
Girish Gowdruab836e92018-10-25 01:17:57 -0700183 if OUTPUT not in action_info and METADATA in classifier_info:
184 # find flow in the next table
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400185 next_flow = self.find_next_flow(flow)
186 if next_flow is None:
187 return
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400188 action_info[OUTPUT] = fd.get_out_port(next_flow)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400189 for field in fd.get_ofb_fields(next_flow):
190 if field.type == fd.VLAN_VID:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400191 classifier_info[METADATA] = field.vlan_vid & 0xfff
192
Craig Lutgenabd9c842018-11-15 23:58:27 +0000193 self.log.debug('flow-ports', classifier_inport=classifier_info[IN_PORT], action_output=action_info[OUTPUT])
194 (port_no, intf_id, onu_id, uni_id) = self.platform.extract_access_from_flow(
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400195 classifier_info[IN_PORT], action_info[OUTPUT])
196
Craig Lutgenabd9c842018-11-15 23:58:27 +0000197 self.divide_and_add_flow(intf_id, onu_id, uni_id, port_no, classifier_info,
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400198 action_info, flow)
199
Girish Gowdruab836e92018-10-25 01:17:57 -0700200 def _is_uni_port(self, port_no):
201 try:
202 port = self.adapter_agent.get_logical_port(self.logical_device_id,
203 'uni-{}'.format(port_no))
204 if port is not None:
205 return (not port.root_port), port.device_id
206 else:
207 return False, None
208 except Exception as e:
209 self.log.error("error-retrieving-port", e=e)
210 return False, None
211
212 def _clear_flow_id_from_rm(self, flow, flow_id, flow_direction):
213 uni_port_no = None
Girish Gowdruab836e92018-10-25 01:17:57 -0700214 child_device_id = None
215 if flow_direction == UPSTREAM:
216 for field in fd.get_ofb_fields(flow):
217 if field.type == fd.IN_PORT:
218 is_uni, child_device_id = self._is_uni_port(field.port)
219 if is_uni:
220 uni_port_no = field.port
Girish Gowdruab836e92018-10-25 01:17:57 -0700221 elif flow_direction == DOWNSTREAM:
222 for field in fd.get_ofb_fields(flow):
223 if field.type == fd.METADATA:
224 uni_port = field.table_metadata & 0xFFFFFFFF
225 is_uni, child_device_id = self._is_uni_port(uni_port)
226 if is_uni:
227 uni_port_no = field.port
228
229 if uni_port_no is None:
230 for action in fd.get_actions(flow):
231 if action.type == fd.OUTPUT:
232 is_uni, child_device_id = \
233 self._is_uni_port(action.output.port)
234 if is_uni:
235 uni_port_no = action.output.port
236
Girish Gowdrub761bc12018-11-29 02:22:18 -0800237 if child_device_id:
Girish Gowdruab836e92018-10-25 01:17:57 -0700238 child_device = self.adapter_agent.get_device(child_device_id)
239 pon_intf = child_device.proxy_address.channel_id
240 onu_id = child_device.proxy_address.onu_id
Craig Lutgenabd9c842018-11-15 23:58:27 +0000241 uni_id = self.platform.uni_id_from_port_num(uni_port_no) if uni_port_no is not None else None
242 flows = self.resource_mgr.get_flow_id_info(pon_intf, onu_id, uni_id, flow_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700243 assert (isinstance(flows, list))
244 self.log.debug("retrieved-flows", flows=flows)
245 for idx in range(len(flows)):
246 if flow_direction == flows[idx]['flow_type']:
247 flows.pop(idx)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000248 self.update_flow_info_to_kv_store(pon_intf, onu_id, uni_id, flow_id, flows)
Girish Gowdruab836e92018-10-25 01:17:57 -0700249 if len(flows) > 0:
250 # There are still flows referencing the same flow_id.
251 # So the flow should not be freed yet.
252 # For ex: Case of HSIA where same flow is shared
253 # between DS and US.
254 return
255
Craig Lutgenabd9c842018-11-15 23:58:27 +0000256 self.resource_mgr.free_flow_id_for_uni(pon_intf, onu_id, uni_id, flow_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700257 else:
258 self.log.error("invalid-info", uni_port_no=uni_port_no,
Girish Gowdruab836e92018-10-25 01:17:57 -0700259 child_device_id=child_device_id)
260
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400261 def remove_flow(self, flow):
262 self.log.debug('trying to remove flows from logical flow :',
Jonathan Hart5b435642018-08-20 08:50:05 -0700263 logical_flow=flow)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400264 device_flows_to_remove = []
265 device_flows = self.flows_proxy.get('/').items
266 for f in device_flows:
267 if f.cookie == flow.id:
268 device_flows_to_remove.append(f)
269
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400270 for f in device_flows_to_remove:
271 (id, direction) = self.decode_stored_id(f.id)
272 flow_to_remove = openolt_pb2.Flow(flow_id=id, flow_type=direction)
Nicolas Palpacuer3d0878d2018-08-17 11:29:42 -0400273 try:
274 self.stub.FlowRemove(flow_to_remove)
275 except grpc.RpcError as grpc_e:
276 if grpc_e.code() == grpc.StatusCode.NOT_FOUND:
277 self.log.debug('This flow does not exist on the switch, '
Jonathan Hart5b435642018-08-20 08:50:05 -0700278 'normal after an OLT reboot',
279 flow=flow_to_remove)
Nicolas Palpacuer3d0878d2018-08-17 11:29:42 -0400280 else:
281 raise grpc_e
282
Girish Gowdruab836e92018-10-25 01:17:57 -0700283 # once we have successfully deleted the flow on the device
284 # release the flow_id on resource pool and also clear any
285 # data associated with the flow_id on KV store.
286 self._clear_flow_id_from_rm(f, id, direction)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400287 self.log.debug('flow removed from device', flow=f,
288 flow_key=flow_to_remove)
289
290 if len(device_flows_to_remove) > 0:
291 new_flows = []
292 flows_ids_to_remove = [f.id for f in device_flows_to_remove]
293 for f in device_flows:
294 if f.id not in flows_ids_to_remove:
295 new_flows.append(f)
296
297 self.flows_proxy.update('/', Flows(items=new_flows))
298 self.log.debug('flows removed from the data store',
299 flow_ids_removed=flows_ids_to_remove,
300 number_of_flows_removed=(len(device_flows) - len(
301 new_flows)), expected_flows_removed=len(
Girish Gowdruab836e92018-10-25 01:17:57 -0700302 device_flows_to_remove))
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400303 else:
304 self.log.debug('no device flow to remove for this flow (normal '
305 'for multi table flows)', flow=flow)
306
Craig Lutgenabd9c842018-11-15 23:58:27 +0000307 def _get_ofp_port_name(self, intf_id, onu_id, uni_id):
Girish Gowdruab836e92018-10-25 01:17:57 -0700308 parent_port_no = self.platform.intf_id_to_port_no(intf_id, Port.PON_OLT)
309 child_device = self.adapter_agent.get_child_device(self.device_id,
310 parent_port_no=parent_port_no, onu_id=onu_id)
311 if child_device is None:
312 self.log.error("could-not-find-child-device",
313 parent_port_no=intf_id, onu_id=onu_id)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000314 return (None, None)
Girish Gowdruab836e92018-10-25 01:17:57 -0700315 ports = self.adapter_agent.get_ports(child_device.id, Port.ETHERNET_UNI)
316 logical_port = self.adapter_agent.get_logical_port(
Craig Lutgenabd9c842018-11-15 23:58:27 +0000317 self.logical_device_id, ports[uni_id].label)
318 ofp_port_name = (logical_port.ofp_port.name, logical_port.ofp_port.port_no)
Girish Gowdruab836e92018-10-25 01:17:57 -0700319 return ofp_port_name
320
Girish Gowdrub761bc12018-11-29 02:22:18 -0800321 def get_tp_path(self, intf_id, ofp_port_name):
322 # FIXME Should get Table id form the flow, as of now hardcoded to
323 # DEFAULT_TECH_PROFILE_TABLE_ID (64)
324 # 'tp_path' contains the suffix part of the tech_profile_instance path.
325 # The prefix to the 'tp_path' should be set to \
326 # TechProfile.KV_STORE_TECH_PROFILE_PATH_PREFIX by the ONU adapter.
327 return self.tech_profile[intf_id]. \
328 get_tp_path(DEFAULT_TECH_PROFILE_TABLE_ID,
329 ofp_port_name)
330
331 def delete_tech_profile_instance(self, intf_id, onu_id, uni_id):
332 # Remove the TP instance associated with the ONU
333 ofp_port_name = self._get_ofp_port_name(intf_id, onu_id, uni_id)
334 tp_path = self.get_tp_path(intf_id, ofp_port_name)
335 return self.tech_profile[intf_id].delete_tech_profile_instance(tp_path)
336
Craig Lutgenabd9c842018-11-15 23:58:27 +0000337 def divide_and_add_flow(self, intf_id, onu_id, uni_id, port_no, classifier,
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400338 action, flow):
339
Craig Lutgenabd9c842018-11-15 23:58:27 +0000340 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 -0400341 classifier=classifier, action=action)
342
Craig Lutgenabd9c842018-11-15 23:58:27 +0000343 alloc_id, gem_ports = self.create_tcont_gemport(intf_id, onu_id, uni_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700344 flow.table_id)
345 if alloc_id is None or gem_ports is None:
346 self.log.error("alloc-id-gem-ports-unavailable", alloc_id=alloc_id,
347 gem_ports=gem_ports)
348 return
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400349
Girish Gowdruab836e92018-10-25 01:17:57 -0700350 self.log.debug('Generated required alloc and gemport ids',
351 alloc_id=alloc_id, gemports=gem_ports)
352
353 # Flows can't be added specific to gemport unless p-bits are received.
354 # Hence adding flows for all gemports
355 for gemport_id in gem_ports:
356 if IP_PROTO in classifier:
357 if classifier[IP_PROTO] == 17:
358 self.log.debug('dhcp flow add')
Craig Lutgenabd9c842018-11-15 23:58:27 +0000359 self.add_dhcp_trap(intf_id, onu_id, uni_id, port_no, classifier,
Girish Gowdruab836e92018-10-25 01:17:57 -0700360 action, flow, alloc_id, gemport_id)
361 elif classifier[IP_PROTO] == 2:
362 self.log.warn('igmp flow add ignored, not implemented yet')
363 else:
364 self.log.warn("Invalid-Classifier-to-handle",
365 classifier=classifier,
366 action=action)
367 elif ETH_TYPE in classifier:
368 if classifier[ETH_TYPE] == EAP_ETH_TYPE:
369 self.log.debug('eapol flow add')
Craig Lutgenabd9c842018-11-15 23:58:27 +0000370 self.add_eapol_flow(intf_id, onu_id, uni_id, port_no, flow, alloc_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700371 gemport_id)
372 vlan_id = self.get_subscriber_vlan(fd.get_in_port(flow))
373 if vlan_id is not None:
374 self.add_eapol_flow(
Craig Lutgenabd9c842018-11-15 23:58:27 +0000375 intf_id, onu_id, uni_id, port_no, flow, alloc_id, gemport_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700376 vlan_id=vlan_id)
377 parent_port_no = self.platform.intf_id_to_port_no(intf_id, Port.PON_OLT)
378 onu_device = self.adapter_agent.get_child_device(self.device_id,
379 onu_id=onu_id,
380 parent_port_no=parent_port_no)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000381 (ofp_port_name, ofp_port_no) = self._get_ofp_port_name(intf_id, onu_id, uni_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700382 if ofp_port_name is None:
383 self.log.error("port-name-not-found")
384 return
385
Girish Gowdrub761bc12018-11-29 02:22:18 -0800386 tp_path = self.get_tp_path(intf_id, ofp_port_name)
Girish Gowdruab836e92018-10-25 01:17:57 -0700387
388 self.log.debug('Load-tech-profile-request-to-brcm-handler',
389 tp_path=tp_path)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000390 msg = {'proxy_address': onu_device.proxy_address, 'uni_id': uni_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700391 'event': 'download_tech_profile', 'event_data': tp_path}
392
393 # Send the event message to the ONU adapter
394 self.adapter_agent.publish_inter_adapter_message(onu_device.id,
395 msg)
396
397 if classifier[ETH_TYPE] == LLDP_ETH_TYPE:
398 self.log.debug('lldp flow add')
Craig Lutgenabd9c842018-11-15 23:58:27 +0000399 self.add_lldp_flow(flow, port_no)
Girish Gowdruab836e92018-10-25 01:17:57 -0700400
401 elif PUSH_VLAN in action:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000402 self.add_upstream_data_flow(intf_id, onu_id, uni_id, port_no, classifier,
Girish Gowdruab836e92018-10-25 01:17:57 -0700403 action, flow, alloc_id, gemport_id)
404 elif POP_VLAN in action:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000405 self.add_downstream_data_flow(intf_id, onu_id, uni_id, port_no, classifier,
Girish Gowdruab836e92018-10-25 01:17:57 -0700406 action, flow, alloc_id, gemport_id)
407 else:
408 self.log.debug('Invalid-flow-type-to-handle',
409 classifier=classifier,
410 action=action, flow=flow)
411
Craig Lutgenabd9c842018-11-15 23:58:27 +0000412 def create_tcont_gemport(self, intf_id, onu_id, uni_id, table_id):
Girish Gowdruab836e92018-10-25 01:17:57 -0700413 alloc_id, gem_port_ids = None, None
Girish Gowdrub761bc12018-11-29 02:22:18 -0800414 pon_intf_onu_id = (intf_id, onu_id)
415
416 # If we already have allocated alloc_id and gem_ports earlier, render them
417 alloc_id = \
418 self.resource_mgr.get_current_alloc_ids_for_onu(pon_intf_onu_id)
419 gem_port_ids = \
420 self.resource_mgr.get_current_gemport_ids_for_onu(pon_intf_onu_id)
421 if alloc_id is not None and gem_port_ids is not None:
422 return alloc_id, gem_port_ids
423
Girish Gowdruab836e92018-10-25 01:17:57 -0700424 try:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000425 (ofp_port_name, ofp_port_no) = self._get_ofp_port_name(intf_id, onu_id, uni_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700426 if ofp_port_name is None:
427 self.log.error("port-name-not-found")
428 return alloc_id, gem_port_ids
429 # FIXME: If table id is <= 63 using 64 as table id
430 if table_id < DEFAULT_TECH_PROFILE_TABLE_ID:
431 table_id = DEFAULT_TECH_PROFILE_TABLE_ID
432
433 # Check tech profile instance already exists for derived port name
434 tech_profile_instance = self.tech_profile[intf_id]. \
435 get_tech_profile_instance(table_id, ofp_port_name)
436 self.log.debug('Get-tech-profile-instance-status', tech_profile_instance=tech_profile_instance)
437
438 if tech_profile_instance is None:
439 # create tech profile instance
440 tech_profile_instance = self.tech_profile[intf_id]. \
441 create_tech_profile_instance(table_id, ofp_port_name,
442 intf_id)
Girish Gowdrub761bc12018-11-29 02:22:18 -0800443 if tech_profile_instance is None:
Girish Gowdruab836e92018-10-25 01:17:57 -0700444 raise Exception('Tech-profile-instance-creation-failed')
445 else:
446 self.log.debug(
447 'Tech-profile-instance-already-exist-for-given port-name',
448 ofp_port_name=ofp_port_name)
449
Girish Gowdrub761bc12018-11-29 02:22:18 -0800450 # upstream scheduler
451 us_scheduler = self.tech_profile[intf_id].get_us_scheduler(
452 tech_profile_instance)
453 # downstream scheduler
454 ds_scheduler = self.tech_profile[intf_id].get_ds_scheduler(
455 tech_profile_instance)
456 # create Tcont
457 tconts = self.tech_profile[intf_id].get_tconts(tech_profile_instance,
458 us_scheduler,
459 ds_scheduler)
460
461 self.stub.CreateTconts(openolt_pb2.Tconts(intf_id=intf_id,
462 onu_id=onu_id,
463 uni_id=uni_id,
464 port_no=ofp_port_no,
465 tconts=tconts))
466
Girish Gowdruab836e92018-10-25 01:17:57 -0700467 # Fetch alloc id and gemports from tech profile instance
468 alloc_id = tech_profile_instance.us_scheduler.alloc_id
469 gem_port_ids = []
470 for i in range(len(
471 tech_profile_instance.upstream_gem_port_attribute_list)):
472 gem_port_ids.append(
473 tech_profile_instance.upstream_gem_port_attribute_list[i].
Girish Gowdrub761bc12018-11-29 02:22:18 -0800474 gemport_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700475 except BaseException as e:
476 self.log.exception(exception=e)
477
Craig Lutgenabd9c842018-11-15 23:58:27 +0000478 # Update the allocated alloc_id and gem_port_id for the ONU/UNI to KV store
479 pon_intf_onu_id = (intf_id, onu_id, uni_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700480 self.resource_mgr.resource_mgrs[intf_id].update_alloc_ids_for_onu(
481 pon_intf_onu_id,
482 list([alloc_id])
483 )
484 self.resource_mgr.resource_mgrs[intf_id].update_gemport_ids_for_onu(
485 pon_intf_onu_id,
486 gem_port_ids
487 )
488
489 self.resource_mgr.update_gemports_ponport_to_onu_map_on_kv_store(
Craig Lutgenabd9c842018-11-15 23:58:27 +0000490 gem_port_ids, intf_id, onu_id, uni_id
Girish Gowdruab836e92018-10-25 01:17:57 -0700491 )
492
493 return alloc_id, gem_port_ids
Shad Ansari2dda4f32018-05-17 07:16:07 +0000494
Craig Lutgenabd9c842018-11-15 23:58:27 +0000495 def add_upstream_data_flow(self, intf_id, onu_id, uni_id, port_no, uplink_classifier,
Girish Gowdruab836e92018-10-25 01:17:57 -0700496 uplink_action, logical_flow, alloc_id,
497 gemport_id):
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400498
499 uplink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG
500
Craig Lutgenabd9c842018-11-15 23:58:27 +0000501 self.add_hsia_flow(intf_id, onu_id, uni_id, port_no, uplink_classifier,
Girish Gowdruab836e92018-10-25 01:17:57 -0700502 uplink_action, UPSTREAM,
503 logical_flow, alloc_id, gemport_id)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000504
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400505 # Secondary EAP on the subscriber vlan
Craig Lutgenabd9c842018-11-15 23:58:27 +0000506 (eap_active, eap_logical_flow) = self.is_eap_enabled(intf_id, onu_id, uni_id)
Nicolas Palpacuer2e0fa582018-07-16 16:04:12 -0400507 if eap_active:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000508 self.add_eapol_flow(intf_id, onu_id, uni_id, port_no, eap_logical_flow, alloc_id,
Girish Gowdrub761bc12018-11-29 02:22:18 -0800509 gemport_id, vlan_id=uplink_classifier[VLAN_VID])
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400510
Craig Lutgenabd9c842018-11-15 23:58:27 +0000511 def add_downstream_data_flow(self, intf_id, onu_id, uni_id, port_no, downlink_classifier,
Girish Gowdruab836e92018-10-25 01:17:57 -0700512 downlink_action, flow, alloc_id, gemport_id):
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400513 downlink_classifier[PACKET_TAG_TYPE] = DOUBLE_TAG
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400514 # Needed ???? It should be already there
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400515 downlink_action[POP_VLAN] = True
516 downlink_action[VLAN_VID] = downlink_classifier[VLAN_VID]
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400517
Craig Lutgenabd9c842018-11-15 23:58:27 +0000518 self.add_hsia_flow(intf_id, onu_id, uni_id, port_no, downlink_classifier,
Girish Gowdruab836e92018-10-25 01:17:57 -0700519 downlink_action, DOWNSTREAM,
520 flow, alloc_id, gemport_id)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400521
Craig Lutgenabd9c842018-11-15 23:58:27 +0000522 def add_hsia_flow(self, intf_id, onu_id, uni_id, port_no, classifier, action,
Girish Gowdruab836e92018-10-25 01:17:57 -0700523 direction, logical_flow, alloc_id, gemport_id):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000524
Girish Gowdrub761bc12018-11-29 02:22:18 -0800525 flow_store_cookie = self._get_flow_store_cookie(classifier,
526 gemport_id)
527
528 # One of the OLT platform (Broadcom BAL) requires that symmetric
529 # flows require the same flow_id to be used across UL and DL.
530 # Since HSIA flow is the only symmetric flow currently, we need to
531 # re-use the flow_id across both direction. The 'flow_category'
532 # takes priority over flow_cookie to find any available HSIA_FLOW
533 # id for the ONU.
534 flow_id = self.resource_mgr.get_flow_id(intf_id, onu_id, uni_id,
535 flow_store_cookie,
536 HSIA_FLOW)
Girish Gowdruab836e92018-10-25 01:17:57 -0700537 if flow_id is None:
538 self.log.error("hsia-flow-unavailable")
539 return
Shad Ansari2dda4f32018-05-17 07:16:07 +0000540
Shad Ansari2dda4f32018-05-17 07:16:07 +0000541 flow = openolt_pb2.Flow(
Craig Lutgenabd9c842018-11-15 23:58:27 +0000542 access_intf_id=intf_id, onu_id=onu_id, uni_id=uni_id, flow_id=flow_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700543 flow_type=direction, alloc_id=alloc_id, network_intf_id=0,
544 gemport_id=gemport_id,
545 classifier=self.mk_classifier(classifier),
546 action=self.mk_action(action),
Craig Lutgenabd9c842018-11-15 23:58:27 +0000547 priority=logical_flow.priority,
548 port_no=port_no,
549 cookie=logical_flow.cookie)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000550
Girish Gowdruab836e92018-10-25 01:17:57 -0700551 if self.add_flow_to_device(flow, logical_flow):
Girish Gowdrub761bc12018-11-29 02:22:18 -0800552 flow_info = self._get_flow_info_as_json_blob(flow,
553 flow_store_cookie,
554 HSIA_FLOW)
555 self.update_flow_info_to_kv_store(flow.access_intf_id,
556 flow.onu_id, flow.uni_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700557 flow.flow_id, flow_info)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000558
Craig Lutgenabd9c842018-11-15 23:58:27 +0000559 def add_dhcp_trap(self, intf_id, onu_id, uni_id, port_no, classifier, action, logical_flow,
Girish Gowdruab836e92018-10-25 01:17:57 -0700560 alloc_id, gemport_id):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000561
Shad Ansari47e0c392018-07-17 23:55:07 +0000562 self.log.debug('add dhcp upstream trap', classifier=classifier,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000563 intf_id=intf_id, onu_id=onu_id, uni_id=uni_id, action=action)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000564
565 action.clear()
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400566 action[TRAP_TO_HOST] = True
Girish Gowdruab836e92018-10-25 01:17:57 -0700567 classifier[UDP_SRC] = 68
568 classifier[UDP_DST] = 67
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400569 classifier[PACKET_TAG_TYPE] = SINGLE_TAG
570 classifier.pop(VLAN_VID, None)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000571
Girish Gowdrub761bc12018-11-29 02:22:18 -0800572 flow_store_cookie = self._get_flow_store_cookie(classifier,
573 gemport_id)
574
575 flow_id = self.resource_mgr.get_flow_id(
576 intf_id, onu_id, uni_id, flow_store_cookie
577 )
Shad Ansari2dda4f32018-05-17 07:16:07 +0000578
Matteo Scandolodf583282018-11-02 16:18:19 -0700579 dhcp_flow = openolt_pb2.Flow(
Craig Lutgenabd9c842018-11-15 23:58:27 +0000580 onu_id=onu_id, uni_id=uni_id, flow_id=flow_id, flow_type=UPSTREAM,
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400581 access_intf_id=intf_id, gemport_id=gemport_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700582 alloc_id=alloc_id, network_intf_id=0,
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400583 priority=logical_flow.priority,
584 classifier=self.mk_classifier(classifier),
Craig Lutgenabd9c842018-11-15 23:58:27 +0000585 action=self.mk_action(action),
586 port_no=port_no,
587 cookie=logical_flow.cookie)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000588
Girish Gowdruab836e92018-10-25 01:17:57 -0700589 if self.add_flow_to_device(dhcp_flow, logical_flow):
Girish Gowdrub761bc12018-11-29 02:22:18 -0800590 flow_info = self._get_flow_info_as_json_blob(dhcp_flow, flow_store_cookie)
Girish Gowdruab836e92018-10-25 01:17:57 -0700591 self.update_flow_info_to_kv_store(dhcp_flow.access_intf_id,
592 dhcp_flow.onu_id,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000593 dhcp_flow.uni_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700594 dhcp_flow.flow_id,
595 flow_info)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400596
Craig Lutgenabd9c842018-11-15 23:58:27 +0000597 def add_eapol_flow(self, intf_id, onu_id, uni_id, port_no, logical_flow, alloc_id,
Girish Gowdrub761bc12018-11-29 02:22:18 -0800598 gemport_id, vlan_id=DEFAULT_MGMT_VLAN):
Shad Ansari2dda4f32018-05-17 07:16:07 +0000599
Girish Gowdruab836e92018-10-25 01:17:57 -0700600 uplink_classifier = dict()
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400601 uplink_classifier[ETH_TYPE] = EAP_ETH_TYPE
602 uplink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG
603 uplink_classifier[VLAN_VID] = vlan_id
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400604
Girish Gowdruab836e92018-10-25 01:17:57 -0700605 uplink_action = dict()
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400606 uplink_action[TRAP_TO_HOST] = True
Shad Ansari2dda4f32018-05-17 07:16:07 +0000607
Girish Gowdrub761bc12018-11-29 02:22:18 -0800608 flow_store_cookie = self._get_flow_store_cookie(uplink_classifier,
609 gemport_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700610 # Add Upstream EAPOL Flow.
Girish Gowdrub761bc12018-11-29 02:22:18 -0800611 uplink_flow_id = self.resource_mgr.get_flow_id(
612 intf_id, onu_id, uni_id, flow_store_cookie
613 )
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400614
Shad Ansari2dda4f32018-05-17 07:16:07 +0000615 upstream_flow = openolt_pb2.Flow(
Craig Lutgenabd9c842018-11-15 23:58:27 +0000616 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 -0700617 flow_type=UPSTREAM, alloc_id=alloc_id, network_intf_id=0,
618 gemport_id=gemport_id,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000619 classifier=self.mk_classifier(uplink_classifier),
Girish Gowdruab836e92018-10-25 01:17:57 -0700620 action=self.mk_action(uplink_action),
Craig Lutgenabd9c842018-11-15 23:58:27 +0000621 priority=logical_flow.priority,
622 port_no=port_no,
623 cookie=logical_flow.cookie)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000624
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400625 logical_flow = copy.deepcopy(logical_flow)
626 logical_flow.match.oxm_fields.extend(fd.mk_oxm_fields([fd.vlan_vid(
627 vlan_id | 0x1000)]))
628 logical_flow.match.type = OFPMT_OXM
629
Girish Gowdruab836e92018-10-25 01:17:57 -0700630 if self.add_flow_to_device(upstream_flow, logical_flow):
Girish Gowdrub761bc12018-11-29 02:22:18 -0800631 flow_info = self._get_flow_info_as_json_blob(upstream_flow,
632 flow_store_cookie)
633 self.update_flow_info_to_kv_store(upstream_flow.access_intf_id,
634 upstream_flow.onu_id,
635 upstream_flow.uni_id,
636 upstream_flow.flow_id,
637 flow_info)
Shad Ansari2dda4f32018-05-17 07:16:07 +0000638
Nicolas Palpacuer6152a322018-09-05 10:52:15 -0400639 if vlan_id == DEFAULT_MGMT_VLAN:
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400640 # Add Downstream EAPOL Flow, Only for first EAP flow (BAL
641 # requirement)
Girish Gowdrub761bc12018-11-29 02:22:18 -0800642 # On one of the platforms (Broadcom BAL), when same DL classifier
643 # vlan was used across multiple ONUs, eapol flow re-adds after
644 # flow delete (cases of onu reboot/disable) fails.
645 # In order to generate unique vlan, a combination of intf_id
646 # onu_id and uni_id is used.
647 # uni_id defaults to 0, so add 1 to it.
648 special_vlan_downstream_flow = 4090 - intf_id * onu_id * (uni_id+1)
649 # Assert that we do not generate invalid vlans under no condition
650 assert (special_vlan_downstream_flow >= 2, 'invalid-vlan-generated')
Shad Ansari2dda4f32018-05-17 07:16:07 +0000651
Girish Gowdruab836e92018-10-25 01:17:57 -0700652 downlink_classifier = dict()
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400653 downlink_classifier[PACKET_TAG_TYPE] = SINGLE_TAG
654 downlink_classifier[VLAN_VID] = special_vlan_downstream_flow
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400655
Girish Gowdruab836e92018-10-25 01:17:57 -0700656 downlink_action = dict()
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400657 downlink_action[PUSH_VLAN] = True
658 downlink_action[VLAN_VID] = vlan_id
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400659
Girish Gowdrub761bc12018-11-29 02:22:18 -0800660
661 flow_store_cookie = self._get_flow_store_cookie(downlink_classifier,
662 gemport_id)
663
664 downlink_flow_id = self.resource_mgr.get_flow_id(
665 intf_id, onu_id, uni_id, flow_store_cookie
666 )
Nicolas Palpacuer6152a322018-09-05 10:52:15 -0400667
668 downstream_flow = openolt_pb2.Flow(
Craig Lutgenabd9c842018-11-15 23:58:27 +0000669 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 -0700670 flow_type=DOWNSTREAM, alloc_id=alloc_id, network_intf_id=0,
671 gemport_id=gemport_id,
Nicolas Palpacuer6152a322018-09-05 10:52:15 -0400672 classifier=self.mk_classifier(downlink_classifier),
Girish Gowdruab836e92018-10-25 01:17:57 -0700673 action=self.mk_action(downlink_action),
Craig Lutgenabd9c842018-11-15 23:58:27 +0000674 priority=logical_flow.priority,
675 port_no=port_no,
676 cookie=logical_flow.cookie)
Nicolas Palpacuer6152a322018-09-05 10:52:15 -0400677
Shad Ansarifd0111d2018-09-13 21:33:06 +0000678 downstream_logical_flow = ofp_flow_stats(
679 id=logical_flow.id, cookie=logical_flow.cookie,
680 table_id=logical_flow.table_id, priority=logical_flow.priority,
681 flags=logical_flow.flags)
Nicolas Palpacuer6152a322018-09-05 10:52:15 -0400682
683 downstream_logical_flow.match.oxm_fields.extend(fd.mk_oxm_fields([
684 fd.in_port(fd.get_out_port(logical_flow)),
Girish Gowdruab836e92018-10-25 01:17:57 -0700685 fd.vlan_vid(special_vlan_downstream_flow | 0x1000)]))
Nicolas Palpacuer6152a322018-09-05 10:52:15 -0400686 downstream_logical_flow.match.type = OFPMT_OXM
687
688 downstream_logical_flow.instructions.extend(
689 fd.mk_instructions_from_actions([fd.output(
Craig Lutgenabd9c842018-11-15 23:58:27 +0000690 self.platform.mk_uni_port_num(intf_id, onu_id, uni_id))]))
Nicolas Palpacuer6152a322018-09-05 10:52:15 -0400691
Girish Gowdruab836e92018-10-25 01:17:57 -0700692 if self.add_flow_to_device(downstream_flow, downstream_logical_flow):
693 flow_info = self._get_flow_info_as_json_blob(downstream_flow,
Girish Gowdrub761bc12018-11-29 02:22:18 -0800694 flow_store_cookie)
Girish Gowdruab836e92018-10-25 01:17:57 -0700695 self.update_flow_info_to_kv_store(downstream_flow.access_intf_id,
696 downstream_flow.onu_id,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000697 downstream_flow.uni_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700698 downstream_flow.flow_id,
699 flow_info)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400700
Nicolas Palpacuer41141352018-08-31 14:11:38 -0400701 def repush_all_different_flows(self):
702 # Check if the device is supposed to have flows, if so add them
703 # Recover static flows after a reboot
704 logical_flows = self.logical_flows_proxy.get('/').items
705 devices_flows = self.flows_proxy.get('/').items
706 logical_flows_ids_provisioned = [f.cookie for f in devices_flows]
707 for logical_flow in logical_flows:
708 try:
709 if logical_flow.id not in logical_flows_ids_provisioned:
710 self.add_flow(logical_flow)
711 except Exception as e:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000712 self.log.exception('Problem reading this flow', e=e)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400713
Nicolas Palpacuer41141352018-08-31 14:11:38 -0400714 def reset_flows(self):
715 self.flows_proxy.update('/', Flows())
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400716
Shad Ansarifd0111d2018-09-13 21:33:06 +0000717 """ Add a downstream LLDP trap flow on the NNI interface
718 """
Girish Gowdruab836e92018-10-25 01:17:57 -0700719
Craig Lutgenabd9c842018-11-15 23:58:27 +0000720 def add_lldp_flow(self, logical_flow, port_no, network_intf_id=0):
Jonathan Hart5b435642018-08-20 08:50:05 -0700721
Girish Gowdruab836e92018-10-25 01:17:57 -0700722 classifier = dict()
Shad Ansarifd0111d2018-09-13 21:33:06 +0000723 classifier[ETH_TYPE] = LLDP_ETH_TYPE
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400724 classifier[PACKET_TAG_TYPE] = UNTAGGED
Girish Gowdruab836e92018-10-25 01:17:57 -0700725 action = dict()
Shad Ansarifd0111d2018-09-13 21:33:06 +0000726 action[TRAP_TO_HOST] = True
Jonathan Hart5b435642018-08-20 08:50:05 -0700727
Girish Gowdruab836e92018-10-25 01:17:57 -0700728 # LLDP flow is installed to trap LLDP packets on the NNI port.
729 # We manage flow_id resource pool on per PON port basis.
730 # Since this situation is tricky, as a hack, we pass the NNI port
731 # index (network_intf_id) as PON port Index for the flow_id resource
732 # pool. Also, there is no ONU Id available for trapping LLDP packets
733 # on NNI port, use onu_id as -1 (invalid)
734 # ****************** CAVEAT *******************
735 # This logic works if the NNI Port Id falls within the same valid
736 # range of PON Port Ids. If this doesn't work for some OLT Vendor
737 # we need to have a re-look at this.
738 # *********************************************
739 onu_id = -1
Craig Lutgenabd9c842018-11-15 23:58:27 +0000740 uni_id = -1
Girish Gowdrub761bc12018-11-29 02:22:18 -0800741 flow_store_cookie = self._get_flow_store_cookie(classifier)
742 flow_id = self.resource_mgr.get_flow_id(network_intf_id, onu_id, uni_id,
743 flow_store_cookie)
Jonathan Hart5b435642018-08-20 08:50:05 -0700744
745 downstream_flow = openolt_pb2.Flow(
Shad Ansarifd0111d2018-09-13 21:33:06 +0000746 access_intf_id=-1, # access_intf_id not required
Craig Lutgenabd9c842018-11-15 23:58:27 +0000747 onu_id=onu_id, # onu_id not required
748 uni_id=uni_id, # uni_id not used
Shad Ansarifd0111d2018-09-13 21:33:06 +0000749 flow_id=flow_id,
750 flow_type=DOWNSTREAM,
Shad Ansarifd0111d2018-09-13 21:33:06 +0000751 network_intf_id=network_intf_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700752 gemport_id=-1, # gemport_id not required
Jonathan Hart5b435642018-08-20 08:50:05 -0700753 classifier=self.mk_classifier(classifier),
Girish Gowdruab836e92018-10-25 01:17:57 -0700754 action=self.mk_action(action),
Craig Lutgenabd9c842018-11-15 23:58:27 +0000755 priority=logical_flow.priority,
756 port_no=port_no,
757 cookie=logical_flow.cookie)
Jonathan Hart5b435642018-08-20 08:50:05 -0700758
Shad Ansarifd0111d2018-09-13 21:33:06 +0000759 self.log.debug('add lldp downstream trap', classifier=classifier,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000760 action=action, flow=downstream_flow, port_no=port_no)
Girish Gowdruab836e92018-10-25 01:17:57 -0700761 if self.add_flow_to_device(downstream_flow, logical_flow):
Craig Lutgenabd9c842018-11-15 23:58:27 +0000762 self.update_flow_info_to_kv_store(network_intf_id, onu_id, uni_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700763 flow_id, downstream_flow)
Jonathan Hart5b435642018-08-20 08:50:05 -0700764
Shad Ansari2dda4f32018-05-17 07:16:07 +0000765 def mk_classifier(self, classifier_info):
766
767 classifier = openolt_pb2.Classifier()
768
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400769 if ETH_TYPE in classifier_info:
770 classifier.eth_type = classifier_info[ETH_TYPE]
771 if IP_PROTO in classifier_info:
772 classifier.ip_proto = classifier_info[IP_PROTO]
773 if VLAN_VID in classifier_info:
774 classifier.o_vid = classifier_info[VLAN_VID]
775 if METADATA in classifier_info:
776 classifier.i_vid = classifier_info[METADATA]
777 if VLAN_PCP in classifier_info:
778 classifier.o_pbits = classifier_info[VLAN_PCP]
779 if UDP_SRC in classifier_info:
780 classifier.src_port = classifier_info[UDP_SRC]
781 if UDP_DST in classifier_info:
782 classifier.dst_port = classifier_info[UDP_DST]
783 if IPV4_DST in classifier_info:
784 classifier.dst_ip = classifier_info[IPV4_DST]
785 if IPV4_SRC in classifier_info:
786 classifier.src_ip = classifier_info[IPV4_SRC]
787 if PACKET_TAG_TYPE in classifier_info:
788 if classifier_info[PACKET_TAG_TYPE] == SINGLE_TAG:
789 classifier.pkt_tag_type = SINGLE_TAG
790 elif classifier_info[PACKET_TAG_TYPE] == DOUBLE_TAG:
791 classifier.pkt_tag_type = DOUBLE_TAG
792 elif classifier_info[PACKET_TAG_TYPE] == UNTAGGED:
793 classifier.pkt_tag_type = UNTAGGED
Shad Ansari2dda4f32018-05-17 07:16:07 +0000794 else:
795 classifier.pkt_tag_type = 'none'
796
797 return classifier
798
799 def mk_action(self, action_info):
800 action = openolt_pb2.Action()
801
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400802 if POP_VLAN in action_info:
803 action.o_vid = action_info[VLAN_VID]
Shad Ansari2dda4f32018-05-17 07:16:07 +0000804 action.cmd.remove_outer_tag = True
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400805 elif PUSH_VLAN in action_info:
806 action.o_vid = action_info[VLAN_VID]
Shad Ansari2dda4f32018-05-17 07:16:07 +0000807 action.cmd.add_outer_tag = True
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400808 elif TRAP_TO_HOST in action_info:
Shad Ansari2dda4f32018-05-17 07:16:07 +0000809 action.cmd.trap_to_host = True
Shad Ansarif9d2d102018-06-13 02:15:26 +0000810 else:
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400811 self.log.info('Invalid-action-field', action_info=action_info)
Shad Ansarif9d2d102018-06-13 02:15:26 +0000812 return
Shad Ansari2dda4f32018-05-17 07:16:07 +0000813 return action
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400814
Craig Lutgenabd9c842018-11-15 23:58:27 +0000815 def is_eap_enabled(self, intf_id, onu_id, uni_id):
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400816 flows = self.logical_flows_proxy.get('/').items
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400817
818 for flow in flows:
819 eap_flow = False
820 eap_intf_id = None
821 eap_onu_id = None
Craig Lutgenabd9c842018-11-15 23:58:27 +0000822 eap_uni_id = None
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400823 for field in fd.get_ofb_fields(flow):
824 if field.type == fd.ETH_TYPE:
825 if field.eth_type == EAP_ETH_TYPE:
826 eap_flow = True
827 if field.type == fd.IN_PORT:
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000828 eap_intf_id = self.platform.intf_id_from_uni_port_num(
Shad Ansari47e0c392018-07-17 23:55:07 +0000829 field.port)
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000830 eap_onu_id = self.platform.onu_id_from_port_num(field.port)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000831 eap_uni_id = self.platform.uni_id_from_port_num(field.port)
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400832
833 if eap_flow:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000834 self.log.debug('eap flow detected', onu_id=onu_id, uni_id=uni_id,
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400835 intf_id=intf_id, eap_intf_id=eap_intf_id,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000836 eap_onu_id=eap_onu_id,
837 eap_uni_id=eap_uni_id)
838 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 -0700839 return True, flow
Nicolas Palpacuer61815162018-06-20 18:12:04 -0400840
Girish Gowdruab836e92018-10-25 01:17:57 -0700841 return False, None
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400842
Nicolas Palpacuer41141352018-08-31 14:11:38 -0400843 def get_subscriber_vlan(self, port):
844 self.log.debug('looking from subscriber flow for port', port=port)
845
846 flows = self.logical_flows_proxy.get('/').items
847 for flow in flows:
848 in_port = fd.get_in_port(flow)
849 out_port = fd.get_out_port(flow)
Girish Gowdrub761bc12018-11-29 02:22:18 -0800850 if in_port == port and out_port is not None and \
Girish Gowdruab836e92018-10-25 01:17:57 -0700851 self.platform.intf_id_to_port_type_name(out_port) \
Shad Ansarifd0111d2018-09-13 21:33:06 +0000852 == Port.ETHERNET_NNI:
Nicolas Palpacuer41141352018-08-31 14:11:38 -0400853 fields = fd.get_ofb_fields(flow)
854 self.log.debug('subscriber flow found', fields=fields)
855 for field in fields:
856 if field.type == OFPXMT_OFB_VLAN_VID:
857 self.log.debug('subscriber vlan found',
858 vlan_id=field.vlan_vid)
859 return field.vlan_vid & 0x0fff
860 self.log.debug('No subscriber flow found', port=port)
861 return None
862
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400863 def add_flow_to_device(self, flow, logical_flow):
864 self.log.debug('pushing flow to device', flow=flow)
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400865 try:
866 self.stub.FlowAdd(flow)
867 except grpc.RpcError as grpc_e:
868 if grpc_e.code() == grpc.StatusCode.ALREADY_EXISTS:
869 self.log.warn('flow already exists', e=grpc_e, flow=flow)
870 else:
871 self.log.error('failed to add flow',
872 logical_flow=logical_flow, flow=flow,
873 grpc_error=grpc_e)
Girish Gowdruab836e92018-10-25 01:17:57 -0700874 return False
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400875 else:
876 self.register_flow(logical_flow, flow)
Girish Gowdruab836e92018-10-25 01:17:57 -0700877 return True
878
Craig Lutgenabd9c842018-11-15 23:58:27 +0000879 def update_flow_info_to_kv_store(self, intf_id, onu_id, uni_id, flow_id, flow):
880 self.resource_mgr.update_flow_id_info_for_uni(intf_id, onu_id, uni_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700881 flow_id, flow)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400882
883 def register_flow(self, logical_flow, device_flow):
884 self.log.debug('registering flow in device',
885 logical_flow=logical_flow, device_flow=device_flow)
886 stored_flow = copy.deepcopy(logical_flow)
887 stored_flow.id = self.generate_stored_id(device_flow.flow_id,
888 device_flow.flow_type)
889 self.log.debug('generated device flow id', id=stored_flow.id,
890 flow_id=device_flow.flow_id,
891 direction=device_flow.flow_type)
892 stored_flow.cookie = logical_flow.id
893 flows = self.flows_proxy.get('/')
894 flows.items.extend([stored_flow])
895 self.flows_proxy.update('/', flows)
896
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400897 def find_next_flow(self, flow):
898 table_id = fd.get_goto_table_id(flow)
899 metadata = 0
Chip Boling41f795a2018-10-04 15:45:34 -0500900 # Prior to ONOS 1.13.5, Metadata contained the UNI output port number. In
901 # 1.13.5 and later, the lower 32-bits is the output port number and the
902 # upper 32-bits is the inner-vid we are looking for. Use just the lower 32
903 # bits. Allows this code to work with pre- and post-1.13.5 ONOS OltPipeline
904
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400905 for field in fd.get_ofb_fields(flow):
906 if field.type == fd.METADATA:
Chip Boling41f795a2018-10-04 15:45:34 -0500907 metadata = field.table_metadata & 0xFFFFFFFF
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400908 if table_id is None:
909 return None
910 flows = self.logical_flows_proxy.get('/').items
911 next_flows = []
912 for f in flows:
913 if f.table_id == table_id:
Jonathan Hart5b435642018-08-20 08:50:05 -0700914 # FIXME
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400915 if fd.get_in_port(f) == fd.get_in_port(flow) and \
916 fd.get_out_port(f) == metadata:
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400917 next_flows.append(f)
918
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400919 if len(next_flows) == 0:
920 self.log.warning('no next flow found, it may be a timing issue',
921 flow=flow, number_of_flows=len(flows))
922 reactor.callLater(5, self.add_flow, flow)
923 return None
924
Jonathan Hart5b435642018-08-20 08:50:05 -0700925 next_flows.sort(key=lambda f: f.priority, reverse=True)
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400926
927 return next_flows[0]
928
929 def update_children_flows(self, device_rules_map):
930
931 for device_id, (flows, groups) in device_rules_map.iteritems():
932 if device_id != self.device_id:
933 self.root_proxy.update('/devices/{}/flows'.format(device_id),
934 Flows(items=flows.values()))
935 self.root_proxy.update('/devices/{}/flow_groups'.format(
936 device_id), FlowGroups(items=groups.values()))
937
Girish Gowdruab836e92018-10-25 01:17:57 -0700938 def clear_flows_and_scheduler_for_logical_port(self, child_device, logical_port):
939 ofp_port_name = logical_port.ofp_port.name
Craig Lutgenabd9c842018-11-15 23:58:27 +0000940 port_no = logical_port.ofp_port.port_no
Girish Gowdruab836e92018-10-25 01:17:57 -0700941 pon_port = child_device.proxy_address.channel_id
942 onu_id = child_device.proxy_address.onu_id
Craig Lutgenabd9c842018-11-15 23:58:27 +0000943 uni_id = self.platform.uni_id_from_port_num(logical_port)
944
Girish Gowdruab836e92018-10-25 01:17:57 -0700945 # TODO: The DEFAULT_TECH_PROFILE_ID is assumed. Right way to do,
946 # is probably to maintain a list of Tech-profile table IDs associated
947 # with the UNI logical_port. This way, when the logical port is deleted,
948 # all the associated tech-profile configuration with the UNI logical_port
949 # can be cleared.
950 tech_profile_instance = self.tech_profile[pon_port]. \
951 get_tech_profile_instance(
952 DEFAULT_TECH_PROFILE_TABLE_ID,
953 ofp_port_name)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000954 flow_ids = self.resource_mgr.get_current_flow_ids_for_uni(pon_port, onu_id, uni_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700955 self.log.debug("outstanding-flows-to-be-cleared", flow_ids=flow_ids)
956 for flow_id in flow_ids:
Craig Lutgenabd9c842018-11-15 23:58:27 +0000957 flow_infos = self.resource_mgr.get_flow_id_info(pon_port, onu_id, uni_id, flow_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700958 for flow_info in flow_infos:
959 direction = flow_info['flow_type']
960 flow_to_remove = openolt_pb2.Flow(flow_id=flow_id,
961 flow_type=direction)
962 try:
963 self.stub.FlowRemove(flow_to_remove)
964 except grpc.RpcError as grpc_e:
965 if grpc_e.code() == grpc.StatusCode.NOT_FOUND:
966 self.log.debug('This flow does not exist on the switch, '
967 'normal after an OLT reboot',
968 flow=flow_to_remove)
969 else:
970 raise grpc_e
971
Craig Lutgenabd9c842018-11-15 23:58:27 +0000972 self.resource_mgr.free_flow_id_for_uni(pon_port, onu_id, uni_id, flow_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700973
974 try:
975 tconts = self.tech_profile[pon_port].get_tconts(tech_profile_instance)
976 self.stub.RemoveTconts(openolt_pb2.Tconts(intf_id=pon_port,
977 onu_id=onu_id,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000978 uni_id=uni_id,
979 port_no=port_no,
Girish Gowdruab836e92018-10-25 01:17:57 -0700980 tconts=tconts))
981 except grpc.RpcError as grpc_e:
982 self.log.error('error-removing-tcont-scheduler-queues',
983 err=grpc_e)
984
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400985 def generate_stored_id(self, flow_id, direction):
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400986 if direction == UPSTREAM:
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400987 self.log.debug('upstream flow, shifting id')
988 return 0x1 << 15 | flow_id
Nicolas Palpacuer2789f042018-09-17 09:10:29 -0400989 elif direction == DOWNSTREAM:
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400990 self.log.debug('downstream flow, not shifting id')
991 return flow_id
992 else:
993 self.log.warn('Unrecognized direction', direction=direction)
994 return flow_id
995
996 def decode_stored_id(self, id):
997 if id >> 15 == 0x1:
Girish Gowdruab836e92018-10-25 01:17:57 -0700998 return id & 0x7fff, UPSTREAM
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400999 else:
Girish Gowdruab836e92018-10-25 01:17:57 -07001000 return id, DOWNSTREAM
1001
1002 def _populate_tech_profile_per_pon_port(self):
1003 for arange in self.resource_mgr.device_info.ranges:
1004 for intf_id in arange.intf_ids:
1005 self.tech_profile[intf_id] = \
1006 self.resource_mgr.resource_mgrs[intf_id].tech_profile
1007
1008 # Make sure we have as many tech_profiles as there are pon ports on
1009 # the device
1010 assert len(self.tech_profile) == self.resource_mgr.device_info.pon_ports
1011
Girish Gowdrub761bc12018-11-29 02:22:18 -08001012 def _get_flow_info_as_json_blob(self, flow, flow_store_cookie,
1013 flow_category=None):
Girish Gowdruab836e92018-10-25 01:17:57 -07001014 json_blob = MessageToDict(message=flow,
1015 preserving_proto_field_name=True)
1016 self.log.debug("flow-info", json_blob=json_blob)
Girish Gowdrub761bc12018-11-29 02:22:18 -08001017 json_blob['flow_store_cookie'] = flow_store_cookie
1018 if flow_category is not None:
1019 json_blob['flow_category'] = flow_category
Girish Gowdruab836e92018-10-25 01:17:57 -07001020 flow_info = self.resource_mgr.get_flow_id_info(flow.access_intf_id,
Craig Lutgenabd9c842018-11-15 23:58:27 +00001021 flow.onu_id, flow.uni_id, flow.flow_id)
Girish Gowdruab836e92018-10-25 01:17:57 -07001022
1023 if flow_info is None:
1024 flow_info = list()
1025 flow_info.append(json_blob)
1026 else:
1027 assert (isinstance(flow_info, list))
1028 flow_info.append(json_blob)
1029
1030 return flow_info
Girish Gowdrub761bc12018-11-29 02:22:18 -08001031
1032 @staticmethod
1033 def _get_flow_store_cookie(classifier, gem_port=None):
1034 assert isinstance(classifier, dict)
1035 # We need unique flows per gem_port
1036 if gem_port is not None:
1037 to_hash = dumps(classifier, sort_keys=True) + str(gem_port)
1038 else:
1039 to_hash = dumps(classifier, sort_keys=True)
1040 return hashlib.md5(to_hash).hexdigest()[:12]