blob: 5f64a71997aedef3e0643e76b3f01a6709574520 [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 fu "github.com/opencord/voltha-lib-go/v7/pkg/flows"
33 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Scott Bakerdbd960e2020-02-28 08:57:51 -080034 rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager"
khenaidoo106c61a2021-08-11 18:05:46 -040035 ofp "github.com/opencord/voltha-protos/v5/go/openflow_13"
36 openoltpb2 "github.com/opencord/voltha-protos/v5/go/openolt"
37 tp_pb "github.com/opencord/voltha-protos/v5/go/tech_profile"
kdarapu3248f9a2019-10-03 13:54:52 +053038)
39
Girish Gowdra9602eb42020-09-09 15:50:39 -070040var flowMgr []*OpenOltFlowMgr
kdarapub26b4502019-10-05 03:02:33 +053041
kdarapu3248f9a2019-10-03 13:54:52 +053042func init() {
Kent Hagermane6ff1012020-07-14 15:07:53 -040043 _, _ = log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
kdarapub26b4502019-10-05 03:02:33 +053044 flowMgr = newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +053045}
kdarapu3248f9a2019-10-03 13:54:52 +053046
Girish Gowdra9602eb42020-09-09 15:50:39 -070047func newMockFlowmgr() []*OpenOltFlowMgr {
kdarapu3248f9a2019-10-03 13:54:52 +053048 dh := newMockDeviceHandler()
49
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070050 // onuGemInfoMap := make([]rsrcMgr.onuGemInfoMap, NumPonPorts)
Girish Gowdra9602eb42020-09-09 15:50:39 -070051 var i uint32
kdarapu3248f9a2019-10-03 13:54:52 +053052
Girish Gowdra9602eb42020-09-09 15:50:39 -070053 for i = 0; i < NumPonPorts; i++ {
54 packetInGemPort := make(map[rsrcMgr.PacketInInfoKey]uint32)
55 packetInGemPort[rsrcMgr.PacketInInfoKey{IntfID: i, OnuID: i + 1, LogicalPort: i + 1, VlanID: uint16(i), Priority: uint8(i)}] = i + 1
kdarapu3248f9a2019-10-03 13:54:52 +053056
Girish Gowdra9602eb42020-09-09 15:50:39 -070057 dh.flowMgr[i].packetInGemPort = packetInGemPort
Girish Gowdra4c3d4602021-07-22 16:33:37 -070058 dh.flowMgr[i].techprofile = mocks.MockTechProfile{}
59
Girish Gowdra9602eb42020-09-09 15:50:39 -070060 interface2mcastQeueuMap := make(map[uint32]*QueueInfoBrief)
61 interface2mcastQeueuMap[0] = &QueueInfoBrief{
62 gemPortID: 4000,
63 servicePriority: 3,
64 }
65 dh.flowMgr[i].grpMgr.interfaceToMcastQueueMap = interface2mcastQeueuMap
kdarapu3248f9a2019-10-03 13:54:52 +053066 }
Girish Gowdra9602eb42020-09-09 15:50:39 -070067 return dh.flowMgr
kdarapu3248f9a2019-10-03 13:54:52 +053068}
kdarapub26b4502019-10-05 03:02:33 +053069
kdarapu3248f9a2019-10-03 13:54:52 +053070func TestOpenOltFlowMgr_CreateSchedulerQueues(t *testing.T) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070071 tprofile := &tp_pb.TechProfileInstance{Name: "tp1", SubscriberIdentifier: "subscriber1",
Girish Gowdra54934262019-11-13 14:19:55 +053072 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070073 InstanceControl: &tp_pb.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"},
kdarapu3248f9a2019-10-03 13:54:52 +053074 }
khenaidoodc2116e2021-10-19 17:33:19 -040075 tprofile.UsScheduler = &tp_pb.SchedulerAttributes{}
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070076 tprofile.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
77 tprofile.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +053078
79 tprofile2 := tprofile
khenaidoodc2116e2021-10-19 17:33:19 -040080 tprofile2.DsScheduler = &tp_pb.SchedulerAttributes{}
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070081 tprofile2.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
82 tprofile2.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Gamze Abaka01174422021-03-10 06:55:27 +000083
kdarapu3248f9a2019-10-03 13:54:52 +053084 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +000085 name string
86 schedQueue schedQueue
87 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +053088 }{
89 // TODO: Add test cases.
Gamze Abaka01174422021-03-10 06:55:27 +000090 {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 1, Upstream)}, false},
91 {"CreateSchedulerQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 1, Downstream)}, false},
92 {"CreateSchedulerQueues-13", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 2, Upstream)}, false},
93 {"CreateSchedulerQueues-14", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 2, Downstream)}, false},
94 {"CreateSchedulerQueues-15", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 3, Upstream)}, false},
95 {"CreateSchedulerQueues-16", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 3, Downstream)}, false},
96 {"CreateSchedulerQueues-17", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 4, Upstream)}, false},
97 {"CreateSchedulerQueues-18", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 4, Downstream)}, false},
98 {"CreateSchedulerQueues-19", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 5, Upstream)}, false},
99 {"CreateSchedulerQueues-20", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 5, Downstream)}, false},
100
Girish Gowdra5467db82022-01-21 15:59:54 -0800101 //Negative testcases
102 {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 0, Upstream)}, true},
103 {"CreateSchedulerQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 0, Downstream)}, true},
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},
Girish Gowdra5467db82022-01-21 15:59:54 -0800108 {"CreateSchedulerQueues-7", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, &ofp.FlowMetadata{}}, true},
khenaidoodc2116e2021-10-19 17:33:19 -0400109 {"CreateSchedulerQueues-8", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 0, &ofp.FlowMetadata{}}, true},
Girish Gowdra5467db82022-01-21 15:59:54 -0800110 {"CreateSchedulerQueues-9", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, &ofp.FlowMetadata{}}, true},
khenaidoodc2116e2021-10-19 17:33:19 -0400111 {"CreateSchedulerQueues-10", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, &ofp.FlowMetadata{}}, true},
112 {"CreateSchedulerQueues-11", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, &ofp.FlowMetadata{}}, true},
Girish Gowdra9602eb42020-09-09 15:50:39 -0700113 {"CreateSchedulerQueues-12", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, nil}, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530114 }
npujarec5762e2020-01-01 14:08:48 +0530115 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
116 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530117 for _, tt := range tests {
118 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700119 if err := flowMgr[tt.schedQueue.intfID].CreateSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530120 t.Errorf("OpenOltFlowMgr.CreateSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr)
121 }
122 })
123 }
124}
125
khenaidoodc2116e2021-10-19 17:33:19 -0400126func createFlowMetadata(techProfile *tp_pb.TechProfileInstance, tcontType int, direction string) *ofp.FlowMetadata {
127 var additionalBw tp_pb.AdditionalBW
Gamze Abaka01174422021-03-10 06:55:27 +0000128 bands := make([]*ofp.OfpMeterBandHeader, 0)
129 switch tcontType {
130 case 1:
131 //tcont-type-1
132 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
133 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700134 additionalBw = tp_pb.AdditionalBW_AdditionalBW_None
Gamze Abaka01174422021-03-10 06:55:27 +0000135 case 2:
136 //tcont-type-2
137 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 60000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
138 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700139 additionalBw = tp_pb.AdditionalBW_AdditionalBW_None
Gamze Abaka01174422021-03-10 06:55:27 +0000140 case 3:
141 //tcont-type-3
142 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
143 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 20000, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700144 additionalBw = tp_pb.AdditionalBW_AdditionalBW_NA
Gamze Abaka01174422021-03-10 06:55:27 +0000145 case 4:
146 //tcont-type-4
147 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 200000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700148 additionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
Gamze Abaka01174422021-03-10 06:55:27 +0000149 case 5:
150 //tcont-type-5
151 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
152 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
153 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700154 additionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
Gamze Abaka01174422021-03-10 06:55:27 +0000155 default:
156 // do nothing, we will return meter config with no meter bands
157 }
158
159 if direction == Downstream {
160 techProfile.DsScheduler.AdditionalBw = additionalBw
161 } else {
162 techProfile.UsScheduler.AdditionalBw = additionalBw
163 }
164
165 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
khenaidoodc2116e2021-10-19 17:33:19 -0400166 return &ofp.FlowMetadata{
Gamze Abaka01174422021-03-10 06:55:27 +0000167 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}}
168}
169
Girish Gowdra5467db82022-01-21 15:59:54 -0800170func TestOpenOltFlowMgr_RemoveScheduler(t *testing.T) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700171 tprofile := &tp_pb.TechProfileInstance{Name: "tp1", SubscriberIdentifier: "subscriber1",
Girish Gowdra54934262019-11-13 14:19:55 +0530172 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700173 InstanceControl: &tp_pb.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"},
kdarapu3248f9a2019-10-03 13:54:52 +0530174 }
khenaidoodc2116e2021-10-19 17:33:19 -0400175 tprofile.UsScheduler = &tp_pb.SchedulerAttributes{}
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700176 tprofile.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
177 tprofile.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
178 tprofile.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +0530179
180 tprofile2 := tprofile
khenaidoodc2116e2021-10-19 17:33:19 -0400181 tprofile2.DsScheduler = &tp_pb.SchedulerAttributes{}
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700182 tprofile2.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
183 tprofile2.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
184 tprofile2.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +0530185 //defTprofile := &tp.DefaultTechProfile{}
kdarapu3248f9a2019-10-03 13:54:52 +0530186 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +0000187 name string
188 schedQueue schedQueue
189 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +0530190 }{
Girish Gowdra5467db82022-01-21 15:59:54 -0800191 {"RemoveScheduler-1", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 0, nil}, false},
192 {"RemoveScheduler-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
193 {"RemoveScheduler-3", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
194 {"RemoveScheduler-4", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530195 }
npujarec5762e2020-01-01 14:08:48 +0530196 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
197 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530198 for _, tt := range tests {
199 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra5467db82022-01-21 15:59:54 -0800200 if err := flowMgr[tt.schedQueue.intfID].RemoveScheduler(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
201 t.Errorf("OpenOltFlowMgr.RemoveScheduler() error = %v, wantErr %v", err, tt.wantErr)
202 }
203 })
204 }
205
206}
207
208func TestOpenOltFlowMgr_RemoveQueues(t *testing.T) {
209 tprofile := &tp_pb.TechProfileInstance{Name: "tp1", SubscriberIdentifier: "subscriber1",
210 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
211 InstanceControl: &tp_pb.InstanceControl{Onu: "single-instance", Uni: "single-instance", MaxGemPayloadSize: "1"},
212 }
213 tprofile.UsScheduler = &tp_pb.SchedulerAttributes{}
214 tprofile.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
215 tprofile.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
216 tprofile.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
217 tprofile.DsScheduler = &tp_pb.SchedulerAttributes{}
218 tprofile.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
219 tprofile.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
220 tprofile.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_StrictPriority
221 tprofile.UpstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
222 tprofile.UpstreamGemPortAttributeList = append(tprofile.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
223 tprofile.UpstreamGemPortAttributeList = append(tprofile.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
224 tprofile.UpstreamGemPortAttributeList = append(tprofile.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
225 tprofile.UpstreamGemPortAttributeList = append(tprofile.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
226
227 tprofile.DownstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
228 tprofile.DownstreamGemPortAttributeList = append(tprofile.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
229 tprofile.DownstreamGemPortAttributeList = append(tprofile.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
230 tprofile.DownstreamGemPortAttributeList = append(tprofile.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
231 tprofile.DownstreamGemPortAttributeList = append(tprofile.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
232
233 tprofile2 := &tp_pb.TechProfileInstance{Name: "tp2", SubscriberIdentifier: "subscriber2",
234 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
235 InstanceControl: &tp_pb.InstanceControl{Onu: "multi-instance", Uni: "single-instance", MaxGemPayloadSize: "1"},
236 }
237 tprofile2.UsScheduler = &tp_pb.SchedulerAttributes{}
238 tprofile2.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
239 tprofile2.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
240 tprofile2.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
241 tprofile2.DsScheduler = &tp_pb.SchedulerAttributes{}
242 tprofile2.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
243 tprofile2.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
244 tprofile2.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_StrictPriority
245 tprofile2.UpstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
246 tprofile2.UpstreamGemPortAttributeList = append(tprofile.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b11111111"})
247 tprofile2.DownstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
248 tprofile2.DownstreamGemPortAttributeList = append(tprofile.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b11111111"})
249
250 //defTprofile := &tp.DefaultTechProfile{}
251 tests := []struct {
252 name string
253 schedQueue schedQueue
254 wantErr bool
255 }{
256 {"RemoveQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 0, nil}, false},
257 {"RemoveQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
258 {"RemoveQueues-3", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
259 {"RemoveQueues-4", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
260 }
261 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
262 defer cancel()
263 for _, tt := range tests {
264 t.Run(tt.name, func(t *testing.T) {
265 if err := flowMgr[tt.schedQueue.intfID].RemoveQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
266 t.Errorf("OpenOltFlowMgr.RemoveQueues() error = %v, wantErr %v", err, tt.wantErr)
kdarapu3248f9a2019-10-03 13:54:52 +0530267 }
268 })
269 }
kdarapub26b4502019-10-05 03:02:33 +0530270
kdarapu3248f9a2019-10-03 13:54:52 +0530271}
272
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700273func TestOpenOltFlowMgr_createTcontGemports(t *testing.T) {
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700274 bands := make([]*ofp.OfpMeterBandHeader, 2)
275 bands[0] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 1000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
276 bands[1] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 2000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
277 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
khenaidoodc2116e2021-10-19 17:33:19 -0400278 flowmetadata := &ofp.FlowMetadata{
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700279 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
280 }
281 type args struct {
282 intfID uint32
283 onuID uint32
284 uniID uint32
285 uni string
286 uniPort uint32
287 TpID uint32
288 UsMeterID uint32
289 DsMeterID uint32
khenaidoodc2116e2021-10-19 17:33:19 -0400290 flowMetadata *ofp.FlowMetadata
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700291 }
292 tests := []struct {
293 name string
294 args args
295 }{
296 {"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 -0700297 }
298 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
299 defer cancel()
300 for _, tt := range tests {
301 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700302 _, _, 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 -0700303 switch tpInst := tpInst.(type) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700304 case *tp_pb.TechProfileInstance:
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700305 if tt.args.TpID != 64 {
306 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
307 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700308 case *tp_pb.EponTechProfileInstance:
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700309 if tt.args.TpID != 65 {
310 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
311 }
312 default:
313 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
314 }
315 })
316 }
317}
318
kdarapu3248f9a2019-10-03 13:54:52 +0530319func TestOpenOltFlowMgr_RemoveFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000320 ctx := context.Background()
Neha Sharma96b7bf22020-06-15 10:37:32 +0000321 logger.Debug(ctx, "Info Warning Error: Starting RemoveFlow() test")
kdarapu3248f9a2019-10-03 13:54:52 +0530322 fa := &fu.FlowArgs{
323 MatchFields: []*ofp.OfpOxmOfbField{
324 fu.InPort(2),
325 fu.Metadata_ofp(2),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300326 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapu3248f9a2019-10-03 13:54:52 +0530327 },
328 Actions: []*ofp.OfpAction{
329 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
330 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
331 fu.Output(1),
332 },
333 }
divyadesaid26f6b12020-03-19 06:30:28 +0000334 ofpstats, _ := fu.MkFlowStat(fa)
kdarapub26b4502019-10-05 03:02:33 +0530335 ofpstats.Cookie = ofpstats.Id
kdarapub26b4502019-10-05 03:02:33 +0530336 lldpFa := &fu.FlowArgs{
337 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
338 MatchFields: []*ofp.OfpOxmOfbField{
339 fu.InPort(1),
340 fu.EthType(0x88CC),
341 fu.TunnelId(536870912),
342 },
343 Actions: []*ofp.OfpAction{
344 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
345 },
346 }
divyadesaid26f6b12020-03-19 06:30:28 +0000347 lldpofpstats, _ := fu.MkFlowStat(lldpFa)
kdarapub26b4502019-10-05 03:02:33 +0530348 //lldpofpstats.Cookie = lldpofpstats.Id
349
350 dhcpFa := &fu.FlowArgs{
351 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
352 MatchFields: []*ofp.OfpOxmOfbField{
353 fu.InPort(1),
354 fu.UdpSrc(67),
355 //fu.TunnelId(536870912),
356 fu.IpProto(17),
357 },
358 Actions: []*ofp.OfpAction{
359 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
360 },
361 }
divyadesaid26f6b12020-03-19 06:30:28 +0000362 dhcpofpstats, _ := fu.MkFlowStat(dhcpFa)
kdarapub26b4502019-10-05 03:02:33 +0530363 //dhcpofpstats.Cookie = dhcpofpstats.Id
Esin Karamanccb714b2019-11-29 15:02:06 +0000364
365 //multicast flow
366 multicastFa := &fu.FlowArgs{
367 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700368 fu.InPort(16777216),
Esin Karamanccb714b2019-11-29 15:02:06 +0000369 fu.VlanVid(660), //vlan
370 fu.Metadata_ofp(uint64(66)), //inner vlan
371 fu.EthType(0x800), //ipv4
372 fu.Ipv4Dst(3809869825), //227.22.0.1
373 },
374 Actions: []*ofp.OfpAction{
375 fu.Group(1),
376 },
377 }
divyadesaid26f6b12020-03-19 06:30:28 +0000378 multicastOfpStats, _ := fu.MkFlowStat(multicastFa)
Esin Karamanccb714b2019-11-29 15:02:06 +0000379 multicastOfpStats.Id = 1
380
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300381 pppoedFa := &fu.FlowArgs{
382 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
383 MatchFields: []*ofp.OfpOxmOfbField{
384 fu.InPort(1),
385 fu.EthType(0x8863),
386 fu.TunnelId(536870912),
387 },
388 Actions: []*ofp.OfpAction{
389 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
390 },
391 }
392 pppoedOfpStats, _ := fu.MkFlowStat(pppoedFa)
393
kdarapu3248f9a2019-10-03 13:54:52 +0530394 type args struct {
395 flow *ofp.OfpFlowStats
396 }
397 tests := []struct {
398 name string
399 args args
400 }{
401 // TODO: Add test cases.
402 {"RemoveFlow", args{flow: ofpstats}},
kdarapub26b4502019-10-05 03:02:33 +0530403 {"RemoveFlow", args{flow: lldpofpstats}},
404 {"RemoveFlow", args{flow: dhcpofpstats}},
Esin Karamanccb714b2019-11-29 15:02:06 +0000405 {"RemoveFlow", args{flow: multicastOfpStats}},
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300406 {"RemoveFlow", args{flow: pppoedOfpStats}},
kdarapu3248f9a2019-10-03 13:54:52 +0530407 }
npujarec5762e2020-01-01 14:08:48 +0530408 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
409 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530410 for _, tt := range tests {
411 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700412 if err := flowMgr[0].RemoveFlow(ctx, tt.args.flow); err != nil {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400413 logger.Warn(ctx, err)
414 }
kdarapu3248f9a2019-10-03 13:54:52 +0530415 })
416 }
kdarapub26b4502019-10-05 03:02:33 +0530417 // t.Error("=====")
kdarapu3248f9a2019-10-03 13:54:52 +0530418}
419
420func TestOpenOltFlowMgr_AddFlow(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530421 kw := make(map[string]uint64)
422 kw["table_id"] = 1
423 kw["meter_id"] = 1
kdarapub26b4502019-10-05 03:02:33 +0530424 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
425
426 // Upstream flow
kdarapu3248f9a2019-10-03 13:54:52 +0530427 fa := &fu.FlowArgs{
428 MatchFields: []*ofp.OfpOxmOfbField{
kdarapub26b4502019-10-05 03:02:33 +0530429 fu.InPort(536870912),
430 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300431 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530432 },
433 Actions: []*ofp.OfpAction{
434 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
435 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700436 fu.Output(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530437 fu.PushVlan(0x8100),
438 },
439 KV: kw,
440 }
441
442 // Downstream flow
443 fa3 := &fu.FlowArgs{
444 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700445 fu.InPort(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530446 fu.Metadata_ofp(1),
447 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
448 },
449 Actions: []*ofp.OfpAction{
450 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
451 //fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
452 fu.PopVlan(),
453 fu.Output(536870912),
454 },
455 KV: kw,
456 }
457
458 fa2 := &fu.FlowArgs{
459 MatchFields: []*ofp.OfpOxmOfbField{
kdarapu3248f9a2019-10-03 13:54:52 +0530460 fu.InPort(1000),
461 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300462 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapu3248f9a2019-10-03 13:54:52 +0530463 },
464 Actions: []*ofp.OfpAction{
465 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
466 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
467 fu.Output(65533),
468 },
469 KV: kw,
470 }
471
kdarapub26b4502019-10-05 03:02:33 +0530472 // TODO Add LLDP flow
473 // TODO Add DHCP flow
474
475 // Flows for negative scenarios
476 // Failure in formulateActionInfoFromFlow()
477 fa4 := &fu.FlowArgs{
478 MatchFields: []*ofp.OfpOxmOfbField{
479 fu.InPort(1000),
480 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300481 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530482 },
483 Actions: []*ofp.OfpAction{
484 fu.Experimenter(257, []byte{1, 2, 3, 4}),
485 },
486 KV: kw,
487 }
488
489 // Invalid Output
490 fa5 := &fu.FlowArgs{
491 MatchFields: []*ofp.OfpOxmOfbField{
492 fu.InPort(1000),
493 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300494 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530495 },
496 Actions: []*ofp.OfpAction{
497 fu.Output(0),
498 },
499 KV: kw,
500 }
501
502 // Tech-Profile-ID update (not supported)
503 kw6 := make(map[string]uint64)
504 kw6["table_id"] = 1
505 kw6["meter_id"] = 1
506 kw6["write_metadata"] = 0x4100000000 // TpID Other than the stored one
507 fa6 := &fu.FlowArgs{
508 MatchFields: []*ofp.OfpOxmOfbField{
509 fu.InPort(536870912),
510 fu.TunnelId(16),
511 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300512 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530513 },
514 Actions: []*ofp.OfpAction{
515 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
516 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
517 fu.Output(65535),
518 },
519 KV: kw6,
520 }
521
522 lldpFa := &fu.FlowArgs{
523 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
524 MatchFields: []*ofp.OfpOxmOfbField{
525 fu.InPort(1),
526 fu.EthType(0x88CC),
527 fu.TunnelId(536870912),
528 },
529 Actions: []*ofp.OfpAction{
530 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
531 },
532 }
533
534 dhcpFa := &fu.FlowArgs{
535 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
536 MatchFields: []*ofp.OfpOxmOfbField{
537 fu.InPort(1),
538 fu.UdpSrc(67),
539 //fu.TunnelId(536870912),
540 fu.IpProto(17),
541 },
542 Actions: []*ofp.OfpAction{
543 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
544 },
545 }
546 igmpFa := &fu.FlowArgs{
547 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
548 MatchFields: []*ofp.OfpOxmOfbField{
549 fu.InPort(1),
550 fu.UdpSrc(67),
551 //fu.TunnelId(536870912),
552 fu.IpProto(2),
553 },
554 Actions: []*ofp.OfpAction{
555 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
556 },
557 }
558
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300559 pppoedFa := &fu.FlowArgs{
560 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
561 MatchFields: []*ofp.OfpOxmOfbField{
562 fu.InPort(1),
563 fu.EthType(0x8863),
564 fu.TunnelId(536870912),
565 },
566 Actions: []*ofp.OfpAction{
567 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
568 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
569 },
570 }
571
kdarapub26b4502019-10-05 03:02:33 +0530572 fa9 := &fu.FlowArgs{
573 MatchFields: []*ofp.OfpOxmOfbField{
574 fu.InPort(536870912),
575 fu.TunnelId(16),
576 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300577 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530578 fu.VlanPcp(1000),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700579 fu.UdpDst(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530580 fu.UdpSrc(536870912),
581 fu.Ipv4Dst(65535),
582 fu.Ipv4Src(536870912),
583 },
584 Actions: []*ofp.OfpAction{
585 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
586 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
587 fu.Output(65535),
588 },
589 KV: kw6,
590 }
591
592 fa10 := &fu.FlowArgs{
593 MatchFields: []*ofp.OfpOxmOfbField{
594 fu.InPort(65533),
595 // fu.TunnelId(16),
596 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300597 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530598 fu.VlanPcp(1000),
599 fu.UdpDst(65535),
600 fu.UdpSrc(536870912),
601 fu.Ipv4Dst(65535),
602 fu.Ipv4Src(536870912),
603 },
604 Actions: []*ofp.OfpAction{
605 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
606 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
607 fu.Output(65535),
608 },
609 KV: kw6,
610 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000611 //multicast flow
612 fa11 := &fu.FlowArgs{
613 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700614 fu.InPort(16777216),
Esin Karamanccb714b2019-11-29 15:02:06 +0000615 fu.VlanVid(660), //vlan
616 fu.Metadata_ofp(uint64(66)), //inner vlan
617 fu.EthType(0x800), //ipv4
618 fu.Ipv4Dst(3809869825), //227.22.0.1
619 },
620 Actions: []*ofp.OfpAction{
621 fu.Group(1),
622 },
623 KV: kw6,
624 }
divyadesaid26f6b12020-03-19 06:30:28 +0000625 ofpstats, _ := fu.MkFlowStat(fa)
626 ofpstats2, _ := fu.MkFlowStat(fa2)
627 ofpstats3, _ := fu.MkFlowStat(fa3)
628 ofpstats4, _ := fu.MkFlowStat(fa4)
629 ofpstats5, _ := fu.MkFlowStat(fa5)
630 ofpstats6, _ := fu.MkFlowStat(fa6)
631 ofpstats7, _ := fu.MkFlowStat(lldpFa)
632 ofpstats8, _ := fu.MkFlowStat(dhcpFa)
633 ofpstats9, _ := fu.MkFlowStat(fa9)
634 ofpstats10, _ := fu.MkFlowStat(fa10)
635 igmpstats, _ := fu.MkFlowStat(igmpFa)
636 ofpstats11, _ := fu.MkFlowStat(fa11)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300637 pppoedstats, _ := fu.MkFlowStat(pppoedFa)
kdarapub26b4502019-10-05 03:02:33 +0530638
Gamze Abakafee36392019-10-03 11:17:24 +0000639 fmt.Println(ofpstats6, ofpstats9, ofpstats10)
640
kdarapu3248f9a2019-10-03 13:54:52 +0530641 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1}
khenaidoodc2116e2021-10-19 17:33:19 -0400642 flowMetadata := &ofp.FlowMetadata{
kdarapu3248f9a2019-10-03 13:54:52 +0530643 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
644 }
645 type args struct {
646 flow *ofp.OfpFlowStats
khenaidoodc2116e2021-10-19 17:33:19 -0400647 flowMetadata *ofp.FlowMetadata
kdarapu3248f9a2019-10-03 13:54:52 +0530648 }
649 tests := []struct {
650 name string
651 args args
652 }{
653 // TODO: Add test cases.
654 {"AddFlow", args{flow: ofpstats, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530655 {"AddFlow", args{flow: ofpstats2, flowMetadata: flowMetadata}},
656 {"AddFlow", args{flow: ofpstats3, flowMetadata: flowMetadata}},
657 {"AddFlow", args{flow: ofpstats4, flowMetadata: flowMetadata}},
658 {"AddFlow", args{flow: ofpstats5, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000659 //{"AddFlow", args{flow: ofpstats6, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530660 {"AddFlow", args{flow: ofpstats7, flowMetadata: flowMetadata}},
661 {"AddFlow", args{flow: ofpstats8, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000662 //{"AddFlow", args{flow: ofpstats9, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530663 {"AddFlow", args{flow: igmpstats, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000664 //{"AddFlow", args{flow: ofpstats10, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530665 //ofpstats10
Esin Karamanccb714b2019-11-29 15:02:06 +0000666 {"AddFlow", args{flow: ofpstats11, flowMetadata: flowMetadata}},
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300667 {"AddFlow", args{flow: pppoedstats, flowMetadata: flowMetadata}},
kdarapu3248f9a2019-10-03 13:54:52 +0530668 }
npujarec5762e2020-01-01 14:08:48 +0530669 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
670 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530671 for _, tt := range tests {
672 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700673 _ = flowMgr[0].AddFlow(ctx, tt.args.flow, tt.args.flowMetadata)
Kent Hagermane6ff1012020-07-14 15:07:53 -0400674 // TODO: actually verify test cases
kdarapu3248f9a2019-10-03 13:54:52 +0530675 })
676 }
677}
678
679func TestOpenOltFlowMgr_UpdateOnuInfo(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530680 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
681 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530682
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700683 wg := sync.WaitGroup{}
684
Girish Gowdra9602eb42020-09-09 15:50:39 -0700685 intfCount := NumPonPorts
686 onuCount := OnuIDEnd - OnuIDStart + 1
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700687
688 for i := 0; i < intfCount; i++ {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700689 for j := 1; j <= onuCount; j++ {
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700690 wg.Add(1)
691 go func(i uint32, j uint32) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400692 // TODO: actually verify success
Girish Gowdra197acc12021-08-16 10:59:45 -0700693 _ = flowMgr[i].AddOnuInfoToFlowMgrCacheAndKvStore(ctx, i, i, fmt.Sprintf("onu-%d", i))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700694 wg.Done()
695 }(uint32(i), uint32(j))
696 }
697
698 }
699
700 wg.Wait()
701}
702
703func TestOpenOltFlowMgr_addGemPortToOnuInfoMap(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700704 intfNum := NumPonPorts
705 onuNum := OnuIDEnd - OnuIDStart + 1
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700706
707 // clean the flowMgr
Girish Gowdra9602eb42020-09-09 15:50:39 -0700708 for i := 0; i < intfNum; i++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700709 flowMgr[i].onuGemInfoMap = make(map[uint32]*rsrcMgr.OnuGemInfo)
Girish Gowdra9602eb42020-09-09 15:50:39 -0700710 }
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700711
712 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
713 defer cancel()
714
715 // Create OnuInfo
716 for i := 0; i < intfNum; i++ {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700717 for o := 1; o <= onuNum; o++ {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400718 // TODO: actually verify success
Girish Gowdra197acc12021-08-16 10:59:45 -0700719 _ = flowMgr[i].AddOnuInfoToFlowMgrCacheAndKvStore(ctx, uint32(i), uint32(o), fmt.Sprintf("i%do%d", i, o-1))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700720 }
721 }
722
723 // Add gemPorts to OnuInfo in parallel threads
724 wg := sync.WaitGroup{}
Girish Gowdra9602eb42020-09-09 15:50:39 -0700725 for o := 1; o <= onuNum; o++ {
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700726 for i := 0; i < intfNum; i++ {
727 wg.Add(1)
728 go func(intfId uint32, onuId uint32) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700729 gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", intfId, onuId-1))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700730
Girish Gowdra9602eb42020-09-09 15:50:39 -0700731 flowMgr[intfId].addGemPortToOnuInfoMap(ctx, intfId, onuId, uint32(gemID))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700732 wg.Done()
733 }(uint32(i), uint32(o))
734 }
735 }
736
737 wg.Wait()
738
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700739 // check that each entry of onuGemInfoMap has the correct number of ONUs
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700740 for i := 0; i < intfNum; i++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700741 lenofOnu := len(flowMgr[i].onuGemInfoMap)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700742 if onuNum != lenofOnu {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700743 t.Errorf("onuGemInfoMap length is not as expected len = %d, want %d", lenofOnu, onuNum)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700744 }
745
Girish Gowdra9602eb42020-09-09 15:50:39 -0700746 for o := 1; o <= onuNum; o++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700747 lenOfGemPorts := len(flowMgr[i].onuGemInfoMap[uint32(o)].GemPorts)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700748 // check that each onuEntry has 1 gemPort
749 if lenOfGemPorts != 1 {
750 t.Errorf("Expected 1 GemPort per ONU, found %d", lenOfGemPorts)
751 }
752
753 // check that the value of the gemport is correct
Girish Gowdra9602eb42020-09-09 15:50:39 -0700754 gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", i, o-1))
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700755 currentValue := flowMgr[i].onuGemInfoMap[uint32(o)].GemPorts[0]
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700756 if uint32(gemID) != currentValue {
757 t.Errorf("Expected GemPort value to be %d, found %d", gemID, currentValue)
758 }
759 }
kdarapu3248f9a2019-10-03 13:54:52 +0530760 }
761}
762
serkant.uluderya96af4932020-02-20 16:58:48 -0800763func TestOpenOltFlowMgr_deleteGemPortFromLocalCache(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700764 // Create fresh flowMgr instance
765 flowMgr = newMockFlowmgr()
serkant.uluderya96af4932020-02-20 16:58:48 -0800766 type args struct {
767 intfID uint32
768 onuID uint32
769 gemPortIDs []uint32
770 gemPortIDsToBeDeleted []uint32
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700771 gemPortIDsRemaining []uint32
serkant.uluderya96af4932020-02-20 16:58:48 -0800772 serialNum string
773 finalLength int
774 }
775 tests := []struct {
776 name string
777 args args
778 }{
779 // Add/Delete single gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700780 {"DeleteGemPortFromLocalCache1", args{0, 1, []uint32{1}, []uint32{1}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800781 // Delete all gemports
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700782 {"DeleteGemPortFromLocalCache2", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{1, 2, 3, 4}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800783 // Try to delete when there is no gem port
Girish Gowdra197acc12021-08-16 10:59:45 -0700784 {"DeleteGemPortFromLocalCache3", args{0, 1, []uint32{}, []uint32{1, 2}, nil, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800785 // Try to delete non-existent gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700786 {"DeleteGemPortFromLocalCache4", args{0, 1, []uint32{1}, []uint32{2}, []uint32{1}, "onu1", 1}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800787 // Try to delete two of the gem ports
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700788 {"DeleteGemPortFromLocalCache5", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{2, 4}, []uint32{1, 3}, "onu1", 2}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800789 }
790 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
791 defer cancel()
792 for _, tt := range tests {
793 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra197acc12021-08-16 10:59:45 -0700794 if err := flowMgr[tt.args.intfID].RemoveOnuInfoFromFlowMgrCacheAndKvStore(ctx, tt.args.intfID, tt.args.onuID); err != nil {
795 t.Errorf("failed to remove onu")
796 }
797 if err := flowMgr[tt.args.intfID].AddOnuInfoToFlowMgrCacheAndKvStore(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum); err != nil {
798 t.Errorf("failed to add onu")
799 }
serkant.uluderya96af4932020-02-20 16:58:48 -0800800 for _, gemPort := range tt.args.gemPortIDs {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700801 flowMgr[tt.args.intfID].addGemPortToOnuInfoMap(ctx, tt.args.intfID, tt.args.onuID, gemPort)
serkant.uluderya96af4932020-02-20 16:58:48 -0800802 }
803 for _, gemPortDeleted := range tt.args.gemPortIDsToBeDeleted {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700804 flowMgr[tt.args.intfID].deleteGemPortFromLocalCache(ctx, tt.args.intfID, tt.args.onuID, gemPortDeleted)
serkant.uluderya96af4932020-02-20 16:58:48 -0800805 }
Girish Gowdra197acc12021-08-16 10:59:45 -0700806 lenofGemPorts := 0
807 gP, ok := flowMgr[tt.args.intfID].onuGemInfoMap[tt.args.onuID]
808 if ok {
809 lenofGemPorts = len(gP.GemPorts)
810 }
serkant.uluderya96af4932020-02-20 16:58:48 -0800811 if lenofGemPorts != tt.args.finalLength {
812 t.Errorf("GemPorts length is not as expected len = %d, want %d", lenofGemPorts, tt.args.finalLength)
813 }
Girish Gowdra197acc12021-08-16 10:59:45 -0700814 gP, ok = flowMgr[tt.args.intfID].onuGemInfoMap[tt.args.onuID]
815 var gemPorts []uint32
816 if ok {
817 gemPorts = gP.GemPorts
818 }
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700819 if !reflect.DeepEqual(tt.args.gemPortIDsRemaining, gemPorts) {
820 t.Errorf("GemPorts are not as expected = %v, want %v", gemPorts, tt.args.gemPortIDsRemaining)
821 }
serkant.uluderya96af4932020-02-20 16:58:48 -0800822
823 })
824 }
825}
826
kdarapu3248f9a2019-10-03 13:54:52 +0530827func TestOpenOltFlowMgr_GetLogicalPortFromPacketIn(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530828 type args struct {
829 packetIn *openoltpb2.PacketIndication
830 }
831 tests := []struct {
832 name string
833 args args
834 want uint32
835 wantErr bool
836 }{
837 // TODO: Add test cases.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700838 {"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},
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700839 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "nni", IntfId: 0, GemportId: 1, OnuId: 1, UniId: 0, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 16777216, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530840 // Negative Test cases.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700841 {"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},
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700842 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 0, GemportId: 257, OnuId: 1, UniId: 0, FlowId: 100, PortNo: 0, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 256, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530843 }
npujarec5762e2020-01-01 14:08:48 +0530844 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
845 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530846 for _, tt := range tests {
847 t.Run(tt.name, func(t *testing.T) {
848
Girish Gowdra9602eb42020-09-09 15:50:39 -0700849 got, err := flowMgr[tt.args.packetIn.IntfId].GetLogicalPortFromPacketIn(ctx, tt.args.packetIn)
kdarapu3248f9a2019-10-03 13:54:52 +0530850 if (err != nil) != tt.wantErr {
851 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() error = %v, wantErr %v", err, tt.wantErr)
852 return
853 }
854 if got != tt.want {
855 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() = %v, want %v", got, tt.want)
856 }
857 })
858 }
859}
860
861func TestOpenOltFlowMgr_GetPacketOutGemPortID(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700862 // Create fresh flowMgr instance
863 flowMgr = newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530864
Esin Karaman7fb80c22020-07-16 14:23:33 +0000865 //untagged packet in hex string
866 untaggedStr := "01005e000002000000000001080046c00020000040000102fa140a000001e00000029404000017000705e10000fa"
867 untagged, err := hex.DecodeString(untaggedStr)
868 if err != nil {
869 t.Error("Unable to parse hex string", err)
870 panic(err)
871 }
Girish Gowdra9602eb42020-09-09 15:50:39 -0700872 //single-tagged packet in hex string. vlanID.pbit: 1.1
873 singleTaggedStr := "01005e0000010025ba48172481002001080046c0002000004000010257deab140023e0000001940400001164ee9b0000000000000000000000000000"
Esin Karaman7fb80c22020-07-16 14:23:33 +0000874 singleTagged, err := hex.DecodeString(singleTaggedStr)
875 if err != nil {
876 t.Error("Unable to parse hex string", err)
877 panic(err)
878 }
Girish Gowdra9602eb42020-09-09 15:50:39 -0700879 //double-tagged packet in hex string. vlanID.pbit: 210.0-0.0
880 doubleTaggedStr := "01005e000016deadbeefba118100021081000000080046000028000000000102c5b87f000001e0000016940400002200f8030000000104000000e10000fa"
Esin Karaman7fb80c22020-07-16 14:23:33 +0000881 doubleTagged, err := hex.DecodeString(doubleTaggedStr)
882 if err != nil {
883 t.Error("Unable to parse hex string", err)
884 panic(err)
885 }
886
kdarapu3248f9a2019-10-03 13:54:52 +0530887 type args struct {
888 intfID uint32
889 onuID uint32
890 portNum uint32
Esin Karaman7fb80c22020-07-16 14:23:33 +0000891 packet []byte
kdarapu3248f9a2019-10-03 13:54:52 +0530892 }
893 tests := []struct {
894 name string
895 args args
896 want uint32
897 wantErr bool
898 }{
899 // TODO: Add test cases.
Girish Gowdra9602eb42020-09-09 15:50:39 -0700900 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: untagged}, 1, false},
901 {"GetPacketOutGemPortID", args{intfID: 1, onuID: 2, portNum: 2, packet: singleTagged}, 2, false},
902 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: doubleTagged}, 1, false},
903 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 10, portNum: 10, packet: untagged}, 2, true},
904 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 3, packet: []byte{}}, 3, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530905 }
Esin Karaman7fb80c22020-07-16 14:23:33 +0000906
npujarec5762e2020-01-01 14:08:48 +0530907 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
908 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530909 for _, tt := range tests {
910 t.Run(tt.name, func(t *testing.T) {
911
Girish Gowdra9602eb42020-09-09 15:50:39 -0700912 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 +0000913 if tt.wantErr {
914 if err == nil {
915 //error expected but got value
916 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, wantErr %v", got, tt.wantErr)
917 }
918 } else {
919 if err != nil {
920 //error is not expected but got error
921 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() error = %v, wantErr %v", err, tt.wantErr)
922 return
923 }
924 if got != tt.want {
925 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, want %v", got, tt.want)
926 }
kdarapu3248f9a2019-10-03 13:54:52 +0530927 }
kdarapu3248f9a2019-10-03 13:54:52 +0530928 })
929 }
930}
931
932func TestOpenOltFlowMgr_DeleteTechProfileInstance(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530933 type args struct {
934 intfID uint32
935 onuID uint32
936 uniID uint32
937 sn string
Gamze Abakafee36392019-10-03 11:17:24 +0000938 tpID uint32
kdarapu3248f9a2019-10-03 13:54:52 +0530939 }
940 tests := []struct {
941 name string
942 args args
943 wantErr bool
944 }{
945 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000946 {"DeleteTechProfileInstance", args{intfID: 0, onuID: 1, uniID: 1, sn: "", tpID: 64}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530947 }
npujarec5762e2020-01-01 14:08:48 +0530948 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
949 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530950 for _, tt := range tests {
951 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700952 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 +0530953 t.Errorf("OpenOltFlowMgr.DeleteTechProfileInstance() error = %v, wantErr %v", err, tt.wantErr)
954 }
955 })
956 }
957}
kdarapub26b4502019-10-05 03:02:33 +0530958
959func TestOpenOltFlowMgr_checkAndAddFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000960 ctx := context.Background()
kdarapub26b4502019-10-05 03:02:33 +0530961 kw := make(map[string]uint64)
962 kw["table_id"] = 1
963 kw["meter_id"] = 1
964 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
965
966 // Upstream flow
967 fa := &fu.FlowArgs{
968 MatchFields: []*ofp.OfpOxmOfbField{
969 fu.InPort(536870912),
970 fu.Metadata_ofp(1),
971 fu.IpProto(17), // dhcp
Gamze Abakafee36392019-10-03 11:17:24 +0000972 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300973 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530974 },
975 Actions: []*ofp.OfpAction{
976 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
977 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700978 fu.Output(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530979 fu.PushVlan(0x8100),
980 },
981 KV: kw,
982 }
983
984 // EAPOL
985 fa2 := &fu.FlowArgs{
986 MatchFields: []*ofp.OfpOxmOfbField{
987 fu.InPort(536870912),
988 fu.Metadata_ofp(1),
989 fu.EthType(0x888E),
990 fu.VlanPcp(1),
991 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
992 },
993 Actions: []*ofp.OfpAction{
994 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
995 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700996 fu.Output(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530997 fu.PushVlan(0x8100),
998 },
999 KV: kw,
1000 }
1001
1002 // HSIA
1003 fa3 := &fu.FlowArgs{
1004 MatchFields: []*ofp.OfpOxmOfbField{
1005 fu.InPort(536870912),
1006 fu.Metadata_ofp(1),
1007 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001008 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +05301009 },
1010 Actions: []*ofp.OfpAction{
1011 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001012 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001013 fu.Output(16777216),
kdarapub26b4502019-10-05 03:02:33 +05301014 fu.PushVlan(0x8100),
1015 },
1016 KV: kw,
1017 }
1018
1019 fa4 := &fu.FlowArgs{
1020 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001021 fu.InPort(16777216),
kdarapub26b4502019-10-05 03:02:33 +05301022 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001023 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +05301024 fu.VlanPcp(1),
1025 },
1026 Actions: []*ofp.OfpAction{
1027 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001028 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
kdarapub26b4502019-10-05 03:02:33 +05301029 fu.Output(536870912),
1030 fu.PopVlan(),
1031 },
1032 KV: kw,
1033 }
1034
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001035 // PPPOED
1036 pppoedFA := &fu.FlowArgs{
1037 MatchFields: []*ofp.OfpOxmOfbField{
1038 fu.InPort(536870912),
1039 fu.Metadata_ofp(1),
1040 fu.EthType(0x8863),
1041 fu.VlanPcp(1),
1042 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
1043 },
1044 Actions: []*ofp.OfpAction{
1045 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001046 fu.Output(16777216),
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001047 fu.PushVlan(0x8100),
1048 },
1049 KV: kw,
1050 }
1051
kdarapub26b4502019-10-05 03:02:33 +05301052 classifierInfo := make(map[string]interface{})
1053 actionInfo := make(map[string]interface{})
1054 classifierInfo2 := make(map[string]interface{})
1055 actionInfo2 := make(map[string]interface{})
1056 classifierInfo3 := make(map[string]interface{})
1057 actionInfo3 := make(map[string]interface{})
1058 classifierInfo4 := make(map[string]interface{})
1059 actionInfo4 := make(map[string]interface{})
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001060 classifierInfo5 := make(map[string]interface{})
1061 actionInfo5 := make(map[string]interface{})
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001062 flow, _ := fu.MkFlowStat(fa)
1063 flow2, _ := fu.MkFlowStat(fa2)
1064 flow3, _ := fu.MkFlowStat(fa3)
1065 flow4, _ := fu.MkFlowStat(fa4)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001066 flow5, _ := fu.MkFlowStat(pppoedFA)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001067 formulateClassifierInfoFromFlow(ctx, classifierInfo, flow)
1068 formulateClassifierInfoFromFlow(ctx, classifierInfo2, flow2)
1069 formulateClassifierInfoFromFlow(ctx, classifierInfo3, flow3)
1070 formulateClassifierInfoFromFlow(ctx, classifierInfo4, flow4)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001071 formulateClassifierInfoFromFlow(ctx, classifierInfo5, flow5)
kdarapub26b4502019-10-05 03:02:33 +05301072
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001073 err := formulateActionInfoFromFlow(ctx, actionInfo, classifierInfo, flow)
kdarapub26b4502019-10-05 03:02:33 +05301074 if err != nil {
1075 // Error logging is already done in the called function
1076 // So just return in case of error
1077 return
1078 }
1079
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001080 err = formulateActionInfoFromFlow(ctx, actionInfo2, classifierInfo2, flow2)
kdarapub26b4502019-10-05 03:02:33 +05301081 if err != nil {
1082 // Error logging is already done in the called function
1083 // So just return in case of error
1084 return
1085 }
1086
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001087 err = formulateActionInfoFromFlow(ctx, actionInfo3, classifierInfo3, flow3)
kdarapub26b4502019-10-05 03:02:33 +05301088 if err != nil {
1089 // Error logging is already done in the called function
1090 // So just return in case of error
1091 return
1092 }
1093
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001094 err = formulateActionInfoFromFlow(ctx, actionInfo4, classifierInfo4, flow4)
kdarapub26b4502019-10-05 03:02:33 +05301095 if err != nil {
1096 // Error logging is already done in the called function
1097 // So just return in case of error
1098 return
1099 }
1100
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001101 err = formulateActionInfoFromFlow(ctx, actionInfo5, classifierInfo5, flow5)
1102 if err != nil {
1103 // Error logging is already done in the called function
1104 // So just return in case of error
1105 return
1106 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001107 /*
1108 usGemList := make([]*tp_pb.GemPortAttributes, 4)
1109 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1110 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1111 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1112 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1113 dsGemList := make([]*tp_pb.GemPortAttributes, 4)
1114 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1115 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1116 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1117 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1118 */
1119 TpInst := &tp_pb.TechProfileInstance{
kdarapub26b4502019-10-05 03:02:33 +05301120 Name: "Test-Tech-Profile",
1121 SubscriberIdentifier: "257",
1122 ProfileType: "Mock",
1123 Version: 1,
1124 NumGemPorts: 4,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001125 InstanceControl: &tp_pb.InstanceControl{
kdarapub26b4502019-10-05 03:02:33 +05301126 Onu: "1",
1127 Uni: "16",
1128 },
khenaidoodc2116e2021-10-19 17:33:19 -04001129 UsScheduler: &tp_pb.SchedulerAttributes{},
1130 DsScheduler: &tp_pb.SchedulerAttributes{},
kdarapub26b4502019-10-05 03:02:33 +05301131 }
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001132 TpInst.UsScheduler.Priority = 1
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001133 TpInst.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
1134 TpInst.UsScheduler.AllocId = 1
1135 TpInst.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
1136 TpInst.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001137 TpInst.UsScheduler.Weight = 4
1138
1139 TpInst.DsScheduler.Priority = 1
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001140 TpInst.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
1141 TpInst.DsScheduler.AllocId = 1
1142 TpInst.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
1143 TpInst.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001144 TpInst.DsScheduler.Weight = 4
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001145 TpInst.UpstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
1146 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
1147 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
1148 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
1149 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001150
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001151 TpInst.DownstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
1152 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
1153 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
1154 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
1155 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
kdarapub26b4502019-10-05 03:02:33 +05301156
kdarapub26b4502019-10-05 03:02:33 +05301157 type args struct {
1158 args map[string]uint32
1159 classifierInfo map[string]interface{}
1160 actionInfo map[string]interface{}
1161 flow *ofp.OfpFlowStats
1162 gemPort uint32
1163 intfID uint32
1164 onuID uint32
1165 uniID uint32
1166 portNo uint32
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001167 TpInst *tp_pb.TechProfileInstance
kdarapub26b4502019-10-05 03:02:33 +05301168 allocID []uint32
1169 gemPorts []uint32
1170 TpID uint32
1171 uni string
1172 }
1173 tests := []struct {
Kent Hagermane6ff1012020-07-14 15:07:53 -04001174 name string
1175 args args
kdarapub26b4502019-10-05 03:02:33 +05301176 }{
1177 {
1178 name: "checkAndAddFlow-1",
1179 args: args{
1180 args: nil,
1181 classifierInfo: classifierInfo,
1182 actionInfo: actionInfo,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001183 flow: flow,
kdarapub26b4502019-10-05 03:02:33 +05301184 gemPort: 1,
1185 intfID: 1,
1186 onuID: 1,
1187 uniID: 16,
1188 portNo: 1,
1189 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001190 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301191 gemPorts: []uint32{1, 2, 3, 4},
1192 TpID: 64,
1193 uni: "16",
1194 },
1195 },
1196 {
1197 name: "checkAndAddFlow-2",
1198 args: args{
1199 args: nil,
1200 classifierInfo: classifierInfo2,
1201 actionInfo: actionInfo2,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001202 flow: flow2,
kdarapub26b4502019-10-05 03:02:33 +05301203 gemPort: 1,
1204 intfID: 1,
1205 onuID: 1,
1206 uniID: 16,
1207 portNo: 1,
1208 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001209 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301210 gemPorts: []uint32{1, 2, 3, 4},
1211 TpID: 64,
1212 uni: "16",
1213 },
1214 },
1215 {
1216 name: "checkAndAddFlow-3",
1217 args: args{
1218 args: nil,
1219 classifierInfo: classifierInfo3,
1220 actionInfo: actionInfo3,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001221 flow: flow3,
kdarapub26b4502019-10-05 03:02:33 +05301222 gemPort: 1,
1223 intfID: 1,
1224 onuID: 1,
1225 uniID: 16,
1226 portNo: 1,
1227 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001228 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301229 gemPorts: []uint32{1, 2, 3, 4},
1230 TpID: 64,
1231 uni: "16",
1232 },
1233 },
1234 {
1235 name: "checkAndAddFlow-4",
1236 args: args{
1237 args: nil,
1238 classifierInfo: classifierInfo4,
1239 actionInfo: actionInfo4,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001240 flow: flow4,
kdarapub26b4502019-10-05 03:02:33 +05301241 gemPort: 1,
1242 intfID: 1,
1243 onuID: 1,
1244 uniID: 16,
1245 portNo: 1,
1246 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001247 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301248 gemPorts: []uint32{1, 2, 3, 4},
1249 TpID: 64,
1250 uni: "16",
1251 },
1252 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001253 {
1254 name: "checkAndAddFlow-5",
1255 args: args{
1256 args: nil,
1257 classifierInfo: classifierInfo5,
1258 actionInfo: actionInfo5,
1259 flow: flow5,
1260 gemPort: 1,
1261 intfID: 1,
1262 onuID: 1,
1263 uniID: 16,
1264 portNo: 1,
1265 TpInst: TpInst,
1266 allocID: []uint32{0x8001},
1267 gemPorts: []uint32{1, 2, 3, 4},
1268 TpID: 64,
1269 uni: "16",
1270 },
1271 },
kdarapub26b4502019-10-05 03:02:33 +05301272 }
npujarec5762e2020-01-01 14:08:48 +05301273 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1274 defer cancel()
kdarapub26b4502019-10-05 03:02:33 +05301275 for _, tt := range tests {
1276 t.Run(tt.name, func(t *testing.T) {
Gamze Abaka6d0a64f2021-11-18 08:08:33 +00001277 err := 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 +00001278 tt.args.TpInst, tt.args.gemPorts, tt.args.TpID, tt.args.uni)
Gamze Abaka6d0a64f2021-11-18 08:08:33 +00001279 if err != nil {
1280 t.Error("check-and-add-flow failed", err)
1281 return
1282 }
kdarapub26b4502019-10-05 03:02:33 +05301283 })
1284 }
1285}
Esin Karamanccb714b2019-11-29 15:02:06 +00001286
Esin Karamand519bbf2020-07-01 11:16:03 +00001287func TestOpenOltFlowMgr_TestMulticastFlowAndGroup(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301288 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1289 defer cancel()
Esin Karamanccb714b2019-11-29 15:02:06 +00001290 //create group
1291 group := newGroup(2, []uint32{1})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001292 err := flowMgr[0].grpMgr.AddGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001293 if err != nil {
1294 t.Error("group-add failed", err)
1295 return
1296 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001297 //create multicast flow
1298 multicastFlowArgs := &fu.FlowArgs{
1299 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001300 fu.InPort(16777216),
Esin Karamanccb714b2019-11-29 15:02:06 +00001301 fu.VlanVid(660), //vlan
1302 fu.Metadata_ofp(uint64(66)), //inner vlan
1303 fu.EthType(0x800), //ipv4
1304 fu.Ipv4Dst(3809869825), //227.22.0.1
1305 },
1306 Actions: []*ofp.OfpAction{
1307 fu.Group(1),
1308 },
1309 }
divyadesaid26f6b12020-03-19 06:30:28 +00001310 ofpStats, _ := fu.MkFlowStat(multicastFlowArgs)
Esin Karamand519bbf2020-07-01 11:16:03 +00001311 fmt.Println(ofpStats.Id)
khenaidoodc2116e2021-10-19 17:33:19 -04001312 err = flowMgr[0].AddFlow(ctx, ofpStats, &ofp.FlowMetadata{})
Esin Karamand519bbf2020-07-01 11:16:03 +00001313 if err != nil {
1314 t.Error("Multicast flow-add failed", err)
1315 return
1316 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001317
1318 //add bucket to the group
1319 group = newGroup(2, []uint32{1, 2})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001320 err = flowMgr[0].grpMgr.ModifyGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001321 if err != nil {
1322 t.Error("modify-group failed", err)
1323 return
1324 }
1325 //remove the multicast flow
Girish Gowdra9602eb42020-09-09 15:50:39 -07001326 err = flowMgr[0].RemoveFlow(ctx, ofpStats)
Esin Karamand519bbf2020-07-01 11:16:03 +00001327 if err != nil {
1328 t.Error("Multicast flow-remove failed", err)
1329 return
1330 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001331
Esin Karamand519bbf2020-07-01 11:16:03 +00001332 //remove the group
Girish Gowdra9602eb42020-09-09 15:50:39 -07001333 err = flowMgr[0].grpMgr.DeleteGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001334 if err != nil {
1335 t.Error("delete-group failed", err)
1336 return
1337 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001338}
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001339
1340func TestOpenOltFlowMgr_TestRouteFlowToOnuChannel(t *testing.T) {
1341 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1342 defer cancel()
1343 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/core", log.DebugLevel)
1344 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager", log.DebugLevel)
1345 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/pkg/mocks", log.DebugLevel)
Girish Gowdra0aca4982021-01-04 12:44:27 -08001346 kwTable1Meter1 := make(map[string]uint64)
1347 kwTable1Meter1["table_id"] = 1
1348 kwTable1Meter1["meter_id"] = 1
1349 kwTable1Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
1350
1351 kwTable0Meter1 := make(map[string]uint64)
1352 kwTable0Meter1["table_id"] = 0
1353 kwTable0Meter1["meter_id"] = 1
1354 kwTable0Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001355
khenaidoodc2116e2021-10-19 17:33:19 -04001356 flowMetadata1 := ofp.FlowMetadata{Meters: []*ofp.OfpMeterConfig{
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001357 {
1358 Flags: 5,
1359 MeterId: 1,
khenaidoodc2116e2021-10-19 17:33:19 -04001360 Bands: []*ofp.OfpMeterBandHeader{
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001361 {
khenaidoodc2116e2021-10-19 17:33:19 -04001362 Type: ofp.OfpMeterBandType_OFPMBT_DROP,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001363 Rate: 16000,
Gamze Abaka01174422021-03-10 06:55:27 +00001364 BurstSize: 0,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001365 },
1366 {
khenaidoodc2116e2021-10-19 17:33:19 -04001367 Type: ofp.OfpMeterBandType_OFPMBT_DROP,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001368 Rate: 32000,
1369 BurstSize: 30,
1370 },
1371 {
khenaidoodc2116e2021-10-19 17:33:19 -04001372 Type: ofp.OfpMeterBandType_OFPMBT_DROP,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001373 Rate: 64000,
1374 BurstSize: 30,
1375 },
1376 },
1377 },
1378 }}
1379
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001380 // Downstream LLDP Trap from NNI0 flow
1381 fa0 := &fu.FlowArgs{
1382 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001383 fu.InPort(16777216),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001384 fu.EthType(35020),
1385 },
1386 Actions: []*ofp.OfpAction{
1387 fu.Output(4294967293),
1388 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001389 KV: make(map[string]uint64),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001390 }
1391
1392 // Upstream flow DHCP flow - ONU1 UNI0 PON0
1393 fa1 := &fu.FlowArgs{
1394 MatchFields: []*ofp.OfpOxmOfbField{
1395 fu.InPort(536870912),
1396 fu.Metadata_ofp(1),
1397 fu.IpProto(17), // dhcp
1398 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001399 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001400 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001401 },
1402 Actions: []*ofp.OfpAction{
1403 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1404 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1405 fu.Output(2147483645),
1406 fu.PushVlan(0x8100),
1407 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001408 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001409 }
1410
1411 // Upstream EAPOL - ONU1 UNI0 PON0
1412 fa2 := &fu.FlowArgs{
1413 MatchFields: []*ofp.OfpOxmOfbField{
1414 fu.InPort(536870912),
1415 fu.Metadata_ofp(1),
1416 fu.EthType(0x888E),
1417 fu.VlanPcp(1),
1418 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001419 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001420 },
1421 Actions: []*ofp.OfpAction{
1422 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1423 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1424 fu.Output(2147483645),
1425 fu.PushVlan(0x8100),
1426 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001427 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001428 }
1429
1430 // Upstream HSIA - ONU1 UNI0 PON0
1431 fa3 := &fu.FlowArgs{
1432 MatchFields: []*ofp.OfpOxmOfbField{
1433 fu.InPort(536870912),
1434 fu.Metadata_ofp(1),
1435 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001436 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001437 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001438 },
1439 Actions: []*ofp.OfpAction{
1440 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001441 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001442 fu.Output(16777216),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001443 fu.PushVlan(0x8100),
1444 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001445 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001446 }
1447
1448 // Downstream HSIA - ONU1 UNI0 PON0
1449 fa4 := &fu.FlowArgs{
1450 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001451 fu.InPort(16777216),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001452 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001453 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001454 fu.VlanPcp(1),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001455 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001456 },
1457 Actions: []*ofp.OfpAction{
1458 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001459 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001460 fu.Output(536870912),
1461 fu.PopVlan(),
1462 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001463 KV: kwTable0Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001464 }
1465
1466 // Upstream flow DHCP flow - ONU1 UNI0 PON15
1467 fa5 := &fu.FlowArgs{
1468 MatchFields: []*ofp.OfpOxmOfbField{
1469 fu.InPort(536870927),
1470 fu.Metadata_ofp(1),
1471 fu.IpProto(17), // dhcp
1472 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001473 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001474 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001475 },
1476 Actions: []*ofp.OfpAction{
1477 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1478 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259)),
1479 fu.Output(2147483645),
1480 fu.PushVlan(0x8100),
1481 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001482 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001483 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001484
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001485 // Upstream EAPOL - ONU1 UNI0 PON15
1486 fa6 := &fu.FlowArgs{
1487 MatchFields: []*ofp.OfpOxmOfbField{
1488 fu.InPort(536870927),
1489 fu.Metadata_ofp(1),
1490 fu.EthType(0x888E),
1491 fu.VlanPcp(1),
1492 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001493 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001494 },
1495 Actions: []*ofp.OfpAction{
1496 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1497 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1498 fu.Output(2147483645),
1499 fu.PushVlan(0x8100),
1500 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001501 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001502 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001503
1504 // Upstream PPPOED - ONU1 UNI0 PON0
1505 fa7 := &fu.FlowArgs{
1506 MatchFields: []*ofp.OfpOxmOfbField{
1507 fu.InPort(536870912),
1508 fu.Metadata_ofp(1),
1509 fu.EthType(0x8863),
1510 fu.VlanPcp(1),
1511 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001512 fu.TunnelId(256),
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001513 },
1514 Actions: []*ofp.OfpAction{
1515 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1516 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1517 fu.Output(2147483645),
1518 fu.PushVlan(0x8100),
1519 },
1520 KV: kwTable1Meter1,
1521 }
1522
1523 // Upstream PPPOED - ONU1 UNI0 PON15
1524 fa8 := &fu.FlowArgs{
1525 MatchFields: []*ofp.OfpOxmOfbField{
1526 fu.InPort(536870927),
1527 fu.Metadata_ofp(1),
1528 fu.EthType(0x8863),
1529 fu.VlanPcp(1),
1530 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001531 fu.TunnelId(256),
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001532 },
1533 Actions: []*ofp.OfpAction{
1534 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1535 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1536 fu.Output(2147483645),
1537 fu.PushVlan(0x8100),
1538 },
1539 KV: kwTable1Meter1,
1540 }
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001541 flow0, _ := fu.MkFlowStat(fa0)
1542 flow1, _ := fu.MkFlowStat(fa1)
1543 flow2, _ := fu.MkFlowStat(fa2)
1544 flow3, _ := fu.MkFlowStat(fa3)
1545 flow4, _ := fu.MkFlowStat(fa4)
1546
1547 flow5, _ := fu.MkFlowStat(fa5)
1548 flow6, _ := fu.MkFlowStat(fa6)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001549 flow7, _ := fu.MkFlowStat(fa7)
1550 flow8, _ := fu.MkFlowStat(fa8)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001551
1552 type args struct {
1553 ctx context.Context
1554 flow *ofp.OfpFlowStats
1555 addFlow bool
khenaidoodc2116e2021-10-19 17:33:19 -04001556 flowMetadata *ofp.FlowMetadata
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001557 }
1558 tests := []struct {
1559 name string
1560 args args
1561 wantErr bool
1562 returnedErr error
1563 }{
1564 {
1565 name: "RouteFlowToOnuChannel-0",
1566 args: args{
1567 ctx: ctx,
1568 flow: flow0,
1569 addFlow: true,
1570 flowMetadata: &flowMetadata1,
1571 },
1572 wantErr: false,
1573 },
1574 {
1575 name: "RouteFlowToOnuChannel-1",
1576 args: args{
1577 ctx: ctx,
1578 flow: flow1,
1579 addFlow: true,
1580 flowMetadata: &flowMetadata1,
1581 },
1582 wantErr: false,
1583 },
1584 {
1585 name: "RouteFlowToOnuChannel-2",
1586 args: args{
1587 ctx: ctx,
1588 flow: flow2,
1589 addFlow: true,
1590 flowMetadata: &flowMetadata1,
1591 },
1592 wantErr: false,
1593 },
1594 {
1595 name: "RouteFlowToOnuChannel-3",
1596 args: args{
1597 ctx: ctx,
1598 flow: flow3,
1599 addFlow: true,
1600 flowMetadata: &flowMetadata1,
1601 },
1602 wantErr: false,
1603 },
1604 {
1605 name: "RouteFlowToOnuChannel-4",
1606 args: args{
1607 ctx: ctx,
1608 flow: flow4,
1609 addFlow: true,
1610 flowMetadata: &flowMetadata1,
1611 },
1612 wantErr: false,
1613 },
1614 {
1615 name: "RouteFlowToOnuChannel-5",
1616 args: args{
1617 ctx: ctx,
1618 flow: flow1,
1619 addFlow: false,
1620 flowMetadata: &flowMetadata1,
1621 },
1622 wantErr: false,
1623 },
1624 {
1625 name: "RouteFlowToOnuChannel-6",
1626 args: args{
1627 ctx: ctx,
1628 flow: flow1,
1629 addFlow: true,
Girish Gowdra0aca4982021-01-04 12:44:27 -08001630 flowMetadata: &flowMetadata1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001631 },
Girish Gowdrad23ce662021-10-20 16:48:28 -07001632 wantErr: false,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001633 },
1634 {
1635 name: "RouteFlowToOnuChannel-7",
1636 args: args{
1637 ctx: ctx,
1638 flow: flow5,
1639 addFlow: true,
1640 flowMetadata: &flowMetadata1,
1641 },
1642 wantErr: false,
1643 },
1644 {
1645 name: "RouteFlowToOnuChannel-8",
1646 args: args{
1647 ctx: ctx,
1648 flow: flow6,
1649 addFlow: true,
1650 flowMetadata: &flowMetadata1,
1651 },
1652 wantErr: false,
1653 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001654 {
1655 name: "RouteFlowToOnuChannel-9",
1656 args: args{
1657 ctx: ctx,
1658 flow: flow7,
1659 addFlow: true,
1660 flowMetadata: &flowMetadata1,
1661 },
1662 wantErr: false,
1663 },
1664 {
1665 name: "RouteFlowToOnuChannel-10",
1666 args: args{
1667 ctx: ctx,
1668 flow: flow8,
1669 addFlow: true,
1670 flowMetadata: &flowMetadata1,
1671 },
1672 wantErr: false,
1673 },
Girish Gowdra5c00ef12021-12-01 17:19:41 +05301674 {
1675 name: "RouteFlowToOnuChannel-11", // Test Remove trap-from-nni LLDP flow
1676 args: args{
1677 ctx: ctx,
1678 flow: flow0,
1679 addFlow: false,
1680 flowMetadata: &flowMetadata1,
1681 },
1682 wantErr: false,
1683 },
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001684 }
1685
1686 var wg sync.WaitGroup
1687 defer wg.Wait() // wait for all go routines to complete
1688 for _, tt := range tests {
Girish Gowdrad23ce662021-10-20 16:48:28 -07001689 wg.Add(1) // one per go routine
1690 // 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
1691 // This delay is needed so that flows arrive in order. Otherwise if all flows are pushed at once the go routine can get scheduled
1692 // in random order causing flows to come out of order and test fails
1693 time.Sleep(5 * time.Millisecond)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001694 t.Run(tt.name, func(t *testing.T) {
Girish Gowdrad23ce662021-10-20 16:48:28 -07001695 defer wg.Done()
1696 tt.returnedErr = flowMgr[0].RouteFlowToOnuChannel(tt.args.ctx, tt.args.flow, tt.args.addFlow, tt.args.flowMetadata)
1697 if (tt.wantErr == false && tt.returnedErr != nil) || (tt.wantErr == true && tt.returnedErr == nil) {
1698 t.Errorf("OpenOltFlowMgr.RouteFlowToOnuChannel() error = %v, wantErr %v", tt.returnedErr, tt.wantErr)
1699 }
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001700 })
1701 }
1702}