blob: 2bd84a75b67b5f2e07850ba45b90f1b096402293 [file] [log] [blame]
Abhilash S.L7f17e402019-03-15 17:40:41 +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
manikkaraj kbf256be2019-03-25 00:13:48 +053017package resourcemanager
Abhilash S.L7f17e402019-03-15 17:40:41 +053018
19import (
Girish Gowdru0c588b22019-04-23 23:24:56 -040020 "encoding/json"
21 "errors"
22 "fmt"
23 "strconv"
24 "strings"
Abhilash S.L7f17e402019-03-15 17:40:41 +053025
Girish Gowdru0c588b22019-04-23 23:24:56 -040026 "github.com/opencord/voltha-go/common/log"
27 ponrmgr "github.com/opencord/voltha-go/common/ponresourcemanager"
28 "github.com/opencord/voltha-go/db/kvstore"
29 "github.com/opencord/voltha-go/db/model"
30 "github.com/opencord/voltha-protos/go/openolt"
Abhilash S.L7f17e402019-03-15 17:40:41 +053031)
32
manikkaraj kbf256be2019-03-25 00:13:48 +053033const KVSTORE_TIMEOUT = 5
Abhilash S.L7f17e402019-03-15 17:40:41 +053034const BASE_PATH_KV_STORE = "service/voltha/openolt/{%s}" // service/voltha/openolt/<device_id>
35
Abhilash S.L8ee90712019-04-29 16:24:22 +053036type FlowInfo struct {
37 Flow *openolt.Flow
38 FlowStoreCookie uint64
39 FlowCategory string
40}
Abhilash S.L7f17e402019-03-15 17:40:41 +053041type OpenOltResourceMgr struct {
Girish Gowdru0c588b22019-04-23 23:24:56 -040042 DeviceID string //OLT device id
43 HostAndPort string // Host and port of the kv store to connect to
44 Args string // args
45 KVStore *model.Backend // backend kv store connection handle
46 DeviceType string
47 Host string // Host ip of the kv store
48 Port int // port of the kv store
49 DevInfo *openolt.DeviceInfo // device information
50 // array of pon resource managers per interface technology
51 ResourceMgrs map[uint32]*ponrmgr.PONResourceManager
Abhilash S.L7f17e402019-03-15 17:40:41 +053052}
53
54func newKVClient(storeType string, address string, timeout uint32) (kvstore.Client, error) {
Girish Gowdru0c588b22019-04-23 23:24:56 -040055 log.Infow("kv-store-type", log.Fields{"store": storeType})
56 switch storeType {
57 case "consul":
58 return kvstore.NewConsulClient(address, int(timeout))
59 case "etcd":
60 return kvstore.NewEtcdClient(address, int(timeout))
61 }
62 return nil, errors.New("unsupported-kv-store")
Abhilash S.L7f17e402019-03-15 17:40:41 +053063}
64
65func SetKVClient(Backend string, Host string, Port int, DeviceID string) *model.Backend {
Girish Gowdru0c588b22019-04-23 23:24:56 -040066 addr := Host + ":" + strconv.Itoa(Port)
67 // TODO : Make sure direct call to NewBackend is working fine with backend , currently there is some
68 // issue between kv store and backend , core is not calling NewBackend directly
69 kvClient, err := newKVClient(Backend, addr, KVSTORE_TIMEOUT)
70 if err != nil {
71 log.Fatalw("Failed to init KV client\n", log.Fields{"err": err})
72 return nil
73 }
74 kvbackend := &model.Backend{
75 Client: kvClient,
76 StoreType: Backend,
77 Host: Host,
78 Port: Port,
79 Timeout: KVSTORE_TIMEOUT,
80 PathPrefix: fmt.Sprintf(BASE_PATH_KV_STORE, DeviceID)}
Abhilash S.L7f17e402019-03-15 17:40:41 +053081
Girish Gowdru0c588b22019-04-23 23:24:56 -040082 return kvbackend
Abhilash S.L7f17e402019-03-15 17:40:41 +053083}
84
Abhilash S.L8ee90712019-04-29 16:24:22 +053085func NewResourceMgr(DeviceID string, KVStoreHostPort string, KVStoreType string, DeviceType string, DevInfo *openolt.DeviceInfo) *OpenOltResourceMgr {
Abhilash S.L7f17e402019-03-15 17:40:41 +053086
Girish Gowdru0c588b22019-04-23 23:24:56 -040087 /* init a New resource maanger instance which in turn instantiates pon resource manager
88 instances according to technology. Initializes the default resource ranges for all
89 the reources.
90 */
91 var ResourceMgr OpenOltResourceMgr
Abhilash S.L8ee90712019-04-29 16:24:22 +053092 log.Debugf("Init new resource manager , host_port: %s, deviceid: %s", KVStoreHostPort, DeviceID)
93 ResourceMgr.HostAndPort = KVStoreHostPort
Girish Gowdru0c588b22019-04-23 23:24:56 -040094 ResourceMgr.DeviceType = DeviceType
95 ResourceMgr.DevInfo = DevInfo
Abhilash S.L8ee90712019-04-29 16:24:22 +053096 IpPort := strings.Split(KVStoreHostPort, ":")
Girish Gowdru0c588b22019-04-23 23:24:56 -040097 ResourceMgr.Host = IpPort[0]
98 ResourceMgr.Port, _ = strconv.Atoi(IpPort[1])
Abhilash S.L7f17e402019-03-15 17:40:41 +053099
Abhilash S.L8ee90712019-04-29 16:24:22 +0530100 Backend := KVStoreType
Girish Gowdru0c588b22019-04-23 23:24:56 -0400101 ResourceMgr.KVStore = SetKVClient(Backend, ResourceMgr.Host,
102 ResourceMgr.Port, DeviceID)
103 if ResourceMgr.KVStore == nil {
104 log.Error("Failed to setup KV store")
105 }
106 Ranges := make(map[string]*openolt.DeviceInfo_DeviceResourceRanges)
107 RsrcMgrsByTech := make(map[string]*ponrmgr.PONResourceManager)
108 ResourceMgr.ResourceMgrs = make(map[uint32]*ponrmgr.PONResourceManager)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530109
Girish Gowdru0c588b22019-04-23 23:24:56 -0400110 // TODO self.args = registry('main').get_args()
Abhilash S.L7f17e402019-03-15 17:40:41 +0530111
Girish Gowdru0c588b22019-04-23 23:24:56 -0400112 /*
113 If a legacy driver returns protobuf without any ranges,s synthesize one from
114 the legacy global per-device informaiton. This, in theory, is temporary until
115 the legacy drivers are upgrade to support pool ranges.
116 */
117 if DevInfo.Ranges == nil {
118 var ranges openolt.DeviceInfo_DeviceResourceRanges
119 ranges.Technology = DevInfo.GetTechnology()
Abhilash S.L7f17e402019-03-15 17:40:41 +0530120
Girish Gowdru0c588b22019-04-23 23:24:56 -0400121 NumPONPorts := DevInfo.GetPonPorts()
122 var index uint32
123 for index = 0; index < NumPONPorts; index++ {
124 ranges.IntfIds = append(ranges.IntfIds, index)
125 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530126
Abhilash S.L8ee90712019-04-29 16:24:22 +0530127 var Pool openolt.DeviceInfo_DeviceResourceRanges_Pool
Girish Gowdru0c588b22019-04-23 23:24:56 -0400128 Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_ONU_ID
129 Pool.Start = DevInfo.OnuIdStart
130 Pool.End = DevInfo.OnuIdEnd
131 Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF
Abhilash S.L8ee90712019-04-29 16:24:22 +0530132 ranges.Pools = append(ranges.Pools, &Pool)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530133
Girish Gowdru0c588b22019-04-23 23:24:56 -0400134 Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_ALLOC_ID
135 Pool.Start = DevInfo.AllocIdStart
136 Pool.End = DevInfo.AllocIdEnd
137 Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH
Abhilash S.L8ee90712019-04-29 16:24:22 +0530138 ranges.Pools = append(ranges.Pools, &Pool)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530139
Girish Gowdru0c588b22019-04-23 23:24:56 -0400140 Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_GEMPORT_ID
141 Pool.Start = DevInfo.GemportIdStart
142 Pool.End = DevInfo.GemportIdEnd
143 Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH
Abhilash S.L8ee90712019-04-29 16:24:22 +0530144 ranges.Pools = append(ranges.Pools, &Pool)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530145
Girish Gowdru0c588b22019-04-23 23:24:56 -0400146 Pool.Type = openolt.DeviceInfo_DeviceResourceRanges_Pool_FLOW_ID
147 Pool.Start = DevInfo.FlowIdStart
148 Pool.End = DevInfo.FlowIdEnd
149 Pool.Sharing = openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH
Abhilash S.L8ee90712019-04-29 16:24:22 +0530150 ranges.Pools = append(ranges.Pools, &Pool)
151 // Add to device info
152 DevInfo.Ranges = append(DevInfo.Ranges, &ranges)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400153 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530154
Girish Gowdru0c588b22019-04-23 23:24:56 -0400155 //Create a separate Resource Manager instance for each range. This assumes that
156 // each technology is represented by only a single range
157 var GlobalPONRsrcMgr *ponrmgr.PONResourceManager
158 var err error
159 for _, TechRange := range DevInfo.Ranges {
160 technology := TechRange.Technology
161 log.Debugf("Device info technology %s", technology)
162 Ranges[technology] = TechRange
163 RsrcMgrsByTech[technology], err = ponrmgr.NewPONResourceManager(technology, DeviceType, DeviceID,
164 Backend, ResourceMgr.Host, ResourceMgr.Port)
165 if err != nil {
166 log.Errorf("Failed to create pon resource manager instacnce for technology %s", technology)
167 return nil
168 }
169 //resource_mgrs_by_tech[technology] = resource_mgr
170 if GlobalPONRsrcMgr == nil {
171 GlobalPONRsrcMgr = RsrcMgrsByTech[technology]
172 }
173 for IntfId := range TechRange.IntfIds {
174 ResourceMgr.ResourceMgrs[uint32(IntfId)] = RsrcMgrsByTech[technology]
175 }
176 //self.initialize_device_resource_range_and_pool(resource_mgr, global_resource_mgr, arange)
177 InitializeDeviceResourceRangeAndPool(RsrcMgrsByTech[technology], GlobalPONRsrcMgr,
178 TechRange, DevInfo)
179 }
180 // After we have initialized resource ranges, initialize the
181 // resource pools accordingly.
182 for _, PONRMgr := range RsrcMgrsByTech {
183 PONRMgr.InitDeviceResourcePool()
184 }
Abhilash S.L8ee90712019-04-29 16:24:22 +0530185 log.Info("Initialization of resource manager success!")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400186 return &ResourceMgr
Abhilash S.L7f17e402019-03-15 17:40:41 +0530187}
188
189func InitializeDeviceResourceRangeAndPool(PONRMgr *ponrmgr.PONResourceManager, GlobalPONRMgr *ponrmgr.PONResourceManager,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400190 TechRange *openolt.DeviceInfo_DeviceResourceRanges, DevInfo *openolt.DeviceInfo) {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530191
Girish Gowdru0c588b22019-04-23 23:24:56 -0400192 // init the resource range pool according to the sharing type
Abhilash S.L7f17e402019-03-15 17:40:41 +0530193
Girish Gowdru0c588b22019-04-23 23:24:56 -0400194 log.Debugf("Resource range pool init for technology %s", PONRMgr.Technology)
195 //first load from KV profiles
196 status := PONRMgr.InitResourceRangesFromKVStore()
197 if status == false {
198 log.Debugf("Failed to load resource ranges from KV store for tech %s", PONRMgr.Technology)
199 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530200
Girish Gowdru0c588b22019-04-23 23:24:56 -0400201 /*
202 Then apply device specific information. If KV doesn't exist
203 or is broader than the device, the device's informationw ill
204 dictate the range limits
205 */
206 log.Debugf("Using device info to init pon resource ranges for tech", PONRMgr.Technology)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530207
Girish Gowdru0c588b22019-04-23 23:24:56 -0400208 ONUIDStart := DevInfo.OnuIdStart
209 ONUIDEnd := DevInfo.OnuIdEnd
210 ONUIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_DEDICATED_PER_INTF
211 ONUIDSharedPoolID := uint32(0)
212 AllocIDStart := DevInfo.AllocIdStart
213 AllocIDEnd := DevInfo.AllocIdEnd
214 AllocIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH // TODO EdgeCore/BAL limitation
215 AllocIDSharedPoolID := uint32(0)
216 GEMPortIDStart := DevInfo.GemportIdStart
217 GEMPortIDEnd := DevInfo.GemportIdEnd
218 GEMPortIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH // TODO EdgeCore/BAL limitation
219 GEMPortIDSharedPoolID := uint32(0)
220 FlowIDStart := DevInfo.FlowIdStart
221 FlowIDEnd := DevInfo.FlowIdEnd
222 FlowIDShared := openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH // TODO EdgeCore/BAL limitation
223 FlowIDSharedPoolID := uint32(0)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530224
Girish Gowdru0c588b22019-04-23 23:24:56 -0400225 var GlobalPoolID uint32
226 var FirstIntfPoolID uint32
227 var SharedPoolID uint32
Abhilash S.L7f17e402019-03-15 17:40:41 +0530228
Girish Gowdru0c588b22019-04-23 23:24:56 -0400229 for _, FirstIntfPoolID = range TechRange.IntfIds {
230 break
231 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530232
Girish Gowdru0c588b22019-04-23 23:24:56 -0400233 for _, RangePool := range TechRange.Pools {
234 if RangePool.Sharing == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
235 SharedPoolID = GlobalPoolID
236 } else if RangePool.Sharing == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_SAME_TECH {
237 SharedPoolID = FirstIntfPoolID
238 } else {
239 SharedPoolID = 0
240 }
241 if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_ONU_ID {
242 ONUIDStart = RangePool.Start
243 ONUIDEnd = RangePool.End
244 ONUIDShared = RangePool.Sharing
245 ONUIDSharedPoolID = SharedPoolID
246 } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_ALLOC_ID {
247 AllocIDStart = RangePool.Start
248 AllocIDEnd = RangePool.End
249 AllocIDShared = RangePool.Sharing
250 AllocIDSharedPoolID = SharedPoolID
251 } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_GEMPORT_ID {
252 GEMPortIDStart = RangePool.Start
253 GEMPortIDEnd = RangePool.End
254 GEMPortIDShared = RangePool.Sharing
255 GEMPortIDSharedPoolID = SharedPoolID
256 } else if RangePool.Type == openolt.DeviceInfo_DeviceResourceRanges_Pool_FLOW_ID {
257 FlowIDStart = RangePool.Start
258 FlowIDEnd = RangePool.End
259 FlowIDShared = RangePool.Sharing
260 FlowIDSharedPoolID = SharedPoolID
261 }
262 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530263
Girish Gowdru0c588b22019-04-23 23:24:56 -0400264 log.Debugw("Device info init", log.Fields{"technology": TechRange.Technology,
265 "onu_id_start": ONUIDStart, "onu_id_end": ONUIDEnd, "onu_id_shared_pool_id": ONUIDSharedPoolID,
266 "alloc_id_start": AllocIDStart, "alloc_id_end": AllocIDEnd,
267 "alloc_id_shared_pool_id": AllocIDSharedPoolID,
268 "gemport_id_start": GEMPortIDStart, "gemport_id_end": GEMPortIDEnd,
269 "gemport_id_shared_pool_id": GEMPortIDSharedPoolID,
270 "flow_id_start": FlowIDStart,
271 "flow_id_end_idx": FlowIDEnd,
272 "flow_id_shared_pool_id": FlowIDSharedPoolID,
273 "intf_ids": TechRange.IntfIds,
274 "uni_id_start": 0,
275 "uni_id_end_idx":/*MaxUNIIDperONU()*/ 1})
Abhilash S.L7f17e402019-03-15 17:40:41 +0530276
Girish Gowdru0c588b22019-04-23 23:24:56 -0400277 PONRMgr.InitDefaultPONResourceRanges(ONUIDStart, ONUIDEnd, ONUIDSharedPoolID,
278 AllocIDStart, AllocIDEnd, AllocIDSharedPoolID,
279 GEMPortIDStart, GEMPortIDEnd, GEMPortIDSharedPoolID,
280 FlowIDStart, FlowIDEnd, FlowIDSharedPoolID, 0, 1,
281 DevInfo.PonPorts, TechRange.IntfIds)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530282
Girish Gowdru0c588b22019-04-23 23:24:56 -0400283 // For global sharing, make sure to refresh both local and global resource manager instances' range
Abhilash S.L7f17e402019-03-15 17:40:41 +0530284
Girish Gowdru0c588b22019-04-23 23:24:56 -0400285 if ONUIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
286 GlobalPONRMgr.UpdateRanges(ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd,
287 "", 0, nil)
288 PONRMgr.UpdateRanges(ponrmgr.ONU_ID_START_IDX, ONUIDStart, ponrmgr.ONU_ID_END_IDX, ONUIDEnd,
289 "", 0, GlobalPONRMgr)
290 }
291 if AllocIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
292 GlobalPONRMgr.UpdateRanges(ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd,
293 "", 0, nil)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530294
Girish Gowdru0c588b22019-04-23 23:24:56 -0400295 PONRMgr.UpdateRanges(ponrmgr.ALLOC_ID_START_IDX, AllocIDStart, ponrmgr.ALLOC_ID_END_IDX, AllocIDEnd,
296 "", 0, GlobalPONRMgr)
297 }
298 if GEMPortIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
299 GlobalPONRMgr.UpdateRanges(ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd,
300 "", 0, nil)
301 PONRMgr.UpdateRanges(ponrmgr.GEMPORT_ID_START_IDX, GEMPortIDStart, ponrmgr.GEMPORT_ID_END_IDX, GEMPortIDEnd,
302 "", 0, GlobalPONRMgr)
303 }
304 if FlowIDShared == openolt.DeviceInfo_DeviceResourceRanges_Pool_SHARED_BY_ALL_INTF_ALL_TECH {
305 GlobalPONRMgr.UpdateRanges(ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd,
306 "", 0, nil)
307 PONRMgr.UpdateRanges(ponrmgr.FLOW_ID_START_IDX, FlowIDStart, ponrmgr.FLOW_ID_END_IDX, FlowIDEnd,
308 "", 0, GlobalPONRMgr)
309 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530310
Girish Gowdru0c588b22019-04-23 23:24:56 -0400311 // Make sure loaded range fits the platform bit encoding ranges
312 PONRMgr.UpdateRanges(ponrmgr.UNI_ID_START_IDX, 0, ponrmgr.UNI_ID_END_IDX /* TODO =OpenOltPlatform.MAX_UNIS_PER_ONU-1*/, 1, "", 0, nil)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530313}
314
315/* TODO
316def __del__(self):
317 self.log.info("clearing-device-resource-pool")
318 for key, resource_mgr in self.resource_mgrs.iteritems():
319 resource_mgr.clear_device_resource_pool()
320
321 def assert_pon_id_limit(self, pon_intf_id):
322 assert pon_intf_id in self.resource_mgrs
323
324 def assert_onu_id_limit(self, pon_intf_id, onu_id):
325 self.assert_pon_id_limit(pon_intf_id)
326 self.resource_mgrs[pon_intf_id].assert_resource_limits(onu_id, PONResourceManager.ONU_ID)
327
328 @property
329 def max_uni_id_per_onu(self):
330 return 0 #OpenOltPlatform.MAX_UNIS_PER_ONU-1, zero-based indexing Uncomment or override to make default multi-uni
331
332 def assert_uni_id_limit(self, pon_intf_id, onu_id, uni_id):
333 self.assert_onu_id_limit(pon_intf_id, onu_id)
334 self.resource_mgrs[pon_intf_id].assert_resource_limits(uni_id, PONResourceManager.UNI_ID)
335*/
336
337func (RsrcMgr *OpenOltResourceMgr) GetONUID(PONIntfID uint32) (uint32, error) {
338
Girish Gowdru0c588b22019-04-23 23:24:56 -0400339 // Get ONU id for a provided pon interface ID.
Abhilash S.L7f17e402019-03-15 17:40:41 +0530340
Girish Gowdru0c588b22019-04-23 23:24:56 -0400341 ONUID, err := RsrcMgr.ResourceMgrs[PONIntfID].GetResourceID(PONIntfID,
342 ponrmgr.ONU_ID, 1)
343 if err != nil {
344 log.Errorf("Failed to get resource for interface %d for type %s",
345 PONIntfID, ponrmgr.ONU_ID)
346 return ONUID[0], err
347 }
348 if ONUID != nil {
349 RsrcMgr.ResourceMgrs[PONIntfID].InitResourceMap(fmt.Sprintf("%d,%d", PONIntfID, ONUID))
350 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530351
Girish Gowdru0c588b22019-04-23 23:24:56 -0400352 return ONUID[0], err
Abhilash S.L7f17e402019-03-15 17:40:41 +0530353}
354
Abhilash S.L8ee90712019-04-29 16:24:22 +0530355func (RsrcMgr *OpenOltResourceMgr) GetFlowIDInfo(PONIntfID uint32, ONUID uint32, UNIID uint32, FlowID uint32) *[]FlowInfo {
356
357 /*
358 Note: For flows which trap from the NNI and not really associated with any particular
359 ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id.
360 */
361 var flows []FlowInfo
362
363 FlowPath := fmt.Sprintf("%d,%d,%d", PONIntfID, ONUID, UNIID)
364 if err := RsrcMgr.ResourceMgrs[PONIntfID].GetFlowIDInfo(FlowPath, FlowID, &flows); err != nil {
365 log.Errorw("Error while getting flows from KV store", log.Fields{"flowId": FlowID})
366 return nil
367 }
368 if len(flows) == 0 {
369 log.Debugw("No flowInfo found in KV store", log.Fields{"flowPath": FlowPath})
370 return nil
371 }
372 return &flows
373}
374
375func (RsrcMgr *OpenOltResourceMgr) GetCurrentFlowIDsForOnu(PONIntfID uint32, ONUID uint32, UNIID uint32) []uint32 {
376 /*
377 Note: For flows which trap from the NNI and not really associated with any particular
378 ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id.
379 */
380 FlowPath := fmt.Sprintf("%d,%d,%d", PONIntfID, ONUID, UNIID)
381 return RsrcMgr.ResourceMgrs[PONIntfID].GetCurrentFlowIDsForOnu(FlowPath)
382}
383
384func (RsrcMgr *OpenOltResourceMgr) UpdateFlowIDInfo(PONIntfID int32, ONUID int32, UNIID int32,
385 FlowID uint32, FlowData *[]FlowInfo) error {
386
387 /*
388 Note: For flows which trap from the NNI and not really associated with any particular
389 ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id.
390 */
391 FlowPath := fmt.Sprintf("%d,%d,%d", PONIntfID, ONUID, UNIID)
392 return RsrcMgr.ResourceMgrs[uint32(PONIntfID)].UpdateFlowIDInfoForOnu(FlowPath, FlowID, *FlowData)
393}
394
Abhilash S.L7f17e402019-03-15 17:40:41 +0530395func (RsrcMgr *OpenOltResourceMgr) GetFlowID(PONIntfID uint32, ONUID uint32, UNIID uint32,
Abhilash S.L8ee90712019-04-29 16:24:22 +0530396 FlowStoreCookie uint64,
397 FlowCategory string) (uint32, error) {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530398
Girish Gowdru0c588b22019-04-23 23:24:56 -0400399 // Get flow ID for a given pon interface id, onu id and uni id.
Abhilash S.L7f17e402019-03-15 17:40:41 +0530400
Girish Gowdru0c588b22019-04-23 23:24:56 -0400401 var err error
402 FlowPath := fmt.Sprintf("%d,%d,%d", PONIntfID, ONUID, UNIID)
403 FlowIDs := RsrcMgr.ResourceMgrs[PONIntfID].GetCurrentFlowIDsForOnu(FlowPath)
404 if FlowIDs != nil {
Abhilash S.L8ee90712019-04-29 16:24:22 +0530405 log.Debugw("Found flowId(s) for this ONU", log.Fields{"pon": PONIntfID, "ONUID": ONUID, "UNIID": UNIID, "KVpath": FlowPath})
406 for _, flowId := range FlowIDs {
407 FlowInfo := RsrcMgr.GetFlowIDInfo(PONIntfID, ONUID, UNIID, uint32(flowId))
408 if FlowInfo != nil {
409 log.Debugw("Found flows", log.Fields{"flows": *FlowInfo, "flowId": flowId})
410 for _, Info := range *FlowInfo {
411 if FlowCategory != "" && Info.FlowCategory == FlowCategory {
412 log.Debug("Found flow matching with flow catagory", log.Fields{"flowId": flowId, "FlowCategory": FlowCategory})
413 return flowId, nil
414 }
415 if FlowStoreCookie != 0 && Info.FlowStoreCookie == FlowStoreCookie {
416 log.Debug("Found flow matching with flowStore cookie", log.Fields{"flowId": flowId, "FlowStoreCookie": FlowStoreCookie})
417 return flowId, nil
418 }
419 }
420 }
421 }
Girish Gowdru0c588b22019-04-23 23:24:56 -0400422 }
Abhilash S.L8ee90712019-04-29 16:24:22 +0530423 log.Debug("No matching flows with flow cookie or flow category, allocating new flowid")
Girish Gowdru0c588b22019-04-23 23:24:56 -0400424 FlowIDs, err = RsrcMgr.ResourceMgrs[PONIntfID].GetResourceID(PONIntfID,
425 ponrmgr.FLOW_ID, 1)
426 if err != nil {
427 log.Errorf("Failed to get resource for interface %d for type %s",
428 PONIntfID, ponrmgr.FLOW_ID)
429 return FlowIDs[0], err
430 }
431 if FlowIDs != nil {
432 RsrcMgr.ResourceMgrs[PONIntfID].UpdateFlowIDForOnu(FlowPath, FlowIDs[0], true)
433 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530434
Girish Gowdru0c588b22019-04-23 23:24:56 -0400435 return FlowIDs[0], err
Abhilash S.L7f17e402019-03-15 17:40:41 +0530436}
437
Abhilash S.L8ee90712019-04-29 16:24:22 +0530438func (RsrcMgr *OpenOltResourceMgr) GetAllocID(IntfID uint32, ONUID uint32, UNIID uint32) uint32 {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530439
Girish Gowdru0c588b22019-04-23 23:24:56 -0400440 // Get alloc id for a given pon interface id and onu id.
441 var err error
Abhilash S.L8ee90712019-04-29 16:24:22 +0530442 IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", IntfID, ONUID, UNIID)
443 AllocID := RsrcMgr.ResourceMgrs[IntfID].GetCurrentAllocIDForOnu(IntfOnuIDUniID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400444 if AllocID != nil {
445 // Since we support only one alloc_id for the ONU at the moment,
446 // return the first alloc_id in the list, if available, for that
447 // ONU.
Abhilash S.L8ee90712019-04-29 16:24:22 +0530448 log.Debugw("Retrived alloc ID from pon resource mgr", log.Fields{"AllocID": AllocID})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400449 return AllocID[0]
450 }
451 AllocID, err = RsrcMgr.ResourceMgrs[IntfID].GetResourceID(IntfID,
452 ponrmgr.ALLOC_ID, 1)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530453
Girish Gowdru0c588b22019-04-23 23:24:56 -0400454 if AllocID == nil || err != nil {
455 log.Error("Failed to allocate alloc id")
456 return 0
457 }
458 // update the resource map on KV store with the list of alloc_id
459 // allocated for the pon_intf_onu_id tuple
Abhilash S.L8ee90712019-04-29 16:24:22 +0530460 err = RsrcMgr.ResourceMgrs[IntfID].UpdateAllocIdsForOnu(IntfOnuIDUniID, AllocID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400461 if err != nil {
462 log.Error("Failed to update Alloc ID")
463 return 0
464 }
Abhilash S.L8ee90712019-04-29 16:24:22 +0530465 log.Debugw("Allocated new Tcont from pon resource mgr", log.Fields{"AllocID": AllocID})
Girish Gowdru0c588b22019-04-23 23:24:56 -0400466 return AllocID[0]
Abhilash S.L7f17e402019-03-15 17:40:41 +0530467}
468
Abhilash S.L8ee90712019-04-29 16:24:22 +0530469func (RsrcMgr *OpenOltResourceMgr) UpdateAllocIdsForOnu(PONPort uint32, ONUID uint32, UNIID uint32, AllocID []uint32) error {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530470
Girish Gowdru0c588b22019-04-23 23:24:56 -0400471 /* update alloc ids in kv store for a given pon interface id,
472 onu id and uni id.
473 */
Abhilash S.L8ee90712019-04-29 16:24:22 +0530474 IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", PONPort, ONUID, UNIID)
475 return RsrcMgr.ResourceMgrs[PONPort].UpdateAllocIdsForOnu(IntfOnuIDUniID,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400476 AllocID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530477}
478func (RsrcMgr *OpenOltResourceMgr) GetCurrentGEMPortIDsForOnu(IntfID uint32, ONUID uint32,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400479 UNIID uint32) []uint32 {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530480
Girish Gowdru0c588b22019-04-23 23:24:56 -0400481 /* Get gem ports for given pon interface , onu id and uni id. */
Abhilash S.L7f17e402019-03-15 17:40:41 +0530482
Abhilash S.L8ee90712019-04-29 16:24:22 +0530483 IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", IntfID, ONUID, UNIID)
484 return RsrcMgr.ResourceMgrs[IntfID].GetCurrentGEMPortIDsForOnu(IntfOnuIDUniID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530485}
486
Abhilash S.L8ee90712019-04-29 16:24:22 +0530487func (RsrcMgr *OpenOltResourceMgr) GetCurrentAllocIDForOnu(IntfID uint32, ONUID uint32, UNIID uint32) uint32 {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530488
Girish Gowdru0c588b22019-04-23 23:24:56 -0400489 /* Get alloc ids for given pon interface and onu id. */
Abhilash S.L7f17e402019-03-15 17:40:41 +0530490
Abhilash S.L8ee90712019-04-29 16:24:22 +0530491 IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", IntfID, ONUID, UNIID)
492 AllocID := RsrcMgr.ResourceMgrs[IntfID].GetCurrentAllocIDForOnu(IntfOnuIDUniID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400493 if AllocID != nil {
494 // Since we support only one alloc_id for the ONU at the moment,
495 // return the first alloc_id in the list, if available, for that
496 // ONU.
497 return AllocID[0]
498 }
499 return 0
Abhilash S.L7f17e402019-03-15 17:40:41 +0530500}
501
502func (RsrcMgr *OpenOltResourceMgr) UpdateGEMportsPonportToOnuMapOnKVStore(GEMPorts []uint32, PonPort uint32,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400503 ONUID uint32, UNIID uint32) error {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530504
Girish Gowdru0c588b22019-04-23 23:24:56 -0400505 /* Update onu and uni id associated with the gem port to the kv store. */
506 var IntfGEMPortPath string
507 Data := fmt.Sprintf("%d %d", ONUID, UNIID)
508 for _, GEM := range GEMPorts {
509 IntfGEMPortPath = fmt.Sprintf("%d,%d", PonPort, GEM)
510 Val, err := json.Marshal(Data)
511 if err != nil {
512 log.Error("failed to Marshal")
513 return err
514 }
515 // This information is used when packet_indication is received and
516 // we need to derive the ONU Id for which the packet arrived based
517 // on the pon_intf and gemport available in the packet_indication
518 if err = RsrcMgr.KVStore.Put(IntfGEMPortPath, Val); err != nil {
519 log.Errorf("Failed to update resource %s", IntfGEMPortPath)
520 return err
521 }
522 }
523 return nil
Abhilash S.L7f17e402019-03-15 17:40:41 +0530524}
525
Abhilash S.L8ee90712019-04-29 16:24:22 +0530526func (RsrcMgr *OpenOltResourceMgr) GetONUUNIfromPONPortGEMPort(PONPort uint32, GEMPort uint32) (err error, OnuID uint32, UniID uint32) {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530527
Abhilash S.L8ee90712019-04-29 16:24:22 +0530528 var ONUID uint32
529 var UNIID uint32
Girish Gowdru0c588b22019-04-23 23:24:56 -0400530 var Data string
Abhilash S.L8ee90712019-04-29 16:24:22 +0530531
532 /* get the onu and uni id for a given gem port and pon port */
533 IntfGEMPortPath := fmt.Sprintf("%d,%d", PONPort, GEMPort)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400534 Value, err := RsrcMgr.KVStore.Get(IntfGEMPortPath)
535 if err == nil {
536 if Value != nil {
537 Val, _ := kvstore.ToByte(Value.Value)
538 if err = json.Unmarshal(Val, &Data); err != nil {
539 log.Error("Failed to unmarshal")
Abhilash S.L8ee90712019-04-29 16:24:22 +0530540 return err, ONUID, UNIID
Girish Gowdru0c588b22019-04-23 23:24:56 -0400541 }
542 IDs := strings.Split(Data, " ")
Abhilash S.L8ee90712019-04-29 16:24:22 +0530543 for index, val := range IDs {
544 switch index {
545 case 0:
546 if intval, err := strconv.Atoi(val); err == nil {
547 ONUID = uint32(intval)
548 }
549 case 1:
550 if intval, err := strconv.Atoi(val); err == nil {
551 UNIID = uint32(intval)
552 }
553 }
Girish Gowdru0c588b22019-04-23 23:24:56 -0400554 }
555 }
556 }
Abhilash S.L8ee90712019-04-29 16:24:22 +0530557 return err, ONUID, UNIID
Abhilash S.L7f17e402019-03-15 17:40:41 +0530558}
559
560func (RsrcMgr *OpenOltResourceMgr) GetGEMPortID(PONPort uint32, ONUID uint32,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400561 UNIID uint32, NumOfPorts uint32) ([]uint32, error) {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530562
Girish Gowdru0c588b22019-04-23 23:24:56 -0400563 /* Get gem port id for a particular pon port, onu id
564 and uni id.
565 */
Abhilash S.L7f17e402019-03-15 17:40:41 +0530566
Girish Gowdru0c588b22019-04-23 23:24:56 -0400567 var err error
Abhilash S.L8ee90712019-04-29 16:24:22 +0530568 IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", PONPort, ONUID, UNIID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530569
Abhilash S.L8ee90712019-04-29 16:24:22 +0530570 GEMPortList := RsrcMgr.ResourceMgrs[PONPort].GetCurrentGEMPortIDsForOnu(IntfOnuIDUniID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400571 if GEMPortList != nil {
572 return GEMPortList, nil
573 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530574
Girish Gowdru0c588b22019-04-23 23:24:56 -0400575 GEMPortList, err = RsrcMgr.ResourceMgrs[PONPort].GetResourceID(PONPort,
576 ponrmgr.GEMPORT_ID, NumOfPorts)
577 if err != nil && GEMPortList == nil {
Abhilash S.L8ee90712019-04-29 16:24:22 +0530578 log.Errorf("Failed to get gem port id for %s", IntfOnuIDUniID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400579 return nil, err
580 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530581
Girish Gowdru0c588b22019-04-23 23:24:56 -0400582 // update the resource map on KV store with the list of gemport_id
583 // allocated for the pon_intf_onu_id tuple
Abhilash S.L8ee90712019-04-29 16:24:22 +0530584 err = RsrcMgr.ResourceMgrs[PONPort].UpdateGEMPortIDsForOnu(IntfOnuIDUniID,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400585 GEMPortList)
586 if err != nil {
Abhilash S.L8ee90712019-04-29 16:24:22 +0530587 log.Errorf("Failed to update GEM ports to kv store for %s", IntfOnuIDUniID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400588 return nil, err
589 }
590 RsrcMgr.UpdateGEMportsPonportToOnuMapOnKVStore(GEMPortList, PONPort,
591 ONUID, UNIID)
592 return GEMPortList, err
Abhilash S.L7f17e402019-03-15 17:40:41 +0530593}
594
595func (RsrcMgr *OpenOltResourceMgr) UpdateGEMPortIDsForOnu(PONPort uint32, ONUID uint32,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400596 UNIID uint32, GEMPortList []uint32) error {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530597
Girish Gowdru0c588b22019-04-23 23:24:56 -0400598 /* Update gemport ids on to kv store for a given pon port,
599 onu id and uni id.
600 */
Abhilash S.L8ee90712019-04-29 16:24:22 +0530601 IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", PONPort, ONUID, UNIID)
602 return RsrcMgr.ResourceMgrs[PONPort].UpdateGEMPortIDsForOnu(IntfOnuIDUniID,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400603 GEMPortList)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530604
605}
606func (RsrcMgr *OpenOltResourceMgr) FreeONUID(IntfID uint32, ONUID []uint32) {
607
Girish Gowdru0c588b22019-04-23 23:24:56 -0400608 /* Free onu id for a particular interface.*/
609 RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID, ponrmgr.ONU_ID, ONUID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530610
Girish Gowdru0c588b22019-04-23 23:24:56 -0400611 var IntfONUID string
612 for _, onu := range ONUID {
613 IntfONUID = fmt.Sprintf("%d,%d", IntfID, onu)
614 RsrcMgr.ResourceMgrs[IntfID].RemoveResourceMap(IntfONUID)
615 }
616 return
Abhilash S.L7f17e402019-03-15 17:40:41 +0530617}
618
619func (RsrcMgr *OpenOltResourceMgr) FreeFlowID(IntfID uint32, ONUID uint32,
Girish Gowdru0c588b22019-04-23 23:24:56 -0400620 UNIID uint32, FlowID []uint32) {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530621
Girish Gowdru0c588b22019-04-23 23:24:56 -0400622 /* Free flow id for a given interface, onu id and uni id.*/
Abhilash S.L7f17e402019-03-15 17:40:41 +0530623
Girish Gowdru0c588b22019-04-23 23:24:56 -0400624 RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID, ponrmgr.FLOW_ID, FlowID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530625
Abhilash S.L8ee90712019-04-29 16:24:22 +0530626 var IntfOnuIDUniID string
Girish Gowdru0c588b22019-04-23 23:24:56 -0400627 var err error
628 for _, flow := range FlowID {
Abhilash S.L8ee90712019-04-29 16:24:22 +0530629 IntfOnuIDUniID = fmt.Sprintf("%d,%d,%d", IntfID, ONUID, UNIID)
630 err = RsrcMgr.ResourceMgrs[IntfID].UpdateFlowIDForOnu(IntfOnuIDUniID, flow, false)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400631 if err != nil {
Abhilash S.L8ee90712019-04-29 16:24:22 +0530632 log.Error("Failed to Update flow id infor for %s", IntfOnuIDUniID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400633 }
Abhilash S.L8ee90712019-04-29 16:24:22 +0530634 RsrcMgr.ResourceMgrs[IntfID].RemoveFlowIDInfo(IntfOnuIDUniID, flow)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400635 }
636 return
Abhilash S.L7f17e402019-03-15 17:40:41 +0530637}
638
Abhilash S.L8ee90712019-04-29 16:24:22 +0530639func (RsrcMgr *OpenOltResourceMgr) FreePONResourcesForONU(IntfID uint32, ONUID uint32, UNIID uint32) {
Abhilash S.L7f17e402019-03-15 17:40:41 +0530640
Girish Gowdru0c588b22019-04-23 23:24:56 -0400641 /* Free pon resources for a given pon interface and onu id. */
Abhilash S.L7f17e402019-03-15 17:40:41 +0530642
Girish Gowdru0c588b22019-04-23 23:24:56 -0400643 var ONUIDs []uint32
644 ONUIDs = append(ONUIDs, ONUID)
Abhilash S.L8ee90712019-04-29 16:24:22 +0530645 IntfOnuIDUniID := fmt.Sprintf("%d,%d,%d", IntfID, ONUID, UNIID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530646
Abhilash S.L8ee90712019-04-29 16:24:22 +0530647 AllocIDs := RsrcMgr.ResourceMgrs[IntfID].GetCurrentAllocIDForOnu(IntfOnuIDUniID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530648
Girish Gowdru0c588b22019-04-23 23:24:56 -0400649 RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID,
650 ponrmgr.ALLOC_ID,
651 AllocIDs)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530652
Abhilash S.L8ee90712019-04-29 16:24:22 +0530653 GEMPortIDs := RsrcMgr.ResourceMgrs[IntfID].GetCurrentGEMPortIDsForOnu(IntfOnuIDUniID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400654 RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID,
655 ponrmgr.GEMPORT_ID,
656 GEMPortIDs)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530657
Abhilash S.L8ee90712019-04-29 16:24:22 +0530658 FlowIDs := RsrcMgr.ResourceMgrs[IntfID].GetCurrentFlowIDsForOnu(IntfOnuIDUniID)
Girish Gowdru0c588b22019-04-23 23:24:56 -0400659 RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID,
660 ponrmgr.FLOW_ID,
661 FlowIDs)
662 RsrcMgr.ResourceMgrs[IntfID].FreeResourceID(IntfID,
663 ponrmgr.ONU_ID,
664 ONUIDs)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530665
Girish Gowdru0c588b22019-04-23 23:24:56 -0400666 // Clear resource map associated with (pon_intf_id, gemport_id) tuple.
Abhilash S.L8ee90712019-04-29 16:24:22 +0530667 RsrcMgr.ResourceMgrs[IntfID].RemoveResourceMap(IntfOnuIDUniID)
Abhilash S.L7f17e402019-03-15 17:40:41 +0530668
Girish Gowdru0c588b22019-04-23 23:24:56 -0400669 // Clear the ONU Id associated with the (pon_intf_id, gemport_id) tuple.
670 for _, GEM := range GEMPortIDs {
671 RsrcMgr.KVStore.Delete(fmt.Sprintf("%d,%d", IntfID, GEM))
672 }
Abhilash S.L7f17e402019-03-15 17:40:41 +0530673}
674
675/* TODO once the flow id info structure is known
676def is_flow_cookie_on_kv_store(self, intf_id, onu_id, uni_id, flow_store_cookie):
677 '''
678 Note: For flows which trap from the NNI and not really associated with any particular
679 ONU (like LLDP), the onu_id and uni_id is set as -1. The intf_id is the NNI intf_id.
680 '''
681 intf_onu_id = (intf_id, onu_id, uni_id)
682 try:
683 flow_ids = self.resource_mgrs[intf_id]. \
684 get_current_flow_ids_for_onu(intf_onu_id)
685 if flow_ids is not None:
686 for flow_id in flow_ids:
687 flows = self.get_flow_id_info(intf_id, onu_id, uni_id, flow_id)
688 assert (isinstance(flows, list))
689 for flow in flows:
690 if flow['flow_store_cookie'] == flow_store_cookie:
691 return True
692 except Exception as e:
693 self.log.error("error-retrieving-flow-info", e=e)
694
695 return False
696*/