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 | |
| 27 | "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif" |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 28 | "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 29 | "github.com/opencord/voltha-lib-go/v3/pkg/kafka" |
| 30 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 31 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 32 | "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 33 | "github.com/opencord/voltha-protos/v3/go/voltha" |
| 34 | |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 35 | "test.internal/openadapter/internal/pkg/config" |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 36 | ) |
| 37 | |
| 38 | //OpenONUAC structure holds the ONU core information |
| 39 | type OpenONUAC struct { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 40 | deviceHandlers map[string]*deviceHandler |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 41 | deviceHandlersCreateChan map[string]chan bool //channels for deviceHandler create events |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 42 | coreProxy adapterif.CoreProxy |
| 43 | adapterProxy adapterif.AdapterProxy |
| 44 | eventProxy adapterif.EventProxy |
| 45 | kafkaICProxy kafka.InterContainerProxy |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 46 | kvClient kvstore.Client |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 47 | config *config.AdapterFlags |
| 48 | numOnus int |
| 49 | KVStoreHost string |
| 50 | KVStorePort int |
| 51 | KVStoreType string |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 52 | KVStoreTimeout time.Duration |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 53 | exitChannel chan int |
| 54 | HeartbeatCheckInterval time.Duration |
| 55 | HeartbeatFailReportInterval time.Duration |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 56 | AcceptIncrementalEvto bool |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 57 | //GrpcTimeoutInterval time.Duration |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 58 | lockDeviceHandlersMap sync.RWMutex |
| 59 | pSupportedFsms *OmciDeviceFsms |
| 60 | maxTimeoutInterAdapterComm time.Duration |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | //NewOpenONUAC returns a new instance of OpenONU_AC |
| 64 | func NewOpenONUAC(ctx context.Context, kafkaICProxy kafka.InterContainerProxy, |
| 65 | coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy, |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 66 | eventProxy adapterif.EventProxy, kvClient kvstore.Client, cfg *config.AdapterFlags) *OpenONUAC { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 67 | var openOnuAc OpenONUAC |
| 68 | openOnuAc.exitChannel = make(chan int, 1) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 69 | openOnuAc.deviceHandlers = make(map[string]*deviceHandler) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 70 | openOnuAc.deviceHandlersCreateChan = make(map[string]chan bool) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 71 | openOnuAc.kafkaICProxy = kafkaICProxy |
| 72 | openOnuAc.config = cfg |
| 73 | openOnuAc.numOnus = cfg.OnuNumber |
| 74 | openOnuAc.coreProxy = coreProxy |
| 75 | openOnuAc.adapterProxy = adapterProxy |
| 76 | openOnuAc.eventProxy = eventProxy |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 77 | openOnuAc.kvClient = kvClient |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 78 | openOnuAc.KVStoreHost = cfg.KVStoreHost |
| 79 | openOnuAc.KVStorePort = cfg.KVStorePort |
| 80 | openOnuAc.KVStoreType = cfg.KVStoreType |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 81 | openOnuAc.KVStoreTimeout = cfg.KVStoreTimeout |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 82 | openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval |
| 83 | openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 84 | openOnuAc.AcceptIncrementalEvto = cfg.AccIncrEvto |
Himani Chawla | d96df18 | 2020-09-28 11:12:02 +0530 | [diff] [blame] | 85 | openOnuAc.maxTimeoutInterAdapterComm = cfg.MaxTimeoutInterAdapterComm |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 86 | //openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval |
| 87 | openOnuAc.lockDeviceHandlersMap = sync.RWMutex{} |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 88 | |
| 89 | openOnuAc.pSupportedFsms = &OmciDeviceFsms{ |
| 90 | "mib-synchronizer": { |
| 91 | //mibSyncFsm, // Implements the MIB synchronization state machine |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 92 | mibDbVolatileDictImpl, // Implements volatile ME MIB database |
Himani Chawla | 4d90833 | 2020-08-31 12:30:20 +0530 | [diff] [blame] | 93 | //true, // Advertise events on OpenOMCI event bus |
| 94 | cMibAuditDelayImpl, // Time to wait between MIB audits. 0 to disable audits. |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 95 | // map[string]func() error{ |
| 96 | // "mib-upload": onuDeviceEntry.MibUploadTask, |
| 97 | // "mib-template": onuDeviceEntry.MibTemplateTask, |
| 98 | // "get-mds": onuDeviceEntry.GetMdsTask, |
| 99 | // "mib-audit": onuDeviceEntry.GetMdsTask, |
| 100 | // "mib-resync": onuDeviceEntry.MibResyncTask, |
| 101 | // "mib-reconcile": onuDeviceEntry.MibReconcileTask, |
| 102 | // }, |
| 103 | }, |
| 104 | } |
| 105 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 106 | return &openOnuAc |
| 107 | } |
| 108 | |
| 109 | //Start starts (logs) the adapter |
| 110 | func (oo *OpenONUAC) Start(ctx context.Context) error { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 111 | logger.Info("starting-openonu-adapter") |
| 112 | logger.Info("openonu-adapter-started") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 113 | return nil |
| 114 | } |
| 115 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 116 | /* |
| 117 | //stop terminates the session |
| 118 | func (oo *OpenONUAC) stop(ctx context.Context) error { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 119 | logger.Info("stopping-device-manager") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 120 | oo.exitChannel <- 1 |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 121 | logger.Info("device-manager-stopped") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 122 | return nil |
| 123 | } |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 124 | */ |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 125 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 126 | func (oo *OpenONUAC) addDeviceHandlerToMap(ctx context.Context, agent *deviceHandler) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 127 | oo.lockDeviceHandlersMap.Lock() |
| 128 | defer oo.lockDeviceHandlersMap.Unlock() |
| 129 | if _, exist := oo.deviceHandlers[agent.deviceID]; !exist { |
| 130 | oo.deviceHandlers[agent.deviceID] = agent |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 131 | oo.deviceHandlers[agent.deviceID].start(ctx) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 132 | if _, exist := oo.deviceHandlersCreateChan[agent.deviceID]; exist { |
| 133 | logger.Debugw("deviceHandler created - trigger processing of pending ONU_IND_REQUEST", log.Fields{"device-id": agent.deviceID}) |
| 134 | oo.deviceHandlersCreateChan[agent.deviceID] <- true |
| 135 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 139 | func (oo *OpenONUAC) deleteDeviceHandlerToMap(agent *deviceHandler) { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 140 | oo.lockDeviceHandlersMap.Lock() |
| 141 | defer oo.lockDeviceHandlersMap.Unlock() |
| 142 | delete(oo.deviceHandlers, agent.deviceID) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 143 | delete(oo.deviceHandlersCreateChan, agent.deviceID) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 146 | //getDeviceHandler gets the ONU deviceHandler and may wait until it is created |
| 147 | func (oo *OpenONUAC) getDeviceHandler(deviceID string, aWait bool) *deviceHandler { |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 148 | oo.lockDeviceHandlersMap.Lock() |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 149 | agent, ok := oo.deviceHandlers[deviceID] |
| 150 | if aWait && !ok { |
| 151 | logger.Debugw("deviceHandler not present - wait for creation or timeout", log.Fields{"device-id": deviceID}) |
| 152 | if _, exist := oo.deviceHandlersCreateChan[deviceID]; !exist { |
| 153 | oo.deviceHandlersCreateChan[deviceID] = make(chan bool, 1) |
| 154 | } |
| 155 | //keep the read sema short to allow for subsequent write |
| 156 | oo.lockDeviceHandlersMap.Unlock() |
| 157 | // based on concurrent processing the deviceHandler creation may not yet be finished at his point |
| 158 | // so it might be needed to wait here for that event with some timeout |
| 159 | select { |
| 160 | case <-time.After(1 * time.Second): //timer may be discussed ... |
| 161 | logger.Warnw("No valid deviceHandler created after max WaitTime", log.Fields{"device-id": deviceID}) |
| 162 | return nil |
| 163 | case <-oo.deviceHandlersCreateChan[deviceID]: |
| 164 | logger.Debugw("deviceHandler is ready now - continue", log.Fields{"device-id": deviceID}) |
| 165 | // if written now, we can return the written value without sema |
| 166 | return oo.deviceHandlers[deviceID] |
| 167 | } |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 168 | } |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 169 | oo.lockDeviceHandlersMap.Unlock() |
| 170 | return agent |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | // Adapter interface required methods ############## begin ######### |
| 174 | // ################################################################# |
| 175 | |
| 176 | // for original content compare: (needs according deviceHandler methods) |
| 177 | // /voltha-openolt-adapter/adaptercore/openolt.go |
| 178 | |
| 179 | // Adopt_device creates a new device handler if not present already and then adopts the device |
| 180 | func (oo *OpenONUAC) Adopt_device(device *voltha.Device) error { |
| 181 | if device == nil { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 182 | logger.Warn("voltha-device-is-nil") |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 183 | return errors.New("nil-device") |
| 184 | } |
| 185 | ctx := context.Background() |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 186 | logger.Infow("adopt-device", log.Fields{"device-id": device.Id}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 187 | var handler *deviceHandler |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 188 | if handler = oo.getDeviceHandler(device.Id, false); handler == nil { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 189 | handler := newDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 190 | oo.addDeviceHandlerToMap(ctx, handler) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 191 | go handler.adoptOrReconcileDevice(ctx, device) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 192 | // Launch the creation of the device topic |
| 193 | // go oo.createDeviceTopic(device) |
| 194 | } |
| 195 | return nil |
| 196 | } |
| 197 | |
| 198 | //Get_ofp_device_info returns OFP information for the given device |
| 199 | func (oo *OpenONUAC) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 200 | logger.Errorw("device-handler-not-set", log.Fields{"device-id": device.Id}) |
Andrea Campanella | 6515c58 | 2020-10-05 11:25:00 +0200 | [diff] [blame] | 201 | return nil, fmt.Errorf("device-handler-not-set %s", device.Id) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | //Get_ofp_port_info returns OFP port information for the given device |
mpagenko | af80163 | 2020-07-03 10:00:42 +0000 | [diff] [blame] | 205 | //200630: method removed as per [VOL-3202]: OF port info is now to be delivered within UniPort create |
| 206 | // cmp changes in onu_uni_port.go::CreateVolthaPort() |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 207 | |
| 208 | //Process_inter_adapter_message sends messages to a target device (between adapters) |
| 209 | func (oo *OpenONUAC) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error { |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 210 | logger.Debugw("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id, |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 211 | "msgProxyDeviceId": msg.Header.ProxyDeviceId, "msgToDeviceId": msg.Header.ToDeviceId}) |
| 212 | |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 213 | var waitForDhInstPresent bool |
| 214 | //ToDeviceId should address a DeviceHandler instance |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 215 | targetDevice := msg.Header.ToDeviceId |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 216 | // As a workaround this handling is only required for the OnuIndication with OperState=Up event. |
| 217 | // But we live without that further check and use this processing also for OperState down/unreachable events to avoid |
| 218 | // the deeper message processing at this stage. Should do no harm on the other events (except for run time) |
| 219 | if msg.Header.Type != ic.InterAdapterMessageType_ONU_IND_REQUEST { |
| 220 | waitForDhInstPresent = false |
| 221 | } else { |
| 222 | //Race condition (relevant in BBSIM-environment only): Due to unsynchronized processing of olt-adapter and rw_core, |
| 223 | //ONU_IND_REQUEST msg by olt-adapter could arrive a little bit earlier than rw_core was able to announce the corresponding |
| 224 | //ONU by RPC of Adopt_device() |
| 225 | logger.Debugw("ONU_IND_REQUEST - potentially wait until DeviceHandler instance is created", log.Fields{"device-id": targetDevice}) |
| 226 | waitForDhInstPresent = true |
| 227 | } |
| 228 | if handler := oo.getDeviceHandler(targetDevice, waitForDhInstPresent); handler != nil { |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 229 | /* 200724: modification towards synchronous implementation - possible errors within processing shall be |
| 230 | * in the accordingly delayed response, some timing effect might result in Techprofile processing for multiple UNI's |
| 231 | */ |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 232 | return handler.processInterAdapterMessage(msg) |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 233 | /* 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] | 234 | go handler.ProcessInterAdapterMessage(msg) |
| 235 | // error treatment might be more sophisticated |
| 236 | // by now let's just accept the message on 'communication layer' |
| 237 | // message content problems have to be evaluated then in the handler |
| 238 | // and are by now not reported to the calling party (to force what reaction there?) |
| 239 | return nil |
mpagenko | 1cc3cb4 | 2020-07-27 15:24:38 +0000 | [diff] [blame] | 240 | */ |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 241 | } |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 242 | logger.Warnw("no handler found for received Inter-Proxy-message", log.Fields{ |
| 243 | "msgToDeviceId": targetDevice}) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 244 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", targetDevice)) |
| 245 | } |
| 246 | |
| 247 | //Adapter_descriptor not implemented |
| 248 | func (oo *OpenONUAC) Adapter_descriptor() error { |
| 249 | return errors.New("unImplemented") |
| 250 | } |
| 251 | |
| 252 | //Device_types unimplemented |
| 253 | func (oo *OpenONUAC) Device_types() (*voltha.DeviceTypes, error) { |
| 254 | return nil, errors.New("unImplemented") |
| 255 | } |
| 256 | |
| 257 | //Health returns unimplemented |
| 258 | func (oo *OpenONUAC) Health() (*voltha.HealthStatus, error) { |
| 259 | return nil, errors.New("unImplemented") |
| 260 | } |
| 261 | |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 262 | //Reconcile_device is called once when the adapter needs to re-create device - usually on core restart |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 263 | func (oo *OpenONUAC) Reconcile_device(device *voltha.Device) error { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 264 | if device == nil { |
| 265 | logger.Warn("voltha-device-is-nil") |
| 266 | return errors.New("nil-device") |
| 267 | } |
| 268 | ctx := context.Background() |
| 269 | logger.Infow("Reconcile_device", log.Fields{"device-id": device.Id}) |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 270 | var handler *deviceHandler |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 271 | if handler = oo.getDeviceHandler(device.Id, false); handler == nil { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 272 | handler := newDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 273 | oo.addDeviceHandlerToMap(ctx, handler) |
| 274 | handler.device = device |
| 275 | handler.reconciling = true |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 276 | go handler.adoptOrReconcileDevice(ctx, handler.device) |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 277 | // reconcilement will be continued after onu-device entry is added |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 278 | } else { |
Holger Hildebrandt | f41a160 | 2020-08-19 09:52:50 +0000 | [diff] [blame] | 279 | 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] | 280 | } |
| 281 | return nil |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | //Abandon_device unimplemented |
| 285 | func (oo *OpenONUAC) Abandon_device(device *voltha.Device) error { |
| 286 | return errors.New("unImplemented") |
| 287 | } |
| 288 | |
| 289 | //Disable_device disables the given device |
| 290 | func (oo *OpenONUAC) Disable_device(device *voltha.Device) error { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 291 | logger.Debugw("Disable_device", log.Fields{"device-id": device.Id}) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 292 | if handler := oo.getDeviceHandler(device.Id, false); handler != nil { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 293 | go handler.disableDevice(device) |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 294 | return nil |
| 295 | } |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 296 | logger.Warnw("no handler found for device-disable", log.Fields{"device-id": device.Id}) |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 297 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 300 | //Reenable_device enables the onu device after disable |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 301 | func (oo *OpenONUAC) Reenable_device(device *voltha.Device) error { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 302 | logger.Debugw("Reenable_device", log.Fields{"device-id": device.Id}) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 303 | if handler := oo.getDeviceHandler(device.Id, false); handler != nil { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 304 | go handler.reEnableDevice(device) |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 305 | return nil |
| 306 | } |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 307 | logger.Warnw("no handler found for device-reenable", log.Fields{"device-id": device.Id}) |
ozgecanetsia | fce57b1 | 2020-05-25 14:39:35 +0300 | [diff] [blame] | 308 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | //Reboot_device reboots the given device |
| 312 | func (oo *OpenONUAC) Reboot_device(device *voltha.Device) error { |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 313 | logger.Debugw("Reboot-device", log.Fields{"device-id": device.Id}) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 314 | if handler := oo.getDeviceHandler(device.Id, false); handler != nil { |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 315 | go handler.rebootDevice(device) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 316 | return nil |
| 317 | } |
divyadesai | 4d29955 | 2020-08-18 07:13:49 +0000 | [diff] [blame] | 318 | logger.Warnw("no handler found for device-reboot", log.Fields{"device-id": device.Id}) |
ozgecanetsia | e11479f | 2020-07-06 09:44:47 +0300 | [diff] [blame] | 319 | return fmt.Errorf(fmt.Sprintf("handler-not-found-#{device.Id}")) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 322 | //Self_test_device unimplemented |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 323 | func (oo *OpenONUAC) Self_test_device(device *voltha.Device) error { |
| 324 | return errors.New("unImplemented") |
| 325 | } |
| 326 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 327 | // Delete_device deletes the given device |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 328 | func (oo *OpenONUAC) Delete_device(device *voltha.Device) error { |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame^] | 329 | logger.Debugw("Delete_device", log.Fields{"device-id": device.Id, "SerialNumber": device.SerialNumber}) |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 330 | if handler := oo.getDeviceHandler(device.Id, false); handler != nil { |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame^] | 331 | err := handler.deleteDevicePersistencyData() |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 332 | //don't leave any garbage - even in error case |
| 333 | oo.deleteDeviceHandlerToMap(handler) |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame^] | 334 | return err |
Holger Hildebrandt | 9ca8b13 | 2020-08-07 14:45:03 +0000 | [diff] [blame] | 335 | } |
mpagenko | 2418ab0 | 2020-11-12 12:58:06 +0000 | [diff] [blame^] | 336 | logger.Warnw("no handler found for device-deletion", log.Fields{"device-id": device.Id}) |
| 337 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | //Get_device_details unimplemented |
| 341 | func (oo *OpenONUAC) Get_device_details(device *voltha.Device) error { |
| 342 | return errors.New("unImplemented") |
| 343 | } |
| 344 | |
| 345 | //Update_flows_bulk returns |
| 346 | func (oo *OpenONUAC) Update_flows_bulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error { |
| 347 | return errors.New("unImplemented") |
| 348 | } |
| 349 | |
| 350 | //Update_flows_incrementally updates (add/remove) the flows on a given device |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 351 | func (oo *OpenONUAC) Update_flows_incrementally(device *voltha.Device, |
| 352 | flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 353 | |
| 354 | //flow config is relayed to handler even if the device might be in some 'inactive' state |
| 355 | // let the handler or related FSM's decide, what to do with the modified flow state info |
| 356 | // 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] | 357 | |
| 358 | // 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] | 359 | // but processing is continued for flowUpdate possibly also set in the request |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 360 | if groups.ToAdd != nil && groups.ToAdd.Items != nil { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 361 | logger.Warnw("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] | 362 | } |
| 363 | if groups.ToRemove != nil && groups.ToRemove.Items != nil { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 364 | logger.Warnw("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] | 365 | } |
| 366 | if groups.ToUpdate != nil && groups.ToUpdate.Items != nil { |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 367 | logger.Warnw("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] | 368 | } |
| 369 | |
Holger Hildebrandt | f07b44a | 2020-11-10 13:07:54 +0000 | [diff] [blame] | 370 | if handler := oo.getDeviceHandler(device.Id, false); handler != nil { |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 371 | err := handler.FlowUpdateIncremental(flows, groups, flowMetadata) |
| 372 | return err |
| 373 | } |
mpagenko | fc4f56e | 2020-11-04 17:17:49 +0000 | [diff] [blame] | 374 | logger.Warnw("no handler found for incremental flow update", log.Fields{"device-id": device.Id}) |
mpagenko | dff5dda | 2020-08-28 11:52:01 +0000 | [diff] [blame] | 375 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id)) |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | //Update_pm_config returns PmConfigs nil or error |
| 379 | func (oo *OpenONUAC) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error { |
| 380 | return errors.New("unImplemented") |
| 381 | } |
| 382 | |
| 383 | //Receive_packet_out sends packet out to the device |
| 384 | func (oo *OpenONUAC) Receive_packet_out(deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error { |
| 385 | return errors.New("unImplemented") |
| 386 | } |
| 387 | |
| 388 | //Suppress_event unimplemented |
| 389 | func (oo *OpenONUAC) Suppress_event(filter *voltha.EventFilter) error { |
| 390 | return errors.New("unImplemented") |
| 391 | } |
| 392 | |
| 393 | //Unsuppress_event unimplemented |
| 394 | func (oo *OpenONUAC) Unsuppress_event(filter *voltha.EventFilter) error { |
| 395 | return errors.New("unImplemented") |
| 396 | } |
| 397 | |
| 398 | //Download_image unimplemented |
| 399 | func (oo *OpenONUAC) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
| 400 | return nil, errors.New("unImplemented") |
| 401 | } |
| 402 | |
| 403 | //Get_image_download_status unimplemented |
| 404 | func (oo *OpenONUAC) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
| 405 | return nil, errors.New("unImplemented") |
| 406 | } |
| 407 | |
| 408 | //Cancel_image_download unimplemented |
| 409 | func (oo *OpenONUAC) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
| 410 | return nil, errors.New("unImplemented") |
| 411 | } |
| 412 | |
| 413 | //Activate_image_update unimplemented |
| 414 | func (oo *OpenONUAC) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
| 415 | return nil, errors.New("unImplemented") |
| 416 | } |
| 417 | |
| 418 | //Revert_image_update unimplemented |
| 419 | func (oo *OpenONUAC) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
| 420 | return nil, errors.New("unImplemented") |
| 421 | } |
| 422 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 423 | // Enable_port to Enable PON/NNI interface - seems not to be used/required according to python code |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 424 | func (oo *OpenONUAC) Enable_port(deviceID string, port *voltha.Port) error { |
| 425 | return errors.New("unImplemented") |
| 426 | } |
| 427 | |
Holger Hildebrandt | ccd390c | 2020-05-29 13:49:04 +0000 | [diff] [blame] | 428 | // Disable_port to Disable pon/nni interface - seems not to be used/required according to python code |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 429 | func (oo *OpenONUAC) Disable_port(deviceID string, port *voltha.Port) error { |
| 430 | return errors.New("unImplemented") |
| 431 | } |
| 432 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 433 | //Child_device_lost - unimplemented |
Holger Hildebrandt | 0f9b88d | 2020-04-20 13:33:25 +0000 | [diff] [blame] | 434 | //needed for if update >= 3.1.x |
Matteo Scandolo | 2e6f1e3 | 2020-04-15 11:28:45 -0700 | [diff] [blame] | 435 | func (oo *OpenONUAC) Child_device_lost(deviceID string, pPortNo uint32, onuID uint32) error { |
| 436 | return errors.New("unImplemented") |
| 437 | } |
| 438 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 439 | // Start_omci_test unimplemented |
Matteo Scandolo | 2e6f1e3 | 2020-04-15 11:28:45 -0700 | [diff] [blame] | 440 | func (oo *OpenONUAC) Start_omci_test(device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) { |
| 441 | return nil, errors.New("unImplemented") |
| 442 | } |
| 443 | |
Himani Chawla | 6d2ae15 | 2020-09-02 13:11:20 +0530 | [diff] [blame] | 444 | // Get_ext_value - unimplemented |
Matteo Scandolo | d132c0e | 2020-04-24 17:06:25 -0700 | [diff] [blame] | 445 | func (oo *OpenONUAC) Get_ext_value(deviceID string, device *voltha.Device, valueparam voltha.ValueType_Type) (*voltha.ReturnValues, error) { |
| 446 | return nil, errors.New("unImplemented") |
| 447 | } |
| 448 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 449 | // Adapter interface required methods ################ end ######### |
| 450 | // ################################################################# |