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