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