blob: 3be01bc5878affc533ec52c5a6a2660a40681b73 [file] [log] [blame]
Girish Gowdra64503432020-01-07 10:59:10 +05301/*
2 * Copyright 2019-present Open Networking Foundation
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//Package resourcemanager provides the utility for managing resources
18package core
19
20import (
21 "errors"
22 "fmt"
23 "strconv"
24 "strings"
25
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030026 "github.com/opencord/voltha-lib-go/v3/pkg/log"
27 ponrmgr "github.com/opencord/voltha-lib-go/v3/pkg/ponresourcemanager"
28 "github.com/opencord/voltha-protos/v3/go/openolt"
29 "golang.org/x/net/context"
Girish Gowdra64503432020-01-07 10:59:10 +053030)
31
32func init() {
33 _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
34}
35
36// OpenOltResourceMgr holds resource related information as provided below for each field
37type OpenOltResourceMgr struct {
38 deviceInfo *openolt.DeviceInfo
39 // array of pon resource managers per interface technology
40 ResourceMgrs map[uint32]*ponrmgr.PONResourceManager
41}
42
43// NewResourceMgr init a New resource manager instance which in turn instantiates pon resource manager
44// instances according to technology. Initializes the default resource ranges for all
45// the resources.
46func NewResourceMgr(deviceID string, KVStoreHostPort string, kvStoreType string, deviceType string, devInfo *openolt.DeviceInfo) *OpenOltResourceMgr {
47 var ResourceMgr OpenOltResourceMgr
48 log.Debugf("Init new resource manager")
49
50 ResourceMgr.deviceInfo = devInfo
51
52 Ranges := make(map[string]*openolt.DeviceInfo_DeviceResourceRanges)
53 RsrcMgrsByTech := make(map[string]*ponrmgr.PONResourceManager)
54 ResourceMgr.ResourceMgrs = make(map[uint32]*ponrmgr.PONResourceManager)
55
56 // TODO self.args = registry('main').get_args()
57
58 /*
59 If a legacy driver returns protobuf without any ranges,s synthesize one from
60 the legacy global per-device information. This, in theory, is temporary until
61 the legacy drivers are upgrade to support pool ranges.
62 */
63 if devInfo.Ranges == nil {
64 var ranges openolt.DeviceInfo_DeviceResourceRanges
65 ranges.Technology = devInfo.GetTechnology()
66
67 NumPONPorts := devInfo.GetPonPorts()
68 var index uint32
69 for index = 0; index < NumPONPorts; index++ {
70 ranges.IntfIds = append(ranges.IntfIds, index)
71 }
72
73 var Pool openolt.DeviceInfo_DeviceResourceRanges_Pool
74 Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_ONU_ID
75 Pool.Start = devInfo.OnuIdStart
76 Pool.End = devInfo.OnuIdEnd
77 Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF
78 onuPool := Pool
79 ranges.Pools = append(ranges.Pools, &onuPool)
80
81 Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_ALLOC_ID
82 Pool.Start = devInfo.AllocIdStart
83 Pool.End = devInfo.AllocIdEnd
84 Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH
85 allocPool := Pool
86 ranges.Pools = append(ranges.Pools, &allocPool)
87
88 Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_GEMPORT_ID
89 Pool.Start = devInfo.GemportIdStart
90 Pool.End = devInfo.GemportIdEnd
91 Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH
92 gemPool := Pool
93 ranges.Pools = append(ranges.Pools, &gemPool)
94
95 Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_FLOW_ID
96 Pool.Start = devInfo.FlowIdStart
97 Pool.End = devInfo.FlowIdEnd
98 Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH
99 ranges.Pools = append(ranges.Pools, &Pool)
100 // Add to device info
101 devInfo.Ranges = append(devInfo.Ranges, &ranges)
102 }
103
104 // Create a separate Resource Manager instance for each range. This assumes that
105 // each technology is represented by only a single range
106 var GlobalPONRsrcMgr *ponrmgr.PONResourceManager
107 var err error
108 IPPort := strings.Split(KVStoreHostPort, ":")
109 for _, TechRange := range devInfo.Ranges {
110 technology := TechRange.Technology
111 log.Debugf("Device info technology %s", technology)
112 Ranges[technology] = TechRange
113 port, _ := strconv.Atoi(IPPort[1])
114 RsrcMgrsByTech[technology], err = ponrmgr.NewPONResourceManager(technology, deviceType, deviceID,
115 kvStoreType, IPPort[0], port)
116 if err != nil {
117 log.Errorf("Failed to create pon resource manager instance for technology %s", technology)
118 return nil
119 }
120 // resource_mgrs_by_tech[technology] = resource_mgr
121 if GlobalPONRsrcMgr == nil {
122 GlobalPONRsrcMgr = RsrcMgrsByTech[technology]
123 }
124 for _, IntfID := range TechRange.IntfIds {
125 ResourceMgr.ResourceMgrs[(IntfID)] = RsrcMgrsByTech[technology]
126 }
127 // self.initialize_device_resource_range_and_pool(resource_mgr, global_resource_mgr, arange)
128 InitializeDeviceResourceRangeAndPool(RsrcMgrsByTech[technology], GlobalPONRsrcMgr,
129 TechRange, devInfo)
130 }
131 // After we have initialized resource ranges, initialize the
132 // resource pools accordingly.
133 for _, PONRMgr := range RsrcMgrsByTech {
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300134 _ = PONRMgr.InitDeviceResourcePool(context.Background())
Girish Gowdra64503432020-01-07 10:59:10 +0530135 }
136 log.Info("Initialization of resource manager success!")
137 return &ResourceMgr
138}
139
140// InitializeDeviceResourceRangeAndPool initializes the resource range pool according to the sharing type, then apply
141// device specific information. If KV doesn't exist
142// or is broader than the device, the device's information will
143// dictate the range limits
144func InitializeDeviceResourceRangeAndPool(ponRMgr *ponrmgr.PONResourceManager, globalPONRMgr *ponrmgr.PONResourceManager,
145 techRange *openolt.DeviceInfo_DeviceResourceRanges, devInfo *openolt.DeviceInfo) {
146
147 // init the resource range pool according to the sharing type
148
149 log.Debugf("Resource range pool init for technology %s", ponRMgr.Technology)
150 // first load from KV profiles
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300151 status := ponRMgr.InitResourceRangesFromKVStore(context.Background())
Girish Gowdra64503432020-01-07 10:59:10 +0530152 if !status {
153 log.Debugf("Failed to load resource ranges from KV store for tech %s", ponRMgr.Technology)
154 }
155
156 /*
157 Then apply device specific information. If KV doesn't exist
158 or is broader than the device, the device's information will
159 dictate the range limits
160 */
161 log.Debugf("Using device info to init pon resource ranges for tech", ponRMgr.Technology)
162
163 ONUIDStart := devInfo.OnuIdStart
164 ONUIDEnd := devInfo.OnuIdEnd
165 ONUIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF
166 ONUIDSharedPoolID := uint32(0)
167 AllocIDStart := devInfo.AllocIdStart
168 AllocIDEnd := devInfo.AllocIdEnd
169 AllocIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH // TODO EdgeCore/BAL limitation
170 AllocIDSharedPoolID := uint32(0)
171 GEMPortIDStart := devInfo.GemportIdStart
172 GEMPortIDEnd := devInfo.GemportIdEnd
173 GEMPortIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH // TODO EdgeCore/BAL limitation
174 GEMPortIDSharedPoolID := uint32(0)
175 FlowIDStart := devInfo.FlowIdStart
176 FlowIDEnd := devInfo.FlowIdEnd
177 FlowIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH // TODO EdgeCore/BAL limitation
178 FlowIDSharedPoolID := uint32(0)
179
180 var FirstIntfPoolID uint32
181 var SharedPoolID uint32
182
183 /*
184 * As a zero check is made against SharedPoolID to check whether the resources are shared across all intfs
185 * if resources are shared across interfaces then SharedPoolID is given a positive number.
186 */
187 for _, FirstIntfPoolID = range techRange.IntfIds {
188 // skip the intf id 0
189 if FirstIntfPoolID == 0 {
190 continue
191 }
192 break
193 }
194
195 for _, RangePool := range techRange.Pools {
196 if RangePool.Sharing == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
197 SharedPoolID = FirstIntfPoolID
198 } else if RangePool.Sharing == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_SAME_TECH {
199 SharedPoolID = FirstIntfPoolID
200 } else {
201 SharedPoolID = 0
202 }
203 if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_ONU_ID {
204 ONUIDStart = RangePool.Start
205 ONUIDEnd = RangePool.End
206 ONUIDShared = RangePool.Sharing
207 ONUIDSharedPoolID = SharedPoolID
208 } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_ALLOC_ID {
209 AllocIDStart = RangePool.Start
210 AllocIDEnd = RangePool.End
211 AllocIDShared = RangePool.Sharing
212 AllocIDSharedPoolID = SharedPoolID
213 } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_GEMPORT_ID {
214 GEMPortIDStart = RangePool.Start
215 GEMPortIDEnd = RangePool.End
216 GEMPortIDShared = RangePool.Sharing
217 GEMPortIDSharedPoolID = SharedPoolID
218 } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_FLOW_ID {
219 FlowIDStart = RangePool.Start
220 FlowIDEnd = RangePool.End
221 FlowIDShared = RangePool.Sharing
222 FlowIDSharedPoolID = SharedPoolID
223 }
224 }
225
226 log.Debugw("Device info init", log.Fields{"technology": techRange.Technology,
227 "onu_id_start": ONUIDStart, "onu_id_end": ONUIDEnd, "onu_id_shared_pool_id": ONUIDSharedPoolID,
228 "alloc_id_start": AllocIDStart, "alloc_id_end": AllocIDEnd,
229 "alloc_id_shared_pool_id": AllocIDSharedPoolID,
230 "gemport_id_start": GEMPortIDStart, "gemport_id_end": GEMPortIDEnd,
231 "gemport_id_shared_pool_id": GEMPortIDSharedPoolID,
232 "flow_id_start": FlowIDStart,
233 "flow_id_end_idx": FlowIDEnd,
234 "flow_id_shared_pool_id": FlowIDSharedPoolID,
235 "intf_ids": techRange.IntfIds,
236 "uni_id_start": 0,
237 "uni_id_end_idx": 1, /*MaxUNIIDperONU()*/
238 })
239
240 ponRMgr.InitDefaultPONResourceRanges(ONUIDStart, ONUIDEnd, ONUIDSharedPoolID,
241 AllocIDStart, AllocIDEnd, AllocIDSharedPoolID,
242 GEMPortIDStart, GEMPortIDEnd, GEMPortIDSharedPoolID,
243 FlowIDStart, FlowIDEnd, FlowIDSharedPoolID, 0, 1,
244 devInfo.PonPorts, techRange.IntfIds)
245
246 // For global sharing, make sure to refresh both local and global resource manager instances' range
247
248 if ONUIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
249 globalPONRMgr.UpdateRanges(ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd,
250 "", 0, nil)
251 ponRMgr.UpdateRanges(ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd,
252 "", 0, globalPONRMgr)
253 }
254 if AllocIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
255 globalPONRMgr.UpdateRanges(ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd,
256 "", 0, nil)
257
258 ponRMgr.UpdateRanges(ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd,
259 "", 0, globalPONRMgr)
260 }
261 if GEMPortIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
262 globalPONRMgr.UpdateRanges(ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd,
263 "", 0, nil)
264 ponRMgr.UpdateRanges(ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd,
265 "", 0, globalPONRMgr)
266 }
267 if FlowIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
268 globalPONRMgr.UpdateRanges(ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd,
269 "", 0, nil)
270 ponRMgr.UpdateRanges(ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd,
271 "", 0, globalPONRMgr)
272 }
273
274 // Make sure loaded range fits the platform bit encoding ranges
275 ponRMgr.UpdateRanges(ponrmgr.UNI_ID_START_IDX, 0, ponrmgr.UNI_ID_END_IDX /* TODO =OpenOltPlatform.MAX_UNIS_PER_ONU-1*/, 1, "", 0, nil)
276}
277
278// Delete clears used resources for the particular olt device being deleted
279func (RsrcMgr *OpenOltResourceMgr) Delete() error {
280 /* TODO
281 def __del__(self):
282 self.log.info("clearing-device-resource-pool")
283 for key, resource_mgr in self.resource_mgrs.iteritems():
284 resource_mgr.clear_device_resource_pool()
285
286 def assert_pon_id_limit(self, pon_intf_id):
287 assert pon_intf_id in self.resource_mgrs
288
289 def assert_onu_id_limit(self, pon_intf_id, onu_id):
290 self.assert_pon_id_limit(pon_intf_id)
291 self.resource_mgrs[pon_intf_id].assert_resource_limits(onu_id, PONResourceManager.ONU_ID)
292
293 @property
294 def max_uni_id_per_onu(self):
295 return 0 #OpenOltPlatform.MAX_UNIS_PER_ONU-1, zero-based indexing Uncomment or override to make default multi-uni
296
297 def assert_uni_id_limit(self, pon_intf_id, onu_id, uni_id):
298 self.assert_onu_id_limit(pon_intf_id, onu_id)
299 self.resource_mgrs[pon_intf_id].assert_resource_limits(uni_id, PONResourceManager.UNI_ID)
300 */
301 for _, rsrcMgr := range RsrcMgr.ResourceMgrs {
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300302 if err := rsrcMgr.ClearDeviceResourcePool(context.Background()); err != nil {
Girish Gowdra64503432020-01-07 10:59:10 +0530303 log.Debug("Failed to clear device resource pool")
304 return err
305 }
306 }
307 log.Debug("Cleared device resource pool")
308 return nil
309}
310
311// GetONUID returns the available OnuID for the given pon-port
312func (RsrcMgr *OpenOltResourceMgr) GetONUID(ponIntfID uint32) (uint32, error) {
313 // Check if Pon Interface ID is present in Resource-manager-map
314 if _, ok := RsrcMgr.ResourceMgrs[ponIntfID]; !ok {
315 err := errors.New("invalid-pon-interface-" + strconv.Itoa(int(ponIntfID)))
316 return 0, err
317 }
318 // Get ONU id for a provided pon interface ID.
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300319 ONUID, err := RsrcMgr.ResourceMgrs[ponIntfID].GetResourceID(context.Background(), ponIntfID,
Girish Gowdra64503432020-01-07 10:59:10 +0530320 ponrmgr.ONU_ID, 1)
321 if err != nil {
322 log.Errorf("Failed to get resource for interface %d for type %s",
323 ponIntfID, ponrmgr.ONU_ID)
324 return 0, err
325 }
326 if ONUID != nil {
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300327 RsrcMgr.ResourceMgrs[ponIntfID].InitResourceMap(context.Background(), fmt.Sprintf("%d,%d", ponIntfID, ONUID[0]))
Girish Gowdra64503432020-01-07 10:59:10 +0530328 return ONUID[0], err
329 }
330
331 return 0, err // return OnuID 0 on error
332}
333
334// GetAllocID return the first Alloc ID for a given pon interface id and onu id and then update the resource map on
335// the KV store with the list of alloc_ids allocated for the pon_intf_onu_id tuple
336// Currently of all the alloc_ids available, it returns the first alloc_id in the list for tha given ONU
337func (RsrcMgr *OpenOltResourceMgr) GetAllocID(intfID uint32, onuID uint32, uniID uint32) uint32 {
338
339 var err error
340 IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", intfID, onuID, uniID)
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300341 AllocID := RsrcMgr.ResourceMgrs[intfID].GetCurrentAllocIDForOnu(context.Background(), IntfOnuIDUniID)
Girish Gowdra64503432020-01-07 10:59:10 +0530342 if AllocID != nil {
343 // Since we support only one alloc_id for the ONU at the moment,
344 // return the first alloc_id in the list, if available, for that
345 // ONU.
346 log.Debugw("Retrieved alloc ID from pon resource mgr", log.Fields{"AllocID": AllocID})
347 return AllocID[0]
348 }
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300349 AllocID, err = RsrcMgr.ResourceMgrs[intfID].GetResourceID(context.Background(), intfID,
Girish Gowdra64503432020-01-07 10:59:10 +0530350 ponrmgr.ALLOC_ID, 1)
351
352 if AllocID == nil || err != nil {
353 log.Error("Failed to allocate alloc id")
354 return 0
355 }
356 // update the resource map on KV store with the list of alloc_id
357 // allocated for the pon_intf_onu_id tuple
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300358 err = RsrcMgr.ResourceMgrs[intfID].UpdateAllocIdsForOnu(context.Background(), IntfOnuIDUniID, AllocID)
Girish Gowdra64503432020-01-07 10:59:10 +0530359 if err != nil {
360 log.Error("Failed to update Alloc ID")
361 return 0
362 }
363 log.Debugw("Allocated new Tcont from pon resource mgr", log.Fields{"AllocID": AllocID})
364 return AllocID[0]
365}
366
367// GetGEMPortID gets gem port id for a particular pon port, onu id and uni id and then update the resource map on
368// the KV store with the list of gemport_id allocated for the pon_intf_onu_id tuple
369func (RsrcMgr *OpenOltResourceMgr) GetGEMPortID(ponPort uint32, onuID uint32,
370 uniID uint32, NumOfPorts uint32) ([]uint32, error) {
371
372 /* Get gem port id for a particular pon port, onu id
373 and uni id.
374 */
375
376 var err error
377 IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", ponPort, onuID, uniID)
378
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300379 GEMPortList := RsrcMgr.ResourceMgrs[ponPort].GetCurrentGEMPortIDsForOnu(context.Background(), IntfOnuIDUniID)
Girish Gowdra64503432020-01-07 10:59:10 +0530380 if GEMPortList != nil {
381 return GEMPortList, nil
382 }
383
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300384 GEMPortList, err = RsrcMgr.ResourceMgrs[ponPort].GetResourceID(context.Background(), ponPort,
Girish Gowdra64503432020-01-07 10:59:10 +0530385 ponrmgr.GEMPORT_ID, NumOfPorts)
386 if err != nil && GEMPortList == nil {
387 log.Errorf("Failed to get gem port id for %s", IntfOnuIDUniID)
388 return nil, err
389 }
390
391 // update the resource map on KV store with the list of gemport_id
392 // allocated for the pon_intf_onu_id tuple
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300393 err = RsrcMgr.ResourceMgrs[ponPort].UpdateGEMPortIDsForOnu(context.Background(), IntfOnuIDUniID,
Girish Gowdra64503432020-01-07 10:59:10 +0530394 GEMPortList)
395 if err != nil {
396 log.Errorf("Failed to update GEM ports to kv store for %s", IntfOnuIDUniID)
397 return nil, err
398 }
399
400 return GEMPortList, err
401}
402
403// FreeFlowID returns the free flow id for a given interface, onu id and uni id
404func (RsrcMgr *OpenOltResourceMgr) FreeFlowID(IntfID uint32, onuID int32,
405 uniID int32, FlowID uint32) {
406 var IntfONUID string
407 var err error
408 FlowIds := make([]uint32, 0)
409
410 FlowIds = append(FlowIds, FlowID)
411 IntfONUID = fmt.Sprintf("%d,%d,%d", IntfID, onuID, uniID)
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300412 err = RsrcMgr.ResourceMgrs[IntfID].UpdateFlowIDForOnu(context.Background(), IntfONUID, FlowID, false)
Girish Gowdra64503432020-01-07 10:59:10 +0530413 if err != nil {
414 log.Errorw("Failed to Update flow id for", log.Fields{"intf": IntfONUID})
415 }
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300416 RsrcMgr.ResourceMgrs[IntfID].RemoveFlowIDInfo(context.Background(), IntfONUID, FlowID)
417 RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(context.Background(), IntfID, ponrmgr.FLOW_ID, FlowIds)
Girish Gowdra64503432020-01-07 10:59:10 +0530418}
419
420// FreeFlowIDs releases the flow Ids
421func (RsrcMgr *OpenOltResourceMgr) FreeFlowIDs(IntfID uint32, onuID uint32,
422 uniID uint32, FlowID []uint32) {
423
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300424 RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(context.Background(), IntfID, ponrmgr.FLOW_ID, FlowID)
Girish Gowdra64503432020-01-07 10:59:10 +0530425
426 var IntfOnuIDUniID string
427 var err error
428 for _, flow := range FlowID {
429 IntfOnuIDUniID = fmt.Sprintf("%d,%d,%d", IntfID, onuID, uniID)
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300430 err = RsrcMgr.ResourceMgrs[IntfID].UpdateFlowIDForOnu(context.Background(), IntfOnuIDUniID, flow, false)
Girish Gowdra64503432020-01-07 10:59:10 +0530431 if err != nil {
432 log.Errorw("Failed to Update flow id for", log.Fields{"intf": IntfOnuIDUniID})
433 }
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300434 RsrcMgr.ResourceMgrs[IntfID].RemoveFlowIDInfo(context.Background(), IntfOnuIDUniID, flow)
Girish Gowdra64503432020-01-07 10:59:10 +0530435 }
436}
437
438// FreeAllocID frees AllocID on the PON resource pool and also frees the allocID association
439// for the given OLT device.
440func (RsrcMgr *OpenOltResourceMgr) FreeAllocID(IntfID uint32, allocID uint32) {
441 allocIDs := make([]uint32, 0)
442 allocIDs = append(allocIDs, allocID)
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300443 RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(context.Background(), IntfID, ponrmgr.ALLOC_ID, allocIDs)
Girish Gowdra64503432020-01-07 10:59:10 +0530444}
445
446// FreeGemPortID frees GemPortID on the PON resource pool and also frees the gemPortID association
447// for the given OLT device.
448func (RsrcMgr *OpenOltResourceMgr) FreeGemPortID(IntfID uint32, gemPortID uint32) {
449 gemPortIDs := make([]uint32, 0)
450 gemPortIDs = append(gemPortIDs, gemPortID)
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300451 RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(context.Background(), IntfID, ponrmgr.GEMPORT_ID, gemPortIDs)
Girish Gowdra64503432020-01-07 10:59:10 +0530452}