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" |
| 30 | "github.com/phayes/freeport" |
| 31 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 32 | "github.com/gogo/protobuf/proto" |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 33 | 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" |
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 | // OLTAdapter represent OLT adapter |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 42 | type OLTAdapter 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 | ChildDeviceType string |
| 45 | childVendor string |
| 46 | grpcServer *vgrpc.GrpcServer |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 47 | } |
| 48 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 49 | // NewOLTAdapter - creates OLT adapter instance |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 50 | func 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}) |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 55 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 56 | |
| 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 | |
| 66 | func (oltA *OLTAdapter) oltRestarted(ctx context.Context, endPoint string) error { |
| 67 | logger.Errorw(ctx, "remote-restarted", log.Fields{"endpoint": endPoint}) |
| 68 | return nil |
| 69 | } |
| 70 | |
| 71 | func (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 |
| 106 | func (oltA *OLTAdapter) StopGrpcClient() { |
| 107 | // Stop the grpc clients |
| 108 | oltA.coreClient.Stop(context.Background()) |
| 109 | } |
| 110 | |
| 111 | // Stop brings down core services |
| 112 | func (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 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 120 | } |
| 121 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 122 | // Adopt_device creates new handler for added device |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 123 | func (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}) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 125 | go func() { |
| 126 | d := proto.Clone(device).(*voltha.Device) |
| 127 | d.Root = true |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 128 | d.Vendor = oltA.vendor |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 129 | d.Model = "go-mock" |
| 130 | d.SerialNumber = com.GetRandomSerialNumber() |
| 131 | d.MacAddress = strings.ToUpper(com.GetRandomMacAddress()) |
| 132 | oltA.storeDevice(d) |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 133 | c, err := oltA.GetCoreClient() |
| 134 | if err != nil { |
| 135 | return |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 136 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 137 | if _, err := c.DeviceUpdate(context.TODO(), d); err != nil { |
| 138 | logger.Fatalf(ctx, "deviceUpdate-failed-%s", err) |
| 139 | } |
| 140 | |
khenaidoo | c6c7bda | 2020-06-17 17:20:18 -0400 | [diff] [blame] | 141 | capability := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 142 | nniPort := &voltha.Port{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 143 | DeviceId: device.Id, |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 144 | PortNo: 2, |
| 145 | Label: fmt.Sprintf("nni-%d", 2), |
| 146 | Type: voltha.Port_ETHERNET_NNI, |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 147 | OperStatus: common.OperStatus_ACTIVE, |
khenaidoo | c6c7bda | 2020-06-17 17:20:18 -0400 | [diff] [blame] | 148 | 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 | }, |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 158 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 159 | if _, err = c.PortCreated(context.TODO(), nniPort); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 160 | logger.Fatalf(ctx, "PortCreated-failed-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | ponPort := &voltha.Port{ |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 164 | DeviceId: device.Id, |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 165 | PortNo: 1, |
| 166 | Label: fmt.Sprintf("pon-%d", 1), |
| 167 | Type: voltha.Port_PON_OLT, |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 168 | OperStatus: common.OperStatus_ACTIVE, |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 169 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 170 | if _, err = c.PortCreated(context.TODO(), ponPort); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 171 | logger.Fatalf(ctx, "PortCreated-failed-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 172 | } |
| 173 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 174 | d.ConnectStatus = common.ConnectStatus_REACHABLE |
| 175 | d.OperStatus = common.OperStatus_ACTIVE |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 176 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 177 | 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) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | //Get the latest device data from the Core |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 182 | 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] | 183 | logger.Fatalf(ctx, "getting-device-failed-%s", err) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 184 | } |
| 185 | |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 186 | oltA.updateDevice(d) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 187 | |
| 188 | // Register Child devices |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 189 | initialUniPortNo := startingUNIPortNo |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 190 | for i := 0; i < numONUPerOLT; i++ { |
| 191 | go func(seqNo int) { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 192 | 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}) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 203 | } |
| 204 | }(i) |
| 205 | } |
| 206 | }() |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 207 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 208 | } |
| 209 | |
Andrea Campanella | 025667e | 2021-01-14 11:50:07 +0100 | [diff] [blame] | 210 | // Single_get_value_request retrieves a single value. |
| 211 | func (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 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 217 | // Get_ofp_device_info returns ofp device info |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 218 | func (oltA *OLTAdapter) GetOfpDeviceInfo(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) { // nolint |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 219 | if d := oltA.getDevice(device.Id); d == nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 220 | logger.Fatalf(ctx, "device-not-found-%s", device.Id) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 221 | } |
| 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 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 239 | // Disable_device disables device |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 240 | 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] | 241 | go func() { |
| 242 | if d := oltA.getDevice(device.Id); d == nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 243 | logger.Fatalf(ctx, "device-not-found-%s", device.Id) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | cloned := proto.Clone(device).(*voltha.Device) |
| 247 | // Update the all ports state on that device to disable |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 248 | 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 { |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 259 | 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] | 260 | } |
| 261 | |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 262 | //Update the device operational state |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 263 | cloned.OperStatus = common.OperStatus_UNKNOWN |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 264 | // 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] | 265 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 266 | if _, err := c.DeviceStateUpdate(context.TODO(), &ic.DeviceStateFilter{ |
| 267 | DeviceId: cloned.Id, |
| 268 | OperStatus: cloned.OperStatus, |
| 269 | ConnStatus: cloned.ConnectStatus, |
| 270 | }); err != nil { |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 271 | // Device may already have been deleted in the core |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 272 | 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] | 273 | return |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 274 | } |
| 275 | |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 276 | oltA.updateDevice(cloned) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 277 | |
| 278 | // 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] | 279 | if _, err := c.ChildDevicesLost(context.TODO(), &common.ID{Id: cloned.Id}); err != nil { |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 280 | // Device may already have been deleted in the core |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 281 | 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] | 282 | } |
| 283 | }() |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 284 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 285 | } |
| 286 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 287 | // Reenable_device reenables device |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 288 | 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] | 289 | go func() { |
| 290 | if d := oltA.getDevice(device.Id); d == nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 291 | logger.Fatalf(ctx, "device-not-found-%s", device.Id) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | cloned := proto.Clone(device).(*voltha.Device) |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 295 | |
| 296 | c, err := oltA.GetCoreClient() |
| 297 | if err != nil { |
| 298 | return |
| 299 | } |
| 300 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 301 | // Update the all ports state on that device to enable |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 302 | 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}) |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | //Update the device state |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 312 | cloned.OperStatus = common.OperStatus_ACTIVE |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 313 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 314 | 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 |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 320 | 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] | 321 | return |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | // Tell the Core that all child devices have been enabled |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 325 | if _, err := c.ChildDevicesDetected(context.TODO(), &common.ID{Id: cloned.Id}); err != nil { |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 326 | 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] | 327 | } |
| 328 | }() |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 329 | return &empty.Empty{}, nil |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 330 | } |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 331 | |
| 332 | // Enable_port - |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 333 | 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] | 334 | go func() { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 335 | c, err := oltA.GetCoreClient() |
| 336 | if err != nil { |
| 337 | return |
| 338 | } |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 339 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 340 | 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}) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | |
| 352 | }() |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 353 | return &empty.Empty{}, nil |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | // Disable_port - |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 357 | 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] | 358 | go func() { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 359 | 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 { |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 371 | // Corresponding device may have been deleted |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 372 | 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] | 373 | } |
| 374 | } |
| 375 | }() |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 376 | return &empty.Empty{}, nil |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 377 | } |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 378 | |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 379 | // Reboot_device - |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 380 | 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] | 381 | logger.Infow(ctx, "reboot-device", log.Fields{"device-id": device.Id}) |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 382 | |
| 383 | go func() { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 384 | c, err := oltA.GetCoreClient() |
| 385 | if err != nil { |
| 386 | return |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 387 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 388 | |
| 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 Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 405 | } |
| 406 | }() |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 407 | return &empty.Empty{}, nil |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 410 | // TODO: REMOVE Start_omci_test begins an omci self-test |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 411 | func (oltA *OLTAdapter) StartOmciTest(ctx context.Context, test *ic.OMCITest) (*voltha.TestResponse, error) { // nolint |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 412 | return nil, errors.New("start-omci-test-not-implemented") |
| 413 | } |
| 414 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 415 | // Helper for test only |
| 416 | func (oltA *OLTAdapter) SetDeviceActive(deviceID string) { |
| 417 | c, err := oltA.GetCoreClient() |
| 418 | if err != nil { |
| 419 | return |
| 420 | } |
ssiddiqui | f076cb8 | 2021-04-23 10:47:04 +0530 | [diff] [blame] | 421 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 422 | 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 | } |
ssiddiqui | f076cb8 | 2021-04-23 10:47:04 +0530 | [diff] [blame] | 430 | |
yasin sapli | 5458a1c | 2021-06-14 22:24:38 +0000 | [diff] [blame] | 431 | } |