blob: 6641e6ef21ca8f40e11cb1d2a70d30ec5b974481 [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"
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"
Scott Bakerdbd960e2020-02-28 08:57:51 -080032 "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager"
33 rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager"
34 "github.com/opencord/voltha-openolt-adapter/pkg/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 }
divyadesaid26f6b12020-03-19 06:30:28 +0000234 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 }
divyadesaid26f6b12020-03-19 06:30:28 +0000247 lldpofpstats, _ := fu.MkFlowStat(lldpFa)
kdarapub26b4502019-10-05 03:02:33 +0530248 //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 }
divyadesaid26f6b12020-03-19 06:30:28 +0000262 dhcpofpstats, _ := fu.MkFlowStat(dhcpFa)
kdarapub26b4502019-10-05 03:02:33 +0530263 //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 }
divyadesaid26f6b12020-03-19 06:30:28 +0000278 multicastOfpStats, _ := fu.MkFlowStat(multicastFa)
Esin Karamanccb714b2019-11-29 15:02:06 +0000279 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 }
divyadesaid26f6b12020-03-19 06:30:28 +0000497 ofpstats, _ := fu.MkFlowStat(fa)
498 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)
508 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
serkant.uluderya96af4932020-02-20 16:58:48 -0800573func TestOpenOltFlowMgr_deleteGemPortFromLocalCache(t *testing.T) {
574 // flowMgr := newMockFlowmgr()
575 type args struct {
576 intfID uint32
577 onuID uint32
578 gemPortIDs []uint32
579 gemPortIDsToBeDeleted []uint32
580 serialNum string
581 finalLength int
582 }
583 tests := []struct {
584 name string
585 args args
586 }{
587 // Add/Delete single gem port
588 {"DeleteGemPortFromLocalCache1", args{0, 1, []uint32{1}, []uint32{1}, "onu1", 0}},
589 // Delete all gemports
590 {"DeleteGemPortFromLocalCache2", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{1, 2, 3, 4}, "onu1", 0}},
591 // Try to delete when there is no gem port
592 {"DeleteGemPortFromLocalCache3", args{0, 1, []uint32{}, []uint32{1, 2}, "onu1", 0}},
593 // Try to delete non-existent gem port
594 {"DeleteGemPortFromLocalCache4", args{0, 1, []uint32{1}, []uint32{2}, "onu1", 1}},
595 // Try to delete two of the gem ports
596 {"DeleteGemPortFromLocalCache5", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{2, 4}, "onu1", 2}},
597 }
598 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
599 defer cancel()
600 for _, tt := range tests {
601 t.Run(tt.name, func(t *testing.T) {
602 flowMgr.UpdateOnuInfo(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum)
603 for _, gemPort := range tt.args.gemPortIDs {
604 flowMgr.addGemPortToOnuInfoMap(ctx, tt.args.intfID, tt.args.onuID, gemPort)
605 }
606 for _, gemPortDeleted := range tt.args.gemPortIDsToBeDeleted {
607 flowMgr.deleteGemPortFromLocalCache(tt.args.intfID, tt.args.onuID, gemPortDeleted)
608 }
609 lenofGemPorts := len(flowMgr.onuGemInfo[tt.args.intfID][0].GemPorts)
610 if lenofGemPorts != tt.args.finalLength {
611 t.Errorf("GemPorts length is not as expected len = %d, want %d", lenofGemPorts, tt.args.finalLength)
612 }
613
614 })
615 }
616}
617
kdarapu3248f9a2019-10-03 13:54:52 +0530618func TestOpenOltFlowMgr_GetLogicalPortFromPacketIn(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530619 // flowMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530620 type args struct {
621 packetIn *openoltpb2.PacketIndication
622 }
623 tests := []struct {
624 name string
625 args args
626 want uint32
627 wantErr bool
628 }{
629 // TODO: Add test cases.
630 {"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 +0000631 {"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 +0530632 // Negative Test cases.
633 {"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 +0000634 {"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 +0530635 }
npujarec5762e2020-01-01 14:08:48 +0530636 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
637 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530638 for _, tt := range tests {
639 t.Run(tt.name, func(t *testing.T) {
640
npujarec5762e2020-01-01 14:08:48 +0530641 got, err := flowMgr.GetLogicalPortFromPacketIn(ctx, tt.args.packetIn)
kdarapu3248f9a2019-10-03 13:54:52 +0530642 if (err != nil) != tt.wantErr {
643 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() error = %v, wantErr %v", err, tt.wantErr)
644 return
645 }
646 if got != tt.want {
647 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() = %v, want %v", got, tt.want)
648 }
649 })
650 }
651}
652
653func TestOpenOltFlowMgr_GetPacketOutGemPortID(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530654 // flwMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530655
656 type args struct {
657 intfID uint32
658 onuID uint32
659 portNum uint32
660 }
661 tests := []struct {
662 name string
663 args args
664 want uint32
665 wantErr bool
666 }{
667 // TODO: Add test cases.
668 {"GetPacketOutGemPortID", args{intfID: 1, onuID: 1, portNum: 1}, 1, false},
669 {"GetPacketOutGemPortID", args{intfID: 2, onuID: 2, portNum: 2}, 2, false},
670 {"GetPacketOutGemPortID", args{intfID: 1, onuID: 2, portNum: 2}, 0, true},
671 }
npujarec5762e2020-01-01 14:08:48 +0530672 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
673 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530674 for _, tt := range tests {
675 t.Run(tt.name, func(t *testing.T) {
676
npujarec5762e2020-01-01 14:08:48 +0530677 got, err := flowMgr.GetPacketOutGemPortID(ctx, tt.args.intfID, tt.args.onuID, tt.args.portNum)
kdarapu3248f9a2019-10-03 13:54:52 +0530678 if (err != nil) != tt.wantErr {
679 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() error = %v, wantErr %v", err, tt.wantErr)
680 return
681 }
682 if got != tt.want {
683 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, want %v", got, tt.want)
684 }
685
686 })
687 }
688}
689
690func TestOpenOltFlowMgr_DeleteTechProfileInstance(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530691 // flwMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530692 type args struct {
693 intfID uint32
694 onuID uint32
695 uniID uint32
696 sn string
Gamze Abakafee36392019-10-03 11:17:24 +0000697 tpID uint32
kdarapu3248f9a2019-10-03 13:54:52 +0530698 }
699 tests := []struct {
700 name string
701 args args
702 wantErr bool
703 }{
704 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000705 {"DeleteTechProfileInstance", args{intfID: 0, onuID: 1, uniID: 1, sn: "", tpID: 64}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530706 }
npujarec5762e2020-01-01 14:08:48 +0530707 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
708 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530709 for _, tt := range tests {
710 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530711 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 +0530712 t.Errorf("OpenOltFlowMgr.DeleteTechProfileInstance() error = %v, wantErr %v", err, tt.wantErr)
713 }
714 })
715 }
716}
kdarapub26b4502019-10-05 03:02:33 +0530717
718func TestOpenOltFlowMgr_checkAndAddFlow(t *testing.T) {
719 // flowMgr := newMockFlowmgr()
720 kw := make(map[string]uint64)
721 kw["table_id"] = 1
722 kw["meter_id"] = 1
723 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
724
725 // Upstream flow
726 fa := &fu.FlowArgs{
727 MatchFields: []*ofp.OfpOxmOfbField{
728 fu.InPort(536870912),
729 fu.Metadata_ofp(1),
730 fu.IpProto(17), // dhcp
Gamze Abakafee36392019-10-03 11:17:24 +0000731 fu.VlanPcp(0),
kdarapub26b4502019-10-05 03:02:33 +0530732 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
733 },
734 Actions: []*ofp.OfpAction{
735 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
736 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
737 fu.Output(65536),
738 fu.PushVlan(0x8100),
739 },
740 KV: kw,
741 }
742
743 // EAPOL
744 fa2 := &fu.FlowArgs{
745 MatchFields: []*ofp.OfpOxmOfbField{
746 fu.InPort(536870912),
747 fu.Metadata_ofp(1),
748 fu.EthType(0x888E),
749 fu.VlanPcp(1),
750 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
751 },
752 Actions: []*ofp.OfpAction{
753 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
754 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
755 fu.Output(65536),
756 fu.PushVlan(0x8100),
757 },
758 KV: kw,
759 }
760
761 // HSIA
762 fa3 := &fu.FlowArgs{
763 MatchFields: []*ofp.OfpOxmOfbField{
764 fu.InPort(536870912),
765 fu.Metadata_ofp(1),
766 //fu.EthType(0x8100),
767 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
768 },
769 Actions: []*ofp.OfpAction{
770 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
771 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)),
772 fu.Output(65536),
773 fu.PushVlan(0x8100),
774 },
775 KV: kw,
776 }
777
778 fa4 := &fu.FlowArgs{
779 MatchFields: []*ofp.OfpOxmOfbField{
780 fu.InPort(65535),
781 fu.Metadata_ofp(1),
782 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
783 fu.VlanPcp(1),
784 },
785 Actions: []*ofp.OfpAction{
786 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
787 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)),
788 fu.Output(536870912),
789 fu.PopVlan(),
790 },
791 KV: kw,
792 }
793
794 classifierInfo := make(map[string]interface{})
795 actionInfo := make(map[string]interface{})
796 classifierInfo2 := make(map[string]interface{})
797 actionInfo2 := make(map[string]interface{})
798 classifierInfo3 := make(map[string]interface{})
799 actionInfo3 := make(map[string]interface{})
800 classifierInfo4 := make(map[string]interface{})
801 actionInfo4 := make(map[string]interface{})
divyadesaid26f6b12020-03-19 06:30:28 +0000802 flowState, _ := fu.MkFlowStat(fa)
803 flowState2, _ := fu.MkFlowStat(fa2)
804 flowState3, _ := fu.MkFlowStat(fa3)
805 flowState4, _ := fu.MkFlowStat(fa4)
kdarapub26b4502019-10-05 03:02:33 +0530806 formulateClassifierInfoFromFlow(classifierInfo, flowState)
807 formulateClassifierInfoFromFlow(classifierInfo2, flowState2)
808 formulateClassifierInfoFromFlow(classifierInfo3, flowState3)
809 formulateClassifierInfoFromFlow(classifierInfo4, flowState4)
810
811 err := formulateActionInfoFromFlow(actionInfo, classifierInfo, flowState)
812 if err != nil {
813 // Error logging is already done in the called function
814 // So just return in case of error
815 return
816 }
817
818 err = formulateActionInfoFromFlow(actionInfo2, classifierInfo2, flowState2)
819 if err != nil {
820 // Error logging is already done in the called function
821 // So just return in case of error
822 return
823 }
824
825 err = formulateActionInfoFromFlow(actionInfo3, classifierInfo3, flowState3)
826 if err != nil {
827 // Error logging is already done in the called function
828 // So just return in case of error
829 return
830 }
831
832 err = formulateActionInfoFromFlow(actionInfo4, classifierInfo4, flowState4)
833 if err != nil {
834 // Error logging is already done in the called function
835 // So just return in case of error
836 return
837 }
838
839 //ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1}
840 //flowMetadata := &voltha.FlowMetadata{
841 // Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
842 //}
843
844 TpInst := &tp.TechProfile{
845 Name: "Test-Tech-Profile",
846 SubscriberIdentifier: "257",
847 ProfileType: "Mock",
848 Version: 1,
849 NumGemPorts: 4,
kdarapub26b4502019-10-05 03:02:33 +0530850 InstanceCtrl: tp.InstanceControl{
851 Onu: "1",
852 Uni: "16",
853 },
854 }
855
856 type fields struct {
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530857 techprofile []tp.TechProfileIf
858 deviceHandler *DeviceHandler
859 resourceMgr *rsrcMgr.OpenOltResourceMgr
kdarapub26b4502019-10-05 03:02:33 +0530860 }
861 type args struct {
862 args map[string]uint32
863 classifierInfo map[string]interface{}
864 actionInfo map[string]interface{}
865 flow *ofp.OfpFlowStats
866 gemPort uint32
867 intfID uint32
868 onuID uint32
869 uniID uint32
870 portNo uint32
871 TpInst *tp.TechProfile
872 allocID []uint32
873 gemPorts []uint32
874 TpID uint32
875 uni string
876 }
877 tests := []struct {
878 name string
879 fields fields
880 args args
881 }{
882 {
883 name: "checkAndAddFlow-1",
884 args: args{
885 args: nil,
886 classifierInfo: classifierInfo,
887 actionInfo: actionInfo,
888 flow: flowState,
889 gemPort: 1,
890 intfID: 1,
891 onuID: 1,
892 uniID: 16,
893 portNo: 1,
894 TpInst: TpInst,
895 allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004},
896 gemPorts: []uint32{1, 2, 3, 4},
897 TpID: 64,
898 uni: "16",
899 },
900 },
901 {
902 name: "checkAndAddFlow-2",
903 args: args{
904 args: nil,
905 classifierInfo: classifierInfo2,
906 actionInfo: actionInfo2,
907 flow: flowState2,
908 gemPort: 1,
909 intfID: 1,
910 onuID: 1,
911 uniID: 16,
912 portNo: 1,
913 TpInst: TpInst,
914 allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004},
915 gemPorts: []uint32{1, 2, 3, 4},
916 TpID: 64,
917 uni: "16",
918 },
919 },
920 {
921 name: "checkAndAddFlow-3",
922 args: args{
923 args: nil,
924 classifierInfo: classifierInfo3,
925 actionInfo: actionInfo3,
926 flow: flowState3,
927 gemPort: 1,
928 intfID: 1,
929 onuID: 1,
930 uniID: 16,
931 portNo: 1,
932 TpInst: TpInst,
933 allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004},
934 gemPorts: []uint32{1, 2, 3, 4},
935 TpID: 64,
936 uni: "16",
937 },
938 },
939 {
940 name: "checkAndAddFlow-4",
941 args: args{
942 args: nil,
943 classifierInfo: classifierInfo4,
944 actionInfo: actionInfo4,
945 flow: flowState4,
946 gemPort: 1,
947 intfID: 1,
948 onuID: 1,
949 uniID: 16,
950 portNo: 1,
951 TpInst: TpInst,
952 allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004},
953 gemPorts: []uint32{1, 2, 3, 4},
954 TpID: 64,
955 uni: "16",
956 },
957 },
958 }
npujarec5762e2020-01-01 14:08:48 +0530959 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
960 defer cancel()
kdarapub26b4502019-10-05 03:02:33 +0530961 for _, tt := range tests {
962 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530963 flowMgr.checkAndAddFlow(ctx, tt.args.args, tt.args.classifierInfo, tt.args.actionInfo, tt.args.flow,
Gamze Abakafee36392019-10-03 11:17:24 +0000964 tt.args.TpInst, tt.args.gemPorts, tt.args.TpID, tt.args.uni)
kdarapub26b4502019-10-05 03:02:33 +0530965 })
966 }
967}
Esin Karamanccb714b2019-11-29 15:02:06 +0000968
969func TestOpenOltFlowMgr_TestMulticastFlow(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530970 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
971 defer cancel()
Esin Karamanccb714b2019-11-29 15:02:06 +0000972 //create group
973 group := newGroup(2, []uint32{1})
npujarec5762e2020-01-01 14:08:48 +0530974 flowMgr.AddGroup(ctx, group)
Esin Karamanccb714b2019-11-29 15:02:06 +0000975
976 //create multicast flow
977 multicastFlowArgs := &fu.FlowArgs{
978 MatchFields: []*ofp.OfpOxmOfbField{
979 fu.InPort(65536),
980 fu.VlanVid(660), //vlan
981 fu.Metadata_ofp(uint64(66)), //inner vlan
982 fu.EthType(0x800), //ipv4
983 fu.Ipv4Dst(3809869825), //227.22.0.1
984 },
985 Actions: []*ofp.OfpAction{
986 fu.Group(1),
987 },
988 }
divyadesaid26f6b12020-03-19 06:30:28 +0000989 ofpStats, _ := fu.MkFlowStat(multicastFlowArgs)
npujarec5762e2020-01-01 14:08:48 +0530990 flowMgr.AddFlow(ctx, ofpStats, &voltha.FlowMetadata{})
Esin Karamanccb714b2019-11-29 15:02:06 +0000991
992 //add bucket to the group
993 group = newGroup(2, []uint32{1, 2})
994
npujarec5762e2020-01-01 14:08:48 +0530995 flowMgr.ModifyGroup(ctx, group)
Esin Karamanccb714b2019-11-29 15:02:06 +0000996}