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