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