khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 1 | /* |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 2 | * Copyright 2019-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. |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 15 | */ |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 16 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 17 | package api |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | "errors" |
| 22 | "fmt" |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 23 | "math/rand" |
| 24 | "os" |
| 25 | "runtime" |
| 26 | "runtime/pprof" |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 27 | "strconv" |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 28 | "strings" |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 29 | "sync" |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 30 | "testing" |
| 31 | "time" |
| 32 | |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 33 | "github.com/golang/protobuf/ptypes/empty" |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 34 | "github.com/opencord/voltha-go/db/model" |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 35 | "github.com/opencord/voltha-go/rw_core/config" |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 36 | "github.com/opencord/voltha-go/rw_core/core/adapter" |
| 37 | "github.com/opencord/voltha-go/rw_core/core/device" |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 38 | cm "github.com/opencord/voltha-go/rw_core/mocks" |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 39 | tst "github.com/opencord/voltha-go/rw_core/test" |
Maninder | dfadc98 | 2020-10-28 14:04:33 +0530 | [diff] [blame] | 40 | "github.com/opencord/voltha-lib-go/v4/pkg/db" |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 41 | "github.com/opencord/voltha-lib-go/v4/pkg/events" |
Maninder | dfadc98 | 2020-10-28 14:04:33 +0530 | [diff] [blame] | 42 | "github.com/opencord/voltha-lib-go/v4/pkg/flows" |
| 43 | "github.com/opencord/voltha-lib-go/v4/pkg/kafka" |
| 44 | mock_etcd "github.com/opencord/voltha-lib-go/v4/pkg/mocks/etcd" |
| 45 | mock_kafka "github.com/opencord/voltha-lib-go/v4/pkg/mocks/kafka" |
| 46 | ofp "github.com/opencord/voltha-protos/v4/go/openflow_13" |
| 47 | "github.com/opencord/voltha-protos/v4/go/voltha" |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 48 | "github.com/phayes/freeport" |
| 49 | "github.com/stretchr/testify/assert" |
| 50 | "google.golang.org/grpc/codes" |
| 51 | "google.golang.org/grpc/status" |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 52 | ) |
| 53 | |
Marcos Aurelio Carrero (Furukawa) | a61a72c | 2021-01-28 13:48:20 -0300 | [diff] [blame] | 54 | const numTrapOnNNIFlows = 4 |
| 55 | |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 56 | type NBTest struct { |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 57 | etcdServer *mock_etcd.EtcdServer |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 58 | deviceMgr *device.Manager |
| 59 | logicalDeviceMgr *device.LogicalManager |
| 60 | adapterMgr *adapter.Manager |
| 61 | kmp kafka.InterContainerProxy |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 62 | kClient kafka.Client |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 63 | kEventClient kafka.Client |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 64 | kvClientPort int |
| 65 | numONUPerOLT int |
| 66 | startingUNIPortNo int |
| 67 | oltAdapter *cm.OLTAdapter |
| 68 | onuAdapter *cm.ONUAdapter |
| 69 | oltAdapterName string |
| 70 | onuAdapterName string |
| 71 | coreInstanceID string |
| 72 | defaultTimeout time.Duration |
| 73 | maxTimeout time.Duration |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 74 | } |
| 75 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 76 | func newNBTest(ctx context.Context) *NBTest { |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 77 | test := &NBTest{} |
| 78 | // Start the embedded etcd server |
| 79 | var err error |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 80 | test.etcdServer, test.kvClientPort, err = tst.StartEmbeddedEtcdServer(ctx, "voltha.rwcore.nb.test", "voltha.rwcore.nb.etcd", "error") |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 81 | if err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 82 | logger.Fatal(ctx, err) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 83 | } |
| 84 | // Create the kafka client |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 85 | test.kClient = mock_kafka.NewKafkaClient() |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 86 | test.kEventClient = mock_kafka.NewKafkaClient() |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 87 | test.oltAdapterName = "olt_adapter_mock" |
| 88 | test.onuAdapterName = "onu_adapter_mock" |
| 89 | test.coreInstanceID = "rw-nbi-test" |
khenaidoo | 3283673 | 2020-03-05 16:10:44 -0500 | [diff] [blame] | 90 | test.defaultTimeout = 10 * time.Second |
| 91 | test.maxTimeout = 20 * time.Second |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 92 | return test |
| 93 | } |
| 94 | |
| 95 | func (nb *NBTest) startCore(inCompeteMode bool) { |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 96 | ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) |
| 97 | defer cancel() |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 98 | cfg := config.NewRWCoreFlags() |
serkant.uluderya | 8ff291d | 2020-05-20 00:58:00 -0700 | [diff] [blame] | 99 | cfg.CoreTopic = "rw_core" |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 100 | cfg.EventTopic = "voltha.events" |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 101 | cfg.DefaultRequestTimeout = nb.defaultTimeout |
| 102 | cfg.DefaultCoreTimeout = nb.defaultTimeout |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 103 | cfg.KVStoreAddress = "127.0.0.1" + ":" + strconv.Itoa(nb.kvClientPort) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 104 | grpcPort, err := freeport.GetFreePort() |
| 105 | if err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 106 | logger.Fatal(ctx, "Cannot get a freeport for grpc") |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 107 | } |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 108 | cfg.GrpcAddress = "127.0.0.1" + ":" + strconv.Itoa(grpcPort) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 109 | setCoreCompeteMode(inCompeteMode) |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 110 | client := tst.SetupKVClient(ctx, cfg, nb.coreInstanceID) |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 111 | backend := &db.Backend{ |
| 112 | Client: client, |
| 113 | StoreType: cfg.KVStoreType, |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 114 | Address: cfg.KVStoreAddress, |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 115 | Timeout: cfg.KVStoreTimeout, |
serkant.uluderya | 8ff291d | 2020-05-20 00:58:00 -0700 | [diff] [blame] | 116 | LivenessChannelInterval: cfg.LiveProbeInterval / 2} |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 117 | nb.kmp = kafka.NewInterContainerProxy( |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 118 | kafka.InterContainerAddress(cfg.KafkaAdapterAddress), |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 119 | kafka.MsgClient(nb.kClient), |
David Bainbridge | 9ae1313 | 2020-06-22 17:28:01 -0700 | [diff] [blame] | 120 | kafka.DefaultTopic(&kafka.Topic{Name: cfg.CoreTopic})) |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 121 | |
| 122 | endpointMgr := kafka.NewEndpointManager(backend) |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 123 | proxy := model.NewDBPath(backend) |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 124 | nb.adapterMgr = adapter.NewAdapterManager(ctx, proxy, nb.coreInstanceID, nb.kClient) |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 125 | eventProxy := events.NewEventProxy(events.MsgClient(nb.kEventClient), events.MsgTopic(kafka.Topic{Name: cfg.EventTopic})) |
Himani Chawla | 9cfc499 | 2021-03-22 12:43:01 +0530 | [diff] [blame] | 126 | nb.deviceMgr, nb.logicalDeviceMgr = device.NewManagers(proxy, nb.adapterMgr, nb.kmp, endpointMgr, cfg.CoreTopic, nb.coreInstanceID, cfg.DefaultCoreTimeout, eventProxy, cfg.VolthaStackID) |
Kent Hagerman | 2f0d055 | 2020-04-23 17:28:52 -0400 | [diff] [blame] | 127 | nb.adapterMgr.Start(ctx) |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 128 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 129 | if err := nb.kmp.Start(ctx); err != nil { |
| 130 | logger.Fatalf(ctx, "Cannot start InterContainerProxy: %s", err) |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 131 | } |
Kent Hagerman | 2f0d055 | 2020-04-23 17:28:52 -0400 | [diff] [blame] | 132 | requestProxy := NewAdapterRequestHandlerProxy(nb.deviceMgr, nb.adapterMgr) |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 133 | if err := nb.kmp.SubscribeWithRequestHandlerInterface(ctx, kafka.Topic{Name: cfg.CoreTopic}, requestProxy); err != nil { |
| 134 | logger.Fatalf(ctx, "Cannot add request handler: %s", err) |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 135 | } |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 136 | } |
| 137 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 138 | func (nb *NBTest) stopAll(ctx context.Context) { |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 139 | if nb.kClient != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 140 | nb.kClient.Stop(ctx) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 141 | } |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 142 | if nb.kmp != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 143 | nb.kmp.Stop(ctx) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 144 | } |
| 145 | if nb.etcdServer != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 146 | tst.StopEmbeddedEtcdServer(ctx, nb.etcdServer) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 147 | } |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 148 | if nb.kEventClient != nil { |
| 149 | nb.kEventClient.Stop(ctx) |
| 150 | } |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 151 | } |
| 152 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 153 | func (nb *NBTest) verifyLogicalDevices(t *testing.T, oltDevice *voltha.Device, nbi *NBIHandler) { |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 154 | // Get the latest set of logical devices |
| 155 | logicalDevices, err := nbi.ListLogicalDevices(getContext(), &empty.Empty{}) |
| 156 | assert.Nil(t, err) |
| 157 | assert.NotNil(t, logicalDevices) |
| 158 | assert.Equal(t, 1, len(logicalDevices.Items)) |
| 159 | |
| 160 | ld := logicalDevices.Items[0] |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 161 | ports, err := nbi.ListLogicalDevicePorts(getContext(), &voltha.ID{Id: ld.Id}) |
| 162 | assert.Nil(t, err) |
| 163 | |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 164 | assert.NotEqual(t, "", ld.Id) |
| 165 | assert.NotEqual(t, uint64(0), ld.DatapathId) |
| 166 | assert.Equal(t, "olt_adapter_mock", ld.Desc.HwDesc) |
| 167 | assert.Equal(t, "olt_adapter_mock", ld.Desc.SwDesc) |
| 168 | assert.NotEqual(t, "", ld.RootDeviceId) |
| 169 | assert.NotEqual(t, "", ld.Desc.SerialNum) |
| 170 | assert.Equal(t, uint32(256), ld.SwitchFeatures.NBuffers) |
| 171 | assert.Equal(t, uint32(2), ld.SwitchFeatures.NTables) |
| 172 | assert.Equal(t, uint32(15), ld.SwitchFeatures.Capabilities) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 173 | assert.Equal(t, 1+nb.numONUPerOLT, len(ports.Items)) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 174 | assert.Equal(t, oltDevice.ParentId, ld.Id) |
| 175 | //Expected port no |
| 176 | expectedPortNo := make(map[uint32]bool) |
| 177 | expectedPortNo[uint32(2)] = false |
| 178 | for i := 0; i < nb.numONUPerOLT; i++ { |
| 179 | expectedPortNo[uint32(i+100)] = false |
| 180 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 181 | for _, p := range ports.Items { |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 182 | assert.Equal(t, p.OfpPort.PortNo, p.DevicePortNo) |
| 183 | assert.Equal(t, uint32(4), p.OfpPort.State) |
| 184 | expectedPortNo[p.OfpPort.PortNo] = true |
| 185 | if strings.HasPrefix(p.Id, "nni") { |
| 186 | assert.Equal(t, true, p.RootPort) |
| 187 | //assert.Equal(t, uint32(2), p.OfpPort.PortNo) |
| 188 | assert.Equal(t, p.Id, fmt.Sprintf("nni-%d", p.DevicePortNo)) |
| 189 | } else { |
| 190 | assert.Equal(t, p.Id, fmt.Sprintf("uni-%d", p.DevicePortNo)) |
| 191 | assert.Equal(t, false, p.RootPort) |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 196 | func (nb *NBTest) verifyDevices(t *testing.T, nbi *NBIHandler) { |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 197 | // Get the latest set of devices |
| 198 | devices, err := nbi.ListDevices(getContext(), &empty.Empty{}) |
| 199 | assert.Nil(t, err) |
| 200 | assert.NotNil(t, devices) |
| 201 | |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 202 | // A device is ready to be examined when its ADMIN state is ENABLED and OPERATIONAL state is ACTIVE |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 203 | var vFunction isDeviceConditionSatisfied = func(device *voltha.Device) bool { |
| 204 | return device.AdminState == voltha.AdminState_ENABLED && device.OperStatus == voltha.OperStatus_ACTIVE |
| 205 | } |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 206 | |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 207 | var wg sync.WaitGroup |
| 208 | for _, device := range devices.Items { |
| 209 | wg.Add(1) |
| 210 | go func(wg *sync.WaitGroup, device *voltha.Device) { |
| 211 | // Wait until the device is in the right state |
| 212 | err := waitUntilDeviceReadiness(device.Id, nb.maxTimeout, vFunction, nbi) |
| 213 | assert.Nil(t, err) |
| 214 | |
| 215 | // Now, verify the details of the device. First get the latest update |
| 216 | d, err := nbi.GetDevice(getContext(), &voltha.ID{Id: device.Id}) |
| 217 | assert.Nil(t, err) |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 218 | dPorts, err := nbi.ListDevicePorts(getContext(), &voltha.ID{Id: device.Id}) |
| 219 | assert.Nil(t, err) |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 220 | assert.Equal(t, voltha.AdminState_ENABLED, d.AdminState) |
| 221 | assert.Equal(t, voltha.ConnectStatus_REACHABLE, d.ConnectStatus) |
| 222 | assert.Equal(t, voltha.OperStatus_ACTIVE, d.OperStatus) |
| 223 | assert.Equal(t, d.Type, d.Adapter) |
| 224 | assert.NotEqual(t, "", d.MacAddress) |
| 225 | assert.NotEqual(t, "", d.SerialNumber) |
| 226 | |
| 227 | if d.Type == "olt_adapter_mock" { |
| 228 | assert.Equal(t, true, d.Root) |
| 229 | assert.NotEqual(t, "", d.Id) |
| 230 | assert.NotEqual(t, "", d.ParentId) |
| 231 | assert.Nil(t, d.ProxyAddress) |
| 232 | } else if d.Type == "onu_adapter_mock" { |
| 233 | assert.Equal(t, false, d.Root) |
| 234 | assert.NotEqual(t, uint32(0), d.Vlan) |
| 235 | assert.NotEqual(t, "", d.Id) |
| 236 | assert.NotEqual(t, "", d.ParentId) |
| 237 | assert.NotEqual(t, "", d.ProxyAddress.DeviceId) |
| 238 | assert.Equal(t, "olt_adapter_mock", d.ProxyAddress.DeviceType) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 239 | } else { |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 240 | assert.Error(t, errors.New("invalid-device-type")) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 241 | } |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 242 | assert.Equal(t, 2, len(dPorts.Items)) |
| 243 | for _, p := range dPorts.Items { |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 244 | assert.Equal(t, voltha.AdminState_ENABLED, p.AdminState) |
| 245 | assert.Equal(t, voltha.OperStatus_ACTIVE, p.OperStatus) |
| 246 | if p.Type == voltha.Port_ETHERNET_NNI || p.Type == voltha.Port_ETHERNET_UNI { |
| 247 | assert.Equal(t, 0, len(p.Peers)) |
| 248 | } else if p.Type == voltha.Port_PON_OLT { |
| 249 | assert.Equal(t, nb.numONUPerOLT, len(p.Peers)) |
| 250 | assert.Equal(t, uint32(1), p.PortNo) |
| 251 | } else if p.Type == voltha.Port_PON_ONU { |
| 252 | assert.Equal(t, 1, len(p.Peers)) |
| 253 | assert.Equal(t, uint32(1), p.PortNo) |
| 254 | } else { |
| 255 | assert.Error(t, errors.New("invalid-port")) |
| 256 | } |
| 257 | } |
| 258 | wg.Done() |
| 259 | }(&wg, device) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 260 | } |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 261 | wg.Wait() |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 262 | } |
| 263 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 264 | func (nb *NBTest) getADevice(rootDevice bool, nbi *NBIHandler) (*voltha.Device, error) { |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 265 | devices, err := nbi.ListDevices(getContext(), &empty.Empty{}) |
| 266 | if err != nil { |
| 267 | return nil, err |
| 268 | } |
| 269 | for _, d := range devices.Items { |
| 270 | if d.Root == rootDevice { |
| 271 | return d, nil |
| 272 | } |
| 273 | } |
| 274 | return nil, status.Errorf(codes.NotFound, "%v device not found", rootDevice) |
| 275 | } |
| 276 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 277 | func (nb *NBTest) testCoreWithoutData(t *testing.T, nbi *NBIHandler) { |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 278 | lds, err := nbi.ListLogicalDevices(getContext(), &empty.Empty{}) |
| 279 | assert.Nil(t, err) |
| 280 | assert.NotNil(t, lds) |
| 281 | assert.Equal(t, 0, len(lds.Items)) |
| 282 | devices, err := nbi.ListDevices(getContext(), &empty.Empty{}) |
| 283 | assert.Nil(t, err) |
| 284 | assert.NotNil(t, devices) |
| 285 | assert.Equal(t, 0, len(devices.Items)) |
| 286 | adapters, err := nbi.ListAdapters(getContext(), &empty.Empty{}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 287 | assert.Equal(t, 0, len(adapters.Items)) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 288 | assert.Nil(t, err) |
| 289 | assert.NotNil(t, adapters) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 290 | } |
| 291 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 292 | func (nb *NBTest) testAdapterRegistration(t *testing.T, nbi *NBIHandler) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 293 | ctx := context.Background() |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 294 | adapters, err := nbi.ListAdapters(getContext(), &empty.Empty{}) |
| 295 | assert.Nil(t, err) |
| 296 | assert.NotNil(t, adapters) |
| 297 | assert.Equal(t, 2, len(adapters.Items)) |
| 298 | for _, a := range adapters.Items { |
| 299 | switch a.Id { |
| 300 | case nb.oltAdapterName: |
| 301 | assert.Equal(t, "Voltha-olt", a.Vendor) |
| 302 | case nb.onuAdapterName: |
| 303 | assert.Equal(t, "Voltha-onu", a.Vendor) |
| 304 | default: |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 305 | logger.Fatal(ctx, "unregistered-adapter", a.Id) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | deviceTypes, err := nbi.ListDeviceTypes(getContext(), &empty.Empty{}) |
| 309 | assert.Nil(t, err) |
| 310 | assert.NotNil(t, deviceTypes) |
| 311 | assert.Equal(t, 2, len(deviceTypes.Items)) |
| 312 | for _, dt := range deviceTypes.Items { |
| 313 | switch dt.Id { |
| 314 | case nb.oltAdapterName: |
| 315 | assert.Equal(t, nb.oltAdapterName, dt.Adapter) |
| 316 | assert.Equal(t, false, dt.AcceptsBulkFlowUpdate) |
| 317 | assert.Equal(t, true, dt.AcceptsAddRemoveFlowUpdates) |
| 318 | case nb.onuAdapterName: |
| 319 | assert.Equal(t, nb.onuAdapterName, dt.Adapter) |
| 320 | assert.Equal(t, false, dt.AcceptsBulkFlowUpdate) |
| 321 | assert.Equal(t, true, dt.AcceptsAddRemoveFlowUpdates) |
| 322 | default: |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 323 | logger.Fatal(ctx, "invalid-device-type", dt.Id) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 328 | func (nb *NBTest) testCreateDevice(t *testing.T, nbi *NBIHandler) { |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 329 | // Create a valid device |
| 330 | oltDevice, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName, MacAddress: "aa:bb:cc:cc:ee:ee"}) |
| 331 | assert.Nil(t, err) |
| 332 | assert.NotNil(t, oltDevice) |
| 333 | device, err := nbi.GetDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 334 | assert.Nil(t, err) |
| 335 | assert.NotNil(t, device) |
| 336 | assert.Equal(t, oltDevice.String(), device.String()) |
| 337 | |
| 338 | // Try to create the same device |
| 339 | _, err = nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName, MacAddress: "aa:bb:cc:cc:ee:ee"}) |
| 340 | assert.NotNil(t, err) |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 341 | assert.Equal(t, "device is already pre-provisioned", err.Error()) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 342 | |
| 343 | // Try to create a device with invalid data |
| 344 | _, err = nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName}) |
| 345 | assert.NotNil(t, err) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 346 | assert.Equal(t, "no-device-info-present; MAC or HOSTIP&PORT", err.Error()) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 347 | |
| 348 | // Ensure we only have 1 device in the Core |
| 349 | devices, err := nbi.ListDevices(getContext(), &empty.Empty{}) |
| 350 | assert.Nil(t, err) |
| 351 | assert.NotNil(t, devices) |
| 352 | assert.Equal(t, 1, len(devices.Items)) |
| 353 | assert.Equal(t, oltDevice.String(), devices.Items[0].String()) |
| 354 | |
| 355 | //Remove the device |
| 356 | _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 357 | assert.Nil(t, err) |
| 358 | |
| 359 | //Ensure there are no devices in the Core now - wait until condition satisfied or timeout |
| 360 | var vFunction isDevicesConditionSatisfied = func(devices *voltha.Devices) bool { |
| 361 | return devices != nil && len(devices.Items) == 0 |
| 362 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 363 | err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunction) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 364 | assert.Nil(t, err) |
| 365 | } |
Himani Chawla | 2ba1c9c | 2020-10-07 13:19:03 +0530 | [diff] [blame] | 366 | func (nb *NBTest) enableDevice(t *testing.T, nbi *NBIHandler, oltDevice *voltha.Device) { |
| 367 | // Create a logical device monitor will automatically send trap and eapol flows to the devices being enables |
| 368 | var wg sync.WaitGroup |
| 369 | wg.Add(1) |
| 370 | go nb.monitorLogicalDevice(t, nbi, 1, nb.numONUPerOLT, &wg, false, false) |
| 371 | |
| 372 | // Enable the oltDevice |
| 373 | _, err := nbi.EnableDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 374 | assert.Nil(t, err) |
| 375 | |
| 376 | // Wait for the logical device to be in the ready state |
| 377 | var vldFunction = func(ports []*voltha.LogicalPort) bool { |
| 378 | return len(ports) == nb.numONUPerOLT+1 |
| 379 | } |
| 380 | err = waitUntilLogicalDevicePortsReadiness(oltDevice.Id, nb.maxTimeout, nbi, vldFunction) |
| 381 | assert.Nil(t, err) |
| 382 | |
| 383 | // Verify that the devices have been setup correctly |
| 384 | nb.verifyDevices(t, nbi) |
| 385 | |
| 386 | // Get latest oltDevice data |
| 387 | oltDevice, err = nbi.GetDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 388 | assert.Nil(t, err) |
| 389 | |
| 390 | // Verify that the logical device has been setup correctly |
| 391 | nb.verifyLogicalDevices(t, oltDevice, nbi) |
| 392 | |
| 393 | // Wait until all flows has been sent to the devices successfully |
| 394 | wg.Wait() |
| 395 | |
| 396 | } |
| 397 | func (nb *NBTest) testForceDeletePreProvDevice(t *testing.T, nbi *NBIHandler) { |
| 398 | // Create a valid device |
| 399 | oltDevice, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName, MacAddress: "aa:bb:cc:cc:ee:ee"}) |
| 400 | assert.Nil(t, err) |
| 401 | assert.NotNil(t, oltDevice) |
| 402 | device, err := nbi.GetDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 403 | assert.Nil(t, err) |
| 404 | assert.NotNil(t, device) |
| 405 | assert.Equal(t, oltDevice.String(), device.String()) |
| 406 | |
| 407 | // Ensure we only have 1 device in the Core |
| 408 | devices, err := nbi.ListDevices(getContext(), &empty.Empty{}) |
| 409 | assert.Nil(t, err) |
| 410 | assert.NotNil(t, devices) |
| 411 | assert.Equal(t, 1, len(devices.Items)) |
| 412 | assert.Equal(t, oltDevice.String(), devices.Items[0].String()) |
| 413 | |
| 414 | //Remove the device forcefully |
| 415 | _, err = nbi.ForceDeleteDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 416 | assert.Nil(t, err) |
| 417 | |
| 418 | //Ensure there are no devices in the Core now - wait until condition satisfied or timeout |
| 419 | var vFunction isDevicesConditionSatisfied = func(devices *voltha.Devices) bool { |
| 420 | return devices != nil && len(devices.Items) == 0 |
| 421 | } |
| 422 | err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunction) |
| 423 | assert.Nil(t, err) |
| 424 | } |
| 425 | |
| 426 | func (nb *NBTest) testForceDeleteEnabledDevice(t *testing.T, nbi *NBIHandler) { |
| 427 | // Create a valid device |
| 428 | oltDevice, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName, MacAddress: "aa:bb:cc:cc:ee:ee"}) |
| 429 | assert.Nil(t, err) |
| 430 | assert.NotNil(t, oltDevice) |
| 431 | device, err := nbi.GetDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 432 | assert.Nil(t, err) |
| 433 | assert.NotNil(t, device) |
| 434 | assert.Equal(t, oltDevice.String(), device.String()) |
| 435 | |
| 436 | nb.enableDevice(t, nbi, oltDevice) |
| 437 | |
| 438 | //Remove the device forcefully |
| 439 | _, err = nbi.ForceDeleteDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 440 | assert.Nil(t, err) |
| 441 | |
| 442 | //Ensure there are no devices in the Core now - wait until condition satisfied or timeout |
| 443 | var vFunction isDevicesConditionSatisfied = func(devices *voltha.Devices) bool { |
| 444 | return devices != nil && len(devices.Items) == 0 |
| 445 | } |
| 446 | err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunction) |
| 447 | assert.Nil(t, err) |
| 448 | } |
| 449 | |
| 450 | func (nb *NBTest) testDeletePreProvDevice(t *testing.T, nbi *NBIHandler) { |
| 451 | // Create a valid device |
| 452 | oltDevice, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName, MacAddress: "aa:bb:cc:cc:ee:ee"}) |
| 453 | assert.Nil(t, err) |
| 454 | assert.NotNil(t, oltDevice) |
| 455 | device, err := nbi.GetDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 456 | assert.Nil(t, err) |
| 457 | assert.NotNil(t, device) |
| 458 | assert.Equal(t, oltDevice.String(), device.String()) |
| 459 | |
| 460 | // Ensure we only have 1 device in the Core |
| 461 | devices, err := nbi.ListDevices(getContext(), &empty.Empty{}) |
| 462 | assert.Nil(t, err) |
| 463 | assert.NotNil(t, devices) |
| 464 | assert.Equal(t, 1, len(devices.Items)) |
| 465 | assert.Equal(t, oltDevice.String(), devices.Items[0].String()) |
| 466 | |
| 467 | //Remove the device forcefully |
| 468 | _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 469 | assert.Nil(t, err) |
| 470 | |
| 471 | //Ensure there are no devices in the Core now - wait until condition satisfied or timeout |
| 472 | var vFunction isDevicesConditionSatisfied = func(devices *voltha.Devices) bool { |
| 473 | return devices != nil && len(devices.Items) == 0 |
| 474 | } |
| 475 | err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunction) |
| 476 | assert.Nil(t, err) |
| 477 | } |
| 478 | |
| 479 | func (nb *NBTest) testDeleteEnabledDevice(t *testing.T, nbi *NBIHandler) { |
| 480 | // Create a valid device |
| 481 | oltDevice, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName, MacAddress: "aa:bb:cc:cc:ee:ee"}) |
| 482 | assert.Nil(t, err) |
| 483 | assert.NotNil(t, oltDevice) |
| 484 | device, err := nbi.GetDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 485 | assert.Nil(t, err) |
| 486 | assert.NotNil(t, device) |
| 487 | assert.Equal(t, oltDevice.String(), device.String()) |
| 488 | |
| 489 | nb.enableDevice(t, nbi, oltDevice) |
| 490 | |
| 491 | //Remove the device |
| 492 | _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 493 | assert.Nil(t, err) |
| 494 | |
| 495 | //Ensure there are no devices in the Core now - wait until condition satisfied or timeout |
| 496 | var vFunction isDevicesConditionSatisfied = func(devices *voltha.Devices) bool { |
| 497 | return devices != nil && len(devices.Items) == 0 |
| 498 | } |
| 499 | err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunction) |
| 500 | assert.Nil(t, err) |
| 501 | } |
| 502 | |
| 503 | func (nb *NBTest) testForceDeleteDeviceFailure(t *testing.T, nbi *NBIHandler) { |
| 504 | // Create a valid device |
| 505 | oltDevice, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName, MacAddress: "aa:bb:cc:cc:ee:ee"}) |
| 506 | assert.Nil(t, err) |
| 507 | assert.NotNil(t, oltDevice) |
| 508 | device, err := nbi.GetDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 509 | assert.Nil(t, err) |
| 510 | assert.NotNil(t, device) |
| 511 | assert.Equal(t, oltDevice.String(), device.String()) |
| 512 | |
| 513 | nb.enableDevice(t, nbi, oltDevice) |
| 514 | nb.oltAdapter.SetDeleteAction(true) |
| 515 | //Remove the device |
| 516 | _, err = nbi.ForceDeleteDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 517 | assert.Nil(t, err) |
| 518 | |
| 519 | //Ensure there are no devices in the Core although delete was failed - wait until condition satisfied or timeout |
| 520 | var vFunction isDevicesConditionSatisfied = func(devices *voltha.Devices) bool { |
| 521 | return devices != nil && len(devices.Items) == 0 |
| 522 | } |
| 523 | err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunction) |
| 524 | assert.Nil(t, err) |
| 525 | |
| 526 | } |
| 527 | |
| 528 | func (nb *NBTest) testDeleteDeviceFailure(t *testing.T, nbi *NBIHandler) { |
| 529 | // Create a valid device |
| 530 | oltDevice, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName, MacAddress: "aa:bb:cc:cc:ee:ee"}) |
| 531 | assert.Nil(t, err) |
| 532 | assert.NotNil(t, oltDevice) |
| 533 | device, err := nbi.GetDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 534 | assert.Nil(t, err) |
| 535 | assert.NotNil(t, device) |
| 536 | assert.Equal(t, oltDevice.String(), device.String()) |
| 537 | |
| 538 | nb.enableDevice(t, nbi, oltDevice) |
| 539 | |
| 540 | nb.oltAdapter.SetDeleteAction(true) |
| 541 | //Remove the device |
| 542 | _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 543 | assert.Nil(t, err) |
| 544 | |
| 545 | //Ensure there are devices in the Core as delete was failed - wait until condition satisfied or timeout |
| 546 | var vFunction1 isDevicesConditionSatisfied = func(devices *voltha.Devices) bool { |
Maninder | a496f85 | 2021-02-22 09:57:56 +0530 | [diff] [blame] | 547 | state, err := nbi.GetTransientState(getContext(), oltDevice.Id) |
| 548 | if err != nil { |
| 549 | return false |
| 550 | } |
| 551 | return devices != nil && len(devices.Items) == (nb.numONUPerOLT+1) && |
| 552 | state == voltha.DeviceTransientState_DELETE_FAILED |
Himani Chawla | 2ba1c9c | 2020-10-07 13:19:03 +0530 | [diff] [blame] | 553 | } |
| 554 | err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunction1) |
| 555 | assert.Nil(t, err) |
| 556 | |
| 557 | nb.oltAdapter.SetDeleteAction(false) |
| 558 | |
| 559 | // Now Force Delete this device |
| 560 | _, err = nbi.ForceDeleteDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 561 | assert.Nil(t, err) |
| 562 | |
| 563 | //Ensure there are devices in the Core as delete was failed - wait until condition satisfied or timeout |
| 564 | var vFunction2 isDevicesConditionSatisfied = func(devices *voltha.Devices) bool { |
| 565 | return devices != nil && len(devices.Items) == 0 |
| 566 | } |
| 567 | err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunction2) |
| 568 | assert.Nil(t, err) |
| 569 | |
| 570 | } |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 571 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 572 | func (nb *NBTest) testEnableDevice(t *testing.T, nbi *NBIHandler) { |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 573 | // Create a device that has no adapter registered |
| 574 | oltDeviceNoAdapter, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: "noAdapterRegistered", MacAddress: "aa:bb:cc:cc:ee:ff"}) |
| 575 | assert.Nil(t, err) |
| 576 | assert.NotNil(t, oltDeviceNoAdapter) |
| 577 | |
| 578 | // Try to enable the oltDevice and check the error message |
| 579 | _, err = nbi.EnableDevice(getContext(), &voltha.ID{Id: oltDeviceNoAdapter.Id}) |
| 580 | assert.NotNil(t, err) |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 581 | assert.Equal(t, "adapter-not-registered-for-device-type noAdapterRegistered", err.Error()) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 582 | |
| 583 | //Remove the device |
| 584 | _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: oltDeviceNoAdapter.Id}) |
| 585 | assert.Nil(t, err) |
| 586 | |
| 587 | //Ensure there are no devices in the Core now - wait until condition satisfied or timeout |
| 588 | var vdFunction isDevicesConditionSatisfied = func(devices *voltha.Devices) bool { |
| 589 | return devices != nil && len(devices.Items) == 0 |
| 590 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 591 | err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vdFunction) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 592 | assert.Nil(t, err) |
| 593 | |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 594 | // Create a logical device monitor will automatically send trap and eapol flows to the devices being enables |
| 595 | var wg sync.WaitGroup |
| 596 | wg.Add(1) |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 597 | go nb.monitorLogicalDevice(t, nbi, 1, nb.numONUPerOLT, &wg, false, false) |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 598 | |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 599 | // Create the device with valid data |
| 600 | oltDevice, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName, MacAddress: "aa:bb:cc:cc:ee:ee"}) |
| 601 | assert.Nil(t, err) |
| 602 | assert.NotNil(t, oltDevice) |
| 603 | |
| 604 | // Verify oltDevice exist in the core |
| 605 | devices, err := nbi.ListDevices(getContext(), &empty.Empty{}) |
| 606 | assert.Nil(t, err) |
| 607 | assert.Equal(t, 1, len(devices.Items)) |
| 608 | assert.Equal(t, oltDevice.Id, devices.Items[0].Id) |
| 609 | |
| 610 | // Enable the oltDevice |
| 611 | _, err = nbi.EnableDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 612 | assert.Nil(t, err) |
| 613 | |
| 614 | // Wait for the logical device to be in the ready state |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 615 | var vldFunction = func(ports []*voltha.LogicalPort) bool { |
| 616 | return len(ports) == nb.numONUPerOLT+1 |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 617 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 618 | err = waitUntilLogicalDevicePortsReadiness(oltDevice.Id, nb.maxTimeout, nbi, vldFunction) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 619 | assert.Nil(t, err) |
| 620 | |
| 621 | // Verify that the devices have been setup correctly |
| 622 | nb.verifyDevices(t, nbi) |
| 623 | |
| 624 | // Get latest oltDevice data |
| 625 | oltDevice, err = nbi.GetDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 626 | assert.Nil(t, err) |
| 627 | |
| 628 | // Verify that the logical device has been setup correctly |
| 629 | nb.verifyLogicalDevices(t, oltDevice, nbi) |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 630 | |
| 631 | // Wait until all flows has been sent to the devices successfully |
| 632 | wg.Wait() |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 633 | } |
| 634 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 635 | func (nb *NBTest) testDisableAndReEnableRootDevice(t *testing.T, nbi *NBIHandler) { |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 636 | //Get an OLT device |
| 637 | oltDevice, err := nb.getADevice(true, nbi) |
| 638 | assert.Nil(t, err) |
| 639 | assert.NotNil(t, oltDevice) |
| 640 | |
| 641 | // Disable the oltDevice |
| 642 | _, err = nbi.DisableDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 643 | assert.Nil(t, err) |
| 644 | |
| 645 | // Wait for the old device to be disabled |
| 646 | var vdFunction isDeviceConditionSatisfied = func(device *voltha.Device) bool { |
| 647 | return device.AdminState == voltha.AdminState_DISABLED && device.OperStatus == voltha.OperStatus_UNKNOWN |
| 648 | } |
| 649 | err = waitUntilDeviceReadiness(oltDevice.Id, nb.maxTimeout, vdFunction, nbi) |
| 650 | assert.Nil(t, err) |
| 651 | |
| 652 | // Verify that all onu devices are disabled as well |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 653 | onuDevices, err := nb.deviceMgr.GetAllChildDevices(getContext(), oltDevice.Id) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 654 | assert.Nil(t, err) |
| 655 | for _, onu := range onuDevices.Items { |
| 656 | err = waitUntilDeviceReadiness(onu.Id, nb.maxTimeout, vdFunction, nbi) |
| 657 | assert.Nil(t, err) |
| 658 | } |
| 659 | |
| 660 | // Wait for the logical device to satisfy the expected condition |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 661 | var vlFunction = func(ports []*voltha.LogicalPort) bool { |
| 662 | for _, lp := range ports { |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 663 | if (lp.OfpPort.Config&uint32(ofp.OfpPortConfig_OFPPC_PORT_DOWN) != lp.OfpPort.Config) || |
| 664 | lp.OfpPort.State != uint32(ofp.OfpPortState_OFPPS_LINK_DOWN) { |
| 665 | return false |
| 666 | } |
| 667 | } |
| 668 | return true |
| 669 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 670 | err = waitUntilLogicalDevicePortsReadiness(oltDevice.Id, nb.maxTimeout, nbi, vlFunction) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 671 | assert.Nil(t, err) |
| 672 | |
| 673 | // Reenable the oltDevice |
| 674 | _, err = nbi.EnableDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 675 | assert.Nil(t, err) |
| 676 | |
| 677 | // Wait for the old device to be enabled |
| 678 | vdFunction = func(device *voltha.Device) bool { |
| 679 | return device.AdminState == voltha.AdminState_ENABLED && device.OperStatus == voltha.OperStatus_ACTIVE |
| 680 | } |
| 681 | err = waitUntilDeviceReadiness(oltDevice.Id, nb.maxTimeout, vdFunction, nbi) |
| 682 | assert.Nil(t, err) |
| 683 | |
| 684 | // Verify that all onu devices are enabled as well |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 685 | onuDevices, err = nb.deviceMgr.GetAllChildDevices(getContext(), oltDevice.Id) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 686 | assert.Nil(t, err) |
| 687 | for _, onu := range onuDevices.Items { |
| 688 | err = waitUntilDeviceReadiness(onu.Id, nb.maxTimeout, vdFunction, nbi) |
| 689 | assert.Nil(t, err) |
| 690 | } |
| 691 | |
| 692 | // Wait for the logical device to satisfy the expected condition |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 693 | vlFunction = func(ports []*voltha.LogicalPort) bool { |
| 694 | for _, lp := range ports { |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 695 | if (lp.OfpPort.Config&^uint32(ofp.OfpPortConfig_OFPPC_PORT_DOWN) != lp.OfpPort.Config) || |
| 696 | lp.OfpPort.State != uint32(ofp.OfpPortState_OFPPS_LIVE) { |
| 697 | return false |
| 698 | } |
| 699 | } |
| 700 | return true |
| 701 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 702 | err = waitUntilLogicalDevicePortsReadiness(oltDevice.Id, nb.maxTimeout, nbi, vlFunction) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 703 | assert.Nil(t, err) |
| 704 | } |
| 705 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 706 | func (nb *NBTest) testDisableAndDeleteAllDevice(t *testing.T, nbi *NBIHandler) { |
khenaidoo | 93d5a3d | 2020-01-15 12:37:05 -0500 | [diff] [blame] | 707 | //Get an OLT device |
| 708 | oltDevice, err := nb.getADevice(true, nbi) |
| 709 | assert.Nil(t, err) |
| 710 | assert.NotNil(t, oltDevice) |
| 711 | |
| 712 | // Disable the oltDevice |
| 713 | _, err = nbi.DisableDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 714 | assert.Nil(t, err) |
| 715 | |
| 716 | // Wait for the olt device to be disabled |
| 717 | var vdFunction isDeviceConditionSatisfied = func(device *voltha.Device) bool { |
| 718 | return device.AdminState == voltha.AdminState_DISABLED && device.OperStatus == voltha.OperStatus_UNKNOWN |
| 719 | } |
| 720 | err = waitUntilDeviceReadiness(oltDevice.Id, nb.maxTimeout, vdFunction, nbi) |
| 721 | assert.Nil(t, err) |
| 722 | |
| 723 | // Verify that all onu devices are disabled as well |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 724 | onuDevices, err := nb.deviceMgr.GetAllChildDevices(getContext(), oltDevice.Id) |
khenaidoo | 93d5a3d | 2020-01-15 12:37:05 -0500 | [diff] [blame] | 725 | assert.Nil(t, err) |
| 726 | for _, onu := range onuDevices.Items { |
| 727 | err = waitUntilDeviceReadiness(onu.Id, nb.maxTimeout, vdFunction, nbi) |
| 728 | assert.Nil(t, err) |
| 729 | } |
| 730 | |
| 731 | // Delete the oltDevice |
| 732 | _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 733 | assert.Nil(t, err) |
| 734 | |
| 735 | var vFunction isDevicesConditionSatisfied = func(devices *voltha.Devices) bool { |
| 736 | return devices != nil && len(devices.Items) == 0 |
| 737 | } |
| 738 | err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunction) |
| 739 | assert.Nil(t, err) |
| 740 | |
| 741 | // Wait for absence of logical device |
| 742 | var vlFunction isLogicalDevicesConditionSatisfied = func(lds *voltha.LogicalDevices) bool { |
| 743 | return lds != nil && len(lds.Items) == 0 |
| 744 | } |
| 745 | |
| 746 | err = waitUntilConditionForLogicalDevices(nb.maxTimeout, nbi, vlFunction) |
| 747 | assert.Nil(t, err) |
| 748 | } |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 749 | |
| 750 | func (nb *NBTest) deleteAllDevices(t *testing.T, nbi *NBIHandler) { |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 751 | devices, _ := nbi.ListDevices(getContext(), &empty.Empty{}) |
| 752 | if len(devices.Items) == 0 { |
| 753 | // Nothing to do |
| 754 | return |
| 755 | } |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 756 | //Get an OLT device |
| 757 | oltDevice, err := nb.getADevice(true, nbi) |
| 758 | assert.Nil(t, err) |
| 759 | assert.NotNil(t, oltDevice) |
| 760 | |
| 761 | // Delete the oltDevice |
| 762 | _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 763 | assert.Nil(t, err) |
| 764 | |
| 765 | // Wait for all devices to be deleted |
| 766 | vFunction := func(devices *voltha.Devices) bool { |
| 767 | return devices != nil && len(devices.Items) == 0 |
| 768 | } |
| 769 | err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunction) |
| 770 | assert.Nil(t, err) |
| 771 | |
| 772 | // Wait for absence of logical device |
| 773 | vlFunction := func(lds *voltha.LogicalDevices) bool { |
| 774 | return lds != nil && len(lds.Items) == 0 |
| 775 | } |
| 776 | |
| 777 | err = waitUntilConditionForLogicalDevices(nb.maxTimeout, nbi, vlFunction) |
| 778 | assert.Nil(t, err) |
| 779 | } |
| 780 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 781 | func (nb *NBTest) testEnableAndDeleteAllDevice(t *testing.T, nbi *NBIHandler) { |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 782 | //Create the device with valid data |
| 783 | oltDevice, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName, MacAddress: "aa:bb:cc:cc:ee:ee"}) |
| 784 | assert.Nil(t, err) |
| 785 | assert.NotNil(t, oltDevice) |
| 786 | |
| 787 | //Get an OLT device |
| 788 | oltDevice, err = nb.getADevice(true, nbi) |
| 789 | assert.Nil(t, err) |
| 790 | assert.NotNil(t, oltDevice) |
| 791 | |
| 792 | // Enable the oltDevice |
| 793 | _, err = nbi.EnableDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 794 | assert.Nil(t, err) |
| 795 | |
| 796 | // Wait for the logical device to be in the ready state |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 797 | var vldFunction = func(ports []*voltha.LogicalPort) bool { |
| 798 | return len(ports) == nb.numONUPerOLT+1 |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 799 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 800 | err = waitUntilLogicalDevicePortsReadiness(oltDevice.Id, nb.maxTimeout, nbi, vldFunction) |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 801 | assert.Nil(t, err) |
| 802 | |
| 803 | //Get all child devices |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 804 | onuDevices, err := nb.deviceMgr.GetAllChildDevices(getContext(), oltDevice.Id) |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 805 | assert.Nil(t, err) |
| 806 | |
| 807 | // Wait for the all onu devices to be enabled |
| 808 | var vdFunction isDeviceConditionSatisfied = func(device *voltha.Device) bool { |
| 809 | return device.AdminState == voltha.AdminState_ENABLED |
| 810 | } |
| 811 | for _, onu := range onuDevices.Items { |
| 812 | err = waitUntilDeviceReadiness(onu.Id, nb.maxTimeout, vdFunction, nbi) |
| 813 | assert.Nil(t, err) |
| 814 | } |
Chaitrashree G S | e8ad020 | 2020-02-27 18:48:00 -0500 | [diff] [blame] | 815 | // Wait for each onu device to get deleted |
| 816 | var vdFunc isDeviceConditionSatisfied = func(device *voltha.Device) bool { |
| 817 | return device == nil |
| 818 | } |
| 819 | |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 820 | // Delete the onuDevice |
| 821 | for _, onu := range onuDevices.Items { |
| 822 | _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: onu.Id}) |
| 823 | assert.Nil(t, err) |
Chaitrashree G S | e8ad020 | 2020-02-27 18:48:00 -0500 | [diff] [blame] | 824 | err = waitUntilDeviceReadiness(onu.Id, nb.maxTimeout, vdFunc, nbi) |
| 825 | assert.Nil(t, err) |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 826 | } |
Chaitrashree G S | e8ad020 | 2020-02-27 18:48:00 -0500 | [diff] [blame] | 827 | |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 828 | // Disable the oltDevice |
| 829 | _, err = nbi.DisableDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 830 | assert.Nil(t, err) |
| 831 | |
| 832 | // Wait for the olt device to be disabled |
| 833 | var vFunction isDeviceConditionSatisfied = func(device *voltha.Device) bool { |
| 834 | return device.AdminState == voltha.AdminState_DISABLED && device.OperStatus == voltha.OperStatus_UNKNOWN |
| 835 | } |
| 836 | err = waitUntilDeviceReadiness(oltDevice.Id, nb.maxTimeout, vFunction, nbi) |
| 837 | assert.Nil(t, err) |
| 838 | |
| 839 | // Delete the oltDevice |
| 840 | _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 841 | assert.Nil(t, err) |
| 842 | |
| 843 | var vFunc isDevicesConditionSatisfied = func(devices *voltha.Devices) bool { |
| 844 | return devices != nil && len(devices.Items) == 0 |
| 845 | } |
| 846 | err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunc) |
| 847 | assert.Nil(t, err) |
| 848 | } |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 849 | func (nb *NBTest) testDisableAndEnablePort(t *testing.T, nbi *NBIHandler) { |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 850 | //Get an OLT device |
| 851 | var cp *voltha.Port |
| 852 | oltDevice, err := nb.getADevice(true, nbi) |
| 853 | assert.Nil(t, err) |
| 854 | assert.NotNil(t, oltDevice) |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 855 | oltPorts, err := nbi.ListDevicePorts(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 856 | assert.Nil(t, err) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 857 | |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 858 | for _, cp = range oltPorts.Items { |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 859 | if cp.Type == voltha.Port_PON_OLT { |
| 860 | break |
| 861 | } |
| 862 | |
| 863 | } |
| 864 | assert.NotNil(t, cp) |
| 865 | cp.DeviceId = oltDevice.Id |
| 866 | |
| 867 | // Disable the NW Port of oltDevice |
| 868 | _, err = nbi.DisablePort(getContext(), cp) |
| 869 | assert.Nil(t, err) |
| 870 | // Wait for the olt device Port to be disabled |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 871 | var vdFunction isDevicePortsConditionSatisfied = func(ports *voltha.Ports) bool { |
| 872 | for _, port := range ports.Items { |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 873 | if port.PortNo == cp.PortNo { |
| 874 | return port.AdminState == voltha.AdminState_DISABLED |
| 875 | } |
| 876 | } |
| 877 | return false |
| 878 | } |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 879 | err = waitUntilDevicePortsReadiness(oltDevice.Id, nb.maxTimeout, vdFunction, nbi) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 880 | assert.Nil(t, err) |
| 881 | // Wait for the logical device to satisfy the expected condition |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 882 | var vlFunction = func(ports []*voltha.LogicalPort) bool { |
| 883 | for _, lp := range ports { |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 884 | if (lp.OfpPort.Config&^uint32(ofp.OfpPortConfig_OFPPC_PORT_DOWN) != lp.OfpPort.Config) || |
| 885 | lp.OfpPort.State != uint32(ofp.OfpPortState_OFPPS_LIVE) { |
| 886 | return false |
| 887 | } |
| 888 | } |
| 889 | return true |
| 890 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 891 | err = waitUntilLogicalDevicePortsReadiness(oltDevice.Id, nb.maxTimeout, nbi, vlFunction) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 892 | assert.Nil(t, err) |
| 893 | |
| 894 | // Enable the NW Port of oltDevice |
| 895 | _, err = nbi.EnablePort(getContext(), cp) |
| 896 | assert.Nil(t, err) |
| 897 | |
| 898 | // Wait for the olt device Port to be enabled |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 899 | vdFunction = func(ports *voltha.Ports) bool { |
| 900 | for _, port := range ports.Items { |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 901 | if port.PortNo == cp.PortNo { |
| 902 | return port.AdminState == voltha.AdminState_ENABLED |
| 903 | } |
| 904 | } |
| 905 | return false |
| 906 | } |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 907 | err = waitUntilDevicePortsReadiness(oltDevice.Id, nb.maxTimeout, vdFunction, nbi) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 908 | assert.Nil(t, err) |
| 909 | // Wait for the logical device to satisfy the expected condition |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 910 | vlFunction = func(ports []*voltha.LogicalPort) bool { |
| 911 | for _, lp := range ports { |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 912 | if (lp.OfpPort.Config&^uint32(ofp.OfpPortConfig_OFPPC_PORT_DOWN) != lp.OfpPort.Config) || |
| 913 | lp.OfpPort.State != uint32(ofp.OfpPortState_OFPPS_LIVE) { |
| 914 | return false |
| 915 | } |
| 916 | } |
| 917 | return true |
| 918 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 919 | err = waitUntilLogicalDevicePortsReadiness(oltDevice.Id, nb.maxTimeout, nbi, vlFunction) |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 920 | assert.Nil(t, err) |
| 921 | |
| 922 | // Disable a non-PON port |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 923 | for _, cp = range oltPorts.Items { |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 924 | if cp.Type != voltha.Port_PON_OLT { |
| 925 | break |
| 926 | } |
| 927 | |
| 928 | } |
| 929 | assert.NotNil(t, cp) |
| 930 | cp.DeviceId = oltDevice.Id |
| 931 | |
| 932 | // Disable the NW Port of oltDevice |
| 933 | _, err = nbi.DisablePort(getContext(), cp) |
| 934 | assert.NotNil(t, err) |
| 935 | |
| 936 | } |
khenaidoo | 93d5a3d | 2020-01-15 12:37:05 -0500 | [diff] [blame] | 937 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 938 | func (nb *NBTest) testDeviceRebootWhenOltIsEnabled(t *testing.T, nbi *NBIHandler) { |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 939 | //Get an OLT device |
| 940 | oltDevice, err := nb.getADevice(true, nbi) |
| 941 | assert.Nil(t, err) |
| 942 | assert.NotNil(t, oltDevice) |
| 943 | assert.Equal(t, oltDevice.ConnectStatus, voltha.ConnectStatus_REACHABLE) |
| 944 | assert.Equal(t, oltDevice.AdminState, voltha.AdminState_ENABLED) |
| 945 | |
| 946 | // Verify that we have one or more ONUs to start with |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 947 | onuDevices, err := nb.deviceMgr.GetAllChildDevices(getContext(), oltDevice.Id) |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 948 | assert.Nil(t, err) |
| 949 | assert.NotNil(t, onuDevices) |
| 950 | assert.Greater(t, len(onuDevices.Items), 0) |
| 951 | |
| 952 | // Reboot the OLT and very that Connection Status goes to UNREACHABLE and operation status to UNKNOWN |
| 953 | _, err = nbi.RebootDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 954 | assert.Nil(t, err) |
| 955 | |
| 956 | var vlFunction0 = func(d *voltha.Device) bool { |
| 957 | return d.ConnectStatus == voltha.ConnectStatus_UNREACHABLE && d.OperStatus == voltha.OperStatus_UNKNOWN |
| 958 | } |
| 959 | |
| 960 | err = waitUntilDeviceReadiness(oltDevice.Id, nb.maxTimeout, vlFunction0, nbi) |
| 961 | assert.Nil(t, err) |
| 962 | |
| 963 | // Wait for the logical device to satisfy the expected condition |
| 964 | var vlFunction1 = func(ld *voltha.LogicalDevice) bool { |
| 965 | return ld == nil |
| 966 | } |
| 967 | |
| 968 | err = waitUntilLogicalDeviceReadiness(oltDevice.Id, nb.maxTimeout, nbi, vlFunction1) |
| 969 | assert.Nil(t, err) |
| 970 | |
| 971 | // Wait for the device to satisfy the expected condition (device does not have flows) |
| 972 | var vlFunction2 = func(d *voltha.Device) bool { |
| 973 | var deviceFlows *ofp.Flows |
| 974 | var err error |
| 975 | if deviceFlows, err = nbi.ListDeviceFlows(getContext(), &voltha.ID{Id: d.Id}); err != nil { |
| 976 | return false |
| 977 | } |
| 978 | return len(deviceFlows.Items) == 0 |
| 979 | } |
| 980 | |
| 981 | err = waitUntilDeviceReadiness(oltDevice.Id, nb.maxTimeout, vlFunction2, nbi) |
| 982 | assert.Nil(t, err) |
| 983 | |
| 984 | // Wait for the device to satisfy the expected condition (there are no child devices) |
| 985 | var vlFunction3 = func(d *voltha.Device) bool { |
| 986 | var devices *voltha.Devices |
| 987 | var err error |
| 988 | if devices, err = nbi.ListDevices(getContext(), nil); err != nil { |
| 989 | return false |
| 990 | } |
| 991 | for _, device := range devices.Items { |
| 992 | if device.ParentId == d.Id { |
| 993 | // We have a child device still left |
| 994 | return false |
| 995 | } |
| 996 | } |
| 997 | return true |
| 998 | } |
| 999 | |
| 1000 | err = waitUntilDeviceReadiness(oltDevice.Id, nb.maxTimeout, vlFunction3, nbi) |
| 1001 | assert.Nil(t, err) |
| 1002 | |
| 1003 | // Update the OLT Connection Status to REACHABLE and operation status to ACTIVE |
| 1004 | // Normally, in a real adapter this happens after connection regain via a heartbeat mechanism with real hardware |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 1005 | err = nbi.UpdateDeviceStatus(getContext(), oltDevice.Id, voltha.OperStatus_ACTIVE, voltha.ConnectStatus_REACHABLE) |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 1006 | assert.Nil(t, err) |
| 1007 | |
| 1008 | // Verify the device connection and operation states |
| 1009 | oltDevice, err = nb.getADevice(true, nbi) |
| 1010 | assert.Nil(t, err) |
| 1011 | assert.NotNil(t, oltDevice) |
| 1012 | assert.Equal(t, oltDevice.ConnectStatus, voltha.ConnectStatus_REACHABLE) |
| 1013 | assert.Equal(t, oltDevice.AdminState, voltha.AdminState_ENABLED) |
| 1014 | |
| 1015 | // Wait for the logical device to satisfy the expected condition |
| 1016 | var vlFunction4 = func(ld *voltha.LogicalDevice) bool { |
| 1017 | return ld != nil |
| 1018 | } |
| 1019 | err = waitUntilLogicalDeviceReadiness(oltDevice.Id, nb.maxTimeout, nbi, vlFunction4) |
| 1020 | assert.Nil(t, err) |
| 1021 | |
| 1022 | // Verify that logical device is created again |
| 1023 | logicalDevices, err := nbi.ListLogicalDevices(getContext(), &empty.Empty{}) |
| 1024 | assert.Nil(t, err) |
| 1025 | assert.NotNil(t, logicalDevices) |
| 1026 | assert.Equal(t, 1, len(logicalDevices.Items)) |
| 1027 | |
| 1028 | // Verify that we have no ONUs left |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 1029 | onuDevices, err = nb.deviceMgr.GetAllChildDevices(getContext(), oltDevice.Id) |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 1030 | assert.Nil(t, err) |
| 1031 | assert.NotNil(t, onuDevices) |
| 1032 | assert.Equal(t, 0, len(onuDevices.Items)) |
| 1033 | } |
| 1034 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 1035 | func (nb *NBTest) testStartOmciTestAction(t *testing.T, nbi *NBIHandler) { |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 1036 | // ----------------------------------------------------------------------- |
| 1037 | // SubTest 1: Omci test action should fail due to nonexistent device id |
| 1038 | |
| 1039 | request := &voltha.OmciTestRequest{Id: "123", Uuid: "456"} |
| 1040 | _, err := nbi.StartOmciTestAction(getContext(), request) |
| 1041 | assert.NotNil(t, err) |
| 1042 | assert.Equal(t, "rpc error: code = NotFound desc = 123", err.Error()) |
| 1043 | |
| 1044 | // ----------------------------------------------------------------------- |
| 1045 | // SubTest 2: Error should be returned for device with no adapter registered |
| 1046 | |
| 1047 | // Create a device that has no adapter registered |
| 1048 | deviceNoAdapter, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: "noAdapterRegisteredOmciTest", MacAddress: "aa:bb:cc:cc:ee:01"}) |
| 1049 | assert.Nil(t, err) |
| 1050 | assert.NotNil(t, deviceNoAdapter) |
| 1051 | |
| 1052 | // Omci test action should fail due to nonexistent adapter |
| 1053 | request = &voltha.OmciTestRequest{Id: deviceNoAdapter.Id, Uuid: "456"} |
| 1054 | _, err = nbi.StartOmciTestAction(getContext(), request) |
| 1055 | assert.NotNil(t, err) |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 1056 | assert.Equal(t, "adapter-not-registered-for-device-type noAdapterRegisteredOmciTest", err.Error()) |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 1057 | |
| 1058 | //Remove the device |
| 1059 | _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: deviceNoAdapter.Id}) |
| 1060 | assert.Nil(t, err) |
| 1061 | |
| 1062 | //Ensure there are no devices in the Core now - wait until condition satisfied or timeout |
| 1063 | var vFunction isDevicesConditionSatisfied = func(devices *voltha.Devices) bool { |
| 1064 | return devices != nil && len(devices.Items) == 0 |
| 1065 | } |
| 1066 | err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunction) |
| 1067 | assert.Nil(t, err) |
| 1068 | |
| 1069 | // ----------------------------------------------------------------------- |
| 1070 | // SubTest 3: Omci test action should succeed on valid ONU |
| 1071 | |
| 1072 | // Create the device with valid data |
| 1073 | oltDevice, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName, MacAddress: "aa:bb:cc:cc:ee:ee"}) |
| 1074 | assert.Nil(t, err) |
| 1075 | assert.NotNil(t, oltDevice) |
| 1076 | |
| 1077 | // Verify oltDevice exist in the core |
| 1078 | devices, err := nbi.ListDevices(getContext(), &empty.Empty{}) |
| 1079 | assert.Nil(t, err) |
| 1080 | assert.Equal(t, 1, len(devices.Items)) |
| 1081 | assert.Equal(t, oltDevice.Id, devices.Items[0].Id) |
| 1082 | |
| 1083 | // Enable the oltDevice |
| 1084 | _, err = nbi.EnableDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 1085 | assert.Nil(t, err) |
| 1086 | |
| 1087 | // Wait for the logical device to be in the ready state |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 1088 | var vldFunction = func(ports []*voltha.LogicalPort) bool { |
| 1089 | return len(ports) == nb.numONUPerOLT+1 |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 1090 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 1091 | err = waitUntilLogicalDevicePortsReadiness(oltDevice.Id, nb.maxTimeout, nbi, vldFunction) |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 1092 | assert.Nil(t, err) |
| 1093 | |
| 1094 | // Wait for the olt device to be enabled |
| 1095 | vdFunction := func(device *voltha.Device) bool { |
| 1096 | return device.AdminState == voltha.AdminState_ENABLED && device.OperStatus == voltha.OperStatus_ACTIVE |
| 1097 | } |
| 1098 | err = waitUntilDeviceReadiness(oltDevice.Id, nb.maxTimeout, vdFunction, nbi) |
| 1099 | assert.Nil(t, err) |
| 1100 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 1101 | onuDevices, err := nb.deviceMgr.GetAllChildDevices(getContext(), oltDevice.Id) |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 1102 | assert.Nil(t, err) |
| 1103 | assert.Greater(t, len(onuDevices.Items), 0) |
| 1104 | |
| 1105 | onuDevice := onuDevices.Items[0] |
| 1106 | |
| 1107 | // Omci test action should succeed |
| 1108 | request = &voltha.OmciTestRequest{Id: onuDevice.Id, Uuid: "456"} |
| 1109 | resp, err := nbi.StartOmciTestAction(getContext(), request) |
| 1110 | assert.Nil(t, err) |
| 1111 | assert.Equal(t, resp.Result, voltha.TestResponse_SUCCESS) |
| 1112 | |
| 1113 | //Remove the device |
| 1114 | _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 1115 | assert.Nil(t, err) |
| 1116 | //Ensure there are no devices in the Core now - wait until condition satisfied or timeout |
| 1117 | err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunction) |
| 1118 | assert.Nil(t, err) |
| 1119 | } |
| 1120 | |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1121 | func makeSimpleFlowMod(fa *flows.FlowArgs) *ofp.OfpFlowMod { |
| 1122 | matchFields := make([]*ofp.OfpOxmField, 0) |
| 1123 | for _, val := range fa.MatchFields { |
| 1124 | matchFields = append(matchFields, &ofp.OfpOxmField{Field: &ofp.OfpOxmField_OfbField{OfbField: val}}) |
| 1125 | } |
| 1126 | return flows.MkSimpleFlowMod(matchFields, fa.Actions, fa.Command, fa.KV) |
| 1127 | } |
| 1128 | |
| 1129 | func createMetadata(cTag int, techProfile int, port int) uint64 { |
| 1130 | md := 0 |
| 1131 | md = (md | (cTag & 0xFFFF)) << 16 |
| 1132 | md = (md | (techProfile & 0xFFFF)) << 32 |
| 1133 | return uint64(md | (port & 0xFFFFFFFF)) |
| 1134 | } |
| 1135 | |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 1136 | func (nb *NBTest) verifyLogicalDeviceFlowCount(t *testing.T, nbi *NBIHandler, numNNIPorts int, numUNIPorts int, flowAddFail bool) { |
Marcos Aurelio Carrero (Furukawa) | a61a72c | 2021-01-28 13:48:20 -0300 | [diff] [blame] | 1137 | expectedNumFlows := numNNIPorts*numTrapOnNNIFlows + numNNIPorts*numUNIPorts |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 1138 | if flowAddFail { |
| 1139 | expectedNumFlows = 0 |
| 1140 | } |
| 1141 | // Wait for logical device to have the flows (or none |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1142 | var vlFunction isLogicalDevicesConditionSatisfied = func(lds *voltha.LogicalDevices) bool { |
Mahir Gunyel | addb66a | 2020-04-29 18:08:50 -0700 | [diff] [blame] | 1143 | flows, _ := nbi.ListLogicalDeviceFlows(getContext(), &voltha.ID{Id: lds.Items[0].Id}) |
| 1144 | return lds != nil && len(lds.Items) == 1 && len(flows.Items) == expectedNumFlows |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1145 | } |
| 1146 | // No timeout implies a success |
| 1147 | err := waitUntilConditionForLogicalDevices(nb.maxTimeout, nbi, vlFunction) |
| 1148 | assert.Nil(t, err) |
| 1149 | } |
| 1150 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 1151 | func (nb *NBTest) sendTrapFlows(t *testing.T, nbi *NBIHandler, logicalDeviceID string, ports []*voltha.LogicalPort, meterID uint64, startingVlan int) (numNNIPorts, numUNIPorts int) { |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1152 | // Send flows for the parent device |
| 1153 | var nniPorts []*voltha.LogicalPort |
| 1154 | var uniPorts []*voltha.LogicalPort |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 1155 | for _, p := range ports { |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1156 | if p.RootPort { |
| 1157 | nniPorts = append(nniPorts, p) |
| 1158 | } else { |
| 1159 | uniPorts = append(uniPorts, p) |
| 1160 | } |
| 1161 | } |
| 1162 | assert.Equal(t, 1, len(nniPorts)) |
| 1163 | //assert.Greater(t, len(uniPorts), 1 ) |
| 1164 | nniPort := nniPorts[0].OfpPort.PortNo |
| 1165 | maxInt32 := uint64(0xFFFFFFFF) |
| 1166 | controllerPortMask := uint32(4294967293) // will result in 4294967293&0x7fffffff => 2147483645 which is the actual controller port |
| 1167 | var fa *flows.FlowArgs |
| 1168 | fa = &flows.FlowArgs{ |
| 1169 | KV: flows.OfpFlowModArgs{"priority": 10000, "buffer_id": maxInt32, "out_port": maxInt32, "out_group": maxInt32, "flags": 1}, |
| 1170 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1171 | flows.InPort(nniPort), |
| 1172 | flows.EthType(35020), |
| 1173 | }, |
| 1174 | Actions: []*ofp.OfpAction{ |
| 1175 | flows.Output(controllerPortMask), |
| 1176 | }, |
| 1177 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 1178 | flowLLDP := ofp.FlowTableUpdate{FlowMod: makeSimpleFlowMod(fa), Id: logicalDeviceID} |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1179 | _, err := nbi.UpdateLogicalDeviceFlowTable(getContext(), &flowLLDP) |
| 1180 | assert.Nil(t, err) |
| 1181 | |
| 1182 | fa = &flows.FlowArgs{ |
| 1183 | KV: flows.OfpFlowModArgs{"priority": 10000, "buffer_id": maxInt32, "out_port": maxInt32, "out_group": maxInt32, "flags": 1}, |
| 1184 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1185 | flows.InPort(nniPort), |
| 1186 | flows.EthType(2048), |
| 1187 | flows.IpProto(17), |
| 1188 | flows.UdpSrc(67), |
| 1189 | flows.UdpDst(68), |
| 1190 | }, |
| 1191 | Actions: []*ofp.OfpAction{ |
| 1192 | flows.Output(controllerPortMask), |
| 1193 | }, |
| 1194 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 1195 | flowIPV4 := ofp.FlowTableUpdate{FlowMod: makeSimpleFlowMod(fa), Id: logicalDeviceID} |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1196 | _, err = nbi.UpdateLogicalDeviceFlowTable(getContext(), &flowIPV4) |
| 1197 | assert.Nil(t, err) |
| 1198 | |
| 1199 | fa = &flows.FlowArgs{ |
| 1200 | KV: flows.OfpFlowModArgs{"priority": 10000, "buffer_id": maxInt32, "out_port": maxInt32, "out_group": maxInt32, "flags": 1}, |
| 1201 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1202 | flows.InPort(nniPort), |
| 1203 | flows.EthType(34525), |
| 1204 | flows.IpProto(17), |
| 1205 | flows.UdpSrc(546), |
| 1206 | flows.UdpDst(547), |
| 1207 | }, |
| 1208 | Actions: []*ofp.OfpAction{ |
| 1209 | flows.Output(controllerPortMask), |
| 1210 | }, |
| 1211 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 1212 | flowIPV6 := ofp.FlowTableUpdate{FlowMod: makeSimpleFlowMod(fa), Id: logicalDeviceID} |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1213 | _, err = nbi.UpdateLogicalDeviceFlowTable(getContext(), &flowIPV6) |
| 1214 | assert.Nil(t, err) |
| 1215 | |
Marcos Aurelio Carrero (Furukawa) | a61a72c | 2021-01-28 13:48:20 -0300 | [diff] [blame] | 1216 | fa = &flows.FlowArgs{ |
| 1217 | KV: flows.OfpFlowModArgs{"priority": 10000, "buffer_id": maxInt32, "out_port": maxInt32, "out_group": maxInt32, "flags": 1}, |
| 1218 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1219 | flows.InPort(nniPort), |
| 1220 | flows.EthType(34915), |
| 1221 | }, |
| 1222 | Actions: []*ofp.OfpAction{ |
| 1223 | flows.Output(controllerPortMask), |
| 1224 | }, |
| 1225 | } |
| 1226 | flowPPPoEP := ofp.FlowTableUpdate{FlowMod: makeSimpleFlowMod(fa), Id: logicalDeviceID} |
| 1227 | _, err = nbi.UpdateLogicalDeviceFlowTable(getContext(), &flowPPPoEP) |
| 1228 | assert.Nil(t, err) |
| 1229 | |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1230 | return len(nniPorts), len(uniPorts) |
| 1231 | } |
| 1232 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 1233 | func (nb *NBTest) sendEAPFlows(t *testing.T, nbi *NBIHandler, logicalDeviceID string, port *ofp.OfpPort, vlan int, meterID uint64) { |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1234 | maxInt32 := uint64(0xFFFFFFFF) |
| 1235 | controllerPortMask := uint32(4294967293) // will result in 4294967293&0x7fffffff => 2147483645 which is the actual controller port |
| 1236 | fa := &flows.FlowArgs{ |
| 1237 | KV: flows.OfpFlowModArgs{"priority": 10000, "buffer_id": maxInt32, "out_port": maxInt32, "out_group": maxInt32, "flags": 1, "write_metadata": createMetadata(vlan, 64, 0), "meter_id": meterID}, |
| 1238 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1239 | flows.InPort(port.PortNo), |
| 1240 | flows.EthType(34958), |
| 1241 | flows.VlanVid(8187), |
| 1242 | }, |
| 1243 | Actions: []*ofp.OfpAction{ |
| 1244 | flows.Output(controllerPortMask), |
| 1245 | }, |
| 1246 | } |
| 1247 | flowEAP := ofp.FlowTableUpdate{FlowMod: makeSimpleFlowMod(fa), Id: logicalDeviceID} |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 1248 | maxTries := 3 |
| 1249 | var err error |
| 1250 | for { |
| 1251 | if _, err = nbi.UpdateLogicalDeviceFlowTable(getContext(), &flowEAP); err == nil { |
| 1252 | if maxTries < 3 { |
| 1253 | t.Log("Re-sending EAPOL flow succeeded for port:", port) |
| 1254 | } |
| 1255 | break |
| 1256 | } |
| 1257 | t.Log("Sending EAPOL flows fail:", err) |
| 1258 | time.Sleep(50 * time.Millisecond) |
| 1259 | maxTries-- |
| 1260 | if maxTries == 0 { |
| 1261 | break |
| 1262 | } |
| 1263 | } |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1264 | assert.Nil(t, err) |
| 1265 | } |
| 1266 | |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 1267 | func (nb *NBTest) monitorLogicalDevice(t *testing.T, nbi *NBIHandler, numNNIPorts int, numUNIPorts int, wg *sync.WaitGroup, flowAddFail bool, flowDeleteFail bool) { |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1268 | defer wg.Done() |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1269 | |
| 1270 | // Clear any existing flows on the adapters |
| 1271 | nb.oltAdapter.ClearFlows() |
| 1272 | nb.onuAdapter.ClearFlows() |
| 1273 | |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 1274 | // Set the adapter actions on flow addition/deletion |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 1275 | nb.oltAdapter.SetFlowAction(flowAddFail, flowDeleteFail) |
| 1276 | nb.onuAdapter.SetFlowAction(flowAddFail, flowDeleteFail) |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 1277 | |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1278 | // Wait until a logical device is ready |
| 1279 | var vlFunction isLogicalDevicesConditionSatisfied = func(lds *voltha.LogicalDevices) bool { |
Matteo Scandolo | ad5e14f | 2021-03-23 10:32:28 -0700 | [diff] [blame] | 1280 | if lds == nil || len(lds.Items) != 1 || lds.Items[0] == nil { |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1281 | return false |
| 1282 | } |
| 1283 | // Ensure there are both NNI ports and at least one UNI port on the logical device |
| 1284 | ld := lds.Items[0] |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 1285 | ports, err := nbi.ListLogicalDevicePorts(getContext(), &voltha.ID{Id: ld.Id}) |
| 1286 | if err != nil { |
| 1287 | return false |
| 1288 | } |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1289 | nniPort := false |
| 1290 | uniPort := false |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 1291 | for _, p := range ports.Items { |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1292 | nniPort = nniPort || p.RootPort == true |
| 1293 | uniPort = uniPort || p.RootPort == false |
| 1294 | if nniPort && uniPort { |
| 1295 | return true |
| 1296 | } |
| 1297 | } |
| 1298 | return false |
| 1299 | } |
| 1300 | err := waitUntilConditionForLogicalDevices(nb.maxTimeout, nbi, vlFunction) |
| 1301 | assert.Nil(t, err) |
| 1302 | |
| 1303 | logicalDevices, err := nbi.ListLogicalDevices(getContext(), &empty.Empty{}) |
| 1304 | assert.Nil(t, err) |
| 1305 | assert.NotNil(t, logicalDevices) |
| 1306 | assert.Equal(t, 1, len(logicalDevices.Items)) |
| 1307 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 1308 | logicalDeviceID := logicalDevices.Items[0].Id |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1309 | meterID := rand.Uint32() |
| 1310 | |
| 1311 | // Add a meter to the logical device |
| 1312 | meterMod := &ofp.OfpMeterMod{ |
| 1313 | Command: ofp.OfpMeterModCommand_OFPMC_ADD, |
| 1314 | Flags: rand.Uint32(), |
| 1315 | MeterId: meterID, |
| 1316 | Bands: []*ofp.OfpMeterBandHeader{ |
| 1317 | {Type: ofp.OfpMeterBandType_OFPMBT_EXPERIMENTER, |
| 1318 | Rate: rand.Uint32(), |
| 1319 | BurstSize: rand.Uint32(), |
| 1320 | Data: nil, |
| 1321 | }, |
| 1322 | }, |
| 1323 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 1324 | _, err = nbi.UpdateLogicalDeviceMeterTable(getContext(), &ofp.MeterModUpdate{Id: logicalDeviceID, MeterMod: meterMod}) |
| 1325 | assert.Nil(t, err) |
| 1326 | |
| 1327 | ports, err := nbi.ListLogicalDevicePorts(getContext(), &voltha.ID{Id: logicalDeviceID}) |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1328 | assert.Nil(t, err) |
| 1329 | |
| 1330 | // Send initial set of Trap flows |
| 1331 | startingVlan := 4091 |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 1332 | nb.sendTrapFlows(t, nbi, logicalDeviceID, ports.Items, uint64(meterID), startingVlan) |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1333 | |
| 1334 | // Listen for port events |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 1335 | start := time.Now() |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 1336 | processedNniLogicalPorts := 0 |
| 1337 | processedUniLogicalPorts := 0 |
| 1338 | |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 1339 | for event := range nbi.GetChangeEventsQueueForTest() { |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1340 | startingVlan++ |
| 1341 | if portStatus, ok := (event.Event).(*ofp.ChangeEvent_PortStatus); ok { |
| 1342 | ps := portStatus.PortStatus |
| 1343 | if ps.Reason == ofp.OfpPortReason_OFPPR_ADD { |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1344 | if ps.Desc.PortNo >= uint32(nb.startingUNIPortNo) { |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 1345 | processedUniLogicalPorts++ |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 1346 | nb.sendEAPFlows(t, nbi, logicalDeviceID, ps.Desc, startingVlan, uint64(meterID)) |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 1347 | } else { |
| 1348 | processedNniLogicalPorts++ |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1349 | } |
| 1350 | } |
| 1351 | } |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 1352 | |
| 1353 | if processedNniLogicalPorts >= numNNIPorts && processedUniLogicalPorts >= numUNIPorts { |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 1354 | fmt.Println("Total time to send all flows:", time.Since(start)) |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1355 | break |
| 1356 | } |
| 1357 | } |
| 1358 | //Verify the flow count on the logical device |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 1359 | nb.verifyLogicalDeviceFlowCount(t, nbi, numNNIPorts, numUNIPorts, flowAddFail) |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1360 | |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 1361 | // Wait until all flows have been sent to the OLT adapters (or all failed) |
Marcos Aurelio Carrero (Furukawa) | a61a72c | 2021-01-28 13:48:20 -0300 | [diff] [blame] | 1362 | expectedFlowCount := (numNNIPorts * numTrapOnNNIFlows) + numNNIPorts*numUNIPorts |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 1363 | if flowAddFail { |
| 1364 | expectedFlowCount = 0 |
| 1365 | } |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1366 | var oltVFunc isConditionSatisfied = func() bool { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 1367 | return nb.oltAdapter.GetFlowCount() >= expectedFlowCount |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1368 | } |
| 1369 | err = waitUntilCondition(nb.maxTimeout, nbi, oltVFunc) |
| 1370 | assert.Nil(t, err) |
| 1371 | |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 1372 | // Wait until all flows have been sent to the ONU adapters (or all failed) |
| 1373 | expectedFlowCount = numUNIPorts |
| 1374 | if flowAddFail { |
| 1375 | expectedFlowCount = 0 |
| 1376 | } |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1377 | var onuVFunc isConditionSatisfied = func() bool { |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 1378 | return nb.onuAdapter.GetFlowCount() == expectedFlowCount |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1379 | } |
| 1380 | err = waitUntilCondition(nb.maxTimeout, nbi, onuVFunc) |
| 1381 | assert.Nil(t, err) |
| 1382 | } |
| 1383 | |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 1384 | func (nb *NBTest) testFlowAddFailure(t *testing.T, nbi *NBIHandler) { |
| 1385 | |
| 1386 | // Create a logical device monitor will automatically send trap and eapol flows to the devices being enables |
| 1387 | var wg sync.WaitGroup |
| 1388 | wg.Add(1) |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 1389 | go nb.monitorLogicalDevice(t, nbi, 1, nb.numONUPerOLT, &wg, true, false) |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 1390 | |
| 1391 | // Create the device with valid data |
| 1392 | oltDevice, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName, MacAddress: "aa:bb:cc:cc:ee:ee"}) |
| 1393 | assert.Nil(t, err) |
| 1394 | assert.NotNil(t, oltDevice) |
| 1395 | |
| 1396 | // Verify oltDevice exist in the core |
| 1397 | devices, err := nbi.ListDevices(getContext(), &empty.Empty{}) |
| 1398 | assert.Nil(t, err) |
| 1399 | assert.Equal(t, 1, len(devices.Items)) |
| 1400 | assert.Equal(t, oltDevice.Id, devices.Items[0].Id) |
| 1401 | |
| 1402 | // Enable the oltDevice |
| 1403 | _, err = nbi.EnableDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 1404 | assert.Nil(t, err) |
| 1405 | |
| 1406 | // Wait for the logical device to be in the ready state |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 1407 | var vldFunction = func(ports []*voltha.LogicalPort) bool { |
| 1408 | return len(ports) == nb.numONUPerOLT+1 |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 1409 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 1410 | err = waitUntilLogicalDevicePortsReadiness(oltDevice.Id, nb.maxTimeout, nbi, vldFunction) |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 1411 | assert.Nil(t, err) |
| 1412 | |
| 1413 | // Verify that the devices have been setup correctly |
| 1414 | nb.verifyDevices(t, nbi) |
| 1415 | |
| 1416 | // Get latest oltDevice data |
| 1417 | oltDevice, err = nbi.GetDevice(getContext(), &voltha.ID{Id: oltDevice.Id}) |
| 1418 | assert.Nil(t, err) |
| 1419 | |
| 1420 | // Verify that the logical device has been setup correctly |
| 1421 | nb.verifyLogicalDevices(t, oltDevice, nbi) |
| 1422 | |
| 1423 | // Wait until all flows has been sent to the devices successfully |
| 1424 | wg.Wait() |
| 1425 | } |
| 1426 | |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 1427 | func TestSuiteNbiApiHandler(t *testing.T) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 1428 | ctx := context.Background() |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 1429 | f, err := os.Create("../../../tests/results/profile.cpu") |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1430 | if err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 1431 | logger.Fatalf(ctx, "could not create CPU profile: %v\n ", err) |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1432 | } |
| 1433 | defer f.Close() |
| 1434 | runtime.SetBlockProfileRate(1) |
| 1435 | runtime.SetMutexProfileFraction(-1) |
| 1436 | if err := pprof.StartCPUProfile(f); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 1437 | logger.Fatalf(ctx, "could not start CPU profile: %v\n", err) |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1438 | } |
| 1439 | defer pprof.StopCPUProfile() |
| 1440 | |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 1441 | //log.SetPackageLogLevel("github.com/opencord/voltha-go/rw_core/core", log.DebugLevel) |
| 1442 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 1443 | nb := newNBTest(ctx) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 1444 | assert.NotNil(t, nb) |
| 1445 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 1446 | defer nb.stopAll(ctx) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 1447 | |
| 1448 | // Start the Core |
| 1449 | nb.startCore(false) |
| 1450 | |
| 1451 | // Set the grpc API interface - no grpc server is running in unit test |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 1452 | nbi := NewNBIHandler(nb.deviceMgr, nb.logicalDeviceMgr, nb.adapterMgr) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 1453 | |
| 1454 | // 1. Basic test with no data in Core |
| 1455 | nb.testCoreWithoutData(t, nbi) |
| 1456 | |
| 1457 | // Create/register the adapters |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 1458 | nb.oltAdapter, nb.onuAdapter = tst.CreateAndregisterAdapters(ctx, t, nb.kClient, nb.coreInstanceID, nb.oltAdapterName, nb.onuAdapterName, nb.adapterMgr) |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 1459 | nb.numONUPerOLT = nb.oltAdapter.GetNumONUPerOLT() |
| 1460 | nb.startingUNIPortNo = nb.oltAdapter.GetStartingUNIPortNo() |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 1461 | |
| 1462 | // 2. Test adapter registration |
| 1463 | nb.testAdapterRegistration(t, nbi) |
| 1464 | |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 1465 | numberOfTestRuns := 2 |
| 1466 | for i := 1; i <= numberOfTestRuns; i++ { |
Himani Chawla | 2ba1c9c | 2020-10-07 13:19:03 +0530 | [diff] [blame] | 1467 | |
| 1468 | // 3. Test create device |
khenaidoo | 93d5a3d | 2020-01-15 12:37:05 -0500 | [diff] [blame] | 1469 | nb.testCreateDevice(t, nbi) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 1470 | |
Himani Chawla | 2ba1c9c | 2020-10-07 13:19:03 +0530 | [diff] [blame] | 1471 | // 4. Test Delete Device Scenarios |
| 1472 | nb.testForceDeletePreProvDevice(t, nbi) |
| 1473 | nb.testDeletePreProvDevice(t, nbi) |
| 1474 | nb.testForceDeleteEnabledDevice(t, nbi) |
| 1475 | nb.testDeleteEnabledDevice(t, nbi) |
| 1476 | nb.testForceDeleteDeviceFailure(t, nbi) |
| 1477 | nb.testDeleteDeviceFailure(t, nbi) |
| 1478 | |
| 1479 | // 5. Test Enable a device |
khenaidoo | 93d5a3d | 2020-01-15 12:37:05 -0500 | [diff] [blame] | 1480 | nb.testEnableDevice(t, nbi) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 1481 | |
Himani Chawla | 2ba1c9c | 2020-10-07 13:19:03 +0530 | [diff] [blame] | 1482 | // 6. Test disable and ReEnable a root device |
khenaidoo | 93d5a3d | 2020-01-15 12:37:05 -0500 | [diff] [blame] | 1483 | nb.testDisableAndReEnableRootDevice(t, nbi) |
khenaidoo | 67b2215 | 2020-03-02 16:01:25 -0500 | [diff] [blame] | 1484 | |
Himani Chawla | 2ba1c9c | 2020-10-07 13:19:03 +0530 | [diff] [blame] | 1485 | // 7. Test disable and Enable pon port of OLT device |
kesavand | bc2d162 | 2020-01-21 00:42:01 -0500 | [diff] [blame] | 1486 | nb.testDisableAndEnablePort(t, nbi) |
khenaidoo | 93d5a3d | 2020-01-15 12:37:05 -0500 | [diff] [blame] | 1487 | |
Himani Chawla | 2ba1c9c | 2020-10-07 13:19:03 +0530 | [diff] [blame] | 1488 | // 8.Test Device unreachable when OLT is enabled |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 1489 | nb.testDeviceRebootWhenOltIsEnabled(t, nbi) |
| 1490 | |
Himani Chawla | 2ba1c9c | 2020-10-07 13:19:03 +0530 | [diff] [blame] | 1491 | // 9. Test disable and delete all devices |
khenaidoo | 93d5a3d | 2020-01-15 12:37:05 -0500 | [diff] [blame] | 1492 | nb.testDisableAndDeleteAllDevice(t, nbi) |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 1493 | |
Himani Chawla | 2ba1c9c | 2020-10-07 13:19:03 +0530 | [diff] [blame] | 1494 | // 10. Test enable and delete all devices |
Chaitrashree G S | 543df3e | 2020-02-24 22:36:54 -0500 | [diff] [blame] | 1495 | nb.testEnableAndDeleteAllDevice(t, nbi) |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 1496 | |
Himani Chawla | 2ba1c9c | 2020-10-07 13:19:03 +0530 | [diff] [blame] | 1497 | // 11. Test omci test |
Scott Baker | 432f9be | 2020-03-26 11:56:30 -0700 | [diff] [blame] | 1498 | nb.testStartOmciTestAction(t, nbi) |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 1499 | |
Himani Chawla | 2ba1c9c | 2020-10-07 13:19:03 +0530 | [diff] [blame] | 1500 | // 12. Remove all devices from tests above |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 1501 | nb.deleteAllDevices(t, nbi) |
| 1502 | |
Himani Chawla | 2ba1c9c | 2020-10-07 13:19:03 +0530 | [diff] [blame] | 1503 | // 13. Test flow add failure |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 1504 | nb.testFlowAddFailure(t, nbi) |
| 1505 | |
Himani Chawla | 2ba1c9c | 2020-10-07 13:19:03 +0530 | [diff] [blame] | 1506 | // 14. Clean up |
khenaidoo | 8b4abbf | 2020-04-24 17:04:30 -0400 | [diff] [blame] | 1507 | nb.deleteAllDevices(t, nbi) |
| 1508 | } |
khenaidoo | b64fc8a | 2019-11-27 15:08:19 -0500 | [diff] [blame] | 1509 | } |