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 | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 17 | //Package adaptercoreonu provides the utility for onu devices, flows and statistics |
| 18 | package adaptercoreonu |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "errors" |
| 23 | "fmt" |
| 24 | "sync" |
| 25 | "time" |
| 26 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 27 | vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc" |
| 28 | "github.com/opencord/voltha-protos/v5/go/adapter_services" |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 29 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 30 | conf "github.com/opencord/voltha-lib-go/v7/pkg/config" |
| 31 | "github.com/opencord/voltha-protos/v5/go/common" |
| 32 | "google.golang.org/grpc" |
| 33 | |
| 34 | "github.com/golang/protobuf/ptypes/empty" |
| 35 | "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
| 36 | "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif" |
| 37 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
| 38 | "github.com/opencord/voltha-protos/v5/go/extension" |
| 39 | ic "github.com/opencord/voltha-protos/v5/go/inter_container" |
| 40 | "github.com/opencord/voltha-protos/v5/go/voltha" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 41 | |
Matteo Scandolo | 761f751 | 2020-11-23 15:52:40 -0800 | [diff] [blame] | 42 | "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 43 | ) |
| 44 | |
| 45 | //OpenONUAC structure holds the ONU core information |
| 46 | type OpenONUAC struct { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 47 | deviceHandlers map[string]*deviceHandler |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 48 | deviceHandlersCreateChan map[string]chan bool //channels for deviceHandler create events |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 49 | lockDeviceHandlersMap sync.RWMutex |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 50 | coreClient *vgrpc.Client |
| 51 | parentAdapterClients map[string]*vgrpc.Client |
| 52 | lockParentAdapterClients sync.RWMutex |
Himani Chawla | c07fda0 | 2020-12-09 16:21:21 +0530 | [diff] [blame] | 53 | eventProxy eventif.EventProxy |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 54 | kvClient kvstore.Client |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 55 | cm *conf.ConfigManager |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 56 | config *config.AdapterFlags |
| 57 | numOnus int |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 58 | KVStoreAddress string |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 59 | KVStoreType string |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 60 | KVStoreTimeout time.Duration |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 61 | mibTemplatesGenerated map[string]bool |
| 62 | lockMibTemplateGenerated sync.RWMutex |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 63 | exitChannel chan int |
| 64 | HeartbeatCheckInterval time.Duration |
| 65 | HeartbeatFailReportInterval time.Duration |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 66 | AcceptIncrementalEvto bool |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 67 | //GrpcTimeoutInterval time.Duration |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 68 | pSupportedFsms *OmciDeviceFsms |
| 69 | maxTimeoutInterAdapterComm time.Duration |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 70 | maxTimeoutReconciling time.Duration |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 71 | pDownloadManager *adapterDownloadManager |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 72 | pFileManager *fileDownloadManager //let coexist 'old and new' DownloadManager as long as 'old' does not get obsolete |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 73 | metricsEnabled bool |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 74 | mibAuditInterval time.Duration |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 75 | omciTimeout int // in seconds |
Himani Chawla | 075f164 | 2021-03-15 19:23:24 +0530 | [diff] [blame] | 76 | alarmAuditInterval time.Duration |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 77 | dlToOnuTimeout4M time.Duration |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 78 | rpcTimeout time.Duration |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | //NewOpenONUAC returns a new instance of OpenONU_AC |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 82 | func NewOpenONUAC(ctx context.Context, coreClient *vgrpc.Client, eventProxy eventif.EventProxy, |
| 83 | kvClient kvstore.Client, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenONUAC { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 84 | var openOnuAc OpenONUAC |
| 85 | openOnuAc.exitChannel = make(chan int, 1) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 86 | openOnuAc.deviceHandlers = make(map[string]*deviceHandler) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 87 | openOnuAc.deviceHandlersCreateChan = make(map[string]chan bool) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 88 | openOnuAc.parentAdapterClients = make(map[string]*vgrpc.Client) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 89 | openOnuAc.lockDeviceHandlersMap = sync.RWMutex{} |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 90 | openOnuAc.config = cfg |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 91 | openOnuAc.cm = cm |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 92 | openOnuAc.coreClient = coreClient |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 93 | openOnuAc.numOnus = cfg.OnuNumber |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 94 | openOnuAc.eventProxy = eventProxy |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 95 | openOnuAc.kvClient = kvClient |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 96 | openOnuAc.KVStoreAddress = cfg.KVStoreAddress |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 97 | openOnuAc.KVStoreType = cfg.KVStoreType |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 98 | openOnuAc.KVStoreTimeout = cfg.KVStoreTimeout |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 99 | openOnuAc.mibTemplatesGenerated = make(map[string]bool) |
| 100 | openOnuAc.lockMibTemplateGenerated = sync.RWMutex{} |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 101 | openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval |
| 102 | openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 103 | openOnuAc.AcceptIncrementalEvto = cfg.AccIncrEvto |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 104 | openOnuAc.maxTimeoutInterAdapterComm = cfg.MaxTimeoutInterAdapterComm |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 105 | openOnuAc.maxTimeoutReconciling = cfg.MaxTimeoutReconciling |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 106 | //openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 107 | openOnuAc.metricsEnabled = cfg.MetricsEnabled |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 108 | openOnuAc.mibAuditInterval = cfg.MibAuditInterval |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 109 | // since consumers of OMCI timeout value everywhere in code is in "int seconds", do this useful conversion |
| 110 | openOnuAc.omciTimeout = int(cfg.OmciTimeout.Seconds()) |
Himani Chawla | 075f164 | 2021-03-15 19:23:24 +0530 | [diff] [blame] | 111 | openOnuAc.alarmAuditInterval = cfg.AlarmAuditInterval |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 112 | openOnuAc.dlToOnuTimeout4M = cfg.DownloadToOnuTimeout4MB |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 113 | openOnuAc.rpcTimeout = cfg.RPCTimeout |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 114 | |
| 115 | openOnuAc.pSupportedFsms = &OmciDeviceFsms{ |
| 116 | "mib-synchronizer": { |
| 117 | //mibSyncFsm, // Implements the MIB synchronization state machine |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 118 | mibDbVolatileDictImpl, // Implements volatile ME MIB database |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 119 | //true, // Advertise events on OpenOMCI event bus |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 120 | openOnuAc.mibAuditInterval, // Time to wait between MIB audits. 0 to disable audits. |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 121 | // map[string]func() error{ |
| 122 | // "mib-upload": onuDeviceEntry.MibUploadTask, |
| 123 | // "mib-template": onuDeviceEntry.MibTemplateTask, |
| 124 | // "get-mds": onuDeviceEntry.GetMdsTask, |
| 125 | // "mib-audit": onuDeviceEntry.GetMdsTask, |
| 126 | // "mib-resync": onuDeviceEntry.MibResyncTask, |
| 127 | // "mib-reconcile": onuDeviceEntry.MibReconcileTask, |
| 128 | // }, |
| 129 | }, |
| 130 | } |
| 131 | |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 132 | openOnuAc.pDownloadManager = newAdapterDownloadManager(ctx) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 133 | openOnuAc.pFileManager = newFileDownloadManager(ctx) |
| 134 | openOnuAc.pFileManager.SetDownloadTimeout(ctx, cfg.DownloadToAdapterTimeout) |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 135 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 136 | return &openOnuAc |
| 137 | } |
| 138 | |
| 139 | //Start starts (logs) the adapter |
| 140 | func (oo *OpenONUAC) Start(ctx context.Context) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 141 | logger.Info(ctx, "starting-openonu-adapter") |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 142 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 143 | return nil |
| 144 | } |
| 145 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 146 | /* |
| 147 | //stop terminates the session |
| 148 | func (oo *OpenONUAC) stop(ctx context.Context) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 149 | logger.Info(ctx,"stopping-device-manager") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 150 | oo.exitChannel <- 1 |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 151 | logger.Info(ctx,"device-manager-stopped") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 152 | return nil |
| 153 | } |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 154 | */ |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 155 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 156 | func (oo *OpenONUAC) addDeviceHandlerToMap(ctx context.Context, agent *deviceHandler) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 157 | oo.lockDeviceHandlersMap.Lock() |
| 158 | defer oo.lockDeviceHandlersMap.Unlock() |
| 159 | if _, exist := oo.deviceHandlers[agent.deviceID]; !exist { |
| 160 | oo.deviceHandlers[agent.deviceID] = agent |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 161 | oo.deviceHandlers[agent.deviceID].start(ctx) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 162 | if _, exist := oo.deviceHandlersCreateChan[agent.deviceID]; exist { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 163 | logger.Debugw(ctx, "deviceHandler created - trigger processing of pending ONU_IND_REQUEST", log.Fields{"device-id": agent.deviceID}) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 164 | oo.deviceHandlersCreateChan[agent.deviceID] <- true |
| 165 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 169 | func (oo *OpenONUAC) deleteDeviceHandlerToMap(agent *deviceHandler) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 170 | oo.lockDeviceHandlersMap.Lock() |
| 171 | defer oo.lockDeviceHandlersMap.Unlock() |
| 172 | delete(oo.deviceHandlers, agent.deviceID) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 173 | delete(oo.deviceHandlersCreateChan, agent.deviceID) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 176 | //getDeviceHandler gets the ONU deviceHandler and may wait until it is created |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 177 | func (oo *OpenONUAC) getDeviceHandler(ctx context.Context, deviceID string, aWait bool) *deviceHandler { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 178 | oo.lockDeviceHandlersMap.Lock() |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 179 | agent, ok := oo.deviceHandlers[deviceID] |
| 180 | if aWait && !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 181 | 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] | 182 | log.Fields{"device-id": deviceID}) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 183 | if _, exist := oo.deviceHandlersCreateChan[deviceID]; !exist { |
| 184 | oo.deviceHandlersCreateChan[deviceID] = make(chan bool, 1) |
| 185 | } |
Girish Gowdra | 7407a4d | 2020-11-12 12:44:53 -0800 | [diff] [blame] | 186 | deviceCreateChan := oo.deviceHandlersCreateChan[deviceID] |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 187 | //keep the read sema short to allow for subsequent write |
| 188 | oo.lockDeviceHandlersMap.Unlock() |
| 189 | // based on concurrent processing the deviceHandler creation may not yet be finished at his point |
| 190 | // so it might be needed to wait here for that event with some timeout |
| 191 | select { |
| 192 | case <-time.After(1 * time.Second): //timer may be discussed ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 193 | 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] | 194 | return nil |
Girish Gowdra | 7407a4d | 2020-11-12 12:44:53 -0800 | [diff] [blame] | 195 | case <-deviceCreateChan: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 196 | logger.Debugw(ctx, "deviceHandler is ready now - continue", log.Fields{"device-id": deviceID}) |
Girish Gowdra | 7407a4d | 2020-11-12 12:44:53 -0800 | [diff] [blame] | 197 | oo.lockDeviceHandlersMap.RLock() |
| 198 | defer oo.lockDeviceHandlersMap.RUnlock() |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 199 | return oo.deviceHandlers[deviceID] |
| 200 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 201 | } |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 202 | oo.lockDeviceHandlersMap.Unlock() |
| 203 | return agent |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 204 | } |
| 205 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 206 | // GetHealthStatus is used as a service readiness validation as a grpc connection |
| 207 | func (oo *OpenONUAC) GetHealthStatus(ctx context.Context, empty *empty.Empty) (*voltha.HealthStatus, error) { |
| 208 | return &voltha.HealthStatus{State: voltha.HealthStatus_HEALTHY}, nil |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 209 | } |
| 210 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 211 | // AdoptDevice creates a new device handler if not present already and then adopts the device |
| 212 | 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] | 213 | if device == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 214 | logger.Warn(ctx, "voltha-device-is-nil") |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 215 | return nil, errors.New("nil-device") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 216 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 217 | logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 218 | var handler *deviceHandler |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 219 | if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 220 | handler := newDeviceHandler(ctx, oo.coreClient, oo.eventProxy, device, oo) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 221 | oo.addDeviceHandlerToMap(ctx, handler) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 222 | |
| 223 | // Setup the grpc communication with the parent adapter |
| 224 | if err := oo.setupParentInterAdapterClient(ctx, device.ProxyAddress.AdapterEndpoint); err != nil { |
| 225 | // TODO: Cleanup on failure needed |
| 226 | return nil, err |
| 227 | } |
| 228 | |
| 229 | go handler.adoptOrReconcileDevice(log.WithSpanFromContext(context.Background(), ctx), device) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 230 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 231 | return &empty.Empty{}, nil |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 232 | } |
| 233 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 234 | //ReconcileDevice is called once when the adapter needs to re-create device - usually on core restart |
| 235 | 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] | 236 | if device == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 237 | logger.Warn(ctx, "reconcile-device-voltha-device-is-nil") |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 238 | return nil, errors.New("nil-device") |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 239 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 240 | logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 241 | var handler *deviceHandler |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 242 | if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 243 | handler := newDeviceHandler(ctx, oo.coreClient, oo.eventProxy, device, oo) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 244 | oo.addDeviceHandlerToMap(ctx, handler) |
| 245 | handler.device = device |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 246 | if err := handler.updateDeviceStateInCore(log.WithSpanFromContext(context.Background(), ctx), &ic.DeviceStateFilter{ |
| 247 | DeviceId: device.Id, |
| 248 | OperStatus: voltha.OperStatus_RECONCILING, |
| 249 | ConnStatus: device.ConnectStatus, |
| 250 | }); err != nil { |
| 251 | 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] | 252 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 253 | // Setup the grpc communication with the parent adapter |
| 254 | if err := oo.setupParentInterAdapterClient(ctx, device.ProxyAddress.AdapterEndpoint); err != nil { |
| 255 | // TODO: Cleanup on failure needed |
| 256 | return nil, err |
| 257 | } |
| 258 | |
| 259 | handler.startReconciling(log.WithSpanFromContext(context.Background(), ctx), false) |
| 260 | go handler.adoptOrReconcileDevice(log.WithSpanFromContext(context.Background(), ctx), handler.device) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 261 | // reconcilement will be continued after onu-device entry is added |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 262 | } else { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 263 | 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] | 264 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 265 | return &empty.Empty{}, nil |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 266 | } |
| 267 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 268 | //DisableDevice disables the given device |
| 269 | func (oo *OpenONUAC) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 270 | logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id}) |
| 271 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 272 | go handler.disableDevice(log.WithSpanFromContext(context.Background(), ctx), device) |
| 273 | return &empty.Empty{}, nil |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 274 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 275 | 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^] | 276 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 277 | } |
| 278 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 279 | //ReEnableDevice enables the onu device after disable |
| 280 | func (oo *OpenONUAC) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 281 | logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id}) |
| 282 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 283 | go handler.reEnableDevice(log.WithSpanFromContext(context.Background(), ctx), device) |
| 284 | return &empty.Empty{}, nil |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 285 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 286 | 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^] | 287 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 288 | } |
| 289 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 290 | //RebootDevice reboots the given device |
| 291 | func (oo *OpenONUAC) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 292 | logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id}) |
| 293 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 294 | go handler.rebootDevice(log.WithSpanFromContext(context.Background(), ctx), true, device) //reboot request with device checking |
| 295 | return &empty.Empty{}, nil |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 296 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 297 | 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^] | 298 | return nil, fmt.Errorf("handler-not-found-for-device: %s", device.Id) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 299 | } |
| 300 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 301 | // DeleteDevice deletes the given device |
| 302 | func (oo *OpenONUAC) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 303 | nctx := log.WithSpanFromContext(context.Background(), ctx) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 304 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 305 | logger.Infow(ctx, "delete-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber, "ctx": ctx, "nctx": nctx}) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 306 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 307 | var errorsList []error |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 308 | |
| 309 | handler.mutexDeletionInProgressFlag.Lock() |
| 310 | handler.deletionInProgress = true |
| 311 | handler.mutexDeletionInProgressFlag.Unlock() |
| 312 | |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 313 | if err := handler.deleteDevicePersistencyData(ctx); err != nil { |
| 314 | errorsList = append(errorsList, err) |
| 315 | } |
Girish Gowdra | 10123c0 | 2021-08-30 11:52:06 -0700 | [diff] [blame] | 316 | |
| 317 | // Stop PM, Alarm and Self Test event handler routines |
| 318 | if handler.getCollectorIsRunning() { |
| 319 | handler.stopCollector <- true |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 320 | logger.Debugw(ctx, "sent stop signal to metric collector routine", log.Fields{"device-id": device.Id}) |
Girish Gowdra | 10123c0 | 2021-08-30 11:52:06 -0700 | [diff] [blame] | 321 | |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 322 | } |
Girish Gowdra | 10123c0 | 2021-08-30 11:52:06 -0700 | [diff] [blame] | 323 | if handler.getAlarmManagerIsRunning(ctx) { |
| 324 | handler.stopAlarmManager <- true |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 325 | logger.Debugw(ctx, "sent stop signal to alarm manager", log.Fields{"device-id": device.Id}) |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 326 | } |
Girish Gowdra | 10123c0 | 2021-08-30 11:52:06 -0700 | [diff] [blame] | 327 | if handler.pSelfTestHdlr.GetSelfTestHandlerIsRunning() { |
| 328 | handler.pSelfTestHdlr.stopSelfTestModule <- true |
| 329 | logger.Debugw(ctx, "sent stop signal to self test handler module", log.Fields{"device-id": device.Id}) |
| 330 | } |
| 331 | |
| 332 | // Clear PM data on the KV store |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 333 | if handler.pOnuMetricsMgr != nil { |
| 334 | if err := handler.pOnuMetricsMgr.clearAllPmData(ctx); err != nil { |
| 335 | errorsList = append(errorsList, err) |
| 336 | } |
| 337 | } |
Girish Gowdra | 10123c0 | 2021-08-30 11:52:06 -0700 | [diff] [blame] | 338 | |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 339 | //don't leave any garbage - even in error case |
| 340 | oo.deleteDeviceHandlerToMap(handler) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 341 | if len(errorsList) > 0 { |
| 342 | 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^] | 343 | 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] | 344 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 345 | return &empty.Empty{}, nil |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 346 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 347 | logger.Warnw(ctx, "no handler found for device-deletion", log.Fields{"device-id": device.Id}) |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 348 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 349 | } |
| 350 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 351 | //UpdateFlowsIncrementally updates (add/remove) the flows on a given device |
| 352 | func (oo *OpenONUAC) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ic.IncrementalFlows) (*empty.Empty, error) { |
| 353 | 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] | 354 | |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 355 | //flow config is relayed to handler even if the device might be in some 'inactive' state |
| 356 | // let the handler or related FSM's decide, what to do with the modified flow state info |
| 357 | // 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] | 358 | |
| 359 | // 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] | 360 | // but processing is continued for flowUpdate possibly also set in the request |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 361 | if incrFlows.Groups.ToAdd != nil && incrFlows.Groups.ToAdd.Items != nil { |
| 362 | 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] | 363 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 364 | if incrFlows.Groups.ToRemove != nil && incrFlows.Groups.ToRemove.Items != nil { |
| 365 | 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] | 366 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 367 | if incrFlows.Groups.ToUpdate != nil && incrFlows.Groups.ToUpdate.Items != nil { |
| 368 | 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] | 369 | } |
| 370 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 371 | if handler := oo.getDeviceHandler(ctx, incrFlows.Device.Id, false); handler != nil { |
| 372 | if err := handler.FlowUpdateIncremental(log.WithSpanFromContext(context.Background(), ctx), incrFlows.Flows, incrFlows.Groups, incrFlows.FlowMetadata); err != nil { |
| 373 | return nil, err |
| 374 | } |
| 375 | return &empty.Empty{}, nil |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 376 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 377 | logger.Warnw(ctx, "no handler found for incremental flow update", log.Fields{"device-id": incrFlows.Device.Id}) |
| 378 | 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] | 379 | } |
| 380 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 381 | //UpdatePmConfig returns PmConfigs nil or error |
| 382 | func (oo *OpenONUAC) UpdatePmConfig(ctx context.Context, configs *ic.PmConfigsInfo) (*empty.Empty, error) { |
| 383 | logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": configs.DeviceId}) |
| 384 | if handler := oo.getDeviceHandler(ctx, configs.DeviceId, false); handler != nil { |
| 385 | if err := handler.updatePmConfig(log.WithSpanFromContext(context.Background(), ctx), configs.PmConfigs); err != nil { |
| 386 | return nil, err |
| 387 | } |
| 388 | return &empty.Empty{}, nil |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 389 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 390 | logger.Warnw(ctx, "no handler found for update-pm-config", log.Fields{"device-id": configs.DeviceId}) |
| 391 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", configs.DeviceId)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 392 | } |
| 393 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 394 | //DownloadImage requests downloading some image according to indications as given in request |
Andrea Campanella | 71e546a | 2021-02-26 11:09:33 +0100 | [diff] [blame] | 395 | //The ImageDownload needs to be called `request`due to library reflection requirements |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 396 | func (oo *OpenONUAC) DownloadImage(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 397 | ctx = log.WithSpanFromContext(context.Background(), ctx) |
| 398 | if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" { |
| 399 | if !oo.pDownloadManager.imageExists(ctx, imageInfo.Image) { |
| 400 | logger.Debugw(ctx, "start image download", log.Fields{"image-description": imageInfo.Image}) |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 401 | // Download_image is not supposed to be blocking, anyway let's call the DownloadManager still synchronously to detect 'fast' problems |
| 402 | // the download itself is later done in background |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 403 | if err := oo.pDownloadManager.startDownload(ctx, imageInfo.Image); err != nil { |
| 404 | return nil, err |
| 405 | } |
| 406 | return imageInfo.Image, nil |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 407 | } |
| 408 | // image already exists |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 409 | logger.Debugw(ctx, "image already downloaded", log.Fields{"image-description": imageInfo.Image}) |
| 410 | return imageInfo.Image, nil |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 411 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 412 | |
| 413 | return nil, errors.New("invalid image definition") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 414 | } |
| 415 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 416 | //ActivateImageUpdate requests downloading some Onu Software image to the INU via OMCI |
Andrea Campanella | 71e546a | 2021-02-26 11:09:33 +0100 | [diff] [blame] | 417 | // according to indications as given in request and on success activate the image on the ONU |
| 418 | //The ImageDownload needs to be called `request`due to library reflection requirements |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 419 | func (oo *OpenONUAC) ActivateImageUpdate(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 420 | if imageInfo != nil && imageInfo.Image != nil && imageInfo.Image.Name != "" { |
| 421 | if oo.pDownloadManager.imageLocallyDownloaded(ctx, imageInfo.Image) { |
| 422 | if handler := oo.getDeviceHandler(ctx, imageInfo.Device.Id, false); handler != nil { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 423 | logger.Debugw(ctx, "image download on omci requested", log.Fields{ |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 424 | "image-description": imageInfo.Image, "device-id": imageInfo.Device.Id}) |
| 425 | if err := handler.doOnuSwUpgrade(ctx, imageInfo.Image, oo.pDownloadManager); err != nil { |
| 426 | return nil, err |
| 427 | } |
| 428 | return imageInfo.Image, nil |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 429 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 430 | logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": imageInfo.Device.Id}) |
| 431 | 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] | 432 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 433 | logger.Debugw(ctx, "image not yet downloaded on activate request", log.Fields{"image-description": imageInfo.Image}) |
| 434 | 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] | 435 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 436 | return nil, errors.New("invalid image definition") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 437 | } |
| 438 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 439 | //GetSingleValue handles the core request to retrieve uni status |
| 440 | func (oo *OpenONUAC) GetSingleValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) { |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 441 | logger.Infow(ctx, "Single_get_value_request", log.Fields{"request": request}) |
| 442 | |
| 443 | if handler := oo.getDeviceHandler(ctx, request.TargetId, false); handler != nil { |
| 444 | switch reqType := request.GetRequest().GetRequest().(type) { |
| 445 | case *extension.GetValueRequest_UniInfo: |
| 446 | return handler.getUniPortStatus(ctx, reqType.UniInfo), nil |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 447 | case *extension.GetValueRequest_OnuOpticalInfo: |
| 448 | commChan := make(chan Message) |
| 449 | respChan := make(chan extension.SingleGetValueResponse) |
| 450 | // Initiate the self test request |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 451 | if err := handler.pSelfTestHdlr.SelfTestRequestStart(ctx, *request, commChan, respChan); err != nil { |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 452 | return &extension.SingleGetValueResponse{ |
| 453 | Response: &extension.GetValueResponse{ |
| 454 | Status: extension.GetValueResponse_ERROR, |
| 455 | ErrReason: extension.GetValueResponse_INTERNAL_ERROR, |
| 456 | }, |
| 457 | }, err |
| 458 | } |
| 459 | // The timeout handling is already implemented in omci_self_test_handler module |
| 460 | resp := <-respChan |
| 461 | return &resp, nil |
Himani Chawla | 43f95ff | 2021-06-03 00:24:12 +0530 | [diff] [blame] | 462 | case *extension.GetValueRequest_OnuInfo: |
| 463 | return handler.getOnuOMCICounters(ctx, reqType.OnuInfo), nil |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 464 | default: |
| 465 | return postUniStatusErrResponse(extension.GetValueResponse_UNSUPPORTED), nil |
| 466 | |
| 467 | } |
| 468 | } |
| 469 | logger.Errorw(ctx, "Single_get_value_request failed ", log.Fields{"request": request}) |
| 470 | return postUniStatusErrResponse(extension.GetValueResponse_INVALID_DEVICE_ID), nil |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 471 | } |
| 472 | |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 473 | //if update >= 4.3.0 |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 474 | // Note: already with the implementation of the 'old' download interface problems were detected when the argument name used here is not the same |
| 475 | // as defined in the adapter interface file. That sounds strange and the effects were strange as well. |
| 476 | // The reason for that was never finally investigated. |
| 477 | // 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] | 478 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 479 | // 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] | 480 | // 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^] | 481 | func (oo *OpenONUAC) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 482 | if request != nil && len((*request).DeviceId) > 0 && (*request).Image.Version != "" { |
| 483 | loResponse := voltha.DeviceImageResponse{} |
| 484 | imageIdentifier := (*request).Image.Version |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 485 | downloadedToAdapter := false |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 486 | firstDevice := true |
| 487 | var vendorID string |
| 488 | for _, pCommonID := range (*request).DeviceId { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 489 | vendorIDMatch := true |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 490 | loDeviceID := (*pCommonID).Id |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 491 | loDeviceImageState := voltha.DeviceImageState{} |
| 492 | loDeviceImageState.DeviceId = loDeviceID |
| 493 | loImageState := voltha.ImageState{} |
| 494 | loDeviceImageState.ImageState = &loImageState |
| 495 | loDeviceImageState.ImageState.Version = (*request).Image.Version |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 496 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 497 | handler := oo.getDeviceHandler(ctx, loDeviceID, false) |
| 498 | if handler == nil { |
| 499 | //cannot start ONU download for requested device |
| 500 | logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": loDeviceID}) |
| 501 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
| 502 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR |
| 503 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 504 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState) |
| 505 | continue |
| 506 | } |
| 507 | |
| 508 | onuVolthaDevice, err := handler.getDeviceFromCore(ctx, loDeviceID) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 509 | if err != nil || onuVolthaDevice == nil { |
| 510 | logger.Warnw(ctx, "Failed to fetch Onu device for image download", |
| 511 | log.Fields{"device-id": loDeviceID, "err": err}) |
| 512 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
| 513 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //proto restriction, better option: 'INVALID_DEVICE' |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 514 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 515 | } else { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 516 | if firstDevice { |
| 517 | //start/verify download of the image to the adapter based on first found device only |
| 518 | // use the OnuVendor identification from first given device |
| 519 | firstDevice = false |
| 520 | vendorID = onuVolthaDevice.VendorId |
| 521 | imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU |
| 522 | logger.Debugw(ctx, "download request for file", log.Fields{"image-id": imageIdentifier}) |
| 523 | |
| 524 | if !oo.pFileManager.ImageExists(ctx, imageIdentifier) { |
| 525 | logger.Debugw(ctx, "start image download", log.Fields{"image-description": request}) |
| 526 | // Download_image is not supposed to be blocking, anyway let's call the DownloadManager still synchronously to detect 'fast' problems |
| 527 | // the download itself is later done in background |
| 528 | if err := oo.pFileManager.StartDownload(ctx, imageIdentifier, (*request).Image.Url); err == nil { |
| 529 | downloadedToAdapter = true |
| 530 | } |
| 531 | //else: treat any error here as 'INVALID_URL' (even though it might as well be some issue on local FS, eg. 'INSUFFICIENT_SPACE') |
| 532 | // otherwise a more sophisticated error evaluation is needed |
| 533 | } else { |
| 534 | // image already exists |
| 535 | downloadedToAdapter = true |
| 536 | logger.Debugw(ctx, "image already downloaded", log.Fields{"image-description": imageIdentifier}) |
| 537 | // note: If the image (with vendorId+name) has already been downloaded before from some other |
| 538 | // valid URL, the current URL is just ignored. If the operators want to ensure that the new URL |
| 539 | // is really used, then they first have to use the 'abort' API to remove the existing image! |
| 540 | // (abort API can be used also after some successful download to just remove the image from adapter) |
| 541 | } |
| 542 | } else { |
| 543 | //for all following devices verify the matching vendorID |
| 544 | if onuVolthaDevice.VendorId != vendorID { |
| 545 | logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored", |
| 546 | log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID}) |
| 547 | vendorIDMatch = false |
| 548 | } |
| 549 | } |
| 550 | if downloadedToAdapter && vendorIDMatch { |
| 551 | // start the ONU download activity for each possible device |
| 552 | // assumption here is, that the concerned device was already created (automatic start after device creation not supported) |
| 553 | if handler := oo.getDeviceHandler(ctx, loDeviceID, false); handler != nil { |
| 554 | logger.Debugw(ctx, "image download on omci requested", log.Fields{ |
| 555 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 556 | //onu upgrade handling called in background without immediate error evaluation here |
| 557 | // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others |
| 558 | // state/progress/success of the request has to be verified using the Get_onu_image_status() API |
| 559 | go handler.onuSwUpgradeAfterDownload(ctx, request, oo.pFileManager, imageIdentifier) |
| 560 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_STARTED |
| 561 | loDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR |
| 562 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 563 | } else { |
| 564 | //cannot start ONU download for requested device |
| 565 | logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": loDeviceID}) |
| 566 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
| 567 | loDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR //proto restriction, better option: 'INVALID_DEVICE' |
| 568 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 569 | } |
| 570 | } else { |
| 571 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
| 572 | if !downloadedToAdapter { |
| 573 | loDeviceImageState.ImageState.Reason = voltha.ImageState_INVALID_URL |
| 574 | } else { //only logical option is !vendorIDMatch |
| 575 | loDeviceImageState.ImageState.Reason = voltha.ImageState_VENDOR_DEVICE_MISMATCH |
| 576 | } |
| 577 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 578 | } |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 579 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 580 | |
| 581 | // start the ONU download activity for each possible device |
| 582 | logger.Debugw(ctx, "image download on omci requested", log.Fields{ |
| 583 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 584 | //onu upgrade handling called in background without immediate error evaluation here |
| 585 | // as the processing can be done for multiple ONU's and an error on one ONU should not stop processing for others |
| 586 | // state/progress/success of the request has to be verified using the Get_onu_image_status() API |
| 587 | go handler.onuSwUpgradeAfterDownload(ctx, request, oo.pFileManager, imageIdentifier) |
| 588 | loDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_STARTED |
| 589 | loDeviceImageState.ImageState.Reason = voltha.ImageState_NO_ERROR |
| 590 | loDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 591 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, &loDeviceImageState) |
mpagenko | c26d4c0 | 2021-05-06 14:27:57 +0000 | [diff] [blame] | 592 | } |
| 593 | pImageResp := &loResponse |
| 594 | return pImageResp, nil |
| 595 | } |
| 596 | return nil, errors.New("invalid image download parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 597 | } |
| 598 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 599 | // GetOnuImageStatus delivers the adapter-related information about the download/activation/commitment |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 600 | // status for the requested image |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 601 | func (oo *OpenONUAC) GetOnuImageStatus(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 602 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 603 | loResponse := voltha.DeviceImageResponse{} |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 604 | imageIdentifier := (*in).Version |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 605 | var vendorIDSet bool |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 606 | firstDevice := true |
| 607 | var vendorID string |
| 608 | for _, pCommonID := range (*in).DeviceId { |
| 609 | loDeviceID := (*pCommonID).Id |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 610 | pDeviceImageState := &voltha.DeviceImageState{DeviceId: loDeviceID} |
| 611 | handler := oo.getDeviceHandler(ctx, loDeviceID, false) |
| 612 | if handler == nil { |
| 613 | //cannot get the handler |
| 614 | logger.Warnw(ctx, "no handler found for image status request ", log.Fields{"device-id": loDeviceID}) |
| 615 | pDeviceImageState.DeviceId = loDeviceID |
| 616 | pDeviceImageState.ImageState.Version = (*in).Version |
| 617 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_FAILED |
| 618 | pDeviceImageState.ImageState.Reason = voltha.ImageState_UNKNOWN_ERROR |
| 619 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 620 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState) |
| 621 | continue |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 622 | } |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 623 | onuVolthaDevice, err := handler.getDeviceFromCore(ctx, loDeviceID) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 624 | if err != nil || onuVolthaDevice == nil { |
| 625 | logger.Warnw(ctx, "Failed to fetch Onu device to get image status", |
| 626 | log.Fields{"device-id": loDeviceID, "err": err}) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 627 | pImageState := &voltha.ImageState{ |
| 628 | Version: (*in).Version, |
| 629 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //no statement about last activity possible |
| 630 | Reason: voltha.ImageState_UNKNOWN_ERROR, //something like "DEVICE_NOT_EXISTS" would be better (proto def) |
| 631 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 632 | } |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 633 | pDeviceImageState.ImageState = pImageState |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 634 | } else { |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 635 | if firstDevice { |
| 636 | //start/verify download of the image to the adapter based on first found device only |
| 637 | // use the OnuVendor identification from first given device |
| 638 | firstDevice = false |
| 639 | vendorID = onuVolthaDevice.VendorId |
| 640 | imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU |
| 641 | vendorIDSet = true |
| 642 | logger.Debugw(ctx, "status request for image", log.Fields{"image-id": imageIdentifier}) |
| 643 | } else { |
| 644 | //for all following devices verify the matching vendorID |
| 645 | if onuVolthaDevice.VendorId != vendorID { |
| 646 | logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored", |
| 647 | log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID}) |
| 648 | } else { |
| 649 | vendorIDSet = true |
| 650 | } |
| 651 | } |
| 652 | if !vendorIDSet { |
| 653 | pImageState := &voltha.ImageState{ |
| 654 | Version: (*in).Version, |
| 655 | DownloadState: voltha.ImageState_DOWNLOAD_UNKNOWN, //can't be sure that download for this device was really tried |
| 656 | Reason: voltha.ImageState_VENDOR_DEVICE_MISMATCH, |
| 657 | ImageState: voltha.ImageState_IMAGE_UNKNOWN, |
| 658 | } |
| 659 | pDeviceImageState.ImageState = pImageState |
| 660 | } else { |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 661 | logger.Debugw(ctx, "image status request for", log.Fields{ |
| 662 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 663 | //status request is called synchronously to collect the indications for all concerned devices |
| 664 | pDeviceImageState.ImageState = handler.requestOnuSwUpgradeState(ctx, imageIdentifier, (*in).Version) |
mpagenko | 38662d0 | 2021-08-11 09:45:19 +0000 | [diff] [blame] | 665 | } |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 666 | } |
| 667 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState) |
| 668 | } |
| 669 | pImageResp := &loResponse |
| 670 | return pImageResp, nil |
| 671 | } |
| 672 | return nil, errors.New("invalid image status request parameters") |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 673 | } |
| 674 | |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 675 | // AbortOnuImageUpgrade stops the actual download/activation/commitment process (on next possibly step) |
| 676 | func (oo *OpenONUAC) AbortOnuImageUpgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 677 | if in != nil && len((*in).DeviceId) > 0 && (*in).Version != "" { |
| 678 | loResponse := voltha.DeviceImageResponse{} |
| 679 | imageIdentifier := (*in).Version |
| 680 | firstDevice := true |
| 681 | var vendorID string |
| 682 | for _, pCommonID := range (*in).DeviceId { |
| 683 | loDeviceID := (*pCommonID).Id |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 684 | pDeviceImageState := &voltha.DeviceImageState{} |
| 685 | loImageState := voltha.ImageState{} |
| 686 | pDeviceImageState.ImageState = &loImageState |
| 687 | |
| 688 | handler := oo.getDeviceHandler(ctx, loDeviceID, false) |
| 689 | if handler == nil { |
| 690 | //cannot start ONU download for requested device |
| 691 | logger.Warnw(ctx, "no handler found for aborting upgrade ", log.Fields{"device-id": loDeviceID}) |
| 692 | pDeviceImageState.DeviceId = loDeviceID |
| 693 | pDeviceImageState.ImageState.Version = (*in).Version |
| 694 | //nolint:misspell |
| 695 | pDeviceImageState.ImageState.DownloadState = voltha.ImageState_DOWNLOAD_CANCELLED |
| 696 | //nolint:misspell |
| 697 | pDeviceImageState.ImageState.Reason = voltha.ImageState_CANCELLED_ON_REQUEST |
| 698 | pDeviceImageState.ImageState.ImageState = voltha.ImageState_IMAGE_UNKNOWN |
| 699 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState) |
| 700 | continue |
| 701 | } |
| 702 | onuVolthaDevice, err := handler.getDeviceFromCore(ctx, loDeviceID) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 703 | if err != nil || onuVolthaDevice == nil { |
| 704 | logger.Warnw(ctx, "Failed to fetch Onu device to abort its download", |
| 705 | log.Fields{"device-id": loDeviceID, "err": err}) |
| 706 | continue //try the work with next deviceId |
| 707 | } |
mpagenko | 2f2f236 | 2021-06-07 08:25:22 +0000 | [diff] [blame] | 708 | |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 709 | if firstDevice { |
| 710 | //start/verify download of the image to the adapter based on first found device only |
| 711 | // use the OnuVendor identification from first given device |
| 712 | firstDevice = false |
| 713 | vendorID = onuVolthaDevice.VendorId |
| 714 | imageIdentifier = vendorID + imageIdentifier //head on vendor ID of the ONU |
| 715 | logger.Debugw(ctx, "abort request for file", log.Fields{"image-id": imageIdentifier}) |
| 716 | } else { |
| 717 | //for all following devices verify the matching vendorID |
| 718 | if onuVolthaDevice.VendorId != vendorID { |
| 719 | logger.Warnw(ctx, "onu vendor id does not match image vendor id, device ignored", |
| 720 | log.Fields{"onu-vendor-id": onuVolthaDevice.VendorId, "image-vendor-id": vendorID}) |
| 721 | continue //try the work with next deviceId |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | // cancel the ONU upgrade activity for each possible device |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame^] | 726 | logger.Debugw(ctx, "image upgrade abort requested", log.Fields{ |
| 727 | "image-id": imageIdentifier, "device-id": loDeviceID}) |
| 728 | //upgrade cancel is called synchronously to collect the imageResponse indications for all concerned devices |
| 729 | handler.cancelOnuSwUpgrade(ctx, imageIdentifier, (*in).Version, pDeviceImageState) |
mpagenko | aa3afe9 | 2021-05-21 16:20:58 +0000 | [diff] [blame] | 730 | loResponse.DeviceImageStates = append(loResponse.DeviceImageStates, pDeviceImageState) |
| 731 | } |
| 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. |
| 863 | func (oo *OpenONUAC) OnuIndication(ctx context.Context, onuInd *ic.OnuIndicationMessage) (*empty.Empty, error) { |
| 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") { |
| 892 | return nil, handler.updateInterface(ctx, onuIndication) |
| 893 | } else { |
| 894 | logger.Errorw(ctx, "unknown-onu-ind-request operState", log.Fields{"OnuId": onuIndication.GetOnuId()}) |
| 895 | return nil, fmt.Errorf("invalidOperState: %s, %s", onuOperstate, onuInd.DeviceId) |
| 896 | } |
| 897 | } |
| 898 | logger.Warnw(ctx, "no handler found for received onu-ind-request", log.Fields{ |
| 899 | "msgToDeviceId": onuInd.DeviceId}) |
| 900 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", onuInd.DeviceId)) |
| 901 | } |
| 902 | |
| 903 | // OmciIndication is part of the ONU Inter-adapter service API. |
| 904 | func (oo *OpenONUAC) OmciIndication(ctx context.Context, msg *ic.OmciMessage) (*empty.Empty, error) { |
| 905 | logger.Debugw(ctx, "omci-response", log.Fields{"parent-device-id": msg.ParentDeviceId, "child-device-id": msg.ChildDeviceId}) |
| 906 | |
| 907 | if handler := oo.getDeviceHandler(ctx, msg.ChildDeviceId, false); handler != nil { |
| 908 | if err := handler.handleOMCIIndication(log.WithSpanFromContext(context.Background(), ctx), msg); err != nil { |
| 909 | return nil, err |
| 910 | } |
| 911 | return &empty.Empty{}, nil |
| 912 | } |
| 913 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", msg.ChildDeviceId)) |
| 914 | } |
| 915 | |
| 916 | // DownloadTechProfile is part of the ONU Inter-adapter service API. |
| 917 | func (oo *OpenONUAC) DownloadTechProfile(ctx context.Context, tProfile *ic.TechProfileDownloadMessage) (*empty.Empty, error) { |
| 918 | logger.Debugw(ctx, "download-tech-profile", log.Fields{"uni-id": tProfile.UniId}) |
| 919 | |
| 920 | if handler := oo.getDeviceHandler(ctx, tProfile.DeviceId, false); handler != nil { |
| 921 | if err := handler.handleTechProfileDownloadRequest(log.WithSpanFromContext(context.Background(), ctx), tProfile); err != nil { |
| 922 | return nil, err |
| 923 | } |
| 924 | return &empty.Empty{}, nil |
| 925 | } |
| 926 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", tProfile.DeviceId)) |
| 927 | } |
| 928 | |
| 929 | // DeleteGemPort is part of the ONU Inter-adapter service API. |
| 930 | func (oo *OpenONUAC) DeleteGemPort(ctx context.Context, gPort *ic.DeleteGemPortMessage) (*empty.Empty, error) { |
| 931 | logger.Debugw(ctx, "delete-gem-port", log.Fields{"device-id": gPort.DeviceId, "uni-id": gPort.UniId}) |
| 932 | |
| 933 | if handler := oo.getDeviceHandler(ctx, gPort.DeviceId, false); handler != nil { |
| 934 | if err := handler.handleDeleteGemPortRequest(log.WithSpanFromContext(context.Background(), ctx), gPort); err != nil { |
| 935 | return nil, err |
| 936 | } |
| 937 | return &empty.Empty{}, nil |
| 938 | } |
| 939 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", gPort.DeviceId)) |
| 940 | } |
| 941 | |
| 942 | // DeleteTCont is part of the ONU Inter-adapter service API. |
| 943 | func (oo *OpenONUAC) DeleteTCont(ctx context.Context, tConf *ic.DeleteTcontMessage) (*empty.Empty, error) { |
| 944 | logger.Debugw(ctx, "delete-tcont", log.Fields{"tconf": tConf}) |
| 945 | |
| 946 | if handler := oo.getDeviceHandler(ctx, tConf.DeviceId, false); handler != nil { |
| 947 | if err := handler.handleDeleteTcontRequest(log.WithSpanFromContext(context.Background(), ctx), tConf); err != nil { |
| 948 | return nil, err |
| 949 | } |
| 950 | return &empty.Empty{}, nil |
| 951 | } |
| 952 | return nil, fmt.Errorf(fmt.Sprintf("handler-not-found-%s", tConf.DeviceId)) |
| 953 | } |
| 954 | |
| 955 | /* |
| 956 | * Parent GRPC clients |
| 957 | */ |
| 958 | |
| 959 | func (oo *OpenONUAC) setupParentInterAdapterClient(ctx context.Context, endpoint string) error { |
| 960 | logger.Infow(ctx, "setting-parent-adapter-connection", log.Fields{"parent-endpoint": endpoint}) |
| 961 | oo.lockParentAdapterClients.Lock() |
| 962 | defer oo.lockParentAdapterClients.Unlock() |
| 963 | if _, ok := oo.parentAdapterClients[endpoint]; ok { |
| 964 | return nil |
| 965 | } |
| 966 | |
| 967 | childClient, err := vgrpc.NewClient(endpoint, |
| 968 | oo.oltAdapterRestarted, |
| 969 | vgrpc.ActivityCheck(true)) |
| 970 | |
| 971 | if err != nil { |
| 972 | return err |
| 973 | } |
| 974 | |
| 975 | oo.parentAdapterClients[endpoint] = childClient |
| 976 | |
| 977 | go oo.parentAdapterClients[endpoint].Start(log.WithSpanFromContext(context.TODO(), ctx), setAndTestAdapterServiceHandler) |
| 978 | |
| 979 | // Wait until we have a connection to the child adapter. |
| 980 | // Unlimited retries or until context expires |
| 981 | subCtx := log.WithSpanFromContext(context.TODO(), ctx) |
| 982 | backoff := vgrpc.NewBackoff(oo.config.MinBackoffRetryDelay, oo.config.MaxBackoffRetryDelay, 0) |
| 983 | for { |
| 984 | client, err := oo.parentAdapterClients[endpoint].GetOltInterAdapterServiceClient() |
| 985 | if err == nil && client != nil { |
| 986 | logger.Infow(subCtx, "connected-to-parent-adapter", log.Fields{"parent-endpoint": endpoint}) |
| 987 | break |
| 988 | } |
| 989 | logger.Warnw(subCtx, "connection-to-parent-adapter-not-ready", log.Fields{"error": err, "parent-endpoint": endpoint}) |
| 990 | // Backoff |
| 991 | if err = backoff.Backoff(subCtx); err != nil { |
| 992 | logger.Errorw(subCtx, "received-error-on-backoff", log.Fields{"error": err, "parent-endpoint": endpoint}) |
| 993 | break |
| 994 | } |
| 995 | } |
| 996 | return nil |
| 997 | } |
| 998 | |
| 999 | func (oo *OpenONUAC) getParentAdapterServiceClient(endpoint string) (adapter_services.OltInterAdapterServiceClient, error) { |
| 1000 | // First check from cache |
| 1001 | oo.lockParentAdapterClients.RLock() |
| 1002 | if pgClient, ok := oo.parentAdapterClients[endpoint]; ok { |
| 1003 | oo.lockParentAdapterClients.RUnlock() |
| 1004 | return pgClient.GetOltInterAdapterServiceClient() |
| 1005 | } |
| 1006 | oo.lockParentAdapterClients.RUnlock() |
| 1007 | |
| 1008 | // Set the parent connection - can occur on restarts |
| 1009 | ctx, cancel := context.WithTimeout(context.Background(), oo.config.RPCTimeout) |
| 1010 | err := oo.setupParentInterAdapterClient(ctx, endpoint) |
| 1011 | cancel() |
| 1012 | if err != nil { |
| 1013 | return nil, err |
| 1014 | } |
| 1015 | |
| 1016 | // Get the parent client now |
| 1017 | oo.lockParentAdapterClients.RLock() |
| 1018 | defer oo.lockParentAdapterClients.RUnlock() |
| 1019 | if pgClient, ok := oo.parentAdapterClients[endpoint]; ok { |
| 1020 | return pgClient.GetOltInterAdapterServiceClient() |
| 1021 | } |
| 1022 | |
| 1023 | return nil, fmt.Errorf("no-client-for-endpoint-%s", endpoint) |
| 1024 | } |
| 1025 | |
| 1026 | // TODO: Any action the adapter needs to do following an olt adapter restart? |
| 1027 | func (oo *OpenONUAC) oltAdapterRestarted(ctx context.Context, endPoint string) error { |
| 1028 | logger.Errorw(ctx, "olt-adapter-restarted", log.Fields{"endpoint": endPoint}) |
| 1029 | return nil |
| 1030 | } |
| 1031 | |
| 1032 | // setAndTestAdapterServiceHandler is used to test whether the remote gRPC service is up |
| 1033 | func setAndTestAdapterServiceHandler(ctx context.Context, conn *grpc.ClientConn) interface{} { |
| 1034 | svc := adapter_services.NewOltInterAdapterServiceClient(conn) |
| 1035 | if h, err := svc.GetHealthStatus(ctx, &empty.Empty{}); err != nil || h.State != voltha.HealthStatus_HEALTHY { |
| 1036 | return nil |
| 1037 | } |
| 1038 | return svc |
| 1039 | } |
| 1040 | |
| 1041 | /* |
| 1042 | * |
| 1043 | * Unimplemented APIs |
| 1044 | * |
| 1045 | */ |
| 1046 | |
| 1047 | //GetOfpDeviceInfo returns OFP information for the given device. Method not implemented as per [VOL-3202]. |
| 1048 | // OF port info is now to be delivered within UniPort create cmp changes in onu_uni_port.go::CreateVolthaPort() |
| 1049 | // |
| 1050 | func (oo *OpenONUAC) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) { |
| 1051 | return nil, errors.New("unImplemented") |
| 1052 | } |
| 1053 | |
| 1054 | //SimulateAlarm is unimplemented |
| 1055 | func (oo *OpenONUAC) SimulateAlarm(context.Context, *ic.SimulateAlarmMessage) (*common.OperationResp, error) { |
| 1056 | return nil, errors.New("unImplemented") |
| 1057 | } |
| 1058 | |
| 1059 | //SetExtValue is unimplemented |
| 1060 | func (oo *OpenONUAC) SetExtValue(context.Context, *ic.SetExtValueMessage) (*empty.Empty, error) { |
| 1061 | return nil, errors.New("unImplemented") |
| 1062 | } |
| 1063 | |
| 1064 | //SetSingleValue is unimplemented |
| 1065 | func (oo *OpenONUAC) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) { |
| 1066 | return nil, errors.New("unImplemented") |
| 1067 | } |
| 1068 | |
| 1069 | //StartOmciTest not implemented |
| 1070 | func (oo *OpenONUAC) StartOmciTest(ctx context.Context, test *ic.OMCITest) (*voltha.TestResponse, error) { |
| 1071 | return nil, errors.New("unImplemented") |
| 1072 | } |
| 1073 | |
| 1074 | //SuppressEvent unimplemented |
| 1075 | func (oo *OpenONUAC) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 1076 | return nil, errors.New("unImplemented") |
| 1077 | } |
| 1078 | |
| 1079 | //UnSuppressEvent unimplemented |
| 1080 | func (oo *OpenONUAC) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 1081 | return nil, errors.New("unImplemented") |
| 1082 | } |
| 1083 | |
| 1084 | //GetImageDownloadStatus is unimplemented |
| 1085 | func (oo *OpenONUAC) GetImageDownloadStatus(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 1086 | return nil, errors.New("unImplemented") |
| 1087 | } |
| 1088 | |
| 1089 | //CancelImageDownload is unimplemented |
| 1090 | func (oo *OpenONUAC) CancelImageDownload(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 1091 | return nil, errors.New("unImplemented") |
| 1092 | } |
| 1093 | |
| 1094 | //RevertImageUpdate is unimplemented |
| 1095 | func (oo *OpenONUAC) RevertImageUpdate(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 1096 | return nil, errors.New("unImplemented") |
| 1097 | } |
| 1098 | |
| 1099 | // UpdateFlowsBulk is unimplemented |
| 1100 | func (oo *OpenONUAC) UpdateFlowsBulk(ctx context.Context, flows *ic.BulkFlows) (*empty.Empty, error) { |
| 1101 | return nil, errors.New("unImplemented") |
| 1102 | } |
| 1103 | |
| 1104 | //SelfTestDevice unimplented |
| 1105 | func (oo *OpenONUAC) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 1106 | return nil, errors.New("unImplemented") |
| 1107 | } |
| 1108 | |
| 1109 | //SendPacketOut sends packet out to the device |
| 1110 | func (oo *OpenONUAC) SendPacketOut(ctx context.Context, packet *ic.PacketOut) (*empty.Empty, error) { |
| 1111 | return nil, errors.New("unImplemented") |
| 1112 | } |
| 1113 | |
| 1114 | // EnablePort to Enable PON/NNI interface - seems not to be used/required according to python code |
| 1115 | func (oo *OpenONUAC) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 1116 | return nil, errors.New("unImplemented") |
| 1117 | } |
| 1118 | |
| 1119 | // DisablePort to Disable pon/nni interface - seems not to be used/required according to python code |
| 1120 | func (oo *OpenONUAC) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 1121 | return nil, errors.New("unImplemented") |
| 1122 | } |
| 1123 | |
| 1124 | // GetExtValue - unimplemented |
| 1125 | func (oo *OpenONUAC) GetExtValue(ctx context.Context, extInfo *ic.GetExtValueMessage) (*voltha.ReturnValues, error) { |
| 1126 | return nil, errors.New("unImplemented") |
| 1127 | } |
| 1128 | |
| 1129 | // ChildDeviceLost - unimplemented |
| 1130 | func (oo *OpenONUAC) ChildDeviceLost(ctx context.Context, childDevice *voltha.Device) (*empty.Empty, error) { |
| 1131 | return nil, errors.New("unImplemented") |
| 1132 | } |