khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-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 | */ |
| 16 | package core |
| 17 | |
| 18 | import ( |
| 19 | "errors" |
| 20 | "github.com/golang/protobuf/ptypes" |
| 21 | "github.com/golang/protobuf/ptypes/empty" |
khenaidoo | 1ce37ad | 2019-03-24 22:07:24 -0400 | [diff] [blame] | 22 | "github.com/opencord/voltha-go/rw_core/utils" |
Scott Baker | 807addd | 2019-10-24 15:16:21 -0700 | [diff] [blame] | 23 | "github.com/opencord/voltha-lib-go/v2/pkg/db/model" |
| 24 | "github.com/opencord/voltha-lib-go/v2/pkg/kafka" |
| 25 | "github.com/opencord/voltha-lib-go/v2/pkg/log" |
Scott Baker | 555307d | 2019-11-04 08:58:01 -0800 | [diff] [blame] | 26 | ic "github.com/opencord/voltha-protos/v2/go/inter_container" |
| 27 | "github.com/opencord/voltha-protos/v2/go/voltha" |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 28 | "google.golang.org/grpc/codes" |
| 29 | "google.golang.org/grpc/status" |
| 30 | ) |
| 31 | |
| 32 | type AdapterRequestHandlerProxy struct { |
khenaidoo | de93b46 | 2019-02-13 22:17:21 -0500 | [diff] [blame] | 33 | TestMode bool |
| 34 | coreInstanceId string |
| 35 | deviceMgr *DeviceManager |
| 36 | lDeviceMgr *LogicalDeviceManager |
| 37 | adapterMgr *AdapterManager |
| 38 | localDataProxy *model.Proxy |
| 39 | clusterDataProxy *model.Proxy |
| 40 | defaultRequestTimeout int64 |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 41 | longRunningRequestTimeout int64 |
khenaidoo | de93b46 | 2019-02-13 22:17:21 -0500 | [diff] [blame] | 42 | coreInCompetingMode bool |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 43 | core *Core |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 44 | } |
| 45 | |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 46 | func NewAdapterRequestHandlerProxy(core *Core, coreInstanceId string, dMgr *DeviceManager, ldMgr *LogicalDeviceManager, |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 47 | aMgr *AdapterManager, cdProxy *model.Proxy, ldProxy *model.Proxy, incompetingMode bool, longRunningRequestTimeout int64, |
| 48 | defaultRequestTimeout int64) *AdapterRequestHandlerProxy { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 49 | var proxy AdapterRequestHandlerProxy |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 50 | proxy.core = core |
khenaidoo | 91ecfd6 | 2018-11-04 17:13:42 -0500 | [diff] [blame] | 51 | proxy.coreInstanceId = coreInstanceId |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 52 | proxy.deviceMgr = dMgr |
| 53 | proxy.lDeviceMgr = ldMgr |
| 54 | proxy.clusterDataProxy = cdProxy |
| 55 | proxy.localDataProxy = ldProxy |
khenaidoo | 21d5115 | 2019-02-01 13:48:37 -0500 | [diff] [blame] | 56 | proxy.adapterMgr = aMgr |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 57 | proxy.coreInCompetingMode = incompetingMode |
| 58 | proxy.defaultRequestTimeout = defaultRequestTimeout |
| 59 | proxy.longRunningRequestTimeout = longRunningRequestTimeout |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 60 | return &proxy |
| 61 | } |
| 62 | |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 63 | // This is a helper function that attempts to acquire the request by using the device ownership model |
| 64 | func (rhp *AdapterRequestHandlerProxy) takeRequestOwnership(transactionId string, devId string, maxTimeout ...int64) (*KVTransaction, error) { |
| 65 | timeout := rhp.defaultRequestTimeout |
| 66 | if len(maxTimeout) > 0 { |
| 67 | timeout = maxTimeout[0] |
| 68 | } |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 69 | txn := NewKVTransaction(transactionId) |
| 70 | if txn == nil { |
| 71 | return nil, errors.New("fail-to-create-transaction") |
| 72 | } |
| 73 | |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 74 | var acquired bool |
| 75 | var err error |
| 76 | if devId != "" { |
| 77 | var ownedByMe bool |
| 78 | if ownedByMe, err = rhp.core.deviceOwnership.OwnedByMe(&utils.DeviceID{Id: devId}); err != nil { |
| 79 | log.Warnw("getting-ownership-failed", log.Fields{"deviceId": devId, "error": err}) |
| 80 | return nil, kafka.ErrorTransactionInvalidId |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 81 | } |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 82 | acquired, err = txn.Acquired(timeout, ownedByMe) |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 83 | } else { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 84 | acquired, err = txn.Acquired(timeout) |
| 85 | } |
| 86 | if err == nil && acquired { |
| 87 | log.Debugw("transaction-acquired", log.Fields{"transactionId": txn.txnId}) |
| 88 | return txn, nil |
| 89 | } else { |
| 90 | log.Debugw("transaction-not-acquired", log.Fields{"transactionId": txn.txnId, "error": err}) |
| 91 | return nil, kafka.ErrorTransactionNotAcquired |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 95 | // competeForTransaction is a helper function to determine whether every request needs to compete with another |
| 96 | // Core to execute the request |
| 97 | func (rhp *AdapterRequestHandlerProxy) competeForTransaction() bool { |
| 98 | return rhp.coreInCompetingMode |
| 99 | } |
| 100 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 101 | func (rhp *AdapterRequestHandlerProxy) Register(args []*ic.Argument) (*voltha.CoreInstance, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 102 | if len(args) < 3 { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 103 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 104 | err := errors.New("invalid-number-of-args") |
| 105 | return nil, err |
| 106 | } |
| 107 | adapter := &voltha.Adapter{} |
khenaidoo | 91ecfd6 | 2018-11-04 17:13:42 -0500 | [diff] [blame] | 108 | deviceTypes := &voltha.DeviceTypes{} |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 109 | transactionId := &ic.StrType{} |
khenaidoo | 91ecfd6 | 2018-11-04 17:13:42 -0500 | [diff] [blame] | 110 | for _, arg := range args { |
| 111 | switch arg.Key { |
| 112 | case "adapter": |
| 113 | if err := ptypes.UnmarshalAny(arg.Value, adapter); err != nil { |
| 114 | log.Warnw("cannot-unmarshal-adapter", log.Fields{"error": err}) |
| 115 | return nil, err |
| 116 | } |
| 117 | case "deviceTypes": |
| 118 | if err := ptypes.UnmarshalAny(arg.Value, deviceTypes); err != nil { |
| 119 | log.Warnw("cannot-unmarshal-device-types", log.Fields{"error": err}) |
| 120 | return nil, err |
| 121 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 122 | case kafka.TransactionKey: |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 123 | if err := ptypes.UnmarshalAny(arg.Value, transactionId); err != nil { |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 124 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 125 | return nil, err |
| 126 | } |
khenaidoo | 91ecfd6 | 2018-11-04 17:13:42 -0500 | [diff] [blame] | 127 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 128 | } |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 129 | log.Debugw("Register", log.Fields{"Adapter": *adapter, "DeviceTypes": deviceTypes, "transactionId": transactionId.Val, "coreId": rhp.coreInstanceId}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 130 | |
| 131 | // Try to grab the transaction as this core may be competing with another Core |
| 132 | if rhp.competeForTransaction() { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 133 | if txn, err := rhp.takeRequestOwnership(transactionId.Val, ""); err != nil { |
| 134 | if err.Error() == kafka.ErrorTransactionNotAcquired.Error() { |
| 135 | log.Debugw("Another core handled the request", log.Fields{"transactionId": transactionId}) |
| 136 | // Update our adapters in memory |
| 137 | go rhp.adapterMgr.updateAdaptersAndDevicetypesInMemory(adapter) |
| 138 | } |
| 139 | return nil, err |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 140 | } else { |
| 141 | defer txn.Close() |
| 142 | } |
| 143 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 144 | |
| 145 | if rhp.TestMode { // Execute only for test cases |
| 146 | return &voltha.CoreInstance{InstanceId: "CoreInstance"}, nil |
| 147 | } |
khenaidoo | 21d5115 | 2019-02-01 13:48:37 -0500 | [diff] [blame] | 148 | return rhp.adapterMgr.registerAdapter(adapter, deviceTypes), nil |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 149 | } |
| 150 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 151 | func (rhp *AdapterRequestHandlerProxy) GetDevice(args []*ic.Argument) (*voltha.Device, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 152 | if len(args) < 2 { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 153 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 154 | err := errors.New("invalid-number-of-args") |
| 155 | return nil, err |
| 156 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 157 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 158 | pID := &voltha.ID{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 159 | transactionID := &ic.StrType{} |
| 160 | for _, arg := range args { |
| 161 | switch arg.Key { |
| 162 | case "device_id": |
| 163 | if err := ptypes.UnmarshalAny(arg.Value, pID); err != nil { |
| 164 | log.Warnw("cannot-unmarshal-ID", log.Fields{"error": err}) |
| 165 | return nil, err |
| 166 | } |
| 167 | case kafka.TransactionKey: |
| 168 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 169 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 170 | return nil, err |
| 171 | } |
| 172 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 173 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 174 | log.Debugw("GetDevice", log.Fields{"deviceId": pID.Id, "transactionID": transactionID.Val}) |
| 175 | |
| 176 | // Try to grab the transaction as this core may be competing with another Core |
| 177 | if rhp.competeForTransaction() { |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 178 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, pID.Id); err != nil { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 179 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 180 | return nil, err |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 181 | } else { |
| 182 | defer txn.Close() |
| 183 | } |
| 184 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 185 | |
| 186 | if rhp.TestMode { // Execute only for test cases |
| 187 | return &voltha.Device{Id: pID.Id}, nil |
| 188 | } |
| 189 | |
| 190 | // Get the device via the device manager |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 191 | if device, err := rhp.deviceMgr.GetDevice(pID.Id); err != nil { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 192 | return nil, status.Errorf(codes.NotFound, "%s", err.Error()) |
| 193 | } else { |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 194 | log.Debugw("GetDevice-response", log.Fields{"deviceId": pID.Id}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 195 | return device, nil |
| 196 | } |
| 197 | } |
| 198 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 199 | func (rhp *AdapterRequestHandlerProxy) DeviceUpdate(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 200 | if len(args) < 2 { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 201 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 202 | err := errors.New("invalid-number-of-args") |
| 203 | return nil, err |
| 204 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 205 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 206 | device := &voltha.Device{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 207 | transactionID := &ic.StrType{} |
| 208 | for _, arg := range args { |
| 209 | switch arg.Key { |
| 210 | case "device": |
| 211 | if err := ptypes.UnmarshalAny(arg.Value, device); err != nil { |
| 212 | log.Warnw("cannot-unmarshal-ID", log.Fields{"error": err}) |
| 213 | return nil, err |
| 214 | } |
| 215 | case kafka.TransactionKey: |
| 216 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 217 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 218 | return nil, err |
| 219 | } |
| 220 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 221 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 222 | log.Debugw("DeviceUpdate", log.Fields{"deviceId": device.Id, "transactionID": transactionID.Val}) |
| 223 | |
| 224 | // Try to grab the transaction as this core may be competing with another Core |
| 225 | if rhp.competeForTransaction() { |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 226 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, device.Id); err != nil { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 227 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 228 | return nil, err |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 229 | } else { |
| 230 | defer txn.Close() |
| 231 | } |
| 232 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 233 | |
Mahir Gunyel | 6deaa24 | 2019-06-27 04:53:33 -0700 | [diff] [blame] | 234 | log.Debugw("DeviceUpdate got txn", log.Fields{"deviceId": device.Id, "transactionID": transactionID.Val}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 235 | if rhp.TestMode { // Execute only for test cases |
| 236 | return new(empty.Empty), nil |
| 237 | } |
Mahir Gunyel | 8e2707d | 2019-07-25 00:36:21 -0700 | [diff] [blame] | 238 | go rhp.deviceMgr.updateDeviceUsingAdapterData(device) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 239 | return new(empty.Empty), nil |
| 240 | } |
| 241 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 242 | func (rhp *AdapterRequestHandlerProxy) GetChildDevice(args []*ic.Argument) (*voltha.Device, error) { |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 243 | if len(args) < 3 { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 244 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 245 | err := errors.New("invalid-number-of-args") |
| 246 | return nil, err |
| 247 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 248 | |
khenaidoo | 2c6f167 | 2018-09-20 23:14:41 -0400 | [diff] [blame] | 249 | pID := &voltha.ID{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 250 | transactionID := &ic.StrType{} |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 251 | serialNumber := &ic.StrType{} |
| 252 | onuId := &ic.IntType{} |
| 253 | parentPortNo := &ic.IntType{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 254 | for _, arg := range args { |
| 255 | switch arg.Key { |
| 256 | case "device_id": |
| 257 | if err := ptypes.UnmarshalAny(arg.Value, pID); err != nil { |
| 258 | log.Warnw("cannot-unmarshal-ID", log.Fields{"error": err}) |
| 259 | return nil, err |
| 260 | } |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 261 | case "serial_number": |
| 262 | if err := ptypes.UnmarshalAny(arg.Value, serialNumber); err != nil { |
| 263 | log.Warnw("cannot-unmarshal-ID", log.Fields{"error": err}) |
| 264 | return nil, err |
| 265 | } |
| 266 | case "onu_id": |
| 267 | if err := ptypes.UnmarshalAny(arg.Value, onuId); err != nil { |
| 268 | log.Warnw("cannot-unmarshal-ID", log.Fields{"error": err}) |
| 269 | return nil, err |
| 270 | } |
| 271 | case "parent_port_no": |
| 272 | if err := ptypes.UnmarshalAny(arg.Value, parentPortNo); err != nil { |
| 273 | log.Warnw("cannot-unmarshal-ID", log.Fields{"error": err}) |
| 274 | return nil, err |
| 275 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 276 | case kafka.TransactionKey: |
| 277 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 278 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 279 | return nil, err |
| 280 | } |
| 281 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 282 | } |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 283 | log.Debugw("GetChildDevice", log.Fields{"parentDeviceId": pID.Id, "args": args, "transactionID": transactionID.Val}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 284 | |
| 285 | // Try to grab the transaction as this core may be competing with another Core |
| 286 | if rhp.competeForTransaction() { |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 287 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, pID.Id); err != nil { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 288 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 289 | return nil, err |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 290 | } else { |
| 291 | defer txn.Close() |
| 292 | } |
| 293 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 294 | |
| 295 | if rhp.TestMode { // Execute only for test cases |
khenaidoo | 2c6f167 | 2018-09-20 23:14:41 -0400 | [diff] [blame] | 296 | return &voltha.Device{Id: pID.Id}, nil |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 297 | } |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 298 | return rhp.deviceMgr.GetChildDevice(pID.Id, serialNumber.Val, onuId.Val, parentPortNo.Val) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 299 | } |
| 300 | |
Matt Jeanneret | 2a20aaa | 2019-03-05 21:04:02 -0500 | [diff] [blame] | 301 | func (rhp *AdapterRequestHandlerProxy) GetChildDeviceWithProxyAddress(args []*ic.Argument) (*voltha.Device, error) { |
| 302 | if len(args) < 2 { |
| 303 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 304 | err := errors.New("invalid-number-of-args") |
| 305 | return nil, err |
| 306 | } |
| 307 | |
| 308 | proxyAddress := &voltha.Device_ProxyAddress{} |
| 309 | transactionID := &ic.StrType{} |
| 310 | for _, arg := range args { |
| 311 | switch arg.Key { |
| 312 | case "proxy_address": |
| 313 | if err := ptypes.UnmarshalAny(arg.Value, proxyAddress); err != nil { |
| 314 | log.Warnw("cannot-unmarshal-proxy-address", log.Fields{"error": err}) |
| 315 | return nil, err |
| 316 | } |
| 317 | case kafka.TransactionKey: |
| 318 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 319 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 320 | return nil, err |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | log.Debugw("GetChildDeviceWithProxyAddress", log.Fields{"proxyAddress": proxyAddress, "transactionID": transactionID.Val}) |
| 325 | |
| 326 | // Try to grab the transaction as this core may be competing with another Core |
| 327 | if rhp.competeForTransaction() { |
khenaidoo | 1ce37ad | 2019-03-24 22:07:24 -0400 | [diff] [blame] | 328 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, proxyAddress.DeviceId); err != nil { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 329 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 330 | return nil, err |
Matt Jeanneret | 2a20aaa | 2019-03-05 21:04:02 -0500 | [diff] [blame] | 331 | } else { |
| 332 | defer txn.Close() |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | if rhp.TestMode { // Execute only for test cases |
| 337 | return &voltha.Device{Id: proxyAddress.DeviceId}, nil |
| 338 | } |
| 339 | return rhp.deviceMgr.GetChildDeviceWithProxyAddress(proxyAddress) |
| 340 | } |
| 341 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 342 | func (rhp *AdapterRequestHandlerProxy) GetPorts(args []*ic.Argument) (*voltha.Ports, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 343 | if len(args) < 3 { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 344 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 345 | err := errors.New("invalid-number-of-args") |
| 346 | return nil, err |
| 347 | } |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 348 | deviceId := &voltha.ID{} |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 349 | pt := &ic.IntType{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 350 | transactionID := &ic.StrType{} |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 351 | for _, arg := range args { |
| 352 | switch arg.Key { |
| 353 | case "device_id": |
| 354 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
| 355 | log.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
| 356 | return nil, err |
| 357 | } |
| 358 | case "port_type": |
| 359 | if err := ptypes.UnmarshalAny(arg.Value, pt); err != nil { |
| 360 | log.Warnw("cannot-unmarshal-porttype", log.Fields{"error": err}) |
| 361 | return nil, err |
| 362 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 363 | case kafka.TransactionKey: |
| 364 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 365 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 366 | return nil, err |
| 367 | } |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 368 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 369 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 370 | log.Debugw("GetPorts", log.Fields{"deviceID": deviceId.Id, "portype": pt.Val, "transactionID": transactionID.Val}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 371 | if rhp.TestMode { // Execute only for test cases |
| 372 | aPort := &voltha.Port{Label: "test_port"} |
| 373 | allPorts := &voltha.Ports{} |
| 374 | allPorts.Items = append(allPorts.Items, aPort) |
| 375 | return allPorts, nil |
| 376 | } |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 377 | // Try to grab the transaction as this core may be competing with another Core |
| 378 | if rhp.competeForTransaction() { |
| 379 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, deviceId.Id); err != nil { |
| 380 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 381 | return nil, err |
| 382 | } else { |
| 383 | defer txn.Close() |
| 384 | } |
| 385 | } |
| 386 | |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 387 | return rhp.deviceMgr.getPorts(nil, deviceId.Id, voltha.Port_PortType(pt.Val)) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 388 | } |
| 389 | |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 390 | func (rhp *AdapterRequestHandlerProxy) GetChildDevices(args []*ic.Argument) (*voltha.Devices, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 391 | if len(args) < 2 { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 392 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 393 | err := errors.New("invalid-number-of-args") |
| 394 | return nil, err |
| 395 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 396 | |
khenaidoo | 2c6f167 | 2018-09-20 23:14:41 -0400 | [diff] [blame] | 397 | pID := &voltha.ID{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 398 | transactionID := &ic.StrType{} |
| 399 | for _, arg := range args { |
| 400 | switch arg.Key { |
| 401 | case "device_id": |
| 402 | if err := ptypes.UnmarshalAny(arg.Value, pID); err != nil { |
| 403 | log.Warnw("cannot-unmarshal-ID", log.Fields{"error": err}) |
| 404 | return nil, err |
| 405 | } |
| 406 | case kafka.TransactionKey: |
| 407 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 408 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 409 | return nil, err |
| 410 | } |
| 411 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 412 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 413 | log.Debugw("GetChildDevices", log.Fields{"deviceId": pID.Id, "transactionID": transactionID.Val}) |
| 414 | |
| 415 | // Try to grab the transaction as this core may be competing with another Core |
| 416 | if rhp.competeForTransaction() { |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 417 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, pID.Id); err != nil { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 418 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 419 | return nil, err |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 420 | } else { |
| 421 | defer txn.Close() |
| 422 | } |
| 423 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 424 | |
| 425 | if rhp.TestMode { // Execute only for test cases |
khenaidoo | de93b46 | 2019-02-13 22:17:21 -0500 | [diff] [blame] | 426 | return &voltha.Devices{Items: nil}, nil |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 427 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 428 | |
| 429 | return rhp.deviceMgr.getAllChildDevices(pID.Id) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | // ChildDeviceDetected is invoked when a child device is detected. The following |
| 433 | // parameters are expected: |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 434 | // {parent_device_id, parent_port_no, child_device_type, channel_id, vendor_id, serial_number) |
Mahir Gunyel | 6deaa24 | 2019-06-27 04:53:33 -0700 | [diff] [blame] | 435 | func (rhp *AdapterRequestHandlerProxy) ChildDeviceDetected(args []*ic.Argument) (*voltha.Device, error) { |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 436 | if len(args) < 5 { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 437 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 438 | err := errors.New("invalid-number-of-args") |
| 439 | return nil, err |
| 440 | } |
| 441 | |
| 442 | pID := &voltha.ID{} |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 443 | portNo := &ic.IntType{} |
| 444 | dt := &ic.StrType{} |
| 445 | chnlId := &ic.IntType{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 446 | transactionID := &ic.StrType{} |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 447 | serialNumber := &ic.StrType{} |
| 448 | vendorId := &ic.StrType{} |
| 449 | onuId := &ic.IntType{} |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 450 | for _, arg := range args { |
| 451 | switch arg.Key { |
| 452 | case "parent_device_id": |
| 453 | if err := ptypes.UnmarshalAny(arg.Value, pID); err != nil { |
| 454 | log.Warnw("cannot-unmarshal-parent-device-id", log.Fields{"error": err}) |
| 455 | return nil, err |
| 456 | } |
| 457 | case "parent_port_no": |
| 458 | if err := ptypes.UnmarshalAny(arg.Value, portNo); err != nil { |
| 459 | log.Warnw("cannot-unmarshal-parent-port", log.Fields{"error": err}) |
| 460 | return nil, err |
| 461 | } |
| 462 | case "child_device_type": |
| 463 | if err := ptypes.UnmarshalAny(arg.Value, dt); err != nil { |
| 464 | log.Warnw("cannot-unmarshal-child-device-type", log.Fields{"error": err}) |
| 465 | return nil, err |
| 466 | } |
| 467 | case "channel_id": |
| 468 | if err := ptypes.UnmarshalAny(arg.Value, chnlId); err != nil { |
| 469 | log.Warnw("cannot-unmarshal-channel-id", log.Fields{"error": err}) |
| 470 | return nil, err |
| 471 | } |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 472 | case "vendor_id": |
| 473 | if err := ptypes.UnmarshalAny(arg.Value, vendorId); err != nil { |
| 474 | log.Warnw("cannot-unmarshal-vendor-id", log.Fields{"error": err}) |
| 475 | return nil, err |
| 476 | } |
| 477 | case "serial_number": |
| 478 | if err := ptypes.UnmarshalAny(arg.Value, serialNumber); err != nil { |
| 479 | log.Warnw("cannot-unmarshal-serial-number", log.Fields{"error": err}) |
| 480 | return nil, err |
| 481 | } |
| 482 | case "onu_id": |
| 483 | if err := ptypes.UnmarshalAny(arg.Value, onuId); err != nil { |
| 484 | log.Warnw("cannot-unmarshal-onu-id", log.Fields{"error": err}) |
| 485 | return nil, err |
| 486 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 487 | case kafka.TransactionKey: |
| 488 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 489 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 490 | return nil, err |
| 491 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 492 | } |
| 493 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 494 | log.Debugw("ChildDeviceDetected", log.Fields{"parentDeviceId": pID.Id, "parentPortNo": portNo.Val, |
Matt Jeanneret | 4e24195 | 2019-02-28 11:16:04 -0500 | [diff] [blame] | 495 | "deviceType": dt.Val, "channelId": chnlId.Val, "serialNumber": serialNumber.Val, |
| 496 | "vendorId": vendorId.Val, "onuId": onuId.Val, "transactionID": transactionID.Val}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 497 | |
| 498 | // Try to grab the transaction as this core may be competing with another Core |
| 499 | if rhp.competeForTransaction() { |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 500 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, pID.Id); err != nil { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 501 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 502 | return nil, err |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 503 | } else { |
| 504 | defer txn.Close() |
| 505 | } |
| 506 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 507 | |
| 508 | if rhp.TestMode { // Execute only for test cases |
| 509 | return nil, nil |
| 510 | } |
Mahir Gunyel | 6deaa24 | 2019-06-27 04:53:33 -0700 | [diff] [blame] | 511 | device, err := rhp.deviceMgr.childDeviceDetected(pID.Id, portNo.Val, dt.Val, chnlId.Val, vendorId.Val, serialNumber.Val, onuId.Val) |
| 512 | if err != nil { |
khenaidoo | 59ef7be | 2019-06-21 12:40:28 -0400 | [diff] [blame] | 513 | log.Errorw("child-detection-failed", log.Fields{"parentId": pID.Id, "onuId": onuId.Val, "error": err}) |
| 514 | return nil, err |
| 515 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 516 | |
Mahir Gunyel | 6deaa24 | 2019-06-27 04:53:33 -0700 | [diff] [blame] | 517 | return device, nil |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 518 | } |
| 519 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 520 | func (rhp *AdapterRequestHandlerProxy) DeviceStateUpdate(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 521 | if len(args) < 3 { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 522 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 523 | err := errors.New("invalid-number-of-args") |
| 524 | return nil, err |
| 525 | } |
| 526 | deviceId := &voltha.ID{} |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 527 | operStatus := &ic.IntType{} |
| 528 | connStatus := &ic.IntType{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 529 | transactionID := &ic.StrType{} |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 530 | for _, arg := range args { |
| 531 | switch arg.Key { |
| 532 | case "device_id": |
| 533 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
| 534 | log.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
| 535 | return nil, err |
| 536 | } |
| 537 | case "oper_status": |
| 538 | if err := ptypes.UnmarshalAny(arg.Value, operStatus); err != nil { |
| 539 | log.Warnw("cannot-unmarshal-operStatus", log.Fields{"error": err}) |
| 540 | return nil, err |
| 541 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 542 | case "connect_status": |
| 543 | if err := ptypes.UnmarshalAny(arg.Value, connStatus); err != nil { |
| 544 | log.Warnw("cannot-unmarshal-connStatus", log.Fields{"error": err}) |
| 545 | return nil, err |
| 546 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 547 | case kafka.TransactionKey: |
| 548 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 549 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 550 | return nil, err |
| 551 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 552 | } |
| 553 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 554 | log.Debugw("DeviceStateUpdate", log.Fields{"deviceId": deviceId.Id, "oper-status": operStatus, |
| 555 | "conn-status": connStatus, "transactionID": transactionID.Val}) |
| 556 | |
| 557 | // Try to grab the transaction as this core may be competing with another Core |
| 558 | if rhp.competeForTransaction() { |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 559 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, deviceId.Id); err != nil { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 560 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 561 | return nil, err |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 562 | } else { |
| 563 | defer txn.Close() |
| 564 | } |
| 565 | } |
| 566 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 567 | if rhp.TestMode { // Execute only for test cases |
| 568 | return nil, nil |
| 569 | } |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 570 | // When the enum is not set (i.e. -1), Go still convert to the Enum type with the value being -1 |
khenaidoo | 1ce37ad | 2019-03-24 22:07:24 -0400 | [diff] [blame] | 571 | go rhp.deviceMgr.updateDeviceStatus(deviceId.Id, voltha.OperStatus_OperStatus(operStatus.Val), |
| 572 | voltha.ConnectStatus_ConnectStatus(connStatus.Val)) |
| 573 | |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 574 | return new(empty.Empty), nil |
| 575 | } |
| 576 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 577 | func (rhp *AdapterRequestHandlerProxy) ChildrenStateUpdate(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 578 | if len(args) < 3 { |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 579 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 580 | err := errors.New("invalid-number-of-args") |
| 581 | return nil, err |
| 582 | } |
| 583 | deviceId := &voltha.ID{} |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 584 | operStatus := &ic.IntType{} |
| 585 | connStatus := &ic.IntType{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 586 | transactionID := &ic.StrType{} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 587 | for _, arg := range args { |
| 588 | switch arg.Key { |
| 589 | case "device_id": |
| 590 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
| 591 | log.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
| 592 | return nil, err |
| 593 | } |
| 594 | case "oper_status": |
| 595 | if err := ptypes.UnmarshalAny(arg.Value, operStatus); err != nil { |
| 596 | log.Warnw("cannot-unmarshal-operStatus", log.Fields{"error": err}) |
| 597 | return nil, err |
| 598 | } |
| 599 | case "connect_status": |
| 600 | if err := ptypes.UnmarshalAny(arg.Value, connStatus); err != nil { |
| 601 | log.Warnw("cannot-unmarshal-connStatus", log.Fields{"error": err}) |
| 602 | return nil, err |
| 603 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 604 | case kafka.TransactionKey: |
| 605 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 606 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 607 | return nil, err |
| 608 | } |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 609 | } |
| 610 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 611 | log.Debugw("ChildrenStateUpdate", log.Fields{"deviceId": deviceId.Id, "oper-status": operStatus, |
| 612 | "conn-status": connStatus, "transactionID": transactionID.Val}) |
| 613 | |
| 614 | // Try to grab the transaction as this core may be competing with another Core |
| 615 | if rhp.competeForTransaction() { |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 616 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, deviceId.Id); err != nil { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 617 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 618 | return nil, err |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 619 | } else { |
| 620 | defer txn.Close() |
| 621 | } |
| 622 | } |
| 623 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 624 | if rhp.TestMode { // Execute only for test cases |
| 625 | return nil, nil |
| 626 | } |
| 627 | |
| 628 | // When the enum is not set (i.e. -1), Go still convert to the Enum type with the value being -1 |
khenaidoo | 1ce37ad | 2019-03-24 22:07:24 -0400 | [diff] [blame] | 629 | go rhp.deviceMgr.updateChildrenStatus(deviceId.Id, voltha.OperStatus_OperStatus(operStatus.Val), |
| 630 | voltha.ConnectStatus_ConnectStatus(connStatus.Val)) |
| 631 | |
| 632 | //if err := rhp.deviceMgr.updateChildrenStatus(deviceId.Id, voltha.OperStatus_OperStatus(operStatus.Val), |
| 633 | // voltha.ConnectStatus_ConnectStatus(connStatus.Val)); err != nil { |
| 634 | // return nil, err |
| 635 | //} |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 636 | return new(empty.Empty), nil |
| 637 | } |
| 638 | |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 639 | func (rhp *AdapterRequestHandlerProxy) PortsStateUpdate(args []*ic.Argument) (*empty.Empty, error) { |
| 640 | if len(args) < 2 { |
| 641 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 642 | err := errors.New("invalid-number-of-args") |
| 643 | return nil, err |
| 644 | } |
| 645 | deviceId := &voltha.ID{} |
| 646 | operStatus := &ic.IntType{} |
| 647 | transactionID := &ic.StrType{} |
| 648 | for _, arg := range args { |
| 649 | switch arg.Key { |
| 650 | case "device_id": |
| 651 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
| 652 | log.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
| 653 | return nil, err |
| 654 | } |
| 655 | case "oper_status": |
| 656 | if err := ptypes.UnmarshalAny(arg.Value, operStatus); err != nil { |
| 657 | log.Warnw("cannot-unmarshal-operStatus", log.Fields{"error": err}) |
| 658 | return nil, err |
| 659 | } |
| 660 | case kafka.TransactionKey: |
| 661 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 662 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 663 | return nil, err |
| 664 | } |
| 665 | } |
| 666 | } |
| 667 | log.Debugw("PortsStateUpdate", log.Fields{"deviceId": deviceId.Id, "operStatus": operStatus, "transactionID": transactionID.Val}) |
| 668 | |
| 669 | // Try to grab the transaction as this core may be competing with another Core |
| 670 | if rhp.competeForTransaction() { |
| 671 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, deviceId.Id); err != nil { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 672 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 673 | return nil, err |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 674 | } else { |
| 675 | defer txn.Close() |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | if rhp.TestMode { // Execute only for test cases |
| 680 | return nil, nil |
| 681 | } |
| 682 | |
| 683 | go rhp.deviceMgr.updatePortsState(deviceId.Id, voltha.OperStatus_OperStatus(operStatus.Val)) |
| 684 | |
| 685 | return new(empty.Empty), nil |
| 686 | } |
| 687 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 688 | func (rhp *AdapterRequestHandlerProxy) PortStateUpdate(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 689 | if len(args) < 3 { |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 690 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 691 | err := errors.New("invalid-number-of-args") |
| 692 | return nil, err |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 693 | } |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 694 | deviceId := &voltha.ID{} |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 695 | portType := &ic.IntType{} |
| 696 | portNo := &ic.IntType{} |
| 697 | operStatus := &ic.IntType{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 698 | transactionID := &ic.StrType{} |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 699 | for _, arg := range args { |
| 700 | switch arg.Key { |
| 701 | case "device_id": |
| 702 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
| 703 | log.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
| 704 | return nil, err |
| 705 | } |
| 706 | case "oper_status": |
| 707 | if err := ptypes.UnmarshalAny(arg.Value, operStatus); err != nil { |
| 708 | log.Warnw("cannot-unmarshal-operStatus", log.Fields{"error": err}) |
| 709 | return nil, err |
| 710 | } |
| 711 | case "port_type": |
| 712 | if err := ptypes.UnmarshalAny(arg.Value, portType); err != nil { |
| 713 | log.Warnw("cannot-unmarshal-porttype", log.Fields{"error": err}) |
| 714 | return nil, err |
| 715 | } |
| 716 | case "port_no": |
| 717 | if err := ptypes.UnmarshalAny(arg.Value, portNo); err != nil { |
| 718 | log.Warnw("cannot-unmarshal-portno", log.Fields{"error": err}) |
| 719 | return nil, err |
| 720 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 721 | case kafka.TransactionKey: |
| 722 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 723 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 724 | return nil, err |
| 725 | } |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 726 | } |
| 727 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 728 | log.Debugw("PortStateUpdate", log.Fields{"deviceId": deviceId.Id, "operStatus": operStatus, |
| 729 | "portType": portType, "portNo": portNo, "transactionID": transactionID.Val}) |
| 730 | |
| 731 | // Try to grab the transaction as this core may be competing with another Core |
| 732 | if rhp.competeForTransaction() { |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 733 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, deviceId.Id); err != nil { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 734 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 735 | return nil, err |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 736 | } else { |
| 737 | defer txn.Close() |
| 738 | } |
| 739 | } |
| 740 | |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 741 | if rhp.TestMode { // Execute only for test cases |
| 742 | return nil, nil |
| 743 | } |
khenaidoo | 1ce37ad | 2019-03-24 22:07:24 -0400 | [diff] [blame] | 744 | |
| 745 | go rhp.deviceMgr.updatePortState(deviceId.Id, voltha.Port_PortType(portType.Val), uint32(portNo.Val), |
| 746 | voltha.OperStatus_OperStatus(operStatus.Val)) |
| 747 | |
| 748 | //if err := rhp.deviceMgr.updatePortState(deviceId.Id, voltha.Port_PortType(portType.Val), uint32(portNo.Val), |
| 749 | // voltha.OperStatus_OperStatus(operStatus.Val)); err != nil { |
| 750 | // return nil, err |
| 751 | //} |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 752 | return new(empty.Empty), nil |
| 753 | } |
| 754 | |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 755 | func (rhp *AdapterRequestHandlerProxy) DeleteAllPorts(args []*ic.Argument) (*empty.Empty, error) { |
| 756 | if len(args) < 3 { |
| 757 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 758 | err := errors.New("invalid-number-of-args") |
| 759 | return nil, err |
| 760 | } |
| 761 | deviceId := &voltha.ID{} |
| 762 | transactionID := &ic.StrType{} |
| 763 | for _, arg := range args { |
| 764 | switch arg.Key { |
| 765 | case "device_id": |
| 766 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
| 767 | log.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
| 768 | return nil, err |
| 769 | } |
| 770 | case kafka.TransactionKey: |
| 771 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 772 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 773 | return nil, err |
| 774 | } |
| 775 | } |
| 776 | } |
| 777 | log.Debugw("DeleteAllPorts", log.Fields{"deviceId": deviceId.Id, "transactionID": transactionID.Val}) |
| 778 | |
| 779 | // Try to grab the transaction as this core may be competing with another Core |
| 780 | if rhp.competeForTransaction() { |
| 781 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, deviceId.Id); err != nil { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 782 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 783 | return nil, err |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 784 | } else { |
| 785 | defer txn.Close() |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | if rhp.TestMode { // Execute only for test cases |
| 790 | return nil, nil |
| 791 | } |
| 792 | |
| 793 | go rhp.deviceMgr.deleteAllPorts(deviceId.Id) |
| 794 | |
| 795 | return new(empty.Empty), nil |
| 796 | } |
| 797 | |
| 798 | func (rhp *AdapterRequestHandlerProxy) ChildDevicesLost(args []*ic.Argument) (*empty.Empty, error) { |
| 799 | if len(args) < 2 { |
| 800 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 801 | err := errors.New("invalid-number-of-args") |
| 802 | return nil, err |
| 803 | } |
| 804 | parentDeviceId := &voltha.ID{} |
| 805 | transactionID := &ic.StrType{} |
| 806 | for _, arg := range args { |
| 807 | switch arg.Key { |
| 808 | case "parent_device_id": |
| 809 | if err := ptypes.UnmarshalAny(arg.Value, parentDeviceId); err != nil { |
| 810 | log.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
| 811 | return nil, err |
| 812 | } |
| 813 | case kafka.TransactionKey: |
| 814 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 815 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 816 | return nil, err |
| 817 | } |
| 818 | } |
| 819 | } |
| 820 | log.Debugw("ChildDevicesLost", log.Fields{"deviceId": parentDeviceId.Id, "transactionID": transactionID.Val}) |
| 821 | |
| 822 | // Try to grab the transaction as this core may be competing with another Core |
| 823 | if rhp.competeForTransaction() { |
| 824 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, parentDeviceId.Id); err != nil { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 825 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 826 | return nil, err |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 827 | } else { |
| 828 | defer txn.Close() |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | if rhp.TestMode { // Execute only for test cases |
| 833 | return nil, nil |
| 834 | } |
| 835 | |
| 836 | go rhp.deviceMgr.childDevicesLost(parentDeviceId.Id) |
| 837 | |
| 838 | return new(empty.Empty), nil |
| 839 | } |
| 840 | |
| 841 | func (rhp *AdapterRequestHandlerProxy) ChildDevicesDetected(args []*ic.Argument) (*empty.Empty, error) { |
| 842 | if len(args) < 2 { |
| 843 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 844 | err := errors.New("invalid-number-of-args") |
| 845 | return nil, err |
| 846 | } |
| 847 | parentDeviceId := &voltha.ID{} |
| 848 | transactionID := &ic.StrType{} |
| 849 | for _, arg := range args { |
| 850 | switch arg.Key { |
| 851 | case "parent_device_id": |
| 852 | if err := ptypes.UnmarshalAny(arg.Value, parentDeviceId); err != nil { |
| 853 | log.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
| 854 | return nil, err |
| 855 | } |
| 856 | case kafka.TransactionKey: |
| 857 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 858 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 859 | return nil, err |
| 860 | } |
| 861 | } |
| 862 | } |
| 863 | log.Debugw("ChildDevicesDetected", log.Fields{"deviceId": parentDeviceId.Id, "transactionID": transactionID.Val}) |
| 864 | |
| 865 | // Try to grab the transaction as this core may be competing with another Core |
| 866 | if rhp.competeForTransaction() { |
| 867 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, parentDeviceId.Id); err != nil { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 868 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 869 | return nil, err |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 870 | } else { |
| 871 | defer txn.Close() |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | if rhp.TestMode { // Execute only for test cases |
| 876 | return nil, nil |
| 877 | } |
| 878 | |
khenaidoo | 59ef7be | 2019-06-21 12:40:28 -0400 | [diff] [blame] | 879 | if err := rhp.deviceMgr.childDevicesDetected(parentDeviceId.Id); err != nil { |
| 880 | log.Errorw("child-devices-dection-failed", log.Fields{"parentId": parentDeviceId.Id, "error": err}) |
| 881 | return nil, err |
| 882 | } |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 883 | |
| 884 | return new(empty.Empty), nil |
| 885 | } |
| 886 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 887 | func (rhp *AdapterRequestHandlerProxy) PortCreated(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 888 | if len(args) < 3 { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 889 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 890 | err := errors.New("invalid-number-of-args") |
| 891 | return nil, err |
| 892 | } |
| 893 | deviceId := &voltha.ID{} |
| 894 | port := &voltha.Port{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 895 | transactionID := &ic.StrType{} |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 896 | for _, arg := range args { |
| 897 | switch arg.Key { |
| 898 | case "device_id": |
| 899 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
| 900 | log.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
| 901 | return nil, err |
| 902 | } |
| 903 | case "port": |
| 904 | if err := ptypes.UnmarshalAny(arg.Value, port); err != nil { |
| 905 | log.Warnw("cannot-unmarshal-port", log.Fields{"error": err}) |
| 906 | return nil, err |
| 907 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 908 | case kafka.TransactionKey: |
| 909 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 910 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 911 | return nil, err |
| 912 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 913 | } |
| 914 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 915 | log.Debugw("PortCreated", log.Fields{"deviceId": deviceId.Id, "port": port, "transactionID": transactionID.Val}) |
| 916 | |
| 917 | // Try to grab the transaction as this core may be competing with another Core |
| 918 | if rhp.competeForTransaction() { |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 919 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, deviceId.Id); err != nil { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 920 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 921 | return nil, err |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 922 | } else { |
| 923 | defer txn.Close() |
| 924 | } |
| 925 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 926 | |
| 927 | if rhp.TestMode { // Execute only for test cases |
| 928 | return nil, nil |
| 929 | } |
khenaidoo | 1ce37ad | 2019-03-24 22:07:24 -0400 | [diff] [blame] | 930 | go rhp.deviceMgr.addPort(deviceId.Id, port) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 931 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 932 | return new(empty.Empty), nil |
| 933 | } |
| 934 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 935 | func (rhp *AdapterRequestHandlerProxy) DevicePMConfigUpdate(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 936 | if len(args) < 2 { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 937 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 938 | err := errors.New("invalid-number-of-args") |
| 939 | return nil, err |
| 940 | } |
| 941 | pmConfigs := &voltha.PmConfigs{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 942 | transactionID := &ic.StrType{} |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 943 | for _, arg := range args { |
| 944 | switch arg.Key { |
| 945 | case "device_pm_config": |
| 946 | if err := ptypes.UnmarshalAny(arg.Value, pmConfigs); err != nil { |
| 947 | log.Warnw("cannot-unmarshal-pm-config", log.Fields{"error": err}) |
| 948 | return nil, err |
| 949 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 950 | case kafka.TransactionKey: |
| 951 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 952 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 953 | return nil, err |
| 954 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 955 | } |
| 956 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 957 | log.Debugw("DevicePMConfigUpdate", log.Fields{"deviceId": pmConfigs.Id, "configs": pmConfigs, |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 958 | "transactionID": transactionID.Val}) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 959 | |
| 960 | // Try to grab the transaction as this core may be competing with another Core |
| 961 | if rhp.competeForTransaction() { |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 962 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, pmConfigs.Id); err != nil { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 963 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 964 | return nil, err |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 965 | } else { |
| 966 | defer txn.Close() |
| 967 | } |
| 968 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 969 | |
| 970 | if rhp.TestMode { // Execute only for test cases |
| 971 | return nil, nil |
| 972 | } |
| 973 | |
khenaidoo | b312747 | 2019-07-24 21:04:55 -0400 | [diff] [blame] | 974 | go rhp.deviceMgr.initPmConfigs(pmConfigs.Id, pmConfigs) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 975 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 976 | return new(empty.Empty), nil |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 977 | } |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 978 | |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 979 | func (rhp *AdapterRequestHandlerProxy) PacketIn(args []*ic.Argument) (*empty.Empty, error) { |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 980 | if len(args) < 4 { |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 981 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 982 | err := errors.New("invalid-number-of-args") |
| 983 | return nil, err |
| 984 | } |
| 985 | deviceId := &voltha.ID{} |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 986 | portNo := &ic.IntType{} |
| 987 | packet := &ic.Packet{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 988 | transactionID := &ic.StrType{} |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 989 | for _, arg := range args { |
| 990 | switch arg.Key { |
| 991 | case "device_id": |
| 992 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
| 993 | log.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
| 994 | return nil, err |
| 995 | } |
| 996 | case "port": |
| 997 | if err := ptypes.UnmarshalAny(arg.Value, portNo); err != nil { |
| 998 | log.Warnw("cannot-unmarshal-port-no", log.Fields{"error": err}) |
| 999 | return nil, err |
| 1000 | } |
| 1001 | case "packet": |
| 1002 | if err := ptypes.UnmarshalAny(arg.Value, packet); err != nil { |
| 1003 | log.Warnw("cannot-unmarshal-packet", log.Fields{"error": err}) |
| 1004 | return nil, err |
| 1005 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 1006 | case kafka.TransactionKey: |
| 1007 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 1008 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 1009 | return nil, err |
| 1010 | } |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 1011 | } |
| 1012 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 1013 | log.Debugw("PacketIn", log.Fields{"deviceId": deviceId.Id, "port": portNo.Val, "packet": packet, |
| 1014 | "transactionID": transactionID.Val}) |
| 1015 | |
khenaidoo | 3d3b8c2 | 2019-05-22 18:10:39 -0400 | [diff] [blame] | 1016 | // Try to grab the transaction as this core may be competing with another Core |
| 1017 | // TODO: If this adds too much latencies then needs to remove transaction and let OFAgent filter out |
| 1018 | // duplicates. |
| 1019 | if rhp.competeForTransaction() { |
| 1020 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, deviceId.Id); err != nil { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 1021 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 1022 | return nil, err |
khenaidoo | 3d3b8c2 | 2019-05-22 18:10:39 -0400 | [diff] [blame] | 1023 | } else { |
| 1024 | defer txn.Close() |
| 1025 | } |
| 1026 | } |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 1027 | if rhp.TestMode { // Execute only for test cases |
| 1028 | return nil, nil |
| 1029 | } |
khenaidoo | 1ce37ad | 2019-03-24 22:07:24 -0400 | [diff] [blame] | 1030 | go rhp.deviceMgr.PacketIn(deviceId.Id, uint32(portNo.Val), transactionID.Val, packet.Payload) |
khenaidoo | 3d3b8c2 | 2019-05-22 18:10:39 -0400 | [diff] [blame] | 1031 | |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 1032 | return new(empty.Empty), nil |
| 1033 | } |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 1034 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 1035 | func (rhp *AdapterRequestHandlerProxy) UpdateImageDownload(args []*ic.Argument) (*empty.Empty, error) { |
| 1036 | if len(args) < 2 { |
| 1037 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 1038 | err := errors.New("invalid-number-of-args") |
| 1039 | return nil, err |
| 1040 | } |
| 1041 | deviceId := &voltha.ID{} |
| 1042 | img := &voltha.ImageDownload{} |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 1043 | transactionID := &ic.StrType{} |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 1044 | for _, arg := range args { |
| 1045 | switch arg.Key { |
| 1046 | case "device_id": |
| 1047 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
| 1048 | log.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
| 1049 | return nil, err |
| 1050 | } |
| 1051 | case "image_download": |
| 1052 | if err := ptypes.UnmarshalAny(arg.Value, img); err != nil { |
| 1053 | log.Warnw("cannot-unmarshal-imgaeDownload", log.Fields{"error": err}) |
| 1054 | return nil, err |
| 1055 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 1056 | case kafka.TransactionKey: |
| 1057 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 1058 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 1059 | return nil, err |
| 1060 | } |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 1061 | } |
| 1062 | } |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 1063 | log.Debugw("UpdateImageDownload", log.Fields{"deviceId": deviceId.Id, "image-download": img, |
| 1064 | "transactionID": transactionID.Val}) |
| 1065 | |
| 1066 | // Try to grab the transaction as this core may be competing with another Core |
| 1067 | if rhp.competeForTransaction() { |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 1068 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, deviceId.Id); err != nil { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 1069 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 1070 | return nil, err |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 1071 | } else { |
| 1072 | defer txn.Close() |
| 1073 | } |
| 1074 | } |
| 1075 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 1076 | if rhp.TestMode { // Execute only for test cases |
| 1077 | return nil, nil |
| 1078 | } |
khenaidoo | 1ce37ad | 2019-03-24 22:07:24 -0400 | [diff] [blame] | 1079 | go rhp.deviceMgr.updateImageDownload(deviceId.Id, img) |
| 1080 | //if err := rhp.deviceMgr.updateImageDownload(deviceId.Id, img); err != nil { |
| 1081 | // return nil, err |
| 1082 | //} |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 1083 | return new(empty.Empty), nil |
| 1084 | } |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 1085 | |
| 1086 | func (rhp *AdapterRequestHandlerProxy) ReconcileChildDevices(args []*ic.Argument) (*empty.Empty, error) { |
| 1087 | if len(args) < 2 { |
| 1088 | log.Warn("invalid-number-of-args", log.Fields{"args": args}) |
| 1089 | err := errors.New("invalid-number-of-args") |
| 1090 | return nil, err |
| 1091 | } |
| 1092 | parentDeviceId := &voltha.ID{} |
| 1093 | transactionID := &ic.StrType{} |
| 1094 | for _, arg := range args { |
| 1095 | switch arg.Key { |
| 1096 | case "parent_device_id": |
| 1097 | if err := ptypes.UnmarshalAny(arg.Value, parentDeviceId); err != nil { |
| 1098 | log.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
| 1099 | return nil, err |
| 1100 | } |
| 1101 | case kafka.TransactionKey: |
| 1102 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 1103 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 1104 | return nil, err |
| 1105 | } |
| 1106 | } |
| 1107 | } |
| 1108 | log.Debugw("ReconcileChildDevices", log.Fields{"deviceId": parentDeviceId.Id, "transactionID": transactionID.Val}) |
| 1109 | |
| 1110 | // Try to grab the transaction as this core may be competing with another Core |
| 1111 | if rhp.competeForTransaction() { |
| 1112 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, parentDeviceId.Id); err != nil { |
khenaidoo | 09771ef | 2019-10-11 14:25:02 -0400 | [diff] [blame] | 1113 | log.Debugw("Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 1114 | return nil, err |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 1115 | } else { |
| 1116 | defer txn.Close() |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | if rhp.TestMode { // Execute only for test cases |
| 1121 | return nil, nil |
| 1122 | } |
| 1123 | |
| 1124 | // Run it in its own routine |
| 1125 | go rhp.deviceMgr.reconcileChildDevices(parentDeviceId.Id) |
| 1126 | |
| 1127 | return new(empty.Empty), nil |
| 1128 | } |
Mahir Gunyel | fdee921 | 2019-10-16 16:52:21 -0700 | [diff] [blame] | 1129 | |
| 1130 | func (rhp *AdapterRequestHandlerProxy) DeviceReasonUpdate(args []*ic.Argument) (*empty.Empty, error) { |
| 1131 | if len(args) < 2 { |
| 1132 | log.Warn("DeviceReasonUpdate: invalid-number-of-args", log.Fields{"args": args}) |
| 1133 | err := errors.New("DeviceReasonUpdate: invalid-number-of-args") |
| 1134 | return nil, err |
| 1135 | } |
| 1136 | deviceId := &voltha.ID{} |
| 1137 | reason := &ic.StrType{} |
| 1138 | transactionID := &ic.StrType{} |
| 1139 | for _, arg := range args { |
| 1140 | switch arg.Key { |
| 1141 | case "device_id": |
| 1142 | if err := ptypes.UnmarshalAny(arg.Value, deviceId); err != nil { |
| 1143 | log.Warnw("cannot-unmarshal-device-id", log.Fields{"error": err}) |
| 1144 | return nil, err |
| 1145 | } |
| 1146 | case "device_reason": |
| 1147 | if err := ptypes.UnmarshalAny(arg.Value, reason); err != nil { |
| 1148 | log.Warnw("cannot-unmarshal-reason", log.Fields{"error": err}) |
| 1149 | return nil, err |
| 1150 | } |
| 1151 | case kafka.TransactionKey: |
| 1152 | if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil { |
| 1153 | log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err}) |
| 1154 | return nil, err |
| 1155 | } |
| 1156 | } |
| 1157 | } |
| 1158 | log.Debugw("DeviceReasonUpdate", log.Fields{"deviceId": deviceId.Id, "reason": reason.Val, |
| 1159 | "transactionID": transactionID.Val}) |
| 1160 | |
| 1161 | // Try to grab the transaction as this core may be competing with another Core |
| 1162 | if rhp.competeForTransaction() { |
| 1163 | if txn, err := rhp.takeRequestOwnership(transactionID.Val, deviceId.Id); err != nil { |
| 1164 | log.Debugw("DeviceReasonUpdate: Core did not process request", log.Fields{"transactionID": transactionID, "error": err}) |
| 1165 | return nil, err |
| 1166 | } else { |
| 1167 | defer txn.Close() |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | if rhp.TestMode { // Execute only for test cases |
| 1172 | return nil, nil |
| 1173 | } |
| 1174 | |
| 1175 | // Run it in its own routine |
| 1176 | go rhp.deviceMgr.updateDeviceReason(deviceId.Id, reason.Val) |
| 1177 | |
| 1178 | return new(empty.Empty), nil |
| 1179 | } |