blob: b985b4e9922d680231a96d6f1d51a56829e72132 [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"
Girish Gowdra4c3d4602021-07-22 16:33:37 -070024 "github.com/opencord/voltha-openolt-adapter/pkg/mocks"
Matteo Scandoloabf9c512020-06-23 19:31:14 -070025 "reflect"
26 "strconv"
27 "sync"
kdarapu3248f9a2019-10-03 13:54:52 +053028 "testing"
npujarec5762e2020-01-01 14:08:48 +053029 "time"
kdarapu3248f9a2019-10-03 13:54:52 +053030
Girish Gowdraa09aeab2020-09-14 16:30:52 -070031 "github.com/opencord/voltha-protos/v4/go/voltha"
kdarapub26b4502019-10-05 03:02:33 +053032
Girish Gowdra4c3d4602021-07-22 16:33:37 -070033 fu "github.com/opencord/voltha-lib-go/v6/pkg/flows"
34 "github.com/opencord/voltha-lib-go/v6/pkg/log"
Scott Bakerdbd960e2020-02-28 08:57:51 -080035 rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070036 ofp "github.com/opencord/voltha-protos/v4/go/openflow_13"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070037 openoltpb2 "github.com/opencord/voltha-protos/v4/go/openolt"
38 tp_pb "github.com/opencord/voltha-protos/v4/go/tech_profile"
kdarapu3248f9a2019-10-03 13:54:52 +053039)
40
Girish Gowdra9602eb42020-09-09 15:50:39 -070041var flowMgr []*OpenOltFlowMgr
kdarapub26b4502019-10-05 03:02:33 +053042
kdarapu3248f9a2019-10-03 13:54:52 +053043func init() {
Kent Hagermane6ff1012020-07-14 15:07:53 -040044 _, _ = log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
kdarapub26b4502019-10-05 03:02:33 +053045 flowMgr = newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +053046}
kdarapu3248f9a2019-10-03 13:54:52 +053047
Girish Gowdra9602eb42020-09-09 15:50:39 -070048func newMockFlowmgr() []*OpenOltFlowMgr {
kdarapu3248f9a2019-10-03 13:54:52 +053049 dh := newMockDeviceHandler()
50
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070051 // onuGemInfoMap := make([]rsrcMgr.onuGemInfoMap, NumPonPorts)
Girish Gowdra9602eb42020-09-09 15:50:39 -070052 var i uint32
kdarapu3248f9a2019-10-03 13:54:52 +053053
Girish Gowdra9602eb42020-09-09 15:50:39 -070054 for i = 0; i < NumPonPorts; i++ {
55 packetInGemPort := make(map[rsrcMgr.PacketInInfoKey]uint32)
56 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 +053057
Girish Gowdra9602eb42020-09-09 15:50:39 -070058 dh.flowMgr[i].packetInGemPort = packetInGemPort
Girish Gowdra4c3d4602021-07-22 16:33:37 -070059 dh.flowMgr[i].techprofile = mocks.MockTechProfile{}
60
Girish Gowdra9602eb42020-09-09 15:50:39 -070061 interface2mcastQeueuMap := make(map[uint32]*QueueInfoBrief)
62 interface2mcastQeueuMap[0] = &QueueInfoBrief{
63 gemPortID: 4000,
64 servicePriority: 3,
65 }
66 dh.flowMgr[i].grpMgr.interfaceToMcastQueueMap = interface2mcastQeueuMap
kdarapu3248f9a2019-10-03 13:54:52 +053067 }
Girish Gowdra9602eb42020-09-09 15:50:39 -070068 return dh.flowMgr
kdarapu3248f9a2019-10-03 13:54:52 +053069}
kdarapub26b4502019-10-05 03:02:33 +053070
kdarapu3248f9a2019-10-03 13:54:52 +053071func TestOpenOltFlowMgr_CreateSchedulerQueues(t *testing.T) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070072 tprofile := &tp_pb.TechProfileInstance{Name: "tp1", SubscriberIdentifier: "subscriber1",
Girish Gowdra54934262019-11-13 14:19:55 +053073 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070074 InstanceControl: &tp_pb.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"},
kdarapu3248f9a2019-10-03 13:54:52 +053075 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070076 tprofile.UsScheduler = &openoltpb2.SchedulerAttributes{}
77 tprofile.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
78 tprofile.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +053079
80 tprofile2 := tprofile
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070081 tprofile2.DsScheduler = &openoltpb2.SchedulerAttributes{}
82 tprofile2.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
83 tprofile2.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Gamze Abaka01174422021-03-10 06:55:27 +000084
kdarapu3248f9a2019-10-03 13:54:52 +053085 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +000086 name string
87 schedQueue schedQueue
88 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +053089 }{
90 // TODO: Add test cases.
Gamze Abaka01174422021-03-10 06:55:27 +000091 {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 1, Upstream)}, false},
92 {"CreateSchedulerQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 1, Downstream)}, false},
93 {"CreateSchedulerQueues-13", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 2, Upstream)}, false},
94 {"CreateSchedulerQueues-14", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 2, Downstream)}, false},
95 {"CreateSchedulerQueues-15", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 3, Upstream)}, false},
96 {"CreateSchedulerQueues-16", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 3, Downstream)}, false},
97 {"CreateSchedulerQueues-17", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 4, Upstream)}, false},
98 {"CreateSchedulerQueues-18", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 4, Downstream)}, false},
99 {"CreateSchedulerQueues-19", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 5, Upstream)}, false},
100 {"CreateSchedulerQueues-20", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 5, Downstream)}, false},
101
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700102 {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 0, Upstream)}, false},
103 {"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 +0000104 {"CreateSchedulerQueues-3", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, createFlowMetadata(tprofile, 2, Upstream)}, true},
105 {"CreateSchedulerQueues-4", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, createFlowMetadata(tprofile2, 2, Downstream)}, true},
106 {"CreateSchedulerQueues-5", schedQueue{tp_pb.Direction_UPSTREAM, 1, 2, 2, 64, 2, tprofile, 2, createFlowMetadata(tprofile, 3, Upstream)}, true},
107 {"CreateSchedulerQueues-6", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 2, 2, 65, 2, tprofile2, 2, createFlowMetadata(tprofile2, 3, Downstream)}, true},
108
kdarapu3248f9a2019-10-03 13:54:52 +0530109 //Negative testcases
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700110 {"CreateSchedulerQueues-7", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, &voltha.FlowMetadata{}}, false},
Girish Gowdra9602eb42020-09-09 15:50:39 -0700111 {"CreateSchedulerQueues-8", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 0, &voltha.FlowMetadata{}}, true},
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700112 {"CreateSchedulerQueues-9", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, &voltha.FlowMetadata{}}, false},
Girish Gowdra9602eb42020-09-09 15:50:39 -0700113 {"CreateSchedulerQueues-10", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, &voltha.FlowMetadata{}}, true},
114 {"CreateSchedulerQueues-11", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, &voltha.FlowMetadata{}}, true},
115 {"CreateSchedulerQueues-12", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, nil}, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530116 }
npujarec5762e2020-01-01 14:08:48 +0530117 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
118 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530119 for _, tt := range tests {
120 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700121 if err := flowMgr[tt.schedQueue.intfID].CreateSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530122 t.Errorf("OpenOltFlowMgr.CreateSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr)
123 }
124 })
125 }
126}
127
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700128func createFlowMetadata(techProfile *tp_pb.TechProfileInstance, tcontType int, direction string) *voltha.FlowMetadata {
129 var additionalBw openoltpb2.AdditionalBW
Gamze Abaka01174422021-03-10 06:55:27 +0000130 bands := make([]*ofp.OfpMeterBandHeader, 0)
131 switch tcontType {
132 case 1:
133 //tcont-type-1
134 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
135 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 -0700136 additionalBw = tp_pb.AdditionalBW_AdditionalBW_None
Gamze Abaka01174422021-03-10 06:55:27 +0000137 case 2:
138 //tcont-type-2
139 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 60000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
140 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 -0700141 additionalBw = tp_pb.AdditionalBW_AdditionalBW_None
Gamze Abaka01174422021-03-10 06:55:27 +0000142 case 3:
143 //tcont-type-3
144 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
145 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 -0700146 additionalBw = tp_pb.AdditionalBW_AdditionalBW_NA
Gamze Abaka01174422021-03-10 06:55:27 +0000147 case 4:
148 //tcont-type-4
149 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 -0700150 additionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
Gamze Abaka01174422021-03-10 06:55:27 +0000151 case 5:
152 //tcont-type-5
153 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
154 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
155 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 -0700156 additionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
Gamze Abaka01174422021-03-10 06:55:27 +0000157 default:
158 // do nothing, we will return meter config with no meter bands
159 }
160
161 if direction == Downstream {
162 techProfile.DsScheduler.AdditionalBw = additionalBw
163 } else {
164 techProfile.UsScheduler.AdditionalBw = additionalBw
165 }
166
167 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
168 return &voltha.FlowMetadata{
169 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}}
170}
171
kdarapu3248f9a2019-10-03 13:54:52 +0530172func TestOpenOltFlowMgr_RemoveSchedulerQueues(t *testing.T) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700173 tprofile := &tp_pb.TechProfileInstance{Name: "tp1", SubscriberIdentifier: "subscriber1",
Girish Gowdra54934262019-11-13 14:19:55 +0530174 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700175 InstanceControl: &tp_pb.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"},
kdarapu3248f9a2019-10-03 13:54:52 +0530176 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700177 tprofile.UsScheduler = &openoltpb2.SchedulerAttributes{}
178 tprofile.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
179 tprofile.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
180 tprofile.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +0530181
182 tprofile2 := tprofile
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700183 tprofile2.DsScheduler = &openoltpb2.SchedulerAttributes{}
184 tprofile2.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
185 tprofile2.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
186 tprofile2.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +0530187 //defTprofile := &tp.DefaultTechProfile{}
kdarapu3248f9a2019-10-03 13:54:52 +0530188 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +0000189 name string
190 schedQueue schedQueue
191 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +0530192 }{
193 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000194 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 0, nil}, false},
195 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530196 // negative test cases
Gamze Abakafee36392019-10-03 11:17:24 +0000197 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
198 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530199 }
npujarec5762e2020-01-01 14:08:48 +0530200 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
201 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530202 for _, tt := range tests {
203 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700204 if err := flowMgr[tt.schedQueue.intfID].RemoveSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530205 t.Errorf("OpenOltFlowMgr.RemoveSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr)
206 }
207 })
208 }
kdarapub26b4502019-10-05 03:02:33 +0530209
kdarapu3248f9a2019-10-03 13:54:52 +0530210}
211
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700212func TestOpenOltFlowMgr_createTcontGemports(t *testing.T) {
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700213 bands := make([]*ofp.OfpMeterBandHeader, 2)
214 bands[0] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 1000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
215 bands[1] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 2000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
216 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
217 flowmetadata := &voltha.FlowMetadata{
218 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
219 }
220 type args struct {
221 intfID uint32
222 onuID uint32
223 uniID uint32
224 uni string
225 uniPort uint32
226 TpID uint32
227 UsMeterID uint32
228 DsMeterID uint32
229 flowMetadata *voltha.FlowMetadata
230 }
231 tests := []struct {
232 name string
233 args args
234 }{
235 {"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 -0700236 }
237 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
238 defer cancel()
239 for _, tt := range tests {
240 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700241 _, _, 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 -0700242 switch tpInst := tpInst.(type) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700243 case *tp_pb.TechProfileInstance:
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700244 if tt.args.TpID != 64 {
245 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
246 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700247 case *tp_pb.EponTechProfileInstance:
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700248 if tt.args.TpID != 65 {
249 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
250 }
251 default:
252 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
253 }
254 })
255 }
256}
257
kdarapu3248f9a2019-10-03 13:54:52 +0530258func TestOpenOltFlowMgr_RemoveFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000259 ctx := context.Background()
Neha Sharma96b7bf22020-06-15 10:37:32 +0000260 logger.Debug(ctx, "Info Warning Error: Starting RemoveFlow() test")
kdarapu3248f9a2019-10-03 13:54:52 +0530261 fa := &fu.FlowArgs{
262 MatchFields: []*ofp.OfpOxmOfbField{
263 fu.InPort(2),
264 fu.Metadata_ofp(2),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300265 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapu3248f9a2019-10-03 13:54:52 +0530266 },
267 Actions: []*ofp.OfpAction{
268 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
269 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
270 fu.Output(1),
271 },
272 }
divyadesaid26f6b12020-03-19 06:30:28 +0000273 ofpstats, _ := fu.MkFlowStat(fa)
kdarapub26b4502019-10-05 03:02:33 +0530274 ofpstats.Cookie = ofpstats.Id
kdarapub26b4502019-10-05 03:02:33 +0530275 lldpFa := &fu.FlowArgs{
276 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
277 MatchFields: []*ofp.OfpOxmOfbField{
278 fu.InPort(1),
279 fu.EthType(0x88CC),
280 fu.TunnelId(536870912),
281 },
282 Actions: []*ofp.OfpAction{
283 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
284 },
285 }
divyadesaid26f6b12020-03-19 06:30:28 +0000286 lldpofpstats, _ := fu.MkFlowStat(lldpFa)
kdarapub26b4502019-10-05 03:02:33 +0530287 //lldpofpstats.Cookie = lldpofpstats.Id
288
289 dhcpFa := &fu.FlowArgs{
290 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
291 MatchFields: []*ofp.OfpOxmOfbField{
292 fu.InPort(1),
293 fu.UdpSrc(67),
294 //fu.TunnelId(536870912),
295 fu.IpProto(17),
296 },
297 Actions: []*ofp.OfpAction{
298 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
299 },
300 }
divyadesaid26f6b12020-03-19 06:30:28 +0000301 dhcpofpstats, _ := fu.MkFlowStat(dhcpFa)
kdarapub26b4502019-10-05 03:02:33 +0530302 //dhcpofpstats.Cookie = dhcpofpstats.Id
Esin Karamanccb714b2019-11-29 15:02:06 +0000303
304 //multicast flow
305 multicastFa := &fu.FlowArgs{
306 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800307 fu.InPort(1048576),
Esin Karamanccb714b2019-11-29 15:02:06 +0000308 fu.VlanVid(660), //vlan
309 fu.Metadata_ofp(uint64(66)), //inner vlan
310 fu.EthType(0x800), //ipv4
311 fu.Ipv4Dst(3809869825), //227.22.0.1
312 },
313 Actions: []*ofp.OfpAction{
314 fu.Group(1),
315 },
316 }
divyadesaid26f6b12020-03-19 06:30:28 +0000317 multicastOfpStats, _ := fu.MkFlowStat(multicastFa)
Esin Karamanccb714b2019-11-29 15:02:06 +0000318 multicastOfpStats.Id = 1
319
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300320 pppoedFa := &fu.FlowArgs{
321 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
322 MatchFields: []*ofp.OfpOxmOfbField{
323 fu.InPort(1),
324 fu.EthType(0x8863),
325 fu.TunnelId(536870912),
326 },
327 Actions: []*ofp.OfpAction{
328 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
329 },
330 }
331 pppoedOfpStats, _ := fu.MkFlowStat(pppoedFa)
332
kdarapu3248f9a2019-10-03 13:54:52 +0530333 type args struct {
334 flow *ofp.OfpFlowStats
335 }
336 tests := []struct {
337 name string
338 args args
339 }{
340 // TODO: Add test cases.
341 {"RemoveFlow", args{flow: ofpstats}},
kdarapub26b4502019-10-05 03:02:33 +0530342 {"RemoveFlow", args{flow: lldpofpstats}},
343 {"RemoveFlow", args{flow: dhcpofpstats}},
Esin Karamanccb714b2019-11-29 15:02:06 +0000344 {"RemoveFlow", args{flow: multicastOfpStats}},
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300345 {"RemoveFlow", args{flow: pppoedOfpStats}},
kdarapu3248f9a2019-10-03 13:54:52 +0530346 }
npujarec5762e2020-01-01 14:08:48 +0530347 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
348 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530349 for _, tt := range tests {
350 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700351 if err := flowMgr[0].RemoveFlow(ctx, tt.args.flow); err != nil {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400352 logger.Warn(ctx, err)
353 }
kdarapu3248f9a2019-10-03 13:54:52 +0530354 })
355 }
kdarapub26b4502019-10-05 03:02:33 +0530356 // t.Error("=====")
kdarapu3248f9a2019-10-03 13:54:52 +0530357}
358
359func TestOpenOltFlowMgr_AddFlow(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530360 kw := make(map[string]uint64)
361 kw["table_id"] = 1
362 kw["meter_id"] = 1
kdarapub26b4502019-10-05 03:02:33 +0530363 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
364
365 // Upstream flow
kdarapu3248f9a2019-10-03 13:54:52 +0530366 fa := &fu.FlowArgs{
367 MatchFields: []*ofp.OfpOxmOfbField{
kdarapub26b4502019-10-05 03:02:33 +0530368 fu.InPort(536870912),
369 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300370 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530371 },
372 Actions: []*ofp.OfpAction{
373 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
374 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800375 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530376 fu.PushVlan(0x8100),
377 },
378 KV: kw,
379 }
380
381 // Downstream flow
382 fa3 := &fu.FlowArgs{
383 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800384 fu.InPort(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530385 fu.Metadata_ofp(1),
386 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
387 },
388 Actions: []*ofp.OfpAction{
389 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
390 //fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
391 fu.PopVlan(),
392 fu.Output(536870912),
393 },
394 KV: kw,
395 }
396
397 fa2 := &fu.FlowArgs{
398 MatchFields: []*ofp.OfpOxmOfbField{
kdarapu3248f9a2019-10-03 13:54:52 +0530399 fu.InPort(1000),
400 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300401 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapu3248f9a2019-10-03 13:54:52 +0530402 },
403 Actions: []*ofp.OfpAction{
404 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
405 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
406 fu.Output(65533),
407 },
408 KV: kw,
409 }
410
kdarapub26b4502019-10-05 03:02:33 +0530411 // TODO Add LLDP flow
412 // TODO Add DHCP flow
413
414 // Flows for negative scenarios
415 // Failure in formulateActionInfoFromFlow()
416 fa4 := &fu.FlowArgs{
417 MatchFields: []*ofp.OfpOxmOfbField{
418 fu.InPort(1000),
419 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300420 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530421 },
422 Actions: []*ofp.OfpAction{
423 fu.Experimenter(257, []byte{1, 2, 3, 4}),
424 },
425 KV: kw,
426 }
427
428 // Invalid Output
429 fa5 := &fu.FlowArgs{
430 MatchFields: []*ofp.OfpOxmOfbField{
431 fu.InPort(1000),
432 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300433 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530434 },
435 Actions: []*ofp.OfpAction{
436 fu.Output(0),
437 },
438 KV: kw,
439 }
440
441 // Tech-Profile-ID update (not supported)
442 kw6 := make(map[string]uint64)
443 kw6["table_id"] = 1
444 kw6["meter_id"] = 1
445 kw6["write_metadata"] = 0x4100000000 // TpID Other than the stored one
446 fa6 := &fu.FlowArgs{
447 MatchFields: []*ofp.OfpOxmOfbField{
448 fu.InPort(536870912),
449 fu.TunnelId(16),
450 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300451 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530452 },
453 Actions: []*ofp.OfpAction{
454 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
455 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
456 fu.Output(65535),
457 },
458 KV: kw6,
459 }
460
461 lldpFa := &fu.FlowArgs{
462 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
463 MatchFields: []*ofp.OfpOxmOfbField{
464 fu.InPort(1),
465 fu.EthType(0x88CC),
466 fu.TunnelId(536870912),
467 },
468 Actions: []*ofp.OfpAction{
469 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
470 },
471 }
472
473 dhcpFa := &fu.FlowArgs{
474 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
475 MatchFields: []*ofp.OfpOxmOfbField{
476 fu.InPort(1),
477 fu.UdpSrc(67),
478 //fu.TunnelId(536870912),
479 fu.IpProto(17),
480 },
481 Actions: []*ofp.OfpAction{
482 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
483 },
484 }
485 igmpFa := &fu.FlowArgs{
486 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
487 MatchFields: []*ofp.OfpOxmOfbField{
488 fu.InPort(1),
489 fu.UdpSrc(67),
490 //fu.TunnelId(536870912),
491 fu.IpProto(2),
492 },
493 Actions: []*ofp.OfpAction{
494 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
495 },
496 }
497
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300498 pppoedFa := &fu.FlowArgs{
499 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
500 MatchFields: []*ofp.OfpOxmOfbField{
501 fu.InPort(1),
502 fu.EthType(0x8863),
503 fu.TunnelId(536870912),
504 },
505 Actions: []*ofp.OfpAction{
506 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
507 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
508 },
509 }
510
kdarapub26b4502019-10-05 03:02:33 +0530511 fa9 := &fu.FlowArgs{
512 MatchFields: []*ofp.OfpOxmOfbField{
513 fu.InPort(536870912),
514 fu.TunnelId(16),
515 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300516 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530517 fu.VlanPcp(1000),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800518 fu.UdpDst(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530519 fu.UdpSrc(536870912),
520 fu.Ipv4Dst(65535),
521 fu.Ipv4Src(536870912),
522 },
523 Actions: []*ofp.OfpAction{
524 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
525 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
526 fu.Output(65535),
527 },
528 KV: kw6,
529 }
530
531 fa10 := &fu.FlowArgs{
532 MatchFields: []*ofp.OfpOxmOfbField{
533 fu.InPort(65533),
534 // fu.TunnelId(16),
535 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300536 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530537 fu.VlanPcp(1000),
538 fu.UdpDst(65535),
539 fu.UdpSrc(536870912),
540 fu.Ipv4Dst(65535),
541 fu.Ipv4Src(536870912),
542 },
543 Actions: []*ofp.OfpAction{
544 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
545 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
546 fu.Output(65535),
547 },
548 KV: kw6,
549 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000550 //multicast flow
551 fa11 := &fu.FlowArgs{
552 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800553 fu.InPort(1048576),
Esin Karamanccb714b2019-11-29 15:02:06 +0000554 fu.VlanVid(660), //vlan
555 fu.Metadata_ofp(uint64(66)), //inner vlan
556 fu.EthType(0x800), //ipv4
557 fu.Ipv4Dst(3809869825), //227.22.0.1
558 },
559 Actions: []*ofp.OfpAction{
560 fu.Group(1),
561 },
562 KV: kw6,
563 }
divyadesaid26f6b12020-03-19 06:30:28 +0000564 ofpstats, _ := fu.MkFlowStat(fa)
565 ofpstats2, _ := fu.MkFlowStat(fa2)
566 ofpstats3, _ := fu.MkFlowStat(fa3)
567 ofpstats4, _ := fu.MkFlowStat(fa4)
568 ofpstats5, _ := fu.MkFlowStat(fa5)
569 ofpstats6, _ := fu.MkFlowStat(fa6)
570 ofpstats7, _ := fu.MkFlowStat(lldpFa)
571 ofpstats8, _ := fu.MkFlowStat(dhcpFa)
572 ofpstats9, _ := fu.MkFlowStat(fa9)
573 ofpstats10, _ := fu.MkFlowStat(fa10)
574 igmpstats, _ := fu.MkFlowStat(igmpFa)
575 ofpstats11, _ := fu.MkFlowStat(fa11)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300576 pppoedstats, _ := fu.MkFlowStat(pppoedFa)
kdarapub26b4502019-10-05 03:02:33 +0530577
Gamze Abakafee36392019-10-03 11:17:24 +0000578 fmt.Println(ofpstats6, ofpstats9, ofpstats10)
579
kdarapu3248f9a2019-10-03 13:54:52 +0530580 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1}
kdarapu3248f9a2019-10-03 13:54:52 +0530581 flowMetadata := &voltha.FlowMetadata{
582 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
583 }
584 type args struct {
585 flow *ofp.OfpFlowStats
586 flowMetadata *voltha.FlowMetadata
587 }
588 tests := []struct {
589 name string
590 args args
591 }{
592 // TODO: Add test cases.
593 {"AddFlow", args{flow: ofpstats, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530594 {"AddFlow", args{flow: ofpstats2, flowMetadata: flowMetadata}},
595 {"AddFlow", args{flow: ofpstats3, flowMetadata: flowMetadata}},
596 {"AddFlow", args{flow: ofpstats4, flowMetadata: flowMetadata}},
597 {"AddFlow", args{flow: ofpstats5, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000598 //{"AddFlow", args{flow: ofpstats6, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530599 {"AddFlow", args{flow: ofpstats7, flowMetadata: flowMetadata}},
600 {"AddFlow", args{flow: ofpstats8, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000601 //{"AddFlow", args{flow: ofpstats9, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530602 {"AddFlow", args{flow: igmpstats, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000603 //{"AddFlow", args{flow: ofpstats10, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530604 //ofpstats10
Esin Karamanccb714b2019-11-29 15:02:06 +0000605 {"AddFlow", args{flow: ofpstats11, flowMetadata: flowMetadata}},
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300606 {"AddFlow", args{flow: pppoedstats, flowMetadata: flowMetadata}},
kdarapu3248f9a2019-10-03 13:54:52 +0530607 }
npujarec5762e2020-01-01 14:08:48 +0530608 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
609 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530610 for _, tt := range tests {
611 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700612 _ = flowMgr[0].AddFlow(ctx, tt.args.flow, tt.args.flowMetadata)
Kent Hagermane6ff1012020-07-14 15:07:53 -0400613 // TODO: actually verify test cases
kdarapu3248f9a2019-10-03 13:54:52 +0530614 })
615 }
616}
617
618func TestOpenOltFlowMgr_UpdateOnuInfo(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530619 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
620 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530621
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700622 wg := sync.WaitGroup{}
623
Girish Gowdra9602eb42020-09-09 15:50:39 -0700624 intfCount := NumPonPorts
625 onuCount := OnuIDEnd - OnuIDStart + 1
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700626
627 for i := 0; i < intfCount; i++ {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700628 for j := 1; j <= onuCount; j++ {
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700629 wg.Add(1)
630 go func(i uint32, j uint32) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400631 // TODO: actually verify success
Girish Gowdra197acc12021-08-16 10:59:45 -0700632 _ = flowMgr[i].AddOnuInfoToFlowMgrCacheAndKvStore(ctx, i, i, fmt.Sprintf("onu-%d", i))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700633 wg.Done()
634 }(uint32(i), uint32(j))
635 }
636
637 }
638
639 wg.Wait()
640}
641
642func TestOpenOltFlowMgr_addGemPortToOnuInfoMap(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700643 intfNum := NumPonPorts
644 onuNum := OnuIDEnd - OnuIDStart + 1
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700645
646 // clean the flowMgr
Girish Gowdra9602eb42020-09-09 15:50:39 -0700647 for i := 0; i < intfNum; i++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700648 flowMgr[i].onuGemInfoMap = make(map[uint32]*rsrcMgr.OnuGemInfo)
Girish Gowdra9602eb42020-09-09 15:50:39 -0700649 }
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700650
651 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
652 defer cancel()
653
654 // Create OnuInfo
655 for i := 0; i < intfNum; i++ {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700656 for o := 1; o <= onuNum; o++ {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400657 // TODO: actually verify success
Girish Gowdra197acc12021-08-16 10:59:45 -0700658 _ = flowMgr[i].AddOnuInfoToFlowMgrCacheAndKvStore(ctx, uint32(i), uint32(o), fmt.Sprintf("i%do%d", i, o-1))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700659 }
660 }
661
662 // Add gemPorts to OnuInfo in parallel threads
663 wg := sync.WaitGroup{}
Girish Gowdra9602eb42020-09-09 15:50:39 -0700664 for o := 1; o <= onuNum; o++ {
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700665 for i := 0; i < intfNum; i++ {
666 wg.Add(1)
667 go func(intfId uint32, onuId uint32) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700668 gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", intfId, onuId-1))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700669
Girish Gowdra9602eb42020-09-09 15:50:39 -0700670 flowMgr[intfId].addGemPortToOnuInfoMap(ctx, intfId, onuId, uint32(gemID))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700671 wg.Done()
672 }(uint32(i), uint32(o))
673 }
674 }
675
676 wg.Wait()
677
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700678 // check that each entry of onuGemInfoMap has the correct number of ONUs
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700679 for i := 0; i < intfNum; i++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700680 lenofOnu := len(flowMgr[i].onuGemInfoMap)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700681 if onuNum != lenofOnu {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700682 t.Errorf("onuGemInfoMap length is not as expected len = %d, want %d", lenofOnu, onuNum)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700683 }
684
Girish Gowdra9602eb42020-09-09 15:50:39 -0700685 for o := 1; o <= onuNum; o++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700686 lenOfGemPorts := len(flowMgr[i].onuGemInfoMap[uint32(o)].GemPorts)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700687 // check that each onuEntry has 1 gemPort
688 if lenOfGemPorts != 1 {
689 t.Errorf("Expected 1 GemPort per ONU, found %d", lenOfGemPorts)
690 }
691
692 // check that the value of the gemport is correct
Girish Gowdra9602eb42020-09-09 15:50:39 -0700693 gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", i, o-1))
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700694 currentValue := flowMgr[i].onuGemInfoMap[uint32(o)].GemPorts[0]
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700695 if uint32(gemID) != currentValue {
696 t.Errorf("Expected GemPort value to be %d, found %d", gemID, currentValue)
697 }
698 }
kdarapu3248f9a2019-10-03 13:54:52 +0530699 }
700}
701
serkant.uluderya96af4932020-02-20 16:58:48 -0800702func TestOpenOltFlowMgr_deleteGemPortFromLocalCache(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700703 // Create fresh flowMgr instance
704 flowMgr = newMockFlowmgr()
serkant.uluderya96af4932020-02-20 16:58:48 -0800705 type args struct {
706 intfID uint32
707 onuID uint32
708 gemPortIDs []uint32
709 gemPortIDsToBeDeleted []uint32
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700710 gemPortIDsRemaining []uint32
serkant.uluderya96af4932020-02-20 16:58:48 -0800711 serialNum string
712 finalLength int
713 }
714 tests := []struct {
715 name string
716 args args
717 }{
718 // Add/Delete single gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700719 {"DeleteGemPortFromLocalCache1", args{0, 1, []uint32{1}, []uint32{1}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800720 // Delete all gemports
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700721 {"DeleteGemPortFromLocalCache2", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{1, 2, 3, 4}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800722 // Try to delete when there is no gem port
Girish Gowdra197acc12021-08-16 10:59:45 -0700723 {"DeleteGemPortFromLocalCache3", args{0, 1, []uint32{}, []uint32{1, 2}, nil, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800724 // Try to delete non-existent gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700725 {"DeleteGemPortFromLocalCache4", args{0, 1, []uint32{1}, []uint32{2}, []uint32{1}, "onu1", 1}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800726 // Try to delete two of the gem ports
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700727 {"DeleteGemPortFromLocalCache5", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{2, 4}, []uint32{1, 3}, "onu1", 2}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800728 }
729 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
730 defer cancel()
731 for _, tt := range tests {
732 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra197acc12021-08-16 10:59:45 -0700733 if err := flowMgr[tt.args.intfID].RemoveOnuInfoFromFlowMgrCacheAndKvStore(ctx, tt.args.intfID, tt.args.onuID); err != nil {
734 t.Errorf("failed to remove onu")
735 }
736 if err := flowMgr[tt.args.intfID].AddOnuInfoToFlowMgrCacheAndKvStore(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum); err != nil {
737 t.Errorf("failed to add onu")
738 }
serkant.uluderya96af4932020-02-20 16:58:48 -0800739 for _, gemPort := range tt.args.gemPortIDs {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700740 flowMgr[tt.args.intfID].addGemPortToOnuInfoMap(ctx, tt.args.intfID, tt.args.onuID, gemPort)
serkant.uluderya96af4932020-02-20 16:58:48 -0800741 }
742 for _, gemPortDeleted := range tt.args.gemPortIDsToBeDeleted {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700743 flowMgr[tt.args.intfID].deleteGemPortFromLocalCache(ctx, tt.args.intfID, tt.args.onuID, gemPortDeleted)
serkant.uluderya96af4932020-02-20 16:58:48 -0800744 }
Girish Gowdra197acc12021-08-16 10:59:45 -0700745 lenofGemPorts := 0
746 gP, ok := flowMgr[tt.args.intfID].onuGemInfoMap[tt.args.onuID]
747 if ok {
748 lenofGemPorts = len(gP.GemPorts)
749 }
serkant.uluderya96af4932020-02-20 16:58:48 -0800750 if lenofGemPorts != tt.args.finalLength {
751 t.Errorf("GemPorts length is not as expected len = %d, want %d", lenofGemPorts, tt.args.finalLength)
752 }
Girish Gowdra197acc12021-08-16 10:59:45 -0700753 gP, ok = flowMgr[tt.args.intfID].onuGemInfoMap[tt.args.onuID]
754 var gemPorts []uint32
755 if ok {
756 gemPorts = gP.GemPorts
757 }
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700758 if !reflect.DeepEqual(tt.args.gemPortIDsRemaining, gemPorts) {
759 t.Errorf("GemPorts are not as expected = %v, want %v", gemPorts, tt.args.gemPortIDsRemaining)
760 }
serkant.uluderya96af4932020-02-20 16:58:48 -0800761
762 })
763 }
764}
765
kdarapu3248f9a2019-10-03 13:54:52 +0530766func TestOpenOltFlowMgr_GetLogicalPortFromPacketIn(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530767 type args struct {
768 packetIn *openoltpb2.PacketIndication
769 }
770 tests := []struct {
771 name string
772 args args
773 want uint32
774 wantErr bool
775 }{
776 // TODO: Add test cases.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700777 {"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},
778 {"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 +0530779 // Negative Test cases.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700780 {"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},
781 {"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 +0530782 }
npujarec5762e2020-01-01 14:08:48 +0530783 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
784 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530785 for _, tt := range tests {
786 t.Run(tt.name, func(t *testing.T) {
787
Girish Gowdra9602eb42020-09-09 15:50:39 -0700788 got, err := flowMgr[tt.args.packetIn.IntfId].GetLogicalPortFromPacketIn(ctx, tt.args.packetIn)
kdarapu3248f9a2019-10-03 13:54:52 +0530789 if (err != nil) != tt.wantErr {
790 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() error = %v, wantErr %v", err, tt.wantErr)
791 return
792 }
793 if got != tt.want {
794 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() = %v, want %v", got, tt.want)
795 }
796 })
797 }
798}
799
800func TestOpenOltFlowMgr_GetPacketOutGemPortID(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700801 // Create fresh flowMgr instance
802 flowMgr = newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530803
Esin Karaman7fb80c22020-07-16 14:23:33 +0000804 //untagged packet in hex string
805 untaggedStr := "01005e000002000000000001080046c00020000040000102fa140a000001e00000029404000017000705e10000fa"
806 untagged, err := hex.DecodeString(untaggedStr)
807 if err != nil {
808 t.Error("Unable to parse hex string", err)
809 panic(err)
810 }
Girish Gowdra9602eb42020-09-09 15:50:39 -0700811 //single-tagged packet in hex string. vlanID.pbit: 1.1
812 singleTaggedStr := "01005e0000010025ba48172481002001080046c0002000004000010257deab140023e0000001940400001164ee9b0000000000000000000000000000"
Esin Karaman7fb80c22020-07-16 14:23:33 +0000813 singleTagged, err := hex.DecodeString(singleTaggedStr)
814 if err != nil {
815 t.Error("Unable to parse hex string", err)
816 panic(err)
817 }
Girish Gowdra9602eb42020-09-09 15:50:39 -0700818 //double-tagged packet in hex string. vlanID.pbit: 210.0-0.0
819 doubleTaggedStr := "01005e000016deadbeefba118100021081000000080046000028000000000102c5b87f000001e0000016940400002200f8030000000104000000e10000fa"
Esin Karaman7fb80c22020-07-16 14:23:33 +0000820 doubleTagged, err := hex.DecodeString(doubleTaggedStr)
821 if err != nil {
822 t.Error("Unable to parse hex string", err)
823 panic(err)
824 }
825
kdarapu3248f9a2019-10-03 13:54:52 +0530826 type args struct {
827 intfID uint32
828 onuID uint32
829 portNum uint32
Esin Karaman7fb80c22020-07-16 14:23:33 +0000830 packet []byte
kdarapu3248f9a2019-10-03 13:54:52 +0530831 }
832 tests := []struct {
833 name string
834 args args
835 want uint32
836 wantErr bool
837 }{
838 // TODO: Add test cases.
Girish Gowdra9602eb42020-09-09 15:50:39 -0700839 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: untagged}, 1, false},
840 {"GetPacketOutGemPortID", args{intfID: 1, onuID: 2, portNum: 2, packet: singleTagged}, 2, false},
841 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: doubleTagged}, 1, false},
842 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 10, portNum: 10, packet: untagged}, 2, true},
843 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 3, packet: []byte{}}, 3, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530844 }
Esin Karaman7fb80c22020-07-16 14:23:33 +0000845
npujarec5762e2020-01-01 14:08:48 +0530846 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
847 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530848 for _, tt := range tests {
849 t.Run(tt.name, func(t *testing.T) {
850
Girish Gowdra9602eb42020-09-09 15:50:39 -0700851 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 +0000852 if tt.wantErr {
853 if err == nil {
854 //error expected but got value
855 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, wantErr %v", got, tt.wantErr)
856 }
857 } else {
858 if err != nil {
859 //error is not expected but got error
860 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() error = %v, wantErr %v", err, tt.wantErr)
861 return
862 }
863 if got != tt.want {
864 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, want %v", got, tt.want)
865 }
kdarapu3248f9a2019-10-03 13:54:52 +0530866 }
kdarapu3248f9a2019-10-03 13:54:52 +0530867 })
868 }
869}
870
871func TestOpenOltFlowMgr_DeleteTechProfileInstance(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530872 type args struct {
873 intfID uint32
874 onuID uint32
875 uniID uint32
876 sn string
Gamze Abakafee36392019-10-03 11:17:24 +0000877 tpID uint32
kdarapu3248f9a2019-10-03 13:54:52 +0530878 }
879 tests := []struct {
880 name string
881 args args
882 wantErr bool
883 }{
884 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000885 {"DeleteTechProfileInstance", args{intfID: 0, onuID: 1, uniID: 1, sn: "", tpID: 64}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530886 }
npujarec5762e2020-01-01 14:08:48 +0530887 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
888 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530889 for _, tt := range tests {
890 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700891 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 +0530892 t.Errorf("OpenOltFlowMgr.DeleteTechProfileInstance() error = %v, wantErr %v", err, tt.wantErr)
893 }
894 })
895 }
896}
kdarapub26b4502019-10-05 03:02:33 +0530897
898func TestOpenOltFlowMgr_checkAndAddFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000899 ctx := context.Background()
kdarapub26b4502019-10-05 03:02:33 +0530900 kw := make(map[string]uint64)
901 kw["table_id"] = 1
902 kw["meter_id"] = 1
903 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
904
905 // Upstream flow
906 fa := &fu.FlowArgs{
907 MatchFields: []*ofp.OfpOxmOfbField{
908 fu.InPort(536870912),
909 fu.Metadata_ofp(1),
910 fu.IpProto(17), // dhcp
Gamze Abakafee36392019-10-03 11:17:24 +0000911 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300912 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530913 },
914 Actions: []*ofp.OfpAction{
915 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
916 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800917 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530918 fu.PushVlan(0x8100),
919 },
920 KV: kw,
921 }
922
923 // EAPOL
924 fa2 := &fu.FlowArgs{
925 MatchFields: []*ofp.OfpOxmOfbField{
926 fu.InPort(536870912),
927 fu.Metadata_ofp(1),
928 fu.EthType(0x888E),
929 fu.VlanPcp(1),
930 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
931 },
932 Actions: []*ofp.OfpAction{
933 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
934 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800935 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530936 fu.PushVlan(0x8100),
937 },
938 KV: kw,
939 }
940
941 // HSIA
942 fa3 := &fu.FlowArgs{
943 MatchFields: []*ofp.OfpOxmOfbField{
944 fu.InPort(536870912),
945 fu.Metadata_ofp(1),
946 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300947 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530948 },
949 Actions: []*ofp.OfpAction{
950 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300951 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800952 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530953 fu.PushVlan(0x8100),
954 },
955 KV: kw,
956 }
957
958 fa4 := &fu.FlowArgs{
959 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800960 fu.InPort(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530961 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300962 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530963 fu.VlanPcp(1),
964 },
965 Actions: []*ofp.OfpAction{
966 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300967 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
kdarapub26b4502019-10-05 03:02:33 +0530968 fu.Output(536870912),
969 fu.PopVlan(),
970 },
971 KV: kw,
972 }
973
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300974 // PPPOED
975 pppoedFA := &fu.FlowArgs{
976 MatchFields: []*ofp.OfpOxmOfbField{
977 fu.InPort(536870912),
978 fu.Metadata_ofp(1),
979 fu.EthType(0x8863),
980 fu.VlanPcp(1),
981 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
982 },
983 Actions: []*ofp.OfpAction{
984 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
985 fu.Output(1048576),
986 fu.PushVlan(0x8100),
987 },
988 KV: kw,
989 }
990
kdarapub26b4502019-10-05 03:02:33 +0530991 classifierInfo := make(map[string]interface{})
992 actionInfo := make(map[string]interface{})
993 classifierInfo2 := make(map[string]interface{})
994 actionInfo2 := make(map[string]interface{})
995 classifierInfo3 := make(map[string]interface{})
996 actionInfo3 := make(map[string]interface{})
997 classifierInfo4 := make(map[string]interface{})
998 actionInfo4 := make(map[string]interface{})
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300999 classifierInfo5 := make(map[string]interface{})
1000 actionInfo5 := make(map[string]interface{})
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001001 flow, _ := fu.MkFlowStat(fa)
1002 flow2, _ := fu.MkFlowStat(fa2)
1003 flow3, _ := fu.MkFlowStat(fa3)
1004 flow4, _ := fu.MkFlowStat(fa4)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001005 flow5, _ := fu.MkFlowStat(pppoedFA)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001006 formulateClassifierInfoFromFlow(ctx, classifierInfo, flow)
1007 formulateClassifierInfoFromFlow(ctx, classifierInfo2, flow2)
1008 formulateClassifierInfoFromFlow(ctx, classifierInfo3, flow3)
1009 formulateClassifierInfoFromFlow(ctx, classifierInfo4, flow4)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001010 formulateClassifierInfoFromFlow(ctx, classifierInfo5, flow5)
kdarapub26b4502019-10-05 03:02:33 +05301011
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001012 err := formulateActionInfoFromFlow(ctx, actionInfo, classifierInfo, flow)
kdarapub26b4502019-10-05 03:02:33 +05301013 if err != nil {
1014 // Error logging is already done in the called function
1015 // So just return in case of error
1016 return
1017 }
1018
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001019 err = formulateActionInfoFromFlow(ctx, actionInfo2, classifierInfo2, flow2)
kdarapub26b4502019-10-05 03:02:33 +05301020 if err != nil {
1021 // Error logging is already done in the called function
1022 // So just return in case of error
1023 return
1024 }
1025
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001026 err = formulateActionInfoFromFlow(ctx, actionInfo3, classifierInfo3, flow3)
kdarapub26b4502019-10-05 03:02:33 +05301027 if err != nil {
1028 // Error logging is already done in the called function
1029 // So just return in case of error
1030 return
1031 }
1032
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001033 err = formulateActionInfoFromFlow(ctx, actionInfo4, classifierInfo4, flow4)
kdarapub26b4502019-10-05 03:02:33 +05301034 if err != nil {
1035 // Error logging is already done in the called function
1036 // So just return in case of error
1037 return
1038 }
1039
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001040 err = formulateActionInfoFromFlow(ctx, actionInfo5, classifierInfo5, flow5)
1041 if err != nil {
1042 // Error logging is already done in the called function
1043 // So just return in case of error
1044 return
1045 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001046 /*
1047 usGemList := make([]*tp_pb.GemPortAttributes, 4)
1048 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1049 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1050 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1051 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1052 dsGemList := make([]*tp_pb.GemPortAttributes, 4)
1053 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1054 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1055 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1056 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1057 */
1058 TpInst := &tp_pb.TechProfileInstance{
kdarapub26b4502019-10-05 03:02:33 +05301059 Name: "Test-Tech-Profile",
1060 SubscriberIdentifier: "257",
1061 ProfileType: "Mock",
1062 Version: 1,
1063 NumGemPorts: 4,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001064 InstanceControl: &tp_pb.InstanceControl{
kdarapub26b4502019-10-05 03:02:33 +05301065 Onu: "1",
1066 Uni: "16",
1067 },
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001068 UsScheduler: &openoltpb2.SchedulerAttributes{},
1069 DsScheduler: &openoltpb2.SchedulerAttributes{},
kdarapub26b4502019-10-05 03:02:33 +05301070 }
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001071 TpInst.UsScheduler.Priority = 1
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001072 TpInst.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
1073 TpInst.UsScheduler.AllocId = 1
1074 TpInst.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
1075 TpInst.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001076 TpInst.UsScheduler.Weight = 4
1077
1078 TpInst.DsScheduler.Priority = 1
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001079 TpInst.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
1080 TpInst.DsScheduler.AllocId = 1
1081 TpInst.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
1082 TpInst.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001083 TpInst.DsScheduler.Weight = 4
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001084 TpInst.UpstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
1085 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
1086 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
1087 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
1088 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001089
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001090 TpInst.DownstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
1091 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
1092 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
1093 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
1094 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
kdarapub26b4502019-10-05 03:02:33 +05301095
kdarapub26b4502019-10-05 03:02:33 +05301096 type args struct {
1097 args map[string]uint32
1098 classifierInfo map[string]interface{}
1099 actionInfo map[string]interface{}
1100 flow *ofp.OfpFlowStats
1101 gemPort uint32
1102 intfID uint32
1103 onuID uint32
1104 uniID uint32
1105 portNo uint32
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001106 TpInst *tp_pb.TechProfileInstance
kdarapub26b4502019-10-05 03:02:33 +05301107 allocID []uint32
1108 gemPorts []uint32
1109 TpID uint32
1110 uni string
1111 }
1112 tests := []struct {
Kent Hagermane6ff1012020-07-14 15:07:53 -04001113 name string
1114 args args
kdarapub26b4502019-10-05 03:02:33 +05301115 }{
1116 {
1117 name: "checkAndAddFlow-1",
1118 args: args{
1119 args: nil,
1120 classifierInfo: classifierInfo,
1121 actionInfo: actionInfo,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001122 flow: flow,
kdarapub26b4502019-10-05 03:02:33 +05301123 gemPort: 1,
1124 intfID: 1,
1125 onuID: 1,
1126 uniID: 16,
1127 portNo: 1,
1128 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001129 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301130 gemPorts: []uint32{1, 2, 3, 4},
1131 TpID: 64,
1132 uni: "16",
1133 },
1134 },
1135 {
1136 name: "checkAndAddFlow-2",
1137 args: args{
1138 args: nil,
1139 classifierInfo: classifierInfo2,
1140 actionInfo: actionInfo2,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001141 flow: flow2,
kdarapub26b4502019-10-05 03:02:33 +05301142 gemPort: 1,
1143 intfID: 1,
1144 onuID: 1,
1145 uniID: 16,
1146 portNo: 1,
1147 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001148 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301149 gemPorts: []uint32{1, 2, 3, 4},
1150 TpID: 64,
1151 uni: "16",
1152 },
1153 },
1154 {
1155 name: "checkAndAddFlow-3",
1156 args: args{
1157 args: nil,
1158 classifierInfo: classifierInfo3,
1159 actionInfo: actionInfo3,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001160 flow: flow3,
kdarapub26b4502019-10-05 03:02:33 +05301161 gemPort: 1,
1162 intfID: 1,
1163 onuID: 1,
1164 uniID: 16,
1165 portNo: 1,
1166 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001167 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301168 gemPorts: []uint32{1, 2, 3, 4},
1169 TpID: 64,
1170 uni: "16",
1171 },
1172 },
1173 {
1174 name: "checkAndAddFlow-4",
1175 args: args{
1176 args: nil,
1177 classifierInfo: classifierInfo4,
1178 actionInfo: actionInfo4,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001179 flow: flow4,
kdarapub26b4502019-10-05 03:02:33 +05301180 gemPort: 1,
1181 intfID: 1,
1182 onuID: 1,
1183 uniID: 16,
1184 portNo: 1,
1185 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001186 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301187 gemPorts: []uint32{1, 2, 3, 4},
1188 TpID: 64,
1189 uni: "16",
1190 },
1191 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001192 {
1193 name: "checkAndAddFlow-5",
1194 args: args{
1195 args: nil,
1196 classifierInfo: classifierInfo5,
1197 actionInfo: actionInfo5,
1198 flow: flow5,
1199 gemPort: 1,
1200 intfID: 1,
1201 onuID: 1,
1202 uniID: 16,
1203 portNo: 1,
1204 TpInst: TpInst,
1205 allocID: []uint32{0x8001},
1206 gemPorts: []uint32{1, 2, 3, 4},
1207 TpID: 64,
1208 uni: "16",
1209 },
1210 },
kdarapub26b4502019-10-05 03:02:33 +05301211 }
npujarec5762e2020-01-01 14:08:48 +05301212 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1213 defer cancel()
kdarapub26b4502019-10-05 03:02:33 +05301214 for _, tt := range tests {
1215 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -07001216 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 +00001217 tt.args.TpInst, tt.args.gemPorts, tt.args.TpID, tt.args.uni)
kdarapub26b4502019-10-05 03:02:33 +05301218 })
1219 }
1220}
Esin Karamanccb714b2019-11-29 15:02:06 +00001221
Esin Karamand519bbf2020-07-01 11:16:03 +00001222func TestOpenOltFlowMgr_TestMulticastFlowAndGroup(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301223 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1224 defer cancel()
Esin Karamanccb714b2019-11-29 15:02:06 +00001225 //create group
1226 group := newGroup(2, []uint32{1})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001227 err := flowMgr[0].grpMgr.AddGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001228 if err != nil {
1229 t.Error("group-add failed", err)
1230 return
1231 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001232 //create multicast flow
1233 multicastFlowArgs := &fu.FlowArgs{
1234 MatchFields: []*ofp.OfpOxmOfbField{
Esin Karamand519bbf2020-07-01 11:16:03 +00001235 fu.InPort(1048576),
Esin Karamanccb714b2019-11-29 15:02:06 +00001236 fu.VlanVid(660), //vlan
1237 fu.Metadata_ofp(uint64(66)), //inner vlan
1238 fu.EthType(0x800), //ipv4
1239 fu.Ipv4Dst(3809869825), //227.22.0.1
1240 },
1241 Actions: []*ofp.OfpAction{
1242 fu.Group(1),
1243 },
1244 }
divyadesaid26f6b12020-03-19 06:30:28 +00001245 ofpStats, _ := fu.MkFlowStat(multicastFlowArgs)
Esin Karamand519bbf2020-07-01 11:16:03 +00001246 fmt.Println(ofpStats.Id)
Girish Gowdra9602eb42020-09-09 15:50:39 -07001247 err = flowMgr[0].AddFlow(ctx, ofpStats, &voltha.FlowMetadata{})
Esin Karamand519bbf2020-07-01 11:16:03 +00001248 if err != nil {
1249 t.Error("Multicast flow-add failed", err)
1250 return
1251 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001252
1253 //add bucket to the group
1254 group = newGroup(2, []uint32{1, 2})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001255 err = flowMgr[0].grpMgr.ModifyGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001256 if err != nil {
1257 t.Error("modify-group failed", err)
1258 return
1259 }
1260 //remove the multicast flow
Girish Gowdra9602eb42020-09-09 15:50:39 -07001261 err = flowMgr[0].RemoveFlow(ctx, ofpStats)
Esin Karamand519bbf2020-07-01 11:16:03 +00001262 if err != nil {
1263 t.Error("Multicast flow-remove failed", err)
1264 return
1265 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001266
Esin Karamand519bbf2020-07-01 11:16:03 +00001267 //remove the group
Girish Gowdra9602eb42020-09-09 15:50:39 -07001268 err = flowMgr[0].grpMgr.DeleteGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001269 if err != nil {
1270 t.Error("delete-group failed", err)
1271 return
1272 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001273}
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001274
1275func TestOpenOltFlowMgr_TestRouteFlowToOnuChannel(t *testing.T) {
1276 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1277 defer cancel()
1278 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/core", log.DebugLevel)
1279 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager", log.DebugLevel)
1280 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/pkg/mocks", log.DebugLevel)
Girish Gowdra0aca4982021-01-04 12:44:27 -08001281 kwTable1Meter1 := make(map[string]uint64)
1282 kwTable1Meter1["table_id"] = 1
1283 kwTable1Meter1["meter_id"] = 1
1284 kwTable1Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
1285
1286 kwTable0Meter1 := make(map[string]uint64)
1287 kwTable0Meter1["table_id"] = 0
1288 kwTable0Meter1["meter_id"] = 1
1289 kwTable0Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001290
1291 flowMetadata1 := voltha.FlowMetadata{Meters: []*voltha.OfpMeterConfig{
1292 {
1293 Flags: 5,
1294 MeterId: 1,
1295 Bands: []*voltha.OfpMeterBandHeader{
1296 {
1297 Type: voltha.OfpMeterBandType_OFPMBT_DROP,
1298 Rate: 16000,
Gamze Abaka01174422021-03-10 06:55:27 +00001299 BurstSize: 0,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001300 },
1301 {
1302 Type: voltha.OfpMeterBandType_OFPMBT_DROP,
1303 Rate: 32000,
1304 BurstSize: 30,
1305 },
1306 {
1307 Type: voltha.OfpMeterBandType_OFPMBT_DROP,
1308 Rate: 64000,
1309 BurstSize: 30,
1310 },
1311 },
1312 },
1313 }}
1314
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001315 // Downstream LLDP Trap from NNI0 flow
1316 fa0 := &fu.FlowArgs{
1317 MatchFields: []*ofp.OfpOxmOfbField{
1318 fu.InPort(1048576),
1319 fu.EthType(35020),
1320 },
1321 Actions: []*ofp.OfpAction{
1322 fu.Output(4294967293),
1323 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001324 KV: make(map[string]uint64),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001325 }
1326
1327 // Upstream flow DHCP flow - ONU1 UNI0 PON0
1328 fa1 := &fu.FlowArgs{
1329 MatchFields: []*ofp.OfpOxmOfbField{
1330 fu.InPort(536870912),
1331 fu.Metadata_ofp(1),
1332 fu.IpProto(17), // dhcp
1333 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001334 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001335 fu.TunnelId(16),
1336 },
1337 Actions: []*ofp.OfpAction{
1338 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1339 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1340 fu.Output(2147483645),
1341 fu.PushVlan(0x8100),
1342 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001343 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001344 }
1345
1346 // Upstream EAPOL - ONU1 UNI0 PON0
1347 fa2 := &fu.FlowArgs{
1348 MatchFields: []*ofp.OfpOxmOfbField{
1349 fu.InPort(536870912),
1350 fu.Metadata_ofp(1),
1351 fu.EthType(0x888E),
1352 fu.VlanPcp(1),
1353 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
1354 fu.TunnelId(16),
1355 },
1356 Actions: []*ofp.OfpAction{
1357 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1358 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1359 fu.Output(2147483645),
1360 fu.PushVlan(0x8100),
1361 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001362 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001363 }
1364
1365 // Upstream HSIA - ONU1 UNI0 PON0
1366 fa3 := &fu.FlowArgs{
1367 MatchFields: []*ofp.OfpOxmOfbField{
1368 fu.InPort(536870912),
1369 fu.Metadata_ofp(1),
1370 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001371 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001372 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001373 },
1374 Actions: []*ofp.OfpAction{
1375 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001376 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001377 fu.Output(1048576),
1378 fu.PushVlan(0x8100),
1379 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001380 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001381 }
1382
1383 // Downstream HSIA - ONU1 UNI0 PON0
1384 fa4 := &fu.FlowArgs{
1385 MatchFields: []*ofp.OfpOxmOfbField{
1386 fu.InPort(1048576),
1387 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001388 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001389 fu.VlanPcp(1),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001390 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001391 },
1392 Actions: []*ofp.OfpAction{
1393 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001394 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001395 fu.Output(536870912),
1396 fu.PopVlan(),
1397 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001398 KV: kwTable0Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001399 }
1400
1401 // Upstream flow DHCP flow - ONU1 UNI0 PON15
1402 fa5 := &fu.FlowArgs{
1403 MatchFields: []*ofp.OfpOxmOfbField{
1404 fu.InPort(536870927),
1405 fu.Metadata_ofp(1),
1406 fu.IpProto(17), // dhcp
1407 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001408 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001409 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001410 },
1411 Actions: []*ofp.OfpAction{
1412 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1413 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259)),
1414 fu.Output(2147483645),
1415 fu.PushVlan(0x8100),
1416 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001417 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001418 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001419
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001420 // Upstream EAPOL - ONU1 UNI0 PON15
1421 fa6 := &fu.FlowArgs{
1422 MatchFields: []*ofp.OfpOxmOfbField{
1423 fu.InPort(536870927),
1424 fu.Metadata_ofp(1),
1425 fu.EthType(0x888E),
1426 fu.VlanPcp(1),
1427 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001428 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001429 },
1430 Actions: []*ofp.OfpAction{
1431 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1432 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1433 fu.Output(2147483645),
1434 fu.PushVlan(0x8100),
1435 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001436 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001437 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001438
1439 // Upstream PPPOED - ONU1 UNI0 PON0
1440 fa7 := &fu.FlowArgs{
1441 MatchFields: []*ofp.OfpOxmOfbField{
1442 fu.InPort(536870912),
1443 fu.Metadata_ofp(1),
1444 fu.EthType(0x8863),
1445 fu.VlanPcp(1),
1446 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
1447 fu.TunnelId(16),
1448 },
1449 Actions: []*ofp.OfpAction{
1450 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1451 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1452 fu.Output(2147483645),
1453 fu.PushVlan(0x8100),
1454 },
1455 KV: kwTable1Meter1,
1456 }
1457
1458 // Upstream PPPOED - ONU1 UNI0 PON15
1459 fa8 := &fu.FlowArgs{
1460 MatchFields: []*ofp.OfpOxmOfbField{
1461 fu.InPort(536870927),
1462 fu.Metadata_ofp(1),
1463 fu.EthType(0x8863),
1464 fu.VlanPcp(1),
1465 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
1466 fu.TunnelId(16),
1467 },
1468 Actions: []*ofp.OfpAction{
1469 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1470 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1471 fu.Output(2147483645),
1472 fu.PushVlan(0x8100),
1473 },
1474 KV: kwTable1Meter1,
1475 }
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001476 flow0, _ := fu.MkFlowStat(fa0)
1477 flow1, _ := fu.MkFlowStat(fa1)
1478 flow2, _ := fu.MkFlowStat(fa2)
1479 flow3, _ := fu.MkFlowStat(fa3)
1480 flow4, _ := fu.MkFlowStat(fa4)
1481
1482 flow5, _ := fu.MkFlowStat(fa5)
1483 flow6, _ := fu.MkFlowStat(fa6)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001484 flow7, _ := fu.MkFlowStat(fa7)
1485 flow8, _ := fu.MkFlowStat(fa8)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001486
1487 type args struct {
1488 ctx context.Context
1489 flow *ofp.OfpFlowStats
1490 addFlow bool
1491 flowMetadata *voltha.FlowMetadata
1492 }
1493 tests := []struct {
1494 name string
1495 args args
1496 wantErr bool
1497 returnedErr error
1498 }{
1499 {
1500 name: "RouteFlowToOnuChannel-0",
1501 args: args{
1502 ctx: ctx,
1503 flow: flow0,
1504 addFlow: true,
1505 flowMetadata: &flowMetadata1,
1506 },
1507 wantErr: false,
1508 },
1509 {
1510 name: "RouteFlowToOnuChannel-1",
1511 args: args{
1512 ctx: ctx,
1513 flow: flow1,
1514 addFlow: true,
1515 flowMetadata: &flowMetadata1,
1516 },
1517 wantErr: false,
1518 },
1519 {
1520 name: "RouteFlowToOnuChannel-2",
1521 args: args{
1522 ctx: ctx,
1523 flow: flow2,
1524 addFlow: true,
1525 flowMetadata: &flowMetadata1,
1526 },
1527 wantErr: false,
1528 },
1529 {
1530 name: "RouteFlowToOnuChannel-3",
1531 args: args{
1532 ctx: ctx,
1533 flow: flow3,
1534 addFlow: true,
1535 flowMetadata: &flowMetadata1,
1536 },
1537 wantErr: false,
1538 },
1539 {
1540 name: "RouteFlowToOnuChannel-4",
1541 args: args{
1542 ctx: ctx,
1543 flow: flow4,
1544 addFlow: true,
1545 flowMetadata: &flowMetadata1,
1546 },
1547 wantErr: false,
1548 },
1549 {
1550 name: "RouteFlowToOnuChannel-5",
1551 args: args{
1552 ctx: ctx,
1553 flow: flow1,
1554 addFlow: false,
1555 flowMetadata: &flowMetadata1,
1556 },
1557 wantErr: false,
1558 },
1559 {
1560 name: "RouteFlowToOnuChannel-6",
1561 args: args{
1562 ctx: ctx,
1563 flow: flow1,
1564 addFlow: true,
Girish Gowdra0aca4982021-01-04 12:44:27 -08001565 flowMetadata: &flowMetadata1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001566 },
1567 wantErr: true,
1568 },
1569 {
1570 name: "RouteFlowToOnuChannel-7",
1571 args: args{
1572 ctx: ctx,
1573 flow: flow5,
1574 addFlow: true,
1575 flowMetadata: &flowMetadata1,
1576 },
1577 wantErr: false,
1578 },
1579 {
1580 name: "RouteFlowToOnuChannel-8",
1581 args: args{
1582 ctx: ctx,
1583 flow: flow6,
1584 addFlow: true,
1585 flowMetadata: &flowMetadata1,
1586 },
1587 wantErr: false,
1588 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001589 {
1590 name: "RouteFlowToOnuChannel-9",
1591 args: args{
1592 ctx: ctx,
1593 flow: flow7,
1594 addFlow: true,
1595 flowMetadata: &flowMetadata1,
1596 },
1597 wantErr: false,
1598 },
1599 {
1600 name: "RouteFlowToOnuChannel-10",
1601 args: args{
1602 ctx: ctx,
1603 flow: flow8,
1604 addFlow: true,
1605 flowMetadata: &flowMetadata1,
1606 },
1607 wantErr: false,
1608 },
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001609 }
1610
1611 var wg sync.WaitGroup
1612 defer wg.Wait() // wait for all go routines to complete
1613 for _, tt := range tests {
1614 t.Run(tt.name, func(t *testing.T) {
1615 wg.Add(1) // one per go routine
1616 go func() {
1617 defer wg.Done()
1618 tt.returnedErr = flowMgr[0].RouteFlowToOnuChannel(tt.args.ctx, tt.args.flow, tt.args.addFlow, tt.args.flowMetadata)
1619 if (tt.wantErr == false && tt.returnedErr != nil) || (tt.wantErr == true && tt.returnedErr == nil) {
1620 t.Errorf("OpenOltFlowMgr.RouteFlowToOnuChannel() error = %v, wantErr %v", tt.returnedErr, tt.wantErr)
1621 }
1622 }()
1623 })
1624 }
1625}