khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 1 | /* |
| 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 | */ |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 16 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 17 | package mocks |
| 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | "fmt" |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 22 | "strconv" |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 23 | "strings" |
| 24 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 25 | "github.com/golang/protobuf/ptypes/empty" |
| 26 | vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc" |
| 27 | "github.com/opencord/voltha-lib-go/v7/pkg/probe" |
| 28 | "github.com/opencord/voltha-protos/v5/go/common" |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame^] | 29 | ca "github.com/opencord/voltha-protos/v5/go/core_adapter" |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 30 | "github.com/opencord/voltha-protos/v5/go/extension" |
| 31 | "github.com/phayes/freeport" |
| 32 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 33 | "github.com/gogo/protobuf/proto" |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 34 | com "github.com/opencord/voltha-lib-go/v7/pkg/adapters/common" |
| 35 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame^] | 36 | "github.com/opencord/voltha-protos/v5/go/omci" |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 37 | of "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 38 | "github.com/opencord/voltha-protos/v5/go/voltha" |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 39 | ) |
| 40 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 41 | // ONUAdapter represent ONU adapter attributes |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 42 | type ONUAdapter struct { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 43 | *Adapter |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 44 | grpcServer *vgrpc.GrpcServer |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 45 | } |
| 46 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 47 | // NewONUAdapter creates ONU adapter |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 48 | func NewONUAdapter(ctx context.Context, coreEndpoint string, deviceType string, vendor string) *ONUAdapter { |
| 49 | // Get an available port |
| 50 | grpcPort, err := freeport.GetFreePort() |
| 51 | if err != nil { |
| 52 | logger.Fatalw(ctx, "no-free-port", log.Fields{"error": err}) |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 53 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 54 | listeningAddress := fmt.Sprintf("127.0.0.1:%s", strconv.Itoa(grpcPort)) |
| 55 | onuAdapter := &ONUAdapter{Adapter: NewAdapter(listeningAddress, coreEndpoint, deviceType, vendor)} |
| 56 | |
| 57 | onuAdapter.start(ctx) |
| 58 | return onuAdapter |
| 59 | } |
| 60 | |
| 61 | func (onuA *ONUAdapter) onuRestarted(ctx context.Context, endPoint string) error { |
| 62 | logger.Errorw(ctx, "remote-restarted", log.Fields{"endpoint": endPoint}) |
| 63 | return nil |
| 64 | } |
| 65 | |
| 66 | func (onuA *ONUAdapter) start(ctx context.Context) { |
| 67 | |
| 68 | // Set up the probe service |
| 69 | onuA.Probe = &probe.Probe{} |
| 70 | probePort, err := freeport.GetFreePort() |
| 71 | if err != nil { |
| 72 | logger.Fatal(ctx, "Cannot get a freeport for probePort") |
| 73 | } |
| 74 | probeAddress := "127.0.0.1:" + strconv.Itoa(probePort) |
| 75 | go onuA.Probe.ListenAndServe(ctx, probeAddress) |
| 76 | |
| 77 | probeCtx := context.WithValue(ctx, probe.ProbeContextKey, onuA.Probe) |
| 78 | |
| 79 | onuA.Probe.RegisterService(ctx, "onu-grpc-service", onuA.coreEnpoint) |
| 80 | |
| 81 | // start gRPC handler |
| 82 | onuA.grpcServer = vgrpc.NewGrpcServer(onuA.serviceEndpoint, nil, false, nil) |
| 83 | |
| 84 | logger.Debugw(ctx, "ONUAdapter-address", log.Fields{"address": onuA.serviceEndpoint}) |
| 85 | |
| 86 | go onuA.startGRPCService(ctx, onuA.grpcServer, onuA, "onu-grpc-service") |
| 87 | |
| 88 | // Establish grpc connection to Core |
| 89 | if onuA.coreClient, err = vgrpc.NewClient(onuA.coreEnpoint, |
| 90 | onuA.onuRestarted, |
| 91 | vgrpc.ActivityCheck(true)); err != nil { |
| 92 | logger.Fatal(ctx, "grpc-client-not-created") |
| 93 | } |
| 94 | go onuA.coreClient.Start(probeCtx, setAndTestCoreServiceHandler) |
| 95 | |
| 96 | logger.Debugw(ctx, "ONUAdapter-started", log.Fields{"grpc-address": onuA.serviceEndpoint}) |
| 97 | } |
| 98 | |
| 99 | // Stop brings down core services |
| 100 | func (onuA *ONUAdapter) StopGrpcClient() { |
| 101 | // Stop the grpc clients |
| 102 | onuA.coreClient.Stop(context.Background()) |
| 103 | } |
| 104 | |
| 105 | func (onuA *ONUAdapter) Stop() { |
| 106 | if onuA.grpcServer != nil { |
| 107 | onuA.grpcServer.Stop() |
| 108 | } |
| 109 | logger.Debugw(context.Background(), "ONUAdapter-stopped", log.Fields{"grpc-address": onuA.serviceEndpoint}) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 110 | } |
| 111 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 112 | // Adopt_device creates new handler for added device |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 113 | func (onuA *ONUAdapter) AdoptDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { |
| 114 | logger.Debugw(ctx, "AdoptDevice", log.Fields{"device": device.AdapterEndpoint, "device-type": onuA.DeviceType}) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 115 | go func() { |
| 116 | d := proto.Clone(device).(*voltha.Device) |
| 117 | d.Root = false |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 118 | d.Vendor = onuA.vendor |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 119 | d.Model = "go-mock" |
| 120 | d.SerialNumber = com.GetRandomSerialNumber() |
| 121 | d.MacAddress = strings.ToUpper(com.GetRandomMacAddress()) |
| 122 | onuA.storeDevice(d) |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 123 | |
| 124 | c, err := onuA.GetCoreClient() |
| 125 | if err != nil { |
| 126 | return |
| 127 | } |
| 128 | if _, err := c.DeviceUpdate(context.TODO(), d); err != nil { |
| 129 | logger.Fatalf(ctx, "deviceUpdate-failed-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 130 | } |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 131 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 132 | d.ConnectStatus = common.ConnectStatus_REACHABLE |
| 133 | d.OperStatus = common.OperStatus_DISCOVERED |
khenaidoo | 9318152 | 2020-01-23 12:43:21 -0500 | [diff] [blame] | 134 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame^] | 135 | if _, err = c.DeviceStateUpdate(context.TODO(), &ca.DeviceStateFilter{DeviceId: d.Id, OperStatus: d.OperStatus, ConnStatus: d.ConnectStatus}); err != nil { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 136 | logger.Fatalf(ctx, "PortCreated-failed-%s", err) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 137 | } |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 138 | |
| 139 | uniPortNo := uint32(2) |
| 140 | if device.ProxyAddress != nil { |
| 141 | if device.ProxyAddress.ChannelId != 0 { |
| 142 | uniPortNo = device.ProxyAddress.ChannelId |
| 143 | } |
| 144 | } |
| 145 | |
khenaidoo | c6c7bda | 2020-06-17 17:20:18 -0400 | [diff] [blame] | 146 | capability := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 147 | uniPort := &voltha.Port{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 148 | DeviceId: d.Id, |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 149 | PortNo: uniPortNo, |
| 150 | Label: fmt.Sprintf("uni-%d", uniPortNo), |
| 151 | Type: voltha.Port_ETHERNET_UNI, |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 152 | OperStatus: common.OperStatus_ACTIVE, |
khenaidoo | c6c7bda | 2020-06-17 17:20:18 -0400 | [diff] [blame] | 153 | OfpPort: &of.OfpPort{ |
| 154 | HwAddr: macAddressToUint32Array("12:12:12:12:12:12"), |
| 155 | Config: 0, |
| 156 | State: uint32(of.OfpPortState_OFPPS_LIVE), |
| 157 | Curr: capability, |
| 158 | Advertised: capability, |
| 159 | Peer: capability, |
| 160 | CurrSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD), |
| 161 | MaxSpeed: uint32(of.OfpPortFeatures_OFPPF_1GB_FD), |
| 162 | }, |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 163 | } |
khenaidoo | c6c7bda | 2020-06-17 17:20:18 -0400 | [diff] [blame] | 164 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 165 | if _, err = c.PortCreated(context.TODO(), uniPort); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 166 | logger.Fatalf(ctx, "PortCreated-failed-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | ponPortNo := uint32(1) |
| 170 | if device.ParentPortNo != 0 { |
| 171 | ponPortNo = device.ParentPortNo |
| 172 | } |
| 173 | |
| 174 | ponPort := &voltha.Port{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 175 | DeviceId: d.Id, |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 176 | PortNo: ponPortNo, |
| 177 | Label: fmt.Sprintf("pon-%d", ponPortNo), |
| 178 | Type: voltha.Port_PON_ONU, |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 179 | OperStatus: common.OperStatus_ACTIVE, |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 180 | Peers: []*voltha.Port_PeerPort{{DeviceId: d.ParentId, // Peer device is OLT |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 181 | PortNo: device.ParentPortNo}}, // Peer port is parent's port number |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 182 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 183 | |
| 184 | if _, err = c.PortCreated(context.TODO(), ponPort); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 185 | logger.Fatalf(ctx, "PortCreated-failed-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 186 | } |
| 187 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 188 | d.ConnectStatus = common.ConnectStatus_REACHABLE |
| 189 | d.OperStatus = common.OperStatus_ACTIVE |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 190 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame^] | 191 | if _, err = c.DeviceStateUpdate(context.TODO(), &ca.DeviceStateFilter{DeviceId: d.Id, OperStatus: d.OperStatus, ConnStatus: d.ConnectStatus}); err != nil { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 192 | logger.Fatalf(ctx, "PortCreated-failed-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 193 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 194 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 195 | //Get the latest device data from the Core |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 196 | if d, err = c.GetDevice(context.TODO(), &common.ID{Id: d.Id}); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 197 | logger.Fatalf(ctx, "getting-device-failed-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 198 | } |
| 199 | |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 200 | onuA.updateDevice(d) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 201 | }() |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 202 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 203 | } |
| 204 | |
Andrea Campanella | 025667e | 2021-01-14 11:50:07 +0100 | [diff] [blame] | 205 | // Single_get_value_request retrieves a single value. |
| 206 | func (onuA *ONUAdapter) Single_get_value_request(ctx context.Context, // nolint |
| 207 | request extension.SingleGetValueRequest) (*extension.SingleGetValueResponse, error) { |
| 208 | logger.Fatalf(ctx, "Single_get_value_request unimplemented") |
| 209 | return nil, nil |
| 210 | } |
| 211 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 212 | // Disable_device disables device |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 213 | func (onuA *ONUAdapter) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 214 | go func() { |
| 215 | if d := onuA.getDevice(device.Id); d == nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 216 | logger.Fatalf(ctx, "device-not-found-%s", device.Id) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 217 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 218 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 219 | cloned := proto.Clone(device).(*voltha.Device) |
| 220 | // Update the all ports state on that device to disable |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 221 | c, err := onuA.GetCoreClient() |
| 222 | if err != nil { |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 223 | return |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 224 | } |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 225 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 226 | if _, err := c.PortsStateUpdate(context.TODO(), |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame^] | 227 | &ca.PortStateFilter{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 228 | DeviceId: cloned.Id, |
| 229 | PortTypeFilter: 0, |
| 230 | OperStatus: common.OperStatus_UNKNOWN, |
| 231 | }); err != nil { |
| 232 | logger.Warnw(ctx, "updating-ports-failed", log.Fields{"device-id": device.Id, "error": err}) |
| 233 | } |
| 234 | |
| 235 | //Update the device operational state |
| 236 | cloned.ConnectStatus = common.ConnectStatus_UNREACHABLE |
| 237 | cloned.OperStatus = common.OperStatus_UNKNOWN |
| 238 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame^] | 239 | if _, err := c.DeviceStateUpdate(context.TODO(), &ca.DeviceStateFilter{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 240 | DeviceId: cloned.Id, |
| 241 | OperStatus: cloned.OperStatus, |
| 242 | ConnStatus: cloned.ConnectStatus, |
| 243 | }); err != nil { |
| 244 | // Device may already have been deleted in the core |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 245 | logger.Warnw(ctx, "device-state-update-failed", log.Fields{"device-id": device.Id, "error": err}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 246 | return |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 247 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 248 | |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 249 | onuA.updateDevice(cloned) |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 250 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 251 | }() |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 252 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 253 | } |
| 254 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 255 | func (onuA *ONUAdapter) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 256 | go func() { |
| 257 | if d := onuA.getDevice(device.Id); d == nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 258 | logger.Fatalf(ctx, "device-not-found-%s", device.Id) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | cloned := proto.Clone(device).(*voltha.Device) |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 262 | |
| 263 | c, err := onuA.GetCoreClient() |
| 264 | if err != nil { |
| 265 | return |
| 266 | } |
| 267 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 268 | // Update the all ports state on that device to enable |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 269 | if _, err := c.PortsStateUpdate(context.TODO(), |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame^] | 270 | &ca.PortStateFilter{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 271 | DeviceId: cloned.Id, |
| 272 | PortTypeFilter: 0, |
| 273 | OperStatus: common.OperStatus_ACTIVE, |
| 274 | }); err != nil { |
| 275 | logger.Warnw(ctx, "updating-ports-failed", log.Fields{"device-id": device.Id, "error": err}) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | //Update the device state |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 279 | cloned.ConnectStatus = common.ConnectStatus_REACHABLE |
| 280 | cloned.OperStatus = common.OperStatus_ACTIVE |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 281 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame^] | 282 | if _, err := c.DeviceStateUpdate(context.TODO(), &ca.DeviceStateFilter{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 283 | DeviceId: cloned.Id, |
| 284 | OperStatus: cloned.OperStatus, |
| 285 | ConnStatus: cloned.ConnectStatus, |
| 286 | }); err != nil { |
| 287 | // Device may already have been deleted in the core |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 288 | logger.Fatalf(ctx, "device-state-update-failed", log.Fields{"device-id": device.Id, "error": err}) |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 289 | return |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 290 | } |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 291 | onuA.updateDevice(cloned) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 292 | }() |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 293 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 294 | } |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 295 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame^] | 296 | func (onuA *ONUAdapter) StartOmciTest(ctx context.Context, _ *ca.OMCITest) (*omci.TestResponse, error) { // nolint |
| 297 | return &omci.TestResponse{Result: omci.TestResponse_SUCCESS}, nil |
yasin sapli | 5458a1c | 2021-06-14 22:24:38 +0000 | [diff] [blame] | 298 | } |