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