blob: a3dd06243706c434b41891c4c9405fd8c5171caf [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
17//Package adaptercore provides the utility for olt devices, flows and statistics
18package adaptercore
19
20import (
npujarec5762e2020-01-01 14:08:48 +053021 "context"
Gamze Abakafee36392019-10-03 11:17:24 +000022 "fmt"
kdarapu3248f9a2019-10-03 13:54:52 +053023 "testing"
npujarec5762e2020-01-01 14:08:48 +053024 "time"
kdarapu3248f9a2019-10-03 13:54:52 +053025
Esin Karamanccb714b2019-11-29 15:02:06 +000026 "github.com/opencord/voltha-protos/v3/go/voltha"
kdarapub26b4502019-10-05 03:02:33 +053027
Esin Karamanccb714b2019-11-29 15:02:06 +000028 "github.com/opencord/voltha-lib-go/v3/pkg/db"
29 fu "github.com/opencord/voltha-lib-go/v3/pkg/flows"
30 "github.com/opencord/voltha-lib-go/v3/pkg/log"
31 tp "github.com/opencord/voltha-lib-go/v3/pkg/techprofile"
kdarapu3248f9a2019-10-03 13:54:52 +053032 "github.com/opencord/voltha-openolt-adapter/adaptercore/resourcemanager"
kdarapub26b4502019-10-05 03:02:33 +053033 rsrcMgr "github.com/opencord/voltha-openolt-adapter/adaptercore/resourcemanager"
kdarapu3248f9a2019-10-03 13:54:52 +053034 "github.com/opencord/voltha-openolt-adapter/mocks"
Esin Karamanccb714b2019-11-29 15:02:06 +000035 ofp "github.com/opencord/voltha-protos/v3/go/openflow_13"
36 "github.com/opencord/voltha-protos/v3/go/openolt"
37 openoltpb2 "github.com/opencord/voltha-protos/v3/go/openolt"
38 tp_pb "github.com/opencord/voltha-protos/v3/go/tech_profile"
kdarapu3248f9a2019-10-03 13:54:52 +053039)
40
kdarapub26b4502019-10-05 03:02:33 +053041var flowMgr *OpenOltFlowMgr
42
kdarapu3248f9a2019-10-03 13:54:52 +053043func init() {
44 log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
kdarapub26b4502019-10-05 03:02:33 +053045 flowMgr = newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +053046}
47func newMockResourceMgr() *resourcemanager.OpenOltResourceMgr {
48 ranges := []*openolt.DeviceInfo_DeviceResourceRanges{
49 {IntfIds: []uint32{0, 1, 2}}}
50
51 deviceinfo := &openolt.DeviceInfo{Vendor: "openolt", Model: "openolt", HardwareVersion: "1.0", FirmwareVersion: "1.0",
52 DeviceId: "olt", DeviceSerialNumber: "openolt", PonPorts: 3, Technology: "Default",
53 OnuIdStart: 1, OnuIdEnd: 1, AllocIdStart: 1, AllocIdEnd: 1,
54 GemportIdStart: 1, GemportIdEnd: 1, FlowIdStart: 1, FlowIdEnd: 1,
55 Ranges: ranges,
56 }
npujarec5762e2020-01-01 14:08:48 +053057 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
58 defer cancel()
59 rsrMgr := resourcemanager.NewResourceMgr(ctx, "olt", "127.0.0.1:2379", "etcd", "olt", deviceinfo)
kdarapub26b4502019-10-05 03:02:33 +053060 for key := range rsrMgr.ResourceMgrs {
sbarbaria8910ba2019-11-05 10:12:23 -050061 rsrMgr.ResourceMgrs[key].KVStore = &db.Backend{}
kdarapub26b4502019-10-05 03:02:33 +053062 rsrMgr.ResourceMgrs[key].KVStore.Client = &mocks.MockKVClient{}
63 rsrMgr.ResourceMgrs[key].TechProfileMgr = mocks.MockTechProfile{TpID: key}
64 }
kdarapu3248f9a2019-10-03 13:54:52 +053065 return rsrMgr
66}
67
68func newMockFlowmgr() *OpenOltFlowMgr {
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +053069 rMgr := newMockResourceMgr()
kdarapu3248f9a2019-10-03 13:54:52 +053070 dh := newMockDeviceHandler()
71
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +053072 rMgr.KVStore = &db.Backend{}
73 rMgr.KVStore.Client = &mocks.MockKVClient{}
kdarapu3248f9a2019-10-03 13:54:52 +053074
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +053075 dh.resourceMgr = rMgr
npujarec5762e2020-01-01 14:08:48 +053076 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
77 defer cancel()
78 flwMgr := NewFlowManager(ctx, dh, rMgr)
kdarapu3248f9a2019-10-03 13:54:52 +053079
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +053080 onuGemInfo1 := make([]rsrcMgr.OnuGemInfo, 2)
81 onuGemInfo2 := make([]rsrcMgr.OnuGemInfo, 2)
82 onuGemInfo1[0] = rsrcMgr.OnuGemInfo{OnuID: 1, SerialNumber: "1", IntfID: 1, GemPorts: []uint32{1}}
83 onuGemInfo2[1] = rsrcMgr.OnuGemInfo{OnuID: 2, SerialNumber: "2", IntfID: 2, GemPorts: []uint32{2}}
84 flwMgr.onuGemInfo[1] = onuGemInfo1
85 flwMgr.onuGemInfo[2] = onuGemInfo2
kdarapu3248f9a2019-10-03 13:54:52 +053086
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +053087 packetInGemPort := make(map[rsrcMgr.PacketInInfoKey]uint32)
88 packetInGemPort[rsrcMgr.PacketInInfoKey{IntfID: 1, OnuID: 1, LogicalPort: 1}] = 1
89 packetInGemPort[rsrcMgr.PacketInInfoKey{IntfID: 2, OnuID: 2, LogicalPort: 2}] = 2
kdarapu3248f9a2019-10-03 13:54:52 +053090
91 flwMgr.packetInGemPort = packetInGemPort
Amit Ghoshd4cbe482019-11-21 12:07:14 +000092 tps := make(map[uint32]tp.TechProfileIf)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +053093 for key := range rMgr.ResourceMgrs {
kdarapub26b4502019-10-05 03:02:33 +053094 tps[key] = mocks.MockTechProfile{TpID: key}
kdarapu3248f9a2019-10-03 13:54:52 +053095 }
96 flwMgr.techprofile = tps
Esin Karamanccb714b2019-11-29 15:02:06 +000097
98 interface2mcastQeueuMap := make(map[uint32]*queueInfoBrief)
99 interface2mcastQeueuMap[0] = &queueInfoBrief{
100 gemPortID: 4000,
101 servicePriority: 3,
102 }
103 flwMgr.interfaceToMcastQueueMap = interface2mcastQeueuMap
kdarapu3248f9a2019-10-03 13:54:52 +0530104 return flwMgr
105}
kdarapub26b4502019-10-05 03:02:33 +0530106
kdarapu3248f9a2019-10-03 13:54:52 +0530107func TestOpenOltFlowMgr_CreateSchedulerQueues(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530108 // flowMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530109
110 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"
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 }
129 type args struct {
130 Dir tp_pb.Direction
131 IntfID uint32
132 OnuID uint32
133 UniID uint32
134 UniPort uint32
135 TpInst *tp.TechProfile
136 MeterID uint32
137 flowMetadata *voltha.FlowMetadata
138 }
139 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +0000140 name string
141 schedQueue schedQueue
142 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +0530143 }{
144 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000145 {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 1, flowmetadata}, false},
146 {"CreateSchedulerQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 1, flowmetadata}, false},
147 {"CreateSchedulerQueues-3", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 2, flowmetadata}, true},
148 {"CreateSchedulerQueues-4", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 2, flowmetadata}, true},
149 {"CreateSchedulerQueues-5", schedQueue{tp_pb.Direction_UPSTREAM, 2, 2, 2, 64, 2, tprofile, 2, flowmetadata}, true},
150 {"CreateSchedulerQueues-6", schedQueue{tp_pb.Direction_DOWNSTREAM, 2, 2, 2, 65, 2, tprofile2, 2, flowmetadata}, true},
151 {"CreateSchedulerQueues-13", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 1, flowmetadata}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530152 //Negative testcases
Gamze Abakafee36392019-10-03 11:17:24 +0000153 {"CreateSchedulerQueues-7", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 1, &voltha.FlowMetadata{}}, true},
154 {"CreateSchedulerQueues-8", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 0, &voltha.FlowMetadata{}}, true},
155 {"CreateSchedulerQueues-9", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 1, &voltha.FlowMetadata{}}, true},
156 {"CreateSchedulerQueues-10", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 2, &voltha.FlowMetadata{}}, true},
157 {"CreateSchedulerQueues-11", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 2, &voltha.FlowMetadata{}}, true},
158 {"CreateSchedulerQueues-12", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 2, nil}, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530159 }
npujarec5762e2020-01-01 14:08:48 +0530160 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
161 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530162 for _, tt := range tests {
163 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530164 if err := flowMgr.CreateSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530165 t.Errorf("OpenOltFlowMgr.CreateSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr)
166 }
167 })
168 }
169}
170
171func TestOpenOltFlowMgr_RemoveSchedulerQueues(t *testing.T) {
172
kdarapub26b4502019-10-05 03:02:33 +0530173 // flowMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530174 tprofile := &tp.TechProfile{Name: "tp1", SubscriberIdentifier: "subscriber1",
Girish Gowdra54934262019-11-13 14:19:55 +0530175 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
kdarapu3248f9a2019-10-03 13:54:52 +0530176 InstanceCtrl: tp.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"},
177 }
178 tprofile.UsScheduler.Direction = "UPSTREAM"
179 tprofile.UsScheduler.AdditionalBw = "AdditionalBW_None"
180 tprofile.UsScheduler.QSchedPolicy = "WRR"
181
182 tprofile2 := tprofile
183 tprofile2.DsScheduler.Direction = "DOWNSTREAM"
184 tprofile2.DsScheduler.AdditionalBw = "AdditionalBW_None"
185 tprofile2.DsScheduler.QSchedPolicy = "WRR"
186 //defTprofile := &tp.DefaultTechProfile{}
187 type args struct {
188 Dir tp_pb.Direction
189 IntfID uint32
190 OnuID uint32
191 UniID uint32
192 UniPort uint32
193 TpInst *tp.TechProfile
194 }
195 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +0000196 name string
197 schedQueue schedQueue
198 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +0530199 }{
200 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000201 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 0, nil}, false},
202 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530203 // negative test cases
Gamze Abakafee36392019-10-03 11:17:24 +0000204 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
205 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530206 }
npujarec5762e2020-01-01 14:08:48 +0530207 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
208 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530209 for _, tt := range tests {
210 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530211 if err := flowMgr.RemoveSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530212 t.Errorf("OpenOltFlowMgr.RemoveSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr)
213 }
214 })
215 }
kdarapub26b4502019-10-05 03:02:33 +0530216
kdarapu3248f9a2019-10-03 13:54:52 +0530217}
218
219func TestOpenOltFlowMgr_RemoveFlow(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530220 // flowMgr := newMockFlowmgr()
221 log.Debug("Info Warning Error: Starting RemoveFlow() test")
kdarapu3248f9a2019-10-03 13:54:52 +0530222 fa := &fu.FlowArgs{
223 MatchFields: []*ofp.OfpOxmOfbField{
224 fu.InPort(2),
225 fu.Metadata_ofp(2),
226 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
227 },
228 Actions: []*ofp.OfpAction{
229 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
230 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
231 fu.Output(1),
232 },
233 }
234 ofpstats := fu.MkFlowStat(fa)
kdarapub26b4502019-10-05 03:02:33 +0530235 ofpstats.Cookie = ofpstats.Id
kdarapub26b4502019-10-05 03:02:33 +0530236 lldpFa := &fu.FlowArgs{
237 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
238 MatchFields: []*ofp.OfpOxmOfbField{
239 fu.InPort(1),
240 fu.EthType(0x88CC),
241 fu.TunnelId(536870912),
242 },
243 Actions: []*ofp.OfpAction{
244 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
245 },
246 }
247 lldpofpstats := fu.MkFlowStat(lldpFa)
248 //lldpofpstats.Cookie = lldpofpstats.Id
249
250 dhcpFa := &fu.FlowArgs{
251 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
252 MatchFields: []*ofp.OfpOxmOfbField{
253 fu.InPort(1),
254 fu.UdpSrc(67),
255 //fu.TunnelId(536870912),
256 fu.IpProto(17),
257 },
258 Actions: []*ofp.OfpAction{
259 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
260 },
261 }
262 dhcpofpstats := fu.MkFlowStat(dhcpFa)
263 //dhcpofpstats.Cookie = dhcpofpstats.Id
Esin Karamanccb714b2019-11-29 15:02:06 +0000264
265 //multicast flow
266 multicastFa := &fu.FlowArgs{
267 MatchFields: []*ofp.OfpOxmOfbField{
268 fu.InPort(65536),
269 fu.VlanVid(660), //vlan
270 fu.Metadata_ofp(uint64(66)), //inner vlan
271 fu.EthType(0x800), //ipv4
272 fu.Ipv4Dst(3809869825), //227.22.0.1
273 },
274 Actions: []*ofp.OfpAction{
275 fu.Group(1),
276 },
277 }
278 multicastOfpStats := fu.MkFlowStat(multicastFa)
279 multicastOfpStats.Id = 1
280
kdarapu3248f9a2019-10-03 13:54:52 +0530281 type args struct {
282 flow *ofp.OfpFlowStats
283 }
284 tests := []struct {
285 name string
286 args args
287 }{
288 // TODO: Add test cases.
289 {"RemoveFlow", args{flow: ofpstats}},
kdarapub26b4502019-10-05 03:02:33 +0530290 {"RemoveFlow", args{flow: lldpofpstats}},
291 {"RemoveFlow", args{flow: dhcpofpstats}},
Esin Karamanccb714b2019-11-29 15:02:06 +0000292 {"RemoveFlow", args{flow: multicastOfpStats}},
kdarapu3248f9a2019-10-03 13:54:52 +0530293 }
npujarec5762e2020-01-01 14:08:48 +0530294 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
295 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530296 for _, tt := range tests {
297 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530298 flowMgr.RemoveFlow(ctx, tt.args.flow)
kdarapu3248f9a2019-10-03 13:54:52 +0530299 })
300 }
kdarapub26b4502019-10-05 03:02:33 +0530301 // t.Error("=====")
kdarapu3248f9a2019-10-03 13:54:52 +0530302}
303
304func TestOpenOltFlowMgr_AddFlow(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530305 // flowMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530306 kw := make(map[string]uint64)
307 kw["table_id"] = 1
308 kw["meter_id"] = 1
kdarapub26b4502019-10-05 03:02:33 +0530309 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
310
311 // Upstream flow
kdarapu3248f9a2019-10-03 13:54:52 +0530312 fa := &fu.FlowArgs{
313 MatchFields: []*ofp.OfpOxmOfbField{
kdarapub26b4502019-10-05 03:02:33 +0530314 fu.InPort(536870912),
315 fu.Metadata_ofp(1),
316 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
317 },
318 Actions: []*ofp.OfpAction{
319 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
320 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
321 fu.Output(65536),
322 fu.PushVlan(0x8100),
323 },
324 KV: kw,
325 }
326
327 // Downstream flow
328 fa3 := &fu.FlowArgs{
329 MatchFields: []*ofp.OfpOxmOfbField{
330 fu.InPort(65536),
331 fu.Metadata_ofp(1),
332 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
333 },
334 Actions: []*ofp.OfpAction{
335 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
336 //fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
337 fu.PopVlan(),
338 fu.Output(536870912),
339 },
340 KV: kw,
341 }
342
343 fa2 := &fu.FlowArgs{
344 MatchFields: []*ofp.OfpOxmOfbField{
kdarapu3248f9a2019-10-03 13:54:52 +0530345 fu.InPort(1000),
346 fu.Metadata_ofp(1),
347 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
348 },
349 Actions: []*ofp.OfpAction{
350 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
351 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
352 fu.Output(65533),
353 },
354 KV: kw,
355 }
356
kdarapub26b4502019-10-05 03:02:33 +0530357 // TODO Add LLDP flow
358 // TODO Add DHCP flow
359
360 // Flows for negative scenarios
361 // Failure in formulateActionInfoFromFlow()
362 fa4 := &fu.FlowArgs{
363 MatchFields: []*ofp.OfpOxmOfbField{
364 fu.InPort(1000),
365 fu.Metadata_ofp(1),
366 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
367 },
368 Actions: []*ofp.OfpAction{
369 fu.Experimenter(257, []byte{1, 2, 3, 4}),
370 },
371 KV: kw,
372 }
373
374 // Invalid Output
375 fa5 := &fu.FlowArgs{
376 MatchFields: []*ofp.OfpOxmOfbField{
377 fu.InPort(1000),
378 fu.Metadata_ofp(1),
379 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
380 },
381 Actions: []*ofp.OfpAction{
382 fu.Output(0),
383 },
384 KV: kw,
385 }
386
387 // Tech-Profile-ID update (not supported)
388 kw6 := make(map[string]uint64)
389 kw6["table_id"] = 1
390 kw6["meter_id"] = 1
391 kw6["write_metadata"] = 0x4100000000 // TpID Other than the stored one
392 fa6 := &fu.FlowArgs{
393 MatchFields: []*ofp.OfpOxmOfbField{
394 fu.InPort(536870912),
395 fu.TunnelId(16),
396 fu.Metadata_ofp(1),
397 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
398 },
399 Actions: []*ofp.OfpAction{
400 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
401 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
402 fu.Output(65535),
403 },
404 KV: kw6,
405 }
406
407 lldpFa := &fu.FlowArgs{
408 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
409 MatchFields: []*ofp.OfpOxmOfbField{
410 fu.InPort(1),
411 fu.EthType(0x88CC),
412 fu.TunnelId(536870912),
413 },
414 Actions: []*ofp.OfpAction{
415 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
416 },
417 }
418
419 dhcpFa := &fu.FlowArgs{
420 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
421 MatchFields: []*ofp.OfpOxmOfbField{
422 fu.InPort(1),
423 fu.UdpSrc(67),
424 //fu.TunnelId(536870912),
425 fu.IpProto(17),
426 },
427 Actions: []*ofp.OfpAction{
428 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
429 },
430 }
431 igmpFa := &fu.FlowArgs{
432 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
433 MatchFields: []*ofp.OfpOxmOfbField{
434 fu.InPort(1),
435 fu.UdpSrc(67),
436 //fu.TunnelId(536870912),
437 fu.IpProto(2),
438 },
439 Actions: []*ofp.OfpAction{
440 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
441 },
442 }
443
444 fa9 := &fu.FlowArgs{
445 MatchFields: []*ofp.OfpOxmOfbField{
446 fu.InPort(536870912),
447 fu.TunnelId(16),
448 fu.Metadata_ofp(1),
449 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
450 fu.VlanPcp(1000),
451 fu.UdpDst(65535),
452 fu.UdpSrc(536870912),
453 fu.Ipv4Dst(65535),
454 fu.Ipv4Src(536870912),
455 },
456 Actions: []*ofp.OfpAction{
457 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
458 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
459 fu.Output(65535),
460 },
461 KV: kw6,
462 }
463
464 fa10 := &fu.FlowArgs{
465 MatchFields: []*ofp.OfpOxmOfbField{
466 fu.InPort(65533),
467 // fu.TunnelId(16),
468 fu.Metadata_ofp(1),
469 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
470 fu.VlanPcp(1000),
471 fu.UdpDst(65535),
472 fu.UdpSrc(536870912),
473 fu.Ipv4Dst(65535),
474 fu.Ipv4Src(536870912),
475 },
476 Actions: []*ofp.OfpAction{
477 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
478 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
479 fu.Output(65535),
480 },
481 KV: kw6,
482 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000483 //multicast flow
484 fa11 := &fu.FlowArgs{
485 MatchFields: []*ofp.OfpOxmOfbField{
486 fu.InPort(65536),
487 fu.VlanVid(660), //vlan
488 fu.Metadata_ofp(uint64(66)), //inner vlan
489 fu.EthType(0x800), //ipv4
490 fu.Ipv4Dst(3809869825), //227.22.0.1
491 },
492 Actions: []*ofp.OfpAction{
493 fu.Group(1),
494 },
495 KV: kw6,
496 }
kdarapu3248f9a2019-10-03 13:54:52 +0530497 ofpstats := fu.MkFlowStat(fa)
kdarapub26b4502019-10-05 03:02:33 +0530498 ofpstats2 := fu.MkFlowStat(fa2)
499 ofpstats3 := fu.MkFlowStat(fa3)
500 ofpstats4 := fu.MkFlowStat(fa4)
501 ofpstats5 := fu.MkFlowStat(fa5)
502 ofpstats6 := fu.MkFlowStat(fa6)
503 ofpstats7 := fu.MkFlowStat(lldpFa)
504 ofpstats8 := fu.MkFlowStat(dhcpFa)
505 ofpstats9 := fu.MkFlowStat(fa9)
506 ofpstats10 := fu.MkFlowStat(fa10)
507 igmpstats := fu.MkFlowStat(igmpFa)
Esin Karamanccb714b2019-11-29 15:02:06 +0000508 ofpstats11 := fu.MkFlowStat(fa11)
kdarapub26b4502019-10-05 03:02:33 +0530509
Gamze Abakafee36392019-10-03 11:17:24 +0000510 fmt.Println(ofpstats6, ofpstats9, ofpstats10)
511
kdarapu3248f9a2019-10-03 13:54:52 +0530512 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1}
kdarapu3248f9a2019-10-03 13:54:52 +0530513 flowMetadata := &voltha.FlowMetadata{
514 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
515 }
516 type args struct {
517 flow *ofp.OfpFlowStats
518 flowMetadata *voltha.FlowMetadata
519 }
520 tests := []struct {
521 name string
522 args args
523 }{
524 // TODO: Add test cases.
525 {"AddFlow", args{flow: ofpstats, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530526 {"AddFlow", args{flow: ofpstats2, flowMetadata: flowMetadata}},
527 {"AddFlow", args{flow: ofpstats3, flowMetadata: flowMetadata}},
528 {"AddFlow", args{flow: ofpstats4, flowMetadata: flowMetadata}},
529 {"AddFlow", args{flow: ofpstats5, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000530 //{"AddFlow", args{flow: ofpstats6, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530531 {"AddFlow", args{flow: ofpstats7, flowMetadata: flowMetadata}},
532 {"AddFlow", args{flow: ofpstats8, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000533 //{"AddFlow", args{flow: ofpstats9, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530534 {"AddFlow", args{flow: igmpstats, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000535 //{"AddFlow", args{flow: ofpstats10, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530536 //ofpstats10
Esin Karamanccb714b2019-11-29 15:02:06 +0000537 {"AddFlow", args{flow: ofpstats11, flowMetadata: flowMetadata}},
kdarapu3248f9a2019-10-03 13:54:52 +0530538 }
npujarec5762e2020-01-01 14:08:48 +0530539 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
540 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530541 for _, tt := range tests {
542 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530543 flowMgr.AddFlow(ctx, tt.args.flow, tt.args.flowMetadata)
kdarapu3248f9a2019-10-03 13:54:52 +0530544 })
545 }
546}
547
548func TestOpenOltFlowMgr_UpdateOnuInfo(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530549 // flowMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530550 type args struct {
551 intfID uint32
552 onuID uint32
553 serialNum string
554 }
555 tests := []struct {
556 name string
557 args args
558 }{
559 // TODO: Add test cases.
560 {"UpdateOnuInfo", args{1, 1, "onu1"}},
561 {"UpdateOnuInfo", args{2, 3, "onu1"}},
562 }
npujarec5762e2020-01-01 14:08:48 +0530563 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
564 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530565 for _, tt := range tests {
566 t.Run(tt.name, func(t *testing.T) {
567
npujarec5762e2020-01-01 14:08:48 +0530568 flowMgr.UpdateOnuInfo(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum)
kdarapu3248f9a2019-10-03 13:54:52 +0530569 })
570 }
571}
572
573func TestOpenOltFlowMgr_GetLogicalPortFromPacketIn(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530574 // flowMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530575 type args struct {
576 packetIn *openoltpb2.PacketIndication
577 }
578 tests := []struct {
579 name string
580 args args
581 want uint32
582 wantErr bool
583 }{
584 // TODO: Add test cases.
585 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 1, GemportId: 1, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 1, false},
Amit Ghoshd4cbe482019-11-21 12:07:14 +0000586 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "nni", IntfId: 1, GemportId: 1, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 1048577, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530587 // Negative Test cases.
588 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 2, GemportId: 1, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 0, true},
Amit Ghoshd4cbe482019-11-21 12:07:14 +0000589 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 1, GemportId: 1, FlowId: 100, PortNo: 0, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 4112, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530590 }
npujarec5762e2020-01-01 14:08:48 +0530591 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
592 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530593 for _, tt := range tests {
594 t.Run(tt.name, func(t *testing.T) {
595
npujarec5762e2020-01-01 14:08:48 +0530596 got, err := flowMgr.GetLogicalPortFromPacketIn(ctx, tt.args.packetIn)
kdarapu3248f9a2019-10-03 13:54:52 +0530597 if (err != nil) != tt.wantErr {
598 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() error = %v, wantErr %v", err, tt.wantErr)
599 return
600 }
601 if got != tt.want {
602 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() = %v, want %v", got, tt.want)
603 }
604 })
605 }
606}
607
608func TestOpenOltFlowMgr_GetPacketOutGemPortID(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530609 // flwMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530610
611 type args struct {
612 intfID uint32
613 onuID uint32
614 portNum uint32
615 }
616 tests := []struct {
617 name string
618 args args
619 want uint32
620 wantErr bool
621 }{
622 // TODO: Add test cases.
623 {"GetPacketOutGemPortID", args{intfID: 1, onuID: 1, portNum: 1}, 1, false},
624 {"GetPacketOutGemPortID", args{intfID: 2, onuID: 2, portNum: 2}, 2, false},
625 {"GetPacketOutGemPortID", args{intfID: 1, onuID: 2, portNum: 2}, 0, true},
626 }
npujarec5762e2020-01-01 14:08:48 +0530627 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
628 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530629 for _, tt := range tests {
630 t.Run(tt.name, func(t *testing.T) {
631
npujarec5762e2020-01-01 14:08:48 +0530632 got, err := flowMgr.GetPacketOutGemPortID(ctx, tt.args.intfID, tt.args.onuID, tt.args.portNum)
kdarapu3248f9a2019-10-03 13:54:52 +0530633 if (err != nil) != tt.wantErr {
634 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() error = %v, wantErr %v", err, tt.wantErr)
635 return
636 }
637 if got != tt.want {
638 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, want %v", got, tt.want)
639 }
640
641 })
642 }
643}
644
645func TestOpenOltFlowMgr_DeleteTechProfileInstance(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530646 // flwMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530647 type args struct {
648 intfID uint32
649 onuID uint32
650 uniID uint32
651 sn string
Gamze Abakafee36392019-10-03 11:17:24 +0000652 tpID uint32
kdarapu3248f9a2019-10-03 13:54:52 +0530653 }
654 tests := []struct {
655 name string
656 args args
657 wantErr bool
658 }{
659 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000660 {"DeleteTechProfileInstance", args{intfID: 0, onuID: 1, uniID: 1, sn: "", tpID: 64}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530661 }
npujarec5762e2020-01-01 14:08:48 +0530662 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
663 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530664 for _, tt := range tests {
665 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530666 if err := flowMgr.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 +0530667 t.Errorf("OpenOltFlowMgr.DeleteTechProfileInstance() error = %v, wantErr %v", err, tt.wantErr)
668 }
669 })
670 }
671}
kdarapub26b4502019-10-05 03:02:33 +0530672
673func TestOpenOltFlowMgr_checkAndAddFlow(t *testing.T) {
674 // flowMgr := newMockFlowmgr()
675 kw := make(map[string]uint64)
676 kw["table_id"] = 1
677 kw["meter_id"] = 1
678 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
679
680 // Upstream flow
681 fa := &fu.FlowArgs{
682 MatchFields: []*ofp.OfpOxmOfbField{
683 fu.InPort(536870912),
684 fu.Metadata_ofp(1),
685 fu.IpProto(17), // dhcp
Gamze Abakafee36392019-10-03 11:17:24 +0000686 fu.VlanPcp(0),
kdarapub26b4502019-10-05 03:02:33 +0530687 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
688 },
689 Actions: []*ofp.OfpAction{
690 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
691 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
692 fu.Output(65536),
693 fu.PushVlan(0x8100),
694 },
695 KV: kw,
696 }
697
698 // EAPOL
699 fa2 := &fu.FlowArgs{
700 MatchFields: []*ofp.OfpOxmOfbField{
701 fu.InPort(536870912),
702 fu.Metadata_ofp(1),
703 fu.EthType(0x888E),
704 fu.VlanPcp(1),
705 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
706 },
707 Actions: []*ofp.OfpAction{
708 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
709 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
710 fu.Output(65536),
711 fu.PushVlan(0x8100),
712 },
713 KV: kw,
714 }
715
716 // HSIA
717 fa3 := &fu.FlowArgs{
718 MatchFields: []*ofp.OfpOxmOfbField{
719 fu.InPort(536870912),
720 fu.Metadata_ofp(1),
721 //fu.EthType(0x8100),
722 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
723 },
724 Actions: []*ofp.OfpAction{
725 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
726 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)),
727 fu.Output(65536),
728 fu.PushVlan(0x8100),
729 },
730 KV: kw,
731 }
732
733 fa4 := &fu.FlowArgs{
734 MatchFields: []*ofp.OfpOxmOfbField{
735 fu.InPort(65535),
736 fu.Metadata_ofp(1),
737 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
738 fu.VlanPcp(1),
739 },
740 Actions: []*ofp.OfpAction{
741 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
742 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)),
743 fu.Output(536870912),
744 fu.PopVlan(),
745 },
746 KV: kw,
747 }
748
749 classifierInfo := make(map[string]interface{})
750 actionInfo := make(map[string]interface{})
751 classifierInfo2 := make(map[string]interface{})
752 actionInfo2 := make(map[string]interface{})
753 classifierInfo3 := make(map[string]interface{})
754 actionInfo3 := make(map[string]interface{})
755 classifierInfo4 := make(map[string]interface{})
756 actionInfo4 := make(map[string]interface{})
757 flowState := fu.MkFlowStat(fa)
758 flowState2 := fu.MkFlowStat(fa2)
759 flowState3 := fu.MkFlowStat(fa3)
760 flowState4 := fu.MkFlowStat(fa4)
761 formulateClassifierInfoFromFlow(classifierInfo, flowState)
762 formulateClassifierInfoFromFlow(classifierInfo2, flowState2)
763 formulateClassifierInfoFromFlow(classifierInfo3, flowState3)
764 formulateClassifierInfoFromFlow(classifierInfo4, flowState4)
765
766 err := formulateActionInfoFromFlow(actionInfo, classifierInfo, flowState)
767 if err != nil {
768 // Error logging is already done in the called function
769 // So just return in case of error
770 return
771 }
772
773 err = formulateActionInfoFromFlow(actionInfo2, classifierInfo2, flowState2)
774 if err != nil {
775 // Error logging is already done in the called function
776 // So just return in case of error
777 return
778 }
779
780 err = formulateActionInfoFromFlow(actionInfo3, classifierInfo3, flowState3)
781 if err != nil {
782 // Error logging is already done in the called function
783 // So just return in case of error
784 return
785 }
786
787 err = formulateActionInfoFromFlow(actionInfo4, classifierInfo4, flowState4)
788 if err != nil {
789 // Error logging is already done in the called function
790 // So just return in case of error
791 return
792 }
793
794 //ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1}
795 //flowMetadata := &voltha.FlowMetadata{
796 // Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
797 //}
798
799 TpInst := &tp.TechProfile{
800 Name: "Test-Tech-Profile",
801 SubscriberIdentifier: "257",
802 ProfileType: "Mock",
803 Version: 1,
804 NumGemPorts: 4,
kdarapub26b4502019-10-05 03:02:33 +0530805 InstanceCtrl: tp.InstanceControl{
806 Onu: "1",
807 Uni: "16",
808 },
809 }
810
811 type fields struct {
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530812 techprofile []tp.TechProfileIf
813 deviceHandler *DeviceHandler
814 resourceMgr *rsrcMgr.OpenOltResourceMgr
kdarapub26b4502019-10-05 03:02:33 +0530815 }
816 type args struct {
817 args map[string]uint32
818 classifierInfo map[string]interface{}
819 actionInfo map[string]interface{}
820 flow *ofp.OfpFlowStats
821 gemPort uint32
822 intfID uint32
823 onuID uint32
824 uniID uint32
825 portNo uint32
826 TpInst *tp.TechProfile
827 allocID []uint32
828 gemPorts []uint32
829 TpID uint32
830 uni string
831 }
832 tests := []struct {
833 name string
834 fields fields
835 args args
836 }{
837 {
838 name: "checkAndAddFlow-1",
839 args: args{
840 args: nil,
841 classifierInfo: classifierInfo,
842 actionInfo: actionInfo,
843 flow: flowState,
844 gemPort: 1,
845 intfID: 1,
846 onuID: 1,
847 uniID: 16,
848 portNo: 1,
849 TpInst: TpInst,
850 allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004},
851 gemPorts: []uint32{1, 2, 3, 4},
852 TpID: 64,
853 uni: "16",
854 },
855 },
856 {
857 name: "checkAndAddFlow-2",
858 args: args{
859 args: nil,
860 classifierInfo: classifierInfo2,
861 actionInfo: actionInfo2,
862 flow: flowState2,
863 gemPort: 1,
864 intfID: 1,
865 onuID: 1,
866 uniID: 16,
867 portNo: 1,
868 TpInst: TpInst,
869 allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004},
870 gemPorts: []uint32{1, 2, 3, 4},
871 TpID: 64,
872 uni: "16",
873 },
874 },
875 {
876 name: "checkAndAddFlow-3",
877 args: args{
878 args: nil,
879 classifierInfo: classifierInfo3,
880 actionInfo: actionInfo3,
881 flow: flowState3,
882 gemPort: 1,
883 intfID: 1,
884 onuID: 1,
885 uniID: 16,
886 portNo: 1,
887 TpInst: TpInst,
888 allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004},
889 gemPorts: []uint32{1, 2, 3, 4},
890 TpID: 64,
891 uni: "16",
892 },
893 },
894 {
895 name: "checkAndAddFlow-4",
896 args: args{
897 args: nil,
898 classifierInfo: classifierInfo4,
899 actionInfo: actionInfo4,
900 flow: flowState4,
901 gemPort: 1,
902 intfID: 1,
903 onuID: 1,
904 uniID: 16,
905 portNo: 1,
906 TpInst: TpInst,
907 allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004},
908 gemPorts: []uint32{1, 2, 3, 4},
909 TpID: 64,
910 uni: "16",
911 },
912 },
913 }
npujarec5762e2020-01-01 14:08:48 +0530914 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
915 defer cancel()
kdarapub26b4502019-10-05 03:02:33 +0530916 for _, tt := range tests {
917 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530918 flowMgr.checkAndAddFlow(ctx, tt.args.args, tt.args.classifierInfo, tt.args.actionInfo, tt.args.flow,
Gamze Abakafee36392019-10-03 11:17:24 +0000919 tt.args.TpInst, tt.args.gemPorts, tt.args.TpID, tt.args.uni)
kdarapub26b4502019-10-05 03:02:33 +0530920 })
921 }
922}
Esin Karamanccb714b2019-11-29 15:02:06 +0000923
924func TestOpenOltFlowMgr_TestMulticastFlow(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530925 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
926 defer cancel()
Esin Karamanccb714b2019-11-29 15:02:06 +0000927 //create group
928 group := newGroup(2, []uint32{1})
npujarec5762e2020-01-01 14:08:48 +0530929 flowMgr.AddGroup(ctx, group)
Esin Karamanccb714b2019-11-29 15:02:06 +0000930
931 //create multicast flow
932 multicastFlowArgs := &fu.FlowArgs{
933 MatchFields: []*ofp.OfpOxmOfbField{
934 fu.InPort(65536),
935 fu.VlanVid(660), //vlan
936 fu.Metadata_ofp(uint64(66)), //inner vlan
937 fu.EthType(0x800), //ipv4
938 fu.Ipv4Dst(3809869825), //227.22.0.1
939 },
940 Actions: []*ofp.OfpAction{
941 fu.Group(1),
942 },
943 }
944 ofpStats := fu.MkFlowStat(multicastFlowArgs)
npujarec5762e2020-01-01 14:08:48 +0530945 flowMgr.AddFlow(ctx, ofpStats, &voltha.FlowMetadata{})
Esin Karamanccb714b2019-11-29 15:02:06 +0000946
947 //add bucket to the group
948 group = newGroup(2, []uint32{1, 2})
949
npujarec5762e2020-01-01 14:08:48 +0530950 flowMgr.ModifyGroup(ctx, group)
Esin Karamanccb714b2019-11-29 15:02:06 +0000951}