| 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 { |
| akashreddyk | e30dfa9 | 2025-11-26 10:51:57 +0530 | [diff] [blame] | 332 | err := handler.rebootDevice(log.WithSpanFromContext(context.Background(), ctx), true, device) //reboot request with device checking |
| 333 | if err != nil { |
| 334 | return nil, err |
| 335 | } |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 336 | return &empty.Empty{}, nil |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 337 | } else { |
| 338 | logger.Warnw(ctx, "no handler found for device-reboot", log.Fields{"device-id": device.Id}) |
| 339 | return nil, err |
| ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 340 | } |
| Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 343 | // DeleteDevice deletes the given device |
| 344 | func (oo *OpenONUAC) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 345 | nctx := log.WithSpanFromContext(context.Background(), ctx) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 346 | 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] | 347 | |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 348 | if handler, err := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
| 349 | // Acquire read lock to check if deletion is already in progress |
| 350 | handler.mutexDeletionInProgressFlag.RLock() |
| 351 | if handler.deletionInProgress { |
| 352 | // If deletion is already in progress, release the read lock and return |
| 353 | handler.mutexDeletionInProgressFlag.RUnlock() |
| 354 | errMsg := fmt.Sprintf("Device deletion is already in progress %s err: %s", device.Id, err) |
| 355 | logger.Info(ctx, errMsg) |
| 356 | return nil, status.Error(codes.FailedPrecondition, errMsg) |
| 357 | } |
| 358 | // Release read lock before setting the deletion flag |
| 359 | handler.mutexDeletionInProgressFlag.RUnlock() |
| Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 360 | handler.mutexDeletionInProgressFlag.Lock() |
| 361 | handler.deletionInProgress = true |
| 362 | handler.mutexDeletionInProgressFlag.Unlock() |
| 363 | |
| Girish Gowdra | abcceb1 | 2022-04-13 23:35:22 -0700 | [diff] [blame] | 364 | // 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] | 365 | if handler.pOnuMetricsMgr != nil { |
| 366 | handler.pOnuMetricsMgr.SetdeviceDeletionInProgress(true) |
| 367 | } |
| praneeth nalmas | f405e96 | 2023-08-07 15:02:03 +0530 | [diff] [blame] | 368 | |
| balaji.nagarajan | 80f6fb8 | 2026-01-13 16:48:05 +0530 | [diff] [blame^] | 369 | if handler.pOnuOmciDevice != nil { |
| 370 | if handler.pOnuOmciDevice.PDevOmciCC != nil { |
| 371 | // Since we cannot rule out that one of the handlers had initiated any OMCI configurations during its |
| 372 | // reset handling (even in future coding), request monitoring is canceled here one last time to |
| 373 | // be sure that all corresponding go routines are terminated |
| 374 | handler.pOnuOmciDevice.PDevOmciCC.CancelRequestMonitoring(ctx) |
| 375 | } |
| 376 | } |
| 377 | |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 378 | close(handler.deviceDeleteCommChan) |
| 379 | if resetErr := handler.resetFsms(ctx, true); resetErr != nil { |
| 380 | logger.Errorw(ctx, "failed to reset FSMs for the device", log.Fields{"device-id": device.Id, "err": resetErr}) |
| 381 | handler.mutexDeletionInProgressFlag.Lock() |
| 382 | handler.deletionInProgress = false |
| 383 | handler.mutexDeletionInProgressFlag.Unlock() |
| 384 | return nil, resetErr |
| Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 385 | } |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 386 | for _, uni := range handler.uniEntityMap { |
| 387 | if handler.GetFlowMonitoringIsRunning(uni.UniID) { |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 388 | select { |
| 389 | case handler.stopFlowMonitoringRoutine[uni.UniID] <- true: |
| 390 | logger.Debugw(ctx, "sent stop signal to self flow monitoring routine", log.Fields{"device-id": device.Id, "uni-id": uni.UniID}) |
| 391 | default: |
| 392 | |
| 393 | logger.Warnw(ctx, "stopFlowMonitoringRoutine channel already closed", log.Fields{"device-id": device.Id, "uni-id": uni.UniID}) |
| 394 | } |
| Girish Gowdra | e95687a | 2021-09-08 16:30:58 -0700 | [diff] [blame] | 395 | } |
| 396 | } |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 397 | //don't leave any garbage in kv-store |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 398 | if forceDeleteErr := oo.forceDeleteDeviceKvData(ctx, device.Id); forceDeleteErr != nil { |
| 399 | logger.Errorw(ctx, "failed to delete ONU data from KV store", log.Fields{"device-id": device.Id, "err": forceDeleteErr}) |
| 400 | return nil, forceDeleteErr |
| Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 401 | } |
| Holger Hildebrandt | e7cc609 | 2022-02-01 11:37:03 +0000 | [diff] [blame] | 402 | oo.deleteDeviceHandlerToMap(handler) |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 403 | handler.PrepareForGarbageCollection(ctx, handler.DeviceID) |
| Holger Hildebrandt | 6065220 | 2021-11-02 11:09:36 +0000 | [diff] [blame] | 404 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 405 | return &empty.Empty{}, nil |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 406 | } else { |
| 407 | errMsg := fmt.Sprintf("Device Handler not found -%s with error %s", device.Id, err) |
| 408 | logger.Error(ctx, errMsg) |
| 409 | return nil, status.Error(codes.NotFound, errMsg) |
| Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 410 | } |
| Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 413 | // UpdateFlowsIncrementally updates (add/remove) the flows on a given device |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 414 | func (oo *OpenONUAC) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ca.IncrementalFlows) (*empty.Empty, error) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 415 | 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] | 416 | |
| mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 417 | //flow config is relayed to handler even if the device might be in some 'inactive' state |
| 418 | // let the handler or related FSM's decide, what to do with the modified flow state info |
| 419 | // 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] | 420 | |
| 421 | // 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] | 422 | // but processing is continued for flowUpdate possibly also set in the request |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 423 | if incrFlows.Groups.ToAdd != nil && incrFlows.Groups.ToAdd.Items != nil { |
| 424 | 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] | 425 | } |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 426 | if incrFlows.Groups.ToRemove != nil && incrFlows.Groups.ToRemove.Items != nil { |
| 427 | 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] | 428 | } |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 429 | if incrFlows.Groups.ToUpdate != nil && incrFlows.Groups.ToUpdate.Items != nil { |
| 430 | 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] | 431 | } |
| 432 | |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 433 | if handler, err := oo.getDeviceHandler(ctx, incrFlows.Device.Id, false); handler != nil { |
| balaji.nagarajan | 62ac62b | 2025-09-08 10:49:58 +0530 | [diff] [blame] | 434 | if flowUpdateErr := handler.FlowUpdateIncremental(ctx, incrFlows.Flows, incrFlows.Groups, incrFlows.FlowMetadata); flowUpdateErr != nil { |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 435 | return nil, flowUpdateErr |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 436 | } |
| 437 | return &empty.Empty{}, nil |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 438 | } else { |
| 439 | logger.Warnw(ctx, "no handler found for incremental flow update", log.Fields{"device-id": incrFlows.Device.Id}) |
| 440 | return nil, err |
| mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 441 | } |
| Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 444 | // UpdatePmConfig returns PmConfigs nil or error |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 445 | func (oo *OpenONUAC) UpdatePmConfig(ctx context.Context, configs *ca.PmConfigsInfo) (*empty.Empty, error) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 446 | logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": configs.DeviceId}) |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 447 | if handler, err := oo.getDeviceHandler(ctx, configs.DeviceId, false); handler != nil { |
| 448 | if pmConfigErr := handler.updatePmConfig(log.WithSpanFromContext(context.Background(), ctx), configs.PmConfigs); pmConfigErr != nil { |
| 449 | return nil, pmConfigErr |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 450 | } |
| 451 | return &empty.Empty{}, nil |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 452 | } else { |
| 453 | logger.Warnw(ctx, "no handler found for update-pm-config", log.Fields{"device-id": configs.DeviceId}) |
| 454 | return nil, err |
| Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 455 | } |
| Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 456 | } |
| 457 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 458 | // DownloadImage requests downloading some image according to indications as given in request |
| 459 | // The ImageDownload needs to be called `request`due to library reflection requirements |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 460 | func (oo *OpenONUAC) DownloadImage(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 461 | ctx = log.WithSpanFromContext(context.Background(), ctx) |
| 462 | if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" { |
| Holger Hildebrandt | 52f271b | 2022-06-02 09:32:27 +0000 | [diff] [blame] | 463 | if strings.Contains(imageInfo.Image.Url, "https:") { |
| 464 | return nil, errors.New("image download via https not supported") |
| 465 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 466 | if !oo.pDownloadManager.ImageExists(ctx, imageInfo.Image) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 467 | logger.Debugw(ctx, "start image download", log.Fields{"image-description": imageInfo.Image}) |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 468 | // Download_image is not supposed to be blocking, anyway let's call the DownloadManager still synchronously to detect 'fast' problems |
| 469 | // the download itself is later done in background |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 470 | if err := oo.pDownloadManager.StartDownload(ctx, imageInfo.Image); err != nil { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 471 | return nil, err |
| 472 | } |
| 473 | return imageInfo.Image, nil |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 474 | } |
| 475 | // image already exists |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 476 | logger.Debugw(ctx, "image already downloaded", log.Fields{"image-description": imageInfo.Image}) |
| 477 | return imageInfo.Image, nil |
| mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 478 | } |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 479 | |
| 480 | return nil, errors.New("invalid image definition") |
| Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 481 | } |
| 482 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 483 | // ActivateImageUpdate requests downloading some Onu Software image to the ONU via OMCI |
| 484 | // |
| 485 | // according to indications as given in request and on success activate the image on the ONU |
| 486 | // |
| 487 | // The ImageDownload needs to be called `request`due to library reflection requirements |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 488 | func (oo *OpenONUAC) ActivateImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 489 | if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" { |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 490 | if oo.pDownloadManager.ImageLocallyDownloaded(ctx, imageInfo.Image) { |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 491 | if handler, err := oo.getDeviceHandler(ctx, imageInfo.Device.Id, false); handler != nil { |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 492 | logger.Debugw(ctx, "image download on omci requested", log.Fields{ |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 493 | "image-description": imageInfo.Image, "device-id": imageInfo.Device.Id}) |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 494 | if swUpgradeErr := handler.doOnuSwUpgrade(ctx, imageInfo.Image, oo.pDownloadManager); swUpgradeErr != nil { |
| 495 | return nil, swUpgradeErr |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 496 | } |
| 497 | return imageInfo.Image, nil |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 498 | } else { |
| 499 | logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": imageInfo.Device.Id}) |
| 500 | return nil, err |
| mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 501 | } |
| mpagenko | 057889c | 2021-01-21 16:51:58 +0000 | [diff] [blame] | 502 | } |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 503 | 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] | 504 | 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] | 505 | } |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 506 | return nil, errors.New("invalid image definition") |
| Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 507 | } |
| 508 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 509 | // GetSingleValue handles the core request to retrieve uni status |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 510 | func (oo *OpenONUAC) GetSingleValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) { |
| kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 511 | logger.Infow(ctx, "Single_get_value_request", log.Fields{"request": request}) |
| 512 | |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 513 | if handler, err := oo.getDeviceHandler(ctx, request.TargetId, false); handler != nil { |
| kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 514 | switch reqType := request.GetRequest().GetRequest().(type) { |
| 515 | case *extension.GetValueRequest_UniInfo: |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 516 | return handler.GetUniPortStatus(ctx, reqType.UniInfo), nil |
| Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 517 | case *extension.GetValueRequest_OnuOpticalInfo: |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 518 | CommChan := make(chan cmn.Message) |
| Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 519 | respChan := make(chan extension.SingleGetValueResponse) |
| 520 | // Initiate the self test request |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 521 | if selfTestErr := handler.pSelfTestHdlr.SelfTestRequestStart(ctx, *request, CommChan, respChan); selfTestErr != nil { |
| Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 522 | return &extension.SingleGetValueResponse{ |
| 523 | Response: &extension.GetValueResponse{ |
| 524 | Status: extension.GetValueResponse_ERROR, |
| 525 | ErrReason: extension.GetValueResponse_INTERNAL_ERROR, |
| 526 | }, |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 527 | }, selfTestErr |
| Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 528 | } |
| 529 | // The timeout handling is already implemented in omci_self_test_handler module |
| 530 | resp := <-respChan |
| 531 | return &resp, nil |
| Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 532 | case *extension.GetValueRequest_OnuInfo: |
| 533 | return handler.getOnuOMCICounters(ctx, reqType.OnuInfo), nil |
| Holger Hildebrandt | 66af5ce | 2022-09-07 13:38:02 +0000 | [diff] [blame] | 534 | case *extension.GetValueRequest_OnuOmciStats: |
| 535 | return handler.getOnuOMCIStats(ctx) |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 536 | case *extension.GetValueRequest_OnuActiveAlarms: |
| 537 | resp := handler.getOnuActiveAlarms(ctx) |
| 538 | logger.Infow(ctx, "Received response for on demand active alarms request ", log.Fields{"response": resp}) |
| 539 | return resp, nil |
| Akash Reddy Kankanala | c28f0e2 | 2025-06-16 11:00:55 +0530 | [diff] [blame] | 540 | case *extension.GetValueRequest_OnuAllocGemStats: |
| 541 | resp := handler.getONUGEMStatsInfo(ctx) |
| pnalmas | 6d6b7d7 | 2025-10-23 16:34:22 +0530 | [diff] [blame] | 542 | logger.Infow(ctx, "Received response for on demand GEM counters ", log.Fields{"response": resp}) |
| Akash Reddy Kankanala | c28f0e2 | 2025-06-16 11:00:55 +0530 | [diff] [blame] | 543 | return resp, nil |
| pnalmas | 6d6b7d7 | 2025-10-23 16:34:22 +0530 | [diff] [blame] | 544 | case *extension.GetValueRequest_FecHistory: |
| 545 | return handler.getOnuFECStats(ctx), nil |
| 546 | |
| kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 547 | default: |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 548 | return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_UNSUPPORTED), nil |
| kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 549 | } |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 550 | } else { |
| 551 | logger.Errorw(ctx, "Single_get_value_request failed ", log.Fields{"request": request}) |
| 552 | return uniprt.PostUniStatusErrResponse(extension.GetValueResponse_INVALID_DEVICE_ID), err |
| kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 553 | } |
| mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 556 | //if update >= 4.3.0 |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 557 | // Note: already with the implementation of the 'old' download interface problems were detected when the argument name used here is not the same |
| 558 | // as defined in the adapter interface file. That sounds strange and the effects were strange as well. |
| 559 | // The reason for that was never finally investigated. |
| 560 | // 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] | 561 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 562 | // 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] | 563 | // |
| 564 | // 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] | 565 | func (oo *OpenONUAC) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) { |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 566 | if request != nil && len((*request).DeviceId) > 0 && (*request).Image.Version != "" { |
| Holger Hildebrandt | 52f271b | 2022-06-02 09:32:27 +0000 | [diff] [blame] | 567 | if strings.Contains((*request).Image.Url, "https:") { |
| 568 | return nil, errors.New("image download via https not supported") |
| 569 | } |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 570 | loResponse := voltha.DeviceImageResponse{} |
| 571 | imageIdentifier := (*request).Image.Version |
| mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 572 | downloadStartDone := false |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 573 | firstDevice := true |
| 574 | var vendorID string |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 575 | var onuVolthaDevice *voltha.Device |
| 576 | var devErr error |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 577 | for _, pCommonID := range (*request).DeviceId { |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 578 | vendorIDMatch := true |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 579 | loDeviceID := (*pCommonID).Id |
| mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 580 | loDeviceImageState := voltha.DeviceImageState{} |
| 581 | loDeviceImageState.DeviceId = loDeviceID |
| 582 | loImageState := voltha.ImageState{} |
| 583 | loDeviceImageState.ImageState = &loImageState |
| 584 | loDeviceImageState.ImageState.Version = (*request).Image.Version |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 585 | |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 586 | onuVolthaDevice = nil |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 587 | handler, err := oo.getDeviceHandler(ctx, loDeviceID, false) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 588 | if handler != nil { |
| 589 | onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID) |
| 590 | } else { |
| 591 | // 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] | 592 | devErr = err |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 593 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 594 | if devErr != nil || onuVolthaDevice == nil { |
| 595 | logger.Warnw(ctx, "Failed to fetch ONU device for image download", |
| 596 | log.Fields{"device-id": loDeviceID, "err": devErr}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 597 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
| 598 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //proto restriction, better option: 'INVALID_DEVICE' |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 599 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 600 | } else { |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 601 | if firstDevice { |
| 602 | //start/verify download of the image to the adapter based on first found device only |
| 603 | // use the OnuVendor identification from first given device |
| mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 604 | |
| 605 | // note: if the request was done for a list of devices on the Voltha interface, rwCore |
| 606 | // 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] | 607 | firstDevice = false |
| 608 | vendorID = onuVolthaDevice.VendorId |
| 609 | imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU |
| mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 610 | logger.Infow(ctx, "download request for file", |
| 611 | log.Fields{"device-id": loDeviceID, "image-id": imageIdentifier}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 612 | |
| mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 613 | // call the StartDownload synchronously to detect 'immediate' download problems |
| 614 | // the real download itself is later done in background |
| 615 | if fileState, err := oo.pFileManager.StartDownload(ctx, imageIdentifier, (*request).Image.Url); err == nil { |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 616 | // 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] | 617 | // valid URL, the current download request is not executed (current code delivers URL error). |
| 618 | // If the operators want to ensure that the new URL |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 619 | // is really used, then they first have to use the 'abort' API to remove the existing image! |
| 620 | // (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] | 621 | if fileState == swupg.CFileStateDlSucceeded || fileState == swupg.CFileStateDlStarted { |
| 622 | downloadStartDone = true |
| 623 | } //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] | 624 | } |
| 625 | } else { |
| 626 | //for all following devices verify the matching vendorID |
| 627 | if onuVolthaDevice.VendorId != vendorID { |
| 628 | logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored", |
| 629 | log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID}) |
| 630 | vendorIDMatch = false |
| 631 | } |
| 632 | } |
| mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 633 | if downloadStartDone && vendorIDMatch { |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 634 | // start the ONU download activity for each possible device |
| mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 635 | logger.Infow(ctx, "request image download to ONU on omci ", log.Fields{ |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 636 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 637 | //onu upgrade handling called in background without immediate error evaluation here |
| 638 | // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others |
| 639 | // state/progress/success of the request has to be verified using the Get_onu_image_status() API |
| 640 | go handler.onuSwUpgradeAfterDownload(ctx, request, oo.pFileManager, imageIdentifier) |
| 641 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_STARTED |
| 642 | loDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR |
| 643 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 644 | } else { |
| 645 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
| mpagenko | c497ee3 | 2021-11-10 17:30:20 +0000 | [diff] [blame] | 646 | if !downloadStartDone { |
| 647 | //based on above fileState more descriptive error codes would be possible, e.g |
| 648 | // IMAGE_EXISTS_WITH_DIFFERENT_URL - would require proto buf update |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 649 | loDeviceImageState.ImageState.Reason = voltha.ImageState_INVALID_URL |
| 650 | } else { //only logical option is !vendorIDMatch |
| 651 | loDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH |
| 652 | } |
| 653 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 654 | } |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 655 | } |
| mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 656 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 657 | } //for all requested devices |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 658 | pImageResp := &loResponse |
| 659 | return pImageResp, nil |
| 660 | } |
| 661 | return nil, errors.New("invalid image download parameters") |
| mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 662 | } |
| 663 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 664 | // GetOnuImageStatus delivers the adapter-related information about the download/activation/commitment |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 665 | // |
| 666 | // status for the requested image |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 667 | func (oo *OpenONUAC) GetOnuImageStatus(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 668 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 669 | loResponse := voltha.DeviceImageResponse{} |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 670 | imageIdentifier := (*in).Version |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 671 | var vendorIDSet bool |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 672 | firstDevice := true |
| 673 | var vendorID string |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 674 | var onuVolthaDevice *voltha.Device |
| 675 | var devErr error |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 676 | for _, pCommonID := range (*in).DeviceId { |
| 677 | loDeviceID := (*pCommonID).Id |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 678 | pDeviceImageState := &voltha.DeviceImageState{DeviceId: loDeviceID} |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 679 | vendorIDSet = false |
| 680 | onuVolthaDevice = nil |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 681 | handler, err := oo.getDeviceHandler(ctx, loDeviceID, false) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 682 | if handler != nil { |
| 683 | onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID) |
| 684 | } else { |
| 685 | // 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] | 686 | devErr = err |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 687 | } |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 688 | if devErr != nil || onuVolthaDevice == nil { |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 689 | logger.Warnw(ctx, "Failed to fetch Onu device to get image status", |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 690 | log.Fields{"device-id": loDeviceID, "err": devErr}) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 691 | pImageState := &voltha.ImageState{ |
| 692 | Version: (*in).Version, |
| 693 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //no statement about last activity possible |
| 694 | Reason: voltha.ImageState_UNKNOWN_ERROR, //something like "DEVICE_NOT_EXISTS" would be better (proto def) |
| 695 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 696 | } |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 697 | pDeviceImageState.ImageState = pImageState |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 698 | } else { |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 699 | if firstDevice { |
| 700 | //start/verify download of the image to the adapter based on first found device only |
| 701 | // use the OnuVendor identification from first given device |
| 702 | firstDevice = false |
| 703 | vendorID = onuVolthaDevice.VendorId |
| 704 | imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU |
| 705 | vendorIDSet = true |
| Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 706 | 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] | 707 | } else { |
| 708 | //for all following devices verify the matching vendorID |
| 709 | if onuVolthaDevice.VendorId != vendorID { |
| 710 | 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] | 711 | 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] | 712 | } else { |
| 713 | vendorIDSet = true |
| 714 | } |
| 715 | } |
| 716 | if !vendorIDSet { |
| 717 | pImageState := &voltha.ImageState{ |
| 718 | Version: (*in).Version, |
| 719 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //can't be sure that download for this device was really tried |
| 720 | Reason: voltha.ImageState_VENDOR_DEVICE_MISMATCH, |
| 721 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 722 | } |
| 723 | pDeviceImageState.ImageState = pImageState |
| 724 | } else { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 725 | logger.Debugw(ctx, "image status request for", log.Fields{ |
| 726 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 727 | //status request is called synchronously to collect the indications for all concerned devices |
| 728 | pDeviceImageState.ImageState = handler.requestOnuSwUpgradeState(ctx, imageIdentifier, (*in).Version) |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 729 | } |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 730 | } |
| 731 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 732 | } //for all requested devices |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 733 | pImageResp := &loResponse |
| 734 | return pImageResp, nil |
| 735 | } |
| 736 | return nil, errors.New("invalid image status request parameters") |
| mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 739 | // AbortOnuImageUpgrade stops the actual download/activation/commitment process (on next possibly step) |
| 740 | func (oo *OpenONUAC) AbortOnuImageUpgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 741 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 742 | loResponse := voltha.DeviceImageResponse{} |
| 743 | imageIdentifier := (*in).Version |
| 744 | firstDevice := true |
| 745 | var vendorID string |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 746 | var vendorIDSet bool |
| 747 | var onuVolthaDevice *voltha.Device |
| 748 | var devErr error |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 749 | for _, pCommonID := range (*in).DeviceId { |
| 750 | loDeviceID := (*pCommonID).Id |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 751 | pDeviceImageState := &voltha.DeviceImageState{} |
| 752 | loImageState := voltha.ImageState{} |
| 753 | pDeviceImageState.ImageState = &loImageState |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 754 | vendorIDSet = false |
| 755 | onuVolthaDevice = nil |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 756 | handler, err := oo.getDeviceHandler(ctx, loDeviceID, false) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 757 | if handler != nil { |
| 758 | onuVolthaDevice, devErr = handler.getDeviceFromCore(ctx, loDeviceID) |
| 759 | } else { |
| 760 | // 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] | 761 | devErr = err |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 762 | } |
| 763 | if devErr != nil || onuVolthaDevice == nil { |
| 764 | logger.Warnw(ctx, "Failed to fetch Onu device to abort its download", |
| 765 | log.Fields{"device-id": loDeviceID, "err": devErr}) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 766 | pDeviceImageState.DeviceId = loDeviceID |
| 767 | pDeviceImageState.ImageState.Version = (*in).Version |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 768 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 769 | 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] | 770 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 771 | } else { |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 772 | if firstDevice { |
| 773 | //start/verify download of the image to the adapter based on first found device only |
| 774 | // use the OnuVendor identification from first given device |
| 775 | firstDevice = false |
| 776 | vendorID = onuVolthaDevice.VendorId |
| 777 | vendorIDSet = true |
| 778 | imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU |
| Holger Hildebrandt | abfef03 | 2022-02-25 12:40:20 +0000 | [diff] [blame] | 779 | 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] | 780 | } else { |
| 781 | //for all following devices verify the matching vendorID |
| 782 | if onuVolthaDevice.VendorId != vendorID { |
| 783 | 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] | 784 | 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] | 785 | pDeviceImageState.DeviceId = loDeviceID |
| 786 | pDeviceImageState.ImageState.Version = (*in).Version |
| 787 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 788 | pDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH |
| 789 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 790 | } else { |
| 791 | vendorIDSet = true |
| 792 | } |
| 793 | } |
| 794 | if vendorIDSet { |
| 795 | // cancel the ONU upgrade activity for each possible device |
| 796 | logger.Debugw(ctx, "image upgrade abort requested", log.Fields{ |
| 797 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 798 | //upgrade cancel is called synchronously to collect the imageResponse indications for all concerned devices |
| 799 | handler.cancelOnuSwUpgrade(ctx, imageIdentifier, (*in).Version, pDeviceImageState) |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 800 | } |
| 801 | } |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 802 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState) |
| mpagenko | 59862f0 | 2021-10-11 08:53:18 +0000 | [diff] [blame] | 803 | } //for all requested devices |
| mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 804 | if !firstDevice { |
| 805 | //if at least one valid device was found cancel also a possibly running download to adapter and remove the image |
| 806 | // this is to be done after the upgradeOnu cancel activities in order to not subduct the file for still running processes |
| 807 | oo.pFileManager.CancelDownload(ctx, imageIdentifier) |
| 808 | } |
| 809 | pImageResp := &loResponse |
| 810 | return pImageResp, nil |
| 811 | } |
| 812 | return nil, errors.New("invalid image upgrade abort parameters") |
| 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 | // GetOnuImages retrieves the ONU SW image status information via OMCI |
| 816 | func (oo *OpenONUAC) GetOnuImages(ctx context.Context, id *common.ID) (*voltha.OnuImages, error) { |
| 817 | logger.Infow(ctx, "Get_onu_images", log.Fields{"device-id": id.Id}) |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 818 | if handler, err := oo.getDeviceHandler(ctx, id.Id, false); handler != nil { |
| 819 | images, getImagesErr := handler.getOnuImages(ctx) |
| 820 | if getImagesErr == nil { |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 821 | return images, nil |
| 822 | } |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 823 | return nil, fmt.Errorf("%s-%s", getImagesErr, id.Id) |
| 824 | } else { |
| 825 | logger.Warnw(ctx, "no handler found for Get_onu_images", log.Fields{"device-id": id.Id}) |
| 826 | return nil, err |
| Holger Hildebrandt | fb402a6 | 2021-05-26 14:40:49 +0000 | [diff] [blame] | 827 | } |
| mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 828 | } |
| 829 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 830 | // ActivateOnuImage initiates the activation of the image for the requested ONU(s) |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 831 | // |
| 832 | // 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] | 833 | func (oo *OpenONUAC) ActivateOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 834 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 835 | loResponse := voltha.DeviceImageResponse{} |
| 836 | imageIdentifier := (*in).Version |
| 837 | //let the deviceHandler find the adequate way of requesting the image activation |
| 838 | for _, pCommonID := range (*in).DeviceId { |
| 839 | loDeviceID := (*pCommonID).Id |
| mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 840 | loDeviceImageState := voltha.DeviceImageState{} |
| 841 | loDeviceImageState.DeviceId = loDeviceID |
| 842 | loImageState := voltha.ImageState{} |
| 843 | loDeviceImageState.ImageState = &loImageState |
| 844 | loDeviceImageState.ImageState.Version = imageIdentifier |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 845 | //compared to download procedure the vendorID (from device) is secondary here |
| 846 | // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed) |
| 847 | // start image activation activity for each possible device |
| 848 | // 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] | 849 | if handler, _ := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil { |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 850 | logger.Debugw(ctx, "onu image activation requested", log.Fields{ |
| 851 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 852 | //onu activation handling called in background without immediate error evaluation here |
| 853 | // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others |
| 854 | // 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] | 855 | if pImageStates, err := handler.onuSwActivateRequest(ctx, imageIdentifier, (*in).CommitOnSuccess); err != nil { |
| 856 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| 857 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR |
| 858 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED |
| 859 | } else { |
| 860 | loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState |
| 861 | loDeviceImageState.ImageState.Reason = pImageStates.Reason |
| 862 | loDeviceImageState.ImageState.ImageState = pImageStates.ImageState |
| 863 | } |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 864 | } else { |
| 865 | //cannot start SW activation for requested device |
| 866 | 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] | 867 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 868 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR |
| 869 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_ACTIVATION_ABORTED |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 870 | } |
| mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 871 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 872 | } |
| 873 | pImageResp := &loResponse |
| 874 | return pImageResp, nil |
| 875 | } |
| 876 | return nil, errors.New("invalid image activation parameters") |
| mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 877 | } |
| 878 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 879 | // CommitOnuImage enforces the commitment of the image for the requested ONU(s) |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 880 | // |
| 881 | // precondition: image activated and not yet committed |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 882 | func (oo *OpenONUAC) CommitOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 883 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 884 | loResponse := voltha.DeviceImageResponse{} |
| 885 | imageIdentifier := (*in).Version |
| 886 | //let the deviceHandler find the adequate way of requesting the image activation |
| 887 | for _, pCommonID := range (*in).DeviceId { |
| 888 | loDeviceID := (*pCommonID).Id |
| mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 889 | loDeviceImageState := voltha.DeviceImageState{} |
| 890 | loDeviceImageState.DeviceId = loDeviceID |
| 891 | loImageState := voltha.ImageState{} |
| 892 | loDeviceImageState.ImageState = &loImageState |
| 893 | loDeviceImageState.ImageState.Version = imageIdentifier |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 894 | //compared to download procedure the vendorID (from device) is secondary here |
| 895 | // and only needed in case the upgrade process is based on some ongoing download process (and can be retrieved in deviceHandler if needed) |
| 896 | // start image activation activity for each possible device |
| 897 | // 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] | 898 | if handler, _ := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil { |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 899 | logger.Debugw(ctx, "onu image commitment requested", log.Fields{ |
| 900 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 901 | //onu commitment handling called in background without immediate error evaluation here |
| 902 | // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others |
| 903 | // 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] | 904 | if pImageStates, err := handler.onuSwCommitRequest(ctx, imageIdentifier); err != nil { |
| mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 905 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
| 906 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //can be multiple reasons here |
| mpagenko | 183647c | 2021-06-08 15:25:04 +0000 | [diff] [blame] | 907 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED |
| 908 | } else { |
| 909 | loDeviceImageState.ImageState.DownloadState = pImageStates.DownloadState |
| 910 | loDeviceImageState.ImageState.Reason = pImageStates.Reason |
| 911 | loDeviceImageState.ImageState.ImageState = pImageStates.ImageState |
| 912 | } |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 913 | } else { |
| 914 | //cannot start SW commitment for requested device |
| 915 | 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] | 916 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_UNKNOWN |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 917 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR |
| 918 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_COMMIT_ABORTED |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 919 | } |
| mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 920 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState) |
| mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 921 | } |
| 922 | pImageResp := &loResponse |
| 923 | return pImageResp, nil |
| 924 | } |
| 925 | return nil, errors.New("invalid image commitment parameters") |
| mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 926 | } |
| 927 | |
| Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 928 | // Adapter interface required methods ################ end ######### |
| 929 | // ################################################################# |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 930 | |
| 931 | /* |
| 932 | * |
| 933 | * ONU inter adapter service |
| 934 | * |
| 935 | */ |
| 936 | |
| 937 | // OnuIndication is part of the ONU Inter-adapter service API. |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 938 | func (oo *OpenONUAC) OnuIndication(ctx context.Context, onuInd *ia.OnuIndicationMessage) (*empty.Empty, error) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 939 | logger.Debugw(ctx, "onu-indication", log.Fields{"onu-indication": onuInd}) |
| 940 | |
| 941 | if onuInd == nil || onuInd.OnuIndication == nil { |
| 942 | return nil, fmt.Errorf("invalid-onu-indication-%v", onuInd) |
| 943 | } |
| 944 | |
| 945 | onuIndication := onuInd.OnuIndication |
| 946 | onuOperstate := onuIndication.GetOperState() |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 947 | //nolint:staticcheck |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 948 | waitForDhInstPresent := false |
| 949 | if onuOperstate == "up" { |
| 950 | //Race condition (relevant in BBSIM-environment only): Due to unsynchronized processing of olt-adapter and rw_core, |
| 951 | //ONU_IND_REQUEST msg by olt-adapter could arrive a little bit earlier than rw_core was able to announce the corresponding |
| 952 | //ONU by RPC of Adopt_device(). Therefore it could be necessary to wait with processing of ONU_IND_REQUEST until call of |
| 953 | //Adopt_device() arrived and DeviceHandler instance was created |
| 954 | waitForDhInstPresent = true |
| 955 | } |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 956 | if handler, _ := oo.getDeviceHandler(ctx, onuInd.DeviceId, waitForDhInstPresent); handler != nil { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 957 | logger.Infow(ctx, "onu-ind-request", log.Fields{"device-id": onuInd.DeviceId, |
| 958 | "OnuId": onuIndication.GetOnuId(), |
| 959 | "AdminState": onuIndication.GetAdminState(), "OperState": onuOperstate, |
| 960 | "SNR": onuIndication.GetSerialNumber()}) |
| 961 | |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 962 | switch onuOperstate { |
| 963 | case "up": |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 964 | if err := handler.createInterface(ctx, onuIndication); err != nil { |
| 965 | return nil, err |
| 966 | } |
| 967 | return &empty.Empty{}, nil |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 968 | case "down", "unreachable": |
| Holger Hildebrandt | 68854a8 | 2022-09-05 07:00:21 +0000 | [diff] [blame] | 969 | if err := handler.UpdateInterface(ctx); err != nil { |
| ozgecanetsia | 76db57a | 2022-02-03 15:32:03 +0300 | [diff] [blame] | 970 | return nil, err |
| 971 | } |
| 972 | return &empty.Empty{}, nil |
| mgouda | d611f4c | 2025-10-30 14:49:27 +0530 | [diff] [blame] | 973 | default: |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 974 | logger.Errorw(ctx, "unknown-onu-ind-request operState", log.Fields{"OnuId": onuIndication.GetOnuId()}) |
| 975 | return nil, fmt.Errorf("invalidOperState: %s, %s", onuOperstate, onuInd.DeviceId) |
| 976 | } |
| 977 | } |
| 978 | logger.Warnw(ctx, "no handler found for received onu-ind-request", log.Fields{ |
| 979 | "msgToDeviceId": onuInd.DeviceId}) |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 980 | return nil, fmt.Errorf("handler-not-found-%s", onuInd.DeviceId) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | // OmciIndication is part of the ONU Inter-adapter service API. |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 984 | func (oo *OpenONUAC) OmciIndication(ctx context.Context, msg *ia.OmciMessage) (*empty.Empty, error) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 985 | logger.Debugw(ctx, "omci-response", log.Fields{"parent-device-id": msg.ParentDeviceId, "child-device-id": msg.ChildDeviceId}) |
| 986 | |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 987 | if handler, err := oo.getDeviceHandler(ctx, msg.ChildDeviceId, false); handler != nil { |
| 988 | if omciIndErr := handler.handleOMCIIndication(log.WithSpanFromContext(context.Background(), ctx), msg); omciIndErr != nil { |
| 989 | return nil, omciIndErr |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 990 | } |
| 991 | return &empty.Empty{}, nil |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 992 | } else { |
| 993 | return nil, err |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 994 | } |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | // DownloadTechProfile is part of the ONU Inter-adapter service API. |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 998 | 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] | 999 | 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] | 1000 | |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 1001 | if handler, err := oo.getDeviceHandler(ctx, tProfile.DeviceId, false); handler != nil { |
| Praneeth Nalmas | 04600be | 2024-12-08 20:12:32 +0530 | [diff] [blame] | 1002 | handler.RLockMutexDeletionInProgressFlag() |
| 1003 | if handler.GetDeletionInProgress() { |
| 1004 | logger.Warnw(ctx, "Device deletion in progress - avoid processing Tech Profile", log.Fields{"device-id": tProfile.DeviceId}) |
| 1005 | |
| 1006 | handler.RUnlockMutexDeletionInProgressFlag() |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 1007 | 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] | 1008 | } |
| 1009 | handler.RUnlockMutexDeletionInProgressFlag() |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 1010 | if tpDownloadErr := handler.handleTechProfileDownloadRequest(log.WithSpanFromContext(context.Background(), ctx), tProfile); tpDownloadErr != nil { |
| 1011 | return nil, tpDownloadErr |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1012 | } |
| 1013 | return &empty.Empty{}, nil |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 1014 | } else { |
| 1015 | return nil, err |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1016 | } |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | // DeleteGemPort is part of the ONU Inter-adapter service API. |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1020 | func (oo *OpenONUAC) DeleteGemPort(ctx context.Context, gPort *ia.DeleteGemPortMessage) (*empty.Empty, error) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1021 | 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] | 1022 | if handler, _ := oo.getDeviceHandler(ctx, gPort.DeviceId, false); handler != nil { |
| nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 1023 | if handler.GetDeletionInProgress() { |
| 1024 | logger.Error(ctx, "device deletion in progres", log.Fields{"device-id": gPort.DeviceId}) |
| 1025 | return nil, fmt.Errorf("device deletion in progress for device-id: %s", gPort.DeviceId) |
| 1026 | } |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1027 | if err := handler.handleDeleteGemPortRequest(log.WithSpanFromContext(context.Background(), ctx), gPort); err != nil { |
| 1028 | return nil, err |
| 1029 | } |
| Holger Hildebrandt | 5b77406 | 2021-11-10 10:24:29 +0000 | [diff] [blame] | 1030 | } else { |
| 1031 | logger.Debugw(ctx, "deviceHandler not found", log.Fields{"device-id": gPort.DeviceId}) |
| 1032 | // 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] | 1033 | } |
| Holger Hildebrandt | 5b77406 | 2021-11-10 10:24:29 +0000 | [diff] [blame] | 1034 | return &empty.Empty{}, nil |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | // DeleteTCont is part of the ONU Inter-adapter service API. |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1038 | 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] | 1039 | logger.Debugw(ctx, "delete-tcont", log.Fields{"device-id": tConf.DeviceId, "tconf": tConf}) |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 1040 | if handler, _ := oo.getDeviceHandler(ctx, tConf.DeviceId, false); handler != nil { |
| nikesh.krishnan | 1249be9 | 2023-11-27 04:20:12 +0530 | [diff] [blame] | 1041 | if handler.GetDeletionInProgress() { |
| 1042 | logger.Error(ctx, "device deletion in progres", log.Fields{"device-id": tConf.DeviceId}) |
| 1043 | return nil, fmt.Errorf("device deletion in progress for device-id: %s", tConf.DeviceId) |
| 1044 | } |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1045 | if err := handler.handleDeleteTcontRequest(log.WithSpanFromContext(context.Background(), ctx), tConf); err != nil { |
| 1046 | return nil, err |
| 1047 | } |
| Holger Hildebrandt | 5b77406 | 2021-11-10 10:24:29 +0000 | [diff] [blame] | 1048 | } else { |
| 1049 | logger.Debugw(ctx, "deviceHandler not found", log.Fields{"device-id": tConf.DeviceId}) |
| 1050 | // 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] | 1051 | } |
| Holger Hildebrandt | 5b77406 | 2021-11-10 10:24:29 +0000 | [diff] [blame] | 1052 | return &empty.Empty{}, nil |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | /* |
| 1056 | * Parent GRPC clients |
| 1057 | */ |
| 1058 | |
| khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1059 | func getHash(endpoint, contextInfo string) string { |
| 1060 | strToHash := endpoint + contextInfo |
| 1061 | h := fnv.New128().Sum([]byte(strToHash)) |
| 1062 | return string(h) |
| 1063 | } |
| 1064 | |
| Akash Reddy Kankanala | 92dfdf8 | 2025-03-23 22:07:09 +0530 | [diff] [blame] | 1065 | // nolint:unparam |
| khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1066 | func (oo *OpenONUAC) updateReachabilityFromRemote(ctx context.Context, remote *common.Connection) { |
| 1067 | logger.Debugw(context.Background(), "updating-remote-connection-status", log.Fields{"remote": remote}) |
| 1068 | oo.lockReachableFromRemote.Lock() |
| 1069 | defer oo.lockReachableFromRemote.Unlock() |
| 1070 | endpointHash := getHash(remote.Endpoint, remote.ContextInfo) |
| 1071 | if _, ok := oo.reachableFromRemote[endpointHash]; ok { |
| 1072 | oo.reachableFromRemote[endpointHash].lastKeepAlive = time.Now() |
| 1073 | oo.reachableFromRemote[endpointHash].keepAliveInterval = remote.KeepAliveInterval |
| 1074 | return |
| 1075 | } |
| 1076 | logger.Debugw(context.Background(), "initial-remote-connection", log.Fields{"remote": remote}) |
| 1077 | oo.reachableFromRemote[endpointHash] = &reachabilityFromRemote{lastKeepAlive: time.Now(), keepAliveInterval: remote.KeepAliveInterval} |
| 1078 | } |
| 1079 | |
| Akash Soni | 931f9b9 | 2024-12-11 18:36:36 +0530 | [diff] [blame] | 1080 | // func (oo *OpenONUAC) isReachableFromRemote(ctx context.Context, endpoint string, contextInfo string) bool { |
| 1081 | // logger.Debugw(ctx, "checking-remote-reachability", log.Fields{"endpoint": endpoint, "context": contextInfo}) |
| 1082 | // oo.lockReachableFromRemote.RLock() |
| 1083 | // defer oo.lockReachableFromRemote.RUnlock() |
| 1084 | // endpointHash := getHash(endpoint, contextInfo) |
| 1085 | // if _, ok := oo.reachableFromRemote[endpointHash]; ok { |
| 1086 | // logger.Debugw(ctx, "endpoint-exists", log.Fields{"last-keep-alive": time.Since(oo.reachableFromRemote[endpointHash].lastKeepAlive)}) |
| 1087 | // // Assume the connection is down if we did not receive 2 keep alives in succession |
| 1088 | // maxKeepAliveWait := time.Duration(oo.reachableFromRemote[endpointHash].keepAliveInterval * 2) |
| 1089 | // return time.Since(oo.reachableFromRemote[endpointHash].lastKeepAlive) <= maxKeepAliveWait |
| 1090 | // } |
| 1091 | // return false |
| 1092 | // } |
| khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1093 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1094 | // stopAllGrpcClients stops all grpc clients in use |
| khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 1095 | func (oo *OpenONUAC) stopAllGrpcClients(ctx context.Context) { |
| 1096 | // Stop the clients that connect to the parent |
| 1097 | oo.lockParentAdapterClients.Lock() |
| 1098 | for key := range oo.parentAdapterClients { |
| 1099 | oo.parentAdapterClients[key].Stop(ctx) |
| 1100 | delete(oo.parentAdapterClients, key) |
| 1101 | } |
| 1102 | oo.lockParentAdapterClients.Unlock() |
| 1103 | |
| 1104 | // Stop core client connection |
| 1105 | oo.coreClient.Stop(ctx) |
| 1106 | } |
| 1107 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1108 | func (oo *OpenONUAC) setupParentInterAdapterClient(ctx context.Context, endpoint string) error { |
| 1109 | logger.Infow(ctx, "setting-parent-adapter-connection", log.Fields{"parent-endpoint": endpoint}) |
| 1110 | oo.lockParentAdapterClients.Lock() |
| 1111 | defer oo.lockParentAdapterClients.Unlock() |
| 1112 | if _, ok := oo.parentAdapterClients[endpoint]; ok { |
| 1113 | return nil |
| 1114 | } |
| 1115 | |
| khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1116 | childClient, err := vgrpc.NewClient( |
| 1117 | oo.config.AdapterEndpoint, |
| 1118 | endpoint, |
| khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 1119 | "olt_inter_adapter_service.OltInterAdapterService", |
| khenaidoo | 55cebc6 | 2021-12-08 14:44:41 -0500 | [diff] [blame] | 1120 | oo.oltAdapterRestarted) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1121 | |
| 1122 | if err != nil { |
| 1123 | return err |
| 1124 | } |
| nikesh.krishnan | ce4879a | 2023-08-01 18:36:57 +0530 | [diff] [blame] | 1125 | retryCodes := []codes.Code{ |
| 1126 | codes.Unavailable, // server is currently unavailable |
| 1127 | codes.DeadlineExceeded, // deadline for the operation was exceeded |
| 1128 | } |
| 1129 | backoffCtxOption := grpc_retry.WithBackoff(grpc_retry.BackoffLinearWithJitter(oo.config.PerRPCRetryTimeout, 0.2)) |
| 1130 | 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] | 1131 | |
| 1132 | oo.parentAdapterClients[endpoint] = childClient |
| nikesh.krishnan | ce4879a | 2023-08-01 18:36:57 +0530 | [diff] [blame] | 1133 | go oo.parentAdapterClients[endpoint].Start(log.WithSpanFromContext(context.TODO(), ctx), getOltInterAdapterServiceClientHandler, grpcRetryOptions) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1134 | // Wait until we have a connection to the child adapter. |
| 1135 | // Unlimited retries or until context expires |
| 1136 | subCtx := log.WithSpanFromContext(context.TODO(), ctx) |
| 1137 | backoff := vgrpc.NewBackoff(oo.config.MinBackoffRetryDelay, oo.config.MaxBackoffRetryDelay, 0) |
| 1138 | for { |
| 1139 | client, err := oo.parentAdapterClients[endpoint].GetOltInterAdapterServiceClient() |
| 1140 | if err == nil && client != nil { |
| 1141 | logger.Infow(subCtx, "connected-to-parent-adapter", log.Fields{"parent-endpoint": endpoint}) |
| 1142 | break |
| 1143 | } |
| 1144 | logger.Warnw(subCtx, "connection-to-parent-adapter-not-ready", log.Fields{"error": err, "parent-endpoint": endpoint}) |
| 1145 | // Backoff |
| 1146 | if err = backoff.Backoff(subCtx); err != nil { |
| 1147 | logger.Errorw(subCtx, "received-error-on-backoff", log.Fields{"error": err, "parent-endpoint": endpoint}) |
| 1148 | break |
| 1149 | } |
| 1150 | } |
| 1151 | return nil |
| 1152 | } |
| 1153 | |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1154 | func (oo *OpenONUAC) getParentAdapterServiceClient(endpoint string) (olt_inter_adapter_service.OltInterAdapterServiceClient, error) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1155 | // First check from cache |
| 1156 | oo.lockParentAdapterClients.RLock() |
| 1157 | if pgClient, ok := oo.parentAdapterClients[endpoint]; ok { |
| 1158 | oo.lockParentAdapterClients.RUnlock() |
| 1159 | return pgClient.GetOltInterAdapterServiceClient() |
| 1160 | } |
| 1161 | oo.lockParentAdapterClients.RUnlock() |
| 1162 | |
| 1163 | // Set the parent connection - can occur on restarts |
| 1164 | ctx, cancel := context.WithTimeout(context.Background(), oo.config.RPCTimeout) |
| 1165 | err := oo.setupParentInterAdapterClient(ctx, endpoint) |
| 1166 | cancel() |
| 1167 | if err != nil { |
| 1168 | return nil, err |
| 1169 | } |
| 1170 | |
| 1171 | // Get the parent client now |
| 1172 | oo.lockParentAdapterClients.RLock() |
| 1173 | defer oo.lockParentAdapterClients.RUnlock() |
| 1174 | if pgClient, ok := oo.parentAdapterClients[endpoint]; ok { |
| 1175 | return pgClient.GetOltInterAdapterServiceClient() |
| 1176 | } |
| 1177 | |
| 1178 | return nil, fmt.Errorf("no-client-for-endpoint-%s", endpoint) |
| 1179 | } |
| 1180 | |
| 1181 | // TODO: Any action the adapter needs to do following an olt adapter restart? |
| 1182 | func (oo *OpenONUAC) oltAdapterRestarted(ctx context.Context, endPoint string) error { |
| 1183 | logger.Errorw(ctx, "olt-adapter-restarted", log.Fields{"endpoint": endPoint}) |
| 1184 | return nil |
| 1185 | } |
| 1186 | |
| khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 1187 | // getOltInterAdapterServiceClientHandler is used to setup the remote gRPC service |
| 1188 | func getOltInterAdapterServiceClientHandler(ctx context.Context, conn *grpc.ClientConn) interface{} { |
| 1189 | if conn == nil { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1190 | return nil |
| 1191 | } |
| khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 1192 | return olt_inter_adapter_service.NewOltInterAdapterServiceClient(conn) |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1193 | } |
| 1194 | |
| Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 1195 | func (oo *OpenONUAC) forceDeleteDeviceKvData(ctx context.Context, aDeviceID string) error { |
| 1196 | 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] | 1197 | |
| Girish Gowdra | f10379e | 2022-02-02 21:49:44 -0800 | [diff] [blame] | 1198 | // delete onu persitent data |
| Girish Gowdra | e9ff261 | 2022-02-04 11:34:33 -0800 | [diff] [blame] | 1199 | onuBaseKvStorePath := fmt.Sprintf(cmn.CBasePathOnuKVStore, oo.cm.Backend.PathPrefix) |
| 1200 | logger.Debugw(ctx, "SetOnuKVStoreBackend", log.Fields{"IpTarget": oo.KVStoreAddress, "BasePathKvStore": onuBaseKvStorePath, |
| 1201 | "device-id": aDeviceID}) |
| 1202 | onuKvbackend := &db.Backend{ |
| 1203 | Client: oo.kvClient, |
| 1204 | StoreType: oo.KVStoreType, |
| 1205 | Address: oo.KVStoreAddress, |
| 1206 | Timeout: oo.KVStoreTimeout, |
| 1207 | PathPrefix: onuBaseKvStorePath, |
| 1208 | } |
| 1209 | err := onuKvbackend.DeleteWithPrefix(ctx, aDeviceID) |
| 1210 | if err != nil { |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 1211 | errMsg := fmt.Sprintf("unable to delete ONU persistent data at %s, error: %s", cmn.CBasePathOnuKVStore, err) |
| 1212 | logger.Error(ctx, errMsg) |
| 1213 | return status.Error(codes.Internal, errMsg) |
| Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 1214 | } |
| Girish Gowdra | f10379e | 2022-02-02 21:49:44 -0800 | [diff] [blame] | 1215 | // delete pm data |
| Girish Gowdra | e9ff261 | 2022-02-04 11:34:33 -0800 | [diff] [blame] | 1216 | pmBaseKvStorePath := fmt.Sprintf(pmmgr.CPmKvStorePrefixBase, oo.cm.Backend.PathPrefix) |
| 1217 | logger.Debugw(ctx, "SetPmKVStoreBackend", log.Fields{"IpTarget": oo.KVStoreAddress, "BasePathKvStore": pmBaseKvStorePath, |
| 1218 | "device-id": aDeviceID}) |
| Girish Gowdra | f10379e | 2022-02-02 21:49:44 -0800 | [diff] [blame] | 1219 | pmKvbackend := &db.Backend{ |
| 1220 | Client: oo.kvClient, |
| 1221 | StoreType: oo.KVStoreType, |
| 1222 | Address: oo.KVStoreAddress, |
| 1223 | Timeout: oo.KVStoreTimeout, |
| Girish Gowdra | e9ff261 | 2022-02-04 11:34:33 -0800 | [diff] [blame] | 1224 | PathPrefix: pmBaseKvStorePath, |
| Girish Gowdra | f10379e | 2022-02-02 21:49:44 -0800 | [diff] [blame] | 1225 | } |
| Girish Gowdra | e9ff261 | 2022-02-04 11:34:33 -0800 | [diff] [blame] | 1226 | err = pmKvbackend.DeleteWithPrefix(ctx, aDeviceID) |
| Girish Gowdra | f10379e | 2022-02-02 21:49:44 -0800 | [diff] [blame] | 1227 | if err != nil { |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 1228 | errMsg := fmt.Sprintf("unable to delete device PM data in KVstore at %s, error: %s", pmmgr.CPmKvStorePrefixBase, err) |
| 1229 | logger.Error(ctx, errMsg) |
| 1230 | return status.Error(codes.Internal, errMsg) |
| Girish Gowdra | f10379e | 2022-02-02 21:49:44 -0800 | [diff] [blame] | 1231 | } |
| Holger Hildebrandt | c69f074 | 2021-11-16 13:48:00 +0000 | [diff] [blame] | 1232 | return nil |
| 1233 | } |
| 1234 | |
| khenaidoo | f333355 | 2021-12-15 16:52:31 -0500 | [diff] [blame] | 1235 | // GetHealthStatus is used by the voltha core to open a streaming connection with the onu adapter. |
| 1236 | func (oo *OpenONUAC) GetHealthStatus(stream adapter_service.AdapterService_GetHealthStatusServer) error { |
| 1237 | ctx := context.Background() |
| 1238 | logger.Debugw(ctx, "receive-stream-connection", log.Fields{"stream": stream}) |
| 1239 | |
| 1240 | if stream == nil { |
| 1241 | return fmt.Errorf("conn-is-nil %v", stream) |
| 1242 | } |
| 1243 | initialRequestTime := time.Now() |
| 1244 | var remoteClient *common.Connection |
| 1245 | var tempClient *common.Connection |
| 1246 | var err error |
| 1247 | loop: |
| 1248 | for { |
| 1249 | tempClient, err = stream.Recv() |
| 1250 | if err != nil { |
| 1251 | logger.Warnw(ctx, "received-stream-error", log.Fields{"remote-client": remoteClient, "error": err}) |
| 1252 | break loop |
| 1253 | } |
| 1254 | // Send a response back |
| 1255 | err = stream.Send(&health.HealthStatus{State: health.HealthStatus_HEALTHY}) |
| 1256 | if err != nil { |
| 1257 | logger.Warnw(ctx, "sending-stream-error", log.Fields{"remote-client": remoteClient, "error": err}) |
| 1258 | break loop |
| 1259 | } |
| 1260 | remoteClient = tempClient |
| 1261 | |
| 1262 | logger.Debugw(ctx, "received-keep-alive", log.Fields{"remote-client": remoteClient}) |
| 1263 | |
| 1264 | select { |
| 1265 | case <-stream.Context().Done(): |
| 1266 | logger.Infow(ctx, "stream-keep-alive-context-done", log.Fields{"remote-client": remoteClient, "error": stream.Context().Err()}) |
| 1267 | break loop |
| 1268 | case <-oo.exitChannel: |
| 1269 | logger.Warnw(ctx, "received-stop", log.Fields{"remote-client": remoteClient, "initial-conn-time": initialRequestTime}) |
| 1270 | break loop |
| 1271 | default: |
| 1272 | } |
| 1273 | } |
| 1274 | logger.Errorw(ctx, "connection-down", log.Fields{"remote-client": remoteClient, "error": err, "initial-conn-time": initialRequestTime}) |
| 1275 | return err |
| 1276 | } |
| 1277 | |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1278 | /* |
| 1279 | * |
| 1280 | * Unimplemented APIs |
| 1281 | * |
| 1282 | */ |
| 1283 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1284 | // 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] | 1285 | // 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] | 1286 | func (oo *OpenONUAC) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1287 | return nil, errors.New("unImplemented") |
| 1288 | } |
| 1289 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1290 | // SimulateAlarm is unimplemented |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1291 | func (oo *OpenONUAC) SimulateAlarm(context.Context, *ca.SimulateAlarmMessage) (*common.OperationResp, error) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1292 | return nil, errors.New("unImplemented") |
| 1293 | } |
| 1294 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1295 | // SetExtValue is unimplemented |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1296 | func (oo *OpenONUAC) SetExtValue(context.Context, *ca.SetExtValueMessage) (*empty.Empty, error) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1297 | return nil, errors.New("unImplemented") |
| 1298 | } |
| 1299 | |
| Akash Soni | 3c176c6 | 2024-12-04 13:30:43 +0530 | [diff] [blame] | 1300 | // SetSingleValue sets a single value based on the given request and returns the response. |
| 1301 | func (oo *OpenONUAC) SetSingleValue(ctx context.Context, request *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) { |
| 1302 | logger.Infow(ctx, "single_set_value_request", log.Fields{"request": request}) |
| 1303 | |
| 1304 | errResp := func(status extension.SetValueResponse_Status, |
| 1305 | reason extension.SetValueResponse_ErrorReason) *extension.SingleSetValueResponse { |
| 1306 | return &extension.SingleSetValueResponse{ |
| 1307 | Response: &extension.SetValueResponse{ |
| 1308 | Status: status, |
| 1309 | ErrReason: reason, |
| 1310 | }, |
| 1311 | } |
| 1312 | } |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 1313 | if handler, err := oo.getDeviceHandler(ctx, request.TargetId, false); handler != nil { |
| Akash Soni | 3c176c6 | 2024-12-04 13:30:43 +0530 | [diff] [blame] | 1314 | switch reqType := request.GetRequest().GetRequest().(type) { |
| 1315 | case *extension.SetValueRequest_AppOffloadOnuConfig: |
| 1316 | return handler.setOnuOffloadStats(ctx, reqType.AppOffloadOnuConfig), nil |
| 1317 | default: |
| 1318 | return errResp(extension.SetValueResponse_ERROR, extension.SetValueResponse_UNSUPPORTED), nil |
| 1319 | } |
| mgouda | a797e1c | 2025-06-24 17:49:42 +0530 | [diff] [blame] | 1320 | } else { |
| 1321 | logger.Errorw(ctx, "Single_set_value_request failed ", log.Fields{"request": request}) |
| 1322 | return errResp(extension.SetValueResponse_ERROR, extension.SetValueResponse_INVALID_DEVICE_ID), err |
| Akash Soni | 3c176c6 | 2024-12-04 13:30:43 +0530 | [diff] [blame] | 1323 | } |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1324 | } |
| 1325 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1326 | // StartOmciTest not implemented |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1327 | func (oo *OpenONUAC) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1328 | return nil, errors.New("unImplemented") |
| 1329 | } |
| 1330 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1331 | // SuppressEvent unimplemented |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1332 | func (oo *OpenONUAC) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 1333 | return nil, errors.New("unImplemented") |
| 1334 | } |
| 1335 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1336 | // UnSuppressEvent unimplemented |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1337 | func (oo *OpenONUAC) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 1338 | return nil, errors.New("unImplemented") |
| 1339 | } |
| 1340 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1341 | // GetImageDownloadStatus is unimplemented |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1342 | func (oo *OpenONUAC) GetImageDownloadStatus(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1343 | return nil, errors.New("unImplemented") |
| 1344 | } |
| 1345 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1346 | // CancelImageDownload is unimplemented |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1347 | func (oo *OpenONUAC) CancelImageDownload(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1348 | return nil, errors.New("unImplemented") |
| 1349 | } |
| 1350 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1351 | // RevertImageUpdate is unimplemented |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1352 | func (oo *OpenONUAC) RevertImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1353 | return nil, errors.New("unImplemented") |
| 1354 | } |
| 1355 | |
| 1356 | // UpdateFlowsBulk is unimplemented |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1357 | func (oo *OpenONUAC) UpdateFlowsBulk(ctx context.Context, flows *ca.BulkFlows) (*empty.Empty, error) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1358 | return nil, errors.New("unImplemented") |
| 1359 | } |
| 1360 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1361 | // SelfTestDevice unimplented |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1362 | func (oo *OpenONUAC) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 1363 | return nil, errors.New("unImplemented") |
| 1364 | } |
| 1365 | |
| praneeth nalmas | 5a0a550 | 2022-12-23 15:57:00 +0530 | [diff] [blame] | 1366 | // SendPacketOut sends packet out to the device |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1367 | func (oo *OpenONUAC) SendPacketOut(ctx context.Context, packet *ca.PacketOut) (*empty.Empty, error) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1368 | return nil, errors.New("unImplemented") |
| 1369 | } |
| 1370 | |
| 1371 | // EnablePort to Enable PON/NNI interface - seems not to be used/required according to python code |
| 1372 | func (oo *OpenONUAC) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 1373 | return nil, errors.New("unImplemented") |
| 1374 | } |
| 1375 | |
| 1376 | // DisablePort to Disable pon/nni interface - seems not to be used/required according to python code |
| 1377 | func (oo *OpenONUAC) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 1378 | return nil, errors.New("unImplemented") |
| 1379 | } |
| 1380 | |
| 1381 | // GetExtValue - unimplemented |
| khenaidoo | 42dcdfd | 2021-10-19 17:34:12 -0400 | [diff] [blame] | 1382 | func (oo *OpenONUAC) GetExtValue(ctx context.Context, extInfo *ca.GetExtValueMessage) (*extension.ReturnValues, error) { |
| khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 1383 | return nil, errors.New("unImplemented") |
| 1384 | } |
| 1385 | |
| 1386 | // ChildDeviceLost - unimplemented |
| 1387 | func (oo *OpenONUAC) ChildDeviceLost(ctx context.Context, childDevice *voltha.Device) (*empty.Empty, error) { |
| 1388 | return nil, errors.New("unImplemented") |
| 1389 | } |
| Holger Hildebrandt | 4b5e73f | 2021-08-19 06:51:21 +0000 | [diff] [blame] | 1390 | |
| 1391 | // GetSupportedFsms - TODO: add comment |
| 1392 | func (oo *OpenONUAC) GetSupportedFsms() *cmn.OmciDeviceFsms { |
| 1393 | return oo.pSupportedFsms |
| 1394 | } |
| 1395 | |
| 1396 | // LockMutexMibTemplateGenerated - TODO: add comment |
| 1397 | func (oo *OpenONUAC) LockMutexMibTemplateGenerated() { |
| 1398 | oo.mutexMibTemplateGenerated.Lock() |
| 1399 | } |
| 1400 | |
| 1401 | // UnlockMutexMibTemplateGenerated - TODO: add comment |
| 1402 | func (oo *OpenONUAC) UnlockMutexMibTemplateGenerated() { |
| 1403 | oo.mutexMibTemplateGenerated.Unlock() |
| 1404 | } |
| 1405 | |
| 1406 | // GetMibTemplatesGenerated - TODO: add comment |
| 1407 | func (oo *OpenONUAC) GetMibTemplatesGenerated(mibTemplatePath string) (value bool, exist bool) { |
| 1408 | value, exist = oo.mibTemplatesGenerated[mibTemplatePath] |
| 1409 | return value, exist |
| 1410 | } |
| 1411 | |
| 1412 | // SetMibTemplatesGenerated - TODO: add comment |
| 1413 | func (oo *OpenONUAC) SetMibTemplatesGenerated(mibTemplatePath string, value bool) { |
| 1414 | oo.mibTemplatesGenerated[mibTemplatePath] = value |
| 1415 | } |
| 1416 | |
| 1417 | // RLockMutexDeviceHandlersMap - TODO: add comment |
| 1418 | func (oo *OpenONUAC) RLockMutexDeviceHandlersMap() { |
| 1419 | oo.mutexDeviceHandlersMap.RLock() |
| 1420 | } |
| 1421 | |
| 1422 | // RUnlockMutexDeviceHandlersMap - TODO: add comment |
| 1423 | func (oo *OpenONUAC) RUnlockMutexDeviceHandlersMap() { |
| 1424 | oo.mutexDeviceHandlersMap.RUnlock() |
| 1425 | } |
| 1426 | |
| 1427 | // GetDeviceHandler - TODO: add comment |
| 1428 | func (oo *OpenONUAC) GetDeviceHandler(deviceID string) (value cmn.IdeviceHandler, exist bool) { |
| 1429 | value, exist = oo.deviceHandlers[deviceID] |
| 1430 | return value, exist |
| 1431 | } |
| Praneeth Kumar Nalmas | 8f8f0c0 | 2024-10-22 19:29:09 +0530 | [diff] [blame] | 1432 | |
| 1433 | // GetONUMIBDBMap - Returns the Map corresponding to ONT type and the MIB common Instance. |
| 1434 | func (oo *OpenONUAC) GetONUMIBDBMap() devdb.OnuMCmnMEDBMap { |
| 1435 | return oo.MibDatabaseMap |
| 1436 | } |
| 1437 | |
| 1438 | // RLockMutexMIBDatabaseMap acquires a read lock on the mutex associated with the MIBDatabaseMap. |
| 1439 | func (oo *OpenONUAC) RLockMutexMIBDatabaseMap() { |
| 1440 | oo.mutexMibDatabaseMap.RLock() |
| 1441 | } |
| 1442 | |
| 1443 | // RUnlockMutexMIBDatabaseMap releases the read lock on the mutex associated with the MIBDatabaseMap. |
| 1444 | func (oo *OpenONUAC) RUnlockMutexMIBDatabaseMap() { |
| 1445 | oo.mutexMibDatabaseMap.RUnlock() |
| 1446 | } |
| 1447 | |
| 1448 | // LockMutexMIBDatabaseMap locks the mutex associated with the MIBDatabaseMap. |
| 1449 | // Should be called before any operations that modify or read from the MIBDatabaseMap. |
| 1450 | func (oo *OpenONUAC) LockMutexMIBDatabaseMap() { |
| 1451 | oo.mutexMibDatabaseMap.Lock() |
| 1452 | } |
| 1453 | |
| 1454 | // UnlockMutexMIBDatabaseMap unlocks the mutex associated with the MIBDatabaseMap. |
| 1455 | // Should be called after completing operations that require exclusive access |
| 1456 | // to the MIBDatabaseMap, ensuring the mutex is released for other goroutines. |
| 1457 | func (oo *OpenONUAC) UnlockMutexMIBDatabaseMap() { |
| 1458 | oo.mutexMibDatabaseMap.Unlock() |
| 1459 | } |
| 1460 | |
| 1461 | // CreateEntryAtMibDatabaseMap adds an entry to the MibDatabaseMap if it doesn't exist |
| 1462 | func (oo *OpenONUAC) CreateEntryAtMibDatabaseMap(ctx context.Context, key string) (*devdb.OnuCmnMEDB, error) { |
| 1463 | oo.mutexMibDatabaseMap.Lock() |
| 1464 | defer oo.mutexMibDatabaseMap.Unlock() |
| 1465 | |
| 1466 | // Check if the key already exists |
| 1467 | if mibEntry, exists := oo.MibDatabaseMap[key]; exists { |
| 1468 | logger.Warnw(ctx, "Entry already exists in MIB Database Map", log.Fields{"remote-client": key}) |
| 1469 | return mibEntry, fmt.Errorf("entry already exists for key: %s", key) |
| 1470 | } |
| 1471 | |
| 1472 | value := devdb.NewOnuCmnMEDB(ctx) |
| 1473 | |
| 1474 | logger.Infow(ctx, "Created a new Common MIB Database Entry", log.Fields{"remote-client": key}) |
| 1475 | oo.MibDatabaseMap[key] = value |
| 1476 | |
| 1477 | return value, nil |
| 1478 | } |
| 1479 | |
| 1480 | // FetchEntryFromMibDatabaseMap fetches a references to common ME DB for a MIB Template from the MibDatabaseMap |
| 1481 | // If a valid entry exists returns pointer to cmnDB else returns nil. |
| 1482 | func (oo *OpenONUAC) FetchEntryFromMibDatabaseMap(ctx context.Context, key string) (*devdb.OnuCmnMEDB, bool) { |
| 1483 | oo.mutexMibDatabaseMap.RLock() |
| 1484 | defer oo.mutexMibDatabaseMap.RUnlock() |
| 1485 | value, exists := oo.MibDatabaseMap[key] |
| 1486 | if !exists { |
| 1487 | return nil, false |
| 1488 | } |
| 1489 | return value, true |
| 1490 | |
| 1491 | } |
| 1492 | |
| 1493 | // ResetEntryFromMibDatabaseMap resets the ME values from the Maps. |
| 1494 | func (oo *OpenONUAC) ResetEntryFromMibDatabaseMap(ctx context.Context, key string) { |
| 1495 | oo.mutexMibDatabaseMap.RLock() |
| 1496 | onuCmnMEDB, exists := oo.MibDatabaseMap[key] |
| 1497 | oo.mutexMibDatabaseMap.RUnlock() |
| 1498 | if exists { |
| 1499 | // Lock the MeDbLock to ensure thread-safe operation |
| 1500 | onuCmnMEDB.MeDbLock.Lock() |
| 1501 | defer onuCmnMEDB.MeDbLock.Unlock() |
| 1502 | |
| 1503 | // Reset the MeDb and UnknownMeAndAttribDb maps |
| 1504 | onuCmnMEDB.MeDb = make(devdb.MeDbMap) |
| 1505 | onuCmnMEDB.UnknownMeAndAttribDb = make(devdb.UnknownMeAndAttribDbMap) |
| 1506 | |
| 1507 | } |
| 1508 | } |
| 1509 | |
| 1510 | // DeleteEntryFromMibDatabaseMap deletes an entry from the MibDatabaseMap |
| 1511 | func (oo *OpenONUAC) DeleteEntryFromMibDatabaseMap(key string) { |
| 1512 | oo.mutexMibDatabaseMap.Lock() |
| 1513 | defer oo.mutexMibDatabaseMap.Unlock() |
| 1514 | delete(oo.MibDatabaseMap, key) |
| 1515 | } |