Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 1 | /* |
Joey Armstrong | 89c812c | 2024-01-12 19:00:20 -0500 | [diff] [blame] | 2 | * Copyright 2020-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 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 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 17 | // Package core provides the utility for onu devices, flows and statistics |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 18 | package core |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "errors" |
| 23 | "fmt" |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 24 | "hash/fnv" |
Holger Hildebrandt | 52f271b | 2022-06-02 09:32:27 +0000 | [diff] [blame] | 25 | "strings" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 26 | "sync" |
| 27 | "time" |
| 28 | |
Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 29 | grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry" |
| 30 | "github.com/opencord/voltha-lib-go/v7/pkg/db" |
| 31 | vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc" |
| 32 | codes "google.golang.org/grpc/codes" |
| 33 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 34 | conf "github.com/opencord/voltha-lib-go/v7/pkg/config" |
khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 35 | "github.com/opencord/voltha-protos/v5/go/adapter_service" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 36 | "github.com/opencord/voltha-protos/v5/go/common" |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 37 | "github.com/opencord/voltha-protos/v5/go/health" |
| 38 | "github.com/opencord/voltha-protos/v5/go/olt_inter_adapter_service" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 39 | "google.golang.org/grpc" |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 40 | "google.golang.org/grpc/status" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 41 | |
| 42 | "github.com/golang/protobuf/ptypes/empty" |
| 43 | "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
| 44 | "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif" |
| 45 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 46 | ca "github.com/opencord/voltha-protos/v5/go/core_adapter" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 47 | "github.com/opencord/voltha-protos/v5/go/extension" |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 48 | ia "github.com/opencord/voltha-protos/v5/go/inter_adapter" |
| 49 | "github.com/opencord/voltha-protos/v5/go/omci" |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 50 | "github.com/opencord/voltha-protos/v5/go/voltha" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 51 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 52 | cmn "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/common" |
Matteo Scandolo | 761f751 | 2020-11-23 15:52:40 -0800 | [diff] [blame] | 53 | "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config" |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame] | 54 | devdb "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/devdb" |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 55 | pmmgr "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/pmmgr" |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 56 | "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/swupg" |
| 57 | uniprt "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/uniprt" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 58 | ) |
| 59 | |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 60 | type reachabilityFromRemote struct { |
| 61 | lastKeepAlive time.Time |
| 62 | keepAliveInterval int64 |
| 63 | } |
| 64 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 65 | // OpenONUAC structure holds the ONU core information |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 66 | type OpenONUAC struct { |
Himani Chawla | c07fda0 | 2020-12-09 16:21:21 +0530 | [diff] [blame] | 67 | eventProxy eventif.EventProxy |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 68 | kvClient kvstore.Client |
Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 69 | deviceHandlers map[string]*deviceHandler |
| 70 | deviceHandlersCreateChan map[string]chan bool //channels for deviceHandler create events |
| 71 | coreClient *vgrpc.Client |
| 72 | parentAdapterClients map[string]*vgrpc.Client |
| 73 | reachableFromRemote map[string]*reachabilityFromRemote |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 74 | cm *conf.ConfigManager |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 75 | config *config.AdapterFlags |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 76 | mibTemplatesGenerated map[string]bool |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 77 | exitChannel chan int |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 78 | pSupportedFsms *cmn.OmciDeviceFsms |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 79 | pDownloadManager *swupg.AdapterDownloadManager |
| 80 | pFileManager *swupg.FileDownloadManager //let coexist 'old and new' DownloadManager as long as 'old' does not get obsolete |
Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 81 | MibDatabaseMap devdb.OnuMCmnMEDBMap |
| 82 | KVStoreAddress string |
| 83 | KVStoreType string |
| 84 | numOnus int |
| 85 | KVStoreTimeout time.Duration |
| 86 | HeartbeatCheckInterval time.Duration |
| 87 | HeartbeatFailReportInterval time.Duration |
| 88 | maxTimeoutInterAdapterComm time.Duration |
| 89 | maxTimeoutReconciling time.Duration |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 90 | mibAuditInterval time.Duration |
| 91 | omciTimeout int // in seconds |
| 92 | alarmAuditInterval time.Duration |
| 93 | dlToOnuTimeout4M time.Duration |
| 94 | rpcTimeout time.Duration |
| 95 | maxConcurrentFlowsPerUni int |
Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 96 | mutexDeviceHandlersMap sync.RWMutex |
| 97 | lockParentAdapterClients sync.RWMutex |
| 98 | lockReachableFromRemote sync.RWMutex |
| 99 | mutexMibTemplateGenerated sync.RWMutex |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame] | 100 | mutexMibDatabaseMap sync.RWMutex |
Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 101 | AcceptIncrementalEvto bool |
| 102 | MetricsEnabled bool |
| 103 | ExtendedOmciSupportEnabled bool |
| 104 | skipOnuConfig bool |
Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame^] | 105 | CheckDeviceTechProfOnReboot bool |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 106 | } |
| 107 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 108 | // NewOpenONUAC returns a new instance of OpenONU_AC |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 109 | func NewOpenONUAC(ctx context.Context, coreClient *vgrpc.Client, eventProxy eventif.EventProxy, |
| 110 | kvClient kvstore.Client, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenONUAC { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 111 | var openOnuAc OpenONUAC |
| 112 | openOnuAc.exitChannel = make(chan int, 1) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 113 | openOnuAc.deviceHandlers = make(map[string]*deviceHandler) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 114 | openOnuAc.deviceHandlersCreateChan = make(map[string]chan bool) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 115 | openOnuAc.parentAdapterClients = make(map[string]*vgrpc.Client) |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 116 | openOnuAc.reachableFromRemote = make(map[string]*reachabilityFromRemote) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 117 | openOnuAc.mutexDeviceHandlersMap = sync.RWMutex{} |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 118 | openOnuAc.config = cfg |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 119 | openOnuAc.cm = cm |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 120 | openOnuAc.coreClient = coreClient |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 121 | openOnuAc.numOnus = cfg.OnuNumber |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 122 | openOnuAc.eventProxy = eventProxy |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 123 | openOnuAc.kvClient = kvClient |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 124 | openOnuAc.KVStoreAddress = cfg.KVStoreAddress |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 125 | openOnuAc.KVStoreType = cfg.KVStoreType |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 126 | openOnuAc.KVStoreTimeout = cfg.KVStoreTimeout |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 127 | openOnuAc.mibTemplatesGenerated = make(map[string]bool) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 128 | openOnuAc.mutexMibTemplateGenerated = sync.RWMutex{} |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 129 | openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval |
| 130 | openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 131 | openOnuAc.AcceptIncrementalEvto = cfg.AccIncrEvto |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 132 | openOnuAc.maxTimeoutInterAdapterComm = cfg.MaxTimeoutInterAdapterComm |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 133 | openOnuAc.maxTimeoutReconciling = cfg.MaxTimeoutReconciling |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 134 | //openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 135 | openOnuAc.MetricsEnabled = cfg.MetricsEnabled |
Holger Hildebrandt | c572e62 | 2022-06-22 09:19:17 +0000 | [diff] [blame] | 136 | openOnuAc.ExtendedOmciSupportEnabled = cfg.ExtendedOmciSupportEnabled |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 137 | openOnuAc.mibAuditInterval = cfg.MibAuditInterval |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 138 | // since consumers of OMCI timeout value everywhere in code is in "int seconds", do this useful conversion |
| 139 | openOnuAc.omciTimeout = int(cfg.OmciTimeout.Seconds()) |
Himani Chawla | 075f164 | 2021-03-15 19:23:24 +0530 | [diff] [blame] | 140 | openOnuAc.alarmAuditInterval = cfg.AlarmAuditInterval |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 141 | openOnuAc.dlToOnuTimeout4M = cfg.DownloadToOnuTimeout4MB |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 142 | openOnuAc.rpcTimeout = cfg.RPCTimeout |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 143 | openOnuAc.maxConcurrentFlowsPerUni = cfg.MaxConcurrentFlowsPerUni |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 144 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 145 | openOnuAc.pSupportedFsms = &cmn.OmciDeviceFsms{ |
Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 146 | "mib-synchronizer": cmn.ActivityDescr{ |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 147 | //mibSyncFsm, // Implements the MIB synchronization state machine |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 148 | DatabaseClass: mibDbVolatileDictImpl, // Implements volatile ME MIB database |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 149 | //true, // Advertise events on OpenOMCI event bus |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 150 | AuditInterval: openOnuAc.mibAuditInterval, // Time to wait between MIB audits. 0 to disable audits. |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 151 | // map[string]func() error{ |
| 152 | // "mib-upload": onuDeviceEntry.MibUploadTask, |
| 153 | // "mib-template": onuDeviceEntry.MibTemplateTask, |
| 154 | // "get-mds": onuDeviceEntry.GetMdsTask, |
| 155 | // "mib-audit": onuDeviceEntry.GetMdsTask, |
| 156 | // "mib-resync": onuDeviceEntry.MibResyncTask, |
| 157 | // "mib-reconcile": onuDeviceEntry.MibReconcileTask, |
| 158 | // }, |
| 159 | }, |
| 160 | } |
| 161 | |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 162 | openOnuAc.pDownloadManager = swupg.NewAdapterDownloadManager(ctx) |
| 163 | openOnuAc.pFileManager = swupg.NewFileDownloadManager(ctx) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 164 | openOnuAc.pFileManager.SetDownloadTimeout(ctx, cfg.DownloadToAdapterTimeout) |
Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 165 | openOnuAc.skipOnuConfig = cfg.SkipOnuConfig |
Sridhar Ravindra | a9cb044 | 2025-07-21 16:55:05 +0530 | [diff] [blame^] | 166 | openOnuAc.CheckDeviceTechProfOnReboot = cfg.CheckDeviceTechProfOnReboot |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame] | 167 | openOnuAc.mutexMibDatabaseMap = sync.RWMutex{} |
| 168 | openOnuAc.MibDatabaseMap = make(map[string]*devdb.OnuCmnMEDB) |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 169 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 170 | return &openOnuAc |
| 171 | } |
| 172 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 173 | // Start starts (logs) the adapter |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 174 | func (oo *OpenONUAC) Start(ctx context.Context) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 175 | logger.Info(ctx, "starting-openonu-adapter") |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 176 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 177 | return nil |
| 178 | } |
| 179 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 180 | // Stop terminates the session |
khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 181 | func (oo *OpenONUAC) Stop(ctx context.Context) error { |
| 182 | logger.Info(ctx, "stopping-device-manager") |
| 183 | close(oo.exitChannel) |
| 184 | oo.stopAllGrpcClients(ctx) |
| 185 | logger.Info(ctx, "device-manager-stopped") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 186 | return nil |
| 187 | } |
| 188 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 189 | func (oo *OpenONUAC) addDeviceHandlerToMap(ctx context.Context, agent *deviceHandler) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 190 | oo.mutexDeviceHandlersMap.Lock() |
| 191 | defer oo.mutexDeviceHandlersMap.Unlock() |
| 192 | if _, exist := oo.deviceHandlers[agent.DeviceID]; !exist { |
| 193 | oo.deviceHandlers[agent.DeviceID] = agent |
| 194 | oo.deviceHandlers[agent.DeviceID].start(ctx) |
| 195 | if _, exist := oo.deviceHandlersCreateChan[agent.DeviceID]; exist { |
| 196 | logger.Debugw(ctx, "deviceHandler created - trigger processing of pending ONU_IND_REQUEST", log.Fields{"device-id": agent.DeviceID}) |
| 197 | oo.deviceHandlersCreateChan[agent.DeviceID] <- true |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 198 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 202 | func (oo *OpenONUAC) deleteDeviceHandlerToMap(agent *deviceHandler) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 203 | oo.mutexDeviceHandlersMap.Lock() |
| 204 | defer oo.mutexDeviceHandlersMap.Unlock() |
| 205 | delete(oo.deviceHandlers, agent.DeviceID) |
| 206 | delete(oo.deviceHandlersCreateChan, agent.DeviceID) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 207 | } |
| 208 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 209 | // getDeviceHandler gets the ONU deviceHandler and may wait until it is created |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 210 | func (oo *OpenONUAC) getDeviceHandler(ctx context.Context, deviceID string, aWait bool) (*deviceHandler, error) { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 211 | oo.mutexDeviceHandlersMap.Lock() |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 212 | agent, ok := oo.deviceHandlers[deviceID] |
| 213 | if aWait && !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 214 | logger.Infow(ctx, "Race condition: deviceHandler not present - wait for creation or timeout", |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 215 | log.Fields{"device-id": deviceID}) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 216 | if _, exist := oo.deviceHandlersCreateChan[deviceID]; !exist { |
| 217 | oo.deviceHandlersCreateChan[deviceID] = make(chan bool, 1) |
| 218 | } |
Girish Gowdra | 7407a4d | 2020-11-12 12:44:53 -0800 | [diff] [blame] | 219 | deviceCreateChan := oo.deviceHandlersCreateChan[deviceID] |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 220 | //keep the read sema short to allow for subsequent write |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 221 | oo.mutexDeviceHandlersMap.Unlock() |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 222 | // based on concurrent processing the deviceHandler creation may not yet be finished at his point |
| 223 | // so it might be needed to wait here for that event with some timeout |
| 224 | select { |
Akash Soni | 71f4476 | 2024-12-11 16:12:21 +0530 | [diff] [blame] | 225 | case <-time.After(20 * time.Second): //timer may be discussed ... |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 226 | errMsg := fmt.Sprintf("No valid deviceHandler created after max WaitTime for device %s", deviceID) |
| 227 | logger.Warn(ctx, errMsg) |
| 228 | return nil, status.Error(codes.NotFound, errMsg) |
Girish Gowdra | 7407a4d | 2020-11-12 12:44:53 -0800 | [diff] [blame] | 229 | case <-deviceCreateChan: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 230 | logger.Debugw(ctx, "deviceHandler is ready now - continue", log.Fields{"device-id": deviceID}) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 231 | oo.mutexDeviceHandlersMap.RLock() |
| 232 | defer oo.mutexDeviceHandlersMap.RUnlock() |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 233 | return oo.deviceHandlers[deviceID], nil |
| 234 | case <-ctx.Done(): |
| 235 | errMsg := fmt.Sprintf("context cancelled while waiting for device handler for device %s: %v", deviceID, ctx.Err()) |
| 236 | logger.Warnw(ctx, errMsg, log.Fields{"device-id": deviceID, "context-error": ctx.Err()}) |
| 237 | return nil, errors.New(errMsg) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 238 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 239 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 240 | oo.mutexDeviceHandlersMap.Unlock() |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 241 | return agent, nil |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 242 | } |
| 243 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 244 | // AdoptDevice creates a new device handler if not present already and then adopts the device |
| 245 | func (oo *OpenONUAC) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 246 | if device == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 247 | logger.Warn(ctx, "voltha-device-is-nil") |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 248 | return nil, errors.New("nil-device") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 249 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 250 | logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 251 | var handler *deviceHandler |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 252 | if handler, _ = oo.getDeviceHandler(ctx, device.Id, false); handler == nil { |
| 253 | fsmCtx := log.WithSpanFromContext(context.Background(), ctx) |
| 254 | handler := newDeviceHandler(fsmCtx, oo.coreClient, oo.eventProxy, device, oo) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 255 | oo.addDeviceHandlerToMap(ctx, handler) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 256 | |
| 257 | // Setup the grpc communication with the parent adapter |
| 258 | if err := oo.setupParentInterAdapterClient(ctx, device.ProxyAddress.AdapterEndpoint); err != nil { |
| 259 | // TODO: Cleanup on failure needed |
| 260 | return nil, err |
| 261 | } |
| 262 | |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 263 | go handler.adoptOrReconcileDevice(fsmCtx, device) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 264 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 265 | return &empty.Empty{}, nil |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 266 | } |
| 267 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 268 | // ReconcileDevice is called once when the adapter needs to re-create device - usually on core restart |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 269 | func (oo *OpenONUAC) ReconcileDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 270 | if device == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 271 | logger.Warn(ctx, "reconcile-device-voltha-device-is-nil") |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 272 | return nil, errors.New("nil-device") |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 273 | } |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 274 | logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id, "parent-id": device.ParentId}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 275 | var handler *deviceHandler |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 276 | if handler, _ = oo.getDeviceHandler(ctx, device.Id, false); handler == nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 277 | handler := newDeviceHandler(ctx, oo.coreClient, oo.eventProxy, device, oo) |
Praneeth Kumar Nalmas | 77ab2f3 | 2024-04-17 11:14:27 +0530 | [diff] [blame] | 278 | logger.Infow(ctx, "reconciling-device skip-onu-config value ", log.Fields{"device-id": device.Id, "parent-id": device.ParentId, "skip-onu-config": oo.skipOnuConfig}) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 279 | handler.device = device |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 280 | if err := handler.updateDeviceStateInCore(log.WithSpanFromContext(context.Background(), ctx), &ca.DeviceStateFilter{ |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 281 | DeviceId: device.Id, |
| 282 | OperStatus: voltha.OperStatus_RECONCILING, |
| 283 | ConnStatus: device.ConnectStatus, |
| 284 | }); err != nil { |
| 285 | return nil, fmt.Errorf("not able to update device state to reconciling. Err : %s", err.Error()) |
Maninder | b518755 | 2021-03-23 22:23:42 +0530 | [diff] [blame] | 286 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 287 | // Setup the grpc communication with the parent adapter |
| 288 | if err := oo.setupParentInterAdapterClient(ctx, device.ProxyAddress.AdapterEndpoint); err != nil { |
| 289 | // TODO: Cleanup on failure needed |
| 290 | return nil, err |
| 291 | } |
Akash Soni | 931f9b9 | 2024-12-11 18:36:36 +0530 | [diff] [blame] | 292 | // Add device handler to map only if adapter and core connections are up |
| 293 | oo.addDeviceHandlerToMap(ctx, handler) |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 294 | handler.StartReconciling(log.WithSpanFromContext(context.Background(), ctx), false) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 295 | go handler.adoptOrReconcileDevice(log.WithSpanFromContext(context.Background(), ctx), handler.device) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 296 | // reconcilement will be continued after onu-device entry is added |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 297 | } else { |
nikesh.krishnan | 9d2bbf7 | 2023-12-11 07:36:57 +0530 | [diff] [blame] | 298 | logger.Warnf(ctx, "device-already-reconciled-or-active", log.Fields{"device-id": device.Id, "parent-id": device.ParentId}) |
| 299 | return &empty.Empty{}, status.Errorf(codes.AlreadyExists, "handler exists: %s", device.Id) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 300 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 301 | return &empty.Empty{}, nil |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 302 | } |
| 303 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 304 | // DisableDevice disables the given device |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 305 | func (oo *OpenONUAC) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 306 | logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id}) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 307 | if handler, err := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 308 | go handler.disableDevice(log.WithSpanFromContext(context.Background(), ctx), device) |
| 309 | return &empty.Empty{}, nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 310 | } else { |
| 311 | logger.Warnw(ctx, "no handler found for device-disable", log.Fields{"device-id": device.Id}) |
| 312 | return nil, err |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 313 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 314 | } |
| 315 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 316 | // ReEnableDevice enables the onu device after disable |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 317 | func (oo *OpenONUAC) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 318 | logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id}) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 319 | if handler, err := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 320 | go handler.reEnableDevice(log.WithSpanFromContext(context.Background(), ctx), device) |
| 321 | return &empty.Empty{}, nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 322 | } else { |
| 323 | logger.Warnw(ctx, "no handler found for device-reenable", log.Fields{"device-id": device.Id}) |
| 324 | return nil, err |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 325 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 326 | } |
| 327 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 328 | // RebootDevice reboots the given device |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 329 | func (oo *OpenONUAC) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 330 | logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id}) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 331 | if handler, err := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 332 | go handler.rebootDevice(log.WithSpanFromContext(context.Background(), ctx), true, device) //reboot request with device checking |
| 333 | return &empty.Empty{}, nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 334 | } else { |
| 335 | logger.Warnw(ctx, "no handler found for device-reboot", log.Fields{"device-id": device.Id}) |
| 336 | return nil, err |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 337 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 338 | } |
| 339 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 340 | // DeleteDevice deletes the given device |
| 341 | func (oo *OpenONUAC) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 342 | nctx := log.WithSpanFromContext(context.Background(), ctx) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 343 | logger.Infow(ctx, "delete-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber, "ctx": ctx, "nctx": nctx}) |
Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 344 | |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 345 | if handler, err := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
| 346 | // Acquire read lock to check if deletion is already in progress |
| 347 | handler.mutexDeletionInProgressFlag.RLock() |
| 348 | if handler.deletionInProgress { |
| 349 | // If deletion is already in progress, release the read lock and return |
| 350 | handler.mutexDeletionInProgressFlag.RUnlock() |
| 351 | errMsg := fmt.Sprintf("Device deletion is already in progress %s err: %s", device.Id, err) |
| 352 | logger.Info(ctx, errMsg) |
| 353 | return nil, status.Error(codes.FailedPrecondition, errMsg) |
| 354 | } |
| 355 | // Release read lock before setting the deletion flag |
| 356 | handler.mutexDeletionInProgressFlag.RUnlock() |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 357 | handler.mutexDeletionInProgressFlag.Lock() |
| 358 | handler.deletionInProgress = true |
| 359 | handler.mutexDeletionInProgressFlag.Unlock() |
| 360 | |
Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 361 | // Setting the device deletion progress flag will cause the PM FSM to cleanup for GC after FSM moves to NULL state |
nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 362 | if handler.pOnuMetricsMgr != nil { |
| 363 | handler.pOnuMetricsMgr.SetdeviceDeletionInProgress(true) |
| 364 | } |
praneeth nalmas | f405e96 | 2023-08-07 15:02:03 +0530 | [diff] [blame] | 365 | |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 366 | close(handler.deviceDeleteCommChan) |
| 367 | if resetErr := handler.resetFsms(ctx, true); resetErr != nil { |
| 368 | logger.Errorw(ctx, "failed to reset FSMs for the device", log.Fields{"device-id": device.Id, "err": resetErr}) |
| 369 | handler.mutexDeletionInProgressFlag.Lock() |
| 370 | handler.deletionInProgress = false |
| 371 | handler.mutexDeletionInProgressFlag.Unlock() |
| 372 | return nil, resetErr |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 373 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 374 | for _, uni := range handler.uniEntityMap { |
| 375 | if handler.GetFlowMonitoringIsRunning(uni.UniID) { |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 376 | select { |
| 377 | case handler.stopFlowMonitoringRoutine[uni.UniID] <- true: |
| 378 | logger.Debugw(ctx, "sent stop signal to self flow monitoring routine", log.Fields{"device-id": device.Id, "uni-id": uni.UniID}) |
| 379 | default: |
| 380 | |
| 381 | logger.Warnw(ctx, "stopFlowMonitoringRoutine channel already closed", log.Fields{"device-id": device.Id, "uni-id": uni.UniID}) |
| 382 | } |
Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 383 | } |
| 384 | } |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 385 | //don't leave any garbage in kv-store |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 386 | if forceDeleteErr := oo.forceDeleteDeviceKvData(ctx, device.Id); forceDeleteErr != nil { |
| 387 | logger.Errorw(ctx, "failed to delete ONU data from KV store", log.Fields{"device-id": device.Id, "err": forceDeleteErr}) |
| 388 | return nil, forceDeleteErr |
Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 389 | } |
Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 390 | oo.deleteDeviceHandlerToMap(handler) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 391 | handler.PrepareForGarbageCollection(ctx, handler.DeviceID) |
Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 392 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 393 | return &empty.Empty{}, nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 394 | } else { |
| 395 | errMsg := fmt.Sprintf("Device Handler not found -%s with error %s", device.Id, err) |
| 396 | logger.Error(ctx, errMsg) |
| 397 | return nil, status.Error(codes.NotFound, errMsg) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 398 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 399 | } |
| 400 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 401 | // UpdateFlowsIncrementally updates (add/remove) the flows on a given device |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 402 | func (oo *OpenONUAC) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ca.IncrementalFlows) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 403 | logger.Infow(ctx, "update-flows-incrementally", log.Fields{"device-id": incrFlows.Device.Id}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 404 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 405 | //flow config is relayed to handler even if the device might be in some 'inactive' state |
| 406 | // let the handler or related FSM's decide, what to do with the modified flow state info |
| 407 | // at least the flow-remove must be done in respect to internal data, while OMCI activity might not be needed here |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 408 | |
| 409 | // For now, there is no support for group changes (as in the actual Py-adapter code) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 410 | // but processing is continued for flowUpdate possibly also set in the request |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 411 | if incrFlows.Groups.ToAdd != nil && incrFlows.Groups.ToAdd.Items != nil { |
| 412 | logger.Warnw(ctx, "Update-flow-incr: group add not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 413 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 414 | if incrFlows.Groups.ToRemove != nil && incrFlows.Groups.ToRemove.Items != nil { |
| 415 | logger.Warnw(ctx, "Update-flow-incr: group remove not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 416 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 417 | if incrFlows.Groups.ToUpdate != nil && incrFlows.Groups.ToUpdate.Items != nil { |
| 418 | logger.Warnw(ctx, "Update-flow-incr: group update not supported (ignored)", log.Fields{"device-id": incrFlows.Device.Id}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 419 | } |
| 420 | |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 421 | if handler, err := oo.getDeviceHandler(ctx, incrFlows.Device.Id, false); handler != nil { |
| 422 | if flowUpdateErr := handler.FlowUpdateIncremental(log.WithSpanFromContext(context.Background(), ctx), incrFlows.Flows, incrFlows.Groups, incrFlows.FlowMetadata); flowUpdateErr != nil { |
| 423 | return nil, flowUpdateErr |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 424 | } |
| 425 | return &empty.Empty{}, nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 426 | } else { |
| 427 | logger.Warnw(ctx, "no handler found for incremental flow update", log.Fields{"device-id": incrFlows.Device.Id}) |
| 428 | return nil, err |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 429 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 430 | } |
| 431 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 432 | // UpdatePmConfig returns PmConfigs nil or error |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 433 | func (oo *OpenONUAC) UpdatePmConfig(ctx context.Context, configs *ca.PmConfigsInfo) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 434 | logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": configs.DeviceId}) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 435 | if handler, err := oo.getDeviceHandler(ctx, configs.DeviceId, false); handler != nil { |
| 436 | if pmConfigErr := handler.updatePmConfig(log.WithSpanFromContext(context.Background(), ctx), configs.PmConfigs); pmConfigErr != nil { |
| 437 | return nil, pmConfigErr |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 438 | } |
| 439 | return &empty.Empty{}, nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 440 | } else { |
| 441 | logger.Warnw(ctx, "no handler found for update-pm-config", log.Fields{"device-id": configs.DeviceId}) |
| 442 | return nil, err |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 443 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 444 | } |
| 445 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 446 | // DownloadImage requests downloading some image according to indications as given in request |
| 447 | // The ImageDownload needs to be called `request`due to library reflection requirements |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 448 | func (oo *OpenONUAC) DownloadImage(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 449 | ctx = log.WithSpanFromContext(context.Background(), ctx) |
| 450 | if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" { |
Holger Hildebrandt | 52f271b | 2022-06-02 09:32:27 +0000 | [diff] [blame] | 451 | if strings.Contains(imageInfo.Image.Url, "https:") { |
| 452 | return nil, errors.New("image download via https not supported") |
| 453 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 454 | if !oo.pDownloadManager.ImageExists(ctx, imageInfo.Image) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 455 | logger.Debugw(ctx, "start image download", log.Fields{"image-description": imageInfo.Image}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 456 | // Download_image is not supposed to be blocking, anyway let's call the DownloadManager still synchronously to detect 'fast' problems |
| 457 | // the download itself is later done in background |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 458 | if err := oo.pDownloadManager.StartDownload(ctx, imageInfo.Image); err != nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 459 | return nil, err |
| 460 | } |
| 461 | return imageInfo.Image, nil |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 462 | } |
| 463 | // image already exists |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 464 | logger.Debugw(ctx, "image already downloaded", log.Fields{"image-description": imageInfo.Image}) |
| 465 | return imageInfo.Image, nil |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 466 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 467 | |
| 468 | return nil, errors.New("invalid image definition") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 469 | } |
| 470 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 471 | // ActivateImageUpdate requests downloading some Onu Software image to the ONU via OMCI |
| 472 | // |
| 473 | // according to indications as given in request and on success activate the image on the ONU |
| 474 | // |
| 475 | // The ImageDownload needs to be called `request`due to library reflection requirements |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 476 | func (oo *OpenONUAC) ActivateImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 477 | if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" { |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 478 | if oo.pDownloadManager.ImageLocallyDownloaded(ctx, imageInfo.Image) { |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 479 | if handler, err := oo.getDeviceHandler(ctx, imageInfo.Device.Id, false); handler != nil { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 480 | logger.Debugw(ctx, "image download on omci requested", log.Fields{ |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 481 | "image-description": imageInfo.Image, "device-id": imageInfo.Device.Id}) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 482 | if swUpgradeErr := handler.doOnuSwUpgrade(ctx, imageInfo.Image, oo.pDownloadManager); swUpgradeErr != nil { |
| 483 | return nil, swUpgradeErr |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 484 | } |
| 485 | return imageInfo.Image, nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 486 | } else { |
| 487 | logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": imageInfo.Device.Id}) |
| 488 | return nil, err |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 489 | } |
mpagenko | 057889c | 2021-01-21 16:51:58 +0000 | [diff] [blame] | 490 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 491 | logger.Debugw(ctx, "image not yet downloaded on activate request", log.Fields{"image-description": imageInfo.Image}) |
Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 492 | return nil, fmt.Errorf("image-not-yet-downloaded - device-id: %s", imageInfo.Device.Id) |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 493 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 494 | return nil, errors.New("invalid image definition") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 495 | } |
| 496 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 497 | // GetSingleValue handles the core request to retrieve uni status |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 498 | func (oo *OpenONUAC) GetSingleValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) { |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 499 | logger.Infow(ctx, "Single_get_value_request", log.Fields{"request": request}) |
| 500 | |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 501 | if handler, err := oo.getDeviceHandler(ctx, request.TargetId, false); handler != nil { |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 502 | switch reqType := request.GetRequest().GetRequest().(type) { |
| 503 | case *extension.GetValueRequest_UniInfo: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 504 | return handler.GetUniPortStatus(ctx, reqType.UniInfo), nil |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 505 | case *extension.GetValueRequest_OnuOpticalInfo: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 506 | CommChan := make(chan cmn.Message) |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 507 | respChan := make(chan extension.SingleGetValueResponse) |
| 508 | // Initiate the self test request |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 509 | if selfTestErr := handler.pSelfTestHdlr.SelfTestRequestStart(ctx, *request, CommChan, respChan); selfTestErr != nil { |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 510 | return &extension.SingleGetValueResponse{ |
| 511 | Response: &extension.GetValueResponse{ |
| 512 | Status: extension.GetValueResponse_ERROR, |
| 513 | ErrReason: extension.GetValueResponse_INTERNAL_ERROR, |
| 514 | }, |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 515 | }, selfTestErr |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 516 | } |
| 517 | // The timeout handling is already implemented in omci_self_test_handler module |
| 518 | resp := <-respChan |
| 519 | return &resp, nil |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 520 | case *extension.GetValueRequest_OnuInfo: |
| 521 | return handler.getOnuOMCICounters(ctx, reqType.OnuInfo), nil |
Holger Hildebrandt | 66af5ce | 2022-09-07 13:38:02 +0000 | [diff] [blame] | 522 | case *extension.GetValueRequest_OnuOmciStats: |
| 523 | return handler.getOnuOMCIStats(ctx) |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 524 | case *extension.GetValueRequest_OnuActiveAlarms: |
| 525 | resp := handler.getOnuActiveAlarms(ctx) |
| 526 | logger.Infow(ctx, "Received response for on demand active alarms request ", log.Fields{"response": resp}) |
| 527 | return resp, nil |
Akash Reddy Kankanala | c28f0e2 | 2025-06-16 11:00:55 +0530 | [diff] [blame] | 528 | case *extension.GetValueRequest_OnuAllocGemStats: |
| 529 | resp := handler.getONUGEMStatsInfo(ctx) |
| 530 | logger.Infow(ctx, "Received response for on demand active alarms request ", log.Fields{"response": resp}) |
| 531 | return resp, nil |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 532 | default: |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 533 | return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_UNSUPPORTED), nil |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 534 | } |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 535 | } else { |
| 536 | logger.Errorw(ctx, "Single_get_value_request failed ", log.Fields{"request": request}) |
| 537 | return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_INVALID_DEVICE_ID), err |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 538 | } |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 539 | } |
| 540 | |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 541 | //if update >= 4.3.0 |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 542 | // Note: already with the implementation of the 'old' download interface problems were detected when the argument name used here is not the same |
| 543 | // as defined in the adapter interface file. That sounds strange and the effects were strange as well. |
| 544 | // The reason for that was never finally investigated. |
| 545 | // To be on the safe side argument names are left here always as defined in iAdapter.go . |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 546 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 547 | // DownloadOnuImage downloads (and optionally activates and commits) the indicated ONU image to the requested ONU(s) |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 548 | // |
| 549 | // if the image is not yet present on the adapter it has to be automatically downloaded |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 550 | func (oo *OpenONUAC) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 551 | if request != nil && len((*request).DeviceId) > 0 && (*request).Image.Version != "" { |
Holger Hildebrandt | 52f271b | 2022-06-02 09:32:27 +0000 | [diff] [blame] | 552 | if strings.Contains((*request).Image.Url, "https:") { |
| 553 | return nil, errors.New("image download via https not supported") |
| 554 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 555 | loResponse := voltha.DeviceImageResponse{} |
| 556 | imageIdentifier := (*request).Image.Version |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 557 | downloadStartDone := false |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 558 | firstDevice := true |
| 559 | var vendorID string |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 560 | var onuVolthaDevice *voltha.Device |
| 561 | var devErr error |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 562 | for _, pCommonID := range (*request).DeviceId { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 563 | vendorIDMatch := true |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 564 | loDeviceID := (*pCommonID).Id |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 565 | loDeviceImageState := voltha.DeviceImageState{} |
| 566 | loDeviceImageState.DeviceId = loDeviceID |
| 567 | loImageState := voltha.ImageState{} |
| 568 | loDeviceImageState.ImageState = &loImageState |
| 569 | loDeviceImageState.ImageState.Version = (*request).Image.Version |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 570 | |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 571 | onuVolthaDevice = nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 572 | handler, err := oo.getDeviceHandler(ctx, loDeviceID, false) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 573 | if handler != nil { |
| 574 | onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID) |
| 575 | } else { |
| 576 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 577 | devErr = err |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 578 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 579 | if devErr != nil || onuVolthaDevice == nil { |
| 580 | logger.Warnw(ctx, "Failed to fetch ONU device for image download", |
| 581 | log.Fields{"device-id": loDeviceID, "err": devErr}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 582 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
| 583 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //proto restriction, better option: 'INVALID_DEVICE' |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 584 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 585 | } else { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 586 | if firstDevice { |
| 587 | //start/verify download of the image to the adapter based on first found device only |
| 588 | // use the OnuVendor identification from first given device |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 589 | |
| 590 | // note: if the request was done for a list of devices on the Voltha interface, rwCore |
| 591 | // translates that into a new rpc for each device, hence each device will be the first device in parallel requests! |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 592 | firstDevice = false |
| 593 | vendorID = onuVolthaDevice.VendorId |
| 594 | imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 595 | logger.Infow(ctx, "download request for file", |
| 596 | log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 597 | |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 598 | // call the StartDownload synchronously to detect 'immediate' download problems |
| 599 | // the real download itself is later done in background |
| 600 | if fileState, err := oo.pFileManager.StartDownload(ctx, imageIdentifier, (*request).Image.Url); err == nil { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 601 | // note: If the image (with vendorId+name) has already been downloaded before from some other |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 602 | // valid URL, the current download request is not executed (current code delivers URL error). |
| 603 | // If the operators want to ensure that the new URL |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 604 | // is really used, then they first have to use the 'abort' API to remove the existing image! |
| 605 | // (abort API can be used also after some successful download to just remove the image from adapter) |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 606 | if fileState == swupg.CFileStateDlSucceeded || fileState == swupg.CFileStateDlStarted { |
| 607 | downloadStartDone = true |
| 608 | } //else fileState may also indicate error situation, where the requested image is not ready to be used for other devices |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 609 | } |
| 610 | } else { |
| 611 | //for all following devices verify the matching vendorID |
| 612 | if onuVolthaDevice.VendorId != vendorID { |
| 613 | logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored", |
| 614 | log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID}) |
| 615 | vendorIDMatch = false |
| 616 | } |
| 617 | } |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 618 | if downloadStartDone && vendorIDMatch { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 619 | // start the ONU download activity for each possible device |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 620 | logger.Infow(ctx, "request image download to ONU on omci ", log.Fields{ |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 621 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 622 | //onu upgrade handling called in background without immediate error evaluation here |
| 623 | // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others |
| 624 | // state/progress/success of the request has to be verified using the Get_onu_image_status() API |
| 625 | go handler.onuSwUpgradeAfterDownload(ctx, request, oo.pFileManager, imageIdentifier) |
| 626 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_STARTED |
| 627 | loDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR |
| 628 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 629 | } else { |
| 630 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 631 | if !downloadStartDone { |
| 632 | //based on above fileState more descriptive error codes would be possible, e.g |
| 633 | // IMAGE_EXISTS_WITH_DIFFERENT_URL - would require proto buf update |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 634 | loDeviceImageState.ImageState.Reason = voltha.ImageState_INVALID_URL |
| 635 | } else { //only logical option is !vendorIDMatch |
| 636 | loDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH |
| 637 | } |
| 638 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 639 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 640 | } |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 641 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 642 | } //for all requested devices |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 643 | pImageResp := &loResponse |
| 644 | return pImageResp, nil |
| 645 | } |
| 646 | return nil, errors.New("invalid image download parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 647 | } |
| 648 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 649 | // GetOnuImageStatus delivers the adapter-related information about the download/activation/commitment |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 650 | // |
| 651 | // status for the requested image |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 652 | func (oo *OpenONUAC) GetOnuImageStatus(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 653 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 654 | loResponse := voltha.DeviceImageResponse{} |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 655 | imageIdentifier := (*in).Version |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 656 | var vendorIDSet bool |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 657 | firstDevice := true |
| 658 | var vendorID string |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 659 | var onuVolthaDevice *voltha.Device |
| 660 | var devErr error |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 661 | for _, pCommonID := range (*in).DeviceId { |
| 662 | loDeviceID := (*pCommonID).Id |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 663 | pDeviceImageState := &voltha.DeviceImageState{DeviceId: loDeviceID} |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 664 | vendorIDSet = false |
| 665 | onuVolthaDevice = nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 666 | handler, err := oo.getDeviceHandler(ctx, loDeviceID, false) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 667 | if handler != nil { |
| 668 | onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID) |
| 669 | } else { |
| 670 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 671 | devErr = err |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 672 | } |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 673 | if devErr != nil || onuVolthaDevice == nil { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 674 | logger.Warnw(ctx, "Failed to fetch Onu device to get image status", |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 675 | log.Fields{"device-id": loDeviceID, "err": devErr}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 676 | pImageState := &voltha.ImageState{ |
| 677 | Version: (*in).Version, |
| 678 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //no statement about last activity possible |
| 679 | Reason: voltha.ImageState_UNKNOWN_ERROR, //something like "DEVICE_NOT_EXISTS" would be better (proto def) |
| 680 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 681 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 682 | pDeviceImageState.ImageState = pImageState |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 683 | } else { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 684 | if firstDevice { |
| 685 | //start/verify download of the image to the adapter based on first found device only |
| 686 | // use the OnuVendor identification from first given device |
| 687 | firstDevice = false |
| 688 | vendorID = onuVolthaDevice.VendorId |
| 689 | imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU |
| 690 | vendorIDSet = true |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 691 | logger.Debugw(ctx, "status request for image", log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 692 | } else { |
| 693 | //for all following devices verify the matching vendorID |
| 694 | if onuVolthaDevice.VendorId != vendorID { |
| 695 | logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored", |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 696 | log.Fields{"device-id": loDeviceID, "onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 697 | } else { |
| 698 | vendorIDSet = true |
| 699 | } |
| 700 | } |
| 701 | if !vendorIDSet { |
| 702 | pImageState := &voltha.ImageState{ |
| 703 | Version: (*in).Version, |
| 704 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //can't be sure that download for this device was really tried |
| 705 | Reason: voltha.ImageState_VENDOR_DEVICE_MISMATCH, |
| 706 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 707 | } |
| 708 | pDeviceImageState.ImageState = pImageState |
| 709 | } else { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 710 | logger.Debugw(ctx, "image status request for", log.Fields{ |
| 711 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 712 | //status request is called synchronously to collect the indications for all concerned devices |
| 713 | pDeviceImageState.ImageState = handler.requestOnuSwUpgradeState(ctx, imageIdentifier, (*in).Version) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 714 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 715 | } |
| 716 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 717 | } //for all requested devices |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 718 | pImageResp := &loResponse |
| 719 | return pImageResp, nil |
| 720 | } |
| 721 | return nil, errors.New("invalid image status request parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 722 | } |
| 723 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 724 | // AbortOnuImageUpgrade stops the actual download/activation/commitment process (on next possibly step) |
| 725 | func (oo *OpenONUAC) AbortOnuImageUpgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 726 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 727 | loResponse := voltha.DeviceImageResponse{} |
| 728 | imageIdentifier := (*in).Version |
| 729 | firstDevice := true |
| 730 | var vendorID string |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 731 | var vendorIDSet bool |
| 732 | var onuVolthaDevice *voltha.Device |
| 733 | var devErr error |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 734 | for _, pCommonID := range (*in).DeviceId { |
| 735 | loDeviceID := (*pCommonID).Id |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 736 | pDeviceImageState := &voltha.DeviceImageState{} |
| 737 | loImageState := voltha.ImageState{} |
| 738 | pDeviceImageState.ImageState = &loImageState |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 739 | vendorIDSet = false |
| 740 | onuVolthaDevice = nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 741 | handler, err := oo.getDeviceHandler(ctx, loDeviceID, false) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 742 | if handler != nil { |
| 743 | onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID) |
| 744 | } else { |
| 745 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 746 | devErr = err |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 747 | } |
| 748 | if devErr != nil || onuVolthaDevice == nil { |
| 749 | logger.Warnw(ctx, "Failed to fetch Onu device to abort its download", |
| 750 | log.Fields{"device-id": loDeviceID, "err": devErr}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 751 | pDeviceImageState.DeviceId = loDeviceID |
| 752 | pDeviceImageState.ImageState.Version = (*in).Version |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 753 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 754 | pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST //something better could be considered (MissingHandler) - proto |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 755 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 756 | } else { |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 757 | if firstDevice { |
| 758 | //start/verify download of the image to the adapter based on first found device only |
| 759 | // use the OnuVendor identification from first given device |
| 760 | firstDevice = false |
| 761 | vendorID = onuVolthaDevice.VendorId |
| 762 | vendorIDSet = true |
| 763 | imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 764 | logger.Debugw(ctx, "abort request for file", log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier}) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 765 | } else { |
| 766 | //for all following devices verify the matching vendorID |
| 767 | if onuVolthaDevice.VendorId != vendorID { |
| 768 | logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored", |
Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 769 | log.Fields{"device-id": loDeviceID, "onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID}) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 770 | pDeviceImageState.DeviceId = loDeviceID |
| 771 | pDeviceImageState.ImageState.Version = (*in).Version |
| 772 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 773 | pDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH |
| 774 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 775 | } else { |
| 776 | vendorIDSet = true |
| 777 | } |
| 778 | } |
| 779 | if vendorIDSet { |
| 780 | // cancel the ONU upgrade activity for each possible device |
| 781 | logger.Debugw(ctx, "image upgrade abort requested", log.Fields{ |
| 782 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 783 | //upgrade cancel is called synchronously to collect the imageResponse indications for all concerned devices |
| 784 | handler.cancelOnuSwUpgrade(ctx, imageIdentifier, (*in).Version, pDeviceImageState) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 785 | } |
| 786 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 787 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState) |
mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 788 | } //for all requested devices |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 789 | if !firstDevice { |
| 790 | //if at least one valid device was found cancel also a possibly running download to adapter and remove the image |
| 791 | // this is to be done after the upgradeOnu cancel activities in order to not subduct the file for still running processes |
| 792 | oo.pFileManager.CancelDownload(ctx, imageIdentifier) |
| 793 | } |
| 794 | pImageResp := &loResponse |
| 795 | return pImageResp, nil |
| 796 | } |
| 797 | return nil, errors.New("invalid image upgrade abort parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 798 | } |
| 799 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 800 | // GetOnuImages retrieves the ONU SW image status information via OMCI |
| 801 | func (oo *OpenONUAC) GetOnuImages(ctx context.Context, id *common.ID) (*voltha.OnuImages, error) { |
| 802 | logger.Infow(ctx, "Get_onu_images", log.Fields{"device-id": id.Id}) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 803 | if handler, err := oo.getDeviceHandler(ctx, id.Id, false); handler != nil { |
| 804 | images, getImagesErr := handler.getOnuImages(ctx) |
| 805 | if getImagesErr == nil { |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 806 | return images, nil |
| 807 | } |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 808 | return nil, fmt.Errorf("%s-%s", getImagesErr, id.Id) |
| 809 | } else { |
| 810 | logger.Warnw(ctx, "no handler found for Get_onu_images", log.Fields{"device-id": id.Id}) |
| 811 | return nil, err |
Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 812 | } |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 813 | } |
| 814 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 815 | // ActivateOnuImage initiates the activation of the image for the requested ONU(s) |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 816 | // |
| 817 | // precondition: image downloaded and not yet activated or image refers to current inactive image |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 818 | func (oo *OpenONUAC) ActivateOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 819 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 820 | loResponse := voltha.DeviceImageResponse{} |
| 821 | imageIdentifier := (*in).Version |
| 822 | //let the deviceHandler find the adequate way of requesting the image activation |
| 823 | for _, pCommonID := range (*in).DeviceId { |
| 824 | loDeviceID := (*pCommonID).Id |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 825 | loDeviceImageState := voltha.DeviceImageState{} |
| 826 | loDeviceImageState.DeviceId = loDeviceID |
| 827 | loImageState := voltha.ImageState{} |
| 828 | loDeviceImageState.ImageState = &loImageState |
| 829 | loDeviceImageState.ImageState.Version = imageIdentifier |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 830 | //compared to download procedure the vendorID (from device) is secondary here |
| 831 | // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed) |
| 832 | // start image activation activity for each possible device |
| 833 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 834 | if handler, _ := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 835 | logger.Debugw(ctx, "onu image activation requested", log.Fields{ |
| 836 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 837 | //onu activation handling called in background without immediate error evaluation here |
| 838 | // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others |
| 839 | // state/progress/success of the request has to be verified using the Get_onu_image_status() API |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 840 | if pImageStates, err := handler.onuSwActivateRequest(ctx, imageIdentifier, (*in).CommitOnSuccess); err != nil { |
| 841 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 842 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR |
| 843 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED |
| 844 | } else { |
| 845 | loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState |
| 846 | loDeviceImageState.ImageState.Reason = pImageStates.Reason |
| 847 | loDeviceImageState.ImageState.ImageState = pImageStates.ImageState |
| 848 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 849 | } else { |
| 850 | //cannot start SW activation for requested device |
| 851 | logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": loDeviceID}) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 852 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 853 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR |
| 854 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 855 | } |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 856 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 857 | } |
| 858 | pImageResp := &loResponse |
| 859 | return pImageResp, nil |
| 860 | } |
| 861 | return nil, errors.New("invalid image activation parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 862 | } |
| 863 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 864 | // CommitOnuImage enforces the commitment of the image for the requested ONU(s) |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 865 | // |
| 866 | // precondition: image activated and not yet committed |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 867 | func (oo *OpenONUAC) CommitOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 868 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 869 | loResponse := voltha.DeviceImageResponse{} |
| 870 | imageIdentifier := (*in).Version |
| 871 | //let the deviceHandler find the adequate way of requesting the image activation |
| 872 | for _, pCommonID := range (*in).DeviceId { |
| 873 | loDeviceID := (*pCommonID).Id |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 874 | loDeviceImageState := voltha.DeviceImageState{} |
| 875 | loDeviceImageState.DeviceId = loDeviceID |
| 876 | loImageState := voltha.ImageState{} |
| 877 | loDeviceImageState.ImageState = &loImageState |
| 878 | loDeviceImageState.ImageState.Version = imageIdentifier |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 879 | //compared to download procedure the vendorID (from device) is secondary here |
| 880 | // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed) |
| 881 | // start image activation activity for each possible device |
| 882 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 883 | if handler, _ := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 884 | logger.Debugw(ctx, "onu image commitment requested", log.Fields{ |
| 885 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 886 | //onu commitment handling called in background without immediate error evaluation here |
| 887 | // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others |
| 888 | // state/progress/success of the request has to be verified using the Get_onu_image_status() API |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 889 | if pImageStates, err := handler.onuSwCommitRequest(ctx, imageIdentifier); err != nil { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 890 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
| 891 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //can be multiple reasons here |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 892 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED |
| 893 | } else { |
| 894 | loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState |
| 895 | loDeviceImageState.ImageState.Reason = pImageStates.Reason |
| 896 | loDeviceImageState.ImageState.ImageState = pImageStates.ImageState |
| 897 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 898 | } else { |
| 899 | //cannot start SW commitment for requested device |
| 900 | logger.Warnw(ctx, "no handler found for image commitment", log.Fields{"device-id": loDeviceID}) |
mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 901 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 902 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR |
| 903 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 904 | } |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 905 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 906 | } |
| 907 | pImageResp := &loResponse |
| 908 | return pImageResp, nil |
| 909 | } |
| 910 | return nil, errors.New("invalid image commitment parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 911 | } |
| 912 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 913 | // Adapter interface required methods ################ end ######### |
| 914 | // ################################################################# |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 915 | |
| 916 | /* |
| 917 | * |
| 918 | * ONU inter adapter service |
| 919 | * |
| 920 | */ |
| 921 | |
| 922 | // OnuIndication is part of the ONU Inter-adapter service API. |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 923 | func (oo *OpenONUAC) OnuIndication(ctx context.Context, onuInd *ia.OnuIndicationMessage) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 924 | logger.Debugw(ctx, "onu-indication", log.Fields{"onu-indication": onuInd}) |
| 925 | |
| 926 | if onuInd == nil || onuInd.OnuIndication == nil { |
| 927 | return nil, fmt.Errorf("invalid-onu-indication-%v", onuInd) |
| 928 | } |
| 929 | |
| 930 | onuIndication := onuInd.OnuIndication |
| 931 | onuOperstate := onuIndication.GetOperState() |
| 932 | waitForDhInstPresent := false |
| 933 | if onuOperstate == "up" { |
| 934 | //Race condition (relevant in BBSIM-environment only): Due to unsynchronized processing of olt-adapter and rw_core, |
| 935 | //ONU_IND_REQUEST msg by olt-adapter could arrive a little bit earlier than rw_core was able to announce the corresponding |
| 936 | //ONU by RPC of Adopt_device(). Therefore it could be necessary to wait with processing of ONU_IND_REQUEST until call of |
| 937 | //Adopt_device() arrived and DeviceHandler instance was created |
| 938 | waitForDhInstPresent = true |
| 939 | } |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 940 | if handler, _ := oo.getDeviceHandler(ctx, onuInd.DeviceId, waitForDhInstPresent); handler != nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 941 | logger.Infow(ctx, "onu-ind-request", log.Fields{"device-id": onuInd.DeviceId, |
| 942 | "OnuId": onuIndication.GetOnuId(), |
| 943 | "AdminState": onuIndication.GetAdminState(), "OperState": onuOperstate, |
| 944 | "SNR": onuIndication.GetSerialNumber()}) |
| 945 | |
| 946 | if onuOperstate == "up" { |
| 947 | if err := handler.createInterface(ctx, onuIndication); err != nil { |
| 948 | return nil, err |
| 949 | } |
| 950 | return &empty.Empty{}, nil |
| 951 | } else if (onuOperstate == "down") || (onuOperstate == "unreachable") { |
Holger Hildebrandt | 68854a8 | 2022-09-05 07:00:21 +0000 | [diff] [blame] | 952 | if err := handler.UpdateInterface(ctx); err != nil { |
ozgecanetsia | 76db57a | 2022-02-03 15:32:03 +0300 | [diff] [blame] | 953 | return nil, err |
| 954 | } |
| 955 | return &empty.Empty{}, nil |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 956 | } else { |
| 957 | logger.Errorw(ctx, "unknown-onu-ind-request operState", log.Fields{"OnuId": onuIndication.GetOnuId()}) |
| 958 | return nil, fmt.Errorf("invalidOperState: %s, %s", onuOperstate, onuInd.DeviceId) |
| 959 | } |
| 960 | } |
| 961 | logger.Warnw(ctx, "no handler found for received onu-ind-request", log.Fields{ |
| 962 | "msgToDeviceId": onuInd.DeviceId}) |
Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 963 | return nil, fmt.Errorf("handler-not-found-%s", onuInd.DeviceId) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | // OmciIndication is part of the ONU Inter-adapter service API. |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 967 | func (oo *OpenONUAC) OmciIndication(ctx context.Context, msg *ia.OmciMessage) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 968 | logger.Debugw(ctx, "omci-response", log.Fields{"parent-device-id": msg.ParentDeviceId, "child-device-id": msg.ChildDeviceId}) |
| 969 | |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 970 | if handler, err := oo.getDeviceHandler(ctx, msg.ChildDeviceId, false); handler != nil { |
| 971 | if omciIndErr := handler.handleOMCIIndication(log.WithSpanFromContext(context.Background(), ctx), msg); omciIndErr != nil { |
| 972 | return nil, omciIndErr |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 973 | } |
| 974 | return &empty.Empty{}, nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 975 | } else { |
| 976 | return nil, err |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 977 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | // DownloadTechProfile is part of the ONU Inter-adapter service API. |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 981 | func (oo *OpenONUAC) DownloadTechProfile(ctx context.Context, tProfile *ia.TechProfileDownloadMessage) (*empty.Empty, error) { |
nikesh.krishnan | 1ffb813 | 2023-05-23 03:44:13 +0530 | [diff] [blame] | 982 | logger.Info(ctx, "download-tech-profile", log.Fields{"device-id": tProfile.DeviceId, "uni-id": tProfile.UniId}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 983 | |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 984 | if handler, err := oo.getDeviceHandler(ctx, tProfile.DeviceId, false); handler != nil { |
Praneeth Nalmas | 04600be | 2024-12-08 20:12:32 +0530 | [diff] [blame] | 985 | handler.RLockMutexDeletionInProgressFlag() |
| 986 | if handler.GetDeletionInProgress() { |
| 987 | logger.Warnw(ctx, "Device deletion in progress - avoid processing Tech Profile", log.Fields{"device-id": tProfile.DeviceId}) |
| 988 | |
| 989 | handler.RUnlockMutexDeletionInProgressFlag() |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 990 | return nil, fmt.Errorf("can't proceed, device deletion is in progress-%s", tProfile.DeviceId) |
Praneeth Nalmas | 04600be | 2024-12-08 20:12:32 +0530 | [diff] [blame] | 991 | } |
| 992 | handler.RUnlockMutexDeletionInProgressFlag() |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 993 | if tpDownloadErr := handler.handleTechProfileDownloadRequest(log.WithSpanFromContext(context.Background(), ctx), tProfile); tpDownloadErr != nil { |
| 994 | return nil, tpDownloadErr |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 995 | } |
| 996 | return &empty.Empty{}, nil |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 997 | } else { |
| 998 | return nil, err |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 999 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | // DeleteGemPort is part of the ONU Inter-adapter service API. |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1003 | func (oo *OpenONUAC) DeleteGemPort(ctx context.Context, gPort *ia.DeleteGemPortMessage) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1004 | logger.Debugw(ctx, "delete-gem-port", log.Fields{"device-id": gPort.DeviceId, "uni-id": gPort.UniId}) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 1005 | if handler, _ := oo.getDeviceHandler(ctx, gPort.DeviceId, false); handler != nil { |
nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 1006 | if handler.GetDeletionInProgress() { |
| 1007 | logger.Error(ctx, "device deletion in progres", log.Fields{"device-id": gPort.DeviceId}) |
| 1008 | return nil, fmt.Errorf("device deletion in progress for device-id: %s", gPort.DeviceId) |
| 1009 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1010 | if err := handler.handleDeleteGemPortRequest(log.WithSpanFromContext(context.Background(), ctx), gPort); err != nil { |
| 1011 | return nil, err |
| 1012 | } |
Holger Hildebrandt | 5b77406 | 2021-11-10 10:24:29 +0000 | [diff] [blame] | 1013 | } else { |
| 1014 | logger.Debugw(ctx, "deviceHandler not found", log.Fields{"device-id": gPort.DeviceId}) |
| 1015 | // delete requests for objects of an already deleted ONU should be acknowledged positively - continue |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1016 | } |
Holger Hildebrandt | 5b77406 | 2021-11-10 10:24:29 +0000 | [diff] [blame] | 1017 | return &empty.Empty{}, nil |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | // DeleteTCont is part of the ONU Inter-adapter service API. |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1021 | func (oo *OpenONUAC) DeleteTCont(ctx context.Context, tConf *ia.DeleteTcontMessage) (*empty.Empty, error) { |
Holger Hildebrandt | ba6fbe8 | 2021-12-03 14:29:42 +0000 | [diff] [blame] | 1022 | logger.Debugw(ctx, "delete-tcont", log.Fields{"device-id": tConf.DeviceId, "tconf": tConf}) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 1023 | if handler, _ := oo.getDeviceHandler(ctx, tConf.DeviceId, false); handler != nil { |
nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 1024 | if handler.GetDeletionInProgress() { |
| 1025 | logger.Error(ctx, "device deletion in progres", log.Fields{"device-id": tConf.DeviceId}) |
| 1026 | return nil, fmt.Errorf("device deletion in progress for device-id: %s", tConf.DeviceId) |
| 1027 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1028 | if err := handler.handleDeleteTcontRequest(log.WithSpanFromContext(context.Background(), ctx), tConf); err != nil { |
| 1029 | return nil, err |
| 1030 | } |
Holger Hildebrandt | 5b77406 | 2021-11-10 10:24:29 +0000 | [diff] [blame] | 1031 | } else { |
| 1032 | logger.Debugw(ctx, "deviceHandler not found", log.Fields{"device-id": tConf.DeviceId}) |
| 1033 | // delete requests for objects of an already deleted ONU should be acknowledged positively - continue |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1034 | } |
Holger Hildebrandt | 5b77406 | 2021-11-10 10:24:29 +0000 | [diff] [blame] | 1035 | return &empty.Empty{}, nil |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | /* |
| 1039 | * Parent GRPC clients |
| 1040 | */ |
| 1041 | |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1042 | func getHash(endpoint, contextInfo string) string { |
| 1043 | strToHash := endpoint + contextInfo |
| 1044 | h := fnv.New128().Sum([]byte(strToHash)) |
| 1045 | return string(h) |
| 1046 | } |
| 1047 | |
Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 1048 | // nolint:unparam |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1049 | func (oo *OpenONUAC) updateReachabilityFromRemote(ctx context.Context, remote *common.Connection) { |
| 1050 | logger.Debugw(context.Background(), "updating-remote-connection-status", log.Fields{"remote": remote}) |
| 1051 | oo.lockReachableFromRemote.Lock() |
| 1052 | defer oo.lockReachableFromRemote.Unlock() |
| 1053 | endpointHash := getHash(remote.Endpoint, remote.ContextInfo) |
| 1054 | if _, ok := oo.reachableFromRemote[endpointHash]; ok { |
| 1055 | oo.reachableFromRemote[endpointHash].lastKeepAlive = time.Now() |
| 1056 | oo.reachableFromRemote[endpointHash].keepAliveInterval = remote.KeepAliveInterval |
| 1057 | return |
| 1058 | } |
| 1059 | logger.Debugw(context.Background(), "initial-remote-connection", log.Fields{"remote": remote}) |
| 1060 | oo.reachableFromRemote[endpointHash] = &reachabilityFromRemote{lastKeepAlive: time.Now(), keepAliveInterval: remote.KeepAliveInterval} |
| 1061 | } |
| 1062 | |
Akash Soni | 931f9b9 | 2024-12-11 18:36:36 +0530 | [diff] [blame] | 1063 | // func (oo *OpenONUAC) isReachableFromRemote(ctx context.Context, endpoint string, contextInfo string) bool { |
| 1064 | // logger.Debugw(ctx, "checking-remote-reachability", log.Fields{"endpoint": endpoint, "context": contextInfo}) |
| 1065 | // oo.lockReachableFromRemote.RLock() |
| 1066 | // defer oo.lockReachableFromRemote.RUnlock() |
| 1067 | // endpointHash := getHash(endpoint, contextInfo) |
| 1068 | // if _, ok := oo.reachableFromRemote[endpointHash]; ok { |
| 1069 | // logger.Debugw(ctx, "endpoint-exists", log.Fields{"last-keep-alive": time.Since(oo.reachableFromRemote[endpointHash].lastKeepAlive)}) |
| 1070 | // // Assume the connection is down if we did not receive 2 keep alives in succession |
| 1071 | // maxKeepAliveWait := time.Duration(oo.reachableFromRemote[endpointHash].keepAliveInterval * 2) |
| 1072 | // return time.Since(oo.reachableFromRemote[endpointHash].lastKeepAlive) <= maxKeepAliveWait |
| 1073 | // } |
| 1074 | // return false |
| 1075 | // } |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1076 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1077 | // stopAllGrpcClients stops all grpc clients in use |
khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 1078 | func (oo *OpenONUAC) stopAllGrpcClients(ctx context.Context) { |
| 1079 | // Stop the clients that connect to the parent |
| 1080 | oo.lockParentAdapterClients.Lock() |
| 1081 | for key := range oo.parentAdapterClients { |
| 1082 | oo.parentAdapterClients[key].Stop(ctx) |
| 1083 | delete(oo.parentAdapterClients, key) |
| 1084 | } |
| 1085 | oo.lockParentAdapterClients.Unlock() |
| 1086 | |
| 1087 | // Stop core client connection |
| 1088 | oo.coreClient.Stop(ctx) |
| 1089 | } |
| 1090 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1091 | func (oo *OpenONUAC) setupParentInterAdapterClient(ctx context.Context, endpoint string) error { |
| 1092 | logger.Infow(ctx, "setting-parent-adapter-connection", log.Fields{"parent-endpoint": endpoint}) |
| 1093 | oo.lockParentAdapterClients.Lock() |
| 1094 | defer oo.lockParentAdapterClients.Unlock() |
| 1095 | if _, ok := oo.parentAdapterClients[endpoint]; ok { |
| 1096 | return nil |
| 1097 | } |
| 1098 | |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1099 | childClient, err := vgrpc.NewClient( |
| 1100 | oo.config.AdapterEndpoint, |
| 1101 | endpoint, |
khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 1102 | "olt_inter_adapter_service.OltInterAdapterService", |
khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1103 | oo.oltAdapterRestarted) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1104 | |
| 1105 | if err != nil { |
| 1106 | return err |
| 1107 | } |
nikesh.krishnan | ce4879a | 2023-08-01 18:36:57 +0530 | [diff] [blame] | 1108 | retryCodes := []codes.Code{ |
| 1109 | codes.Unavailable, // server is currently unavailable |
| 1110 | codes.DeadlineExceeded, // deadline for the operation was exceeded |
| 1111 | } |
| 1112 | backoffCtxOption := grpc_retry.WithBackoff(grpc_retry.BackoffLinearWithJitter(oo.config.PerRPCRetryTimeout, 0.2)) |
| 1113 | grpcRetryOptions := grpc_retry.UnaryClientInterceptor(grpc_retry.WithMax(oo.config.MaxRetries), grpc_retry.WithPerRetryTimeout(oo.config.PerRPCRetryTimeout), grpc_retry.WithCodes(retryCodes...), backoffCtxOption) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1114 | |
| 1115 | oo.parentAdapterClients[endpoint] = childClient |
nikesh.krishnan | ce4879a | 2023-08-01 18:36:57 +0530 | [diff] [blame] | 1116 | go oo.parentAdapterClients[endpoint].Start(log.WithSpanFromContext(context.TODO(), ctx), getOltInterAdapterServiceClientHandler, grpcRetryOptions) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1117 | // Wait until we have a connection to the child adapter. |
| 1118 | // Unlimited retries or until context expires |
| 1119 | subCtx := log.WithSpanFromContext(context.TODO(), ctx) |
| 1120 | backoff := vgrpc.NewBackoff(oo.config.MinBackoffRetryDelay, oo.config.MaxBackoffRetryDelay, 0) |
| 1121 | for { |
| 1122 | client, err := oo.parentAdapterClients[endpoint].GetOltInterAdapterServiceClient() |
| 1123 | if err == nil && client != nil { |
| 1124 | logger.Infow(subCtx, "connected-to-parent-adapter", log.Fields{"parent-endpoint": endpoint}) |
| 1125 | break |
| 1126 | } |
| 1127 | logger.Warnw(subCtx, "connection-to-parent-adapter-not-ready", log.Fields{"error": err, "parent-endpoint": endpoint}) |
| 1128 | // Backoff |
| 1129 | if err = backoff.Backoff(subCtx); err != nil { |
| 1130 | logger.Errorw(subCtx, "received-error-on-backoff", log.Fields{"error": err, "parent-endpoint": endpoint}) |
| 1131 | break |
| 1132 | } |
| 1133 | } |
| 1134 | return nil |
| 1135 | } |
| 1136 | |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1137 | func (oo *OpenONUAC) getParentAdapterServiceClient(endpoint string) (olt_inter_adapter_service.OltInterAdapterServiceClient, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1138 | // First check from cache |
| 1139 | oo.lockParentAdapterClients.RLock() |
| 1140 | if pgClient, ok := oo.parentAdapterClients[endpoint]; ok { |
| 1141 | oo.lockParentAdapterClients.RUnlock() |
| 1142 | return pgClient.GetOltInterAdapterServiceClient() |
| 1143 | } |
| 1144 | oo.lockParentAdapterClients.RUnlock() |
| 1145 | |
| 1146 | // Set the parent connection - can occur on restarts |
| 1147 | ctx, cancel := context.WithTimeout(context.Background(), oo.config.RPCTimeout) |
| 1148 | err := oo.setupParentInterAdapterClient(ctx, endpoint) |
| 1149 | cancel() |
| 1150 | if err != nil { |
| 1151 | return nil, err |
| 1152 | } |
| 1153 | |
| 1154 | // Get the parent client now |
| 1155 | oo.lockParentAdapterClients.RLock() |
| 1156 | defer oo.lockParentAdapterClients.RUnlock() |
| 1157 | if pgClient, ok := oo.parentAdapterClients[endpoint]; ok { |
| 1158 | return pgClient.GetOltInterAdapterServiceClient() |
| 1159 | } |
| 1160 | |
| 1161 | return nil, fmt.Errorf("no-client-for-endpoint-%s", endpoint) |
| 1162 | } |
| 1163 | |
| 1164 | // TODO: Any action the adapter needs to do following an olt adapter restart? |
| 1165 | func (oo *OpenONUAC) oltAdapterRestarted(ctx context.Context, endPoint string) error { |
| 1166 | logger.Errorw(ctx, "olt-adapter-restarted", log.Fields{"endpoint": endPoint}) |
| 1167 | return nil |
| 1168 | } |
| 1169 | |
khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 1170 | // getOltInterAdapterServiceClientHandler is used to setup the remote gRPC service |
| 1171 | func getOltInterAdapterServiceClientHandler(ctx context.Context, conn *grpc.ClientConn) interface{} { |
| 1172 | if conn == nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1173 | return nil |
| 1174 | } |
khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 1175 | return olt_inter_adapter_service.NewOltInterAdapterServiceClient(conn) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1176 | } |
| 1177 | |
Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 1178 | func (oo *OpenONUAC) forceDeleteDeviceKvData(ctx context.Context, aDeviceID string) error { |
| 1179 | logger.Debugw(ctx, "force deletion of ONU device specific data in kv store", log.Fields{"device-id": aDeviceID}) |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 1180 | |
Girish Gowdra | f10379e | 2022-02-02 21:49:44 -0800 | [diff] [blame] | 1181 | // delete onu persitent data |
Girish Gowdra | e9ff261 | 2022-02-04 11:34:33 -0800 | [diff] [blame] | 1182 | onuBaseKvStorePath := fmt.Sprintf(cmn.CBasePathOnuKVStore, oo.cm.Backend.PathPrefix) |
| 1183 | logger.Debugw(ctx, "SetOnuKVStoreBackend", log.Fields{"IpTarget": oo.KVStoreAddress, "BasePathKvStore": onuBaseKvStorePath, |
| 1184 | "device-id": aDeviceID}) |
| 1185 | onuKvbackend := &db.Backend{ |
| 1186 | Client: oo.kvClient, |
| 1187 | StoreType: oo.KVStoreType, |
| 1188 | Address: oo.KVStoreAddress, |
| 1189 | Timeout: oo.KVStoreTimeout, |
| 1190 | PathPrefix: onuBaseKvStorePath, |
| 1191 | } |
| 1192 | err := onuKvbackend.DeleteWithPrefix(ctx, aDeviceID) |
| 1193 | if err != nil { |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 1194 | errMsg := fmt.Sprintf("unable to delete ONU persistent data at %s, error: %s", cmn.CBasePathOnuKVStore, err) |
| 1195 | logger.Error(ctx, errMsg) |
| 1196 | return status.Error(codes.Internal, errMsg) |
Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 1197 | } |
Girish Gowdra | f10379e | 2022-02-02 21:49:44 -0800 | [diff] [blame] | 1198 | // delete pm data |
Girish Gowdra | e9ff261 | 2022-02-04 11:34:33 -0800 | [diff] [blame] | 1199 | pmBaseKvStorePath := fmt.Sprintf(pmmgr.CPmKvStorePrefixBase, oo.cm.Backend.PathPrefix) |
| 1200 | logger.Debugw(ctx, "SetPmKVStoreBackend", log.Fields{"IpTarget": oo.KVStoreAddress, "BasePathKvStore": pmBaseKvStorePath, |
| 1201 | "device-id": aDeviceID}) |
Girish Gowdra | f10379e | 2022-02-02 21:49:44 -0800 | [diff] [blame] | 1202 | pmKvbackend := &db.Backend{ |
| 1203 | Client: oo.kvClient, |
| 1204 | StoreType: oo.KVStoreType, |
| 1205 | Address: oo.KVStoreAddress, |
| 1206 | Timeout: oo.KVStoreTimeout, |
Girish Gowdra | e9ff261 | 2022-02-04 11:34:33 -0800 | [diff] [blame] | 1207 | PathPrefix: pmBaseKvStorePath, |
Girish Gowdra | f10379e | 2022-02-02 21:49:44 -0800 | [diff] [blame] | 1208 | } |
Girish Gowdra | e9ff261 | 2022-02-04 11:34:33 -0800 | [diff] [blame] | 1209 | err = pmKvbackend.DeleteWithPrefix(ctx, aDeviceID) |
Girish Gowdra | f10379e | 2022-02-02 21:49:44 -0800 | [diff] [blame] | 1210 | if err != nil { |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 1211 | errMsg := fmt.Sprintf("unable to delete device PM data in KVstore at %s, error: %s", pmmgr.CPmKvStorePrefixBase, err) |
| 1212 | logger.Error(ctx, errMsg) |
| 1213 | return status.Error(codes.Internal, errMsg) |
Girish Gowdra | f10379e | 2022-02-02 21:49:44 -0800 | [diff] [blame] | 1214 | } |
Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 1215 | return nil |
| 1216 | } |
| 1217 | |
khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 1218 | // GetHealthStatus is used by the voltha core to open a streaming connection with the onu adapter. |
| 1219 | func (oo *OpenONUAC) GetHealthStatus(stream adapter_service.AdapterService_GetHealthStatusServer) error { |
| 1220 | ctx := context.Background() |
| 1221 | logger.Debugw(ctx, "receive-stream-connection", log.Fields{"stream": stream}) |
| 1222 | |
| 1223 | if stream == nil { |
| 1224 | return fmt.Errorf("conn-is-nil %v", stream) |
| 1225 | } |
| 1226 | initialRequestTime := time.Now() |
| 1227 | var remoteClient *common.Connection |
| 1228 | var tempClient *common.Connection |
| 1229 | var err error |
| 1230 | loop: |
| 1231 | for { |
| 1232 | tempClient, err = stream.Recv() |
| 1233 | if err != nil { |
| 1234 | logger.Warnw(ctx, "received-stream-error", log.Fields{"remote-client": remoteClient, "error": err}) |
| 1235 | break loop |
| 1236 | } |
| 1237 | // Send a response back |
| 1238 | err = stream.Send(&health.HealthStatus{State: health.HealthStatus_HEALTHY}) |
| 1239 | if err != nil { |
| 1240 | logger.Warnw(ctx, "sending-stream-error", log.Fields{"remote-client": remoteClient, "error": err}) |
| 1241 | break loop |
| 1242 | } |
| 1243 | remoteClient = tempClient |
| 1244 | |
| 1245 | logger.Debugw(ctx, "received-keep-alive", log.Fields{"remote-client": remoteClient}) |
| 1246 | |
| 1247 | select { |
| 1248 | case <-stream.Context().Done(): |
| 1249 | logger.Infow(ctx, "stream-keep-alive-context-done", log.Fields{"remote-client": remoteClient, "error": stream.Context().Err()}) |
| 1250 | break loop |
| 1251 | case <-oo.exitChannel: |
| 1252 | logger.Warnw(ctx, "received-stop", log.Fields{"remote-client": remoteClient, "initial-conn-time": initialRequestTime}) |
| 1253 | break loop |
| 1254 | default: |
| 1255 | } |
| 1256 | } |
| 1257 | logger.Errorw(ctx, "connection-down", log.Fields{"remote-client": remoteClient, "error": err, "initial-conn-time": initialRequestTime}) |
| 1258 | return err |
| 1259 | } |
| 1260 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1261 | /* |
| 1262 | * |
| 1263 | * Unimplemented APIs |
| 1264 | * |
| 1265 | */ |
| 1266 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1267 | // GetOfpDeviceInfo returns OFP information for the given device. Method not implemented as per [VOL-3202]. |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1268 | // OF port info is now to be delivered within UniPort create cmp changes in onu_uni_port.go::CreateVolthaPort() |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1269 | func (oo *OpenONUAC) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1270 | return nil, errors.New("unImplemented") |
| 1271 | } |
| 1272 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1273 | // SimulateAlarm is unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1274 | func (oo *OpenONUAC) SimulateAlarm(context.Context, *ca.SimulateAlarmMessage) (*common.OperationResp, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1275 | return nil, errors.New("unImplemented") |
| 1276 | } |
| 1277 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1278 | // SetExtValue is unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1279 | func (oo *OpenONUAC) SetExtValue(context.Context, *ca.SetExtValueMessage) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1280 | return nil, errors.New("unImplemented") |
| 1281 | } |
| 1282 | |
Akash Soni | 3c176c6 | 2024-12-04 13:30:43 +0530 | [diff] [blame] | 1283 | // SetSingleValue sets a single value based on the given request and returns the response. |
| 1284 | func (oo *OpenONUAC) SetSingleValue(ctx context.Context, request *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) { |
| 1285 | logger.Infow(ctx, "single_set_value_request", log.Fields{"request": request}) |
| 1286 | |
| 1287 | errResp := func(status extension.SetValueResponse_Status, |
| 1288 | reason extension.SetValueResponse_ErrorReason) *extension.SingleSetValueResponse { |
| 1289 | return &extension.SingleSetValueResponse{ |
| 1290 | Response: &extension.SetValueResponse{ |
| 1291 | Status: status, |
| 1292 | ErrReason: reason, |
| 1293 | }, |
| 1294 | } |
| 1295 | } |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 1296 | if handler, err := oo.getDeviceHandler(ctx, request.TargetId, false); handler != nil { |
Akash Soni | 3c176c6 | 2024-12-04 13:30:43 +0530 | [diff] [blame] | 1297 | switch reqType := request.GetRequest().GetRequest().(type) { |
| 1298 | case *extension.SetValueRequest_AppOffloadOnuConfig: |
| 1299 | return handler.setOnuOffloadStats(ctx, reqType.AppOffloadOnuConfig), nil |
| 1300 | default: |
| 1301 | return errResp(extension.SetValueResponse_ERROR, extension.SetValueResponse_UNSUPPORTED), nil |
| 1302 | } |
mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 1303 | } else { |
| 1304 | logger.Errorw(ctx, "Single_set_value_request failed ", log.Fields{"request": request}) |
| 1305 | return errResp(extension.SetValueResponse_ERROR, extension.SetValueResponse_INVALID_DEVICE_ID), err |
Akash Soni | 3c176c6 | 2024-12-04 13:30:43 +0530 | [diff] [blame] | 1306 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1307 | } |
| 1308 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1309 | // StartOmciTest not implemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1310 | func (oo *OpenONUAC) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1311 | return nil, errors.New("unImplemented") |
| 1312 | } |
| 1313 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1314 | // SuppressEvent unimplemented |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1315 | func (oo *OpenONUAC) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 1316 | return nil, errors.New("unImplemented") |
| 1317 | } |
| 1318 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1319 | // UnSuppressEvent unimplemented |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1320 | func (oo *OpenONUAC) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 1321 | return nil, errors.New("unImplemented") |
| 1322 | } |
| 1323 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1324 | // GetImageDownloadStatus is unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1325 | func (oo *OpenONUAC) GetImageDownloadStatus(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1326 | return nil, errors.New("unImplemented") |
| 1327 | } |
| 1328 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1329 | // CancelImageDownload is unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1330 | func (oo *OpenONUAC) CancelImageDownload(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1331 | return nil, errors.New("unImplemented") |
| 1332 | } |
| 1333 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1334 | // RevertImageUpdate is unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1335 | func (oo *OpenONUAC) RevertImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1336 | return nil, errors.New("unImplemented") |
| 1337 | } |
| 1338 | |
| 1339 | // UpdateFlowsBulk is unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1340 | func (oo *OpenONUAC) UpdateFlowsBulk(ctx context.Context, flows *ca.BulkFlows) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1341 | return nil, errors.New("unImplemented") |
| 1342 | } |
| 1343 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1344 | // SelfTestDevice unimplented |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1345 | func (oo *OpenONUAC) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 1346 | return nil, errors.New("unImplemented") |
| 1347 | } |
| 1348 | |
praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1349 | // SendPacketOut sends packet out to the device |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1350 | func (oo *OpenONUAC) SendPacketOut(ctx context.Context, packet *ca.PacketOut) (*empty.Empty, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1351 | return nil, errors.New("unImplemented") |
| 1352 | } |
| 1353 | |
| 1354 | // EnablePort to Enable PON/NNI interface - seems not to be used/required according to python code |
| 1355 | func (oo *OpenONUAC) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 1356 | return nil, errors.New("unImplemented") |
| 1357 | } |
| 1358 | |
| 1359 | // DisablePort to Disable pon/nni interface - seems not to be used/required according to python code |
| 1360 | func (oo *OpenONUAC) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 1361 | return nil, errors.New("unImplemented") |
| 1362 | } |
| 1363 | |
| 1364 | // GetExtValue - unimplemented |
khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1365 | func (oo *OpenONUAC) GetExtValue(ctx context.Context, extInfo *ca.GetExtValueMessage) (*extension.ReturnValues, error) { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1366 | return nil, errors.New("unImplemented") |
| 1367 | } |
| 1368 | |
| 1369 | // ChildDeviceLost - unimplemented |
| 1370 | func (oo *OpenONUAC) ChildDeviceLost(ctx context.Context, childDevice *voltha.Device) (*empty.Empty, error) { |
| 1371 | return nil, errors.New("unImplemented") |
| 1372 | } |
Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1373 | |
| 1374 | // GetSupportedFsms - TODO: add comment |
| 1375 | func (oo *OpenONUAC) GetSupportedFsms() *cmn.OmciDeviceFsms { |
| 1376 | return oo.pSupportedFsms |
| 1377 | } |
| 1378 | |
| 1379 | // LockMutexMibTemplateGenerated - TODO: add comment |
| 1380 | func (oo *OpenONUAC) LockMutexMibTemplateGenerated() { |
| 1381 | oo.mutexMibTemplateGenerated.Lock() |
| 1382 | } |
| 1383 | |
| 1384 | // UnlockMutexMibTemplateGenerated - TODO: add comment |
| 1385 | func (oo *OpenONUAC) UnlockMutexMibTemplateGenerated() { |
| 1386 | oo.mutexMibTemplateGenerated.Unlock() |
| 1387 | } |
| 1388 | |
| 1389 | // GetMibTemplatesGenerated - TODO: add comment |
| 1390 | func (oo *OpenONUAC) GetMibTemplatesGenerated(mibTemplatePath string) (value bool, exist bool) { |
| 1391 | value, exist = oo.mibTemplatesGenerated[mibTemplatePath] |
| 1392 | return value, exist |
| 1393 | } |
| 1394 | |
| 1395 | // SetMibTemplatesGenerated - TODO: add comment |
| 1396 | func (oo *OpenONUAC) SetMibTemplatesGenerated(mibTemplatePath string, value bool) { |
| 1397 | oo.mibTemplatesGenerated[mibTemplatePath] = value |
| 1398 | } |
| 1399 | |
| 1400 | // RLockMutexDeviceHandlersMap - TODO: add comment |
| 1401 | func (oo *OpenONUAC) RLockMutexDeviceHandlersMap() { |
| 1402 | oo.mutexDeviceHandlersMap.RLock() |
| 1403 | } |
| 1404 | |
| 1405 | // RUnlockMutexDeviceHandlersMap - TODO: add comment |
| 1406 | func (oo *OpenONUAC) RUnlockMutexDeviceHandlersMap() { |
| 1407 | oo.mutexDeviceHandlersMap.RUnlock() |
| 1408 | } |
| 1409 | |
| 1410 | // GetDeviceHandler - TODO: add comment |
| 1411 | func (oo *OpenONUAC) GetDeviceHandler(deviceID string) (value cmn.IdeviceHandler, exist bool) { |
| 1412 | value, exist = oo.deviceHandlers[deviceID] |
| 1413 | return value, exist |
| 1414 | } |
Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame] | 1415 | |
| 1416 | // GetONUMIBDBMap - Returns the Map corresponding to ONT type and the MIB common Instance. |
| 1417 | func (oo *OpenONUAC) GetONUMIBDBMap() devdb.OnuMCmnMEDBMap { |
| 1418 | return oo.MibDatabaseMap |
| 1419 | } |
| 1420 | |
| 1421 | // RLockMutexMIBDatabaseMap acquires a read lock on the mutex associated with the MIBDatabaseMap. |
| 1422 | func (oo *OpenONUAC) RLockMutexMIBDatabaseMap() { |
| 1423 | oo.mutexMibDatabaseMap.RLock() |
| 1424 | } |
| 1425 | |
| 1426 | // RUnlockMutexMIBDatabaseMap releases the read lock on the mutex associated with the MIBDatabaseMap. |
| 1427 | func (oo *OpenONUAC) RUnlockMutexMIBDatabaseMap() { |
| 1428 | oo.mutexMibDatabaseMap.RUnlock() |
| 1429 | } |
| 1430 | |
| 1431 | // LockMutexMIBDatabaseMap locks the mutex associated with the MIBDatabaseMap. |
| 1432 | // Should be called before any operations that modify or read from the MIBDatabaseMap. |
| 1433 | func (oo *OpenONUAC) LockMutexMIBDatabaseMap() { |
| 1434 | oo.mutexMibDatabaseMap.Lock() |
| 1435 | } |
| 1436 | |
| 1437 | // UnlockMutexMIBDatabaseMap unlocks the mutex associated with the MIBDatabaseMap. |
| 1438 | // Should be called after completing operations that require exclusive access |
| 1439 | // to the MIBDatabaseMap, ensuring the mutex is released for other goroutines. |
| 1440 | func (oo *OpenONUAC) UnlockMutexMIBDatabaseMap() { |
| 1441 | oo.mutexMibDatabaseMap.Unlock() |
| 1442 | } |
| 1443 | |
| 1444 | // CreateEntryAtMibDatabaseMap adds an entry to the MibDatabaseMap if it doesn't exist |
| 1445 | func (oo *OpenONUAC) CreateEntryAtMibDatabaseMap(ctx context.Context, key string) (*devdb.OnuCmnMEDB, error) { |
| 1446 | oo.mutexMibDatabaseMap.Lock() |
| 1447 | defer oo.mutexMibDatabaseMap.Unlock() |
| 1448 | |
| 1449 | // Check if the key already exists |
| 1450 | if mibEntry, exists := oo.MibDatabaseMap[key]; exists { |
| 1451 | logger.Warnw(ctx, "Entry already exists in MIB Database Map", log.Fields{"remote-client": key}) |
| 1452 | return mibEntry, fmt.Errorf("entry already exists for key: %s", key) |
| 1453 | } |
| 1454 | |
| 1455 | value := devdb.NewOnuCmnMEDB(ctx) |
| 1456 | |
| 1457 | logger.Infow(ctx, "Created a new Common MIB Database Entry", log.Fields{"remote-client": key}) |
| 1458 | oo.MibDatabaseMap[key] = value |
| 1459 | |
| 1460 | return value, nil |
| 1461 | } |
| 1462 | |
| 1463 | // FetchEntryFromMibDatabaseMap fetches a references to common ME DB for a MIB Template from the MibDatabaseMap |
| 1464 | // If a valid entry exists returns pointer to cmnDB else returns nil. |
| 1465 | func (oo *OpenONUAC) FetchEntryFromMibDatabaseMap(ctx context.Context, key string) (*devdb.OnuCmnMEDB, bool) { |
| 1466 | oo.mutexMibDatabaseMap.RLock() |
| 1467 | defer oo.mutexMibDatabaseMap.RUnlock() |
| 1468 | value, exists := oo.MibDatabaseMap[key] |
| 1469 | if !exists { |
| 1470 | return nil, false |
| 1471 | } |
| 1472 | return value, true |
| 1473 | |
| 1474 | } |
| 1475 | |
| 1476 | // ResetEntryFromMibDatabaseMap resets the ME values from the Maps. |
| 1477 | func (oo *OpenONUAC) ResetEntryFromMibDatabaseMap(ctx context.Context, key string) { |
| 1478 | oo.mutexMibDatabaseMap.RLock() |
| 1479 | onuCmnMEDB, exists := oo.MibDatabaseMap[key] |
| 1480 | oo.mutexMibDatabaseMap.RUnlock() |
| 1481 | if exists { |
| 1482 | // Lock the MeDbLock to ensure thread-safe operation |
| 1483 | onuCmnMEDB.MeDbLock.Lock() |
| 1484 | defer onuCmnMEDB.MeDbLock.Unlock() |
| 1485 | |
| 1486 | // Reset the MeDb and UnknownMeAndAttribDb maps |
| 1487 | onuCmnMEDB.MeDb = make(devdb.MeDbMap) |
| 1488 | onuCmnMEDB.UnknownMeAndAttribDb = make(devdb.UnknownMeAndAttribDbMap) |
| 1489 | |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | // DeleteEntryFromMibDatabaseMap deletes an entry from the MibDatabaseMap |
| 1494 | func (oo *OpenONUAC) DeleteEntryFromMibDatabaseMap(key string) { |
| 1495 | oo.mutexMibDatabaseMap.Lock() |
| 1496 | defer oo.mutexMibDatabaseMap.Unlock() |
| 1497 | delete(oo.MibDatabaseMap, key) |
| 1498 | } |