blob: b0ff7118258fa6a6c4ce761ec0dafbbed02a08ea [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"
30 "github.com/phayes/freeport"
31
khenaidooab1f7bd2019-11-14 14:00:27 -050032 "github.com/gogo/protobuf/proto"
khenaidood948f772021-08-11 17:49:24 -040033 com "github.com/opencord/voltha-lib-go/v7/pkg/adapters/common"
34 vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc"
35 "github.com/opencord/voltha-lib-go/v7/pkg/log"
36 ic "github.com/opencord/voltha-protos/v5/go/inter_container"
37 of "github.com/opencord/voltha-protos/v5/go/openflow_13"
38 "github.com/opencord/voltha-protos/v5/go/voltha"
khenaidooab1f7bd2019-11-14 14:00:27 -050039)
40
npujar1d86a522019-11-14 17:11:16 +053041// OLTAdapter represent OLT adapter
khenaidooab1f7bd2019-11-14 14:00:27 -050042type OLTAdapter struct {
khenaidoo8b4abbf2020-04-24 17:04:30 -040043 *Adapter
khenaidood948f772021-08-11 17:49:24 -040044 ChildDeviceType string
45 childVendor string
46 grpcServer *vgrpc.GrpcServer
khenaidooab1f7bd2019-11-14 14:00:27 -050047}
48
npujar1d86a522019-11-14 17:11:16 +053049// NewOLTAdapter - creates OLT adapter instance
khenaidood948f772021-08-11 17:49:24 -040050func NewOLTAdapter(ctx context.Context, coreEndpoint string, deviceType string, vendor string, childDeviceType, childVendor string) *OLTAdapter {
51 // Get an available port
52 grpcPort, err := freeport.GetFreePort()
53 if err != nil {
54 logger.Fatalw(ctx, "no-free-port", log.Fields{"error": err})
khenaidoo67b22152020-03-02 16:01:25 -050055 }
khenaidood948f772021-08-11 17:49:24 -040056
57 // start gRPC handler
58 listeningAddress := fmt.Sprintf("127.0.0.1:%s", strconv.Itoa(grpcPort))
59 oltAdapter := &OLTAdapter{Adapter: NewAdapter(listeningAddress, coreEndpoint, deviceType, vendor),
60 ChildDeviceType: childDeviceType, childVendor: childVendor}
61
62 oltAdapter.start(ctx)
63 return oltAdapter
64}
65
66func (oltA *OLTAdapter) oltRestarted(ctx context.Context, endPoint string) error {
67 logger.Errorw(ctx, "remote-restarted", log.Fields{"endpoint": endPoint})
68 return nil
69}
70
71func (oltA *OLTAdapter) start(ctx context.Context) {
72
73 // Set up the probe service
74 oltA.Probe = &probe.Probe{}
75 probePort, err := freeport.GetFreePort()
76 if err != nil {
77 logger.Fatal(ctx, "Cannot get a freeport for probePort")
78 }
79 probeAddress := "127.0.0.1:" + strconv.Itoa(probePort)
80 go oltA.Probe.ListenAndServe(ctx, probeAddress)
81
82 probeCtx := context.WithValue(ctx, probe.ProbeContextKey, oltA.Probe)
83
84 oltA.Probe.RegisterService(ctx, "olt-grpc-service", oltA.coreEnpoint)
85
86 oltA.grpcServer = vgrpc.NewGrpcServer(oltA.serviceEndpoint, nil, false, nil)
87
88 logger.Debugw(ctx, "OLTAdapter-address", log.Fields{"address": oltA.serviceEndpoint})
89
90 go oltA.startGRPCService(ctx, oltA.grpcServer, oltA, "olt-grpc-service")
91
92 // Establish grpc connection to Core
93 if oltA.coreClient, err = vgrpc.NewClient(oltA.coreEnpoint,
94 oltA.oltRestarted,
95 vgrpc.ActivityCheck(true)); err != nil {
96 logger.Fatal(ctx, "grpc-client-not-created")
97 }
98
99 go oltA.coreClient.Start(probeCtx, setAndTestCoreServiceHandler)
100
101 logger.Debugw(ctx, "OLTAdapter-started", log.Fields{"grpc-address": oltA.serviceEndpoint})
102
103}
104
105// Stop brings down core services
106func (oltA *OLTAdapter) StopGrpcClient() {
107 // Stop the grpc clients
108 oltA.coreClient.Stop(context.Background())
109}
110
111// Stop brings down core services
112func (oltA *OLTAdapter) Stop() {
113
114 // Stop the grpc
115 if oltA.grpcServer != nil {
116 oltA.grpcServer.Stop()
117 }
118 logger.Debugw(context.Background(), "OLTAdapter-stopped", log.Fields{"grpc-address": oltA.serviceEndpoint})
119
khenaidooab1f7bd2019-11-14 14:00:27 -0500120}
121
npujar1d86a522019-11-14 17:11:16 +0530122// Adopt_device creates new handler for added device
khenaidood948f772021-08-11 17:49:24 -0400123func (oltA *OLTAdapter) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) {
124 logger.Debugw(ctx, "AdoptDevice", log.Fields{"device": device.AdapterEndpoint, "device-type": oltA.DeviceType})
khenaidooab1f7bd2019-11-14 14:00:27 -0500125 go func() {
126 d := proto.Clone(device).(*voltha.Device)
127 d.Root = true
khenaidood948f772021-08-11 17:49:24 -0400128 d.Vendor = oltA.vendor
khenaidooab1f7bd2019-11-14 14:00:27 -0500129 d.Model = "go-mock"
130 d.SerialNumber = com.GetRandomSerialNumber()
131 d.MacAddress = strings.ToUpper(com.GetRandomMacAddress())
132 oltA.storeDevice(d)
khenaidood948f772021-08-11 17:49:24 -0400133 c, err := oltA.GetCoreClient()
134 if err != nil {
135 return
khenaidooab1f7bd2019-11-14 14:00:27 -0500136 }
khenaidood948f772021-08-11 17:49:24 -0400137 if _, err := c.DeviceUpdate(context.TODO(), d); err != nil {
138 logger.Fatalf(ctx, "deviceUpdate-failed-%s", err)
139 }
140
khenaidooc6c7bda2020-06-17 17:20:18 -0400141 capability := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER)
khenaidooab1f7bd2019-11-14 14:00:27 -0500142 nniPort := &voltha.Port{
khenaidood948f772021-08-11 17:49:24 -0400143 DeviceId: device.Id,
khenaidooab1f7bd2019-11-14 14:00:27 -0500144 PortNo: 2,
145 Label: fmt.Sprintf("nni-%d", 2),
146 Type: voltha.Port_ETHERNET_NNI,
khenaidood948f772021-08-11 17:49:24 -0400147 OperStatus: common.OperStatus_ACTIVE,
khenaidooc6c7bda2020-06-17 17:20:18 -0400148 OfpPort: &of.OfpPort{
149 HwAddr: macAddressToUint32Array("11:22:33:44:55:66"),
150 Config: 0,
151 State: uint32(of.OfpPortState_OFPPS_LIVE),
152 Curr: capability,
153 Advertised: capability,
154 Peer: capability,
155 CurrSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD),
156 MaxSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD),
157 },
khenaidooab1f7bd2019-11-14 14:00:27 -0500158 }
khenaidood948f772021-08-11 17:49:24 -0400159 if _, err = c.PortCreated(context.TODO(), nniPort); err != nil {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000160 logger.Fatalf(ctx, "PortCreated-failed-%s", err)
khenaidooab1f7bd2019-11-14 14:00:27 -0500161 }
162
163 ponPort := &voltha.Port{
khenaidood948f772021-08-11 17:49:24 -0400164 DeviceId: device.Id,
khenaidooab1f7bd2019-11-14 14:00:27 -0500165 PortNo: 1,
166 Label: fmt.Sprintf("pon-%d", 1),
167 Type: voltha.Port_PON_OLT,
khenaidood948f772021-08-11 17:49:24 -0400168 OperStatus: common.OperStatus_ACTIVE,
khenaidooab1f7bd2019-11-14 14:00:27 -0500169 }
khenaidood948f772021-08-11 17:49:24 -0400170 if _, err = c.PortCreated(context.TODO(), ponPort); err != nil {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000171 logger.Fatalf(ctx, "PortCreated-failed-%s", err)
khenaidooab1f7bd2019-11-14 14:00:27 -0500172 }
173
khenaidood948f772021-08-11 17:49:24 -0400174 d.ConnectStatus = common.ConnectStatus_REACHABLE
175 d.OperStatus = common.OperStatus_ACTIVE
khenaidooab1f7bd2019-11-14 14:00:27 -0500176
khenaidood948f772021-08-11 17:49:24 -0400177 if _, err = c.DeviceStateUpdate(context.TODO(), &ic.DeviceStateFilter{DeviceId: d.Id, OperStatus: d.OperStatus, ConnStatus: d.ConnectStatus}); err != nil {
178 logger.Fatalf(ctx, "PortCreated-failed-%s", err)
khenaidooab1f7bd2019-11-14 14:00:27 -0500179 }
180
181 //Get the latest device data from the Core
khenaidood948f772021-08-11 17:49:24 -0400182 if d, err = c.GetDevice(context.TODO(), &common.ID{Id: d.Id}); err != nil {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000183 logger.Fatalf(ctx, "getting-device-failed-%s", err)
khenaidooab1f7bd2019-11-14 14:00:27 -0500184 }
185
khenaidoo8b4abbf2020-04-24 17:04:30 -0400186 oltA.updateDevice(d)
khenaidooab1f7bd2019-11-14 14:00:27 -0500187
188 // Register Child devices
khenaidoo67b22152020-03-02 16:01:25 -0500189 initialUniPortNo := startingUNIPortNo
khenaidooab1f7bd2019-11-14 14:00:27 -0500190 for i := 0; i < numONUPerOLT; i++ {
191 go func(seqNo int) {
khenaidood948f772021-08-11 17:49:24 -0400192 if _, err := c.ChildDeviceDetected(context.TODO(),
193 &ic.DeviceDiscovery{
194 ParentId: d.Id,
195 ParentPortNo: 1,
196 ChildDeviceType: oltA.ChildDeviceType,
197 ChannelId: uint32(initialUniPortNo + seqNo),
198 VendorId: oltA.childVendor,
199 SerialNumber: com.GetRandomSerialNumber(),
200 OnuId: uint32(seqNo),
201 }); err != nil {
202 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 -0500203 }
204 }(i)
205 }
206 }()
khenaidood948f772021-08-11 17:49:24 -0400207 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500208}
209
Andrea Campanella025667e2021-01-14 11:50:07 +0100210// Single_get_value_request retrieves a single value.
211func (oltA *OLTAdapter) Single_get_value_request(ctx context.Context, // nolint
212 request extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) {
213 logger.Fatalf(ctx, "Single_get_value_request unimplemented")
214 return nil, nil
215}
216
npujar1d86a522019-11-14 17:11:16 +0530217// Get_ofp_device_info returns ofp device info
khenaidood948f772021-08-11 17:49:24 -0400218func (oltA *OLTAdapter) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500219 if d := oltA.getDevice(device.Id); d == nil {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000220 logger.Fatalf(ctx, "device-not-found-%s", device.Id)
khenaidooab1f7bd2019-11-14 14:00:27 -0500221 }
222 return &ic.SwitchCapability{
223 Desc: &of.OfpDesc{
224 HwDesc: "olt_adapter_mock",
225 SwDesc: "olt_adapter_mock",
226 SerialNum: "12345678",
227 },
228 SwitchFeatures: &of.OfpSwitchFeatures{
229 NBuffers: 256,
230 NTables: 2,
231 Capabilities: uint32(of.OfpCapabilities_OFPC_FLOW_STATS |
232 of.OfpCapabilities_OFPC_TABLE_STATS |
233 of.OfpCapabilities_OFPC_PORT_STATS |
234 of.OfpCapabilities_OFPC_GROUP_STATS),
235 },
236 }, nil
237}
238
npujar1d86a522019-11-14 17:11:16 +0530239// Disable_device disables device
khenaidood948f772021-08-11 17:49:24 -0400240func (oltA *OLTAdapter) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500241 go func() {
242 if d := oltA.getDevice(device.Id); d == nil {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000243 logger.Fatalf(ctx, "device-not-found-%s", device.Id)
khenaidooab1f7bd2019-11-14 14:00:27 -0500244 }
245
246 cloned := proto.Clone(device).(*voltha.Device)
247 // Update the all ports state on that device to disable
khenaidood948f772021-08-11 17:49:24 -0400248 c, err := oltA.GetCoreClient()
249 if err != nil {
250 return
251 }
252
253 if _, err := c.PortsStateUpdate(context.TODO(),
254 &ic.PortStateFilter{
255 DeviceId: cloned.Id,
256 PortTypeFilter: 0,
257 OperStatus: common.OperStatus_UNKNOWN,
258 }); err != nil {
divyadesaicb8b59d2020-08-18 09:55:47 +0000259 logger.Warnw(ctx, "updating-ports-failed", log.Fields{"device-id": device.Id, "error": err})
khenaidooab1f7bd2019-11-14 14:00:27 -0500260 }
261
Girish Gowdra408cd962020-03-11 14:31:31 -0700262 //Update the device operational state
khenaidood948f772021-08-11 17:49:24 -0400263 cloned.OperStatus = common.OperStatus_UNKNOWN
Girish Gowdra408cd962020-03-11 14:31:31 -0700264 // The device is still reachable after it has been disabled, so the connection status should not be changed.
khenaidooab1f7bd2019-11-14 14:00:27 -0500265
khenaidood948f772021-08-11 17:49:24 -0400266 if _, err := c.DeviceStateUpdate(context.TODO(), &ic.DeviceStateFilter{
267 DeviceId: cloned.Id,
268 OperStatus: cloned.OperStatus,
269 ConnStatus: cloned.ConnectStatus,
270 }); err != nil {
khenaidoo442e7c72020-03-10 16:13:48 -0400271 // Device may already have been deleted in the core
divyadesaicb8b59d2020-08-18 09:55:47 +0000272 logger.Warnw(ctx, "device-state-update-failed", log.Fields{"device-id": device.Id, "error": err})
khenaidoo442e7c72020-03-10 16:13:48 -0400273 return
khenaidooab1f7bd2019-11-14 14:00:27 -0500274 }
275
khenaidoo8b4abbf2020-04-24 17:04:30 -0400276 oltA.updateDevice(cloned)
khenaidooab1f7bd2019-11-14 14:00:27 -0500277
278 // 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 -0400279 if _, err := c.ChildDevicesLost(context.TODO(), &common.ID{Id: cloned.Id}); err != nil {
khenaidoo442e7c72020-03-10 16:13:48 -0400280 // Device may already have been deleted in the core
divyadesaicb8b59d2020-08-18 09:55:47 +0000281 logger.Warnw(ctx, "lost-notif-of-child-devices-failed", log.Fields{"device-id": device.Id, "error": err})
khenaidooab1f7bd2019-11-14 14:00:27 -0500282 }
283 }()
khenaidood948f772021-08-11 17:49:24 -0400284 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500285}
286
npujar1d86a522019-11-14 17:11:16 +0530287// Reenable_device reenables device
khenaidood948f772021-08-11 17:49:24 -0400288func (oltA *OLTAdapter) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { // nolint
khenaidooab1f7bd2019-11-14 14:00:27 -0500289 go func() {
290 if d := oltA.getDevice(device.Id); d == nil {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000291 logger.Fatalf(ctx, "device-not-found-%s", device.Id)
khenaidooab1f7bd2019-11-14 14:00:27 -0500292 }
293
294 cloned := proto.Clone(device).(*voltha.Device)
khenaidood948f772021-08-11 17:49:24 -0400295
296 c, err := oltA.GetCoreClient()
297 if err != nil {
298 return
299 }
300
khenaidooab1f7bd2019-11-14 14:00:27 -0500301 // Update the all ports state on that device to enable
khenaidood948f772021-08-11 17:49:24 -0400302 if _, err := c.PortsStateUpdate(context.TODO(),
303 &ic.PortStateFilter{
304 DeviceId: cloned.Id,
305 PortTypeFilter: 0,
306 OperStatus: common.OperStatus_ACTIVE,
307 }); err != nil {
308 logger.Warnw(ctx, "updating-ports-failed", log.Fields{"device-id": device.Id, "error": err})
khenaidooab1f7bd2019-11-14 14:00:27 -0500309 }
310
311 //Update the device state
khenaidood948f772021-08-11 17:49:24 -0400312 cloned.OperStatus = common.OperStatus_ACTIVE
khenaidooab1f7bd2019-11-14 14:00:27 -0500313
khenaidood948f772021-08-11 17:49:24 -0400314 if _, err := c.DeviceStateUpdate(context.TODO(), &ic.DeviceStateFilter{
315 DeviceId: cloned.Id,
316 OperStatus: cloned.OperStatus,
317 ConnStatus: cloned.ConnectStatus,
318 }); err != nil {
319 // Device may already have been deleted in the core
divyadesaicb8b59d2020-08-18 09:55:47 +0000320 logger.Fatalf(ctx, "device-state-update-failed", log.Fields{"device-id": device.Id, "error": err})
khenaidood948f772021-08-11 17:49:24 -0400321 return
khenaidooab1f7bd2019-11-14 14:00:27 -0500322 }
323
324 // Tell the Core that all child devices have been enabled
khenaidood948f772021-08-11 17:49:24 -0400325 if _, err := c.ChildDevicesDetected(context.TODO(), &common.ID{Id: cloned.Id}); err != nil {
divyadesaicb8b59d2020-08-18 09:55:47 +0000326 logger.Fatalf(ctx, "detection-notif-of-child-devices-failed", log.Fields{"device-id": device.Id, "error": err})
khenaidooab1f7bd2019-11-14 14:00:27 -0500327 }
328 }()
khenaidood948f772021-08-11 17:49:24 -0400329 return &empty.Empty{}, nil
khenaidooab1f7bd2019-11-14 14:00:27 -0500330}
kesavandbc2d1622020-01-21 00:42:01 -0500331
332// Enable_port -
khenaidood948f772021-08-11 17:49:24 -0400333func (oltA *OLTAdapter) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { //nolint
kesavandbc2d1622020-01-21 00:42:01 -0500334 go func() {
khenaidood948f772021-08-11 17:49:24 -0400335 c, err := oltA.GetCoreClient()
336 if err != nil {
337 return
338 }
kesavandbc2d1622020-01-21 00:42:01 -0500339
khenaidood948f772021-08-11 17:49:24 -0400340 if port.Type == voltha.Port_PON_OLT {
341 if _, err := c.PortStateUpdate(context.TODO(),
342 &ic.PortState{
343 DeviceId: port.DeviceId,
344 PortType: voltha.Port_ETHERNET_NNI,
345 PortNo: port.PortNo,
346 OperStatus: common.OperStatus_ACTIVE,
347 }); err != nil {
348 logger.Fatalf(ctx, "updating-ports-failed", log.Fields{"device-id": port.DeviceId, "error": err})
kesavandbc2d1622020-01-21 00:42:01 -0500349 }
350 }
351
352 }()
khenaidood948f772021-08-11 17:49:24 -0400353 return &empty.Empty{}, nil
kesavandbc2d1622020-01-21 00:42:01 -0500354}
355
356// Disable_port -
khenaidood948f772021-08-11 17:49:24 -0400357func (oltA *OLTAdapter) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { //nolint
kesavandbc2d1622020-01-21 00:42:01 -0500358 go func() {
khenaidood948f772021-08-11 17:49:24 -0400359 c, err := oltA.GetCoreClient()
360 if err != nil {
361 return
362 }
363 if port.Type == voltha.Port_PON_OLT {
364 if _, err := c.PortStateUpdate(context.TODO(),
365 &ic.PortState{
366 DeviceId: port.DeviceId,
367 PortType: voltha.Port_PON_OLT,
368 PortNo: port.PortNo,
369 OperStatus: common.OperStatus_DISCOVERED,
370 }); err != nil {
khenaidoo442e7c72020-03-10 16:13:48 -0400371 // Corresponding device may have been deleted
khenaidood948f772021-08-11 17:49:24 -0400372 logger.Warnw(ctx, "updating-ports-failed", log.Fields{"device-id": port.DeviceId, "error": err})
kesavandbc2d1622020-01-21 00:42:01 -0500373 }
374 }
375 }()
khenaidood948f772021-08-11 17:49:24 -0400376 return &empty.Empty{}, nil
Chaitrashree G S543df3e2020-02-24 22:36:54 -0500377}
khenaidoo67b22152020-03-02 16:01:25 -0500378
Girish Gowdra408cd962020-03-11 14:31:31 -0700379// Reboot_device -
khenaidood948f772021-08-11 17:49:24 -0400380func (oltA *OLTAdapter) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { // nolint
divyadesaicb8b59d2020-08-18 09:55:47 +0000381 logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id})
Girish Gowdra408cd962020-03-11 14:31:31 -0700382
383 go func() {
khenaidood948f772021-08-11 17:49:24 -0400384 c, err := oltA.GetCoreClient()
385 if err != nil {
386 return
Girish Gowdra408cd962020-03-11 14:31:31 -0700387 }
khenaidood948f772021-08-11 17:49:24 -0400388
389 if _, err := c.DeviceStateUpdate(context.TODO(), &ic.DeviceStateFilter{
390 DeviceId: device.Id,
391 OperStatus: common.OperStatus_UNKNOWN,
392 ConnStatus: common.ConnectStatus_UNREACHABLE,
393 }); err != nil {
394 logger.Fatalf(ctx, "device-state-update-failed", log.Fields{"device-id": device.Id, "error": err})
395 return
396 }
397
398 if _, err := c.PortsStateUpdate(context.TODO(),
399 &ic.PortStateFilter{
400 DeviceId: device.Id,
401 PortTypeFilter: 0,
402 OperStatus: common.OperStatus_UNKNOWN,
403 }); err != nil {
404 logger.Warnw(ctx, "updating-ports-failed", log.Fields{"device-id": device.Id, "error": err})
Girish Gowdra408cd962020-03-11 14:31:31 -0700405 }
406 }()
khenaidood948f772021-08-11 17:49:24 -0400407 return &empty.Empty{}, nil
Girish Gowdra408cd962020-03-11 14:31:31 -0700408}
409
Scott Baker432f9be2020-03-26 11:56:30 -0700410// TODO: REMOVE Start_omci_test begins an omci self-test
khenaidood948f772021-08-11 17:49:24 -0400411func (oltA *OLTAdapter) StartOmciTest(ctx context.Context, test *ic.OMCITest) (*voltha.TestResponse, error) { // nolint
Scott Baker432f9be2020-03-26 11:56:30 -0700412 return nil, errors.New("start-omci-test-not-implemented")
413}
414
khenaidood948f772021-08-11 17:49:24 -0400415// Helper for test only
416func (oltA *OLTAdapter) SetDeviceActive(deviceID string) {
417 c, err := oltA.GetCoreClient()
418 if err != nil {
419 return
420 }
ssiddiquif076cb82021-04-23 10:47:04 +0530421
khenaidood948f772021-08-11 17:49:24 -0400422 if _, err := c.DeviceStateUpdate(context.TODO(), &ic.DeviceStateFilter{
423 DeviceId: deviceID,
424 OperStatus: common.OperStatus_ACTIVE,
425 ConnStatus: common.ConnectStatus_REACHABLE,
426 }); err != nil {
427 logger.Warnw(context.Background(), "device-state-update-failed", log.Fields{"device-id": deviceID, "error": err})
428 return
429 }
ssiddiquif076cb82021-04-23 10:47:04 +0530430
yasin sapli5458a1c2021-06-14 22:24:38 +0000431}