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" |
| 21 | "encoding/json" |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 22 | "math/rand" |
| 23 | "reflect" |
| 24 | "strconv" |
| 25 | "testing" |
| 26 | "time" |
| 27 | |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 28 | "github.com/golang/protobuf/proto" |
| 29 | "github.com/google/uuid" |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 30 | "github.com/opencord/voltha-lib-go/v2/pkg/log" |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 31 | "github.com/opencord/voltha-protos/v2/go/common" |
| 32 | "github.com/opencord/voltha-protos/v2/go/openflow_13" |
| 33 | "github.com/opencord/voltha-protos/v2/go/voltha" |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 34 | "github.com/stretchr/testify/assert" |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 35 | ) |
| 36 | |
| 37 | var ( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 38 | TestProxyRoot Root |
| 39 | TestProxyRootLogicalDevice *Proxy |
| 40 | TestProxyRootDevice *Proxy |
| 41 | TestProxyRootAdapter *Proxy |
| 42 | TestProxyDeviceID string |
| 43 | TestProxyAdapterID string |
| 44 | TestProxyLogicalDeviceID string |
| 45 | TestProxyTargetDeviceID string |
| 46 | TestProxyTargetLogicalDeviceID string |
| 47 | TestProxyLogicalPorts []*voltha.LogicalPort |
| 48 | TestProxyPorts []*voltha.Port |
| 49 | TestProxyStats *openflow_13.OfpFlowStats |
| 50 | TestProxyFlows *openflow_13.Flows |
| 51 | TestProxyDevice *voltha.Device |
| 52 | TestProxyLogicalDevice *voltha.LogicalDevice |
| 53 | TestProxyAdapter *voltha.Adapter |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 54 | ) |
| 55 | |
| 56 | func init() { |
| 57 | //log.AddPackage(log.JSON, log.InfoLevel, log.Fields{"instanceId": "DB_MODEL"}) |
| 58 | //log.UpdateAllLoggers(log.Fields{"instanceId": "PROXY_LOAD_TEST"}) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 59 | var err error |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 60 | TestProxyRoot = NewRoot(&voltha.Voltha{}, nil) |
| 61 | if TestProxyRootLogicalDevice, err = TestProxyRoot.CreateProxy(context.Background(), "/", false); err != nil { |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 62 | log.With(log.Fields{"error": err}).Fatal("Cannot create logical device proxy") |
| 63 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 64 | if TestProxyRootDevice, err = TestProxyRoot.CreateProxy(context.Background(), "/", false); err != nil { |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 65 | log.With(log.Fields{"error": err}).Fatal("Cannot create device proxy") |
| 66 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 67 | if TestProxyRootAdapter, err = TestProxyRoot.CreateProxy(context.Background(), "/", false); err != nil { |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 68 | log.With(log.Fields{"error": err}).Fatal("Cannot create adapter proxy") |
| 69 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 70 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 71 | TestProxyLogicalPorts = []*voltha.LogicalPort{ |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 72 | { |
| 73 | Id: "123", |
| 74 | DeviceId: "logicalport-0-device-id", |
| 75 | DevicePortNo: 123, |
| 76 | RootPort: false, |
| 77 | }, |
| 78 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 79 | TestProxyPorts = []*voltha.Port{ |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 80 | { |
| 81 | PortNo: 123, |
| 82 | Label: "test-port-0", |
| 83 | Type: voltha.Port_PON_OLT, |
| 84 | AdminState: common.AdminState_ENABLED, |
| 85 | OperStatus: common.OperStatus_ACTIVE, |
| 86 | DeviceId: "etcd_port-0-device-id", |
| 87 | Peers: []*voltha.Port_PeerPort{}, |
| 88 | }, |
| 89 | } |
| 90 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 91 | TestProxyStats = &openflow_13.OfpFlowStats{ |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 92 | Id: 1111, |
| 93 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 94 | TestProxyFlows = &openflow_13.Flows{ |
| 95 | Items: []*openflow_13.OfpFlowStats{TestProxyStats}, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 96 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 97 | TestProxyDevice = &voltha.Device{ |
| 98 | Id: TestProxyDeviceID, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 99 | Type: "simulated_olt", |
| 100 | Address: &voltha.Device_HostAndPort{HostAndPort: "1.2.3.4:5555"}, |
| 101 | AdminState: voltha.AdminState_PREPROVISIONED, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 102 | Flows: TestProxyFlows, |
| 103 | Ports: TestProxyPorts, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 104 | } |
| 105 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 106 | TestProxyLogicalDevice = &voltha.LogicalDevice{ |
| 107 | Id: TestProxyDeviceID, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 108 | DatapathId: 0, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 109 | Ports: TestProxyLogicalPorts, |
| 110 | Flows: TestProxyFlows, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 111 | } |
| 112 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 113 | TestProxyAdapter = &voltha.Adapter{ |
| 114 | Id: TestProxyAdapterID, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 115 | Vendor: "test-adapter-vendor", |
| 116 | Version: "test-adapter-version", |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | func TestProxy_1_1_1_Add_NewDevice(t *testing.T) { |
| 121 | devIDBin, _ := uuid.New().MarshalBinary() |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 122 | TestProxyDeviceID = "0001" + hex.EncodeToString(devIDBin)[:12] |
| 123 | TestProxyDevice.Id = TestProxyDeviceID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 124 | |
| 125 | preAddExecuted := make(chan struct{}) |
| 126 | postAddExecuted := make(chan struct{}) |
| 127 | preAddExecutedPtr, postAddExecutedPtr := preAddExecuted, postAddExecuted |
| 128 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 129 | devicesProxy, err := TestProxyRoot.CreateProxy(context.Background(), "/devices", false) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 130 | if err != nil { |
| 131 | log.With(log.Fields{"error": err}).Fatal("Cannot create devices proxy") |
| 132 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 133 | devicesProxy.RegisterCallback(PreAdd, commonCallback2, "PRE_ADD Device container changes") |
| 134 | devicesProxy.RegisterCallback(PostAdd, commonCallback2, "POST_ADD Device container changes") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 135 | |
| 136 | // Register ADD instructions callbacks |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 137 | TestProxyRootDevice.RegisterCallback(PreAdd, commonChanCallback, "PreAdd instructions", &preAddExecutedPtr) |
| 138 | TestProxyRootDevice.RegisterCallback(PostAdd, commonChanCallback, "PostAdd instructions", &postAddExecutedPtr) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 139 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 140 | added, err := TestProxyRootDevice.Add(context.Background(), "/devices", TestProxyDevice, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 141 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 142 | BenchmarkProxyLogger.Errorf("Failed to add test proxy device due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 143 | assert.NotNil(t, err) |
| 144 | } |
| 145 | if added == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 146 | t.Error("Failed to add device") |
| 147 | } else { |
| 148 | t.Logf("Added device : %+v", added) |
| 149 | } |
| 150 | |
| 151 | if !verifyGotResponse(preAddExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 152 | t.Error("PreAdd callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 153 | } |
| 154 | if !verifyGotResponse(postAddExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 155 | t.Error("PostAdd callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | // Verify that the added device can now be retrieved |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 159 | d, err := TestProxyRootDevice.Get(context.Background(), "/devices/"+TestProxyDeviceID, 0, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 160 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 161 | BenchmarkProxyLogger.Errorf("Failed get device info from test proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 162 | assert.NotNil(t, err) |
| 163 | } |
| 164 | if !reflect.ValueOf(d).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 165 | t.Error("Failed to find added device") |
| 166 | } else { |
| 167 | djson, _ := json.Marshal(d) |
| 168 | t.Logf("Found device: %s", string(djson)) |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | func TestProxy_1_1_2_Add_ExistingDevice(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 173 | TestProxyDevice.Id = TestProxyDeviceID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 174 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 175 | added, err := TestProxyRootDevice.Add(context.Background(), "/devices", TestProxyDevice, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 176 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 177 | BenchmarkProxyLogger.Errorf("Failed to add device to test proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 178 | assert.NotNil(t, err) |
| 179 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 180 | if added.(proto.Message).String() != reflect.ValueOf(TestProxyDevice).Interface().(proto.Message).String() { |
| 181 | t.Errorf("Devices don't match - existing: %+v returned: %+v", TestProxyLogicalDevice, added) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
| 185 | func verifyGotResponse(callbackIndicator <-chan struct{}) bool { |
| 186 | timeout := time.After(1 * time.Second) |
| 187 | // Wait until the channel closes, or we time out |
| 188 | select { |
| 189 | case <-callbackIndicator: |
| 190 | // Received response successfully |
| 191 | return true |
| 192 | |
| 193 | case <-timeout: |
| 194 | // Got a timeout! fail with a timeout error |
| 195 | return false |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | func TestProxy_1_1_3_Add_NewAdapter(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 200 | TestProxyAdapterID = "test-adapter" |
| 201 | TestProxyAdapter.Id = TestProxyAdapterID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 202 | preAddExecuted := make(chan struct{}) |
| 203 | postAddExecuted := make(chan struct{}) |
| 204 | preAddExecutedPtr, postAddExecutedPtr := preAddExecuted, postAddExecuted |
| 205 | |
| 206 | // Register ADD instructions callbacks |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 207 | TestProxyRootAdapter.RegisterCallback(PreAdd, commonChanCallback, "PreAdd instructions for adapters", &preAddExecutedPtr) |
| 208 | TestProxyRootAdapter.RegisterCallback(PostAdd, commonChanCallback, "PostAdd instructions for adapters", &postAddExecutedPtr) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 209 | |
| 210 | // Add the adapter |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 211 | added, err := TestProxyRootAdapter.Add(context.Background(), "/adapters", TestProxyAdapter, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 212 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 213 | BenchmarkProxyLogger.Errorf("Failed to add adapter to test proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 214 | assert.NotNil(t, err) |
| 215 | } |
| 216 | if added == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 217 | t.Error("Failed to add adapter") |
| 218 | } else { |
| 219 | t.Logf("Added adapter : %+v", added) |
| 220 | } |
| 221 | |
| 222 | verifyGotResponse(postAddExecuted) |
| 223 | |
| 224 | // Verify that the added device can now be retrieved |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 225 | d, err := TestProxyRootAdapter.Get(context.Background(), "/adapters/"+TestProxyAdapterID, 0, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 226 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 227 | BenchmarkProxyLogger.Errorf("Failed to retrieve device info from test proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 228 | assert.NotNil(t, err) |
| 229 | } |
| 230 | if !reflect.ValueOf(d).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 231 | t.Error("Failed to find added adapter") |
| 232 | } else { |
| 233 | djson, _ := json.Marshal(d) |
| 234 | t.Logf("Found adapter: %s", string(djson)) |
| 235 | } |
| 236 | |
| 237 | if !verifyGotResponse(preAddExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 238 | t.Error("PreAdd callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 239 | } |
| 240 | if !verifyGotResponse(postAddExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 241 | t.Error("PostAdd callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
| 245 | func TestProxy_1_2_1_Get_AllDevices(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 246 | devices, err := TestProxyRootDevice.Get(context.Background(), "/devices", 1, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 247 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 248 | BenchmarkProxyLogger.Errorf("Failed to get all devices info from test proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 249 | assert.NotNil(t, err) |
| 250 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 251 | if len(devices.([]interface{})) == 0 { |
| 252 | t.Error("there are no available devices to retrieve") |
| 253 | } else { |
| 254 | // Save the target device id for later tests |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 255 | TestProxyTargetDeviceID = devices.([]interface{})[0].(*voltha.Device).Id |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 256 | t.Logf("retrieved all devices: %+v", devices) |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | func TestProxy_1_2_2_Get_SingleDevice(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 261 | d, err := TestProxyRootDevice.Get(context.Background(), "/devices/"+TestProxyTargetDeviceID, 0, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 262 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 263 | BenchmarkProxyLogger.Errorf("Failed to get single device info from test proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 264 | assert.NotNil(t, err) |
| 265 | } |
| 266 | if !reflect.ValueOf(d).IsValid() { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 267 | t.Errorf("Failed to find device : %s", TestProxyTargetDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 268 | } else { |
| 269 | djson, _ := json.Marshal(d) |
| 270 | t.Logf("Found device: %s", string(djson)) |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | func TestProxy_1_3_1_Update_Device(t *testing.T) { |
| 275 | var fwVersion int |
| 276 | |
| 277 | preUpdateExecuted := make(chan struct{}) |
| 278 | postUpdateExecuted := make(chan struct{}) |
| 279 | preUpdateExecutedPtr, postUpdateExecutedPtr := preUpdateExecuted, postUpdateExecuted |
| 280 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 281 | retrieved, err := TestProxyRootDevice.Get(context.Background(), "/devices/"+TestProxyTargetDeviceID, 1, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 282 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 283 | BenchmarkProxyLogger.Errorf("Failed to get device info from test proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 284 | assert.NotNil(t, err) |
| 285 | } |
| 286 | if retrieved == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 287 | t.Error("Failed to get device") |
| 288 | } else { |
| 289 | t.Logf("Found raw device (root proxy): %+v", retrieved) |
| 290 | |
| 291 | if retrieved.(*voltha.Device).FirmwareVersion == "n/a" { |
| 292 | fwVersion = 0 |
| 293 | } else { |
| 294 | fwVersion, _ = strconv.Atoi(retrieved.(*voltha.Device).FirmwareVersion) |
| 295 | fwVersion++ |
| 296 | } |
| 297 | |
| 298 | retrieved.(*voltha.Device).FirmwareVersion = strconv.Itoa(fwVersion) |
| 299 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 300 | TestProxyRootDevice.RegisterCallback( |
| 301 | PreUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 302 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 303 | "PreUpdate instructions (root proxy)", &preUpdateExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 304 | ) |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 305 | TestProxyRootDevice.RegisterCallback( |
| 306 | PostUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 307 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 308 | "PostUpdate instructions (root proxy)", &postUpdateExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 309 | ) |
| 310 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 311 | afterUpdate, err := TestProxyRootDevice.Update(context.Background(), "/devices/"+TestProxyTargetDeviceID, retrieved, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 312 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 313 | BenchmarkProxyLogger.Errorf("Failed to update device info test proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 314 | assert.NotNil(t, err) |
| 315 | } |
| 316 | if afterUpdate == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 317 | t.Error("Failed to update device") |
| 318 | } else { |
| 319 | t.Logf("Updated device : %+v", afterUpdate) |
| 320 | } |
| 321 | |
| 322 | if !verifyGotResponse(preUpdateExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 323 | t.Error("PreUpdate callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 324 | } |
| 325 | if !verifyGotResponse(postUpdateExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 326 | t.Error("PostUpdate callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 327 | } |
| 328 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 329 | d, err := TestProxyRootDevice.Get(context.Background(), "/devices/"+TestProxyTargetDeviceID, 1, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 330 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 331 | BenchmarkProxyLogger.Errorf("Failed to get device info from test proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 332 | assert.NotNil(t, err) |
| 333 | } |
| 334 | if !reflect.ValueOf(d).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 335 | t.Error("Failed to find updated device (root proxy)") |
| 336 | } else { |
| 337 | djson, _ := json.Marshal(d) |
| 338 | t.Logf("Found device (root proxy): %s raw: %+v", string(djson), d) |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | func TestProxy_1_3_2_Update_DeviceFlows(t *testing.T) { |
| 344 | // Get a device proxy and update a specific port |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 345 | devFlowsProxy, err := TestProxyRoot.CreateProxy(context.Background(), "/devices/"+TestProxyDeviceID+"/flows", false) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 346 | if err != nil { |
| 347 | log.With(log.Fields{"error": err}).Fatal("Cannot create device flows proxy") |
| 348 | } |
| 349 | flows, err := devFlowsProxy.Get(context.Background(), "/", 0, false, "") |
| 350 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 351 | BenchmarkProxyLogger.Errorf("Failed to get flows from device flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 352 | assert.NotNil(t, err) |
| 353 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 354 | flows.(*openflow_13.Flows).Items[0].TableId = 2244 |
| 355 | |
| 356 | preUpdateExecuted := make(chan struct{}) |
| 357 | postUpdateExecuted := make(chan struct{}) |
| 358 | preUpdateExecutedPtr, postUpdateExecutedPtr := preUpdateExecuted, postUpdateExecuted |
| 359 | |
| 360 | devFlowsProxy.RegisterCallback( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 361 | PreUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 362 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 363 | "PreUpdate instructions (flows proxy)", &preUpdateExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 364 | ) |
| 365 | devFlowsProxy.RegisterCallback( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 366 | PostUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 367 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 368 | "PostUpdate instructions (flows proxy)", &postUpdateExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 369 | ) |
| 370 | |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 371 | kvFlows, err := devFlowsProxy.Get(context.Background(), "/", 0, false, "") |
| 372 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 373 | BenchmarkProxyLogger.Errorf("Failed to get flows from device flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 374 | assert.NotNil(t, err) |
| 375 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 376 | |
| 377 | if reflect.DeepEqual(flows, kvFlows) { |
| 378 | t.Errorf("Local changes have changed the KV store contents - local:%+v, kv: %+v", flows, kvFlows) |
| 379 | } |
| 380 | |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 381 | updated, err := devFlowsProxy.Update(context.Background(), "/", flows.(*openflow_13.Flows), false, "") |
| 382 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 383 | BenchmarkProxyLogger.Errorf("Failed to update flows in device flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 384 | assert.NotNil(t, err) |
| 385 | } |
| 386 | if updated == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 387 | t.Error("Failed to update flow") |
| 388 | } else { |
| 389 | t.Logf("Updated flows : %+v", updated) |
| 390 | } |
| 391 | |
| 392 | if !verifyGotResponse(preUpdateExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 393 | t.Error("PreUpdate callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 394 | } |
| 395 | if !verifyGotResponse(postUpdateExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 396 | t.Error("PostUpdate callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 397 | } |
| 398 | |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 399 | d, err := devFlowsProxy.Get(context.Background(), "/", 0, false, "") |
| 400 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 401 | BenchmarkProxyLogger.Errorf("Failed to get flows in device flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 402 | assert.NotNil(t, err) |
| 403 | } |
| 404 | if d == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 405 | t.Error("Failed to find updated flows (flows proxy)") |
| 406 | } else { |
| 407 | djson, _ := json.Marshal(d) |
| 408 | t.Logf("Found flows (flows proxy): %s", string(djson)) |
| 409 | } |
| 410 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 411 | d, err = TestProxyRootDevice.Get(context.Background(), "/devices/"+TestProxyDeviceID+"/flows", 1, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 412 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 413 | BenchmarkProxyLogger.Errorf("Failed to get flows from device flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 414 | assert.NotNil(t, err) |
| 415 | } |
| 416 | if !reflect.ValueOf(d).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 417 | t.Error("Failed to find updated flows (root proxy)") |
| 418 | } else { |
| 419 | djson, _ := json.Marshal(d) |
| 420 | t.Logf("Found flows (root proxy): %s", string(djson)) |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | func TestProxy_1_3_3_Update_Adapter(t *testing.T) { |
| 425 | preUpdateExecuted := make(chan struct{}) |
| 426 | postUpdateExecuted := make(chan struct{}) |
| 427 | preUpdateExecutedPtr, postUpdateExecutedPtr := preUpdateExecuted, postUpdateExecuted |
| 428 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 429 | adaptersProxy, err := TestProxyRoot.CreateProxy(context.Background(), "/adapters", false) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 430 | if err != nil { |
| 431 | log.With(log.Fields{"error": err}).Fatal("Cannot create adapters proxy") |
| 432 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 433 | retrieved, err := TestProxyRootAdapter.Get(context.Background(), "/adapters/"+TestProxyAdapterID, 1, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 434 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 435 | BenchmarkProxyLogger.Errorf("Failed to retrieve adapter info from adapters proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 436 | assert.NotNil(t, err) |
| 437 | } |
| 438 | if retrieved == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 439 | t.Error("Failed to get adapter") |
| 440 | } else { |
| 441 | t.Logf("Found raw adapter (root proxy): %+v", retrieved) |
| 442 | |
| 443 | retrieved.(*voltha.Adapter).Version = "test-adapter-version-2" |
| 444 | |
| 445 | adaptersProxy.RegisterCallback( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 446 | PreUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 447 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 448 | "PreUpdate instructions for adapters", &preUpdateExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 449 | ) |
| 450 | adaptersProxy.RegisterCallback( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 451 | PostUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 452 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 453 | "PostUpdate instructions for adapters", &postUpdateExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 454 | ) |
| 455 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 456 | afterUpdate, err := adaptersProxy.Update(context.Background(), "/"+TestProxyAdapterID, retrieved, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 457 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 458 | BenchmarkProxyLogger.Errorf("Failed to update adapter info in adapters proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 459 | assert.NotNil(t, err) |
| 460 | } |
| 461 | if afterUpdate == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 462 | t.Error("Failed to update adapter") |
| 463 | } else { |
| 464 | t.Logf("Updated adapter : %+v", afterUpdate) |
| 465 | } |
| 466 | |
| 467 | if !verifyGotResponse(preUpdateExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 468 | t.Error("PreUpdate callback for adapter was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 469 | } |
| 470 | if !verifyGotResponse(postUpdateExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 471 | t.Error("PostUpdate callback for adapter was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 472 | } |
| 473 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 474 | d, err := TestProxyRootAdapter.Get(context.Background(), "/adapters/"+TestProxyAdapterID, 1, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 475 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 476 | BenchmarkProxyLogger.Errorf("Failed to get updated adapter info from adapters proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 477 | assert.NotNil(t, err) |
| 478 | } |
| 479 | if !reflect.ValueOf(d).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 480 | t.Error("Failed to find updated adapter (root proxy)") |
| 481 | } else { |
| 482 | djson, _ := json.Marshal(d) |
| 483 | t.Logf("Found adapter (root proxy): %s raw: %+v", string(djson), d) |
| 484 | } |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | func TestProxy_1_4_1_Remove_Device(t *testing.T) { |
| 489 | preRemoveExecuted := make(chan struct{}) |
| 490 | postRemoveExecuted := make(chan struct{}) |
| 491 | preRemoveExecutedPtr, postRemoveExecutedPtr := preRemoveExecuted, postRemoveExecuted |
| 492 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 493 | TestProxyRootDevice.RegisterCallback( |
| 494 | PreRemove, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 495 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 496 | "PreRemove instructions (root proxy)", &preRemoveExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 497 | ) |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 498 | TestProxyRootDevice.RegisterCallback( |
| 499 | PostRemove, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 500 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 501 | "PostRemove instructions (root proxy)", &postRemoveExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 502 | ) |
| 503 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 504 | removed, err := TestProxyRootDevice.Remove(context.Background(), "/devices/"+TestProxyDeviceID, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 505 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 506 | BenchmarkProxyLogger.Errorf("Failed to remove device from devices proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 507 | assert.NotNil(t, err) |
| 508 | } |
| 509 | if removed == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 510 | t.Error("Failed to remove device") |
| 511 | } else { |
| 512 | t.Logf("Removed device : %+v", removed) |
| 513 | } |
| 514 | |
| 515 | if !verifyGotResponse(preRemoveExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 516 | t.Error("PreRemove callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 517 | } |
| 518 | if !verifyGotResponse(postRemoveExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 519 | t.Error("PostRemove callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 520 | } |
| 521 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 522 | d, err := TestProxyRootDevice.Get(context.Background(), "/devices/"+TestProxyDeviceID, 0, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 523 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 524 | BenchmarkProxyLogger.Errorf("Failed to get device info from devices proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 525 | assert.NotNil(t, err) |
| 526 | } |
| 527 | if reflect.ValueOf(d).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 528 | djson, _ := json.Marshal(d) |
| 529 | t.Errorf("Device was not removed - %s", djson) |
| 530 | } else { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 531 | t.Logf("Device was removed: %s", TestProxyDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 532 | } |
| 533 | } |
| 534 | |
| 535 | func TestProxy_2_1_1_Add_NewLogicalDevice(t *testing.T) { |
| 536 | |
| 537 | ldIDBin, _ := uuid.New().MarshalBinary() |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 538 | TestProxyLogicalDeviceID = "0001" + hex.EncodeToString(ldIDBin)[:12] |
| 539 | TestProxyLogicalDevice.Id = TestProxyLogicalDeviceID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 540 | |
| 541 | preAddExecuted := make(chan struct{}) |
| 542 | postAddExecuted := make(chan struct{}) |
| 543 | preAddExecutedPtr, postAddExecutedPtr := preAddExecuted, postAddExecuted |
| 544 | |
| 545 | // Register |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 546 | TestProxyRootLogicalDevice.RegisterCallback(PreAdd, commonChanCallback, "PreAdd instructions", &preAddExecutedPtr) |
| 547 | TestProxyRootLogicalDevice.RegisterCallback(PostAdd, commonChanCallback, "PostAdd instructions", &postAddExecutedPtr) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 548 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 549 | added, err := TestProxyRootLogicalDevice.Add(context.Background(), "/logical_devices", TestProxyLogicalDevice, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 550 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 551 | BenchmarkProxyLogger.Errorf("Failed to add new logical device into proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 552 | assert.NotNil(t, err) |
| 553 | } |
| 554 | if added == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 555 | t.Error("Failed to add logical device") |
| 556 | } else { |
| 557 | t.Logf("Added logical device : %+v", added) |
| 558 | } |
| 559 | |
| 560 | verifyGotResponse(postAddExecuted) |
| 561 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 562 | ld, err := TestProxyRootLogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxyLogicalDeviceID, 0, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 563 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 564 | BenchmarkProxyLogger.Errorf("Failed to get logical device info from logical device proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 565 | assert.NotNil(t, err) |
| 566 | } |
| 567 | if !reflect.ValueOf(ld).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 568 | t.Error("Failed to find added logical device") |
| 569 | } else { |
| 570 | ldJSON, _ := json.Marshal(ld) |
| 571 | t.Logf("Found logical device: %s", string(ldJSON)) |
| 572 | } |
| 573 | |
| 574 | if !verifyGotResponse(preAddExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 575 | t.Error("PreAdd callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 576 | } |
| 577 | if !verifyGotResponse(postAddExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 578 | t.Error("PostAdd callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | |
| 582 | func TestProxy_2_1_2_Add_ExistingLogicalDevice(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 583 | TestProxyLogicalDevice.Id = TestProxyLogicalDeviceID |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 584 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 585 | added, err := TestProxyRootLogicalDevice.Add(context.Background(), "/logical_devices", TestProxyLogicalDevice, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 586 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 587 | BenchmarkProxyLogger.Errorf("Failed to add logical device due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 588 | assert.NotNil(t, err) |
| 589 | } |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 590 | if added.(proto.Message).String() != reflect.ValueOf(TestProxyLogicalDevice).Interface().(proto.Message).String() { |
| 591 | t.Errorf("Logical devices don't match - existing: %+v returned: %+v", TestProxyLogicalDevice, added) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 592 | } |
| 593 | } |
| 594 | |
| 595 | func TestProxy_2_2_1_Get_AllLogicalDevices(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 596 | logicalDevices, err := TestProxyRootLogicalDevice.Get(context.Background(), "/logical_devices", 1, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 597 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 598 | BenchmarkProxyLogger.Errorf("Failed to get all logical devices from proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 599 | assert.NotNil(t, err) |
| 600 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 601 | if len(logicalDevices.([]interface{})) == 0 { |
| 602 | t.Error("there are no available logical devices to retrieve") |
| 603 | } else { |
| 604 | // Save the target device id for later tests |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 605 | TestProxyTargetLogicalDeviceID = logicalDevices.([]interface{})[0].(*voltha.LogicalDevice).Id |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 606 | t.Logf("retrieved all logical devices: %+v", logicalDevices) |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | func TestProxy_2_2_2_Get_SingleLogicalDevice(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 611 | ld, err := TestProxyRootLogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxyTargetLogicalDeviceID, 0, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 612 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 613 | BenchmarkProxyLogger.Errorf("Failed to get single logical device from proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 614 | assert.NotNil(t, err) |
| 615 | } |
| 616 | if !reflect.ValueOf(ld).IsValid() { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 617 | t.Errorf("Failed to find logical device : %s", TestProxyTargetLogicalDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 618 | } else { |
| 619 | ldJSON, _ := json.Marshal(ld) |
| 620 | t.Logf("Found logical device: %s", string(ldJSON)) |
| 621 | } |
| 622 | |
| 623 | } |
| 624 | |
| 625 | func TestProxy_2_3_1_Update_LogicalDevice(t *testing.T) { |
| 626 | var fwVersion int |
| 627 | preUpdateExecuted := make(chan struct{}) |
| 628 | postUpdateExecuted := make(chan struct{}) |
| 629 | preUpdateExecutedPtr, postUpdateExecutedPtr := preUpdateExecuted, postUpdateExecuted |
| 630 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 631 | retrieved, err := TestProxyRootLogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxyTargetLogicalDeviceID, 1, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 632 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 633 | BenchmarkProxyLogger.Errorf("Failed to get logical devices due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 634 | assert.NotNil(t, err) |
| 635 | } |
| 636 | if retrieved == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 637 | t.Error("Failed to get logical device") |
| 638 | } else { |
| 639 | t.Logf("Found raw logical device (root proxy): %+v", retrieved) |
| 640 | |
| 641 | if retrieved.(*voltha.LogicalDevice).RootDeviceId == "" { |
| 642 | fwVersion = 0 |
| 643 | } else { |
| 644 | fwVersion, _ = strconv.Atoi(retrieved.(*voltha.LogicalDevice).RootDeviceId) |
| 645 | fwVersion++ |
| 646 | } |
| 647 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 648 | TestProxyRootLogicalDevice.RegisterCallback( |
| 649 | PreUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 650 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 651 | "PreUpdate instructions (root proxy)", &preUpdateExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 652 | ) |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 653 | TestProxyRootLogicalDevice.RegisterCallback( |
| 654 | PostUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 655 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 656 | "PostUpdate instructions (root proxy)", &postUpdateExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 657 | ) |
| 658 | |
| 659 | retrieved.(*voltha.LogicalDevice).RootDeviceId = strconv.Itoa(fwVersion) |
| 660 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 661 | afterUpdate, err := TestProxyRootLogicalDevice.Update(context.Background(), "/logical_devices/"+TestProxyTargetLogicalDeviceID, retrieved, false, |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 662 | "") |
| 663 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 664 | BenchmarkProxyLogger.Errorf("Faield to update logical device info due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 665 | assert.NotNil(t, err) |
| 666 | } |
| 667 | if afterUpdate == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 668 | t.Error("Failed to update logical device") |
| 669 | } else { |
| 670 | t.Logf("Updated logical device : %+v", afterUpdate) |
| 671 | } |
| 672 | |
| 673 | if !verifyGotResponse(preUpdateExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 674 | t.Error("PreUpdate callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 675 | } |
| 676 | if !verifyGotResponse(postUpdateExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 677 | t.Error("PostUpdate callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 678 | } |
| 679 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 680 | d, err := TestProxyRootLogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxyTargetLogicalDeviceID, 1, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 681 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 682 | BenchmarkProxyLogger.Errorf("Failed to get logical device info due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 683 | assert.NotNil(t, err) |
| 684 | } |
| 685 | if !reflect.ValueOf(d).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 686 | t.Error("Failed to find updated logical device (root proxy)") |
| 687 | } else { |
| 688 | djson, _ := json.Marshal(d) |
| 689 | |
| 690 | t.Logf("Found logical device (root proxy): %s raw: %+v", string(djson), d) |
| 691 | } |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | func TestProxy_2_3_2_Update_LogicalDeviceFlows(t *testing.T) { |
| 696 | // Get a device proxy and update a specific port |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 697 | ldFlowsProxy, err := TestProxyRoot.CreateProxy(context.Background(), "/logical_devices/"+TestProxyLogicalDeviceID+"/flows", false) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 698 | if err != nil { |
| 699 | log.With(log.Fields{"error": err}).Fatal("Failed to create logical device flows proxy") |
| 700 | } |
| 701 | flows, err := ldFlowsProxy.Get(context.Background(), "/", 0, false, "") |
| 702 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 703 | BenchmarkProxyLogger.Errorf("Failed to get flows from logical device flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 704 | assert.NotNil(t, err) |
| 705 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 706 | flows.(*openflow_13.Flows).Items[0].TableId = rand.Uint32() |
| 707 | t.Logf("before updated flows: %+v", flows) |
| 708 | |
| 709 | ldFlowsProxy.RegisterCallback( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 710 | PreUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 711 | commonCallback2, |
| 712 | ) |
| 713 | ldFlowsProxy.RegisterCallback( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 714 | PostUpdate, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 715 | commonCallback2, |
| 716 | ) |
| 717 | |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 718 | kvFlows, err := ldFlowsProxy.Get(context.Background(), "/", 0, false, "") |
| 719 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 720 | BenchmarkProxyLogger.Errorf("Faield to get flows from logical device flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 721 | assert.NotNil(t, err) |
| 722 | } |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 723 | if reflect.DeepEqual(flows, kvFlows) { |
| 724 | t.Errorf("Local changes have changed the KV store contents - local:%+v, kv: %+v", flows, kvFlows) |
| 725 | } |
| 726 | |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 727 | updated, err := ldFlowsProxy.Update(context.Background(), "/", flows.(*openflow_13.Flows), false, "") |
| 728 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 729 | BenchmarkProxyLogger.Errorf("Failed to update flows in logical device flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 730 | assert.NotNil(t, err) |
| 731 | } |
| 732 | if updated == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 733 | t.Error("Failed to update logical device flows") |
| 734 | } else { |
| 735 | t.Logf("Updated logical device flows : %+v", updated) |
| 736 | } |
| 737 | |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 738 | if d, _ := ldFlowsProxy.Get(context.Background(), "/", 0, false, ""); d == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 739 | t.Error("Failed to find updated logical device flows (flows proxy)") |
| 740 | } else { |
| 741 | djson, _ := json.Marshal(d) |
| 742 | t.Logf("Found flows (flows proxy): %s", string(djson)) |
| 743 | } |
| 744 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 745 | d, err := TestProxyRootLogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxyLogicalDeviceID+"/flows", 0, false, |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 746 | "") |
| 747 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 748 | BenchmarkProxyLogger.Errorf("Failed to get flows from logical device flows proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 749 | assert.NotNil(t, err) |
| 750 | } |
| 751 | if !reflect.ValueOf(d).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 752 | t.Error("Failed to find updated logical device flows (root proxy)") |
| 753 | } else { |
| 754 | djson, _ := json.Marshal(d) |
| 755 | t.Logf("Found logical device flows (root proxy): %s", string(djson)) |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | func TestProxy_2_4_1_Remove_Device(t *testing.T) { |
| 760 | preRemoveExecuted := make(chan struct{}) |
| 761 | postRemoveExecuted := make(chan struct{}) |
| 762 | preRemoveExecutedPtr, postRemoveExecutedPtr := preRemoveExecuted, postRemoveExecuted |
| 763 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 764 | TestProxyRootLogicalDevice.RegisterCallback( |
| 765 | PreRemove, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 766 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 767 | "PreRemove instructions (root proxy)", &preRemoveExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 768 | ) |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 769 | TestProxyRootLogicalDevice.RegisterCallback( |
| 770 | PostRemove, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 771 | commonChanCallback, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 772 | "PostRemove instructions (root proxy)", &postRemoveExecutedPtr, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 773 | ) |
| 774 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 775 | removed, err := TestProxyRootLogicalDevice.Remove(context.Background(), "/logical_devices/"+TestProxyLogicalDeviceID, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 776 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 777 | BenchmarkProxyLogger.Errorf("Failed to remove device from logical devices proxy due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 778 | assert.NotNil(t, err) |
| 779 | } |
| 780 | if removed == nil { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 781 | t.Error("Failed to remove logical device") |
| 782 | } else { |
| 783 | t.Logf("Removed device : %+v", removed) |
| 784 | } |
| 785 | |
| 786 | if !verifyGotResponse(preRemoveExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 787 | t.Error("PreRemove callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 788 | } |
| 789 | if !verifyGotResponse(postRemoveExecuted) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 790 | t.Error("PostRemove callback was not executed") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 791 | } |
| 792 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 793 | d, err := TestProxyRootLogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxyLogicalDeviceID, 0, false, "") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 794 | if err != nil { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 795 | BenchmarkProxyLogger.Errorf("Failed to get logical device info due to error: %v", err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 796 | assert.NotNil(t, err) |
| 797 | } |
| 798 | if reflect.ValueOf(d).IsValid() { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 799 | djson, _ := json.Marshal(d) |
| 800 | t.Errorf("Device was not removed - %s", djson) |
| 801 | } else { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 802 | t.Logf("Device was removed: %s", TestProxyLogicalDeviceID) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 803 | } |
| 804 | } |
| 805 | |
| 806 | // ----------------------------- |
| 807 | // Callback tests |
| 808 | // ----------------------------- |
| 809 | |
| 810 | func TestProxy_Callbacks_1_Register(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 811 | TestProxyRootDevice.RegisterCallback(PreAdd, firstCallback, "abcde", "12345") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 812 | |
| 813 | m := make(map[string]string) |
| 814 | m["name"] = "fghij" |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 815 | TestProxyRootDevice.RegisterCallback(PreAdd, secondCallback, m, 1.2345) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 816 | |
| 817 | d := &voltha.Device{Id: "12345"} |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 818 | TestProxyRootDevice.RegisterCallback(PreAdd, thirdCallback, "klmno", d) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | func TestProxy_Callbacks_2_Invoke_WithNoInterruption(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 822 | TestProxyRootDevice.InvokeCallbacks(PreAdd, false, nil) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | func TestProxy_Callbacks_3_Invoke_WithInterruption(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 826 | TestProxyRootDevice.InvokeCallbacks(PreAdd, true, nil) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | func TestProxy_Callbacks_4_Unregister(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 830 | TestProxyRootDevice.UnregisterCallback(PreAdd, firstCallback) |
| 831 | TestProxyRootDevice.UnregisterCallback(PreAdd, secondCallback) |
| 832 | TestProxyRootDevice.UnregisterCallback(PreAdd, thirdCallback) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | //func TestProxy_Callbacks_5_Add(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 836 | // TestProxyRootDevice.Root.AddCallback(TestProxyRootDevice.InvokeCallbacks, PostUpdate, false, "some data", "some new data") |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 837 | //} |
| 838 | // |
| 839 | //func TestProxy_Callbacks_6_Execute(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame^] | 840 | // TestProxyRootDevice.Root.ExecuteCallbacks() |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 841 | //} |