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