blob: b69feb0fc0a52a6eecce6c54332182312b799342 [file] [log] [blame]
kdarapu3248f9a2019-10-03 13:54:52 +05301/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Scott Bakerdbd960e2020-02-28 08:57:51 -080017//Package core provides the utility for olt devices, flows and statistics
18package core
kdarapu3248f9a2019-10-03 13:54:52 +053019
20import (
npujarec5762e2020-01-01 14:08:48 +053021 "context"
Esin Karaman7fb80c22020-07-16 14:23:33 +000022 "encoding/hex"
Gamze Abakafee36392019-10-03 11:17:24 +000023 "fmt"
Matteo Scandoloabf9c512020-06-23 19:31:14 -070024 "reflect"
25 "strconv"
26 "sync"
kdarapu3248f9a2019-10-03 13:54:52 +053027 "testing"
npujarec5762e2020-01-01 14:08:48 +053028 "time"
kdarapu3248f9a2019-10-03 13:54:52 +053029
Girish Gowdraa09aeab2020-09-14 16:30:52 -070030 "github.com/opencord/voltha-protos/v4/go/voltha"
kdarapub26b4502019-10-05 03:02:33 +053031
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070032 fu "github.com/opencord/voltha-lib-go/v5/pkg/flows"
33 "github.com/opencord/voltha-lib-go/v5/pkg/log"
Scott Bakerdbd960e2020-02-28 08:57:51 -080034 rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070035 ofp "github.com/opencord/voltha-protos/v4/go/openflow_13"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070036 openoltpb2 "github.com/opencord/voltha-protos/v4/go/openolt"
37 tp_pb "github.com/opencord/voltha-protos/v4/go/tech_profile"
kdarapu3248f9a2019-10-03 13:54:52 +053038)
39
Girish Gowdra9602eb42020-09-09 15:50:39 -070040var flowMgr []*OpenOltFlowMgr
kdarapub26b4502019-10-05 03:02:33 +053041
kdarapu3248f9a2019-10-03 13:54:52 +053042func init() {
Kent Hagermane6ff1012020-07-14 15:07:53 -040043 _, _ = log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
kdarapub26b4502019-10-05 03:02:33 +053044 flowMgr = newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +053045}
kdarapu3248f9a2019-10-03 13:54:52 +053046
Girish Gowdra9602eb42020-09-09 15:50:39 -070047func newMockFlowmgr() []*OpenOltFlowMgr {
kdarapu3248f9a2019-10-03 13:54:52 +053048 dh := newMockDeviceHandler()
49
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070050 // onuGemInfoMap := make([]rsrcMgr.onuGemInfoMap, NumPonPorts)
Girish Gowdra9602eb42020-09-09 15:50:39 -070051 var i uint32
kdarapu3248f9a2019-10-03 13:54:52 +053052
Girish Gowdra9602eb42020-09-09 15:50:39 -070053 for i = 0; i < NumPonPorts; i++ {
54 packetInGemPort := make(map[rsrcMgr.PacketInInfoKey]uint32)
55 packetInGemPort[rsrcMgr.PacketInInfoKey{IntfID: i, OnuID: i + 1, LogicalPort: i + 1, VlanID: uint16(i), Priority: uint8(i)}] = i + 1
kdarapu3248f9a2019-10-03 13:54:52 +053056
Girish Gowdra9602eb42020-09-09 15:50:39 -070057 dh.flowMgr[i].packetInGemPort = packetInGemPort
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070058 dh.flowMgr[i].techprofile = dh.resourceMgr[i].PonRsrMgr.TechProfileMgr
Girish Gowdra9602eb42020-09-09 15:50:39 -070059 interface2mcastQeueuMap := make(map[uint32]*QueueInfoBrief)
60 interface2mcastQeueuMap[0] = &QueueInfoBrief{
61 gemPortID: 4000,
62 servicePriority: 3,
63 }
64 dh.flowMgr[i].grpMgr.interfaceToMcastQueueMap = interface2mcastQeueuMap
kdarapu3248f9a2019-10-03 13:54:52 +053065 }
Girish Gowdra9602eb42020-09-09 15:50:39 -070066 return dh.flowMgr
kdarapu3248f9a2019-10-03 13:54:52 +053067}
kdarapub26b4502019-10-05 03:02:33 +053068
kdarapu3248f9a2019-10-03 13:54:52 +053069func TestOpenOltFlowMgr_CreateSchedulerQueues(t *testing.T) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070070 tprofile := &tp_pb.TechProfileInstance{Name: "tp1", SubscriberIdentifier: "subscriber1",
Girish Gowdra54934262019-11-13 14:19:55 +053071 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070072 InstanceControl: &tp_pb.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"},
kdarapu3248f9a2019-10-03 13:54:52 +053073 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070074 tprofile.UsScheduler = &openoltpb2.SchedulerAttributes{}
75 tprofile.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
76 tprofile.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +053077
78 tprofile2 := tprofile
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070079 tprofile2.DsScheduler = &openoltpb2.SchedulerAttributes{}
80 tprofile2.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
81 tprofile2.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Gamze Abaka01174422021-03-10 06:55:27 +000082
kdarapu3248f9a2019-10-03 13:54:52 +053083 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +000084 name string
85 schedQueue schedQueue
86 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +053087 }{
88 // TODO: Add test cases.
Gamze Abaka01174422021-03-10 06:55:27 +000089 {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 1, Upstream)}, false},
90 {"CreateSchedulerQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 1, Downstream)}, false},
91 {"CreateSchedulerQueues-13", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 2, Upstream)}, false},
92 {"CreateSchedulerQueues-14", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 2, Downstream)}, false},
93 {"CreateSchedulerQueues-15", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 3, Upstream)}, false},
94 {"CreateSchedulerQueues-16", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 3, Downstream)}, false},
95 {"CreateSchedulerQueues-17", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 4, Upstream)}, false},
96 {"CreateSchedulerQueues-18", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 4, Downstream)}, false},
97 {"CreateSchedulerQueues-19", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 5, Upstream)}, false},
98 {"CreateSchedulerQueues-20", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 5, Downstream)}, false},
99
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700100 {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 0, Upstream)}, false},
101 {"CreateSchedulerQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 0, Downstream)}, false},
Gamze Abaka01174422021-03-10 06:55:27 +0000102 {"CreateSchedulerQueues-3", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, createFlowMetadata(tprofile, 2, Upstream)}, true},
103 {"CreateSchedulerQueues-4", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, createFlowMetadata(tprofile2, 2, Downstream)}, true},
104 {"CreateSchedulerQueues-5", schedQueue{tp_pb.Direction_UPSTREAM, 1, 2, 2, 64, 2, tprofile, 2, createFlowMetadata(tprofile, 3, Upstream)}, true},
105 {"CreateSchedulerQueues-6", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 2, 2, 65, 2, tprofile2, 2, createFlowMetadata(tprofile2, 3, Downstream)}, true},
106
kdarapu3248f9a2019-10-03 13:54:52 +0530107 //Negative testcases
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700108 {"CreateSchedulerQueues-7", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, &voltha.FlowMetadata{}}, false},
Girish Gowdra9602eb42020-09-09 15:50:39 -0700109 {"CreateSchedulerQueues-8", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 0, &voltha.FlowMetadata{}}, true},
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700110 {"CreateSchedulerQueues-9", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, &voltha.FlowMetadata{}}, false},
Girish Gowdra9602eb42020-09-09 15:50:39 -0700111 {"CreateSchedulerQueues-10", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, &voltha.FlowMetadata{}}, true},
112 {"CreateSchedulerQueues-11", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, &voltha.FlowMetadata{}}, true},
113 {"CreateSchedulerQueues-12", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, nil}, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530114 }
npujarec5762e2020-01-01 14:08:48 +0530115 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
116 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530117 for _, tt := range tests {
118 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700119 if err := flowMgr[tt.schedQueue.intfID].CreateSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530120 t.Errorf("OpenOltFlowMgr.CreateSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr)
121 }
122 })
123 }
124}
125
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700126func createFlowMetadata(techProfile *tp_pb.TechProfileInstance, tcontType int, direction string) *voltha.FlowMetadata {
127 var additionalBw openoltpb2.AdditionalBW
Gamze Abaka01174422021-03-10 06:55:27 +0000128 bands := make([]*ofp.OfpMeterBandHeader, 0)
129 switch tcontType {
130 case 1:
131 //tcont-type-1
132 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
133 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700134 additionalBw = tp_pb.AdditionalBW_AdditionalBW_None
Gamze Abaka01174422021-03-10 06:55:27 +0000135 case 2:
136 //tcont-type-2
137 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 60000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
138 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700139 additionalBw = tp_pb.AdditionalBW_AdditionalBW_None
Gamze Abaka01174422021-03-10 06:55:27 +0000140 case 3:
141 //tcont-type-3
142 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
143 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 20000, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700144 additionalBw = tp_pb.AdditionalBW_AdditionalBW_NA
Gamze Abaka01174422021-03-10 06:55:27 +0000145 case 4:
146 //tcont-type-4
147 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 200000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700148 additionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
Gamze Abaka01174422021-03-10 06:55:27 +0000149 case 5:
150 //tcont-type-5
151 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
152 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
153 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700154 additionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
Gamze Abaka01174422021-03-10 06:55:27 +0000155 default:
156 // do nothing, we will return meter config with no meter bands
157 }
158
159 if direction == Downstream {
160 techProfile.DsScheduler.AdditionalBw = additionalBw
161 } else {
162 techProfile.UsScheduler.AdditionalBw = additionalBw
163 }
164
165 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
166 return &voltha.FlowMetadata{
167 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}}
168}
169
kdarapu3248f9a2019-10-03 13:54:52 +0530170func TestOpenOltFlowMgr_RemoveSchedulerQueues(t *testing.T) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700171 tprofile := &tp_pb.TechProfileInstance{Name: "tp1", SubscriberIdentifier: "subscriber1",
Girish Gowdra54934262019-11-13 14:19:55 +0530172 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700173 InstanceControl: &tp_pb.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"},
kdarapu3248f9a2019-10-03 13:54:52 +0530174 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700175 tprofile.UsScheduler = &openoltpb2.SchedulerAttributes{}
176 tprofile.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
177 tprofile.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
178 tprofile.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +0530179
180 tprofile2 := tprofile
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700181 tprofile2.DsScheduler = &openoltpb2.SchedulerAttributes{}
182 tprofile2.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
183 tprofile2.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
184 tprofile2.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +0530185 //defTprofile := &tp.DefaultTechProfile{}
kdarapu3248f9a2019-10-03 13:54:52 +0530186 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +0000187 name string
188 schedQueue schedQueue
189 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +0530190 }{
191 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000192 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 0, nil}, false},
193 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530194 // negative test cases
Gamze Abakafee36392019-10-03 11:17:24 +0000195 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
196 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530197 }
npujarec5762e2020-01-01 14:08:48 +0530198 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
199 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530200 for _, tt := range tests {
201 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700202 if err := flowMgr[tt.schedQueue.intfID].RemoveSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530203 t.Errorf("OpenOltFlowMgr.RemoveSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr)
204 }
205 })
206 }
kdarapub26b4502019-10-05 03:02:33 +0530207
kdarapu3248f9a2019-10-03 13:54:52 +0530208}
209
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700210func TestOpenOltFlowMgr_createTcontGemports(t *testing.T) {
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700211 bands := make([]*ofp.OfpMeterBandHeader, 2)
212 bands[0] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 1000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
213 bands[1] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 2000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
214 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
215 flowmetadata := &voltha.FlowMetadata{
216 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
217 }
218 type args struct {
219 intfID uint32
220 onuID uint32
221 uniID uint32
222 uni string
223 uniPort uint32
224 TpID uint32
225 UsMeterID uint32
226 DsMeterID uint32
227 flowMetadata *voltha.FlowMetadata
228 }
229 tests := []struct {
230 name string
231 args args
232 }{
233 {"createTcontGemports-1", args{intfID: 0, onuID: 1, uniID: 1, uni: "16", uniPort: 1, TpID: 64, UsMeterID: 1, DsMeterID: 1, flowMetadata: flowmetadata}},
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700234 }
235 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
236 defer cancel()
237 for _, tt := range tests {
238 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700239 _, _, tpInst := flowMgr[tt.args.intfID].createTcontGemports(ctx, tt.args.intfID, tt.args.onuID, tt.args.uniID, tt.args.uni, tt.args.uniPort, tt.args.TpID, tt.args.UsMeterID, tt.args.DsMeterID, tt.args.flowMetadata)
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700240 switch tpInst := tpInst.(type) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700241 case *tp_pb.TechProfileInstance:
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700242 if tt.args.TpID != 64 {
243 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
244 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700245 case *tp_pb.EponTechProfileInstance:
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700246 if tt.args.TpID != 65 {
247 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
248 }
249 default:
250 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
251 }
252 })
253 }
254}
255
kdarapu3248f9a2019-10-03 13:54:52 +0530256func TestOpenOltFlowMgr_RemoveFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000257 ctx := context.Background()
Neha Sharma96b7bf22020-06-15 10:37:32 +0000258 logger.Debug(ctx, "Info Warning Error: Starting RemoveFlow() test")
kdarapu3248f9a2019-10-03 13:54:52 +0530259 fa := &fu.FlowArgs{
260 MatchFields: []*ofp.OfpOxmOfbField{
261 fu.InPort(2),
262 fu.Metadata_ofp(2),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300263 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapu3248f9a2019-10-03 13:54:52 +0530264 },
265 Actions: []*ofp.OfpAction{
266 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
267 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
268 fu.Output(1),
269 },
270 }
divyadesaid26f6b12020-03-19 06:30:28 +0000271 ofpstats, _ := fu.MkFlowStat(fa)
kdarapub26b4502019-10-05 03:02:33 +0530272 ofpstats.Cookie = ofpstats.Id
kdarapub26b4502019-10-05 03:02:33 +0530273 lldpFa := &fu.FlowArgs{
274 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
275 MatchFields: []*ofp.OfpOxmOfbField{
276 fu.InPort(1),
277 fu.EthType(0x88CC),
278 fu.TunnelId(536870912),
279 },
280 Actions: []*ofp.OfpAction{
281 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
282 },
283 }
divyadesaid26f6b12020-03-19 06:30:28 +0000284 lldpofpstats, _ := fu.MkFlowStat(lldpFa)
kdarapub26b4502019-10-05 03:02:33 +0530285 //lldpofpstats.Cookie = lldpofpstats.Id
286
287 dhcpFa := &fu.FlowArgs{
288 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
289 MatchFields: []*ofp.OfpOxmOfbField{
290 fu.InPort(1),
291 fu.UdpSrc(67),
292 //fu.TunnelId(536870912),
293 fu.IpProto(17),
294 },
295 Actions: []*ofp.OfpAction{
296 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
297 },
298 }
divyadesaid26f6b12020-03-19 06:30:28 +0000299 dhcpofpstats, _ := fu.MkFlowStat(dhcpFa)
kdarapub26b4502019-10-05 03:02:33 +0530300 //dhcpofpstats.Cookie = dhcpofpstats.Id
Esin Karamanccb714b2019-11-29 15:02:06 +0000301
302 //multicast flow
303 multicastFa := &fu.FlowArgs{
304 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800305 fu.InPort(1048576),
Esin Karamanccb714b2019-11-29 15:02:06 +0000306 fu.VlanVid(660), //vlan
307 fu.Metadata_ofp(uint64(66)), //inner vlan
308 fu.EthType(0x800), //ipv4
309 fu.Ipv4Dst(3809869825), //227.22.0.1
310 },
311 Actions: []*ofp.OfpAction{
312 fu.Group(1),
313 },
314 }
divyadesaid26f6b12020-03-19 06:30:28 +0000315 multicastOfpStats, _ := fu.MkFlowStat(multicastFa)
Esin Karamanccb714b2019-11-29 15:02:06 +0000316 multicastOfpStats.Id = 1
317
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300318 pppoedFa := &fu.FlowArgs{
319 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
320 MatchFields: []*ofp.OfpOxmOfbField{
321 fu.InPort(1),
322 fu.EthType(0x8863),
323 fu.TunnelId(536870912),
324 },
325 Actions: []*ofp.OfpAction{
326 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
327 },
328 }
329 pppoedOfpStats, _ := fu.MkFlowStat(pppoedFa)
330
kdarapu3248f9a2019-10-03 13:54:52 +0530331 type args struct {
332 flow *ofp.OfpFlowStats
333 }
334 tests := []struct {
335 name string
336 args args
337 }{
338 // TODO: Add test cases.
339 {"RemoveFlow", args{flow: ofpstats}},
kdarapub26b4502019-10-05 03:02:33 +0530340 {"RemoveFlow", args{flow: lldpofpstats}},
341 {"RemoveFlow", args{flow: dhcpofpstats}},
Esin Karamanccb714b2019-11-29 15:02:06 +0000342 {"RemoveFlow", args{flow: multicastOfpStats}},
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300343 {"RemoveFlow", args{flow: pppoedOfpStats}},
kdarapu3248f9a2019-10-03 13:54:52 +0530344 }
npujarec5762e2020-01-01 14:08:48 +0530345 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
346 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530347 for _, tt := range tests {
348 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700349 if err := flowMgr[0].RemoveFlow(ctx, tt.args.flow); err != nil {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400350 logger.Warn(ctx, err)
351 }
kdarapu3248f9a2019-10-03 13:54:52 +0530352 })
353 }
kdarapub26b4502019-10-05 03:02:33 +0530354 // t.Error("=====")
kdarapu3248f9a2019-10-03 13:54:52 +0530355}
356
357func TestOpenOltFlowMgr_AddFlow(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530358 kw := make(map[string]uint64)
359 kw["table_id"] = 1
360 kw["meter_id"] = 1
kdarapub26b4502019-10-05 03:02:33 +0530361 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
362
363 // Upstream flow
kdarapu3248f9a2019-10-03 13:54:52 +0530364 fa := &fu.FlowArgs{
365 MatchFields: []*ofp.OfpOxmOfbField{
kdarapub26b4502019-10-05 03:02:33 +0530366 fu.InPort(536870912),
367 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300368 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530369 },
370 Actions: []*ofp.OfpAction{
371 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
372 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800373 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530374 fu.PushVlan(0x8100),
375 },
376 KV: kw,
377 }
378
379 // Downstream flow
380 fa3 := &fu.FlowArgs{
381 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800382 fu.InPort(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530383 fu.Metadata_ofp(1),
384 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
385 },
386 Actions: []*ofp.OfpAction{
387 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
388 //fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
389 fu.PopVlan(),
390 fu.Output(536870912),
391 },
392 KV: kw,
393 }
394
395 fa2 := &fu.FlowArgs{
396 MatchFields: []*ofp.OfpOxmOfbField{
kdarapu3248f9a2019-10-03 13:54:52 +0530397 fu.InPort(1000),
398 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300399 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapu3248f9a2019-10-03 13:54:52 +0530400 },
401 Actions: []*ofp.OfpAction{
402 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
403 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
404 fu.Output(65533),
405 },
406 KV: kw,
407 }
408
kdarapub26b4502019-10-05 03:02:33 +0530409 // TODO Add LLDP flow
410 // TODO Add DHCP flow
411
412 // Flows for negative scenarios
413 // Failure in formulateActionInfoFromFlow()
414 fa4 := &fu.FlowArgs{
415 MatchFields: []*ofp.OfpOxmOfbField{
416 fu.InPort(1000),
417 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300418 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530419 },
420 Actions: []*ofp.OfpAction{
421 fu.Experimenter(257, []byte{1, 2, 3, 4}),
422 },
423 KV: kw,
424 }
425
426 // Invalid Output
427 fa5 := &fu.FlowArgs{
428 MatchFields: []*ofp.OfpOxmOfbField{
429 fu.InPort(1000),
430 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300431 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530432 },
433 Actions: []*ofp.OfpAction{
434 fu.Output(0),
435 },
436 KV: kw,
437 }
438
439 // Tech-Profile-ID update (not supported)
440 kw6 := make(map[string]uint64)
441 kw6["table_id"] = 1
442 kw6["meter_id"] = 1
443 kw6["write_metadata"] = 0x4100000000 // TpID Other than the stored one
444 fa6 := &fu.FlowArgs{
445 MatchFields: []*ofp.OfpOxmOfbField{
446 fu.InPort(536870912),
447 fu.TunnelId(16),
448 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300449 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530450 },
451 Actions: []*ofp.OfpAction{
452 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
453 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
454 fu.Output(65535),
455 },
456 KV: kw6,
457 }
458
459 lldpFa := &fu.FlowArgs{
460 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
461 MatchFields: []*ofp.OfpOxmOfbField{
462 fu.InPort(1),
463 fu.EthType(0x88CC),
464 fu.TunnelId(536870912),
465 },
466 Actions: []*ofp.OfpAction{
467 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
468 },
469 }
470
471 dhcpFa := &fu.FlowArgs{
472 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
473 MatchFields: []*ofp.OfpOxmOfbField{
474 fu.InPort(1),
475 fu.UdpSrc(67),
476 //fu.TunnelId(536870912),
477 fu.IpProto(17),
478 },
479 Actions: []*ofp.OfpAction{
480 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
481 },
482 }
483 igmpFa := &fu.FlowArgs{
484 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
485 MatchFields: []*ofp.OfpOxmOfbField{
486 fu.InPort(1),
487 fu.UdpSrc(67),
488 //fu.TunnelId(536870912),
489 fu.IpProto(2),
490 },
491 Actions: []*ofp.OfpAction{
492 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
493 },
494 }
495
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300496 pppoedFa := &fu.FlowArgs{
497 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
498 MatchFields: []*ofp.OfpOxmOfbField{
499 fu.InPort(1),
500 fu.EthType(0x8863),
501 fu.TunnelId(536870912),
502 },
503 Actions: []*ofp.OfpAction{
504 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
505 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
506 },
507 }
508
kdarapub26b4502019-10-05 03:02:33 +0530509 fa9 := &fu.FlowArgs{
510 MatchFields: []*ofp.OfpOxmOfbField{
511 fu.InPort(536870912),
512 fu.TunnelId(16),
513 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300514 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530515 fu.VlanPcp(1000),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800516 fu.UdpDst(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530517 fu.UdpSrc(536870912),
518 fu.Ipv4Dst(65535),
519 fu.Ipv4Src(536870912),
520 },
521 Actions: []*ofp.OfpAction{
522 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
523 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
524 fu.Output(65535),
525 },
526 KV: kw6,
527 }
528
529 fa10 := &fu.FlowArgs{
530 MatchFields: []*ofp.OfpOxmOfbField{
531 fu.InPort(65533),
532 // fu.TunnelId(16),
533 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300534 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530535 fu.VlanPcp(1000),
536 fu.UdpDst(65535),
537 fu.UdpSrc(536870912),
538 fu.Ipv4Dst(65535),
539 fu.Ipv4Src(536870912),
540 },
541 Actions: []*ofp.OfpAction{
542 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
543 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
544 fu.Output(65535),
545 },
546 KV: kw6,
547 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000548 //multicast flow
549 fa11 := &fu.FlowArgs{
550 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800551 fu.InPort(1048576),
Esin Karamanccb714b2019-11-29 15:02:06 +0000552 fu.VlanVid(660), //vlan
553 fu.Metadata_ofp(uint64(66)), //inner vlan
554 fu.EthType(0x800), //ipv4
555 fu.Ipv4Dst(3809869825), //227.22.0.1
556 },
557 Actions: []*ofp.OfpAction{
558 fu.Group(1),
559 },
560 KV: kw6,
561 }
divyadesaid26f6b12020-03-19 06:30:28 +0000562 ofpstats, _ := fu.MkFlowStat(fa)
563 ofpstats2, _ := fu.MkFlowStat(fa2)
564 ofpstats3, _ := fu.MkFlowStat(fa3)
565 ofpstats4, _ := fu.MkFlowStat(fa4)
566 ofpstats5, _ := fu.MkFlowStat(fa5)
567 ofpstats6, _ := fu.MkFlowStat(fa6)
568 ofpstats7, _ := fu.MkFlowStat(lldpFa)
569 ofpstats8, _ := fu.MkFlowStat(dhcpFa)
570 ofpstats9, _ := fu.MkFlowStat(fa9)
571 ofpstats10, _ := fu.MkFlowStat(fa10)
572 igmpstats, _ := fu.MkFlowStat(igmpFa)
573 ofpstats11, _ := fu.MkFlowStat(fa11)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300574 pppoedstats, _ := fu.MkFlowStat(pppoedFa)
kdarapub26b4502019-10-05 03:02:33 +0530575
Gamze Abakafee36392019-10-03 11:17:24 +0000576 fmt.Println(ofpstats6, ofpstats9, ofpstats10)
577
kdarapu3248f9a2019-10-03 13:54:52 +0530578 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1}
kdarapu3248f9a2019-10-03 13:54:52 +0530579 flowMetadata := &voltha.FlowMetadata{
580 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
581 }
582 type args struct {
583 flow *ofp.OfpFlowStats
584 flowMetadata *voltha.FlowMetadata
585 }
586 tests := []struct {
587 name string
588 args args
589 }{
590 // TODO: Add test cases.
591 {"AddFlow", args{flow: ofpstats, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530592 {"AddFlow", args{flow: ofpstats2, flowMetadata: flowMetadata}},
593 {"AddFlow", args{flow: ofpstats3, flowMetadata: flowMetadata}},
594 {"AddFlow", args{flow: ofpstats4, flowMetadata: flowMetadata}},
595 {"AddFlow", args{flow: ofpstats5, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000596 //{"AddFlow", args{flow: ofpstats6, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530597 {"AddFlow", args{flow: ofpstats7, flowMetadata: flowMetadata}},
598 {"AddFlow", args{flow: ofpstats8, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000599 //{"AddFlow", args{flow: ofpstats9, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530600 {"AddFlow", args{flow: igmpstats, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000601 //{"AddFlow", args{flow: ofpstats10, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530602 //ofpstats10
Esin Karamanccb714b2019-11-29 15:02:06 +0000603 {"AddFlow", args{flow: ofpstats11, flowMetadata: flowMetadata}},
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300604 {"AddFlow", args{flow: pppoedstats, flowMetadata: flowMetadata}},
kdarapu3248f9a2019-10-03 13:54:52 +0530605 }
npujarec5762e2020-01-01 14:08:48 +0530606 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
607 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530608 for _, tt := range tests {
609 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700610 _ = flowMgr[0].AddFlow(ctx, tt.args.flow, tt.args.flowMetadata)
Kent Hagermane6ff1012020-07-14 15:07:53 -0400611 // TODO: actually verify test cases
kdarapu3248f9a2019-10-03 13:54:52 +0530612 })
613 }
614}
615
616func TestOpenOltFlowMgr_UpdateOnuInfo(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530617 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
618 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530619
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700620 wg := sync.WaitGroup{}
621
Girish Gowdra9602eb42020-09-09 15:50:39 -0700622 intfCount := NumPonPorts
623 onuCount := OnuIDEnd - OnuIDStart + 1
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700624
625 for i := 0; i < intfCount; i++ {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700626 for j := 1; j <= onuCount; j++ {
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700627 wg.Add(1)
628 go func(i uint32, j uint32) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400629 // TODO: actually verify success
Girish Gowdra37f13fa2021-08-16 10:59:45 -0700630 _ = flowMgr[i].AddOnuInfoToFlowMgrCacheAndKvStore(ctx, i, i, fmt.Sprintf("onu-%d", i))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700631 wg.Done()
632 }(uint32(i), uint32(j))
633 }
634
635 }
636
637 wg.Wait()
638}
639
640func TestOpenOltFlowMgr_addGemPortToOnuInfoMap(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700641 intfNum := NumPonPorts
642 onuNum := OnuIDEnd - OnuIDStart + 1
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700643
644 // clean the flowMgr
Girish Gowdra9602eb42020-09-09 15:50:39 -0700645 for i := 0; i < intfNum; i++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700646 flowMgr[i].onuGemInfoMap = make(map[uint32]*rsrcMgr.OnuGemInfo)
Girish Gowdra9602eb42020-09-09 15:50:39 -0700647 }
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700648
649 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
650 defer cancel()
651
652 // Create OnuInfo
653 for i := 0; i < intfNum; i++ {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700654 for o := 1; o <= onuNum; o++ {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400655 // TODO: actually verify success
Girish Gowdra37f13fa2021-08-16 10:59:45 -0700656 _ = flowMgr[i].AddOnuInfoToFlowMgrCacheAndKvStore(ctx, uint32(i), uint32(o), fmt.Sprintf("i%do%d", i, o-1))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700657 }
658 }
659
660 // Add gemPorts to OnuInfo in parallel threads
661 wg := sync.WaitGroup{}
Girish Gowdra9602eb42020-09-09 15:50:39 -0700662 for o := 1; o <= onuNum; o++ {
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700663 for i := 0; i < intfNum; i++ {
664 wg.Add(1)
665 go func(intfId uint32, onuId uint32) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700666 gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", intfId, onuId-1))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700667
Girish Gowdra9602eb42020-09-09 15:50:39 -0700668 flowMgr[intfId].addGemPortToOnuInfoMap(ctx, intfId, onuId, uint32(gemID))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700669 wg.Done()
670 }(uint32(i), uint32(o))
671 }
672 }
673
674 wg.Wait()
675
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700676 // check that each entry of onuGemInfoMap has the correct number of ONUs
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700677 for i := 0; i < intfNum; i++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700678 lenofOnu := len(flowMgr[i].onuGemInfoMap)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700679 if onuNum != lenofOnu {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700680 t.Errorf("onuGemInfoMap length is not as expected len = %d, want %d", lenofOnu, onuNum)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700681 }
682
Girish Gowdra9602eb42020-09-09 15:50:39 -0700683 for o := 1; o <= onuNum; o++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700684 lenOfGemPorts := len(flowMgr[i].onuGemInfoMap[uint32(o)].GemPorts)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700685 // check that each onuEntry has 1 gemPort
686 if lenOfGemPorts != 1 {
687 t.Errorf("Expected 1 GemPort per ONU, found %d", lenOfGemPorts)
688 }
689
690 // check that the value of the gemport is correct
Girish Gowdra9602eb42020-09-09 15:50:39 -0700691 gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", i, o-1))
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700692 currentValue := flowMgr[i].onuGemInfoMap[uint32(o)].GemPorts[0]
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700693 if uint32(gemID) != currentValue {
694 t.Errorf("Expected GemPort value to be %d, found %d", gemID, currentValue)
695 }
696 }
kdarapu3248f9a2019-10-03 13:54:52 +0530697 }
698}
699
serkant.uluderya96af4932020-02-20 16:58:48 -0800700func TestOpenOltFlowMgr_deleteGemPortFromLocalCache(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700701 // Create fresh flowMgr instance
702 flowMgr = newMockFlowmgr()
serkant.uluderya96af4932020-02-20 16:58:48 -0800703 type args struct {
704 intfID uint32
705 onuID uint32
706 gemPortIDs []uint32
707 gemPortIDsToBeDeleted []uint32
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700708 gemPortIDsRemaining []uint32
serkant.uluderya96af4932020-02-20 16:58:48 -0800709 serialNum string
710 finalLength int
711 }
712 tests := []struct {
713 name string
714 args args
715 }{
716 // Add/Delete single gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700717 {"DeleteGemPortFromLocalCache1", args{0, 1, []uint32{1}, []uint32{1}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800718 // Delete all gemports
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700719 {"DeleteGemPortFromLocalCache2", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{1, 2, 3, 4}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800720 // Try to delete when there is no gem port
Girish Gowdra37f13fa2021-08-16 10:59:45 -0700721 {"DeleteGemPortFromLocalCache3", args{0, 1, []uint32{}, []uint32{1, 2}, nil, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800722 // Try to delete non-existent gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700723 {"DeleteGemPortFromLocalCache4", args{0, 1, []uint32{1}, []uint32{2}, []uint32{1}, "onu1", 1}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800724 // Try to delete two of the gem ports
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700725 {"DeleteGemPortFromLocalCache5", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{2, 4}, []uint32{1, 3}, "onu1", 2}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800726 }
727 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
728 defer cancel()
729 for _, tt := range tests {
730 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra37f13fa2021-08-16 10:59:45 -0700731 if err := flowMgr[tt.args.intfID].RemoveOnuInfoFromFlowMgrCacheAndKvStore(ctx, tt.args.intfID, tt.args.onuID); err != nil {
732 t.Errorf("failed to remove onu")
733 }
734 if err := flowMgr[tt.args.intfID].AddOnuInfoToFlowMgrCacheAndKvStore(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum); err != nil {
735 t.Errorf("failed to add onu")
736 }
serkant.uluderya96af4932020-02-20 16:58:48 -0800737 for _, gemPort := range tt.args.gemPortIDs {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700738 flowMgr[tt.args.intfID].addGemPortToOnuInfoMap(ctx, tt.args.intfID, tt.args.onuID, gemPort)
serkant.uluderya96af4932020-02-20 16:58:48 -0800739 }
740 for _, gemPortDeleted := range tt.args.gemPortIDsToBeDeleted {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700741 flowMgr[tt.args.intfID].deleteGemPortFromLocalCache(ctx, tt.args.intfID, tt.args.onuID, gemPortDeleted)
serkant.uluderya96af4932020-02-20 16:58:48 -0800742 }
Girish Gowdra37f13fa2021-08-16 10:59:45 -0700743 lenofGemPorts := 0
744 gP, ok := flowMgr[tt.args.intfID].onuGemInfoMap[tt.args.onuID]
745 if ok {
746 lenofGemPorts = len(gP.GemPorts)
747 }
serkant.uluderya96af4932020-02-20 16:58:48 -0800748 if lenofGemPorts != tt.args.finalLength {
749 t.Errorf("GemPorts length is not as expected len = %d, want %d", lenofGemPorts, tt.args.finalLength)
750 }
Girish Gowdra37f13fa2021-08-16 10:59:45 -0700751 gP, ok = flowMgr[tt.args.intfID].onuGemInfoMap[tt.args.onuID]
752 var gemPorts []uint32
753 if ok {
754 gemPorts = gP.GemPorts
755 }
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700756 if !reflect.DeepEqual(tt.args.gemPortIDsRemaining, gemPorts) {
757 t.Errorf("GemPorts are not as expected = %v, want %v", gemPorts, tt.args.gemPortIDsRemaining)
758 }
serkant.uluderya96af4932020-02-20 16:58:48 -0800759
760 })
761 }
762}
763
kdarapu3248f9a2019-10-03 13:54:52 +0530764func TestOpenOltFlowMgr_GetLogicalPortFromPacketIn(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530765 type args struct {
766 packetIn *openoltpb2.PacketIndication
767 }
768 tests := []struct {
769 name string
770 args args
771 want uint32
772 wantErr bool
773 }{
774 // TODO: Add test cases.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700775 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 0, GemportId: 255, OnuId: 1, UniId: 0, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 1, false},
776 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "nni", IntfId: 0, GemportId: 1, OnuId: 1, UniId: 0, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 1048576, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530777 // Negative Test cases.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700778 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 1, GemportId: 1, OnuId: 1, UniId: 0, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 1, false},
779 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 0, GemportId: 257, OnuId: 1, UniId: 0, FlowId: 100, PortNo: 0, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 16, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530780 }
npujarec5762e2020-01-01 14:08:48 +0530781 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
782 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530783 for _, tt := range tests {
784 t.Run(tt.name, func(t *testing.T) {
785
Girish Gowdra9602eb42020-09-09 15:50:39 -0700786 got, err := flowMgr[tt.args.packetIn.IntfId].GetLogicalPortFromPacketIn(ctx, tt.args.packetIn)
kdarapu3248f9a2019-10-03 13:54:52 +0530787 if (err != nil) != tt.wantErr {
788 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() error = %v, wantErr %v", err, tt.wantErr)
789 return
790 }
791 if got != tt.want {
792 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() = %v, want %v", got, tt.want)
793 }
794 })
795 }
796}
797
798func TestOpenOltFlowMgr_GetPacketOutGemPortID(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700799 // Create fresh flowMgr instance
800 flowMgr = newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530801
Esin Karaman7fb80c22020-07-16 14:23:33 +0000802 //untagged packet in hex string
803 untaggedStr := "01005e000002000000000001080046c00020000040000102fa140a000001e00000029404000017000705e10000fa"
804 untagged, err := hex.DecodeString(untaggedStr)
805 if err != nil {
806 t.Error("Unable to parse hex string", err)
807 panic(err)
808 }
Girish Gowdra9602eb42020-09-09 15:50:39 -0700809 //single-tagged packet in hex string. vlanID.pbit: 1.1
810 singleTaggedStr := "01005e0000010025ba48172481002001080046c0002000004000010257deab140023e0000001940400001164ee9b0000000000000000000000000000"
Esin Karaman7fb80c22020-07-16 14:23:33 +0000811 singleTagged, err := hex.DecodeString(singleTaggedStr)
812 if err != nil {
813 t.Error("Unable to parse hex string", err)
814 panic(err)
815 }
Girish Gowdra9602eb42020-09-09 15:50:39 -0700816 //double-tagged packet in hex string. vlanID.pbit: 210.0-0.0
817 doubleTaggedStr := "01005e000016deadbeefba118100021081000000080046000028000000000102c5b87f000001e0000016940400002200f8030000000104000000e10000fa"
Esin Karaman7fb80c22020-07-16 14:23:33 +0000818 doubleTagged, err := hex.DecodeString(doubleTaggedStr)
819 if err != nil {
820 t.Error("Unable to parse hex string", err)
821 panic(err)
822 }
823
kdarapu3248f9a2019-10-03 13:54:52 +0530824 type args struct {
825 intfID uint32
826 onuID uint32
827 portNum uint32
Esin Karaman7fb80c22020-07-16 14:23:33 +0000828 packet []byte
kdarapu3248f9a2019-10-03 13:54:52 +0530829 }
830 tests := []struct {
831 name string
832 args args
833 want uint32
834 wantErr bool
835 }{
836 // TODO: Add test cases.
Girish Gowdra9602eb42020-09-09 15:50:39 -0700837 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: untagged}, 1, false},
838 {"GetPacketOutGemPortID", args{intfID: 1, onuID: 2, portNum: 2, packet: singleTagged}, 2, false},
839 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: doubleTagged}, 1, false},
840 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 10, portNum: 10, packet: untagged}, 2, true},
841 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 3, packet: []byte{}}, 3, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530842 }
Esin Karaman7fb80c22020-07-16 14:23:33 +0000843
npujarec5762e2020-01-01 14:08:48 +0530844 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
845 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530846 for _, tt := range tests {
847 t.Run(tt.name, func(t *testing.T) {
848
Girish Gowdra9602eb42020-09-09 15:50:39 -0700849 got, err := flowMgr[tt.args.intfID].GetPacketOutGemPortID(ctx, tt.args.intfID, tt.args.onuID, tt.args.portNum, tt.args.packet)
Esin Karaman7fb80c22020-07-16 14:23:33 +0000850 if tt.wantErr {
851 if err == nil {
852 //error expected but got value
853 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, wantErr %v", got, tt.wantErr)
854 }
855 } else {
856 if err != nil {
857 //error is not expected but got error
858 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() error = %v, wantErr %v", err, tt.wantErr)
859 return
860 }
861 if got != tt.want {
862 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, want %v", got, tt.want)
863 }
kdarapu3248f9a2019-10-03 13:54:52 +0530864 }
kdarapu3248f9a2019-10-03 13:54:52 +0530865 })
866 }
867}
868
869func TestOpenOltFlowMgr_DeleteTechProfileInstance(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530870 type args struct {
871 intfID uint32
872 onuID uint32
873 uniID uint32
874 sn string
Gamze Abakafee36392019-10-03 11:17:24 +0000875 tpID uint32
kdarapu3248f9a2019-10-03 13:54:52 +0530876 }
877 tests := []struct {
878 name string
879 args args
880 wantErr bool
881 }{
882 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000883 {"DeleteTechProfileInstance", args{intfID: 0, onuID: 1, uniID: 1, sn: "", tpID: 64}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530884 }
npujarec5762e2020-01-01 14:08:48 +0530885 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
886 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530887 for _, tt := range tests {
888 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700889 if err := flowMgr[tt.args.intfID].DeleteTechProfileInstance(ctx, tt.args.intfID, tt.args.onuID, tt.args.uniID, tt.args.sn, tt.args.tpID); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530890 t.Errorf("OpenOltFlowMgr.DeleteTechProfileInstance() error = %v, wantErr %v", err, tt.wantErr)
891 }
892 })
893 }
894}
kdarapub26b4502019-10-05 03:02:33 +0530895
896func TestOpenOltFlowMgr_checkAndAddFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000897 ctx := context.Background()
kdarapub26b4502019-10-05 03:02:33 +0530898 kw := make(map[string]uint64)
899 kw["table_id"] = 1
900 kw["meter_id"] = 1
901 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
902
903 // Upstream flow
904 fa := &fu.FlowArgs{
905 MatchFields: []*ofp.OfpOxmOfbField{
906 fu.InPort(536870912),
907 fu.Metadata_ofp(1),
908 fu.IpProto(17), // dhcp
Gamze Abakafee36392019-10-03 11:17:24 +0000909 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300910 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530911 },
912 Actions: []*ofp.OfpAction{
913 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
914 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800915 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530916 fu.PushVlan(0x8100),
917 },
918 KV: kw,
919 }
920
921 // EAPOL
922 fa2 := &fu.FlowArgs{
923 MatchFields: []*ofp.OfpOxmOfbField{
924 fu.InPort(536870912),
925 fu.Metadata_ofp(1),
926 fu.EthType(0x888E),
927 fu.VlanPcp(1),
928 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
929 },
930 Actions: []*ofp.OfpAction{
931 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
932 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800933 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530934 fu.PushVlan(0x8100),
935 },
936 KV: kw,
937 }
938
939 // HSIA
940 fa3 := &fu.FlowArgs{
941 MatchFields: []*ofp.OfpOxmOfbField{
942 fu.InPort(536870912),
943 fu.Metadata_ofp(1),
944 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300945 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530946 },
947 Actions: []*ofp.OfpAction{
948 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300949 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800950 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530951 fu.PushVlan(0x8100),
952 },
953 KV: kw,
954 }
955
956 fa4 := &fu.FlowArgs{
957 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800958 fu.InPort(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530959 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300960 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530961 fu.VlanPcp(1),
962 },
963 Actions: []*ofp.OfpAction{
964 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300965 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
kdarapub26b4502019-10-05 03:02:33 +0530966 fu.Output(536870912),
967 fu.PopVlan(),
968 },
969 KV: kw,
970 }
971
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300972 // PPPOED
973 pppoedFA := &fu.FlowArgs{
974 MatchFields: []*ofp.OfpOxmOfbField{
975 fu.InPort(536870912),
976 fu.Metadata_ofp(1),
977 fu.EthType(0x8863),
978 fu.VlanPcp(1),
979 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
980 },
981 Actions: []*ofp.OfpAction{
982 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
983 fu.Output(1048576),
984 fu.PushVlan(0x8100),
985 },
986 KV: kw,
987 }
988
kdarapub26b4502019-10-05 03:02:33 +0530989 classifierInfo := make(map[string]interface{})
990 actionInfo := make(map[string]interface{})
991 classifierInfo2 := make(map[string]interface{})
992 actionInfo2 := make(map[string]interface{})
993 classifierInfo3 := make(map[string]interface{})
994 actionInfo3 := make(map[string]interface{})
995 classifierInfo4 := make(map[string]interface{})
996 actionInfo4 := make(map[string]interface{})
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300997 classifierInfo5 := make(map[string]interface{})
998 actionInfo5 := make(map[string]interface{})
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700999 flow, _ := fu.MkFlowStat(fa)
1000 flow2, _ := fu.MkFlowStat(fa2)
1001 flow3, _ := fu.MkFlowStat(fa3)
1002 flow4, _ := fu.MkFlowStat(fa4)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001003 flow5, _ := fu.MkFlowStat(pppoedFA)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001004 formulateClassifierInfoFromFlow(ctx, classifierInfo, flow)
1005 formulateClassifierInfoFromFlow(ctx, classifierInfo2, flow2)
1006 formulateClassifierInfoFromFlow(ctx, classifierInfo3, flow3)
1007 formulateClassifierInfoFromFlow(ctx, classifierInfo4, flow4)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001008 formulateClassifierInfoFromFlow(ctx, classifierInfo5, flow5)
kdarapub26b4502019-10-05 03:02:33 +05301009
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001010 err := formulateActionInfoFromFlow(ctx, actionInfo, classifierInfo, flow)
kdarapub26b4502019-10-05 03:02:33 +05301011 if err != nil {
1012 // Error logging is already done in the called function
1013 // So just return in case of error
1014 return
1015 }
1016
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001017 err = formulateActionInfoFromFlow(ctx, actionInfo2, classifierInfo2, flow2)
kdarapub26b4502019-10-05 03:02:33 +05301018 if err != nil {
1019 // Error logging is already done in the called function
1020 // So just return in case of error
1021 return
1022 }
1023
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001024 err = formulateActionInfoFromFlow(ctx, actionInfo3, classifierInfo3, flow3)
kdarapub26b4502019-10-05 03:02:33 +05301025 if err != nil {
1026 // Error logging is already done in the called function
1027 // So just return in case of error
1028 return
1029 }
1030
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001031 err = formulateActionInfoFromFlow(ctx, actionInfo4, classifierInfo4, flow4)
kdarapub26b4502019-10-05 03:02:33 +05301032 if err != nil {
1033 // Error logging is already done in the called function
1034 // So just return in case of error
1035 return
1036 }
1037
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001038 err = formulateActionInfoFromFlow(ctx, actionInfo5, classifierInfo5, flow5)
1039 if err != nil {
1040 // Error logging is already done in the called function
1041 // So just return in case of error
1042 return
1043 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001044 /*
1045 usGemList := make([]*tp_pb.GemPortAttributes, 4)
1046 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1047 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1048 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1049 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1050 dsGemList := make([]*tp_pb.GemPortAttributes, 4)
1051 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1052 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1053 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1054 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1055 */
1056 TpInst := &tp_pb.TechProfileInstance{
kdarapub26b4502019-10-05 03:02:33 +05301057 Name: "Test-Tech-Profile",
1058 SubscriberIdentifier: "257",
1059 ProfileType: "Mock",
1060 Version: 1,
1061 NumGemPorts: 4,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001062 InstanceControl: &tp_pb.InstanceControl{
kdarapub26b4502019-10-05 03:02:33 +05301063 Onu: "1",
1064 Uni: "16",
1065 },
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001066 UsScheduler: &openoltpb2.SchedulerAttributes{},
1067 DsScheduler: &openoltpb2.SchedulerAttributes{},
kdarapub26b4502019-10-05 03:02:33 +05301068 }
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001069 TpInst.UsScheduler.Priority = 1
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001070 TpInst.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
1071 TpInst.UsScheduler.AllocId = 1
1072 TpInst.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
1073 TpInst.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001074 TpInst.UsScheduler.Weight = 4
1075
1076 TpInst.DsScheduler.Priority = 1
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001077 TpInst.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
1078 TpInst.DsScheduler.AllocId = 1
1079 TpInst.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
1080 TpInst.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001081 TpInst.DsScheduler.Weight = 4
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001082 TpInst.UpstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
1083 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
1084 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
1085 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
1086 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001087
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001088 TpInst.DownstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
1089 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
1090 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
1091 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
1092 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
kdarapub26b4502019-10-05 03:02:33 +05301093
kdarapub26b4502019-10-05 03:02:33 +05301094 type args struct {
1095 args map[string]uint32
1096 classifierInfo map[string]interface{}
1097 actionInfo map[string]interface{}
1098 flow *ofp.OfpFlowStats
1099 gemPort uint32
1100 intfID uint32
1101 onuID uint32
1102 uniID uint32
1103 portNo uint32
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001104 TpInst *tp_pb.TechProfileInstance
kdarapub26b4502019-10-05 03:02:33 +05301105 allocID []uint32
1106 gemPorts []uint32
1107 TpID uint32
1108 uni string
1109 }
1110 tests := []struct {
Kent Hagermane6ff1012020-07-14 15:07:53 -04001111 name string
1112 args args
kdarapub26b4502019-10-05 03:02:33 +05301113 }{
1114 {
1115 name: "checkAndAddFlow-1",
1116 args: args{
1117 args: nil,
1118 classifierInfo: classifierInfo,
1119 actionInfo: actionInfo,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001120 flow: flow,
kdarapub26b4502019-10-05 03:02:33 +05301121 gemPort: 1,
1122 intfID: 1,
1123 onuID: 1,
1124 uniID: 16,
1125 portNo: 1,
1126 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001127 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301128 gemPorts: []uint32{1, 2, 3, 4},
1129 TpID: 64,
1130 uni: "16",
1131 },
1132 },
1133 {
1134 name: "checkAndAddFlow-2",
1135 args: args{
1136 args: nil,
1137 classifierInfo: classifierInfo2,
1138 actionInfo: actionInfo2,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001139 flow: flow2,
kdarapub26b4502019-10-05 03:02:33 +05301140 gemPort: 1,
1141 intfID: 1,
1142 onuID: 1,
1143 uniID: 16,
1144 portNo: 1,
1145 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001146 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301147 gemPorts: []uint32{1, 2, 3, 4},
1148 TpID: 64,
1149 uni: "16",
1150 },
1151 },
1152 {
1153 name: "checkAndAddFlow-3",
1154 args: args{
1155 args: nil,
1156 classifierInfo: classifierInfo3,
1157 actionInfo: actionInfo3,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001158 flow: flow3,
kdarapub26b4502019-10-05 03:02:33 +05301159 gemPort: 1,
1160 intfID: 1,
1161 onuID: 1,
1162 uniID: 16,
1163 portNo: 1,
1164 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001165 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301166 gemPorts: []uint32{1, 2, 3, 4},
1167 TpID: 64,
1168 uni: "16",
1169 },
1170 },
1171 {
1172 name: "checkAndAddFlow-4",
1173 args: args{
1174 args: nil,
1175 classifierInfo: classifierInfo4,
1176 actionInfo: actionInfo4,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001177 flow: flow4,
kdarapub26b4502019-10-05 03:02:33 +05301178 gemPort: 1,
1179 intfID: 1,
1180 onuID: 1,
1181 uniID: 16,
1182 portNo: 1,
1183 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001184 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301185 gemPorts: []uint32{1, 2, 3, 4},
1186 TpID: 64,
1187 uni: "16",
1188 },
1189 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001190 {
1191 name: "checkAndAddFlow-5",
1192 args: args{
1193 args: nil,
1194 classifierInfo: classifierInfo5,
1195 actionInfo: actionInfo5,
1196 flow: flow5,
1197 gemPort: 1,
1198 intfID: 1,
1199 onuID: 1,
1200 uniID: 16,
1201 portNo: 1,
1202 TpInst: TpInst,
1203 allocID: []uint32{0x8001},
1204 gemPorts: []uint32{1, 2, 3, 4},
1205 TpID: 64,
1206 uni: "16",
1207 },
1208 },
kdarapub26b4502019-10-05 03:02:33 +05301209 }
npujarec5762e2020-01-01 14:08:48 +05301210 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1211 defer cancel()
kdarapub26b4502019-10-05 03:02:33 +05301212 for _, tt := range tests {
1213 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -07001214 flowMgr[tt.args.intfID].checkAndAddFlow(ctx, tt.args.args, tt.args.classifierInfo, tt.args.actionInfo, tt.args.flow,
Gamze Abakafee36392019-10-03 11:17:24 +00001215 tt.args.TpInst, tt.args.gemPorts, tt.args.TpID, tt.args.uni)
kdarapub26b4502019-10-05 03:02:33 +05301216 })
1217 }
1218}
Esin Karamanccb714b2019-11-29 15:02:06 +00001219
Esin Karamand519bbf2020-07-01 11:16:03 +00001220func TestOpenOltFlowMgr_TestMulticastFlowAndGroup(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301221 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1222 defer cancel()
Esin Karamanccb714b2019-11-29 15:02:06 +00001223 //create group
1224 group := newGroup(2, []uint32{1})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001225 err := flowMgr[0].grpMgr.AddGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001226 if err != nil {
1227 t.Error("group-add failed", err)
1228 return
1229 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001230 //create multicast flow
1231 multicastFlowArgs := &fu.FlowArgs{
1232 MatchFields: []*ofp.OfpOxmOfbField{
Esin Karamand519bbf2020-07-01 11:16:03 +00001233 fu.InPort(1048576),
Esin Karamanccb714b2019-11-29 15:02:06 +00001234 fu.VlanVid(660), //vlan
1235 fu.Metadata_ofp(uint64(66)), //inner vlan
1236 fu.EthType(0x800), //ipv4
1237 fu.Ipv4Dst(3809869825), //227.22.0.1
1238 },
1239 Actions: []*ofp.OfpAction{
1240 fu.Group(1),
1241 },
1242 }
divyadesaid26f6b12020-03-19 06:30:28 +00001243 ofpStats, _ := fu.MkFlowStat(multicastFlowArgs)
Esin Karamand519bbf2020-07-01 11:16:03 +00001244 fmt.Println(ofpStats.Id)
Girish Gowdra9602eb42020-09-09 15:50:39 -07001245 err = flowMgr[0].AddFlow(ctx, ofpStats, &voltha.FlowMetadata{})
Esin Karamand519bbf2020-07-01 11:16:03 +00001246 if err != nil {
1247 t.Error("Multicast flow-add failed", err)
1248 return
1249 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001250
1251 //add bucket to the group
1252 group = newGroup(2, []uint32{1, 2})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001253 err = flowMgr[0].grpMgr.ModifyGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001254 if err != nil {
1255 t.Error("modify-group failed", err)
1256 return
1257 }
1258 //remove the multicast flow
Girish Gowdra9602eb42020-09-09 15:50:39 -07001259 err = flowMgr[0].RemoveFlow(ctx, ofpStats)
Esin Karamand519bbf2020-07-01 11:16:03 +00001260 if err != nil {
1261 t.Error("Multicast flow-remove failed", err)
1262 return
1263 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001264
Esin Karamand519bbf2020-07-01 11:16:03 +00001265 //remove the group
Girish Gowdra9602eb42020-09-09 15:50:39 -07001266 err = flowMgr[0].grpMgr.DeleteGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001267 if err != nil {
1268 t.Error("delete-group failed", err)
1269 return
1270 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001271}
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001272
1273func TestOpenOltFlowMgr_TestRouteFlowToOnuChannel(t *testing.T) {
1274 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1275 defer cancel()
1276 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/core", log.DebugLevel)
1277 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager", log.DebugLevel)
1278 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/pkg/mocks", log.DebugLevel)
Girish Gowdra0aca4982021-01-04 12:44:27 -08001279 kwTable1Meter1 := make(map[string]uint64)
1280 kwTable1Meter1["table_id"] = 1
1281 kwTable1Meter1["meter_id"] = 1
1282 kwTable1Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
1283
1284 kwTable0Meter1 := make(map[string]uint64)
1285 kwTable0Meter1["table_id"] = 0
1286 kwTable0Meter1["meter_id"] = 1
1287 kwTable0Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001288
1289 flowMetadata1 := voltha.FlowMetadata{Meters: []*voltha.OfpMeterConfig{
1290 {
1291 Flags: 5,
1292 MeterId: 1,
1293 Bands: []*voltha.OfpMeterBandHeader{
1294 {
1295 Type: voltha.OfpMeterBandType_OFPMBT_DROP,
1296 Rate: 16000,
Gamze Abaka01174422021-03-10 06:55:27 +00001297 BurstSize: 0,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001298 },
1299 {
1300 Type: voltha.OfpMeterBandType_OFPMBT_DROP,
1301 Rate: 32000,
1302 BurstSize: 30,
1303 },
1304 {
1305 Type: voltha.OfpMeterBandType_OFPMBT_DROP,
1306 Rate: 64000,
1307 BurstSize: 30,
1308 },
1309 },
1310 },
1311 }}
1312
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001313 // Downstream LLDP Trap from NNI0 flow
1314 fa0 := &fu.FlowArgs{
1315 MatchFields: []*ofp.OfpOxmOfbField{
1316 fu.InPort(1048576),
1317 fu.EthType(35020),
1318 },
1319 Actions: []*ofp.OfpAction{
1320 fu.Output(4294967293),
1321 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001322 KV: make(map[string]uint64),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001323 }
1324
1325 // Upstream flow DHCP flow - ONU1 UNI0 PON0
1326 fa1 := &fu.FlowArgs{
1327 MatchFields: []*ofp.OfpOxmOfbField{
1328 fu.InPort(536870912),
1329 fu.Metadata_ofp(1),
1330 fu.IpProto(17), // dhcp
1331 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001332 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001333 fu.TunnelId(16),
1334 },
1335 Actions: []*ofp.OfpAction{
1336 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1337 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1338 fu.Output(2147483645),
1339 fu.PushVlan(0x8100),
1340 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001341 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001342 }
1343
1344 // Upstream EAPOL - ONU1 UNI0 PON0
1345 fa2 := &fu.FlowArgs{
1346 MatchFields: []*ofp.OfpOxmOfbField{
1347 fu.InPort(536870912),
1348 fu.Metadata_ofp(1),
1349 fu.EthType(0x888E),
1350 fu.VlanPcp(1),
1351 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
1352 fu.TunnelId(16),
1353 },
1354 Actions: []*ofp.OfpAction{
1355 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1356 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1357 fu.Output(2147483645),
1358 fu.PushVlan(0x8100),
1359 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001360 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001361 }
1362
1363 // Upstream HSIA - ONU1 UNI0 PON0
1364 fa3 := &fu.FlowArgs{
1365 MatchFields: []*ofp.OfpOxmOfbField{
1366 fu.InPort(536870912),
1367 fu.Metadata_ofp(1),
1368 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001369 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001370 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001371 },
1372 Actions: []*ofp.OfpAction{
1373 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001374 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001375 fu.Output(1048576),
1376 fu.PushVlan(0x8100),
1377 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001378 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001379 }
1380
1381 // Downstream HSIA - ONU1 UNI0 PON0
1382 fa4 := &fu.FlowArgs{
1383 MatchFields: []*ofp.OfpOxmOfbField{
1384 fu.InPort(1048576),
1385 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001386 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001387 fu.VlanPcp(1),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001388 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001389 },
1390 Actions: []*ofp.OfpAction{
1391 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001392 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001393 fu.Output(536870912),
1394 fu.PopVlan(),
1395 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001396 KV: kwTable0Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001397 }
1398
1399 // Upstream flow DHCP flow - ONU1 UNI0 PON15
1400 fa5 := &fu.FlowArgs{
1401 MatchFields: []*ofp.OfpOxmOfbField{
1402 fu.InPort(536870927),
1403 fu.Metadata_ofp(1),
1404 fu.IpProto(17), // dhcp
1405 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001406 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001407 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001408 },
1409 Actions: []*ofp.OfpAction{
1410 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1411 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259)),
1412 fu.Output(2147483645),
1413 fu.PushVlan(0x8100),
1414 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001415 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001416 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001417
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001418 // Upstream EAPOL - ONU1 UNI0 PON15
1419 fa6 := &fu.FlowArgs{
1420 MatchFields: []*ofp.OfpOxmOfbField{
1421 fu.InPort(536870927),
1422 fu.Metadata_ofp(1),
1423 fu.EthType(0x888E),
1424 fu.VlanPcp(1),
1425 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001426 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001427 },
1428 Actions: []*ofp.OfpAction{
1429 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1430 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1431 fu.Output(2147483645),
1432 fu.PushVlan(0x8100),
1433 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001434 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001435 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001436
1437 // Upstream PPPOED - ONU1 UNI0 PON0
1438 fa7 := &fu.FlowArgs{
1439 MatchFields: []*ofp.OfpOxmOfbField{
1440 fu.InPort(536870912),
1441 fu.Metadata_ofp(1),
1442 fu.EthType(0x8863),
1443 fu.VlanPcp(1),
1444 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
1445 fu.TunnelId(16),
1446 },
1447 Actions: []*ofp.OfpAction{
1448 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1449 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1450 fu.Output(2147483645),
1451 fu.PushVlan(0x8100),
1452 },
1453 KV: kwTable1Meter1,
1454 }
1455
1456 // Upstream PPPOED - ONU1 UNI0 PON15
1457 fa8 := &fu.FlowArgs{
1458 MatchFields: []*ofp.OfpOxmOfbField{
1459 fu.InPort(536870927),
1460 fu.Metadata_ofp(1),
1461 fu.EthType(0x8863),
1462 fu.VlanPcp(1),
1463 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
1464 fu.TunnelId(16),
1465 },
1466 Actions: []*ofp.OfpAction{
1467 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1468 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1469 fu.Output(2147483645),
1470 fu.PushVlan(0x8100),
1471 },
1472 KV: kwTable1Meter1,
1473 }
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001474 flow0, _ := fu.MkFlowStat(fa0)
1475 flow1, _ := fu.MkFlowStat(fa1)
1476 flow2, _ := fu.MkFlowStat(fa2)
1477 flow3, _ := fu.MkFlowStat(fa3)
1478 flow4, _ := fu.MkFlowStat(fa4)
1479
1480 flow5, _ := fu.MkFlowStat(fa5)
1481 flow6, _ := fu.MkFlowStat(fa6)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001482 flow7, _ := fu.MkFlowStat(fa7)
1483 flow8, _ := fu.MkFlowStat(fa8)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001484
1485 type args struct {
1486 ctx context.Context
1487 flow *ofp.OfpFlowStats
1488 addFlow bool
1489 flowMetadata *voltha.FlowMetadata
1490 }
1491 tests := []struct {
1492 name string
1493 args args
1494 wantErr bool
1495 returnedErr error
1496 }{
1497 {
1498 name: "RouteFlowToOnuChannel-0",
1499 args: args{
1500 ctx: ctx,
1501 flow: flow0,
1502 addFlow: true,
1503 flowMetadata: &flowMetadata1,
1504 },
1505 wantErr: false,
1506 },
1507 {
1508 name: "RouteFlowToOnuChannel-1",
1509 args: args{
1510 ctx: ctx,
1511 flow: flow1,
1512 addFlow: true,
1513 flowMetadata: &flowMetadata1,
1514 },
1515 wantErr: false,
1516 },
1517 {
1518 name: "RouteFlowToOnuChannel-2",
1519 args: args{
1520 ctx: ctx,
1521 flow: flow2,
1522 addFlow: true,
1523 flowMetadata: &flowMetadata1,
1524 },
1525 wantErr: false,
1526 },
1527 {
1528 name: "RouteFlowToOnuChannel-3",
1529 args: args{
1530 ctx: ctx,
1531 flow: flow3,
1532 addFlow: true,
1533 flowMetadata: &flowMetadata1,
1534 },
1535 wantErr: false,
1536 },
1537 {
1538 name: "RouteFlowToOnuChannel-4",
1539 args: args{
1540 ctx: ctx,
1541 flow: flow4,
1542 addFlow: true,
1543 flowMetadata: &flowMetadata1,
1544 },
1545 wantErr: false,
1546 },
1547 {
1548 name: "RouteFlowToOnuChannel-5",
1549 args: args{
1550 ctx: ctx,
1551 flow: flow1,
1552 addFlow: false,
1553 flowMetadata: &flowMetadata1,
1554 },
1555 wantErr: false,
1556 },
1557 {
1558 name: "RouteFlowToOnuChannel-6",
1559 args: args{
1560 ctx: ctx,
1561 flow: flow1,
1562 addFlow: true,
Girish Gowdra0aca4982021-01-04 12:44:27 -08001563 flowMetadata: &flowMetadata1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001564 },
1565 wantErr: true,
1566 },
1567 {
1568 name: "RouteFlowToOnuChannel-7",
1569 args: args{
1570 ctx: ctx,
1571 flow: flow5,
1572 addFlow: true,
1573 flowMetadata: &flowMetadata1,
1574 },
1575 wantErr: false,
1576 },
1577 {
1578 name: "RouteFlowToOnuChannel-8",
1579 args: args{
1580 ctx: ctx,
1581 flow: flow6,
1582 addFlow: true,
1583 flowMetadata: &flowMetadata1,
1584 },
1585 wantErr: false,
1586 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001587 {
1588 name: "RouteFlowToOnuChannel-9",
1589 args: args{
1590 ctx: ctx,
1591 flow: flow7,
1592 addFlow: true,
1593 flowMetadata: &flowMetadata1,
1594 },
1595 wantErr: false,
1596 },
1597 {
1598 name: "RouteFlowToOnuChannel-10",
1599 args: args{
1600 ctx: ctx,
1601 flow: flow8,
1602 addFlow: true,
1603 flowMetadata: &flowMetadata1,
1604 },
1605 wantErr: false,
1606 },
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001607 }
1608
1609 var wg sync.WaitGroup
1610 defer wg.Wait() // wait for all go routines to complete
1611 for _, tt := range tests {
1612 t.Run(tt.name, func(t *testing.T) {
1613 wg.Add(1) // one per go routine
1614 go func() {
1615 defer wg.Done()
1616 tt.returnedErr = flowMgr[0].RouteFlowToOnuChannel(tt.args.ctx, tt.args.flow, tt.args.addFlow, tt.args.flowMetadata)
1617 if (tt.wantErr == false && tt.returnedErr != nil) || (tt.wantErr == true && tt.returnedErr == nil) {
1618 t.Errorf("OpenOltFlowMgr.RouteFlowToOnuChannel() error = %v, wantErr %v", tt.returnedErr, tt.wantErr)
1619 }
1620 }()
1621 })
1622 }
1623}