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