blob: 0d966d3b91d4681a9524ec63731bc9b140c81967 [file] [log] [blame]
kdarapu3248f9a2019-10-03 13:54:52 +05301/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Scott Bakerdbd960e2020-02-28 08:57:51 -080017//Package core provides the utility for olt devices, flows and statistics
18package core
kdarapu3248f9a2019-10-03 13:54:52 +053019
20import (
npujarec5762e2020-01-01 14:08:48 +053021 "context"
Esin Karaman7fb80c22020-07-16 14:23:33 +000022 "encoding/hex"
Gamze Abakafee36392019-10-03 11:17:24 +000023 "fmt"
Girish Gowdra4c3d4602021-07-22 16:33:37 -070024 "github.com/opencord/voltha-openolt-adapter/pkg/mocks"
Matteo Scandoloabf9c512020-06-23 19:31:14 -070025 "reflect"
26 "strconv"
27 "sync"
kdarapu3248f9a2019-10-03 13:54:52 +053028 "testing"
npujarec5762e2020-01-01 14:08:48 +053029 "time"
kdarapu3248f9a2019-10-03 13:54:52 +053030
Girish Gowdraa09aeab2020-09-14 16:30:52 -070031 "github.com/opencord/voltha-protos/v4/go/voltha"
kdarapub26b4502019-10-05 03:02:33 +053032
Girish Gowdra4c3d4602021-07-22 16:33:37 -070033 fu "github.com/opencord/voltha-lib-go/v6/pkg/flows"
34 "github.com/opencord/voltha-lib-go/v6/pkg/log"
Scott Bakerdbd960e2020-02-28 08:57:51 -080035 rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070036 ofp "github.com/opencord/voltha-protos/v4/go/openflow_13"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070037 openoltpb2 "github.com/opencord/voltha-protos/v4/go/openolt"
38 tp_pb "github.com/opencord/voltha-protos/v4/go/tech_profile"
kdarapu3248f9a2019-10-03 13:54:52 +053039)
40
Girish Gowdra9602eb42020-09-09 15:50:39 -070041var flowMgr []*OpenOltFlowMgr
kdarapub26b4502019-10-05 03:02:33 +053042
kdarapu3248f9a2019-10-03 13:54:52 +053043func init() {
Kent Hagermane6ff1012020-07-14 15:07:53 -040044 _, _ = log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
kdarapub26b4502019-10-05 03:02:33 +053045 flowMgr = newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +053046}
kdarapu3248f9a2019-10-03 13:54:52 +053047
Girish Gowdra9602eb42020-09-09 15:50:39 -070048func newMockFlowmgr() []*OpenOltFlowMgr {
kdarapu3248f9a2019-10-03 13:54:52 +053049 dh := newMockDeviceHandler()
50
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070051 // onuGemInfoMap := make([]rsrcMgr.onuGemInfoMap, NumPonPorts)
Girish Gowdra9602eb42020-09-09 15:50:39 -070052 var i uint32
kdarapu3248f9a2019-10-03 13:54:52 +053053
Girish Gowdra9602eb42020-09-09 15:50:39 -070054 for i = 0; i < NumPonPorts; i++ {
55 packetInGemPort := make(map[rsrcMgr.PacketInInfoKey]uint32)
56 packetInGemPort[rsrcMgr.PacketInInfoKey{IntfID: i, OnuID: i + 1, LogicalPort: i + 1, VlanID: uint16(i), Priority: uint8(i)}] = i + 1
kdarapu3248f9a2019-10-03 13:54:52 +053057
Girish Gowdra9602eb42020-09-09 15:50:39 -070058 dh.flowMgr[i].packetInGemPort = packetInGemPort
Girish Gowdra4c3d4602021-07-22 16:33:37 -070059 dh.flowMgr[i].techprofile = mocks.MockTechProfile{}
60
Girish Gowdra9602eb42020-09-09 15:50:39 -070061 interface2mcastQeueuMap := make(map[uint32]*QueueInfoBrief)
62 interface2mcastQeueuMap[0] = &QueueInfoBrief{
63 gemPortID: 4000,
64 servicePriority: 3,
65 }
66 dh.flowMgr[i].grpMgr.interfaceToMcastQueueMap = interface2mcastQeueuMap
kdarapu3248f9a2019-10-03 13:54:52 +053067 }
Girish Gowdra9602eb42020-09-09 15:50:39 -070068 return dh.flowMgr
kdarapu3248f9a2019-10-03 13:54:52 +053069}
kdarapub26b4502019-10-05 03:02:33 +053070
kdarapu3248f9a2019-10-03 13:54:52 +053071func TestOpenOltFlowMgr_CreateSchedulerQueues(t *testing.T) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070072 tprofile := &tp_pb.TechProfileInstance{Name: "tp1", SubscriberIdentifier: "subscriber1",
Girish Gowdra54934262019-11-13 14:19:55 +053073 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070074 InstanceControl: &tp_pb.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"},
kdarapu3248f9a2019-10-03 13:54:52 +053075 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070076 tprofile.UsScheduler = &openoltpb2.SchedulerAttributes{}
77 tprofile.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
78 tprofile.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +053079
80 tprofile2 := tprofile
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070081 tprofile2.DsScheduler = &openoltpb2.SchedulerAttributes{}
82 tprofile2.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
83 tprofile2.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Gamze Abaka01174422021-03-10 06:55:27 +000084
kdarapu3248f9a2019-10-03 13:54:52 +053085 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +000086 name string
87 schedQueue schedQueue
88 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +053089 }{
90 // TODO: Add test cases.
Gamze Abaka01174422021-03-10 06:55:27 +000091 {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 1, Upstream)}, false},
92 {"CreateSchedulerQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 1, Downstream)}, false},
93 {"CreateSchedulerQueues-13", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 2, Upstream)}, false},
94 {"CreateSchedulerQueues-14", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 2, Downstream)}, false},
95 {"CreateSchedulerQueues-15", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 3, Upstream)}, false},
96 {"CreateSchedulerQueues-16", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 3, Downstream)}, false},
97 {"CreateSchedulerQueues-17", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 4, Upstream)}, false},
98 {"CreateSchedulerQueues-18", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 4, Downstream)}, false},
99 {"CreateSchedulerQueues-19", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 5, Upstream)}, false},
100 {"CreateSchedulerQueues-20", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 5, Downstream)}, false},
101
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700102 {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 0, Upstream)}, false},
103 {"CreateSchedulerQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 0, Downstream)}, false},
Gamze Abaka01174422021-03-10 06:55:27 +0000104 {"CreateSchedulerQueues-3", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, createFlowMetadata(tprofile, 2, Upstream)}, true},
105 {"CreateSchedulerQueues-4", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, createFlowMetadata(tprofile2, 2, Downstream)}, true},
106 {"CreateSchedulerQueues-5", schedQueue{tp_pb.Direction_UPSTREAM, 1, 2, 2, 64, 2, tprofile, 2, createFlowMetadata(tprofile, 3, Upstream)}, true},
107 {"CreateSchedulerQueues-6", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 2, 2, 65, 2, tprofile2, 2, createFlowMetadata(tprofile2, 3, Downstream)}, true},
108
kdarapu3248f9a2019-10-03 13:54:52 +0530109 //Negative testcases
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700110 {"CreateSchedulerQueues-7", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, &voltha.FlowMetadata{}}, false},
Girish Gowdra9602eb42020-09-09 15:50:39 -0700111 {"CreateSchedulerQueues-8", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 0, &voltha.FlowMetadata{}}, true},
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700112 {"CreateSchedulerQueues-9", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, &voltha.FlowMetadata{}}, false},
Girish Gowdra9602eb42020-09-09 15:50:39 -0700113 {"CreateSchedulerQueues-10", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, &voltha.FlowMetadata{}}, true},
114 {"CreateSchedulerQueues-11", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, &voltha.FlowMetadata{}}, true},
115 {"CreateSchedulerQueues-12", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, nil}, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530116 }
npujarec5762e2020-01-01 14:08:48 +0530117 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
118 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530119 for _, tt := range tests {
120 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700121 if err := flowMgr[tt.schedQueue.intfID].CreateSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530122 t.Errorf("OpenOltFlowMgr.CreateSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr)
123 }
124 })
125 }
126}
127
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700128func createFlowMetadata(techProfile *tp_pb.TechProfileInstance, tcontType int, direction string) *voltha.FlowMetadata {
129 var additionalBw openoltpb2.AdditionalBW
Gamze Abaka01174422021-03-10 06:55:27 +0000130 bands := make([]*ofp.OfpMeterBandHeader, 0)
131 switch tcontType {
132 case 1:
133 //tcont-type-1
134 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
135 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700136 additionalBw = tp_pb.AdditionalBW_AdditionalBW_None
Gamze Abaka01174422021-03-10 06:55:27 +0000137 case 2:
138 //tcont-type-2
139 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 60000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
140 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700141 additionalBw = tp_pb.AdditionalBW_AdditionalBW_None
Gamze Abaka01174422021-03-10 06:55:27 +0000142 case 3:
143 //tcont-type-3
144 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
145 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 20000, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700146 additionalBw = tp_pb.AdditionalBW_AdditionalBW_NA
Gamze Abaka01174422021-03-10 06:55:27 +0000147 case 4:
148 //tcont-type-4
149 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 200000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700150 additionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
Gamze Abaka01174422021-03-10 06:55:27 +0000151 case 5:
152 //tcont-type-5
153 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
154 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
155 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700156 additionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
Gamze Abaka01174422021-03-10 06:55:27 +0000157 default:
158 // do nothing, we will return meter config with no meter bands
159 }
160
161 if direction == Downstream {
162 techProfile.DsScheduler.AdditionalBw = additionalBw
163 } else {
164 techProfile.UsScheduler.AdditionalBw = additionalBw
165 }
166
167 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
168 return &voltha.FlowMetadata{
169 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}}
170}
171
kdarapu3248f9a2019-10-03 13:54:52 +0530172func TestOpenOltFlowMgr_RemoveSchedulerQueues(t *testing.T) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700173 tprofile := &tp_pb.TechProfileInstance{Name: "tp1", SubscriberIdentifier: "subscriber1",
Girish Gowdra54934262019-11-13 14:19:55 +0530174 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700175 InstanceControl: &tp_pb.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"},
kdarapu3248f9a2019-10-03 13:54:52 +0530176 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700177 tprofile.UsScheduler = &openoltpb2.SchedulerAttributes{}
178 tprofile.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
179 tprofile.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
180 tprofile.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +0530181
182 tprofile2 := tprofile
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700183 tprofile2.DsScheduler = &openoltpb2.SchedulerAttributes{}
184 tprofile2.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
185 tprofile2.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
186 tprofile2.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +0530187 //defTprofile := &tp.DefaultTechProfile{}
kdarapu3248f9a2019-10-03 13:54:52 +0530188 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +0000189 name string
190 schedQueue schedQueue
191 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +0530192 }{
193 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000194 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 0, nil}, false},
195 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530196 // negative test cases
Gamze Abakafee36392019-10-03 11:17:24 +0000197 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
198 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530199 }
npujarec5762e2020-01-01 14:08:48 +0530200 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
201 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530202 for _, tt := range tests {
203 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700204 if err := flowMgr[tt.schedQueue.intfID].RemoveSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530205 t.Errorf("OpenOltFlowMgr.RemoveSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr)
206 }
207 })
208 }
kdarapub26b4502019-10-05 03:02:33 +0530209
kdarapu3248f9a2019-10-03 13:54:52 +0530210}
211
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700212func TestOpenOltFlowMgr_createTcontGemports(t *testing.T) {
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700213 bands := make([]*ofp.OfpMeterBandHeader, 2)
214 bands[0] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 1000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
215 bands[1] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 2000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
216 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
217 flowmetadata := &voltha.FlowMetadata{
218 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
219 }
220 type args struct {
221 intfID uint32
222 onuID uint32
223 uniID uint32
224 uni string
225 uniPort uint32
226 TpID uint32
227 UsMeterID uint32
228 DsMeterID uint32
229 flowMetadata *voltha.FlowMetadata
230 }
231 tests := []struct {
232 name string
233 args args
234 }{
235 {"createTcontGemports-1", args{intfID: 0, onuID: 1, uniID: 1, uni: "16", uniPort: 1, TpID: 64, UsMeterID: 1, DsMeterID: 1, flowMetadata: flowmetadata}},
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700236 }
237 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
238 defer cancel()
239 for _, tt := range tests {
240 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700241 _, _, tpInst := flowMgr[tt.args.intfID].createTcontGemports(ctx, tt.args.intfID, tt.args.onuID, tt.args.uniID, tt.args.uni, tt.args.uniPort, tt.args.TpID, tt.args.UsMeterID, tt.args.DsMeterID, tt.args.flowMetadata)
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700242 switch tpInst := tpInst.(type) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700243 case *tp_pb.TechProfileInstance:
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700244 if tt.args.TpID != 64 {
245 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
246 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700247 case *tp_pb.EponTechProfileInstance:
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700248 if tt.args.TpID != 65 {
249 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
250 }
251 default:
252 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
253 }
254 })
255 }
256}
257
kdarapu3248f9a2019-10-03 13:54:52 +0530258func TestOpenOltFlowMgr_RemoveFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000259 ctx := context.Background()
Neha Sharma96b7bf22020-06-15 10:37:32 +0000260 logger.Debug(ctx, "Info Warning Error: Starting RemoveFlow() test")
kdarapu3248f9a2019-10-03 13:54:52 +0530261 fa := &fu.FlowArgs{
262 MatchFields: []*ofp.OfpOxmOfbField{
263 fu.InPort(2),
264 fu.Metadata_ofp(2),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300265 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapu3248f9a2019-10-03 13:54:52 +0530266 },
267 Actions: []*ofp.OfpAction{
268 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
269 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
270 fu.Output(1),
271 },
272 }
divyadesaid26f6b12020-03-19 06:30:28 +0000273 ofpstats, _ := fu.MkFlowStat(fa)
kdarapub26b4502019-10-05 03:02:33 +0530274 ofpstats.Cookie = ofpstats.Id
kdarapub26b4502019-10-05 03:02:33 +0530275 lldpFa := &fu.FlowArgs{
276 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
277 MatchFields: []*ofp.OfpOxmOfbField{
278 fu.InPort(1),
279 fu.EthType(0x88CC),
280 fu.TunnelId(536870912),
281 },
282 Actions: []*ofp.OfpAction{
283 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
284 },
285 }
divyadesaid26f6b12020-03-19 06:30:28 +0000286 lldpofpstats, _ := fu.MkFlowStat(lldpFa)
kdarapub26b4502019-10-05 03:02:33 +0530287 //lldpofpstats.Cookie = lldpofpstats.Id
288
289 dhcpFa := &fu.FlowArgs{
290 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
291 MatchFields: []*ofp.OfpOxmOfbField{
292 fu.InPort(1),
293 fu.UdpSrc(67),
294 //fu.TunnelId(536870912),
295 fu.IpProto(17),
296 },
297 Actions: []*ofp.OfpAction{
298 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
299 },
300 }
divyadesaid26f6b12020-03-19 06:30:28 +0000301 dhcpofpstats, _ := fu.MkFlowStat(dhcpFa)
kdarapub26b4502019-10-05 03:02:33 +0530302 //dhcpofpstats.Cookie = dhcpofpstats.Id
Esin Karamanccb714b2019-11-29 15:02:06 +0000303
304 //multicast flow
305 multicastFa := &fu.FlowArgs{
306 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800307 fu.InPort(1048576),
Esin Karamanccb714b2019-11-29 15:02:06 +0000308 fu.VlanVid(660), //vlan
309 fu.Metadata_ofp(uint64(66)), //inner vlan
310 fu.EthType(0x800), //ipv4
311 fu.Ipv4Dst(3809869825), //227.22.0.1
312 },
313 Actions: []*ofp.OfpAction{
314 fu.Group(1),
315 },
316 }
divyadesaid26f6b12020-03-19 06:30:28 +0000317 multicastOfpStats, _ := fu.MkFlowStat(multicastFa)
Esin Karamanccb714b2019-11-29 15:02:06 +0000318 multicastOfpStats.Id = 1
319
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300320 pppoedFa := &fu.FlowArgs{
321 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
322 MatchFields: []*ofp.OfpOxmOfbField{
323 fu.InPort(1),
324 fu.EthType(0x8863),
325 fu.TunnelId(536870912),
326 },
327 Actions: []*ofp.OfpAction{
328 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
329 },
330 }
331 pppoedOfpStats, _ := fu.MkFlowStat(pppoedFa)
332
kdarapu3248f9a2019-10-03 13:54:52 +0530333 type args struct {
334 flow *ofp.OfpFlowStats
335 }
336 tests := []struct {
337 name string
338 args args
339 }{
340 // TODO: Add test cases.
341 {"RemoveFlow", args{flow: ofpstats}},
kdarapub26b4502019-10-05 03:02:33 +0530342 {"RemoveFlow", args{flow: lldpofpstats}},
343 {"RemoveFlow", args{flow: dhcpofpstats}},
Esin Karamanccb714b2019-11-29 15:02:06 +0000344 {"RemoveFlow", args{flow: multicastOfpStats}},
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300345 {"RemoveFlow", args{flow: pppoedOfpStats}},
kdarapu3248f9a2019-10-03 13:54:52 +0530346 }
npujarec5762e2020-01-01 14:08:48 +0530347 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
348 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530349 for _, tt := range tests {
350 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700351 if err := flowMgr[0].RemoveFlow(ctx, tt.args.flow); err != nil {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400352 logger.Warn(ctx, err)
353 }
kdarapu3248f9a2019-10-03 13:54:52 +0530354 })
355 }
kdarapub26b4502019-10-05 03:02:33 +0530356 // t.Error("=====")
kdarapu3248f9a2019-10-03 13:54:52 +0530357}
358
359func TestOpenOltFlowMgr_AddFlow(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530360 kw := make(map[string]uint64)
361 kw["table_id"] = 1
362 kw["meter_id"] = 1
kdarapub26b4502019-10-05 03:02:33 +0530363 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
364
365 // Upstream flow
kdarapu3248f9a2019-10-03 13:54:52 +0530366 fa := &fu.FlowArgs{
367 MatchFields: []*ofp.OfpOxmOfbField{
kdarapub26b4502019-10-05 03:02:33 +0530368 fu.InPort(536870912),
369 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300370 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530371 },
372 Actions: []*ofp.OfpAction{
373 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
374 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800375 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530376 fu.PushVlan(0x8100),
377 },
378 KV: kw,
379 }
380
381 // Downstream flow
382 fa3 := &fu.FlowArgs{
383 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800384 fu.InPort(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530385 fu.Metadata_ofp(1),
386 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
387 },
388 Actions: []*ofp.OfpAction{
389 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
390 //fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
391 fu.PopVlan(),
392 fu.Output(536870912),
393 },
394 KV: kw,
395 }
396
397 fa2 := &fu.FlowArgs{
398 MatchFields: []*ofp.OfpOxmOfbField{
kdarapu3248f9a2019-10-03 13:54:52 +0530399 fu.InPort(1000),
400 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300401 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapu3248f9a2019-10-03 13:54:52 +0530402 },
403 Actions: []*ofp.OfpAction{
404 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
405 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
406 fu.Output(65533),
407 },
408 KV: kw,
409 }
410
kdarapub26b4502019-10-05 03:02:33 +0530411 // TODO Add LLDP flow
412 // TODO Add DHCP flow
413
414 // Flows for negative scenarios
415 // Failure in formulateActionInfoFromFlow()
416 fa4 := &fu.FlowArgs{
417 MatchFields: []*ofp.OfpOxmOfbField{
418 fu.InPort(1000),
419 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300420 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530421 },
422 Actions: []*ofp.OfpAction{
423 fu.Experimenter(257, []byte{1, 2, 3, 4}),
424 },
425 KV: kw,
426 }
427
428 // Invalid Output
429 fa5 := &fu.FlowArgs{
430 MatchFields: []*ofp.OfpOxmOfbField{
431 fu.InPort(1000),
432 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300433 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530434 },
435 Actions: []*ofp.OfpAction{
436 fu.Output(0),
437 },
438 KV: kw,
439 }
440
441 // Tech-Profile-ID update (not supported)
442 kw6 := make(map[string]uint64)
443 kw6["table_id"] = 1
444 kw6["meter_id"] = 1
445 kw6["write_metadata"] = 0x4100000000 // TpID Other than the stored one
446 fa6 := &fu.FlowArgs{
447 MatchFields: []*ofp.OfpOxmOfbField{
448 fu.InPort(536870912),
449 fu.TunnelId(16),
450 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300451 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530452 },
453 Actions: []*ofp.OfpAction{
454 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
455 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
456 fu.Output(65535),
457 },
458 KV: kw6,
459 }
460
461 lldpFa := &fu.FlowArgs{
462 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
463 MatchFields: []*ofp.OfpOxmOfbField{
464 fu.InPort(1),
465 fu.EthType(0x88CC),
466 fu.TunnelId(536870912),
467 },
468 Actions: []*ofp.OfpAction{
469 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
470 },
471 }
472
473 dhcpFa := &fu.FlowArgs{
474 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
475 MatchFields: []*ofp.OfpOxmOfbField{
476 fu.InPort(1),
477 fu.UdpSrc(67),
478 //fu.TunnelId(536870912),
479 fu.IpProto(17),
480 },
481 Actions: []*ofp.OfpAction{
482 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
483 },
484 }
485 igmpFa := &fu.FlowArgs{
486 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
487 MatchFields: []*ofp.OfpOxmOfbField{
488 fu.InPort(1),
489 fu.UdpSrc(67),
490 //fu.TunnelId(536870912),
491 fu.IpProto(2),
492 },
493 Actions: []*ofp.OfpAction{
494 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
495 },
496 }
497
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300498 pppoedFa := &fu.FlowArgs{
499 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
500 MatchFields: []*ofp.OfpOxmOfbField{
501 fu.InPort(1),
502 fu.EthType(0x8863),
503 fu.TunnelId(536870912),
504 },
505 Actions: []*ofp.OfpAction{
506 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
507 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
508 },
509 }
510
kdarapub26b4502019-10-05 03:02:33 +0530511 fa9 := &fu.FlowArgs{
512 MatchFields: []*ofp.OfpOxmOfbField{
513 fu.InPort(536870912),
514 fu.TunnelId(16),
515 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300516 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530517 fu.VlanPcp(1000),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800518 fu.UdpDst(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530519 fu.UdpSrc(536870912),
520 fu.Ipv4Dst(65535),
521 fu.Ipv4Src(536870912),
522 },
523 Actions: []*ofp.OfpAction{
524 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
525 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
526 fu.Output(65535),
527 },
528 KV: kw6,
529 }
530
531 fa10 := &fu.FlowArgs{
532 MatchFields: []*ofp.OfpOxmOfbField{
533 fu.InPort(65533),
534 // fu.TunnelId(16),
535 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300536 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530537 fu.VlanPcp(1000),
538 fu.UdpDst(65535),
539 fu.UdpSrc(536870912),
540 fu.Ipv4Dst(65535),
541 fu.Ipv4Src(536870912),
542 },
543 Actions: []*ofp.OfpAction{
544 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
545 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
546 fu.Output(65535),
547 },
548 KV: kw6,
549 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000550 //multicast flow
551 fa11 := &fu.FlowArgs{
552 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800553 fu.InPort(1048576),
Esin Karamanccb714b2019-11-29 15:02:06 +0000554 fu.VlanVid(660), //vlan
555 fu.Metadata_ofp(uint64(66)), //inner vlan
556 fu.EthType(0x800), //ipv4
557 fu.Ipv4Dst(3809869825), //227.22.0.1
558 },
559 Actions: []*ofp.OfpAction{
560 fu.Group(1),
561 },
562 KV: kw6,
563 }
divyadesaid26f6b12020-03-19 06:30:28 +0000564 ofpstats, _ := fu.MkFlowStat(fa)
565 ofpstats2, _ := fu.MkFlowStat(fa2)
566 ofpstats3, _ := fu.MkFlowStat(fa3)
567 ofpstats4, _ := fu.MkFlowStat(fa4)
568 ofpstats5, _ := fu.MkFlowStat(fa5)
569 ofpstats6, _ := fu.MkFlowStat(fa6)
570 ofpstats7, _ := fu.MkFlowStat(lldpFa)
571 ofpstats8, _ := fu.MkFlowStat(dhcpFa)
572 ofpstats9, _ := fu.MkFlowStat(fa9)
573 ofpstats10, _ := fu.MkFlowStat(fa10)
574 igmpstats, _ := fu.MkFlowStat(igmpFa)
575 ofpstats11, _ := fu.MkFlowStat(fa11)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300576 pppoedstats, _ := fu.MkFlowStat(pppoedFa)
kdarapub26b4502019-10-05 03:02:33 +0530577
Gamze Abakafee36392019-10-03 11:17:24 +0000578 fmt.Println(ofpstats6, ofpstats9, ofpstats10)
579
kdarapu3248f9a2019-10-03 13:54:52 +0530580 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1}
kdarapu3248f9a2019-10-03 13:54:52 +0530581 flowMetadata := &voltha.FlowMetadata{
582 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
583 }
584 type args struct {
585 flow *ofp.OfpFlowStats
586 flowMetadata *voltha.FlowMetadata
587 }
588 tests := []struct {
589 name string
590 args args
591 }{
592 // TODO: Add test cases.
593 {"AddFlow", args{flow: ofpstats, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530594 {"AddFlow", args{flow: ofpstats2, flowMetadata: flowMetadata}},
595 {"AddFlow", args{flow: ofpstats3, flowMetadata: flowMetadata}},
596 {"AddFlow", args{flow: ofpstats4, flowMetadata: flowMetadata}},
597 {"AddFlow", args{flow: ofpstats5, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000598 //{"AddFlow", args{flow: ofpstats6, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530599 {"AddFlow", args{flow: ofpstats7, flowMetadata: flowMetadata}},
600 {"AddFlow", args{flow: ofpstats8, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000601 //{"AddFlow", args{flow: ofpstats9, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530602 {"AddFlow", args{flow: igmpstats, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000603 //{"AddFlow", args{flow: ofpstats10, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530604 //ofpstats10
Esin Karamanccb714b2019-11-29 15:02:06 +0000605 {"AddFlow", args{flow: ofpstats11, flowMetadata: flowMetadata}},
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300606 {"AddFlow", args{flow: pppoedstats, flowMetadata: flowMetadata}},
kdarapu3248f9a2019-10-03 13:54:52 +0530607 }
npujarec5762e2020-01-01 14:08:48 +0530608 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
609 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530610 for _, tt := range tests {
611 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700612 _ = flowMgr[0].AddFlow(ctx, tt.args.flow, tt.args.flowMetadata)
Kent Hagermane6ff1012020-07-14 15:07:53 -0400613 // TODO: actually verify test cases
kdarapu3248f9a2019-10-03 13:54:52 +0530614 })
615 }
616}
617
618func TestOpenOltFlowMgr_UpdateOnuInfo(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530619 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
620 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530621
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700622 wg := sync.WaitGroup{}
623
Girish Gowdra9602eb42020-09-09 15:50:39 -0700624 intfCount := NumPonPorts
625 onuCount := OnuIDEnd - OnuIDStart + 1
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700626
627 for i := 0; i < intfCount; i++ {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700628 for j := 1; j <= onuCount; j++ {
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700629 wg.Add(1)
630 go func(i uint32, j uint32) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400631 // TODO: actually verify success
Girish Gowdra9602eb42020-09-09 15:50:39 -0700632 _ = flowMgr[i].UpdateOnuInfo(ctx, i, i, fmt.Sprintf("onu-%d", i))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700633 wg.Done()
634 }(uint32(i), uint32(j))
635 }
636
637 }
638
639 wg.Wait()
640}
641
642func TestOpenOltFlowMgr_addGemPortToOnuInfoMap(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700643 intfNum := NumPonPorts
644 onuNum := OnuIDEnd - OnuIDStart + 1
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700645
646 // clean the flowMgr
Girish Gowdra9602eb42020-09-09 15:50:39 -0700647 for i := 0; i < intfNum; i++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700648 flowMgr[i].onuGemInfoMap = make(map[uint32]*rsrcMgr.OnuGemInfo)
Girish Gowdra9602eb42020-09-09 15:50:39 -0700649 }
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700650
651 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
652 defer cancel()
653
654 // Create OnuInfo
655 for i := 0; i < intfNum; i++ {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700656 for o := 1; o <= onuNum; o++ {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400657 // TODO: actually verify success
Girish Gowdra9602eb42020-09-09 15:50:39 -0700658 _ = flowMgr[i].UpdateOnuInfo(ctx, uint32(i), uint32(o), fmt.Sprintf("i%do%d", i, o-1))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700659 }
660 }
661
662 // Add gemPorts to OnuInfo in parallel threads
663 wg := sync.WaitGroup{}
Girish Gowdra9602eb42020-09-09 15:50:39 -0700664 for o := 1; o <= onuNum; o++ {
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700665 for i := 0; i < intfNum; i++ {
666 wg.Add(1)
667 go func(intfId uint32, onuId uint32) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700668 gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", intfId, onuId-1))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700669
Girish Gowdra9602eb42020-09-09 15:50:39 -0700670 flowMgr[intfId].addGemPortToOnuInfoMap(ctx, intfId, onuId, uint32(gemID))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700671 wg.Done()
672 }(uint32(i), uint32(o))
673 }
674 }
675
676 wg.Wait()
677
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700678 // check that each entry of onuGemInfoMap has the correct number of ONUs
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700679 for i := 0; i < intfNum; i++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700680 lenofOnu := len(flowMgr[i].onuGemInfoMap)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700681 if onuNum != lenofOnu {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700682 t.Errorf("onuGemInfoMap length is not as expected len = %d, want %d", lenofOnu, onuNum)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700683 }
684
Girish Gowdra9602eb42020-09-09 15:50:39 -0700685 for o := 1; o <= onuNum; o++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700686 lenOfGemPorts := len(flowMgr[i].onuGemInfoMap[uint32(o)].GemPorts)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700687 // check that each onuEntry has 1 gemPort
688 if lenOfGemPorts != 1 {
689 t.Errorf("Expected 1 GemPort per ONU, found %d", lenOfGemPorts)
690 }
691
692 // check that the value of the gemport is correct
Girish Gowdra9602eb42020-09-09 15:50:39 -0700693 gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", i, o-1))
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700694 currentValue := flowMgr[i].onuGemInfoMap[uint32(o)].GemPorts[0]
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700695 if uint32(gemID) != currentValue {
696 t.Errorf("Expected GemPort value to be %d, found %d", gemID, currentValue)
697 }
698 }
kdarapu3248f9a2019-10-03 13:54:52 +0530699 }
700}
701
serkant.uluderya96af4932020-02-20 16:58:48 -0800702func TestOpenOltFlowMgr_deleteGemPortFromLocalCache(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700703 // Create fresh flowMgr instance
704 flowMgr = newMockFlowmgr()
serkant.uluderya96af4932020-02-20 16:58:48 -0800705 type args struct {
706 intfID uint32
707 onuID uint32
708 gemPortIDs []uint32
709 gemPortIDsToBeDeleted []uint32
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700710 gemPortIDsRemaining []uint32
serkant.uluderya96af4932020-02-20 16:58:48 -0800711 serialNum string
712 finalLength int
713 }
714 tests := []struct {
715 name string
716 args args
717 }{
718 // Add/Delete single gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700719 {"DeleteGemPortFromLocalCache1", args{0, 1, []uint32{1}, []uint32{1}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800720 // Delete all gemports
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700721 {"DeleteGemPortFromLocalCache2", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{1, 2, 3, 4}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800722 // Try to delete when there is no gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700723 {"DeleteGemPortFromLocalCache3", args{0, 1, []uint32{}, []uint32{1, 2}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800724 // Try to delete non-existent gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700725 {"DeleteGemPortFromLocalCache4", args{0, 1, []uint32{1}, []uint32{2}, []uint32{1}, "onu1", 1}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800726 // Try to delete two of the gem ports
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700727 {"DeleteGemPortFromLocalCache5", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{2, 4}, []uint32{1, 3}, "onu1", 2}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800728 }
729 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
730 defer cancel()
731 for _, tt := range tests {
732 t.Run(tt.name, func(t *testing.T) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400733 // TODO: should check returned errors are as expected?
Girish Gowdra9602eb42020-09-09 15:50:39 -0700734 _ = flowMgr[tt.args.intfID].UpdateOnuInfo(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum)
serkant.uluderya96af4932020-02-20 16:58:48 -0800735 for _, gemPort := range tt.args.gemPortIDs {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700736 flowMgr[tt.args.intfID].addGemPortToOnuInfoMap(ctx, tt.args.intfID, tt.args.onuID, gemPort)
serkant.uluderya96af4932020-02-20 16:58:48 -0800737 }
738 for _, gemPortDeleted := range tt.args.gemPortIDsToBeDeleted {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700739 flowMgr[tt.args.intfID].deleteGemPortFromLocalCache(ctx, tt.args.intfID, tt.args.onuID, gemPortDeleted)
serkant.uluderya96af4932020-02-20 16:58:48 -0800740 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700741 lenofGemPorts := len(flowMgr[tt.args.intfID].onuGemInfoMap[1].GemPorts)
serkant.uluderya96af4932020-02-20 16:58:48 -0800742 if lenofGemPorts != tt.args.finalLength {
743 t.Errorf("GemPorts length is not as expected len = %d, want %d", lenofGemPorts, tt.args.finalLength)
744 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700745 gemPorts := flowMgr[tt.args.intfID].onuGemInfoMap[1].GemPorts
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700746 if !reflect.DeepEqual(tt.args.gemPortIDsRemaining, gemPorts) {
747 t.Errorf("GemPorts are not as expected = %v, want %v", gemPorts, tt.args.gemPortIDsRemaining)
748 }
serkant.uluderya96af4932020-02-20 16:58:48 -0800749
750 })
751 }
752}
753
kdarapu3248f9a2019-10-03 13:54:52 +0530754func TestOpenOltFlowMgr_GetLogicalPortFromPacketIn(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530755 type args struct {
756 packetIn *openoltpb2.PacketIndication
757 }
758 tests := []struct {
759 name string
760 args args
761 want uint32
762 wantErr bool
763 }{
764 // TODO: Add test cases.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700765 {"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},
766 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "nni", IntfId: 0, GemportId: 1, OnuId: 1, UniId: 0, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 1048576, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530767 // Negative Test cases.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700768 {"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},
769 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 0, GemportId: 257, OnuId: 1, UniId: 0, FlowId: 100, PortNo: 0, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 16, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530770 }
npujarec5762e2020-01-01 14:08:48 +0530771 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
772 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530773 for _, tt := range tests {
774 t.Run(tt.name, func(t *testing.T) {
775
Girish Gowdra9602eb42020-09-09 15:50:39 -0700776 got, err := flowMgr[tt.args.packetIn.IntfId].GetLogicalPortFromPacketIn(ctx, tt.args.packetIn)
kdarapu3248f9a2019-10-03 13:54:52 +0530777 if (err != nil) != tt.wantErr {
778 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() error = %v, wantErr %v", err, tt.wantErr)
779 return
780 }
781 if got != tt.want {
782 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() = %v, want %v", got, tt.want)
783 }
784 })
785 }
786}
787
788func TestOpenOltFlowMgr_GetPacketOutGemPortID(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700789 // Create fresh flowMgr instance
790 flowMgr = newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530791
Esin Karaman7fb80c22020-07-16 14:23:33 +0000792 //untagged packet in hex string
793 untaggedStr := "01005e000002000000000001080046c00020000040000102fa140a000001e00000029404000017000705e10000fa"
794 untagged, err := hex.DecodeString(untaggedStr)
795 if err != nil {
796 t.Error("Unable to parse hex string", err)
797 panic(err)
798 }
Girish Gowdra9602eb42020-09-09 15:50:39 -0700799 //single-tagged packet in hex string. vlanID.pbit: 1.1
800 singleTaggedStr := "01005e0000010025ba48172481002001080046c0002000004000010257deab140023e0000001940400001164ee9b0000000000000000000000000000"
Esin Karaman7fb80c22020-07-16 14:23:33 +0000801 singleTagged, err := hex.DecodeString(singleTaggedStr)
802 if err != nil {
803 t.Error("Unable to parse hex string", err)
804 panic(err)
805 }
Girish Gowdra9602eb42020-09-09 15:50:39 -0700806 //double-tagged packet in hex string. vlanID.pbit: 210.0-0.0
807 doubleTaggedStr := "01005e000016deadbeefba118100021081000000080046000028000000000102c5b87f000001e0000016940400002200f8030000000104000000e10000fa"
Esin Karaman7fb80c22020-07-16 14:23:33 +0000808 doubleTagged, err := hex.DecodeString(doubleTaggedStr)
809 if err != nil {
810 t.Error("Unable to parse hex string", err)
811 panic(err)
812 }
813
kdarapu3248f9a2019-10-03 13:54:52 +0530814 type args struct {
815 intfID uint32
816 onuID uint32
817 portNum uint32
Esin Karaman7fb80c22020-07-16 14:23:33 +0000818 packet []byte
kdarapu3248f9a2019-10-03 13:54:52 +0530819 }
820 tests := []struct {
821 name string
822 args args
823 want uint32
824 wantErr bool
825 }{
826 // TODO: Add test cases.
Girish Gowdra9602eb42020-09-09 15:50:39 -0700827 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: untagged}, 1, false},
828 {"GetPacketOutGemPortID", args{intfID: 1, onuID: 2, portNum: 2, packet: singleTagged}, 2, false},
829 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: doubleTagged}, 1, false},
830 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 10, portNum: 10, packet: untagged}, 2, true},
831 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 3, packet: []byte{}}, 3, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530832 }
Esin Karaman7fb80c22020-07-16 14:23:33 +0000833
npujarec5762e2020-01-01 14:08:48 +0530834 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
835 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530836 for _, tt := range tests {
837 t.Run(tt.name, func(t *testing.T) {
838
Girish Gowdra9602eb42020-09-09 15:50:39 -0700839 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 +0000840 if tt.wantErr {
841 if err == nil {
842 //error expected but got value
843 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, wantErr %v", got, tt.wantErr)
844 }
845 } else {
846 if err != nil {
847 //error is not expected but got error
848 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() error = %v, wantErr %v", err, tt.wantErr)
849 return
850 }
851 if got != tt.want {
852 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, want %v", got, tt.want)
853 }
kdarapu3248f9a2019-10-03 13:54:52 +0530854 }
kdarapu3248f9a2019-10-03 13:54:52 +0530855 })
856 }
857}
858
859func TestOpenOltFlowMgr_DeleteTechProfileInstance(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530860 type args struct {
861 intfID uint32
862 onuID uint32
863 uniID uint32
864 sn string
Gamze Abakafee36392019-10-03 11:17:24 +0000865 tpID uint32
kdarapu3248f9a2019-10-03 13:54:52 +0530866 }
867 tests := []struct {
868 name string
869 args args
870 wantErr bool
871 }{
872 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000873 {"DeleteTechProfileInstance", args{intfID: 0, onuID: 1, uniID: 1, sn: "", tpID: 64}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530874 }
npujarec5762e2020-01-01 14:08:48 +0530875 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
876 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530877 for _, tt := range tests {
878 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700879 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 +0530880 t.Errorf("OpenOltFlowMgr.DeleteTechProfileInstance() error = %v, wantErr %v", err, tt.wantErr)
881 }
882 })
883 }
884}
kdarapub26b4502019-10-05 03:02:33 +0530885
886func TestOpenOltFlowMgr_checkAndAddFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000887 ctx := context.Background()
kdarapub26b4502019-10-05 03:02:33 +0530888 kw := make(map[string]uint64)
889 kw["table_id"] = 1
890 kw["meter_id"] = 1
891 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
892
893 // Upstream flow
894 fa := &fu.FlowArgs{
895 MatchFields: []*ofp.OfpOxmOfbField{
896 fu.InPort(536870912),
897 fu.Metadata_ofp(1),
898 fu.IpProto(17), // dhcp
Gamze Abakafee36392019-10-03 11:17:24 +0000899 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300900 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530901 },
902 Actions: []*ofp.OfpAction{
903 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
904 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800905 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530906 fu.PushVlan(0x8100),
907 },
908 KV: kw,
909 }
910
911 // EAPOL
912 fa2 := &fu.FlowArgs{
913 MatchFields: []*ofp.OfpOxmOfbField{
914 fu.InPort(536870912),
915 fu.Metadata_ofp(1),
916 fu.EthType(0x888E),
917 fu.VlanPcp(1),
918 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
919 },
920 Actions: []*ofp.OfpAction{
921 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
922 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800923 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530924 fu.PushVlan(0x8100),
925 },
926 KV: kw,
927 }
928
929 // HSIA
930 fa3 := &fu.FlowArgs{
931 MatchFields: []*ofp.OfpOxmOfbField{
932 fu.InPort(536870912),
933 fu.Metadata_ofp(1),
934 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300935 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530936 },
937 Actions: []*ofp.OfpAction{
938 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300939 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800940 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530941 fu.PushVlan(0x8100),
942 },
943 KV: kw,
944 }
945
946 fa4 := &fu.FlowArgs{
947 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800948 fu.InPort(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530949 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300950 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530951 fu.VlanPcp(1),
952 },
953 Actions: []*ofp.OfpAction{
954 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300955 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
kdarapub26b4502019-10-05 03:02:33 +0530956 fu.Output(536870912),
957 fu.PopVlan(),
958 },
959 KV: kw,
960 }
961
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300962 // PPPOED
963 pppoedFA := &fu.FlowArgs{
964 MatchFields: []*ofp.OfpOxmOfbField{
965 fu.InPort(536870912),
966 fu.Metadata_ofp(1),
967 fu.EthType(0x8863),
968 fu.VlanPcp(1),
969 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
970 },
971 Actions: []*ofp.OfpAction{
972 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
973 fu.Output(1048576),
974 fu.PushVlan(0x8100),
975 },
976 KV: kw,
977 }
978
kdarapub26b4502019-10-05 03:02:33 +0530979 classifierInfo := make(map[string]interface{})
980 actionInfo := make(map[string]interface{})
981 classifierInfo2 := make(map[string]interface{})
982 actionInfo2 := make(map[string]interface{})
983 classifierInfo3 := make(map[string]interface{})
984 actionInfo3 := make(map[string]interface{})
985 classifierInfo4 := make(map[string]interface{})
986 actionInfo4 := make(map[string]interface{})
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300987 classifierInfo5 := make(map[string]interface{})
988 actionInfo5 := make(map[string]interface{})
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700989 flow, _ := fu.MkFlowStat(fa)
990 flow2, _ := fu.MkFlowStat(fa2)
991 flow3, _ := fu.MkFlowStat(fa3)
992 flow4, _ := fu.MkFlowStat(fa4)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300993 flow5, _ := fu.MkFlowStat(pppoedFA)
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700994 formulateClassifierInfoFromFlow(ctx, classifierInfo, flow)
995 formulateClassifierInfoFromFlow(ctx, classifierInfo2, flow2)
996 formulateClassifierInfoFromFlow(ctx, classifierInfo3, flow3)
997 formulateClassifierInfoFromFlow(ctx, classifierInfo4, flow4)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300998 formulateClassifierInfoFromFlow(ctx, classifierInfo5, flow5)
kdarapub26b4502019-10-05 03:02:33 +0530999
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001000 err := formulateActionInfoFromFlow(ctx, actionInfo, classifierInfo, flow)
kdarapub26b4502019-10-05 03:02:33 +05301001 if err != nil {
1002 // Error logging is already done in the called function
1003 // So just return in case of error
1004 return
1005 }
1006
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001007 err = formulateActionInfoFromFlow(ctx, actionInfo2, classifierInfo2, flow2)
kdarapub26b4502019-10-05 03:02:33 +05301008 if err != nil {
1009 // Error logging is already done in the called function
1010 // So just return in case of error
1011 return
1012 }
1013
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001014 err = formulateActionInfoFromFlow(ctx, actionInfo3, classifierInfo3, flow3)
kdarapub26b4502019-10-05 03:02:33 +05301015 if err != nil {
1016 // Error logging is already done in the called function
1017 // So just return in case of error
1018 return
1019 }
1020
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001021 err = formulateActionInfoFromFlow(ctx, actionInfo4, classifierInfo4, flow4)
kdarapub26b4502019-10-05 03:02:33 +05301022 if err != nil {
1023 // Error logging is already done in the called function
1024 // So just return in case of error
1025 return
1026 }
1027
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001028 err = formulateActionInfoFromFlow(ctx, actionInfo5, classifierInfo5, flow5)
1029 if err != nil {
1030 // Error logging is already done in the called function
1031 // So just return in case of error
1032 return
1033 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001034 /*
1035 usGemList := make([]*tp_pb.GemPortAttributes, 4)
1036 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1037 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1038 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1039 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1040 dsGemList := make([]*tp_pb.GemPortAttributes, 4)
1041 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1042 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1043 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1044 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1045 */
1046 TpInst := &tp_pb.TechProfileInstance{
kdarapub26b4502019-10-05 03:02:33 +05301047 Name: "Test-Tech-Profile",
1048 SubscriberIdentifier: "257",
1049 ProfileType: "Mock",
1050 Version: 1,
1051 NumGemPorts: 4,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001052 InstanceControl: &tp_pb.InstanceControl{
kdarapub26b4502019-10-05 03:02:33 +05301053 Onu: "1",
1054 Uni: "16",
1055 },
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001056 UsScheduler: &openoltpb2.SchedulerAttributes{},
1057 DsScheduler: &openoltpb2.SchedulerAttributes{},
kdarapub26b4502019-10-05 03:02:33 +05301058 }
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001059 TpInst.UsScheduler.Priority = 1
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001060 TpInst.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
1061 TpInst.UsScheduler.AllocId = 1
1062 TpInst.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
1063 TpInst.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001064 TpInst.UsScheduler.Weight = 4
1065
1066 TpInst.DsScheduler.Priority = 1
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001067 TpInst.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
1068 TpInst.DsScheduler.AllocId = 1
1069 TpInst.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
1070 TpInst.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001071 TpInst.DsScheduler.Weight = 4
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001072 TpInst.UpstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
1073 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
1074 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
1075 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
1076 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001077
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001078 TpInst.DownstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
1079 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
1080 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
1081 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
1082 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
kdarapub26b4502019-10-05 03:02:33 +05301083
kdarapub26b4502019-10-05 03:02:33 +05301084 type args struct {
1085 args map[string]uint32
1086 classifierInfo map[string]interface{}
1087 actionInfo map[string]interface{}
1088 flow *ofp.OfpFlowStats
1089 gemPort uint32
1090 intfID uint32
1091 onuID uint32
1092 uniID uint32
1093 portNo uint32
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001094 TpInst *tp_pb.TechProfileInstance
kdarapub26b4502019-10-05 03:02:33 +05301095 allocID []uint32
1096 gemPorts []uint32
1097 TpID uint32
1098 uni string
1099 }
1100 tests := []struct {
Kent Hagermane6ff1012020-07-14 15:07:53 -04001101 name string
1102 args args
kdarapub26b4502019-10-05 03:02:33 +05301103 }{
1104 {
1105 name: "checkAndAddFlow-1",
1106 args: args{
1107 args: nil,
1108 classifierInfo: classifierInfo,
1109 actionInfo: actionInfo,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001110 flow: flow,
kdarapub26b4502019-10-05 03:02:33 +05301111 gemPort: 1,
1112 intfID: 1,
1113 onuID: 1,
1114 uniID: 16,
1115 portNo: 1,
1116 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001117 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301118 gemPorts: []uint32{1, 2, 3, 4},
1119 TpID: 64,
1120 uni: "16",
1121 },
1122 },
1123 {
1124 name: "checkAndAddFlow-2",
1125 args: args{
1126 args: nil,
1127 classifierInfo: classifierInfo2,
1128 actionInfo: actionInfo2,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001129 flow: flow2,
kdarapub26b4502019-10-05 03:02:33 +05301130 gemPort: 1,
1131 intfID: 1,
1132 onuID: 1,
1133 uniID: 16,
1134 portNo: 1,
1135 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001136 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301137 gemPorts: []uint32{1, 2, 3, 4},
1138 TpID: 64,
1139 uni: "16",
1140 },
1141 },
1142 {
1143 name: "checkAndAddFlow-3",
1144 args: args{
1145 args: nil,
1146 classifierInfo: classifierInfo3,
1147 actionInfo: actionInfo3,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001148 flow: flow3,
kdarapub26b4502019-10-05 03:02:33 +05301149 gemPort: 1,
1150 intfID: 1,
1151 onuID: 1,
1152 uniID: 16,
1153 portNo: 1,
1154 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001155 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301156 gemPorts: []uint32{1, 2, 3, 4},
1157 TpID: 64,
1158 uni: "16",
1159 },
1160 },
1161 {
1162 name: "checkAndAddFlow-4",
1163 args: args{
1164 args: nil,
1165 classifierInfo: classifierInfo4,
1166 actionInfo: actionInfo4,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001167 flow: flow4,
kdarapub26b4502019-10-05 03:02:33 +05301168 gemPort: 1,
1169 intfID: 1,
1170 onuID: 1,
1171 uniID: 16,
1172 portNo: 1,
1173 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001174 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301175 gemPorts: []uint32{1, 2, 3, 4},
1176 TpID: 64,
1177 uni: "16",
1178 },
1179 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001180 {
1181 name: "checkAndAddFlow-5",
1182 args: args{
1183 args: nil,
1184 classifierInfo: classifierInfo5,
1185 actionInfo: actionInfo5,
1186 flow: flow5,
1187 gemPort: 1,
1188 intfID: 1,
1189 onuID: 1,
1190 uniID: 16,
1191 portNo: 1,
1192 TpInst: TpInst,
1193 allocID: []uint32{0x8001},
1194 gemPorts: []uint32{1, 2, 3, 4},
1195 TpID: 64,
1196 uni: "16",
1197 },
1198 },
kdarapub26b4502019-10-05 03:02:33 +05301199 }
npujarec5762e2020-01-01 14:08:48 +05301200 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1201 defer cancel()
kdarapub26b4502019-10-05 03:02:33 +05301202 for _, tt := range tests {
1203 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -07001204 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 +00001205 tt.args.TpInst, tt.args.gemPorts, tt.args.TpID, tt.args.uni)
kdarapub26b4502019-10-05 03:02:33 +05301206 })
1207 }
1208}
Esin Karamanccb714b2019-11-29 15:02:06 +00001209
Esin Karamand519bbf2020-07-01 11:16:03 +00001210func TestOpenOltFlowMgr_TestMulticastFlowAndGroup(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301211 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1212 defer cancel()
Esin Karamanccb714b2019-11-29 15:02:06 +00001213 //create group
1214 group := newGroup(2, []uint32{1})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001215 err := flowMgr[0].grpMgr.AddGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001216 if err != nil {
1217 t.Error("group-add failed", err)
1218 return
1219 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001220 //create multicast flow
1221 multicastFlowArgs := &fu.FlowArgs{
1222 MatchFields: []*ofp.OfpOxmOfbField{
Esin Karamand519bbf2020-07-01 11:16:03 +00001223 fu.InPort(1048576),
Esin Karamanccb714b2019-11-29 15:02:06 +00001224 fu.VlanVid(660), //vlan
1225 fu.Metadata_ofp(uint64(66)), //inner vlan
1226 fu.EthType(0x800), //ipv4
1227 fu.Ipv4Dst(3809869825), //227.22.0.1
1228 },
1229 Actions: []*ofp.OfpAction{
1230 fu.Group(1),
1231 },
1232 }
divyadesaid26f6b12020-03-19 06:30:28 +00001233 ofpStats, _ := fu.MkFlowStat(multicastFlowArgs)
Esin Karamand519bbf2020-07-01 11:16:03 +00001234 fmt.Println(ofpStats.Id)
Girish Gowdra9602eb42020-09-09 15:50:39 -07001235 err = flowMgr[0].AddFlow(ctx, ofpStats, &voltha.FlowMetadata{})
Esin Karamand519bbf2020-07-01 11:16:03 +00001236 if err != nil {
1237 t.Error("Multicast flow-add failed", err)
1238 return
1239 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001240
1241 //add bucket to the group
1242 group = newGroup(2, []uint32{1, 2})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001243 err = flowMgr[0].grpMgr.ModifyGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001244 if err != nil {
1245 t.Error("modify-group failed", err)
1246 return
1247 }
1248 //remove the multicast flow
Girish Gowdra9602eb42020-09-09 15:50:39 -07001249 err = flowMgr[0].RemoveFlow(ctx, ofpStats)
Esin Karamand519bbf2020-07-01 11:16:03 +00001250 if err != nil {
1251 t.Error("Multicast flow-remove failed", err)
1252 return
1253 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001254
Esin Karamand519bbf2020-07-01 11:16:03 +00001255 //remove the group
Girish Gowdra9602eb42020-09-09 15:50:39 -07001256 err = flowMgr[0].grpMgr.DeleteGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001257 if err != nil {
1258 t.Error("delete-group failed", err)
1259 return
1260 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001261}
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001262
1263func TestOpenOltFlowMgr_TestRouteFlowToOnuChannel(t *testing.T) {
1264 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1265 defer cancel()
1266 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/core", log.DebugLevel)
1267 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager", log.DebugLevel)
1268 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/pkg/mocks", log.DebugLevel)
Girish Gowdra0aca4982021-01-04 12:44:27 -08001269 kwTable1Meter1 := make(map[string]uint64)
1270 kwTable1Meter1["table_id"] = 1
1271 kwTable1Meter1["meter_id"] = 1
1272 kwTable1Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
1273
1274 kwTable0Meter1 := make(map[string]uint64)
1275 kwTable0Meter1["table_id"] = 0
1276 kwTable0Meter1["meter_id"] = 1
1277 kwTable0Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001278
1279 flowMetadata1 := voltha.FlowMetadata{Meters: []*voltha.OfpMeterConfig{
1280 {
1281 Flags: 5,
1282 MeterId: 1,
1283 Bands: []*voltha.OfpMeterBandHeader{
1284 {
1285 Type: voltha.OfpMeterBandType_OFPMBT_DROP,
1286 Rate: 16000,
Gamze Abaka01174422021-03-10 06:55:27 +00001287 BurstSize: 0,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001288 },
1289 {
1290 Type: voltha.OfpMeterBandType_OFPMBT_DROP,
1291 Rate: 32000,
1292 BurstSize: 30,
1293 },
1294 {
1295 Type: voltha.OfpMeterBandType_OFPMBT_DROP,
1296 Rate: 64000,
1297 BurstSize: 30,
1298 },
1299 },
1300 },
1301 }}
1302
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001303 // Downstream LLDP Trap from NNI0 flow
1304 fa0 := &fu.FlowArgs{
1305 MatchFields: []*ofp.OfpOxmOfbField{
1306 fu.InPort(1048576),
1307 fu.EthType(35020),
1308 },
1309 Actions: []*ofp.OfpAction{
1310 fu.Output(4294967293),
1311 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001312 KV: make(map[string]uint64),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001313 }
1314
1315 // Upstream flow DHCP flow - ONU1 UNI0 PON0
1316 fa1 := &fu.FlowArgs{
1317 MatchFields: []*ofp.OfpOxmOfbField{
1318 fu.InPort(536870912),
1319 fu.Metadata_ofp(1),
1320 fu.IpProto(17), // dhcp
1321 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001322 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001323 fu.TunnelId(16),
1324 },
1325 Actions: []*ofp.OfpAction{
1326 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1327 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1328 fu.Output(2147483645),
1329 fu.PushVlan(0x8100),
1330 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001331 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001332 }
1333
1334 // Upstream EAPOL - ONU1 UNI0 PON0
1335 fa2 := &fu.FlowArgs{
1336 MatchFields: []*ofp.OfpOxmOfbField{
1337 fu.InPort(536870912),
1338 fu.Metadata_ofp(1),
1339 fu.EthType(0x888E),
1340 fu.VlanPcp(1),
1341 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
1342 fu.TunnelId(16),
1343 },
1344 Actions: []*ofp.OfpAction{
1345 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1346 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1347 fu.Output(2147483645),
1348 fu.PushVlan(0x8100),
1349 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001350 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001351 }
1352
1353 // Upstream HSIA - ONU1 UNI0 PON0
1354 fa3 := &fu.FlowArgs{
1355 MatchFields: []*ofp.OfpOxmOfbField{
1356 fu.InPort(536870912),
1357 fu.Metadata_ofp(1),
1358 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001359 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001360 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001361 },
1362 Actions: []*ofp.OfpAction{
1363 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001364 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001365 fu.Output(1048576),
1366 fu.PushVlan(0x8100),
1367 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001368 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001369 }
1370
1371 // Downstream HSIA - ONU1 UNI0 PON0
1372 fa4 := &fu.FlowArgs{
1373 MatchFields: []*ofp.OfpOxmOfbField{
1374 fu.InPort(1048576),
1375 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001376 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001377 fu.VlanPcp(1),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001378 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001379 },
1380 Actions: []*ofp.OfpAction{
1381 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001382 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001383 fu.Output(536870912),
1384 fu.PopVlan(),
1385 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001386 KV: kwTable0Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001387 }
1388
1389 // Upstream flow DHCP flow - ONU1 UNI0 PON15
1390 fa5 := &fu.FlowArgs{
1391 MatchFields: []*ofp.OfpOxmOfbField{
1392 fu.InPort(536870927),
1393 fu.Metadata_ofp(1),
1394 fu.IpProto(17), // dhcp
1395 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001396 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001397 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001398 },
1399 Actions: []*ofp.OfpAction{
1400 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1401 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259)),
1402 fu.Output(2147483645),
1403 fu.PushVlan(0x8100),
1404 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001405 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001406 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001407
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001408 // Upstream EAPOL - ONU1 UNI0 PON15
1409 fa6 := &fu.FlowArgs{
1410 MatchFields: []*ofp.OfpOxmOfbField{
1411 fu.InPort(536870927),
1412 fu.Metadata_ofp(1),
1413 fu.EthType(0x888E),
1414 fu.VlanPcp(1),
1415 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001416 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001417 },
1418 Actions: []*ofp.OfpAction{
1419 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1420 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1421 fu.Output(2147483645),
1422 fu.PushVlan(0x8100),
1423 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001424 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001425 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001426
1427 // Upstream PPPOED - ONU1 UNI0 PON0
1428 fa7 := &fu.FlowArgs{
1429 MatchFields: []*ofp.OfpOxmOfbField{
1430 fu.InPort(536870912),
1431 fu.Metadata_ofp(1),
1432 fu.EthType(0x8863),
1433 fu.VlanPcp(1),
1434 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
1435 fu.TunnelId(16),
1436 },
1437 Actions: []*ofp.OfpAction{
1438 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1439 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1440 fu.Output(2147483645),
1441 fu.PushVlan(0x8100),
1442 },
1443 KV: kwTable1Meter1,
1444 }
1445
1446 // Upstream PPPOED - ONU1 UNI0 PON15
1447 fa8 := &fu.FlowArgs{
1448 MatchFields: []*ofp.OfpOxmOfbField{
1449 fu.InPort(536870927),
1450 fu.Metadata_ofp(1),
1451 fu.EthType(0x8863),
1452 fu.VlanPcp(1),
1453 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
1454 fu.TunnelId(16),
1455 },
1456 Actions: []*ofp.OfpAction{
1457 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1458 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1459 fu.Output(2147483645),
1460 fu.PushVlan(0x8100),
1461 },
1462 KV: kwTable1Meter1,
1463 }
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001464 flow0, _ := fu.MkFlowStat(fa0)
1465 flow1, _ := fu.MkFlowStat(fa1)
1466 flow2, _ := fu.MkFlowStat(fa2)
1467 flow3, _ := fu.MkFlowStat(fa3)
1468 flow4, _ := fu.MkFlowStat(fa4)
1469
1470 flow5, _ := fu.MkFlowStat(fa5)
1471 flow6, _ := fu.MkFlowStat(fa6)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001472 flow7, _ := fu.MkFlowStat(fa7)
1473 flow8, _ := fu.MkFlowStat(fa8)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001474
1475 type args struct {
1476 ctx context.Context
1477 flow *ofp.OfpFlowStats
1478 addFlow bool
1479 flowMetadata *voltha.FlowMetadata
1480 }
1481 tests := []struct {
1482 name string
1483 args args
1484 wantErr bool
1485 returnedErr error
1486 }{
1487 {
1488 name: "RouteFlowToOnuChannel-0",
1489 args: args{
1490 ctx: ctx,
1491 flow: flow0,
1492 addFlow: true,
1493 flowMetadata: &flowMetadata1,
1494 },
1495 wantErr: false,
1496 },
1497 {
1498 name: "RouteFlowToOnuChannel-1",
1499 args: args{
1500 ctx: ctx,
1501 flow: flow1,
1502 addFlow: true,
1503 flowMetadata: &flowMetadata1,
1504 },
1505 wantErr: false,
1506 },
1507 {
1508 name: "RouteFlowToOnuChannel-2",
1509 args: args{
1510 ctx: ctx,
1511 flow: flow2,
1512 addFlow: true,
1513 flowMetadata: &flowMetadata1,
1514 },
1515 wantErr: false,
1516 },
1517 {
1518 name: "RouteFlowToOnuChannel-3",
1519 args: args{
1520 ctx: ctx,
1521 flow: flow3,
1522 addFlow: true,
1523 flowMetadata: &flowMetadata1,
1524 },
1525 wantErr: false,
1526 },
1527 {
1528 name: "RouteFlowToOnuChannel-4",
1529 args: args{
1530 ctx: ctx,
1531 flow: flow4,
1532 addFlow: true,
1533 flowMetadata: &flowMetadata1,
1534 },
1535 wantErr: false,
1536 },
1537 {
1538 name: "RouteFlowToOnuChannel-5",
1539 args: args{
1540 ctx: ctx,
1541 flow: flow1,
1542 addFlow: false,
1543 flowMetadata: &flowMetadata1,
1544 },
1545 wantErr: false,
1546 },
1547 {
1548 name: "RouteFlowToOnuChannel-6",
1549 args: args{
1550 ctx: ctx,
1551 flow: flow1,
1552 addFlow: true,
Girish Gowdra0aca4982021-01-04 12:44:27 -08001553 flowMetadata: &flowMetadata1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001554 },
1555 wantErr: true,
1556 },
1557 {
1558 name: "RouteFlowToOnuChannel-7",
1559 args: args{
1560 ctx: ctx,
1561 flow: flow5,
1562 addFlow: true,
1563 flowMetadata: &flowMetadata1,
1564 },
1565 wantErr: false,
1566 },
1567 {
1568 name: "RouteFlowToOnuChannel-8",
1569 args: args{
1570 ctx: ctx,
1571 flow: flow6,
1572 addFlow: true,
1573 flowMetadata: &flowMetadata1,
1574 },
1575 wantErr: false,
1576 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001577 {
1578 name: "RouteFlowToOnuChannel-9",
1579 args: args{
1580 ctx: ctx,
1581 flow: flow7,
1582 addFlow: true,
1583 flowMetadata: &flowMetadata1,
1584 },
1585 wantErr: false,
1586 },
1587 {
1588 name: "RouteFlowToOnuChannel-10",
1589 args: args{
1590 ctx: ctx,
1591 flow: flow8,
1592 addFlow: true,
1593 flowMetadata: &flowMetadata1,
1594 },
1595 wantErr: false,
1596 },
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001597 }
1598
1599 var wg sync.WaitGroup
1600 defer wg.Wait() // wait for all go routines to complete
1601 for _, tt := range tests {
1602 t.Run(tt.name, func(t *testing.T) {
1603 wg.Add(1) // one per go routine
1604 go func() {
1605 defer wg.Done()
1606 tt.returnedErr = flowMgr[0].RouteFlowToOnuChannel(tt.args.ctx, tt.args.flow, tt.args.addFlow, tt.args.flowMetadata)
1607 if (tt.wantErr == false && tt.returnedErr != nil) || (tt.wantErr == true && tt.returnedErr == nil) {
1608 t.Errorf("OpenOltFlowMgr.RouteFlowToOnuChannel() error = %v, wantErr %v", tt.returnedErr, tt.wantErr)
1609 }
1610 }()
1611 })
1612 }
1613}