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