blob: 4a74e9a4107c06e01fb93af9ec8f48e013cebce2 [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) {
kdarapub26b4502019-10-05 03:02:33 +0530268 // flowMgr := newMockFlowmgr()
Girish Kumar2ad402b2020-03-20 19:45:12 +0000269 logger.Debug("Info Warning Error: Starting RemoveFlow() test")
kdarapu3248f9a2019-10-03 13:54:52 +0530270 fa := &fu.FlowArgs{
271 MatchFields: []*ofp.OfpOxmOfbField{
272 fu.InPort(2),
273 fu.Metadata_ofp(2),
274 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
275 },
276 Actions: []*ofp.OfpAction{
277 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
278 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
279 fu.Output(1),
280 },
281 }
divyadesaid26f6b12020-03-19 06:30:28 +0000282 ofpstats, _ := fu.MkFlowStat(fa)
kdarapub26b4502019-10-05 03:02:33 +0530283 ofpstats.Cookie = ofpstats.Id
kdarapub26b4502019-10-05 03:02:33 +0530284 lldpFa := &fu.FlowArgs{
285 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
286 MatchFields: []*ofp.OfpOxmOfbField{
287 fu.InPort(1),
288 fu.EthType(0x88CC),
289 fu.TunnelId(536870912),
290 },
291 Actions: []*ofp.OfpAction{
292 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
293 },
294 }
divyadesaid26f6b12020-03-19 06:30:28 +0000295 lldpofpstats, _ := fu.MkFlowStat(lldpFa)
kdarapub26b4502019-10-05 03:02:33 +0530296 //lldpofpstats.Cookie = lldpofpstats.Id
297
298 dhcpFa := &fu.FlowArgs{
299 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
300 MatchFields: []*ofp.OfpOxmOfbField{
301 fu.InPort(1),
302 fu.UdpSrc(67),
303 //fu.TunnelId(536870912),
304 fu.IpProto(17),
305 },
306 Actions: []*ofp.OfpAction{
307 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
308 },
309 }
divyadesaid26f6b12020-03-19 06:30:28 +0000310 dhcpofpstats, _ := fu.MkFlowStat(dhcpFa)
kdarapub26b4502019-10-05 03:02:33 +0530311 //dhcpofpstats.Cookie = dhcpofpstats.Id
Esin Karamanccb714b2019-11-29 15:02:06 +0000312
313 //multicast flow
314 multicastFa := &fu.FlowArgs{
315 MatchFields: []*ofp.OfpOxmOfbField{
316 fu.InPort(65536),
317 fu.VlanVid(660), //vlan
318 fu.Metadata_ofp(uint64(66)), //inner vlan
319 fu.EthType(0x800), //ipv4
320 fu.Ipv4Dst(3809869825), //227.22.0.1
321 },
322 Actions: []*ofp.OfpAction{
323 fu.Group(1),
324 },
325 }
divyadesaid26f6b12020-03-19 06:30:28 +0000326 multicastOfpStats, _ := fu.MkFlowStat(multicastFa)
Esin Karamanccb714b2019-11-29 15:02:06 +0000327 multicastOfpStats.Id = 1
328
kdarapu3248f9a2019-10-03 13:54:52 +0530329 type args struct {
330 flow *ofp.OfpFlowStats
331 }
332 tests := []struct {
333 name string
334 args args
335 }{
336 // TODO: Add test cases.
337 {"RemoveFlow", args{flow: ofpstats}},
kdarapub26b4502019-10-05 03:02:33 +0530338 {"RemoveFlow", args{flow: lldpofpstats}},
339 {"RemoveFlow", args{flow: dhcpofpstats}},
Esin Karamanccb714b2019-11-29 15:02:06 +0000340 {"RemoveFlow", args{flow: multicastOfpStats}},
kdarapu3248f9a2019-10-03 13:54:52 +0530341 }
npujarec5762e2020-01-01 14:08:48 +0530342 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
343 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530344 for _, tt := range tests {
345 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530346 flowMgr.RemoveFlow(ctx, tt.args.flow)
kdarapu3248f9a2019-10-03 13:54:52 +0530347 })
348 }
kdarapub26b4502019-10-05 03:02:33 +0530349 // t.Error("=====")
kdarapu3248f9a2019-10-03 13:54:52 +0530350}
351
352func TestOpenOltFlowMgr_AddFlow(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530353 // flowMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530354 kw := make(map[string]uint64)
355 kw["table_id"] = 1
356 kw["meter_id"] = 1
kdarapub26b4502019-10-05 03:02:33 +0530357 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
358
359 // Upstream flow
kdarapu3248f9a2019-10-03 13:54:52 +0530360 fa := &fu.FlowArgs{
361 MatchFields: []*ofp.OfpOxmOfbField{
kdarapub26b4502019-10-05 03:02:33 +0530362 fu.InPort(536870912),
363 fu.Metadata_ofp(1),
364 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
365 },
366 Actions: []*ofp.OfpAction{
367 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
368 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
369 fu.Output(65536),
370 fu.PushVlan(0x8100),
371 },
372 KV: kw,
373 }
374
375 // Downstream flow
376 fa3 := &fu.FlowArgs{
377 MatchFields: []*ofp.OfpOxmOfbField{
378 fu.InPort(65536),
379 fu.Metadata_ofp(1),
380 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
381 },
382 Actions: []*ofp.OfpAction{
383 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
384 //fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
385 fu.PopVlan(),
386 fu.Output(536870912),
387 },
388 KV: kw,
389 }
390
391 fa2 := &fu.FlowArgs{
392 MatchFields: []*ofp.OfpOxmOfbField{
kdarapu3248f9a2019-10-03 13:54:52 +0530393 fu.InPort(1000),
394 fu.Metadata_ofp(1),
395 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
396 },
397 Actions: []*ofp.OfpAction{
398 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
399 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
400 fu.Output(65533),
401 },
402 KV: kw,
403 }
404
kdarapub26b4502019-10-05 03:02:33 +0530405 // TODO Add LLDP flow
406 // TODO Add DHCP flow
407
408 // Flows for negative scenarios
409 // Failure in formulateActionInfoFromFlow()
410 fa4 := &fu.FlowArgs{
411 MatchFields: []*ofp.OfpOxmOfbField{
412 fu.InPort(1000),
413 fu.Metadata_ofp(1),
414 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
415 },
416 Actions: []*ofp.OfpAction{
417 fu.Experimenter(257, []byte{1, 2, 3, 4}),
418 },
419 KV: kw,
420 }
421
422 // Invalid Output
423 fa5 := &fu.FlowArgs{
424 MatchFields: []*ofp.OfpOxmOfbField{
425 fu.InPort(1000),
426 fu.Metadata_ofp(1),
427 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
428 },
429 Actions: []*ofp.OfpAction{
430 fu.Output(0),
431 },
432 KV: kw,
433 }
434
435 // Tech-Profile-ID update (not supported)
436 kw6 := make(map[string]uint64)
437 kw6["table_id"] = 1
438 kw6["meter_id"] = 1
439 kw6["write_metadata"] = 0x4100000000 // TpID Other than the stored one
440 fa6 := &fu.FlowArgs{
441 MatchFields: []*ofp.OfpOxmOfbField{
442 fu.InPort(536870912),
443 fu.TunnelId(16),
444 fu.Metadata_ofp(1),
445 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
446 },
447 Actions: []*ofp.OfpAction{
448 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
449 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
450 fu.Output(65535),
451 },
452 KV: kw6,
453 }
454
455 lldpFa := &fu.FlowArgs{
456 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
457 MatchFields: []*ofp.OfpOxmOfbField{
458 fu.InPort(1),
459 fu.EthType(0x88CC),
460 fu.TunnelId(536870912),
461 },
462 Actions: []*ofp.OfpAction{
463 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
464 },
465 }
466
467 dhcpFa := &fu.FlowArgs{
468 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
469 MatchFields: []*ofp.OfpOxmOfbField{
470 fu.InPort(1),
471 fu.UdpSrc(67),
472 //fu.TunnelId(536870912),
473 fu.IpProto(17),
474 },
475 Actions: []*ofp.OfpAction{
476 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
477 },
478 }
479 igmpFa := &fu.FlowArgs{
480 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
481 MatchFields: []*ofp.OfpOxmOfbField{
482 fu.InPort(1),
483 fu.UdpSrc(67),
484 //fu.TunnelId(536870912),
485 fu.IpProto(2),
486 },
487 Actions: []*ofp.OfpAction{
488 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
489 },
490 }
491
492 fa9 := &fu.FlowArgs{
493 MatchFields: []*ofp.OfpOxmOfbField{
494 fu.InPort(536870912),
495 fu.TunnelId(16),
496 fu.Metadata_ofp(1),
497 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
498 fu.VlanPcp(1000),
499 fu.UdpDst(65535),
500 fu.UdpSrc(536870912),
501 fu.Ipv4Dst(65535),
502 fu.Ipv4Src(536870912),
503 },
504 Actions: []*ofp.OfpAction{
505 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
506 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
507 fu.Output(65535),
508 },
509 KV: kw6,
510 }
511
512 fa10 := &fu.FlowArgs{
513 MatchFields: []*ofp.OfpOxmOfbField{
514 fu.InPort(65533),
515 // fu.TunnelId(16),
516 fu.Metadata_ofp(1),
517 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
518 fu.VlanPcp(1000),
519 fu.UdpDst(65535),
520 fu.UdpSrc(536870912),
521 fu.Ipv4Dst(65535),
522 fu.Ipv4Src(536870912),
523 },
524 Actions: []*ofp.OfpAction{
525 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
526 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
527 fu.Output(65535),
528 },
529 KV: kw6,
530 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000531 //multicast flow
532 fa11 := &fu.FlowArgs{
533 MatchFields: []*ofp.OfpOxmOfbField{
534 fu.InPort(65536),
535 fu.VlanVid(660), //vlan
536 fu.Metadata_ofp(uint64(66)), //inner vlan
537 fu.EthType(0x800), //ipv4
538 fu.Ipv4Dst(3809869825), //227.22.0.1
539 },
540 Actions: []*ofp.OfpAction{
541 fu.Group(1),
542 },
543 KV: kw6,
544 }
divyadesaid26f6b12020-03-19 06:30:28 +0000545 ofpstats, _ := fu.MkFlowStat(fa)
546 ofpstats2, _ := fu.MkFlowStat(fa2)
547 ofpstats3, _ := fu.MkFlowStat(fa3)
548 ofpstats4, _ := fu.MkFlowStat(fa4)
549 ofpstats5, _ := fu.MkFlowStat(fa5)
550 ofpstats6, _ := fu.MkFlowStat(fa6)
551 ofpstats7, _ := fu.MkFlowStat(lldpFa)
552 ofpstats8, _ := fu.MkFlowStat(dhcpFa)
553 ofpstats9, _ := fu.MkFlowStat(fa9)
554 ofpstats10, _ := fu.MkFlowStat(fa10)
555 igmpstats, _ := fu.MkFlowStat(igmpFa)
556 ofpstats11, _ := fu.MkFlowStat(fa11)
kdarapub26b4502019-10-05 03:02:33 +0530557
Gamze Abakafee36392019-10-03 11:17:24 +0000558 fmt.Println(ofpstats6, ofpstats9, ofpstats10)
559
kdarapu3248f9a2019-10-03 13:54:52 +0530560 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1}
kdarapu3248f9a2019-10-03 13:54:52 +0530561 flowMetadata := &voltha.FlowMetadata{
562 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
563 }
564 type args struct {
565 flow *ofp.OfpFlowStats
566 flowMetadata *voltha.FlowMetadata
567 }
568 tests := []struct {
569 name string
570 args args
571 }{
572 // TODO: Add test cases.
573 {"AddFlow", args{flow: ofpstats, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530574 {"AddFlow", args{flow: ofpstats2, flowMetadata: flowMetadata}},
575 {"AddFlow", args{flow: ofpstats3, flowMetadata: flowMetadata}},
576 {"AddFlow", args{flow: ofpstats4, flowMetadata: flowMetadata}},
577 {"AddFlow", args{flow: ofpstats5, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000578 //{"AddFlow", args{flow: ofpstats6, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530579 {"AddFlow", args{flow: ofpstats7, flowMetadata: flowMetadata}},
580 {"AddFlow", args{flow: ofpstats8, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000581 //{"AddFlow", args{flow: ofpstats9, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530582 {"AddFlow", args{flow: igmpstats, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000583 //{"AddFlow", args{flow: ofpstats10, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530584 //ofpstats10
Esin Karamanccb714b2019-11-29 15:02:06 +0000585 {"AddFlow", args{flow: ofpstats11, flowMetadata: flowMetadata}},
kdarapu3248f9a2019-10-03 13:54:52 +0530586 }
npujarec5762e2020-01-01 14:08:48 +0530587 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
588 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530589 for _, tt := range tests {
590 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530591 flowMgr.AddFlow(ctx, tt.args.flow, tt.args.flowMetadata)
kdarapu3248f9a2019-10-03 13:54:52 +0530592 })
593 }
594}
595
596func TestOpenOltFlowMgr_UpdateOnuInfo(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530597 // flowMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530598 type args struct {
599 intfID uint32
600 onuID uint32
601 serialNum string
602 }
603 tests := []struct {
604 name string
605 args args
606 }{
607 // TODO: Add test cases.
608 {"UpdateOnuInfo", args{1, 1, "onu1"}},
609 {"UpdateOnuInfo", args{2, 3, "onu1"}},
610 }
npujarec5762e2020-01-01 14:08:48 +0530611 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
612 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530613 for _, tt := range tests {
614 t.Run(tt.name, func(t *testing.T) {
615
npujarec5762e2020-01-01 14:08:48 +0530616 flowMgr.UpdateOnuInfo(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum)
kdarapu3248f9a2019-10-03 13:54:52 +0530617 })
618 }
619}
620
serkant.uluderya96af4932020-02-20 16:58:48 -0800621func TestOpenOltFlowMgr_deleteGemPortFromLocalCache(t *testing.T) {
622 // flowMgr := newMockFlowmgr()
623 type args struct {
624 intfID uint32
625 onuID uint32
626 gemPortIDs []uint32
627 gemPortIDsToBeDeleted []uint32
628 serialNum string
629 finalLength int
630 }
631 tests := []struct {
632 name string
633 args args
634 }{
635 // Add/Delete single gem port
636 {"DeleteGemPortFromLocalCache1", args{0, 1, []uint32{1}, []uint32{1}, "onu1", 0}},
637 // Delete all gemports
638 {"DeleteGemPortFromLocalCache2", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{1, 2, 3, 4}, "onu1", 0}},
639 // Try to delete when there is no gem port
640 {"DeleteGemPortFromLocalCache3", args{0, 1, []uint32{}, []uint32{1, 2}, "onu1", 0}},
641 // Try to delete non-existent gem port
642 {"DeleteGemPortFromLocalCache4", args{0, 1, []uint32{1}, []uint32{2}, "onu1", 1}},
643 // Try to delete two of the gem ports
644 {"DeleteGemPortFromLocalCache5", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{2, 4}, "onu1", 2}},
645 }
646 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
647 defer cancel()
648 for _, tt := range tests {
649 t.Run(tt.name, func(t *testing.T) {
650 flowMgr.UpdateOnuInfo(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum)
651 for _, gemPort := range tt.args.gemPortIDs {
652 flowMgr.addGemPortToOnuInfoMap(ctx, tt.args.intfID, tt.args.onuID, gemPort)
653 }
654 for _, gemPortDeleted := range tt.args.gemPortIDsToBeDeleted {
655 flowMgr.deleteGemPortFromLocalCache(tt.args.intfID, tt.args.onuID, gemPortDeleted)
656 }
657 lenofGemPorts := len(flowMgr.onuGemInfo[tt.args.intfID][0].GemPorts)
658 if lenofGemPorts != tt.args.finalLength {
659 t.Errorf("GemPorts length is not as expected len = %d, want %d", lenofGemPorts, tt.args.finalLength)
660 }
661
662 })
663 }
664}
665
kdarapu3248f9a2019-10-03 13:54:52 +0530666func TestOpenOltFlowMgr_GetLogicalPortFromPacketIn(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530667 // flowMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530668 type args struct {
669 packetIn *openoltpb2.PacketIndication
670 }
671 tests := []struct {
672 name string
673 args args
674 want uint32
675 wantErr bool
676 }{
677 // TODO: Add test cases.
678 {"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 +0000679 {"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 +0530680 // Negative Test cases.
681 {"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 +0000682 {"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 +0530683 }
npujarec5762e2020-01-01 14:08:48 +0530684 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
685 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530686 for _, tt := range tests {
687 t.Run(tt.name, func(t *testing.T) {
688
npujarec5762e2020-01-01 14:08:48 +0530689 got, err := flowMgr.GetLogicalPortFromPacketIn(ctx, tt.args.packetIn)
kdarapu3248f9a2019-10-03 13:54:52 +0530690 if (err != nil) != tt.wantErr {
691 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() error = %v, wantErr %v", err, tt.wantErr)
692 return
693 }
694 if got != tt.want {
695 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() = %v, want %v", got, tt.want)
696 }
697 })
698 }
699}
700
701func TestOpenOltFlowMgr_GetPacketOutGemPortID(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530702 // flwMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530703
704 type args struct {
705 intfID uint32
706 onuID uint32
707 portNum uint32
708 }
709 tests := []struct {
710 name string
711 args args
712 want uint32
713 wantErr bool
714 }{
715 // TODO: Add test cases.
716 {"GetPacketOutGemPortID", args{intfID: 1, onuID: 1, portNum: 1}, 1, false},
717 {"GetPacketOutGemPortID", args{intfID: 2, onuID: 2, portNum: 2}, 2, false},
718 {"GetPacketOutGemPortID", args{intfID: 1, onuID: 2, portNum: 2}, 0, true},
719 }
npujarec5762e2020-01-01 14:08:48 +0530720 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
721 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530722 for _, tt := range tests {
723 t.Run(tt.name, func(t *testing.T) {
724
npujarec5762e2020-01-01 14:08:48 +0530725 got, err := flowMgr.GetPacketOutGemPortID(ctx, tt.args.intfID, tt.args.onuID, tt.args.portNum)
kdarapu3248f9a2019-10-03 13:54:52 +0530726 if (err != nil) != tt.wantErr {
727 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() error = %v, wantErr %v", err, tt.wantErr)
728 return
729 }
730 if got != tt.want {
731 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, want %v", got, tt.want)
732 }
733
734 })
735 }
736}
737
738func TestOpenOltFlowMgr_DeleteTechProfileInstance(t *testing.T) {
kdarapub26b4502019-10-05 03:02:33 +0530739 // flwMgr := newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530740 type args struct {
741 intfID uint32
742 onuID uint32
743 uniID uint32
744 sn string
Gamze Abakafee36392019-10-03 11:17:24 +0000745 tpID uint32
kdarapu3248f9a2019-10-03 13:54:52 +0530746 }
747 tests := []struct {
748 name string
749 args args
750 wantErr bool
751 }{
752 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000753 {"DeleteTechProfileInstance", args{intfID: 0, onuID: 1, uniID: 1, sn: "", tpID: 64}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530754 }
npujarec5762e2020-01-01 14:08:48 +0530755 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
756 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530757 for _, tt := range tests {
758 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530759 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 +0530760 t.Errorf("OpenOltFlowMgr.DeleteTechProfileInstance() error = %v, wantErr %v", err, tt.wantErr)
761 }
762 })
763 }
764}
kdarapub26b4502019-10-05 03:02:33 +0530765
766func TestOpenOltFlowMgr_checkAndAddFlow(t *testing.T) {
767 // flowMgr := newMockFlowmgr()
768 kw := make(map[string]uint64)
769 kw["table_id"] = 1
770 kw["meter_id"] = 1
771 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
772
773 // Upstream flow
774 fa := &fu.FlowArgs{
775 MatchFields: []*ofp.OfpOxmOfbField{
776 fu.InPort(536870912),
777 fu.Metadata_ofp(1),
778 fu.IpProto(17), // dhcp
Gamze Abakafee36392019-10-03 11:17:24 +0000779 fu.VlanPcp(0),
kdarapub26b4502019-10-05 03:02:33 +0530780 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
781 },
782 Actions: []*ofp.OfpAction{
783 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
784 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
785 fu.Output(65536),
786 fu.PushVlan(0x8100),
787 },
788 KV: kw,
789 }
790
791 // EAPOL
792 fa2 := &fu.FlowArgs{
793 MatchFields: []*ofp.OfpOxmOfbField{
794 fu.InPort(536870912),
795 fu.Metadata_ofp(1),
796 fu.EthType(0x888E),
797 fu.VlanPcp(1),
798 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
799 },
800 Actions: []*ofp.OfpAction{
801 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
802 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
803 fu.Output(65536),
804 fu.PushVlan(0x8100),
805 },
806 KV: kw,
807 }
808
809 // HSIA
810 fa3 := &fu.FlowArgs{
811 MatchFields: []*ofp.OfpOxmOfbField{
812 fu.InPort(536870912),
813 fu.Metadata_ofp(1),
814 //fu.EthType(0x8100),
815 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
816 },
817 Actions: []*ofp.OfpAction{
818 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
819 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)),
820 fu.Output(65536),
821 fu.PushVlan(0x8100),
822 },
823 KV: kw,
824 }
825
826 fa4 := &fu.FlowArgs{
827 MatchFields: []*ofp.OfpOxmOfbField{
828 fu.InPort(65535),
829 fu.Metadata_ofp(1),
830 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0),
831 fu.VlanPcp(1),
832 },
833 Actions: []*ofp.OfpAction{
834 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
835 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)),
836 fu.Output(536870912),
837 fu.PopVlan(),
838 },
839 KV: kw,
840 }
841
842 classifierInfo := make(map[string]interface{})
843 actionInfo := make(map[string]interface{})
844 classifierInfo2 := make(map[string]interface{})
845 actionInfo2 := make(map[string]interface{})
846 classifierInfo3 := make(map[string]interface{})
847 actionInfo3 := make(map[string]interface{})
848 classifierInfo4 := make(map[string]interface{})
849 actionInfo4 := make(map[string]interface{})
divyadesaid26f6b12020-03-19 06:30:28 +0000850 flowState, _ := fu.MkFlowStat(fa)
851 flowState2, _ := fu.MkFlowStat(fa2)
852 flowState3, _ := fu.MkFlowStat(fa3)
853 flowState4, _ := fu.MkFlowStat(fa4)
kdarapub26b4502019-10-05 03:02:33 +0530854 formulateClassifierInfoFromFlow(classifierInfo, flowState)
855 formulateClassifierInfoFromFlow(classifierInfo2, flowState2)
856 formulateClassifierInfoFromFlow(classifierInfo3, flowState3)
857 formulateClassifierInfoFromFlow(classifierInfo4, flowState4)
858
859 err := formulateActionInfoFromFlow(actionInfo, classifierInfo, flowState)
860 if err != nil {
861 // Error logging is already done in the called function
862 // So just return in case of error
863 return
864 }
865
866 err = formulateActionInfoFromFlow(actionInfo2, classifierInfo2, flowState2)
867 if err != nil {
868 // Error logging is already done in the called function
869 // So just return in case of error
870 return
871 }
872
873 err = formulateActionInfoFromFlow(actionInfo3, classifierInfo3, flowState3)
874 if err != nil {
875 // Error logging is already done in the called function
876 // So just return in case of error
877 return
878 }
879
880 err = formulateActionInfoFromFlow(actionInfo4, classifierInfo4, flowState4)
881 if err != nil {
882 // Error logging is already done in the called function
883 // So just return in case of error
884 return
885 }
886
887 //ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1}
888 //flowMetadata := &voltha.FlowMetadata{
889 // Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
890 //}
891
892 TpInst := &tp.TechProfile{
893 Name: "Test-Tech-Profile",
894 SubscriberIdentifier: "257",
895 ProfileType: "Mock",
896 Version: 1,
897 NumGemPorts: 4,
kdarapub26b4502019-10-05 03:02:33 +0530898 InstanceCtrl: tp.InstanceControl{
899 Onu: "1",
900 Uni: "16",
901 },
902 }
903
904 type fields struct {
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530905 techprofile []tp.TechProfileIf
906 deviceHandler *DeviceHandler
907 resourceMgr *rsrcMgr.OpenOltResourceMgr
kdarapub26b4502019-10-05 03:02:33 +0530908 }
909 type args struct {
910 args map[string]uint32
911 classifierInfo map[string]interface{}
912 actionInfo map[string]interface{}
913 flow *ofp.OfpFlowStats
914 gemPort uint32
915 intfID uint32
916 onuID uint32
917 uniID uint32
918 portNo uint32
919 TpInst *tp.TechProfile
920 allocID []uint32
921 gemPorts []uint32
922 TpID uint32
923 uni string
924 }
925 tests := []struct {
926 name string
927 fields fields
928 args args
929 }{
930 {
931 name: "checkAndAddFlow-1",
932 args: args{
933 args: nil,
934 classifierInfo: classifierInfo,
935 actionInfo: actionInfo,
936 flow: flowState,
937 gemPort: 1,
938 intfID: 1,
939 onuID: 1,
940 uniID: 16,
941 portNo: 1,
942 TpInst: TpInst,
943 allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004},
944 gemPorts: []uint32{1, 2, 3, 4},
945 TpID: 64,
946 uni: "16",
947 },
948 },
949 {
950 name: "checkAndAddFlow-2",
951 args: args{
952 args: nil,
953 classifierInfo: classifierInfo2,
954 actionInfo: actionInfo2,
955 flow: flowState2,
956 gemPort: 1,
957 intfID: 1,
958 onuID: 1,
959 uniID: 16,
960 portNo: 1,
961 TpInst: TpInst,
962 allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004},
963 gemPorts: []uint32{1, 2, 3, 4},
964 TpID: 64,
965 uni: "16",
966 },
967 },
968 {
969 name: "checkAndAddFlow-3",
970 args: args{
971 args: nil,
972 classifierInfo: classifierInfo3,
973 actionInfo: actionInfo3,
974 flow: flowState3,
975 gemPort: 1,
976 intfID: 1,
977 onuID: 1,
978 uniID: 16,
979 portNo: 1,
980 TpInst: TpInst,
981 allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004},
982 gemPorts: []uint32{1, 2, 3, 4},
983 TpID: 64,
984 uni: "16",
985 },
986 },
987 {
988 name: "checkAndAddFlow-4",
989 args: args{
990 args: nil,
991 classifierInfo: classifierInfo4,
992 actionInfo: actionInfo4,
993 flow: flowState4,
994 gemPort: 1,
995 intfID: 1,
996 onuID: 1,
997 uniID: 16,
998 portNo: 1,
999 TpInst: TpInst,
1000 allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004},
1001 gemPorts: []uint32{1, 2, 3, 4},
1002 TpID: 64,
1003 uni: "16",
1004 },
1005 },
1006 }
npujarec5762e2020-01-01 14:08:48 +05301007 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1008 defer cancel()
kdarapub26b4502019-10-05 03:02:33 +05301009 for _, tt := range tests {
1010 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301011 flowMgr.checkAndAddFlow(ctx, tt.args.args, tt.args.classifierInfo, tt.args.actionInfo, tt.args.flow,
Gamze Abakafee36392019-10-03 11:17:24 +00001012 tt.args.TpInst, tt.args.gemPorts, tt.args.TpID, tt.args.uni)
kdarapub26b4502019-10-05 03:02:33 +05301013 })
1014 }
1015}
Esin Karamanccb714b2019-11-29 15:02:06 +00001016
1017func TestOpenOltFlowMgr_TestMulticastFlow(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301018 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1019 defer cancel()
Esin Karamanccb714b2019-11-29 15:02:06 +00001020 //create group
1021 group := newGroup(2, []uint32{1})
npujarec5762e2020-01-01 14:08:48 +05301022 flowMgr.AddGroup(ctx, group)
Esin Karamanccb714b2019-11-29 15:02:06 +00001023
1024 //create multicast flow
1025 multicastFlowArgs := &fu.FlowArgs{
1026 MatchFields: []*ofp.OfpOxmOfbField{
1027 fu.InPort(65536),
1028 fu.VlanVid(660), //vlan
1029 fu.Metadata_ofp(uint64(66)), //inner vlan
1030 fu.EthType(0x800), //ipv4
1031 fu.Ipv4Dst(3809869825), //227.22.0.1
1032 },
1033 Actions: []*ofp.OfpAction{
1034 fu.Group(1),
1035 },
1036 }
divyadesaid26f6b12020-03-19 06:30:28 +00001037 ofpStats, _ := fu.MkFlowStat(multicastFlowArgs)
npujarec5762e2020-01-01 14:08:48 +05301038 flowMgr.AddFlow(ctx, ofpStats, &voltha.FlowMetadata{})
Esin Karamanccb714b2019-11-29 15:02:06 +00001039
1040 //add bucket to the group
1041 group = newGroup(2, []uint32{1, 2})
1042
npujarec5762e2020-01-01 14:08:48 +05301043 flowMgr.ModifyGroup(ctx, group)
Esin Karamanccb714b2019-11-29 15:02:06 +00001044}