Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package model |
| 17 | |
| 18 | import ( |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 19 | "encoding/hex" |
| 20 | "encoding/json" |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 21 | "github.com/golang/protobuf/proto" |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 22 | "github.com/google/uuid" |
William Kurkian | daa6bb2 | 2019-03-07 12:26:28 -0500 | [diff] [blame] | 23 | "github.com/opencord/voltha-protos/go/common" |
| 24 | "github.com/opencord/voltha-protos/go/openflow_13" |
| 25 | "github.com/opencord/voltha-protos/go/voltha" |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 26 | "math/rand" |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 27 | "reflect" |
| 28 | "strconv" |
| 29 | "testing" |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 30 | ) |
| 31 | |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 32 | var ( |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 33 | TestProxy_Root *root |
| 34 | TestProxy_Root_LogicalDevice *Proxy |
| 35 | TestProxy_Root_Device *Proxy |
Stephane Barbarie | aa46794 | 2019-02-06 14:09:44 -0500 | [diff] [blame] | 36 | TestProxy_Root_Adapter *Proxy |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 37 | TestProxy_DeviceId string |
Stephane Barbarie | aa46794 | 2019-02-06 14:09:44 -0500 | [diff] [blame] | 38 | TestProxy_AdapterId string |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 39 | TestProxy_LogicalDeviceId string |
| 40 | TestProxy_TargetDeviceId string |
| 41 | TestProxy_TargetLogicalDeviceId string |
| 42 | TestProxy_LogicalPorts []*voltha.LogicalPort |
| 43 | TestProxy_Ports []*voltha.Port |
| 44 | TestProxy_Stats *openflow_13.OfpFlowStats |
| 45 | TestProxy_Flows *openflow_13.Flows |
| 46 | TestProxy_Device *voltha.Device |
| 47 | TestProxy_LogicalDevice *voltha.LogicalDevice |
Stephane Barbarie | aa46794 | 2019-02-06 14:09:44 -0500 | [diff] [blame] | 48 | TestProxy_Adapter *voltha.Adapter |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 49 | ) |
| 50 | |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 51 | func init() { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 52 | //log.AddPackage(log.JSON, log.InfoLevel, log.Fields{"instanceId": "DB_MODEL"}) |
| 53 | //log.UpdateAllLoggers(log.Fields{"instanceId": "PROXY_LOAD_TEST"}) |
| 54 | TestProxy_Root = NewRoot(&voltha.Voltha{}, nil) |
| 55 | TestProxy_Root_LogicalDevice = TestProxy_Root.CreateProxy("/", false) |
| 56 | TestProxy_Root_Device = TestProxy_Root.CreateProxy("/", false) |
Stephane Barbarie | aa46794 | 2019-02-06 14:09:44 -0500 | [diff] [blame] | 57 | TestProxy_Root_Adapter = TestProxy_Root.CreateProxy("/", false) |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 58 | |
| 59 | TestProxy_LogicalPorts = []*voltha.LogicalPort{ |
| 60 | { |
| 61 | Id: "123", |
| 62 | DeviceId: "logicalport-0-device-id", |
| 63 | DevicePortNo: 123, |
| 64 | RootPort: false, |
| 65 | }, |
| 66 | } |
| 67 | TestProxy_Ports = []*voltha.Port{ |
| 68 | { |
| 69 | PortNo: 123, |
| 70 | Label: "test-port-0", |
| 71 | Type: voltha.Port_PON_OLT, |
| 72 | AdminState: common.AdminState_ENABLED, |
| 73 | OperStatus: common.OperStatus_ACTIVE, |
| 74 | DeviceId: "etcd_port-0-device-id", |
| 75 | Peers: []*voltha.Port_PeerPort{}, |
| 76 | }, |
| 77 | } |
| 78 | |
| 79 | TestProxy_Stats = &openflow_13.OfpFlowStats{ |
| 80 | Id: 1111, |
| 81 | } |
| 82 | TestProxy_Flows = &openflow_13.Flows{ |
| 83 | Items: []*openflow_13.OfpFlowStats{TestProxy_Stats}, |
| 84 | } |
| 85 | TestProxy_Device = &voltha.Device{ |
| 86 | Id: TestProxy_DeviceId, |
| 87 | Type: "simulated_olt", |
| 88 | Address: &voltha.Device_HostAndPort{HostAndPort: "1.2.3.4:5555"}, |
| 89 | AdminState: voltha.AdminState_PREPROVISIONED, |
| 90 | Flows: TestProxy_Flows, |
| 91 | Ports: TestProxy_Ports, |
| 92 | } |
| 93 | |
| 94 | TestProxy_LogicalDevice = &voltha.LogicalDevice{ |
| 95 | Id: TestProxy_DeviceId, |
| 96 | DatapathId: 0, |
| 97 | Ports: TestProxy_LogicalPorts, |
| 98 | Flows: TestProxy_Flows, |
| 99 | } |
Stephane Barbarie | aa46794 | 2019-02-06 14:09:44 -0500 | [diff] [blame] | 100 | |
| 101 | TestProxy_Adapter = &voltha.Adapter{ |
| 102 | Id: TestProxy_AdapterId, |
| 103 | Vendor: "test-adapter-vendor", |
| 104 | Version: "test-adapter-version", |
| 105 | } |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 106 | } |
| 107 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 108 | func TestProxy_1_1_1_Add_NewDevice(t *testing.T) { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 109 | devIDBin, _ := uuid.New().MarshalBinary() |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 110 | TestProxy_DeviceId = "0001" + hex.EncodeToString(devIDBin)[:12] |
| 111 | TestProxy_Device.Id = TestProxy_DeviceId |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 112 | |
Stephane Barbarie | a188d94 | 2018-10-16 16:43:04 -0400 | [diff] [blame] | 113 | preAddExecuted := false |
| 114 | postAddExecuted := false |
| 115 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 116 | devicesProxy := TestProxy_Root.node.CreateProxy("/devices", false) |
| 117 | devicesProxy.RegisterCallback(PRE_ADD, commonCallback2, "PRE_ADD Device container changes") |
| 118 | devicesProxy.RegisterCallback(POST_ADD, commonCallback2, "POST_ADD Device container changes") |
| 119 | |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 120 | // Register ADD instructions callbacks |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 121 | TestProxy_Root_Device.RegisterCallback(PRE_ADD, commonCallback, "PRE_ADD instructions", &preAddExecuted) |
| 122 | TestProxy_Root_Device.RegisterCallback(POST_ADD, commonCallback, "POST_ADD instructions", &postAddExecuted) |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 123 | |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 124 | // Add the device |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 125 | if added := TestProxy_Root_Device.Add("/devices", TestProxy_Device, ""); added == nil { |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 126 | t.Error("Failed to add device") |
| 127 | } else { |
| 128 | t.Logf("Added device : %+v", added) |
| 129 | } |
| 130 | |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 131 | // Verify that the added device can now be retrieved |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 132 | if d := TestProxy_Root_Device.Get("/devices/"+TestProxy_DeviceId, 0, false, ""); !reflect.ValueOf(d).IsValid() { |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 133 | t.Error("Failed to find added device") |
| 134 | } else { |
| 135 | djson, _ := json.Marshal(d) |
| 136 | t.Logf("Found device: %s", string(djson)) |
| 137 | } |
| 138 | |
| 139 | if !preAddExecuted { |
| 140 | t.Error("PRE_ADD callback was not executed") |
| 141 | } |
| 142 | if !postAddExecuted { |
| 143 | t.Error("POST_ADD callback was not executed") |
| 144 | } |
| 145 | } |
| 146 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 147 | func TestProxy_1_1_2_Add_ExistingDevice(t *testing.T) { |
| 148 | TestProxy_Device.Id = TestProxy_DeviceId |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 149 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 150 | added := TestProxy_Root_Device.Add("/devices", TestProxy_Device, ""); |
| 151 | if added.(proto.Message).String() != reflect.ValueOf(TestProxy_Device).Interface().(proto.Message).String() { |
| 152 | t.Errorf("Devices don't match - existing: %+v returned: %+v", TestProxy_LogicalDevice, added) |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 153 | } |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 154 | } |
| 155 | |
Stephane Barbarie | aa46794 | 2019-02-06 14:09:44 -0500 | [diff] [blame] | 156 | func TestProxy_1_1_3_Add_NewAdapter(t *testing.T) { |
| 157 | TestProxy_AdapterId = "test-adapter" |
| 158 | TestProxy_Adapter.Id = TestProxy_AdapterId |
| 159 | preAddExecuted := false |
| 160 | postAddExecuted := false |
| 161 | |
| 162 | // Register ADD instructions callbacks |
| 163 | TestProxy_Root_Adapter.RegisterCallback(PRE_ADD, commonCallback, "PRE_ADD instructions for adapters", &preAddExecuted) |
| 164 | TestProxy_Root_Adapter.RegisterCallback(POST_ADD, commonCallback, "POST_ADD instructions for adapters", &postAddExecuted) |
| 165 | |
| 166 | // Add the adapter |
| 167 | if added := TestProxy_Root_Adapter.Add("/adapters", TestProxy_Adapter, ""); added == nil { |
| 168 | t.Error("Failed to add adapter") |
| 169 | } else { |
| 170 | t.Logf("Added adapter : %+v", added) |
| 171 | } |
| 172 | |
| 173 | // Verify that the added device can now be retrieved |
| 174 | if d := TestProxy_Root_Adapter.Get("/adapters/"+TestProxy_AdapterId, 0, false, ""); !reflect.ValueOf(d).IsValid() { |
| 175 | t.Error("Failed to find added adapter") |
| 176 | } else { |
| 177 | djson, _ := json.Marshal(d) |
| 178 | t.Logf("Found adapter: %s", string(djson)) |
| 179 | } |
| 180 | |
| 181 | if !preAddExecuted { |
| 182 | t.Error("PRE_ADD callback was not executed") |
| 183 | } |
| 184 | if !postAddExecuted { |
| 185 | t.Error("POST_ADD callback was not executed") |
| 186 | } |
| 187 | } |
| 188 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 189 | func TestProxy_1_2_1_Get_AllDevices(t *testing.T) { |
| 190 | devices := TestProxy_Root_Device.Get("/devices", 1, false, "") |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 191 | |
| 192 | if len(devices.([]interface{})) == 0 { |
| 193 | t.Error("there are no available devices to retrieve") |
| 194 | } else { |
| 195 | // Save the target device id for later tests |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 196 | TestProxy_TargetDeviceId = devices.([]interface{})[0].(*voltha.Device).Id |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 197 | t.Logf("retrieved all devices: %+v", devices) |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 201 | func TestProxy_1_2_2_Get_SingleDevice(t *testing.T) { |
| 202 | if d := TestProxy_Root_Device.Get("/devices/"+TestProxy_TargetDeviceId, 0, false, ""); !reflect.ValueOf(d).IsValid() { |
| 203 | t.Errorf("Failed to find device : %s", TestProxy_TargetDeviceId) |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 204 | } else { |
| 205 | djson, _ := json.Marshal(d) |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 206 | t.Logf("Found device: %s", string(djson)) |
| 207 | } |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 208 | } |
| 209 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 210 | func TestProxy_1_3_1_Update_Device(t *testing.T) { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 211 | var fwVersion int |
| 212 | preUpdateExecuted := false |
| 213 | postUpdateExecuted := false |
| 214 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 215 | if retrieved := TestProxy_Root_Device.Get("/devices/"+TestProxy_TargetDeviceId, 1, false, ""); retrieved == nil { |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 216 | t.Error("Failed to get device") |
| 217 | } else { |
Stephane Barbarie | a188d94 | 2018-10-16 16:43:04 -0400 | [diff] [blame] | 218 | t.Logf("Found raw device (root proxy): %+v", retrieved) |
| 219 | |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 220 | if retrieved.(*voltha.Device).FirmwareVersion == "n/a" { |
| 221 | fwVersion = 0 |
| 222 | } else { |
| 223 | fwVersion, _ = strconv.Atoi(retrieved.(*voltha.Device).FirmwareVersion) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 224 | fwVersion++ |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 225 | } |
| 226 | |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 227 | retrieved.(*voltha.Device).FirmwareVersion = strconv.Itoa(fwVersion) |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 228 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 229 | TestProxy_Root_Device.RegisterCallback( |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 230 | PRE_UPDATE, |
| 231 | commonCallback, |
| 232 | "PRE_UPDATE instructions (root proxy)", &preUpdateExecuted, |
| 233 | ) |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 234 | TestProxy_Root_Device.RegisterCallback( |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 235 | POST_UPDATE, |
| 236 | commonCallback, |
| 237 | "POST_UPDATE instructions (root proxy)", &postUpdateExecuted, |
| 238 | ) |
| 239 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 240 | if afterUpdate := TestProxy_Root_Device.Update("/devices/"+TestProxy_TargetDeviceId, retrieved, false, ""); afterUpdate == nil { |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 241 | t.Error("Failed to update device") |
| 242 | } else { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 243 | t.Logf("Updated device : %+v", afterUpdate) |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 244 | } |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 245 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 246 | if d := TestProxy_Root_Device.Get("/devices/"+TestProxy_TargetDeviceId, 1, false, ""); !reflect.ValueOf(d).IsValid() { |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 247 | t.Error("Failed to find updated device (root proxy)") |
| 248 | } else { |
| 249 | djson, _ := json.Marshal(d) |
Stephane Barbarie | a188d94 | 2018-10-16 16:43:04 -0400 | [diff] [blame] | 250 | t.Logf("Found device (root proxy): %s raw: %+v", string(djson), d) |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | if !preUpdateExecuted { |
| 254 | t.Error("PRE_UPDATE callback was not executed") |
| 255 | } |
| 256 | if !postUpdateExecuted { |
| 257 | t.Error("POST_UPDATE callback was not executed") |
| 258 | } |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 259 | } |
| 260 | } |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 261 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 262 | func TestProxy_1_3_2_Update_DeviceFlows(t *testing.T) { |
Stephane Barbarie | 06c4a74 | 2018-10-01 11:09:32 -0400 | [diff] [blame] | 263 | // Get a device proxy and update a specific port |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 264 | devFlowsProxy := TestProxy_Root.node.CreateProxy("/devices/"+TestProxy_DeviceId+"/flows", false) |
| 265 | flows := devFlowsProxy.Get("/", 0, false, "") |
Stephane Barbarie | a188d94 | 2018-10-16 16:43:04 -0400 | [diff] [blame] | 266 | flows.(*openflow_13.Flows).Items[0].TableId = 2244 |
Stephane Barbarie | 06c4a74 | 2018-10-01 11:09:32 -0400 | [diff] [blame] | 267 | |
Stephane Barbarie | a188d94 | 2018-10-16 16:43:04 -0400 | [diff] [blame] | 268 | preUpdateExecuted := false |
| 269 | postUpdateExecuted := false |
Stephane Barbarie | 06c4a74 | 2018-10-01 11:09:32 -0400 | [diff] [blame] | 270 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 271 | devFlowsProxy.RegisterCallback( |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 272 | PRE_UPDATE, |
| 273 | commonCallback, |
| 274 | "PRE_UPDATE instructions (flows proxy)", &preUpdateExecuted, |
| 275 | ) |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 276 | devFlowsProxy.RegisterCallback( |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 277 | POST_UPDATE, |
| 278 | commonCallback, |
| 279 | "POST_UPDATE instructions (flows proxy)", &postUpdateExecuted, |
| 280 | ) |
Stephane Barbarie | 06c4a74 | 2018-10-01 11:09:32 -0400 | [diff] [blame] | 281 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 282 | kvFlows := devFlowsProxy.Get("/", 0, false, "") |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 283 | |
| 284 | if reflect.DeepEqual(flows, kvFlows) { |
| 285 | t.Errorf("Local changes have changed the KV store contents - local:%+v, kv: %+v", flows, kvFlows) |
| 286 | } |
| 287 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 288 | if updated := devFlowsProxy.Update("/", flows.(*openflow_13.Flows), false, ""); updated == nil { |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 289 | t.Error("Failed to update flow") |
| 290 | } else { |
| 291 | t.Logf("Updated flows : %+v", updated) |
| 292 | } |
| 293 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 294 | if d := devFlowsProxy.Get("/", 0, false, ""); d == nil { |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 295 | t.Error("Failed to find updated flows (flows proxy)") |
| 296 | } else { |
| 297 | djson, _ := json.Marshal(d) |
| 298 | t.Logf("Found flows (flows proxy): %s", string(djson)) |
| 299 | } |
| 300 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 301 | if d := TestProxy_Root_Device.Get("/devices/"+TestProxy_DeviceId+"/flows", 1, false, ""); !reflect.ValueOf(d).IsValid() { |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 302 | t.Error("Failed to find updated flows (root proxy)") |
| 303 | } else { |
| 304 | djson, _ := json.Marshal(d) |
| 305 | t.Logf("Found flows (root proxy): %s", string(djson)) |
| 306 | } |
| 307 | |
| 308 | if !preUpdateExecuted { |
| 309 | t.Error("PRE_UPDATE callback was not executed") |
| 310 | } |
| 311 | if !postUpdateExecuted { |
| 312 | t.Error("POST_UPDATE callback was not executed") |
| 313 | } |
Stephane Barbarie | 06c4a74 | 2018-10-01 11:09:32 -0400 | [diff] [blame] | 314 | } |
| 315 | |
Stephane Barbarie | aa46794 | 2019-02-06 14:09:44 -0500 | [diff] [blame] | 316 | func TestProxy_1_3_3_Update_Adapter(t *testing.T) { |
| 317 | preUpdateExecuted := false |
| 318 | postUpdateExecuted := false |
| 319 | |
| 320 | adaptersProxy := TestProxy_Root.node.CreateProxy("/adapters", false) |
| 321 | |
| 322 | if retrieved := TestProxy_Root_Adapter.Get("/adapters/"+TestProxy_AdapterId, 1, false, ""); retrieved == nil { |
| 323 | t.Error("Failed to get adapter") |
| 324 | } else { |
| 325 | t.Logf("Found raw adapter (root proxy): %+v", retrieved) |
| 326 | |
| 327 | retrieved.(*voltha.Adapter).Version = "test-adapter-version-2" |
| 328 | |
| 329 | adaptersProxy.RegisterCallback( |
| 330 | PRE_UPDATE, |
| 331 | commonCallback, |
| 332 | "PRE_UPDATE instructions for adapters", &preUpdateExecuted, |
| 333 | ) |
| 334 | adaptersProxy.RegisterCallback( |
| 335 | POST_UPDATE, |
| 336 | commonCallback, |
| 337 | "POST_UPDATE instructions for adapters", &postUpdateExecuted, |
| 338 | ) |
| 339 | |
| 340 | if afterUpdate := adaptersProxy.Update("/"+TestProxy_AdapterId, retrieved, false, ""); afterUpdate == nil { |
| 341 | t.Error("Failed to update adapter") |
| 342 | } else { |
| 343 | t.Logf("Updated adapter : %+v", afterUpdate) |
| 344 | } |
| 345 | |
| 346 | if d := TestProxy_Root_Adapter.Get("/adapters/"+TestProxy_AdapterId, 1, false, ""); !reflect.ValueOf(d).IsValid() { |
| 347 | t.Error("Failed to find updated adapter (root proxy)") |
| 348 | } else { |
| 349 | djson, _ := json.Marshal(d) |
| 350 | t.Logf("Found adapter (root proxy): %s raw: %+v", string(djson), d) |
| 351 | } |
| 352 | |
| 353 | if !preUpdateExecuted { |
| 354 | t.Error("PRE_UPDATE callback for adapter was not executed") |
| 355 | } |
| 356 | if !postUpdateExecuted { |
| 357 | t.Error("POST_UPDATE callback for adapter was not executed") |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 362 | func TestProxy_1_4_1_Remove_Device(t *testing.T) { |
Stephane Barbarie | a188d94 | 2018-10-16 16:43:04 -0400 | [diff] [blame] | 363 | preRemoveExecuted := false |
| 364 | postRemoveExecuted := false |
Stephane Barbarie | 06c4a74 | 2018-10-01 11:09:32 -0400 | [diff] [blame] | 365 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 366 | TestProxy_Root_Device.RegisterCallback( |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 367 | PRE_REMOVE, |
| 368 | commonCallback, |
| 369 | "PRE_REMOVE instructions (root proxy)", &preRemoveExecuted, |
| 370 | ) |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 371 | TestProxy_Root_Device.RegisterCallback( |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 372 | POST_REMOVE, |
| 373 | commonCallback, |
| 374 | "POST_REMOVE instructions (root proxy)", &postRemoveExecuted, |
| 375 | ) |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 376 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 377 | if removed := TestProxy_Root_Device.Remove("/devices/"+TestProxy_DeviceId, ""); removed == nil { |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 378 | t.Error("Failed to remove device") |
| 379 | } else { |
| 380 | t.Logf("Removed device : %+v", removed) |
| 381 | } |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 382 | if d := TestProxy_Root_Device.Get("/devices/"+TestProxy_DeviceId, 0, false, ""); reflect.ValueOf(d).IsValid() { |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 383 | djson, _ := json.Marshal(d) |
| 384 | t.Errorf("Device was not removed - %s", djson) |
| 385 | } else { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 386 | t.Logf("Device was removed: %s", TestProxy_DeviceId) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | if !preRemoveExecuted { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 390 | t.Error("PRE_REMOVE callback was not executed") |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 391 | } |
| 392 | if !postRemoveExecuted { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 393 | t.Error("POST_REMOVE callback was not executed") |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 397 | func TestProxy_2_1_1_Add_NewLogicalDevice(t *testing.T) { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 398 | |
| 399 | ldIDBin, _ := uuid.New().MarshalBinary() |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 400 | TestProxy_LogicalDeviceId = "0001" + hex.EncodeToString(ldIDBin)[:12] |
| 401 | TestProxy_LogicalDevice.Id = TestProxy_LogicalDeviceId |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 402 | |
| 403 | preAddExecuted := false |
| 404 | postAddExecuted := false |
| 405 | |
| 406 | // Register |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 407 | TestProxy_Root_LogicalDevice.RegisterCallback(PRE_ADD, commonCallback, "PRE_ADD instructions", &preAddExecuted) |
| 408 | TestProxy_Root_LogicalDevice.RegisterCallback(POST_ADD, commonCallback, "POST_ADD instructions", &postAddExecuted) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 409 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 410 | if added := TestProxy_Root_LogicalDevice.Add("/logical_devices", TestProxy_LogicalDevice, ""); added == nil { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 411 | t.Error("Failed to add logical device") |
| 412 | } else { |
| 413 | t.Logf("Added logical device : %+v", added) |
| 414 | } |
| 415 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 416 | if ld := TestProxy_Root_LogicalDevice.Get("/logical_devices/"+TestProxy_LogicalDeviceId, 0, false, ""); !reflect.ValueOf(ld).IsValid() { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 417 | t.Error("Failed to find added logical device") |
| 418 | } else { |
| 419 | ldJSON, _ := json.Marshal(ld) |
| 420 | t.Logf("Found logical device: %s", string(ldJSON)) |
| 421 | } |
| 422 | |
| 423 | if !preAddExecuted { |
| 424 | t.Error("PRE_ADD callback was not executed") |
| 425 | } |
| 426 | if !postAddExecuted { |
| 427 | t.Error("POST_ADD callback was not executed") |
| 428 | } |
| 429 | } |
| 430 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 431 | func TestProxy_2_1_2_Add_ExistingLogicalDevice(t *testing.T) { |
| 432 | TestProxy_LogicalDevice.Id = TestProxy_LogicalDeviceId |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 433 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 434 | added := TestProxy_Root_LogicalDevice.Add("/logical_devices", TestProxy_LogicalDevice, ""); |
| 435 | if added.(proto.Message).String() != reflect.ValueOf(TestProxy_LogicalDevice).Interface().(proto.Message).String() { |
| 436 | t.Errorf("Logical devices don't match - existing: %+v returned: %+v", TestProxy_LogicalDevice, added) |
| 437 | } |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 438 | } |
| 439 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 440 | func TestProxy_2_2_1_Get_AllLogicalDevices(t *testing.T) { |
| 441 | logicalDevices := TestProxy_Root_LogicalDevice.Get("/logical_devices", 1, false, "") |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 442 | |
| 443 | if len(logicalDevices.([]interface{})) == 0 { |
| 444 | t.Error("there are no available logical devices to retrieve") |
| 445 | } else { |
| 446 | // Save the target device id for later tests |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 447 | TestProxy_TargetLogicalDeviceId = logicalDevices.([]interface{})[0].(*voltha.LogicalDevice).Id |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 448 | t.Logf("retrieved all logical devices: %+v", logicalDevices) |
| 449 | } |
| 450 | } |
| 451 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 452 | func TestProxy_2_2_2_Get_SingleLogicalDevice(t *testing.T) { |
| 453 | if ld := TestProxy_Root_LogicalDevice.Get("/logical_devices/"+TestProxy_TargetLogicalDeviceId, 0, false, ""); !reflect.ValueOf(ld).IsValid() { |
| 454 | t.Errorf("Failed to find logical device : %s", TestProxy_TargetLogicalDeviceId) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 455 | } else { |
| 456 | ldJSON, _ := json.Marshal(ld) |
| 457 | t.Logf("Found logical device: %s", string(ldJSON)) |
| 458 | } |
| 459 | |
| 460 | } |
| 461 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 462 | func TestProxy_2_3_1_Update_LogicalDevice(t *testing.T) { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 463 | var fwVersion int |
| 464 | preUpdateExecuted := false |
| 465 | postUpdateExecuted := false |
| 466 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 467 | if retrieved := TestProxy_Root_LogicalDevice.Get("/logical_devices/"+TestProxy_TargetLogicalDeviceId, 1, false, ""); retrieved == nil { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 468 | t.Error("Failed to get logical device") |
| 469 | } else { |
| 470 | t.Logf("Found raw logical device (root proxy): %+v", retrieved) |
| 471 | |
| 472 | if retrieved.(*voltha.LogicalDevice).RootDeviceId == "" { |
| 473 | fwVersion = 0 |
| 474 | } else { |
| 475 | fwVersion, _ = strconv.Atoi(retrieved.(*voltha.LogicalDevice).RootDeviceId) |
| 476 | fwVersion++ |
| 477 | } |
| 478 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 479 | TestProxy_Root_LogicalDevice.RegisterCallback( |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 480 | PRE_UPDATE, |
| 481 | commonCallback, |
| 482 | "PRE_UPDATE instructions (root proxy)", &preUpdateExecuted, |
| 483 | ) |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 484 | TestProxy_Root_LogicalDevice.RegisterCallback( |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 485 | POST_UPDATE, |
| 486 | commonCallback, |
| 487 | "POST_UPDATE instructions (root proxy)", &postUpdateExecuted, |
| 488 | ) |
| 489 | |
| 490 | retrieved.(*voltha.LogicalDevice).RootDeviceId = strconv.Itoa(fwVersion) |
| 491 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 492 | if afterUpdate := TestProxy_Root_LogicalDevice.Update("/logical_devices/"+TestProxy_TargetLogicalDeviceId, retrieved, false, |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 493 | ""); afterUpdate == nil { |
| 494 | t.Error("Failed to update logical device") |
| 495 | } else { |
| 496 | t.Logf("Updated logical device : %+v", afterUpdate) |
| 497 | } |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 498 | if d := TestProxy_Root_LogicalDevice.Get("/logical_devices/"+TestProxy_TargetLogicalDeviceId, 1, false, ""); !reflect.ValueOf(d).IsValid() { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 499 | t.Error("Failed to find updated logical device (root proxy)") |
| 500 | } else { |
| 501 | djson, _ := json.Marshal(d) |
| 502 | |
| 503 | t.Logf("Found logical device (root proxy): %s raw: %+v", string(djson), d) |
| 504 | } |
| 505 | |
| 506 | if !preUpdateExecuted { |
| 507 | t.Error("PRE_UPDATE callback was not executed") |
| 508 | } |
| 509 | if !postUpdateExecuted { |
| 510 | t.Error("POST_UPDATE callback was not executed") |
| 511 | } |
| 512 | } |
| 513 | } |
| 514 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 515 | func TestProxy_2_3_2_Update_LogicalDeviceFlows(t *testing.T) { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 516 | // Get a device proxy and update a specific port |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 517 | ldFlowsProxy := TestProxy_Root.node.CreateProxy("/logical_devices/"+TestProxy_LogicalDeviceId+"/flows", false) |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 518 | flows := ldFlowsProxy.Get("/", 0, false, "") |
| 519 | flows.(*openflow_13.Flows).Items[0].TableId = rand.Uint32() |
| 520 | t.Logf("before updated flows: %+v", flows) |
| 521 | |
| 522 | ldFlowsProxy.RegisterCallback( |
| 523 | PRE_UPDATE, |
| 524 | commonCallback2, |
| 525 | ) |
| 526 | ldFlowsProxy.RegisterCallback( |
| 527 | POST_UPDATE, |
| 528 | commonCallback2, |
| 529 | ) |
| 530 | |
| 531 | kvFlows := ldFlowsProxy.Get("/", 0, false, "") |
| 532 | |
| 533 | if reflect.DeepEqual(flows, kvFlows) { |
| 534 | t.Errorf("Local changes have changed the KV store contents - local:%+v, kv: %+v", flows, kvFlows) |
| 535 | } |
| 536 | |
| 537 | if updated := ldFlowsProxy.Update("/", flows.(*openflow_13.Flows), false, ""); updated == nil { |
| 538 | t.Error("Failed to update logical device flows") |
| 539 | } else { |
| 540 | t.Logf("Updated logical device flows : %+v", updated) |
| 541 | } |
| 542 | |
| 543 | if d := ldFlowsProxy.Get("/", 0, false, ""); d == nil { |
| 544 | t.Error("Failed to find updated logical device flows (flows proxy)") |
| 545 | } else { |
| 546 | djson, _ := json.Marshal(d) |
| 547 | t.Logf("Found flows (flows proxy): %s", string(djson)) |
| 548 | } |
| 549 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 550 | if d := TestProxy_Root_LogicalDevice.Get("/logical_devices/"+TestProxy_LogicalDeviceId+"/flows", 0, false, |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 551 | ""); !reflect.ValueOf(d).IsValid() { |
| 552 | t.Error("Failed to find updated logical device flows (root proxy)") |
| 553 | } else { |
| 554 | djson, _ := json.Marshal(d) |
| 555 | t.Logf("Found logical device flows (root proxy): %s", string(djson)) |
| 556 | } |
| 557 | } |
| 558 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 559 | func TestProxy_2_4_1_Remove_Device(t *testing.T) { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 560 | preRemoveExecuted := false |
| 561 | postRemoveExecuted := false |
| 562 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 563 | TestProxy_Root_LogicalDevice.RegisterCallback( |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 564 | PRE_REMOVE, |
| 565 | commonCallback, |
| 566 | "PRE_REMOVE instructions (root proxy)", &preRemoveExecuted, |
| 567 | ) |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 568 | TestProxy_Root_LogicalDevice.RegisterCallback( |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 569 | POST_REMOVE, |
| 570 | commonCallback, |
| 571 | "POST_REMOVE instructions (root proxy)", &postRemoveExecuted, |
| 572 | ) |
| 573 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 574 | if removed := TestProxy_Root_LogicalDevice.Remove("/logical_devices/"+TestProxy_LogicalDeviceId, ""); removed == nil { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 575 | t.Error("Failed to remove logical device") |
| 576 | } else { |
| 577 | t.Logf("Removed device : %+v", removed) |
| 578 | } |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 579 | if d := TestProxy_Root_LogicalDevice.Get("/logical_devices/"+TestProxy_LogicalDeviceId, 0, false, ""); reflect.ValueOf(d).IsValid() { |
Stephane Barbarie | dc5022d | 2018-11-19 15:21:44 -0500 | [diff] [blame] | 580 | djson, _ := json.Marshal(d) |
| 581 | t.Errorf("Device was not removed - %s", djson) |
| 582 | } else { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 583 | t.Logf("Device was removed: %s", TestProxy_LogicalDeviceId) |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 584 | } |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 585 | |
| 586 | if !preRemoveExecuted { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 587 | t.Error("PRE_REMOVE callback was not executed") |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 588 | } |
| 589 | if !postRemoveExecuted { |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 590 | t.Error("POST_REMOVE callback was not executed") |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 591 | } |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 592 | } |
Stephane Barbarie | 694e2b9 | 2018-09-07 12:17:36 -0400 | [diff] [blame] | 593 | |
| 594 | // ----------------------------- |
| 595 | // Callback tests |
| 596 | // ----------------------------- |
| 597 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 598 | func TestProxy_Callbacks_1_Register(t *testing.T) { |
| 599 | TestProxy_Root_Device.RegisterCallback(PRE_ADD, firstCallback, "abcde", "12345") |
Stephane Barbarie | 694e2b9 | 2018-09-07 12:17:36 -0400 | [diff] [blame] | 600 | |
| 601 | m := make(map[string]string) |
| 602 | m["name"] = "fghij" |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 603 | TestProxy_Root_Device.RegisterCallback(PRE_ADD, secondCallback, m, 1.2345) |
Stephane Barbarie | 694e2b9 | 2018-09-07 12:17:36 -0400 | [diff] [blame] | 604 | |
| 605 | d := &voltha.Device{Id: "12345"} |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 606 | TestProxy_Root_Device.RegisterCallback(PRE_ADD, thirdCallback, "klmno", d) |
Stephane Barbarie | 694e2b9 | 2018-09-07 12:17:36 -0400 | [diff] [blame] | 607 | } |
| 608 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 609 | func TestProxy_Callbacks_2_Invoke_WithNoInterruption(t *testing.T) { |
| 610 | TestProxy_Root_Device.InvokeCallbacks(PRE_ADD, false, nil) |
Stephane Barbarie | 694e2b9 | 2018-09-07 12:17:36 -0400 | [diff] [blame] | 611 | } |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 612 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 613 | func TestProxy_Callbacks_3_Invoke_WithInterruption(t *testing.T) { |
| 614 | TestProxy_Root_Device.InvokeCallbacks(PRE_ADD, true, nil) |
Stephane Barbarie | 694e2b9 | 2018-09-07 12:17:36 -0400 | [diff] [blame] | 615 | } |
| 616 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 617 | func TestProxy_Callbacks_4_Unregister(t *testing.T) { |
| 618 | TestProxy_Root_Device.UnregisterCallback(PRE_ADD, firstCallback) |
| 619 | TestProxy_Root_Device.UnregisterCallback(PRE_ADD, secondCallback) |
| 620 | TestProxy_Root_Device.UnregisterCallback(PRE_ADD, thirdCallback) |
Stephane Barbarie | 694e2b9 | 2018-09-07 12:17:36 -0400 | [diff] [blame] | 621 | } |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 622 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 623 | //func TestProxy_Callbacks_5_Add(t *testing.T) { |
| 624 | // TestProxy_Root_Device.Root.AddCallback(TestProxy_Root_Device.InvokeCallbacks, POST_UPDATE, false, "some data", "some new data") |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 625 | //} |
| 626 | // |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame] | 627 | //func TestProxy_Callbacks_6_Execute(t *testing.T) { |
| 628 | // TestProxy_Root_Device.Root.ExecuteCallbacks() |
Stephane Barbarie | 126101e | 2018-10-11 16:18:48 -0400 | [diff] [blame] | 629 | //} |