blob: 5801f278ca7fcd5e32cef42a9b6393cbe415f85b [file] [log] [blame]
khenaidoob64fc8a2019-11-27 15:08:19 -05001/*
Kent Hagerman45a13e42020-04-13 12:23:50 -04002 * 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.
khenaidoob64fc8a2019-11-27 15:08:19 -050015 */
Kent Hagerman45a13e42020-04-13 12:23:50 -040016
Kent Hagerman2b216042020-04-03 18:28:56 -040017package api
khenaidoob64fc8a2019-11-27 15:08:19 -050018
19import (
20 "context"
21 "errors"
22 "fmt"
khenaidoo67b22152020-03-02 16:01:25 -050023 "math/rand"
24 "os"
25 "runtime"
26 "runtime/pprof"
Neha Sharmad1387da2020-05-07 20:07:28 +000027 "strconv"
serkant.uluderya2ae470f2020-01-21 11:13:09 -080028 "strings"
khenaidoo67b22152020-03-02 16:01:25 -050029 "sync"
serkant.uluderya2ae470f2020-01-21 11:13:09 -080030 "testing"
31 "time"
32
khenaidoob64fc8a2019-11-27 15:08:19 -050033 "github.com/golang/protobuf/ptypes/empty"
Kent Hagerman2b216042020-04-03 18:28:56 -040034 "github.com/opencord/voltha-go/db/model"
khenaidoob64fc8a2019-11-27 15:08:19 -050035 "github.com/opencord/voltha-go/rw_core/config"
Kent Hagerman2b216042020-04-03 18:28:56 -040036 "github.com/opencord/voltha-go/rw_core/core/adapter"
37 "github.com/opencord/voltha-go/rw_core/core/device"
khenaidoob64fc8a2019-11-27 15:08:19 -050038 cm "github.com/opencord/voltha-go/rw_core/mocks"
Mahir Gunyel03de0d32020-06-03 01:36:59 -070039 tst "github.com/opencord/voltha-go/rw_core/test"
Kent Hagerman2b216042020-04-03 18:28:56 -040040 "github.com/opencord/voltha-lib-go/v3/pkg/db"
41 "github.com/opencord/voltha-lib-go/v3/pkg/flows"
serkant.uluderya2ae470f2020-01-21 11:13:09 -080042 "github.com/opencord/voltha-lib-go/v3/pkg/kafka"
Matteo Scandolod525ae32020-04-02 17:27:29 -070043 mock_etcd "github.com/opencord/voltha-lib-go/v3/pkg/mocks/etcd"
44 mock_kafka "github.com/opencord/voltha-lib-go/v3/pkg/mocks/kafka"
serkant.uluderya2ae470f2020-01-21 11:13:09 -080045 ofp "github.com/opencord/voltha-protos/v3/go/openflow_13"
46 "github.com/opencord/voltha-protos/v3/go/voltha"
khenaidoob64fc8a2019-11-27 15:08:19 -050047 "github.com/phayes/freeport"
48 "github.com/stretchr/testify/assert"
49 "google.golang.org/grpc/codes"
50 "google.golang.org/grpc/status"
khenaidoob64fc8a2019-11-27 15:08:19 -050051)
52
53type NBTest struct {
Matteo Scandolod525ae32020-04-02 17:27:29 -070054 etcdServer *mock_etcd.EtcdServer
Kent Hagerman2b216042020-04-03 18:28:56 -040055 deviceMgr *device.Manager
56 logicalDeviceMgr *device.LogicalManager
57 adapterMgr *adapter.Manager
58 kmp kafka.InterContainerProxy
khenaidoo67b22152020-03-02 16:01:25 -050059 kClient kafka.Client
60 kvClientPort int
61 numONUPerOLT int
62 startingUNIPortNo int
63 oltAdapter *cm.OLTAdapter
64 onuAdapter *cm.ONUAdapter
65 oltAdapterName string
66 onuAdapterName string
67 coreInstanceID string
68 defaultTimeout time.Duration
69 maxTimeout time.Duration
khenaidoob64fc8a2019-11-27 15:08:19 -050070}
71
72func newNBTest() *NBTest {
73 test := &NBTest{}
74 // Start the embedded etcd server
75 var err error
Mahir Gunyel03de0d32020-06-03 01:36:59 -070076 test.etcdServer, test.kvClientPort, err = tst.StartEmbeddedEtcdServer("voltha.rwcore.nb.test", "voltha.rwcore.nb.etcd", "error")
khenaidoob64fc8a2019-11-27 15:08:19 -050077 if err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +000078 logger.Fatal(err)
khenaidoob64fc8a2019-11-27 15:08:19 -050079 }
80 // Create the kafka client
Matteo Scandolod525ae32020-04-02 17:27:29 -070081 test.kClient = mock_kafka.NewKafkaClient()
khenaidoob64fc8a2019-11-27 15:08:19 -050082 test.oltAdapterName = "olt_adapter_mock"
83 test.onuAdapterName = "onu_adapter_mock"
84 test.coreInstanceID = "rw-nbi-test"
khenaidoo32836732020-03-05 16:10:44 -050085 test.defaultTimeout = 10 * time.Second
86 test.maxTimeout = 20 * time.Second
khenaidoob64fc8a2019-11-27 15:08:19 -050087 return test
88}
89
90func (nb *NBTest) startCore(inCompeteMode bool) {
Thomas Lee Se5a44012019-11-07 20:32:24 +053091 ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
92 defer cancel()
khenaidoob64fc8a2019-11-27 15:08:19 -050093 cfg := config.NewRWCoreFlags()
serkant.uluderya8ff291d2020-05-20 00:58:00 -070094 cfg.CoreTopic = "rw_core"
khenaidoo442e7c72020-03-10 16:13:48 -040095 cfg.DefaultRequestTimeout = nb.defaultTimeout
96 cfg.DefaultCoreTimeout = nb.defaultTimeout
khenaidoob64fc8a2019-11-27 15:08:19 -050097 cfg.InCompetingMode = inCompeteMode
Neha Sharmad1387da2020-05-07 20:07:28 +000098 cfg.KVStoreAddress = "127.0.0.1" + ":" + strconv.Itoa(nb.kvClientPort)
khenaidoob64fc8a2019-11-27 15:08:19 -050099 grpcPort, err := freeport.GetFreePort()
100 if err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +0000101 logger.Fatal("Cannot get a freeport for grpc")
khenaidoob64fc8a2019-11-27 15:08:19 -0500102 }
Neha Sharmad1387da2020-05-07 20:07:28 +0000103 cfg.GrpcAddress = "127.0.0.1" + ":" + strconv.Itoa(grpcPort)
khenaidoob64fc8a2019-11-27 15:08:19 -0500104 setCoreCompeteMode(inCompeteMode)
Mahir Gunyel03de0d32020-06-03 01:36:59 -0700105 client := tst.SetupKVClient(cfg, nb.coreInstanceID)
Kent Hagerman2b216042020-04-03 18:28:56 -0400106 backend := &db.Backend{
107 Client: client,
108 StoreType: cfg.KVStoreType,
Neha Sharmad1387da2020-05-07 20:07:28 +0000109 Address: cfg.KVStoreAddress,
Kent Hagerman2b216042020-04-03 18:28:56 -0400110 Timeout: cfg.KVStoreTimeout,
serkant.uluderya8ff291d2020-05-20 00:58:00 -0700111 LivenessChannelInterval: cfg.LiveProbeInterval / 2}
Kent Hagerman2b216042020-04-03 18:28:56 -0400112 nb.kmp = kafka.NewInterContainerProxy(
Neha Sharmad1387da2020-05-07 20:07:28 +0000113 kafka.InterContainerAddress(cfg.KafkaAdapterAddress),
Kent Hagerman2b216042020-04-03 18:28:56 -0400114 kafka.MsgClient(nb.kClient),
115 kafka.DefaultTopic(&kafka.Topic{Name: cfg.CoreTopic}),
116 kafka.DeviceDiscoveryTopic(&kafka.Topic{Name: cfg.AffinityRouterTopic}))
117
118 endpointMgr := kafka.NewEndpointManager(backend)
Kent Hagermanf5a67352020-04-30 15:15:26 -0400119 proxy := model.NewDBPath(backend)
Kent Hagerman2b216042020-04-03 18:28:56 -0400120 nb.adapterMgr = adapter.NewAdapterManager(proxy, nb.coreInstanceID, nb.kClient)
serkant.uluderya8ff291d2020-05-20 00:58:00 -0700121 nb.deviceMgr, nb.logicalDeviceMgr = device.NewManagers(proxy, nb.adapterMgr, nb.kmp, endpointMgr, cfg.CoreTopic, nb.coreInstanceID, cfg.DefaultCoreTimeout)
Kent Hagerman2f0d0552020-04-23 17:28:52 -0400122 nb.adapterMgr.Start(ctx)
Kent Hagerman2b216042020-04-03 18:28:56 -0400123
Kent Hagerman2f0d0552020-04-23 17:28:52 -0400124 if err := nb.kmp.Start(); err != nil {
Kent Hagerman2b216042020-04-03 18:28:56 -0400125 logger.Fatalf("Cannot start InterContainerProxy: %s", err)
126 }
Kent Hagerman2f0d0552020-04-23 17:28:52 -0400127 requestProxy := NewAdapterRequestHandlerProxy(nb.deviceMgr, nb.adapterMgr)
Kent Hagerman2b216042020-04-03 18:28:56 -0400128 if err := nb.kmp.SubscribeWithRequestHandlerInterface(kafka.Topic{Name: cfg.CoreTopic}, requestProxy); err != nil {
129 logger.Fatalf("Cannot add request handler: %s", err)
130 }
khenaidoob64fc8a2019-11-27 15:08:19 -0500131}
132
khenaidoob64fc8a2019-11-27 15:08:19 -0500133func (nb *NBTest) stopAll() {
134 if nb.kClient != nil {
135 nb.kClient.Stop()
136 }
Kent Hagerman2b216042020-04-03 18:28:56 -0400137 if nb.kmp != nil {
138 nb.kmp.Stop()
khenaidoob64fc8a2019-11-27 15:08:19 -0500139 }
140 if nb.etcdServer != nil {
Mahir Gunyel03de0d32020-06-03 01:36:59 -0700141 tst.StopEmbeddedEtcdServer(nb.etcdServer)
khenaidoob64fc8a2019-11-27 15:08:19 -0500142 }
143}
144
Kent Hagerman2b216042020-04-03 18:28:56 -0400145func (nb *NBTest) verifyLogicalDevices(t *testing.T, oltDevice *voltha.Device, nbi *NBIHandler) {
khenaidoob64fc8a2019-11-27 15:08:19 -0500146 // Get the latest set of logical devices
147 logicalDevices, err := nbi.ListLogicalDevices(getContext(), &empty.Empty{})
148 assert.Nil(t, err)
149 assert.NotNil(t, logicalDevices)
150 assert.Equal(t, 1, len(logicalDevices.Items))
151
152 ld := logicalDevices.Items[0]
153 assert.NotEqual(t, "", ld.Id)
154 assert.NotEqual(t, uint64(0), ld.DatapathId)
155 assert.Equal(t, "olt_adapter_mock", ld.Desc.HwDesc)
156 assert.Equal(t, "olt_adapter_mock", ld.Desc.SwDesc)
157 assert.NotEqual(t, "", ld.RootDeviceId)
158 assert.NotEqual(t, "", ld.Desc.SerialNum)
159 assert.Equal(t, uint32(256), ld.SwitchFeatures.NBuffers)
160 assert.Equal(t, uint32(2), ld.SwitchFeatures.NTables)
161 assert.Equal(t, uint32(15), ld.SwitchFeatures.Capabilities)
162 assert.Equal(t, 1+nb.numONUPerOLT, len(ld.Ports))
163 assert.Equal(t, oltDevice.ParentId, ld.Id)
164 //Expected port no
165 expectedPortNo := make(map[uint32]bool)
166 expectedPortNo[uint32(2)] = false
167 for i := 0; i < nb.numONUPerOLT; i++ {
168 expectedPortNo[uint32(i+100)] = false
169 }
170 for _, p := range ld.Ports {
171 assert.Equal(t, p.OfpPort.PortNo, p.DevicePortNo)
172 assert.Equal(t, uint32(4), p.OfpPort.State)
173 expectedPortNo[p.OfpPort.PortNo] = true
174 if strings.HasPrefix(p.Id, "nni") {
175 assert.Equal(t, true, p.RootPort)
176 //assert.Equal(t, uint32(2), p.OfpPort.PortNo)
177 assert.Equal(t, p.Id, fmt.Sprintf("nni-%d", p.DevicePortNo))
178 } else {
179 assert.Equal(t, p.Id, fmt.Sprintf("uni-%d", p.DevicePortNo))
180 assert.Equal(t, false, p.RootPort)
181 }
182 }
183}
184
Kent Hagerman2b216042020-04-03 18:28:56 -0400185func (nb *NBTest) verifyDevices(t *testing.T, nbi *NBIHandler) {
khenaidoob64fc8a2019-11-27 15:08:19 -0500186 // Get the latest set of devices
187 devices, err := nbi.ListDevices(getContext(), &empty.Empty{})
188 assert.Nil(t, err)
189 assert.NotNil(t, devices)
190
khenaidoo67b22152020-03-02 16:01:25 -0500191 // A device is ready to be examined when its ADMIN state is ENABLED and OPERATIONAL state is ACTIVE
khenaidoob64fc8a2019-11-27 15:08:19 -0500192 var vFunction isDeviceConditionSatisfied = func(device *voltha.Device) bool {
193 return device.AdminState == voltha.AdminState_ENABLED && device.OperStatus == voltha.OperStatus_ACTIVE
194 }
khenaidoob64fc8a2019-11-27 15:08:19 -0500195
khenaidoo67b22152020-03-02 16:01:25 -0500196 var wg sync.WaitGroup
197 for _, device := range devices.Items {
198 wg.Add(1)
199 go func(wg *sync.WaitGroup, device *voltha.Device) {
200 // Wait until the device is in the right state
201 err := waitUntilDeviceReadiness(device.Id, nb.maxTimeout, vFunction, nbi)
202 assert.Nil(t, err)
203
204 // Now, verify the details of the device. First get the latest update
205 d, err := nbi.GetDevice(getContext(), &voltha.ID{Id: device.Id})
206 assert.Nil(t, err)
207 assert.Equal(t, voltha.AdminState_ENABLED, d.AdminState)
208 assert.Equal(t, voltha.ConnectStatus_REACHABLE, d.ConnectStatus)
209 assert.Equal(t, voltha.OperStatus_ACTIVE, d.OperStatus)
210 assert.Equal(t, d.Type, d.Adapter)
211 assert.NotEqual(t, "", d.MacAddress)
212 assert.NotEqual(t, "", d.SerialNumber)
213
214 if d.Type == "olt_adapter_mock" {
215 assert.Equal(t, true, d.Root)
216 assert.NotEqual(t, "", d.Id)
217 assert.NotEqual(t, "", d.ParentId)
218 assert.Nil(t, d.ProxyAddress)
219 } else if d.Type == "onu_adapter_mock" {
220 assert.Equal(t, false, d.Root)
221 assert.NotEqual(t, uint32(0), d.Vlan)
222 assert.NotEqual(t, "", d.Id)
223 assert.NotEqual(t, "", d.ParentId)
224 assert.NotEqual(t, "", d.ProxyAddress.DeviceId)
225 assert.Equal(t, "olt_adapter_mock", d.ProxyAddress.DeviceType)
khenaidoob64fc8a2019-11-27 15:08:19 -0500226 } else {
khenaidoo67b22152020-03-02 16:01:25 -0500227 assert.Error(t, errors.New("invalid-device-type"))
khenaidoob64fc8a2019-11-27 15:08:19 -0500228 }
khenaidoo67b22152020-03-02 16:01:25 -0500229 assert.Equal(t, 2, len(d.Ports))
230 for _, p := range d.Ports {
231 assert.Equal(t, voltha.AdminState_ENABLED, p.AdminState)
232 assert.Equal(t, voltha.OperStatus_ACTIVE, p.OperStatus)
233 if p.Type == voltha.Port_ETHERNET_NNI || p.Type == voltha.Port_ETHERNET_UNI {
234 assert.Equal(t, 0, len(p.Peers))
235 } else if p.Type == voltha.Port_PON_OLT {
236 assert.Equal(t, nb.numONUPerOLT, len(p.Peers))
237 assert.Equal(t, uint32(1), p.PortNo)
238 } else if p.Type == voltha.Port_PON_ONU {
239 assert.Equal(t, 1, len(p.Peers))
240 assert.Equal(t, uint32(1), p.PortNo)
241 } else {
242 assert.Error(t, errors.New("invalid-port"))
243 }
244 }
245 wg.Done()
246 }(&wg, device)
khenaidoob64fc8a2019-11-27 15:08:19 -0500247 }
khenaidoo67b22152020-03-02 16:01:25 -0500248 wg.Wait()
khenaidoob64fc8a2019-11-27 15:08:19 -0500249}
250
Kent Hagerman2b216042020-04-03 18:28:56 -0400251func (nb *NBTest) getADevice(rootDevice bool, nbi *NBIHandler) (*voltha.Device, error) {
khenaidoob64fc8a2019-11-27 15:08:19 -0500252 devices, err := nbi.ListDevices(getContext(), &empty.Empty{})
253 if err != nil {
254 return nil, err
255 }
256 for _, d := range devices.Items {
257 if d.Root == rootDevice {
258 return d, nil
259 }
260 }
261 return nil, status.Errorf(codes.NotFound, "%v device not found", rootDevice)
262}
263
Kent Hagerman2b216042020-04-03 18:28:56 -0400264func (nb *NBTest) testCoreWithoutData(t *testing.T, nbi *NBIHandler) {
khenaidoob64fc8a2019-11-27 15:08:19 -0500265 lds, err := nbi.ListLogicalDevices(getContext(), &empty.Empty{})
266 assert.Nil(t, err)
267 assert.NotNil(t, lds)
268 assert.Equal(t, 0, len(lds.Items))
269 devices, err := nbi.ListDevices(getContext(), &empty.Empty{})
270 assert.Nil(t, err)
271 assert.NotNil(t, devices)
272 assert.Equal(t, 0, len(devices.Items))
273 adapters, err := nbi.ListAdapters(getContext(), &empty.Empty{})
khenaidoo442e7c72020-03-10 16:13:48 -0400274 assert.Equal(t, 0, len(adapters.Items))
khenaidoob64fc8a2019-11-27 15:08:19 -0500275 assert.Nil(t, err)
276 assert.NotNil(t, adapters)
khenaidoob64fc8a2019-11-27 15:08:19 -0500277}
278
Kent Hagerman2b216042020-04-03 18:28:56 -0400279func (nb *NBTest) testAdapterRegistration(t *testing.T, nbi *NBIHandler) {
khenaidoob64fc8a2019-11-27 15:08:19 -0500280 adapters, err := nbi.ListAdapters(getContext(), &empty.Empty{})
281 assert.Nil(t, err)
282 assert.NotNil(t, adapters)
283 assert.Equal(t, 2, len(adapters.Items))
284 for _, a := range adapters.Items {
285 switch a.Id {
286 case nb.oltAdapterName:
287 assert.Equal(t, "Voltha-olt", a.Vendor)
288 case nb.onuAdapterName:
289 assert.Equal(t, "Voltha-onu", a.Vendor)
290 default:
Girish Kumarf56a4682020-03-20 20:07:46 +0000291 logger.Fatal("unregistered-adapter", a.Id)
khenaidoob64fc8a2019-11-27 15:08:19 -0500292 }
293 }
294 deviceTypes, err := nbi.ListDeviceTypes(getContext(), &empty.Empty{})
295 assert.Nil(t, err)
296 assert.NotNil(t, deviceTypes)
297 assert.Equal(t, 2, len(deviceTypes.Items))
298 for _, dt := range deviceTypes.Items {
299 switch dt.Id {
300 case nb.oltAdapterName:
301 assert.Equal(t, nb.oltAdapterName, dt.Adapter)
302 assert.Equal(t, false, dt.AcceptsBulkFlowUpdate)
303 assert.Equal(t, true, dt.AcceptsAddRemoveFlowUpdates)
304 case nb.onuAdapterName:
305 assert.Equal(t, nb.onuAdapterName, dt.Adapter)
306 assert.Equal(t, false, dt.AcceptsBulkFlowUpdate)
307 assert.Equal(t, true, dt.AcceptsAddRemoveFlowUpdates)
308 default:
Girish Kumarf56a4682020-03-20 20:07:46 +0000309 logger.Fatal("invalid-device-type", dt.Id)
khenaidoob64fc8a2019-11-27 15:08:19 -0500310 }
311 }
312}
313
Kent Hagerman2b216042020-04-03 18:28:56 -0400314func (nb *NBTest) testCreateDevice(t *testing.T, nbi *NBIHandler) {
khenaidoob64fc8a2019-11-27 15:08:19 -0500315 // Create a valid device
316 oltDevice, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName, MacAddress: "aa:bb:cc:cc:ee:ee"})
317 assert.Nil(t, err)
318 assert.NotNil(t, oltDevice)
319 device, err := nbi.GetDevice(getContext(), &voltha.ID{Id: oltDevice.Id})
320 assert.Nil(t, err)
321 assert.NotNil(t, device)
322 assert.Equal(t, oltDevice.String(), device.String())
323
324 // Try to create the same device
325 _, err = nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName, MacAddress: "aa:bb:cc:cc:ee:ee"})
326 assert.NotNil(t, err)
Kent Hagerman45a13e42020-04-13 12:23:50 -0400327 assert.Equal(t, "device is already pre-provisioned", err.Error())
khenaidoob64fc8a2019-11-27 15:08:19 -0500328
329 // Try to create a device with invalid data
330 _, err = nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName})
331 assert.NotNil(t, err)
Thomas Lee Se5a44012019-11-07 20:32:24 +0530332 assert.Equal(t, "no-device-info-present; MAC or HOSTIP&PORT", err.Error())
khenaidoob64fc8a2019-11-27 15:08:19 -0500333
334 // Ensure we only have 1 device in the Core
335 devices, err := nbi.ListDevices(getContext(), &empty.Empty{})
336 assert.Nil(t, err)
337 assert.NotNil(t, devices)
338 assert.Equal(t, 1, len(devices.Items))
339 assert.Equal(t, oltDevice.String(), devices.Items[0].String())
340
341 //Remove the device
342 _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: oltDevice.Id})
343 assert.Nil(t, err)
344
345 //Ensure there are no devices in the Core now - wait until condition satisfied or timeout
346 var vFunction isDevicesConditionSatisfied = func(devices *voltha.Devices) bool {
347 return devices != nil && len(devices.Items) == 0
348 }
khenaidoo442e7c72020-03-10 16:13:48 -0400349 err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunction)
khenaidoob64fc8a2019-11-27 15:08:19 -0500350 assert.Nil(t, err)
351}
352
Kent Hagerman2b216042020-04-03 18:28:56 -0400353func (nb *NBTest) testEnableDevice(t *testing.T, nbi *NBIHandler) {
khenaidoob64fc8a2019-11-27 15:08:19 -0500354 // Create a device that has no adapter registered
355 oltDeviceNoAdapter, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: "noAdapterRegistered", MacAddress: "aa:bb:cc:cc:ee:ff"})
356 assert.Nil(t, err)
357 assert.NotNil(t, oltDeviceNoAdapter)
358
359 // Try to enable the oltDevice and check the error message
360 _, err = nbi.EnableDevice(getContext(), &voltha.ID{Id: oltDeviceNoAdapter.Id})
361 assert.NotNil(t, err)
Kent Hagerman45a13e42020-04-13 12:23:50 -0400362 assert.Equal(t, "adapter-not-registered-for-device-type noAdapterRegistered", err.Error())
khenaidoob64fc8a2019-11-27 15:08:19 -0500363
364 //Remove the device
365 _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: oltDeviceNoAdapter.Id})
366 assert.Nil(t, err)
367
368 //Ensure there are no devices in the Core now - wait until condition satisfied or timeout
369 var vdFunction isDevicesConditionSatisfied = func(devices *voltha.Devices) bool {
370 return devices != nil && len(devices.Items) == 0
371 }
khenaidoo442e7c72020-03-10 16:13:48 -0400372 err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vdFunction)
khenaidoob64fc8a2019-11-27 15:08:19 -0500373 assert.Nil(t, err)
374
khenaidoo67b22152020-03-02 16:01:25 -0500375 // Create a logical device monitor will automatically send trap and eapol flows to the devices being enables
376 var wg sync.WaitGroup
377 wg.Add(1)
khenaidoo8b4abbf2020-04-24 17:04:30 -0400378 go nb.monitorLogicalDevice(t, nbi, 1, nb.numONUPerOLT, &wg, false, false)
khenaidoo67b22152020-03-02 16:01:25 -0500379
khenaidoob64fc8a2019-11-27 15:08:19 -0500380 // Create the device with valid data
381 oltDevice, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName, MacAddress: "aa:bb:cc:cc:ee:ee"})
382 assert.Nil(t, err)
383 assert.NotNil(t, oltDevice)
384
385 // Verify oltDevice exist in the core
386 devices, err := nbi.ListDevices(getContext(), &empty.Empty{})
387 assert.Nil(t, err)
388 assert.Equal(t, 1, len(devices.Items))
389 assert.Equal(t, oltDevice.Id, devices.Items[0].Id)
390
391 // Enable the oltDevice
392 _, err = nbi.EnableDevice(getContext(), &voltha.ID{Id: oltDevice.Id})
393 assert.Nil(t, err)
394
395 // Wait for the logical device to be in the ready state
396 var vldFunction isLogicalDeviceConditionSatisfied = func(ld *voltha.LogicalDevice) bool {
397 return ld != nil && len(ld.Ports) == nb.numONUPerOLT+1
398 }
399 err = waitUntilLogicalDeviceReadiness(oltDevice.Id, nb.maxTimeout, nbi, vldFunction)
400 assert.Nil(t, err)
401
402 // Verify that the devices have been setup correctly
403 nb.verifyDevices(t, nbi)
404
405 // Get latest oltDevice data
406 oltDevice, err = nbi.GetDevice(getContext(), &voltha.ID{Id: oltDevice.Id})
407 assert.Nil(t, err)
408
409 // Verify that the logical device has been setup correctly
410 nb.verifyLogicalDevices(t, oltDevice, nbi)
khenaidoo67b22152020-03-02 16:01:25 -0500411
412 // Wait until all flows has been sent to the devices successfully
413 wg.Wait()
khenaidoob64fc8a2019-11-27 15:08:19 -0500414}
415
Kent Hagerman2b216042020-04-03 18:28:56 -0400416func (nb *NBTest) testDisableAndReEnableRootDevice(t *testing.T, nbi *NBIHandler) {
khenaidoob64fc8a2019-11-27 15:08:19 -0500417 //Get an OLT device
418 oltDevice, err := nb.getADevice(true, nbi)
419 assert.Nil(t, err)
420 assert.NotNil(t, oltDevice)
421
422 // Disable the oltDevice
423 _, err = nbi.DisableDevice(getContext(), &voltha.ID{Id: oltDevice.Id})
424 assert.Nil(t, err)
425
426 // Wait for the old device to be disabled
427 var vdFunction isDeviceConditionSatisfied = func(device *voltha.Device) bool {
428 return device.AdminState == voltha.AdminState_DISABLED && device.OperStatus == voltha.OperStatus_UNKNOWN
429 }
430 err = waitUntilDeviceReadiness(oltDevice.Id, nb.maxTimeout, vdFunction, nbi)
431 assert.Nil(t, err)
432
433 // Verify that all onu devices are disabled as well
Kent Hagerman2b216042020-04-03 18:28:56 -0400434 onuDevices, err := nb.deviceMgr.GetAllChildDevices(getContext(), oltDevice.Id)
khenaidoob64fc8a2019-11-27 15:08:19 -0500435 assert.Nil(t, err)
436 for _, onu := range onuDevices.Items {
437 err = waitUntilDeviceReadiness(onu.Id, nb.maxTimeout, vdFunction, nbi)
438 assert.Nil(t, err)
439 }
440
441 // Wait for the logical device to satisfy the expected condition
442 var vlFunction isLogicalDeviceConditionSatisfied = func(ld *voltha.LogicalDevice) bool {
khenaidoo67b22152020-03-02 16:01:25 -0500443 if ld == nil {
444 return false
445 }
khenaidoob64fc8a2019-11-27 15:08:19 -0500446 for _, lp := range ld.Ports {
447 if (lp.OfpPort.Config&uint32(ofp.OfpPortConfig_OFPPC_PORT_DOWN) != lp.OfpPort.Config) ||
448 lp.OfpPort.State != uint32(ofp.OfpPortState_OFPPS_LINK_DOWN) {
449 return false
450 }
451 }
452 return true
453 }
454 err = waitUntilLogicalDeviceReadiness(oltDevice.Id, nb.maxTimeout, nbi, vlFunction)
455 assert.Nil(t, err)
456
457 // Reenable the oltDevice
458 _, err = nbi.EnableDevice(getContext(), &voltha.ID{Id: oltDevice.Id})
459 assert.Nil(t, err)
460
461 // Wait for the old device to be enabled
462 vdFunction = func(device *voltha.Device) bool {
463 return device.AdminState == voltha.AdminState_ENABLED && device.OperStatus == voltha.OperStatus_ACTIVE
464 }
465 err = waitUntilDeviceReadiness(oltDevice.Id, nb.maxTimeout, vdFunction, nbi)
466 assert.Nil(t, err)
467
468 // Verify that all onu devices are enabled as well
Kent Hagerman2b216042020-04-03 18:28:56 -0400469 onuDevices, err = nb.deviceMgr.GetAllChildDevices(getContext(), oltDevice.Id)
khenaidoob64fc8a2019-11-27 15:08:19 -0500470 assert.Nil(t, err)
471 for _, onu := range onuDevices.Items {
472 err = waitUntilDeviceReadiness(onu.Id, nb.maxTimeout, vdFunction, nbi)
473 assert.Nil(t, err)
474 }
475
476 // Wait for the logical device to satisfy the expected condition
477 vlFunction = func(ld *voltha.LogicalDevice) bool {
khenaidoo67b22152020-03-02 16:01:25 -0500478 if ld == nil {
479 return false
480 }
khenaidoob64fc8a2019-11-27 15:08:19 -0500481 for _, lp := range ld.Ports {
482 if (lp.OfpPort.Config&^uint32(ofp.OfpPortConfig_OFPPC_PORT_DOWN) != lp.OfpPort.Config) ||
483 lp.OfpPort.State != uint32(ofp.OfpPortState_OFPPS_LIVE) {
484 return false
485 }
486 }
487 return true
488 }
489 err = waitUntilLogicalDeviceReadiness(oltDevice.Id, nb.maxTimeout, nbi, vlFunction)
490 assert.Nil(t, err)
491}
492
Kent Hagerman2b216042020-04-03 18:28:56 -0400493func (nb *NBTest) testDisableAndDeleteAllDevice(t *testing.T, nbi *NBIHandler) {
khenaidoo93d5a3d2020-01-15 12:37:05 -0500494 //Get an OLT device
495 oltDevice, err := nb.getADevice(true, nbi)
496 assert.Nil(t, err)
497 assert.NotNil(t, oltDevice)
498
499 // Disable the oltDevice
500 _, err = nbi.DisableDevice(getContext(), &voltha.ID{Id: oltDevice.Id})
501 assert.Nil(t, err)
502
503 // Wait for the olt device to be disabled
504 var vdFunction isDeviceConditionSatisfied = func(device *voltha.Device) bool {
505 return device.AdminState == voltha.AdminState_DISABLED && device.OperStatus == voltha.OperStatus_UNKNOWN
506 }
507 err = waitUntilDeviceReadiness(oltDevice.Id, nb.maxTimeout, vdFunction, nbi)
508 assert.Nil(t, err)
509
510 // Verify that all onu devices are disabled as well
Kent Hagerman2b216042020-04-03 18:28:56 -0400511 onuDevices, err := nb.deviceMgr.GetAllChildDevices(getContext(), oltDevice.Id)
khenaidoo93d5a3d2020-01-15 12:37:05 -0500512 assert.Nil(t, err)
513 for _, onu := range onuDevices.Items {
514 err = waitUntilDeviceReadiness(onu.Id, nb.maxTimeout, vdFunction, nbi)
515 assert.Nil(t, err)
516 }
517
518 // Delete the oltDevice
519 _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: oltDevice.Id})
520 assert.Nil(t, err)
521
522 var vFunction isDevicesConditionSatisfied = func(devices *voltha.Devices) bool {
523 return devices != nil && len(devices.Items) == 0
524 }
525 err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunction)
526 assert.Nil(t, err)
527
528 // Wait for absence of logical device
529 var vlFunction isLogicalDevicesConditionSatisfied = func(lds *voltha.LogicalDevices) bool {
530 return lds != nil && len(lds.Items) == 0
531 }
532
533 err = waitUntilConditionForLogicalDevices(nb.maxTimeout, nbi, vlFunction)
534 assert.Nil(t, err)
535}
khenaidoo8b4abbf2020-04-24 17:04:30 -0400536
537func (nb *NBTest) deleteAllDevices(t *testing.T, nbi *NBIHandler) {
khenaidoo0db4c812020-05-27 15:27:30 -0400538 devices, _ := nbi.ListDevices(getContext(), &empty.Empty{})
539 if len(devices.Items) == 0 {
540 // Nothing to do
541 return
542 }
khenaidoo8b4abbf2020-04-24 17:04:30 -0400543 //Get an OLT device
544 oltDevice, err := nb.getADevice(true, nbi)
545 assert.Nil(t, err)
546 assert.NotNil(t, oltDevice)
547
548 // Delete the oltDevice
549 _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: oltDevice.Id})
550 assert.Nil(t, err)
551
552 // Wait for all devices to be deleted
553 vFunction := func(devices *voltha.Devices) bool {
554 return devices != nil && len(devices.Items) == 0
555 }
556 err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunction)
557 assert.Nil(t, err)
558
559 // Wait for absence of logical device
560 vlFunction := func(lds *voltha.LogicalDevices) bool {
561 return lds != nil && len(lds.Items) == 0
562 }
563
564 err = waitUntilConditionForLogicalDevices(nb.maxTimeout, nbi, vlFunction)
565 assert.Nil(t, err)
566}
567
Kent Hagerman2b216042020-04-03 18:28:56 -0400568func (nb *NBTest) testEnableAndDeleteAllDevice(t *testing.T, nbi *NBIHandler) {
Chaitrashree G S543df3e2020-02-24 22:36:54 -0500569 //Create the device with valid data
570 oltDevice, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName, MacAddress: "aa:bb:cc:cc:ee:ee"})
571 assert.Nil(t, err)
572 assert.NotNil(t, oltDevice)
573
574 //Get an OLT device
575 oltDevice, err = nb.getADevice(true, nbi)
576 assert.Nil(t, err)
577 assert.NotNil(t, oltDevice)
578
579 // Enable the oltDevice
580 _, err = nbi.EnableDevice(getContext(), &voltha.ID{Id: oltDevice.Id})
581 assert.Nil(t, err)
582
583 // Wait for the logical device to be in the ready state
584 var vldFunction isLogicalDeviceConditionSatisfied = func(ld *voltha.LogicalDevice) bool {
585 return ld != nil && len(ld.Ports) == nb.numONUPerOLT+1
586 }
587 err = waitUntilLogicalDeviceReadiness(oltDevice.Id, nb.maxTimeout, nbi, vldFunction)
588 assert.Nil(t, err)
589
590 //Get all child devices
Kent Hagerman2b216042020-04-03 18:28:56 -0400591 onuDevices, err := nb.deviceMgr.GetAllChildDevices(getContext(), oltDevice.Id)
Chaitrashree G S543df3e2020-02-24 22:36:54 -0500592 assert.Nil(t, err)
593
594 // Wait for the all onu devices to be enabled
595 var vdFunction isDeviceConditionSatisfied = func(device *voltha.Device) bool {
596 return device.AdminState == voltha.AdminState_ENABLED
597 }
598 for _, onu := range onuDevices.Items {
599 err = waitUntilDeviceReadiness(onu.Id, nb.maxTimeout, vdFunction, nbi)
600 assert.Nil(t, err)
601 }
Chaitrashree G Se8ad0202020-02-27 18:48:00 -0500602 // Wait for each onu device to get deleted
603 var vdFunc isDeviceConditionSatisfied = func(device *voltha.Device) bool {
604 return device == nil
605 }
606
Chaitrashree G S543df3e2020-02-24 22:36:54 -0500607 // Delete the onuDevice
608 for _, onu := range onuDevices.Items {
609 _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: onu.Id})
610 assert.Nil(t, err)
Chaitrashree G Se8ad0202020-02-27 18:48:00 -0500611 err = waitUntilDeviceReadiness(onu.Id, nb.maxTimeout, vdFunc, nbi)
612 assert.Nil(t, err)
Chaitrashree G S543df3e2020-02-24 22:36:54 -0500613 }
Chaitrashree G Se8ad0202020-02-27 18:48:00 -0500614
Chaitrashree G S543df3e2020-02-24 22:36:54 -0500615 // Disable the oltDevice
616 _, err = nbi.DisableDevice(getContext(), &voltha.ID{Id: oltDevice.Id})
617 assert.Nil(t, err)
618
619 // Wait for the olt device to be disabled
620 var vFunction isDeviceConditionSatisfied = func(device *voltha.Device) bool {
621 return device.AdminState == voltha.AdminState_DISABLED && device.OperStatus == voltha.OperStatus_UNKNOWN
622 }
623 err = waitUntilDeviceReadiness(oltDevice.Id, nb.maxTimeout, vFunction, nbi)
624 assert.Nil(t, err)
625
626 // Delete the oltDevice
627 _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: oltDevice.Id})
628 assert.Nil(t, err)
629
630 var vFunc isDevicesConditionSatisfied = func(devices *voltha.Devices) bool {
631 return devices != nil && len(devices.Items) == 0
632 }
633 err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunc)
634 assert.Nil(t, err)
635}
Kent Hagerman2b216042020-04-03 18:28:56 -0400636func (nb *NBTest) testDisableAndEnablePort(t *testing.T, nbi *NBIHandler) {
kesavandbc2d1622020-01-21 00:42:01 -0500637 //Get an OLT device
638 var cp *voltha.Port
639 oltDevice, err := nb.getADevice(true, nbi)
640 assert.Nil(t, err)
641 assert.NotNil(t, oltDevice)
642
643 for _, cp = range oltDevice.Ports {
644 if cp.Type == voltha.Port_PON_OLT {
645 break
646 }
647
648 }
649 assert.NotNil(t, cp)
650 cp.DeviceId = oltDevice.Id
651
652 // Disable the NW Port of oltDevice
653 _, err = nbi.DisablePort(getContext(), cp)
654 assert.Nil(t, err)
655 // Wait for the olt device Port to be disabled
656 var vdFunction isDeviceConditionSatisfied = func(device *voltha.Device) bool {
657 for _, port := range device.Ports {
658 if port.PortNo == cp.PortNo {
659 return port.AdminState == voltha.AdminState_DISABLED
660 }
661 }
662 return false
663 }
664 err = waitUntilDeviceReadiness(oltDevice.Id, nb.maxTimeout, vdFunction, nbi)
665 assert.Nil(t, err)
666 // Wait for the logical device to satisfy the expected condition
667 var vlFunction = func(ld *voltha.LogicalDevice) bool {
khenaidoo67b22152020-03-02 16:01:25 -0500668 if ld == nil {
669 return false
670 }
kesavandbc2d1622020-01-21 00:42:01 -0500671 for _, lp := range ld.Ports {
672 if (lp.OfpPort.Config&^uint32(ofp.OfpPortConfig_OFPPC_PORT_DOWN) != lp.OfpPort.Config) ||
673 lp.OfpPort.State != uint32(ofp.OfpPortState_OFPPS_LIVE) {
674 return false
675 }
676 }
677 return true
678 }
679 err = waitUntilLogicalDeviceReadiness(oltDevice.Id, nb.maxTimeout, nbi, vlFunction)
680 assert.Nil(t, err)
681
682 // Enable the NW Port of oltDevice
683 _, err = nbi.EnablePort(getContext(), cp)
684 assert.Nil(t, err)
685
686 // Wait for the olt device Port to be enabled
687 vdFunction = func(device *voltha.Device) bool {
688 for _, port := range device.Ports {
689 if port.PortNo == cp.PortNo {
690 return port.AdminState == voltha.AdminState_ENABLED
691 }
692 }
693 return false
694 }
695 err = waitUntilDeviceReadiness(oltDevice.Id, nb.maxTimeout, vdFunction, nbi)
696 assert.Nil(t, err)
697 // Wait for the logical device to satisfy the expected condition
698 vlFunction = func(ld *voltha.LogicalDevice) bool {
khenaidoo67b22152020-03-02 16:01:25 -0500699 if ld == nil {
700 return false
701 }
kesavandbc2d1622020-01-21 00:42:01 -0500702 for _, lp := range ld.Ports {
703 if (lp.OfpPort.Config&^uint32(ofp.OfpPortConfig_OFPPC_PORT_DOWN) != lp.OfpPort.Config) ||
704 lp.OfpPort.State != uint32(ofp.OfpPortState_OFPPS_LIVE) {
705 return false
706 }
707 }
708 return true
709 }
710 err = waitUntilLogicalDeviceReadiness(oltDevice.Id, nb.maxTimeout, nbi, vlFunction)
711 assert.Nil(t, err)
712
713 // Disable a non-PON port
714 for _, cp = range oltDevice.Ports {
715 if cp.Type != voltha.Port_PON_OLT {
716 break
717 }
718
719 }
720 assert.NotNil(t, cp)
721 cp.DeviceId = oltDevice.Id
722
723 // Disable the NW Port of oltDevice
724 _, err = nbi.DisablePort(getContext(), cp)
725 assert.NotNil(t, err)
726
727}
khenaidoo93d5a3d2020-01-15 12:37:05 -0500728
Kent Hagerman2b216042020-04-03 18:28:56 -0400729func (nb *NBTest) testDeviceRebootWhenOltIsEnabled(t *testing.T, nbi *NBIHandler) {
Girish Gowdra408cd962020-03-11 14:31:31 -0700730 //Get an OLT device
731 oltDevice, err := nb.getADevice(true, nbi)
732 assert.Nil(t, err)
733 assert.NotNil(t, oltDevice)
734 assert.Equal(t, oltDevice.ConnectStatus, voltha.ConnectStatus_REACHABLE)
735 assert.Equal(t, oltDevice.AdminState, voltha.AdminState_ENABLED)
736
737 // Verify that we have one or more ONUs to start with
Kent Hagerman2b216042020-04-03 18:28:56 -0400738 onuDevices, err := nb.deviceMgr.GetAllChildDevices(getContext(), oltDevice.Id)
Girish Gowdra408cd962020-03-11 14:31:31 -0700739 assert.Nil(t, err)
740 assert.NotNil(t, onuDevices)
741 assert.Greater(t, len(onuDevices.Items), 0)
742
743 // Reboot the OLT and very that Connection Status goes to UNREACHABLE and operation status to UNKNOWN
744 _, err = nbi.RebootDevice(getContext(), &voltha.ID{Id: oltDevice.Id})
745 assert.Nil(t, err)
746
747 var vlFunction0 = func(d *voltha.Device) bool {
748 return d.ConnectStatus == voltha.ConnectStatus_UNREACHABLE && d.OperStatus == voltha.OperStatus_UNKNOWN
749 }
750
751 err = waitUntilDeviceReadiness(oltDevice.Id, nb.maxTimeout, vlFunction0, nbi)
752 assert.Nil(t, err)
753
754 // Wait for the logical device to satisfy the expected condition
755 var vlFunction1 = func(ld *voltha.LogicalDevice) bool {
756 return ld == nil
757 }
758
759 err = waitUntilLogicalDeviceReadiness(oltDevice.Id, nb.maxTimeout, nbi, vlFunction1)
760 assert.Nil(t, err)
761
762 // Wait for the device to satisfy the expected condition (device does not have flows)
763 var vlFunction2 = func(d *voltha.Device) bool {
764 var deviceFlows *ofp.Flows
765 var err error
766 if deviceFlows, err = nbi.ListDeviceFlows(getContext(), &voltha.ID{Id: d.Id}); err != nil {
767 return false
768 }
769 return len(deviceFlows.Items) == 0
770 }
771
772 err = waitUntilDeviceReadiness(oltDevice.Id, nb.maxTimeout, vlFunction2, nbi)
773 assert.Nil(t, err)
774
775 // Wait for the device to satisfy the expected condition (there are no child devices)
776 var vlFunction3 = func(d *voltha.Device) bool {
777 var devices *voltha.Devices
778 var err error
779 if devices, err = nbi.ListDevices(getContext(), nil); err != nil {
780 return false
781 }
782 for _, device := range devices.Items {
783 if device.ParentId == d.Id {
784 // We have a child device still left
785 return false
786 }
787 }
788 return true
789 }
790
791 err = waitUntilDeviceReadiness(oltDevice.Id, nb.maxTimeout, vlFunction3, nbi)
792 assert.Nil(t, err)
793
794 // Update the OLT Connection Status to REACHABLE and operation status to ACTIVE
795 // Normally, in a real adapter this happens after connection regain via a heartbeat mechanism with real hardware
Kent Hagerman45a13e42020-04-13 12:23:50 -0400796 err = nbi.UpdateDeviceStatus(getContext(), oltDevice.Id, voltha.OperStatus_ACTIVE, voltha.ConnectStatus_REACHABLE)
Girish Gowdra408cd962020-03-11 14:31:31 -0700797 assert.Nil(t, err)
798
799 // Verify the device connection and operation states
800 oltDevice, err = nb.getADevice(true, nbi)
801 assert.Nil(t, err)
802 assert.NotNil(t, oltDevice)
803 assert.Equal(t, oltDevice.ConnectStatus, voltha.ConnectStatus_REACHABLE)
804 assert.Equal(t, oltDevice.AdminState, voltha.AdminState_ENABLED)
805
806 // Wait for the logical device to satisfy the expected condition
807 var vlFunction4 = func(ld *voltha.LogicalDevice) bool {
808 return ld != nil
809 }
810 err = waitUntilLogicalDeviceReadiness(oltDevice.Id, nb.maxTimeout, nbi, vlFunction4)
811 assert.Nil(t, err)
812
813 // Verify that logical device is created again
814 logicalDevices, err := nbi.ListLogicalDevices(getContext(), &empty.Empty{})
815 assert.Nil(t, err)
816 assert.NotNil(t, logicalDevices)
817 assert.Equal(t, 1, len(logicalDevices.Items))
818
819 // Verify that we have no ONUs left
Kent Hagerman2b216042020-04-03 18:28:56 -0400820 onuDevices, err = nb.deviceMgr.GetAllChildDevices(getContext(), oltDevice.Id)
Girish Gowdra408cd962020-03-11 14:31:31 -0700821 assert.Nil(t, err)
822 assert.NotNil(t, onuDevices)
823 assert.Equal(t, 0, len(onuDevices.Items))
824}
825
Kent Hagerman2b216042020-04-03 18:28:56 -0400826func (nb *NBTest) testStartOmciTestAction(t *testing.T, nbi *NBIHandler) {
Scott Baker432f9be2020-03-26 11:56:30 -0700827 // -----------------------------------------------------------------------
828 // SubTest 1: Omci test action should fail due to nonexistent device id
829
830 request := &voltha.OmciTestRequest{Id: "123", Uuid: "456"}
831 _, err := nbi.StartOmciTestAction(getContext(), request)
832 assert.NotNil(t, err)
833 assert.Equal(t, "rpc error: code = NotFound desc = 123", err.Error())
834
835 // -----------------------------------------------------------------------
836 // SubTest 2: Error should be returned for device with no adapter registered
837
838 // Create a device that has no adapter registered
839 deviceNoAdapter, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: "noAdapterRegisteredOmciTest", MacAddress: "aa:bb:cc:cc:ee:01"})
840 assert.Nil(t, err)
841 assert.NotNil(t, deviceNoAdapter)
842
843 // Omci test action should fail due to nonexistent adapter
844 request = &voltha.OmciTestRequest{Id: deviceNoAdapter.Id, Uuid: "456"}
845 _, err = nbi.StartOmciTestAction(getContext(), request)
846 assert.NotNil(t, err)
Kent Hagerman45a13e42020-04-13 12:23:50 -0400847 assert.Equal(t, "adapter-not-registered-for-device-type noAdapterRegisteredOmciTest", err.Error())
Scott Baker432f9be2020-03-26 11:56:30 -0700848
849 //Remove the device
850 _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: deviceNoAdapter.Id})
851 assert.Nil(t, err)
852
853 //Ensure there are no devices in the Core now - wait until condition satisfied or timeout
854 var vFunction isDevicesConditionSatisfied = func(devices *voltha.Devices) bool {
855 return devices != nil && len(devices.Items) == 0
856 }
857 err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunction)
858 assert.Nil(t, err)
859
860 // -----------------------------------------------------------------------
861 // SubTest 3: Omci test action should succeed on valid ONU
862
863 // Create the device with valid data
864 oltDevice, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName, MacAddress: "aa:bb:cc:cc:ee:ee"})
865 assert.Nil(t, err)
866 assert.NotNil(t, oltDevice)
867
868 // Verify oltDevice exist in the core
869 devices, err := nbi.ListDevices(getContext(), &empty.Empty{})
870 assert.Nil(t, err)
871 assert.Equal(t, 1, len(devices.Items))
872 assert.Equal(t, oltDevice.Id, devices.Items[0].Id)
873
874 // Enable the oltDevice
875 _, err = nbi.EnableDevice(getContext(), &voltha.ID{Id: oltDevice.Id})
876 assert.Nil(t, err)
877
878 // Wait for the logical device to be in the ready state
879 var vldFunction isLogicalDeviceConditionSatisfied = func(ld *voltha.LogicalDevice) bool {
880 return ld != nil && len(ld.Ports) == nb.numONUPerOLT+1
881 }
882 err = waitUntilLogicalDeviceReadiness(oltDevice.Id, nb.maxTimeout, nbi, vldFunction)
883 assert.Nil(t, err)
884
885 // Wait for the olt device to be enabled
886 vdFunction := func(device *voltha.Device) bool {
887 return device.AdminState == voltha.AdminState_ENABLED && device.OperStatus == voltha.OperStatus_ACTIVE
888 }
889 err = waitUntilDeviceReadiness(oltDevice.Id, nb.maxTimeout, vdFunction, nbi)
890 assert.Nil(t, err)
891
Kent Hagerman2b216042020-04-03 18:28:56 -0400892 onuDevices, err := nb.deviceMgr.GetAllChildDevices(getContext(), oltDevice.Id)
Scott Baker432f9be2020-03-26 11:56:30 -0700893 assert.Nil(t, err)
894 assert.Greater(t, len(onuDevices.Items), 0)
895
896 onuDevice := onuDevices.Items[0]
897
898 // Omci test action should succeed
899 request = &voltha.OmciTestRequest{Id: onuDevice.Id, Uuid: "456"}
900 resp, err := nbi.StartOmciTestAction(getContext(), request)
901 assert.Nil(t, err)
902 assert.Equal(t, resp.Result, voltha.TestResponse_SUCCESS)
903
904 //Remove the device
905 _, err = nbi.DeleteDevice(getContext(), &voltha.ID{Id: oltDevice.Id})
906 assert.Nil(t, err)
907 //Ensure there are no devices in the Core now - wait until condition satisfied or timeout
908 err = waitUntilConditionForDevices(nb.maxTimeout, nbi, vFunction)
909 assert.Nil(t, err)
910}
911
khenaidoo67b22152020-03-02 16:01:25 -0500912func makeSimpleFlowMod(fa *flows.FlowArgs) *ofp.OfpFlowMod {
913 matchFields := make([]*ofp.OfpOxmField, 0)
914 for _, val := range fa.MatchFields {
915 matchFields = append(matchFields, &ofp.OfpOxmField{Field: &ofp.OfpOxmField_OfbField{OfbField: val}})
916 }
917 return flows.MkSimpleFlowMod(matchFields, fa.Actions, fa.Command, fa.KV)
918}
919
920func createMetadata(cTag int, techProfile int, port int) uint64 {
921 md := 0
922 md = (md | (cTag & 0xFFFF)) << 16
923 md = (md | (techProfile & 0xFFFF)) << 32
924 return uint64(md | (port & 0xFFFFFFFF))
925}
926
khenaidoo8b4abbf2020-04-24 17:04:30 -0400927func (nb *NBTest) verifyLogicalDeviceFlowCount(t *testing.T, nbi *NBIHandler, numNNIPorts int, numUNIPorts int, flowAddFail bool) {
khenaidoo67b22152020-03-02 16:01:25 -0500928 expectedNumFlows := numNNIPorts*3 + numNNIPorts*numUNIPorts
khenaidoo8b4abbf2020-04-24 17:04:30 -0400929 if flowAddFail {
930 expectedNumFlows = 0
931 }
932 // Wait for logical device to have the flows (or none
khenaidoo67b22152020-03-02 16:01:25 -0500933 var vlFunction isLogicalDevicesConditionSatisfied = func(lds *voltha.LogicalDevices) bool {
Mahir Gunyeladdb66a2020-04-29 18:08:50 -0700934 flows, _ := nbi.ListLogicalDeviceFlows(getContext(), &voltha.ID{Id: lds.Items[0].Id})
935 return lds != nil && len(lds.Items) == 1 && len(flows.Items) == expectedNumFlows
khenaidoo67b22152020-03-02 16:01:25 -0500936 }
937 // No timeout implies a success
938 err := waitUntilConditionForLogicalDevices(nb.maxTimeout, nbi, vlFunction)
939 assert.Nil(t, err)
940}
941
Kent Hagerman2b216042020-04-03 18:28:56 -0400942func (nb *NBTest) sendTrapFlows(t *testing.T, nbi *NBIHandler, logicalDevice *voltha.LogicalDevice, meterID uint64, startingVlan int) (numNNIPorts, numUNIPorts int) {
khenaidoo67b22152020-03-02 16:01:25 -0500943 // Send flows for the parent device
944 var nniPorts []*voltha.LogicalPort
945 var uniPorts []*voltha.LogicalPort
946 for _, p := range logicalDevice.Ports {
947 if p.RootPort {
948 nniPorts = append(nniPorts, p)
949 } else {
950 uniPorts = append(uniPorts, p)
951 }
952 }
953 assert.Equal(t, 1, len(nniPorts))
954 //assert.Greater(t, len(uniPorts), 1 )
955 nniPort := nniPorts[0].OfpPort.PortNo
956 maxInt32 := uint64(0xFFFFFFFF)
957 controllerPortMask := uint32(4294967293) // will result in 4294967293&0x7fffffff => 2147483645 which is the actual controller port
958 var fa *flows.FlowArgs
959 fa = &flows.FlowArgs{
960 KV: flows.OfpFlowModArgs{"priority": 10000, "buffer_id": maxInt32, "out_port": maxInt32, "out_group": maxInt32, "flags": 1},
961 MatchFields: []*ofp.OfpOxmOfbField{
962 flows.InPort(nniPort),
963 flows.EthType(35020),
964 },
965 Actions: []*ofp.OfpAction{
966 flows.Output(controllerPortMask),
967 },
968 }
969 flowLLDP := ofp.FlowTableUpdate{FlowMod: makeSimpleFlowMod(fa), Id: logicalDevice.Id}
970 _, err := nbi.UpdateLogicalDeviceFlowTable(getContext(), &flowLLDP)
971 assert.Nil(t, err)
972
973 fa = &flows.FlowArgs{
974 KV: flows.OfpFlowModArgs{"priority": 10000, "buffer_id": maxInt32, "out_port": maxInt32, "out_group": maxInt32, "flags": 1},
975 MatchFields: []*ofp.OfpOxmOfbField{
976 flows.InPort(nniPort),
977 flows.EthType(2048),
978 flows.IpProto(17),
979 flows.UdpSrc(67),
980 flows.UdpDst(68),
981 },
982 Actions: []*ofp.OfpAction{
983 flows.Output(controllerPortMask),
984 },
985 }
986 flowIPV4 := ofp.FlowTableUpdate{FlowMod: makeSimpleFlowMod(fa), Id: logicalDevice.Id}
987 _, err = nbi.UpdateLogicalDeviceFlowTable(getContext(), &flowIPV4)
988 assert.Nil(t, err)
989
990 fa = &flows.FlowArgs{
991 KV: flows.OfpFlowModArgs{"priority": 10000, "buffer_id": maxInt32, "out_port": maxInt32, "out_group": maxInt32, "flags": 1},
992 MatchFields: []*ofp.OfpOxmOfbField{
993 flows.InPort(nniPort),
994 flows.EthType(34525),
995 flows.IpProto(17),
996 flows.UdpSrc(546),
997 flows.UdpDst(547),
998 },
999 Actions: []*ofp.OfpAction{
1000 flows.Output(controllerPortMask),
1001 },
1002 }
1003 flowIPV6 := ofp.FlowTableUpdate{FlowMod: makeSimpleFlowMod(fa), Id: logicalDevice.Id}
1004 _, err = nbi.UpdateLogicalDeviceFlowTable(getContext(), &flowIPV6)
1005 assert.Nil(t, err)
1006
1007 return len(nniPorts), len(uniPorts)
1008}
1009
Kent Hagerman2b216042020-04-03 18:28:56 -04001010func (nb *NBTest) sendEAPFlows(t *testing.T, nbi *NBIHandler, logicalDeviceID string, port *ofp.OfpPort, vlan int, meterID uint64) {
khenaidoo67b22152020-03-02 16:01:25 -05001011 maxInt32 := uint64(0xFFFFFFFF)
1012 controllerPortMask := uint32(4294967293) // will result in 4294967293&0x7fffffff => 2147483645 which is the actual controller port
1013 fa := &flows.FlowArgs{
1014 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},
1015 MatchFields: []*ofp.OfpOxmOfbField{
1016 flows.InPort(port.PortNo),
1017 flows.EthType(34958),
1018 flows.VlanVid(8187),
1019 },
1020 Actions: []*ofp.OfpAction{
1021 flows.Output(controllerPortMask),
1022 },
1023 }
1024 flowEAP := ofp.FlowTableUpdate{FlowMod: makeSimpleFlowMod(fa), Id: logicalDeviceID}
khenaidoo0db4c812020-05-27 15:27:30 -04001025 maxTries := 3
1026 var err error
1027 for {
1028 if _, err = nbi.UpdateLogicalDeviceFlowTable(getContext(), &flowEAP); err == nil {
1029 if maxTries < 3 {
1030 t.Log("Re-sending EAPOL flow succeeded for port:", port)
1031 }
1032 break
1033 }
1034 t.Log("Sending EAPOL flows fail:", err)
1035 time.Sleep(50 * time.Millisecond)
1036 maxTries--
1037 if maxTries == 0 {
1038 break
1039 }
1040 }
khenaidoo67b22152020-03-02 16:01:25 -05001041 assert.Nil(t, err)
1042}
1043
khenaidoo0db4c812020-05-27 15:27:30 -04001044func (nb *NBTest) monitorLogicalDevice(t *testing.T, nbi *NBIHandler, numNNIPorts int, numUNIPorts int, wg *sync.WaitGroup, flowAddFail bool, flowDeleteFail bool) {
khenaidoo67b22152020-03-02 16:01:25 -05001045 defer wg.Done()
khenaidoo67b22152020-03-02 16:01:25 -05001046
1047 // Clear any existing flows on the adapters
1048 nb.oltAdapter.ClearFlows()
1049 nb.onuAdapter.ClearFlows()
1050
khenaidoo8b4abbf2020-04-24 17:04:30 -04001051 // Set the adapter actions on flow addition/deletion
khenaidoo0db4c812020-05-27 15:27:30 -04001052 nb.oltAdapter.SetFlowAction(flowAddFail, flowDeleteFail)
1053 nb.onuAdapter.SetFlowAction(flowAddFail, flowDeleteFail)
khenaidoo8b4abbf2020-04-24 17:04:30 -04001054
khenaidoo67b22152020-03-02 16:01:25 -05001055 // Wait until a logical device is ready
1056 var vlFunction isLogicalDevicesConditionSatisfied = func(lds *voltha.LogicalDevices) bool {
1057 if lds == nil || len(lds.Items) != 1 {
1058 return false
1059 }
1060 // Ensure there are both NNI ports and at least one UNI port on the logical device
1061 ld := lds.Items[0]
1062 nniPort := false
1063 uniPort := false
1064 for _, p := range ld.Ports {
1065 nniPort = nniPort || p.RootPort == true
1066 uniPort = uniPort || p.RootPort == false
1067 if nniPort && uniPort {
1068 return true
1069 }
1070 }
1071 return false
1072 }
1073 err := waitUntilConditionForLogicalDevices(nb.maxTimeout, nbi, vlFunction)
1074 assert.Nil(t, err)
1075
1076 logicalDevices, err := nbi.ListLogicalDevices(getContext(), &empty.Empty{})
1077 assert.Nil(t, err)
1078 assert.NotNil(t, logicalDevices)
1079 assert.Equal(t, 1, len(logicalDevices.Items))
1080
1081 logicalDevice := logicalDevices.Items[0]
1082 meterID := rand.Uint32()
1083
1084 // Add a meter to the logical device
1085 meterMod := &ofp.OfpMeterMod{
1086 Command: ofp.OfpMeterModCommand_OFPMC_ADD,
1087 Flags: rand.Uint32(),
1088 MeterId: meterID,
1089 Bands: []*ofp.OfpMeterBandHeader{
1090 {Type: ofp.OfpMeterBandType_OFPMBT_EXPERIMENTER,
1091 Rate: rand.Uint32(),
1092 BurstSize: rand.Uint32(),
1093 Data: nil,
1094 },
1095 },
1096 }
1097 _, err = nbi.UpdateLogicalDeviceMeterTable(getContext(), &ofp.MeterModUpdate{Id: logicalDevice.Id, MeterMod: meterMod})
1098 assert.Nil(t, err)
1099
1100 // Send initial set of Trap flows
1101 startingVlan := 4091
1102 nb.sendTrapFlows(t, nbi, logicalDevice, uint64(meterID), startingVlan)
1103
1104 // Listen for port events
khenaidoo442e7c72020-03-10 16:13:48 -04001105 start := time.Now()
Girish Gowdra408cd962020-03-11 14:31:31 -07001106 processedNniLogicalPorts := 0
1107 processedUniLogicalPorts := 0
1108
Kent Hagerman45a13e42020-04-13 12:23:50 -04001109 for event := range nbi.GetChangeEventsQueueForTest() {
khenaidoo67b22152020-03-02 16:01:25 -05001110 startingVlan++
1111 if portStatus, ok := (event.Event).(*ofp.ChangeEvent_PortStatus); ok {
1112 ps := portStatus.PortStatus
1113 if ps.Reason == ofp.OfpPortReason_OFPPR_ADD {
khenaidoo67b22152020-03-02 16:01:25 -05001114 if ps.Desc.PortNo >= uint32(nb.startingUNIPortNo) {
Girish Gowdra408cd962020-03-11 14:31:31 -07001115 processedUniLogicalPorts++
khenaidoo67b22152020-03-02 16:01:25 -05001116 nb.sendEAPFlows(t, nbi, logicalDevice.Id, ps.Desc, startingVlan, uint64(meterID))
Girish Gowdra408cd962020-03-11 14:31:31 -07001117 } else {
1118 processedNniLogicalPorts++
khenaidoo67b22152020-03-02 16:01:25 -05001119 }
1120 }
1121 }
Girish Gowdra408cd962020-03-11 14:31:31 -07001122
1123 if processedNniLogicalPorts >= numNNIPorts && processedUniLogicalPorts >= numUNIPorts {
khenaidoo442e7c72020-03-10 16:13:48 -04001124 fmt.Println("Total time to send all flows:", time.Since(start))
khenaidoo67b22152020-03-02 16:01:25 -05001125 break
1126 }
1127 }
1128 //Verify the flow count on the logical device
khenaidoo8b4abbf2020-04-24 17:04:30 -04001129 nb.verifyLogicalDeviceFlowCount(t, nbi, numNNIPorts, numUNIPorts, flowAddFail)
khenaidoo67b22152020-03-02 16:01:25 -05001130
khenaidoo8b4abbf2020-04-24 17:04:30 -04001131 // Wait until all flows have been sent to the OLT adapters (or all failed)
1132 expectedFlowCount := (numNNIPorts * 3) + numNNIPorts*numUNIPorts
1133 if flowAddFail {
1134 expectedFlowCount = 0
1135 }
khenaidoo67b22152020-03-02 16:01:25 -05001136 var oltVFunc isConditionSatisfied = func() bool {
khenaidoo8b4abbf2020-04-24 17:04:30 -04001137 return nb.oltAdapter.GetFlowCount() >= expectedFlowCount
khenaidoo67b22152020-03-02 16:01:25 -05001138 }
1139 err = waitUntilCondition(nb.maxTimeout, nbi, oltVFunc)
1140 assert.Nil(t, err)
1141
khenaidoo8b4abbf2020-04-24 17:04:30 -04001142 // Wait until all flows have been sent to the ONU adapters (or all failed)
1143 expectedFlowCount = numUNIPorts
1144 if flowAddFail {
1145 expectedFlowCount = 0
1146 }
khenaidoo67b22152020-03-02 16:01:25 -05001147 var onuVFunc isConditionSatisfied = func() bool {
khenaidoo8b4abbf2020-04-24 17:04:30 -04001148 return nb.onuAdapter.GetFlowCount() == expectedFlowCount
khenaidoo67b22152020-03-02 16:01:25 -05001149 }
1150 err = waitUntilCondition(nb.maxTimeout, nbi, onuVFunc)
1151 assert.Nil(t, err)
1152}
1153
khenaidoo8b4abbf2020-04-24 17:04:30 -04001154func (nb *NBTest) testFlowAddFailure(t *testing.T, nbi *NBIHandler) {
1155
1156 // Create a logical device monitor will automatically send trap and eapol flows to the devices being enables
1157 var wg sync.WaitGroup
1158 wg.Add(1)
khenaidoo0db4c812020-05-27 15:27:30 -04001159 go nb.monitorLogicalDevice(t, nbi, 1, nb.numONUPerOLT, &wg, true, false)
khenaidoo8b4abbf2020-04-24 17:04:30 -04001160
1161 // Create the device with valid data
1162 oltDevice, err := nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName, MacAddress: "aa:bb:cc:cc:ee:ee"})
1163 assert.Nil(t, err)
1164 assert.NotNil(t, oltDevice)
1165
1166 // Verify oltDevice exist in the core
1167 devices, err := nbi.ListDevices(getContext(), &empty.Empty{})
1168 assert.Nil(t, err)
1169 assert.Equal(t, 1, len(devices.Items))
1170 assert.Equal(t, oltDevice.Id, devices.Items[0].Id)
1171
1172 // Enable the oltDevice
1173 _, err = nbi.EnableDevice(getContext(), &voltha.ID{Id: oltDevice.Id})
1174 assert.Nil(t, err)
1175
1176 // Wait for the logical device to be in the ready state
1177 var vldFunction isLogicalDeviceConditionSatisfied = func(ld *voltha.LogicalDevice) bool {
1178 return ld != nil && len(ld.Ports) == nb.numONUPerOLT+1
1179 }
1180 err = waitUntilLogicalDeviceReadiness(oltDevice.Id, nb.maxTimeout, nbi, vldFunction)
1181 assert.Nil(t, err)
1182
1183 // Verify that the devices have been setup correctly
1184 nb.verifyDevices(t, nbi)
1185
1186 // Get latest oltDevice data
1187 oltDevice, err = nbi.GetDevice(getContext(), &voltha.ID{Id: oltDevice.Id})
1188 assert.Nil(t, err)
1189
1190 // Verify that the logical device has been setup correctly
1191 nb.verifyLogicalDevices(t, oltDevice, nbi)
1192
1193 // Wait until all flows has been sent to the devices successfully
1194 wg.Wait()
1195}
1196
Matteo Scandolod525ae32020-04-02 17:27:29 -07001197func TestSuiteNbiApiHandler(t *testing.T) {
Kent Hagerman2b216042020-04-03 18:28:56 -04001198 f, err := os.Create("../../../tests/results/profile.cpu")
khenaidoo67b22152020-03-02 16:01:25 -05001199 if err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +00001200 logger.Fatalf("could not create CPU profile: %v\n ", err)
khenaidoo67b22152020-03-02 16:01:25 -05001201 }
1202 defer f.Close()
1203 runtime.SetBlockProfileRate(1)
1204 runtime.SetMutexProfileFraction(-1)
1205 if err := pprof.StartCPUProfile(f); err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +00001206 logger.Fatalf("could not start CPU profile: %v\n", err)
khenaidoo67b22152020-03-02 16:01:25 -05001207 }
1208 defer pprof.StopCPUProfile()
1209
khenaidoo442e7c72020-03-10 16:13:48 -04001210 //log.SetPackageLogLevel("github.com/opencord/voltha-go/rw_core/core", log.DebugLevel)
1211
khenaidoob64fc8a2019-11-27 15:08:19 -05001212 nb := newNBTest()
1213 assert.NotNil(t, nb)
1214
1215 defer nb.stopAll()
1216
1217 // Start the Core
1218 nb.startCore(false)
1219
1220 // Set the grpc API interface - no grpc server is running in unit test
Kent Hagerman45a13e42020-04-13 12:23:50 -04001221 nbi := NewNBIHandler(nb.deviceMgr, nb.logicalDeviceMgr, nb.adapterMgr)
khenaidoob64fc8a2019-11-27 15:08:19 -05001222
1223 // 1. Basic test with no data in Core
1224 nb.testCoreWithoutData(t, nbi)
1225
1226 // Create/register the adapters
Mahir Gunyel03de0d32020-06-03 01:36:59 -07001227 nb.oltAdapter, nb.onuAdapter = tst.CreateAndregisterAdapters(t, nb.kClient, nb.coreInstanceID, nb.oltAdapterName, nb.onuAdapterName, nb.adapterMgr)
1228 nb.numONUPerOLT = nb.oltAdapter.GetNumONUPerOLT()
1229 nb.startingUNIPortNo = nb.oltAdapter.GetStartingUNIPortNo()
khenaidoob64fc8a2019-11-27 15:08:19 -05001230
1231 // 2. Test adapter registration
1232 nb.testAdapterRegistration(t, nbi)
1233
khenaidoo8b4abbf2020-04-24 17:04:30 -04001234 numberOfTestRuns := 2
1235 for i := 1; i <= numberOfTestRuns; i++ {
khenaidoo67b22152020-03-02 16:01:25 -05001236 //3. Test create device
khenaidoo93d5a3d2020-01-15 12:37:05 -05001237 nb.testCreateDevice(t, nbi)
khenaidoob64fc8a2019-11-27 15:08:19 -05001238
khenaidoo93d5a3d2020-01-15 12:37:05 -05001239 // 4. Test Enable a device
1240 nb.testEnableDevice(t, nbi)
khenaidoob64fc8a2019-11-27 15:08:19 -05001241
khenaidoo0db4c812020-05-27 15:27:30 -04001242 //// 5. Test disable and ReEnable a root device
khenaidoo93d5a3d2020-01-15 12:37:05 -05001243 nb.testDisableAndReEnableRootDevice(t, nbi)
khenaidoo67b22152020-03-02 16:01:25 -05001244
kesavandbc2d1622020-01-21 00:42:01 -05001245 // 6. Test disable and Enable pon port of OLT device
1246 nb.testDisableAndEnablePort(t, nbi)
khenaidoo93d5a3d2020-01-15 12:37:05 -05001247
Girish Gowdra408cd962020-03-11 14:31:31 -07001248 // 7.Test Device unreachable when OLT is enabled
1249 nb.testDeviceRebootWhenOltIsEnabled(t, nbi)
1250
1251 // 8. Test disable and delete all devices
khenaidoo93d5a3d2020-01-15 12:37:05 -05001252 nb.testDisableAndDeleteAllDevice(t, nbi)
Chaitrashree G S543df3e2020-02-24 22:36:54 -05001253
Girish Gowdra408cd962020-03-11 14:31:31 -07001254 // 9. Test enable and delete all devices
Chaitrashree G S543df3e2020-02-24 22:36:54 -05001255 nb.testEnableAndDeleteAllDevice(t, nbi)
Scott Baker432f9be2020-03-26 11:56:30 -07001256
1257 // 10. Test omci test
1258 nb.testStartOmciTestAction(t, nbi)
khenaidoob64fc8a2019-11-27 15:08:19 -05001259
khenaidoo0db4c812020-05-27 15:27:30 -04001260 // 11. Remove all devices from tests above
1261 nb.deleteAllDevices(t, nbi)
1262
khenaidoo8b4abbf2020-04-24 17:04:30 -04001263 // 11. Test flow add failure
1264 nb.testFlowAddFailure(t, nbi)
1265
1266 // 12. Clean up
1267 nb.deleteAllDevices(t, nbi)
1268 }
khenaidoob64fc8a2019-11-27 15:08:19 -05001269}