blob: 01c608f263e918e92912aa3b880b5e8291042e7a [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
khenaidoo106c61a2021-08-11 18:05:46 -040030 "github.com/opencord/voltha-openolt-adapter/pkg/mocks"
kdarapub26b4502019-10-05 03:02:33 +053031
khenaidoo106c61a2021-08-11 18:05:46 -040032 "github.com/opencord/voltha-protos/v5/go/voltha"
33
34 fu "github.com/opencord/voltha-lib-go/v7/pkg/flows"
35 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Scott Bakerdbd960e2020-02-28 08:57:51 -080036 rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager"
khenaidoo106c61a2021-08-11 18:05:46 -040037 ofp "github.com/opencord/voltha-protos/v5/go/openflow_13"
38 openoltpb2 "github.com/opencord/voltha-protos/v5/go/openolt"
39 tp_pb "github.com/opencord/voltha-protos/v5/go/tech_profile"
kdarapu3248f9a2019-10-03 13:54:52 +053040)
41
Girish Gowdra9602eb42020-09-09 15:50:39 -070042var flowMgr []*OpenOltFlowMgr
kdarapub26b4502019-10-05 03:02:33 +053043
kdarapu3248f9a2019-10-03 13:54:52 +053044func init() {
Kent Hagermane6ff1012020-07-14 15:07:53 -040045 _, _ = log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
kdarapub26b4502019-10-05 03:02:33 +053046 flowMgr = newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +053047}
kdarapu3248f9a2019-10-03 13:54:52 +053048
Girish Gowdra9602eb42020-09-09 15:50:39 -070049func newMockFlowmgr() []*OpenOltFlowMgr {
kdarapu3248f9a2019-10-03 13:54:52 +053050 dh := newMockDeviceHandler()
51
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070052 // onuGemInfoMap := make([]rsrcMgr.onuGemInfoMap, NumPonPorts)
Girish Gowdra9602eb42020-09-09 15:50:39 -070053 var i uint32
kdarapu3248f9a2019-10-03 13:54:52 +053054
Girish Gowdra9602eb42020-09-09 15:50:39 -070055 for i = 0; i < NumPonPorts; i++ {
56 packetInGemPort := make(map[rsrcMgr.PacketInInfoKey]uint32)
57 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 +053058
Girish Gowdra9602eb42020-09-09 15:50:39 -070059 dh.flowMgr[i].packetInGemPort = packetInGemPort
Girish Gowdra4c3d4602021-07-22 16:33:37 -070060 dh.flowMgr[i].techprofile = mocks.MockTechProfile{}
61
Girish Gowdra9602eb42020-09-09 15:50:39 -070062 interface2mcastQeueuMap := make(map[uint32]*QueueInfoBrief)
63 interface2mcastQeueuMap[0] = &QueueInfoBrief{
64 gemPortID: 4000,
65 servicePriority: 3,
66 }
67 dh.flowMgr[i].grpMgr.interfaceToMcastQueueMap = interface2mcastQeueuMap
kdarapu3248f9a2019-10-03 13:54:52 +053068 }
Girish Gowdra9602eb42020-09-09 15:50:39 -070069 return dh.flowMgr
kdarapu3248f9a2019-10-03 13:54:52 +053070}
kdarapub26b4502019-10-05 03:02:33 +053071
kdarapu3248f9a2019-10-03 13:54:52 +053072func TestOpenOltFlowMgr_CreateSchedulerQueues(t *testing.T) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070073 tprofile := &tp_pb.TechProfileInstance{Name: "tp1", SubscriberIdentifier: "subscriber1",
Girish Gowdra54934262019-11-13 14:19:55 +053074 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070075 InstanceControl: &tp_pb.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"},
kdarapu3248f9a2019-10-03 13:54:52 +053076 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070077 tprofile.UsScheduler = &openoltpb2.SchedulerAttributes{}
78 tprofile.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
79 tprofile.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +053080
81 tprofile2 := tprofile
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070082 tprofile2.DsScheduler = &openoltpb2.SchedulerAttributes{}
83 tprofile2.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
84 tprofile2.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Gamze Abaka01174422021-03-10 06:55:27 +000085
kdarapu3248f9a2019-10-03 13:54:52 +053086 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +000087 name string
88 schedQueue schedQueue
89 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +053090 }{
91 // TODO: Add test cases.
Gamze Abaka01174422021-03-10 06:55:27 +000092 {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 1, Upstream)}, false},
93 {"CreateSchedulerQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 1, Downstream)}, false},
94 {"CreateSchedulerQueues-13", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 2, Upstream)}, false},
95 {"CreateSchedulerQueues-14", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 2, Downstream)}, false},
96 {"CreateSchedulerQueues-15", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 3, Upstream)}, false},
97 {"CreateSchedulerQueues-16", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 3, Downstream)}, false},
98 {"CreateSchedulerQueues-17", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 4, Upstream)}, false},
99 {"CreateSchedulerQueues-18", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 4, Downstream)}, false},
100 {"CreateSchedulerQueues-19", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 5, Upstream)}, false},
101 {"CreateSchedulerQueues-20", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 5, Downstream)}, false},
102
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700103 {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 0, Upstream)}, false},
104 {"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 +0000105 {"CreateSchedulerQueues-3", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, createFlowMetadata(tprofile, 2, Upstream)}, true},
106 {"CreateSchedulerQueues-4", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, createFlowMetadata(tprofile2, 2, Downstream)}, true},
107 {"CreateSchedulerQueues-5", schedQueue{tp_pb.Direction_UPSTREAM, 1, 2, 2, 64, 2, tprofile, 2, createFlowMetadata(tprofile, 3, Upstream)}, true},
108 {"CreateSchedulerQueues-6", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 2, 2, 65, 2, tprofile2, 2, createFlowMetadata(tprofile2, 3, Downstream)}, true},
109
kdarapu3248f9a2019-10-03 13:54:52 +0530110 //Negative testcases
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700111 {"CreateSchedulerQueues-7", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, &voltha.FlowMetadata{}}, false},
Girish Gowdra9602eb42020-09-09 15:50:39 -0700112 {"CreateSchedulerQueues-8", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 0, &voltha.FlowMetadata{}}, true},
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700113 {"CreateSchedulerQueues-9", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, &voltha.FlowMetadata{}}, false},
Girish Gowdra9602eb42020-09-09 15:50:39 -0700114 {"CreateSchedulerQueues-10", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, &voltha.FlowMetadata{}}, true},
115 {"CreateSchedulerQueues-11", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, &voltha.FlowMetadata{}}, true},
116 {"CreateSchedulerQueues-12", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, nil}, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530117 }
npujarec5762e2020-01-01 14:08:48 +0530118 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
119 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530120 for _, tt := range tests {
121 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700122 if err := flowMgr[tt.schedQueue.intfID].CreateSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530123 t.Errorf("OpenOltFlowMgr.CreateSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr)
124 }
125 })
126 }
127}
128
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700129func createFlowMetadata(techProfile *tp_pb.TechProfileInstance, tcontType int, direction string) *voltha.FlowMetadata {
130 var additionalBw openoltpb2.AdditionalBW
Gamze Abaka01174422021-03-10 06:55:27 +0000131 bands := make([]*ofp.OfpMeterBandHeader, 0)
132 switch tcontType {
133 case 1:
134 //tcont-type-1
135 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
136 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 -0700137 additionalBw = tp_pb.AdditionalBW_AdditionalBW_None
Gamze Abaka01174422021-03-10 06:55:27 +0000138 case 2:
139 //tcont-type-2
140 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 60000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
141 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 -0700142 additionalBw = tp_pb.AdditionalBW_AdditionalBW_None
Gamze Abaka01174422021-03-10 06:55:27 +0000143 case 3:
144 //tcont-type-3
145 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
146 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 -0700147 additionalBw = tp_pb.AdditionalBW_AdditionalBW_NA
Gamze Abaka01174422021-03-10 06:55:27 +0000148 case 4:
149 //tcont-type-4
150 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 -0700151 additionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
Gamze Abaka01174422021-03-10 06:55:27 +0000152 case 5:
153 //tcont-type-5
154 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
155 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
156 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 -0700157 additionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
Gamze Abaka01174422021-03-10 06:55:27 +0000158 default:
159 // do nothing, we will return meter config with no meter bands
160 }
161
162 if direction == Downstream {
163 techProfile.DsScheduler.AdditionalBw = additionalBw
164 } else {
165 techProfile.UsScheduler.AdditionalBw = additionalBw
166 }
167
168 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
169 return &voltha.FlowMetadata{
170 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}}
171}
172
kdarapu3248f9a2019-10-03 13:54:52 +0530173func TestOpenOltFlowMgr_RemoveSchedulerQueues(t *testing.T) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700174 tprofile := &tp_pb.TechProfileInstance{Name: "tp1", SubscriberIdentifier: "subscriber1",
Girish Gowdra54934262019-11-13 14:19:55 +0530175 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700176 InstanceControl: &tp_pb.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"},
kdarapu3248f9a2019-10-03 13:54:52 +0530177 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700178 tprofile.UsScheduler = &openoltpb2.SchedulerAttributes{}
179 tprofile.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
180 tprofile.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
181 tprofile.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +0530182
183 tprofile2 := tprofile
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700184 tprofile2.DsScheduler = &openoltpb2.SchedulerAttributes{}
185 tprofile2.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
186 tprofile2.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
187 tprofile2.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +0530188 //defTprofile := &tp.DefaultTechProfile{}
kdarapu3248f9a2019-10-03 13:54:52 +0530189 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +0000190 name string
191 schedQueue schedQueue
192 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +0530193 }{
194 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000195 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 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 // negative test cases
Gamze Abakafee36392019-10-03 11:17:24 +0000198 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
199 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530200 }
npujarec5762e2020-01-01 14:08:48 +0530201 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
202 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530203 for _, tt := range tests {
204 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700205 if err := flowMgr[tt.schedQueue.intfID].RemoveSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530206 t.Errorf("OpenOltFlowMgr.RemoveSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr)
207 }
208 })
209 }
kdarapub26b4502019-10-05 03:02:33 +0530210
kdarapu3248f9a2019-10-03 13:54:52 +0530211}
212
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700213func TestOpenOltFlowMgr_createTcontGemports(t *testing.T) {
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700214 bands := make([]*ofp.OfpMeterBandHeader, 2)
215 bands[0] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 1000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
216 bands[1] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 2000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
217 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
218 flowmetadata := &voltha.FlowMetadata{
219 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
220 }
221 type args struct {
222 intfID uint32
223 onuID uint32
224 uniID uint32
225 uni string
226 uniPort uint32
227 TpID uint32
228 UsMeterID uint32
229 DsMeterID uint32
230 flowMetadata *voltha.FlowMetadata
231 }
232 tests := []struct {
233 name string
234 args args
235 }{
236 {"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 -0700237 }
238 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
239 defer cancel()
240 for _, tt := range tests {
241 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700242 _, _, 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 -0700243 switch tpInst := tpInst.(type) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700244 case *tp_pb.TechProfileInstance:
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700245 if tt.args.TpID != 64 {
246 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
247 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700248 case *tp_pb.EponTechProfileInstance:
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700249 if tt.args.TpID != 65 {
250 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
251 }
252 default:
253 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
254 }
255 })
256 }
257}
258
kdarapu3248f9a2019-10-03 13:54:52 +0530259func TestOpenOltFlowMgr_RemoveFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000260 ctx := context.Background()
Neha Sharma96b7bf22020-06-15 10:37:32 +0000261 logger.Debug(ctx, "Info Warning Error: Starting RemoveFlow() test")
kdarapu3248f9a2019-10-03 13:54:52 +0530262 fa := &fu.FlowArgs{
263 MatchFields: []*ofp.OfpOxmOfbField{
264 fu.InPort(2),
265 fu.Metadata_ofp(2),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300266 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapu3248f9a2019-10-03 13:54:52 +0530267 },
268 Actions: []*ofp.OfpAction{
269 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
270 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
271 fu.Output(1),
272 },
273 }
divyadesaid26f6b12020-03-19 06:30:28 +0000274 ofpstats, _ := fu.MkFlowStat(fa)
kdarapub26b4502019-10-05 03:02:33 +0530275 ofpstats.Cookie = ofpstats.Id
kdarapub26b4502019-10-05 03:02:33 +0530276 lldpFa := &fu.FlowArgs{
277 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
278 MatchFields: []*ofp.OfpOxmOfbField{
279 fu.InPort(1),
280 fu.EthType(0x88CC),
281 fu.TunnelId(536870912),
282 },
283 Actions: []*ofp.OfpAction{
284 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
285 },
286 }
divyadesaid26f6b12020-03-19 06:30:28 +0000287 lldpofpstats, _ := fu.MkFlowStat(lldpFa)
kdarapub26b4502019-10-05 03:02:33 +0530288 //lldpofpstats.Cookie = lldpofpstats.Id
289
290 dhcpFa := &fu.FlowArgs{
291 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
292 MatchFields: []*ofp.OfpOxmOfbField{
293 fu.InPort(1),
294 fu.UdpSrc(67),
295 //fu.TunnelId(536870912),
296 fu.IpProto(17),
297 },
298 Actions: []*ofp.OfpAction{
299 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
300 },
301 }
divyadesaid26f6b12020-03-19 06:30:28 +0000302 dhcpofpstats, _ := fu.MkFlowStat(dhcpFa)
kdarapub26b4502019-10-05 03:02:33 +0530303 //dhcpofpstats.Cookie = dhcpofpstats.Id
Esin Karamanccb714b2019-11-29 15:02:06 +0000304
305 //multicast flow
306 multicastFa := &fu.FlowArgs{
307 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800308 fu.InPort(1048576),
Esin Karamanccb714b2019-11-29 15:02:06 +0000309 fu.VlanVid(660), //vlan
310 fu.Metadata_ofp(uint64(66)), //inner vlan
311 fu.EthType(0x800), //ipv4
312 fu.Ipv4Dst(3809869825), //227.22.0.1
313 },
314 Actions: []*ofp.OfpAction{
315 fu.Group(1),
316 },
317 }
divyadesaid26f6b12020-03-19 06:30:28 +0000318 multicastOfpStats, _ := fu.MkFlowStat(multicastFa)
Esin Karamanccb714b2019-11-29 15:02:06 +0000319 multicastOfpStats.Id = 1
320
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300321 pppoedFa := &fu.FlowArgs{
322 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
323 MatchFields: []*ofp.OfpOxmOfbField{
324 fu.InPort(1),
325 fu.EthType(0x8863),
326 fu.TunnelId(536870912),
327 },
328 Actions: []*ofp.OfpAction{
329 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
330 },
331 }
332 pppoedOfpStats, _ := fu.MkFlowStat(pppoedFa)
333
kdarapu3248f9a2019-10-03 13:54:52 +0530334 type args struct {
335 flow *ofp.OfpFlowStats
336 }
337 tests := []struct {
338 name string
339 args args
340 }{
341 // TODO: Add test cases.
342 {"RemoveFlow", args{flow: ofpstats}},
kdarapub26b4502019-10-05 03:02:33 +0530343 {"RemoveFlow", args{flow: lldpofpstats}},
344 {"RemoveFlow", args{flow: dhcpofpstats}},
Esin Karamanccb714b2019-11-29 15:02:06 +0000345 {"RemoveFlow", args{flow: multicastOfpStats}},
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300346 {"RemoveFlow", args{flow: pppoedOfpStats}},
kdarapu3248f9a2019-10-03 13:54:52 +0530347 }
npujarec5762e2020-01-01 14:08:48 +0530348 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
349 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530350 for _, tt := range tests {
351 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700352 if err := flowMgr[0].RemoveFlow(ctx, tt.args.flow); err != nil {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400353 logger.Warn(ctx, err)
354 }
kdarapu3248f9a2019-10-03 13:54:52 +0530355 })
356 }
kdarapub26b4502019-10-05 03:02:33 +0530357 // t.Error("=====")
kdarapu3248f9a2019-10-03 13:54:52 +0530358}
359
360func TestOpenOltFlowMgr_AddFlow(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530361 kw := make(map[string]uint64)
362 kw["table_id"] = 1
363 kw["meter_id"] = 1
kdarapub26b4502019-10-05 03:02:33 +0530364 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
365
366 // Upstream flow
kdarapu3248f9a2019-10-03 13:54:52 +0530367 fa := &fu.FlowArgs{
368 MatchFields: []*ofp.OfpOxmOfbField{
kdarapub26b4502019-10-05 03:02:33 +0530369 fu.InPort(536870912),
370 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300371 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530372 },
373 Actions: []*ofp.OfpAction{
374 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
375 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800376 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530377 fu.PushVlan(0x8100),
378 },
379 KV: kw,
380 }
381
382 // Downstream flow
383 fa3 := &fu.FlowArgs{
384 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800385 fu.InPort(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530386 fu.Metadata_ofp(1),
387 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
388 },
389 Actions: []*ofp.OfpAction{
390 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
391 //fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
392 fu.PopVlan(),
393 fu.Output(536870912),
394 },
395 KV: kw,
396 }
397
398 fa2 := &fu.FlowArgs{
399 MatchFields: []*ofp.OfpOxmOfbField{
kdarapu3248f9a2019-10-03 13:54:52 +0530400 fu.InPort(1000),
401 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300402 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapu3248f9a2019-10-03 13:54:52 +0530403 },
404 Actions: []*ofp.OfpAction{
405 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
406 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
407 fu.Output(65533),
408 },
409 KV: kw,
410 }
411
kdarapub26b4502019-10-05 03:02:33 +0530412 // TODO Add LLDP flow
413 // TODO Add DHCP flow
414
415 // Flows for negative scenarios
416 // Failure in formulateActionInfoFromFlow()
417 fa4 := &fu.FlowArgs{
418 MatchFields: []*ofp.OfpOxmOfbField{
419 fu.InPort(1000),
420 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300421 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530422 },
423 Actions: []*ofp.OfpAction{
424 fu.Experimenter(257, []byte{1, 2, 3, 4}),
425 },
426 KV: kw,
427 }
428
429 // Invalid Output
430 fa5 := &fu.FlowArgs{
431 MatchFields: []*ofp.OfpOxmOfbField{
432 fu.InPort(1000),
433 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300434 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530435 },
436 Actions: []*ofp.OfpAction{
437 fu.Output(0),
438 },
439 KV: kw,
440 }
441
442 // Tech-Profile-ID update (not supported)
443 kw6 := make(map[string]uint64)
444 kw6["table_id"] = 1
445 kw6["meter_id"] = 1
446 kw6["write_metadata"] = 0x4100000000 // TpID Other than the stored one
447 fa6 := &fu.FlowArgs{
448 MatchFields: []*ofp.OfpOxmOfbField{
449 fu.InPort(536870912),
450 fu.TunnelId(16),
451 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300452 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530453 },
454 Actions: []*ofp.OfpAction{
455 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
456 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
457 fu.Output(65535),
458 },
459 KV: kw6,
460 }
461
462 lldpFa := &fu.FlowArgs{
463 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
464 MatchFields: []*ofp.OfpOxmOfbField{
465 fu.InPort(1),
466 fu.EthType(0x88CC),
467 fu.TunnelId(536870912),
468 },
469 Actions: []*ofp.OfpAction{
470 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
471 },
472 }
473
474 dhcpFa := &fu.FlowArgs{
475 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
476 MatchFields: []*ofp.OfpOxmOfbField{
477 fu.InPort(1),
478 fu.UdpSrc(67),
479 //fu.TunnelId(536870912),
480 fu.IpProto(17),
481 },
482 Actions: []*ofp.OfpAction{
483 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
484 },
485 }
486 igmpFa := &fu.FlowArgs{
487 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
488 MatchFields: []*ofp.OfpOxmOfbField{
489 fu.InPort(1),
490 fu.UdpSrc(67),
491 //fu.TunnelId(536870912),
492 fu.IpProto(2),
493 },
494 Actions: []*ofp.OfpAction{
495 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
496 },
497 }
498
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300499 pppoedFa := &fu.FlowArgs{
500 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
501 MatchFields: []*ofp.OfpOxmOfbField{
502 fu.InPort(1),
503 fu.EthType(0x8863),
504 fu.TunnelId(536870912),
505 },
506 Actions: []*ofp.OfpAction{
507 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
508 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
509 },
510 }
511
kdarapub26b4502019-10-05 03:02:33 +0530512 fa9 := &fu.FlowArgs{
513 MatchFields: []*ofp.OfpOxmOfbField{
514 fu.InPort(536870912),
515 fu.TunnelId(16),
516 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300517 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530518 fu.VlanPcp(1000),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800519 fu.UdpDst(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530520 fu.UdpSrc(536870912),
521 fu.Ipv4Dst(65535),
522 fu.Ipv4Src(536870912),
523 },
524 Actions: []*ofp.OfpAction{
525 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
526 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
527 fu.Output(65535),
528 },
529 KV: kw6,
530 }
531
532 fa10 := &fu.FlowArgs{
533 MatchFields: []*ofp.OfpOxmOfbField{
534 fu.InPort(65533),
535 // fu.TunnelId(16),
536 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300537 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530538 fu.VlanPcp(1000),
539 fu.UdpDst(65535),
540 fu.UdpSrc(536870912),
541 fu.Ipv4Dst(65535),
542 fu.Ipv4Src(536870912),
543 },
544 Actions: []*ofp.OfpAction{
545 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
546 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
547 fu.Output(65535),
548 },
549 KV: kw6,
550 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000551 //multicast flow
552 fa11 := &fu.FlowArgs{
553 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800554 fu.InPort(1048576),
Esin Karamanccb714b2019-11-29 15:02:06 +0000555 fu.VlanVid(660), //vlan
556 fu.Metadata_ofp(uint64(66)), //inner vlan
557 fu.EthType(0x800), //ipv4
558 fu.Ipv4Dst(3809869825), //227.22.0.1
559 },
560 Actions: []*ofp.OfpAction{
561 fu.Group(1),
562 },
563 KV: kw6,
564 }
divyadesaid26f6b12020-03-19 06:30:28 +0000565 ofpstats, _ := fu.MkFlowStat(fa)
566 ofpstats2, _ := fu.MkFlowStat(fa2)
567 ofpstats3, _ := fu.MkFlowStat(fa3)
568 ofpstats4, _ := fu.MkFlowStat(fa4)
569 ofpstats5, _ := fu.MkFlowStat(fa5)
570 ofpstats6, _ := fu.MkFlowStat(fa6)
571 ofpstats7, _ := fu.MkFlowStat(lldpFa)
572 ofpstats8, _ := fu.MkFlowStat(dhcpFa)
573 ofpstats9, _ := fu.MkFlowStat(fa9)
574 ofpstats10, _ := fu.MkFlowStat(fa10)
575 igmpstats, _ := fu.MkFlowStat(igmpFa)
576 ofpstats11, _ := fu.MkFlowStat(fa11)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300577 pppoedstats, _ := fu.MkFlowStat(pppoedFa)
kdarapub26b4502019-10-05 03:02:33 +0530578
Gamze Abakafee36392019-10-03 11:17:24 +0000579 fmt.Println(ofpstats6, ofpstats9, ofpstats10)
580
kdarapu3248f9a2019-10-03 13:54:52 +0530581 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1}
kdarapu3248f9a2019-10-03 13:54:52 +0530582 flowMetadata := &voltha.FlowMetadata{
583 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
584 }
585 type args struct {
586 flow *ofp.OfpFlowStats
587 flowMetadata *voltha.FlowMetadata
588 }
589 tests := []struct {
590 name string
591 args args
592 }{
593 // TODO: Add test cases.
594 {"AddFlow", args{flow: ofpstats, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530595 {"AddFlow", args{flow: ofpstats2, flowMetadata: flowMetadata}},
596 {"AddFlow", args{flow: ofpstats3, flowMetadata: flowMetadata}},
597 {"AddFlow", args{flow: ofpstats4, flowMetadata: flowMetadata}},
598 {"AddFlow", args{flow: ofpstats5, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000599 //{"AddFlow", args{flow: ofpstats6, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530600 {"AddFlow", args{flow: ofpstats7, flowMetadata: flowMetadata}},
601 {"AddFlow", args{flow: ofpstats8, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000602 //{"AddFlow", args{flow: ofpstats9, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530603 {"AddFlow", args{flow: igmpstats, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000604 //{"AddFlow", args{flow: ofpstats10, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530605 //ofpstats10
Esin Karamanccb714b2019-11-29 15:02:06 +0000606 {"AddFlow", args{flow: ofpstats11, flowMetadata: flowMetadata}},
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300607 {"AddFlow", args{flow: pppoedstats, flowMetadata: flowMetadata}},
kdarapu3248f9a2019-10-03 13:54:52 +0530608 }
npujarec5762e2020-01-01 14:08:48 +0530609 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
610 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530611 for _, tt := range tests {
612 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700613 _ = flowMgr[0].AddFlow(ctx, tt.args.flow, tt.args.flowMetadata)
Kent Hagermane6ff1012020-07-14 15:07:53 -0400614 // TODO: actually verify test cases
kdarapu3248f9a2019-10-03 13:54:52 +0530615 })
616 }
617}
618
619func TestOpenOltFlowMgr_UpdateOnuInfo(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530620 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
621 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530622
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700623 wg := sync.WaitGroup{}
624
Girish Gowdra9602eb42020-09-09 15:50:39 -0700625 intfCount := NumPonPorts
626 onuCount := OnuIDEnd - OnuIDStart + 1
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700627
628 for i := 0; i < intfCount; i++ {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700629 for j := 1; j <= onuCount; j++ {
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700630 wg.Add(1)
631 go func(i uint32, j uint32) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400632 // TODO: actually verify success
Girish Gowdra197acc12021-08-16 10:59:45 -0700633 _ = flowMgr[i].AddOnuInfoToFlowMgrCacheAndKvStore(ctx, i, i, fmt.Sprintf("onu-%d", i))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700634 wg.Done()
635 }(uint32(i), uint32(j))
636 }
637
638 }
639
640 wg.Wait()
641}
642
643func TestOpenOltFlowMgr_addGemPortToOnuInfoMap(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700644 intfNum := NumPonPorts
645 onuNum := OnuIDEnd - OnuIDStart + 1
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700646
647 // clean the flowMgr
Girish Gowdra9602eb42020-09-09 15:50:39 -0700648 for i := 0; i < intfNum; i++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700649 flowMgr[i].onuGemInfoMap = make(map[uint32]*rsrcMgr.OnuGemInfo)
Girish Gowdra9602eb42020-09-09 15:50:39 -0700650 }
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700651
652 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
653 defer cancel()
654
655 // Create OnuInfo
656 for i := 0; i < intfNum; i++ {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700657 for o := 1; o <= onuNum; o++ {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400658 // TODO: actually verify success
Girish Gowdra197acc12021-08-16 10:59:45 -0700659 _ = flowMgr[i].AddOnuInfoToFlowMgrCacheAndKvStore(ctx, uint32(i), uint32(o), fmt.Sprintf("i%do%d", i, o-1))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700660 }
661 }
662
663 // Add gemPorts to OnuInfo in parallel threads
664 wg := sync.WaitGroup{}
Girish Gowdra9602eb42020-09-09 15:50:39 -0700665 for o := 1; o <= onuNum; o++ {
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700666 for i := 0; i < intfNum; i++ {
667 wg.Add(1)
668 go func(intfId uint32, onuId uint32) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700669 gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", intfId, onuId-1))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700670
Girish Gowdra9602eb42020-09-09 15:50:39 -0700671 flowMgr[intfId].addGemPortToOnuInfoMap(ctx, intfId, onuId, uint32(gemID))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700672 wg.Done()
673 }(uint32(i), uint32(o))
674 }
675 }
676
677 wg.Wait()
678
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700679 // check that each entry of onuGemInfoMap has the correct number of ONUs
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700680 for i := 0; i < intfNum; i++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700681 lenofOnu := len(flowMgr[i].onuGemInfoMap)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700682 if onuNum != lenofOnu {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700683 t.Errorf("onuGemInfoMap length is not as expected len = %d, want %d", lenofOnu, onuNum)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700684 }
685
Girish Gowdra9602eb42020-09-09 15:50:39 -0700686 for o := 1; o <= onuNum; o++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700687 lenOfGemPorts := len(flowMgr[i].onuGemInfoMap[uint32(o)].GemPorts)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700688 // check that each onuEntry has 1 gemPort
689 if lenOfGemPorts != 1 {
690 t.Errorf("Expected 1 GemPort per ONU, found %d", lenOfGemPorts)
691 }
692
693 // check that the value of the gemport is correct
Girish Gowdra9602eb42020-09-09 15:50:39 -0700694 gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", i, o-1))
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700695 currentValue := flowMgr[i].onuGemInfoMap[uint32(o)].GemPorts[0]
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700696 if uint32(gemID) != currentValue {
697 t.Errorf("Expected GemPort value to be %d, found %d", gemID, currentValue)
698 }
699 }
kdarapu3248f9a2019-10-03 13:54:52 +0530700 }
701}
702
serkant.uluderya96af4932020-02-20 16:58:48 -0800703func TestOpenOltFlowMgr_deleteGemPortFromLocalCache(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700704 // Create fresh flowMgr instance
705 flowMgr = newMockFlowmgr()
serkant.uluderya96af4932020-02-20 16:58:48 -0800706 type args struct {
707 intfID uint32
708 onuID uint32
709 gemPortIDs []uint32
710 gemPortIDsToBeDeleted []uint32
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700711 gemPortIDsRemaining []uint32
serkant.uluderya96af4932020-02-20 16:58:48 -0800712 serialNum string
713 finalLength int
714 }
715 tests := []struct {
716 name string
717 args args
718 }{
719 // Add/Delete single gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700720 {"DeleteGemPortFromLocalCache1", args{0, 1, []uint32{1}, []uint32{1}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800721 // Delete all gemports
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700722 {"DeleteGemPortFromLocalCache2", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{1, 2, 3, 4}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800723 // Try to delete when there is no gem port
Girish Gowdra197acc12021-08-16 10:59:45 -0700724 {"DeleteGemPortFromLocalCache3", args{0, 1, []uint32{}, []uint32{1, 2}, nil, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800725 // Try to delete non-existent gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700726 {"DeleteGemPortFromLocalCache4", args{0, 1, []uint32{1}, []uint32{2}, []uint32{1}, "onu1", 1}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800727 // Try to delete two of the gem ports
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700728 {"DeleteGemPortFromLocalCache5", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{2, 4}, []uint32{1, 3}, "onu1", 2}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800729 }
730 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
731 defer cancel()
732 for _, tt := range tests {
733 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra197acc12021-08-16 10:59:45 -0700734 if err := flowMgr[tt.args.intfID].RemoveOnuInfoFromFlowMgrCacheAndKvStore(ctx, tt.args.intfID, tt.args.onuID); err != nil {
735 t.Errorf("failed to remove onu")
736 }
737 if err := flowMgr[tt.args.intfID].AddOnuInfoToFlowMgrCacheAndKvStore(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum); err != nil {
738 t.Errorf("failed to add onu")
739 }
serkant.uluderya96af4932020-02-20 16:58:48 -0800740 for _, gemPort := range tt.args.gemPortIDs {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700741 flowMgr[tt.args.intfID].addGemPortToOnuInfoMap(ctx, tt.args.intfID, tt.args.onuID, gemPort)
serkant.uluderya96af4932020-02-20 16:58:48 -0800742 }
743 for _, gemPortDeleted := range tt.args.gemPortIDsToBeDeleted {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700744 flowMgr[tt.args.intfID].deleteGemPortFromLocalCache(ctx, tt.args.intfID, tt.args.onuID, gemPortDeleted)
serkant.uluderya96af4932020-02-20 16:58:48 -0800745 }
Girish Gowdra197acc12021-08-16 10:59:45 -0700746 lenofGemPorts := 0
747 gP, ok := flowMgr[tt.args.intfID].onuGemInfoMap[tt.args.onuID]
748 if ok {
749 lenofGemPorts = len(gP.GemPorts)
750 }
serkant.uluderya96af4932020-02-20 16:58:48 -0800751 if lenofGemPorts != tt.args.finalLength {
752 t.Errorf("GemPorts length is not as expected len = %d, want %d", lenofGemPorts, tt.args.finalLength)
753 }
Girish Gowdra197acc12021-08-16 10:59:45 -0700754 gP, ok = flowMgr[tt.args.intfID].onuGemInfoMap[tt.args.onuID]
755 var gemPorts []uint32
756 if ok {
757 gemPorts = gP.GemPorts
758 }
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700759 if !reflect.DeepEqual(tt.args.gemPortIDsRemaining, gemPorts) {
760 t.Errorf("GemPorts are not as expected = %v, want %v", gemPorts, tt.args.gemPortIDsRemaining)
761 }
serkant.uluderya96af4932020-02-20 16:58:48 -0800762
763 })
764 }
765}
766
kdarapu3248f9a2019-10-03 13:54:52 +0530767func TestOpenOltFlowMgr_GetLogicalPortFromPacketIn(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530768 type args struct {
769 packetIn *openoltpb2.PacketIndication
770 }
771 tests := []struct {
772 name string
773 args args
774 want uint32
775 wantErr bool
776 }{
777 // TODO: Add test cases.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700778 {"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},
779 {"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 +0530780 // Negative Test cases.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700781 {"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},
782 {"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 +0530783 }
npujarec5762e2020-01-01 14:08:48 +0530784 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
785 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530786 for _, tt := range tests {
787 t.Run(tt.name, func(t *testing.T) {
788
Girish Gowdra9602eb42020-09-09 15:50:39 -0700789 got, err := flowMgr[tt.args.packetIn.IntfId].GetLogicalPortFromPacketIn(ctx, tt.args.packetIn)
kdarapu3248f9a2019-10-03 13:54:52 +0530790 if (err != nil) != tt.wantErr {
791 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() error = %v, wantErr %v", err, tt.wantErr)
792 return
793 }
794 if got != tt.want {
795 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() = %v, want %v", got, tt.want)
796 }
797 })
798 }
799}
800
801func TestOpenOltFlowMgr_GetPacketOutGemPortID(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700802 // Create fresh flowMgr instance
803 flowMgr = newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530804
Esin Karaman7fb80c22020-07-16 14:23:33 +0000805 //untagged packet in hex string
806 untaggedStr := "01005e000002000000000001080046c00020000040000102fa140a000001e00000029404000017000705e10000fa"
807 untagged, err := hex.DecodeString(untaggedStr)
808 if err != nil {
809 t.Error("Unable to parse hex string", err)
810 panic(err)
811 }
Girish Gowdra9602eb42020-09-09 15:50:39 -0700812 //single-tagged packet in hex string. vlanID.pbit: 1.1
813 singleTaggedStr := "01005e0000010025ba48172481002001080046c0002000004000010257deab140023e0000001940400001164ee9b0000000000000000000000000000"
Esin Karaman7fb80c22020-07-16 14:23:33 +0000814 singleTagged, err := hex.DecodeString(singleTaggedStr)
815 if err != nil {
816 t.Error("Unable to parse hex string", err)
817 panic(err)
818 }
Girish Gowdra9602eb42020-09-09 15:50:39 -0700819 //double-tagged packet in hex string. vlanID.pbit: 210.0-0.0
820 doubleTaggedStr := "01005e000016deadbeefba118100021081000000080046000028000000000102c5b87f000001e0000016940400002200f8030000000104000000e10000fa"
Esin Karaman7fb80c22020-07-16 14:23:33 +0000821 doubleTagged, err := hex.DecodeString(doubleTaggedStr)
822 if err != nil {
823 t.Error("Unable to parse hex string", err)
824 panic(err)
825 }
826
kdarapu3248f9a2019-10-03 13:54:52 +0530827 type args struct {
828 intfID uint32
829 onuID uint32
830 portNum uint32
Esin Karaman7fb80c22020-07-16 14:23:33 +0000831 packet []byte
kdarapu3248f9a2019-10-03 13:54:52 +0530832 }
833 tests := []struct {
834 name string
835 args args
836 want uint32
837 wantErr bool
838 }{
839 // TODO: Add test cases.
Girish Gowdra9602eb42020-09-09 15:50:39 -0700840 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: untagged}, 1, false},
841 {"GetPacketOutGemPortID", args{intfID: 1, onuID: 2, portNum: 2, packet: singleTagged}, 2, false},
842 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: doubleTagged}, 1, false},
843 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 10, portNum: 10, packet: untagged}, 2, true},
844 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 3, packet: []byte{}}, 3, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530845 }
Esin Karaman7fb80c22020-07-16 14:23:33 +0000846
npujarec5762e2020-01-01 14:08:48 +0530847 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
848 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530849 for _, tt := range tests {
850 t.Run(tt.name, func(t *testing.T) {
851
Girish Gowdra9602eb42020-09-09 15:50:39 -0700852 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 +0000853 if tt.wantErr {
854 if err == nil {
855 //error expected but got value
856 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, wantErr %v", got, tt.wantErr)
857 }
858 } else {
859 if err != nil {
860 //error is not expected but got error
861 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() error = %v, wantErr %v", err, tt.wantErr)
862 return
863 }
864 if got != tt.want {
865 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, want %v", got, tt.want)
866 }
kdarapu3248f9a2019-10-03 13:54:52 +0530867 }
kdarapu3248f9a2019-10-03 13:54:52 +0530868 })
869 }
870}
871
872func TestOpenOltFlowMgr_DeleteTechProfileInstance(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530873 type args struct {
874 intfID uint32
875 onuID uint32
876 uniID uint32
877 sn string
Gamze Abakafee36392019-10-03 11:17:24 +0000878 tpID uint32
kdarapu3248f9a2019-10-03 13:54:52 +0530879 }
880 tests := []struct {
881 name string
882 args args
883 wantErr bool
884 }{
885 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000886 {"DeleteTechProfileInstance", args{intfID: 0, onuID: 1, uniID: 1, sn: "", tpID: 64}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530887 }
npujarec5762e2020-01-01 14:08:48 +0530888 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
889 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530890 for _, tt := range tests {
891 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700892 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 +0530893 t.Errorf("OpenOltFlowMgr.DeleteTechProfileInstance() error = %v, wantErr %v", err, tt.wantErr)
894 }
895 })
896 }
897}
kdarapub26b4502019-10-05 03:02:33 +0530898
899func TestOpenOltFlowMgr_checkAndAddFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000900 ctx := context.Background()
kdarapub26b4502019-10-05 03:02:33 +0530901 kw := make(map[string]uint64)
902 kw["table_id"] = 1
903 kw["meter_id"] = 1
904 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
905
906 // Upstream flow
907 fa := &fu.FlowArgs{
908 MatchFields: []*ofp.OfpOxmOfbField{
909 fu.InPort(536870912),
910 fu.Metadata_ofp(1),
911 fu.IpProto(17), // dhcp
Gamze Abakafee36392019-10-03 11:17:24 +0000912 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300913 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530914 },
915 Actions: []*ofp.OfpAction{
916 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
917 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800918 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530919 fu.PushVlan(0x8100),
920 },
921 KV: kw,
922 }
923
924 // EAPOL
925 fa2 := &fu.FlowArgs{
926 MatchFields: []*ofp.OfpOxmOfbField{
927 fu.InPort(536870912),
928 fu.Metadata_ofp(1),
929 fu.EthType(0x888E),
930 fu.VlanPcp(1),
931 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
932 },
933 Actions: []*ofp.OfpAction{
934 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
935 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800936 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530937 fu.PushVlan(0x8100),
938 },
939 KV: kw,
940 }
941
942 // HSIA
943 fa3 := &fu.FlowArgs{
944 MatchFields: []*ofp.OfpOxmOfbField{
945 fu.InPort(536870912),
946 fu.Metadata_ofp(1),
947 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300948 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530949 },
950 Actions: []*ofp.OfpAction{
951 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300952 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800953 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530954 fu.PushVlan(0x8100),
955 },
956 KV: kw,
957 }
958
959 fa4 := &fu.FlowArgs{
960 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800961 fu.InPort(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530962 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300963 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530964 fu.VlanPcp(1),
965 },
966 Actions: []*ofp.OfpAction{
967 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300968 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
kdarapub26b4502019-10-05 03:02:33 +0530969 fu.Output(536870912),
970 fu.PopVlan(),
971 },
972 KV: kw,
973 }
974
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300975 // PPPOED
976 pppoedFA := &fu.FlowArgs{
977 MatchFields: []*ofp.OfpOxmOfbField{
978 fu.InPort(536870912),
979 fu.Metadata_ofp(1),
980 fu.EthType(0x8863),
981 fu.VlanPcp(1),
982 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
983 },
984 Actions: []*ofp.OfpAction{
985 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
986 fu.Output(1048576),
987 fu.PushVlan(0x8100),
988 },
989 KV: kw,
990 }
991
kdarapub26b4502019-10-05 03:02:33 +0530992 classifierInfo := make(map[string]interface{})
993 actionInfo := make(map[string]interface{})
994 classifierInfo2 := make(map[string]interface{})
995 actionInfo2 := make(map[string]interface{})
996 classifierInfo3 := make(map[string]interface{})
997 actionInfo3 := make(map[string]interface{})
998 classifierInfo4 := make(map[string]interface{})
999 actionInfo4 := make(map[string]interface{})
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001000 classifierInfo5 := make(map[string]interface{})
1001 actionInfo5 := make(map[string]interface{})
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001002 flow, _ := fu.MkFlowStat(fa)
1003 flow2, _ := fu.MkFlowStat(fa2)
1004 flow3, _ := fu.MkFlowStat(fa3)
1005 flow4, _ := fu.MkFlowStat(fa4)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001006 flow5, _ := fu.MkFlowStat(pppoedFA)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001007 formulateClassifierInfoFromFlow(ctx, classifierInfo, flow)
1008 formulateClassifierInfoFromFlow(ctx, classifierInfo2, flow2)
1009 formulateClassifierInfoFromFlow(ctx, classifierInfo3, flow3)
1010 formulateClassifierInfoFromFlow(ctx, classifierInfo4, flow4)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001011 formulateClassifierInfoFromFlow(ctx, classifierInfo5, flow5)
kdarapub26b4502019-10-05 03:02:33 +05301012
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001013 err := formulateActionInfoFromFlow(ctx, actionInfo, classifierInfo, flow)
kdarapub26b4502019-10-05 03:02:33 +05301014 if err != nil {
1015 // Error logging is already done in the called function
1016 // So just return in case of error
1017 return
1018 }
1019
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001020 err = formulateActionInfoFromFlow(ctx, actionInfo2, classifierInfo2, flow2)
kdarapub26b4502019-10-05 03:02:33 +05301021 if err != nil {
1022 // Error logging is already done in the called function
1023 // So just return in case of error
1024 return
1025 }
1026
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001027 err = formulateActionInfoFromFlow(ctx, actionInfo3, classifierInfo3, flow3)
kdarapub26b4502019-10-05 03:02:33 +05301028 if err != nil {
1029 // Error logging is already done in the called function
1030 // So just return in case of error
1031 return
1032 }
1033
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001034 err = formulateActionInfoFromFlow(ctx, actionInfo4, classifierInfo4, flow4)
kdarapub26b4502019-10-05 03:02:33 +05301035 if err != nil {
1036 // Error logging is already done in the called function
1037 // So just return in case of error
1038 return
1039 }
1040
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001041 err = formulateActionInfoFromFlow(ctx, actionInfo5, classifierInfo5, flow5)
1042 if err != nil {
1043 // Error logging is already done in the called function
1044 // So just return in case of error
1045 return
1046 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001047 /*
1048 usGemList := make([]*tp_pb.GemPortAttributes, 4)
1049 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1050 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1051 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1052 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1053 dsGemList := make([]*tp_pb.GemPortAttributes, 4)
1054 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1055 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1056 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1057 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1058 */
1059 TpInst := &tp_pb.TechProfileInstance{
kdarapub26b4502019-10-05 03:02:33 +05301060 Name: "Test-Tech-Profile",
1061 SubscriberIdentifier: "257",
1062 ProfileType: "Mock",
1063 Version: 1,
1064 NumGemPorts: 4,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001065 InstanceControl: &tp_pb.InstanceControl{
kdarapub26b4502019-10-05 03:02:33 +05301066 Onu: "1",
1067 Uni: "16",
1068 },
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001069 UsScheduler: &openoltpb2.SchedulerAttributes{},
1070 DsScheduler: &openoltpb2.SchedulerAttributes{},
kdarapub26b4502019-10-05 03:02:33 +05301071 }
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001072 TpInst.UsScheduler.Priority = 1
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001073 TpInst.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
1074 TpInst.UsScheduler.AllocId = 1
1075 TpInst.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
1076 TpInst.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001077 TpInst.UsScheduler.Weight = 4
1078
1079 TpInst.DsScheduler.Priority = 1
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001080 TpInst.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
1081 TpInst.DsScheduler.AllocId = 1
1082 TpInst.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
1083 TpInst.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001084 TpInst.DsScheduler.Weight = 4
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001085 TpInst.UpstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
1086 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
1087 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
1088 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
1089 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001090
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001091 TpInst.DownstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
1092 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
1093 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
1094 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
1095 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
kdarapub26b4502019-10-05 03:02:33 +05301096
kdarapub26b4502019-10-05 03:02:33 +05301097 type args struct {
1098 args map[string]uint32
1099 classifierInfo map[string]interface{}
1100 actionInfo map[string]interface{}
1101 flow *ofp.OfpFlowStats
1102 gemPort uint32
1103 intfID uint32
1104 onuID uint32
1105 uniID uint32
1106 portNo uint32
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001107 TpInst *tp_pb.TechProfileInstance
kdarapub26b4502019-10-05 03:02:33 +05301108 allocID []uint32
1109 gemPorts []uint32
1110 TpID uint32
1111 uni string
1112 }
1113 tests := []struct {
Kent Hagermane6ff1012020-07-14 15:07:53 -04001114 name string
1115 args args
kdarapub26b4502019-10-05 03:02:33 +05301116 }{
1117 {
1118 name: "checkAndAddFlow-1",
1119 args: args{
1120 args: nil,
1121 classifierInfo: classifierInfo,
1122 actionInfo: actionInfo,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001123 flow: flow,
kdarapub26b4502019-10-05 03:02:33 +05301124 gemPort: 1,
1125 intfID: 1,
1126 onuID: 1,
1127 uniID: 16,
1128 portNo: 1,
1129 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001130 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301131 gemPorts: []uint32{1, 2, 3, 4},
1132 TpID: 64,
1133 uni: "16",
1134 },
1135 },
1136 {
1137 name: "checkAndAddFlow-2",
1138 args: args{
1139 args: nil,
1140 classifierInfo: classifierInfo2,
1141 actionInfo: actionInfo2,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001142 flow: flow2,
kdarapub26b4502019-10-05 03:02:33 +05301143 gemPort: 1,
1144 intfID: 1,
1145 onuID: 1,
1146 uniID: 16,
1147 portNo: 1,
1148 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001149 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301150 gemPorts: []uint32{1, 2, 3, 4},
1151 TpID: 64,
1152 uni: "16",
1153 },
1154 },
1155 {
1156 name: "checkAndAddFlow-3",
1157 args: args{
1158 args: nil,
1159 classifierInfo: classifierInfo3,
1160 actionInfo: actionInfo3,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001161 flow: flow3,
kdarapub26b4502019-10-05 03:02:33 +05301162 gemPort: 1,
1163 intfID: 1,
1164 onuID: 1,
1165 uniID: 16,
1166 portNo: 1,
1167 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001168 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301169 gemPorts: []uint32{1, 2, 3, 4},
1170 TpID: 64,
1171 uni: "16",
1172 },
1173 },
1174 {
1175 name: "checkAndAddFlow-4",
1176 args: args{
1177 args: nil,
1178 classifierInfo: classifierInfo4,
1179 actionInfo: actionInfo4,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001180 flow: flow4,
kdarapub26b4502019-10-05 03:02:33 +05301181 gemPort: 1,
1182 intfID: 1,
1183 onuID: 1,
1184 uniID: 16,
1185 portNo: 1,
1186 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001187 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301188 gemPorts: []uint32{1, 2, 3, 4},
1189 TpID: 64,
1190 uni: "16",
1191 },
1192 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001193 {
1194 name: "checkAndAddFlow-5",
1195 args: args{
1196 args: nil,
1197 classifierInfo: classifierInfo5,
1198 actionInfo: actionInfo5,
1199 flow: flow5,
1200 gemPort: 1,
1201 intfID: 1,
1202 onuID: 1,
1203 uniID: 16,
1204 portNo: 1,
1205 TpInst: TpInst,
1206 allocID: []uint32{0x8001},
1207 gemPorts: []uint32{1, 2, 3, 4},
1208 TpID: 64,
1209 uni: "16",
1210 },
1211 },
kdarapub26b4502019-10-05 03:02:33 +05301212 }
npujarec5762e2020-01-01 14:08:48 +05301213 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1214 defer cancel()
kdarapub26b4502019-10-05 03:02:33 +05301215 for _, tt := range tests {
1216 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -07001217 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 +00001218 tt.args.TpInst, tt.args.gemPorts, tt.args.TpID, tt.args.uni)
kdarapub26b4502019-10-05 03:02:33 +05301219 })
1220 }
1221}
Esin Karamanccb714b2019-11-29 15:02:06 +00001222
Esin Karamand519bbf2020-07-01 11:16:03 +00001223func TestOpenOltFlowMgr_TestMulticastFlowAndGroup(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301224 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1225 defer cancel()
Esin Karamanccb714b2019-11-29 15:02:06 +00001226 //create group
1227 group := newGroup(2, []uint32{1})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001228 err := flowMgr[0].grpMgr.AddGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001229 if err != nil {
1230 t.Error("group-add failed", err)
1231 return
1232 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001233 //create multicast flow
1234 multicastFlowArgs := &fu.FlowArgs{
1235 MatchFields: []*ofp.OfpOxmOfbField{
Esin Karamand519bbf2020-07-01 11:16:03 +00001236 fu.InPort(1048576),
Esin Karamanccb714b2019-11-29 15:02:06 +00001237 fu.VlanVid(660), //vlan
1238 fu.Metadata_ofp(uint64(66)), //inner vlan
1239 fu.EthType(0x800), //ipv4
1240 fu.Ipv4Dst(3809869825), //227.22.0.1
1241 },
1242 Actions: []*ofp.OfpAction{
1243 fu.Group(1),
1244 },
1245 }
divyadesaid26f6b12020-03-19 06:30:28 +00001246 ofpStats, _ := fu.MkFlowStat(multicastFlowArgs)
Esin Karamand519bbf2020-07-01 11:16:03 +00001247 fmt.Println(ofpStats.Id)
Girish Gowdra9602eb42020-09-09 15:50:39 -07001248 err = flowMgr[0].AddFlow(ctx, ofpStats, &voltha.FlowMetadata{})
Esin Karamand519bbf2020-07-01 11:16:03 +00001249 if err != nil {
1250 t.Error("Multicast flow-add failed", err)
1251 return
1252 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001253
1254 //add bucket to the group
1255 group = newGroup(2, []uint32{1, 2})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001256 err = flowMgr[0].grpMgr.ModifyGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001257 if err != nil {
1258 t.Error("modify-group failed", err)
1259 return
1260 }
1261 //remove the multicast flow
Girish Gowdra9602eb42020-09-09 15:50:39 -07001262 err = flowMgr[0].RemoveFlow(ctx, ofpStats)
Esin Karamand519bbf2020-07-01 11:16:03 +00001263 if err != nil {
1264 t.Error("Multicast flow-remove failed", err)
1265 return
1266 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001267
Esin Karamand519bbf2020-07-01 11:16:03 +00001268 //remove the group
Girish Gowdra9602eb42020-09-09 15:50:39 -07001269 err = flowMgr[0].grpMgr.DeleteGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001270 if err != nil {
1271 t.Error("delete-group failed", err)
1272 return
1273 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001274}
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001275
1276func TestOpenOltFlowMgr_TestRouteFlowToOnuChannel(t *testing.T) {
1277 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1278 defer cancel()
1279 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/core", log.DebugLevel)
1280 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager", log.DebugLevel)
1281 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/pkg/mocks", log.DebugLevel)
Girish Gowdra0aca4982021-01-04 12:44:27 -08001282 kwTable1Meter1 := make(map[string]uint64)
1283 kwTable1Meter1["table_id"] = 1
1284 kwTable1Meter1["meter_id"] = 1
1285 kwTable1Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
1286
1287 kwTable0Meter1 := make(map[string]uint64)
1288 kwTable0Meter1["table_id"] = 0
1289 kwTable0Meter1["meter_id"] = 1
1290 kwTable0Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001291
1292 flowMetadata1 := voltha.FlowMetadata{Meters: []*voltha.OfpMeterConfig{
1293 {
1294 Flags: 5,
1295 MeterId: 1,
1296 Bands: []*voltha.OfpMeterBandHeader{
1297 {
1298 Type: voltha.OfpMeterBandType_OFPMBT_DROP,
1299 Rate: 16000,
Gamze Abaka01174422021-03-10 06:55:27 +00001300 BurstSize: 0,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001301 },
1302 {
1303 Type: voltha.OfpMeterBandType_OFPMBT_DROP,
1304 Rate: 32000,
1305 BurstSize: 30,
1306 },
1307 {
1308 Type: voltha.OfpMeterBandType_OFPMBT_DROP,
1309 Rate: 64000,
1310 BurstSize: 30,
1311 },
1312 },
1313 },
1314 }}
1315
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001316 // Downstream LLDP Trap from NNI0 flow
1317 fa0 := &fu.FlowArgs{
1318 MatchFields: []*ofp.OfpOxmOfbField{
1319 fu.InPort(1048576),
1320 fu.EthType(35020),
1321 },
1322 Actions: []*ofp.OfpAction{
1323 fu.Output(4294967293),
1324 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001325 KV: make(map[string]uint64),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001326 }
1327
1328 // Upstream flow DHCP flow - ONU1 UNI0 PON0
1329 fa1 := &fu.FlowArgs{
1330 MatchFields: []*ofp.OfpOxmOfbField{
1331 fu.InPort(536870912),
1332 fu.Metadata_ofp(1),
1333 fu.IpProto(17), // dhcp
1334 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001335 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001336 fu.TunnelId(16),
1337 },
1338 Actions: []*ofp.OfpAction{
1339 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1340 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1341 fu.Output(2147483645),
1342 fu.PushVlan(0x8100),
1343 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001344 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001345 }
1346
1347 // Upstream EAPOL - ONU1 UNI0 PON0
1348 fa2 := &fu.FlowArgs{
1349 MatchFields: []*ofp.OfpOxmOfbField{
1350 fu.InPort(536870912),
1351 fu.Metadata_ofp(1),
1352 fu.EthType(0x888E),
1353 fu.VlanPcp(1),
1354 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
1355 fu.TunnelId(16),
1356 },
1357 Actions: []*ofp.OfpAction{
1358 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1359 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1360 fu.Output(2147483645),
1361 fu.PushVlan(0x8100),
1362 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001363 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001364 }
1365
1366 // Upstream HSIA - ONU1 UNI0 PON0
1367 fa3 := &fu.FlowArgs{
1368 MatchFields: []*ofp.OfpOxmOfbField{
1369 fu.InPort(536870912),
1370 fu.Metadata_ofp(1),
1371 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001372 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001373 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001374 },
1375 Actions: []*ofp.OfpAction{
1376 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001377 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001378 fu.Output(1048576),
1379 fu.PushVlan(0x8100),
1380 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001381 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001382 }
1383
1384 // Downstream HSIA - ONU1 UNI0 PON0
1385 fa4 := &fu.FlowArgs{
1386 MatchFields: []*ofp.OfpOxmOfbField{
1387 fu.InPort(1048576),
1388 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001389 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001390 fu.VlanPcp(1),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001391 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001392 },
1393 Actions: []*ofp.OfpAction{
1394 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001395 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001396 fu.Output(536870912),
1397 fu.PopVlan(),
1398 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001399 KV: kwTable0Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001400 }
1401
1402 // Upstream flow DHCP flow - ONU1 UNI0 PON15
1403 fa5 := &fu.FlowArgs{
1404 MatchFields: []*ofp.OfpOxmOfbField{
1405 fu.InPort(536870927),
1406 fu.Metadata_ofp(1),
1407 fu.IpProto(17), // dhcp
1408 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001409 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001410 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001411 },
1412 Actions: []*ofp.OfpAction{
1413 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1414 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259)),
1415 fu.Output(2147483645),
1416 fu.PushVlan(0x8100),
1417 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001418 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001419 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001420
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001421 // Upstream EAPOL - ONU1 UNI0 PON15
1422 fa6 := &fu.FlowArgs{
1423 MatchFields: []*ofp.OfpOxmOfbField{
1424 fu.InPort(536870927),
1425 fu.Metadata_ofp(1),
1426 fu.EthType(0x888E),
1427 fu.VlanPcp(1),
1428 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001429 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001430 },
1431 Actions: []*ofp.OfpAction{
1432 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1433 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1434 fu.Output(2147483645),
1435 fu.PushVlan(0x8100),
1436 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001437 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001438 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001439
1440 // Upstream PPPOED - ONU1 UNI0 PON0
1441 fa7 := &fu.FlowArgs{
1442 MatchFields: []*ofp.OfpOxmOfbField{
1443 fu.InPort(536870912),
1444 fu.Metadata_ofp(1),
1445 fu.EthType(0x8863),
1446 fu.VlanPcp(1),
1447 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
1448 fu.TunnelId(16),
1449 },
1450 Actions: []*ofp.OfpAction{
1451 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1452 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1453 fu.Output(2147483645),
1454 fu.PushVlan(0x8100),
1455 },
1456 KV: kwTable1Meter1,
1457 }
1458
1459 // Upstream PPPOED - ONU1 UNI0 PON15
1460 fa8 := &fu.FlowArgs{
1461 MatchFields: []*ofp.OfpOxmOfbField{
1462 fu.InPort(536870927),
1463 fu.Metadata_ofp(1),
1464 fu.EthType(0x8863),
1465 fu.VlanPcp(1),
1466 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
1467 fu.TunnelId(16),
1468 },
1469 Actions: []*ofp.OfpAction{
1470 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1471 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1472 fu.Output(2147483645),
1473 fu.PushVlan(0x8100),
1474 },
1475 KV: kwTable1Meter1,
1476 }
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001477 flow0, _ := fu.MkFlowStat(fa0)
1478 flow1, _ := fu.MkFlowStat(fa1)
1479 flow2, _ := fu.MkFlowStat(fa2)
1480 flow3, _ := fu.MkFlowStat(fa3)
1481 flow4, _ := fu.MkFlowStat(fa4)
1482
1483 flow5, _ := fu.MkFlowStat(fa5)
1484 flow6, _ := fu.MkFlowStat(fa6)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001485 flow7, _ := fu.MkFlowStat(fa7)
1486 flow8, _ := fu.MkFlowStat(fa8)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001487
1488 type args struct {
1489 ctx context.Context
1490 flow *ofp.OfpFlowStats
1491 addFlow bool
1492 flowMetadata *voltha.FlowMetadata
1493 }
1494 tests := []struct {
1495 name string
1496 args args
1497 wantErr bool
1498 returnedErr error
1499 }{
1500 {
1501 name: "RouteFlowToOnuChannel-0",
1502 args: args{
1503 ctx: ctx,
1504 flow: flow0,
1505 addFlow: true,
1506 flowMetadata: &flowMetadata1,
1507 },
1508 wantErr: false,
1509 },
1510 {
1511 name: "RouteFlowToOnuChannel-1",
1512 args: args{
1513 ctx: ctx,
1514 flow: flow1,
1515 addFlow: true,
1516 flowMetadata: &flowMetadata1,
1517 },
1518 wantErr: false,
1519 },
1520 {
1521 name: "RouteFlowToOnuChannel-2",
1522 args: args{
1523 ctx: ctx,
1524 flow: flow2,
1525 addFlow: true,
1526 flowMetadata: &flowMetadata1,
1527 },
1528 wantErr: false,
1529 },
1530 {
1531 name: "RouteFlowToOnuChannel-3",
1532 args: args{
1533 ctx: ctx,
1534 flow: flow3,
1535 addFlow: true,
1536 flowMetadata: &flowMetadata1,
1537 },
1538 wantErr: false,
1539 },
1540 {
1541 name: "RouteFlowToOnuChannel-4",
1542 args: args{
1543 ctx: ctx,
1544 flow: flow4,
1545 addFlow: true,
1546 flowMetadata: &flowMetadata1,
1547 },
1548 wantErr: false,
1549 },
1550 {
1551 name: "RouteFlowToOnuChannel-5",
1552 args: args{
1553 ctx: ctx,
1554 flow: flow1,
1555 addFlow: false,
1556 flowMetadata: &flowMetadata1,
1557 },
1558 wantErr: false,
1559 },
1560 {
1561 name: "RouteFlowToOnuChannel-6",
1562 args: args{
1563 ctx: ctx,
1564 flow: flow1,
1565 addFlow: true,
Girish Gowdra0aca4982021-01-04 12:44:27 -08001566 flowMetadata: &flowMetadata1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001567 },
Girish Gowdrad23ce662021-10-20 16:48:28 -07001568 wantErr: false,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001569 },
1570 {
1571 name: "RouteFlowToOnuChannel-7",
1572 args: args{
1573 ctx: ctx,
1574 flow: flow5,
1575 addFlow: true,
1576 flowMetadata: &flowMetadata1,
1577 },
1578 wantErr: false,
1579 },
1580 {
1581 name: "RouteFlowToOnuChannel-8",
1582 args: args{
1583 ctx: ctx,
1584 flow: flow6,
1585 addFlow: true,
1586 flowMetadata: &flowMetadata1,
1587 },
1588 wantErr: false,
1589 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001590 {
1591 name: "RouteFlowToOnuChannel-9",
1592 args: args{
1593 ctx: ctx,
1594 flow: flow7,
1595 addFlow: true,
1596 flowMetadata: &flowMetadata1,
1597 },
1598 wantErr: false,
1599 },
1600 {
1601 name: "RouteFlowToOnuChannel-10",
1602 args: args{
1603 ctx: ctx,
1604 flow: flow8,
1605 addFlow: true,
1606 flowMetadata: &flowMetadata1,
1607 },
1608 wantErr: false,
1609 },
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001610 }
1611
1612 var wg sync.WaitGroup
1613 defer wg.Wait() // wait for all go routines to complete
1614 for _, tt := range tests {
Girish Gowdrad23ce662021-10-20 16:48:28 -07001615 wg.Add(1) // one per go routine
1616 // The flows needs to be pushed in a particular order as they are stateful - meaning a flow delete can happen only if a flow add was done
1617 // This delay is needed so that flows arrive in order. Otherwise if all flows are pushed at once the go routine can get scheduled
1618 // in random order causing flows to come out of order and test fails
1619 time.Sleep(5 * time.Millisecond)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001620 t.Run(tt.name, func(t *testing.T) {
Girish Gowdrad23ce662021-10-20 16:48:28 -07001621 defer wg.Done()
1622 tt.returnedErr = flowMgr[0].RouteFlowToOnuChannel(tt.args.ctx, tt.args.flow, tt.args.addFlow, tt.args.flowMetadata)
1623 if (tt.wantErr == false && tt.returnedErr != nil) || (tt.wantErr == true && tt.returnedErr == nil) {
1624 t.Errorf("OpenOltFlowMgr.RouteFlowToOnuChannel() error = %v, wantErr %v", tt.returnedErr, tt.wantErr)
1625 }
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001626 })
1627 }
1628}