blob: 44a02fbbbfc5dec6c283ae4427b89b1c1a414761 [file] [log] [blame]
kdarapu3248f9a2019-10-03 13:54:52 +05301/*
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 Bakerdbd960e2020-02-28 08:57:51 -080017//Package core provides the utility for olt devices, flows and statistics
18package core
kdarapu3248f9a2019-10-03 13:54:52 +053019
20import (
npujarec5762e2020-01-01 14:08:48 +053021 "context"
Esin Karaman7fb80c22020-07-16 14:23:33 +000022 "encoding/hex"
Gamze Abakafee36392019-10-03 11:17:24 +000023 "fmt"
Matteo Scandoloabf9c512020-06-23 19:31:14 -070024 "reflect"
25 "strconv"
26 "sync"
kdarapu3248f9a2019-10-03 13:54:52 +053027 "testing"
npujarec5762e2020-01-01 14:08:48 +053028 "time"
kdarapu3248f9a2019-10-03 13:54:52 +053029
Girish Gowdraa09aeab2020-09-14 16:30:52 -070030 "github.com/opencord/voltha-protos/v4/go/voltha"
kdarapub26b4502019-10-05 03:02:33 +053031
Girish Gowdraa09aeab2020-09-14 16:30:52 -070032 "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 Bakerdbd960e2020-02-28 08:57:51 -080036 "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 Gowdraa09aeab2020-09-14 16:30:52 -070039 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"
kdarapu3248f9a2019-10-03 13:54:52 +053043)
44
Girish Gowdra9602eb42020-09-09 15:50:39 -070045var flowMgr []*OpenOltFlowMgr
kdarapub26b4502019-10-05 03:02:33 +053046
kdarapu3248f9a2019-10-03 13:54:52 +053047func init() {
Kent Hagermane6ff1012020-07-14 15:07:53 -040048 _, _ = log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
kdarapub26b4502019-10-05 03:02:33 +053049 flowMgr = newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +053050}
51func newMockResourceMgr() *resourcemanager.OpenOltResourceMgr {
52 ranges := []*openolt.DeviceInfo_DeviceResourceRanges{
Matteo Scandoloabf9c512020-06-23 19:31:14 -070053 {
54 IntfIds: []uint32{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
55 Technology: "Default",
56 },
57 }
kdarapu3248f9a2019-10-03 13:54:52 +053058
59 deviceinfo := &openolt.DeviceInfo{Vendor: "openolt", Model: "openolt", HardwareVersion: "1.0", FirmwareVersion: "1.0",
Matteo Scandoloabf9c512020-06-23 19:31:14 -070060 DeviceId: "olt", DeviceSerialNumber: "openolt", PonPorts: 16, Technology: "Default",
Girish Gowdra9602eb42020-09-09 15:50:39 -070061 OnuIdStart: OnuIDStart, OnuIdEnd: OnuIDEnd, AllocIdStart: AllocIDStart, AllocIdEnd: AllocIDEnd,
62 GemportIdStart: GemIDStart, GemportIdEnd: GemIDEnd, FlowIdStart: FlowIDStart, FlowIdEnd: FlowIDEnd,
kdarapu3248f9a2019-10-03 13:54:52 +053063 Ranges: ranges,
64 }
npujarec5762e2020-01-01 14:08:48 +053065 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
66 defer cancel()
Matteo Scandolodfa7a972020-11-06 13:03:40 -080067 rsrMgr := resourcemanager.NewResourceMgr(ctx, "olt", "127.0.0.1:2379", "etcd", "olt", deviceinfo, "service/voltha")
kdarapub26b4502019-10-05 03:02:33 +053068 for key := range rsrMgr.ResourceMgrs {
sbarbaria8910ba2019-11-05 10:12:23 -050069 rsrMgr.ResourceMgrs[key].KVStore = &db.Backend{}
kdarapub26b4502019-10-05 03:02:33 +053070 rsrMgr.ResourceMgrs[key].KVStore.Client = &mocks.MockKVClient{}
71 rsrMgr.ResourceMgrs[key].TechProfileMgr = mocks.MockTechProfile{TpID: key}
72 }
kdarapu3248f9a2019-10-03 13:54:52 +053073 return rsrMgr
74}
75
Girish Gowdra9602eb42020-09-09 15:50:39 -070076func newMockFlowmgr() []*OpenOltFlowMgr {
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +053077 rMgr := newMockResourceMgr()
kdarapu3248f9a2019-10-03 13:54:52 +053078 dh := newMockDeviceHandler()
79
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +053080 rMgr.KVStore = &db.Backend{}
81 rMgr.KVStore.Client = &mocks.MockKVClient{}
kdarapu3248f9a2019-10-03 13:54:52 +053082
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +053083 dh.resourceMgr = rMgr
kdarapu3248f9a2019-10-03 13:54:52 +053084
Girish Gowdra9602eb42020-09-09 15:50:39 -070085 // onuGemInfo := make([]rsrcMgr.OnuGemInfo, NumPonPorts)
86 var i uint32
kdarapu3248f9a2019-10-03 13:54:52 +053087
Girish Gowdra9602eb42020-09-09 15:50:39 -070088 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
kdarapu3248f9a2019-10-03 13:54:52 +053091
Girish Gowdra9602eb42020-09-09 15:50:39 -070092 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
kdarapu3248f9a2019-10-03 13:54:52 +0530104 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000105
Girish Gowdra9602eb42020-09-09 15:50:39 -0700106 return dh.flowMgr
kdarapu3248f9a2019-10-03 13:54:52 +0530107}
kdarapub26b4502019-10-05 03:02:33 +0530108
kdarapu3248f9a2019-10-03 13:54:52 +0530109func TestOpenOltFlowMgr_CreateSchedulerQueues(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530110 tprofile := &tp.TechProfile{Name: "tp1", SubscriberIdentifier: "subscriber1",
Girish Gowdra54934262019-11-13 14:19:55 +0530111 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
kdarapu3248f9a2019-10-03 13:54:52 +0530112 InstanceCtrl: tp.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"},
113 }
114 tprofile.UsScheduler.Direction = "UPSTREAM"
kdarapu3248f9a2019-10-03 13:54:52 +0530115 tprofile.UsScheduler.QSchedPolicy = "WRR"
116
117 tprofile2 := tprofile
118 tprofile2.DsScheduler.Direction = "DOWNSTREAM"
kdarapu3248f9a2019-10-03 13:54:52 +0530119 tprofile2.DsScheduler.QSchedPolicy = "WRR"
Gamze Abaka01174422021-03-10 06:55:27 +0000120
kdarapu3248f9a2019-10-03 13:54:52 +0530121 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +0000122 name string
123 schedQueue schedQueue
124 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +0530125 }{
126 // TODO: Add test cases.
Gamze Abaka01174422021-03-10 06:55:27 +0000127 {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 1, Upstream)}, false},
128 {"CreateSchedulerQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 1, Downstream)}, false},
129 {"CreateSchedulerQueues-13", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 2, Upstream)}, false},
130 {"CreateSchedulerQueues-14", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 2, Downstream)}, false},
131 {"CreateSchedulerQueues-15", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 3, Upstream)}, false},
132 {"CreateSchedulerQueues-16", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 3, Downstream)}, false},
133 {"CreateSchedulerQueues-17", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 4, Upstream)}, false},
134 {"CreateSchedulerQueues-18", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 4, Downstream)}, false},
135 {"CreateSchedulerQueues-19", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 5, Upstream)}, false},
136 {"CreateSchedulerQueues-20", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 5, Downstream)}, false},
137
138 {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 0, Upstream)}, true},
139 {"CreateSchedulerQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 0, Downstream)}, true},
140 {"CreateSchedulerQueues-3", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, createFlowMetadata(tprofile, 2, Upstream)}, true},
141 {"CreateSchedulerQueues-4", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, createFlowMetadata(tprofile2, 2, Downstream)}, true},
142 {"CreateSchedulerQueues-5", schedQueue{tp_pb.Direction_UPSTREAM, 1, 2, 2, 64, 2, tprofile, 2, createFlowMetadata(tprofile, 3, Upstream)}, true},
143 {"CreateSchedulerQueues-6", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 2, 2, 65, 2, tprofile2, 2, createFlowMetadata(tprofile2, 3, Downstream)}, true},
144
kdarapu3248f9a2019-10-03 13:54:52 +0530145 //Negative testcases
Girish Gowdra9602eb42020-09-09 15:50:39 -0700146 {"CreateSchedulerQueues-7", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, &voltha.FlowMetadata{}}, true},
147 {"CreateSchedulerQueues-8", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 0, &voltha.FlowMetadata{}}, true},
148 {"CreateSchedulerQueues-9", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, &voltha.FlowMetadata{}}, true},
149 {"CreateSchedulerQueues-10", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, &voltha.FlowMetadata{}}, true},
150 {"CreateSchedulerQueues-11", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, &voltha.FlowMetadata{}}, true},
151 {"CreateSchedulerQueues-12", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, nil}, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530152 }
npujarec5762e2020-01-01 14:08:48 +0530153 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
154 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530155 for _, tt := range tests {
156 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700157 if err := flowMgr[tt.schedQueue.intfID].CreateSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530158 t.Errorf("OpenOltFlowMgr.CreateSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr)
159 }
160 })
161 }
162}
163
Gamze Abaka01174422021-03-10 06:55:27 +0000164func createFlowMetadata(techProfile *tp.TechProfile, tcontType int, direction string) *voltha.FlowMetadata {
165 var additionalBw string
166 bands := make([]*ofp.OfpMeterBandHeader, 0)
167 switch tcontType {
168 case 1:
169 //tcont-type-1
170 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
171 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
172 additionalBw = "AdditionalBW_None"
173 case 2:
174 //tcont-type-2
175 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 60000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
176 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
177 additionalBw = "AdditionalBW_None"
178 case 3:
179 //tcont-type-3
180 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
181 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 20000, Data: &ofp.OfpMeterBandHeader_Drop{}})
182 additionalBw = "AdditionalBW_NA"
183 case 4:
184 //tcont-type-4
185 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 200000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
186 additionalBw = "AdditionalBW_BestEffort"
187 case 5:
188 //tcont-type-5
189 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
190 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
191 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
192 additionalBw = "AdditionalBW_BestEffort"
193 default:
194 // do nothing, we will return meter config with no meter bands
195 }
196
197 if direction == Downstream {
198 techProfile.DsScheduler.AdditionalBw = additionalBw
199 } else {
200 techProfile.UsScheduler.AdditionalBw = additionalBw
201 }
202
203 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
204 return &voltha.FlowMetadata{
205 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}}
206}
207
kdarapu3248f9a2019-10-03 13:54:52 +0530208func TestOpenOltFlowMgr_RemoveSchedulerQueues(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530209 tprofile := &tp.TechProfile{Name: "tp1", SubscriberIdentifier: "subscriber1",
Girish Gowdra54934262019-11-13 14:19:55 +0530210 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
kdarapu3248f9a2019-10-03 13:54:52 +0530211 InstanceCtrl: tp.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"},
212 }
213 tprofile.UsScheduler.Direction = "UPSTREAM"
214 tprofile.UsScheduler.AdditionalBw = "AdditionalBW_None"
215 tprofile.UsScheduler.QSchedPolicy = "WRR"
216
217 tprofile2 := tprofile
218 tprofile2.DsScheduler.Direction = "DOWNSTREAM"
219 tprofile2.DsScheduler.AdditionalBw = "AdditionalBW_None"
220 tprofile2.DsScheduler.QSchedPolicy = "WRR"
221 //defTprofile := &tp.DefaultTechProfile{}
kdarapu3248f9a2019-10-03 13:54:52 +0530222 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +0000223 name string
224 schedQueue schedQueue
225 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +0530226 }{
227 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000228 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 0, nil}, false},
229 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530230 // negative test cases
Gamze Abakafee36392019-10-03 11:17:24 +0000231 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
232 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530233 }
npujarec5762e2020-01-01 14:08:48 +0530234 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
235 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530236 for _, tt := range tests {
237 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700238 if err := flowMgr[tt.schedQueue.intfID].RemoveSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530239 t.Errorf("OpenOltFlowMgr.RemoveSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr)
240 }
241 })
242 }
kdarapub26b4502019-10-05 03:02:33 +0530243
kdarapu3248f9a2019-10-03 13:54:52 +0530244}
245
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700246func TestOpenOltFlowMgr_createTcontGemports(t *testing.T) {
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700247 bands := make([]*ofp.OfpMeterBandHeader, 2)
248 bands[0] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 1000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
249 bands[1] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 2000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
250 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
251 flowmetadata := &voltha.FlowMetadata{
252 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
253 }
254 type args struct {
255 intfID uint32
256 onuID uint32
257 uniID uint32
258 uni string
259 uniPort uint32
260 TpID uint32
261 UsMeterID uint32
262 DsMeterID uint32
263 flowMetadata *voltha.FlowMetadata
264 }
265 tests := []struct {
266 name string
267 args args
268 }{
269 {"createTcontGemports-1", args{intfID: 0, onuID: 1, uniID: 1, uni: "16", uniPort: 1, TpID: 64, UsMeterID: 1, DsMeterID: 1, flowMetadata: flowmetadata}},
270 {"createTcontGemports-1", args{intfID: 0, onuID: 1, uniID: 1, uni: "16", uniPort: 1, TpID: 65, UsMeterID: 1, DsMeterID: 1, flowMetadata: flowmetadata}},
271 }
272 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
273 defer cancel()
274 for _, tt := range tests {
275 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700276 _, _, 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 Suzuki2ba0e0b2020-06-05 14:23:03 -0700277 switch tpInst := tpInst.(type) {
278 case *tp.TechProfile:
279 if tt.args.TpID != 64 {
280 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
281 }
282 case *tp.EponProfile:
283 if tt.args.TpID != 65 {
284 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
285 }
286 default:
287 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
288 }
289 })
290 }
291}
292
kdarapu3248f9a2019-10-03 13:54:52 +0530293func TestOpenOltFlowMgr_RemoveFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000294 ctx := context.Background()
Neha Sharma96b7bf22020-06-15 10:37:32 +0000295 logger.Debug(ctx, "Info Warning Error: Starting RemoveFlow() test")
kdarapu3248f9a2019-10-03 13:54:52 +0530296 fa := &fu.FlowArgs{
297 MatchFields: []*ofp.OfpOxmOfbField{
298 fu.InPort(2),
299 fu.Metadata_ofp(2),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300300 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapu3248f9a2019-10-03 13:54:52 +0530301 },
302 Actions: []*ofp.OfpAction{
303 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
304 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
305 fu.Output(1),
306 },
307 }
divyadesaid26f6b12020-03-19 06:30:28 +0000308 ofpstats, _ := fu.MkFlowStat(fa)
kdarapub26b4502019-10-05 03:02:33 +0530309 ofpstats.Cookie = ofpstats.Id
kdarapub26b4502019-10-05 03:02:33 +0530310 lldpFa := &fu.FlowArgs{
311 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
312 MatchFields: []*ofp.OfpOxmOfbField{
313 fu.InPort(1),
314 fu.EthType(0x88CC),
315 fu.TunnelId(536870912),
316 },
317 Actions: []*ofp.OfpAction{
318 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
319 },
320 }
divyadesaid26f6b12020-03-19 06:30:28 +0000321 lldpofpstats, _ := fu.MkFlowStat(lldpFa)
kdarapub26b4502019-10-05 03:02:33 +0530322 //lldpofpstats.Cookie = lldpofpstats.Id
323
324 dhcpFa := &fu.FlowArgs{
325 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
326 MatchFields: []*ofp.OfpOxmOfbField{
327 fu.InPort(1),
328 fu.UdpSrc(67),
329 //fu.TunnelId(536870912),
330 fu.IpProto(17),
331 },
332 Actions: []*ofp.OfpAction{
333 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
334 },
335 }
divyadesaid26f6b12020-03-19 06:30:28 +0000336 dhcpofpstats, _ := fu.MkFlowStat(dhcpFa)
kdarapub26b4502019-10-05 03:02:33 +0530337 //dhcpofpstats.Cookie = dhcpofpstats.Id
Esin Karamanccb714b2019-11-29 15:02:06 +0000338
339 //multicast flow
340 multicastFa := &fu.FlowArgs{
341 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800342 fu.InPort(1048576),
Esin Karamanccb714b2019-11-29 15:02:06 +0000343 fu.VlanVid(660), //vlan
344 fu.Metadata_ofp(uint64(66)), //inner vlan
345 fu.EthType(0x800), //ipv4
346 fu.Ipv4Dst(3809869825), //227.22.0.1
347 },
348 Actions: []*ofp.OfpAction{
349 fu.Group(1),
350 },
351 }
divyadesaid26f6b12020-03-19 06:30:28 +0000352 multicastOfpStats, _ := fu.MkFlowStat(multicastFa)
Esin Karamanccb714b2019-11-29 15:02:06 +0000353 multicastOfpStats.Id = 1
354
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300355 pppoedFa := &fu.FlowArgs{
356 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
357 MatchFields: []*ofp.OfpOxmOfbField{
358 fu.InPort(1),
359 fu.EthType(0x8863),
360 fu.TunnelId(536870912),
361 },
362 Actions: []*ofp.OfpAction{
363 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
364 },
365 }
366 pppoedOfpStats, _ := fu.MkFlowStat(pppoedFa)
367
kdarapu3248f9a2019-10-03 13:54:52 +0530368 type args struct {
369 flow *ofp.OfpFlowStats
370 }
371 tests := []struct {
372 name string
373 args args
374 }{
375 // TODO: Add test cases.
376 {"RemoveFlow", args{flow: ofpstats}},
kdarapub26b4502019-10-05 03:02:33 +0530377 {"RemoveFlow", args{flow: lldpofpstats}},
378 {"RemoveFlow", args{flow: dhcpofpstats}},
Esin Karamanccb714b2019-11-29 15:02:06 +0000379 {"RemoveFlow", args{flow: multicastOfpStats}},
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300380 {"RemoveFlow", args{flow: pppoedOfpStats}},
kdarapu3248f9a2019-10-03 13:54:52 +0530381 }
npujarec5762e2020-01-01 14:08:48 +0530382 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
383 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530384 for _, tt := range tests {
385 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700386 if err := flowMgr[0].RemoveFlow(ctx, tt.args.flow); err != nil {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400387 logger.Warn(ctx, err)
388 }
kdarapu3248f9a2019-10-03 13:54:52 +0530389 })
390 }
kdarapub26b4502019-10-05 03:02:33 +0530391 // t.Error("=====")
kdarapu3248f9a2019-10-03 13:54:52 +0530392}
393
394func TestOpenOltFlowMgr_AddFlow(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530395 kw := make(map[string]uint64)
396 kw["table_id"] = 1
397 kw["meter_id"] = 1
kdarapub26b4502019-10-05 03:02:33 +0530398 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
399
400 // Upstream flow
kdarapu3248f9a2019-10-03 13:54:52 +0530401 fa := &fu.FlowArgs{
402 MatchFields: []*ofp.OfpOxmOfbField{
kdarapub26b4502019-10-05 03:02:33 +0530403 fu.InPort(536870912),
404 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300405 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530406 },
407 Actions: []*ofp.OfpAction{
408 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
409 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800410 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530411 fu.PushVlan(0x8100),
412 },
413 KV: kw,
414 }
415
416 // Downstream flow
417 fa3 := &fu.FlowArgs{
418 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800419 fu.InPort(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530420 fu.Metadata_ofp(1),
421 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
422 },
423 Actions: []*ofp.OfpAction{
424 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
425 //fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
426 fu.PopVlan(),
427 fu.Output(536870912),
428 },
429 KV: kw,
430 }
431
432 fa2 := &fu.FlowArgs{
433 MatchFields: []*ofp.OfpOxmOfbField{
kdarapu3248f9a2019-10-03 13:54:52 +0530434 fu.InPort(1000),
435 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300436 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapu3248f9a2019-10-03 13:54:52 +0530437 },
438 Actions: []*ofp.OfpAction{
439 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
440 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
441 fu.Output(65533),
442 },
443 KV: kw,
444 }
445
kdarapub26b4502019-10-05 03:02:33 +0530446 // TODO Add LLDP flow
447 // TODO Add DHCP flow
448
449 // Flows for negative scenarios
450 // Failure in formulateActionInfoFromFlow()
451 fa4 := &fu.FlowArgs{
452 MatchFields: []*ofp.OfpOxmOfbField{
453 fu.InPort(1000),
454 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300455 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530456 },
457 Actions: []*ofp.OfpAction{
458 fu.Experimenter(257, []byte{1, 2, 3, 4}),
459 },
460 KV: kw,
461 }
462
463 // Invalid Output
464 fa5 := &fu.FlowArgs{
465 MatchFields: []*ofp.OfpOxmOfbField{
466 fu.InPort(1000),
467 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300468 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530469 },
470 Actions: []*ofp.OfpAction{
471 fu.Output(0),
472 },
473 KV: kw,
474 }
475
476 // Tech-Profile-ID update (not supported)
477 kw6 := make(map[string]uint64)
478 kw6["table_id"] = 1
479 kw6["meter_id"] = 1
480 kw6["write_metadata"] = 0x4100000000 // TpID Other than the stored one
481 fa6 := &fu.FlowArgs{
482 MatchFields: []*ofp.OfpOxmOfbField{
483 fu.InPort(536870912),
484 fu.TunnelId(16),
485 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300486 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530487 },
488 Actions: []*ofp.OfpAction{
489 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
490 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
491 fu.Output(65535),
492 },
493 KV: kw6,
494 }
495
496 lldpFa := &fu.FlowArgs{
497 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
498 MatchFields: []*ofp.OfpOxmOfbField{
499 fu.InPort(1),
500 fu.EthType(0x88CC),
501 fu.TunnelId(536870912),
502 },
503 Actions: []*ofp.OfpAction{
504 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
505 },
506 }
507
508 dhcpFa := &fu.FlowArgs{
509 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
510 MatchFields: []*ofp.OfpOxmOfbField{
511 fu.InPort(1),
512 fu.UdpSrc(67),
513 //fu.TunnelId(536870912),
514 fu.IpProto(17),
515 },
516 Actions: []*ofp.OfpAction{
517 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
518 },
519 }
520 igmpFa := &fu.FlowArgs{
521 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
522 MatchFields: []*ofp.OfpOxmOfbField{
523 fu.InPort(1),
524 fu.UdpSrc(67),
525 //fu.TunnelId(536870912),
526 fu.IpProto(2),
527 },
528 Actions: []*ofp.OfpAction{
529 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
530 },
531 }
532
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300533 pppoedFa := &fu.FlowArgs{
534 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
535 MatchFields: []*ofp.OfpOxmOfbField{
536 fu.InPort(1),
537 fu.EthType(0x8863),
538 fu.TunnelId(536870912),
539 },
540 Actions: []*ofp.OfpAction{
541 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
542 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
543 },
544 }
545
kdarapub26b4502019-10-05 03:02:33 +0530546 fa9 := &fu.FlowArgs{
547 MatchFields: []*ofp.OfpOxmOfbField{
548 fu.InPort(536870912),
549 fu.TunnelId(16),
550 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300551 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530552 fu.VlanPcp(1000),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800553 fu.UdpDst(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530554 fu.UdpSrc(536870912),
555 fu.Ipv4Dst(65535),
556 fu.Ipv4Src(536870912),
557 },
558 Actions: []*ofp.OfpAction{
559 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
560 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
561 fu.Output(65535),
562 },
563 KV: kw6,
564 }
565
566 fa10 := &fu.FlowArgs{
567 MatchFields: []*ofp.OfpOxmOfbField{
568 fu.InPort(65533),
569 // fu.TunnelId(16),
570 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300571 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530572 fu.VlanPcp(1000),
573 fu.UdpDst(65535),
574 fu.UdpSrc(536870912),
575 fu.Ipv4Dst(65535),
576 fu.Ipv4Src(536870912),
577 },
578 Actions: []*ofp.OfpAction{
579 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
580 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
581 fu.Output(65535),
582 },
583 KV: kw6,
584 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000585 //multicast flow
586 fa11 := &fu.FlowArgs{
587 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800588 fu.InPort(1048576),
Esin Karamanccb714b2019-11-29 15:02:06 +0000589 fu.VlanVid(660), //vlan
590 fu.Metadata_ofp(uint64(66)), //inner vlan
591 fu.EthType(0x800), //ipv4
592 fu.Ipv4Dst(3809869825), //227.22.0.1
593 },
594 Actions: []*ofp.OfpAction{
595 fu.Group(1),
596 },
597 KV: kw6,
598 }
divyadesaid26f6b12020-03-19 06:30:28 +0000599 ofpstats, _ := fu.MkFlowStat(fa)
600 ofpstats2, _ := fu.MkFlowStat(fa2)
601 ofpstats3, _ := fu.MkFlowStat(fa3)
602 ofpstats4, _ := fu.MkFlowStat(fa4)
603 ofpstats5, _ := fu.MkFlowStat(fa5)
604 ofpstats6, _ := fu.MkFlowStat(fa6)
605 ofpstats7, _ := fu.MkFlowStat(lldpFa)
606 ofpstats8, _ := fu.MkFlowStat(dhcpFa)
607 ofpstats9, _ := fu.MkFlowStat(fa9)
608 ofpstats10, _ := fu.MkFlowStat(fa10)
609 igmpstats, _ := fu.MkFlowStat(igmpFa)
610 ofpstats11, _ := fu.MkFlowStat(fa11)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300611 pppoedstats, _ := fu.MkFlowStat(pppoedFa)
kdarapub26b4502019-10-05 03:02:33 +0530612
Gamze Abakafee36392019-10-03 11:17:24 +0000613 fmt.Println(ofpstats6, ofpstats9, ofpstats10)
614
kdarapu3248f9a2019-10-03 13:54:52 +0530615 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1}
kdarapu3248f9a2019-10-03 13:54:52 +0530616 flowMetadata := &voltha.FlowMetadata{
617 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
618 }
619 type args struct {
620 flow *ofp.OfpFlowStats
621 flowMetadata *voltha.FlowMetadata
622 }
623 tests := []struct {
624 name string
625 args args
626 }{
627 // TODO: Add test cases.
628 {"AddFlow", args{flow: ofpstats, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530629 {"AddFlow", args{flow: ofpstats2, flowMetadata: flowMetadata}},
630 {"AddFlow", args{flow: ofpstats3, flowMetadata: flowMetadata}},
631 {"AddFlow", args{flow: ofpstats4, flowMetadata: flowMetadata}},
632 {"AddFlow", args{flow: ofpstats5, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000633 //{"AddFlow", args{flow: ofpstats6, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530634 {"AddFlow", args{flow: ofpstats7, flowMetadata: flowMetadata}},
635 {"AddFlow", args{flow: ofpstats8, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000636 //{"AddFlow", args{flow: ofpstats9, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530637 {"AddFlow", args{flow: igmpstats, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000638 //{"AddFlow", args{flow: ofpstats10, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530639 //ofpstats10
Esin Karamanccb714b2019-11-29 15:02:06 +0000640 {"AddFlow", args{flow: ofpstats11, flowMetadata: flowMetadata}},
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300641 {"AddFlow", args{flow: pppoedstats, flowMetadata: flowMetadata}},
kdarapu3248f9a2019-10-03 13:54:52 +0530642 }
npujarec5762e2020-01-01 14:08:48 +0530643 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
644 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530645 for _, tt := range tests {
646 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700647 _ = flowMgr[0].AddFlow(ctx, tt.args.flow, tt.args.flowMetadata)
Kent Hagermane6ff1012020-07-14 15:07:53 -0400648 // TODO: actually verify test cases
kdarapu3248f9a2019-10-03 13:54:52 +0530649 })
650 }
651}
652
653func TestOpenOltFlowMgr_UpdateOnuInfo(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530654 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
655 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530656
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700657 wg := sync.WaitGroup{}
658
Girish Gowdra9602eb42020-09-09 15:50:39 -0700659 intfCount := NumPonPorts
660 onuCount := OnuIDEnd - OnuIDStart + 1
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700661
662 for i := 0; i < intfCount; i++ {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700663 for j := 1; j <= onuCount; j++ {
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700664 wg.Add(1)
665 go func(i uint32, j uint32) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400666 // TODO: actually verify success
Girish Gowdra9602eb42020-09-09 15:50:39 -0700667 _ = flowMgr[i].UpdateOnuInfo(ctx, i, i, fmt.Sprintf("onu-%d", i))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700668 wg.Done()
669 }(uint32(i), uint32(j))
670 }
671
672 }
673
674 wg.Wait()
675}
676
677func TestOpenOltFlowMgr_addGemPortToOnuInfoMap(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700678 intfNum := NumPonPorts
679 onuNum := OnuIDEnd - OnuIDStart + 1
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700680
681 // clean the flowMgr
Girish Gowdra9602eb42020-09-09 15:50:39 -0700682 for i := 0; i < intfNum; i++ {
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700683 flowMgr[i].onuGemInfo = make([]rsrcMgr.OnuGemInfo, 0)
Girish Gowdra9602eb42020-09-09 15:50:39 -0700684 }
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700685
686 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
687 defer cancel()
688
689 // Create OnuInfo
690 for i := 0; i < intfNum; i++ {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700691 for o := 1; o <= onuNum; o++ {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400692 // TODO: actually verify success
Girish Gowdra9602eb42020-09-09 15:50:39 -0700693 _ = flowMgr[i].UpdateOnuInfo(ctx, uint32(i), uint32(o), fmt.Sprintf("i%do%d", i, o-1))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700694 }
695 }
696
697 // Add gemPorts to OnuInfo in parallel threads
698 wg := sync.WaitGroup{}
699
Girish Gowdra9602eb42020-09-09 15:50:39 -0700700 for o := 1; o <= onuNum; o++ {
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700701 for i := 0; i < intfNum; i++ {
702 wg.Add(1)
703 go func(intfId uint32, onuId uint32) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700704 gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", intfId, onuId-1))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700705
Girish Gowdra9602eb42020-09-09 15:50:39 -0700706 flowMgr[intfId].addGemPortToOnuInfoMap(ctx, intfId, onuId, uint32(gemID))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700707 wg.Done()
708 }(uint32(i), uint32(o))
709 }
710 }
711
712 wg.Wait()
713
714 // check that each entry of onuGemInfo has the correct number of ONUs
715 for i := 0; i < intfNum; i++ {
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700716 lenofOnu := len(flowMgr[i].onuGemInfo)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700717 if onuNum != lenofOnu {
718 t.Errorf("OnuGemInfo length is not as expected len = %d, want %d", lenofOnu, onuNum)
719 }
720
Girish Gowdra9602eb42020-09-09 15:50:39 -0700721 for o := 1; o <= onuNum; o++ {
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700722 lenOfGemPorts := len(flowMgr[i].onuGemInfo[o-1].GemPorts)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700723 // check that each onuEntry has 1 gemPort
724 if lenOfGemPorts != 1 {
725 t.Errorf("Expected 1 GemPort per ONU, found %d", lenOfGemPorts)
726 }
727
728 // check that the value of the gemport is correct
Girish Gowdra9602eb42020-09-09 15:50:39 -0700729 gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", i, o-1))
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700730 currentValue := flowMgr[i].onuGemInfo[o-1].GemPorts[0]
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700731 if uint32(gemID) != currentValue {
732 t.Errorf("Expected GemPort value to be %d, found %d", gemID, currentValue)
733 }
734 }
kdarapu3248f9a2019-10-03 13:54:52 +0530735 }
736}
737
serkant.uluderya96af4932020-02-20 16:58:48 -0800738func TestOpenOltFlowMgr_deleteGemPortFromLocalCache(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700739 // Create fresh flowMgr instance
740 flowMgr = newMockFlowmgr()
serkant.uluderya96af4932020-02-20 16:58:48 -0800741 type args struct {
742 intfID uint32
743 onuID uint32
744 gemPortIDs []uint32
745 gemPortIDsToBeDeleted []uint32
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700746 gemPortIDsRemaining []uint32
serkant.uluderya96af4932020-02-20 16:58:48 -0800747 serialNum string
748 finalLength int
749 }
750 tests := []struct {
751 name string
752 args args
753 }{
754 // Add/Delete single gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700755 {"DeleteGemPortFromLocalCache1", args{0, 1, []uint32{1}, []uint32{1}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800756 // Delete all gemports
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700757 {"DeleteGemPortFromLocalCache2", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{1, 2, 3, 4}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800758 // Try to delete when there is no gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700759 {"DeleteGemPortFromLocalCache3", args{0, 1, []uint32{}, []uint32{1, 2}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800760 // Try to delete non-existent gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700761 {"DeleteGemPortFromLocalCache4", args{0, 1, []uint32{1}, []uint32{2}, []uint32{1}, "onu1", 1}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800762 // Try to delete two of the gem ports
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700763 {"DeleteGemPortFromLocalCache5", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{2, 4}, []uint32{1, 3}, "onu1", 2}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800764 }
765 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
766 defer cancel()
767 for _, tt := range tests {
768 t.Run(tt.name, func(t *testing.T) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400769 // TODO: should check returned errors are as expected?
Girish Gowdra9602eb42020-09-09 15:50:39 -0700770 _ = flowMgr[tt.args.intfID].UpdateOnuInfo(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum)
serkant.uluderya96af4932020-02-20 16:58:48 -0800771 for _, gemPort := range tt.args.gemPortIDs {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700772 flowMgr[tt.args.intfID].addGemPortToOnuInfoMap(ctx, tt.args.intfID, tt.args.onuID, gemPort)
serkant.uluderya96af4932020-02-20 16:58:48 -0800773 }
774 for _, gemPortDeleted := range tt.args.gemPortIDsToBeDeleted {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700775 flowMgr[tt.args.intfID].deleteGemPortFromLocalCache(ctx, tt.args.intfID, tt.args.onuID, gemPortDeleted)
serkant.uluderya96af4932020-02-20 16:58:48 -0800776 }
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700777 lenofGemPorts := len(flowMgr[tt.args.intfID].onuGemInfo[0].GemPorts)
serkant.uluderya96af4932020-02-20 16:58:48 -0800778 if lenofGemPorts != tt.args.finalLength {
779 t.Errorf("GemPorts length is not as expected len = %d, want %d", lenofGemPorts, tt.args.finalLength)
780 }
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700781 gemPorts := flowMgr[tt.args.intfID].onuGemInfo[0].GemPorts
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700782 if !reflect.DeepEqual(tt.args.gemPortIDsRemaining, gemPorts) {
783 t.Errorf("GemPorts are not as expected = %v, want %v", gemPorts, tt.args.gemPortIDsRemaining)
784 }
serkant.uluderya96af4932020-02-20 16:58:48 -0800785
786 })
787 }
788}
789
kdarapu3248f9a2019-10-03 13:54:52 +0530790func TestOpenOltFlowMgr_GetLogicalPortFromPacketIn(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530791 type args struct {
792 packetIn *openoltpb2.PacketIndication
793 }
794 tests := []struct {
795 name string
796 args args
797 want uint32
798 wantErr bool
799 }{
800 // TODO: Add test cases.
Esin Karamandf392e12020-12-16 13:33:09 +0000801 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 0, GemportId: 255, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 1, false},
Girish Gowdra9602eb42020-09-09 15:50:39 -0700802 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "nni", IntfId: 0, GemportId: 1, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 1048576, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530803 // Negative Test cases.
Girish Gowdra9602eb42020-09-09 15:50:39 -0700804 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 1, GemportId: 1, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 0, true},
Esin Karamandf392e12020-12-16 13:33:09 +0000805 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 0, GemportId: 257, FlowId: 100, PortNo: 0, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 16, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530806 }
npujarec5762e2020-01-01 14:08:48 +0530807 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
808 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530809 for _, tt := range tests {
810 t.Run(tt.name, func(t *testing.T) {
811
Girish Gowdra9602eb42020-09-09 15:50:39 -0700812 got, err := flowMgr[tt.args.packetIn.IntfId].GetLogicalPortFromPacketIn(ctx, tt.args.packetIn)
kdarapu3248f9a2019-10-03 13:54:52 +0530813 if (err != nil) != tt.wantErr {
814 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() error = %v, wantErr %v", err, tt.wantErr)
815 return
816 }
817 if got != tt.want {
818 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() = %v, want %v", got, tt.want)
819 }
820 })
821 }
822}
823
824func TestOpenOltFlowMgr_GetPacketOutGemPortID(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700825 // Create fresh flowMgr instance
826 flowMgr = newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530827
Esin Karaman7fb80c22020-07-16 14:23:33 +0000828 //untagged packet in hex string
829 untaggedStr := "01005e000002000000000001080046c00020000040000102fa140a000001e00000029404000017000705e10000fa"
830 untagged, err := hex.DecodeString(untaggedStr)
831 if err != nil {
832 t.Error("Unable to parse hex string", err)
833 panic(err)
834 }
Girish Gowdra9602eb42020-09-09 15:50:39 -0700835 //single-tagged packet in hex string. vlanID.pbit: 1.1
836 singleTaggedStr := "01005e0000010025ba48172481002001080046c0002000004000010257deab140023e0000001940400001164ee9b0000000000000000000000000000"
Esin Karaman7fb80c22020-07-16 14:23:33 +0000837 singleTagged, err := hex.DecodeString(singleTaggedStr)
838 if err != nil {
839 t.Error("Unable to parse hex string", err)
840 panic(err)
841 }
Girish Gowdra9602eb42020-09-09 15:50:39 -0700842 //double-tagged packet in hex string. vlanID.pbit: 210.0-0.0
843 doubleTaggedStr := "01005e000016deadbeefba118100021081000000080046000028000000000102c5b87f000001e0000016940400002200f8030000000104000000e10000fa"
Esin Karaman7fb80c22020-07-16 14:23:33 +0000844 doubleTagged, err := hex.DecodeString(doubleTaggedStr)
845 if err != nil {
846 t.Error("Unable to parse hex string", err)
847 panic(err)
848 }
849
kdarapu3248f9a2019-10-03 13:54:52 +0530850 type args struct {
851 intfID uint32
852 onuID uint32
853 portNum uint32
Esin Karaman7fb80c22020-07-16 14:23:33 +0000854 packet []byte
kdarapu3248f9a2019-10-03 13:54:52 +0530855 }
856 tests := []struct {
857 name string
858 args args
859 want uint32
860 wantErr bool
861 }{
862 // TODO: Add test cases.
Girish Gowdra9602eb42020-09-09 15:50:39 -0700863 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: untagged}, 1, false},
864 {"GetPacketOutGemPortID", args{intfID: 1, onuID: 2, portNum: 2, packet: singleTagged}, 2, false},
865 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: doubleTagged}, 1, false},
866 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 10, portNum: 10, packet: untagged}, 2, true},
867 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 3, packet: []byte{}}, 3, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530868 }
Esin Karaman7fb80c22020-07-16 14:23:33 +0000869
npujarec5762e2020-01-01 14:08:48 +0530870 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
871 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530872 for _, tt := range tests {
873 t.Run(tt.name, func(t *testing.T) {
874
Girish Gowdra9602eb42020-09-09 15:50:39 -0700875 got, err := flowMgr[tt.args.intfID].GetPacketOutGemPortID(ctx, tt.args.intfID, tt.args.onuID, tt.args.portNum, tt.args.packet)
Esin Karaman7fb80c22020-07-16 14:23:33 +0000876 if tt.wantErr {
877 if err == nil {
878 //error expected but got value
879 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, wantErr %v", got, tt.wantErr)
880 }
881 } else {
882 if err != nil {
883 //error is not expected but got error
884 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() error = %v, wantErr %v", err, tt.wantErr)
885 return
886 }
887 if got != tt.want {
888 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, want %v", got, tt.want)
889 }
kdarapu3248f9a2019-10-03 13:54:52 +0530890 }
kdarapu3248f9a2019-10-03 13:54:52 +0530891 })
892 }
893}
894
895func TestOpenOltFlowMgr_DeleteTechProfileInstance(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530896 type args struct {
897 intfID uint32
898 onuID uint32
899 uniID uint32
900 sn string
Gamze Abakafee36392019-10-03 11:17:24 +0000901 tpID uint32
kdarapu3248f9a2019-10-03 13:54:52 +0530902 }
903 tests := []struct {
904 name string
905 args args
906 wantErr bool
907 }{
908 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000909 {"DeleteTechProfileInstance", args{intfID: 0, onuID: 1, uniID: 1, sn: "", tpID: 64}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530910 }
npujarec5762e2020-01-01 14:08:48 +0530911 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
912 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530913 for _, tt := range tests {
914 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700915 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 {
kdarapu3248f9a2019-10-03 13:54:52 +0530916 t.Errorf("OpenOltFlowMgr.DeleteTechProfileInstance() error = %v, wantErr %v", err, tt.wantErr)
917 }
918 })
919 }
920}
kdarapub26b4502019-10-05 03:02:33 +0530921
922func TestOpenOltFlowMgr_checkAndAddFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000923 ctx := context.Background()
kdarapub26b4502019-10-05 03:02:33 +0530924 kw := make(map[string]uint64)
925 kw["table_id"] = 1
926 kw["meter_id"] = 1
927 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
928
929 // Upstream flow
930 fa := &fu.FlowArgs{
931 MatchFields: []*ofp.OfpOxmOfbField{
932 fu.InPort(536870912),
933 fu.Metadata_ofp(1),
934 fu.IpProto(17), // dhcp
Gamze Abakafee36392019-10-03 11:17:24 +0000935 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300936 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530937 },
938 Actions: []*ofp.OfpAction{
939 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
940 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800941 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530942 fu.PushVlan(0x8100),
943 },
944 KV: kw,
945 }
946
947 // EAPOL
948 fa2 := &fu.FlowArgs{
949 MatchFields: []*ofp.OfpOxmOfbField{
950 fu.InPort(536870912),
951 fu.Metadata_ofp(1),
952 fu.EthType(0x888E),
953 fu.VlanPcp(1),
954 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
955 },
956 Actions: []*ofp.OfpAction{
957 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
958 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800959 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530960 fu.PushVlan(0x8100),
961 },
962 KV: kw,
963 }
964
965 // HSIA
966 fa3 := &fu.FlowArgs{
967 MatchFields: []*ofp.OfpOxmOfbField{
968 fu.InPort(536870912),
969 fu.Metadata_ofp(1),
970 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300971 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530972 },
973 Actions: []*ofp.OfpAction{
974 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300975 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800976 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530977 fu.PushVlan(0x8100),
978 },
979 KV: kw,
980 }
981
982 fa4 := &fu.FlowArgs{
983 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800984 fu.InPort(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530985 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300986 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530987 fu.VlanPcp(1),
988 },
989 Actions: []*ofp.OfpAction{
990 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300991 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
kdarapub26b4502019-10-05 03:02:33 +0530992 fu.Output(536870912),
993 fu.PopVlan(),
994 },
995 KV: kw,
996 }
997
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300998 // PPPOED
999 pppoedFA := &fu.FlowArgs{
1000 MatchFields: []*ofp.OfpOxmOfbField{
1001 fu.InPort(536870912),
1002 fu.Metadata_ofp(1),
1003 fu.EthType(0x8863),
1004 fu.VlanPcp(1),
1005 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
1006 },
1007 Actions: []*ofp.OfpAction{
1008 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1009 fu.Output(1048576),
1010 fu.PushVlan(0x8100),
1011 },
1012 KV: kw,
1013 }
1014
kdarapub26b4502019-10-05 03:02:33 +05301015 classifierInfo := make(map[string]interface{})
1016 actionInfo := make(map[string]interface{})
1017 classifierInfo2 := make(map[string]interface{})
1018 actionInfo2 := make(map[string]interface{})
1019 classifierInfo3 := make(map[string]interface{})
1020 actionInfo3 := make(map[string]interface{})
1021 classifierInfo4 := make(map[string]interface{})
1022 actionInfo4 := make(map[string]interface{})
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001023 classifierInfo5 := make(map[string]interface{})
1024 actionInfo5 := make(map[string]interface{})
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001025 flow, _ := fu.MkFlowStat(fa)
1026 flow2, _ := fu.MkFlowStat(fa2)
1027 flow3, _ := fu.MkFlowStat(fa3)
1028 flow4, _ := fu.MkFlowStat(fa4)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001029 flow5, _ := fu.MkFlowStat(pppoedFA)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001030 formulateClassifierInfoFromFlow(ctx, classifierInfo, flow)
1031 formulateClassifierInfoFromFlow(ctx, classifierInfo2, flow2)
1032 formulateClassifierInfoFromFlow(ctx, classifierInfo3, flow3)
1033 formulateClassifierInfoFromFlow(ctx, classifierInfo4, flow4)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001034 formulateClassifierInfoFromFlow(ctx, classifierInfo5, flow5)
kdarapub26b4502019-10-05 03:02:33 +05301035
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001036 err := formulateActionInfoFromFlow(ctx, actionInfo, classifierInfo, flow)
kdarapub26b4502019-10-05 03:02:33 +05301037 if err != nil {
1038 // Error logging is already done in the called function
1039 // So just return in case of error
1040 return
1041 }
1042
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001043 err = formulateActionInfoFromFlow(ctx, actionInfo2, classifierInfo2, flow2)
kdarapub26b4502019-10-05 03:02:33 +05301044 if err != nil {
1045 // Error logging is already done in the called function
1046 // So just return in case of error
1047 return
1048 }
1049
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001050 err = formulateActionInfoFromFlow(ctx, actionInfo3, classifierInfo3, flow3)
kdarapub26b4502019-10-05 03:02:33 +05301051 if err != nil {
1052 // Error logging is already done in the called function
1053 // So just return in case of error
1054 return
1055 }
1056
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001057 err = formulateActionInfoFromFlow(ctx, actionInfo4, classifierInfo4, flow4)
kdarapub26b4502019-10-05 03:02:33 +05301058 if err != nil {
1059 // Error logging is already done in the called function
1060 // So just return in case of error
1061 return
1062 }
1063
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001064 err = formulateActionInfoFromFlow(ctx, actionInfo5, classifierInfo5, flow5)
1065 if err != nil {
1066 // Error logging is already done in the called function
1067 // So just return in case of error
1068 return
1069 }
1070
kdarapub26b4502019-10-05 03:02:33 +05301071 TpInst := &tp.TechProfile{
1072 Name: "Test-Tech-Profile",
1073 SubscriberIdentifier: "257",
1074 ProfileType: "Mock",
1075 Version: 1,
1076 NumGemPorts: 4,
kdarapub26b4502019-10-05 03:02:33 +05301077 InstanceCtrl: tp.InstanceControl{
1078 Onu: "1",
1079 Uni: "16",
1080 },
1081 }
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001082 TpInst.UsScheduler.Priority = 1
1083 TpInst.UsScheduler.Direction = "upstream"
1084 TpInst.UsScheduler.AllocID = 1
1085 TpInst.UsScheduler.AdditionalBw = "None"
1086 TpInst.UsScheduler.QSchedPolicy = "PQ"
1087 TpInst.UsScheduler.Weight = 4
1088
1089 TpInst.DsScheduler.Priority = 1
1090 TpInst.DsScheduler.Direction = "upstream"
1091 TpInst.DsScheduler.AllocID = 1
1092 TpInst.DsScheduler.AdditionalBw = "None"
1093 TpInst.DsScheduler.QSchedPolicy = "PQ"
1094 TpInst.DsScheduler.Weight = 4
1095
1096 TpInst.UpstreamGemPortAttributeList = make([]tp.IGemPortAttribute, 4)
1097 TpInst.UpstreamGemPortAttributeList[0].GemportID = 1
1098 TpInst.UpstreamGemPortAttributeList[0].PbitMap = "0b00000011"
1099 TpInst.UpstreamGemPortAttributeList[0].GemportID = 2
1100 TpInst.UpstreamGemPortAttributeList[0].PbitMap = "0b00001100"
1101 TpInst.UpstreamGemPortAttributeList[0].GemportID = 3
1102 TpInst.UpstreamGemPortAttributeList[0].PbitMap = "0b00110000"
1103 TpInst.UpstreamGemPortAttributeList[0].GemportID = 4
1104 TpInst.UpstreamGemPortAttributeList[0].PbitMap = "0b11000000"
1105
1106 TpInst.DownstreamGemPortAttributeList = make([]tp.IGemPortAttribute, 4)
1107 TpInst.DownstreamGemPortAttributeList[0].GemportID = 1
1108 TpInst.DownstreamGemPortAttributeList[0].PbitMap = "0b00000011"
1109 TpInst.DownstreamGemPortAttributeList[0].GemportID = 2
1110 TpInst.DownstreamGemPortAttributeList[0].PbitMap = "0b00001100"
1111 TpInst.DownstreamGemPortAttributeList[0].GemportID = 3
1112 TpInst.DownstreamGemPortAttributeList[0].PbitMap = "0b00110000"
1113 TpInst.DownstreamGemPortAttributeList[0].GemportID = 4
1114 TpInst.DownstreamGemPortAttributeList[0].PbitMap = "0b11000000"
kdarapub26b4502019-10-05 03:02:33 +05301115
kdarapub26b4502019-10-05 03:02:33 +05301116 type args struct {
1117 args map[string]uint32
1118 classifierInfo map[string]interface{}
1119 actionInfo map[string]interface{}
1120 flow *ofp.OfpFlowStats
1121 gemPort uint32
1122 intfID uint32
1123 onuID uint32
1124 uniID uint32
1125 portNo uint32
1126 TpInst *tp.TechProfile
1127 allocID []uint32
1128 gemPorts []uint32
1129 TpID uint32
1130 uni string
1131 }
1132 tests := []struct {
Kent Hagermane6ff1012020-07-14 15:07:53 -04001133 name string
1134 args args
kdarapub26b4502019-10-05 03:02:33 +05301135 }{
1136 {
1137 name: "checkAndAddFlow-1",
1138 args: args{
1139 args: nil,
1140 classifierInfo: classifierInfo,
1141 actionInfo: actionInfo,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001142 flow: flow,
kdarapub26b4502019-10-05 03:02:33 +05301143 gemPort: 1,
1144 intfID: 1,
1145 onuID: 1,
1146 uniID: 16,
1147 portNo: 1,
1148 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001149 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301150 gemPorts: []uint32{1, 2, 3, 4},
1151 TpID: 64,
1152 uni: "16",
1153 },
1154 },
1155 {
1156 name: "checkAndAddFlow-2",
1157 args: args{
1158 args: nil,
1159 classifierInfo: classifierInfo2,
1160 actionInfo: actionInfo2,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001161 flow: flow2,
kdarapub26b4502019-10-05 03:02:33 +05301162 gemPort: 1,
1163 intfID: 1,
1164 onuID: 1,
1165 uniID: 16,
1166 portNo: 1,
1167 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001168 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301169 gemPorts: []uint32{1, 2, 3, 4},
1170 TpID: 64,
1171 uni: "16",
1172 },
1173 },
1174 {
1175 name: "checkAndAddFlow-3",
1176 args: args{
1177 args: nil,
1178 classifierInfo: classifierInfo3,
1179 actionInfo: actionInfo3,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001180 flow: flow3,
kdarapub26b4502019-10-05 03:02:33 +05301181 gemPort: 1,
1182 intfID: 1,
1183 onuID: 1,
1184 uniID: 16,
1185 portNo: 1,
1186 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001187 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301188 gemPorts: []uint32{1, 2, 3, 4},
1189 TpID: 64,
1190 uni: "16",
1191 },
1192 },
1193 {
1194 name: "checkAndAddFlow-4",
1195 args: args{
1196 args: nil,
1197 classifierInfo: classifierInfo4,
1198 actionInfo: actionInfo4,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001199 flow: flow4,
kdarapub26b4502019-10-05 03:02:33 +05301200 gemPort: 1,
1201 intfID: 1,
1202 onuID: 1,
1203 uniID: 16,
1204 portNo: 1,
1205 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001206 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301207 gemPorts: []uint32{1, 2, 3, 4},
1208 TpID: 64,
1209 uni: "16",
1210 },
1211 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001212 {
1213 name: "checkAndAddFlow-5",
1214 args: args{
1215 args: nil,
1216 classifierInfo: classifierInfo5,
1217 actionInfo: actionInfo5,
1218 flow: flow5,
1219 gemPort: 1,
1220 intfID: 1,
1221 onuID: 1,
1222 uniID: 16,
1223 portNo: 1,
1224 TpInst: TpInst,
1225 allocID: []uint32{0x8001},
1226 gemPorts: []uint32{1, 2, 3, 4},
1227 TpID: 64,
1228 uni: "16",
1229 },
1230 },
kdarapub26b4502019-10-05 03:02:33 +05301231 }
npujarec5762e2020-01-01 14:08:48 +05301232 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1233 defer cancel()
kdarapub26b4502019-10-05 03:02:33 +05301234 for _, tt := range tests {
1235 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -07001236 flowMgr[tt.args.intfID].checkAndAddFlow(ctx, tt.args.args, tt.args.classifierInfo, tt.args.actionInfo, tt.args.flow,
Gamze Abakafee36392019-10-03 11:17:24 +00001237 tt.args.TpInst, tt.args.gemPorts, tt.args.TpID, tt.args.uni)
kdarapub26b4502019-10-05 03:02:33 +05301238 })
1239 }
1240}
Esin Karamanccb714b2019-11-29 15:02:06 +00001241
Esin Karamand519bbf2020-07-01 11:16:03 +00001242func TestOpenOltFlowMgr_TestMulticastFlowAndGroup(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301243 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1244 defer cancel()
Esin Karamanccb714b2019-11-29 15:02:06 +00001245 //create group
1246 group := newGroup(2, []uint32{1})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001247 err := flowMgr[0].grpMgr.AddGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001248 if err != nil {
1249 t.Error("group-add failed", err)
1250 return
1251 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001252 //create multicast flow
1253 multicastFlowArgs := &fu.FlowArgs{
1254 MatchFields: []*ofp.OfpOxmOfbField{
Esin Karamand519bbf2020-07-01 11:16:03 +00001255 fu.InPort(1048576),
Esin Karamanccb714b2019-11-29 15:02:06 +00001256 fu.VlanVid(660), //vlan
1257 fu.Metadata_ofp(uint64(66)), //inner vlan
1258 fu.EthType(0x800), //ipv4
1259 fu.Ipv4Dst(3809869825), //227.22.0.1
1260 },
1261 Actions: []*ofp.OfpAction{
1262 fu.Group(1),
1263 },
1264 }
divyadesaid26f6b12020-03-19 06:30:28 +00001265 ofpStats, _ := fu.MkFlowStat(multicastFlowArgs)
Esin Karamand519bbf2020-07-01 11:16:03 +00001266 fmt.Println(ofpStats.Id)
Girish Gowdra9602eb42020-09-09 15:50:39 -07001267 err = flowMgr[0].AddFlow(ctx, ofpStats, &voltha.FlowMetadata{})
Esin Karamand519bbf2020-07-01 11:16:03 +00001268 if err != nil {
1269 t.Error("Multicast flow-add failed", err)
1270 return
1271 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001272
1273 //add bucket to the group
1274 group = newGroup(2, []uint32{1, 2})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001275 err = flowMgr[0].grpMgr.ModifyGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001276 if err != nil {
1277 t.Error("modify-group failed", err)
1278 return
1279 }
1280 //remove the multicast flow
Girish Gowdra9602eb42020-09-09 15:50:39 -07001281 err = flowMgr[0].RemoveFlow(ctx, ofpStats)
Esin Karamand519bbf2020-07-01 11:16:03 +00001282 if err != nil {
1283 t.Error("Multicast flow-remove failed", err)
1284 return
1285 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001286
Esin Karamand519bbf2020-07-01 11:16:03 +00001287 //remove the group
Girish Gowdra9602eb42020-09-09 15:50:39 -07001288 err = flowMgr[0].grpMgr.DeleteGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001289 if err != nil {
1290 t.Error("delete-group failed", err)
1291 return
1292 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001293}
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001294
1295func TestOpenOltFlowMgr_TestRouteFlowToOnuChannel(t *testing.T) {
1296 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1297 defer cancel()
1298 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/core", log.DebugLevel)
1299 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager", log.DebugLevel)
1300 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/pkg/mocks", log.DebugLevel)
Girish Gowdra0aca4982021-01-04 12:44:27 -08001301 kwTable1Meter1 := make(map[string]uint64)
1302 kwTable1Meter1["table_id"] = 1
1303 kwTable1Meter1["meter_id"] = 1
1304 kwTable1Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
1305
1306 kwTable0Meter1 := make(map[string]uint64)
1307 kwTable0Meter1["table_id"] = 0
1308 kwTable0Meter1["meter_id"] = 1
1309 kwTable0Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001310
1311 flowMetadata1 := voltha.FlowMetadata{Meters: []*voltha.OfpMeterConfig{
1312 {
1313 Flags: 5,
1314 MeterId: 1,
1315 Bands: []*voltha.OfpMeterBandHeader{
1316 {
1317 Type: voltha.OfpMeterBandType_OFPMBT_DROP,
1318 Rate: 16000,
Gamze Abaka01174422021-03-10 06:55:27 +00001319 BurstSize: 0,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001320 },
1321 {
1322 Type: voltha.OfpMeterBandType_OFPMBT_DROP,
1323 Rate: 32000,
1324 BurstSize: 30,
1325 },
1326 {
1327 Type: voltha.OfpMeterBandType_OFPMBT_DROP,
1328 Rate: 64000,
1329 BurstSize: 30,
1330 },
1331 },
1332 },
1333 }}
1334
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001335 // Downstream LLDP Trap from NNI0 flow
1336 fa0 := &fu.FlowArgs{
1337 MatchFields: []*ofp.OfpOxmOfbField{
1338 fu.InPort(1048576),
1339 fu.EthType(35020),
1340 },
1341 Actions: []*ofp.OfpAction{
1342 fu.Output(4294967293),
1343 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001344 KV: make(map[string]uint64),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001345 }
1346
1347 // Upstream flow DHCP flow - ONU1 UNI0 PON0
1348 fa1 := &fu.FlowArgs{
1349 MatchFields: []*ofp.OfpOxmOfbField{
1350 fu.InPort(536870912),
1351 fu.Metadata_ofp(1),
1352 fu.IpProto(17), // dhcp
1353 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001354 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001355 fu.TunnelId(16),
1356 },
1357 Actions: []*ofp.OfpAction{
1358 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1359 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1360 fu.Output(2147483645),
1361 fu.PushVlan(0x8100),
1362 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001363 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001364 }
1365
1366 // Upstream EAPOL - ONU1 UNI0 PON0
1367 fa2 := &fu.FlowArgs{
1368 MatchFields: []*ofp.OfpOxmOfbField{
1369 fu.InPort(536870912),
1370 fu.Metadata_ofp(1),
1371 fu.EthType(0x888E),
1372 fu.VlanPcp(1),
1373 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
1374 fu.TunnelId(16),
1375 },
1376 Actions: []*ofp.OfpAction{
1377 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1378 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1379 fu.Output(2147483645),
1380 fu.PushVlan(0x8100),
1381 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001382 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001383 }
1384
1385 // Upstream HSIA - ONU1 UNI0 PON0
1386 fa3 := &fu.FlowArgs{
1387 MatchFields: []*ofp.OfpOxmOfbField{
1388 fu.InPort(536870912),
1389 fu.Metadata_ofp(1),
1390 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001391 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001392 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001393 },
1394 Actions: []*ofp.OfpAction{
1395 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001396 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001397 fu.Output(1048576),
1398 fu.PushVlan(0x8100),
1399 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001400 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001401 }
1402
1403 // Downstream HSIA - ONU1 UNI0 PON0
1404 fa4 := &fu.FlowArgs{
1405 MatchFields: []*ofp.OfpOxmOfbField{
1406 fu.InPort(1048576),
1407 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001408 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001409 fu.VlanPcp(1),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001410 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001411 },
1412 Actions: []*ofp.OfpAction{
1413 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001414 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001415 fu.Output(536870912),
1416 fu.PopVlan(),
1417 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001418 KV: kwTable0Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001419 }
1420
1421 // Upstream flow DHCP flow - ONU1 UNI0 PON15
1422 fa5 := &fu.FlowArgs{
1423 MatchFields: []*ofp.OfpOxmOfbField{
1424 fu.InPort(536870927),
1425 fu.Metadata_ofp(1),
1426 fu.IpProto(17), // dhcp
1427 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001428 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001429 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001430 },
1431 Actions: []*ofp.OfpAction{
1432 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1433 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259)),
1434 fu.Output(2147483645),
1435 fu.PushVlan(0x8100),
1436 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001437 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001438 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001439
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001440 // Upstream EAPOL - ONU1 UNI0 PON15
1441 fa6 := &fu.FlowArgs{
1442 MatchFields: []*ofp.OfpOxmOfbField{
1443 fu.InPort(536870927),
1444 fu.Metadata_ofp(1),
1445 fu.EthType(0x888E),
1446 fu.VlanPcp(1),
1447 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001448 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001449 },
1450 Actions: []*ofp.OfpAction{
1451 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1452 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1453 fu.Output(2147483645),
1454 fu.PushVlan(0x8100),
1455 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001456 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001457 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001458
1459 // Upstream PPPOED - ONU1 UNI0 PON0
1460 fa7 := &fu.FlowArgs{
1461 MatchFields: []*ofp.OfpOxmOfbField{
1462 fu.InPort(536870912),
1463 fu.Metadata_ofp(1),
1464 fu.EthType(0x8863),
1465 fu.VlanPcp(1),
1466 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
1467 fu.TunnelId(16),
1468 },
1469 Actions: []*ofp.OfpAction{
1470 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1471 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1472 fu.Output(2147483645),
1473 fu.PushVlan(0x8100),
1474 },
1475 KV: kwTable1Meter1,
1476 }
1477
1478 // Upstream PPPOED - ONU1 UNI0 PON15
1479 fa8 := &fu.FlowArgs{
1480 MatchFields: []*ofp.OfpOxmOfbField{
1481 fu.InPort(536870927),
1482 fu.Metadata_ofp(1),
1483 fu.EthType(0x8863),
1484 fu.VlanPcp(1),
1485 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
1486 fu.TunnelId(16),
1487 },
1488 Actions: []*ofp.OfpAction{
1489 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1490 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1491 fu.Output(2147483645),
1492 fu.PushVlan(0x8100),
1493 },
1494 KV: kwTable1Meter1,
1495 }
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001496 flow0, _ := fu.MkFlowStat(fa0)
1497 flow1, _ := fu.MkFlowStat(fa1)
1498 flow2, _ := fu.MkFlowStat(fa2)
1499 flow3, _ := fu.MkFlowStat(fa3)
1500 flow4, _ := fu.MkFlowStat(fa4)
1501
1502 flow5, _ := fu.MkFlowStat(fa5)
1503 flow6, _ := fu.MkFlowStat(fa6)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001504 flow7, _ := fu.MkFlowStat(fa7)
1505 flow8, _ := fu.MkFlowStat(fa8)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001506
1507 type args struct {
1508 ctx context.Context
1509 flow *ofp.OfpFlowStats
1510 addFlow bool
1511 flowMetadata *voltha.FlowMetadata
1512 }
1513 tests := []struct {
1514 name string
1515 args args
1516 wantErr bool
1517 returnedErr error
1518 }{
1519 {
1520 name: "RouteFlowToOnuChannel-0",
1521 args: args{
1522 ctx: ctx,
1523 flow: flow0,
1524 addFlow: true,
1525 flowMetadata: &flowMetadata1,
1526 },
1527 wantErr: false,
1528 },
1529 {
1530 name: "RouteFlowToOnuChannel-1",
1531 args: args{
1532 ctx: ctx,
1533 flow: flow1,
1534 addFlow: true,
1535 flowMetadata: &flowMetadata1,
1536 },
1537 wantErr: false,
1538 },
1539 {
1540 name: "RouteFlowToOnuChannel-2",
1541 args: args{
1542 ctx: ctx,
1543 flow: flow2,
1544 addFlow: true,
1545 flowMetadata: &flowMetadata1,
1546 },
1547 wantErr: false,
1548 },
1549 {
1550 name: "RouteFlowToOnuChannel-3",
1551 args: args{
1552 ctx: ctx,
1553 flow: flow3,
1554 addFlow: true,
1555 flowMetadata: &flowMetadata1,
1556 },
1557 wantErr: false,
1558 },
1559 {
1560 name: "RouteFlowToOnuChannel-4",
1561 args: args{
1562 ctx: ctx,
1563 flow: flow4,
1564 addFlow: true,
1565 flowMetadata: &flowMetadata1,
1566 },
1567 wantErr: false,
1568 },
1569 {
1570 name: "RouteFlowToOnuChannel-5",
1571 args: args{
1572 ctx: ctx,
1573 flow: flow1,
1574 addFlow: false,
1575 flowMetadata: &flowMetadata1,
1576 },
1577 wantErr: false,
1578 },
1579 {
1580 name: "RouteFlowToOnuChannel-6",
1581 args: args{
1582 ctx: ctx,
1583 flow: flow1,
1584 addFlow: true,
Girish Gowdra0aca4982021-01-04 12:44:27 -08001585 flowMetadata: &flowMetadata1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001586 },
1587 wantErr: true,
1588 },
1589 {
1590 name: "RouteFlowToOnuChannel-7",
1591 args: args{
1592 ctx: ctx,
1593 flow: flow5,
1594 addFlow: true,
1595 flowMetadata: &flowMetadata1,
1596 },
1597 wantErr: false,
1598 },
1599 {
1600 name: "RouteFlowToOnuChannel-8",
1601 args: args{
1602 ctx: ctx,
1603 flow: flow6,
1604 addFlow: true,
1605 flowMetadata: &flowMetadata1,
1606 },
1607 wantErr: false,
1608 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001609 {
1610 name: "RouteFlowToOnuChannel-9",
1611 args: args{
1612 ctx: ctx,
1613 flow: flow7,
1614 addFlow: true,
1615 flowMetadata: &flowMetadata1,
1616 },
1617 wantErr: false,
1618 },
1619 {
1620 name: "RouteFlowToOnuChannel-10",
1621 args: args{
1622 ctx: ctx,
1623 flow: flow8,
1624 addFlow: true,
1625 flowMetadata: &flowMetadata1,
1626 },
1627 wantErr: false,
1628 },
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001629 }
1630
1631 var wg sync.WaitGroup
1632 defer wg.Wait() // wait for all go routines to complete
1633 for _, tt := range tests {
1634 t.Run(tt.name, func(t *testing.T) {
1635 wg.Add(1) // one per go routine
1636 go func() {
1637 defer wg.Done()
1638 tt.returnedErr = flowMgr[0].RouteFlowToOnuChannel(tt.args.ctx, tt.args.flow, tt.args.addFlow, tt.args.flowMetadata)
1639 if (tt.wantErr == false && tt.returnedErr != nil) || (tt.wantErr == true && tt.returnedErr == nil) {
1640 t.Errorf("OpenOltFlowMgr.RouteFlowToOnuChannel() error = %v, wantErr %v", tt.returnedErr, tt.wantErr)
1641 }
1642 }()
1643 })
1644 }
1645}