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" |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 21 | "errors" |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 22 | "fmt" |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 23 | "strconv" |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 24 | "strings" |
| 25 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 26 | "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" |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 30 | "github.com/opencord/voltha-protos/v5/go/omci" |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 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 | vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc" |
| 36 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 37 | ca "github.com/opencord/voltha-protos/v5/go/core_adapter" |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 38 | of "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 39 | "github.com/opencord/voltha-protos/v5/go/voltha" |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 40 | ) |
| 41 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 42 | // OLTAdapter represent OLT adapter |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 43 | type OLTAdapter struct { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 44 | *Adapter |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 45 | ChildDeviceType string |
| 46 | childVendor string |
| 47 | grpcServer *vgrpc.GrpcServer |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 48 | } |
| 49 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 50 | // NewOLTAdapter - creates OLT adapter instance |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 51 | func 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}) |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 56 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 57 | |
| 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 | |
| 67 | func (oltA *OLTAdapter) oltRestarted(ctx context.Context, endPoint string) error { |
| 68 | logger.Errorw(ctx, "remote-restarted", log.Fields{"endpoint": endPoint}) |
| 69 | return nil |
| 70 | } |
| 71 | |
| 72 | func (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 |
| 107 | func (oltA *OLTAdapter) StopGrpcClient() { |
| 108 | // Stop the grpc clients |
| 109 | oltA.coreClient.Stop(context.Background()) |
| 110 | } |
| 111 | |
| 112 | // Stop brings down core services |
| 113 | func (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 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 121 | } |
| 122 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 123 | // Adopt_device creates new handler for added device |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 124 | func (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}) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 126 | go func() { |
| 127 | d := proto.Clone(device).(*voltha.Device) |
| 128 | d.Root = true |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 129 | d.Vendor = oltA.vendor |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 130 | d.Model = "go-mock" |
| 131 | d.SerialNumber = com.GetRandomSerialNumber() |
| 132 | d.MacAddress = strings.ToUpper(com.GetRandomMacAddress()) |
| 133 | oltA.storeDevice(d) |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 134 | c, err := oltA.GetCoreClient() |
| 135 | if err != nil { |
| 136 | return |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 137 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 138 | if _, err := c.DeviceUpdate(context.TODO(), d); err != nil { |
| 139 | logger.Fatalf(ctx, "deviceUpdate-failed-%s", err) |
| 140 | } |
| 141 | |
khenaidoo | c6c7bda | 2020-06-17 17:20:18 -0400 | [diff] [blame] | 142 | capability := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 143 | nniPort := &voltha.Port{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 144 | DeviceId: device.Id, |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 145 | PortNo: 2, |
| 146 | Label: fmt.Sprintf("nni-%d", 2), |
| 147 | Type: voltha.Port_ETHERNET_NNI, |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 148 | OperStatus: common.OperStatus_ACTIVE, |
khenaidoo | c6c7bda | 2020-06-17 17:20:18 -0400 | [diff] [blame] | 149 | 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 | }, |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 159 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 160 | if _, err = c.PortCreated(context.TODO(), nniPort); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 161 | logger.Fatalf(ctx, "PortCreated-failed-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | ponPort := &voltha.Port{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 165 | DeviceId: device.Id, |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 166 | PortNo: 1, |
| 167 | Label: fmt.Sprintf("pon-%d", 1), |
| 168 | Type: voltha.Port_PON_OLT, |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 169 | OperStatus: common.OperStatus_ACTIVE, |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 170 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 171 | if _, err = c.PortCreated(context.TODO(), ponPort); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 172 | logger.Fatalf(ctx, "PortCreated-failed-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 173 | } |
| 174 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 175 | d.ConnectStatus = common.ConnectStatus_REACHABLE |
| 176 | d.OperStatus = common.OperStatus_ACTIVE |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 177 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 178 | 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] | 179 | logger.Fatalf(ctx, "PortCreated-failed-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | //Get the latest device data from the Core |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 183 | 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] | 184 | logger.Fatalf(ctx, "getting-device-failed-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 185 | } |
| 186 | |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 187 | oltA.updateDevice(d) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 188 | |
| 189 | // Register Child devices |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 190 | initialUniPortNo := startingUNIPortNo |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 191 | for i := 0; i < numONUPerOLT; i++ { |
| 192 | go func(seqNo int) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 193 | if _, err := c.ChildDeviceDetected(context.TODO(), |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 194 | &ca.DeviceDiscovery{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 195 | 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}) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 204 | } |
| 205 | }(i) |
| 206 | } |
| 207 | }() |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 208 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 209 | } |
| 210 | |
Andrea Campanella | 025667e | 2021-01-14 11:50:07 +0100 | [diff] [blame] | 211 | // Single_get_value_request retrieves a single value. |
| 212 | func (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 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 218 | // Get_ofp_device_info returns ofp device info |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 219 | func (oltA *OLTAdapter) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ca.SwitchCapability, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 220 | if d := oltA.getDevice(device.Id); d == nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 221 | logger.Fatalf(ctx, "device-not-found-%s", device.Id) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 222 | } |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 223 | return &ca.SwitchCapability{ |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 224 | 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 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 240 | // Disable_device disables device |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 241 | func (oltA *OLTAdapter) DisableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 242 | go func() { |
| 243 | if d := oltA.getDevice(device.Id); d == nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 244 | logger.Fatalf(ctx, "device-not-found-%s", device.Id) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | cloned := proto.Clone(device).(*voltha.Device) |
| 248 | // Update the all ports state on that device to disable |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 249 | c, err := oltA.GetCoreClient() |
| 250 | if err != nil { |
| 251 | return |
| 252 | } |
| 253 | |
| 254 | if _, err := c.PortsStateUpdate(context.TODO(), |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 255 | &ca.PortStateFilter{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 256 | DeviceId: cloned.Id, |
| 257 | PortTypeFilter: 0, |
| 258 | OperStatus: common.OperStatus_UNKNOWN, |
| 259 | }); err != nil { |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 260 | 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] | 261 | } |
| 262 | |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 263 | //Update the device operational state |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 264 | cloned.OperStatus = common.OperStatus_UNKNOWN |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 265 | // The device is still reachable after it has been disabled, so the connection status should not be changed. |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 266 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 267 | if _, err := c.DeviceStateUpdate(context.TODO(), &ca.DeviceStateFilter{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 268 | DeviceId: cloned.Id, |
| 269 | OperStatus: cloned.OperStatus, |
| 270 | ConnStatus: cloned.ConnectStatus, |
| 271 | }); err != nil { |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 272 | // Device may already have been deleted in the core |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 273 | 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] | 274 | return |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 275 | } |
| 276 | |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 277 | oltA.updateDevice(cloned) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 278 | |
| 279 | // Tell the Core that all child devices have been disabled (by default it's an action already taken by the Core |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 280 | if _, err := c.ChildDevicesLost(context.TODO(), &common.ID{Id: cloned.Id}); err != nil { |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 281 | // Device may already have been deleted in the core |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 282 | logger.Warnw(ctx, "lost-notif-of-child-devices-failed", log.Fields{"device-id": device.Id, "error": err}) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 283 | } |
| 284 | }() |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 285 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 286 | } |
| 287 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 288 | // Reenable_device reenables device |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 289 | func (oltA *OLTAdapter) ReEnableDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 290 | go func() { |
| 291 | if d := oltA.getDevice(device.Id); d == nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 292 | logger.Fatalf(ctx, "device-not-found-%s", device.Id) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | cloned := proto.Clone(device).(*voltha.Device) |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 296 | |
| 297 | c, err := oltA.GetCoreClient() |
| 298 | if err != nil { |
| 299 | return |
| 300 | } |
| 301 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 302 | // Update the all ports state on that device to enable |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 303 | if _, err := c.PortsStateUpdate(context.TODO(), |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 304 | &ca.PortStateFilter{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 305 | 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}) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | //Update the device state |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 313 | cloned.OperStatus = common.OperStatus_ACTIVE |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 314 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 315 | if _, err := c.DeviceStateUpdate(context.TODO(), &ca.DeviceStateFilter{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 316 | DeviceId: cloned.Id, |
| 317 | OperStatus: cloned.OperStatus, |
| 318 | ConnStatus: cloned.ConnectStatus, |
| 319 | }); err != nil { |
| 320 | // Device may already have been deleted in the core |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 321 | 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] | 322 | return |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | // Tell the Core that all child devices have been enabled |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 326 | if _, err := c.ChildDevicesDetected(context.TODO(), &common.ID{Id: cloned.Id}); err != nil { |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 327 | logger.Fatalf(ctx, "detection-notif-of-child-devices-failed", log.Fields{"device-id": device.Id, "error": err}) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 328 | } |
| 329 | }() |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 330 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 331 | } |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 332 | |
| 333 | // Enable_port - |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 334 | func (oltA *OLTAdapter) EnablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { //nolint |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 335 | go func() { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 336 | c, err := oltA.GetCoreClient() |
| 337 | if err != nil { |
| 338 | return |
| 339 | } |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 340 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 341 | if port.Type == voltha.Port_PON_OLT { |
| 342 | if _, err := c.PortStateUpdate(context.TODO(), |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 343 | &ca.PortState{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 344 | 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}) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | |
| 353 | }() |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 354 | return &empty.Empty{}, nil |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | // Disable_port - |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 358 | func (oltA *OLTAdapter) DisablePort(ctx context.Context, port *voltha.Port) (*empty.Empty, error) { //nolint |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 359 | go func() { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 360 | 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(), |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 366 | &ca.PortState{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 367 | DeviceId: port.DeviceId, |
| 368 | PortType: voltha.Port_PON_OLT, |
| 369 | PortNo: port.PortNo, |
| 370 | OperStatus: common.OperStatus_DISCOVERED, |
| 371 | }); err != nil { |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 372 | // Corresponding device may have been deleted |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 373 | logger.Warnw(ctx, "updating-ports-failed", log.Fields{"device-id": port.DeviceId, "error": err}) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | }() |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 377 | return &empty.Empty{}, nil |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 378 | } |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 379 | |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 380 | // Reboot_device - |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 381 | func (oltA *OLTAdapter) RebootDevice(ctx context.Context, device *voltha.Device) (*empty.Empty, error) { // nolint |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 382 | logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id}) |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 383 | |
| 384 | go func() { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 385 | c, err := oltA.GetCoreClient() |
| 386 | if err != nil { |
| 387 | return |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 388 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 389 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 390 | if _, err := c.DeviceStateUpdate(context.TODO(), &ca.DeviceStateFilter{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 391 | 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(), |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 400 | &ca.PortStateFilter{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 401 | 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 Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 406 | } |
| 407 | }() |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 408 | return &empty.Empty{}, nil |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 411 | // TODO: REMOVE Start_omci_test begins an omci self-test |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 412 | func (oltA *OLTAdapter) StartOmciTest(ctx context.Context, test *ca.OMCITest) (*omci.TestResponse, error) { // nolint |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 413 | return nil, errors.New("start-omci-test-not-implemented") |
| 414 | } |
| 415 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 416 | // Helper for test only |
| 417 | func (oltA *OLTAdapter) SetDeviceActive(deviceID string) { |
| 418 | c, err := oltA.GetCoreClient() |
| 419 | if err != nil { |
| 420 | return |
| 421 | } |
ssiddiqui | f076cb8 | 2021-04-23 10:47:04 +0530 | [diff] [blame] | 422 | |
khenaidoo | 9beaaf1 | 2021-10-19 17:32:01 -0400 | [diff] [blame] | 423 | if _, err := c.DeviceStateUpdate(context.TODO(), &ca.DeviceStateFilter{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 424 | 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 | } |
ssiddiqui | f076cb8 | 2021-04-23 10:47:04 +0530 | [diff] [blame] | 431 | |
yasin sapli | 5458a1c | 2021-06-14 22:24:38 +0000 | [diff] [blame] | 432 | } |