blob: 96dfb33a2bc973f0ec0e1a6c08118f68aefacaa9 [file] [log] [blame]
khenaidooab1f7bd2019-11-14 14:00:27 -05001/*
2 * Copyright 2019-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 */
npujar1d86a522019-11-14 17:11:16 +053016
khenaidooab1f7bd2019-11-14 14:00:27 -050017package mocks
18
19import (
20 "context"
Scott Baker432f9be2020-03-26 11:56:30 -070021 "errors"
khenaidooab1f7bd2019-11-14 14:00:27 -050022 "fmt"
khenaidood948f772021-08-11 17:49:24 -040023 "strconv"
Kent Hagerman2a07b862020-06-19 15:23:07 -040024 "strings"
25
khenaidood948f772021-08-11 17:49:24 -040026 "github.com/golang/protobuf/ptypes/empty"
27 "github.com/opencord/voltha-lib-go/v7/pkg/probe"
28 "github.com/opencord/voltha-protos/v5/go/common"
29 "github.com/opencord/voltha-protos/v5/go/extension"
khenaidoo9beaaf12021-10-19 17:32:01 -040030 "github.com/opencord/voltha-protos/v5/go/omci"
khenaidood948f772021-08-11 17:49:24 -040031 "github.com/phayes/freeport"
32
khenaidooab1f7bd2019-11-14 14:00:27 -050033 "github.com/gogo/protobuf/proto"
khenaidood948f772021-08-11 17:49:24 -040034 com "github.com/opencord/voltha-lib-go/v7/pkg/adapters/common"
35 vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc"
36 "github.com/opencord/voltha-lib-go/v7/pkg/log"
khenaidoo9beaaf12021-10-19 17:32:01 -040037 ca "github.com/opencord/voltha-protos/v5/go/core_adapter"
khenaidood948f772021-08-11 17:49:24 -040038 of "github.com/opencord/voltha-protos/v5/go/openflow_13"
39 "github.com/opencord/voltha-protos/v5/go/voltha"
khenaidooab1f7bd2019-11-14 14:00:27 -050040)
41
npujar1d86a522019-11-14 17:11:16 +053042// OLTAdapter represent OLT adapter
khenaidooab1f7bd2019-11-14 14:00:27 -050043type OLTAdapter struct {
khenaidoo8b4abbf2020-04-24 17:04:30 -040044 *Adapter
khenaidood948f772021-08-11 17:49:24 -040045 ChildDeviceType string
46 childVendor string
47 grpcServer *vgrpc.GrpcServer
khenaidooab1f7bd2019-11-14 14:00:27 -050048}
49
npujar1d86a522019-11-14 17:11:16 +053050// NewOLTAdapter - creates OLT adapter instance
khenaidood948f772021-08-11 17:49:24 -040051func NewOLTAdapter(ctx context.Context, coreEndpoint string, deviceType string, vendor string, childDeviceType, childVendor string) *OLTAdapter {
52 // Get an available port
53 grpcPort, err := freeport.GetFreePort()
54 if err != nil {
55 logger.Fatalw(ctx, "no-free-port", log.Fields{"error": err})
khenaidoo67b22152020-03-02 16:01:25 -050056 }
khenaidood948f772021-08-11 17:49:24 -040057
58 // start gRPC handler
59 listeningAddress := fmt.Sprintf("127.0.0.1:%s", strconv.Itoa(grpcPort))
60 oltAdapter := &OLTAdapter{Adapter: NewAdapter(listeningAddress, coreEndpoint, deviceType, vendor),
61 ChildDeviceType: childDeviceType, childVendor: childVendor}
62
63 oltAdapter.start(ctx)
64 return oltAdapter
65}
66
67func (oltA *OLTAdapter) oltRestarted(ctx context.Context, endPoint string) error {
68 logger.Errorw(ctx, "remote-restarted", log.Fields{"endpoint": endPoint})
69 return nil
70}
71
72func (oltA *OLTAdapter) start(ctx context.Context) {
73
74 // Set up the probe service
75 oltA.Probe = &probe.Probe{}
76 probePort, err := freeport.GetFreePort()
77 if err != nil {
78 logger.Fatal(ctx, "Cannot get a freeport for probePort")
79 }
80 probeAddress := "127.0.0.1:" + strconv.Itoa(probePort)
81 go oltA.Probe.ListenAndServe(ctx, probeAddress)
82
83 probeCtx := context.WithValue(ctx, probe.ProbeContextKey, oltA.Probe)
84
85 oltA.Probe.RegisterService(ctx, "olt-grpc-service", oltA.coreEnpoint)
86
87 oltA.grpcServer = vgrpc.NewGrpcServer(oltA.serviceEndpoint, nil, false, nil)
88
89 logger.Debugw(ctx, "OLTAdapter-address", log.Fields{"address": oltA.serviceEndpoint})
90
91 go oltA.startGRPCService(ctx, oltA.grpcServer, oltA, "olt-grpc-service")
92
93 // Establish grpc connection to Core
khenaidoo25057da2021-12-08 14:40:45 -050094 if oltA.coreClient, err = vgrpc.NewClient(
95 "olt-endpoint",
96 oltA.coreEnpoint,
97 oltA.oltRestarted); err != nil {
khenaidood948f772021-08-11 17:49:24 -040098 logger.Fatal(ctx, "grpc-client-not-created")
99 }
100
101 go oltA.coreClient.Start(probeCtx, setAndTestCoreServiceHandler)
102
103 logger.Debugw(ctx, "OLTAdapter-started", log.Fields{"grpc-address": oltA.serviceEndpoint})
104
105}
106
107// Stop brings down core services
108func (oltA *OLTAdapter) StopGrpcClient() {
109 // Stop the grpc clients
110 oltA.coreClient.Stop(context.Background())
111}
112
113// Stop brings down core services
114func (oltA *OLTAdapter) Stop() {
115
116 // Stop the grpc
117 if oltA.grpcServer != nil {
118 oltA.grpcServer.Stop()
119 }
120 logger.Debugw(context.Background(), "OLTAdapter-stopped", log.Fields{"grpc-address": oltA.serviceEndpoint})
121
khenaidooab1f7bd2019-11-14 14:00:27 -0500122}
123
npujar1d86a522019-11-14 17:11:16 +0530124// Adopt_device creates new handler for added device
khenaidood948f772021-08-11 17:49:24 -0400125func (oltA *OLTAdapter) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
126 logger.Debugw(ctx, "AdoptDevice", log.Fields{"device": device.AdapterEndpoint, "device-type": oltA.DeviceType})
khenaidooab1f7bd2019-11-14 14:00:27 -0500127 go func() {
128 d := proto.Clone(device).(*voltha.Device)
129 d.Root = true
khenaidood948f772021-08-11 17:49:24 -0400130 d.Vendor = oltA.vendor
khenaidooab1f7bd2019-11-14 14:00:27 -0500131 d.Model = "go-mock"
132 d.SerialNumber = com.GetRandomSerialNumber()
133 d.MacAddress = strings.ToUpper(com.GetRandomMacAddress())
134 oltA.storeDevice(d)
khenaidood948f772021-08-11 17:49:24 -0400135 c, err := oltA.GetCoreClient()
136 if err != nil {
137 return
khenaidooab1f7bd2019-11-14 14:00:27 -0500138 }
khenaidood948f772021-08-11 17:49:24 -0400139 if _, err := c.DeviceUpdate(context.TODO(), d); err != nil {
140 logger.Fatalf(ctx, "deviceUpdate-failed-%s", err)
141 }
142
khenaidooc6c7bda2020-06-17 17:20:18 -0400143 capability := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER)
khenaidooab1f7bd2019-11-14 14:00:27 -0500144 nniPort := &voltha.Port{
khenaidood948f772021-08-11 17:49:24 -0400145 DeviceId: device.Id,
khenaidooab1f7bd2019-11-14 14:00:27 -0500146 PortNo: 2,
147 Label: fmt.Sprintf("nni-%d", 2),
148 Type: voltha.Port_ETHERNET_NNI,
khenaidood948f772021-08-11 17:49:24 -0400149 OperStatus: common.OperStatus_ACTIVE,
khenaidooc6c7bda2020-06-17 17:20:18 -0400150 OfpPort: &of.OfpPort{
151 HwAddr: macAddressToUint32Array("11:22:33:44:55:66"),
152 Config: 0,
153 State: uint32(of.OfpPortState_OFPPS_LIVE),
154 Curr: capability,
155 Advertised: capability,
156 Peer: capability,
157 CurrSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD),
158 MaxSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD),
159 },
khenaidooab1f7bd2019-11-14 14:00:27 -0500160 }
khenaidood948f772021-08-11 17:49:24 -0400161 if _, err = c.PortCreated(context.TODO(), nniPort); err != nil {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000162 logger.Fatalf(ctx, "PortCreated-failed-%s", err)
khenaidooab1f7bd2019-11-14 14:00:27 -0500163 }
164
165 ponPort := &voltha.Port{
khenaidood948f772021-08-11 17:49:24 -0400166 DeviceId: device.Id,
khenaidooab1f7bd2019-11-14 14:00:27 -0500167 PortNo: 1,
168 Label: fmt.Sprintf("pon-%d", 1),
169 Type: voltha.Port_PON_OLT,
khenaidood948f772021-08-11 17:49:24 -0400170 OperStatus: common.OperStatus_ACTIVE,
khenaidooab1f7bd2019-11-14 14:00:27 -0500171 }
khenaidood948f772021-08-11 17:49:24 -0400172 if _, err = c.PortCreated(context.TODO(), ponPort); err != nil {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000173 logger.Fatalf(ctx, "PortCreated-failed-%s", err)
khenaidooab1f7bd2019-11-14 14:00:27 -0500174 }
175
khenaidood948f772021-08-11 17:49:24 -0400176 d.ConnectStatus = common.ConnectStatus_REACHABLE
177 d.OperStatus = common.OperStatus_ACTIVE
khenaidooab1f7bd2019-11-14 14:00:27 -0500178
khenaidoo9beaaf12021-10-19 17:32:01 -0400179 if _, err = c.DeviceStateUpdate(context.TODO(), &ca.DeviceStateFilter{DeviceId: d.Id, OperStatus: d.OperStatus, ConnStatus: d.ConnectStatus}); err != nil {
khenaidood948f772021-08-11 17:49:24 -0400180 logger.Fatalf(ctx, "PortCreated-failed-%s", err)
khenaidooab1f7bd2019-11-14 14:00:27 -0500181 }
182
183 //Get the latest device data from the Core
khenaidood948f772021-08-11 17:49:24 -0400184 if d, err = c.GetDevice(context.TODO(), &common.ID{Id: d.Id}); err != nil {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000185 logger.Fatalf(ctx, "getting-device-failed-%s", err)
khenaidooab1f7bd2019-11-14 14:00:27 -0500186 }
187
khenaidoo8b4abbf2020-04-24 17:04:30 -0400188 oltA.updateDevice(d)
khenaidooab1f7bd2019-11-14 14:00:27 -0500189
190 // Register Child devices
khenaidoo67b22152020-03-02 16:01:25 -0500191 initialUniPortNo := startingUNIPortNo
khenaidooab1f7bd2019-11-14 14:00:27 -0500192 for i := 0; i < numONUPerOLT; i++ {
193 go func(seqNo int) {
khenaidood948f772021-08-11 17:49:24 -0400194 if _, err := c.ChildDeviceDetected(context.TODO(),
khenaidoo9beaaf12021-10-19 17:32:01 -0400195 &ca.DeviceDiscovery{
khenaidood948f772021-08-11 17:49:24 -0400196 ParentId: d.Id,
197 ParentPortNo: 1,
198 ChildDeviceType: oltA.ChildDeviceType,
199 ChannelId: uint32(initialUniPortNo + seqNo),
200 VendorId: oltA.childVendor,
201 SerialNumber: com.GetRandomSerialNumber(),
202 OnuId: uint32(seqNo),
203 }); err != nil {
204 logger.Fatalw(ctx, "failure-sending-child-device", log.Fields{"error": err, "parent-id": d.Id, "child-device-type": oltA.ChildDeviceType})
khenaidooab1f7bd2019-11-14 14:00:27 -0500205 }
206 }(i)
207 }
208 }()
khenaidood948f772021-08-11 17:49:24 -0400209 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500210}
211
Andrea Campanella025667e2021-01-14 11:50:07 +0100212// Single_get_value_request retrieves a single value.
213func (oltA *OLTAdapter) Single_get_value_request(ctx context.Context, // nolint
214 request extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
215 logger.Fatalf(ctx, "Single_get_value_request unimplemented")
216 return nil, nil
217}
218
npujar1d86a522019-11-14 17:11:16 +0530219// Get_ofp_device_info returns ofp device info
khenaidoo9beaaf12021-10-19 17:32:01 -0400220func (oltA *OLTAdapter) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500221 if d := oltA.getDevice(device.Id); d == nil {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000222 logger.Fatalf(ctx, "device-not-found-%s", device.Id)
khenaidooab1f7bd2019-11-14 14:00:27 -0500223 }
khenaidoo9beaaf12021-10-19 17:32:01 -0400224 return &ca.SwitchCapability{
khenaidooab1f7bd2019-11-14 14:00:27 -0500225 Desc: &of.OfpDesc{
226 HwDesc: "olt_adapter_mock",
227 SwDesc: "olt_adapter_mock",
228 SerialNum: "12345678",
229 },
230 SwitchFeatures: &of.OfpSwitchFeatures{
231 NBuffers: 256,
232 NTables: 2,
233 Capabilities: uint32(of.OfpCapabilities_OFPC_FLOW_STATS |
234 of.OfpCapabilities_OFPC_TABLE_STATS |
235 of.OfpCapabilities_OFPC_PORT_STATS |
236 of.OfpCapabilities_OFPC_GROUP_STATS),
237 },
238 }, nil
239}
240
npujar1d86a522019-11-14 17:11:16 +0530241// Disable_device disables device
khenaidood948f772021-08-11 17:49:24 -0400242func (oltA *OLTAdapter) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500243 go func() {
244 if d := oltA.getDevice(device.Id); d == nil {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000245 logger.Fatalf(ctx, "device-not-found-%s", device.Id)
khenaidooab1f7bd2019-11-14 14:00:27 -0500246 }
247
248 cloned := proto.Clone(device).(*voltha.Device)
249 // Update the all ports state on that device to disable
khenaidood948f772021-08-11 17:49:24 -0400250 c, err := oltA.GetCoreClient()
251 if err != nil {
252 return
253 }
254
255 if _, err := c.PortsStateUpdate(context.TODO(),
khenaidoo9beaaf12021-10-19 17:32:01 -0400256 &ca.PortStateFilter{
khenaidood948f772021-08-11 17:49:24 -0400257 DeviceId: cloned.Id,
258 PortTypeFilter: 0,
259 OperStatus: common.OperStatus_UNKNOWN,
260 }); err != nil {
divyadesaicb8b59d2020-08-18 09:55:47 +0000261 logger.Warnw(ctx, "updating-ports-failed", log.Fields{"device-id": device.Id, "error": err})
khenaidooab1f7bd2019-11-14 14:00:27 -0500262 }
263
Girish Gowdra408cd962020-03-11 14:31:31 -0700264 //Update the device operational state
khenaidood948f772021-08-11 17:49:24 -0400265 cloned.OperStatus = common.OperStatus_UNKNOWN
Girish Gowdra408cd962020-03-11 14:31:31 -0700266 // The device is still reachable after it has been disabled, so the connection status should not be changed.
khenaidooab1f7bd2019-11-14 14:00:27 -0500267
khenaidoo9beaaf12021-10-19 17:32:01 -0400268 if _, err := c.DeviceStateUpdate(context.TODO(), &ca.DeviceStateFilter{
khenaidood948f772021-08-11 17:49:24 -0400269 DeviceId: cloned.Id,
270 OperStatus: cloned.OperStatus,
271 ConnStatus: cloned.ConnectStatus,
272 }); err != nil {
khenaidoo442e7c72020-03-10 16:13:48 -0400273 // Device may already have been deleted in the core
divyadesaicb8b59d2020-08-18 09:55:47 +0000274 logger.Warnw(ctx, "device-state-update-failed", log.Fields{"device-id": device.Id, "error": err})
khenaidoo442e7c72020-03-10 16:13:48 -0400275 return
khenaidooab1f7bd2019-11-14 14:00:27 -0500276 }
277
khenaidoo8b4abbf2020-04-24 17:04:30 -0400278 oltA.updateDevice(cloned)
khenaidooab1f7bd2019-11-14 14:00:27 -0500279
280 // Tell the Core that all child devices have been disabled (by default it's an action already taken by the Core
khenaidood948f772021-08-11 17:49:24 -0400281 if _, err := c.ChildDevicesLost(context.TODO(), &common.ID{Id: cloned.Id}); err != nil {
khenaidoo442e7c72020-03-10 16:13:48 -0400282 // Device may already have been deleted in the core
divyadesaicb8b59d2020-08-18 09:55:47 +0000283 logger.Warnw(ctx, "lost-notif-of-child-devices-failed", log.Fields{"device-id": device.Id, "error": err})
khenaidooab1f7bd2019-11-14 14:00:27 -0500284 }
285 }()
khenaidood948f772021-08-11 17:49:24 -0400286 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500287}
288
npujar1d86a522019-11-14 17:11:16 +0530289// Reenable_device reenables device
khenaidood948f772021-08-11 17:49:24 -0400290func (oltA *OLTAdapter) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500291 go func() {
292 if d := oltA.getDevice(device.Id); d == nil {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000293 logger.Fatalf(ctx, "device-not-found-%s", device.Id)
khenaidooab1f7bd2019-11-14 14:00:27 -0500294 }
295
296 cloned := proto.Clone(device).(*voltha.Device)
khenaidood948f772021-08-11 17:49:24 -0400297
298 c, err := oltA.GetCoreClient()
299 if err != nil {
300 return
301 }
302
khenaidooab1f7bd2019-11-14 14:00:27 -0500303 // Update the all ports state on that device to enable
khenaidood948f772021-08-11 17:49:24 -0400304 if _, err := c.PortsStateUpdate(context.TODO(),
khenaidoo9beaaf12021-10-19 17:32:01 -0400305 &ca.PortStateFilter{
khenaidood948f772021-08-11 17:49:24 -0400306 DeviceId: cloned.Id,
307 PortTypeFilter: 0,
308 OperStatus: common.OperStatus_ACTIVE,
309 }); err != nil {
310 logger.Warnw(ctx, "updating-ports-failed", log.Fields{"device-id": device.Id, "error": err})
khenaidooab1f7bd2019-11-14 14:00:27 -0500311 }
312
313 //Update the device state
khenaidood948f772021-08-11 17:49:24 -0400314 cloned.OperStatus = common.OperStatus_ACTIVE
khenaidooab1f7bd2019-11-14 14:00:27 -0500315
khenaidoo9beaaf12021-10-19 17:32:01 -0400316 if _, err := c.DeviceStateUpdate(context.TODO(), &ca.DeviceStateFilter{
khenaidood948f772021-08-11 17:49:24 -0400317 DeviceId: cloned.Id,
318 OperStatus: cloned.OperStatus,
319 ConnStatus: cloned.ConnectStatus,
320 }); err != nil {
321 // Device may already have been deleted in the core
divyadesaicb8b59d2020-08-18 09:55:47 +0000322 logger.Fatalf(ctx, "device-state-update-failed", log.Fields{"device-id": device.Id, "error": err})
khenaidood948f772021-08-11 17:49:24 -0400323 return
khenaidooab1f7bd2019-11-14 14:00:27 -0500324 }
325
326 // Tell the Core that all child devices have been enabled
khenaidood948f772021-08-11 17:49:24 -0400327 if _, err := c.ChildDevicesDetected(context.TODO(), &common.ID{Id: cloned.Id}); err != nil {
divyadesaicb8b59d2020-08-18 09:55:47 +0000328 logger.Fatalf(ctx, "detection-notif-of-child-devices-failed", log.Fields{"device-id": device.Id, "error": err})
khenaidooab1f7bd2019-11-14 14:00:27 -0500329 }
330 }()
khenaidood948f772021-08-11 17:49:24 -0400331 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500332}
kesavandbc2d1622020-01-21 00:42:01 -0500333
334// Enable_port -
khenaidood948f772021-08-11 17:49:24 -0400335func (oltA *OLTAdapter) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { //nolint
kesavandbc2d1622020-01-21 00:42:01 -0500336 go func() {
khenaidood948f772021-08-11 17:49:24 -0400337 c, err := oltA.GetCoreClient()
338 if err != nil {
339 return
340 }
kesavandbc2d1622020-01-21 00:42:01 -0500341
khenaidood948f772021-08-11 17:49:24 -0400342 if port.Type == voltha.Port_PON_OLT {
343 if _, err := c.PortStateUpdate(context.TODO(),
khenaidoo9beaaf12021-10-19 17:32:01 -0400344 &ca.PortState{
khenaidood948f772021-08-11 17:49:24 -0400345 DeviceId: port.DeviceId,
346 PortType: voltha.Port_ETHERNET_NNI,
347 PortNo: port.PortNo,
348 OperStatus: common.OperStatus_ACTIVE,
349 }); err != nil {
350 logger.Fatalf(ctx, "updating-ports-failed", log.Fields{"device-id": port.DeviceId, "error": err})
kesavandbc2d1622020-01-21 00:42:01 -0500351 }
352 }
353
354 }()
khenaidood948f772021-08-11 17:49:24 -0400355 return &empty.Empty{}, nil
kesavandbc2d1622020-01-21 00:42:01 -0500356}
357
358// Disable_port -
khenaidood948f772021-08-11 17:49:24 -0400359func (oltA *OLTAdapter) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { //nolint
kesavandbc2d1622020-01-21 00:42:01 -0500360 go func() {
khenaidood948f772021-08-11 17:49:24 -0400361 c, err := oltA.GetCoreClient()
362 if err != nil {
363 return
364 }
365 if port.Type == voltha.Port_PON_OLT {
366 if _, err := c.PortStateUpdate(context.TODO(),
khenaidoo9beaaf12021-10-19 17:32:01 -0400367 &ca.PortState{
khenaidood948f772021-08-11 17:49:24 -0400368 DeviceId: port.DeviceId,
369 PortType: voltha.Port_PON_OLT,
370 PortNo: port.PortNo,
371 OperStatus: common.OperStatus_DISCOVERED,
372 }); err != nil {
khenaidoo442e7c72020-03-10 16:13:48 -0400373 // Corresponding device may have been deleted
khenaidood948f772021-08-11 17:49:24 -0400374 logger.Warnw(ctx, "updating-ports-failed", log.Fields{"device-id": port.DeviceId, "error": err})
kesavandbc2d1622020-01-21 00:42:01 -0500375 }
376 }
377 }()
khenaidood948f772021-08-11 17:49:24 -0400378 return &empty.Empty{}, nil
Chaitrashree G S543df3e2020-02-24 22:36:54 -0500379}
khenaidoo67b22152020-03-02 16:01:25 -0500380
Girish Gowdra408cd962020-03-11 14:31:31 -0700381// Reboot_device -
khenaidood948f772021-08-11 17:49:24 -0400382func (oltA *OLTAdapter) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { // nolint
divyadesaicb8b59d2020-08-18 09:55:47 +0000383 logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id})
Girish Gowdra408cd962020-03-11 14:31:31 -0700384
385 go func() {
khenaidood948f772021-08-11 17:49:24 -0400386 c, err := oltA.GetCoreClient()
387 if err != nil {
388 return
Girish Gowdra408cd962020-03-11 14:31:31 -0700389 }
khenaidood948f772021-08-11 17:49:24 -0400390
khenaidoo9beaaf12021-10-19 17:32:01 -0400391 if _, err := c.DeviceStateUpdate(context.TODO(), &ca.DeviceStateFilter{
khenaidood948f772021-08-11 17:49:24 -0400392 DeviceId: device.Id,
393 OperStatus: common.OperStatus_UNKNOWN,
394 ConnStatus: common.ConnectStatus_UNREACHABLE,
395 }); err != nil {
396 logger.Fatalf(ctx, "device-state-update-failed", log.Fields{"device-id": device.Id, "error": err})
397 return
398 }
399
400 if _, err := c.PortsStateUpdate(context.TODO(),
khenaidoo9beaaf12021-10-19 17:32:01 -0400401 &ca.PortStateFilter{
khenaidood948f772021-08-11 17:49:24 -0400402 DeviceId: device.Id,
403 PortTypeFilter: 0,
404 OperStatus: common.OperStatus_UNKNOWN,
405 }); err != nil {
406 logger.Warnw(ctx, "updating-ports-failed", log.Fields{"device-id": device.Id, "error": err})
Girish Gowdra408cd962020-03-11 14:31:31 -0700407 }
408 }()
khenaidood948f772021-08-11 17:49:24 -0400409 return &empty.Empty{}, nil
Girish Gowdra408cd962020-03-11 14:31:31 -0700410}
411
Scott Baker432f9be2020-03-26 11:56:30 -0700412// TODO: REMOVE Start_omci_test begins an omci self-test
khenaidoo9beaaf12021-10-19 17:32:01 -0400413func (oltA *OLTAdapter) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) { // nolint
Scott Baker432f9be2020-03-26 11:56:30 -0700414 return nil, errors.New("start-omci-test-not-implemented")
415}
416
khenaidood948f772021-08-11 17:49:24 -0400417// Helper for test only
418func (oltA *OLTAdapter) SetDeviceActive(deviceID string) {
419 c, err := oltA.GetCoreClient()
420 if err != nil {
421 return
422 }
ssiddiquif076cb82021-04-23 10:47:04 +0530423
khenaidoo9beaaf12021-10-19 17:32:01 -0400424 if _, err := c.DeviceStateUpdate(context.TODO(), &ca.DeviceStateFilter{
khenaidood948f772021-08-11 17:49:24 -0400425 DeviceId: deviceID,
426 OperStatus: common.OperStatus_ACTIVE,
427 ConnStatus: common.ConnectStatus_REACHABLE,
428 }); err != nil {
429 logger.Warnw(context.Background(), "device-state-update-failed", log.Fields{"device-id": deviceID, "error": err})
430 return
431 }
ssiddiquif076cb82021-04-23 10:47:04 +0530432
yasin sapli5458a1c2021-06-14 22:24:38 +0000433}