blob: 45cd79eb2b910802794e5aa34470ea94ef020919 [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) {
Girish Gowdra9602eb42020-09-09 15:50:39 -07001215 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)
kdarapub26b4502019-10-05 03:02:33 +05301217 })
1218 }
1219}
Esin Karamanccb714b2019-11-29 15:02:06 +00001220
Esin Karamand519bbf2020-07-01 11:16:03 +00001221func TestOpenOltFlowMgr_TestMulticastFlowAndGroup(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301222 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1223 defer cancel()
Esin Karamanccb714b2019-11-29 15:02:06 +00001224 //create group
1225 group := newGroup(2, []uint32{1})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001226 err := flowMgr[0].grpMgr.AddGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001227 if err != nil {
1228 t.Error("group-add failed", err)
1229 return
1230 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001231 //create multicast flow
1232 multicastFlowArgs := &fu.FlowArgs{
1233 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001234 fu.InPort(16777216),
Esin Karamanccb714b2019-11-29 15:02:06 +00001235 fu.VlanVid(660), //vlan
1236 fu.Metadata_ofp(uint64(66)), //inner vlan
1237 fu.EthType(0x800), //ipv4
1238 fu.Ipv4Dst(3809869825), //227.22.0.1
1239 },
1240 Actions: []*ofp.OfpAction{
1241 fu.Group(1),
1242 },
1243 }
divyadesaid26f6b12020-03-19 06:30:28 +00001244 ofpStats, _ := fu.MkFlowStat(multicastFlowArgs)
Esin Karamand519bbf2020-07-01 11:16:03 +00001245 fmt.Println(ofpStats.Id)
khenaidoodc2116e2021-10-19 17:33:19 -04001246 err = flowMgr[0].AddFlow(ctx, ofpStats, &ofp.FlowMetadata{})
Esin Karamand519bbf2020-07-01 11:16:03 +00001247 if err != nil {
1248 t.Error("Multicast flow-add failed", err)
1249 return
1250 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001251
1252 //add bucket to the group
1253 group = newGroup(2, []uint32{1, 2})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001254 err = flowMgr[0].grpMgr.ModifyGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001255 if err != nil {
1256 t.Error("modify-group failed", err)
1257 return
1258 }
1259 //remove the multicast flow
Girish Gowdra9602eb42020-09-09 15:50:39 -07001260 err = flowMgr[0].RemoveFlow(ctx, ofpStats)
Esin Karamand519bbf2020-07-01 11:16:03 +00001261 if err != nil {
1262 t.Error("Multicast flow-remove failed", err)
1263 return
1264 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001265
Esin Karamand519bbf2020-07-01 11:16:03 +00001266 //remove the group
Girish Gowdra9602eb42020-09-09 15:50:39 -07001267 err = flowMgr[0].grpMgr.DeleteGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001268 if err != nil {
1269 t.Error("delete-group failed", err)
1270 return
1271 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001272}
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001273
1274func TestOpenOltFlowMgr_TestRouteFlowToOnuChannel(t *testing.T) {
1275 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1276 defer cancel()
1277 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/core", log.DebugLevel)
1278 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager", log.DebugLevel)
1279 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/pkg/mocks", log.DebugLevel)
Girish Gowdra0aca4982021-01-04 12:44:27 -08001280 kwTable1Meter1 := make(map[string]uint64)
1281 kwTable1Meter1["table_id"] = 1
1282 kwTable1Meter1["meter_id"] = 1
1283 kwTable1Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
1284
1285 kwTable0Meter1 := make(map[string]uint64)
1286 kwTable0Meter1["table_id"] = 0
1287 kwTable0Meter1["meter_id"] = 1
1288 kwTable0Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001289
khenaidoodc2116e2021-10-19 17:33:19 -04001290 flowMetadata1 := ofp.FlowMetadata{Meters: []*ofp.OfpMeterConfig{
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001291 {
1292 Flags: 5,
1293 MeterId: 1,
khenaidoodc2116e2021-10-19 17:33:19 -04001294 Bands: []*ofp.OfpMeterBandHeader{
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001295 {
khenaidoodc2116e2021-10-19 17:33:19 -04001296 Type: ofp.OfpMeterBandType_OFPMBT_DROP,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001297 Rate: 16000,
Gamze Abaka01174422021-03-10 06:55:27 +00001298 BurstSize: 0,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001299 },
1300 {
khenaidoodc2116e2021-10-19 17:33:19 -04001301 Type: ofp.OfpMeterBandType_OFPMBT_DROP,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001302 Rate: 32000,
1303 BurstSize: 30,
1304 },
1305 {
khenaidoodc2116e2021-10-19 17:33:19 -04001306 Type: ofp.OfpMeterBandType_OFPMBT_DROP,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001307 Rate: 64000,
1308 BurstSize: 30,
1309 },
1310 },
1311 },
1312 }}
1313
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001314 // Downstream LLDP Trap from NNI0 flow
1315 fa0 := &fu.FlowArgs{
1316 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001317 fu.InPort(16777216),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001318 fu.EthType(35020),
1319 },
1320 Actions: []*ofp.OfpAction{
1321 fu.Output(4294967293),
1322 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001323 KV: make(map[string]uint64),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001324 }
1325
1326 // Upstream flow DHCP flow - ONU1 UNI0 PON0
1327 fa1 := &fu.FlowArgs{
1328 MatchFields: []*ofp.OfpOxmOfbField{
1329 fu.InPort(536870912),
1330 fu.Metadata_ofp(1),
1331 fu.IpProto(17), // dhcp
1332 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001333 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001334 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001335 },
1336 Actions: []*ofp.OfpAction{
1337 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1338 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1339 fu.Output(2147483645),
1340 fu.PushVlan(0x8100),
1341 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001342 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001343 }
1344
1345 // Upstream EAPOL - ONU1 UNI0 PON0
1346 fa2 := &fu.FlowArgs{
1347 MatchFields: []*ofp.OfpOxmOfbField{
1348 fu.InPort(536870912),
1349 fu.Metadata_ofp(1),
1350 fu.EthType(0x888E),
1351 fu.VlanPcp(1),
1352 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001353 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001354 },
1355 Actions: []*ofp.OfpAction{
1356 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1357 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1358 fu.Output(2147483645),
1359 fu.PushVlan(0x8100),
1360 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001361 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001362 }
1363
1364 // Upstream HSIA - ONU1 UNI0 PON0
1365 fa3 := &fu.FlowArgs{
1366 MatchFields: []*ofp.OfpOxmOfbField{
1367 fu.InPort(536870912),
1368 fu.Metadata_ofp(1),
1369 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001370 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001371 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001372 },
1373 Actions: []*ofp.OfpAction{
1374 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001375 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001376 fu.Output(16777216),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001377 fu.PushVlan(0x8100),
1378 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001379 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001380 }
1381
1382 // Downstream HSIA - ONU1 UNI0 PON0
1383 fa4 := &fu.FlowArgs{
1384 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001385 fu.InPort(16777216),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001386 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001387 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001388 fu.VlanPcp(1),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001389 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001390 },
1391 Actions: []*ofp.OfpAction{
1392 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001393 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001394 fu.Output(536870912),
1395 fu.PopVlan(),
1396 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001397 KV: kwTable0Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001398 }
1399
1400 // Upstream flow DHCP flow - ONU1 UNI0 PON15
1401 fa5 := &fu.FlowArgs{
1402 MatchFields: []*ofp.OfpOxmOfbField{
1403 fu.InPort(536870927),
1404 fu.Metadata_ofp(1),
1405 fu.IpProto(17), // dhcp
1406 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001407 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001408 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001409 },
1410 Actions: []*ofp.OfpAction{
1411 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1412 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259)),
1413 fu.Output(2147483645),
1414 fu.PushVlan(0x8100),
1415 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001416 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001417 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001418
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001419 // Upstream EAPOL - ONU1 UNI0 PON15
1420 fa6 := &fu.FlowArgs{
1421 MatchFields: []*ofp.OfpOxmOfbField{
1422 fu.InPort(536870927),
1423 fu.Metadata_ofp(1),
1424 fu.EthType(0x888E),
1425 fu.VlanPcp(1),
1426 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001427 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001428 },
1429 Actions: []*ofp.OfpAction{
1430 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1431 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1432 fu.Output(2147483645),
1433 fu.PushVlan(0x8100),
1434 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001435 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001436 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001437
1438 // Upstream PPPOED - ONU1 UNI0 PON0
1439 fa7 := &fu.FlowArgs{
1440 MatchFields: []*ofp.OfpOxmOfbField{
1441 fu.InPort(536870912),
1442 fu.Metadata_ofp(1),
1443 fu.EthType(0x8863),
1444 fu.VlanPcp(1),
1445 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001446 fu.TunnelId(256),
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001447 },
1448 Actions: []*ofp.OfpAction{
1449 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1450 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1451 fu.Output(2147483645),
1452 fu.PushVlan(0x8100),
1453 },
1454 KV: kwTable1Meter1,
1455 }
1456
1457 // Upstream PPPOED - ONU1 UNI0 PON15
1458 fa8 := &fu.FlowArgs{
1459 MatchFields: []*ofp.OfpOxmOfbField{
1460 fu.InPort(536870927),
1461 fu.Metadata_ofp(1),
1462 fu.EthType(0x8863),
1463 fu.VlanPcp(1),
1464 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001465 fu.TunnelId(256),
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001466 },
1467 Actions: []*ofp.OfpAction{
1468 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1469 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1470 fu.Output(2147483645),
1471 fu.PushVlan(0x8100),
1472 },
1473 KV: kwTable1Meter1,
1474 }
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001475 flow0, _ := fu.MkFlowStat(fa0)
1476 flow1, _ := fu.MkFlowStat(fa1)
1477 flow2, _ := fu.MkFlowStat(fa2)
1478 flow3, _ := fu.MkFlowStat(fa3)
1479 flow4, _ := fu.MkFlowStat(fa4)
1480
1481 flow5, _ := fu.MkFlowStat(fa5)
1482 flow6, _ := fu.MkFlowStat(fa6)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001483 flow7, _ := fu.MkFlowStat(fa7)
1484 flow8, _ := fu.MkFlowStat(fa8)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001485
1486 type args struct {
1487 ctx context.Context
1488 flow *ofp.OfpFlowStats
1489 addFlow bool
khenaidoodc2116e2021-10-19 17:33:19 -04001490 flowMetadata *ofp.FlowMetadata
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001491 }
1492 tests := []struct {
1493 name string
1494 args args
1495 wantErr bool
1496 returnedErr error
1497 }{
1498 {
1499 name: "RouteFlowToOnuChannel-0",
1500 args: args{
1501 ctx: ctx,
1502 flow: flow0,
1503 addFlow: true,
1504 flowMetadata: &flowMetadata1,
1505 },
1506 wantErr: false,
1507 },
1508 {
1509 name: "RouteFlowToOnuChannel-1",
1510 args: args{
1511 ctx: ctx,
1512 flow: flow1,
1513 addFlow: true,
1514 flowMetadata: &flowMetadata1,
1515 },
1516 wantErr: false,
1517 },
1518 {
1519 name: "RouteFlowToOnuChannel-2",
1520 args: args{
1521 ctx: ctx,
1522 flow: flow2,
1523 addFlow: true,
1524 flowMetadata: &flowMetadata1,
1525 },
1526 wantErr: false,
1527 },
1528 {
1529 name: "RouteFlowToOnuChannel-3",
1530 args: args{
1531 ctx: ctx,
1532 flow: flow3,
1533 addFlow: true,
1534 flowMetadata: &flowMetadata1,
1535 },
1536 wantErr: false,
1537 },
1538 {
1539 name: "RouteFlowToOnuChannel-4",
1540 args: args{
1541 ctx: ctx,
1542 flow: flow4,
1543 addFlow: true,
1544 flowMetadata: &flowMetadata1,
1545 },
1546 wantErr: false,
1547 },
1548 {
1549 name: "RouteFlowToOnuChannel-5",
1550 args: args{
1551 ctx: ctx,
1552 flow: flow1,
1553 addFlow: false,
1554 flowMetadata: &flowMetadata1,
1555 },
1556 wantErr: false,
1557 },
1558 {
1559 name: "RouteFlowToOnuChannel-6",
1560 args: args{
1561 ctx: ctx,
1562 flow: flow1,
1563 addFlow: true,
Girish Gowdra0aca4982021-01-04 12:44:27 -08001564 flowMetadata: &flowMetadata1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001565 },
Girish Gowdrad23ce662021-10-20 16:48:28 -07001566 wantErr: false,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001567 },
1568 {
1569 name: "RouteFlowToOnuChannel-7",
1570 args: args{
1571 ctx: ctx,
1572 flow: flow5,
1573 addFlow: true,
1574 flowMetadata: &flowMetadata1,
1575 },
1576 wantErr: false,
1577 },
1578 {
1579 name: "RouteFlowToOnuChannel-8",
1580 args: args{
1581 ctx: ctx,
1582 flow: flow6,
1583 addFlow: true,
1584 flowMetadata: &flowMetadata1,
1585 },
1586 wantErr: false,
1587 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001588 {
1589 name: "RouteFlowToOnuChannel-9",
1590 args: args{
1591 ctx: ctx,
1592 flow: flow7,
1593 addFlow: true,
1594 flowMetadata: &flowMetadata1,
1595 },
1596 wantErr: false,
1597 },
1598 {
1599 name: "RouteFlowToOnuChannel-10",
1600 args: args{
1601 ctx: ctx,
1602 flow: flow8,
1603 addFlow: true,
1604 flowMetadata: &flowMetadata1,
1605 },
1606 wantErr: false,
1607 },
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001608 }
1609
1610 var wg sync.WaitGroup
1611 defer wg.Wait() // wait for all go routines to complete
1612 for _, tt := range tests {
Girish Gowdrad23ce662021-10-20 16:48:28 -07001613 wg.Add(1) // one per go routine
1614 // 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
1615 // This delay is needed so that flows arrive in order. Otherwise if all flows are pushed at once the go routine can get scheduled
1616 // in random order causing flows to come out of order and test fails
1617 time.Sleep(5 * time.Millisecond)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001618 t.Run(tt.name, func(t *testing.T) {
Girish Gowdrad23ce662021-10-20 16:48:28 -07001619 defer wg.Done()
1620 tt.returnedErr = flowMgr[0].RouteFlowToOnuChannel(tt.args.ctx, tt.args.flow, tt.args.addFlow, tt.args.flowMetadata)
1621 if (tt.wantErr == false && tt.returnedErr != nil) || (tt.wantErr == true && tt.returnedErr == nil) {
1622 t.Errorf("OpenOltFlowMgr.RouteFlowToOnuChannel() error = %v, wantErr %v", tt.returnedErr, tt.wantErr)
1623 }
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001624 })
1625 }
1626}