khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -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 | 6e55d9e | 2019-12-12 18:26:26 -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 device |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 18 | |
| 19 | import ( |
| 20 | "context" |
Kent Hagerman | f6db9f1 | 2020-07-22 17:16:19 -0400 | [diff] [blame] | 21 | "fmt" |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 22 | "math/rand" |
| 23 | "sort" |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 24 | "strconv" |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 25 | "strings" |
| 26 | "sync" |
| 27 | "testing" |
| 28 | "time" |
| 29 | |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 30 | "github.com/gogo/protobuf/proto" |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 31 | "github.com/opencord/voltha-go/db/model" |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 32 | "github.com/opencord/voltha-go/rw_core/config" |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 33 | "github.com/opencord/voltha-go/rw_core/core/adapter" |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 34 | cm "github.com/opencord/voltha-go/rw_core/mocks" |
| 35 | tst "github.com/opencord/voltha-go/rw_core/test" |
yasin sapli | 5458a1c | 2021-06-14 22:24:38 +0000 | [diff] [blame] | 36 | com "github.com/opencord/voltha-lib-go/v5/pkg/adapters/common" |
| 37 | "github.com/opencord/voltha-lib-go/v5/pkg/db" |
| 38 | "github.com/opencord/voltha-lib-go/v5/pkg/events" |
| 39 | "github.com/opencord/voltha-lib-go/v5/pkg/kafka" |
| 40 | "github.com/opencord/voltha-lib-go/v5/pkg/log" |
| 41 | mock_etcd "github.com/opencord/voltha-lib-go/v5/pkg/mocks/etcd" |
| 42 | mock_kafka "github.com/opencord/voltha-lib-go/v5/pkg/mocks/kafka" |
Maninder | dfadc98 | 2020-10-28 14:04:33 +0530 | [diff] [blame] | 43 | ofp "github.com/opencord/voltha-protos/v4/go/openflow_13" |
| 44 | "github.com/opencord/voltha-protos/v4/go/voltha" |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 45 | "github.com/phayes/freeport" |
| 46 | "github.com/stretchr/testify/assert" |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 47 | ) |
| 48 | |
| 49 | type DATest struct { |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 50 | etcdServer *mock_etcd.EtcdServer |
| 51 | deviceMgr *Manager |
| 52 | logicalDeviceMgr *LogicalManager |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 53 | adapterMgr *adapter.Manager |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 54 | kmp kafka.InterContainerProxy |
| 55 | kClient kafka.Client |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 56 | kEventClient kafka.Client |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 57 | kvClientPort int |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 58 | oltAdapter *cm.OLTAdapter |
| 59 | onuAdapter *cm.ONUAdapter |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 60 | oltAdapterName string |
| 61 | onuAdapterName string |
| 62 | coreInstanceID string |
| 63 | defaultTimeout time.Duration |
| 64 | maxTimeout time.Duration |
| 65 | device *voltha.Device |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 66 | devicePorts map[uint32]*voltha.Port |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 67 | done chan int |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 68 | } |
| 69 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 70 | func newDATest(ctx context.Context) *DATest { |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 71 | test := &DATest{} |
| 72 | // Start the embedded etcd server |
| 73 | var err error |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 74 | test.etcdServer, test.kvClientPort, err = tst.StartEmbeddedEtcdServer(ctx, "voltha.rwcore.da.test", "voltha.rwcore.da.etcd", "error") |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 75 | if err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 76 | logger.Fatal(ctx, err) |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 77 | } |
| 78 | // Create the kafka client |
Matteo Scandolo | d525ae3 | 2020-04-02 17:27:29 -0700 | [diff] [blame] | 79 | test.kClient = mock_kafka.NewKafkaClient() |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 80 | test.kEventClient = mock_kafka.NewKafkaClient() |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 81 | test.oltAdapterName = "olt_adapter_mock" |
| 82 | test.onuAdapterName = "onu_adapter_mock" |
| 83 | test.coreInstanceID = "rw-da-test" |
| 84 | test.defaultTimeout = 5 * time.Second |
| 85 | test.maxTimeout = 20 * time.Second |
| 86 | test.done = make(chan int) |
| 87 | parentID := com.GetRandomString(10) |
| 88 | test.device = &voltha.Device{ |
| 89 | Type: "onu_adapter_mock", |
| 90 | ParentId: parentID, |
| 91 | ParentPortNo: 1, |
| 92 | VendorId: "onu_adapter_mock", |
| 93 | Adapter: "onu_adapter_mock", |
| 94 | Vlan: 100, |
| 95 | Address: nil, |
| 96 | ProxyAddress: &voltha.Device_ProxyAddress{ |
| 97 | DeviceId: parentID, |
| 98 | DeviceType: "olt_adapter_mock", |
| 99 | ChannelId: 100, |
| 100 | ChannelGroupId: 0, |
| 101 | ChannelTermination: "", |
| 102 | OnuId: 2, |
| 103 | }, |
| 104 | AdminState: voltha.AdminState_PREPROVISIONED, |
| 105 | OperStatus: voltha.OperStatus_UNKNOWN, |
| 106 | Reason: "All good", |
| 107 | ConnectStatus: voltha.ConnectStatus_UNKNOWN, |
| 108 | Custom: nil, |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 109 | } |
| 110 | test.devicePorts = map[uint32]*voltha.Port{ |
| 111 | 1: {PortNo: 1, Label: "pon-1", Type: voltha.Port_PON_ONU, AdminState: voltha.AdminState_ENABLED, |
| 112 | OperStatus: voltha.OperStatus_ACTIVE, Peers: []*voltha.Port_PeerPort{{DeviceId: parentID, PortNo: 1}}}, |
| 113 | 100: {PortNo: 100, Label: "uni-100", Type: voltha.Port_ETHERNET_UNI, AdminState: voltha.AdminState_ENABLED, |
| 114 | OperStatus: voltha.OperStatus_ACTIVE}, |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 115 | } |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 116 | return test |
| 117 | } |
| 118 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 119 | func (dat *DATest) startCore(ctx context.Context) { |
David K. Bainbridge | 6080c17 | 2021-07-24 00:22:28 +0000 | [diff] [blame] | 120 | cfg := &config.RWCoreFlags{} |
| 121 | cfg.ParseCommandArguments([]string{}) |
serkant.uluderya | 8ff291d | 2020-05-20 00:58:00 -0700 | [diff] [blame] | 122 | cfg.CoreTopic = "rw_core" |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 123 | cfg.EventTopic = "voltha.events" |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 124 | cfg.DefaultRequestTimeout = dat.defaultTimeout |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 125 | cfg.KVStoreAddress = "127.0.0.1" + ":" + strconv.Itoa(dat.kvClientPort) |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 126 | grpcPort, err := freeport.GetFreePort() |
| 127 | if err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 128 | logger.Fatal(ctx, "Cannot get a freeport for grpc") |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 129 | } |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 130 | cfg.GrpcAddress = "127.0.0.1" + ":" + strconv.Itoa(grpcPort) |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 131 | client := tst.SetupKVClient(ctx, cfg, dat.coreInstanceID) |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 132 | backend := &db.Backend{ |
| 133 | Client: client, |
| 134 | StoreType: cfg.KVStoreType, |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 135 | Address: cfg.KVStoreAddress, |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 136 | Timeout: cfg.KVStoreTimeout, |
serkant.uluderya | 8ff291d | 2020-05-20 00:58:00 -0700 | [diff] [blame] | 137 | LivenessChannelInterval: cfg.LiveProbeInterval / 2} |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 138 | dat.kmp = kafka.NewInterContainerProxy( |
Neha Sharma | d1387da | 2020-05-07 20:07:28 +0000 | [diff] [blame] | 139 | kafka.InterContainerAddress(cfg.KafkaAdapterAddress), |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 140 | kafka.MsgClient(dat.kClient), |
David Bainbridge | 9ae1313 | 2020-06-22 17:28:01 -0700 | [diff] [blame] | 141 | kafka.DefaultTopic(&kafka.Topic{Name: cfg.CoreTopic})) |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 142 | |
| 143 | endpointMgr := kafka.NewEndpointManager(backend) |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 144 | proxy := model.NewDBPath(backend) |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 145 | dat.adapterMgr = adapter.NewAdapterManager(ctx, proxy, dat.coreInstanceID, dat.kClient) |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 146 | eventProxy := events.NewEventProxy(events.MsgClient(dat.kEventClient), events.MsgTopic(kafka.Topic{Name: cfg.EventTopic})) |
Maninder | 0aabf0c | 2021-03-17 14:55:14 +0530 | [diff] [blame] | 147 | dat.deviceMgr, dat.logicalDeviceMgr = NewManagers(proxy, dat.adapterMgr, dat.kmp, endpointMgr, cfg, dat.coreInstanceID, eventProxy) |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 148 | dat.adapterMgr.Start(context.Background()) |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 149 | if err = dat.kmp.Start(ctx); err != nil { |
| 150 | logger.Fatal(ctx, "Cannot start InterContainerProxy") |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 151 | } |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 152 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 153 | if err := dat.kmp.SubscribeWithDefaultRequestHandler(ctx, kafka.Topic{Name: cfg.CoreTopic}, kafka.OffsetNewest); err != nil { |
| 154 | logger.Fatalf(ctx, "Cannot add default request handler: %s", err) |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 155 | } |
| 156 | |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 157 | } |
| 158 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 159 | func (dat *DATest) stopAll(ctx context.Context) { |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 160 | if dat.kClient != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 161 | dat.kClient.Stop(ctx) |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 162 | } |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 163 | if dat.kmp != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 164 | dat.kmp.Stop(ctx) |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 165 | } |
| 166 | if dat.etcdServer != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 167 | tst.StopEmbeddedEtcdServer(ctx, dat.etcdServer) |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 168 | } |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 169 | if dat.kEventClient != nil { |
| 170 | dat.kEventClient.Stop(ctx) |
| 171 | } |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 172 | } |
| 173 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 174 | func (dat *DATest) createDeviceAgent(t *testing.T) *Agent { |
| 175 | deviceMgr := dat.deviceMgr |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 176 | clonedDevice := proto.Clone(dat.device).(*voltha.Device) |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 177 | deviceAgent := newAgent(deviceMgr.adapterProxy, clonedDevice, deviceMgr, deviceMgr.dbPath, deviceMgr.dProxy, deviceMgr.defaultTimeout) |
khenaidoo | 7585a96 | 2021-06-10 16:15:38 -0400 | [diff] [blame] | 178 | d, err := deviceAgent.start(context.TODO(), false, clonedDevice) |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 179 | assert.Nil(t, err) |
| 180 | assert.NotNil(t, d) |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 181 | for _, port := range dat.devicePorts { |
| 182 | err := deviceAgent.addPort(context.TODO(), port) |
| 183 | assert.Nil(t, err) |
| 184 | } |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 185 | deviceMgr.addDeviceAgentToMap(deviceAgent) |
| 186 | return deviceAgent |
| 187 | } |
| 188 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 189 | func (dat *DATest) updateDeviceConcurrently(t *testing.T, da *Agent, globalWG *sync.WaitGroup) { |
Kent Hagerman | cba2f30 | 2020-07-28 13:37:36 -0400 | [diff] [blame] | 190 | originalDevice, err := da.getDeviceReadOnly(context.Background()) |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 191 | originalDevicePorts := da.listDevicePorts() |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 192 | assert.Nil(t, err) |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 193 | assert.NotNil(t, originalDevice) |
| 194 | var localWG sync.WaitGroup |
| 195 | |
| 196 | // Update device routine |
| 197 | var ( |
| 198 | root = false |
| 199 | vendor = "onu_adapter_mock" |
| 200 | model = "go-mock" |
| 201 | serialNumber = com.GetRandomSerialNumber() |
| 202 | macAddress = strings.ToUpper(com.GetRandomMacAddress()) |
| 203 | vlan = rand.Uint32() |
| 204 | reason = "testing concurrent device update" |
| 205 | portToAdd = &voltha.Port{PortNo: 101, Label: "uni-101", Type: voltha.Port_ETHERNET_UNI, AdminState: voltha.AdminState_ENABLED, |
| 206 | OperStatus: voltha.OperStatus_ACTIVE} |
| 207 | ) |
| 208 | localWG.Add(1) |
| 209 | go func() { |
| 210 | deviceToUpdate := proto.Clone(originalDevice).(*voltha.Device) |
| 211 | deviceToUpdate.Root = root |
| 212 | deviceToUpdate.Vendor = vendor |
| 213 | deviceToUpdate.Model = model |
| 214 | deviceToUpdate.SerialNumber = serialNumber |
| 215 | deviceToUpdate.MacAddress = macAddress |
| 216 | deviceToUpdate.Vlan = vlan |
| 217 | deviceToUpdate.Reason = reason |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 218 | err := da.updateDeviceUsingAdapterData(context.Background(), deviceToUpdate) |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 219 | assert.Nil(t, err) |
| 220 | localWG.Done() |
| 221 | }() |
| 222 | |
| 223 | // Update the device status routine |
| 224 | localWG.Add(1) |
| 225 | go func() { |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 226 | err := da.updateDeviceStatus(context.Background(), voltha.OperStatus_ACTIVE, voltha.ConnectStatus_REACHABLE) |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 227 | assert.Nil(t, err) |
| 228 | localWG.Done() |
| 229 | }() |
| 230 | |
| 231 | // Add a port routine |
| 232 | localWG.Add(1) |
| 233 | go func() { |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 234 | err := da.addPort(context.Background(), portToAdd) |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 235 | assert.Nil(t, err) |
| 236 | localWG.Done() |
| 237 | }() |
| 238 | |
| 239 | // wait for go routines to be done |
| 240 | localWG.Wait() |
| 241 | |
| 242 | expectedChange := proto.Clone(originalDevice).(*voltha.Device) |
| 243 | expectedChange.OperStatus = voltha.OperStatus_ACTIVE |
| 244 | expectedChange.ConnectStatus = voltha.ConnectStatus_REACHABLE |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 245 | expectedChange.Root = root |
| 246 | expectedChange.Vendor = vendor |
| 247 | expectedChange.Model = model |
| 248 | expectedChange.SerialNumber = serialNumber |
| 249 | expectedChange.MacAddress = macAddress |
| 250 | expectedChange.Vlan = vlan |
| 251 | expectedChange.Reason = reason |
| 252 | |
Kent Hagerman | cba2f30 | 2020-07-28 13:37:36 -0400 | [diff] [blame] | 253 | updatedDevice, _ := da.getDeviceReadOnly(context.Background()) |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 254 | updatedDevicePorts := da.listDevicePorts() |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 255 | assert.NotNil(t, updatedDevice) |
Kent Hagerman | f6db9f1 | 2020-07-22 17:16:19 -0400 | [diff] [blame] | 256 | fmt.Printf("1 %+v\n", expectedChange) |
| 257 | fmt.Printf("2 %+v\n", updatedDevice) |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 258 | assert.True(t, proto.Equal(expectedChange, updatedDevice)) |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 259 | assert.Equal(t, len(originalDevicePorts)+1, len(updatedDevicePorts)) |
| 260 | assert.True(t, proto.Equal(updatedDevicePorts[portToAdd.PortNo], portToAdd)) |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 261 | |
| 262 | globalWG.Done() |
| 263 | } |
| 264 | |
| 265 | func TestConcurrentDevices(t *testing.T) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 266 | ctx := context.Background() |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 267 | for i := 0; i < 2; i++ { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 268 | da := newDATest(ctx) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 269 | assert.NotNil(t, da) |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 270 | defer da.stopAll(ctx) |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 271 | log.SetPackageLogLevel("github.com/opencord/voltha-go/rw_core/core", log.DebugLevel) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 272 | // Start the Core |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 273 | da.startCore(ctx) |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 274 | |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 275 | var wg sync.WaitGroup |
| 276 | numConCurrentDeviceAgents := 20 |
| 277 | for i := 0; i < numConCurrentDeviceAgents; i++ { |
| 278 | wg.Add(1) |
| 279 | a := da.createDeviceAgent(t) |
| 280 | go da.updateDeviceConcurrently(t, a, &wg) |
| 281 | } |
| 282 | |
| 283 | wg.Wait() |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 284 | } |
khenaidoo | 6e55d9e | 2019-12-12 18:26:26 -0500 | [diff] [blame] | 285 | } |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 286 | func TestFlowUpdates(t *testing.T) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 287 | ctx := context.Background() |
| 288 | da := newDATest(ctx) |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 289 | assert.NotNil(t, da) |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 290 | defer da.stopAll(ctx) |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 291 | |
| 292 | log.SetPackageLogLevel("github.com/opencord/voltha-go/rw_core/core", log.DebugLevel) |
| 293 | // Start the Core |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 294 | da.startCore(ctx) |
| 295 | da.oltAdapter, da.onuAdapter = tst.CreateAndregisterAdapters(ctx, t, da.kClient, da.coreInstanceID, da.oltAdapterName, da.onuAdapterName, da.adapterMgr) |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 296 | |
| 297 | a := da.createDeviceAgent(t) |
Kent Hagerman | f6db9f1 | 2020-07-22 17:16:19 -0400 | [diff] [blame] | 298 | err1 := a.requestQueue.WaitForGreenLight(ctx) |
| 299 | assert.Nil(t, err1) |
| 300 | cloned := a.cloneDeviceWithoutLock() |
| 301 | cloned.AdminState, cloned.ConnectStatus, cloned.OperStatus = voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE |
| 302 | err2 := a.updateDeviceAndReleaseLock(ctx, cloned) |
| 303 | assert.Nil(t, err2) |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 304 | da.testFlowAddDeletes(t, a) |
| 305 | } |
| 306 | |
| 307 | func TestGroupUpdates(t *testing.T) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 308 | ctx := context.Background() |
| 309 | da := newDATest(ctx) |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 310 | assert.NotNil(t, da) |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 311 | defer da.stopAll(ctx) |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 312 | |
| 313 | // Start the Core |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 314 | da.startCore(ctx) |
| 315 | da.oltAdapter, da.onuAdapter = tst.CreateAndregisterAdapters(ctx, t, da.kClient, da.coreInstanceID, da.oltAdapterName, da.onuAdapterName, da.adapterMgr) |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 316 | a := da.createDeviceAgent(t) |
Kent Hagerman | f6db9f1 | 2020-07-22 17:16:19 -0400 | [diff] [blame] | 317 | err1 := a.requestQueue.WaitForGreenLight(ctx) |
| 318 | assert.Nil(t, err1) |
| 319 | cloned := a.cloneDeviceWithoutLock() |
| 320 | cloned.AdminState, cloned.ConnectStatus, cloned.OperStatus = voltha.AdminState_ENABLED, voltha.ConnectStatus_REACHABLE, voltha.OperStatus_ACTIVE |
| 321 | err2 := a.updateDeviceAndReleaseLock(ctx, cloned) |
| 322 | assert.Nil(t, err2) |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 323 | da.testGroupAddDeletes(t, a) |
| 324 | } |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 325 | |
| 326 | func isFlowSliceEqual(a, b []*ofp.OfpFlowStats) bool { |
| 327 | if len(a) != len(b) { |
| 328 | return false |
| 329 | } |
| 330 | sort.Slice(a, func(i, j int) bool { |
| 331 | return a[i].Id < a[j].Id |
| 332 | }) |
| 333 | sort.Slice(b, func(i, j int) bool { |
| 334 | return b[i].Id < b[j].Id |
| 335 | }) |
| 336 | for idx := range a { |
| 337 | if !proto.Equal(a[idx], b[idx]) { |
| 338 | return false |
| 339 | } |
| 340 | } |
| 341 | return true |
| 342 | } |
| 343 | |
| 344 | func isGroupSliceEqual(a, b []*ofp.OfpGroupEntry) bool { |
| 345 | if len(a) != len(b) { |
| 346 | return false |
| 347 | } |
| 348 | sort.Slice(a, func(i, j int) bool { |
| 349 | return a[i].Desc.GroupId < a[j].Desc.GroupId |
| 350 | }) |
| 351 | sort.Slice(b, func(i, j int) bool { |
| 352 | return b[i].Desc.GroupId < b[j].Desc.GroupId |
| 353 | }) |
| 354 | for idx := range a { |
| 355 | if !proto.Equal(a[idx], b[idx]) { |
| 356 | return false |
| 357 | } |
| 358 | } |
| 359 | return true |
| 360 | } |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 361 | func changeToFlowList(flowList map[uint64]*ofp.OfpFlowStats) []*ofp.OfpFlowStats { |
| 362 | flows := make([]*ofp.OfpFlowStats, 0) |
| 363 | for _, flow := range flowList { |
| 364 | flows = append(flows, flow) |
| 365 | } |
| 366 | return flows |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 367 | } |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 368 | func changeToGroupList(groupList map[uint32]*ofp.OfpGroupEntry) []*ofp.OfpGroupEntry { |
| 369 | groups := make([]*ofp.OfpGroupEntry, 0) |
| 370 | for _, group := range groupList { |
| 371 | groups = append(groups, group) |
| 372 | } |
| 373 | return groups |
| 374 | } |
| 375 | func (dat *DATest) testFlowAddDeletes(t *testing.T, da *Agent) { |
| 376 | //Add new Flows on empty list |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 377 | newFlows := []*ofp.OfpFlowStats{ |
| 378 | {Id: 123, TableId: 1230, Priority: 100, IdleTimeout: 0, Flags: 0, Cookie: 1230000, PacketCount: 0}, |
| 379 | {Id: 124, TableId: 1240, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1240000, PacketCount: 0}, |
| 380 | {Id: 125, TableId: 1250, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1250000, PacketCount: 0}, |
| 381 | } |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 382 | err := da.addFlowsAndGroups(context.Background(), newFlows, []*ofp.OfpGroupEntry{}, &voltha.FlowMetadata{}) |
| 383 | assert.Nil(t, err) |
| 384 | daFlows := changeToFlowList(da.listDeviceFlows()) |
| 385 | assert.True(t, isFlowSliceEqual(newFlows, daFlows)) |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 386 | |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 387 | //Add new Flows on existing ones |
| 388 | newFlows = []*ofp.OfpFlowStats{ |
| 389 | {Id: 126, TableId: 1260, Priority: 100, IdleTimeout: 0, Flags: 0, Cookie: 1260000, PacketCount: 0}, |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 390 | {Id: 127, TableId: 1270, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1270000, PacketCount: 0}, |
| 391 | } |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 392 | |
| 393 | expectedFlows := []*ofp.OfpFlowStats{ |
| 394 | {Id: 123, TableId: 1230, Priority: 100, IdleTimeout: 0, Flags: 0, Cookie: 1230000, PacketCount: 0}, |
| 395 | {Id: 124, TableId: 1240, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1240000, PacketCount: 0}, |
| 396 | {Id: 125, TableId: 1250, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1250000, PacketCount: 0}, |
| 397 | {Id: 126, TableId: 1260, Priority: 100, IdleTimeout: 0, Flags: 0, Cookie: 1260000, PacketCount: 0}, |
| 398 | {Id: 127, TableId: 1270, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1270000, PacketCount: 0}, |
| 399 | } |
| 400 | |
| 401 | err = da.addFlowsAndGroups(context.Background(), newFlows, []*ofp.OfpGroupEntry{}, &voltha.FlowMetadata{}) |
| 402 | assert.Nil(t, err) |
| 403 | daFlows = changeToFlowList(da.listDeviceFlows()) |
| 404 | assert.True(t, isFlowSliceEqual(expectedFlows, daFlows)) |
| 405 | |
| 406 | //Add existing Flows again with a new flow |
| 407 | newFlows = []*ofp.OfpFlowStats{ |
| 408 | {Id: 126, TableId: 1260, Priority: 100, IdleTimeout: 0, Flags: 0, Cookie: 1260000, PacketCount: 0}, |
| 409 | {Id: 127, TableId: 1270, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1270001, PacketCount: 0}, |
| 410 | {Id: 128, TableId: 1280, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1280000, PacketCount: 0}, |
| 411 | } |
| 412 | |
| 413 | expectedFlows = []*ofp.OfpFlowStats{ |
| 414 | {Id: 123, TableId: 1230, Priority: 100, IdleTimeout: 0, Flags: 0, Cookie: 1230000, PacketCount: 0}, |
| 415 | {Id: 124, TableId: 1240, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1240000, PacketCount: 0}, |
| 416 | {Id: 125, TableId: 1250, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1250000, PacketCount: 0}, |
| 417 | {Id: 126, TableId: 1260, Priority: 100, IdleTimeout: 0, Flags: 0, Cookie: 1260000, PacketCount: 0}, |
| 418 | {Id: 127, TableId: 1270, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1270001, PacketCount: 0}, |
| 419 | {Id: 128, TableId: 1280, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1280000, PacketCount: 0}, |
| 420 | } |
| 421 | |
| 422 | err = da.addFlowsAndGroups(context.Background(), newFlows, []*ofp.OfpGroupEntry{}, &voltha.FlowMetadata{}) |
| 423 | assert.Nil(t, err) |
| 424 | daFlows = changeToFlowList(da.listDeviceFlows()) |
| 425 | assert.True(t, isFlowSliceEqual(expectedFlows, daFlows)) |
| 426 | |
| 427 | //Add already existing flows again |
| 428 | newFlows = []*ofp.OfpFlowStats{ |
| 429 | {Id: 126, TableId: 1260, Priority: 100, IdleTimeout: 0, Flags: 0, Cookie: 1260000, PacketCount: 0}, |
| 430 | {Id: 127, TableId: 1270, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1270001, PacketCount: 0}, |
| 431 | {Id: 128, TableId: 1280, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1280000, PacketCount: 0}, |
| 432 | } |
| 433 | |
| 434 | expectedFlows = []*ofp.OfpFlowStats{ |
| 435 | {Id: 123, TableId: 1230, Priority: 100, IdleTimeout: 0, Flags: 0, Cookie: 1230000, PacketCount: 0}, |
| 436 | {Id: 124, TableId: 1240, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1240000, PacketCount: 0}, |
| 437 | {Id: 125, TableId: 1250, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1250000, PacketCount: 0}, |
| 438 | {Id: 126, TableId: 1260, Priority: 100, IdleTimeout: 0, Flags: 0, Cookie: 1260000, PacketCount: 0}, |
| 439 | {Id: 127, TableId: 1270, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1270001, PacketCount: 0}, |
| 440 | {Id: 128, TableId: 1280, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1280000, PacketCount: 0}, |
| 441 | } |
| 442 | |
| 443 | err = da.addFlowsAndGroups(context.Background(), newFlows, []*ofp.OfpGroupEntry{}, &voltha.FlowMetadata{}) |
| 444 | assert.Nil(t, err) |
| 445 | daFlows = changeToFlowList(da.listDeviceFlows()) |
| 446 | assert.True(t, isFlowSliceEqual(expectedFlows, daFlows)) |
| 447 | |
| 448 | //Delete flows |
| 449 | flowsToDelete := []*ofp.OfpFlowStats{ |
| 450 | {Id: 126, TableId: 1260, Priority: 100, IdleTimeout: 0, Flags: 0, Cookie: 1260000, PacketCount: 0}, |
| 451 | {Id: 127, TableId: 1270, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1270001, PacketCount: 0}, |
| 452 | {Id: 128, TableId: 1280, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1280000, PacketCount: 0}, |
| 453 | } |
| 454 | |
| 455 | expectedFlows = []*ofp.OfpFlowStats{ |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 456 | {Id: 123, TableId: 1230, Priority: 100, IdleTimeout: 0, Flags: 0, Cookie: 1230000, PacketCount: 0}, |
| 457 | {Id: 124, TableId: 1240, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1240000, PacketCount: 0}, |
| 458 | {Id: 125, TableId: 1250, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1250000, PacketCount: 0}, |
| 459 | } |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 460 | |
| 461 | err = da.deleteFlowsAndGroups(context.Background(), flowsToDelete, []*ofp.OfpGroupEntry{}, &voltha.FlowMetadata{}) |
| 462 | assert.Nil(t, err) |
| 463 | daFlows = changeToFlowList(da.listDeviceFlows()) |
| 464 | assert.True(t, isFlowSliceEqual(expectedFlows, daFlows)) |
| 465 | //Delete flows with an unexisting one |
| 466 | flowsToDelete = []*ofp.OfpFlowStats{ |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 467 | {Id: 125, TableId: 1250, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1250000, PacketCount: 0}, |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 468 | {Id: 129, TableId: 1290, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1290000, PacketCount: 0}, |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 469 | } |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 470 | |
| 471 | expectedFlows = []*ofp.OfpFlowStats{ |
| 472 | {Id: 123, TableId: 1230, Priority: 100, IdleTimeout: 0, Flags: 0, Cookie: 1230000, PacketCount: 0}, |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 473 | {Id: 124, TableId: 1240, Priority: 1000, IdleTimeout: 0, Flags: 0, Cookie: 1240000, PacketCount: 0}, |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 474 | } |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 475 | |
| 476 | err = da.deleteFlowsAndGroups(context.Background(), flowsToDelete, []*ofp.OfpGroupEntry{}, &voltha.FlowMetadata{}) |
| 477 | assert.Nil(t, err) |
| 478 | daFlows = changeToFlowList(da.listDeviceFlows()) |
| 479 | assert.True(t, isFlowSliceEqual(expectedFlows, daFlows)) |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 480 | } |
| 481 | |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 482 | func (dat *DATest) testGroupAddDeletes(t *testing.T, da *Agent) { |
| 483 | //Add new Groups on empty list |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 484 | newGroups := []*ofp.OfpGroupEntry{ |
| 485 | {Desc: &ofp.OfpGroupDesc{Type: 1, GroupId: 10, Buckets: nil}}, |
| 486 | {Desc: &ofp.OfpGroupDesc{Type: 2, GroupId: 20, Buckets: nil}}, |
| 487 | } |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 488 | err := da.addFlowsAndGroups(context.Background(), []*ofp.OfpFlowStats{}, newGroups, &voltha.FlowMetadata{}) |
| 489 | assert.Nil(t, err) |
| 490 | daGroups := changeToGroupList(da.listDeviceGroups()) |
| 491 | assert.True(t, isGroupSliceEqual(newGroups, daGroups)) |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 492 | |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 493 | //Add new Groups on existing ones |
| 494 | newGroups = []*ofp.OfpGroupEntry{ |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 495 | {Desc: &ofp.OfpGroupDesc{Type: 3, GroupId: 30, Buckets: nil}}, |
| 496 | {Desc: &ofp.OfpGroupDesc{Type: 4, GroupId: 40, Buckets: nil}}, |
| 497 | } |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 498 | expectedGroups := []*ofp.OfpGroupEntry{ |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 499 | {Desc: &ofp.OfpGroupDesc{Type: 1, GroupId: 10, Buckets: nil}}, |
| 500 | {Desc: &ofp.OfpGroupDesc{Type: 2, GroupId: 20, Buckets: nil}}, |
| 501 | {Desc: &ofp.OfpGroupDesc{Type: 3, GroupId: 30, Buckets: nil}}, |
| 502 | {Desc: &ofp.OfpGroupDesc{Type: 4, GroupId: 40, Buckets: nil}}, |
| 503 | } |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 504 | err = da.addFlowsAndGroups(context.Background(), []*ofp.OfpFlowStats{}, newGroups, &voltha.FlowMetadata{}) |
| 505 | assert.Nil(t, err) |
| 506 | daGroups = changeToGroupList(da.listDeviceGroups()) |
| 507 | assert.True(t, isGroupSliceEqual(expectedGroups, daGroups)) |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 508 | |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 509 | //Add new Groups on existing ones |
| 510 | newGroups = []*ofp.OfpGroupEntry{ |
| 511 | {Desc: &ofp.OfpGroupDesc{Type: 3, GroupId: 30, Buckets: nil}}, |
| 512 | {Desc: &ofp.OfpGroupDesc{Type: 44, GroupId: 40, Buckets: nil}}, |
| 513 | {Desc: &ofp.OfpGroupDesc{Type: 5, GroupId: 50, Buckets: nil}}, |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 514 | } |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 515 | expectedGroups = []*ofp.OfpGroupEntry{ |
| 516 | {Desc: &ofp.OfpGroupDesc{Type: 1, GroupId: 10, Buckets: nil}}, |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 517 | {Desc: &ofp.OfpGroupDesc{Type: 2, GroupId: 20, Buckets: nil}}, |
| 518 | {Desc: &ofp.OfpGroupDesc{Type: 3, GroupId: 30, Buckets: nil}}, |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 519 | {Desc: &ofp.OfpGroupDesc{Type: 44, GroupId: 40, Buckets: nil}}, |
| 520 | {Desc: &ofp.OfpGroupDesc{Type: 5, GroupId: 50, Buckets: nil}}, |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 521 | } |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 522 | err = da.addFlowsAndGroups(context.Background(), []*ofp.OfpFlowStats{}, newGroups, &voltha.FlowMetadata{}) |
| 523 | assert.Nil(t, err) |
| 524 | daGroups = changeToGroupList(da.listDeviceGroups()) |
| 525 | assert.True(t, isGroupSliceEqual(expectedGroups, daGroups)) |
| 526 | |
| 527 | //Modify Group |
| 528 | updtGroups := []*ofp.OfpGroupEntry{ |
| 529 | {Desc: &ofp.OfpGroupDesc{Type: 33, GroupId: 30, Buckets: nil}}, |
| 530 | } |
| 531 | expectedGroups = []*ofp.OfpGroupEntry{ |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 532 | {Desc: &ofp.OfpGroupDesc{Type: 1, GroupId: 10, Buckets: nil}}, |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 533 | {Desc: &ofp.OfpGroupDesc{Type: 2, GroupId: 20, Buckets: nil}}, |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 534 | {Desc: &ofp.OfpGroupDesc{Type: 33, GroupId: 30, Buckets: nil}}, |
| 535 | {Desc: &ofp.OfpGroupDesc{Type: 44, GroupId: 40, Buckets: nil}}, |
| 536 | {Desc: &ofp.OfpGroupDesc{Type: 5, GroupId: 50, Buckets: nil}}, |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 537 | } |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 538 | err = da.updateFlowsAndGroups(context.Background(), []*ofp.OfpFlowStats{}, updtGroups, &voltha.FlowMetadata{}) |
| 539 | assert.Nil(t, err) |
| 540 | daGroups = changeToGroupList(da.listDeviceGroups()) |
| 541 | assert.True(t, isGroupSliceEqual(expectedGroups, daGroups)) |
| 542 | |
| 543 | //Delete Group |
| 544 | delGroups := []*ofp.OfpGroupEntry{ |
| 545 | {Desc: &ofp.OfpGroupDesc{Type: 33, GroupId: 30, Buckets: nil}}, |
| 546 | } |
| 547 | expectedGroups = []*ofp.OfpGroupEntry{ |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 548 | {Desc: &ofp.OfpGroupDesc{Type: 1, GroupId: 10, Buckets: nil}}, |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 549 | {Desc: &ofp.OfpGroupDesc{Type: 2, GroupId: 20, Buckets: nil}}, |
| 550 | {Desc: &ofp.OfpGroupDesc{Type: 44, GroupId: 40, Buckets: nil}}, |
| 551 | {Desc: &ofp.OfpGroupDesc{Type: 5, GroupId: 50, Buckets: nil}}, |
| 552 | } |
| 553 | err = da.deleteFlowsAndGroups(context.Background(), []*ofp.OfpFlowStats{}, delGroups, &voltha.FlowMetadata{}) |
| 554 | assert.Nil(t, err) |
| 555 | daGroups = changeToGroupList(da.listDeviceGroups()) |
| 556 | assert.True(t, isGroupSliceEqual(expectedGroups, daGroups)) |
| 557 | |
| 558 | //Delete Group |
| 559 | delGroups = []*ofp.OfpGroupEntry{ |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 560 | {Desc: &ofp.OfpGroupDesc{Type: 4, GroupId: 40, Buckets: nil}}, |
| 561 | } |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 562 | expectedGroups = []*ofp.OfpGroupEntry{ |
| 563 | {Desc: &ofp.OfpGroupDesc{Type: 1, GroupId: 10, Buckets: nil}}, |
| 564 | {Desc: &ofp.OfpGroupDesc{Type: 2, GroupId: 20, Buckets: nil}}, |
| 565 | {Desc: &ofp.OfpGroupDesc{Type: 5, GroupId: 50, Buckets: nil}}, |
| 566 | } |
| 567 | err = da.deleteFlowsAndGroups(context.Background(), []*ofp.OfpFlowStats{}, delGroups, &voltha.FlowMetadata{}) |
| 568 | assert.Nil(t, err) |
| 569 | daGroups = changeToGroupList(da.listDeviceGroups()) |
| 570 | assert.True(t, isGroupSliceEqual(expectedGroups, daGroups)) |
khenaidoo | b2121e5 | 2019-12-16 17:17:22 -0500 | [diff] [blame] | 571 | } |