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" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 22 | "sync" |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 23 | "time" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 24 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 25 | "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif" |
| 26 | "github.com/opencord/voltha-lib-go/v3/pkg/kafka" |
| 27 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 28 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/config" |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 29 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 30 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 31 | "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 32 | "github.com/opencord/voltha-protos/v3/go/voltha" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 33 | ) |
| 34 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 35 | //OpenOLT structure holds the OLT information |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 36 | type OpenOLT struct { |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 37 | deviceHandlers map[string]*DeviceHandler |
| 38 | coreProxy adapterif.CoreProxy |
| 39 | adapterProxy adapterif.AdapterProxy |
| 40 | eventProxy adapterif.EventProxy |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 41 | kafkaICProxy kafka.InterContainerProxy |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 42 | config *config.AdapterFlags |
| 43 | numOnus int |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 44 | KVStoreAddress string |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 45 | KVStoreType string |
| 46 | exitChannel chan int |
| 47 | HeartbeatCheckInterval time.Duration |
| 48 | HeartbeatFailReportInterval time.Duration |
| 49 | GrpcTimeoutInterval time.Duration |
| 50 | lockDeviceHandlersMap sync.RWMutex |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 51 | } |
| 52 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 53 | //NewOpenOLT returns a new instance of OpenOLT |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 54 | func NewOpenOLT(ctx context.Context, kafkaICProxy kafka.InterContainerProxy, |
kdarapu | 381c690 | 2019-07-31 18:23:16 +0530 | [diff] [blame] | 55 | coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy, |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 56 | eventProxy adapterif.EventProxy, cfg *config.AdapterFlags) *OpenOLT { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 57 | var openOLT OpenOLT |
| 58 | openOLT.exitChannel = make(chan int, 1) |
| 59 | openOLT.deviceHandlers = make(map[string]*DeviceHandler) |
| 60 | openOLT.kafkaICProxy = kafkaICProxy |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 61 | openOLT.config = cfg |
| 62 | openOLT.numOnus = cfg.OnuNumber |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 63 | openOLT.coreProxy = coreProxy |
| 64 | openOLT.adapterProxy = adapterProxy |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 65 | openOLT.eventProxy = eventProxy |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 66 | openOLT.KVStoreAddress = cfg.KVStoreAddress |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 67 | openOLT.KVStoreType = cfg.KVStoreType |
| 68 | openOLT.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval |
| 69 | openOLT.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval |
| 70 | openOLT.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 71 | openOLT.lockDeviceHandlersMap = sync.RWMutex{} |
| 72 | return &openOLT |
| 73 | } |
| 74 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 75 | //Start starts (logs) the device manager |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 76 | func (oo *OpenOLT) Start(ctx context.Context) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 77 | logger.Info("starting-device-manager") |
| 78 | logger.Info("device-manager-started") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 79 | return nil |
| 80 | } |
| 81 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 82 | //Stop terminates the session |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 83 | func (oo *OpenOLT) Stop(ctx context.Context) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 84 | logger.Info("stopping-device-manager") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 85 | oo.exitChannel <- 1 |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 86 | logger.Info("device-manager-stopped") |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 87 | return nil |
| 88 | } |
| 89 | |
| 90 | func sendResponse(ctx context.Context, ch chan interface{}, result interface{}) { |
| 91 | if ctx.Err() == nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 92 | // Returned response only of the ctx has not been canceled/timeout/etc |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 93 | // Channel is automatically closed when a context is Done |
| 94 | ch <- result |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 95 | logger.Debugw("sendResponse", log.Fields{"result": result}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 96 | } else { |
| 97 | // Should the transaction be reverted back? |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 98 | logger.Debugw("sendResponse-context-error", log.Fields{"context-error": ctx.Err()}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
| 102 | func (oo *OpenOLT) addDeviceHandlerToMap(agent *DeviceHandler) { |
| 103 | oo.lockDeviceHandlersMap.Lock() |
| 104 | defer oo.lockDeviceHandlersMap.Unlock() |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 105 | if _, exist := oo.deviceHandlers[agent.device.Id]; !exist { |
| 106 | oo.deviceHandlers[agent.device.Id] = agent |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
| 110 | func (oo *OpenOLT) deleteDeviceHandlerToMap(agent *DeviceHandler) { |
| 111 | oo.lockDeviceHandlersMap.Lock() |
| 112 | defer oo.lockDeviceHandlersMap.Unlock() |
Thomas Lee S | 985938d | 2020-05-04 11:40:41 +0530 | [diff] [blame] | 113 | delete(oo.deviceHandlers, agent.device.Id) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 114 | } |
| 115 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 116 | func (oo *OpenOLT) getDeviceHandler(deviceID string) *DeviceHandler { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 117 | oo.lockDeviceHandlersMap.Lock() |
| 118 | defer oo.lockDeviceHandlersMap.Unlock() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 119 | if agent, ok := oo.deviceHandlers[deviceID]; ok { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 120 | return agent |
| 121 | } |
| 122 | return nil |
| 123 | } |
| 124 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 125 | //createDeviceTopic returns |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 126 | func (oo *OpenOLT) createDeviceTopic(device *voltha.Device) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 127 | logger.Infow("create-device-topic", log.Fields{"deviceId": device.Id}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 128 | defaultTopic := oo.kafkaICProxy.GetDefaultTopic() |
| 129 | deviceTopic := kafka.Topic{Name: defaultTopic.Name + "_" + device.Id} |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 130 | // TODO for the offset |
| 131 | if err := oo.kafkaICProxy.SubscribeWithDefaultRequestHandler(deviceTopic, 0); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 132 | return olterrors.NewErrAdapter("subscribe-for-device-topic-failed", log.Fields{"device-topic": deviceTopic}, err) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 133 | } |
| 134 | return nil |
| 135 | } |
| 136 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 137 | // Adopt_device creates a new device handler if not present already and then adopts the device |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 138 | func (oo *OpenOLT) Adopt_device(device *voltha.Device) error { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 139 | ctx := context.Background() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 140 | if device == nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 141 | return olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil).Log() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 142 | } |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 143 | logger.Infow("adopt-device", log.Fields{"deviceId": device.Id}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 144 | var handler *DeviceHandler |
| 145 | if handler = oo.getDeviceHandler(device.Id); handler == nil { |
Devmalya Paul | fb990a5 | 2019-07-09 10:01:49 -0400 | [diff] [blame] | 146 | handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 147 | oo.addDeviceHandlerToMap(handler) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 148 | go handler.AdoptDevice(ctx, device) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 149 | // Launch the creation of the device topic |
| 150 | // go oo.createDeviceTopic(device) |
| 151 | } |
| 152 | return nil |
| 153 | } |
| 154 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 155 | //Get_ofp_device_info returns OFP information for the given device |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 156 | func (oo *OpenOLT) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 157 | logger.Infow("Get_ofp_device_info", log.Fields{"deviceId": device.Id}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 158 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
| 159 | return handler.GetOfpDeviceInfo(device) |
| 160 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 161 | 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] | 162 | } |
| 163 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 164 | //Get_ofp_port_info returns OFP port information for the given device |
| 165 | func (oo *OpenOLT) Get_ofp_port_info(device *voltha.Device, portNo int64) (*ic.PortCapability, error) { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 166 | logger.Infow("Get_ofp_port_info", log.Fields{"deviceId": device.Id}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 167 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 168 | return handler.GetOfpPortInfo(device, portNo) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 169 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 170 | 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] | 171 | } |
| 172 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 173 | //Process_inter_adapter_message sends messages to a target device (between adapters) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 174 | func (oo *OpenOLT) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error { |
Andrea Campanella | 9931ad6 | 2020-04-28 15:11:06 +0200 | [diff] [blame] | 175 | logger.Debugw("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id}) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 176 | targetDevice := msg.Header.ProxyDeviceId // Request? |
| 177 | if targetDevice == "" && msg.Header.ToDeviceId != "" { |
| 178 | // Typical response |
| 179 | targetDevice = msg.Header.ToDeviceId |
| 180 | } |
| 181 | if handler := oo.getDeviceHandler(targetDevice); handler != nil { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 182 | return handler.ProcessInterAdapterMessage(msg) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 183 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 184 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": targetDevice}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 185 | } |
| 186 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 187 | //Adapter_descriptor not implemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 188 | func (oo *OpenOLT) Adapter_descriptor() error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 189 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 190 | } |
| 191 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 192 | //Device_types unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 193 | func (oo *OpenOLT) Device_types() (*voltha.DeviceTypes, error) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 194 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 195 | } |
| 196 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 197 | //Health returns unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 198 | func (oo *OpenOLT) Health() (*voltha.HealthStatus, error) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 199 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 200 | } |
| 201 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 202 | //Reconcile_device unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 203 | func (oo *OpenOLT) Reconcile_device(device *voltha.Device) error { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 204 | ctx := context.Background() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 205 | if device == nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 206 | return olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 207 | } |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 208 | logger.Infow("reconcile-device", log.Fields{"deviceId": device.Id}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 209 | var handler *DeviceHandler |
| 210 | if handler = oo.getDeviceHandler(device.Id); handler == nil { |
| 211 | handler := NewDeviceHandler(oo.coreProxy, oo.adapterProxy, oo.eventProxy, device, oo) |
| 212 | oo.addDeviceHandlerToMap(handler) |
| 213 | handler.transitionMap = NewTransitionMap(handler) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 214 | handler.transitionMap.Handle(ctx, DeviceInit) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 215 | } |
| 216 | return nil |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 217 | } |
| 218 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 219 | //Abandon_device unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 220 | func (oo *OpenOLT) Abandon_device(device *voltha.Device) error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 221 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 222 | } |
| 223 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 224 | //Disable_device disables the given device |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 225 | func (oo *OpenOLT) Disable_device(device *voltha.Device) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 226 | logger.Infow("disable-device", log.Fields{"deviceId": device.Id}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 227 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
| 228 | return handler.DisableDevice(device) |
| 229 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 230 | return 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 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 233 | //Reenable_device enables the olt device after disable |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 234 | func (oo *OpenOLT) Reenable_device(device *voltha.Device) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 235 | logger.Infow("reenable-device", log.Fields{"deviceId": device.Id}) |
Girish Gowdru | 5ba46c9 | 2019-04-25 05:00:05 -0400 | [diff] [blame] | 236 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
| 237 | return handler.ReenableDevice(device) |
| 238 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 239 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 240 | } |
| 241 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 242 | //Reboot_device reboots the given device |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 243 | func (oo *OpenOLT) Reboot_device(device *voltha.Device) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 244 | logger.Infow("reboot-device", log.Fields{"deviceId": device.Id}) |
Girish Gowdru | 0fe5f7e | 2019-05-28 05:12:27 -0400 | [diff] [blame] | 245 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
| 246 | return handler.RebootDevice(device) |
| 247 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 248 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 249 | } |
| 250 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 251 | //Self_test_device unimplented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 252 | func (oo *OpenOLT) Self_test_device(device *voltha.Device) error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 253 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 254 | } |
| 255 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 256 | //Delete_device unimplemented |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 257 | func (oo *OpenOLT) Delete_device(device *voltha.Device) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 258 | logger.Infow("delete-device", log.Fields{"deviceId": device.Id}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 259 | ctx := context.Background() |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 260 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 261 | if err := handler.DeleteDevice(ctx, device); err != nil { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 262 | logger.Errorw("failed-to-handle-delete-device", log.Fields{"device-id": device.Id}) |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 263 | } |
| 264 | oo.deleteDeviceHandlerToMap(handler) |
| 265 | return nil |
| 266 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 267 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 268 | } |
| 269 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 270 | //Get_device_details unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 271 | func (oo *OpenOLT) Get_device_details(device *voltha.Device) error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 272 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 273 | } |
| 274 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 275 | //Update_flows_bulk returns |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 276 | func (oo *OpenOLT) Update_flows_bulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 277 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 278 | } |
| 279 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 280 | //Update_flows_incrementally updates (add/remove) the flows on a given device |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 281 | func (oo *OpenOLT) Update_flows_incrementally(device *voltha.Device, flows *openflow_13.FlowChanges, groups *openflow_13.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 282 | logger.Debugw("Update_flows_incrementally", log.Fields{"deviceId": device.Id, "flows": flows, "flowMetadata": flowMetadata}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 283 | ctx := context.Background() |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 284 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 285 | return handler.UpdateFlowsIncrementally(ctx, device, flows, groups, flowMetadata) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 286 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 287 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 288 | } |
| 289 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 290 | //Update_pm_config returns PmConfigs nil or error |
| 291 | func (oo *OpenOLT) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error { |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame^] | 292 | logger.Debugw("Update_pm_config", log.Fields{"device-id": device.Id, "pm-configs": pmConfigs}) |
| 293 | if handler := oo.getDeviceHandler(device.Id); handler != nil { |
| 294 | handler.UpdatePmConfig(pmConfigs) |
| 295 | return nil |
| 296 | } |
| 297 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": device.Id}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 298 | } |
| 299 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 300 | //Receive_packet_out sends packet out to the device |
| 301 | func (oo *OpenOLT) Receive_packet_out(deviceID string, egressPortNo int, packet *openflow_13.OfpPacketOut) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 302 | logger.Debugw("Receive_packet_out", log.Fields{"deviceId": deviceID, "egress_port_no": egressPortNo, "pkt": packet}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 303 | ctx := context.Background() |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 304 | if handler := oo.getDeviceHandler(deviceID); handler != nil { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 305 | return handler.PacketOut(ctx, egressPortNo, packet) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 306 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 307 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil) |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 308 | } |
| 309 | |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 310 | //Suppress_event unimplemented |
| 311 | func (oo *OpenOLT) Suppress_event(filter *voltha.EventFilter) error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 312 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 313 | } |
| 314 | |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 315 | //Unsuppress_event unimplemented |
| 316 | func (oo *OpenOLT) Unsuppress_event(filter *voltha.EventFilter) error { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 317 | return olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 318 | } |
| 319 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 320 | //Download_image unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 321 | func (oo *OpenOLT) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 322 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 323 | } |
| 324 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 325 | //Get_image_download_status unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 326 | func (oo *OpenOLT) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 327 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 328 | } |
| 329 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 330 | //Cancel_image_download unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 331 | func (oo *OpenOLT) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 332 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 333 | } |
| 334 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 335 | //Activate_image_update unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 336 | func (oo *OpenOLT) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 337 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 338 | } |
| 339 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 340 | //Revert_image_update unimplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 341 | func (oo *OpenOLT) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 342 | return nil, olterrors.ErrNotImplemented |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 343 | } |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 344 | |
| 345 | // Enable_port to Enable PON/NNI interface |
| 346 | func (oo *OpenOLT) Enable_port(deviceID string, port *voltha.Port) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 347 | logger.Infow("Enable_port", log.Fields{"deviceId": deviceID, "port": port}) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 348 | return oo.enableDisablePort(deviceID, port, true) |
| 349 | } |
| 350 | |
| 351 | // Disable_port to Disable pon/nni interface |
| 352 | func (oo *OpenOLT) Disable_port(deviceID string, port *voltha.Port) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 353 | logger.Infow("Disable_port", log.Fields{"deviceId": deviceID, "port": port}) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 354 | return oo.enableDisablePort(deviceID, port, false) |
| 355 | } |
| 356 | |
| 357 | // enableDisablePort to Disable pon or Enable PON interface |
| 358 | func (oo *OpenOLT) enableDisablePort(deviceID string, port *voltha.Port, enablePort bool) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 359 | logger.Infow("enableDisablePort", log.Fields{"deviceId": deviceID, "port": port}) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 360 | if port == nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 361 | return olterrors.NewErrInvalidValue(log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 362 | "reason": "port cannot be nil", |
| 363 | "device-id": deviceID, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 364 | "port": nil}, nil) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 365 | } |
| 366 | if handler := oo.getDeviceHandler(deviceID); handler != nil { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 367 | logger.Debugw("Enable_Disable_Port", log.Fields{"deviceId": deviceID, "port": port}) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 368 | if enablePort { |
| 369 | if err := handler.EnablePort(port); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 370 | return olterrors.NewErrAdapter("error-occurred-during-enable-port", log.Fields{"deviceID": deviceID, "port": port}, err) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 371 | } |
| 372 | } else { |
| 373 | if err := handler.DisablePort(port); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 374 | return olterrors.NewErrAdapter("error-occurred-during-disable-port", log.Fields{"deviceID": deviceID, "port": port}, err) |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | } |
| 378 | return nil |
| 379 | } |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 380 | |
| 381 | //Child_device_lost deletes the ONU and its references from PONResources |
| 382 | func (oo *OpenOLT) Child_device_lost(deviceID string, pPortNo uint32, onuID uint32) error { |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 383 | logger.Infow("Child-device-lost", log.Fields{"parentId": deviceID}) |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 384 | ctx := context.Background() |
| 385 | if handler := oo.getDeviceHandler(deviceID); handler != nil { |
| 386 | return handler.ChildDeviceLost(ctx, pPortNo, onuID) |
| 387 | } |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 388 | return olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": deviceID}, nil).Log() |
Chaitrashree G S | 1a55b88 | 2020-02-04 17:35:35 -0500 | [diff] [blame] | 389 | } |
Scott Baker | 24f83e2 | 2020-03-30 16:14:28 -0700 | [diff] [blame] | 390 | |
| 391 | //Start_omci_test not implemented |
| 392 | func (oo *OpenOLT) Start_omci_test(device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) { |
| 393 | return nil, olterrors.ErrNotImplemented |
| 394 | } |
Dinesh Belwalkar | db587af | 2020-02-27 15:37:16 -0800 | [diff] [blame] | 395 | |
Andrea Campanella | 9931ad6 | 2020-04-28 15:11:06 +0200 | [diff] [blame] | 396 | //Get_ext_value retrieves a value on a particular ONU |
Dinesh Belwalkar | db587af | 2020-02-27 15:37:16 -0800 | [diff] [blame] | 397 | func (oo *OpenOLT) Get_ext_value(deviceID string, device *voltha.Device, valueparam voltha.ValueType_Type) (*voltha.ReturnValues, error) { |
| 398 | var err error |
| 399 | resp := new(voltha.ReturnValues) |
| 400 | log.Infow("Get_ext_value", log.Fields{"device-id": deviceID, "onu-id": device.Id}) |
| 401 | if handler := oo.getDeviceHandler(deviceID); handler != nil { |
| 402 | if resp, err = handler.getExtValue(device, valueparam); err != nil { |
| 403 | log.Errorw("error-occurred-during-get-ext-value", log.Fields{"device-id": deviceID, "onu-id": device.Id, |
| 404 | "error": err}) |
| 405 | return nil, err |
| 406 | } |
| 407 | } |
| 408 | return resp, nil |
| 409 | } |