sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package model |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "encoding/hex" |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 21 | "math/rand" |
| 22 | "reflect" |
| 23 | "strconv" |
| 24 | "sync" |
| 25 | "testing" |
| 26 | |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 27 | "github.com/google/uuid" |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 28 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 29 | "github.com/opencord/voltha-protos/v3/go/common" |
| 30 | "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 31 | "github.com/opencord/voltha-protos/v3/go/voltha" |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 32 | "github.com/stretchr/testify/assert" |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 33 | ) |
| 34 | |
| 35 | var ( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 36 | BenchmarkProxyRoot Root |
| 37 | BenchmarkProxyDeviceProxy *Proxy |
| 38 | BenchmarkProxyPLT *proxyLoadTest |
| 39 | BenchmarkProxyLogger log.Logger |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 40 | ) |
| 41 | |
| 42 | type proxyLoadChanges struct { |
| 43 | ID string |
| 44 | Before interface{} |
| 45 | After interface{} |
| 46 | } |
| 47 | type proxyLoadTest struct { |
| 48 | mutex sync.RWMutex |
| 49 | |
| 50 | addMutex sync.RWMutex |
| 51 | addedDevices []string |
| 52 | |
| 53 | firmwareMutex sync.RWMutex |
| 54 | updatedFirmwares []proxyLoadChanges |
| 55 | flowMutex sync.RWMutex |
| 56 | updatedFlows []proxyLoadChanges |
| 57 | |
| 58 | preAddExecuted bool |
| 59 | postAddExecuted bool |
| 60 | preUpdateExecuted bool |
| 61 | postUpdateExecuted bool |
| 62 | } |
| 63 | |
| 64 | func (plt *proxyLoadTest) SetPreAddExecuted(status bool) { |
| 65 | plt.mutex.Lock() |
| 66 | defer plt.mutex.Unlock() |
| 67 | plt.preAddExecuted = status |
| 68 | } |
| 69 | func (plt *proxyLoadTest) SetPostAddExecuted(status bool) { |
| 70 | plt.mutex.Lock() |
| 71 | defer plt.mutex.Unlock() |
| 72 | plt.postAddExecuted = status |
| 73 | } |
| 74 | func (plt *proxyLoadTest) SetPreUpdateExecuted(status bool) { |
| 75 | plt.mutex.Lock() |
| 76 | defer plt.mutex.Unlock() |
| 77 | plt.preUpdateExecuted = status |
| 78 | } |
| 79 | func (plt *proxyLoadTest) SetPostUpdateExecuted(status bool) { |
| 80 | plt.mutex.Lock() |
| 81 | defer plt.mutex.Unlock() |
| 82 | plt.postUpdateExecuted = status |
| 83 | } |
| 84 | |
| 85 | func init() { |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 86 | var err error |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 87 | BenchmarkProxyRoot = NewRoot(&voltha.Voltha{}, nil) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 88 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 89 | BenchmarkProxyLogger, _ = log.AddPackage(log.JSON, log.DebugLevel, log.Fields{"instanceId": "PLT"}) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 90 | //log.UpdateAllLoggers(log.Fields{"instanceId": "PROXY_LOAD_TEST"}) |
| 91 | //Setup default logger - applies for packages that do not have specific logger set |
| 92 | if _, err := log.SetDefaultLogger(log.JSON, log.DebugLevel, log.Fields{"instanceId": "PLT"}); err != nil { |
| 93 | log.With(log.Fields{"error": err}).Fatal("Cannot setup logging") |
| 94 | } |
| 95 | |
| 96 | // Update all loggers (provisioned via init) with a common field |
| 97 | if err := log.UpdateAllLoggers(log.Fields{"instanceId": "PLT"}); err != nil { |
| 98 | log.With(log.Fields{"error": err}).Fatal("Cannot setup logging") |
| 99 | } |
| 100 | log.SetPackageLogLevel("github.com/opencord/voltha-go/db/model", log.DebugLevel) |
| 101 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 102 | if BenchmarkProxyDeviceProxy, err = BenchmarkProxyRoot.CreateProxy(context.Background(), "/", false); err != nil { |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 103 | log.With(log.Fields{"error": err}).Fatal("Cannot create benchmark proxy") |
| 104 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 105 | // Register ADD instructions callbacks |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 106 | BenchmarkProxyPLT = &proxyLoadTest{} |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 107 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 108 | BenchmarkProxyDeviceProxy.RegisterCallback(PreAdd, commonCallbackFunc, "PreAdd", BenchmarkProxyPLT.SetPreAddExecuted) |
| 109 | BenchmarkProxyDeviceProxy.RegisterCallback(PostAdd, commonCallbackFunc, "PostAdd", BenchmarkProxyPLT.SetPostAddExecuted) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 110 | |
| 111 | //// Register UPDATE instructions callbacks |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 112 | BenchmarkProxyDeviceProxy.RegisterCallback(PreUpdate, commonCallbackFunc, "PreUpdate", BenchmarkProxyPLT.SetPreUpdateExecuted) |
| 113 | BenchmarkProxyDeviceProxy.RegisterCallback(PostUpdate, commonCallbackFunc, "PostUpdate", BenchmarkProxyPLT.SetPostUpdateExecuted) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 114 | |
| 115 | } |
| 116 | |
| 117 | func BenchmarkProxy_AddDevice(b *testing.B) { |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 118 | var err error |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 119 | defer GetProfiling().Report() |
| 120 | b.RunParallel(func(pb *testing.PB) { |
| 121 | b.Log("Started adding devices") |
| 122 | for pb.Next() { |
| 123 | ltPorts := []*voltha.Port{ |
| 124 | { |
| 125 | PortNo: 123, |
| 126 | Label: "lt-port-0", |
| 127 | Type: voltha.Port_PON_OLT, |
| 128 | AdminState: common.AdminState_ENABLED, |
| 129 | OperStatus: common.OperStatus_ACTIVE, |
| 130 | DeviceId: "lt-port-0-device-id", |
| 131 | Peers: []*voltha.Port_PeerPort{}, |
| 132 | }, |
| 133 | } |
| 134 | |
| 135 | ltStats := &openflow_13.OfpFlowStats{ |
| 136 | Id: 1000, |
| 137 | } |
| 138 | ltFlows := &openflow_13.Flows{ |
| 139 | Items: []*openflow_13.OfpFlowStats{ltStats}, |
| 140 | } |
| 141 | ltDevice := &voltha.Device{ |
| 142 | Id: "", |
| 143 | Type: "simulated_olt", |
| 144 | Address: &voltha.Device_HostAndPort{HostAndPort: "1.2.3.4:5555"}, |
| 145 | AdminState: voltha.AdminState_PREPROVISIONED, |
| 146 | Flows: ltFlows, |
| 147 | Ports: ltPorts, |
| 148 | } |
| 149 | |
| 150 | ltDevIDBin, _ := uuid.New().MarshalBinary() |
| 151 | ltDevID := "0001" + hex.EncodeToString(ltDevIDBin)[:12] |
| 152 | ltDevice.Id = ltDevID |
| 153 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 154 | BenchmarkProxyPLT.SetPreAddExecuted(false) |
| 155 | BenchmarkProxyPLT.SetPostAddExecuted(false) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 156 | |
| 157 | var added interface{} |
| 158 | // Add the device |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 159 | if added, err = BenchmarkProxyDeviceProxy.AddWithID(context.Background(), "/devices", ltDevID, ltDevice, ""); err != nil { |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 160 | log.With(log.Fields{"error": err}).Fatal("Cannot create proxy") |
| 161 | } |
| 162 | if added == nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 163 | BenchmarkProxyLogger.Errorf("Failed to add device: %+v", ltDevice) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 164 | continue |
| 165 | } else { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 166 | BenchmarkProxyLogger.Infof("Device was added 1: %+v", added) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 167 | } |
| 168 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 169 | BenchmarkProxyPLT.addMutex.Lock() |
| 170 | BenchmarkProxyPLT.addedDevices = append(BenchmarkProxyPLT.addedDevices, added.(*voltha.Device).Id) |
| 171 | BenchmarkProxyPLT.addMutex.Unlock() |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 172 | } |
| 173 | }) |
| 174 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 175 | BenchmarkProxyLogger.Infof("Number of added devices : %d", len(BenchmarkProxyPLT.addedDevices)) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | func BenchmarkProxy_UpdateFirmware(b *testing.B) { |
| 179 | b.RunParallel(func(pb *testing.PB) { |
| 180 | for pb.Next() { |
| 181 | //for i:=0; i < b.N; i++ { |
| 182 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 183 | if len(BenchmarkProxyPLT.addedDevices) > 0 { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 184 | var target interface{} |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 185 | randomID := BenchmarkProxyPLT.addedDevices[rand.Intn(len(BenchmarkProxyPLT.addedDevices))] |
| 186 | firmProxy, err := BenchmarkProxyRoot.CreateProxy(context.Background(), "/", false) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 187 | if err != nil { |
| 188 | log.With(log.Fields{"error": err}).Fatal("Cannot create firmware proxy") |
| 189 | } |
| 190 | target, err = firmProxy.Get(context.Background(), "/devices/"+randomID, 0, false, |
| 191 | "") |
| 192 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 193 | BenchmarkProxyLogger.Errorf("Failed to create target due to error %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 194 | assert.NotNil(b, err) |
| 195 | } |
| 196 | if !reflect.ValueOf(target).IsValid() { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 197 | BenchmarkProxyLogger.Errorf("Failed to find device: %s %+v", randomID, target) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 198 | continue |
| 199 | } |
| 200 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 201 | BenchmarkProxyPLT.SetPreUpdateExecuted(false) |
| 202 | BenchmarkProxyPLT.SetPostUpdateExecuted(false) |
| 203 | firmProxy.RegisterCallback(PreUpdate, commonCallbackFunc, "PreUpdate", BenchmarkProxyPLT.SetPreUpdateExecuted) |
| 204 | firmProxy.RegisterCallback(PostUpdate, commonCallbackFunc, "PostUpdate", BenchmarkProxyPLT.SetPostUpdateExecuted) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 205 | |
| 206 | var fwVersion int |
| 207 | |
| 208 | before := target.(*voltha.Device).FirmwareVersion |
| 209 | if target.(*voltha.Device).FirmwareVersion == "n/a" { |
| 210 | fwVersion = 0 |
| 211 | } else { |
| 212 | fwVersion, _ = strconv.Atoi(target.(*voltha.Device).FirmwareVersion) |
| 213 | fwVersion++ |
| 214 | } |
| 215 | |
| 216 | target.(*voltha.Device).FirmwareVersion = strconv.Itoa(fwVersion) |
| 217 | after := target.(*voltha.Device).FirmwareVersion |
| 218 | |
| 219 | var updated interface{} |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 220 | if updated, err = firmProxy.Update(context.Background(), "/devices/"+randomID, target.(*voltha.Device), false, ""); err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 221 | BenchmarkProxyLogger.Errorf("Failed to update firmware proxy due to error %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 222 | assert.NotNil(b, err) |
| 223 | } |
| 224 | if updated == nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 225 | BenchmarkProxyLogger.Errorf("Failed to update device: %+v", target) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 226 | continue |
| 227 | } else { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 228 | BenchmarkProxyLogger.Infof("Device was updated : %+v", updated) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 229 | |
| 230 | } |
| 231 | |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 232 | d, err := firmProxy.Get(context.Background(), "/devices/"+randomID, 0, false, "") |
| 233 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 234 | BenchmarkProxyLogger.Errorf("Failed to get device info from firmware proxy due to error %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 235 | assert.NotNil(b, err) |
| 236 | } |
| 237 | if !reflect.ValueOf(d).IsValid() { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 238 | BenchmarkProxyLogger.Errorf("Failed to get device: %s", randomID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 239 | continue |
| 240 | } else if d.(*voltha.Device).FirmwareVersion == after { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 241 | BenchmarkProxyLogger.Infof("Imm Device was updated with new value: %s %+v", randomID, d) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 242 | } else if d.(*voltha.Device).FirmwareVersion == before { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 243 | BenchmarkProxyLogger.Errorf("Imm Device kept old value: %s %+v %+v", randomID, d, target) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 244 | } else { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 245 | BenchmarkProxyLogger.Errorf("Imm Device has unknown value: %s %+v %+v", randomID, d, target) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 246 | } |
| 247 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 248 | BenchmarkProxyPLT.firmwareMutex.Lock() |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 249 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 250 | BenchmarkProxyPLT.updatedFirmwares = append( |
| 251 | BenchmarkProxyPLT.updatedFirmwares, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 252 | proxyLoadChanges{ID: randomID, Before: before, After: after}, |
| 253 | ) |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 254 | BenchmarkProxyPLT.firmwareMutex.Unlock() |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | }) |
| 258 | } |
| 259 | |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 260 | func BenchmarkProxy_UpdateFlows(b *testing.B) { |
| 261 | b.RunParallel(func(pb *testing.PB) { |
| 262 | for pb.Next() { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 263 | if len(BenchmarkProxyPLT.addedDevices) > 0 { |
| 264 | randomID := BenchmarkProxyPLT.addedDevices[rand.Intn(len(BenchmarkProxyPLT.addedDevices))] |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 265 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 266 | flowsProxy, err := BenchmarkProxyRoot.CreateProxy(context.Background(), "/devices/"+randomID+"/flows", false) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 267 | if err != nil { |
| 268 | log.With(log.Fields{"error": err}).Fatal("Cannot create flows proxy") |
| 269 | } |
| 270 | flows, err := flowsProxy.Get(context.Background(), "/", 0, false, "") |
| 271 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 272 | BenchmarkProxyLogger.Errorf("Failed to get flows from flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 273 | assert.NotNil(b, err) |
| 274 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 275 | |
| 276 | before := flows.(*openflow_13.Flows).Items[0].TableId |
| 277 | flows.(*openflow_13.Flows).Items[0].TableId = uint32(rand.Intn(3000)) |
| 278 | after := flows.(*openflow_13.Flows).Items[0].TableId |
| 279 | |
| 280 | flowsProxy.RegisterCallback( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 281 | PreUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 282 | commonCallback2, |
| 283 | ) |
| 284 | flowsProxy.RegisterCallback( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 285 | PostUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 286 | commonCallback2, |
| 287 | ) |
| 288 | |
| 289 | var updated interface{} |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 290 | if updated, err = flowsProxy.Update(context.Background(), "/", flows.(*openflow_13.Flows), false, ""); err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 291 | BenchmarkProxyLogger.Errorf("Cannot update flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 292 | assert.NotNil(b, err) |
| 293 | } |
| 294 | if updated == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 295 | b.Errorf("Failed to update flows for device: %+v", flows) |
| 296 | } else { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 297 | BenchmarkProxyLogger.Infof("Flows were updated : %+v", updated) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 298 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 299 | BenchmarkProxyPLT.flowMutex.Lock() |
| 300 | BenchmarkProxyPLT.updatedFlows = append( |
| 301 | BenchmarkProxyPLT.updatedFlows, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 302 | proxyLoadChanges{ID: randomID, Before: before, After: after}, |
| 303 | ) |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 304 | BenchmarkProxyPLT.flowMutex.Unlock() |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | }) |
| 308 | } |
| 309 | |
| 310 | func BenchmarkProxy_GetDevices(b *testing.B) { |
| 311 | //traverseBranches(BenchmarkProxy_DeviceProxy.Root.node.Branches[NONE].GetLatest(), 0) |
| 312 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 313 | for i := 0; i < len(BenchmarkProxyPLT.addedDevices); i++ { |
| 314 | devToGet := BenchmarkProxyPLT.addedDevices[i] |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 315 | // Verify that the added device can now be retrieved |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 316 | d, err := BenchmarkProxyDeviceProxy.Get(context.Background(), "/devices/"+devToGet, 0, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 317 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 318 | BenchmarkProxyLogger.Errorf("Failed to get device info from device proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 319 | assert.NotNil(b, err) |
| 320 | } |
| 321 | if !reflect.ValueOf(d).IsValid() { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 322 | BenchmarkProxyLogger.Errorf("Failed to get device: %s", devToGet) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 323 | continue |
| 324 | } else { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 325 | BenchmarkProxyLogger.Infof("Got device: %s %+v", devToGet, d) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | func BenchmarkProxy_GetUpdatedFirmware(b *testing.B) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 331 | for i := 0; i < len(BenchmarkProxyPLT.updatedFirmwares); i++ { |
| 332 | devToGet := BenchmarkProxyPLT.updatedFirmwares[i].ID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 333 | // Verify that the updated device can be retrieved and that the updates were actually applied |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 334 | d, err := BenchmarkProxyDeviceProxy.Get(context.Background(), "/devices/"+devToGet, 0, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 335 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 336 | BenchmarkProxyLogger.Errorf("Failed to get device info from device proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 337 | assert.NotNil(b, err) |
| 338 | } |
| 339 | if !reflect.ValueOf(d).IsValid() { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 340 | BenchmarkProxyLogger.Errorf("Failed to get device: %s", devToGet) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 341 | continue |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 342 | } else if d.(*voltha.Device).FirmwareVersion == BenchmarkProxyPLT.updatedFirmwares[i].After.(string) { |
| 343 | BenchmarkProxyLogger.Infof("Device was updated with new value: %s %+v", devToGet, d) |
| 344 | } else if d.(*voltha.Device).FirmwareVersion == BenchmarkProxyPLT.updatedFirmwares[i].Before.(string) { |
| 345 | BenchmarkProxyLogger.Errorf("Device kept old value: %s %+v %+v", devToGet, d, BenchmarkProxyPLT.updatedFirmwares[i]) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 346 | } else { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 347 | BenchmarkProxyLogger.Errorf("Device has unknown value: %s %+v %+v", devToGet, d, BenchmarkProxyPLT.updatedFirmwares[i]) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | } |