Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-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 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 16 | |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 17 | //Package core provides the utility for olt devices, flows and statistics |
| 18 | package core |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 22 | "errors" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 23 | "sync" |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 24 | "time" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 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 | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 33 | "github.com/opencord/voltha-protos/v5/go/common" |
| 34 | "github.com/opencord/voltha-protos/v5/go/extension" |
| 35 | ic "github.com/opencord/voltha-protos/v5/go/inter_container" |
| 36 | "github.com/opencord/voltha-protos/v5/go/voltha" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 37 | ) |
| 38 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 39 | //OpenOLT structure holds the OLT information |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 40 | type OpenOLT struct { |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 41 | configManager *conf.ConfigManager |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 42 | deviceHandlers map[string]*DeviceHandler |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 43 | coreClient *vgrpc.Client |
Himani Chawla | cd40780 | 2020-12-10 12:08:59 +0530 | [diff] [blame] | 44 | eventProxy eventif.EventProxy |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 45 | config *config.AdapterFlags |
| 46 | numOnus int |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 47 | KVStoreAddress string |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 48 | KVStoreType string |
| 49 | exitChannel chan int |
| 50 | HeartbeatCheckInterval time.Duration |
| 51 | HeartbeatFailReportInterval time.Duration |
| 52 | GrpcTimeoutInterval time.Duration |
| 53 | lockDeviceHandlersMap sync.RWMutex |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 54 | enableONUStats bool |
| 55 | enableGemStats bool |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 56 | rpcTimeout time.Duration |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 57 | } |
| 58 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 59 | //NewOpenOLT returns a new instance of OpenOLT |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 60 | func NewOpenOLT(ctx context.Context, |
| 61 | coreClient *vgrpc.Client, |
Himani Chawla | cd40780 | 2020-12-10 12:08:59 +0530 | [diff] [blame] | 62 | eventProxy eventif.EventProxy, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenOLT { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 63 | var openOLT OpenOLT |
| 64 | openOLT.exitChannel = make(chan int, 1) |
| 65 | openOLT.deviceHandlers = make(map[string]*DeviceHandler) |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 66 | openOLT.config = cfg |
| 67 | openOLT.numOnus = cfg.OnuNumber |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 68 | openOLT.coreClient = coreClient |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 69 | openOLT.eventProxy = eventProxy |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 70 | openOLT.KVStoreAddress = cfg.KVStoreAddress |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 71 | openOLT.KVStoreType = cfg.KVStoreType |
| 72 | openOLT.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval |
| 73 | openOLT.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval |
| 74 | openOLT.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 75 | openOLT.lockDeviceHandlersMap = sync.RWMutex{} |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 76 | openOLT.configManager = cm |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 77 | openOLT.enableONUStats = cfg.EnableONUStats |
| 78 | openOLT.enableGemStats = cfg.EnableGEMStats |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 79 | openOLT.rpcTimeout = cfg.RPCTimeout |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 80 | return &openOLT |
| 81 | } |
| 82 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 83 | //Start starts (logs) the device manager |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 84 | func (oo *OpenOLT) Start(ctx context.Context) error { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 85 | logger.Info(ctx, "starting-device-manager") |
| 86 | logger.Info(ctx, "device-manager-started") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 87 | return nil |
| 88 | } |
| 89 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 90 | //Stop terminates the session |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 91 | func (oo *OpenOLT) Stop(ctx context.Context) error { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 92 | logger.Info(ctx, "stopping-device-manager") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 93 | oo.exitChannel <- 1 |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 94 | logger.Info(ctx, "device-manager-stopped") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 95 | return nil |
| 96 | } |
| 97 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 98 | func (oo *OpenOLT) addDeviceHandlerToMap(agent *DeviceHandler) { |
| 99 | oo.lockDeviceHandlersMap.Lock() |
| 100 | defer oo.lockDeviceHandlersMap.Unlock() |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 101 | if _, exist := oo.deviceHandlers[agent.device.Id]; !exist { |
| 102 | oo.deviceHandlers[agent.device.Id] = agent |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
| 106 | func (oo *OpenOLT) deleteDeviceHandlerToMap(agent *DeviceHandler) { |
| 107 | oo.lockDeviceHandlersMap.Lock() |
| 108 | defer oo.lockDeviceHandlersMap.Unlock() |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 109 | delete(oo.deviceHandlers, agent.device.Id) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 110 | } |
| 111 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 112 | func (oo *OpenOLT) getDeviceHandler(deviceID string) *DeviceHandler { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 113 | oo.lockDeviceHandlersMap.Lock() |
| 114 | defer oo.lockDeviceHandlersMap.Unlock() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 115 | if agent, ok := oo.deviceHandlers[deviceID]; ok { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 116 | return agent |
| 117 | } |
| 118 | return nil |
| 119 | } |
| 120 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 121 | // GetHealthStatus is used as a service readiness validation as a grpc connection |
| 122 | func (oo *OpenOLT) GetHealthStatus(ctx context.Context, empty *empty.Empty) (*voltha.HealthStatus, error) { |
| 123 | return &voltha.HealthStatus{State: voltha.HealthStatus_HEALTHY}, nil |
| 124 | } |
| 125 | |
| 126 | // AdoptDevice creates a new device handler if not present already and then adopts the device |
| 127 | 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] | 128 | if device == nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 129 | return nil, olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil).Log() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 130 | } |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 131 | logger.Infow(ctx, "adopt-device", log.Fields{"device-id": device.Id}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 132 | var handler *DeviceHandler |
| 133 | if handler = oo.getDeviceHandler(device.Id); handler == nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 134 | handler := NewDeviceHandler(oo.coreClient, oo.eventProxy, device, oo, oo.configManager, oo.config) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 135 | oo.addDeviceHandlerToMap(handler) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 136 | go handler.AdoptDevice(log.WithSpanFromContext(context.Background(), ctx), device) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 137 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 138 | return &empty.Empty{}, nil |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 139 | } |
| 140 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 141 | //GetOfpDeviceInfo returns OFP information for the given device |
| 142 | func (oo *OpenOLT) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) { |
| 143 | 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] | 144 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
| 145 | return handler.GetOfpDeviceInfo(device) |
| 146 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 147 | 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] | 148 | } |
| 149 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 150 | //ReconcileDevice unimplemented |
| 151 | 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] | 152 | if device == nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 153 | return nil, olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 154 | } |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 155 | logger.Infow(ctx, "reconcile-device", log.Fields{"device-id": device.Id}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 156 | var handler *DeviceHandler |
| 157 | if handler = oo.getDeviceHandler(device.Id); handler == nil { |
Maninder | e49938d | 2021-03-19 00:23:24 +0530 | [diff] [blame] | 158 | //Setting state to RECONCILING |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 159 | cgClient, err := oo.coreClient.GetCoreServiceClient() |
Maninder | e49938d | 2021-03-19 00:23:24 +0530 | [diff] [blame] | 160 | if err != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 161 | return nil, err |
Maninder | e49938d | 2021-03-19 00:23:24 +0530 | [diff] [blame] | 162 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 163 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), oo.rpcTimeout) |
| 164 | defer cancel() |
| 165 | if _, err := cgClient.DeviceStateUpdate(subCtx, &ic.DeviceStateFilter{ |
| 166 | DeviceId: device.Id, |
| 167 | OperStatus: voltha.OperStatus_RECONCILING, |
| 168 | ConnStatus: device.ConnectStatus, |
| 169 | }); err != nil { |
| 170 | return nil, olterrors.NewErrAdapter("device-update-failed", log.Fields{"device-id": device.Id}, err) |
| 171 | } |
| 172 | |
Girish Gowdra | 0fb24a3 | 2021-10-27 15:15:27 -0700 | [diff] [blame^] | 173 | // The OperState of the device is set to RECONCILING in the previous section. This also needs to be set on the |
| 174 | // locally cached copy of the device struct. |
| 175 | device.OperStatus = voltha.OperStatus_RECONCILING |
| 176 | handler := NewDeviceHandler(oo.coreClient, oo.eventProxy, device, oo, oo.configManager, oo.config) |
| 177 | handler.adapterPreviouslyConnected = true |
| 178 | oo.addDeviceHandlerToMap(handler) |
| 179 | handler.transitionMap = NewTransitionMap(handler) |
| 180 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 181 | handler.transitionMap.Handle(log.WithSpanFromContext(context.Background(), ctx), DeviceInit) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 182 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 183 | return &empty.Empty{}, nil |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 184 | } |
| 185 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 186 | //DisableDevice disables the given device |
| 187 | func (oo *OpenOLT) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 188 | logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 189 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 190 | if err := handler.DisableDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil { |
| 191 | return nil, err |
| 192 | } |
| 193 | return &empty.Empty{}, nil |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 194 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 195 | 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] | 196 | } |
| 197 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 198 | //ReEnableDevice enables the olt device after disable |
| 199 | func (oo *OpenOLT) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 200 | logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 201 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 202 | if err := handler.ReenableDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil { |
| 203 | return nil, err |
| 204 | } |
| 205 | return &empty.Empty{}, nil |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 206 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 207 | 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] | 208 | } |
| 209 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 210 | //RebootDevice reboots the given device |
| 211 | func (oo *OpenOLT) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 212 | logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id}) |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 213 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 214 | if err := handler.RebootDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil { |
| 215 | return nil, err |
| 216 | } |
| 217 | return &empty.Empty{}, nil |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 218 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 219 | return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
| 220 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 221 | } |
| 222 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 223 | //DeleteDevice deletes a device |
| 224 | func (oo *OpenOLT) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 225 | logger.Infow(ctx, "delete-device", log.Fields{"device-id": device.Id}) |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 226 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 227 | if err := handler.DeleteDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 228 | logger.Errorw(ctx, "failed-to-handle-delete-device", log.Fields{"device-id": device.Id}) |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 229 | } |
| 230 | oo.deleteDeviceHandlerToMap(handler) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 231 | return &empty.Empty{}, nil |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 232 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 233 | 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] | 234 | } |
| 235 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 236 | //UpdateFlowsIncrementally updates (add/remove) the flows on a given device |
| 237 | func (oo *OpenOLT) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ic.IncrementalFlows) (*empty.Empty, error) { |
| 238 | logger.Infow(ctx, "update_flows_incrementally", log.Fields{"device-id": incrFlows.Device.Id, "flows": incrFlows.Flows, "flowMetadata": incrFlows.FlowMetadata}) |
| 239 | if handler := oo.getDeviceHandler(incrFlows.Device.Id); handler != nil { |
| 240 | if err := handler.UpdateFlowsIncrementally(log.WithSpanFromContext(context.Background(), ctx), incrFlows.Device, incrFlows.Flows, incrFlows.Groups, incrFlows.FlowMetadata); err != nil { |
| 241 | return nil, err |
| 242 | } |
| 243 | return &empty.Empty{}, nil |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 244 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 245 | 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] | 246 | } |
| 247 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 248 | //UpdatePmConfig returns PmConfigs nil or error |
| 249 | func (oo *OpenOLT) UpdatePmConfig(ctx context.Context, configs *ic.PmConfigsInfo) (*empty.Empty, error) { |
| 250 | logger.Debugw(ctx, "update_pm_config", log.Fields{"device-id": configs.DeviceId, "pm-configs": configs.PmConfigs}) |
| 251 | if handler := oo.getDeviceHandler(configs.DeviceId); handler != nil { |
| 252 | handler.UpdatePmConfig(log.WithSpanFromContext(context.Background(), ctx), configs.PmConfigs) |
| 253 | return &empty.Empty{}, nil |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 254 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 255 | 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] | 256 | } |
| 257 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 258 | //SendPacketOut sends packet out to the device |
| 259 | func (oo *OpenOLT) SendPacketOut(ctx context.Context, packet *ic.PacketOut) (*empty.Empty, error) { |
| 260 | logger.Debugw(ctx, "send_packet_out", log.Fields{"device-id": packet.DeviceId, "egress_port_no": packet.EgressPortNo, "pkt": packet.Packet}) |
| 261 | if handler := oo.getDeviceHandler(packet.DeviceId); handler != nil { |
| 262 | if err := handler.PacketOut(log.WithSpanFromContext(context.Background(), ctx), packet.EgressPortNo, packet.Packet); err != nil { |
| 263 | return nil, err |
| 264 | } |
| 265 | return &empty.Empty{}, nil |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 266 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 267 | return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": packet.DeviceId}, nil) |
| 268 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 269 | } |
| 270 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 271 | // EnablePort to Enable PON/NNI interface |
| 272 | func (oo *OpenOLT) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 273 | logger.Infow(ctx, "enable_port", log.Fields{"device-id": port.DeviceId, "port": port}) |
| 274 | if err := oo.enableDisablePort(log.WithSpanFromContext(context.Background(), ctx), port.DeviceId, port, true); err != nil { |
| 275 | return nil, err |
| 276 | } |
| 277 | return &empty.Empty{}, nil |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 278 | } |
| 279 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 280 | // DisablePort to Disable pon/nni interface |
| 281 | func (oo *OpenOLT) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 282 | logger.Infow(ctx, "disable_port", log.Fields{"device-id": port.DeviceId, "port": port}) |
| 283 | if err := oo.enableDisablePort(log.WithSpanFromContext(context.Background(), ctx), port.DeviceId, port, false); err != nil { |
| 284 | return nil, err |
| 285 | } |
| 286 | return &empty.Empty{}, nil |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | // enableDisablePort to Disable pon or Enable PON interface |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 290 | 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] | 291 | logger.Infow(ctx, "enableDisablePort", log.Fields{"device-id": deviceID, "port": port}) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 292 | if port == nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 293 | return olterrors.NewErrInvalidValue(log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 294 | "reason": "port cannot be nil", |
| 295 | "device-id": deviceID, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 296 | "port": nil}, nil) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 297 | } |
| 298 | if handler := oo.getDeviceHandler(deviceID); handler != nil { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 299 | logger.Debugw(ctx, "Enable_Disable_Port", log.Fields{"device-id": deviceID, "port": port}) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 300 | if enablePort { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 301 | if err := handler.EnablePort(ctx, port); err != nil { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 302 | 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] | 303 | } |
| 304 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 305 | if err := handler.DisablePort(ctx, port); err != nil { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 306 | 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] | 307 | } |
| 308 | } |
| 309 | } |
| 310 | return nil |
| 311 | } |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 312 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 313 | //ChildDeviceLost deletes the ONU and its references from PONResources |
| 314 | 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] | 315 | logger.Infow(ctx, "Child-device-lost", log.Fields{"parent-device-id": childDevice.ParentId, "child-device-id": childDevice.Id}) |
| 316 | if handler := oo.getDeviceHandler(childDevice.ParentId); handler != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 317 | if err := handler.ChildDeviceLost(log.WithSpanFromContext(context.Background(), ctx), childDevice.ParentPortNo, childDevice.ProxyAddress.OnuId, childDevice.SerialNumber); err != nil { |
| 318 | return nil, err |
| 319 | } |
| 320 | return &empty.Empty{}, nil |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 321 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 322 | 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] | 323 | } |
Scott Baker | 24f83e2 | 2020-03-30 16:14:28 -0700 | [diff] [blame] | 324 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 325 | // GetExtValue retrieves a value on a particular ONU |
| 326 | func (oo *OpenOLT) GetExtValue(ctx context.Context, extInfo *ic.GetExtValueMessage) (*voltha.ReturnValues, error) { |
Dinesh Belwalkar | db587af | 2020-02-27 15:37:16 -0800 | [diff] [blame] | 327 | var err error |
| 328 | resp := new(voltha.ReturnValues) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 329 | logger.Infow(ctx, "get_ext_value", log.Fields{"parent-device-id": extInfo.ParentDevice.Id, "onu-id": extInfo.ChildDevice.Id}) |
| 330 | if handler := oo.getDeviceHandler(extInfo.ParentDevice.Id); handler != nil { |
| 331 | if resp, err = handler.getExtValue(ctx, extInfo.ChildDevice, extInfo.ValueType); err != nil { |
| 332 | logger.Errorw(ctx, "error-occurred-during-get-ext-value", |
| 333 | 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] | 334 | return nil, err |
| 335 | } |
| 336 | } |
| 337 | return resp, nil |
| 338 | } |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 339 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 340 | //GetSingleValue handles get uni status on ONU and ondemand metric on OLT |
| 341 | func (oo *OpenOLT) GetSingleValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) { |
| 342 | logger.Infow(ctx, "single_get_value_request", log.Fields{"request": request}) |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 343 | |
| 344 | errResp := func(status extension.GetValueResponse_Status, |
| 345 | reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
| 346 | return &extension.SingleGetValueResponse{ |
| 347 | Response: &extension.GetValueResponse{ |
| 348 | Status: status, |
| 349 | ErrReason: reason, |
| 350 | }, |
| 351 | } |
| 352 | } |
| 353 | if handler := oo.getDeviceHandler(request.TargetId); handler != nil { |
| 354 | switch reqType := request.GetRequest().GetRequest().(type) { |
| 355 | case *extension.GetValueRequest_OltPortInfo: |
| 356 | return handler.getOltPortCounters(ctx, reqType.OltPortInfo), nil |
Himani Chawla | 2c8ae0f | 2021-05-18 23:27:00 +0530 | [diff] [blame] | 357 | case *extension.GetValueRequest_OnuPonInfo: |
| 358 | return handler.getOnuPonCounters(ctx, reqType.OnuPonInfo), nil |
Gamze Abaka | 85e9a14 | 2021-05-26 13:41:39 +0000 | [diff] [blame] | 359 | case *extension.GetValueRequest_RxPower: |
| 360 | return handler.getRxPower(ctx, reqType.RxPower), nil |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 361 | default: |
| 362 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_UNSUPPORTED), nil |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | logger.Infow(ctx, "Single_get_value_request failed ", log.Fields{"request": request}) |
| 367 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE_ID), nil |
| 368 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 369 | |
| 370 | /* |
| 371 | * OLT Inter-adapter service |
| 372 | */ |
| 373 | |
| 374 | // ProxyOmciRequest proxies an OMCI request from the child adapter |
| 375 | func (oo *OpenOLT) ProxyOmciRequest(ctx context.Context, request *ic.OmciMessage) (*empty.Empty, error) { |
| 376 | logger.Debugw(ctx, "proxy-omci-request", log.Fields{"request": request}) |
| 377 | |
| 378 | if handler := oo.getDeviceHandler(request.ParentDeviceId); handler != nil { |
| 379 | if err := handler.ProxyOmciMessage(ctx, request); err != nil { |
| 380 | return nil, errors.New(err.Error()) |
| 381 | } |
| 382 | return &empty.Empty{}, nil |
| 383 | } |
| 384 | return nil, olterrors.NewErrNotFound("no-device-handler", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.ChildDeviceId}, nil).Log() |
| 385 | } |
| 386 | |
| 387 | // GetTechProfileInstance returns an instance of a tech profile |
| 388 | func (oo *OpenOLT) GetTechProfileInstance(ctx context.Context, request *ic.TechProfileInstanceRequestMessage) (*ic.TechProfileDownloadMessage, error) { |
| 389 | logger.Debugw(ctx, "getting-tech-profile-request", log.Fields{"request": request}) |
| 390 | |
| 391 | targetDeviceID := request.ParentDeviceId |
| 392 | if targetDeviceID == "" { |
| 393 | return nil, olterrors.NewErrNotFound("parent-id-empty", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.DeviceId}, nil).Log() |
| 394 | } |
| 395 | if handler := oo.getDeviceHandler(targetDeviceID); handler != nil { |
| 396 | return handler.GetTechProfileDownloadMessage(ctx, request) |
| 397 | } |
| 398 | return nil, olterrors.NewErrNotFound("no-device-handler", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.DeviceId}, nil).Log() |
| 399 | |
| 400 | } |
| 401 | |
| 402 | /* |
| 403 | * |
| 404 | * Unimplemented APIs |
| 405 | * |
| 406 | */ |
| 407 | |
| 408 | //SimulateAlarm is unimplemented |
| 409 | func (oo *OpenOLT) SimulateAlarm(context.Context, *ic.SimulateAlarmMessage) (*voltha.OperationResp, error) { |
| 410 | return nil, olterrors.ErrNotImplemented |
| 411 | } |
| 412 | |
| 413 | //SetExtValue is unimplemented |
| 414 | func (oo *OpenOLT) SetExtValue(context.Context, *ic.SetExtValueMessage) (*empty.Empty, error) { |
| 415 | return nil, olterrors.ErrNotImplemented |
| 416 | } |
| 417 | |
| 418 | //SetSingleValue is unimplemented |
| 419 | func (oo *OpenOLT) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) { |
| 420 | return nil, olterrors.ErrNotImplemented |
| 421 | } |
| 422 | |
| 423 | //StartOmciTest not implemented |
| 424 | func (oo *OpenOLT) StartOmciTest(ctx context.Context, test *ic.OMCITest) (*voltha.TestResponse, error) { |
| 425 | return nil, olterrors.ErrNotImplemented |
| 426 | } |
| 427 | |
| 428 | //SuppressEvent unimplemented |
| 429 | func (oo *OpenOLT) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 430 | return nil, olterrors.ErrNotImplemented |
| 431 | } |
| 432 | |
| 433 | //UnSuppressEvent unimplemented |
| 434 | func (oo *OpenOLT) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 435 | return nil, olterrors.ErrNotImplemented |
| 436 | } |
| 437 | |
| 438 | //DownloadImage is unimplemented |
| 439 | func (oo *OpenOLT) DownloadImage(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 440 | return nil, olterrors.ErrNotImplemented |
| 441 | } |
| 442 | |
| 443 | //GetImageDownloadStatus is unimplemented |
| 444 | func (oo *OpenOLT) GetImageDownloadStatus(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 445 | return nil, olterrors.ErrNotImplemented |
| 446 | } |
| 447 | |
| 448 | //CancelImageDownload is unimplemented |
| 449 | func (oo *OpenOLT) CancelImageDownload(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 450 | return nil, olterrors.ErrNotImplemented |
| 451 | } |
| 452 | |
| 453 | //ActivateImageUpdate is unimplemented |
| 454 | func (oo *OpenOLT) ActivateImageUpdate(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 455 | return nil, olterrors.ErrNotImplemented |
| 456 | } |
| 457 | |
| 458 | //RevertImageUpdate is unimplemented |
| 459 | func (oo *OpenOLT) RevertImageUpdate(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 460 | return nil, olterrors.ErrNotImplemented |
| 461 | } |
| 462 | |
| 463 | //DownloadOnuImage unimplemented |
| 464 | func (oo *OpenOLT) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) { |
| 465 | return nil, olterrors.ErrNotImplemented |
| 466 | } |
| 467 | |
| 468 | //GetOnuImageStatus unimplemented |
| 469 | func (oo *OpenOLT) GetOnuImageStatus(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 470 | return nil, olterrors.ErrNotImplemented |
| 471 | } |
| 472 | |
| 473 | //AbortOnuImageUpgrade unimplemented |
| 474 | func (oo *OpenOLT) AbortOnuImageUpgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 475 | return nil, olterrors.ErrNotImplemented |
| 476 | } |
| 477 | |
| 478 | //GetOnuImages unimplemented |
| 479 | func (oo *OpenOLT) GetOnuImages(ctx context.Context, deviceID *common.ID) (*voltha.OnuImages, error) { |
| 480 | return nil, olterrors.ErrNotImplemented |
| 481 | } |
| 482 | |
| 483 | //ActivateOnuImage unimplemented |
| 484 | func (oo *OpenOLT) ActivateOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 485 | return nil, olterrors.ErrNotImplemented |
| 486 | } |
| 487 | |
| 488 | //CommitOnuImage unimplemented |
| 489 | func (oo *OpenOLT) CommitOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 490 | return nil, olterrors.ErrNotImplemented |
| 491 | } |
| 492 | |
| 493 | // UpdateFlowsBulk is unimplemented |
| 494 | func (oo *OpenOLT) UpdateFlowsBulk(ctx context.Context, flows *ic.BulkFlows) (*empty.Empty, error) { |
| 495 | return nil, olterrors.ErrNotImplemented |
| 496 | } |
| 497 | |
| 498 | //SelfTestDevice unimplemented |
| 499 | func (oo *OpenOLT) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 500 | return nil, olterrors.ErrNotImplemented |
| 501 | } |