khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -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 | */ |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 16 | package core |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "errors" |
Richard Jankowski | dbab94a | 2018-12-06 16:20:25 -0500 | [diff] [blame] | 21 | "github.com/golang-collections/go-datastructures/queue" |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 22 | "github.com/golang/protobuf/ptypes/empty" |
| 23 | da "github.com/opencord/voltha-go/common/core/northbound/grpc" |
| 24 | "github.com/opencord/voltha-go/common/log" |
khenaidoo | 1ce37ad | 2019-03-24 22:07:24 -0400 | [diff] [blame] | 25 | "github.com/opencord/voltha-go/rw_core/utils" |
William Kurkian | daa6bb2 | 2019-03-07 12:26:28 -0500 | [diff] [blame] | 26 | "github.com/opencord/voltha-protos/go/common" |
William Kurkian | daa6bb2 | 2019-03-07 12:26:28 -0500 | [diff] [blame] | 27 | "github.com/opencord/voltha-protos/go/omci" |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 28 | "github.com/opencord/voltha-protos/go/openflow_13" |
William Kurkian | daa6bb2 | 2019-03-07 12:26:28 -0500 | [diff] [blame] | 29 | "github.com/opencord/voltha-protos/go/voltha" |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 30 | "google.golang.org/grpc/codes" |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 31 | "google.golang.org/grpc/metadata" |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 32 | "google.golang.org/grpc/status" |
Stephane Barbarie | 6e1bd50 | 2018-11-05 22:44:45 -0500 | [diff] [blame] | 33 | "io" |
| 34 | "time" |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 35 | ) |
| 36 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 37 | const ( |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 38 | IMAGE_DOWNLOAD = iota |
| 39 | CANCEL_IMAGE_DOWNLOAD = iota |
| 40 | ACTIVATE_IMAGE = iota |
| 41 | REVERT_IMAGE = iota |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 42 | ) |
| 43 | |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 44 | type APIHandler struct { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 45 | deviceMgr *DeviceManager |
| 46 | logicalDeviceMgr *LogicalDeviceManager |
| 47 | adapterMgr *AdapterManager |
| 48 | packetInQueue *queue.Queue |
| 49 | changeEventQueue *queue.Queue |
| 50 | coreInCompetingMode bool |
khenaidoo | b608032 | 2019-01-29 21:47:38 -0500 | [diff] [blame] | 51 | longRunningRequestTimeout int64 |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 52 | defaultRequestTimeout int64 |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 53 | da.DefaultAPIHandler |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 54 | core *Core |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 55 | } |
| 56 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 57 | func NewAPIHandler(core *Core) *APIHandler { |
Stephane Barbarie | 6e1bd50 | 2018-11-05 22:44:45 -0500 | [diff] [blame] | 58 | handler := &APIHandler{ |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 59 | deviceMgr: core.deviceMgr, |
| 60 | logicalDeviceMgr: core.logicalDeviceMgr, |
| 61 | adapterMgr: core.adapterMgr, |
| 62 | coreInCompetingMode: core.config.InCompetingMode, |
| 63 | longRunningRequestTimeout: core.config.LongRunningRequestTimeout, |
| 64 | defaultRequestTimeout: core.config.DefaultRequestTimeout, |
Richard Jankowski | dbab94a | 2018-12-06 16:20:25 -0500 | [diff] [blame] | 65 | // TODO: Figure out what the 'hint' parameter to queue.New does |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 66 | packetInQueue: queue.New(10), |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 67 | changeEventQueue: queue.New(10), |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 68 | core: core, |
Stephane Barbarie | 6e1bd50 | 2018-11-05 22:44:45 -0500 | [diff] [blame] | 69 | } |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 70 | return handler |
| 71 | } |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 72 | |
| 73 | // isTestMode is a helper function to determine a function is invoked for testing only |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 74 | func isTestMode(ctx context.Context) bool { |
| 75 | md, _ := metadata.FromIncomingContext(ctx) |
| 76 | _, exist := md[common.TestModeKeys_api_test.String()] |
| 77 | return exist |
| 78 | } |
| 79 | |
Richard Jankowski | d42826e | 2018-11-02 16:06:37 -0400 | [diff] [blame] | 80 | // This function attempts to extract the serial number from the request metadata |
| 81 | // and create a KV transaction for that serial number for the current core. |
| 82 | func (handler *APIHandler) createKvTransaction(ctx context.Context) (*KVTransaction, error) { |
| 83 | var ( |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 84 | err error |
| 85 | ok bool |
| 86 | md metadata.MD |
Richard Jankowski | d42826e | 2018-11-02 16:06:37 -0400 | [diff] [blame] | 87 | serNum []string |
| 88 | ) |
| 89 | if md, ok = metadata.FromIncomingContext(ctx); !ok { |
| 90 | err = errors.New("metadata-not-found") |
| 91 | } else if serNum, ok = md["voltha_serial_number"]; !ok { |
| 92 | err = errors.New("serial-number-not-found") |
| 93 | } |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 94 | if !ok || serNum == nil { |
Richard Jankowski | d42826e | 2018-11-02 16:06:37 -0400 | [diff] [blame] | 95 | log.Error(err) |
| 96 | return nil, err |
| 97 | } |
| 98 | // Create KV transaction |
| 99 | txn := NewKVTransaction(serNum[0]) |
| 100 | return txn, nil |
| 101 | } |
| 102 | |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 103 | // isOFControllerRequest is a helper function to determine if a request was initiated |
| 104 | // from the OpenFlow controller (or its proxy, e.g. OFAgent) |
Richard Jankowski | 46464e9 | 2019-03-05 11:53:55 -0500 | [diff] [blame] | 105 | func (handler *APIHandler) isOFControllerRequest(ctx context.Context) bool { |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 106 | if md, ok := metadata.FromIncomingContext(ctx); ok { |
| 107 | // Metadata in context |
Richard Jankowski | 46464e9 | 2019-03-05 11:53:55 -0500 | [diff] [blame] | 108 | if _, ok = md[handler.core.config.CoreBindingKey]; ok { |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 109 | // OFAgent field in metadata |
| 110 | return true |
| 111 | } |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 112 | } |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 113 | return false |
| 114 | } |
| 115 | |
| 116 | // competeForTransaction is a helper function to determine whether every request needs to compete with another |
| 117 | // Core to execute the request |
| 118 | func (handler *APIHandler) competeForTransaction() bool { |
| 119 | return handler.coreInCompetingMode |
| 120 | } |
| 121 | |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 122 | // This function handles the creation of new devices |
| 123 | func (handler *APIHandler) acquireRequest(ctx context.Context, id interface{}, maxTimeout ...int64) (*KVTransaction, error) { |
khenaidoo | b608032 | 2019-01-29 21:47:38 -0500 | [diff] [blame] | 124 | timeout := handler.defaultRequestTimeout |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 125 | if len(maxTimeout) > 0 { |
| 126 | timeout = maxTimeout[0] |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 127 | } |
khenaidoo | b608032 | 2019-01-29 21:47:38 -0500 | [diff] [blame] | 128 | log.Debugw("transaction-timeout", log.Fields{"timeout": timeout}) |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 129 | txn, err := handler.createKvTransaction(ctx) |
| 130 | if txn == nil { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 131 | return nil, err |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 132 | } else if txn.Acquired(timeout) { |
| 133 | return txn, nil |
| 134 | } else { |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 135 | if id != nil { |
| 136 | // The id can either be a device Id or a logical device id. |
khenaidoo | 1ce37ad | 2019-03-24 22:07:24 -0400 | [diff] [blame] | 137 | if dId, ok := id.(*utils.DeviceID); ok { |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 138 | // Since this core has not processed this request, let's load the device, along with its extended |
| 139 | // family (parents and children) in memory. This will keep this core in-sync with its paired core as |
| 140 | // much as possible. The watch feature in the core model will ensure that the contents of those objects in |
| 141 | // memory are in sync. |
| 142 | time.Sleep(2 * time.Second) |
khenaidoo | 1ce37ad | 2019-03-24 22:07:24 -0400 | [diff] [blame] | 143 | go handler.deviceMgr.load(dId.Id) |
| 144 | } else if ldId, ok := id.(*utils.LogicalDeviceID); ok { |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 145 | // This will load the logical device along with its children and grandchildren |
khenaidoo | 1ce37ad | 2019-03-24 22:07:24 -0400 | [diff] [blame] | 146 | go handler.logicalDeviceMgr.load(ldId.Id) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 147 | } |
| 148 | } |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 149 | return nil, errors.New("failed-to-seize-request") |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 150 | } |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 151 | } |
| 152 | |
khenaidoo | 6d62c00 | 2019-05-15 21:57:03 -0400 | [diff] [blame] | 153 | // takeRequestOwnership creates a transaction in the dB for this request and handles the logic of transaction |
| 154 | // acquisition. If the device is owned by this Core (in a core-pair) then acquire the transaction with a |
| 155 | // timeout value (in the event of a timeout the other Core in the core-pair will proceed with the transaction). If the |
| 156 | // device is not owned then this Core will just monitor the transaction for potential timeouts. |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 157 | func (handler *APIHandler) takeRequestOwnership(ctx context.Context, id interface{}, maxTimeout ...int64) (*KVTransaction, error) { |
khenaidoo | 6d62c00 | 2019-05-15 21:57:03 -0400 | [diff] [blame] | 158 | t := time.Now() |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 159 | timeout := handler.defaultRequestTimeout |
| 160 | if len(maxTimeout) > 0 { |
| 161 | timeout = maxTimeout[0] |
| 162 | } |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 163 | txn, err := handler.createKvTransaction(ctx) |
| 164 | if txn == nil { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 165 | return nil, err |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | owned := false |
| 169 | if id != nil { |
khenaidoo | 1ce37ad | 2019-03-24 22:07:24 -0400 | [diff] [blame] | 170 | owned = handler.core.deviceOwnership.OwnedByMe(id) |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 171 | } |
| 172 | if owned { |
| 173 | if txn.Acquired(timeout) { |
khenaidoo | 6d62c00 | 2019-05-15 21:57:03 -0400 | [diff] [blame] | 174 | log.Debugw("acquired-transaction", log.Fields{"transaction-timeout": timeout}) |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 175 | return txn, nil |
| 176 | } else { |
| 177 | return nil, errors.New("failed-to-seize-request") |
| 178 | } |
| 179 | } else { |
| 180 | if txn.Monitor(timeout) { |
khenaidoo | 6d62c00 | 2019-05-15 21:57:03 -0400 | [diff] [blame] | 181 | log.Debugw("acquired-transaction-after-timeout", log.Fields{"timeout": timeout, "waited-time": time.Since(t)}) |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 182 | return txn, nil |
| 183 | } else { |
khenaidoo | 6d62c00 | 2019-05-15 21:57:03 -0400 | [diff] [blame] | 184 | log.Debugw("transaction-completed-by-other", log.Fields{"timeout": timeout, "waited-time": time.Since(t)}) |
| 185 | return nil, errors.New(string(COMPLETED_BY_OTHER)) |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 190 | // waitForNilResponseOnSuccess is a helper function to wait for a response on channel ch where an nil |
| 191 | // response is expected in a successful scenario |
| 192 | func waitForNilResponseOnSuccess(ctx context.Context, ch chan interface{}) (*empty.Empty, error) { |
| 193 | select { |
| 194 | case res := <-ch: |
| 195 | if res == nil { |
| 196 | return new(empty.Empty), nil |
| 197 | } else if err, ok := res.(error); ok { |
| 198 | return new(empty.Empty), err |
| 199 | } else { |
| 200 | log.Warnw("unexpected-return-type", log.Fields{"result": res}) |
| 201 | err = status.Errorf(codes.Internal, "%s", res) |
| 202 | return new(empty.Empty), err |
| 203 | } |
| 204 | case <-ctx.Done(): |
| 205 | log.Debug("client-timeout") |
| 206 | return nil, ctx.Err() |
| 207 | } |
| 208 | } |
| 209 | |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 210 | func (handler *APIHandler) UpdateLogLevel(ctx context.Context, logging *voltha.Logging) (*empty.Empty, error) { |
khenaidoo | 6f2fbe3 | 2019-01-18 16:16:50 -0500 | [diff] [blame] | 211 | log.Debugw("UpdateLogLevel-request", log.Fields{"package": logging.PackageName, "intval": int(logging.Level)}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 212 | out := new(empty.Empty) |
khenaidoo | 6f2fbe3 | 2019-01-18 16:16:50 -0500 | [diff] [blame] | 213 | if logging.PackageName == "" { |
| 214 | log.SetAllLogLevel(int(logging.Level)) |
| 215 | } else { |
| 216 | log.SetPackageLogLevel(logging.PackageName, int(logging.Level)) |
| 217 | } |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 218 | return out, nil |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 219 | } |
| 220 | |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 221 | func (handler *APIHandler) UpdateMembership(ctx context.Context, membership *voltha.Membership) (*empty.Empty, error) { |
| 222 | log.Debugw("UpdateMembership-request", log.Fields{"membership": membership}) |
| 223 | out := new(empty.Empty) |
khenaidoo | 6417b6c | 2019-03-01 18:18:01 -0500 | [diff] [blame] | 224 | if err := handler.core.updateCoreMembership(ctx, membership); err != nil { |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 225 | return out, err |
| 226 | } |
| 227 | return out, nil |
| 228 | } |
| 229 | |
khenaidoo | 6417b6c | 2019-03-01 18:18:01 -0500 | [diff] [blame] | 230 | func (handler *APIHandler) GetMembership(ctx context.Context, empty *empty.Empty) (*voltha.Membership, error) { |
| 231 | log.Debug("GetMembership-request") |
| 232 | if membership := handler.core.getCoreMembership(ctx); membership != nil { |
| 233 | return membership, nil |
| 234 | } |
| 235 | return &voltha.Membership{}, nil |
| 236 | } |
| 237 | |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 238 | func (handler *APIHandler) EnableLogicalDevicePort(ctx context.Context, id *voltha.LogicalPortId) (*empty.Empty, error) { |
| 239 | log.Debugw("EnableLogicalDevicePort-request", log.Fields{"id": id, "test": common.TestModeKeys_api_test.String()}) |
| 240 | if isTestMode(ctx) { |
| 241 | out := new(empty.Empty) |
| 242 | return out, nil |
| 243 | } |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 244 | |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 245 | if handler.competeForTransaction() { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 246 | if txn, err := handler.takeRequestOwnership(ctx, &utils.LogicalDeviceID{Id: id.Id}); err != nil { |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 247 | return new(empty.Empty), err |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 248 | } else { |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 249 | defer txn.Close() |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 250 | } |
| 251 | } |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 252 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 253 | ch := make(chan interface{}) |
| 254 | defer close(ch) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 255 | go handler.logicalDeviceMgr.enableLogicalPort(ctx, id, ch) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 256 | return waitForNilResponseOnSuccess(ctx, ch) |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | func (handler *APIHandler) DisableLogicalDevicePort(ctx context.Context, id *voltha.LogicalPortId) (*empty.Empty, error) { |
| 260 | log.Debugw("DisableLogicalDevicePort-request", log.Fields{"id": id, "test": common.TestModeKeys_api_test.String()}) |
| 261 | if isTestMode(ctx) { |
| 262 | out := new(empty.Empty) |
| 263 | return out, nil |
| 264 | } |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 265 | |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 266 | if handler.competeForTransaction() { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 267 | if txn, err := handler.takeRequestOwnership(ctx, &utils.LogicalDeviceID{Id: id.Id}); err != nil { |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 268 | return new(empty.Empty), err |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 269 | } else { |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 270 | defer txn.Close() |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 271 | } |
| 272 | } |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 273 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 274 | ch := make(chan interface{}) |
| 275 | defer close(ch) |
| 276 | go handler.logicalDeviceMgr.disableLogicalPort(ctx, id, ch) |
| 277 | return waitForNilResponseOnSuccess(ctx, ch) |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | func (handler *APIHandler) UpdateLogicalDeviceFlowTable(ctx context.Context, flow *openflow_13.FlowTableUpdate) (*empty.Empty, error) { |
| 281 | log.Debugw("UpdateLogicalDeviceFlowTable-request", log.Fields{"flow": flow, "test": common.TestModeKeys_api_test.String()}) |
| 282 | if isTestMode(ctx) { |
| 283 | out := new(empty.Empty) |
| 284 | return out, nil |
| 285 | } |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 286 | |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 287 | if handler.competeForTransaction() { |
Richard Jankowski | 46464e9 | 2019-03-05 11:53:55 -0500 | [diff] [blame] | 288 | if !handler.isOFControllerRequest(ctx) { // No need to acquire the transaction as request is sent to one core only |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 289 | if txn, err := handler.takeRequestOwnership(ctx, &utils.LogicalDeviceID{Id: flow.Id}); err != nil { |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 290 | return new(empty.Empty), err |
| 291 | } else { |
| 292 | defer txn.Close() |
| 293 | } |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 294 | } |
| 295 | } |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 296 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 297 | ch := make(chan interface{}) |
| 298 | defer close(ch) |
| 299 | go handler.logicalDeviceMgr.updateFlowTable(ctx, flow.Id, flow.FlowMod, ch) |
| 300 | return waitForNilResponseOnSuccess(ctx, ch) |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | func (handler *APIHandler) UpdateLogicalDeviceFlowGroupTable(ctx context.Context, flow *openflow_13.FlowGroupTableUpdate) (*empty.Empty, error) { |
| 304 | log.Debugw("UpdateLogicalDeviceFlowGroupTable-request", log.Fields{"flow": flow, "test": common.TestModeKeys_api_test.String()}) |
| 305 | if isTestMode(ctx) { |
| 306 | out := new(empty.Empty) |
| 307 | return out, nil |
| 308 | } |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 309 | |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 310 | if handler.competeForTransaction() { |
Richard Jankowski | 46464e9 | 2019-03-05 11:53:55 -0500 | [diff] [blame] | 311 | if !handler.isOFControllerRequest(ctx) { // No need to acquire the transaction as request is sent to one core only |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 312 | if txn, err := handler.takeRequestOwnership(ctx, &utils.LogicalDeviceID{Id: flow.Id}); err != nil { |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 313 | return new(empty.Empty), err |
| 314 | } else { |
| 315 | defer txn.Close() |
| 316 | } |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 317 | } |
| 318 | } |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 319 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 320 | ch := make(chan interface{}) |
| 321 | defer close(ch) |
| 322 | go handler.logicalDeviceMgr.updateGroupTable(ctx, flow.Id, flow.GroupMod, ch) |
| 323 | return waitForNilResponseOnSuccess(ctx, ch) |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 324 | } |
| 325 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 326 | // GetDevice must be implemented in the read-only containers - should it also be implemented here? |
| 327 | func (handler *APIHandler) GetDevice(ctx context.Context, id *voltha.ID) (*voltha.Device, error) { |
| 328 | log.Debugw("GetDevice-request", log.Fields{"id": id}) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 329 | return handler.deviceMgr.GetDevice(id.Id) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | // GetDevice must be implemented in the read-only containers - should it also be implemented here? |
| 333 | func (handler *APIHandler) ListDevices(ctx context.Context, empty *empty.Empty) (*voltha.Devices, error) { |
| 334 | log.Debug("ListDevices") |
| 335 | return handler.deviceMgr.ListDevices() |
| 336 | } |
| 337 | |
khenaidoo | 7ccedd5 | 2018-12-14 16:48:54 -0500 | [diff] [blame] | 338 | // ListDeviceIds returns the list of device ids managed by a voltha core |
| 339 | func (handler *APIHandler) ListDeviceIds(ctx context.Context, empty *empty.Empty) (*voltha.IDs, error) { |
| 340 | log.Debug("ListDeviceIDs") |
| 341 | if isTestMode(ctx) { |
| 342 | out := &voltha.IDs{Items: make([]*voltha.ID, 0)} |
| 343 | return out, nil |
| 344 | } |
| 345 | return handler.deviceMgr.ListDeviceIds() |
| 346 | } |
| 347 | |
| 348 | //ReconcileDevices is a request to a voltha core to managed a list of devices based on their IDs |
| 349 | func (handler *APIHandler) ReconcileDevices(ctx context.Context, ids *voltha.IDs) (*empty.Empty, error) { |
| 350 | log.Debug("ReconcileDevices") |
| 351 | if isTestMode(ctx) { |
| 352 | out := new(empty.Empty) |
| 353 | return out, nil |
| 354 | } |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 355 | |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 356 | // No need to grab a transaction as this request is core specific |
| 357 | |
khenaidoo | 7ccedd5 | 2018-12-14 16:48:54 -0500 | [diff] [blame] | 358 | ch := make(chan interface{}) |
| 359 | defer close(ch) |
| 360 | go handler.deviceMgr.ReconcileDevices(ctx, ids, ch) |
| 361 | return waitForNilResponseOnSuccess(ctx, ch) |
| 362 | } |
| 363 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 364 | // GetLogicalDevice must be implemented in the read-only containers - should it also be implemented here? |
| 365 | func (handler *APIHandler) GetLogicalDevice(ctx context.Context, id *voltha.ID) (*voltha.LogicalDevice, error) { |
| 366 | log.Debugw("GetLogicalDevice-request", log.Fields{"id": id}) |
| 367 | return handler.logicalDeviceMgr.getLogicalDevice(id.Id) |
| 368 | } |
| 369 | |
| 370 | // ListLogicalDevices must be implemented in the read-only containers - should it also be implemented here? |
| 371 | func (handler *APIHandler) ListLogicalDevices(ctx context.Context, empty *empty.Empty) (*voltha.LogicalDevices, error) { |
| 372 | log.Debug("ListLogicalDevices") |
| 373 | return handler.logicalDeviceMgr.listLogicalDevices() |
| 374 | } |
| 375 | |
khenaidoo | 21d5115 | 2019-02-01 13:48:37 -0500 | [diff] [blame] | 376 | // ListAdapters returns the contents of all adapters known to the system |
| 377 | func (handler *APIHandler) ListAdapters(ctx context.Context, empty *empty.Empty) (*voltha.Adapters, error) { |
| 378 | log.Debug("ListDevices") |
| 379 | return handler.adapterMgr.listAdapters(ctx) |
| 380 | } |
| 381 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 382 | // ListLogicalDevicePorts must be implemented in the read-only containers - should it also be implemented here? |
| 383 | func (handler *APIHandler) ListLogicalDevicePorts(ctx context.Context, id *voltha.ID) (*voltha.LogicalPorts, error) { |
| 384 | log.Debugw("ListLogicalDevicePorts", log.Fields{"logicaldeviceid": id}) |
| 385 | return handler.logicalDeviceMgr.ListLogicalDevicePorts(ctx, id.Id) |
| 386 | } |
| 387 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 388 | // CreateDevice creates a new parent device in the data model |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 389 | func (handler *APIHandler) CreateDevice(ctx context.Context, device *voltha.Device) (*voltha.Device, error) { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 390 | log.Debugw("createdevice", log.Fields{"device": *device}) |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 391 | if isTestMode(ctx) { |
| 392 | return &voltha.Device{Id: device.Id}, nil |
| 393 | } |
Richard Jankowski | d42826e | 2018-11-02 16:06:37 -0400 | [diff] [blame] | 394 | |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 395 | if handler.competeForTransaction() { |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 396 | if txn, err := handler.acquireRequest(ctx, nil); err != nil { |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 397 | return &voltha.Device{}, err |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 398 | } else { |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 399 | defer txn.Close() |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 400 | } |
| 401 | } |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 402 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 403 | ch := make(chan interface{}) |
| 404 | defer close(ch) |
| 405 | go handler.deviceMgr.createDevice(ctx, device, ch) |
| 406 | select { |
| 407 | case res := <-ch: |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 408 | if res != nil { |
| 409 | if err, ok := res.(error); ok { |
| 410 | return &voltha.Device{}, err |
| 411 | } |
| 412 | if d, ok := res.(*voltha.Device); ok { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 413 | handler.core.deviceOwnership.OwnedByMe(&utils.DeviceID{Id: d.Id}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 414 | return d, nil |
| 415 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 416 | } |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 417 | log.Warnw("create-device-unexpected-return-type", log.Fields{"result": res}) |
| 418 | err := status.Errorf(codes.Internal, "%s", res) |
| 419 | return &voltha.Device{}, err |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 420 | case <-ctx.Done(): |
| 421 | log.Debug("createdevice-client-timeout") |
| 422 | return nil, ctx.Err() |
| 423 | } |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 424 | } |
| 425 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 426 | // EnableDevice activates a device by invoking the adopt_device API on the appropriate adapter |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 427 | func (handler *APIHandler) EnableDevice(ctx context.Context, id *voltha.ID) (*empty.Empty, error) { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 428 | log.Debugw("enabledevice", log.Fields{"id": id}) |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 429 | if isTestMode(ctx) { |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 430 | return new(empty.Empty), nil |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 431 | } |
Richard Jankowski | d42826e | 2018-11-02 16:06:37 -0400 | [diff] [blame] | 432 | |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 433 | if handler.competeForTransaction() { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 434 | if txn, err := handler.takeRequestOwnership(ctx, &utils.DeviceID{Id: id.Id}, handler.longRunningRequestTimeout); err != nil { |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 435 | return new(empty.Empty), err |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 436 | } else { |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 437 | defer txn.Close() |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 438 | } |
| 439 | } |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 440 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 441 | ch := make(chan interface{}) |
| 442 | defer close(ch) |
| 443 | go handler.deviceMgr.enableDevice(ctx, id, ch) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 444 | return waitForNilResponseOnSuccess(ctx, ch) |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 445 | } |
| 446 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 447 | // DisableDevice disables a device along with any child device it may have |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 448 | func (handler *APIHandler) DisableDevice(ctx context.Context, id *voltha.ID) (*empty.Empty, error) { |
| 449 | log.Debugw("disabledevice-request", log.Fields{"id": id}) |
| 450 | if isTestMode(ctx) { |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 451 | return new(empty.Empty), nil |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 452 | } |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 453 | |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 454 | if handler.competeForTransaction() { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 455 | if txn, err := handler.takeRequestOwnership(ctx, &utils.DeviceID{Id: id.Id}); err != nil { |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 456 | return new(empty.Empty), err |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 457 | } else { |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 458 | defer txn.Close() |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 459 | } |
| 460 | } |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 461 | |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 462 | ch := make(chan interface{}) |
| 463 | defer close(ch) |
| 464 | go handler.deviceMgr.disableDevice(ctx, id, ch) |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 465 | return waitForNilResponseOnSuccess(ctx, ch) |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 466 | } |
| 467 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 468 | //RebootDevice invoked the reboot API to the corresponding adapter |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 469 | func (handler *APIHandler) RebootDevice(ctx context.Context, id *voltha.ID) (*empty.Empty, error) { |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 470 | log.Debugw("rebootDevice-request", log.Fields{"id": id}) |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 471 | if isTestMode(ctx) { |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 472 | return new(empty.Empty), nil |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 473 | } |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 474 | |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 475 | if handler.competeForTransaction() { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 476 | if txn, err := handler.takeRequestOwnership(ctx, &utils.DeviceID{Id: id.Id}); err != nil { |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 477 | return new(empty.Empty), err |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 478 | } else { |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 479 | defer txn.Close() |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 480 | } |
| 481 | } |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 482 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 483 | ch := make(chan interface{}) |
| 484 | defer close(ch) |
| 485 | go handler.deviceMgr.rebootDevice(ctx, id, ch) |
| 486 | return waitForNilResponseOnSuccess(ctx, ch) |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 487 | } |
| 488 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 489 | // DeleteDevice removes a device from the data model |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 490 | func (handler *APIHandler) DeleteDevice(ctx context.Context, id *voltha.ID) (*empty.Empty, error) { |
| 491 | log.Debugw("deletedevice-request", log.Fields{"id": id}) |
| 492 | if isTestMode(ctx) { |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 493 | return new(empty.Empty), nil |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 494 | } |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 495 | |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 496 | if handler.competeForTransaction() { |
khenaidoo | 6d62c00 | 2019-05-15 21:57:03 -0400 | [diff] [blame] | 497 | if txn, err := handler.takeRequestOwnership(ctx, &utils.DeviceID{Id: id.Id}); err != nil { |
| 498 | // Remove the device in memory |
| 499 | if err.Error() == (errors.New(string(COMPLETED_BY_OTHER)).Error()) { |
| 500 | handler.deviceMgr.stopManagingDevice(id.Id) |
| 501 | } |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 502 | return new(empty.Empty), err |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 503 | } else { |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 504 | defer txn.Close() |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 505 | } |
| 506 | } |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 507 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 508 | ch := make(chan interface{}) |
| 509 | defer close(ch) |
| 510 | go handler.deviceMgr.deleteDevice(ctx, id, ch) |
| 511 | return waitForNilResponseOnSuccess(ctx, ch) |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 512 | } |
| 513 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 514 | // processImageRequest is a helper method to execute an image download request |
| 515 | func (handler *APIHandler) processImageRequest(ctx context.Context, img *voltha.ImageDownload, requestType int) (*common.OperationResp, error) { |
| 516 | log.Debugw("processImageDownload", log.Fields{"img": *img, "requestType": requestType}) |
| 517 | if isTestMode(ctx) { |
| 518 | resp := &common.OperationResp{Code: common.OperationResp_OPERATION_SUCCESS} |
| 519 | return resp, nil |
| 520 | } |
| 521 | |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 522 | if handler.competeForTransaction() { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 523 | if txn, err := handler.takeRequestOwnership(ctx, &utils.DeviceID{Id: img.Id}); err != nil { |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 524 | return &common.OperationResp{}, err |
| 525 | } else { |
| 526 | defer txn.Close() |
| 527 | } |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 528 | } |
| 529 | |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 530 | failedresponse := &common.OperationResp{Code: voltha.OperationResp_OPERATION_FAILURE} |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 531 | |
| 532 | ch := make(chan interface{}) |
| 533 | defer close(ch) |
| 534 | switch requestType { |
| 535 | case IMAGE_DOWNLOAD: |
| 536 | go handler.deviceMgr.downloadImage(ctx, img, ch) |
| 537 | case CANCEL_IMAGE_DOWNLOAD: |
| 538 | go handler.deviceMgr.cancelImageDownload(ctx, img, ch) |
| 539 | case ACTIVATE_IMAGE: |
| 540 | go handler.deviceMgr.activateImage(ctx, img, ch) |
| 541 | case REVERT_IMAGE: |
| 542 | go handler.deviceMgr.revertImage(ctx, img, ch) |
| 543 | default: |
| 544 | log.Warn("invalid-request-type", log.Fields{"requestType": requestType}) |
| 545 | return failedresponse, status.Errorf(codes.InvalidArgument, "%d", requestType) |
| 546 | } |
| 547 | select { |
| 548 | case res := <-ch: |
| 549 | if res != nil { |
| 550 | if err, ok := res.(error); ok { |
| 551 | return failedresponse, err |
| 552 | } |
| 553 | if opResp, ok := res.(*common.OperationResp); ok { |
| 554 | return opResp, nil |
| 555 | } |
| 556 | } |
| 557 | log.Warnw("download-image-unexpected-return-type", log.Fields{"result": res}) |
| 558 | return failedresponse, status.Errorf(codes.Internal, "%s", res) |
| 559 | case <-ctx.Done(): |
| 560 | log.Debug("downloadImage-client-timeout") |
| 561 | return nil, ctx.Err() |
| 562 | } |
| 563 | } |
| 564 | |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 565 | func (handler *APIHandler) DownloadImage(ctx context.Context, img *voltha.ImageDownload) (*common.OperationResp, error) { |
| 566 | log.Debugw("DownloadImage-request", log.Fields{"img": *img}) |
| 567 | if isTestMode(ctx) { |
| 568 | resp := &common.OperationResp{Code: common.OperationResp_OPERATION_SUCCESS} |
| 569 | return resp, nil |
| 570 | } |
| 571 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 572 | return handler.processImageRequest(ctx, img, IMAGE_DOWNLOAD) |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | func (handler *APIHandler) CancelImageDownload(ctx context.Context, img *voltha.ImageDownload) (*common.OperationResp, error) { |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 576 | log.Debugw("cancelImageDownload-request", log.Fields{"img": *img}) |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 577 | if isTestMode(ctx) { |
| 578 | resp := &common.OperationResp{Code: common.OperationResp_OPERATION_SUCCESS} |
| 579 | return resp, nil |
| 580 | } |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 581 | return handler.processImageRequest(ctx, img, CANCEL_IMAGE_DOWNLOAD) |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | func (handler *APIHandler) ActivateImageUpdate(ctx context.Context, img *voltha.ImageDownload) (*common.OperationResp, error) { |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 585 | log.Debugw("activateImageUpdate-request", log.Fields{"img": *img}) |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 586 | if isTestMode(ctx) { |
| 587 | resp := &common.OperationResp{Code: common.OperationResp_OPERATION_SUCCESS} |
| 588 | return resp, nil |
| 589 | } |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 590 | |
| 591 | return handler.processImageRequest(ctx, img, ACTIVATE_IMAGE) |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | func (handler *APIHandler) RevertImageUpdate(ctx context.Context, img *voltha.ImageDownload) (*common.OperationResp, error) { |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 595 | log.Debugw("revertImageUpdate-request", log.Fields{"img": *img}) |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 596 | if isTestMode(ctx) { |
| 597 | resp := &common.OperationResp{Code: common.OperationResp_OPERATION_SUCCESS} |
| 598 | return resp, nil |
| 599 | } |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 600 | |
| 601 | return handler.processImageRequest(ctx, img, REVERT_IMAGE) |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 602 | } |
| 603 | |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 604 | func (handler *APIHandler) GetImageDownloadStatus(ctx context.Context, img *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
| 605 | log.Debugw("getImageDownloadStatus-request", log.Fields{"img": *img}) |
| 606 | if isTestMode(ctx) { |
Stephane Barbarie | df5479f | 2019-01-29 22:13:00 -0500 | [diff] [blame] | 607 | resp := &voltha.ImageDownload{DownloadState: voltha.ImageDownload_DOWNLOAD_SUCCEEDED} |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 608 | return resp, nil |
| 609 | } |
| 610 | |
Stephane Barbarie | df5479f | 2019-01-29 22:13:00 -0500 | [diff] [blame] | 611 | failedresponse := &voltha.ImageDownload{DownloadState: voltha.ImageDownload_DOWNLOAD_UNKNOWN} |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 612 | |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 613 | if handler.competeForTransaction() { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 614 | if txn, err := handler.takeRequestOwnership(ctx, &utils.DeviceID{Id: img.Id}); err != nil { |
khenaidoo | 9cdc1a6 | 2019-01-24 21:57:40 -0500 | [diff] [blame] | 615 | return failedresponse, err |
| 616 | } else { |
| 617 | defer txn.Close() |
| 618 | } |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | ch := make(chan interface{}) |
| 622 | defer close(ch) |
| 623 | go handler.deviceMgr.getImageDownloadStatus(ctx, img, ch) |
| 624 | |
| 625 | select { |
| 626 | case res := <-ch: |
| 627 | if res != nil { |
| 628 | if err, ok := res.(error); ok { |
| 629 | return failedresponse, err |
| 630 | } |
| 631 | if downloadResp, ok := res.(*voltha.ImageDownload); ok { |
| 632 | return downloadResp, nil |
| 633 | } |
| 634 | } |
| 635 | log.Warnw("download-image-status", log.Fields{"result": res}) |
| 636 | return failedresponse, status.Errorf(codes.Internal, "%s", res) |
| 637 | case <-ctx.Done(): |
| 638 | log.Debug("downloadImage-client-timeout") |
| 639 | return failedresponse, ctx.Err() |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | func (handler *APIHandler) GetImageDownload(ctx context.Context, img *voltha.ImageDownload) (*voltha.ImageDownload, error) { |
| 644 | log.Debugw("GetImageDownload-request", log.Fields{"img": *img}) |
| 645 | if isTestMode(ctx) { |
Stephane Barbarie | df5479f | 2019-01-29 22:13:00 -0500 | [diff] [blame] | 646 | resp := &voltha.ImageDownload{DownloadState: voltha.ImageDownload_DOWNLOAD_SUCCEEDED} |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 647 | return resp, nil |
| 648 | } |
| 649 | |
| 650 | if download, err := handler.deviceMgr.getImageDownload(ctx, img); err != nil { |
Stephane Barbarie | df5479f | 2019-01-29 22:13:00 -0500 | [diff] [blame] | 651 | return &voltha.ImageDownload{DownloadState: voltha.ImageDownload_DOWNLOAD_UNKNOWN}, err |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 652 | } else { |
| 653 | return download, nil |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | func (handler *APIHandler) ListImageDownloads(ctx context.Context, id *voltha.ID) (*voltha.ImageDownloads, error) { |
| 658 | log.Debugw("ListImageDownloads-request", log.Fields{"deviceId": id.Id}) |
| 659 | if isTestMode(ctx) { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 660 | resp := &voltha.ImageDownloads{Items: []*voltha.ImageDownload{}} |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 661 | return resp, nil |
| 662 | } |
| 663 | |
| 664 | if downloads, err := handler.deviceMgr.listImageDownloads(ctx, id.Id); err != nil { |
| 665 | failedResp := &voltha.ImageDownloads{ |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 666 | Items: []*voltha.ImageDownload{ |
| 667 | {DownloadState: voltha.ImageDownload_DOWNLOAD_UNKNOWN}, |
| 668 | }, |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 669 | } |
| 670 | return failedResp, err |
| 671 | } else { |
| 672 | return downloads, nil |
| 673 | } |
| 674 | } |
| 675 | |
khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 676 | func (handler *APIHandler) UpdateDevicePmConfigs(ctx context.Context, configs *voltha.PmConfigs) (*empty.Empty, error) { |
| 677 | log.Debugw("UpdateDevicePmConfigs-request", log.Fields{"configs": *configs}) |
| 678 | if isTestMode(ctx) { |
| 679 | out := new(empty.Empty) |
| 680 | return out, nil |
| 681 | } |
| 682 | return nil, errors.New("UnImplemented") |
| 683 | } |
| 684 | |
| 685 | func (handler *APIHandler) CreateAlarmFilter(ctx context.Context, filter *voltha.AlarmFilter) (*voltha.AlarmFilter, error) { |
| 686 | log.Debugw("CreateAlarmFilter-request", log.Fields{"filter": *filter}) |
| 687 | if isTestMode(ctx) { |
| 688 | f := &voltha.AlarmFilter{Id: filter.Id} |
| 689 | return f, nil |
| 690 | } |
| 691 | return nil, errors.New("UnImplemented") |
| 692 | } |
| 693 | |
| 694 | func (handler *APIHandler) UpdateAlarmFilter(ctx context.Context, filter *voltha.AlarmFilter) (*voltha.AlarmFilter, error) { |
| 695 | log.Debugw("UpdateAlarmFilter-request", log.Fields{"filter": *filter}) |
| 696 | if isTestMode(ctx) { |
| 697 | f := &voltha.AlarmFilter{Id: filter.Id} |
| 698 | return f, nil |
| 699 | } |
| 700 | return nil, errors.New("UnImplemented") |
| 701 | } |
| 702 | |
| 703 | func (handler *APIHandler) DeleteAlarmFilter(ctx context.Context, id *voltha.ID) (*empty.Empty, error) { |
| 704 | log.Debugw("DeleteAlarmFilter-request", log.Fields{"id": *id}) |
| 705 | if isTestMode(ctx) { |
| 706 | out := new(empty.Empty) |
| 707 | return out, nil |
| 708 | } |
| 709 | return nil, errors.New("UnImplemented") |
| 710 | } |
| 711 | |
| 712 | func (handler *APIHandler) SelfTest(ctx context.Context, id *voltha.ID) (*voltha.SelfTestResponse, error) { |
| 713 | log.Debugw("SelfTest-request", log.Fields{"id": id}) |
| 714 | if isTestMode(ctx) { |
| 715 | resp := &voltha.SelfTestResponse{Result: voltha.SelfTestResponse_SUCCESS} |
| 716 | return resp, nil |
| 717 | } |
| 718 | return nil, errors.New("UnImplemented") |
| 719 | } |
Stephane Barbarie | 6e1bd50 | 2018-11-05 22:44:45 -0500 | [diff] [blame] | 720 | |
| 721 | func (handler *APIHandler) forwardPacketOut(packet *openflow_13.PacketOut) { |
| 722 | log.Debugw("forwardPacketOut-request", log.Fields{"packet": packet}) |
Richard Jankowski | 2755adf | 2019-01-17 17:16:48 -0500 | [diff] [blame] | 723 | agent := handler.logicalDeviceMgr.getLogicalDeviceAgent(packet.Id) |
| 724 | agent.packetOut(packet.PacketOut) |
Stephane Barbarie | 6e1bd50 | 2018-11-05 22:44:45 -0500 | [diff] [blame] | 725 | } |
| 726 | func (handler *APIHandler) StreamPacketsOut( |
| 727 | packets voltha.VolthaService_StreamPacketsOutServer, |
| 728 | ) error { |
| 729 | log.Debugw("StreamPacketsOut-request", log.Fields{"packets": packets}) |
| 730 | for { |
| 731 | packet, err := packets.Recv() |
| 732 | |
| 733 | if err == io.EOF { |
| 734 | break |
| 735 | } else if err != nil { |
| 736 | log.Errorw("Failed to receive packet", log.Fields{"error": err}) |
| 737 | } |
| 738 | |
| 739 | handler.forwardPacketOut(packet) |
| 740 | } |
| 741 | |
| 742 | log.Debugw("StreamPacketsOut-request-done", log.Fields{"packets": packets}) |
| 743 | return nil |
| 744 | } |
| 745 | |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 746 | func (handler *APIHandler) sendPacketIn(deviceId string, transationId string, packet *openflow_13.OfpPacketIn) { |
| 747 | // TODO: Augment the OF PacketIn to include the transactionId |
Stephane Barbarie | 6e1bd50 | 2018-11-05 22:44:45 -0500 | [diff] [blame] | 748 | packetIn := openflow_13.PacketIn{Id: deviceId, PacketIn: packet} |
| 749 | log.Debugw("sendPacketIn", log.Fields{"packetIn": packetIn}) |
Richard Jankowski | dbab94a | 2018-12-06 16:20:25 -0500 | [diff] [blame] | 750 | // Enqueue the packet |
| 751 | if err := handler.packetInQueue.Put(packetIn); err != nil { |
| 752 | log.Errorw("failed-to-enqueue-packet", log.Fields{"error": err}) |
| 753 | } |
Stephane Barbarie | 6e1bd50 | 2018-11-05 22:44:45 -0500 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | func (handler *APIHandler) ReceivePacketsIn( |
| 757 | empty *empty.Empty, |
| 758 | packetsIn voltha.VolthaService_ReceivePacketsInServer, |
| 759 | ) error { |
| 760 | log.Debugw("ReceivePacketsIn-request", log.Fields{"packetsIn": packetsIn}) |
| 761 | |
| 762 | for { |
Richard Jankowski | dbab94a | 2018-12-06 16:20:25 -0500 | [diff] [blame] | 763 | // Dequeue a packet |
| 764 | if packets, err := handler.packetInQueue.Get(1); err == nil { |
| 765 | log.Debugw("dequeued-packet", log.Fields{"packet": packets[0]}) |
| 766 | if packet, ok := packets[0].(openflow_13.PacketIn); ok { |
| 767 | log.Debugw("sending-packet-in", log.Fields{"packet": packet}) |
| 768 | if err := packetsIn.Send(&packet); err != nil { |
| 769 | log.Errorw("failed-to-send-packet", log.Fields{"error": err}) |
| 770 | } |
| 771 | } |
Stephane Barbarie | 6e1bd50 | 2018-11-05 22:44:45 -0500 | [diff] [blame] | 772 | } |
| 773 | } |
khenaidoo | f5a5bfa | 2019-01-23 22:20:29 -0500 | [diff] [blame] | 774 | //TODO: FInd an elegant way to get out of the above loop when the Core is stopped |
Stephane Barbarie | 6e1bd50 | 2018-11-05 22:44:45 -0500 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | func (handler *APIHandler) sendChangeEvent(deviceId string, portStatus *openflow_13.OfpPortStatus) { |
| 778 | // TODO: validate the type of portStatus parameter |
| 779 | //if _, ok := portStatus.(*openflow_13.OfpPortStatus); ok { |
| 780 | //} |
| 781 | event := openflow_13.ChangeEvent{Id: deviceId, Event: &openflow_13.ChangeEvent_PortStatus{PortStatus: portStatus}} |
| 782 | log.Debugw("sendChangeEvent", log.Fields{"event": event}) |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 783 | // Enqueue the change event |
| 784 | if err := handler.changeEventQueue.Put(event); err != nil { |
| 785 | log.Errorw("failed-to-enqueue-change-event", log.Fields{"error": err}) |
| 786 | } |
Stephane Barbarie | 6e1bd50 | 2018-11-05 22:44:45 -0500 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | func (handler *APIHandler) ReceiveChangeEvents( |
| 790 | empty *empty.Empty, |
| 791 | changeEvents voltha.VolthaService_ReceiveChangeEventsServer, |
| 792 | ) error { |
| 793 | log.Debugw("ReceiveChangeEvents-request", log.Fields{"changeEvents": changeEvents}) |
| 794 | for { |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 795 | // Dequeue a change event |
| 796 | if events, err := handler.changeEventQueue.Get(1); err == nil { |
| 797 | log.Debugw("dequeued-change-event", log.Fields{"event": events[0]}) |
| 798 | if event, ok := events[0].(openflow_13.ChangeEvent); ok { |
| 799 | log.Debugw("sending-change-event", log.Fields{"event": event}) |
| 800 | if err := changeEvents.Send(&event); err != nil { |
| 801 | log.Errorw("failed-to-send-change-event", log.Fields{"error": err}) |
| 802 | } |
| 803 | } |
Stephane Barbarie | 6e1bd50 | 2018-11-05 22:44:45 -0500 | [diff] [blame] | 804 | } |
| 805 | } |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 806 | } |
Stephane Barbarie | 6e1bd50 | 2018-11-05 22:44:45 -0500 | [diff] [blame] | 807 | |
| 808 | func (handler *APIHandler) Subscribe( |
| 809 | ctx context.Context, |
| 810 | ofAgent *voltha.OfAgentSubscriber, |
| 811 | ) (*voltha.OfAgentSubscriber, error) { |
| 812 | log.Debugw("Subscribe-request", log.Fields{"ofAgent": ofAgent}) |
| 813 | return &voltha.OfAgentSubscriber{OfagentId: ofAgent.OfagentId, VolthaId: ofAgent.VolthaId}, nil |
| 814 | } |
William Kurkian | daa6bb2 | 2019-03-07 12:26:28 -0500 | [diff] [blame] | 815 | |
| 816 | //@TODO useless stub, what should this actually do? |
| 817 | func (handler *APIHandler) GetAlarmDeviceData( |
| 818 | ctx context.Context, |
| 819 | in *common.ID, |
| 820 | ) (*omci.AlarmDeviceData, error) { |
| 821 | log.Debug("GetAlarmDeviceData-stub") |
| 822 | return nil, nil |
| 823 | } |
| 824 | |
| 825 | //@TODO useless stub, what should this actually do? |
| 826 | func (handler *APIHandler) GetMeterStatsOfLogicalDevice( |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 827 | ctx context.Context, |
William Kurkian | daa6bb2 | 2019-03-07 12:26:28 -0500 | [diff] [blame] | 828 | in *common.ID, |
| 829 | ) (*openflow_13.MeterStatsReply, error) { |
| 830 | log.Debug("GetMeterStatsOfLogicalDevice-stub") |
| 831 | return nil, nil |
| 832 | } |
| 833 | |
| 834 | //@TODO useless stub, what should this actually do? |
| 835 | func (handler *APIHandler) GetMibDeviceData( |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 836 | ctx context.Context, |
| 837 | in *common.ID, |
William Kurkian | daa6bb2 | 2019-03-07 12:26:28 -0500 | [diff] [blame] | 838 | ) (*omci.MibDeviceData, error) { |
| 839 | log.Debug("GetMibDeviceData-stub") |
| 840 | return nil, nil |
| 841 | } |
| 842 | |
William Kurkian | daa6bb2 | 2019-03-07 12:26:28 -0500 | [diff] [blame] | 843 | func (handler *APIHandler) SimulateAlarm( |
| 844 | ctx context.Context, |
| 845 | in *voltha.SimulateAlarmRequest, |
| 846 | ) (*common.OperationResp, error) { |
serkant.uluderya | 334479d | 2019-04-10 08:26:15 -0700 | [diff] [blame] | 847 | log.Debugw("SimulateAlarm-request", log.Fields{"id": in.Id}) |
| 848 | successResp := &common.OperationResp{Code: common.OperationResp_OPERATION_SUCCESS} |
| 849 | if isTestMode(ctx) { |
| 850 | return successResp, nil |
| 851 | } |
| 852 | |
| 853 | if handler.competeForTransaction() { |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame] | 854 | if txn, err := handler.takeRequestOwnership(ctx, &utils.DeviceID{Id: in.Id}, handler.longRunningRequestTimeout); err != nil { |
| 855 | failedresponse := &common.OperationResp{Code: voltha.OperationResp_OPERATION_FAILURE} |
serkant.uluderya | 334479d | 2019-04-10 08:26:15 -0700 | [diff] [blame] | 856 | return failedresponse, err |
| 857 | } else { |
| 858 | defer txn.Close() |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | ch := make(chan interface{}) |
| 863 | defer close(ch) |
| 864 | go handler.deviceMgr.simulateAlarm(ctx, in, ch) |
| 865 | return successResp, nil |
William Kurkian | daa6bb2 | 2019-03-07 12:26:28 -0500 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | //@TODO useless stub, what should this actually do? |
| 869 | func (handler *APIHandler) UpdateLogicalDeviceMeterTable( |
| 870 | ctx context.Context, |
| 871 | in *openflow_13.MeterModUpdate, |
| 872 | ) (*empty.Empty, error) { |
| 873 | log.Debug("UpdateLogicalDeviceMeterTable-stub") |
| 874 | return nil, nil |
| 875 | } |