Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -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 | "encoding/hex" |
| 20 | "github.com/google/uuid" |
| 21 | "github.com/opencord/voltha-go/common/log" |
William Kurkian | daa6bb2 | 2019-03-07 12:26:28 -0500 | [diff] [blame] | 22 | "github.com/opencord/voltha-protos/go/common" |
| 23 | "github.com/opencord/voltha-protos/go/openflow_13" |
| 24 | "github.com/opencord/voltha-protos/go/voltha" |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 25 | "math/rand" |
| 26 | "reflect" |
| 27 | "strconv" |
| 28 | "sync" |
| 29 | "testing" |
| 30 | ) |
| 31 | |
| 32 | var ( |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 33 | BenchmarkProxy_Root *root |
| 34 | BenchmarkProxy_DeviceProxy *Proxy |
| 35 | BenchmarkProxy_PLT *proxyLoadTest |
| 36 | BenchmarkProxy_Logger log.Logger |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 37 | ) |
| 38 | |
| 39 | type proxyLoadChanges struct { |
| 40 | ID string |
| 41 | Before interface{} |
| 42 | After interface{} |
| 43 | } |
| 44 | type proxyLoadTest struct { |
| 45 | sync.RWMutex |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame^] | 46 | addedDevices []string |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 47 | updatedFirmwares []proxyLoadChanges |
| 48 | updatedFlows []proxyLoadChanges |
| 49 | preAddExecuted bool |
| 50 | postAddExecuted bool |
| 51 | preUpdateExecuted bool |
| 52 | postUpdateExecuted bool |
| 53 | } |
| 54 | |
| 55 | func (plt *proxyLoadTest) SetPreAddExecuted(status bool) { |
| 56 | plt.Lock() |
| 57 | defer plt.Unlock() |
| 58 | plt.preAddExecuted = status |
| 59 | } |
| 60 | func (plt *proxyLoadTest) SetPostAddExecuted(status bool) { |
| 61 | plt.Lock() |
| 62 | defer plt.Unlock() |
| 63 | plt.postAddExecuted = status |
| 64 | } |
| 65 | func (plt *proxyLoadTest) SetPreUpdateExecuted(status bool) { |
| 66 | plt.Lock() |
| 67 | defer plt.Unlock() |
| 68 | plt.preUpdateExecuted = status |
| 69 | } |
| 70 | func (plt *proxyLoadTest) SetPostUpdateExecuted(status bool) { |
| 71 | plt.Lock() |
| 72 | defer plt.Unlock() |
| 73 | plt.postUpdateExecuted = status |
| 74 | } |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 75 | |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 76 | func init() { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 77 | BenchmarkProxy_Root = NewRoot(&voltha.Voltha{}, nil) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 78 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 79 | BenchmarkProxy_Logger, _ = log.AddPackage(log.JSON, log.InfoLevel, nil) |
| 80 | //log.UpdateAllLoggers(log.Fields{"instanceId": "PROXY_LOAD_TEST"}) |
| 81 | |
| 82 | BenchmarkProxy_DeviceProxy = BenchmarkProxy_Root.node.CreateProxy("/", false) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 83 | // Register ADD instructions callbacks |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 84 | BenchmarkProxy_PLT = &proxyLoadTest{} |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 85 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 86 | BenchmarkProxy_DeviceProxy.RegisterCallback(PRE_ADD, commonCallbackFunc, "PRE_ADD", BenchmarkProxy_PLT.SetPreAddExecuted) |
| 87 | BenchmarkProxy_DeviceProxy.RegisterCallback(POST_ADD, commonCallbackFunc, "POST_ADD", BenchmarkProxy_PLT.SetPostAddExecuted) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 88 | |
| 89 | //// Register UPDATE instructions callbacks |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 90 | BenchmarkProxy_DeviceProxy.RegisterCallback(PRE_UPDATE, commonCallbackFunc, "PRE_UPDATE", BenchmarkProxy_PLT.SetPreUpdateExecuted) |
| 91 | BenchmarkProxy_DeviceProxy.RegisterCallback(POST_UPDATE, commonCallbackFunc, "POST_UPDATE", BenchmarkProxy_PLT.SetPostUpdateExecuted) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 92 | |
| 93 | } |
| 94 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 95 | func BenchmarkProxy_AddDevice(b *testing.B) { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 96 | defer GetProfiling().Report() |
| 97 | b.RunParallel(func(pb *testing.PB) { |
| 98 | b.Log("Started adding devices") |
| 99 | for pb.Next() { |
| 100 | ltPorts := []*voltha.Port{ |
| 101 | { |
| 102 | PortNo: 123, |
| 103 | Label: "lt-port-0", |
| 104 | Type: voltha.Port_PON_OLT, |
| 105 | AdminState: common.AdminState_ENABLED, |
| 106 | OperStatus: common.OperStatus_ACTIVE, |
| 107 | DeviceId: "lt-port-0-device-id", |
| 108 | Peers: []*voltha.Port_PeerPort{}, |
| 109 | }, |
| 110 | } |
| 111 | |
| 112 | ltStats := &openflow_13.OfpFlowStats{ |
| 113 | Id: 1000, |
| 114 | } |
| 115 | ltFlows := &openflow_13.Flows{ |
| 116 | Items: []*openflow_13.OfpFlowStats{ltStats}, |
| 117 | } |
| 118 | ltDevice := &voltha.Device{ |
| 119 | Id: "", |
| 120 | Type: "simulated_olt", |
| 121 | Address: &voltha.Device_HostAndPort{HostAndPort: "1.2.3.4:5555"}, |
| 122 | AdminState: voltha.AdminState_PREPROVISIONED, |
| 123 | Flows: ltFlows, |
| 124 | Ports: ltPorts, |
| 125 | } |
| 126 | |
| 127 | ltDevIDBin, _ := uuid.New().MarshalBinary() |
| 128 | ltDevID := "0001" + hex.EncodeToString(ltDevIDBin)[:12] |
| 129 | ltDevice.Id = ltDevID |
| 130 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 131 | BenchmarkProxy_PLT.SetPreAddExecuted(false) |
| 132 | BenchmarkProxy_PLT.SetPostAddExecuted(false) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 133 | |
| 134 | var added interface{} |
| 135 | // Add the device |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 136 | if added = BenchmarkProxy_DeviceProxy.AddWithID("/devices", ltDevID, ltDevice, ""); added == nil { |
| 137 | BenchmarkProxy_Logger.Errorf("Failed to add device: %+v", ltDevice) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 138 | continue |
| 139 | } else { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 140 | BenchmarkProxy_Logger.Infof("Device was added 1: %+v", added) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 141 | } |
| 142 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 143 | BenchmarkProxy_PLT.Lock() |
| 144 | BenchmarkProxy_PLT.addedDevices = append(BenchmarkProxy_PLT.addedDevices, added.(*voltha.Device).Id) |
| 145 | BenchmarkProxy_PLT.Unlock() |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 146 | } |
| 147 | }) |
| 148 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 149 | BenchmarkProxy_Logger.Infof("Number of added devices : %d", len(BenchmarkProxy_PLT.addedDevices)) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 150 | } |
| 151 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 152 | func BenchmarkProxy_UpdateFirmware(b *testing.B) { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 153 | b.RunParallel(func(pb *testing.PB) { |
| 154 | for pb.Next() { |
| 155 | //for i:=0; i < b.N; i++ { |
| 156 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 157 | if len(BenchmarkProxy_PLT.addedDevices) > 0 { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 158 | var target interface{} |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 159 | randomID := BenchmarkProxy_PLT.addedDevices[rand.Intn(len(BenchmarkProxy_PLT.addedDevices))] |
| 160 | firmProxy := BenchmarkProxy_Root.node.CreateProxy("/", false) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 161 | if target = firmProxy.Get("/devices/"+randomID, 0, false, |
| 162 | ""); !reflect.ValueOf(target).IsValid() { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 163 | BenchmarkProxy_Logger.Errorf("Failed to find device: %s %+v", randomID, target) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 164 | continue |
| 165 | } |
| 166 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 167 | BenchmarkProxy_PLT.SetPreUpdateExecuted(false) |
| 168 | BenchmarkProxy_PLT.SetPostUpdateExecuted(false) |
| 169 | firmProxy.RegisterCallback(PRE_UPDATE, commonCallbackFunc, "PRE_UPDATE", BenchmarkProxy_PLT.SetPreUpdateExecuted) |
| 170 | firmProxy.RegisterCallback(POST_UPDATE, commonCallbackFunc, "POST_UPDATE", BenchmarkProxy_PLT.SetPostUpdateExecuted) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 171 | |
| 172 | var fwVersion int |
| 173 | |
| 174 | before := target.(*voltha.Device).FirmwareVersion |
| 175 | if target.(*voltha.Device).FirmwareVersion == "n/a" { |
| 176 | fwVersion = 0 |
| 177 | } else { |
| 178 | fwVersion, _ = strconv.Atoi(target.(*voltha.Device).FirmwareVersion) |
| 179 | fwVersion++ |
| 180 | } |
| 181 | |
| 182 | target.(*voltha.Device).FirmwareVersion = strconv.Itoa(fwVersion) |
| 183 | after := target.(*voltha.Device).FirmwareVersion |
| 184 | |
| 185 | var updated interface{} |
| 186 | if updated = firmProxy.Update("/devices/"+randomID, target.(*voltha.Device), false, |
| 187 | ""); updated == nil { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 188 | BenchmarkProxy_Logger.Errorf("Failed to update device: %+v", target) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 189 | continue |
| 190 | } else { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 191 | BenchmarkProxy_Logger.Infof("Device was updated : %+v", updated) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 192 | |
| 193 | } |
| 194 | |
| 195 | if d := firmProxy.Get("/devices/"+randomID, 0, false, |
| 196 | ""); !reflect.ValueOf(d).IsValid() { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 197 | BenchmarkProxy_Logger.Errorf("Failed to get device: %s", randomID) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 198 | continue |
| 199 | } else if d.(*voltha.Device).FirmwareVersion == after { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 200 | BenchmarkProxy_Logger.Infof("Imm Device was updated with new value: %s %+v", randomID, d) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 201 | } else if d.(*voltha.Device).FirmwareVersion == before { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 202 | BenchmarkProxy_Logger.Errorf("Imm Device kept old value: %s %+v %+v", randomID, d, target) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 203 | } else { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 204 | BenchmarkProxy_Logger.Errorf("Imm Device has unknown value: %s %+v %+v", randomID, d, target) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 205 | } |
| 206 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 207 | BenchmarkProxy_PLT.Lock() |
| 208 | BenchmarkProxy_PLT.updatedFirmwares = append( |
| 209 | BenchmarkProxy_PLT.updatedFirmwares, |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 210 | proxyLoadChanges{ID: randomID, Before: before, After: after}, |
| 211 | ) |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 212 | BenchmarkProxy_PLT.Unlock() |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | }) |
| 216 | } |
| 217 | |
| 218 | func traverseBranches(revision Revision, depth int) { |
| 219 | if revision == nil { |
| 220 | return |
| 221 | } |
| 222 | prefix := strconv.Itoa(depth) + " ~~~~ " |
| 223 | for i := 0; i < depth; i++ { |
| 224 | prefix += " " |
| 225 | } |
| 226 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 227 | BenchmarkProxy_Logger.Debugf("%sRevision: %s %+v", prefix, revision.GetHash(), revision.GetData()) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 228 | |
| 229 | //for brIdx, brRev := range revision.GetBranch().Revisions { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 230 | // BenchmarkProxy_Logger.Debugf("%sbranchIndex: %s", prefix, brIdx) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 231 | // traverseBranches(brRev, depth+1) |
| 232 | //} |
Stephane Barbarie | 3cb0122 | 2019-01-16 17:15:56 -0500 | [diff] [blame] | 233 | for childrenI, children := range revision.GetAllChildren() { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 234 | BenchmarkProxy_Logger.Debugf("%schildrenIndex: %s, length: %d", prefix, childrenI, len(children)) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 235 | |
| 236 | for _, subrev := range children { |
| 237 | //subrev.GetBranch().Latest |
| 238 | traverseBranches(subrev, depth+1) |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | } |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 243 | func BenchmarkProxy_UpdateFlows(b *testing.B) { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 244 | b.RunParallel(func(pb *testing.PB) { |
| 245 | for pb.Next() { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 246 | if len(BenchmarkProxy_PLT.addedDevices) > 0 { |
| 247 | randomID := BenchmarkProxy_PLT.addedDevices[rand.Intn(len(BenchmarkProxy_PLT.addedDevices))] |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 248 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 249 | flowsProxy := BenchmarkProxy_Root.node.CreateProxy("/devices/"+randomID+"/flows", false) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 250 | flows := flowsProxy.Get("/", 0, false, "") |
| 251 | |
| 252 | before := flows.(*openflow_13.Flows).Items[0].TableId |
| 253 | flows.(*openflow_13.Flows).Items[0].TableId = uint32(rand.Intn(3000)) |
| 254 | after := flows.(*openflow_13.Flows).Items[0].TableId |
| 255 | |
| 256 | flowsProxy.RegisterCallback( |
| 257 | PRE_UPDATE, |
| 258 | commonCallback2, |
| 259 | ) |
| 260 | flowsProxy.RegisterCallback( |
| 261 | POST_UPDATE, |
| 262 | commonCallback2, |
| 263 | ) |
| 264 | |
| 265 | var updated interface{} |
| 266 | if updated = flowsProxy.Update("/", flows.(*openflow_13.Flows), false, ""); updated == nil { |
| 267 | b.Errorf("Failed to update flows for device: %+v", flows) |
| 268 | } else { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 269 | BenchmarkProxy_Logger.Infof("Flows were updated : %+v", updated) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 270 | } |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 271 | BenchmarkProxy_PLT.Lock() |
| 272 | BenchmarkProxy_PLT.updatedFlows = append( |
| 273 | BenchmarkProxy_PLT.updatedFlows, |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 274 | proxyLoadChanges{ID: randomID, Before: before, After: after}, |
| 275 | ) |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 276 | BenchmarkProxy_PLT.Unlock() |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | }) |
| 280 | } |
| 281 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 282 | func BenchmarkProxy_GetDevices(b *testing.B) { |
| 283 | //traverseBranches(BenchmarkProxy_DeviceProxy.Root.node.Branches[NONE].GetLatest(), 0) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 284 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 285 | for i := 0; i < len(BenchmarkProxy_PLT.addedDevices); i++ { |
| 286 | devToGet := BenchmarkProxy_PLT.addedDevices[i] |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 287 | // Verify that the added device can now be retrieved |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 288 | if d := BenchmarkProxy_DeviceProxy.Get("/devices/"+devToGet, 0, false, |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 289 | ""); !reflect.ValueOf(d).IsValid() { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 290 | BenchmarkProxy_Logger.Errorf("Failed to get device: %s", devToGet) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 291 | continue |
| 292 | } else { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 293 | BenchmarkProxy_Logger.Infof("Got device: %s %+v", devToGet, d) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 298 | func BenchmarkProxy_GetUpdatedFirmware(b *testing.B) { |
| 299 | for i := 0; i < len(BenchmarkProxy_PLT.updatedFirmwares); i++ { |
| 300 | devToGet := BenchmarkProxy_PLT.updatedFirmwares[i].ID |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 301 | // Verify that the updated device can be retrieved and that the updates were actually applied |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 302 | if d := BenchmarkProxy_DeviceProxy.Get("/devices/"+devToGet, 0, false, |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 303 | ""); !reflect.ValueOf(d).IsValid() { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 304 | BenchmarkProxy_Logger.Errorf("Failed to get device: %s", devToGet) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 305 | continue |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 306 | } else if d.(*voltha.Device).FirmwareVersion == BenchmarkProxy_PLT.updatedFirmwares[i].After.(string) { |
| 307 | BenchmarkProxy_Logger.Infof("Device was updated with new value: %s %+v", devToGet, d) |
| 308 | } else if d.(*voltha.Device).FirmwareVersion == BenchmarkProxy_PLT.updatedFirmwares[i].Before.(string) { |
| 309 | BenchmarkProxy_Logger.Errorf("Device kept old value: %s %+v %+v", devToGet, d, BenchmarkProxy_PLT.updatedFirmwares[i]) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 310 | } else { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 311 | BenchmarkProxy_Logger.Errorf("Device has unknown value: %s %+v %+v", devToGet, d, BenchmarkProxy_PLT.updatedFirmwares[i]) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 316 | func BenchmarkProxy_GetUpdatedFlows(b *testing.B) { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 317 | var d interface{} |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 318 | for i := 0; i < len(BenchmarkProxy_PLT.updatedFlows); i++ { |
| 319 | devToGet := BenchmarkProxy_PLT.updatedFlows[i].ID |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 320 | // Verify that the updated device can be retrieved and that the updates were actually applied |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 321 | flowsProxy := BenchmarkProxy_Root.node.CreateProxy("/devices/"+devToGet+"/flows", false) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 322 | if d = flowsProxy.Get("/", 0, false, |
| 323 | ""); !reflect.ValueOf(d).IsValid() { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 324 | BenchmarkProxy_Logger.Errorf("Failed to get device flows: %s", devToGet) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 325 | continue |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 326 | } else if d.(*openflow_13.Flows).Items[0].TableId == BenchmarkProxy_PLT.updatedFlows[i].After.(uint32) { |
| 327 | BenchmarkProxy_Logger.Infof("Device was updated with new flow value: %s %+v", devToGet, d) |
| 328 | } else if d.(*openflow_13.Flows).Items[0].TableId == BenchmarkProxy_PLT.updatedFlows[i].Before.(uint32) { |
| 329 | BenchmarkProxy_Logger.Errorf("Device kept old flow value: %s %+v %+v", devToGet, d, BenchmarkProxy_PLT.updatedFlows[i]) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 330 | } else { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 331 | BenchmarkProxy_Logger.Errorf("Device has unknown flow value: %s %+v %+v", devToGet, d, BenchmarkProxy_PLT.updatedFlows[i]) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 332 | } |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 333 | } |
| 334 | } |