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