blob: 9bfb2d82824b8955d9a936cdfb787e899f441a5a [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
94 if oltA.coreClient, err = vgrpc.NewClient(oltA.coreEnpoint,
95 oltA.oltRestarted,
96 vgrpc.ActivityCheck(true)); err != nil {
97 logger.Fatal(ctx, "grpc-client-not-created")
98 }
99
100 go oltA.coreClient.Start(probeCtx, setAndTestCoreServiceHandler)
101
102 logger.Debugw(ctx, "OLTAdapter-started", log.Fields{"grpc-address": oltA.serviceEndpoint})
103
104}
105
106// Stop brings down core services
107func (oltA *OLTAdapter) StopGrpcClient() {
108 // Stop the grpc clients
109 oltA.coreClient.Stop(context.Background())
110}
111
112// Stop brings down core services
113func (oltA *OLTAdapter) Stop() {
114
115 // Stop the grpc
116 if oltA.grpcServer != nil {
117 oltA.grpcServer.Stop()
118 }
119 logger.Debugw(context.Background(), "OLTAdapter-stopped", log.Fields{"grpc-address": oltA.serviceEndpoint})
120
khenaidooab1f7bd2019-11-14 14:00:27 -0500121}
122
npujar1d86a522019-11-14 17:11:16 +0530123// Adopt_device creates new handler for added device
khenaidood948f772021-08-11 17:49:24 -0400124func (oltA *OLTAdapter) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
125 logger.Debugw(ctx, "AdoptDevice", log.Fields{"device": device.AdapterEndpoint, "device-type": oltA.DeviceType})
khenaidooab1f7bd2019-11-14 14:00:27 -0500126 go func() {
127 d := proto.Clone(device).(*voltha.Device)
128 d.Root = true
khenaidood948f772021-08-11 17:49:24 -0400129 d.Vendor = oltA.vendor
khenaidooab1f7bd2019-11-14 14:00:27 -0500130 d.Model = "go-mock"
131 d.SerialNumber = com.GetRandomSerialNumber()
132 d.MacAddress = strings.ToUpper(com.GetRandomMacAddress())
133 oltA.storeDevice(d)
khenaidood948f772021-08-11 17:49:24 -0400134 c, err := oltA.GetCoreClient()
135 if err != nil {
136 return
khenaidooab1f7bd2019-11-14 14:00:27 -0500137 }
khenaidood948f772021-08-11 17:49:24 -0400138 if _, err := c.DeviceUpdate(context.TODO(), d); err != nil {
139 logger.Fatalf(ctx, "deviceUpdate-failed-%s", err)
140 }
141
khenaidooc6c7bda2020-06-17 17:20:18 -0400142 capability := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER)
khenaidooab1f7bd2019-11-14 14:00:27 -0500143 nniPort := &voltha.Port{
khenaidood948f772021-08-11 17:49:24 -0400144 DeviceId: device.Id,
khenaidooab1f7bd2019-11-14 14:00:27 -0500145 PortNo: 2,
146 Label: fmt.Sprintf("nni-%d", 2),
147 Type: voltha.Port_ETHERNET_NNI,
khenaidood948f772021-08-11 17:49:24 -0400148 OperStatus: common.OperStatus_ACTIVE,
khenaidooc6c7bda2020-06-17 17:20:18 -0400149 OfpPort: &of.OfpPort{
150 HwAddr: macAddressToUint32Array("11:22:33:44:55:66"),
151 Config: 0,
152 State: uint32(of.OfpPortState_OFPPS_LIVE),
153 Curr: capability,
154 Advertised: capability,
155 Peer: capability,
156 CurrSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD),
157 MaxSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD),
158 },
khenaidooab1f7bd2019-11-14 14:00:27 -0500159 }
khenaidood948f772021-08-11 17:49:24 -0400160 if _, err = c.PortCreated(context.TODO(), nniPort); err != nil {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000161 logger.Fatalf(ctx, "PortCreated-failed-%s", err)
khenaidooab1f7bd2019-11-14 14:00:27 -0500162 }
163
164 ponPort := &voltha.Port{
khenaidood948f772021-08-11 17:49:24 -0400165 DeviceId: device.Id,
khenaidooab1f7bd2019-11-14 14:00:27 -0500166 PortNo: 1,
167 Label: fmt.Sprintf("pon-%d", 1),
168 Type: voltha.Port_PON_OLT,
khenaidood948f772021-08-11 17:49:24 -0400169 OperStatus: common.OperStatus_ACTIVE,
khenaidooab1f7bd2019-11-14 14:00:27 -0500170 }
khenaidood948f772021-08-11 17:49:24 -0400171 if _, err = c.PortCreated(context.TODO(), ponPort); err != nil {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000172 logger.Fatalf(ctx, "PortCreated-failed-%s", err)
khenaidooab1f7bd2019-11-14 14:00:27 -0500173 }
174
khenaidood948f772021-08-11 17:49:24 -0400175 d.ConnectStatus = common.ConnectStatus_REACHABLE
176 d.OperStatus = common.OperStatus_ACTIVE
khenaidooab1f7bd2019-11-14 14:00:27 -0500177
khenaidoo9beaaf12021-10-19 17:32:01 -0400178 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 -0400179 logger.Fatalf(ctx, "PortCreated-failed-%s", err)
khenaidooab1f7bd2019-11-14 14:00:27 -0500180 }
181
182 //Get the latest device data from the Core
khenaidood948f772021-08-11 17:49:24 -0400183 if d, err = c.GetDevice(context.TODO(), &common.ID{Id: d.Id}); err != nil {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000184 logger.Fatalf(ctx, "getting-device-failed-%s", err)
khenaidooab1f7bd2019-11-14 14:00:27 -0500185 }
186
khenaidoo8b4abbf2020-04-24 17:04:30 -0400187 oltA.updateDevice(d)
khenaidooab1f7bd2019-11-14 14:00:27 -0500188
189 // Register Child devices
khenaidoo67b22152020-03-02 16:01:25 -0500190 initialUniPortNo := startingUNIPortNo
khenaidooab1f7bd2019-11-14 14:00:27 -0500191 for i := 0; i < numONUPerOLT; i++ {
192 go func(seqNo int) {
khenaidood948f772021-08-11 17:49:24 -0400193 if _, err := c.ChildDeviceDetected(context.TODO(),
khenaidoo9beaaf12021-10-19 17:32:01 -0400194 &ca.DeviceDiscovery{
khenaidood948f772021-08-11 17:49:24 -0400195 ParentId: d.Id,
196 ParentPortNo: 1,
197 ChildDeviceType: oltA.ChildDeviceType,
198 ChannelId: uint32(initialUniPortNo + seqNo),
199 VendorId: oltA.childVendor,
200 SerialNumber: com.GetRandomSerialNumber(),
201 OnuId: uint32(seqNo),
202 }); err != nil {
203 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 -0500204 }
205 }(i)
206 }
207 }()
khenaidood948f772021-08-11 17:49:24 -0400208 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500209}
210
Andrea Campanella025667e2021-01-14 11:50:07 +0100211// Single_get_value_request retrieves a single value.
212func (oltA *OLTAdapter) Single_get_value_request(ctx context.Context, // nolint
213 request extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
214 logger.Fatalf(ctx, "Single_get_value_request unimplemented")
215 return nil, nil
216}
217
npujar1d86a522019-11-14 17:11:16 +0530218// Get_ofp_device_info returns ofp device info
khenaidoo9beaaf12021-10-19 17:32:01 -0400219func (oltA *OLTAdapter) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500220 if d := oltA.getDevice(device.Id); d == nil {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000221 logger.Fatalf(ctx, "device-not-found-%s", device.Id)
khenaidooab1f7bd2019-11-14 14:00:27 -0500222 }
khenaidoo9beaaf12021-10-19 17:32:01 -0400223 return &ca.SwitchCapability{
khenaidooab1f7bd2019-11-14 14:00:27 -0500224 Desc: &of.OfpDesc{
225 HwDesc: "olt_adapter_mock",
226 SwDesc: "olt_adapter_mock",
227 SerialNum: "12345678",
228 },
229 SwitchFeatures: &of.OfpSwitchFeatures{
230 NBuffers: 256,
231 NTables: 2,
232 Capabilities: uint32(of.OfpCapabilities_OFPC_FLOW_STATS |
233 of.OfpCapabilities_OFPC_TABLE_STATS |
234 of.OfpCapabilities_OFPC_PORT_STATS |
235 of.OfpCapabilities_OFPC_GROUP_STATS),
236 },
237 }, nil
238}
239
npujar1d86a522019-11-14 17:11:16 +0530240// Disable_device disables device
khenaidood948f772021-08-11 17:49:24 -0400241func (oltA *OLTAdapter) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500242 go func() {
243 if d := oltA.getDevice(device.Id); d == nil {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000244 logger.Fatalf(ctx, "device-not-found-%s", device.Id)
khenaidooab1f7bd2019-11-14 14:00:27 -0500245 }
246
247 cloned := proto.Clone(device).(*voltha.Device)
248 // Update the all ports state on that device to disable
khenaidood948f772021-08-11 17:49:24 -0400249 c, err := oltA.GetCoreClient()
250 if err != nil {
251 return
252 }
253
254 if _, err := c.PortsStateUpdate(context.TODO(),
khenaidoo9beaaf12021-10-19 17:32:01 -0400255 &ca.PortStateFilter{
khenaidood948f772021-08-11 17:49:24 -0400256 DeviceId: cloned.Id,
257 PortTypeFilter: 0,
258 OperStatus: common.OperStatus_UNKNOWN,
259 }); err != nil {
divyadesaicb8b59d2020-08-18 09:55:47 +0000260 logger.Warnw(ctx, "updating-ports-failed", log.Fields{"device-id": device.Id, "error": err})
khenaidooab1f7bd2019-11-14 14:00:27 -0500261 }
262
Girish Gowdra408cd962020-03-11 14:31:31 -0700263 //Update the device operational state
khenaidood948f772021-08-11 17:49:24 -0400264 cloned.OperStatus = common.OperStatus_UNKNOWN
Girish Gowdra408cd962020-03-11 14:31:31 -0700265 // The device is still reachable after it has been disabled, so the connection status should not be changed.
khenaidooab1f7bd2019-11-14 14:00:27 -0500266
khenaidoo9beaaf12021-10-19 17:32:01 -0400267 if _, err := c.DeviceStateUpdate(context.TODO(), &ca.DeviceStateFilter{
khenaidood948f772021-08-11 17:49:24 -0400268 DeviceId: cloned.Id,
269 OperStatus: cloned.OperStatus,
270 ConnStatus: cloned.ConnectStatus,
271 }); err != nil {
khenaidoo442e7c72020-03-10 16:13:48 -0400272 // Device may already have been deleted in the core
divyadesaicb8b59d2020-08-18 09:55:47 +0000273 logger.Warnw(ctx, "device-state-update-failed", log.Fields{"device-id": device.Id, "error": err})
khenaidoo442e7c72020-03-10 16:13:48 -0400274 return
khenaidooab1f7bd2019-11-14 14:00:27 -0500275 }
276
khenaidoo8b4abbf2020-04-24 17:04:30 -0400277 oltA.updateDevice(cloned)
khenaidooab1f7bd2019-11-14 14:00:27 -0500278
279 // 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 -0400280 if _, err := c.ChildDevicesLost(context.TODO(), &common.ID{Id: cloned.Id}); err != nil {
khenaidoo442e7c72020-03-10 16:13:48 -0400281 // Device may already have been deleted in the core
divyadesaicb8b59d2020-08-18 09:55:47 +0000282 logger.Warnw(ctx, "lost-notif-of-child-devices-failed", log.Fields{"device-id": device.Id, "error": err})
khenaidooab1f7bd2019-11-14 14:00:27 -0500283 }
284 }()
khenaidood948f772021-08-11 17:49:24 -0400285 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500286}
287
npujar1d86a522019-11-14 17:11:16 +0530288// Reenable_device reenables device
khenaidood948f772021-08-11 17:49:24 -0400289func (oltA *OLTAdapter) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500290 go func() {
291 if d := oltA.getDevice(device.Id); d == nil {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000292 logger.Fatalf(ctx, "device-not-found-%s", device.Id)
khenaidooab1f7bd2019-11-14 14:00:27 -0500293 }
294
295 cloned := proto.Clone(device).(*voltha.Device)
khenaidood948f772021-08-11 17:49:24 -0400296
297 c, err := oltA.GetCoreClient()
298 if err != nil {
299 return
300 }
301
khenaidooab1f7bd2019-11-14 14:00:27 -0500302 // Update the all ports state on that device to enable
khenaidood948f772021-08-11 17:49:24 -0400303 if _, err := c.PortsStateUpdate(context.TODO(),
khenaidoo9beaaf12021-10-19 17:32:01 -0400304 &ca.PortStateFilter{
khenaidood948f772021-08-11 17:49:24 -0400305 DeviceId: cloned.Id,
306 PortTypeFilter: 0,
307 OperStatus: common.OperStatus_ACTIVE,
308 }); err != nil {
309 logger.Warnw(ctx, "updating-ports-failed", log.Fields{"device-id": device.Id, "error": err})
khenaidooab1f7bd2019-11-14 14:00:27 -0500310 }
311
312 //Update the device state
khenaidood948f772021-08-11 17:49:24 -0400313 cloned.OperStatus = common.OperStatus_ACTIVE
khenaidooab1f7bd2019-11-14 14:00:27 -0500314
khenaidoo9beaaf12021-10-19 17:32:01 -0400315 if _, err := c.DeviceStateUpdate(context.TODO(), &ca.DeviceStateFilter{
khenaidood948f772021-08-11 17:49:24 -0400316 DeviceId: cloned.Id,
317 OperStatus: cloned.OperStatus,
318 ConnStatus: cloned.ConnectStatus,
319 }); err != nil {
320 // Device may already have been deleted in the core
divyadesaicb8b59d2020-08-18 09:55:47 +0000321 logger.Fatalf(ctx, "device-state-update-failed", log.Fields{"device-id": device.Id, "error": err})
khenaidood948f772021-08-11 17:49:24 -0400322 return
khenaidooab1f7bd2019-11-14 14:00:27 -0500323 }
324
325 // Tell the Core that all child devices have been enabled
khenaidood948f772021-08-11 17:49:24 -0400326 if _, err := c.ChildDevicesDetected(context.TODO(), &common.ID{Id: cloned.Id}); err != nil {
divyadesaicb8b59d2020-08-18 09:55:47 +0000327 logger.Fatalf(ctx, "detection-notif-of-child-devices-failed", log.Fields{"device-id": device.Id, "error": err})
khenaidooab1f7bd2019-11-14 14:00:27 -0500328 }
329 }()
khenaidood948f772021-08-11 17:49:24 -0400330 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500331}
kesavandbc2d1622020-01-21 00:42:01 -0500332
333// Enable_port -
khenaidood948f772021-08-11 17:49:24 -0400334func (oltA *OLTAdapter) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { //nolint
kesavandbc2d1622020-01-21 00:42:01 -0500335 go func() {
khenaidood948f772021-08-11 17:49:24 -0400336 c, err := oltA.GetCoreClient()
337 if err != nil {
338 return
339 }
kesavandbc2d1622020-01-21 00:42:01 -0500340
khenaidood948f772021-08-11 17:49:24 -0400341 if port.Type == voltha.Port_PON_OLT {
342 if _, err := c.PortStateUpdate(context.TODO(),
khenaidoo9beaaf12021-10-19 17:32:01 -0400343 &ca.PortState{
khenaidood948f772021-08-11 17:49:24 -0400344 DeviceId: port.DeviceId,
345 PortType: voltha.Port_ETHERNET_NNI,
346 PortNo: port.PortNo,
347 OperStatus: common.OperStatus_ACTIVE,
348 }); err != nil {
349 logger.Fatalf(ctx, "updating-ports-failed", log.Fields{"device-id": port.DeviceId, "error": err})
kesavandbc2d1622020-01-21 00:42:01 -0500350 }
351 }
352
353 }()
khenaidood948f772021-08-11 17:49:24 -0400354 return &empty.Empty{}, nil
kesavandbc2d1622020-01-21 00:42:01 -0500355}
356
357// Disable_port -
khenaidood948f772021-08-11 17:49:24 -0400358func (oltA *OLTAdapter) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { //nolint
kesavandbc2d1622020-01-21 00:42:01 -0500359 go func() {
khenaidood948f772021-08-11 17:49:24 -0400360 c, err := oltA.GetCoreClient()
361 if err != nil {
362 return
363 }
364 if port.Type == voltha.Port_PON_OLT {
365 if _, err := c.PortStateUpdate(context.TODO(),
khenaidoo9beaaf12021-10-19 17:32:01 -0400366 &ca.PortState{
khenaidood948f772021-08-11 17:49:24 -0400367 DeviceId: port.DeviceId,
368 PortType: voltha.Port_PON_OLT,
369 PortNo: port.PortNo,
370 OperStatus: common.OperStatus_DISCOVERED,
371 }); err != nil {
khenaidoo442e7c72020-03-10 16:13:48 -0400372 // Corresponding device may have been deleted
khenaidood948f772021-08-11 17:49:24 -0400373 logger.Warnw(ctx, "updating-ports-failed", log.Fields{"device-id": port.DeviceId, "error": err})
kesavandbc2d1622020-01-21 00:42:01 -0500374 }
375 }
376 }()
khenaidood948f772021-08-11 17:49:24 -0400377 return &empty.Empty{}, nil
Chaitrashree G S543df3e2020-02-24 22:36:54 -0500378}
khenaidoo67b22152020-03-02 16:01:25 -0500379
Girish Gowdra408cd962020-03-11 14:31:31 -0700380// Reboot_device -
khenaidood948f772021-08-11 17:49:24 -0400381func (oltA *OLTAdapter) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { // nolint
divyadesaicb8b59d2020-08-18 09:55:47 +0000382 logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id})
Girish Gowdra408cd962020-03-11 14:31:31 -0700383
384 go func() {
khenaidood948f772021-08-11 17:49:24 -0400385 c, err := oltA.GetCoreClient()
386 if err != nil {
387 return
Girish Gowdra408cd962020-03-11 14:31:31 -0700388 }
khenaidood948f772021-08-11 17:49:24 -0400389
khenaidoo9beaaf12021-10-19 17:32:01 -0400390 if _, err := c.DeviceStateUpdate(context.TODO(), &ca.DeviceStateFilter{
khenaidood948f772021-08-11 17:49:24 -0400391 DeviceId: device.Id,
392 OperStatus: common.OperStatus_UNKNOWN,
393 ConnStatus: common.ConnectStatus_UNREACHABLE,
394 }); err != nil {
395 logger.Fatalf(ctx, "device-state-update-failed", log.Fields{"device-id": device.Id, "error": err})
396 return
397 }
398
399 if _, err := c.PortsStateUpdate(context.TODO(),
khenaidoo9beaaf12021-10-19 17:32:01 -0400400 &ca.PortStateFilter{
khenaidood948f772021-08-11 17:49:24 -0400401 DeviceId: device.Id,
402 PortTypeFilter: 0,
403 OperStatus: common.OperStatus_UNKNOWN,
404 }); err != nil {
405 logger.Warnw(ctx, "updating-ports-failed", log.Fields{"device-id": device.Id, "error": err})
Girish Gowdra408cd962020-03-11 14:31:31 -0700406 }
407 }()
khenaidood948f772021-08-11 17:49:24 -0400408 return &empty.Empty{}, nil
Girish Gowdra408cd962020-03-11 14:31:31 -0700409}
410
Scott Baker432f9be2020-03-26 11:56:30 -0700411// TODO: REMOVE Start_omci_test begins an omci self-test
khenaidoo9beaaf12021-10-19 17:32:01 -0400412func (oltA *OLTAdapter) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) { // nolint
Scott Baker432f9be2020-03-26 11:56:30 -0700413 return nil, errors.New("start-omci-test-not-implemented")
414}
415
khenaidood948f772021-08-11 17:49:24 -0400416// Helper for test only
417func (oltA *OLTAdapter) SetDeviceActive(deviceID string) {
418 c, err := oltA.GetCoreClient()
419 if err != nil {
420 return
421 }
ssiddiquif076cb82021-04-23 10:47:04 +0530422
khenaidoo9beaaf12021-10-19 17:32:01 -0400423 if _, err := c.DeviceStateUpdate(context.TODO(), &ca.DeviceStateFilter{
khenaidood948f772021-08-11 17:49:24 -0400424 DeviceId: deviceID,
425 OperStatus: common.OperStatus_ACTIVE,
426 ConnStatus: common.ConnectStatus_REACHABLE,
427 }); err != nil {
428 logger.Warnw(context.Background(), "device-state-update-failed", log.Fields{"device-id": deviceID, "error": err})
429 return
430 }
ssiddiquif076cb82021-04-23 10:47:04 +0530431
yasin sapli5458a1c2021-06-14 22:24:38 +0000432}