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 { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 158 | handler := NewDeviceHandler(oo.coreClient, oo.eventProxy, device, oo, oo.configManager, oo.config) |
Gamze Abaka | c2c32a6 | 2021-03-11 11:44:18 +0000 | [diff] [blame] | 159 | handler.adapterPreviouslyConnected = true |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 160 | oo.addDeviceHandlerToMap(handler) |
| 161 | handler.transitionMap = NewTransitionMap(handler) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 162 | |
Maninder | e49938d | 2021-03-19 00:23:24 +0530 | [diff] [blame] | 163 | //Setting state to RECONCILING |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 164 | cgClient, err := oo.coreClient.GetCoreServiceClient() |
Maninder | e49938d | 2021-03-19 00:23:24 +0530 | [diff] [blame] | 165 | if err != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 166 | return nil, err |
Maninder | e49938d | 2021-03-19 00:23:24 +0530 | [diff] [blame] | 167 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 168 | subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), oo.rpcTimeout) |
| 169 | defer cancel() |
| 170 | if _, err := cgClient.DeviceStateUpdate(subCtx, &ic.DeviceStateFilter{ |
| 171 | DeviceId: device.Id, |
| 172 | OperStatus: voltha.OperStatus_RECONCILING, |
| 173 | ConnStatus: device.ConnectStatus, |
| 174 | }); err != nil { |
| 175 | return nil, olterrors.NewErrAdapter("device-update-failed", log.Fields{"device-id": device.Id}, err) |
| 176 | } |
| 177 | |
| 178 | handler.transitionMap.Handle(log.WithSpanFromContext(context.Background(), ctx), DeviceInit) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 179 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 180 | return &empty.Empty{}, nil |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 181 | } |
| 182 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 183 | //DisableDevice disables the given device |
| 184 | func (oo *OpenOLT) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 185 | logger.Infow(ctx, "disable-device", log.Fields{"device-id": device.Id}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 186 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 187 | if err := handler.DisableDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil { |
| 188 | return nil, err |
| 189 | } |
| 190 | return &empty.Empty{}, nil |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 191 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 192 | 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] | 193 | } |
| 194 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 195 | //ReEnableDevice enables the olt device after disable |
| 196 | func (oo *OpenOLT) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 197 | logger.Infow(ctx, "reenable-device", log.Fields{"device-id": device.Id}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 198 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 199 | if err := handler.ReenableDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil { |
| 200 | return nil, err |
| 201 | } |
| 202 | return &empty.Empty{}, nil |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 203 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 204 | 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] | 205 | } |
| 206 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 207 | //RebootDevice reboots the given device |
| 208 | func (oo *OpenOLT) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 209 | logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id}) |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 210 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 211 | if err := handler.RebootDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil { |
| 212 | return nil, err |
| 213 | } |
| 214 | return &empty.Empty{}, nil |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 215 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 216 | return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
| 217 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 218 | } |
| 219 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 220 | //DeleteDevice deletes a device |
| 221 | func (oo *OpenOLT) DeleteDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 222 | logger.Infow(ctx, "delete-device", log.Fields{"device-id": device.Id}) |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 223 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 224 | if err := handler.DeleteDevice(log.WithSpanFromContext(context.Background(), ctx), device); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 225 | 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] | 226 | } |
| 227 | oo.deleteDeviceHandlerToMap(handler) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 228 | return &empty.Empty{}, nil |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 229 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 230 | 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] | 231 | } |
| 232 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 233 | //UpdateFlowsIncrementally updates (add/remove) the flows on a given device |
| 234 | func (oo *OpenOLT) UpdateFlowsIncrementally(ctx context.Context, incrFlows *ic.IncrementalFlows) (*empty.Empty, error) { |
| 235 | logger.Infow(ctx, "update_flows_incrementally", log.Fields{"device-id": incrFlows.Device.Id, "flows": incrFlows.Flows, "flowMetadata": incrFlows.FlowMetadata}) |
| 236 | if handler := oo.getDeviceHandler(incrFlows.Device.Id); handler != nil { |
| 237 | if err := handler.UpdateFlowsIncrementally(log.WithSpanFromContext(context.Background(), ctx), incrFlows.Device, incrFlows.Flows, incrFlows.Groups, incrFlows.FlowMetadata); err != nil { |
| 238 | return nil, err |
| 239 | } |
| 240 | return &empty.Empty{}, nil |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -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": incrFlows.Device.Id}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 243 | } |
| 244 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 245 | //UpdatePmConfig returns PmConfigs nil or error |
| 246 | func (oo *OpenOLT) UpdatePmConfig(ctx context.Context, configs *ic.PmConfigsInfo) (*empty.Empty, error) { |
| 247 | logger.Debugw(ctx, "update_pm_config", log.Fields{"device-id": configs.DeviceId, "pm-configs": configs.PmConfigs}) |
| 248 | if handler := oo.getDeviceHandler(configs.DeviceId); handler != nil { |
| 249 | handler.UpdatePmConfig(log.WithSpanFromContext(context.Background(), ctx), configs.PmConfigs) |
| 250 | return &empty.Empty{}, nil |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 251 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 252 | 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] | 253 | } |
| 254 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 255 | //SendPacketOut sends packet out to the device |
| 256 | func (oo *OpenOLT) SendPacketOut(ctx context.Context, packet *ic.PacketOut) (*empty.Empty, error) { |
| 257 | logger.Debugw(ctx, "send_packet_out", log.Fields{"device-id": packet.DeviceId, "egress_port_no": packet.EgressPortNo, "pkt": packet.Packet}) |
| 258 | if handler := oo.getDeviceHandler(packet.DeviceId); handler != nil { |
| 259 | if err := handler.PacketOut(log.WithSpanFromContext(context.Background(), ctx), packet.EgressPortNo, packet.Packet); err != nil { |
| 260 | return nil, err |
| 261 | } |
| 262 | return &empty.Empty{}, nil |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 263 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 264 | return nil, olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": packet.DeviceId}, nil) |
| 265 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 266 | } |
| 267 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 268 | // EnablePort to Enable PON/NNI interface |
| 269 | func (oo *OpenOLT) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 270 | logger.Infow(ctx, "enable_port", log.Fields{"device-id": port.DeviceId, "port": port}) |
| 271 | if err := oo.enableDisablePort(log.WithSpanFromContext(context.Background(), ctx), port.DeviceId, port, true); err != nil { |
| 272 | return nil, err |
| 273 | } |
| 274 | return &empty.Empty{}, nil |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 275 | } |
| 276 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 277 | // DisablePort to Disable pon/nni interface |
| 278 | func (oo *OpenOLT) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { |
| 279 | logger.Infow(ctx, "disable_port", log.Fields{"device-id": port.DeviceId, "port": port}) |
| 280 | if err := oo.enableDisablePort(log.WithSpanFromContext(context.Background(), ctx), port.DeviceId, port, false); err != nil { |
| 281 | return nil, err |
| 282 | } |
| 283 | return &empty.Empty{}, nil |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | // enableDisablePort to Disable pon or Enable PON interface |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 287 | 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] | 288 | logger.Infow(ctx, "enableDisablePort", log.Fields{"device-id": deviceID, "port": port}) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 289 | if port == nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 290 | return olterrors.NewErrInvalidValue(log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 291 | "reason": "port cannot be nil", |
| 292 | "device-id": deviceID, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 293 | "port": nil}, nil) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 294 | } |
| 295 | if handler := oo.getDeviceHandler(deviceID); handler != nil { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 296 | logger.Debugw(ctx, "Enable_Disable_Port", log.Fields{"device-id": deviceID, "port": port}) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 297 | if enablePort { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 298 | if err := handler.EnablePort(ctx, port); err != nil { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 299 | 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] | 300 | } |
| 301 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 302 | if err := handler.DisablePort(ctx, port); err != nil { |
divyadesai | 3af43e1 | 2020-08-18 07:10:54 +0000 | [diff] [blame] | 303 | 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] | 304 | } |
| 305 | } |
| 306 | } |
| 307 | return nil |
| 308 | } |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 309 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 310 | //ChildDeviceLost deletes the ONU and its references from PONResources |
| 311 | 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] | 312 | logger.Infow(ctx, "Child-device-lost", log.Fields{"parent-device-id": childDevice.ParentId, "child-device-id": childDevice.Id}) |
| 313 | if handler := oo.getDeviceHandler(childDevice.ParentId); handler != nil { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 314 | if err := handler.ChildDeviceLost(log.WithSpanFromContext(context.Background(), ctx), childDevice.ParentPortNo, childDevice.ProxyAddress.OnuId, childDevice.SerialNumber); err != nil { |
| 315 | return nil, err |
| 316 | } |
| 317 | return &empty.Empty{}, nil |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 318 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 319 | 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] | 320 | } |
Scott Baker | 24f83e2 | 2020-03-30 16:14:28 -0700 | [diff] [blame] | 321 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 322 | // GetExtValue retrieves a value on a particular ONU |
| 323 | 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] | 324 | var err error |
| 325 | resp := new(voltha.ReturnValues) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 326 | logger.Infow(ctx, "get_ext_value", log.Fields{"parent-device-id": extInfo.ParentDevice.Id, "onu-id": extInfo.ChildDevice.Id}) |
| 327 | if handler := oo.getDeviceHandler(extInfo.ParentDevice.Id); handler != nil { |
| 328 | if resp, err = handler.getExtValue(ctx, extInfo.ChildDevice, extInfo.ValueType); err != nil { |
| 329 | logger.Errorw(ctx, "error-occurred-during-get-ext-value", |
| 330 | 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] | 331 | return nil, err |
| 332 | } |
| 333 | } |
| 334 | return resp, nil |
| 335 | } |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 336 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 337 | //GetSingleValue handles get uni status on ONU and ondemand metric on OLT |
| 338 | func (oo *OpenOLT) GetSingleValue(ctx context.Context, request *extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) { |
| 339 | logger.Infow(ctx, "single_get_value_request", log.Fields{"request": request}) |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 340 | |
| 341 | errResp := func(status extension.GetValueResponse_Status, |
| 342 | reason extension.GetValueResponse_ErrorReason) *extension.SingleGetValueResponse { |
| 343 | return &extension.SingleGetValueResponse{ |
| 344 | Response: &extension.GetValueResponse{ |
| 345 | Status: status, |
| 346 | ErrReason: reason, |
| 347 | }, |
| 348 | } |
| 349 | } |
| 350 | if handler := oo.getDeviceHandler(request.TargetId); handler != nil { |
| 351 | switch reqType := request.GetRequest().GetRequest().(type) { |
| 352 | case *extension.GetValueRequest_OltPortInfo: |
| 353 | return handler.getOltPortCounters(ctx, reqType.OltPortInfo), nil |
Himani Chawla | 2c8ae0f | 2021-05-18 23:27:00 +0530 | [diff] [blame] | 354 | case *extension.GetValueRequest_OnuPonInfo: |
| 355 | return handler.getOnuPonCounters(ctx, reqType.OnuPonInfo), nil |
Gamze Abaka | 85e9a14 | 2021-05-26 13:41:39 +0000 | [diff] [blame] | 356 | case *extension.GetValueRequest_RxPower: |
| 357 | return handler.getRxPower(ctx, reqType.RxPower), nil |
kesavand | 6212621 | 2021-01-12 04:56:06 -0500 | [diff] [blame] | 358 | default: |
| 359 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_UNSUPPORTED), nil |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | logger.Infow(ctx, "Single_get_value_request failed ", log.Fields{"request": request}) |
| 364 | return errResp(extension.GetValueResponse_ERROR, extension.GetValueResponse_INVALID_DEVICE_ID), nil |
| 365 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 366 | |
| 367 | /* |
| 368 | * OLT Inter-adapter service |
| 369 | */ |
| 370 | |
| 371 | // ProxyOmciRequest proxies an OMCI request from the child adapter |
| 372 | func (oo *OpenOLT) ProxyOmciRequest(ctx context.Context, request *ic.OmciMessage) (*empty.Empty, error) { |
| 373 | logger.Debugw(ctx, "proxy-omci-request", log.Fields{"request": request}) |
| 374 | |
| 375 | if handler := oo.getDeviceHandler(request.ParentDeviceId); handler != nil { |
| 376 | if err := handler.ProxyOmciMessage(ctx, request); err != nil { |
| 377 | return nil, errors.New(err.Error()) |
| 378 | } |
| 379 | return &empty.Empty{}, nil |
| 380 | } |
| 381 | return nil, olterrors.NewErrNotFound("no-device-handler", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.ChildDeviceId}, nil).Log() |
| 382 | } |
| 383 | |
| 384 | // GetTechProfileInstance returns an instance of a tech profile |
| 385 | func (oo *OpenOLT) GetTechProfileInstance(ctx context.Context, request *ic.TechProfileInstanceRequestMessage) (*ic.TechProfileDownloadMessage, error) { |
| 386 | logger.Debugw(ctx, "getting-tech-profile-request", log.Fields{"request": request}) |
| 387 | |
| 388 | targetDeviceID := request.ParentDeviceId |
| 389 | if targetDeviceID == "" { |
| 390 | return nil, olterrors.NewErrNotFound("parent-id-empty", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.DeviceId}, nil).Log() |
| 391 | } |
| 392 | if handler := oo.getDeviceHandler(targetDeviceID); handler != nil { |
| 393 | return handler.GetTechProfileDownloadMessage(ctx, request) |
| 394 | } |
| 395 | return nil, olterrors.NewErrNotFound("no-device-handler", log.Fields{"parent-device-id": request.ParentDeviceId, "child-device-id": request.DeviceId}, nil).Log() |
| 396 | |
| 397 | } |
| 398 | |
| 399 | /* |
| 400 | * |
| 401 | * Unimplemented APIs |
| 402 | * |
| 403 | */ |
| 404 | |
| 405 | //SimulateAlarm is unimplemented |
| 406 | func (oo *OpenOLT) SimulateAlarm(context.Context, *ic.SimulateAlarmMessage) (*voltha.OperationResp, error) { |
| 407 | return nil, olterrors.ErrNotImplemented |
| 408 | } |
| 409 | |
| 410 | //SetExtValue is unimplemented |
| 411 | func (oo *OpenOLT) SetExtValue(context.Context, *ic.SetExtValueMessage) (*empty.Empty, error) { |
| 412 | return nil, olterrors.ErrNotImplemented |
| 413 | } |
| 414 | |
| 415 | //SetSingleValue is unimplemented |
| 416 | func (oo *OpenOLT) SetSingleValue(context.Context, *extension.SingleSetValueRequest) (*extension.SingleSetValueResponse, error) { |
| 417 | return nil, olterrors.ErrNotImplemented |
| 418 | } |
| 419 | |
| 420 | //StartOmciTest not implemented |
| 421 | func (oo *OpenOLT) StartOmciTest(ctx context.Context, test *ic.OMCITest) (*voltha.TestResponse, error) { |
| 422 | return nil, olterrors.ErrNotImplemented |
| 423 | } |
| 424 | |
| 425 | //SuppressEvent unimplemented |
| 426 | func (oo *OpenOLT) SuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 427 | return nil, olterrors.ErrNotImplemented |
| 428 | } |
| 429 | |
| 430 | //UnSuppressEvent unimplemented |
| 431 | func (oo *OpenOLT) UnSuppressEvent(ctx context.Context, filter *voltha.EventFilter) (*empty.Empty, error) { |
| 432 | return nil, olterrors.ErrNotImplemented |
| 433 | } |
| 434 | |
| 435 | //DownloadImage is unimplemented |
| 436 | func (oo *OpenOLT) DownloadImage(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 437 | return nil, olterrors.ErrNotImplemented |
| 438 | } |
| 439 | |
| 440 | //GetImageDownloadStatus is unimplemented |
| 441 | func (oo *OpenOLT) GetImageDownloadStatus(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 442 | return nil, olterrors.ErrNotImplemented |
| 443 | } |
| 444 | |
| 445 | //CancelImageDownload is unimplemented |
| 446 | func (oo *OpenOLT) CancelImageDownload(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 447 | return nil, olterrors.ErrNotImplemented |
| 448 | } |
| 449 | |
| 450 | //ActivateImageUpdate is unimplemented |
| 451 | func (oo *OpenOLT) ActivateImageUpdate(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 452 | return nil, olterrors.ErrNotImplemented |
| 453 | } |
| 454 | |
| 455 | //RevertImageUpdate is unimplemented |
| 456 | func (oo *OpenOLT) RevertImageUpdate(ctx context.Context, imageInfo *ic.ImageDownloadMessage) (*voltha.ImageDownload, error) { |
| 457 | return nil, olterrors.ErrNotImplemented |
| 458 | } |
| 459 | |
| 460 | //DownloadOnuImage unimplemented |
| 461 | func (oo *OpenOLT) DownloadOnuImage(ctx context.Context, request *voltha.DeviceImageDownloadRequest) (*voltha.DeviceImageResponse, error) { |
| 462 | return nil, olterrors.ErrNotImplemented |
| 463 | } |
| 464 | |
| 465 | //GetOnuImageStatus unimplemented |
| 466 | func (oo *OpenOLT) GetOnuImageStatus(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 467 | return nil, olterrors.ErrNotImplemented |
| 468 | } |
| 469 | |
| 470 | //AbortOnuImageUpgrade unimplemented |
| 471 | func (oo *OpenOLT) AbortOnuImageUpgrade(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 472 | return nil, olterrors.ErrNotImplemented |
| 473 | } |
| 474 | |
| 475 | //GetOnuImages unimplemented |
| 476 | func (oo *OpenOLT) GetOnuImages(ctx context.Context, deviceID *common.ID) (*voltha.OnuImages, error) { |
| 477 | return nil, olterrors.ErrNotImplemented |
| 478 | } |
| 479 | |
| 480 | //ActivateOnuImage unimplemented |
| 481 | func (oo *OpenOLT) ActivateOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 482 | return nil, olterrors.ErrNotImplemented |
| 483 | } |
| 484 | |
| 485 | //CommitOnuImage unimplemented |
| 486 | func (oo *OpenOLT) CommitOnuImage(ctx context.Context, in *voltha.DeviceImageRequest) (*voltha.DeviceImageResponse, error) { |
| 487 | return nil, olterrors.ErrNotImplemented |
| 488 | } |
| 489 | |
| 490 | // UpdateFlowsBulk is unimplemented |
| 491 | func (oo *OpenOLT) UpdateFlowsBulk(ctx context.Context, flows *ic.BulkFlows) (*empty.Empty, error) { |
| 492 | return nil, olterrors.ErrNotImplemented |
| 493 | } |
| 494 | |
| 495 | //SelfTestDevice unimplemented |
| 496 | func (oo *OpenOLT) SelfTestDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 497 | return nil, olterrors.ErrNotImplemented |
| 498 | } |