blob: bda822c5904c5f04a7fe9ce19808aa5e892f6b42 [file] [log] [blame]
Girish Gowdru1e77ea02018-09-24 09:10:35 -07001#
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#
16
17import structlog
18
19from common.pon_resource_manager.resource_manager import PONResourceManager
20from voltha.registry import registry
21from voltha.core.config.config_backend import ConsulStore
22from voltha.core.config.config_backend import EtcdStore
Girish Gowdruab836e92018-10-25 01:17:57 -070023from voltha.adapters.openolt.openolt_flow_mgr import *
24
Craig Lutgen1dd47082018-10-23 13:12:26 -050025from voltha.adapters.openolt.protos import openolt_pb2
Craig Lutgenabd9c842018-11-15 23:58:27 +000026from voltha.adapters.openolt.openolt_platform import OpenOltPlatform
Girish Gowdru1e77ea02018-09-24 09:10:35 -070027
Girish Gowdruab836e92018-10-25 01:17:57 -070028
Girish Gowdru1e77ea02018-09-24 09:10:35 -070029class OpenOltResourceMgr(object):
Girish Gowdrub761bc12018-11-29 02:22:18 -080030 BASE_PATH_KV_STORE = "service/voltha/openolt/{}" # service/voltha/openolt/<device_id>
Thiyagarajan Subramani353af122019-02-20 23:14:24 -080031 TP_ID_PATH_SUFFIX = 'tp_id/{}'
Girish Gowdru1e77ea02018-09-24 09:10:35 -070032
33 def __init__(self, device_id, host_and_port, extra_args, device_info):
34 self.log = structlog.get_logger(id=device_id,
35 ip=host_and_port)
36 self.device_id = device_id
37 self.host_and_port = host_and_port
38 self.extra_args = extra_args
39 self.device_info = device_info
40 self.args = registry('main').get_args()
41
42 # KV store's IP Address and PORT
Girish Gowdru1e77ea02018-09-24 09:10:35 -070043 if self.args.backend == 'etcd':
44 host, port = self.args.etcd.split(':', 1)
45 self.kv_store = EtcdStore(host, port,
46 OpenOltResourceMgr.BASE_PATH_KV_STORE.format(device_id))
47 elif self.args.backend == 'consul':
48 host, port = self.args.consul.split(':', 1)
49 self.kv_store = ConsulStore(host, port,
50 OpenOltResourceMgr.BASE_PATH_KV_STORE.format(device_id))
51 else:
52 self.log.error('Invalid-backend')
53 raise Exception("Invalid-backend-for-kv-store")
54
Craig Lutgen1dd47082018-10-23 13:12:26 -050055 ranges = dict()
56 resource_mgrs_by_tech = dict()
57 self.resource_mgrs = dict()
Girish Gowdru1e77ea02018-09-24 09:10:35 -070058
Craig Lutgen1dd47082018-10-23 13:12:26 -050059 # If a legacy driver returns protobuf without any ranges,s synthesize one from
60 # the legacy global per-device informaiton. This, in theory, is temporary until
61 # the legacy drivers are upgrade to support pool ranges.
62 if len(self.device_info.ranges) == 0:
63 arange = self.device_info.ranges.add()
64 arange.technology = self.device_info.technology
65 arange.intf_ids.extend(range(0, device_info.pon_ports))
Girish Gowdru1e77ea02018-09-24 09:10:35 -070066
Craig Lutgen1dd47082018-10-23 13:12:26 -050067 pool = arange.pools.add()
68 pool.type = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.ONU_ID
69 pool.start = self.device_info.onu_id_start
70 pool.end = self.device_info.onu_id_end
71 pool.sharing = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.DEDICATED_PER_INTF
72
73 pool = arange.pools.add()
74 pool.type = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.ALLOC_ID
75 pool.start = self.device_info.alloc_id_start
76 pool.end = self.device_info.alloc_id_end
77 pool.sharing = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH
78
79 pool = arange.pools.add()
80 pool.type = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.GEMPORT_ID
81 pool.start = self.device_info.gemport_id_start
82 pool.end = self.device_info.gemport_id_end
83 pool.sharing = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH
84
Girish Gowdruab836e92018-10-25 01:17:57 -070085 pool = arange.pools.add()
86 pool.type = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.FLOW_ID
87 pool.start = self.device_info.flow_id_start
88 pool.end = self.device_info.flow_id_end
89 pool.sharing = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH
90
Craig Lutgen1dd47082018-10-23 13:12:26 -050091 # Create a separate Resource Manager instance for each range. This assumes that
92 # each technology is represented by only a single range
93 global_resource_mgr = None
94 for arange in self.device_info.ranges:
95 technology = arange.technology
96 self.log.info("device-info", technology=technology)
97 ranges[technology] = arange
Girish Gowdruab836e92018-10-25 01:17:57 -070098 extra_args = self.extra_args + ' ' + PONResourceManager.OLT_MODEL_ARG + ' {}'.format(self.device_info.model)
Craig Lutgen1dd47082018-10-23 13:12:26 -050099 resource_mgr = PONResourceManager(technology,
Girish Gowdruab836e92018-10-25 01:17:57 -0700100 extra_args, self.device_id, self.args.backend, host, port)
Craig Lutgen1dd47082018-10-23 13:12:26 -0500101 resource_mgrs_by_tech[technology] = resource_mgr
Girish Gowdruab836e92018-10-25 01:17:57 -0700102 if global_resource_mgr is None:
103 global_resource_mgr = resource_mgr
Craig Lutgen1dd47082018-10-23 13:12:26 -0500104 for intf_id in arange.intf_ids:
105 self.resource_mgrs[intf_id] = resource_mgrs_by_tech[technology]
106 self.initialize_device_resource_range_and_pool(resource_mgr, global_resource_mgr, arange)
107
108 # After we have initialized resource ranges, initialize the
109 # resource pools accordingly.
110 for technology, resource_mgr in resource_mgrs_by_tech.iteritems():
111 resource_mgr.init_device_resource_pool()
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700112
113 def __del__(self):
114 self.log.info("clearing-device-resource-pool")
Girish Gowdruab836e92018-10-25 01:17:57 -0700115 for key, resource_mgr in self.resource_mgrs.iteritems():
Craig Lutgen1dd47082018-10-23 13:12:26 -0500116 resource_mgr.clear_device_resource_pool()
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700117
Craig Lutgenabd9c842018-11-15 23:58:27 +0000118 def assert_pon_id_limit(self, pon_intf_id):
119 assert pon_intf_id in self.resource_mgrs
120
121 def assert_onu_id_limit(self, pon_intf_id, onu_id):
122 self.assert_pon_id_limit(pon_intf_id)
123 self.resource_mgrs[pon_intf_id].assert_resource_limits(onu_id, PONResourceManager.ONU_ID)
124
Craig Lutgenb25ca142018-12-13 10:22:35 -0600125 @property
126 def max_uni_id_per_onu(self):
127 return 0 #OpenOltPlatform.MAX_UNIS_PER_ONU-1, zero-based indexing Uncomment or override to make default multi-uni
128
Craig Lutgenabd9c842018-11-15 23:58:27 +0000129 def assert_uni_id_limit(self, pon_intf_id, onu_id, uni_id):
130 self.assert_onu_id_limit(pon_intf_id, onu_id)
131 self.resource_mgrs[pon_intf_id].assert_resource_limits(uni_id, PONResourceManager.UNI_ID)
132
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700133 def get_onu_id(self, pon_intf_id):
Craig Lutgen1dd47082018-10-23 13:12:26 -0500134 onu_id = self.resource_mgrs[pon_intf_id].get_resource_id(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700135 pon_intf_id, PONResourceManager.ONU_ID, 1)
136
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700137 return onu_id
138
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800139 def get_flow_id(self, intf_id, onu_id, uni_id, flow_store_cookie,
Girish Gowdrub761bc12018-11-29 02:22:18 -0800140 flow_category=None):
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800141 intf_onu_id = (intf_id, onu_id, uni_id)
Girish Gowdrub761bc12018-11-29 02:22:18 -0800142 try:
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800143 flow_ids = self.resource_mgrs[intf_id]. \
144 get_current_flow_ids_for_onu(intf_onu_id)
Girish Gowdrub761bc12018-11-29 02:22:18 -0800145 if flow_ids is not None:
146 for flow_id in flow_ids:
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800147 flows = self.get_flow_id_info(intf_id, onu_id, uni_id, flow_id)
Girish Gowdrub761bc12018-11-29 02:22:18 -0800148 assert (isinstance(flows, list))
149 for flow in flows:
150
151 if flow_category is not None and \
152 'flow_category' in flow and \
153 flow['flow_category'] == flow_category:
154 return flow_id
155 if flow['flow_store_cookie'] == flow_store_cookie:
156 return flow_id
157 except Exception as e:
158 self.log.error("error-retrieving-flow-info", e=e)
159
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800160 flow_id = self.resource_mgrs[intf_id].get_resource_id(
161 intf_onu_id[0], PONResourceManager.FLOW_ID)
Girish Gowdruab836e92018-10-25 01:17:57 -0700162 if flow_id is not None:
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800163 self.resource_mgrs[intf_id].update_flow_id_for_onu(
164 intf_onu_id, flow_id
Girish Gowdrub761bc12018-11-29 02:22:18 -0800165 )
Girish Gowdruab836e92018-10-25 01:17:57 -0700166
167 return flow_id
168
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800169 def get_flow_id_info(self, intf_id, onu_id, uni_id, flow_id):
170 '''
171 Note: For flows which trap from the NNI and not really associated with any particular
172 ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id.
173 '''
174 intf_onu_id = (intf_id, onu_id, uni_id)
175 return self.resource_mgrs[intf_id].get_flow_id_info(intf_onu_id, flow_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700176
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800177 def get_current_flow_ids(self, intf_id, onu_id, uni_id):
178 '''
179 Note: For flows which trap from the NNI and not really associated with any particular
180 ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id.
181 '''
182 intf_onu_id = (intf_id, onu_id, uni_id)
183 return self.resource_mgrs[intf_id].get_current_flow_ids_for_onu(intf_onu_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700184
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800185 def update_flow_id_info(self, intf_id, onu_id, uni_id, flow_id, flow_data):
186 '''
187 Note: For flows which trap from the NNI and not really associated with any particular
188 ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id.
189 '''
190 intf_onu_id = (intf_id, onu_id, uni_id)
191 return self.resource_mgrs[intf_id].update_flow_id_info_for_onu(
192 intf_onu_id, flow_id, flow_data)
Girish Gowdruab836e92018-10-25 01:17:57 -0700193
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700194 def get_alloc_id(self, pon_intf_onu_id):
195 # Derive the pon_intf from the pon_intf_onu_id tuple
196 pon_intf = pon_intf_onu_id[0]
Craig Lutgen1dd47082018-10-23 13:12:26 -0500197 alloc_id_list = self.resource_mgrs[pon_intf].get_current_alloc_ids_for_onu(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700198 pon_intf_onu_id)
199
200 if alloc_id_list and len(alloc_id_list) > 0:
201 # Since we support only one alloc_id for the ONU at the moment,
202 # return the first alloc_id in the list, if available, for that
203 # ONU.
204 return alloc_id_list[0]
205
Girish Gowdruab836e92018-10-25 01:17:57 -0700206 alloc_id = self.resource_mgrs[pon_intf].get_resource_id(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700207 pon_intf_id=pon_intf,
208 resource_type=PONResourceManager.ALLOC_ID,
209 num_of_id=1
210 )
Girish Gowdruab836e92018-10-25 01:17:57 -0700211 if alloc_id is None:
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700212 self.log.error("no-alloc-id-available")
213 return None
214
215 # update the resource map on KV store with the list of alloc_id
216 # allocated for the pon_intf_onu_id tuple
Craig Lutgen1dd47082018-10-23 13:12:26 -0500217 self.resource_mgrs[pon_intf].update_alloc_ids_for_onu(pon_intf_onu_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700218 list(alloc_id))
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700219
220 return alloc_id
221
Girish Gowdruab836e92018-10-25 01:17:57 -0700222 def get_current_gemport_ids_for_onu(self, pon_intf_onu_id):
223 pon_intf_id = pon_intf_onu_id[0]
224 return self.resource_mgrs[pon_intf_id].get_current_gemport_ids_for_onu(pon_intf_onu_id)
225
Girish Gowdrub761bc12018-11-29 02:22:18 -0800226 def get_current_alloc_ids_for_onu(self, pon_intf_onu_id):
227 pon_intf_id = pon_intf_onu_id[0]
228 alloc_ids = self.resource_mgrs[pon_intf_id].get_current_alloc_ids_for_onu(pon_intf_onu_id)
229 if alloc_ids is None:
230 return None
231 # We support only one tcont at the moment
232 return alloc_ids[0]
233
Craig Lutgenabd9c842018-11-15 23:58:27 +0000234 def update_gemports_ponport_to_onu_map_on_kv_store(self, gemport_list, pon_port, onu_id, uni_id):
Girish Gowdruab836e92018-10-25 01:17:57 -0700235 for gemport in gemport_list:
236 pon_intf_gemport = (pon_port, gemport)
237 # This information is used when packet_indication is received and
238 # we need to derive the ONU Id for which the packet arrived based
239 # on the pon_intf and gemport available in the packet_indication
Craig Lutgenabd9c842018-11-15 23:58:27 +0000240 self.kv_store[str(pon_intf_gemport)] = ' '.join(map(str, (onu_id, uni_id)))
241
242 def get_onu_uni_from_ponport_gemport(self, pon_port, gemport):
243 pon_intf_gemport = (pon_port, gemport)
244 return tuple(map(int, self.kv_store[str(pon_intf_gemport)].split(' ')))
Girish Gowdruab836e92018-10-25 01:17:57 -0700245
246 def get_gemport_id(self, pon_intf_onu_id, num_of_id=1):
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700247 # Derive the pon_intf and onu_id from the pon_intf_onu_id tuple
248 pon_intf = pon_intf_onu_id[0]
249 onu_id = pon_intf_onu_id[1]
Craig Lutgenabd9c842018-11-15 23:58:27 +0000250 uni_id = pon_intf_onu_id[2]
251 assert False, 'unused function'
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700252
Craig Lutgen1dd47082018-10-23 13:12:26 -0500253 gemport_id_list = self.resource_mgrs[pon_intf].get_current_gemport_ids_for_onu(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700254 pon_intf_onu_id)
255 if gemport_id_list and len(gemport_id_list) > 0:
Girish Gowdruab836e92018-10-25 01:17:57 -0700256 return gemport_id_list
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700257
Craig Lutgen1dd47082018-10-23 13:12:26 -0500258 gemport_id_list = self.resource_mgrs[pon_intf].get_resource_id(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700259 pon_intf_id=pon_intf,
260 resource_type=PONResourceManager.GEMPORT_ID,
Girish Gowdruab836e92018-10-25 01:17:57 -0700261 num_of_id=num_of_id
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700262 )
263
264 if gemport_id_list and len(gemport_id_list) == 0:
265 self.log.error("no-gemport-id-available")
266 return None
267
268 # update the resource map on KV store with the list of gemport_id
269 # allocated for the pon_intf_onu_id tuple
Craig Lutgen1dd47082018-10-23 13:12:26 -0500270 self.resource_mgrs[pon_intf].update_gemport_ids_for_onu(pon_intf_onu_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700271 gemport_id_list)
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700272
Girish Gowdruab836e92018-10-25 01:17:57 -0700273 self.update_gemports_ponport_to_onu_map_on_kv_store(gemport_id_list,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000274 pon_intf, onu_id, uni_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700275 return gemport_id_list
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700276
277 def free_onu_id(self, pon_intf_id, onu_id):
Girish Gowdruab836e92018-10-25 01:17:57 -0700278 _ = self.resource_mgrs[pon_intf_id].free_resource_id(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700279 pon_intf_id, PONResourceManager.ONU_ID, onu_id)
280
281 pon_intf_onu_id = (pon_intf_id, onu_id)
Craig Lutgen1dd47082018-10-23 13:12:26 -0500282 self.resource_mgrs[pon_intf_id].remove_resource_map(
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700283 pon_intf_onu_id)
284
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800285 def free_flow_id(self, intf_id, onu_id, uni_id, flow_id):
286 self.resource_mgrs[intf_id].free_resource_id(
287 intf_id, PONResourceManager.FLOW_ID, flow_id)
288 intf_onu_id = (intf_id, onu_id, uni_id)
289 self.resource_mgrs[intf_id].update_flow_id_for_onu(intf_onu_id,
290 flow_id, False)
291 self.resource_mgrs[intf_id].remove_flow_id_info(intf_onu_id,
292 flow_id)
Girish Gowdruab836e92018-10-25 01:17:57 -0700293
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700294 def free_pon_resources_for_onu(self, pon_intf_id_onu_id):
295
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700296 pon_intf_id = pon_intf_id_onu_id[0]
297 onu_id = pon_intf_id_onu_id[1]
Craig Lutgen1dd47082018-10-23 13:12:26 -0500298 alloc_ids = \
299 self.resource_mgrs[pon_intf_id].get_current_alloc_ids_for_onu(pon_intf_id_onu_id)
300 self.resource_mgrs[pon_intf_id].free_resource_id(pon_intf_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700301 PONResourceManager.ALLOC_ID,
302 alloc_ids)
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700303
304 gemport_ids = \
Craig Lutgen1dd47082018-10-23 13:12:26 -0500305 self.resource_mgrs[pon_intf_id].get_current_gemport_ids_for_onu(pon_intf_id_onu_id)
306 self.resource_mgrs[pon_intf_id].free_resource_id(pon_intf_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700307 PONResourceManager.GEMPORT_ID,
308 gemport_ids)
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700309
Girish Gowdrub761bc12018-11-29 02:22:18 -0800310 flow_ids = \
311 self.resource_mgrs[pon_intf_id].get_current_flow_ids_for_onu(pon_intf_id_onu_id)
312 self.resource_mgrs[pon_intf_id].free_resource_id(pon_intf_id,
313 PONResourceManager.FLOW_ID,
314 flow_ids)
315
Craig Lutgen1dd47082018-10-23 13:12:26 -0500316 self.resource_mgrs[pon_intf_id].free_resource_id(pon_intf_id,
Girish Gowdruab836e92018-10-25 01:17:57 -0700317 PONResourceManager.ONU_ID,
318 onu_id)
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700319
320 # Clear resource map associated with (pon_intf_id, gemport_id) tuple.
Craig Lutgen1dd47082018-10-23 13:12:26 -0500321 self.resource_mgrs[pon_intf_id].remove_resource_map(pon_intf_id_onu_id)
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700322
323 # Clear the ONU Id associated with the (pon_intf_id, gemport_id) tuple.
324 for gemport_id in gemport_ids:
325 del self.kv_store[str((pon_intf_id, gemport_id))]
326
Craig Lutgen1dd47082018-10-23 13:12:26 -0500327 def initialize_device_resource_range_and_pool(self, resource_mgr, global_resource_mgr, arange):
328 self.log.info("resource-range-pool-init", technology=resource_mgr.technology)
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700329
Craig Lutgen1dd47082018-10-23 13:12:26 -0500330 # first load from KV profiles
331 status = resource_mgr.init_resource_ranges_from_kv_store()
332 if not status:
333 self.log.info("failed-to-load-resource-range-from-kv-store", technology=resource_mgr.technology)
334
335 # Then apply device specific information. If KV doesn't exist
336 # or is broader than the device, the device's informationw ill
337 # dictate the range limits
338 self.log.info("using-device-info-to-init-pon-resource-ranges", technology=resource_mgr.technology)
339
340 onu_id_start = self.device_info.onu_id_start
341 onu_id_end = self.device_info.onu_id_end
342 onu_id_shared = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.DEDICATED_PER_INTF
343 onu_id_shared_pool_id = None
344 alloc_id_start = self.device_info.alloc_id_start
345 alloc_id_end = self.device_info.alloc_id_end
Girish Gowdruab836e92018-10-25 01:17:57 -0700346 alloc_id_shared = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH # TODO EdgeCore/BAL limitation
Craig Lutgen1dd47082018-10-23 13:12:26 -0500347 alloc_id_shared_pool_id = None
348 gemport_id_start = self.device_info.gemport_id_start
349 gemport_id_end = self.device_info.gemport_id_end
Girish Gowdruab836e92018-10-25 01:17:57 -0700350 gemport_id_shared = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH # TODO EdgeCore/BAL limitation
Craig Lutgen1dd47082018-10-23 13:12:26 -0500351 gemport_id_shared_pool_id = None
Girish Gowdruab836e92018-10-25 01:17:57 -0700352 flow_id_start = self.device_info.flow_id_start
353 flow_id_end = self.device_info.flow_id_end
354 flow_id_shared = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH # TODO EdgeCore/BAL limitation
355 flow_id_shared_pool_id = None
Craig Lutgen1dd47082018-10-23 13:12:26 -0500356
357 global_pool_id = 0
Girish Gowdruab836e92018-10-25 01:17:57 -0700358 for first_intf_pool_id in arange.intf_ids:
359 break
Craig Lutgen1dd47082018-10-23 13:12:26 -0500360
361 for pool in arange.pools:
362 shared_pool_id = global_pool_id if pool.sharing == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH else \
Girish Gowdruab836e92018-10-25 01:17:57 -0700363 first_intf_pool_id if pool.sharing == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_SAME_TECH else \
364 None
Craig Lutgen1dd47082018-10-23 13:12:26 -0500365
366 if pool.type == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.ONU_ID:
367 onu_id_start = pool.start
368 onu_id_end = pool.end
369 onu_id_shared = pool.sharing
370 onu_id_shared_pool_id = shared_pool_id
371 elif pool.type == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.ALLOC_ID:
372 alloc_id_start = pool.start
373 alloc_id_end = pool.end
374 alloc_id_shared = pool.sharing
375 alloc_id_shared_pool_id = shared_pool_id
376 elif pool.type == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.GEMPORT_ID:
377 gemport_id_start = pool.start
378 gemport_id_end = pool.end
379 gemport_id_shared = pool.sharing
380 gemport_id_shared_pool_id = shared_pool_id
Girish Gowdruab836e92018-10-25 01:17:57 -0700381 elif pool.type == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.FLOW_ID:
382 flow_id_start = pool.start
383 flow_id_end = pool.end
384 flow_id_shared = pool.sharing
385 flow_id_shared_pool_id = shared_pool_id
Craig Lutgen1dd47082018-10-23 13:12:26 -0500386
387 self.log.info("device-info-init", technology=arange.technology,
Girish Gowdruab836e92018-10-25 01:17:57 -0700388 onu_id_start=onu_id_start, onu_id_end=onu_id_end, onu_id_shared_pool_id=onu_id_shared_pool_id,
389 alloc_id_start=alloc_id_start, alloc_id_end=alloc_id_end,
390 alloc_id_shared_pool_id=alloc_id_shared_pool_id,
391 gemport_id_start=gemport_id_start, gemport_id_end=gemport_id_end,
392 gemport_id_shared_pool_id=gemport_id_shared_pool_id,
393 flow_id_start_idx=flow_id_start,
394 flow_id_end_idx=flow_id_end,
395 flow_id_shared_pool_id=flow_id_shared_pool_id,
Craig Lutgenb25ca142018-12-13 10:22:35 -0600396 intf_ids=arange.intf_ids,
397 uni_id_start_idx=0,
398 uni_id_end_idx=self.max_uni_id_per_onu)
Craig Lutgen1dd47082018-10-23 13:12:26 -0500399
400 resource_mgr.init_default_pon_resource_ranges(
Girish Gowdruab836e92018-10-25 01:17:57 -0700401 onu_id_start_idx=onu_id_start,
402 onu_id_end_idx=onu_id_end,
403 onu_id_shared_pool_id=onu_id_shared_pool_id,
404 alloc_id_start_idx=alloc_id_start,
405 alloc_id_end_idx=alloc_id_end,
406 alloc_id_shared_pool_id=alloc_id_shared_pool_id,
407 gemport_id_start_idx=gemport_id_start,
408 gemport_id_end_idx=gemport_id_end,
409 gemport_id_shared_pool_id=gemport_id_shared_pool_id,
410 flow_id_start_idx=flow_id_start,
411 flow_id_end_idx=flow_id_end,
412 flow_id_shared_pool_id=flow_id_shared_pool_id,
Craig Lutgenabd9c842018-11-15 23:58:27 +0000413 uni_id_start_idx=0, uni_id_end_idx=self.max_uni_id_per_onu,
Girish Gowdruab836e92018-10-25 01:17:57 -0700414 num_of_pon_ports=self.device_info.pon_ports,
415 intf_ids=arange.intf_ids
416 )
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700417
Craig Lutgen1dd47082018-10-23 13:12:26 -0500418 # For global sharing, make sure to refresh both local and global resource manager instances' range
419 if global_resource_mgr is not self:
420 if onu_id_shared == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH:
421 global_resource_mgr.update_ranges(onu_id_start_idx=onu_id_start, onu_id_end_idx=onu_id_end)
422 resource_mgr.update_ranges(onu_id_start_idx=onu_id_start, onu_id_end_idx=onu_id_end,
Girish Gowdruab836e92018-10-25 01:17:57 -0700423 onu_id_shared_resource_mgr=global_resource_mgr)
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700424
Craig Lutgen1dd47082018-10-23 13:12:26 -0500425 if alloc_id_shared == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH:
426 global_resource_mgr.update_ranges(alloc_id_start_idx=alloc_id_start, alloc_id_end_idx=alloc_id_end)
427 resource_mgr.update_ranges(alloc_id_start_idx=alloc_id_start, alloc_id_end_idx=alloc_id_end,
Girish Gowdruab836e92018-10-25 01:17:57 -0700428 alloc_id_shared_resource_mgr=global_resource_mgr)
Craig Lutgen1dd47082018-10-23 13:12:26 -0500429
430 if gemport_id_shared == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH:
Girish Gowdruab836e92018-10-25 01:17:57 -0700431 global_resource_mgr.update_ranges(gemport_id_start_idx=gemport_id_start,
432 gemport_id_end_idx=gemport_id_end)
Craig Lutgen1dd47082018-10-23 13:12:26 -0500433 resource_mgr.update_ranges(gemport_id_start_idx=gemport_id_start, gemport_id_end_idx=gemport_id_end,
Girish Gowdruab836e92018-10-25 01:17:57 -0700434 gemport_id_shared_resource_mgr=global_resource_mgr)
435
436 if flow_id_shared == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH:
437 global_resource_mgr.update_ranges(flow_id_start_idx=flow_id_start,
438 flow_id_end_idx=flow_id_end)
439 resource_mgr.update_ranges(flow_id_start_idx=flow_id_start, flow_id_end_idx=flow_id_end,
440 flow_id_shared_resource_mgr=global_resource_mgr)
Craig Lutgenabd9c842018-11-15 23:58:27 +0000441
442 # Make sure loaded range fits the platform bit encoding ranges
443 resource_mgr.update_ranges(uni_id_start_idx=0, uni_id_end_idx=OpenOltPlatform.MAX_UNIS_PER_ONU-1)
Girish Gowdru50f62fb2019-02-04 22:16:15 -0800444
445 def is_flow_cookie_on_kv_store(self, intf_id, onu_id, uni_id, flow_store_cookie):
446 '''
447 Note: For flows which trap from the NNI and not really associated with any particular
448 ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id.
449 '''
450 intf_onu_id = (intf_id, onu_id, uni_id)
451 try:
452 flow_ids = self.resource_mgrs[intf_id]. \
453 get_current_flow_ids_for_onu(intf_onu_id)
454 if flow_ids is not None:
455 for flow_id in flow_ids:
456 flows = self.get_flow_id_info(intf_id, onu_id, uni_id, flow_id)
457 assert (isinstance(flows, list))
458 for flow in flows:
459 if flow['flow_store_cookie'] == flow_store_cookie:
460 return True
461 except Exception as e:
462 self.log.error("error-retrieving-flow-info", e=e)
463
464 return False
Thiyagarajan Subramani353af122019-02-20 23:14:24 -0800465
466 def get_tech_profile_id_for_onu(self, intf_id, onu_id, uni_id):
467 intf_id_onu_id_uni_id = (intf_id, onu_id, uni_id)
468 try:
469 kv_path = OpenOltResourceMgr.TP_ID_PATH_SUFFIX.format(str(intf_id_onu_id_uni_id))
470 return int(self.kv_store[kv_path])
471 except Exception as e:
472 self.log.warn("tp-id-not-found-on-kv-store", e=e)
473 return DEFAULT_TECH_PROFILE_TABLE_ID