Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1 | /* |
Joey Armstrong | 11f5a57 | 2024-01-12 19:11:32 -0500 | [diff] [blame] | 2 | * Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 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 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 16 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 17 | // Package core provides the utility for olt devices, flows and statistics |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 18 | package core |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 22 | "fmt" |
Akash Soni | f49299a | 2024-04-25 12:06:37 +0530 | [diff] [blame] | 23 | "sync" |
| 24 | "time" |
| 25 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 26 | "github.com/golang/protobuf/ptypes/empty" |
| 27 | conf "github.com/opencord/voltha-lib-go/v7/pkg/config" |
| 28 | "github.com/opencord/voltha-lib-go/v7/pkg/events/eventif" |
| 29 | vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc" |
| 30 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 31 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/config" |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 32 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 33 | "github.com/opencord/voltha-protos/v5/go/adapter_service" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 34 | "github.com/opencord/voltha-protos/v5/go/common" |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 35 | ca "github.com/opencord/voltha-protos/v5/go/core_adapter" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 36 | "github.com/opencord/voltha-protos/v5/go/extension" |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 37 | "github.com/opencord/voltha-protos/v5/go/health" |
| 38 | ia "github.com/opencord/voltha-protos/v5/go/inter_adapter" |
| 39 | "github.com/opencord/voltha-protos/v5/go/omci" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 40 | "github.com/opencord/voltha-protos/v5/go/voltha" |
nikesh.krishnan | 4d64453 | 2023-12-16 00:21:07 +0530 | [diff] [blame] | 41 | "google.golang.org/grpc/codes" |
| 42 | "google.golang.org/grpc/status" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 43 | ) |
| 44 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 45 | // OpenOLT structure holds the OLT information |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 46 | type OpenOLT struct { |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 47 | configManager *conf.ConfigManager |
| 48 | deviceHandlers map[string]*DeviceHandler |
| 49 | coreClient *vgrpc.Client |
| 50 | eventProxy eventif.EventProxy |
| 51 | config *config.AdapterFlags |
| 52 | numOnus int |
| 53 | KVStoreAddress string |
| 54 | KVStoreType string |
| 55 | exitChannel chan struct{} |
| 56 | HeartbeatCheckInterval time.Duration |
| 57 | HeartbeatFailReportInterval time.Duration |
| 58 | GrpcTimeoutInterval time.Duration |
| 59 | lockDeviceHandlersMap sync.RWMutex |
| 60 | enableONUStats bool |
| 61 | enableGemStats bool |
| 62 | rpcTimeout time.Duration |
| 63 | CheckOnuDevExistenceAtOnuDiscovery bool |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 64 | } |
| 65 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 66 | // NewOpenOLT returns a new instance of OpenOLT |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 67 | func NewOpenOLT(ctx context.Context, |
| 68 | coreClient *vgrpc.Client, |
Himani Chawla | cd40780 | 2020-12-10 12:08:59 +0530 | [diff] [blame] | 69 | eventProxy eventif.EventProxy, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenOLT { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 70 | var openOLT OpenOLT |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 71 | openOLT.exitChannel = make(chan struct{}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 72 | openOLT.deviceHandlers = make(map[string]*DeviceHandler) |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 73 | openOLT.config = cfg |
| 74 | openOLT.numOnus = cfg.OnuNumber |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 75 | openOLT.coreClient = coreClient |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 76 | openOLT.eventProxy = eventProxy |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 77 | openOLT.KVStoreAddress = cfg.KVStoreAddress |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 78 | openOLT.KVStoreType = cfg.KVStoreType |
| 79 | openOLT.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval |
| 80 | openOLT.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval |
| 81 | openOLT.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 82 | openOLT.lockDeviceHandlersMap = sync.RWMutex{} |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 83 | openOLT.configManager = cm |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 84 | openOLT.enableONUStats = cfg.EnableONUStats |
| 85 | openOLT.enableGemStats = cfg.EnableGEMStats |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 86 | openOLT.rpcTimeout = cfg.RPCTimeout |
Abhilash Laxmeshwar | d0f58cf | 2022-06-01 12:15:19 +0530 | [diff] [blame] | 87 | openOLT.CheckOnuDevExistenceAtOnuDiscovery = cfg.CheckOnuDevExistenceAtOnuDiscovery |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 88 | return &openOLT |
| 89 | } |
| 90 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 91 | // Start starts (logs) the device manager |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 92 | func (oo *OpenOLT) Start(ctx context.Context) error { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 93 | logger.Info(ctx, "starting-device-manager") |
| 94 | logger.Info(ctx, "device-manager-started") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 95 | return nil |
| 96 | } |
| 97 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 98 | // Stop terminates the session |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 99 | func (oo *OpenOLT) Stop(ctx context.Context) error { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 100 | logger.Info(ctx, "stopping-device-manager") |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 101 | close(oo.exitChannel) |
| 102 | // Stop the device handlers |
| 103 | oo.stopAllDeviceHandlers(ctx) |
| 104 | |
| 105 | // Stop the core grpc client connection |
| 106 | if oo.coreClient != nil { |
| 107 | oo.coreClient.Stop(ctx) |
| 108 | } |
| 109 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 110 | logger.Info(ctx, "device-manager-stopped") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 111 | return nil |
| 112 | } |
| 113 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 114 | func (oo *OpenOLT) addDeviceHandlerToMap(agent *DeviceHandler) { |
| 115 | oo.lockDeviceHandlersMap.Lock() |
| 116 | defer oo.lockDeviceHandlersMap.Unlock() |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 117 | if _, exist := oo.deviceHandlers[agent.device.Id]; !exist { |
| 118 | oo.deviceHandlers[agent.device.Id] = agent |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
| 122 | func (oo *OpenOLT) deleteDeviceHandlerToMap(agent *DeviceHandler) { |
| 123 | oo.lockDeviceHandlersMap.Lock() |
| 124 | defer oo.lockDeviceHandlersMap.Unlock() |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 125 | delete(oo.deviceHandlers, agent.device.Id) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 126 | } |
| 127 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 128 | func (oo *OpenOLT) getDeviceHandler(deviceID string) *DeviceHandler { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 129 | oo.lockDeviceHandlersMap.Lock() |
| 130 | defer oo.lockDeviceHandlersMap.Unlock() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 131 | if agent, ok := oo.deviceHandlers[deviceID]; ok { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 132 | return agent |
| 133 | } |
| 134 | return nil |
| 135 | } |
| 136 | |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 137 | func (oo *OpenOLT) stopAllDeviceHandlers(ctx context.Context) { |
| 138 | oo.lockDeviceHandlersMap.Lock() |
| 139 | defer oo.lockDeviceHandlersMap.Unlock() |
| 140 | for _, handler := range oo.deviceHandlers { |
| 141 | handler.Stop(ctx) |
| 142 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | // AdoptDevice creates a new device handler if not present already and then adopts the device |
| 146 | func (oo *OpenOLT) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 147 | if device == nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 148 | return nil, olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil).Log() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 149 | } |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 150 | logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 151 | var handler *DeviceHandler |
| 152 | if handler = oo.getDeviceHandler(device.Id); handler == nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 153 | handler := NewDeviceHandler(oo.coreClient, oo.eventProxy, device, oo, oo.configManager, oo.config) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 154 | oo.addDeviceHandlerToMap(handler) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 155 | go handler.AdoptDevice(log.WithSpanFromContext(context.Background(), ctx), device) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 156 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 157 | return &empty.Empty{}, nil |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 158 | } |
| 159 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 160 | // GetOfpDeviceInfo returns OFP information for the given device |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 161 | func (oo *OpenOLT) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 162 | logger.Infow(ctx, "get_ofp_device_info", log.Fields{"device-id": device.Id}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 163 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
| 164 | return handler.GetOfpDeviceInfo(device) |
| 165 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 166 | return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 167 | } |
| 168 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 169 | // ReconcileDevice unimplemented |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 170 | func (oo *OpenOLT) ReconcileDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 171 | if device == nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 172 | return nil, olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 173 | } |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 174 | logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 175 | var handler *DeviceHandler |
| 176 | if handler = oo.getDeviceHandler(device.Id); handler == nil { |
Maninder | e49938d | 2021-03-19 00:23:24 +0530 | [diff] [blame] | 177 | //Setting state to RECONCILING |
Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 178 | // Fetch previous state |
| 179 | //here we are fetching the previous operation states of the device,so to check which operation state it was previously for proper transition and proper clean up of the resources. |
| 180 | PrevOperStatus := device.OperStatus |
| 181 | |
| 182 | // Log previous state |
| 183 | logger.Infow(ctx, "previous-device-state", log.Fields{ |
| 184 | "device-id": device.Id, |
| 185 | "previous-operStatus": PrevOperStatus, |
| 186 | "Device-connStatus": device.ConnectStatus, |
| 187 | }) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 188 | cgClient, err := oo.coreClient.GetCoreServiceClient() |
Maninder | e49938d | 2021-03-19 00:23:24 +0530 | [diff] [blame] | 189 | if err != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 190 | return nil, err |
Maninder | e49938d | 2021-03-19 00:23:24 +0530 | [diff] [blame] | 191 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 192 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), oo.rpcTimeout) |
| 193 | defer cancel() |
Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 194 | // Create DeviceStateFilter with new state |
| 195 | deviceStateFilter := &ca.DeviceStateFilter{ |
| 196 | DeviceId: device.Id, |
| 197 | OperStatus: voltha.OperStatus_RECONCILING, |
| 198 | ConnStatus: device.ConnectStatus, |
| 199 | } |
| 200 | |
| 201 | // Log the new state being set |
| 202 | logger.Infow(ctx, "setting-new-device-state", log.Fields{ |
| 203 | "device-id": deviceStateFilter.DeviceId, |
| 204 | "new-operStatus": deviceStateFilter.OperStatus, |
| 205 | "new-connStatus": deviceStateFilter.ConnStatus, |
| 206 | }) |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 207 | if _, err := cgClient.DeviceStateUpdate(subCtx, &ca.DeviceStateFilter{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 208 | DeviceId: device.Id, |
| 209 | OperStatus: voltha.OperStatus_RECONCILING, |
Akash Soni | f49299a | 2024-04-25 12:06:37 +0530 | [diff] [blame] | 210 | ConnStatus: voltha.ConnectStatus_UNREACHABLE, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 211 | }); err != nil { |
| 212 | return nil, olterrors.NewErrAdapter("device-update-failed", log.Fields{"device-id": device.Id}, err) |
| 213 | } |
| 214 | |
Akash Soni | f49299a | 2024-04-25 12:06:37 +0530 | [diff] [blame] | 215 | // The OperState and connection state of the device is set to RECONCILING and UNREACHABLE in the previous section. This also needs to be set on the |
Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 216 | // locally cached copy of the device struct. |
| 217 | device.OperStatus = voltha.OperStatus_RECONCILING |
Akash Soni | f49299a | 2024-04-25 12:06:37 +0530 | [diff] [blame] | 218 | device.ConnectStatus = voltha.ConnectStatus_UNREACHABLE |
Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 219 | handler := NewDeviceHandler(oo.coreClient, oo.eventProxy, device, oo, oo.configManager, oo.config) |
| 220 | handler.adapterPreviouslyConnected = true |
Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 221 | handler.prevOperStatus = PrevOperStatus |
Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame] | 222 | oo.addDeviceHandlerToMap(handler) |
| 223 | handler.transitionMap = NewTransitionMap(handler) |
| 224 | |
Nandita Biradar | 1b590f1 | 2024-09-27 10:56:28 +0530 | [diff] [blame] | 225 | go handler.transitionMap.Handle(log.WithSpanFromContext(context.Background(), ctx), DeviceInit) |
nikesh.krishnan | 4d64453 | 2023-12-16 00:21:07 +0530 | [diff] [blame] | 226 | } else { |
| 227 | logger.Warnf(ctx, "device-already-reconciled-or-active", log.Fields{"device-id": device.Id}) |
| 228 | return &empty.Empty{}, status.Errorf(codes.AlreadyExists, "handler exists: %s", device.Id) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 229 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 230 | return &empty.Empty{}, nil |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 231 | } |
| 232 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 233 | // DisableDevice disables the given device |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 234 | func (oo *OpenOLT) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 235 | logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 236 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 237 | if err := handler.DisableDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil { |
| 238 | return nil, err |
| 239 | } |
| 240 | return &empty.Empty{}, nil |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 241 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 242 | return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 243 | } |
| 244 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 245 | // ReEnableDevice enables the olt device after disable |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 246 | func (oo *OpenOLT) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 247 | logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 248 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 249 | if err := handler.ReenableDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil { |
| 250 | return nil, err |
| 251 | } |
| 252 | return &empty.Empty{}, nil |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 253 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 254 | return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 255 | } |
| 256 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 257 | // RebootDevice reboots the given device |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 258 | func (oo *OpenOLT) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 259 | logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id}) |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 260 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 261 | if err := handler.RebootDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil { |
| 262 | return nil, err |
| 263 | } |
| 264 | return &empty.Empty{}, nil |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 265 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 266 | return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
| 267 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 268 | } |
| 269 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 270 | // DeleteDevice deletes a device |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 271 | func (oo *OpenOLT) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 272 | logger.Infow(ctx, "delete-device", log.Fields{"device-id": device.Id}) |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 273 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 274 | if err := handler.DeleteDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil { |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 275 | return nil, err |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 276 | } |
| 277 | oo.deleteDeviceHandlerToMap(handler) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 278 | return &empty.Empty{}, nil |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 279 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 280 | return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 281 | } |
| 282 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 283 | // UpdateFlowsIncrementally updates (add/remove) the flows on a given device |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 284 | func (oo *OpenOLT) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ca.IncrementalFlows) (*empty.Empty, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 285 | logger.Infow(ctx, "update_flows_incrementally", log.Fields{"device-id": incrFlows.Device.Id, "flows": incrFlows.Flows, "flowMetadata": incrFlows.FlowMetadata}) |
| 286 | if handler := oo.getDeviceHandler(incrFlows.Device.Id); handler != nil { |
| 287 | if err := handler.UpdateFlowsIncrementally(log.WithSpanFromContext(context.Background(), ctx), incrFlows.Device, incrFlows.Flows, incrFlows.Groups, incrFlows.FlowMetadata); err != nil { |
| 288 | return nil, err |
| 289 | } |
| 290 | return &empty.Empty{}, nil |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 291 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 292 | return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": incrFlows.Device.Id}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 293 | } |
| 294 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 295 | // UpdatePmConfig returns PmConfigs nil or error |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 296 | func (oo *OpenOLT) UpdatePmConfig(ctx context.Context, configs *ca.PmConfigsInfo) (*empty.Empty, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 297 | logger.Debugw(ctx, "update_pm_config", log.Fields{"device-id": configs.DeviceId, "pm-configs": configs.PmConfigs}) |
| 298 | if handler := oo.getDeviceHandler(configs.DeviceId); handler != nil { |
| 299 | handler.UpdatePmConfig(log.WithSpanFromContext(context.Background(), ctx), configs.PmConfigs) |
| 300 | return &empty.Empty{}, nil |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 301 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 302 | return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": configs.DeviceId}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 303 | } |
| 304 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 305 | // SendPacketOut sends packet out to the device |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 306 | func (oo *OpenOLT) SendPacketOut(ctx context.Context, packet *ca.PacketOut) (*empty.Empty, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 307 | logger.Debugw(ctx, "send_packet_out", log.Fields{"device-id": packet.DeviceId, "egress_port_no": packet.EgressPortNo, "pkt": packet.Packet}) |
| 308 | if handler := oo.getDeviceHandler(packet.DeviceId); handler != nil { |
| 309 | if err := handler.PacketOut(log.WithSpanFromContext(context.Background(), ctx), packet.EgressPortNo, packet.Packet); err != nil { |
| 310 | return nil, err |
| 311 | } |
| 312 | return &empty.Empty{}, nil |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 313 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 314 | return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": packet.DeviceId}, nil) |
| 315 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 316 | } |
| 317 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 318 | // EnablePort to Enable PON/NNI interface |
| 319 | func (oo *OpenOLT) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 320 | logger.Infow(ctx, "enable_port", log.Fields{"device-id": port.DeviceId, "port": port}) |
| 321 | if err := oo.enableDisablePort(log.WithSpanFromContext(context.Background(), ctx), port.DeviceId, port, true); err != nil { |
| 322 | return nil, err |
| 323 | } |
| 324 | return &empty.Empty{}, nil |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 325 | } |
| 326 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 327 | // DisablePort to Disable pon/nni interface |
| 328 | func (oo *OpenOLT) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 329 | logger.Infow(ctx, "disable_port", log.Fields{"device-id": port.DeviceId, "port": port}) |
| 330 | if err := oo.enableDisablePort(log.WithSpanFromContext(context.Background(), ctx), port.DeviceId, port, false); err != nil { |
| 331 | return nil, err |
| 332 | } |
| 333 | return &empty.Empty{}, nil |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | // enableDisablePort to Disable pon or Enable PON interface |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 337 | func (oo *OpenOLT) enableDisablePort(ctx context.Context, deviceID string, port *voltha.Port, enablePort bool) error { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 338 | logger.Infow(ctx, "enableDisablePort", log.Fields{"device-id": deviceID, "port": port}) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 339 | if port == nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 340 | return olterrors.NewErrInvalidValue(log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 341 | "reason": "port cannot be nil", |
| 342 | "device-id": deviceID, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 343 | "port": nil}, nil) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 344 | } |
| 345 | if handler := oo.getDeviceHandler(deviceID); handler != nil { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 346 | logger.Debugw(ctx, "Enable_Disable_Port", log.Fields{"device-id": deviceID, "port": port}) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 347 | if enablePort { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 348 | if err := handler.EnablePort(ctx, port); err != nil { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 349 | return olterrors.NewErrAdapter("error-occurred-during-enable-port", log.Fields{"device-id": deviceID, "port": port}, err) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 350 | } |
| 351 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 352 | if err := handler.DisablePort(ctx, port); err != nil { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 353 | return olterrors.NewErrAdapter("error-occurred-during-disable-port", log.Fields{"device-id": deviceID, "port": port}, err) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | } |
| 357 | return nil |
| 358 | } |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 359 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 360 | // ChildDeviceLost deletes the ONU and its references from PONResources |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 361 | func (oo *OpenOLT) ChildDeviceLost(ctx context.Context, childDevice *voltha.Device) (*empty.Empty, error) { |
Girish Gowdra | a087056 | 2021-03-11 14:30:14 -0800 | [diff] [blame] | 362 | logger.Infow(ctx, "Child-device-lost", log.Fields{"parent-device-id": childDevice.ParentId, "child-device-id": childDevice.Id}) |
| 363 | if handler := oo.getDeviceHandler(childDevice.ParentId); handler != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 364 | if err := handler.ChildDeviceLost(log.WithSpanFromContext(context.Background(), ctx), childDevice.ParentPortNo, childDevice.ProxyAddress.OnuId, childDevice.SerialNumber); err != nil { |
| 365 | return nil, err |
| 366 | } |
| 367 | return &empty.Empty{}, nil |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 368 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 369 | return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"parent-device-id": childDevice.ParentId}, nil).Log() |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 370 | } |
Scott Baker | 24f83e2 | 2020-03-30 16:14:28 -0700 | [diff] [blame] | 371 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 372 | // GetExtValue retrieves a value on a particular ONU |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 373 | func (oo *OpenOLT) GetExtValue(ctx context.Context, extInfo *ca.GetExtValueMessage) (*extension.ReturnValues, error) { |
Dinesh Belwalkar | db587af | 2020-02-27 15:37:16 -0800 | [diff] [blame] | 374 | var err error |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 375 | resp := new(extension.ReturnValues) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 376 | logger.Infow(ctx, "get_ext_value", log.Fields{"parent-device-id": extInfo.ParentDevice.Id, "onu-id": extInfo.ChildDevice.Id}) |
| 377 | if handler := oo.getDeviceHandler(extInfo.ParentDevice.Id); handler != nil { |
| 378 | if resp, err = handler.getExtValue(ctx, extInfo.ChildDevice, extInfo.ValueType); err != nil { |
| 379 | logger.Errorw(ctx, "error-occurred-during-get-ext-value", |
| 380 | log.Fields{"parent-device-id": extInfo.ParentDevice.Id, "onu-id": extInfo.ChildDevice.Id, "error": err}) |
Dinesh Belwalkar | db587af | 2020-02-27 15:37:16 -0800 | [diff] [blame] | 381 | return nil, err |
| 382 | } |
| 383 | } |
| 384 | return resp, nil |
| 385 | } |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 386 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 387 | // GetSingleValue handles get uni status on ONU and ondemand metric on OLT |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 388 | func (oo *OpenOLT) GetSingleValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) { |
| 389 | logger.Infow(ctx, "single_get_value_request", log.Fields{"request": request}) |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 390 | |
| 391 | errResp := func(status extension.GetValueResponse_Status, |
| 392 | reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
| 393 | return &extension.SingleGetValueResponse{ |
| 394 | Response: &extension.GetValueResponse{ |
| 395 | Status: status, |
| 396 | ErrReason: reason, |
| 397 | }, |
| 398 | } |
| 399 | } |
| 400 | if handler := oo.getDeviceHandler(request.TargetId); handler != nil { |
| 401 | switch reqType := request.GetRequest().GetRequest().(type) { |
| 402 | case *extension.GetValueRequest_OltPortInfo: |
| 403 | return handler.getOltPortCounters(ctx, reqType.OltPortInfo), nil |
Himani Chawla | 2c8ae0f | 2021-05-18 23:27:00 +0530 | [diff] [blame] | 404 | case *extension.GetValueRequest_OnuPonInfo: |
| 405 | return handler.getOnuPonCounters(ctx, reqType.OnuPonInfo), nil |
Gamze Abaka | 85e9a14 | 2021-05-26 13:41:39 +0000 | [diff] [blame] | 406 | case *extension.GetValueRequest_RxPower: |
| 407 | return handler.getRxPower(ctx, reqType.RxPower), nil |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 408 | case *extension.GetValueRequest_OltRxPower: |
| 409 | return handler.getPONRxPower(ctx, reqType.OltRxPower), nil |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 410 | default: |
| 411 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_UNSUPPORTED), nil |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | logger.Infow(ctx, "Single_get_value_request failed ", log.Fields{"request": request}) |
| 416 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE_ID), nil |
| 417 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 418 | |
| 419 | /* |
| 420 | * OLT Inter-adapter service |
| 421 | */ |
| 422 | |
kesavand | b9f54fd | 2021-11-25 20:08:04 +0530 | [diff] [blame] | 423 | // ProxyOmciRequests proxies an onu sw download OMCI request from the child adapter |
| 424 | func (oo *OpenOLT) ProxyOmciRequests(ctx context.Context, request *ia.OmciMessages) (*empty.Empty, error) { |
| 425 | if handler := oo.getDeviceHandler(request.ParentDeviceId); handler != nil { |
| 426 | if err := handler.ProxyOmciRequests(ctx, request); err != nil { |
Abhilash Laxmeshwar | 092e6ca | 2022-12-08 19:51:27 +0530 | [diff] [blame] | 427 | return nil, err |
kesavand | b9f54fd | 2021-11-25 20:08:04 +0530 | [diff] [blame] | 428 | } |
| 429 | return &empty.Empty{}, nil |
| 430 | } |
| 431 | return nil, olterrors.NewErrNotFound("no-device-handler", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.ChildDeviceId}, nil).Log() |
| 432 | } |
| 433 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 434 | // ProxyOmciRequest proxies an OMCI request from the child adapter |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 435 | func (oo *OpenOLT) ProxyOmciRequest(ctx context.Context, request *ia.OmciMessage) (*empty.Empty, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 436 | logger.Debugw(ctx, "proxy-omci-request", log.Fields{"request": request}) |
| 437 | |
| 438 | if handler := oo.getDeviceHandler(request.ParentDeviceId); handler != nil { |
| 439 | if err := handler.ProxyOmciMessage(ctx, request); err != nil { |
Abhilash Laxmeshwar | 092e6ca | 2022-12-08 19:51:27 +0530 | [diff] [blame] | 440 | return nil, err |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 441 | } |
| 442 | return &empty.Empty{}, nil |
| 443 | } |
| 444 | return nil, olterrors.NewErrNotFound("no-device-handler", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.ChildDeviceId}, nil).Log() |
| 445 | } |
| 446 | |
| 447 | // GetTechProfileInstance returns an instance of a tech profile |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 448 | func (oo *OpenOLT) GetTechProfileInstance(ctx context.Context, request *ia.TechProfileInstanceRequestMessage) (*ia.TechProfileDownloadMessage, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 449 | logger.Debugw(ctx, "getting-tech-profile-request", log.Fields{"request": request}) |
| 450 | |
| 451 | targetDeviceID := request.ParentDeviceId |
| 452 | if targetDeviceID == "" { |
| 453 | return nil, olterrors.NewErrNotFound("parent-id-empty", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.DeviceId}, nil).Log() |
| 454 | } |
| 455 | if handler := oo.getDeviceHandler(targetDeviceID); handler != nil { |
| 456 | return handler.GetTechProfileDownloadMessage(ctx, request) |
| 457 | } |
| 458 | return nil, olterrors.NewErrNotFound("no-device-handler", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.DeviceId}, nil).Log() |
| 459 | |
| 460 | } |
| 461 | |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 462 | // GetHealthStatus is used by a OltAdapterService client to detect a connection |
| 463 | // lost with the gRPC server hosting the OltAdapterService service |
| 464 | func (oo *OpenOLT) GetHealthStatus(stream adapter_service.AdapterService_GetHealthStatusServer) error { |
| 465 | ctx := context.Background() |
| 466 | logger.Debugw(ctx, "receive-stream-connection", log.Fields{"stream": stream}) |
| 467 | |
| 468 | if stream == nil { |
| 469 | return fmt.Errorf("conn-is-nil %v", stream) |
| 470 | } |
| 471 | initialRequestTime := time.Now() |
| 472 | var remoteClient *common.Connection |
| 473 | var tempClient *common.Connection |
| 474 | var err error |
| 475 | loop: |
| 476 | for { |
| 477 | tempClient, err = stream.Recv() |
| 478 | if err != nil { |
| 479 | logger.Warnw(ctx, "received-stream-error", log.Fields{"remote-client": remoteClient, "error": err}) |
| 480 | break loop |
| 481 | } |
| 482 | // Send a response back |
| 483 | err = stream.Send(&health.HealthStatus{State: health.HealthStatus_HEALTHY}) |
| 484 | if err != nil { |
| 485 | logger.Warnw(ctx, "sending-stream-error", log.Fields{"remote-client": remoteClient, "error": err}) |
| 486 | break loop |
| 487 | } |
| 488 | |
| 489 | remoteClient = tempClient |
| 490 | logger.Debugw(ctx, "received-keep-alive", log.Fields{"remote-client": remoteClient}) |
| 491 | |
| 492 | select { |
| 493 | case <-stream.Context().Done(): |
| 494 | logger.Infow(ctx, "stream-keep-alive-context-done", log.Fields{"remote-client": remoteClient, "error": stream.Context().Err()}) |
| 495 | break loop |
| 496 | case <-oo.exitChannel: |
| 497 | logger.Warnw(ctx, "received-stop", log.Fields{"remote-client": remoteClient, "initial-conn-time": initialRequestTime}) |
| 498 | break loop |
| 499 | default: |
| 500 | } |
| 501 | } |
| 502 | logger.Errorw(ctx, "connection-down", log.Fields{"remote-client": remoteClient, "error": err, "initial-conn-time": initialRequestTime}) |
| 503 | return err |
| 504 | } |
| 505 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 506 | /* |
| 507 | * |
| 508 | * Unimplemented APIs |
| 509 | * |
| 510 | */ |
| 511 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 512 | // SimulateAlarm is unimplemented |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 513 | func (oo *OpenOLT) SimulateAlarm(context.Context, *ca.SimulateAlarmMessage) (*voltha.OperationResp, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 514 | return nil, olterrors.ErrNotImplemented |
| 515 | } |
| 516 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 517 | // SetExtValue is unimplemented |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 518 | func (oo *OpenOLT) SetExtValue(context.Context, *ca.SetExtValueMessage) (*empty.Empty, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 519 | return nil, olterrors.ErrNotImplemented |
| 520 | } |
| 521 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 522 | // SetSingleValue is unimplemented |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 523 | func (oo *OpenOLT) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) { |
| 524 | return nil, olterrors.ErrNotImplemented |
| 525 | } |
| 526 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 527 | // StartOmciTest not implemented |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 528 | func (oo *OpenOLT) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 529 | return nil, olterrors.ErrNotImplemented |
| 530 | } |
| 531 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 532 | // SuppressEvent unimplemented |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 533 | func (oo *OpenOLT) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 534 | return nil, olterrors.ErrNotImplemented |
| 535 | } |
| 536 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 537 | // UnSuppressEvent unimplemented |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 538 | func (oo *OpenOLT) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 539 | return nil, olterrors.ErrNotImplemented |
| 540 | } |
| 541 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 542 | // DownloadImage is unimplemented |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 543 | func (oo *OpenOLT) DownloadImage(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 544 | return nil, olterrors.ErrNotImplemented |
| 545 | } |
| 546 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 547 | // GetImageDownloadStatus is unimplemented |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 548 | func (oo *OpenOLT) GetImageDownloadStatus(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 549 | return nil, olterrors.ErrNotImplemented |
| 550 | } |
| 551 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 552 | // CancelImageDownload is unimplemented |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 553 | func (oo *OpenOLT) CancelImageDownload(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 554 | return nil, olterrors.ErrNotImplemented |
| 555 | } |
| 556 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 557 | // ActivateImageUpdate is unimplemented |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 558 | func (oo *OpenOLT) ActivateImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 559 | return nil, olterrors.ErrNotImplemented |
| 560 | } |
| 561 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 562 | // RevertImageUpdate is unimplemented |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 563 | func (oo *OpenOLT) RevertImageUpdate(ctx context.Context, imageInfo *ca.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 564 | return nil, olterrors.ErrNotImplemented |
| 565 | } |
| 566 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 567 | // DownloadOnuImage unimplemented |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 568 | func (oo *OpenOLT) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) { |
| 569 | return nil, olterrors.ErrNotImplemented |
| 570 | } |
| 571 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 572 | // GetOnuImageStatus unimplemented |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 573 | func (oo *OpenOLT) GetOnuImageStatus(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 574 | return nil, olterrors.ErrNotImplemented |
| 575 | } |
| 576 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 577 | // AbortOnuImageUpgrade unimplemented |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 578 | func (oo *OpenOLT) AbortOnuImageUpgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 579 | return nil, olterrors.ErrNotImplemented |
| 580 | } |
| 581 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 582 | // GetOnuImages unimplemented |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 583 | func (oo *OpenOLT) GetOnuImages(ctx context.Context, deviceID *common.ID) (*voltha.OnuImages, error) { |
| 584 | return nil, olterrors.ErrNotImplemented |
| 585 | } |
| 586 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 587 | // ActivateOnuImage unimplemented |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 588 | func (oo *OpenOLT) ActivateOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 589 | return nil, olterrors.ErrNotImplemented |
| 590 | } |
| 591 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 592 | // CommitOnuImage unimplemented |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 593 | func (oo *OpenOLT) CommitOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 594 | return nil, olterrors.ErrNotImplemented |
| 595 | } |
| 596 | |
| 597 | // UpdateFlowsBulk is unimplemented |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 598 | func (oo *OpenOLT) UpdateFlowsBulk(ctx context.Context, flows *ca.BulkFlows) (*empty.Empty, error) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 599 | return nil, olterrors.ErrNotImplemented |
| 600 | } |
| 601 | |
praneeth nalmas | 55616d6 | 2023-02-06 09:19:18 +0530 | [diff] [blame] | 602 | // SelfTestDevice unimplemented |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 603 | func (oo *OpenOLT) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 604 | return nil, olterrors.ErrNotImplemented |
| 605 | } |