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 | |
| 17 | //Package adaptercoreont provides the utility for onu devices, flows and statistics |
| 18 | package adaptercoreont |
| 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" |
| 28 | "github.com/opencord/voltha-lib-go/v3/pkg/kafka" |
| 29 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 30 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 31 | "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 32 | "github.com/opencord/voltha-protos/v3/go/voltha" |
| 33 | |
| 34 | "test.internal/openadapter/config" |
| 35 | ) |
| 36 | |
| 37 | //OpenONUAC structure holds the ONU core information |
| 38 | type OpenONUAC struct { |
| 39 | deviceHandlers map[string]*DeviceHandler |
| 40 | coreProxy adapterif.CoreProxy |
| 41 | adapterProxy adapterif.AdapterProxy |
| 42 | eventProxy adapterif.EventProxy |
| 43 | kafkaICProxy kafka.InterContainerProxy |
| 44 | config *config.AdapterFlags |
| 45 | numOnus int |
| 46 | KVStoreHost string |
| 47 | KVStorePort int |
| 48 | KVStoreType string |
| 49 | exitChannel chan int |
| 50 | HeartbeatCheckInterval time.Duration |
| 51 | HeartbeatFailReportInterval time.Duration |
| 52 | //GrpcTimeoutInterval time.Duration |
| 53 | lockDeviceHandlersMap sync.RWMutex |
| 54 | } |
| 55 | |
| 56 | //NewOpenONUAC returns a new instance of OpenONU_AC |
| 57 | func NewOpenONUAC(ctx context.Context, kafkaICProxy kafka.InterContainerProxy, |
| 58 | coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy, |
| 59 | eventProxy adapterif.EventProxy, cfg *config.AdapterFlags) *OpenONUAC { |
| 60 | var openOnuAc OpenONUAC |
| 61 | openOnuAc.exitChannel = make(chan int, 1) |
| 62 | openOnuAc.deviceHandlers = make(map[string]*DeviceHandler) |
| 63 | openOnuAc.kafkaICProxy = kafkaICProxy |
| 64 | openOnuAc.config = cfg |
| 65 | openOnuAc.numOnus = cfg.OnuNumber |
| 66 | openOnuAc.coreProxy = coreProxy |
| 67 | openOnuAc.adapterProxy = adapterProxy |
| 68 | openOnuAc.eventProxy = eventProxy |
| 69 | openOnuAc.KVStoreHost = cfg.KVStoreHost |
| 70 | openOnuAc.KVStorePort = cfg.KVStorePort |
| 71 | openOnuAc.KVStoreType = cfg.KVStoreType |
| 72 | openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval |
| 73 | openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval |
| 74 | //openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval |
| 75 | openOnuAc.lockDeviceHandlersMap = sync.RWMutex{} |
| 76 | return &openOnuAc |
| 77 | } |
| 78 | |
| 79 | //Start starts (logs) the adapter |
| 80 | func (oo *OpenONUAC) Start(ctx context.Context) error { |
| 81 | log.Info("starting-openonu-adapter") |
| 82 | log.Info("openonu-adapter-started") |
| 83 | return nil |
| 84 | } |
| 85 | |
| 86 | //Stop terminates the session |
| 87 | func (oo *OpenONUAC) Stop(ctx context.Context) error { |
| 88 | log.Info("stopping-device-manager") |
| 89 | oo.exitChannel <- 1 |
| 90 | log.Info("device-manager-stopped") |
| 91 | return nil |
| 92 | } |
| 93 | |
| 94 | func (oo *OpenONUAC) addDeviceHandlerToMap(ctx context.Context, agent *DeviceHandler) { |
| 95 | oo.lockDeviceHandlersMap.Lock() |
| 96 | defer oo.lockDeviceHandlersMap.Unlock() |
| 97 | if _, exist := oo.deviceHandlers[agent.deviceID]; !exist { |
| 98 | oo.deviceHandlers[agent.deviceID] = agent |
| 99 | oo.deviceHandlers[agent.deviceID].Start(ctx) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | func (oo *OpenONUAC) deleteDeviceHandlerToMap(agent *DeviceHandler) { |
| 104 | oo.lockDeviceHandlersMap.Lock() |
| 105 | defer oo.lockDeviceHandlersMap.Unlock() |
| 106 | delete(oo.deviceHandlers, agent.deviceID) |
| 107 | } |
| 108 | |
| 109 | func (oo *OpenONUAC) getDeviceHandler(deviceID string) *DeviceHandler { |
| 110 | oo.lockDeviceHandlersMap.Lock() |
| 111 | defer oo.lockDeviceHandlersMap.Unlock() |
| 112 | if agent, ok := oo.deviceHandlers[deviceID]; ok { |
| 113 | return agent |
| 114 | } |
| 115 | return nil |
| 116 | } |
| 117 | |
| 118 | // Adapter interface required methods ############## begin ######### |
| 119 | // ################################################################# |
| 120 | |
| 121 | // for original content compare: (needs according deviceHandler methods) |
| 122 | // /voltha-openolt-adapter/adaptercore/openolt.go |
| 123 | |
| 124 | // Adopt_device creates a new device handler if not present already and then adopts the device |
| 125 | func (oo *OpenONUAC) Adopt_device(device *voltha.Device) error { |
| 126 | if device == nil { |
| 127 | log.Warn("voltha-device-is-nil") |
| 128 | return errors.New("nil-device") |
| 129 | } |
| 130 | ctx := context.Background() |
| 131 | log.Infow("adopt-device", log.Fields{"deviceId": device.Id}) |
| 132 | var handler *DeviceHandler |
| 133 | if handler = oo.getDeviceHandler(device.Id); handler == nil { |
| 134 | handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo) |
| 135 | oo.addDeviceHandlerToMap(ctx, handler) |
| 136 | go handler.AdoptDevice(ctx, device) |
| 137 | // Launch the creation of the device topic |
| 138 | // go oo.createDeviceTopic(device) |
| 139 | } |
| 140 | return nil |
| 141 | } |
| 142 | |
| 143 | //Get_ofp_device_info returns OFP information for the given device |
| 144 | func (oo *OpenONUAC) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) { |
| 145 | log.Errorw("device-handler-not-set", log.Fields{"deviceId": device.Id}) |
| 146 | return nil, errors.New("device-handler-not-set") |
| 147 | } |
| 148 | |
| 149 | //Get_ofp_port_info returns OFP port information for the given device |
| 150 | func (oo *OpenONUAC) Get_ofp_port_info(device *voltha.Device, portNo int64) (*ic.PortCapability, error) { |
| 151 | log.Errorw("device-handler-not-set", log.Fields{"deviceId": device.Id}) |
| 152 | return nil, errors.New("device-handler-not-set") |
| 153 | } |
| 154 | |
| 155 | //Process_inter_adapter_message sends messages to a target device (between adapters) |
| 156 | func (oo *OpenONUAC) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error { |
| 157 | log.Debugw("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id, |
| 158 | "msgProxyDeviceId": msg.Header.ProxyDeviceId, "msgToDeviceId": msg.Header.ToDeviceId}) |
| 159 | |
| 160 | targetDevice := msg.Header.ToDeviceId |
| 161 | //ToDeviceId should address an DeviceHandler instance |
| 162 | if handler := oo.getDeviceHandler(targetDevice); handler != nil { |
| 163 | return handler.ProcessInterAdapterMessage(msg) |
| 164 | } |
| 165 | log.Warn("no handler found for received Inter-Proxy-message 'ToDeviceId'") |
| 166 | return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", targetDevice)) |
| 167 | } |
| 168 | |
| 169 | //Adapter_descriptor not implemented |
| 170 | func (oo *OpenONUAC) Adapter_descriptor() error { |
| 171 | return errors.New("unImplemented") |
| 172 | } |
| 173 | |
| 174 | //Device_types unimplemented |
| 175 | func (oo *OpenONUAC) Device_types() (*voltha.DeviceTypes, error) { |
| 176 | return nil, errors.New("unImplemented") |
| 177 | } |
| 178 | |
| 179 | //Health returns unimplemented |
| 180 | func (oo *OpenONUAC) Health() (*voltha.HealthStatus, error) { |
| 181 | return nil, errors.New("unImplemented") |
| 182 | } |
| 183 | |
| 184 | //Reconcile_device unimplemented |
| 185 | func (oo *OpenONUAC) Reconcile_device(device *voltha.Device) error { |
| 186 | return errors.New("unImplemented") |
| 187 | } |
| 188 | |
| 189 | //Abandon_device unimplemented |
| 190 | func (oo *OpenONUAC) Abandon_device(device *voltha.Device) error { |
| 191 | return errors.New("unImplemented") |
| 192 | } |
| 193 | |
| 194 | //Disable_device disables the given device |
| 195 | func (oo *OpenONUAC) Disable_device(device *voltha.Device) error { |
| 196 | return errors.New("unImplemented") |
| 197 | } |
| 198 | |
| 199 | //Reenable_device enables the olt device after disable |
| 200 | func (oo *OpenONUAC) Reenable_device(device *voltha.Device) error { |
| 201 | return errors.New("unImplemented") |
| 202 | } |
| 203 | |
| 204 | //Reboot_device reboots the given device |
| 205 | func (oo *OpenONUAC) Reboot_device(device *voltha.Device) error { |
| 206 | return errors.New("unImplemented") |
| 207 | } |
| 208 | |
| 209 | //Self_test_device unimplented |
| 210 | func (oo *OpenONUAC) Self_test_device(device *voltha.Device) error { |
| 211 | return errors.New("unImplemented") |
| 212 | } |
| 213 | |
| 214 | //Delete_device unimplemented |
| 215 | func (oo *OpenONUAC) Delete_device(device *voltha.Device) error { |
| 216 | return errors.New("unImplemented") |
| 217 | } |
| 218 | |
| 219 | //Get_device_details unimplemented |
| 220 | func (oo *OpenONUAC) Get_device_details(device *voltha.Device) error { |
| 221 | return errors.New("unImplemented") |
| 222 | } |
| 223 | |
| 224 | //Update_flows_bulk returns |
| 225 | func (oo *OpenONUAC) Update_flows_bulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error { |
| 226 | return errors.New("unImplemented") |
| 227 | } |
| 228 | |
| 229 | //Update_flows_incrementally updates (add/remove) the flows on a given device |
| 230 | func (oo *OpenONUAC) Update_flows_incrementally(device *voltha.Device, flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error { |
| 231 | return errors.New("unImplemented") |
| 232 | } |
| 233 | |
| 234 | //Update_pm_config returns PmConfigs nil or error |
| 235 | func (oo *OpenONUAC) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error { |
| 236 | return errors.New("unImplemented") |
| 237 | } |
| 238 | |
| 239 | //Receive_packet_out sends packet out to the device |
| 240 | func (oo *OpenONUAC) Receive_packet_out(deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error { |
| 241 | return errors.New("unImplemented") |
| 242 | } |
| 243 | |
| 244 | //Suppress_event unimplemented |
| 245 | func (oo *OpenONUAC) Suppress_event(filter *voltha.EventFilter) error { |
| 246 | return errors.New("unImplemented") |
| 247 | } |
| 248 | |
| 249 | //Unsuppress_event unimplemented |
| 250 | func (oo *OpenONUAC) Unsuppress_event(filter *voltha.EventFilter) error { |
| 251 | return errors.New("unImplemented") |
| 252 | } |
| 253 | |
| 254 | //Download_image unimplemented |
| 255 | func (oo *OpenONUAC) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
| 256 | return nil, errors.New("unImplemented") |
| 257 | } |
| 258 | |
| 259 | //Get_image_download_status unimplemented |
| 260 | func (oo *OpenONUAC) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
| 261 | return nil, errors.New("unImplemented") |
| 262 | } |
| 263 | |
| 264 | //Cancel_image_download unimplemented |
| 265 | func (oo *OpenONUAC) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
| 266 | return nil, errors.New("unImplemented") |
| 267 | } |
| 268 | |
| 269 | //Activate_image_update unimplemented |
| 270 | func (oo *OpenONUAC) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
| 271 | return nil, errors.New("unImplemented") |
| 272 | } |
| 273 | |
| 274 | //Revert_image_update unimplemented |
| 275 | func (oo *OpenONUAC) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
| 276 | return nil, errors.New("unImplemented") |
| 277 | } |
| 278 | |
| 279 | // Enable_port to Enable PON/NNI interface |
| 280 | func (oo *OpenONUAC) Enable_port(deviceID string, port *voltha.Port) error { |
| 281 | return errors.New("unImplemented") |
| 282 | } |
| 283 | |
| 284 | // Disable_port to Disable pon/nni interface |
| 285 | func (oo *OpenONUAC) Disable_port(deviceID string, port *voltha.Port) error { |
| 286 | return errors.New("unImplemented") |
| 287 | } |
| 288 | |
| 289 | // enableDisablePort to Disable pon or Enable PON interface |
| 290 | func (oo *OpenONUAC) enableDisablePort(deviceID string, port *voltha.Port, enablePort bool) error { |
| 291 | return errors.New("unImplemented") |
| 292 | } |
| 293 | |
Matteo Scandolo | 2e6f1e3 | 2020-04-15 11:28:45 -0700 | [diff] [blame^] | 294 | func (oo *OpenONUAC) Child_device_lost(deviceID string, pPortNo uint32, onuID uint32) error { |
| 295 | return errors.New("unImplemented") |
| 296 | } |
| 297 | |
| 298 | func (oo *OpenONUAC) Start_omci_test(device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) { |
| 299 | return nil, errors.New("unImplemented") |
| 300 | } |
| 301 | |
Holger Hildebrandt | fa07499 | 2020-03-27 15:42:06 +0000 | [diff] [blame] | 302 | // Adapter interface required methods ################ end ######### |
| 303 | // ################################################################# |