kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-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. |
| 15 | */ |
| 16 | |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 17 | //Package core provides the utility for olt devices, flows and statistics |
| 18 | package core |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 19 | |
| 20 | import ( |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 21 | "context" |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 22 | "encoding/hex" |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 23 | "fmt" |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 24 | "reflect" |
| 25 | "strconv" |
| 26 | "sync" |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 27 | "testing" |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 28 | "time" |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 29 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 30 | "github.com/opencord/voltha-protos/v4/go/voltha" |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 31 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 32 | "github.com/opencord/voltha-lib-go/v4/pkg/db" |
| 33 | fu "github.com/opencord/voltha-lib-go/v4/pkg/flows" |
| 34 | "github.com/opencord/voltha-lib-go/v4/pkg/log" |
| 35 | tp "github.com/opencord/voltha-lib-go/v4/pkg/techprofile" |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 36 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager" |
| 37 | rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager" |
| 38 | "github.com/opencord/voltha-openolt-adapter/pkg/mocks" |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 39 | ofp "github.com/opencord/voltha-protos/v4/go/openflow_13" |
| 40 | "github.com/opencord/voltha-protos/v4/go/openolt" |
| 41 | openoltpb2 "github.com/opencord/voltha-protos/v4/go/openolt" |
| 42 | tp_pb "github.com/opencord/voltha-protos/v4/go/tech_profile" |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 43 | ) |
| 44 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 45 | var flowMgr []*OpenOltFlowMgr |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 46 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 47 | func init() { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 48 | _, _ = log.SetDefaultLogger(log.JSON, log.DebugLevel, nil) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 49 | flowMgr = newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 50 | } |
| 51 | func newMockResourceMgr() *resourcemanager.OpenOltResourceMgr { |
| 52 | ranges := []*openolt.DeviceInfo_DeviceResourceRanges{ |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 53 | { |
| 54 | IntfIds: []uint32{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, |
| 55 | Technology: "Default", |
| 56 | }, |
| 57 | } |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 58 | |
| 59 | deviceinfo := &openolt.DeviceInfo{Vendor: "openolt", Model: "openolt", HardwareVersion: "1.0", FirmwareVersion: "1.0", |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 60 | DeviceId: "olt", DeviceSerialNumber: "openolt", PonPorts: 16, Technology: "Default", |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 61 | OnuIdStart: OnuIDStart, OnuIdEnd: OnuIDEnd, AllocIdStart: AllocIDStart, AllocIdEnd: AllocIDEnd, |
| 62 | GemportIdStart: GemIDStart, GemportIdEnd: GemIDEnd, FlowIdStart: FlowIDStart, FlowIdEnd: FlowIDEnd, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 63 | Ranges: ranges, |
| 64 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 65 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 66 | defer cancel() |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 67 | rsrMgr := resourcemanager.NewResourceMgr(ctx, "olt", "127.0.0.1:2379", "etcd", "olt", deviceinfo, "service/voltha") |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 68 | for key := range rsrMgr.ResourceMgrs { |
sbarbari | a8910ba | 2019-11-05 10:12:23 -0500 | [diff] [blame] | 69 | rsrMgr.ResourceMgrs[key].KVStore = &db.Backend{} |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 70 | rsrMgr.ResourceMgrs[key].KVStore.Client = &mocks.MockKVClient{} |
| 71 | rsrMgr.ResourceMgrs[key].TechProfileMgr = mocks.MockTechProfile{TpID: key} |
| 72 | } |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 73 | return rsrMgr |
| 74 | } |
| 75 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 76 | func newMockFlowmgr() []*OpenOltFlowMgr { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 77 | rMgr := newMockResourceMgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 78 | dh := newMockDeviceHandler() |
| 79 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 80 | rMgr.KVStore = &db.Backend{} |
| 81 | rMgr.KVStore.Client = &mocks.MockKVClient{} |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 82 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 83 | dh.resourceMgr = rMgr |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 84 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 85 | // onuGemInfo := make([]rsrcMgr.OnuGemInfo, NumPonPorts) |
| 86 | var i uint32 |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 87 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 88 | for i = 0; i < NumPonPorts; i++ { |
| 89 | packetInGemPort := make(map[rsrcMgr.PacketInInfoKey]uint32) |
| 90 | packetInGemPort[rsrcMgr.PacketInInfoKey{IntfID: i, OnuID: i + 1, LogicalPort: i + 1, VlanID: uint16(i), Priority: uint8(i)}] = i + 1 |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 91 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 92 | dh.flowMgr[i].packetInGemPort = packetInGemPort |
| 93 | tps := make(map[uint32]tp.TechProfileIf) |
| 94 | for key := range rMgr.ResourceMgrs { |
| 95 | tps[key] = mocks.MockTechProfile{TpID: key} |
| 96 | } |
| 97 | dh.flowMgr[i].techprofile = tps |
| 98 | interface2mcastQeueuMap := make(map[uint32]*QueueInfoBrief) |
| 99 | interface2mcastQeueuMap[0] = &QueueInfoBrief{ |
| 100 | gemPortID: 4000, |
| 101 | servicePriority: 3, |
| 102 | } |
| 103 | dh.flowMgr[i].grpMgr.interfaceToMcastQueueMap = interface2mcastQeueuMap |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 104 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 105 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 106 | return dh.flowMgr |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 107 | } |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 108 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 109 | func TestOpenOltFlowMgr_CreateSchedulerQueues(t *testing.T) { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 110 | tprofile := &tp.TechProfile{Name: "tp1", SubscriberIdentifier: "subscriber1", |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 111 | ProfileType: "pt1", NumGemPorts: 1, Version: 1, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 112 | InstanceCtrl: tp.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"}, |
| 113 | } |
| 114 | tprofile.UsScheduler.Direction = "UPSTREAM" |
| 115 | tprofile.UsScheduler.AdditionalBw = "AdditionalBW_None" |
| 116 | tprofile.UsScheduler.QSchedPolicy = "WRR" |
| 117 | |
| 118 | tprofile2 := tprofile |
| 119 | tprofile2.DsScheduler.Direction = "DOWNSTREAM" |
| 120 | tprofile2.DsScheduler.AdditionalBw = "AdditionalBW_None" |
| 121 | tprofile2.DsScheduler.QSchedPolicy = "WRR" |
| 122 | bands := make([]*ofp.OfpMeterBandHeader, 2) |
| 123 | bands[0] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 1000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}} |
| 124 | bands[1] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 2000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}} |
| 125 | ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands} |
| 126 | flowmetadata := &voltha.FlowMetadata{ |
| 127 | Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}, |
| 128 | } |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 129 | tests := []struct { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 130 | name string |
| 131 | schedQueue schedQueue |
| 132 | wantErr bool |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 133 | }{ |
| 134 | // TODO: Add test cases. |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 135 | {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, flowmetadata}, false}, |
| 136 | {"CreateSchedulerQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, flowmetadata}, false}, |
| 137 | {"CreateSchedulerQueues-3", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, flowmetadata}, true}, |
| 138 | {"CreateSchedulerQueues-4", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, flowmetadata}, true}, |
| 139 | {"CreateSchedulerQueues-5", schedQueue{tp_pb.Direction_UPSTREAM, 1, 2, 2, 64, 2, tprofile, 2, flowmetadata}, true}, |
| 140 | {"CreateSchedulerQueues-6", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 2, 2, 65, 2, tprofile2, 2, flowmetadata}, true}, |
| 141 | {"CreateSchedulerQueues-13", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, flowmetadata}, false}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 142 | //Negative testcases |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 143 | {"CreateSchedulerQueues-7", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, &voltha.FlowMetadata{}}, true}, |
| 144 | {"CreateSchedulerQueues-8", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 0, &voltha.FlowMetadata{}}, true}, |
| 145 | {"CreateSchedulerQueues-9", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, &voltha.FlowMetadata{}}, true}, |
| 146 | {"CreateSchedulerQueues-10", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, &voltha.FlowMetadata{}}, true}, |
| 147 | {"CreateSchedulerQueues-11", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, &voltha.FlowMetadata{}}, true}, |
| 148 | {"CreateSchedulerQueues-12", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, nil}, true}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 149 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 150 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 151 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 152 | for _, tt := range tests { |
| 153 | t.Run(tt.name, func(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 154 | if err := flowMgr[tt.schedQueue.intfID].CreateSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 155 | t.Errorf("OpenOltFlowMgr.CreateSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr) |
| 156 | } |
| 157 | }) |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | func TestOpenOltFlowMgr_RemoveSchedulerQueues(t *testing.T) { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 162 | tprofile := &tp.TechProfile{Name: "tp1", SubscriberIdentifier: "subscriber1", |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 163 | ProfileType: "pt1", NumGemPorts: 1, Version: 1, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 164 | InstanceCtrl: tp.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"}, |
| 165 | } |
| 166 | tprofile.UsScheduler.Direction = "UPSTREAM" |
| 167 | tprofile.UsScheduler.AdditionalBw = "AdditionalBW_None" |
| 168 | tprofile.UsScheduler.QSchedPolicy = "WRR" |
| 169 | |
| 170 | tprofile2 := tprofile |
| 171 | tprofile2.DsScheduler.Direction = "DOWNSTREAM" |
| 172 | tprofile2.DsScheduler.AdditionalBw = "AdditionalBW_None" |
| 173 | tprofile2.DsScheduler.QSchedPolicy = "WRR" |
| 174 | //defTprofile := &tp.DefaultTechProfile{} |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 175 | tests := []struct { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 176 | name string |
| 177 | schedQueue schedQueue |
| 178 | wantErr bool |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 179 | }{ |
| 180 | // TODO: Add test cases. |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 181 | {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 0, nil}, false}, |
| 182 | {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 183 | // negative test cases |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 184 | {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false}, |
| 185 | {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 186 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 187 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 188 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 189 | for _, tt := range tests { |
| 190 | t.Run(tt.name, func(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 191 | if err := flowMgr[tt.schedQueue.intfID].RemoveSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 192 | t.Errorf("OpenOltFlowMgr.RemoveSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr) |
| 193 | } |
| 194 | }) |
| 195 | } |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 196 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 197 | } |
| 198 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 199 | func TestOpenOltFlowMgr_createTcontGemports(t *testing.T) { |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 200 | bands := make([]*ofp.OfpMeterBandHeader, 2) |
| 201 | bands[0] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 1000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}} |
| 202 | bands[1] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 2000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}} |
| 203 | ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands} |
| 204 | flowmetadata := &voltha.FlowMetadata{ |
| 205 | Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}, |
| 206 | } |
| 207 | type args struct { |
| 208 | intfID uint32 |
| 209 | onuID uint32 |
| 210 | uniID uint32 |
| 211 | uni string |
| 212 | uniPort uint32 |
| 213 | TpID uint32 |
| 214 | UsMeterID uint32 |
| 215 | DsMeterID uint32 |
| 216 | flowMetadata *voltha.FlowMetadata |
| 217 | } |
| 218 | tests := []struct { |
| 219 | name string |
| 220 | args args |
| 221 | }{ |
| 222 | {"createTcontGemports-1", args{intfID: 0, onuID: 1, uniID: 1, uni: "16", uniPort: 1, TpID: 64, UsMeterID: 1, DsMeterID: 1, flowMetadata: flowmetadata}}, |
| 223 | {"createTcontGemports-1", args{intfID: 0, onuID: 1, uniID: 1, uni: "16", uniPort: 1, TpID: 65, UsMeterID: 1, DsMeterID: 1, flowMetadata: flowmetadata}}, |
| 224 | } |
| 225 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 226 | defer cancel() |
| 227 | for _, tt := range tests { |
| 228 | t.Run(tt.name, func(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 229 | _, _, tpInst := flowMgr[tt.args.intfID].createTcontGemports(ctx, tt.args.intfID, tt.args.onuID, tt.args.uniID, tt.args.uni, tt.args.uniPort, tt.args.TpID, tt.args.UsMeterID, tt.args.DsMeterID, tt.args.flowMetadata) |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 230 | switch tpInst := tpInst.(type) { |
| 231 | case *tp.TechProfile: |
| 232 | if tt.args.TpID != 64 { |
| 233 | t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst) |
| 234 | } |
| 235 | case *tp.EponProfile: |
| 236 | if tt.args.TpID != 65 { |
| 237 | t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst) |
| 238 | } |
| 239 | default: |
| 240 | t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst) |
| 241 | } |
| 242 | }) |
| 243 | } |
| 244 | } |
| 245 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 246 | func TestOpenOltFlowMgr_RemoveFlow(t *testing.T) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 247 | ctx := context.Background() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 248 | logger.Debug(ctx, "Info Warning Error: Starting RemoveFlow() test") |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 249 | fa := &fu.FlowArgs{ |
| 250 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 251 | fu.InPort(2), |
| 252 | fu.Metadata_ofp(2), |
| 253 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 254 | }, |
| 255 | Actions: []*ofp.OfpAction{ |
| 256 | fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 257 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 258 | fu.Output(1), |
| 259 | }, |
| 260 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 261 | ofpstats, _ := fu.MkFlowStat(fa) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 262 | ofpstats.Cookie = ofpstats.Id |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 263 | lldpFa := &fu.FlowArgs{ |
| 264 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 265 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 266 | fu.InPort(1), |
| 267 | fu.EthType(0x88CC), |
| 268 | fu.TunnelId(536870912), |
| 269 | }, |
| 270 | Actions: []*ofp.OfpAction{ |
| 271 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 272 | }, |
| 273 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 274 | lldpofpstats, _ := fu.MkFlowStat(lldpFa) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 275 | //lldpofpstats.Cookie = lldpofpstats.Id |
| 276 | |
| 277 | dhcpFa := &fu.FlowArgs{ |
| 278 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 279 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 280 | fu.InPort(1), |
| 281 | fu.UdpSrc(67), |
| 282 | //fu.TunnelId(536870912), |
| 283 | fu.IpProto(17), |
| 284 | }, |
| 285 | Actions: []*ofp.OfpAction{ |
| 286 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 287 | }, |
| 288 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 289 | dhcpofpstats, _ := fu.MkFlowStat(dhcpFa) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 290 | //dhcpofpstats.Cookie = dhcpofpstats.Id |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 291 | |
| 292 | //multicast flow |
| 293 | multicastFa := &fu.FlowArgs{ |
| 294 | MatchFields: []*ofp.OfpOxmOfbField{ |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 295 | fu.InPort(1048576), |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 296 | fu.VlanVid(660), //vlan |
| 297 | fu.Metadata_ofp(uint64(66)), //inner vlan |
| 298 | fu.EthType(0x800), //ipv4 |
| 299 | fu.Ipv4Dst(3809869825), //227.22.0.1 |
| 300 | }, |
| 301 | Actions: []*ofp.OfpAction{ |
| 302 | fu.Group(1), |
| 303 | }, |
| 304 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 305 | multicastOfpStats, _ := fu.MkFlowStat(multicastFa) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 306 | multicastOfpStats.Id = 1 |
| 307 | |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 308 | pppoedFa := &fu.FlowArgs{ |
| 309 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 310 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 311 | fu.InPort(1), |
| 312 | fu.EthType(0x8863), |
| 313 | fu.TunnelId(536870912), |
| 314 | }, |
| 315 | Actions: []*ofp.OfpAction{ |
| 316 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 317 | }, |
| 318 | } |
| 319 | pppoedOfpStats, _ := fu.MkFlowStat(pppoedFa) |
| 320 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 321 | type args struct { |
| 322 | flow *ofp.OfpFlowStats |
| 323 | } |
| 324 | tests := []struct { |
| 325 | name string |
| 326 | args args |
| 327 | }{ |
| 328 | // TODO: Add test cases. |
| 329 | {"RemoveFlow", args{flow: ofpstats}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 330 | {"RemoveFlow", args{flow: lldpofpstats}}, |
| 331 | {"RemoveFlow", args{flow: dhcpofpstats}}, |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 332 | {"RemoveFlow", args{flow: multicastOfpStats}}, |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 333 | {"RemoveFlow", args{flow: pppoedOfpStats}}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 334 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 335 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 336 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 337 | for _, tt := range tests { |
| 338 | t.Run(tt.name, func(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 339 | if err := flowMgr[0].RemoveFlow(ctx, tt.args.flow); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 340 | logger.Warn(ctx, err) |
| 341 | } |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 342 | }) |
| 343 | } |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 344 | // t.Error("=====") |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | func TestOpenOltFlowMgr_AddFlow(t *testing.T) { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 348 | kw := make(map[string]uint64) |
| 349 | kw["table_id"] = 1 |
| 350 | kw["meter_id"] = 1 |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 351 | kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64 |
| 352 | |
| 353 | // Upstream flow |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 354 | fa := &fu.FlowArgs{ |
| 355 | MatchFields: []*ofp.OfpOxmOfbField{ |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 356 | fu.InPort(536870912), |
| 357 | fu.Metadata_ofp(1), |
| 358 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 359 | }, |
| 360 | Actions: []*ofp.OfpAction{ |
| 361 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 362 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 363 | fu.Output(1048576), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 364 | fu.PushVlan(0x8100), |
| 365 | }, |
| 366 | KV: kw, |
| 367 | } |
| 368 | |
| 369 | // Downstream flow |
| 370 | fa3 := &fu.FlowArgs{ |
| 371 | MatchFields: []*ofp.OfpOxmOfbField{ |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 372 | fu.InPort(1048576), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 373 | fu.Metadata_ofp(1), |
| 374 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257), |
| 375 | }, |
| 376 | Actions: []*ofp.OfpAction{ |
| 377 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 378 | //fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 379 | fu.PopVlan(), |
| 380 | fu.Output(536870912), |
| 381 | }, |
| 382 | KV: kw, |
| 383 | } |
| 384 | |
| 385 | fa2 := &fu.FlowArgs{ |
| 386 | MatchFields: []*ofp.OfpOxmOfbField{ |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 387 | fu.InPort(1000), |
| 388 | fu.Metadata_ofp(1), |
| 389 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 390 | }, |
| 391 | Actions: []*ofp.OfpAction{ |
| 392 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 393 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 394 | fu.Output(65533), |
| 395 | }, |
| 396 | KV: kw, |
| 397 | } |
| 398 | |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 399 | // TODO Add LLDP flow |
| 400 | // TODO Add DHCP flow |
| 401 | |
| 402 | // Flows for negative scenarios |
| 403 | // Failure in formulateActionInfoFromFlow() |
| 404 | fa4 := &fu.FlowArgs{ |
| 405 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 406 | fu.InPort(1000), |
| 407 | fu.Metadata_ofp(1), |
| 408 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 409 | }, |
| 410 | Actions: []*ofp.OfpAction{ |
| 411 | fu.Experimenter(257, []byte{1, 2, 3, 4}), |
| 412 | }, |
| 413 | KV: kw, |
| 414 | } |
| 415 | |
| 416 | // Invalid Output |
| 417 | fa5 := &fu.FlowArgs{ |
| 418 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 419 | fu.InPort(1000), |
| 420 | fu.Metadata_ofp(1), |
| 421 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 422 | }, |
| 423 | Actions: []*ofp.OfpAction{ |
| 424 | fu.Output(0), |
| 425 | }, |
| 426 | KV: kw, |
| 427 | } |
| 428 | |
| 429 | // Tech-Profile-ID update (not supported) |
| 430 | kw6 := make(map[string]uint64) |
| 431 | kw6["table_id"] = 1 |
| 432 | kw6["meter_id"] = 1 |
| 433 | kw6["write_metadata"] = 0x4100000000 // TpID Other than the stored one |
| 434 | fa6 := &fu.FlowArgs{ |
| 435 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 436 | fu.InPort(536870912), |
| 437 | fu.TunnelId(16), |
| 438 | fu.Metadata_ofp(1), |
| 439 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 440 | }, |
| 441 | Actions: []*ofp.OfpAction{ |
| 442 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 443 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 444 | fu.Output(65535), |
| 445 | }, |
| 446 | KV: kw6, |
| 447 | } |
| 448 | |
| 449 | lldpFa := &fu.FlowArgs{ |
| 450 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 451 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 452 | fu.InPort(1), |
| 453 | fu.EthType(0x88CC), |
| 454 | fu.TunnelId(536870912), |
| 455 | }, |
| 456 | Actions: []*ofp.OfpAction{ |
| 457 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 458 | }, |
| 459 | } |
| 460 | |
| 461 | dhcpFa := &fu.FlowArgs{ |
| 462 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 463 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 464 | fu.InPort(1), |
| 465 | fu.UdpSrc(67), |
| 466 | //fu.TunnelId(536870912), |
| 467 | fu.IpProto(17), |
| 468 | }, |
| 469 | Actions: []*ofp.OfpAction{ |
| 470 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 471 | }, |
| 472 | } |
| 473 | igmpFa := &fu.FlowArgs{ |
| 474 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 475 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 476 | fu.InPort(1), |
| 477 | fu.UdpSrc(67), |
| 478 | //fu.TunnelId(536870912), |
| 479 | fu.IpProto(2), |
| 480 | }, |
| 481 | Actions: []*ofp.OfpAction{ |
| 482 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 483 | }, |
| 484 | } |
| 485 | |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 486 | pppoedFa := &fu.FlowArgs{ |
| 487 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 488 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 489 | fu.InPort(1), |
| 490 | fu.EthType(0x8863), |
| 491 | fu.TunnelId(536870912), |
| 492 | }, |
| 493 | Actions: []*ofp.OfpAction{ |
| 494 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 495 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 496 | }, |
| 497 | } |
| 498 | |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 499 | fa9 := &fu.FlowArgs{ |
| 500 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 501 | fu.InPort(536870912), |
| 502 | fu.TunnelId(16), |
| 503 | fu.Metadata_ofp(1), |
| 504 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 505 | fu.VlanPcp(1000), |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 506 | fu.UdpDst(1048576), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 507 | fu.UdpSrc(536870912), |
| 508 | fu.Ipv4Dst(65535), |
| 509 | fu.Ipv4Src(536870912), |
| 510 | }, |
| 511 | Actions: []*ofp.OfpAction{ |
| 512 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 513 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 514 | fu.Output(65535), |
| 515 | }, |
| 516 | KV: kw6, |
| 517 | } |
| 518 | |
| 519 | fa10 := &fu.FlowArgs{ |
| 520 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 521 | fu.InPort(65533), |
| 522 | // fu.TunnelId(16), |
| 523 | fu.Metadata_ofp(1), |
| 524 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 525 | fu.VlanPcp(1000), |
| 526 | fu.UdpDst(65535), |
| 527 | fu.UdpSrc(536870912), |
| 528 | fu.Ipv4Dst(65535), |
| 529 | fu.Ipv4Src(536870912), |
| 530 | }, |
| 531 | Actions: []*ofp.OfpAction{ |
| 532 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 533 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 534 | fu.Output(65535), |
| 535 | }, |
| 536 | KV: kw6, |
| 537 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 538 | //multicast flow |
| 539 | fa11 := &fu.FlowArgs{ |
| 540 | MatchFields: []*ofp.OfpOxmOfbField{ |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 541 | fu.InPort(1048576), |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 542 | fu.VlanVid(660), //vlan |
| 543 | fu.Metadata_ofp(uint64(66)), //inner vlan |
| 544 | fu.EthType(0x800), //ipv4 |
| 545 | fu.Ipv4Dst(3809869825), //227.22.0.1 |
| 546 | }, |
| 547 | Actions: []*ofp.OfpAction{ |
| 548 | fu.Group(1), |
| 549 | }, |
| 550 | KV: kw6, |
| 551 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 552 | ofpstats, _ := fu.MkFlowStat(fa) |
| 553 | ofpstats2, _ := fu.MkFlowStat(fa2) |
| 554 | ofpstats3, _ := fu.MkFlowStat(fa3) |
| 555 | ofpstats4, _ := fu.MkFlowStat(fa4) |
| 556 | ofpstats5, _ := fu.MkFlowStat(fa5) |
| 557 | ofpstats6, _ := fu.MkFlowStat(fa6) |
| 558 | ofpstats7, _ := fu.MkFlowStat(lldpFa) |
| 559 | ofpstats8, _ := fu.MkFlowStat(dhcpFa) |
| 560 | ofpstats9, _ := fu.MkFlowStat(fa9) |
| 561 | ofpstats10, _ := fu.MkFlowStat(fa10) |
| 562 | igmpstats, _ := fu.MkFlowStat(igmpFa) |
| 563 | ofpstats11, _ := fu.MkFlowStat(fa11) |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 564 | pppoedstats, _ := fu.MkFlowStat(pppoedFa) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 565 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 566 | fmt.Println(ofpstats6, ofpstats9, ofpstats10) |
| 567 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 568 | ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1} |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 569 | flowMetadata := &voltha.FlowMetadata{ |
| 570 | Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}, |
| 571 | } |
| 572 | type args struct { |
| 573 | flow *ofp.OfpFlowStats |
| 574 | flowMetadata *voltha.FlowMetadata |
| 575 | } |
| 576 | tests := []struct { |
| 577 | name string |
| 578 | args args |
| 579 | }{ |
| 580 | // TODO: Add test cases. |
| 581 | {"AddFlow", args{flow: ofpstats, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 582 | {"AddFlow", args{flow: ofpstats2, flowMetadata: flowMetadata}}, |
| 583 | {"AddFlow", args{flow: ofpstats3, flowMetadata: flowMetadata}}, |
| 584 | {"AddFlow", args{flow: ofpstats4, flowMetadata: flowMetadata}}, |
| 585 | {"AddFlow", args{flow: ofpstats5, flowMetadata: flowMetadata}}, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 586 | //{"AddFlow", args{flow: ofpstats6, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 587 | {"AddFlow", args{flow: ofpstats7, flowMetadata: flowMetadata}}, |
| 588 | {"AddFlow", args{flow: ofpstats8, flowMetadata: flowMetadata}}, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 589 | //{"AddFlow", args{flow: ofpstats9, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 590 | {"AddFlow", args{flow: igmpstats, flowMetadata: flowMetadata}}, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 591 | //{"AddFlow", args{flow: ofpstats10, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 592 | //ofpstats10 |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 593 | {"AddFlow", args{flow: ofpstats11, flowMetadata: flowMetadata}}, |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 594 | {"AddFlow", args{flow: pppoedstats, flowMetadata: flowMetadata}}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 595 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 596 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 597 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 598 | for _, tt := range tests { |
| 599 | t.Run(tt.name, func(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 600 | _ = flowMgr[0].AddFlow(ctx, tt.args.flow, tt.args.flowMetadata) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 601 | // TODO: actually verify test cases |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 602 | }) |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | func TestOpenOltFlowMgr_UpdateOnuInfo(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 607 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 608 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 609 | |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 610 | wg := sync.WaitGroup{} |
| 611 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 612 | intfCount := NumPonPorts |
| 613 | onuCount := OnuIDEnd - OnuIDStart + 1 |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 614 | |
| 615 | for i := 0; i < intfCount; i++ { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 616 | for j := 1; j <= onuCount; j++ { |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 617 | wg.Add(1) |
| 618 | go func(i uint32, j uint32) { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 619 | // TODO: actually verify success |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 620 | _ = flowMgr[i].UpdateOnuInfo(ctx, i, i, fmt.Sprintf("onu-%d", i)) |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 621 | wg.Done() |
| 622 | }(uint32(i), uint32(j)) |
| 623 | } |
| 624 | |
| 625 | } |
| 626 | |
| 627 | wg.Wait() |
| 628 | } |
| 629 | |
| 630 | func TestOpenOltFlowMgr_addGemPortToOnuInfoMap(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 631 | intfNum := NumPonPorts |
| 632 | onuNum := OnuIDEnd - OnuIDStart + 1 |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 633 | |
| 634 | // clean the flowMgr |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 635 | for i := 0; i < intfNum; i++ { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 636 | flowMgr[i].onuGemInfo = make([]rsrcMgr.OnuGemInfo, 0) |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 637 | } |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 638 | |
| 639 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 640 | defer cancel() |
| 641 | |
| 642 | // Create OnuInfo |
| 643 | for i := 0; i < intfNum; i++ { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 644 | for o := 1; o <= onuNum; o++ { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 645 | // TODO: actually verify success |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 646 | _ = flowMgr[i].UpdateOnuInfo(ctx, uint32(i), uint32(o), fmt.Sprintf("i%do%d", i, o-1)) |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 647 | } |
| 648 | } |
| 649 | |
| 650 | // Add gemPorts to OnuInfo in parallel threads |
| 651 | wg := sync.WaitGroup{} |
| 652 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 653 | for o := 1; o <= onuNum; o++ { |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 654 | for i := 0; i < intfNum; i++ { |
| 655 | wg.Add(1) |
| 656 | go func(intfId uint32, onuId uint32) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 657 | gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", intfId, onuId-1)) |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 658 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 659 | flowMgr[intfId].addGemPortToOnuInfoMap(ctx, intfId, onuId, uint32(gemID)) |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 660 | wg.Done() |
| 661 | }(uint32(i), uint32(o)) |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | wg.Wait() |
| 666 | |
| 667 | // check that each entry of onuGemInfo has the correct number of ONUs |
| 668 | for i := 0; i < intfNum; i++ { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 669 | lenofOnu := len(flowMgr[i].onuGemInfo) |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 670 | if onuNum != lenofOnu { |
| 671 | t.Errorf("OnuGemInfo length is not as expected len = %d, want %d", lenofOnu, onuNum) |
| 672 | } |
| 673 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 674 | for o := 1; o <= onuNum; o++ { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 675 | lenOfGemPorts := len(flowMgr[i].onuGemInfo[o-1].GemPorts) |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 676 | // check that each onuEntry has 1 gemPort |
| 677 | if lenOfGemPorts != 1 { |
| 678 | t.Errorf("Expected 1 GemPort per ONU, found %d", lenOfGemPorts) |
| 679 | } |
| 680 | |
| 681 | // check that the value of the gemport is correct |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 682 | gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", i, o-1)) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 683 | currentValue := flowMgr[i].onuGemInfo[o-1].GemPorts[0] |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 684 | if uint32(gemID) != currentValue { |
| 685 | t.Errorf("Expected GemPort value to be %d, found %d", gemID, currentValue) |
| 686 | } |
| 687 | } |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 691 | func TestOpenOltFlowMgr_deleteGemPortFromLocalCache(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 692 | // Create fresh flowMgr instance |
| 693 | flowMgr = newMockFlowmgr() |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 694 | type args struct { |
| 695 | intfID uint32 |
| 696 | onuID uint32 |
| 697 | gemPortIDs []uint32 |
| 698 | gemPortIDsToBeDeleted []uint32 |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 699 | gemPortIDsRemaining []uint32 |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 700 | serialNum string |
| 701 | finalLength int |
| 702 | } |
| 703 | tests := []struct { |
| 704 | name string |
| 705 | args args |
| 706 | }{ |
| 707 | // Add/Delete single gem port |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 708 | {"DeleteGemPortFromLocalCache1", args{0, 1, []uint32{1}, []uint32{1}, []uint32{}, "onu1", 0}}, |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 709 | // Delete all gemports |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 710 | {"DeleteGemPortFromLocalCache2", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{1, 2, 3, 4}, []uint32{}, "onu1", 0}}, |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 711 | // Try to delete when there is no gem port |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 712 | {"DeleteGemPortFromLocalCache3", args{0, 1, []uint32{}, []uint32{1, 2}, []uint32{}, "onu1", 0}}, |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 713 | // Try to delete non-existent gem port |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 714 | {"DeleteGemPortFromLocalCache4", args{0, 1, []uint32{1}, []uint32{2}, []uint32{1}, "onu1", 1}}, |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 715 | // Try to delete two of the gem ports |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 716 | {"DeleteGemPortFromLocalCache5", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{2, 4}, []uint32{1, 3}, "onu1", 2}}, |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 717 | } |
| 718 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 719 | defer cancel() |
| 720 | for _, tt := range tests { |
| 721 | t.Run(tt.name, func(t *testing.T) { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 722 | // TODO: should check returned errors are as expected? |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 723 | _ = flowMgr[tt.args.intfID].UpdateOnuInfo(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum) |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 724 | for _, gemPort := range tt.args.gemPortIDs { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 725 | flowMgr[tt.args.intfID].addGemPortToOnuInfoMap(ctx, tt.args.intfID, tt.args.onuID, gemPort) |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 726 | } |
| 727 | for _, gemPortDeleted := range tt.args.gemPortIDsToBeDeleted { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 728 | flowMgr[tt.args.intfID].deleteGemPortFromLocalCache(ctx, tt.args.intfID, tt.args.onuID, gemPortDeleted) |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 729 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 730 | lenofGemPorts := len(flowMgr[tt.args.intfID].onuGemInfo[0].GemPorts) |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 731 | if lenofGemPorts != tt.args.finalLength { |
| 732 | t.Errorf("GemPorts length is not as expected len = %d, want %d", lenofGemPorts, tt.args.finalLength) |
| 733 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 734 | gemPorts := flowMgr[tt.args.intfID].onuGemInfo[0].GemPorts |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 735 | if !reflect.DeepEqual(tt.args.gemPortIDsRemaining, gemPorts) { |
| 736 | t.Errorf("GemPorts are not as expected = %v, want %v", gemPorts, tt.args.gemPortIDsRemaining) |
| 737 | } |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 738 | |
| 739 | }) |
| 740 | } |
| 741 | } |
| 742 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 743 | func TestOpenOltFlowMgr_GetLogicalPortFromPacketIn(t *testing.T) { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 744 | type args struct { |
| 745 | packetIn *openoltpb2.PacketIndication |
| 746 | } |
| 747 | tests := []struct { |
| 748 | name string |
| 749 | args args |
| 750 | want uint32 |
| 751 | wantErr bool |
| 752 | }{ |
| 753 | // TODO: Add test cases. |
Esin Karaman | df392e1 | 2020-12-16 13:33:09 +0000 | [diff] [blame] | 754 | {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 0, GemportId: 255, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 1, false}, |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 755 | {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "nni", IntfId: 0, GemportId: 1, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 1048576, false}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 756 | // Negative Test cases. |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 757 | {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 1, GemportId: 1, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 0, true}, |
Esin Karaman | df392e1 | 2020-12-16 13:33:09 +0000 | [diff] [blame] | 758 | {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 0, GemportId: 257, FlowId: 100, PortNo: 0, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 16, false}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 759 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 760 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 761 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 762 | for _, tt := range tests { |
| 763 | t.Run(tt.name, func(t *testing.T) { |
| 764 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 765 | got, err := flowMgr[tt.args.packetIn.IntfId].GetLogicalPortFromPacketIn(ctx, tt.args.packetIn) |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 766 | if (err != nil) != tt.wantErr { |
| 767 | t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() error = %v, wantErr %v", err, tt.wantErr) |
| 768 | return |
| 769 | } |
| 770 | if got != tt.want { |
| 771 | t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() = %v, want %v", got, tt.want) |
| 772 | } |
| 773 | }) |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | func TestOpenOltFlowMgr_GetPacketOutGemPortID(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 778 | // Create fresh flowMgr instance |
| 779 | flowMgr = newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 780 | |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 781 | //untagged packet in hex string |
| 782 | untaggedStr := "01005e000002000000000001080046c00020000040000102fa140a000001e00000029404000017000705e10000fa" |
| 783 | untagged, err := hex.DecodeString(untaggedStr) |
| 784 | if err != nil { |
| 785 | t.Error("Unable to parse hex string", err) |
| 786 | panic(err) |
| 787 | } |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 788 | //single-tagged packet in hex string. vlanID.pbit: 1.1 |
| 789 | singleTaggedStr := "01005e0000010025ba48172481002001080046c0002000004000010257deab140023e0000001940400001164ee9b0000000000000000000000000000" |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 790 | singleTagged, err := hex.DecodeString(singleTaggedStr) |
| 791 | if err != nil { |
| 792 | t.Error("Unable to parse hex string", err) |
| 793 | panic(err) |
| 794 | } |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 795 | //double-tagged packet in hex string. vlanID.pbit: 210.0-0.0 |
| 796 | doubleTaggedStr := "01005e000016deadbeefba118100021081000000080046000028000000000102c5b87f000001e0000016940400002200f8030000000104000000e10000fa" |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 797 | doubleTagged, err := hex.DecodeString(doubleTaggedStr) |
| 798 | if err != nil { |
| 799 | t.Error("Unable to parse hex string", err) |
| 800 | panic(err) |
| 801 | } |
| 802 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 803 | type args struct { |
| 804 | intfID uint32 |
| 805 | onuID uint32 |
| 806 | portNum uint32 |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 807 | packet []byte |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 808 | } |
| 809 | tests := []struct { |
| 810 | name string |
| 811 | args args |
| 812 | want uint32 |
| 813 | wantErr bool |
| 814 | }{ |
| 815 | // TODO: Add test cases. |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 816 | {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: untagged}, 1, false}, |
| 817 | {"GetPacketOutGemPortID", args{intfID: 1, onuID: 2, portNum: 2, packet: singleTagged}, 2, false}, |
| 818 | {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: doubleTagged}, 1, false}, |
| 819 | {"GetPacketOutGemPortID", args{intfID: 0, onuID: 10, portNum: 10, packet: untagged}, 2, true}, |
| 820 | {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 3, packet: []byte{}}, 3, true}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 821 | } |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 822 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 823 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 824 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 825 | for _, tt := range tests { |
| 826 | t.Run(tt.name, func(t *testing.T) { |
| 827 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 828 | got, err := flowMgr[tt.args.intfID].GetPacketOutGemPortID(ctx, tt.args.intfID, tt.args.onuID, tt.args.portNum, tt.args.packet) |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 829 | if tt.wantErr { |
| 830 | if err == nil { |
| 831 | //error expected but got value |
| 832 | t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, wantErr %v", got, tt.wantErr) |
| 833 | } |
| 834 | } else { |
| 835 | if err != nil { |
| 836 | //error is not expected but got error |
| 837 | t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() error = %v, wantErr %v", err, tt.wantErr) |
| 838 | return |
| 839 | } |
| 840 | if got != tt.want { |
| 841 | t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, want %v", got, tt.want) |
| 842 | } |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 843 | } |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 844 | }) |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | func TestOpenOltFlowMgr_DeleteTechProfileInstance(t *testing.T) { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 849 | type args struct { |
| 850 | intfID uint32 |
| 851 | onuID uint32 |
| 852 | uniID uint32 |
| 853 | sn string |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 854 | tpID uint32 |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 855 | } |
| 856 | tests := []struct { |
| 857 | name string |
| 858 | args args |
| 859 | wantErr bool |
| 860 | }{ |
| 861 | // TODO: Add test cases. |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 862 | {"DeleteTechProfileInstance", args{intfID: 0, onuID: 1, uniID: 1, sn: "", tpID: 64}, false}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 863 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 864 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 865 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 866 | for _, tt := range tests { |
| 867 | t.Run(tt.name, func(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 868 | if err := flowMgr[tt.args.intfID].DeleteTechProfileInstance(ctx, tt.args.intfID, tt.args.onuID, tt.args.uniID, tt.args.sn, tt.args.tpID); (err != nil) != tt.wantErr { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 869 | t.Errorf("OpenOltFlowMgr.DeleteTechProfileInstance() error = %v, wantErr %v", err, tt.wantErr) |
| 870 | } |
| 871 | }) |
| 872 | } |
| 873 | } |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 874 | |
| 875 | func TestOpenOltFlowMgr_checkAndAddFlow(t *testing.T) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 876 | ctx := context.Background() |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 877 | kw := make(map[string]uint64) |
| 878 | kw["table_id"] = 1 |
| 879 | kw["meter_id"] = 1 |
| 880 | kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64 |
| 881 | |
| 882 | // Upstream flow |
| 883 | fa := &fu.FlowArgs{ |
| 884 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 885 | fu.InPort(536870912), |
| 886 | fu.Metadata_ofp(1), |
| 887 | fu.IpProto(17), // dhcp |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 888 | fu.VlanPcp(0), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 889 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 890 | }, |
| 891 | Actions: []*ofp.OfpAction{ |
| 892 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 893 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 894 | fu.Output(1048576), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 895 | fu.PushVlan(0x8100), |
| 896 | }, |
| 897 | KV: kw, |
| 898 | } |
| 899 | |
| 900 | // EAPOL |
| 901 | fa2 := &fu.FlowArgs{ |
| 902 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 903 | fu.InPort(536870912), |
| 904 | fu.Metadata_ofp(1), |
| 905 | fu.EthType(0x888E), |
| 906 | fu.VlanPcp(1), |
| 907 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257), |
| 908 | }, |
| 909 | Actions: []*ofp.OfpAction{ |
| 910 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 911 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 912 | fu.Output(1048576), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 913 | fu.PushVlan(0x8100), |
| 914 | }, |
| 915 | KV: kw, |
| 916 | } |
| 917 | |
| 918 | // HSIA |
| 919 | fa3 := &fu.FlowArgs{ |
| 920 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 921 | fu.InPort(536870912), |
| 922 | fu.Metadata_ofp(1), |
| 923 | //fu.EthType(0x8100), |
| 924 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 925 | }, |
| 926 | Actions: []*ofp.OfpAction{ |
| 927 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 928 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)), |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 929 | fu.Output(1048576), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 930 | fu.PushVlan(0x8100), |
| 931 | }, |
| 932 | KV: kw, |
| 933 | } |
| 934 | |
| 935 | fa4 := &fu.FlowArgs{ |
| 936 | MatchFields: []*ofp.OfpOxmOfbField{ |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 937 | fu.InPort(1048576), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 938 | fu.Metadata_ofp(1), |
| 939 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 940 | fu.VlanPcp(1), |
| 941 | }, |
| 942 | Actions: []*ofp.OfpAction{ |
| 943 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 944 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)), |
| 945 | fu.Output(536870912), |
| 946 | fu.PopVlan(), |
| 947 | }, |
| 948 | KV: kw, |
| 949 | } |
| 950 | |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 951 | // PPPOED |
| 952 | pppoedFA := &fu.FlowArgs{ |
| 953 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 954 | fu.InPort(536870912), |
| 955 | fu.Metadata_ofp(1), |
| 956 | fu.EthType(0x8863), |
| 957 | fu.VlanPcp(1), |
| 958 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257), |
| 959 | }, |
| 960 | Actions: []*ofp.OfpAction{ |
| 961 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 962 | fu.Output(1048576), |
| 963 | fu.PushVlan(0x8100), |
| 964 | }, |
| 965 | KV: kw, |
| 966 | } |
| 967 | |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 968 | classifierInfo := make(map[string]interface{}) |
| 969 | actionInfo := make(map[string]interface{}) |
| 970 | classifierInfo2 := make(map[string]interface{}) |
| 971 | actionInfo2 := make(map[string]interface{}) |
| 972 | classifierInfo3 := make(map[string]interface{}) |
| 973 | actionInfo3 := make(map[string]interface{}) |
| 974 | classifierInfo4 := make(map[string]interface{}) |
| 975 | actionInfo4 := make(map[string]interface{}) |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 976 | classifierInfo5 := make(map[string]interface{}) |
| 977 | actionInfo5 := make(map[string]interface{}) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 978 | flow, _ := fu.MkFlowStat(fa) |
| 979 | flow2, _ := fu.MkFlowStat(fa2) |
| 980 | flow3, _ := fu.MkFlowStat(fa3) |
| 981 | flow4, _ := fu.MkFlowStat(fa4) |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 982 | flow5, _ := fu.MkFlowStat(pppoedFA) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 983 | formulateClassifierInfoFromFlow(ctx, classifierInfo, flow) |
| 984 | formulateClassifierInfoFromFlow(ctx, classifierInfo2, flow2) |
| 985 | formulateClassifierInfoFromFlow(ctx, classifierInfo3, flow3) |
| 986 | formulateClassifierInfoFromFlow(ctx, classifierInfo4, flow4) |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 987 | formulateClassifierInfoFromFlow(ctx, classifierInfo5, flow5) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 988 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 989 | err := formulateActionInfoFromFlow(ctx, actionInfo, classifierInfo, flow) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 990 | if err != nil { |
| 991 | // Error logging is already done in the called function |
| 992 | // So just return in case of error |
| 993 | return |
| 994 | } |
| 995 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 996 | err = formulateActionInfoFromFlow(ctx, actionInfo2, classifierInfo2, flow2) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 997 | if err != nil { |
| 998 | // Error logging is already done in the called function |
| 999 | // So just return in case of error |
| 1000 | return |
| 1001 | } |
| 1002 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1003 | err = formulateActionInfoFromFlow(ctx, actionInfo3, classifierInfo3, flow3) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1004 | if err != nil { |
| 1005 | // Error logging is already done in the called function |
| 1006 | // So just return in case of error |
| 1007 | return |
| 1008 | } |
| 1009 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1010 | err = formulateActionInfoFromFlow(ctx, actionInfo4, classifierInfo4, flow4) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1011 | if err != nil { |
| 1012 | // Error logging is already done in the called function |
| 1013 | // So just return in case of error |
| 1014 | return |
| 1015 | } |
| 1016 | |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1017 | err = formulateActionInfoFromFlow(ctx, actionInfo5, classifierInfo5, flow5) |
| 1018 | if err != nil { |
| 1019 | // Error logging is already done in the called function |
| 1020 | // So just return in case of error |
| 1021 | return |
| 1022 | } |
| 1023 | |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1024 | TpInst := &tp.TechProfile{ |
| 1025 | Name: "Test-Tech-Profile", |
| 1026 | SubscriberIdentifier: "257", |
| 1027 | ProfileType: "Mock", |
| 1028 | Version: 1, |
| 1029 | NumGemPorts: 4, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1030 | InstanceCtrl: tp.InstanceControl{ |
| 1031 | Onu: "1", |
| 1032 | Uni: "16", |
| 1033 | }, |
| 1034 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1035 | TpInst.UsScheduler.Priority = 1 |
| 1036 | TpInst.UsScheduler.Direction = "upstream" |
| 1037 | TpInst.UsScheduler.AllocID = 1 |
| 1038 | TpInst.UsScheduler.AdditionalBw = "None" |
| 1039 | TpInst.UsScheduler.QSchedPolicy = "PQ" |
| 1040 | TpInst.UsScheduler.Weight = 4 |
| 1041 | |
| 1042 | TpInst.DsScheduler.Priority = 1 |
| 1043 | TpInst.DsScheduler.Direction = "upstream" |
| 1044 | TpInst.DsScheduler.AllocID = 1 |
| 1045 | TpInst.DsScheduler.AdditionalBw = "None" |
| 1046 | TpInst.DsScheduler.QSchedPolicy = "PQ" |
| 1047 | TpInst.DsScheduler.Weight = 4 |
| 1048 | |
| 1049 | TpInst.UpstreamGemPortAttributeList = make([]tp.IGemPortAttribute, 4) |
| 1050 | TpInst.UpstreamGemPortAttributeList[0].GemportID = 1 |
| 1051 | TpInst.UpstreamGemPortAttributeList[0].PbitMap = "0b00000011" |
| 1052 | TpInst.UpstreamGemPortAttributeList[0].GemportID = 2 |
| 1053 | TpInst.UpstreamGemPortAttributeList[0].PbitMap = "0b00001100" |
| 1054 | TpInst.UpstreamGemPortAttributeList[0].GemportID = 3 |
| 1055 | TpInst.UpstreamGemPortAttributeList[0].PbitMap = "0b00110000" |
| 1056 | TpInst.UpstreamGemPortAttributeList[0].GemportID = 4 |
| 1057 | TpInst.UpstreamGemPortAttributeList[0].PbitMap = "0b11000000" |
| 1058 | |
| 1059 | TpInst.DownstreamGemPortAttributeList = make([]tp.IGemPortAttribute, 4) |
| 1060 | TpInst.DownstreamGemPortAttributeList[0].GemportID = 1 |
| 1061 | TpInst.DownstreamGemPortAttributeList[0].PbitMap = "0b00000011" |
| 1062 | TpInst.DownstreamGemPortAttributeList[0].GemportID = 2 |
| 1063 | TpInst.DownstreamGemPortAttributeList[0].PbitMap = "0b00001100" |
| 1064 | TpInst.DownstreamGemPortAttributeList[0].GemportID = 3 |
| 1065 | TpInst.DownstreamGemPortAttributeList[0].PbitMap = "0b00110000" |
| 1066 | TpInst.DownstreamGemPortAttributeList[0].GemportID = 4 |
| 1067 | TpInst.DownstreamGemPortAttributeList[0].PbitMap = "0b11000000" |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1068 | |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1069 | type args struct { |
| 1070 | args map[string]uint32 |
| 1071 | classifierInfo map[string]interface{} |
| 1072 | actionInfo map[string]interface{} |
| 1073 | flow *ofp.OfpFlowStats |
| 1074 | gemPort uint32 |
| 1075 | intfID uint32 |
| 1076 | onuID uint32 |
| 1077 | uniID uint32 |
| 1078 | portNo uint32 |
| 1079 | TpInst *tp.TechProfile |
| 1080 | allocID []uint32 |
| 1081 | gemPorts []uint32 |
| 1082 | TpID uint32 |
| 1083 | uni string |
| 1084 | } |
| 1085 | tests := []struct { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1086 | name string |
| 1087 | args args |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1088 | }{ |
| 1089 | { |
| 1090 | name: "checkAndAddFlow-1", |
| 1091 | args: args{ |
| 1092 | args: nil, |
| 1093 | classifierInfo: classifierInfo, |
| 1094 | actionInfo: actionInfo, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1095 | flow: flow, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1096 | gemPort: 1, |
| 1097 | intfID: 1, |
| 1098 | onuID: 1, |
| 1099 | uniID: 16, |
| 1100 | portNo: 1, |
| 1101 | TpInst: TpInst, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1102 | allocID: []uint32{0x8001}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1103 | gemPorts: []uint32{1, 2, 3, 4}, |
| 1104 | TpID: 64, |
| 1105 | uni: "16", |
| 1106 | }, |
| 1107 | }, |
| 1108 | { |
| 1109 | name: "checkAndAddFlow-2", |
| 1110 | args: args{ |
| 1111 | args: nil, |
| 1112 | classifierInfo: classifierInfo2, |
| 1113 | actionInfo: actionInfo2, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1114 | flow: flow2, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1115 | gemPort: 1, |
| 1116 | intfID: 1, |
| 1117 | onuID: 1, |
| 1118 | uniID: 16, |
| 1119 | portNo: 1, |
| 1120 | TpInst: TpInst, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1121 | allocID: []uint32{0x8001}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1122 | gemPorts: []uint32{1, 2, 3, 4}, |
| 1123 | TpID: 64, |
| 1124 | uni: "16", |
| 1125 | }, |
| 1126 | }, |
| 1127 | { |
| 1128 | name: "checkAndAddFlow-3", |
| 1129 | args: args{ |
| 1130 | args: nil, |
| 1131 | classifierInfo: classifierInfo3, |
| 1132 | actionInfo: actionInfo3, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1133 | flow: flow3, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1134 | gemPort: 1, |
| 1135 | intfID: 1, |
| 1136 | onuID: 1, |
| 1137 | uniID: 16, |
| 1138 | portNo: 1, |
| 1139 | TpInst: TpInst, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1140 | allocID: []uint32{0x8001}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1141 | gemPorts: []uint32{1, 2, 3, 4}, |
| 1142 | TpID: 64, |
| 1143 | uni: "16", |
| 1144 | }, |
| 1145 | }, |
| 1146 | { |
| 1147 | name: "checkAndAddFlow-4", |
| 1148 | args: args{ |
| 1149 | args: nil, |
| 1150 | classifierInfo: classifierInfo4, |
| 1151 | actionInfo: actionInfo4, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1152 | flow: flow4, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1153 | gemPort: 1, |
| 1154 | intfID: 1, |
| 1155 | onuID: 1, |
| 1156 | uniID: 16, |
| 1157 | portNo: 1, |
| 1158 | TpInst: TpInst, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1159 | allocID: []uint32{0x8001}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1160 | gemPorts: []uint32{1, 2, 3, 4}, |
| 1161 | TpID: 64, |
| 1162 | uni: "16", |
| 1163 | }, |
| 1164 | }, |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1165 | { |
| 1166 | name: "checkAndAddFlow-5", |
| 1167 | args: args{ |
| 1168 | args: nil, |
| 1169 | classifierInfo: classifierInfo5, |
| 1170 | actionInfo: actionInfo5, |
| 1171 | flow: flow5, |
| 1172 | gemPort: 1, |
| 1173 | intfID: 1, |
| 1174 | onuID: 1, |
| 1175 | uniID: 16, |
| 1176 | portNo: 1, |
| 1177 | TpInst: TpInst, |
| 1178 | allocID: []uint32{0x8001}, |
| 1179 | gemPorts: []uint32{1, 2, 3, 4}, |
| 1180 | TpID: 64, |
| 1181 | uni: "16", |
| 1182 | }, |
| 1183 | }, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1184 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1185 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1186 | defer cancel() |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1187 | for _, tt := range tests { |
| 1188 | t.Run(tt.name, func(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 1189 | flowMgr[tt.args.intfID].checkAndAddFlow(ctx, tt.args.args, tt.args.classifierInfo, tt.args.actionInfo, tt.args.flow, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1190 | tt.args.TpInst, tt.args.gemPorts, tt.args.TpID, tt.args.uni) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1191 | }) |
| 1192 | } |
| 1193 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1194 | |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1195 | func TestOpenOltFlowMgr_TestMulticastFlowAndGroup(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1196 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1197 | defer cancel() |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1198 | //create group |
| 1199 | group := newGroup(2, []uint32{1}) |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 1200 | err := flowMgr[0].grpMgr.AddGroup(ctx, group) |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1201 | if err != nil { |
| 1202 | t.Error("group-add failed", err) |
| 1203 | return |
| 1204 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1205 | //create multicast flow |
| 1206 | multicastFlowArgs := &fu.FlowArgs{ |
| 1207 | MatchFields: []*ofp.OfpOxmOfbField{ |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1208 | fu.InPort(1048576), |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1209 | fu.VlanVid(660), //vlan |
| 1210 | fu.Metadata_ofp(uint64(66)), //inner vlan |
| 1211 | fu.EthType(0x800), //ipv4 |
| 1212 | fu.Ipv4Dst(3809869825), //227.22.0.1 |
| 1213 | }, |
| 1214 | Actions: []*ofp.OfpAction{ |
| 1215 | fu.Group(1), |
| 1216 | }, |
| 1217 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 1218 | ofpStats, _ := fu.MkFlowStat(multicastFlowArgs) |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1219 | fmt.Println(ofpStats.Id) |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 1220 | err = flowMgr[0].AddFlow(ctx, ofpStats, &voltha.FlowMetadata{}) |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1221 | if err != nil { |
| 1222 | t.Error("Multicast flow-add failed", err) |
| 1223 | return |
| 1224 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1225 | |
| 1226 | //add bucket to the group |
| 1227 | group = newGroup(2, []uint32{1, 2}) |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 1228 | err = flowMgr[0].grpMgr.ModifyGroup(ctx, group) |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1229 | if err != nil { |
| 1230 | t.Error("modify-group failed", err) |
| 1231 | return |
| 1232 | } |
| 1233 | //remove the multicast flow |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 1234 | err = flowMgr[0].RemoveFlow(ctx, ofpStats) |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1235 | if err != nil { |
| 1236 | t.Error("Multicast flow-remove failed", err) |
| 1237 | return |
| 1238 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1239 | |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1240 | //remove the group |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 1241 | err = flowMgr[0].grpMgr.DeleteGroup(ctx, group) |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1242 | if err != nil { |
| 1243 | t.Error("delete-group failed", err) |
| 1244 | return |
| 1245 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1246 | } |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1247 | |
| 1248 | func TestOpenOltFlowMgr_TestRouteFlowToOnuChannel(t *testing.T) { |
| 1249 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1250 | defer cancel() |
| 1251 | log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/core", log.DebugLevel) |
| 1252 | log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager", log.DebugLevel) |
| 1253 | log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/pkg/mocks", log.DebugLevel) |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1254 | kwTable1Meter1 := make(map[string]uint64) |
| 1255 | kwTable1Meter1["table_id"] = 1 |
| 1256 | kwTable1Meter1["meter_id"] = 1 |
| 1257 | kwTable1Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64 |
| 1258 | |
| 1259 | kwTable0Meter1 := make(map[string]uint64) |
| 1260 | kwTable0Meter1["table_id"] = 0 |
| 1261 | kwTable0Meter1["meter_id"] = 1 |
| 1262 | kwTable0Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64 |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1263 | |
| 1264 | flowMetadata1 := voltha.FlowMetadata{Meters: []*voltha.OfpMeterConfig{ |
| 1265 | { |
| 1266 | Flags: 5, |
| 1267 | MeterId: 1, |
| 1268 | Bands: []*voltha.OfpMeterBandHeader{ |
| 1269 | { |
| 1270 | Type: voltha.OfpMeterBandType_OFPMBT_DROP, |
| 1271 | Rate: 16000, |
| 1272 | BurstSize: 30, |
| 1273 | }, |
| 1274 | { |
| 1275 | Type: voltha.OfpMeterBandType_OFPMBT_DROP, |
| 1276 | Rate: 32000, |
| 1277 | BurstSize: 30, |
| 1278 | }, |
| 1279 | { |
| 1280 | Type: voltha.OfpMeterBandType_OFPMBT_DROP, |
| 1281 | Rate: 64000, |
| 1282 | BurstSize: 30, |
| 1283 | }, |
| 1284 | }, |
| 1285 | }, |
| 1286 | }} |
| 1287 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1288 | // Downstream LLDP Trap from NNI0 flow |
| 1289 | fa0 := &fu.FlowArgs{ |
| 1290 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1291 | fu.InPort(1048576), |
| 1292 | fu.EthType(35020), |
| 1293 | }, |
| 1294 | Actions: []*ofp.OfpAction{ |
| 1295 | fu.Output(4294967293), |
| 1296 | }, |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1297 | KV: make(map[string]uint64), |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | // Upstream flow DHCP flow - ONU1 UNI0 PON0 |
| 1301 | fa1 := &fu.FlowArgs{ |
| 1302 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1303 | fu.InPort(536870912), |
| 1304 | fu.Metadata_ofp(1), |
| 1305 | fu.IpProto(17), // dhcp |
| 1306 | fu.VlanPcp(0), |
| 1307 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 1308 | fu.TunnelId(16), |
| 1309 | }, |
| 1310 | Actions: []*ofp.OfpAction{ |
| 1311 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 1312 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 1313 | fu.Output(2147483645), |
| 1314 | fu.PushVlan(0x8100), |
| 1315 | }, |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1316 | KV: kwTable1Meter1, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | // Upstream EAPOL - ONU1 UNI0 PON0 |
| 1320 | fa2 := &fu.FlowArgs{ |
| 1321 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1322 | fu.InPort(536870912), |
| 1323 | fu.Metadata_ofp(1), |
| 1324 | fu.EthType(0x888E), |
| 1325 | fu.VlanPcp(1), |
| 1326 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257), |
| 1327 | fu.TunnelId(16), |
| 1328 | }, |
| 1329 | Actions: []*ofp.OfpAction{ |
| 1330 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 1331 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 1332 | fu.Output(2147483645), |
| 1333 | fu.PushVlan(0x8100), |
| 1334 | }, |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1335 | KV: kwTable1Meter1, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | // Upstream HSIA - ONU1 UNI0 PON0 |
| 1339 | fa3 := &fu.FlowArgs{ |
| 1340 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1341 | fu.InPort(536870912), |
| 1342 | fu.Metadata_ofp(1), |
| 1343 | //fu.EthType(0x8100), |
| 1344 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1345 | fu.TunnelId(16), |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1346 | }, |
| 1347 | Actions: []*ofp.OfpAction{ |
| 1348 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 1349 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)), |
| 1350 | fu.Output(1048576), |
| 1351 | fu.PushVlan(0x8100), |
| 1352 | }, |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1353 | KV: kwTable1Meter1, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | // Downstream HSIA - ONU1 UNI0 PON0 |
| 1357 | fa4 := &fu.FlowArgs{ |
| 1358 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1359 | fu.InPort(1048576), |
| 1360 | fu.Metadata_ofp(1), |
| 1361 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 1362 | fu.VlanPcp(1), |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1363 | fu.TunnelId(16), |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1364 | }, |
| 1365 | Actions: []*ofp.OfpAction{ |
| 1366 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 1367 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)), |
| 1368 | fu.Output(536870912), |
| 1369 | fu.PopVlan(), |
| 1370 | }, |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1371 | KV: kwTable0Meter1, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | // Upstream flow DHCP flow - ONU1 UNI0 PON15 |
| 1375 | fa5 := &fu.FlowArgs{ |
| 1376 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1377 | fu.InPort(536870927), |
| 1378 | fu.Metadata_ofp(1), |
| 1379 | fu.IpProto(17), // dhcp |
| 1380 | fu.VlanPcp(0), |
| 1381 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1382 | fu.TunnelId(16), |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1383 | }, |
| 1384 | Actions: []*ofp.OfpAction{ |
| 1385 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 1386 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259)), |
| 1387 | fu.Output(2147483645), |
| 1388 | fu.PushVlan(0x8100), |
| 1389 | }, |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1390 | KV: kwTable1Meter1, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1391 | } |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1392 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1393 | // Upstream EAPOL - ONU1 UNI0 PON15 |
| 1394 | fa6 := &fu.FlowArgs{ |
| 1395 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1396 | fu.InPort(536870927), |
| 1397 | fu.Metadata_ofp(1), |
| 1398 | fu.EthType(0x888E), |
| 1399 | fu.VlanPcp(1), |
| 1400 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259), |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1401 | fu.TunnelId(16), |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1402 | }, |
| 1403 | Actions: []*ofp.OfpAction{ |
| 1404 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 1405 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 1406 | fu.Output(2147483645), |
| 1407 | fu.PushVlan(0x8100), |
| 1408 | }, |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1409 | KV: kwTable1Meter1, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1410 | } |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1411 | |
| 1412 | // Upstream PPPOED - ONU1 UNI0 PON0 |
| 1413 | fa7 := &fu.FlowArgs{ |
| 1414 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1415 | fu.InPort(536870912), |
| 1416 | fu.Metadata_ofp(1), |
| 1417 | fu.EthType(0x8863), |
| 1418 | fu.VlanPcp(1), |
| 1419 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257), |
| 1420 | fu.TunnelId(16), |
| 1421 | }, |
| 1422 | Actions: []*ofp.OfpAction{ |
| 1423 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 1424 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 1425 | fu.Output(2147483645), |
| 1426 | fu.PushVlan(0x8100), |
| 1427 | }, |
| 1428 | KV: kwTable1Meter1, |
| 1429 | } |
| 1430 | |
| 1431 | // Upstream PPPOED - ONU1 UNI0 PON15 |
| 1432 | fa8 := &fu.FlowArgs{ |
| 1433 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1434 | fu.InPort(536870927), |
| 1435 | fu.Metadata_ofp(1), |
| 1436 | fu.EthType(0x8863), |
| 1437 | fu.VlanPcp(1), |
| 1438 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259), |
| 1439 | fu.TunnelId(16), |
| 1440 | }, |
| 1441 | Actions: []*ofp.OfpAction{ |
| 1442 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 1443 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 1444 | fu.Output(2147483645), |
| 1445 | fu.PushVlan(0x8100), |
| 1446 | }, |
| 1447 | KV: kwTable1Meter1, |
| 1448 | } |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1449 | flow0, _ := fu.MkFlowStat(fa0) |
| 1450 | flow1, _ := fu.MkFlowStat(fa1) |
| 1451 | flow2, _ := fu.MkFlowStat(fa2) |
| 1452 | flow3, _ := fu.MkFlowStat(fa3) |
| 1453 | flow4, _ := fu.MkFlowStat(fa4) |
| 1454 | |
| 1455 | flow5, _ := fu.MkFlowStat(fa5) |
| 1456 | flow6, _ := fu.MkFlowStat(fa6) |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1457 | flow7, _ := fu.MkFlowStat(fa7) |
| 1458 | flow8, _ := fu.MkFlowStat(fa8) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1459 | |
| 1460 | type args struct { |
| 1461 | ctx context.Context |
| 1462 | flow *ofp.OfpFlowStats |
| 1463 | addFlow bool |
| 1464 | flowMetadata *voltha.FlowMetadata |
| 1465 | } |
| 1466 | tests := []struct { |
| 1467 | name string |
| 1468 | args args |
| 1469 | wantErr bool |
| 1470 | returnedErr error |
| 1471 | }{ |
| 1472 | { |
| 1473 | name: "RouteFlowToOnuChannel-0", |
| 1474 | args: args{ |
| 1475 | ctx: ctx, |
| 1476 | flow: flow0, |
| 1477 | addFlow: true, |
| 1478 | flowMetadata: &flowMetadata1, |
| 1479 | }, |
| 1480 | wantErr: false, |
| 1481 | }, |
| 1482 | { |
| 1483 | name: "RouteFlowToOnuChannel-1", |
| 1484 | args: args{ |
| 1485 | ctx: ctx, |
| 1486 | flow: flow1, |
| 1487 | addFlow: true, |
| 1488 | flowMetadata: &flowMetadata1, |
| 1489 | }, |
| 1490 | wantErr: false, |
| 1491 | }, |
| 1492 | { |
| 1493 | name: "RouteFlowToOnuChannel-2", |
| 1494 | args: args{ |
| 1495 | ctx: ctx, |
| 1496 | flow: flow2, |
| 1497 | addFlow: true, |
| 1498 | flowMetadata: &flowMetadata1, |
| 1499 | }, |
| 1500 | wantErr: false, |
| 1501 | }, |
| 1502 | { |
| 1503 | name: "RouteFlowToOnuChannel-3", |
| 1504 | args: args{ |
| 1505 | ctx: ctx, |
| 1506 | flow: flow3, |
| 1507 | addFlow: true, |
| 1508 | flowMetadata: &flowMetadata1, |
| 1509 | }, |
| 1510 | wantErr: false, |
| 1511 | }, |
| 1512 | { |
| 1513 | name: "RouteFlowToOnuChannel-4", |
| 1514 | args: args{ |
| 1515 | ctx: ctx, |
| 1516 | flow: flow4, |
| 1517 | addFlow: true, |
| 1518 | flowMetadata: &flowMetadata1, |
| 1519 | }, |
| 1520 | wantErr: false, |
| 1521 | }, |
| 1522 | { |
| 1523 | name: "RouteFlowToOnuChannel-5", |
| 1524 | args: args{ |
| 1525 | ctx: ctx, |
| 1526 | flow: flow1, |
| 1527 | addFlow: false, |
| 1528 | flowMetadata: &flowMetadata1, |
| 1529 | }, |
| 1530 | wantErr: false, |
| 1531 | }, |
| 1532 | { |
| 1533 | name: "RouteFlowToOnuChannel-6", |
| 1534 | args: args{ |
| 1535 | ctx: ctx, |
| 1536 | flow: flow1, |
| 1537 | addFlow: true, |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1538 | flowMetadata: &flowMetadata1, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1539 | }, |
| 1540 | wantErr: true, |
| 1541 | }, |
| 1542 | { |
| 1543 | name: "RouteFlowToOnuChannel-7", |
| 1544 | args: args{ |
| 1545 | ctx: ctx, |
| 1546 | flow: flow5, |
| 1547 | addFlow: true, |
| 1548 | flowMetadata: &flowMetadata1, |
| 1549 | }, |
| 1550 | wantErr: false, |
| 1551 | }, |
| 1552 | { |
| 1553 | name: "RouteFlowToOnuChannel-8", |
| 1554 | args: args{ |
| 1555 | ctx: ctx, |
| 1556 | flow: flow6, |
| 1557 | addFlow: true, |
| 1558 | flowMetadata: &flowMetadata1, |
| 1559 | }, |
| 1560 | wantErr: false, |
| 1561 | }, |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1562 | { |
| 1563 | name: "RouteFlowToOnuChannel-9", |
| 1564 | args: args{ |
| 1565 | ctx: ctx, |
| 1566 | flow: flow7, |
| 1567 | addFlow: true, |
| 1568 | flowMetadata: &flowMetadata1, |
| 1569 | }, |
| 1570 | wantErr: false, |
| 1571 | }, |
| 1572 | { |
| 1573 | name: "RouteFlowToOnuChannel-10", |
| 1574 | args: args{ |
| 1575 | ctx: ctx, |
| 1576 | flow: flow8, |
| 1577 | addFlow: true, |
| 1578 | flowMetadata: &flowMetadata1, |
| 1579 | }, |
| 1580 | wantErr: false, |
| 1581 | }, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | var wg sync.WaitGroup |
| 1585 | defer wg.Wait() // wait for all go routines to complete |
| 1586 | for _, tt := range tests { |
| 1587 | t.Run(tt.name, func(t *testing.T) { |
| 1588 | wg.Add(1) // one per go routine |
| 1589 | go func() { |
| 1590 | defer wg.Done() |
| 1591 | tt.returnedErr = flowMgr[0].RouteFlowToOnuChannel(tt.args.ctx, tt.args.flow, tt.args.addFlow, tt.args.flowMetadata) |
| 1592 | if (tt.wantErr == false && tt.returnedErr != nil) || (tt.wantErr == true && tt.returnedErr == nil) { |
| 1593 | t.Errorf("OpenOltFlowMgr.RouteFlowToOnuChannel() error = %v, wantErr %v", tt.returnedErr, tt.wantErr) |
| 1594 | } |
| 1595 | }() |
| 1596 | }) |
| 1597 | } |
| 1598 | } |