Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 1 | # |
| 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 | |
| 17 | import structlog |
| 18 | |
| 19 | from common.pon_resource_manager.resource_manager import PONResourceManager |
| 20 | from voltha.registry import registry |
| 21 | from voltha.core.config.config_backend import ConsulStore |
| 22 | from voltha.core.config.config_backend import EtcdStore |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 23 | from voltha.adapters.openolt.openolt_flow_mgr import * |
| 24 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 25 | from voltha.adapters.openolt.protos import openolt_pb2 |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 26 | from voltha.adapters.openolt.openolt_platform import OpenOltPlatform |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 27 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 28 | |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 29 | class OpenOltResourceMgr(object): |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 30 | BASE_PATH_KV_STORE = "service/voltha/openolt/{}" # service/voltha/openolt/<device_id> |
Thiyagarajan Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame^] | 31 | TP_ID_PATH_SUFFIX = 'tp_id/{}' |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 32 | |
| 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 Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 43 | 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 Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 55 | ranges = dict() |
| 56 | resource_mgrs_by_tech = dict() |
| 57 | self.resource_mgrs = dict() |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 58 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 59 | # 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 Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 66 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 67 | 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 Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 85 | 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 Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 91 | # 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 Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 98 | extra_args = self.extra_args + ' ' + PONResourceManager.OLT_MODEL_ARG + ' {}'.format(self.device_info.model) |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 99 | resource_mgr = PONResourceManager(technology, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 100 | extra_args, self.device_id, self.args.backend, host, port) |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 101 | resource_mgrs_by_tech[technology] = resource_mgr |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 102 | if global_resource_mgr is None: |
| 103 | global_resource_mgr = resource_mgr |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 104 | 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 Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 112 | |
| 113 | def __del__(self): |
| 114 | self.log.info("clearing-device-resource-pool") |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 115 | for key, resource_mgr in self.resource_mgrs.iteritems(): |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 116 | resource_mgr.clear_device_resource_pool() |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 117 | |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 118 | 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 Lutgen | b25ca14 | 2018-12-13 10:22:35 -0600 | [diff] [blame] | 125 | @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 Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 129 | 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 Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 133 | def get_onu_id(self, pon_intf_id): |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 134 | onu_id = self.resource_mgrs[pon_intf_id].get_resource_id( |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 135 | pon_intf_id, PONResourceManager.ONU_ID, 1) |
| 136 | |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 137 | return onu_id |
| 138 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 139 | def get_flow_id(self, intf_id, onu_id, uni_id, flow_store_cookie, |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 140 | flow_category=None): |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 141 | intf_onu_id = (intf_id, onu_id, uni_id) |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 142 | try: |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 143 | flow_ids = self.resource_mgrs[intf_id]. \ |
| 144 | get_current_flow_ids_for_onu(intf_onu_id) |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 145 | if flow_ids is not None: |
| 146 | for flow_id in flow_ids: |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 147 | flows = self.get_flow_id_info(intf_id, onu_id, uni_id, flow_id) |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 148 | 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 Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 160 | flow_id = self.resource_mgrs[intf_id].get_resource_id( |
| 161 | intf_onu_id[0], PONResourceManager.FLOW_ID) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 162 | if flow_id is not None: |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 163 | self.resource_mgrs[intf_id].update_flow_id_for_onu( |
| 164 | intf_onu_id, flow_id |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 165 | ) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 166 | |
| 167 | return flow_id |
| 168 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 169 | 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 Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 176 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 177 | 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 Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 184 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 185 | 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 Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 193 | |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 194 | 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 Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 197 | alloc_id_list = self.resource_mgrs[pon_intf].get_current_alloc_ids_for_onu( |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 198 | 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 Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 206 | alloc_id = self.resource_mgrs[pon_intf].get_resource_id( |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 207 | pon_intf_id=pon_intf, |
| 208 | resource_type=PONResourceManager.ALLOC_ID, |
| 209 | num_of_id=1 |
| 210 | ) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 211 | if alloc_id is None: |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 212 | 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 Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 217 | self.resource_mgrs[pon_intf].update_alloc_ids_for_onu(pon_intf_onu_id, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 218 | list(alloc_id)) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 219 | |
| 220 | return alloc_id |
| 221 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 222 | 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 Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 226 | 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 Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 234 | def update_gemports_ponport_to_onu_map_on_kv_store(self, gemport_list, pon_port, onu_id, uni_id): |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 235 | 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 Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 240 | 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 Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 245 | |
| 246 | def get_gemport_id(self, pon_intf_onu_id, num_of_id=1): |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 247 | # 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 Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 250 | uni_id = pon_intf_onu_id[2] |
| 251 | assert False, 'unused function' |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 252 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 253 | gemport_id_list = self.resource_mgrs[pon_intf].get_current_gemport_ids_for_onu( |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 254 | pon_intf_onu_id) |
| 255 | if gemport_id_list and len(gemport_id_list) > 0: |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 256 | return gemport_id_list |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 257 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 258 | gemport_id_list = self.resource_mgrs[pon_intf].get_resource_id( |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 259 | pon_intf_id=pon_intf, |
| 260 | resource_type=PONResourceManager.GEMPORT_ID, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 261 | num_of_id=num_of_id |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 262 | ) |
| 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 Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 270 | self.resource_mgrs[pon_intf].update_gemport_ids_for_onu(pon_intf_onu_id, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 271 | gemport_id_list) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 272 | |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 273 | self.update_gemports_ponport_to_onu_map_on_kv_store(gemport_id_list, |
Craig Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 274 | pon_intf, onu_id, uni_id) |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 275 | return gemport_id_list |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 276 | |
| 277 | def free_onu_id(self, pon_intf_id, onu_id): |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 278 | _ = self.resource_mgrs[pon_intf_id].free_resource_id( |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 279 | pon_intf_id, PONResourceManager.ONU_ID, onu_id) |
| 280 | |
| 281 | pon_intf_onu_id = (pon_intf_id, onu_id) |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 282 | self.resource_mgrs[pon_intf_id].remove_resource_map( |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 283 | pon_intf_onu_id) |
| 284 | |
Girish Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 285 | 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 Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 293 | |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 294 | def free_pon_resources_for_onu(self, pon_intf_id_onu_id): |
| 295 | |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 296 | pon_intf_id = pon_intf_id_onu_id[0] |
| 297 | onu_id = pon_intf_id_onu_id[1] |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 298 | 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 Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 301 | PONResourceManager.ALLOC_ID, |
| 302 | alloc_ids) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 303 | |
| 304 | gemport_ids = \ |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 305 | 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 Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 307 | PONResourceManager.GEMPORT_ID, |
| 308 | gemport_ids) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 309 | |
Girish Gowdru | b761bc1 | 2018-11-29 02:22:18 -0800 | [diff] [blame] | 310 | 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 Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 316 | self.resource_mgrs[pon_intf_id].free_resource_id(pon_intf_id, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 317 | PONResourceManager.ONU_ID, |
| 318 | onu_id) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 319 | |
| 320 | # Clear resource map associated with (pon_intf_id, gemport_id) tuple. |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 321 | self.resource_mgrs[pon_intf_id].remove_resource_map(pon_intf_id_onu_id) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 322 | |
| 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 Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 327 | 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 Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 329 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 330 | # 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 Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 346 | alloc_id_shared = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH # TODO EdgeCore/BAL limitation |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 347 | 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 Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 350 | gemport_id_shared = openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH # TODO EdgeCore/BAL limitation |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 351 | gemport_id_shared_pool_id = None |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 352 | 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 Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 356 | |
| 357 | global_pool_id = 0 |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 358 | for first_intf_pool_id in arange.intf_ids: |
| 359 | break |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 360 | |
| 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 Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 363 | first_intf_pool_id if pool.sharing == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_SAME_TECH else \ |
| 364 | None |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 365 | |
| 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 Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 381 | 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 Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 386 | |
| 387 | self.log.info("device-info-init", technology=arange.technology, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 388 | 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 Lutgen | b25ca14 | 2018-12-13 10:22:35 -0600 | [diff] [blame] | 396 | intf_ids=arange.intf_ids, |
| 397 | uni_id_start_idx=0, |
| 398 | uni_id_end_idx=self.max_uni_id_per_onu) |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 399 | |
| 400 | resource_mgr.init_default_pon_resource_ranges( |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 401 | 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 Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 413 | uni_id_start_idx=0, uni_id_end_idx=self.max_uni_id_per_onu, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 414 | num_of_pon_ports=self.device_info.pon_ports, |
| 415 | intf_ids=arange.intf_ids |
| 416 | ) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 417 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 418 | # 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 Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 423 | onu_id_shared_resource_mgr=global_resource_mgr) |
Girish Gowdru | 1e77ea0 | 2018-09-24 09:10:35 -0700 | [diff] [blame] | 424 | |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 425 | 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 Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 428 | alloc_id_shared_resource_mgr=global_resource_mgr) |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 429 | |
| 430 | if gemport_id_shared == openolt_pb2.DeviceInfo.DeviceResourceRanges.Pool.SHARED_BY_ALL_INTF_ALL_TECH: |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 431 | global_resource_mgr.update_ranges(gemport_id_start_idx=gemport_id_start, |
| 432 | gemport_id_end_idx=gemport_id_end) |
Craig Lutgen | 1dd4708 | 2018-10-23 13:12:26 -0500 | [diff] [blame] | 433 | resource_mgr.update_ranges(gemport_id_start_idx=gemport_id_start, gemport_id_end_idx=gemport_id_end, |
Girish Gowdru | ab836e9 | 2018-10-25 01:17:57 -0700 | [diff] [blame] | 434 | 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 Lutgen | abd9c84 | 2018-11-15 23:58:27 +0000 | [diff] [blame] | 441 | |
| 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 Gowdru | 50f62fb | 2019-02-04 22:16:15 -0800 | [diff] [blame] | 444 | |
| 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 Subramani | 353af12 | 2019-02-20 23:14:24 -0800 | [diff] [blame^] | 465 | |
| 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 |