blob: af7b1476b7b01246196d751eb3e3612c02f103da [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 Gowdra8a0bdcd2021-05-13 12:31:04 -0700101 {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 0, Upstream)}, false},
102 {"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 +0000103 {"CreateSchedulerQueues-3", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, createFlowMetadata(tprofile, 2, Upstream)}, true},
104 {"CreateSchedulerQueues-4", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, createFlowMetadata(tprofile2, 2, Downstream)}, true},
105 {"CreateSchedulerQueues-5", schedQueue{tp_pb.Direction_UPSTREAM, 1, 2, 2, 64, 2, tprofile, 2, createFlowMetadata(tprofile, 3, Upstream)}, true},
106 {"CreateSchedulerQueues-6", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 2, 2, 65, 2, tprofile2, 2, createFlowMetadata(tprofile2, 3, Downstream)}, true},
107
kdarapu3248f9a2019-10-03 13:54:52 +0530108 //Negative testcases
khenaidoodc2116e2021-10-19 17:33:19 -0400109 {"CreateSchedulerQueues-7", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, &ofp.FlowMetadata{}}, false},
110 {"CreateSchedulerQueues-8", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 0, &ofp.FlowMetadata{}}, true},
111 {"CreateSchedulerQueues-9", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, &ofp.FlowMetadata{}}, false},
112 {"CreateSchedulerQueues-10", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, &ofp.FlowMetadata{}}, true},
113 {"CreateSchedulerQueues-11", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, &ofp.FlowMetadata{}}, true},
Girish Gowdra9602eb42020-09-09 15:50:39 -0700114 {"CreateSchedulerQueues-12", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, nil}, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530115 }
npujarec5762e2020-01-01 14:08:48 +0530116 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
117 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530118 for _, tt := range tests {
119 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700120 if err := flowMgr[tt.schedQueue.intfID].CreateSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530121 t.Errorf("OpenOltFlowMgr.CreateSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr)
122 }
123 })
124 }
125}
126
khenaidoodc2116e2021-10-19 17:33:19 -0400127func createFlowMetadata(techProfile *tp_pb.TechProfileInstance, tcontType int, direction string) *ofp.FlowMetadata {
128 var additionalBw tp_pb.AdditionalBW
Gamze Abaka01174422021-03-10 06:55:27 +0000129 bands := make([]*ofp.OfpMeterBandHeader, 0)
130 switch tcontType {
131 case 1:
132 //tcont-type-1
133 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
134 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 -0700135 additionalBw = tp_pb.AdditionalBW_AdditionalBW_None
Gamze Abaka01174422021-03-10 06:55:27 +0000136 case 2:
137 //tcont-type-2
138 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 60000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
139 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 -0700140 additionalBw = tp_pb.AdditionalBW_AdditionalBW_None
Gamze Abaka01174422021-03-10 06:55:27 +0000141 case 3:
142 //tcont-type-3
143 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
144 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 -0700145 additionalBw = tp_pb.AdditionalBW_AdditionalBW_NA
Gamze Abaka01174422021-03-10 06:55:27 +0000146 case 4:
147 //tcont-type-4
148 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 -0700149 additionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
Gamze Abaka01174422021-03-10 06:55:27 +0000150 case 5:
151 //tcont-type-5
152 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
153 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
154 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 -0700155 additionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
Gamze Abaka01174422021-03-10 06:55:27 +0000156 default:
157 // do nothing, we will return meter config with no meter bands
158 }
159
160 if direction == Downstream {
161 techProfile.DsScheduler.AdditionalBw = additionalBw
162 } else {
163 techProfile.UsScheduler.AdditionalBw = additionalBw
164 }
165
166 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
khenaidoodc2116e2021-10-19 17:33:19 -0400167 return &ofp.FlowMetadata{
Gamze Abaka01174422021-03-10 06:55:27 +0000168 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}}
169}
170
kdarapu3248f9a2019-10-03 13:54:52 +0530171func TestOpenOltFlowMgr_RemoveSchedulerQueues(t *testing.T) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700172 tprofile := &tp_pb.TechProfileInstance{Name: "tp1", SubscriberIdentifier: "subscriber1",
Girish Gowdra54934262019-11-13 14:19:55 +0530173 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700174 InstanceControl: &tp_pb.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"},
kdarapu3248f9a2019-10-03 13:54:52 +0530175 }
khenaidoodc2116e2021-10-19 17:33:19 -0400176 tprofile.UsScheduler = &tp_pb.SchedulerAttributes{}
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700177 tprofile.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
178 tprofile.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
179 tprofile.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +0530180
181 tprofile2 := tprofile
khenaidoodc2116e2021-10-19 17:33:19 -0400182 tprofile2.DsScheduler = &tp_pb.SchedulerAttributes{}
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700183 tprofile2.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
184 tprofile2.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
185 tprofile2.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +0530186 //defTprofile := &tp.DefaultTechProfile{}
kdarapu3248f9a2019-10-03 13:54:52 +0530187 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +0000188 name string
189 schedQueue schedQueue
190 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +0530191 }{
192 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000193 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 0, nil}, false},
194 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530195 // negative test cases
Gamze Abakafee36392019-10-03 11:17:24 +0000196 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
197 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530198 }
npujarec5762e2020-01-01 14:08:48 +0530199 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
200 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530201 for _, tt := range tests {
202 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700203 if err := flowMgr[tt.schedQueue.intfID].RemoveSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530204 t.Errorf("OpenOltFlowMgr.RemoveSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr)
205 }
206 })
207 }
kdarapub26b4502019-10-05 03:02:33 +0530208
kdarapu3248f9a2019-10-03 13:54:52 +0530209}
210
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700211func TestOpenOltFlowMgr_createTcontGemports(t *testing.T) {
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700212 bands := make([]*ofp.OfpMeterBandHeader, 2)
213 bands[0] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 1000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
214 bands[1] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 2000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
215 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
khenaidoodc2116e2021-10-19 17:33:19 -0400216 flowmetadata := &ofp.FlowMetadata{
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700217 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
218 }
219 type args struct {
220 intfID uint32
221 onuID uint32
222 uniID uint32
223 uni string
224 uniPort uint32
225 TpID uint32
226 UsMeterID uint32
227 DsMeterID uint32
khenaidoodc2116e2021-10-19 17:33:19 -0400228 flowMetadata *ofp.FlowMetadata
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700229 }
230 tests := []struct {
231 name string
232 args args
233 }{
234 {"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 -0700235 }
236 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
237 defer cancel()
238 for _, tt := range tests {
239 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700240 _, _, 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 -0700241 switch tpInst := tpInst.(type) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700242 case *tp_pb.TechProfileInstance:
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700243 if tt.args.TpID != 64 {
244 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
245 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700246 case *tp_pb.EponTechProfileInstance:
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700247 if tt.args.TpID != 65 {
248 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
249 }
250 default:
251 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
252 }
253 })
254 }
255}
256
kdarapu3248f9a2019-10-03 13:54:52 +0530257func TestOpenOltFlowMgr_RemoveFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000258 ctx := context.Background()
Neha Sharma96b7bf22020-06-15 10:37:32 +0000259 logger.Debug(ctx, "Info Warning Error: Starting RemoveFlow() test")
kdarapu3248f9a2019-10-03 13:54:52 +0530260 fa := &fu.FlowArgs{
261 MatchFields: []*ofp.OfpOxmOfbField{
262 fu.InPort(2),
263 fu.Metadata_ofp(2),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300264 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapu3248f9a2019-10-03 13:54:52 +0530265 },
266 Actions: []*ofp.OfpAction{
267 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
268 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
269 fu.Output(1),
270 },
271 }
divyadesaid26f6b12020-03-19 06:30:28 +0000272 ofpstats, _ := fu.MkFlowStat(fa)
kdarapub26b4502019-10-05 03:02:33 +0530273 ofpstats.Cookie = ofpstats.Id
kdarapub26b4502019-10-05 03:02:33 +0530274 lldpFa := &fu.FlowArgs{
275 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
276 MatchFields: []*ofp.OfpOxmOfbField{
277 fu.InPort(1),
278 fu.EthType(0x88CC),
279 fu.TunnelId(536870912),
280 },
281 Actions: []*ofp.OfpAction{
282 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
283 },
284 }
divyadesaid26f6b12020-03-19 06:30:28 +0000285 lldpofpstats, _ := fu.MkFlowStat(lldpFa)
kdarapub26b4502019-10-05 03:02:33 +0530286 //lldpofpstats.Cookie = lldpofpstats.Id
287
288 dhcpFa := &fu.FlowArgs{
289 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
290 MatchFields: []*ofp.OfpOxmOfbField{
291 fu.InPort(1),
292 fu.UdpSrc(67),
293 //fu.TunnelId(536870912),
294 fu.IpProto(17),
295 },
296 Actions: []*ofp.OfpAction{
297 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
298 },
299 }
divyadesaid26f6b12020-03-19 06:30:28 +0000300 dhcpofpstats, _ := fu.MkFlowStat(dhcpFa)
kdarapub26b4502019-10-05 03:02:33 +0530301 //dhcpofpstats.Cookie = dhcpofpstats.Id
Esin Karamanccb714b2019-11-29 15:02:06 +0000302
303 //multicast flow
304 multicastFa := &fu.FlowArgs{
305 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700306 fu.InPort(16777216),
Esin Karamanccb714b2019-11-29 15:02:06 +0000307 fu.VlanVid(660), //vlan
308 fu.Metadata_ofp(uint64(66)), //inner vlan
309 fu.EthType(0x800), //ipv4
310 fu.Ipv4Dst(3809869825), //227.22.0.1
311 },
312 Actions: []*ofp.OfpAction{
313 fu.Group(1),
314 },
315 }
divyadesaid26f6b12020-03-19 06:30:28 +0000316 multicastOfpStats, _ := fu.MkFlowStat(multicastFa)
Esin Karamanccb714b2019-11-29 15:02:06 +0000317 multicastOfpStats.Id = 1
318
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300319 pppoedFa := &fu.FlowArgs{
320 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
321 MatchFields: []*ofp.OfpOxmOfbField{
322 fu.InPort(1),
323 fu.EthType(0x8863),
324 fu.TunnelId(536870912),
325 },
326 Actions: []*ofp.OfpAction{
327 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
328 },
329 }
330 pppoedOfpStats, _ := fu.MkFlowStat(pppoedFa)
331
kdarapu3248f9a2019-10-03 13:54:52 +0530332 type args struct {
333 flow *ofp.OfpFlowStats
334 }
335 tests := []struct {
336 name string
337 args args
338 }{
339 // TODO: Add test cases.
340 {"RemoveFlow", args{flow: ofpstats}},
kdarapub26b4502019-10-05 03:02:33 +0530341 {"RemoveFlow", args{flow: lldpofpstats}},
342 {"RemoveFlow", args{flow: dhcpofpstats}},
Esin Karamanccb714b2019-11-29 15:02:06 +0000343 {"RemoveFlow", args{flow: multicastOfpStats}},
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300344 {"RemoveFlow", args{flow: pppoedOfpStats}},
kdarapu3248f9a2019-10-03 13:54:52 +0530345 }
npujarec5762e2020-01-01 14:08:48 +0530346 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
347 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530348 for _, tt := range tests {
349 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700350 if err := flowMgr[0].RemoveFlow(ctx, tt.args.flow); err != nil {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400351 logger.Warn(ctx, err)
352 }
kdarapu3248f9a2019-10-03 13:54:52 +0530353 })
354 }
kdarapub26b4502019-10-05 03:02:33 +0530355 // t.Error("=====")
kdarapu3248f9a2019-10-03 13:54:52 +0530356}
357
358func TestOpenOltFlowMgr_AddFlow(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530359 kw := make(map[string]uint64)
360 kw["table_id"] = 1
361 kw["meter_id"] = 1
kdarapub26b4502019-10-05 03:02:33 +0530362 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
363
364 // Upstream flow
kdarapu3248f9a2019-10-03 13:54:52 +0530365 fa := &fu.FlowArgs{
366 MatchFields: []*ofp.OfpOxmOfbField{
kdarapub26b4502019-10-05 03:02:33 +0530367 fu.InPort(536870912),
368 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300369 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530370 },
371 Actions: []*ofp.OfpAction{
372 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
373 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700374 fu.Output(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530375 fu.PushVlan(0x8100),
376 },
377 KV: kw,
378 }
379
380 // Downstream flow
381 fa3 := &fu.FlowArgs{
382 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700383 fu.InPort(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530384 fu.Metadata_ofp(1),
385 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
386 },
387 Actions: []*ofp.OfpAction{
388 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
389 //fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
390 fu.PopVlan(),
391 fu.Output(536870912),
392 },
393 KV: kw,
394 }
395
396 fa2 := &fu.FlowArgs{
397 MatchFields: []*ofp.OfpOxmOfbField{
kdarapu3248f9a2019-10-03 13:54:52 +0530398 fu.InPort(1000),
399 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300400 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapu3248f9a2019-10-03 13:54:52 +0530401 },
402 Actions: []*ofp.OfpAction{
403 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
404 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
405 fu.Output(65533),
406 },
407 KV: kw,
408 }
409
kdarapub26b4502019-10-05 03:02:33 +0530410 // TODO Add LLDP flow
411 // TODO Add DHCP flow
412
413 // Flows for negative scenarios
414 // Failure in formulateActionInfoFromFlow()
415 fa4 := &fu.FlowArgs{
416 MatchFields: []*ofp.OfpOxmOfbField{
417 fu.InPort(1000),
418 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300419 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530420 },
421 Actions: []*ofp.OfpAction{
422 fu.Experimenter(257, []byte{1, 2, 3, 4}),
423 },
424 KV: kw,
425 }
426
427 // Invalid Output
428 fa5 := &fu.FlowArgs{
429 MatchFields: []*ofp.OfpOxmOfbField{
430 fu.InPort(1000),
431 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300432 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530433 },
434 Actions: []*ofp.OfpAction{
435 fu.Output(0),
436 },
437 KV: kw,
438 }
439
440 // Tech-Profile-ID update (not supported)
441 kw6 := make(map[string]uint64)
442 kw6["table_id"] = 1
443 kw6["meter_id"] = 1
444 kw6["write_metadata"] = 0x4100000000 // TpID Other than the stored one
445 fa6 := &fu.FlowArgs{
446 MatchFields: []*ofp.OfpOxmOfbField{
447 fu.InPort(536870912),
448 fu.TunnelId(16),
449 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300450 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530451 },
452 Actions: []*ofp.OfpAction{
453 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
454 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
455 fu.Output(65535),
456 },
457 KV: kw6,
458 }
459
460 lldpFa := &fu.FlowArgs{
461 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
462 MatchFields: []*ofp.OfpOxmOfbField{
463 fu.InPort(1),
464 fu.EthType(0x88CC),
465 fu.TunnelId(536870912),
466 },
467 Actions: []*ofp.OfpAction{
468 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
469 },
470 }
471
472 dhcpFa := &fu.FlowArgs{
473 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
474 MatchFields: []*ofp.OfpOxmOfbField{
475 fu.InPort(1),
476 fu.UdpSrc(67),
477 //fu.TunnelId(536870912),
478 fu.IpProto(17),
479 },
480 Actions: []*ofp.OfpAction{
481 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
482 },
483 }
484 igmpFa := &fu.FlowArgs{
485 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
486 MatchFields: []*ofp.OfpOxmOfbField{
487 fu.InPort(1),
488 fu.UdpSrc(67),
489 //fu.TunnelId(536870912),
490 fu.IpProto(2),
491 },
492 Actions: []*ofp.OfpAction{
493 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
494 },
495 }
496
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300497 pppoedFa := &fu.FlowArgs{
498 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
499 MatchFields: []*ofp.OfpOxmOfbField{
500 fu.InPort(1),
501 fu.EthType(0x8863),
502 fu.TunnelId(536870912),
503 },
504 Actions: []*ofp.OfpAction{
505 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
506 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
507 },
508 }
509
kdarapub26b4502019-10-05 03:02:33 +0530510 fa9 := &fu.FlowArgs{
511 MatchFields: []*ofp.OfpOxmOfbField{
512 fu.InPort(536870912),
513 fu.TunnelId(16),
514 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300515 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530516 fu.VlanPcp(1000),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700517 fu.UdpDst(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530518 fu.UdpSrc(536870912),
519 fu.Ipv4Dst(65535),
520 fu.Ipv4Src(536870912),
521 },
522 Actions: []*ofp.OfpAction{
523 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
524 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
525 fu.Output(65535),
526 },
527 KV: kw6,
528 }
529
530 fa10 := &fu.FlowArgs{
531 MatchFields: []*ofp.OfpOxmOfbField{
532 fu.InPort(65533),
533 // fu.TunnelId(16),
534 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300535 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530536 fu.VlanPcp(1000),
537 fu.UdpDst(65535),
538 fu.UdpSrc(536870912),
539 fu.Ipv4Dst(65535),
540 fu.Ipv4Src(536870912),
541 },
542 Actions: []*ofp.OfpAction{
543 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
544 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
545 fu.Output(65535),
546 },
547 KV: kw6,
548 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000549 //multicast flow
550 fa11 := &fu.FlowArgs{
551 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700552 fu.InPort(16777216),
Esin Karamanccb714b2019-11-29 15:02:06 +0000553 fu.VlanVid(660), //vlan
554 fu.Metadata_ofp(uint64(66)), //inner vlan
555 fu.EthType(0x800), //ipv4
556 fu.Ipv4Dst(3809869825), //227.22.0.1
557 },
558 Actions: []*ofp.OfpAction{
559 fu.Group(1),
560 },
561 KV: kw6,
562 }
divyadesaid26f6b12020-03-19 06:30:28 +0000563 ofpstats, _ := fu.MkFlowStat(fa)
564 ofpstats2, _ := fu.MkFlowStat(fa2)
565 ofpstats3, _ := fu.MkFlowStat(fa3)
566 ofpstats4, _ := fu.MkFlowStat(fa4)
567 ofpstats5, _ := fu.MkFlowStat(fa5)
568 ofpstats6, _ := fu.MkFlowStat(fa6)
569 ofpstats7, _ := fu.MkFlowStat(lldpFa)
570 ofpstats8, _ := fu.MkFlowStat(dhcpFa)
571 ofpstats9, _ := fu.MkFlowStat(fa9)
572 ofpstats10, _ := fu.MkFlowStat(fa10)
573 igmpstats, _ := fu.MkFlowStat(igmpFa)
574 ofpstats11, _ := fu.MkFlowStat(fa11)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300575 pppoedstats, _ := fu.MkFlowStat(pppoedFa)
kdarapub26b4502019-10-05 03:02:33 +0530576
Gamze Abakafee36392019-10-03 11:17:24 +0000577 fmt.Println(ofpstats6, ofpstats9, ofpstats10)
578
kdarapu3248f9a2019-10-03 13:54:52 +0530579 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1}
khenaidoodc2116e2021-10-19 17:33:19 -0400580 flowMetadata := &ofp.FlowMetadata{
kdarapu3248f9a2019-10-03 13:54:52 +0530581 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
582 }
583 type args struct {
584 flow *ofp.OfpFlowStats
khenaidoodc2116e2021-10-19 17:33:19 -0400585 flowMetadata *ofp.FlowMetadata
kdarapu3248f9a2019-10-03 13:54:52 +0530586 }
587 tests := []struct {
588 name string
589 args args
590 }{
591 // TODO: Add test cases.
592 {"AddFlow", args{flow: ofpstats, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530593 {"AddFlow", args{flow: ofpstats2, flowMetadata: flowMetadata}},
594 {"AddFlow", args{flow: ofpstats3, flowMetadata: flowMetadata}},
595 {"AddFlow", args{flow: ofpstats4, flowMetadata: flowMetadata}},
596 {"AddFlow", args{flow: ofpstats5, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000597 //{"AddFlow", args{flow: ofpstats6, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530598 {"AddFlow", args{flow: ofpstats7, flowMetadata: flowMetadata}},
599 {"AddFlow", args{flow: ofpstats8, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000600 //{"AddFlow", args{flow: ofpstats9, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530601 {"AddFlow", args{flow: igmpstats, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000602 //{"AddFlow", args{flow: ofpstats10, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530603 //ofpstats10
Esin Karamanccb714b2019-11-29 15:02:06 +0000604 {"AddFlow", args{flow: ofpstats11, flowMetadata: flowMetadata}},
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300605 {"AddFlow", args{flow: pppoedstats, flowMetadata: flowMetadata}},
kdarapu3248f9a2019-10-03 13:54:52 +0530606 }
npujarec5762e2020-01-01 14:08:48 +0530607 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
608 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530609 for _, tt := range tests {
610 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700611 _ = flowMgr[0].AddFlow(ctx, tt.args.flow, tt.args.flowMetadata)
Kent Hagermane6ff1012020-07-14 15:07:53 -0400612 // TODO: actually verify test cases
kdarapu3248f9a2019-10-03 13:54:52 +0530613 })
614 }
615}
616
617func TestOpenOltFlowMgr_UpdateOnuInfo(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530618 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
619 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530620
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700621 wg := sync.WaitGroup{}
622
Girish Gowdra9602eb42020-09-09 15:50:39 -0700623 intfCount := NumPonPorts
624 onuCount := OnuIDEnd - OnuIDStart + 1
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700625
626 for i := 0; i < intfCount; i++ {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700627 for j := 1; j <= onuCount; j++ {
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700628 wg.Add(1)
629 go func(i uint32, j uint32) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400630 // TODO: actually verify success
Girish Gowdra197acc12021-08-16 10:59:45 -0700631 _ = flowMgr[i].AddOnuInfoToFlowMgrCacheAndKvStore(ctx, i, i, fmt.Sprintf("onu-%d", i))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700632 wg.Done()
633 }(uint32(i), uint32(j))
634 }
635
636 }
637
638 wg.Wait()
639}
640
641func TestOpenOltFlowMgr_addGemPortToOnuInfoMap(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700642 intfNum := NumPonPorts
643 onuNum := OnuIDEnd - OnuIDStart + 1
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700644
645 // clean the flowMgr
Girish Gowdra9602eb42020-09-09 15:50:39 -0700646 for i := 0; i < intfNum; i++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700647 flowMgr[i].onuGemInfoMap = make(map[uint32]*rsrcMgr.OnuGemInfo)
Girish Gowdra9602eb42020-09-09 15:50:39 -0700648 }
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700649
650 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
651 defer cancel()
652
653 // Create OnuInfo
654 for i := 0; i < intfNum; i++ {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700655 for o := 1; o <= onuNum; o++ {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400656 // TODO: actually verify success
Girish Gowdra197acc12021-08-16 10:59:45 -0700657 _ = flowMgr[i].AddOnuInfoToFlowMgrCacheAndKvStore(ctx, uint32(i), uint32(o), fmt.Sprintf("i%do%d", i, o-1))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700658 }
659 }
660
661 // Add gemPorts to OnuInfo in parallel threads
662 wg := sync.WaitGroup{}
Girish Gowdra9602eb42020-09-09 15:50:39 -0700663 for o := 1; o <= onuNum; o++ {
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700664 for i := 0; i < intfNum; i++ {
665 wg.Add(1)
666 go func(intfId uint32, onuId uint32) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700667 gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", intfId, onuId-1))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700668
Girish Gowdra9602eb42020-09-09 15:50:39 -0700669 flowMgr[intfId].addGemPortToOnuInfoMap(ctx, intfId, onuId, uint32(gemID))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700670 wg.Done()
671 }(uint32(i), uint32(o))
672 }
673 }
674
675 wg.Wait()
676
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700677 // check that each entry of onuGemInfoMap has the correct number of ONUs
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700678 for i := 0; i < intfNum; i++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700679 lenofOnu := len(flowMgr[i].onuGemInfoMap)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700680 if onuNum != lenofOnu {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700681 t.Errorf("onuGemInfoMap length is not as expected len = %d, want %d", lenofOnu, onuNum)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700682 }
683
Girish Gowdra9602eb42020-09-09 15:50:39 -0700684 for o := 1; o <= onuNum; o++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700685 lenOfGemPorts := len(flowMgr[i].onuGemInfoMap[uint32(o)].GemPorts)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700686 // check that each onuEntry has 1 gemPort
687 if lenOfGemPorts != 1 {
688 t.Errorf("Expected 1 GemPort per ONU, found %d", lenOfGemPorts)
689 }
690
691 // check that the value of the gemport is correct
Girish Gowdra9602eb42020-09-09 15:50:39 -0700692 gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", i, o-1))
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700693 currentValue := flowMgr[i].onuGemInfoMap[uint32(o)].GemPorts[0]
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700694 if uint32(gemID) != currentValue {
695 t.Errorf("Expected GemPort value to be %d, found %d", gemID, currentValue)
696 }
697 }
kdarapu3248f9a2019-10-03 13:54:52 +0530698 }
699}
700
serkant.uluderya96af4932020-02-20 16:58:48 -0800701func TestOpenOltFlowMgr_deleteGemPortFromLocalCache(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700702 // Create fresh flowMgr instance
703 flowMgr = newMockFlowmgr()
serkant.uluderya96af4932020-02-20 16:58:48 -0800704 type args struct {
705 intfID uint32
706 onuID uint32
707 gemPortIDs []uint32
708 gemPortIDsToBeDeleted []uint32
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700709 gemPortIDsRemaining []uint32
serkant.uluderya96af4932020-02-20 16:58:48 -0800710 serialNum string
711 finalLength int
712 }
713 tests := []struct {
714 name string
715 args args
716 }{
717 // Add/Delete single gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700718 {"DeleteGemPortFromLocalCache1", args{0, 1, []uint32{1}, []uint32{1}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800719 // Delete all gemports
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700720 {"DeleteGemPortFromLocalCache2", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{1, 2, 3, 4}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800721 // Try to delete when there is no gem port
Girish Gowdra197acc12021-08-16 10:59:45 -0700722 {"DeleteGemPortFromLocalCache3", args{0, 1, []uint32{}, []uint32{1, 2}, nil, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800723 // Try to delete non-existent gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700724 {"DeleteGemPortFromLocalCache4", args{0, 1, []uint32{1}, []uint32{2}, []uint32{1}, "onu1", 1}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800725 // Try to delete two of the gem ports
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700726 {"DeleteGemPortFromLocalCache5", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{2, 4}, []uint32{1, 3}, "onu1", 2}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800727 }
728 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
729 defer cancel()
730 for _, tt := range tests {
731 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra197acc12021-08-16 10:59:45 -0700732 if err := flowMgr[tt.args.intfID].RemoveOnuInfoFromFlowMgrCacheAndKvStore(ctx, tt.args.intfID, tt.args.onuID); err != nil {
733 t.Errorf("failed to remove onu")
734 }
735 if err := flowMgr[tt.args.intfID].AddOnuInfoToFlowMgrCacheAndKvStore(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum); err != nil {
736 t.Errorf("failed to add onu")
737 }
serkant.uluderya96af4932020-02-20 16:58:48 -0800738 for _, gemPort := range tt.args.gemPortIDs {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700739 flowMgr[tt.args.intfID].addGemPortToOnuInfoMap(ctx, tt.args.intfID, tt.args.onuID, gemPort)
serkant.uluderya96af4932020-02-20 16:58:48 -0800740 }
741 for _, gemPortDeleted := range tt.args.gemPortIDsToBeDeleted {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700742 flowMgr[tt.args.intfID].deleteGemPortFromLocalCache(ctx, tt.args.intfID, tt.args.onuID, gemPortDeleted)
serkant.uluderya96af4932020-02-20 16:58:48 -0800743 }
Girish Gowdra197acc12021-08-16 10:59:45 -0700744 lenofGemPorts := 0
745 gP, ok := flowMgr[tt.args.intfID].onuGemInfoMap[tt.args.onuID]
746 if ok {
747 lenofGemPorts = len(gP.GemPorts)
748 }
serkant.uluderya96af4932020-02-20 16:58:48 -0800749 if lenofGemPorts != tt.args.finalLength {
750 t.Errorf("GemPorts length is not as expected len = %d, want %d", lenofGemPorts, tt.args.finalLength)
751 }
Girish Gowdra197acc12021-08-16 10:59:45 -0700752 gP, ok = flowMgr[tt.args.intfID].onuGemInfoMap[tt.args.onuID]
753 var gemPorts []uint32
754 if ok {
755 gemPorts = gP.GemPorts
756 }
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700757 if !reflect.DeepEqual(tt.args.gemPortIDsRemaining, gemPorts) {
758 t.Errorf("GemPorts are not as expected = %v, want %v", gemPorts, tt.args.gemPortIDsRemaining)
759 }
serkant.uluderya96af4932020-02-20 16:58:48 -0800760
761 })
762 }
763}
764
kdarapu3248f9a2019-10-03 13:54:52 +0530765func TestOpenOltFlowMgr_GetLogicalPortFromPacketIn(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530766 type args struct {
767 packetIn *openoltpb2.PacketIndication
768 }
769 tests := []struct {
770 name string
771 args args
772 want uint32
773 wantErr bool
774 }{
775 // TODO: Add test cases.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700776 {"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 -0700777 {"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 +0530778 // Negative Test cases.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700779 {"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 -0700780 {"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 +0530781 }
npujarec5762e2020-01-01 14:08:48 +0530782 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
783 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530784 for _, tt := range tests {
785 t.Run(tt.name, func(t *testing.T) {
786
Girish Gowdra9602eb42020-09-09 15:50:39 -0700787 got, err := flowMgr[tt.args.packetIn.IntfId].GetLogicalPortFromPacketIn(ctx, tt.args.packetIn)
kdarapu3248f9a2019-10-03 13:54:52 +0530788 if (err != nil) != tt.wantErr {
789 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() error = %v, wantErr %v", err, tt.wantErr)
790 return
791 }
792 if got != tt.want {
793 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() = %v, want %v", got, tt.want)
794 }
795 })
796 }
797}
798
799func TestOpenOltFlowMgr_GetPacketOutGemPortID(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700800 // Create fresh flowMgr instance
801 flowMgr = newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530802
Esin Karaman7fb80c22020-07-16 14:23:33 +0000803 //untagged packet in hex string
804 untaggedStr := "01005e000002000000000001080046c00020000040000102fa140a000001e00000029404000017000705e10000fa"
805 untagged, err := hex.DecodeString(untaggedStr)
806 if err != nil {
807 t.Error("Unable to parse hex string", err)
808 panic(err)
809 }
Girish Gowdra9602eb42020-09-09 15:50:39 -0700810 //single-tagged packet in hex string. vlanID.pbit: 1.1
811 singleTaggedStr := "01005e0000010025ba48172481002001080046c0002000004000010257deab140023e0000001940400001164ee9b0000000000000000000000000000"
Esin Karaman7fb80c22020-07-16 14:23:33 +0000812 singleTagged, err := hex.DecodeString(singleTaggedStr)
813 if err != nil {
814 t.Error("Unable to parse hex string", err)
815 panic(err)
816 }
Girish Gowdra9602eb42020-09-09 15:50:39 -0700817 //double-tagged packet in hex string. vlanID.pbit: 210.0-0.0
818 doubleTaggedStr := "01005e000016deadbeefba118100021081000000080046000028000000000102c5b87f000001e0000016940400002200f8030000000104000000e10000fa"
Esin Karaman7fb80c22020-07-16 14:23:33 +0000819 doubleTagged, err := hex.DecodeString(doubleTaggedStr)
820 if err != nil {
821 t.Error("Unable to parse hex string", err)
822 panic(err)
823 }
824
kdarapu3248f9a2019-10-03 13:54:52 +0530825 type args struct {
826 intfID uint32
827 onuID uint32
828 portNum uint32
Esin Karaman7fb80c22020-07-16 14:23:33 +0000829 packet []byte
kdarapu3248f9a2019-10-03 13:54:52 +0530830 }
831 tests := []struct {
832 name string
833 args args
834 want uint32
835 wantErr bool
836 }{
837 // TODO: Add test cases.
Girish Gowdra9602eb42020-09-09 15:50:39 -0700838 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: untagged}, 1, false},
839 {"GetPacketOutGemPortID", args{intfID: 1, onuID: 2, portNum: 2, packet: singleTagged}, 2, false},
840 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: doubleTagged}, 1, false},
841 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 10, portNum: 10, packet: untagged}, 2, true},
842 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 3, packet: []byte{}}, 3, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530843 }
Esin Karaman7fb80c22020-07-16 14:23:33 +0000844
npujarec5762e2020-01-01 14:08:48 +0530845 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
846 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530847 for _, tt := range tests {
848 t.Run(tt.name, func(t *testing.T) {
849
Girish Gowdra9602eb42020-09-09 15:50:39 -0700850 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 +0000851 if tt.wantErr {
852 if err == nil {
853 //error expected but got value
854 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, wantErr %v", got, tt.wantErr)
855 }
856 } else {
857 if err != nil {
858 //error is not expected but got error
859 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() error = %v, wantErr %v", err, tt.wantErr)
860 return
861 }
862 if got != tt.want {
863 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, want %v", got, tt.want)
864 }
kdarapu3248f9a2019-10-03 13:54:52 +0530865 }
kdarapu3248f9a2019-10-03 13:54:52 +0530866 })
867 }
868}
869
870func TestOpenOltFlowMgr_DeleteTechProfileInstance(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530871 type args struct {
872 intfID uint32
873 onuID uint32
874 uniID uint32
875 sn string
Gamze Abakafee36392019-10-03 11:17:24 +0000876 tpID uint32
kdarapu3248f9a2019-10-03 13:54:52 +0530877 }
878 tests := []struct {
879 name string
880 args args
881 wantErr bool
882 }{
883 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000884 {"DeleteTechProfileInstance", args{intfID: 0, onuID: 1, uniID: 1, sn: "", tpID: 64}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530885 }
npujarec5762e2020-01-01 14:08:48 +0530886 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
887 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530888 for _, tt := range tests {
889 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700890 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 +0530891 t.Errorf("OpenOltFlowMgr.DeleteTechProfileInstance() error = %v, wantErr %v", err, tt.wantErr)
892 }
893 })
894 }
895}
kdarapub26b4502019-10-05 03:02:33 +0530896
897func TestOpenOltFlowMgr_checkAndAddFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000898 ctx := context.Background()
kdarapub26b4502019-10-05 03:02:33 +0530899 kw := make(map[string]uint64)
900 kw["table_id"] = 1
901 kw["meter_id"] = 1
902 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
903
904 // Upstream flow
905 fa := &fu.FlowArgs{
906 MatchFields: []*ofp.OfpOxmOfbField{
907 fu.InPort(536870912),
908 fu.Metadata_ofp(1),
909 fu.IpProto(17), // dhcp
Gamze Abakafee36392019-10-03 11:17:24 +0000910 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300911 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530912 },
913 Actions: []*ofp.OfpAction{
914 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
915 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700916 fu.Output(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530917 fu.PushVlan(0x8100),
918 },
919 KV: kw,
920 }
921
922 // EAPOL
923 fa2 := &fu.FlowArgs{
924 MatchFields: []*ofp.OfpOxmOfbField{
925 fu.InPort(536870912),
926 fu.Metadata_ofp(1),
927 fu.EthType(0x888E),
928 fu.VlanPcp(1),
929 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
930 },
931 Actions: []*ofp.OfpAction{
932 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
933 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700934 fu.Output(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530935 fu.PushVlan(0x8100),
936 },
937 KV: kw,
938 }
939
940 // HSIA
941 fa3 := &fu.FlowArgs{
942 MatchFields: []*ofp.OfpOxmOfbField{
943 fu.InPort(536870912),
944 fu.Metadata_ofp(1),
945 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300946 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530947 },
948 Actions: []*ofp.OfpAction{
949 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300950 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700951 fu.Output(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530952 fu.PushVlan(0x8100),
953 },
954 KV: kw,
955 }
956
957 fa4 := &fu.FlowArgs{
958 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700959 fu.InPort(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530960 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300961 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530962 fu.VlanPcp(1),
963 },
964 Actions: []*ofp.OfpAction{
965 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300966 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
kdarapub26b4502019-10-05 03:02:33 +0530967 fu.Output(536870912),
968 fu.PopVlan(),
969 },
970 KV: kw,
971 }
972
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300973 // PPPOED
974 pppoedFA := &fu.FlowArgs{
975 MatchFields: []*ofp.OfpOxmOfbField{
976 fu.InPort(536870912),
977 fu.Metadata_ofp(1),
978 fu.EthType(0x8863),
979 fu.VlanPcp(1),
980 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
981 },
982 Actions: []*ofp.OfpAction{
983 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700984 fu.Output(16777216),
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300985 fu.PushVlan(0x8100),
986 },
987 KV: kw,
988 }
989
kdarapub26b4502019-10-05 03:02:33 +0530990 classifierInfo := make(map[string]interface{})
991 actionInfo := make(map[string]interface{})
992 classifierInfo2 := make(map[string]interface{})
993 actionInfo2 := make(map[string]interface{})
994 classifierInfo3 := make(map[string]interface{})
995 actionInfo3 := make(map[string]interface{})
996 classifierInfo4 := make(map[string]interface{})
997 actionInfo4 := make(map[string]interface{})
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300998 classifierInfo5 := make(map[string]interface{})
999 actionInfo5 := make(map[string]interface{})
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001000 flow, _ := fu.MkFlowStat(fa)
1001 flow2, _ := fu.MkFlowStat(fa2)
1002 flow3, _ := fu.MkFlowStat(fa3)
1003 flow4, _ := fu.MkFlowStat(fa4)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001004 flow5, _ := fu.MkFlowStat(pppoedFA)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001005 formulateClassifierInfoFromFlow(ctx, classifierInfo, flow)
1006 formulateClassifierInfoFromFlow(ctx, classifierInfo2, flow2)
1007 formulateClassifierInfoFromFlow(ctx, classifierInfo3, flow3)
1008 formulateClassifierInfoFromFlow(ctx, classifierInfo4, flow4)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001009 formulateClassifierInfoFromFlow(ctx, classifierInfo5, flow5)
kdarapub26b4502019-10-05 03:02:33 +05301010
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001011 err := formulateActionInfoFromFlow(ctx, actionInfo, classifierInfo, flow)
kdarapub26b4502019-10-05 03:02:33 +05301012 if err != nil {
1013 // Error logging is already done in the called function
1014 // So just return in case of error
1015 return
1016 }
1017
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001018 err = formulateActionInfoFromFlow(ctx, actionInfo2, classifierInfo2, flow2)
kdarapub26b4502019-10-05 03:02:33 +05301019 if err != nil {
1020 // Error logging is already done in the called function
1021 // So just return in case of error
1022 return
1023 }
1024
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001025 err = formulateActionInfoFromFlow(ctx, actionInfo3, classifierInfo3, flow3)
kdarapub26b4502019-10-05 03:02:33 +05301026 if err != nil {
1027 // Error logging is already done in the called function
1028 // So just return in case of error
1029 return
1030 }
1031
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001032 err = formulateActionInfoFromFlow(ctx, actionInfo4, classifierInfo4, flow4)
kdarapub26b4502019-10-05 03:02:33 +05301033 if err != nil {
1034 // Error logging is already done in the called function
1035 // So just return in case of error
1036 return
1037 }
1038
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001039 err = formulateActionInfoFromFlow(ctx, actionInfo5, classifierInfo5, flow5)
1040 if err != nil {
1041 // Error logging is already done in the called function
1042 // So just return in case of error
1043 return
1044 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001045 /*
1046 usGemList := make([]*tp_pb.GemPortAttributes, 4)
1047 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1048 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1049 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1050 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1051 dsGemList := make([]*tp_pb.GemPortAttributes, 4)
1052 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1053 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1054 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1055 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1056 */
1057 TpInst := &tp_pb.TechProfileInstance{
kdarapub26b4502019-10-05 03:02:33 +05301058 Name: "Test-Tech-Profile",
1059 SubscriberIdentifier: "257",
1060 ProfileType: "Mock",
1061 Version: 1,
1062 NumGemPorts: 4,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001063 InstanceControl: &tp_pb.InstanceControl{
kdarapub26b4502019-10-05 03:02:33 +05301064 Onu: "1",
1065 Uni: "16",
1066 },
khenaidoodc2116e2021-10-19 17:33:19 -04001067 UsScheduler: &tp_pb.SchedulerAttributes{},
1068 DsScheduler: &tp_pb.SchedulerAttributes{},
kdarapub26b4502019-10-05 03:02:33 +05301069 }
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001070 TpInst.UsScheduler.Priority = 1
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001071 TpInst.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
1072 TpInst.UsScheduler.AllocId = 1
1073 TpInst.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
1074 TpInst.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001075 TpInst.UsScheduler.Weight = 4
1076
1077 TpInst.DsScheduler.Priority = 1
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001078 TpInst.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
1079 TpInst.DsScheduler.AllocId = 1
1080 TpInst.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
1081 TpInst.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001082 TpInst.DsScheduler.Weight = 4
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001083 TpInst.UpstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
1084 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
1085 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
1086 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
1087 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001088
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001089 TpInst.DownstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
1090 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
1091 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
1092 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
1093 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
kdarapub26b4502019-10-05 03:02:33 +05301094
kdarapub26b4502019-10-05 03:02:33 +05301095 type args struct {
1096 args map[string]uint32
1097 classifierInfo map[string]interface{}
1098 actionInfo map[string]interface{}
1099 flow *ofp.OfpFlowStats
1100 gemPort uint32
1101 intfID uint32
1102 onuID uint32
1103 uniID uint32
1104 portNo uint32
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001105 TpInst *tp_pb.TechProfileInstance
kdarapub26b4502019-10-05 03:02:33 +05301106 allocID []uint32
1107 gemPorts []uint32
1108 TpID uint32
1109 uni string
1110 }
1111 tests := []struct {
Kent Hagermane6ff1012020-07-14 15:07:53 -04001112 name string
1113 args args
kdarapub26b4502019-10-05 03:02:33 +05301114 }{
1115 {
1116 name: "checkAndAddFlow-1",
1117 args: args{
1118 args: nil,
1119 classifierInfo: classifierInfo,
1120 actionInfo: actionInfo,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001121 flow: flow,
kdarapub26b4502019-10-05 03:02:33 +05301122 gemPort: 1,
1123 intfID: 1,
1124 onuID: 1,
1125 uniID: 16,
1126 portNo: 1,
1127 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001128 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301129 gemPorts: []uint32{1, 2, 3, 4},
1130 TpID: 64,
1131 uni: "16",
1132 },
1133 },
1134 {
1135 name: "checkAndAddFlow-2",
1136 args: args{
1137 args: nil,
1138 classifierInfo: classifierInfo2,
1139 actionInfo: actionInfo2,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001140 flow: flow2,
kdarapub26b4502019-10-05 03:02:33 +05301141 gemPort: 1,
1142 intfID: 1,
1143 onuID: 1,
1144 uniID: 16,
1145 portNo: 1,
1146 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001147 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301148 gemPorts: []uint32{1, 2, 3, 4},
1149 TpID: 64,
1150 uni: "16",
1151 },
1152 },
1153 {
1154 name: "checkAndAddFlow-3",
1155 args: args{
1156 args: nil,
1157 classifierInfo: classifierInfo3,
1158 actionInfo: actionInfo3,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001159 flow: flow3,
kdarapub26b4502019-10-05 03:02:33 +05301160 gemPort: 1,
1161 intfID: 1,
1162 onuID: 1,
1163 uniID: 16,
1164 portNo: 1,
1165 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001166 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301167 gemPorts: []uint32{1, 2, 3, 4},
1168 TpID: 64,
1169 uni: "16",
1170 },
1171 },
1172 {
1173 name: "checkAndAddFlow-4",
1174 args: args{
1175 args: nil,
1176 classifierInfo: classifierInfo4,
1177 actionInfo: actionInfo4,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001178 flow: flow4,
kdarapub26b4502019-10-05 03:02:33 +05301179 gemPort: 1,
1180 intfID: 1,
1181 onuID: 1,
1182 uniID: 16,
1183 portNo: 1,
1184 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001185 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301186 gemPorts: []uint32{1, 2, 3, 4},
1187 TpID: 64,
1188 uni: "16",
1189 },
1190 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001191 {
1192 name: "checkAndAddFlow-5",
1193 args: args{
1194 args: nil,
1195 classifierInfo: classifierInfo5,
1196 actionInfo: actionInfo5,
1197 flow: flow5,
1198 gemPort: 1,
1199 intfID: 1,
1200 onuID: 1,
1201 uniID: 16,
1202 portNo: 1,
1203 TpInst: TpInst,
1204 allocID: []uint32{0x8001},
1205 gemPorts: []uint32{1, 2, 3, 4},
1206 TpID: 64,
1207 uni: "16",
1208 },
1209 },
kdarapub26b4502019-10-05 03:02:33 +05301210 }
npujarec5762e2020-01-01 14:08:48 +05301211 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1212 defer cancel()
kdarapub26b4502019-10-05 03:02:33 +05301213 for _, tt := range tests {
1214 t.Run(tt.name, func(t *testing.T) {
Gamze Abaka6d0a64f2021-11-18 08:08:33 +00001215 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 +00001216 tt.args.TpInst, tt.args.gemPorts, tt.args.TpID, tt.args.uni)
Gamze Abaka6d0a64f2021-11-18 08:08:33 +00001217 if err != nil {
1218 t.Error("check-and-add-flow failed", err)
1219 return
1220 }
kdarapub26b4502019-10-05 03:02:33 +05301221 })
1222 }
1223}
Esin Karamanccb714b2019-11-29 15:02:06 +00001224
Esin Karamand519bbf2020-07-01 11:16:03 +00001225func TestOpenOltFlowMgr_TestMulticastFlowAndGroup(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301226 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1227 defer cancel()
Esin Karamanccb714b2019-11-29 15:02:06 +00001228 //create group
1229 group := newGroup(2, []uint32{1})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001230 err := flowMgr[0].grpMgr.AddGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001231 if err != nil {
1232 t.Error("group-add failed", err)
1233 return
1234 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001235 //create multicast flow
1236 multicastFlowArgs := &fu.FlowArgs{
1237 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001238 fu.InPort(16777216),
Esin Karamanccb714b2019-11-29 15:02:06 +00001239 fu.VlanVid(660), //vlan
1240 fu.Metadata_ofp(uint64(66)), //inner vlan
1241 fu.EthType(0x800), //ipv4
1242 fu.Ipv4Dst(3809869825), //227.22.0.1
1243 },
1244 Actions: []*ofp.OfpAction{
1245 fu.Group(1),
1246 },
1247 }
divyadesaid26f6b12020-03-19 06:30:28 +00001248 ofpStats, _ := fu.MkFlowStat(multicastFlowArgs)
Esin Karamand519bbf2020-07-01 11:16:03 +00001249 fmt.Println(ofpStats.Id)
khenaidoodc2116e2021-10-19 17:33:19 -04001250 err = flowMgr[0].AddFlow(ctx, ofpStats, &ofp.FlowMetadata{})
Esin Karamand519bbf2020-07-01 11:16:03 +00001251 if err != nil {
1252 t.Error("Multicast flow-add failed", err)
1253 return
1254 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001255
1256 //add bucket to the group
1257 group = newGroup(2, []uint32{1, 2})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001258 err = flowMgr[0].grpMgr.ModifyGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001259 if err != nil {
1260 t.Error("modify-group failed", err)
1261 return
1262 }
1263 //remove the multicast flow
Girish Gowdra9602eb42020-09-09 15:50:39 -07001264 err = flowMgr[0].RemoveFlow(ctx, ofpStats)
Esin Karamand519bbf2020-07-01 11:16:03 +00001265 if err != nil {
1266 t.Error("Multicast flow-remove failed", err)
1267 return
1268 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001269
Esin Karamand519bbf2020-07-01 11:16:03 +00001270 //remove the group
Girish Gowdra9602eb42020-09-09 15:50:39 -07001271 err = flowMgr[0].grpMgr.DeleteGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001272 if err != nil {
1273 t.Error("delete-group failed", err)
1274 return
1275 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001276}
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001277
1278func TestOpenOltFlowMgr_TestRouteFlowToOnuChannel(t *testing.T) {
1279 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1280 defer cancel()
1281 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/core", log.DebugLevel)
1282 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager", log.DebugLevel)
1283 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/pkg/mocks", log.DebugLevel)
Girish Gowdra0aca4982021-01-04 12:44:27 -08001284 kwTable1Meter1 := make(map[string]uint64)
1285 kwTable1Meter1["table_id"] = 1
1286 kwTable1Meter1["meter_id"] = 1
1287 kwTable1Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
1288
1289 kwTable0Meter1 := make(map[string]uint64)
1290 kwTable0Meter1["table_id"] = 0
1291 kwTable0Meter1["meter_id"] = 1
1292 kwTable0Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001293
khenaidoodc2116e2021-10-19 17:33:19 -04001294 flowMetadata1 := ofp.FlowMetadata{Meters: []*ofp.OfpMeterConfig{
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001295 {
1296 Flags: 5,
1297 MeterId: 1,
khenaidoodc2116e2021-10-19 17:33:19 -04001298 Bands: []*ofp.OfpMeterBandHeader{
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001299 {
khenaidoodc2116e2021-10-19 17:33:19 -04001300 Type: ofp.OfpMeterBandType_OFPMBT_DROP,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001301 Rate: 16000,
Gamze Abaka01174422021-03-10 06:55:27 +00001302 BurstSize: 0,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001303 },
1304 {
khenaidoodc2116e2021-10-19 17:33:19 -04001305 Type: ofp.OfpMeterBandType_OFPMBT_DROP,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001306 Rate: 32000,
1307 BurstSize: 30,
1308 },
1309 {
khenaidoodc2116e2021-10-19 17:33:19 -04001310 Type: ofp.OfpMeterBandType_OFPMBT_DROP,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001311 Rate: 64000,
1312 BurstSize: 30,
1313 },
1314 },
1315 },
1316 }}
1317
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001318 // Downstream LLDP Trap from NNI0 flow
1319 fa0 := &fu.FlowArgs{
1320 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001321 fu.InPort(16777216),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001322 fu.EthType(35020),
1323 },
1324 Actions: []*ofp.OfpAction{
1325 fu.Output(4294967293),
1326 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001327 KV: make(map[string]uint64),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001328 }
1329
1330 // Upstream flow DHCP flow - ONU1 UNI0 PON0
1331 fa1 := &fu.FlowArgs{
1332 MatchFields: []*ofp.OfpOxmOfbField{
1333 fu.InPort(536870912),
1334 fu.Metadata_ofp(1),
1335 fu.IpProto(17), // dhcp
1336 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001337 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001338 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001339 },
1340 Actions: []*ofp.OfpAction{
1341 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1342 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1343 fu.Output(2147483645),
1344 fu.PushVlan(0x8100),
1345 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001346 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001347 }
1348
1349 // Upstream EAPOL - ONU1 UNI0 PON0
1350 fa2 := &fu.FlowArgs{
1351 MatchFields: []*ofp.OfpOxmOfbField{
1352 fu.InPort(536870912),
1353 fu.Metadata_ofp(1),
1354 fu.EthType(0x888E),
1355 fu.VlanPcp(1),
1356 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001357 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001358 },
1359 Actions: []*ofp.OfpAction{
1360 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1361 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1362 fu.Output(2147483645),
1363 fu.PushVlan(0x8100),
1364 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001365 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001366 }
1367
1368 // Upstream HSIA - ONU1 UNI0 PON0
1369 fa3 := &fu.FlowArgs{
1370 MatchFields: []*ofp.OfpOxmOfbField{
1371 fu.InPort(536870912),
1372 fu.Metadata_ofp(1),
1373 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001374 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001375 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001376 },
1377 Actions: []*ofp.OfpAction{
1378 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001379 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001380 fu.Output(16777216),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001381 fu.PushVlan(0x8100),
1382 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001383 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001384 }
1385
1386 // Downstream HSIA - ONU1 UNI0 PON0
1387 fa4 := &fu.FlowArgs{
1388 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001389 fu.InPort(16777216),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001390 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001391 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001392 fu.VlanPcp(1),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001393 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001394 },
1395 Actions: []*ofp.OfpAction{
1396 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001397 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001398 fu.Output(536870912),
1399 fu.PopVlan(),
1400 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001401 KV: kwTable0Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001402 }
1403
1404 // Upstream flow DHCP flow - ONU1 UNI0 PON15
1405 fa5 := &fu.FlowArgs{
1406 MatchFields: []*ofp.OfpOxmOfbField{
1407 fu.InPort(536870927),
1408 fu.Metadata_ofp(1),
1409 fu.IpProto(17), // dhcp
1410 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001411 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001412 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001413 },
1414 Actions: []*ofp.OfpAction{
1415 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1416 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259)),
1417 fu.Output(2147483645),
1418 fu.PushVlan(0x8100),
1419 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001420 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001421 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001422
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001423 // Upstream EAPOL - ONU1 UNI0 PON15
1424 fa6 := &fu.FlowArgs{
1425 MatchFields: []*ofp.OfpOxmOfbField{
1426 fu.InPort(536870927),
1427 fu.Metadata_ofp(1),
1428 fu.EthType(0x888E),
1429 fu.VlanPcp(1),
1430 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001431 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001432 },
1433 Actions: []*ofp.OfpAction{
1434 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1435 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1436 fu.Output(2147483645),
1437 fu.PushVlan(0x8100),
1438 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001439 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001440 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001441
1442 // Upstream PPPOED - ONU1 UNI0 PON0
1443 fa7 := &fu.FlowArgs{
1444 MatchFields: []*ofp.OfpOxmOfbField{
1445 fu.InPort(536870912),
1446 fu.Metadata_ofp(1),
1447 fu.EthType(0x8863),
1448 fu.VlanPcp(1),
1449 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001450 fu.TunnelId(256),
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001451 },
1452 Actions: []*ofp.OfpAction{
1453 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1454 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1455 fu.Output(2147483645),
1456 fu.PushVlan(0x8100),
1457 },
1458 KV: kwTable1Meter1,
1459 }
1460
1461 // Upstream PPPOED - ONU1 UNI0 PON15
1462 fa8 := &fu.FlowArgs{
1463 MatchFields: []*ofp.OfpOxmOfbField{
1464 fu.InPort(536870927),
1465 fu.Metadata_ofp(1),
1466 fu.EthType(0x8863),
1467 fu.VlanPcp(1),
1468 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001469 fu.TunnelId(256),
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001470 },
1471 Actions: []*ofp.OfpAction{
1472 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1473 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1474 fu.Output(2147483645),
1475 fu.PushVlan(0x8100),
1476 },
1477 KV: kwTable1Meter1,
1478 }
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001479 flow0, _ := fu.MkFlowStat(fa0)
1480 flow1, _ := fu.MkFlowStat(fa1)
1481 flow2, _ := fu.MkFlowStat(fa2)
1482 flow3, _ := fu.MkFlowStat(fa3)
1483 flow4, _ := fu.MkFlowStat(fa4)
1484
1485 flow5, _ := fu.MkFlowStat(fa5)
1486 flow6, _ := fu.MkFlowStat(fa6)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001487 flow7, _ := fu.MkFlowStat(fa7)
1488 flow8, _ := fu.MkFlowStat(fa8)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001489
1490 type args struct {
1491 ctx context.Context
1492 flow *ofp.OfpFlowStats
1493 addFlow bool
khenaidoodc2116e2021-10-19 17:33:19 -04001494 flowMetadata *ofp.FlowMetadata
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001495 }
1496 tests := []struct {
1497 name string
1498 args args
1499 wantErr bool
1500 returnedErr error
1501 }{
1502 {
1503 name: "RouteFlowToOnuChannel-0",
1504 args: args{
1505 ctx: ctx,
1506 flow: flow0,
1507 addFlow: true,
1508 flowMetadata: &flowMetadata1,
1509 },
1510 wantErr: false,
1511 },
1512 {
1513 name: "RouteFlowToOnuChannel-1",
1514 args: args{
1515 ctx: ctx,
1516 flow: flow1,
1517 addFlow: true,
1518 flowMetadata: &flowMetadata1,
1519 },
1520 wantErr: false,
1521 },
1522 {
1523 name: "RouteFlowToOnuChannel-2",
1524 args: args{
1525 ctx: ctx,
1526 flow: flow2,
1527 addFlow: true,
1528 flowMetadata: &flowMetadata1,
1529 },
1530 wantErr: false,
1531 },
1532 {
1533 name: "RouteFlowToOnuChannel-3",
1534 args: args{
1535 ctx: ctx,
1536 flow: flow3,
1537 addFlow: true,
1538 flowMetadata: &flowMetadata1,
1539 },
1540 wantErr: false,
1541 },
1542 {
1543 name: "RouteFlowToOnuChannel-4",
1544 args: args{
1545 ctx: ctx,
1546 flow: flow4,
1547 addFlow: true,
1548 flowMetadata: &flowMetadata1,
1549 },
1550 wantErr: false,
1551 },
1552 {
1553 name: "RouteFlowToOnuChannel-5",
1554 args: args{
1555 ctx: ctx,
1556 flow: flow1,
1557 addFlow: false,
1558 flowMetadata: &flowMetadata1,
1559 },
1560 wantErr: false,
1561 },
1562 {
1563 name: "RouteFlowToOnuChannel-6",
1564 args: args{
1565 ctx: ctx,
1566 flow: flow1,
1567 addFlow: true,
Girish Gowdra0aca4982021-01-04 12:44:27 -08001568 flowMetadata: &flowMetadata1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001569 },
Girish Gowdrad23ce662021-10-20 16:48:28 -07001570 wantErr: false,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001571 },
1572 {
1573 name: "RouteFlowToOnuChannel-7",
1574 args: args{
1575 ctx: ctx,
1576 flow: flow5,
1577 addFlow: true,
1578 flowMetadata: &flowMetadata1,
1579 },
1580 wantErr: false,
1581 },
1582 {
1583 name: "RouteFlowToOnuChannel-8",
1584 args: args{
1585 ctx: ctx,
1586 flow: flow6,
1587 addFlow: true,
1588 flowMetadata: &flowMetadata1,
1589 },
1590 wantErr: false,
1591 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001592 {
1593 name: "RouteFlowToOnuChannel-9",
1594 args: args{
1595 ctx: ctx,
1596 flow: flow7,
1597 addFlow: true,
1598 flowMetadata: &flowMetadata1,
1599 },
1600 wantErr: false,
1601 },
1602 {
1603 name: "RouteFlowToOnuChannel-10",
1604 args: args{
1605 ctx: ctx,
1606 flow: flow8,
1607 addFlow: true,
1608 flowMetadata: &flowMetadata1,
1609 },
1610 wantErr: false,
1611 },
Girish Gowdra5c00ef12021-12-01 17:19:41 +05301612 {
1613 name: "RouteFlowToOnuChannel-11", // Test Remove trap-from-nni LLDP flow
1614 args: args{
1615 ctx: ctx,
1616 flow: flow0,
1617 addFlow: false,
1618 flowMetadata: &flowMetadata1,
1619 },
1620 wantErr: false,
1621 },
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001622 }
1623
1624 var wg sync.WaitGroup
1625 defer wg.Wait() // wait for all go routines to complete
1626 for _, tt := range tests {
Girish Gowdrad23ce662021-10-20 16:48:28 -07001627 wg.Add(1) // one per go routine
1628 // 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
1629 // This delay is needed so that flows arrive in order. Otherwise if all flows are pushed at once the go routine can get scheduled
1630 // in random order causing flows to come out of order and test fails
1631 time.Sleep(5 * time.Millisecond)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001632 t.Run(tt.name, func(t *testing.T) {
Girish Gowdrad23ce662021-10-20 16:48:28 -07001633 defer wg.Done()
1634 tt.returnedErr = flowMgr[0].RouteFlowToOnuChannel(tt.args.ctx, tt.args.flow, tt.args.addFlow, tt.args.flowMetadata)
1635 if (tt.wantErr == false && tt.returnedErr != nil) || (tt.wantErr == true && tt.returnedErr == nil) {
1636 t.Errorf("OpenOltFlowMgr.RouteFlowToOnuChannel() error = %v, wantErr %v", tt.returnedErr, tt.wantErr)
1637 }
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001638 })
1639 }
1640}