blob: 26697aa0c7f46ae82a538528302fcae1e83fcdfc [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
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700219func TestOpenOltFlowMgr_createTcontGemports(t *testing.T) {
220 // flowMgr := newMockFlowmgr()
221 bands := make([]*ofp.OfpMeterBandHeader, 2)
222 bands[0] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 1000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
223 bands[1] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 2000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
224 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
225 flowmetadata := &voltha.FlowMetadata{
226 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
227 }
228 type args struct {
229 intfID uint32
230 onuID uint32
231 uniID uint32
232 uni string
233 uniPort uint32
234 TpID uint32
235 UsMeterID uint32
236 DsMeterID uint32
237 flowMetadata *voltha.FlowMetadata
238 }
239 tests := []struct {
240 name string
241 args args
242 }{
243 {"createTcontGemports-1", args{intfID: 0, onuID: 1, uniID: 1, uni: "16", uniPort: 1, TpID: 64, UsMeterID: 1, DsMeterID: 1, flowMetadata: flowmetadata}},
244 {"createTcontGemports-1", args{intfID: 0, onuID: 1, uniID: 1, uni: "16", uniPort: 1, TpID: 65, UsMeterID: 1, DsMeterID: 1, flowMetadata: flowmetadata}},
245 }
246 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
247 defer cancel()
248 for _, tt := range tests {
249 t.Run(tt.name, func(t *testing.T) {
250 _, _, tpInst := flowMgr.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)
251 switch tpInst := tpInst.(type) {
252 case *tp.TechProfile:
253 if tt.args.TpID != 64 {
254 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
255 }
256 case *tp.EponProfile:
257 if tt.args.TpID != 65 {
258 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
259 }
260 default:
261 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
262 }
263 })
264 }
265}
266
kdarapu3248f9a2019-10-03 13:54:52 +0530267func TestOpenOltFlowMgr_RemoveFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000268 ctx := context.Background()
kdarapub26b4502019-10-05 03:02:33 +0530269 // flowMgr := newMockFlowmgr()
Neha Sharma96b7bf22020-06-15 10:37:32 +0000270 logger.Debug(ctx, "Info Warning Error: Starting RemoveFlow() test")
kdarapu3248f9a2019-10-03 13:54:52 +0530271 fa := &fu.FlowArgs{
272 MatchFields: []*ofp.OfpOxmOfbField{
273 fu.InPort(2),
274 fu.Metadata_ofp(2),
275 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
276 },
277 Actions: []*ofp.OfpAction{
278 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
279 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
280 fu.Output(1),
281 },
282 }
divyadesaid26f6b12020-03-19 06:30:28 +0000283 ofpstats, _ := fu.MkFlowStat(fa)
kdarapub26b4502019-10-05 03:02:33 +0530284 ofpstats.Cookie = ofpstats.Id
kdarapub26b4502019-10-05 03:02:33 +0530285 lldpFa := &fu.FlowArgs{
286 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
287 MatchFields: []*ofp.OfpOxmOfbField{
288 fu.InPort(1),
289 fu.EthType(0x88CC),
290 fu.TunnelId(536870912),
291 },
292 Actions: []*ofp.OfpAction{
293 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
294 },
295 }
divyadesaid26f6b12020-03-19 06:30:28 +0000296 lldpofpstats, _ := fu.MkFlowStat(lldpFa)
kdarapub26b4502019-10-05 03:02:33 +0530297 //lldpofpstats.Cookie = lldpofpstats.Id
298
299 dhcpFa := &fu.FlowArgs{
300 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
301 MatchFields: []*ofp.OfpOxmOfbField{
302 fu.InPort(1),
303 fu.UdpSrc(67),
304 //fu.TunnelId(536870912),
305 fu.IpProto(17),
306 },
307 Actions: []*ofp.OfpAction{
308 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
309 },
310 }
divyadesaid26f6b12020-03-19 06:30:28 +0000311 dhcpofpstats, _ := fu.MkFlowStat(dhcpFa)
kdarapub26b4502019-10-05 03:02:33 +0530312 //dhcpofpstats.Cookie = dhcpofpstats.Id
Esin Karamanccb714b2019-11-29 15:02:06 +0000313
314 //multicast flow
315 multicastFa := &fu.FlowArgs{
316 MatchFields: []*ofp.OfpOxmOfbField{
317 fu.InPort(65536),
318 fu.VlanVid(660), //vlan
319 fu.Metadata_ofp(uint64(66)), //inner vlan
320 fu.EthType(0x800), //ipv4
321 fu.Ipv4Dst(3809869825), //227.22.0.1
322 },
323 Actions: []*ofp.OfpAction{
324 fu.Group(1),
325 },
326 }
divyadesaid26f6b12020-03-19 06:30:28 +0000327 multicastOfpStats, _ := fu.MkFlowStat(multicastFa)
Esin Karamanccb714b2019-11-29 15:02:06 +0000328 multicastOfpStats.Id = 1
329
kdarapu3248f9a2019-10-03 13:54:52 +0530330 type args struct {
331 flow *ofp.OfpFlowStats
332 }
333 tests := []struct {
334 name string
335 args args
336 }{
337 // TODO: Add test cases.
338 {"RemoveFlow", args{flow: ofpstats}},
kdarapub26b4502019-10-05 03:02:33 +0530339 {"RemoveFlow", args{flow: lldpofpstats}},
340 {"RemoveFlow", args{flow: dhcpofpstats}},
Esin Karamanccb714b2019-11-29 15:02:06 +0000341 {"RemoveFlow", args{flow: multicastOfpStats}},
kdarapu3248f9a2019-10-03 13:54:52 +0530342 }
npujarec5762e2020-01-01 14:08:48 +0530343 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
344 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530345 for _, tt := range tests {
346 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530347 flowMgr.RemoveFlow(ctx, tt.args.flow)
kdarapu3248f9a2019-10-03 13:54:52 +0530348 })
349 }
kdarapub26b4502019-10-05 03:02:33 +0530350 // t.Error("=====")
kdarapu3248f9a2019-10-03 13:54:52 +0530351}
352
353func TestOpenOltFlowMgr_AddFlow(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530354 // flowMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530355 kw := make(map[string]uint64)
356 kw["table_id"] = 1
357 kw["meter_id"] = 1
kdarapub26b4502019-10-05 03:02:33 +0530358 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
359
360 // Upstream flow
kdarapu3248f9a2019-10-03 13:54:52 +0530361 fa := &fu.FlowArgs{
362 MatchFields: []*ofp.OfpOxmOfbField{
kdarapub26b4502019-10-05 03:02:33 +0530363 fu.InPort(536870912),
364 fu.Metadata_ofp(1),
365 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
366 },
367 Actions: []*ofp.OfpAction{
368 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
369 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
370 fu.Output(65536),
371 fu.PushVlan(0x8100),
372 },
373 KV: kw,
374 }
375
376 // Downstream flow
377 fa3 := &fu.FlowArgs{
378 MatchFields: []*ofp.OfpOxmOfbField{
379 fu.InPort(65536),
380 fu.Metadata_ofp(1),
381 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
382 },
383 Actions: []*ofp.OfpAction{
384 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
385 //fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
386 fu.PopVlan(),
387 fu.Output(536870912),
388 },
389 KV: kw,
390 }
391
392 fa2 := &fu.FlowArgs{
393 MatchFields: []*ofp.OfpOxmOfbField{
kdarapu3248f9a2019-10-03 13:54:52 +0530394 fu.InPort(1000),
395 fu.Metadata_ofp(1),
396 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
397 },
398 Actions: []*ofp.OfpAction{
399 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
400 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
401 fu.Output(65533),
402 },
403 KV: kw,
404 }
405
kdarapub26b4502019-10-05 03:02:33 +0530406 // TODO Add LLDP flow
407 // TODO Add DHCP flow
408
409 // Flows for negative scenarios
410 // Failure in formulateActionInfoFromFlow()
411 fa4 := &fu.FlowArgs{
412 MatchFields: []*ofp.OfpOxmOfbField{
413 fu.InPort(1000),
414 fu.Metadata_ofp(1),
415 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
416 },
417 Actions: []*ofp.OfpAction{
418 fu.Experimenter(257, []byte{1, 2, 3, 4}),
419 },
420 KV: kw,
421 }
422
423 // Invalid Output
424 fa5 := &fu.FlowArgs{
425 MatchFields: []*ofp.OfpOxmOfbField{
426 fu.InPort(1000),
427 fu.Metadata_ofp(1),
428 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
429 },
430 Actions: []*ofp.OfpAction{
431 fu.Output(0),
432 },
433 KV: kw,
434 }
435
436 // Tech-Profile-ID update (not supported)
437 kw6 := make(map[string]uint64)
438 kw6["table_id"] = 1
439 kw6["meter_id"] = 1
440 kw6["write_metadata"] = 0x4100000000 // TpID Other than the stored one
441 fa6 := &fu.FlowArgs{
442 MatchFields: []*ofp.OfpOxmOfbField{
443 fu.InPort(536870912),
444 fu.TunnelId(16),
445 fu.Metadata_ofp(1),
446 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
447 },
448 Actions: []*ofp.OfpAction{
449 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
450 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
451 fu.Output(65535),
452 },
453 KV: kw6,
454 }
455
456 lldpFa := &fu.FlowArgs{
457 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
458 MatchFields: []*ofp.OfpOxmOfbField{
459 fu.InPort(1),
460 fu.EthType(0x88CC),
461 fu.TunnelId(536870912),
462 },
463 Actions: []*ofp.OfpAction{
464 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
465 },
466 }
467
468 dhcpFa := &fu.FlowArgs{
469 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
470 MatchFields: []*ofp.OfpOxmOfbField{
471 fu.InPort(1),
472 fu.UdpSrc(67),
473 //fu.TunnelId(536870912),
474 fu.IpProto(17),
475 },
476 Actions: []*ofp.OfpAction{
477 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
478 },
479 }
480 igmpFa := &fu.FlowArgs{
481 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
482 MatchFields: []*ofp.OfpOxmOfbField{
483 fu.InPort(1),
484 fu.UdpSrc(67),
485 //fu.TunnelId(536870912),
486 fu.IpProto(2),
487 },
488 Actions: []*ofp.OfpAction{
489 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
490 },
491 }
492
493 fa9 := &fu.FlowArgs{
494 MatchFields: []*ofp.OfpOxmOfbField{
495 fu.InPort(536870912),
496 fu.TunnelId(16),
497 fu.Metadata_ofp(1),
498 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
499 fu.VlanPcp(1000),
500 fu.UdpDst(65535),
501 fu.UdpSrc(536870912),
502 fu.Ipv4Dst(65535),
503 fu.Ipv4Src(536870912),
504 },
505 Actions: []*ofp.OfpAction{
506 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
507 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
508 fu.Output(65535),
509 },
510 KV: kw6,
511 }
512
513 fa10 := &fu.FlowArgs{
514 MatchFields: []*ofp.OfpOxmOfbField{
515 fu.InPort(65533),
516 // fu.TunnelId(16),
517 fu.Metadata_ofp(1),
518 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
519 fu.VlanPcp(1000),
520 fu.UdpDst(65535),
521 fu.UdpSrc(536870912),
522 fu.Ipv4Dst(65535),
523 fu.Ipv4Src(536870912),
524 },
525 Actions: []*ofp.OfpAction{
526 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
527 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
528 fu.Output(65535),
529 },
530 KV: kw6,
531 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000532 //multicast flow
533 fa11 := &fu.FlowArgs{
534 MatchFields: []*ofp.OfpOxmOfbField{
535 fu.InPort(65536),
536 fu.VlanVid(660), //vlan
537 fu.Metadata_ofp(uint64(66)), //inner vlan
538 fu.EthType(0x800), //ipv4
539 fu.Ipv4Dst(3809869825), //227.22.0.1
540 },
541 Actions: []*ofp.OfpAction{
542 fu.Group(1),
543 },
544 KV: kw6,
545 }
divyadesaid26f6b12020-03-19 06:30:28 +0000546 ofpstats, _ := fu.MkFlowStat(fa)
547 ofpstats2, _ := fu.MkFlowStat(fa2)
548 ofpstats3, _ := fu.MkFlowStat(fa3)
549 ofpstats4, _ := fu.MkFlowStat(fa4)
550 ofpstats5, _ := fu.MkFlowStat(fa5)
551 ofpstats6, _ := fu.MkFlowStat(fa6)
552 ofpstats7, _ := fu.MkFlowStat(lldpFa)
553 ofpstats8, _ := fu.MkFlowStat(dhcpFa)
554 ofpstats9, _ := fu.MkFlowStat(fa9)
555 ofpstats10, _ := fu.MkFlowStat(fa10)
556 igmpstats, _ := fu.MkFlowStat(igmpFa)
557 ofpstats11, _ := fu.MkFlowStat(fa11)
kdarapub26b4502019-10-05 03:02:33 +0530558
Gamze Abakafee36392019-10-03 11:17:24 +0000559 fmt.Println(ofpstats6, ofpstats9, ofpstats10)
560
kdarapu3248f9a2019-10-03 13:54:52 +0530561 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1}
kdarapu3248f9a2019-10-03 13:54:52 +0530562 flowMetadata := &voltha.FlowMetadata{
563 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
564 }
565 type args struct {
566 flow *ofp.OfpFlowStats
567 flowMetadata *voltha.FlowMetadata
568 }
569 tests := []struct {
570 name string
571 args args
572 }{
573 // TODO: Add test cases.
574 {"AddFlow", args{flow: ofpstats, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530575 {"AddFlow", args{flow: ofpstats2, flowMetadata: flowMetadata}},
576 {"AddFlow", args{flow: ofpstats3, flowMetadata: flowMetadata}},
577 {"AddFlow", args{flow: ofpstats4, flowMetadata: flowMetadata}},
578 {"AddFlow", args{flow: ofpstats5, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000579 //{"AddFlow", args{flow: ofpstats6, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530580 {"AddFlow", args{flow: ofpstats7, flowMetadata: flowMetadata}},
581 {"AddFlow", args{flow: ofpstats8, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000582 //{"AddFlow", args{flow: ofpstats9, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530583 {"AddFlow", args{flow: igmpstats, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000584 //{"AddFlow", args{flow: ofpstats10, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530585 //ofpstats10
Esin Karamanccb714b2019-11-29 15:02:06 +0000586 {"AddFlow", args{flow: ofpstats11, flowMetadata: flowMetadata}},
kdarapu3248f9a2019-10-03 13:54:52 +0530587 }
npujarec5762e2020-01-01 14:08:48 +0530588 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
589 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530590 for _, tt := range tests {
591 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530592 flowMgr.AddFlow(ctx, tt.args.flow, tt.args.flowMetadata)
kdarapu3248f9a2019-10-03 13:54:52 +0530593 })
594 }
595}
596
597func TestOpenOltFlowMgr_UpdateOnuInfo(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530598 // flowMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530599 type args struct {
600 intfID uint32
601 onuID uint32
602 serialNum string
603 }
604 tests := []struct {
605 name string
606 args args
607 }{
608 // TODO: Add test cases.
609 {"UpdateOnuInfo", args{1, 1, "onu1"}},
610 {"UpdateOnuInfo", args{2, 3, "onu1"}},
611 }
npujarec5762e2020-01-01 14:08:48 +0530612 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
613 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530614 for _, tt := range tests {
615 t.Run(tt.name, func(t *testing.T) {
616
npujarec5762e2020-01-01 14:08:48 +0530617 flowMgr.UpdateOnuInfo(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum)
kdarapu3248f9a2019-10-03 13:54:52 +0530618 })
619 }
620}
621
serkant.uluderya96af4932020-02-20 16:58:48 -0800622func TestOpenOltFlowMgr_deleteGemPortFromLocalCache(t *testing.T) {
623 // flowMgr := newMockFlowmgr()
624 type args struct {
625 intfID uint32
626 onuID uint32
627 gemPortIDs []uint32
628 gemPortIDsToBeDeleted []uint32
629 serialNum string
630 finalLength int
631 }
632 tests := []struct {
633 name string
634 args args
635 }{
636 // Add/Delete single gem port
637 {"DeleteGemPortFromLocalCache1", args{0, 1, []uint32{1}, []uint32{1}, "onu1", 0}},
638 // Delete all gemports
639 {"DeleteGemPortFromLocalCache2", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{1, 2, 3, 4}, "onu1", 0}},
640 // Try to delete when there is no gem port
641 {"DeleteGemPortFromLocalCache3", args{0, 1, []uint32{}, []uint32{1, 2}, "onu1", 0}},
642 // Try to delete non-existent gem port
643 {"DeleteGemPortFromLocalCache4", args{0, 1, []uint32{1}, []uint32{2}, "onu1", 1}},
644 // Try to delete two of the gem ports
645 {"DeleteGemPortFromLocalCache5", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{2, 4}, "onu1", 2}},
646 }
647 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
648 defer cancel()
649 for _, tt := range tests {
650 t.Run(tt.name, func(t *testing.T) {
651 flowMgr.UpdateOnuInfo(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum)
652 for _, gemPort := range tt.args.gemPortIDs {
653 flowMgr.addGemPortToOnuInfoMap(ctx, tt.args.intfID, tt.args.onuID, gemPort)
654 }
655 for _, gemPortDeleted := range tt.args.gemPortIDsToBeDeleted {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000656 flowMgr.deleteGemPortFromLocalCache(context.Background(), tt.args.intfID, tt.args.onuID, gemPortDeleted)
serkant.uluderya96af4932020-02-20 16:58:48 -0800657 }
658 lenofGemPorts := len(flowMgr.onuGemInfo[tt.args.intfID][0].GemPorts)
659 if lenofGemPorts != tt.args.finalLength {
660 t.Errorf("GemPorts length is not as expected len = %d, want %d", lenofGemPorts, tt.args.finalLength)
661 }
662
663 })
664 }
665}
666
kdarapu3248f9a2019-10-03 13:54:52 +0530667func TestOpenOltFlowMgr_GetLogicalPortFromPacketIn(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530668 // flowMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530669 type args struct {
670 packetIn *openoltpb2.PacketIndication
671 }
672 tests := []struct {
673 name string
674 args args
675 want uint32
676 wantErr bool
677 }{
678 // TODO: Add test cases.
679 {"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 +0000680 {"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 +0530681 // Negative Test cases.
682 {"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 +0000683 {"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 +0530684 }
npujarec5762e2020-01-01 14:08:48 +0530685 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
686 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530687 for _, tt := range tests {
688 t.Run(tt.name, func(t *testing.T) {
689
npujarec5762e2020-01-01 14:08:48 +0530690 got, err := flowMgr.GetLogicalPortFromPacketIn(ctx, tt.args.packetIn)
kdarapu3248f9a2019-10-03 13:54:52 +0530691 if (err != nil) != tt.wantErr {
692 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() error = %v, wantErr %v", err, tt.wantErr)
693 return
694 }
695 if got != tt.want {
696 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() = %v, want %v", got, tt.want)
697 }
698 })
699 }
700}
701
702func TestOpenOltFlowMgr_GetPacketOutGemPortID(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530703 // flwMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530704
705 type args struct {
706 intfID uint32
707 onuID uint32
708 portNum uint32
709 }
710 tests := []struct {
711 name string
712 args args
713 want uint32
714 wantErr bool
715 }{
716 // TODO: Add test cases.
717 {"GetPacketOutGemPortID", args{intfID: 1, onuID: 1, portNum: 1}, 1, false},
718 {"GetPacketOutGemPortID", args{intfID: 2, onuID: 2, portNum: 2}, 2, false},
719 {"GetPacketOutGemPortID", args{intfID: 1, onuID: 2, portNum: 2}, 0, true},
720 }
npujarec5762e2020-01-01 14:08:48 +0530721 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
722 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530723 for _, tt := range tests {
724 t.Run(tt.name, func(t *testing.T) {
725
npujarec5762e2020-01-01 14:08:48 +0530726 got, err := flowMgr.GetPacketOutGemPortID(ctx, tt.args.intfID, tt.args.onuID, tt.args.portNum)
kdarapu3248f9a2019-10-03 13:54:52 +0530727 if (err != nil) != tt.wantErr {
728 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() error = %v, wantErr %v", err, tt.wantErr)
729 return
730 }
731 if got != tt.want {
732 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, want %v", got, tt.want)
733 }
734
735 })
736 }
737}
738
739func TestOpenOltFlowMgr_DeleteTechProfileInstance(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530740 // flwMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530741 type args struct {
742 intfID uint32
743 onuID uint32
744 uniID uint32
745 sn string
Gamze Abakafee36392019-10-03 11:17:24 +0000746 tpID uint32
kdarapu3248f9a2019-10-03 13:54:52 +0530747 }
748 tests := []struct {
749 name string
750 args args
751 wantErr bool
752 }{
753 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000754 {"DeleteTechProfileInstance", args{intfID: 0, onuID: 1, uniID: 1, sn: "", tpID: 64}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530755 }
npujarec5762e2020-01-01 14:08:48 +0530756 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
757 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530758 for _, tt := range tests {
759 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530760 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 +0530761 t.Errorf("OpenOltFlowMgr.DeleteTechProfileInstance() error = %v, wantErr %v", err, tt.wantErr)
762 }
763 })
764 }
765}
kdarapub26b4502019-10-05 03:02:33 +0530766
767func TestOpenOltFlowMgr_checkAndAddFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000768 ctx := context.Background()
kdarapub26b4502019-10-05 03:02:33 +0530769 // flowMgr := newMockFlowmgr()
770 kw := make(map[string]uint64)
771 kw["table_id"] = 1
772 kw["meter_id"] = 1
773 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
774
775 // Upstream flow
776 fa := &fu.FlowArgs{
777 MatchFields: []*ofp.OfpOxmOfbField{
778 fu.InPort(536870912),
779 fu.Metadata_ofp(1),
780 fu.IpProto(17), // dhcp
Gamze Abakafee36392019-10-03 11:17:24 +0000781 fu.VlanPcp(0),
kdarapub26b4502019-10-05 03:02:33 +0530782 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
783 },
784 Actions: []*ofp.OfpAction{
785 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
786 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
787 fu.Output(65536),
788 fu.PushVlan(0x8100),
789 },
790 KV: kw,
791 }
792
793 // EAPOL
794 fa2 := &fu.FlowArgs{
795 MatchFields: []*ofp.OfpOxmOfbField{
796 fu.InPort(536870912),
797 fu.Metadata_ofp(1),
798 fu.EthType(0x888E),
799 fu.VlanPcp(1),
800 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
801 },
802 Actions: []*ofp.OfpAction{
803 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
804 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
805 fu.Output(65536),
806 fu.PushVlan(0x8100),
807 },
808 KV: kw,
809 }
810
811 // HSIA
812 fa3 := &fu.FlowArgs{
813 MatchFields: []*ofp.OfpOxmOfbField{
814 fu.InPort(536870912),
815 fu.Metadata_ofp(1),
816 //fu.EthType(0x8100),
817 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
818 },
819 Actions: []*ofp.OfpAction{
820 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
821 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)),
822 fu.Output(65536),
823 fu.PushVlan(0x8100),
824 },
825 KV: kw,
826 }
827
828 fa4 := &fu.FlowArgs{
829 MatchFields: []*ofp.OfpOxmOfbField{
830 fu.InPort(65535),
831 fu.Metadata_ofp(1),
832 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
833 fu.VlanPcp(1),
834 },
835 Actions: []*ofp.OfpAction{
836 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
837 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)),
838 fu.Output(536870912),
839 fu.PopVlan(),
840 },
841 KV: kw,
842 }
843
844 classifierInfo := make(map[string]interface{})
845 actionInfo := make(map[string]interface{})
846 classifierInfo2 := make(map[string]interface{})
847 actionInfo2 := make(map[string]interface{})
848 classifierInfo3 := make(map[string]interface{})
849 actionInfo3 := make(map[string]interface{})
850 classifierInfo4 := make(map[string]interface{})
851 actionInfo4 := make(map[string]interface{})
divyadesaid26f6b12020-03-19 06:30:28 +0000852 flowState, _ := fu.MkFlowStat(fa)
853 flowState2, _ := fu.MkFlowStat(fa2)
854 flowState3, _ := fu.MkFlowStat(fa3)
855 flowState4, _ := fu.MkFlowStat(fa4)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000856 formulateClassifierInfoFromFlow(ctx, classifierInfo, flowState)
857 formulateClassifierInfoFromFlow(ctx, classifierInfo2, flowState2)
858 formulateClassifierInfoFromFlow(ctx, classifierInfo3, flowState3)
859 formulateClassifierInfoFromFlow(ctx, classifierInfo4, flowState4)
kdarapub26b4502019-10-05 03:02:33 +0530860
Neha Sharma96b7bf22020-06-15 10:37:32 +0000861 err := formulateActionInfoFromFlow(ctx, actionInfo, classifierInfo, flowState)
kdarapub26b4502019-10-05 03:02:33 +0530862 if err != nil {
863 // Error logging is already done in the called function
864 // So just return in case of error
865 return
866 }
867
Neha Sharma96b7bf22020-06-15 10:37:32 +0000868 err = formulateActionInfoFromFlow(ctx, actionInfo2, classifierInfo2, flowState2)
kdarapub26b4502019-10-05 03:02:33 +0530869 if err != nil {
870 // Error logging is already done in the called function
871 // So just return in case of error
872 return
873 }
874
Neha Sharma96b7bf22020-06-15 10:37:32 +0000875 err = formulateActionInfoFromFlow(ctx, actionInfo3, classifierInfo3, flowState3)
kdarapub26b4502019-10-05 03:02:33 +0530876 if err != nil {
877 // Error logging is already done in the called function
878 // So just return in case of error
879 return
880 }
881
Neha Sharma96b7bf22020-06-15 10:37:32 +0000882 err = formulateActionInfoFromFlow(ctx, actionInfo4, classifierInfo4, flowState4)
kdarapub26b4502019-10-05 03:02:33 +0530883 if err != nil {
884 // Error logging is already done in the called function
885 // So just return in case of error
886 return
887 }
888
889 //ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1}
890 //flowMetadata := &voltha.FlowMetadata{
891 // Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
892 //}
893
894 TpInst := &tp.TechProfile{
895 Name: "Test-Tech-Profile",
896 SubscriberIdentifier: "257",
897 ProfileType: "Mock",
898 Version: 1,
899 NumGemPorts: 4,
kdarapub26b4502019-10-05 03:02:33 +0530900 InstanceCtrl: tp.InstanceControl{
901 Onu: "1",
902 Uni: "16",
903 },
904 }
905
906 type fields struct {
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530907 techprofile []tp.TechProfileIf
908 deviceHandler *DeviceHandler
909 resourceMgr *rsrcMgr.OpenOltResourceMgr
kdarapub26b4502019-10-05 03:02:33 +0530910 }
911 type args struct {
912 args map[string]uint32
913 classifierInfo map[string]interface{}
914 actionInfo map[string]interface{}
915 flow *ofp.OfpFlowStats
916 gemPort uint32
917 intfID uint32
918 onuID uint32
919 uniID uint32
920 portNo uint32
921 TpInst *tp.TechProfile
922 allocID []uint32
923 gemPorts []uint32
924 TpID uint32
925 uni string
926 }
927 tests := []struct {
928 name string
929 fields fields
930 args args
931 }{
932 {
933 name: "checkAndAddFlow-1",
934 args: args{
935 args: nil,
936 classifierInfo: classifierInfo,
937 actionInfo: actionInfo,
938 flow: flowState,
939 gemPort: 1,
940 intfID: 1,
941 onuID: 1,
942 uniID: 16,
943 portNo: 1,
944 TpInst: TpInst,
945 allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004},
946 gemPorts: []uint32{1, 2, 3, 4},
947 TpID: 64,
948 uni: "16",
949 },
950 },
951 {
952 name: "checkAndAddFlow-2",
953 args: args{
954 args: nil,
955 classifierInfo: classifierInfo2,
956 actionInfo: actionInfo2,
957 flow: flowState2,
958 gemPort: 1,
959 intfID: 1,
960 onuID: 1,
961 uniID: 16,
962 portNo: 1,
963 TpInst: TpInst,
964 allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004},
965 gemPorts: []uint32{1, 2, 3, 4},
966 TpID: 64,
967 uni: "16",
968 },
969 },
970 {
971 name: "checkAndAddFlow-3",
972 args: args{
973 args: nil,
974 classifierInfo: classifierInfo3,
975 actionInfo: actionInfo3,
976 flow: flowState3,
977 gemPort: 1,
978 intfID: 1,
979 onuID: 1,
980 uniID: 16,
981 portNo: 1,
982 TpInst: TpInst,
983 allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004},
984 gemPorts: []uint32{1, 2, 3, 4},
985 TpID: 64,
986 uni: "16",
987 },
988 },
989 {
990 name: "checkAndAddFlow-4",
991 args: args{
992 args: nil,
993 classifierInfo: classifierInfo4,
994 actionInfo: actionInfo4,
995 flow: flowState4,
996 gemPort: 1,
997 intfID: 1,
998 onuID: 1,
999 uniID: 16,
1000 portNo: 1,
1001 TpInst: TpInst,
1002 allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004},
1003 gemPorts: []uint32{1, 2, 3, 4},
1004 TpID: 64,
1005 uni: "16",
1006 },
1007 },
1008 }
npujarec5762e2020-01-01 14:08:48 +05301009 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1010 defer cancel()
kdarapub26b4502019-10-05 03:02:33 +05301011 for _, tt := range tests {
1012 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301013 flowMgr.checkAndAddFlow(ctx, tt.args.args, tt.args.classifierInfo, tt.args.actionInfo, tt.args.flow,
Gamze Abakafee36392019-10-03 11:17:24 +00001014 tt.args.TpInst, tt.args.gemPorts, tt.args.TpID, tt.args.uni)
kdarapub26b4502019-10-05 03:02:33 +05301015 })
1016 }
1017}
Esin Karamanccb714b2019-11-29 15:02:06 +00001018
1019func TestOpenOltFlowMgr_TestMulticastFlow(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301020 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1021 defer cancel()
Esin Karamanccb714b2019-11-29 15:02:06 +00001022 //create group
1023 group := newGroup(2, []uint32{1})
npujarec5762e2020-01-01 14:08:48 +05301024 flowMgr.AddGroup(ctx, group)
Esin Karamanccb714b2019-11-29 15:02:06 +00001025
1026 //create multicast flow
1027 multicastFlowArgs := &fu.FlowArgs{
1028 MatchFields: []*ofp.OfpOxmOfbField{
1029 fu.InPort(65536),
1030 fu.VlanVid(660), //vlan
1031 fu.Metadata_ofp(uint64(66)), //inner vlan
1032 fu.EthType(0x800), //ipv4
1033 fu.Ipv4Dst(3809869825), //227.22.0.1
1034 },
1035 Actions: []*ofp.OfpAction{
1036 fu.Group(1),
1037 },
1038 }
divyadesaid26f6b12020-03-19 06:30:28 +00001039 ofpStats, _ := fu.MkFlowStat(multicastFlowArgs)
npujarec5762e2020-01-01 14:08:48 +05301040 flowMgr.AddFlow(ctx, ofpStats, &voltha.FlowMetadata{})
Esin Karamanccb714b2019-11-29 15:02:06 +00001041
1042 //add bucket to the group
1043 group = newGroup(2, []uint32{1, 2})
1044
npujarec5762e2020-01-01 14:08:48 +05301045 flowMgr.ModifyGroup(ctx, group)
Esin Karamanccb714b2019-11-29 15:02:06 +00001046}