Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 17 | //Package adaptercoreonu provides the utility for onu devices, flows and statistics |
| 18 | package adaptercoreonu |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "errors" |
| 23 | "fmt" |
| 24 | "sync" |
| 25 | "time" |
| 26 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 27 | conf "github.com/opencord/voltha-lib-go/v4/pkg/config" |
| 28 | |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 29 | "github.com/golang/protobuf/ptypes" |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 30 | "github.com/opencord/voltha-lib-go/v4/pkg/adapters/adapterif" |
| 31 | "github.com/opencord/voltha-lib-go/v4/pkg/db/kvstore" |
Himani Chawla | c07fda0 | 2020-12-09 16:21:21 +0530 | [diff] [blame] | 32 | "github.com/opencord/voltha-lib-go/v4/pkg/events/eventif" |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 33 | "github.com/opencord/voltha-lib-go/v4/pkg/kafka" |
| 34 | "github.com/opencord/voltha-lib-go/v4/pkg/log" |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 35 | "github.com/opencord/voltha-protos/v4/go/extension" |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 36 | ic "github.com/opencord/voltha-protos/v4/go/inter_container" |
| 37 | "github.com/opencord/voltha-protos/v4/go/openflow_13" |
| 38 | oop "github.com/opencord/voltha-protos/v4/go/openolt" |
| 39 | "github.com/opencord/voltha-protos/v4/go/voltha" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 40 | |
Matteo Scandolo | 761f751 | 2020-11-23 15:52:40 -0800 | [diff] [blame] | 41 | "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 42 | ) |
| 43 | |
| 44 | //OpenONUAC structure holds the ONU core information |
| 45 | type OpenONUAC struct { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 46 | deviceHandlers map[string]*deviceHandler |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 47 | deviceHandlersCreateChan map[string]chan bool //channels for deviceHandler create events |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 48 | lockDeviceHandlersMap sync.RWMutex |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 49 | coreProxy adapterif.CoreProxy |
| 50 | adapterProxy adapterif.AdapterProxy |
Himani Chawla | c07fda0 | 2020-12-09 16:21:21 +0530 | [diff] [blame] | 51 | eventProxy eventif.EventProxy |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 52 | kafkaICProxy kafka.InterContainerProxy |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 53 | kvClient kvstore.Client |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 54 | cm *conf.ConfigManager |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 55 | config *config.AdapterFlags |
| 56 | numOnus int |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 57 | KVStoreAddress string |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 58 | KVStoreType string |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 59 | KVStoreTimeout time.Duration |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 60 | mibTemplatesGenerated map[string]bool |
| 61 | lockMibTemplateGenerated sync.RWMutex |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 62 | exitChannel chan int |
| 63 | HeartbeatCheckInterval time.Duration |
| 64 | HeartbeatFailReportInterval time.Duration |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 65 | AcceptIncrementalEvto bool |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 66 | //GrpcTimeoutInterval time.Duration |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 67 | pSupportedFsms *OmciDeviceFsms |
| 68 | maxTimeoutInterAdapterComm time.Duration |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 69 | maxTimeoutReconciling time.Duration |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 70 | pDownloadManager *adapterDownloadManager |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 71 | metricsEnabled bool |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 72 | mibAuditInterval time.Duration |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 73 | omciTimeout int // in seconds |
Himani Chawla | 075f164 | 2021-03-15 19:23:24 +0530 | [diff] [blame] | 74 | alarmAuditInterval time.Duration |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | //NewOpenONUAC returns a new instance of OpenONU_AC |
| 78 | func NewOpenONUAC(ctx context.Context, kafkaICProxy kafka.InterContainerProxy, |
| 79 | coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy, |
Himani Chawla | c07fda0 | 2020-12-09 16:21:21 +0530 | [diff] [blame] | 80 | eventProxy eventif.EventProxy, kvClient kvstore.Client, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenONUAC { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 81 | var openOnuAc OpenONUAC |
| 82 | openOnuAc.exitChannel = make(chan int, 1) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 83 | openOnuAc.deviceHandlers = make(map[string]*deviceHandler) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 84 | openOnuAc.deviceHandlersCreateChan = make(map[string]chan bool) |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 85 | openOnuAc.lockDeviceHandlersMap = sync.RWMutex{} |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 86 | openOnuAc.kafkaICProxy = kafkaICProxy |
| 87 | openOnuAc.config = cfg |
Matteo Scandolo | f1f39a7 | 2020-11-24 12:08:11 -0800 | [diff] [blame] | 88 | openOnuAc.cm = cm |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 89 | openOnuAc.numOnus = cfg.OnuNumber |
| 90 | openOnuAc.coreProxy = coreProxy |
| 91 | openOnuAc.adapterProxy = adapterProxy |
| 92 | openOnuAc.eventProxy = eventProxy |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 93 | openOnuAc.kvClient = kvClient |
Matteo Scandolo | 127c59d | 2021-01-28 11:31:18 -0800 | [diff] [blame] | 94 | openOnuAc.KVStoreAddress = cfg.KVStoreAddress |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 95 | openOnuAc.KVStoreType = cfg.KVStoreType |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 96 | openOnuAc.KVStoreTimeout = cfg.KVStoreTimeout |
Holger Hildebrandt | 61b24d0 | 2020-11-16 13:36:40 +0000 | [diff] [blame] | 97 | openOnuAc.mibTemplatesGenerated = make(map[string]bool) |
| 98 | openOnuAc.lockMibTemplateGenerated = sync.RWMutex{} |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 99 | openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval |
| 100 | openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 101 | openOnuAc.AcceptIncrementalEvto = cfg.AccIncrEvto |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 102 | openOnuAc.maxTimeoutInterAdapterComm = cfg.MaxTimeoutInterAdapterComm |
Holger Hildebrandt | 38985dc | 2021-02-18 16:25:20 +0000 | [diff] [blame] | 103 | openOnuAc.maxTimeoutReconciling = cfg.MaxTimeoutReconciling |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 104 | //openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval |
Girish Gowdra | af0ad63 | 2021-01-27 13:00:01 -0800 | [diff] [blame] | 105 | openOnuAc.metricsEnabled = cfg.MetricsEnabled |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 106 | openOnuAc.mibAuditInterval = cfg.MibAuditInterval |
Girish Gowdra | 0b23584 | 2021-03-09 13:06:46 -0800 | [diff] [blame] | 107 | // since consumers of OMCI timeout value everywhere in code is in "int seconds", do this useful conversion |
| 108 | openOnuAc.omciTimeout = int(cfg.OmciTimeout.Seconds()) |
Himani Chawla | 075f164 | 2021-03-15 19:23:24 +0530 | [diff] [blame] | 109 | openOnuAc.alarmAuditInterval = cfg.AlarmAuditInterval |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 110 | |
| 111 | openOnuAc.pSupportedFsms = &OmciDeviceFsms{ |
| 112 | "mib-synchronizer": { |
| 113 | //mibSyncFsm, // Implements the MIB synchronization state machine |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 114 | mibDbVolatileDictImpl, // Implements volatile ME MIB database |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 115 | //true, // Advertise events on OpenOMCI event bus |
Holger Hildebrandt | e3677f1 | 2021-02-05 14:50:56 +0000 | [diff] [blame] | 116 | openOnuAc.mibAuditInterval, // Time to wait between MIB audits. 0 to disable audits. |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 117 | // map[string]func() error{ |
| 118 | // "mib-upload": onuDeviceEntry.MibUploadTask, |
| 119 | // "mib-template": onuDeviceEntry.MibTemplateTask, |
| 120 | // "get-mds": onuDeviceEntry.GetMdsTask, |
| 121 | // "mib-audit": onuDeviceEntry.GetMdsTask, |
| 122 | // "mib-resync": onuDeviceEntry.MibResyncTask, |
| 123 | // "mib-reconcile": onuDeviceEntry.MibReconcileTask, |
| 124 | // }, |
| 125 | }, |
| 126 | } |
| 127 | |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 128 | openOnuAc.pDownloadManager = newAdapterDownloadManager(ctx) |
| 129 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 130 | return &openOnuAc |
| 131 | } |
| 132 | |
| 133 | //Start starts (logs) the adapter |
| 134 | func (oo *OpenONUAC) Start(ctx context.Context) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 135 | logger.Info(ctx, "starting-openonu-adapter") |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 136 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 137 | return nil |
| 138 | } |
| 139 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 140 | /* |
| 141 | //stop terminates the session |
| 142 | func (oo *OpenONUAC) stop(ctx context.Context) error { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 143 | logger.Info(ctx,"stopping-device-manager") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 144 | oo.exitChannel <- 1 |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 145 | logger.Info(ctx,"device-manager-stopped") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 146 | return nil |
| 147 | } |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 148 | */ |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 149 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 150 | func (oo *OpenONUAC) addDeviceHandlerToMap(ctx context.Context, agent *deviceHandler) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 151 | oo.lockDeviceHandlersMap.Lock() |
| 152 | defer oo.lockDeviceHandlersMap.Unlock() |
| 153 | if _, exist := oo.deviceHandlers[agent.deviceID]; !exist { |
| 154 | oo.deviceHandlers[agent.deviceID] = agent |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 155 | oo.deviceHandlers[agent.deviceID].start(ctx) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 156 | if _, exist := oo.deviceHandlersCreateChan[agent.deviceID]; exist { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 157 | logger.Debugw(ctx, "deviceHandler created - trigger processing of pending ONU_IND_REQUEST", log.Fields{"device-id": agent.deviceID}) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 158 | oo.deviceHandlersCreateChan[agent.deviceID] <- true |
| 159 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 163 | func (oo *OpenONUAC) deleteDeviceHandlerToMap(agent *deviceHandler) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 164 | oo.lockDeviceHandlersMap.Lock() |
| 165 | defer oo.lockDeviceHandlersMap.Unlock() |
| 166 | delete(oo.deviceHandlers, agent.deviceID) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 167 | delete(oo.deviceHandlersCreateChan, agent.deviceID) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 170 | //getDeviceHandler gets the ONU deviceHandler and may wait until it is created |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 171 | func (oo *OpenONUAC) getDeviceHandler(ctx context.Context, deviceID string, aWait bool) *deviceHandler { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 172 | oo.lockDeviceHandlersMap.Lock() |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 173 | agent, ok := oo.deviceHandlers[deviceID] |
| 174 | if aWait && !ok { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 175 | 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] | 176 | log.Fields{"device-id": deviceID}) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 177 | if _, exist := oo.deviceHandlersCreateChan[deviceID]; !exist { |
| 178 | oo.deviceHandlersCreateChan[deviceID] = make(chan bool, 1) |
| 179 | } |
Girish Gowdra | 7407a4d | 2020-11-12 12:44:53 -0800 | [diff] [blame] | 180 | deviceCreateChan := oo.deviceHandlersCreateChan[deviceID] |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 181 | //keep the read sema short to allow for subsequent write |
| 182 | oo.lockDeviceHandlersMap.Unlock() |
| 183 | // based on concurrent processing the deviceHandler creation may not yet be finished at his point |
| 184 | // so it might be needed to wait here for that event with some timeout |
| 185 | select { |
| 186 | case <-time.After(1 * time.Second): //timer may be discussed ... |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 187 | 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] | 188 | return nil |
Girish Gowdra | 7407a4d | 2020-11-12 12:44:53 -0800 | [diff] [blame] | 189 | case <-deviceCreateChan: |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 190 | logger.Debugw(ctx, "deviceHandler is ready now - continue", log.Fields{"device-id": deviceID}) |
Girish Gowdra | 7407a4d | 2020-11-12 12:44:53 -0800 | [diff] [blame] | 191 | oo.lockDeviceHandlersMap.RLock() |
| 192 | defer oo.lockDeviceHandlersMap.RUnlock() |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 193 | return oo.deviceHandlers[deviceID] |
| 194 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 195 | } |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 196 | oo.lockDeviceHandlersMap.Unlock() |
| 197 | return agent |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 198 | } |
| 199 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 200 | func (oo *OpenONUAC) processInterAdapterONUIndReqMessage(ctx context.Context, msg *ic.InterAdapterMessage) error { |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 201 | msgBody := msg.GetBody() |
| 202 | onuIndication := &oop.OnuIndication{} |
| 203 | if err := ptypes.UnmarshalAny(msgBody, onuIndication); err != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 204 | logger.Warnw(ctx, "onu-ind-request-cannot-unmarshal-msg-body", log.Fields{"error": err}) |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 205 | return err |
| 206 | } |
| 207 | //ToDeviceId should address a DeviceHandler instance |
| 208 | targetDevice := msg.Header.ToDeviceId |
| 209 | |
| 210 | onuOperstate := onuIndication.GetOperState() |
| 211 | waitForDhInstPresent := false |
| 212 | if onuOperstate == "up" { |
| 213 | //Race condition (relevant in BBSIM-environment only): Due to unsynchronized processing of olt-adapter and rw_core, |
| 214 | //ONU_IND_REQUEST msg by olt-adapter could arrive a little bit earlier than rw_core was able to announce the corresponding |
| 215 | //ONU by RPC of Adopt_device(). Therefore it could be necessary to wait with processing of ONU_IND_REQUEST until call of |
| 216 | //Adopt_device() arrived and DeviceHandler instance was created |
| 217 | waitForDhInstPresent = true |
| 218 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 219 | if handler := oo.getDeviceHandler(ctx, targetDevice, waitForDhInstPresent); handler != nil { |
| 220 | logger.Infow(ctx, "onu-ind-request", log.Fields{"device-id": targetDevice, |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 221 | "OnuId": onuIndication.GetOnuId(), |
| 222 | "AdminState": onuIndication.GetAdminState(), "OperState": onuOperstate, |
| 223 | "SNR": onuIndication.GetSerialNumber()}) |
| 224 | |
| 225 | if onuOperstate == "up" { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 226 | return handler.createInterface(ctx, onuIndication) |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 227 | } else if (onuOperstate == "down") || (onuOperstate == "unreachable") { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 228 | return handler.updateInterface(ctx, onuIndication) |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 229 | } else { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 230 | logger.Errorw(ctx, "unknown-onu-ind-request operState", log.Fields{"OnuId": onuIndication.GetOnuId()}) |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 231 | return fmt.Errorf("invalidOperState: %s, %s", onuOperstate, targetDevice) |
| 232 | } |
| 233 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 234 | logger.Warnw(ctx, "no handler found for received onu-ind-request", log.Fields{ |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 235 | "msgToDeviceId": targetDevice}) |
| 236 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", targetDevice)) |
| 237 | } |
| 238 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 239 | // Adapter interface required methods ############## begin ######### |
| 240 | // ################################################################# |
| 241 | |
| 242 | // for original content compare: (needs according deviceHandler methods) |
| 243 | // /voltha-openolt-adapter/adaptercore/openolt.go |
| 244 | |
| 245 | // Adopt_device creates a new device handler if not present already and then adopts the device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 246 | func (oo *OpenONUAC) Adopt_device(ctx context.Context, device *voltha.Device) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 247 | if device == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 248 | logger.Warn(ctx, "voltha-device-is-nil") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 249 | return errors.New("nil-device") |
| 250 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 251 | logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 252 | var handler *deviceHandler |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 253 | if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil { |
| 254 | handler := newDeviceHandler(ctx, oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 255 | oo.addDeviceHandlerToMap(ctx, handler) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 256 | go handler.adoptOrReconcileDevice(ctx, device) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 257 | // Launch the creation of the device topic |
| 258 | // go oo.createDeviceTopic(device) |
| 259 | } |
| 260 | return nil |
| 261 | } |
| 262 | |
| 263 | //Get_ofp_device_info returns OFP information for the given device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 264 | func (oo *OpenONUAC) Get_ofp_device_info(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) { |
| 265 | logger.Errorw(ctx, "device-handler-not-set", log.Fields{"device-id": device.Id}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 266 | return nil, fmt.Errorf("device-handler-not-set %s", device.Id) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | //Get_ofp_port_info returns OFP port information for the given device |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 270 | //200630: method removed as per [VOL-3202]: OF port info is now to be delivered within UniPort create |
| 271 | // cmp changes in onu_uni_port.go::CreateVolthaPort() |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 272 | |
| 273 | //Process_inter_adapter_message sends messages to a target device (between adapters) |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 274 | func (oo *OpenONUAC) Process_inter_adapter_message(ctx context.Context, msg *ic.InterAdapterMessage) error { |
| 275 | logger.Debugw(ctx, "Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id, |
Holger Hildebrandt | 80129db | 2020-11-23 10:49:32 +0000 | [diff] [blame] | 276 | "msgProxyDeviceId": msg.Header.ProxyDeviceId, "msgToDeviceId": msg.Header.ToDeviceId, "Type": msg.Header.Type}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 277 | |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 278 | if msg.Header.Type == ic.InterAdapterMessageType_ONU_IND_REQUEST { |
| 279 | // we have to handle ONU_IND_REQUEST already here - see comments in processInterAdapterONUIndReqMessage() |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 280 | return oo.processInterAdapterONUIndReqMessage(ctx, msg) |
Holger Hildebrandt | 6c1fb0a | 2020-11-25 15:41:01 +0000 | [diff] [blame] | 281 | } |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 282 | //ToDeviceId should address a DeviceHandler instance |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 283 | targetDevice := msg.Header.ToDeviceId |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 284 | if handler := oo.getDeviceHandler(ctx, targetDevice, false); handler != nil { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 285 | /* 200724: modification towards synchronous implementation - possible errors within processing shall be |
| 286 | * in the accordingly delayed response, some timing effect might result in Techprofile processing for multiple UNI's |
| 287 | */ |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 288 | return handler.processInterAdapterMessage(ctx, msg) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 289 | /* so far the processing has been in background with according commented error treatment restrictions: |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 290 | go handler.ProcessInterAdapterMessage(msg) |
| 291 | // error treatment might be more sophisticated |
| 292 | // by now let's just accept the message on 'communication layer' |
| 293 | // message content problems have to be evaluated then in the handler |
| 294 | // and are by now not reported to the calling party (to force what reaction there?) |
| 295 | return nil |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 296 | */ |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 297 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 298 | logger.Warnw(ctx, "no handler found for received Inter-Proxy-message", log.Fields{ |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 299 | "msgToDeviceId": targetDevice}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 300 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", targetDevice)) |
| 301 | } |
| 302 | |
| 303 | //Adapter_descriptor not implemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 304 | func (oo *OpenONUAC) Adapter_descriptor(ctx context.Context) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 305 | return errors.New("unImplemented") |
| 306 | } |
| 307 | |
| 308 | //Device_types unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 309 | func (oo *OpenONUAC) Device_types(ctx context.Context) (*voltha.DeviceTypes, error) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 310 | return nil, errors.New("unImplemented") |
| 311 | } |
| 312 | |
| 313 | //Health returns unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 314 | func (oo *OpenONUAC) Health(ctx context.Context) (*voltha.HealthStatus, error) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 315 | return nil, errors.New("unImplemented") |
| 316 | } |
| 317 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 318 | //Reconcile_device is called once when the adapter needs to re-create device - usually on core restart |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 319 | func (oo *OpenONUAC) Reconcile_device(ctx context.Context, device *voltha.Device) error { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 320 | if device == nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 321 | logger.Warn(ctx, "reconcile-device-voltha-device-is-nil") |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 322 | return errors.New("nil-device") |
| 323 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 324 | logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 325 | var handler *deviceHandler |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 326 | if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil { |
| 327 | handler := newDeviceHandler(ctx, oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 328 | oo.addDeviceHandlerToMap(ctx, handler) |
| 329 | handler.device = device |
Holger Hildebrandt | be52384 | 2021-03-10 10:47:18 +0000 | [diff] [blame] | 330 | handler.startReconciling(ctx, false) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 331 | go handler.adoptOrReconcileDevice(ctx, handler.device) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 332 | // reconcilement will be continued after onu-device entry is added |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 333 | } else { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 334 | return fmt.Errorf(fmt.Sprintf("device-already-reconciled-or-active-%s", device.Id)) |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 335 | } |
| 336 | return nil |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | //Abandon_device unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 340 | func (oo *OpenONUAC) Abandon_device(ctx context.Context, device *voltha.Device) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 341 | return errors.New("unImplemented") |
| 342 | } |
| 343 | |
| 344 | //Disable_device disables the given device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 345 | func (oo *OpenONUAC) Disable_device(ctx context.Context, device *voltha.Device) error { |
| 346 | logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id}) |
| 347 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
| 348 | go handler.disableDevice(ctx, device) |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 349 | return nil |
| 350 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 351 | logger.Warnw(ctx, "no handler found for device-disable", log.Fields{"device-id": device.Id}) |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 352 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 355 | //Reenable_device enables the onu device after disable |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 356 | func (oo *OpenONUAC) Reenable_device(ctx context.Context, device *voltha.Device) error { |
| 357 | logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id}) |
| 358 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
| 359 | go handler.reEnableDevice(ctx, device) |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 360 | return nil |
| 361 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 362 | logger.Warnw(ctx, "no handler found for device-reenable", log.Fields{"device-id": device.Id}) |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 363 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | //Reboot_device reboots the given device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 367 | func (oo *OpenONUAC) Reboot_device(ctx context.Context, device *voltha.Device) error { |
| 368 | logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id}) |
| 369 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 370 | go handler.rebootDevice(ctx, true, device) //reboot request with device checking |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 371 | return nil |
| 372 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 373 | logger.Warnw(ctx, "no handler found for device-reboot", log.Fields{"device-id": device.Id}) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 374 | return fmt.Errorf(fmt.Sprintf("handler-not-found-#{device.Id}")) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 377 | //Self_test_device unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 378 | func (oo *OpenONUAC) Self_test_device(ctx context.Context, device *voltha.Device) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 379 | return errors.New("unImplemented") |
| 380 | } |
| 381 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 382 | // Delete_device deletes the given device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 383 | func (oo *OpenONUAC) Delete_device(ctx context.Context, device *voltha.Device) error { |
| 384 | logger.Infow(ctx, "delete-device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber}) |
| 385 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 386 | var errorsList []error |
Holger Hildebrandt | ff05b68 | 2021-03-16 15:02:05 +0000 | [diff] [blame] | 387 | |
| 388 | handler.mutexDeletionInProgressFlag.Lock() |
| 389 | handler.deletionInProgress = true |
| 390 | handler.mutexDeletionInProgressFlag.Unlock() |
| 391 | |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 392 | if err := handler.deleteDevicePersistencyData(ctx); err != nil { |
| 393 | errorsList = append(errorsList, err) |
| 394 | } |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 395 | select { |
| 396 | case handler.stopCollector <- true: // stop the metric collector routine |
| 397 | logger.Debugw(ctx, "sent stop signal to metric collector routine", log.Fields{"device-id": device.Id}) |
| 398 | default: |
| 399 | logger.Warnw(ctx, "metric collector routine not waiting on stop signal", log.Fields{"device-id": device.Id}) |
| 400 | } |
| 401 | select { |
| 402 | case handler.stopAlarmManager <- true: //stop the alarm manager. |
| 403 | logger.Debugw(ctx, "sent stop signal to alarm manager", log.Fields{"device-id": device.Id}) |
| 404 | default: |
| 405 | logger.Warnw(ctx, "alarm manager not waiting on stop signal", log.Fields{"device-id": device.Id}) |
| 406 | } |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 407 | if handler.pOnuMetricsMgr != nil { |
| 408 | if err := handler.pOnuMetricsMgr.clearAllPmData(ctx); err != nil { |
| 409 | errorsList = append(errorsList, err) |
| 410 | } |
| 411 | } |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 412 | select { |
| 413 | case handler.pSelfTestHdlr.stopSelfTestModule <- true: |
| 414 | logger.Debugw(ctx, "sent stop signal to self test handler module", log.Fields{"device-id": device.Id}) |
| 415 | default: |
| 416 | logger.Warnw(ctx, "self test handler module not waiting on stop signal", log.Fields{"device-id": device.Id}) |
| 417 | } |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 418 | //don't leave any garbage - even in error case |
| 419 | oo.deleteDeviceHandlerToMap(handler) |
Girish Gowdra | 0e53364 | 2021-03-02 22:02:51 -0800 | [diff] [blame] | 420 | if len(errorsList) > 0 { |
| 421 | logger.Errorw(ctx, "one-or-more-error-during-device-delete", log.Fields{"device-id": device.Id}) |
| 422 | return fmt.Errorf("one-or-more-error-during-device-delete, errors:%v", errorsList) |
| 423 | } |
| 424 | return nil |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 425 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 426 | logger.Warnw(ctx, "no handler found for device-deletion", log.Fields{"device-id": device.Id}) |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame] | 427 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | //Get_device_details unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 431 | func (oo *OpenONUAC) Get_device_details(ctx context.Context, device *voltha.Device) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 432 | return errors.New("unImplemented") |
| 433 | } |
| 434 | |
| 435 | //Update_flows_bulk returns |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 436 | func (oo *OpenONUAC) Update_flows_bulk(ctx context.Context, device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 437 | return errors.New("unImplemented") |
| 438 | } |
| 439 | |
| 440 | //Update_flows_incrementally updates (add/remove) the flows on a given device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 441 | func (oo *OpenONUAC) Update_flows_incrementally(ctx context.Context, device *voltha.Device, |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 442 | flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 443 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 444 | logger.Infow(ctx, "update-flows-incrementally", log.Fields{"device-id": device.Id}) |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 445 | //flow config is relayed to handler even if the device might be in some 'inactive' state |
| 446 | // let the handler or related FSM's decide, what to do with the modified flow state info |
| 447 | // 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] | 448 | |
| 449 | // 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] | 450 | // but processing is continued for flowUpdate possibly also set in the request |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 451 | if groups.ToAdd != nil && groups.ToAdd.Items != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 452 | logger.Warnw(ctx, "Update-flow-incr: group add not supported (ignored)", log.Fields{"device-id": device.Id}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 453 | } |
| 454 | if groups.ToRemove != nil && groups.ToRemove.Items != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 455 | logger.Warnw(ctx, "Update-flow-incr: group remove not supported (ignored)", log.Fields{"device-id": device.Id}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 456 | } |
| 457 | if groups.ToUpdate != nil && groups.ToUpdate.Items != nil { |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 458 | logger.Warnw(ctx, "Update-flow-incr: group update not supported (ignored)", log.Fields{"device-id": device.Id}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 459 | } |
| 460 | |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 461 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
| 462 | err := handler.FlowUpdateIncremental(ctx, flows, groups, flowMetadata) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 463 | return err |
| 464 | } |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 465 | logger.Warnw(ctx, "no handler found for incremental flow update", log.Fields{"device-id": device.Id}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 466 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | //Update_pm_config returns PmConfigs nil or error |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 470 | func (oo *OpenONUAC) Update_pm_config(ctx context.Context, device *voltha.Device, pmConfigs *voltha.PmConfigs) error { |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 471 | logger.Infow(ctx, "update-pm-config", log.Fields{"device-id": device.Id}) |
| 472 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 473 | return handler.updatePmConfig(ctx, pmConfigs) |
Girish Gowdra | e09a620 | 2021-01-12 18:10:59 -0800 | [diff] [blame] | 474 | } |
Girish Gowdra | 5a7c492 | 2021-01-22 18:33:41 -0800 | [diff] [blame] | 475 | logger.Warnw(ctx, "no handler found for update-pm-config", log.Fields{"device-id": device.Id}) |
| 476 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | //Receive_packet_out sends packet out to the device |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 480 | func (oo *OpenONUAC) Receive_packet_out(ctx context.Context, deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 481 | return errors.New("unImplemented") |
| 482 | } |
| 483 | |
| 484 | //Suppress_event unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 485 | func (oo *OpenONUAC) Suppress_event(ctx context.Context, filter *voltha.EventFilter) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 486 | return errors.New("unImplemented") |
| 487 | } |
| 488 | |
| 489 | //Unsuppress_event unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 490 | func (oo *OpenONUAC) Unsuppress_event(ctx context.Context, filter *voltha.EventFilter) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 491 | return errors.New("unImplemented") |
| 492 | } |
| 493 | |
Andrea Campanella | 71e546a | 2021-02-26 11:09:33 +0100 | [diff] [blame] | 494 | //Download_image requests downloading some image according to indications as given in request |
| 495 | //The ImageDownload needs to be called `request`due to library reflection requirements |
| 496 | func (oo *OpenONUAC) Download_image(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 497 | if request != nil && (*request).Name != "" { |
| 498 | if !oo.pDownloadManager.imageExists(ctx, request) { |
| 499 | logger.Debugw(ctx, "start image download", log.Fields{"image-description": request}) |
| 500 | // Download_image is not supposed to be blocking, anyway let's call the DownloadManager still synchronously to detect 'fast' problems |
| 501 | // the download itself is later done in background |
| 502 | err := oo.pDownloadManager.startDownload(ctx, request) |
| 503 | return request, err |
| 504 | } |
| 505 | // image already exists |
| 506 | logger.Debugw(ctx, "image already downloaded", log.Fields{"image-description": request}) |
| 507 | return request, nil |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 508 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 509 | return request, errors.New("invalid image definition") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | //Get_image_download_status unimplemented |
Andrea Campanella | 71e546a | 2021-02-26 11:09:33 +0100 | [diff] [blame] | 513 | //The ImageDownload needs to be called `request`due to library reflection requirements |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 514 | func (oo *OpenONUAC) Get_image_download_status(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 515 | return nil, errors.New("unImplemented") |
| 516 | } |
| 517 | |
| 518 | //Cancel_image_download unimplemented |
Andrea Campanella | 71e546a | 2021-02-26 11:09:33 +0100 | [diff] [blame] | 519 | //The ImageDownload needs to be called `request`due to library reflection requirements |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 520 | func (oo *OpenONUAC) Cancel_image_download(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 521 | return nil, errors.New("unImplemented") |
| 522 | } |
| 523 | |
mpagenko | 057889c | 2021-01-21 16:51:58 +0000 | [diff] [blame] | 524 | //Activate_image_update requests downloading some Onu Software image to the INU via OMCI |
Andrea Campanella | 71e546a | 2021-02-26 11:09:33 +0100 | [diff] [blame] | 525 | // according to indications as given in request and on success activate the image on the ONU |
| 526 | //The ImageDownload needs to be called `request`due to library reflection requirements |
| 527 | func (oo *OpenONUAC) Activate_image_update(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 528 | if request != nil && (*request).Name != "" { |
| 529 | if oo.pDownloadManager.imageLocallyDownloaded(ctx, request) { |
| 530 | if handler := oo.getDeviceHandler(ctx, device.Id, false); handler != nil { |
| 531 | logger.Debugw(ctx, "image download on omci requested", log.Fields{ |
| 532 | "image-description": request, "device-id": device.Id}) |
| 533 | err := handler.doOnuSwUpgrade(ctx, request, oo.pDownloadManager) |
| 534 | return request, err |
| 535 | } |
| 536 | logger.Warnw(ctx, "no handler found for image activation", log.Fields{"device-id": device.Id}) |
| 537 | return request, fmt.Errorf(fmt.Sprintf("handler-not-found - device-id: %s", device.Id)) |
mpagenko | 057889c | 2021-01-21 16:51:58 +0000 | [diff] [blame] | 538 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 539 | logger.Debugw(ctx, "image not yet downloaded on activate request", log.Fields{"image-description": request}) |
| 540 | return request, fmt.Errorf(fmt.Sprintf("image-not-yet-downloaded - device-id: %s", device.Id)) |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 541 | } |
mpagenko | 15ff4a5 | 2021-03-02 10:09:20 +0000 | [diff] [blame] | 542 | return request, errors.New("invalid image definition") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | //Revert_image_update unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 546 | func (oo *OpenONUAC) Revert_image_update(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 547 | return nil, errors.New("unImplemented") |
| 548 | } |
| 549 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 550 | // Enable_port to Enable PON/NNI interface - seems not to be used/required according to python code |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 551 | func (oo *OpenONUAC) Enable_port(ctx context.Context, deviceID string, port *voltha.Port) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 552 | return errors.New("unImplemented") |
| 553 | } |
| 554 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 555 | // Disable_port to Disable pon/nni interface - seems not to be used/required according to python code |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 556 | func (oo *OpenONUAC) Disable_port(ctx context.Context, deviceID string, port *voltha.Port) error { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 557 | return errors.New("unImplemented") |
| 558 | } |
| 559 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 560 | //Child_device_lost - unimplemented |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 561 | //needed for if update >= 3.1.x |
Matteo Scandolo | 3f2bdc8 | 2021-03-18 18:18:22 -0700 | [diff] [blame] | 562 | func (oo *OpenONUAC) Child_device_lost(ctx context.Context, device *voltha.Device) error { |
Matteo Scandolo | 2e6f1e3 | 2020-04-15 11:28:45 -0700 | [diff] [blame] | 563 | return errors.New("unImplemented") |
| 564 | } |
| 565 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 566 | // Start_omci_test unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 567 | func (oo *OpenONUAC) Start_omci_test(ctx context.Context, device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) { |
Matteo Scandolo | 2e6f1e3 | 2020-04-15 11:28:45 -0700 | [diff] [blame] | 568 | return nil, errors.New("unImplemented") |
| 569 | } |
| 570 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 571 | // Get_ext_value - unimplemented |
dbainbri | 4d3a0dc | 2020-12-02 00:33:42 +0000 | [diff] [blame] | 572 | func (oo *OpenONUAC) Get_ext_value(ctx context.Context, deviceID string, device *voltha.Device, valueparam voltha.ValueType_Type) (*voltha.ReturnValues, error) { |
Matteo Scandolo | d132c0e | 2020-04-24 17:06:25 -0700 | [diff] [blame] | 573 | return nil, errors.New("unImplemented") |
| 574 | } |
| 575 | |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 576 | //Single_get_value_request handles the core request to retrieve uni status |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 577 | func (oo *OpenONUAC) Single_get_value_request(ctx context.Context, request extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) { |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 578 | logger.Infow(ctx, "Single_get_value_request", log.Fields{"request": request}) |
| 579 | |
| 580 | if handler := oo.getDeviceHandler(ctx, request.TargetId, false); handler != nil { |
| 581 | switch reqType := request.GetRequest().GetRequest().(type) { |
| 582 | case *extension.GetValueRequest_UniInfo: |
| 583 | return handler.getUniPortStatus(ctx, reqType.UniInfo), nil |
Girish Gowdra | 6afb56a | 2021-04-27 17:47:57 -0700 | [diff] [blame] | 584 | case *extension.GetValueRequest_OnuOpticalInfo: |
| 585 | commChan := make(chan Message) |
| 586 | respChan := make(chan extension.SingleGetValueResponse) |
| 587 | // Initiate the self test request |
| 588 | if err := handler.pSelfTestHdlr.SelfTestRequestStart(ctx, request, commChan, respChan); err != nil { |
| 589 | return &extension.SingleGetValueResponse{ |
| 590 | Response: &extension.GetValueResponse{ |
| 591 | Status: extension.GetValueResponse_ERROR, |
| 592 | ErrReason: extension.GetValueResponse_INTERNAL_ERROR, |
| 593 | }, |
| 594 | }, err |
| 595 | } |
| 596 | // The timeout handling is already implemented in omci_self_test_handler module |
| 597 | resp := <-respChan |
| 598 | return &resp, nil |
kesavand | fdf7763 | 2021-01-26 23:40:33 -0500 | [diff] [blame] | 599 | default: |
| 600 | return postUniStatusErrResponse(extension.GetValueResponse_UNSUPPORTED), nil |
| 601 | |
| 602 | } |
| 603 | } |
| 604 | logger.Errorw(ctx, "Single_get_value_request failed ", log.Fields{"request": request}) |
| 605 | return postUniStatusErrResponse(extension.GetValueResponse_INVALID_DEVICE_ID), nil |
mpagenko | c8bba41 | 2021-01-15 15:38:44 +0000 | [diff] [blame] | 606 | } |
| 607 | |
mpagenko | 8314427 | 2021-04-27 10:06:22 +0000 | [diff] [blame] | 608 | //if update >= 4.3.0 |
| 609 | |
| 610 | // Download_onu_image downloads (and optionally activates and commits) the indicated ONU image to the requested ONU(s) |
| 611 | // if the image is not yet present on the adapter it has to be automatically downloaded |
| 612 | func (oo *OpenONUAC) Download_onu_image(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) { |
| 613 | return nil, errors.New("unImplemented") |
| 614 | } |
| 615 | |
| 616 | // Get_onu_image_status delivers the adapter-related information about the download/activation/commitment |
| 617 | // status for the requested image |
| 618 | func (oo *OpenONUAC) Get_onu_image_status(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 619 | return nil, errors.New("unImplemented") |
| 620 | } |
| 621 | |
| 622 | // Abort_onu_image_upgrade stops the actual download/activation/commitment process (on next possibly step) |
| 623 | func (oo *OpenONUAC) Abort_onu_image_upgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 624 | return nil, errors.New("unImplemented") |
| 625 | } |
| 626 | |
| 627 | // Get_onu_images retrieves the ONU SW image status information via OMCI |
| 628 | func (oo *OpenONUAC) Get_onu_images(ctx context.Context, deviceID string) (*voltha.OnuImages, error) { |
| 629 | return nil, errors.New("unImplemented") |
| 630 | } |
| 631 | |
| 632 | // Activate_onu_image initiates the activation of the image for the requested ONU(s) |
| 633 | // precondition: image downloaded and not yet activated |
| 634 | func (oo *OpenONUAC) Activate_onu_image(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 635 | return nil, errors.New("unImplemented") |
| 636 | } |
| 637 | |
| 638 | // Commit_onu_image enforces the commitment of the image for the requested ONU(s) |
| 639 | // precondition: image activated and not yet committed |
| 640 | func (oo *OpenONUAC) Commit_onu_image(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 641 | return nil, errors.New("unImplemented") |
| 642 | } |
| 643 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 644 | // Adapter interface required methods ################ end ######### |
| 645 | // ################################################################# |