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