blob: 214fa611ead9aaef5bbc83fffd2e11b7ff98866e [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
Girish Gowdraa09aeab2020-09-14 16:30:52 -070030 "github.com/opencord/voltha-protos/v4/go/voltha"
kdarapub26b4502019-10-05 03:02:33 +053031
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070032 fu "github.com/opencord/voltha-lib-go/v5/pkg/flows"
33 "github.com/opencord/voltha-lib-go/v5/pkg/log"
Scott Bakerdbd960e2020-02-28 08:57:51 -080034 rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070035 ofp "github.com/opencord/voltha-protos/v4/go/openflow_13"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070036 openoltpb2 "github.com/opencord/voltha-protos/v4/go/openolt"
37 tp_pb "github.com/opencord/voltha-protos/v4/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 Gowdra8a0bdcd2021-05-13 12:31:04 -070058 dh.flowMgr[i].techprofile = dh.resourceMgr[i].PonRsrMgr.TechProfileMgr
Girish Gowdra9602eb42020-09-09 15:50:39 -070059 interface2mcastQeueuMap := make(map[uint32]*QueueInfoBrief)
60 interface2mcastQeueuMap[0] = &QueueInfoBrief{
61 gemPortID: 4000,
62 servicePriority: 3,
63 }
64 dh.flowMgr[i].grpMgr.interfaceToMcastQueueMap = interface2mcastQeueuMap
kdarapu3248f9a2019-10-03 13:54:52 +053065 }
Girish Gowdra9602eb42020-09-09 15:50:39 -070066 return dh.flowMgr
kdarapu3248f9a2019-10-03 13:54:52 +053067}
kdarapub26b4502019-10-05 03:02:33 +053068
kdarapu3248f9a2019-10-03 13:54:52 +053069func TestOpenOltFlowMgr_CreateSchedulerQueues(t *testing.T) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070070 tprofile := &tp_pb.TechProfileInstance{Name: "tp1", SubscriberIdentifier: "subscriber1",
Girish Gowdra54934262019-11-13 14:19:55 +053071 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070072 InstanceControl: &tp_pb.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"},
kdarapu3248f9a2019-10-03 13:54:52 +053073 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070074 tprofile.UsScheduler = &openoltpb2.SchedulerAttributes{}
75 tprofile.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
76 tprofile.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +053077
78 tprofile2 := tprofile
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070079 tprofile2.DsScheduler = &openoltpb2.SchedulerAttributes{}
80 tprofile2.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
81 tprofile2.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Gamze Abaka01174422021-03-10 06:55:27 +000082
kdarapu3248f9a2019-10-03 13:54:52 +053083 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +000084 name string
85 schedQueue schedQueue
86 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +053087 }{
88 // TODO: Add test cases.
Gamze Abaka01174422021-03-10 06:55:27 +000089 {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 1, Upstream)}, false},
90 {"CreateSchedulerQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 1, Downstream)}, false},
91 {"CreateSchedulerQueues-13", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 2, Upstream)}, false},
92 {"CreateSchedulerQueues-14", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 2, Downstream)}, false},
93 {"CreateSchedulerQueues-15", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 3, Upstream)}, false},
94 {"CreateSchedulerQueues-16", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 3, Downstream)}, false},
95 {"CreateSchedulerQueues-17", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 4, Upstream)}, false},
96 {"CreateSchedulerQueues-18", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 4, Downstream)}, false},
97 {"CreateSchedulerQueues-19", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 5, Upstream)}, false},
98 {"CreateSchedulerQueues-20", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 5, Downstream)}, false},
99
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700100 {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 0, Upstream)}, false},
101 {"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 +0000102 {"CreateSchedulerQueues-3", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, createFlowMetadata(tprofile, 2, Upstream)}, true},
103 {"CreateSchedulerQueues-4", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, createFlowMetadata(tprofile2, 2, Downstream)}, true},
104 {"CreateSchedulerQueues-5", schedQueue{tp_pb.Direction_UPSTREAM, 1, 2, 2, 64, 2, tprofile, 2, createFlowMetadata(tprofile, 3, Upstream)}, true},
105 {"CreateSchedulerQueues-6", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 2, 2, 65, 2, tprofile2, 2, createFlowMetadata(tprofile2, 3, Downstream)}, true},
106
kdarapu3248f9a2019-10-03 13:54:52 +0530107 //Negative testcases
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700108 {"CreateSchedulerQueues-7", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, &voltha.FlowMetadata{}}, false},
Girish Gowdra9602eb42020-09-09 15:50:39 -0700109 {"CreateSchedulerQueues-8", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 0, &voltha.FlowMetadata{}}, true},
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700110 {"CreateSchedulerQueues-9", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, &voltha.FlowMetadata{}}, false},
Girish Gowdra9602eb42020-09-09 15:50:39 -0700111 {"CreateSchedulerQueues-10", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, &voltha.FlowMetadata{}}, true},
112 {"CreateSchedulerQueues-11", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, &voltha.FlowMetadata{}}, true},
113 {"CreateSchedulerQueues-12", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, nil}, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530114 }
npujarec5762e2020-01-01 14:08:48 +0530115 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
116 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530117 for _, tt := range tests {
118 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700119 if err := flowMgr[tt.schedQueue.intfID].CreateSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530120 t.Errorf("OpenOltFlowMgr.CreateSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr)
121 }
122 })
123 }
124}
125
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700126func createFlowMetadata(techProfile *tp_pb.TechProfileInstance, tcontType int, direction string) *voltha.FlowMetadata {
127 var additionalBw openoltpb2.AdditionalBW
Gamze Abaka01174422021-03-10 06:55:27 +0000128 bands := make([]*ofp.OfpMeterBandHeader, 0)
129 switch tcontType {
130 case 1:
131 //tcont-type-1
132 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
133 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700134 additionalBw = tp_pb.AdditionalBW_AdditionalBW_None
Gamze Abaka01174422021-03-10 06:55:27 +0000135 case 2:
136 //tcont-type-2
137 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 60000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
138 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700139 additionalBw = tp_pb.AdditionalBW_AdditionalBW_None
Gamze Abaka01174422021-03-10 06:55:27 +0000140 case 3:
141 //tcont-type-3
142 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
143 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 20000, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700144 additionalBw = tp_pb.AdditionalBW_AdditionalBW_NA
Gamze Abaka01174422021-03-10 06:55:27 +0000145 case 4:
146 //tcont-type-4
147 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 200000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700148 additionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
Gamze Abaka01174422021-03-10 06:55:27 +0000149 case 5:
150 //tcont-type-5
151 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
152 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
153 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700154 additionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
Gamze Abaka01174422021-03-10 06:55:27 +0000155 default:
156 // do nothing, we will return meter config with no meter bands
157 }
158
159 if direction == Downstream {
160 techProfile.DsScheduler.AdditionalBw = additionalBw
161 } else {
162 techProfile.UsScheduler.AdditionalBw = additionalBw
163 }
164
165 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
166 return &voltha.FlowMetadata{
167 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}}
168}
169
kdarapu3248f9a2019-10-03 13:54:52 +0530170func TestOpenOltFlowMgr_RemoveSchedulerQueues(t *testing.T) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700171 tprofile := &tp_pb.TechProfileInstance{Name: "tp1", SubscriberIdentifier: "subscriber1",
Girish Gowdra54934262019-11-13 14:19:55 +0530172 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700173 InstanceControl: &tp_pb.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"},
kdarapu3248f9a2019-10-03 13:54:52 +0530174 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700175 tprofile.UsScheduler = &openoltpb2.SchedulerAttributes{}
176 tprofile.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
177 tprofile.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
178 tprofile.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +0530179
180 tprofile2 := tprofile
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700181 tprofile2.DsScheduler = &openoltpb2.SchedulerAttributes{}
182 tprofile2.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
183 tprofile2.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
184 tprofile2.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +0530185 //defTprofile := &tp.DefaultTechProfile{}
kdarapu3248f9a2019-10-03 13:54:52 +0530186 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +0000187 name string
188 schedQueue schedQueue
189 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +0530190 }{
191 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000192 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 0, nil}, false},
193 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530194 // negative test cases
Gamze Abakafee36392019-10-03 11:17:24 +0000195 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
196 {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530197 }
npujarec5762e2020-01-01 14:08:48 +0530198 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
199 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530200 for _, tt := range tests {
201 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700202 if err := flowMgr[tt.schedQueue.intfID].RemoveSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530203 t.Errorf("OpenOltFlowMgr.RemoveSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr)
204 }
205 })
206 }
kdarapub26b4502019-10-05 03:02:33 +0530207
kdarapu3248f9a2019-10-03 13:54:52 +0530208}
209
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700210func TestOpenOltFlowMgr_createTcontGemports(t *testing.T) {
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700211 bands := make([]*ofp.OfpMeterBandHeader, 2)
212 bands[0] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 1000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
213 bands[1] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 2000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
214 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
215 flowmetadata := &voltha.FlowMetadata{
216 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
217 }
218 type args struct {
219 intfID uint32
220 onuID uint32
221 uniID uint32
222 uni string
223 uniPort uint32
224 TpID uint32
225 UsMeterID uint32
226 DsMeterID uint32
227 flowMetadata *voltha.FlowMetadata
228 }
229 tests := []struct {
230 name string
231 args args
232 }{
233 {"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 -0700234 }
235 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
236 defer cancel()
237 for _, tt := range tests {
238 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700239 _, _, 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 -0700240 switch tpInst := tpInst.(type) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700241 case *tp_pb.TechProfileInstance:
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700242 if tt.args.TpID != 64 {
243 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
244 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700245 case *tp_pb.EponTechProfileInstance:
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700246 if tt.args.TpID != 65 {
247 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
248 }
249 default:
250 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
251 }
252 })
253 }
254}
255
kdarapu3248f9a2019-10-03 13:54:52 +0530256func TestOpenOltFlowMgr_RemoveFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000257 ctx := context.Background()
Neha Sharma96b7bf22020-06-15 10:37:32 +0000258 logger.Debug(ctx, "Info Warning Error: Starting RemoveFlow() test")
kdarapu3248f9a2019-10-03 13:54:52 +0530259 fa := &fu.FlowArgs{
260 MatchFields: []*ofp.OfpOxmOfbField{
261 fu.InPort(2),
262 fu.Metadata_ofp(2),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300263 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapu3248f9a2019-10-03 13:54:52 +0530264 },
265 Actions: []*ofp.OfpAction{
266 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
267 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
268 fu.Output(1),
269 },
270 }
divyadesaid26f6b12020-03-19 06:30:28 +0000271 ofpstats, _ := fu.MkFlowStat(fa)
kdarapub26b4502019-10-05 03:02:33 +0530272 ofpstats.Cookie = ofpstats.Id
kdarapub26b4502019-10-05 03:02:33 +0530273 lldpFa := &fu.FlowArgs{
274 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
275 MatchFields: []*ofp.OfpOxmOfbField{
276 fu.InPort(1),
277 fu.EthType(0x88CC),
278 fu.TunnelId(536870912),
279 },
280 Actions: []*ofp.OfpAction{
281 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
282 },
283 }
divyadesaid26f6b12020-03-19 06:30:28 +0000284 lldpofpstats, _ := fu.MkFlowStat(lldpFa)
kdarapub26b4502019-10-05 03:02:33 +0530285 //lldpofpstats.Cookie = lldpofpstats.Id
286
287 dhcpFa := &fu.FlowArgs{
288 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
289 MatchFields: []*ofp.OfpOxmOfbField{
290 fu.InPort(1),
291 fu.UdpSrc(67),
292 //fu.TunnelId(536870912),
293 fu.IpProto(17),
294 },
295 Actions: []*ofp.OfpAction{
296 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
297 },
298 }
divyadesaid26f6b12020-03-19 06:30:28 +0000299 dhcpofpstats, _ := fu.MkFlowStat(dhcpFa)
kdarapub26b4502019-10-05 03:02:33 +0530300 //dhcpofpstats.Cookie = dhcpofpstats.Id
Esin Karamanccb714b2019-11-29 15:02:06 +0000301
302 //multicast flow
303 multicastFa := &fu.FlowArgs{
304 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800305 fu.InPort(1048576),
Esin Karamanccb714b2019-11-29 15:02:06 +0000306 fu.VlanVid(660), //vlan
307 fu.Metadata_ofp(uint64(66)), //inner vlan
308 fu.EthType(0x800), //ipv4
309 fu.Ipv4Dst(3809869825), //227.22.0.1
310 },
311 Actions: []*ofp.OfpAction{
312 fu.Group(1),
313 },
314 }
divyadesaid26f6b12020-03-19 06:30:28 +0000315 multicastOfpStats, _ := fu.MkFlowStat(multicastFa)
Esin Karamanccb714b2019-11-29 15:02:06 +0000316 multicastOfpStats.Id = 1
317
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300318 pppoedFa := &fu.FlowArgs{
319 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
320 MatchFields: []*ofp.OfpOxmOfbField{
321 fu.InPort(1),
322 fu.EthType(0x8863),
323 fu.TunnelId(536870912),
324 },
325 Actions: []*ofp.OfpAction{
326 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
327 },
328 }
329 pppoedOfpStats, _ := fu.MkFlowStat(pppoedFa)
330
kdarapu3248f9a2019-10-03 13:54:52 +0530331 type args struct {
332 flow *ofp.OfpFlowStats
333 }
334 tests := []struct {
335 name string
336 args args
337 }{
338 // TODO: Add test cases.
339 {"RemoveFlow", args{flow: ofpstats}},
kdarapub26b4502019-10-05 03:02:33 +0530340 {"RemoveFlow", args{flow: lldpofpstats}},
341 {"RemoveFlow", args{flow: dhcpofpstats}},
Esin Karamanccb714b2019-11-29 15:02:06 +0000342 {"RemoveFlow", args{flow: multicastOfpStats}},
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300343 {"RemoveFlow", args{flow: pppoedOfpStats}},
kdarapu3248f9a2019-10-03 13:54:52 +0530344 }
npujarec5762e2020-01-01 14:08:48 +0530345 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
346 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530347 for _, tt := range tests {
348 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700349 if err := flowMgr[0].RemoveFlow(ctx, tt.args.flow); err != nil {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400350 logger.Warn(ctx, err)
351 }
kdarapu3248f9a2019-10-03 13:54:52 +0530352 })
353 }
kdarapub26b4502019-10-05 03:02:33 +0530354 // t.Error("=====")
kdarapu3248f9a2019-10-03 13:54:52 +0530355}
356
357func TestOpenOltFlowMgr_AddFlow(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530358 kw := make(map[string]uint64)
359 kw["table_id"] = 1
360 kw["meter_id"] = 1
kdarapub26b4502019-10-05 03:02:33 +0530361 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
362
363 // Upstream flow
kdarapu3248f9a2019-10-03 13:54:52 +0530364 fa := &fu.FlowArgs{
365 MatchFields: []*ofp.OfpOxmOfbField{
kdarapub26b4502019-10-05 03:02:33 +0530366 fu.InPort(536870912),
367 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300368 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530369 },
370 Actions: []*ofp.OfpAction{
371 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
372 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800373 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530374 fu.PushVlan(0x8100),
375 },
376 KV: kw,
377 }
378
379 // Downstream flow
380 fa3 := &fu.FlowArgs{
381 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800382 fu.InPort(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530383 fu.Metadata_ofp(1),
384 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
385 },
386 Actions: []*ofp.OfpAction{
387 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
388 //fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
389 fu.PopVlan(),
390 fu.Output(536870912),
391 },
392 KV: kw,
393 }
394
395 fa2 := &fu.FlowArgs{
396 MatchFields: []*ofp.OfpOxmOfbField{
kdarapu3248f9a2019-10-03 13:54:52 +0530397 fu.InPort(1000),
398 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300399 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapu3248f9a2019-10-03 13:54:52 +0530400 },
401 Actions: []*ofp.OfpAction{
402 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
403 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
404 fu.Output(65533),
405 },
406 KV: kw,
407 }
408
kdarapub26b4502019-10-05 03:02:33 +0530409 // TODO Add LLDP flow
410 // TODO Add DHCP flow
411
412 // Flows for negative scenarios
413 // Failure in formulateActionInfoFromFlow()
414 fa4 := &fu.FlowArgs{
415 MatchFields: []*ofp.OfpOxmOfbField{
416 fu.InPort(1000),
417 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300418 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530419 },
420 Actions: []*ofp.OfpAction{
421 fu.Experimenter(257, []byte{1, 2, 3, 4}),
422 },
423 KV: kw,
424 }
425
426 // Invalid Output
427 fa5 := &fu.FlowArgs{
428 MatchFields: []*ofp.OfpOxmOfbField{
429 fu.InPort(1000),
430 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300431 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530432 },
433 Actions: []*ofp.OfpAction{
434 fu.Output(0),
435 },
436 KV: kw,
437 }
438
439 // Tech-Profile-ID update (not supported)
440 kw6 := make(map[string]uint64)
441 kw6["table_id"] = 1
442 kw6["meter_id"] = 1
443 kw6["write_metadata"] = 0x4100000000 // TpID Other than the stored one
444 fa6 := &fu.FlowArgs{
445 MatchFields: []*ofp.OfpOxmOfbField{
446 fu.InPort(536870912),
447 fu.TunnelId(16),
448 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300449 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530450 },
451 Actions: []*ofp.OfpAction{
452 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
453 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
454 fu.Output(65535),
455 },
456 KV: kw6,
457 }
458
459 lldpFa := &fu.FlowArgs{
460 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
461 MatchFields: []*ofp.OfpOxmOfbField{
462 fu.InPort(1),
463 fu.EthType(0x88CC),
464 fu.TunnelId(536870912),
465 },
466 Actions: []*ofp.OfpAction{
467 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
468 },
469 }
470
471 dhcpFa := &fu.FlowArgs{
472 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
473 MatchFields: []*ofp.OfpOxmOfbField{
474 fu.InPort(1),
475 fu.UdpSrc(67),
476 //fu.TunnelId(536870912),
477 fu.IpProto(17),
478 },
479 Actions: []*ofp.OfpAction{
480 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
481 },
482 }
483 igmpFa := &fu.FlowArgs{
484 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
485 MatchFields: []*ofp.OfpOxmOfbField{
486 fu.InPort(1),
487 fu.UdpSrc(67),
488 //fu.TunnelId(536870912),
489 fu.IpProto(2),
490 },
491 Actions: []*ofp.OfpAction{
492 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
493 },
494 }
495
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300496 pppoedFa := &fu.FlowArgs{
497 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
498 MatchFields: []*ofp.OfpOxmOfbField{
499 fu.InPort(1),
500 fu.EthType(0x8863),
501 fu.TunnelId(536870912),
502 },
503 Actions: []*ofp.OfpAction{
504 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
505 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
506 },
507 }
508
kdarapub26b4502019-10-05 03:02:33 +0530509 fa9 := &fu.FlowArgs{
510 MatchFields: []*ofp.OfpOxmOfbField{
511 fu.InPort(536870912),
512 fu.TunnelId(16),
513 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300514 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530515 fu.VlanPcp(1000),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800516 fu.UdpDst(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530517 fu.UdpSrc(536870912),
518 fu.Ipv4Dst(65535),
519 fu.Ipv4Src(536870912),
520 },
521 Actions: []*ofp.OfpAction{
522 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
523 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
524 fu.Output(65535),
525 },
526 KV: kw6,
527 }
528
529 fa10 := &fu.FlowArgs{
530 MatchFields: []*ofp.OfpOxmOfbField{
531 fu.InPort(65533),
532 // fu.TunnelId(16),
533 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300534 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530535 fu.VlanPcp(1000),
536 fu.UdpDst(65535),
537 fu.UdpSrc(536870912),
538 fu.Ipv4Dst(65535),
539 fu.Ipv4Src(536870912),
540 },
541 Actions: []*ofp.OfpAction{
542 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
543 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
544 fu.Output(65535),
545 },
546 KV: kw6,
547 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000548 //multicast flow
549 fa11 := &fu.FlowArgs{
550 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800551 fu.InPort(1048576),
Esin Karamanccb714b2019-11-29 15:02:06 +0000552 fu.VlanVid(660), //vlan
553 fu.Metadata_ofp(uint64(66)), //inner vlan
554 fu.EthType(0x800), //ipv4
555 fu.Ipv4Dst(3809869825), //227.22.0.1
556 },
557 Actions: []*ofp.OfpAction{
558 fu.Group(1),
559 },
560 KV: kw6,
561 }
divyadesaid26f6b12020-03-19 06:30:28 +0000562 ofpstats, _ := fu.MkFlowStat(fa)
563 ofpstats2, _ := fu.MkFlowStat(fa2)
564 ofpstats3, _ := fu.MkFlowStat(fa3)
565 ofpstats4, _ := fu.MkFlowStat(fa4)
566 ofpstats5, _ := fu.MkFlowStat(fa5)
567 ofpstats6, _ := fu.MkFlowStat(fa6)
568 ofpstats7, _ := fu.MkFlowStat(lldpFa)
569 ofpstats8, _ := fu.MkFlowStat(dhcpFa)
570 ofpstats9, _ := fu.MkFlowStat(fa9)
571 ofpstats10, _ := fu.MkFlowStat(fa10)
572 igmpstats, _ := fu.MkFlowStat(igmpFa)
573 ofpstats11, _ := fu.MkFlowStat(fa11)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300574 pppoedstats, _ := fu.MkFlowStat(pppoedFa)
kdarapub26b4502019-10-05 03:02:33 +0530575
Gamze Abakafee36392019-10-03 11:17:24 +0000576 fmt.Println(ofpstats6, ofpstats9, ofpstats10)
577
kdarapu3248f9a2019-10-03 13:54:52 +0530578 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1}
kdarapu3248f9a2019-10-03 13:54:52 +0530579 flowMetadata := &voltha.FlowMetadata{
580 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
581 }
582 type args struct {
583 flow *ofp.OfpFlowStats
584 flowMetadata *voltha.FlowMetadata
585 }
586 tests := []struct {
587 name string
588 args args
589 }{
590 // TODO: Add test cases.
591 {"AddFlow", args{flow: ofpstats, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530592 {"AddFlow", args{flow: ofpstats2, flowMetadata: flowMetadata}},
593 {"AddFlow", args{flow: ofpstats3, flowMetadata: flowMetadata}},
594 {"AddFlow", args{flow: ofpstats4, flowMetadata: flowMetadata}},
595 {"AddFlow", args{flow: ofpstats5, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000596 //{"AddFlow", args{flow: ofpstats6, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530597 {"AddFlow", args{flow: ofpstats7, flowMetadata: flowMetadata}},
598 {"AddFlow", args{flow: ofpstats8, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000599 //{"AddFlow", args{flow: ofpstats9, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530600 {"AddFlow", args{flow: igmpstats, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000601 //{"AddFlow", args{flow: ofpstats10, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530602 //ofpstats10
Esin Karamanccb714b2019-11-29 15:02:06 +0000603 {"AddFlow", args{flow: ofpstats11, flowMetadata: flowMetadata}},
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300604 {"AddFlow", args{flow: pppoedstats, flowMetadata: flowMetadata}},
kdarapu3248f9a2019-10-03 13:54:52 +0530605 }
npujarec5762e2020-01-01 14:08:48 +0530606 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
607 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530608 for _, tt := range tests {
609 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700610 _ = flowMgr[0].AddFlow(ctx, tt.args.flow, tt.args.flowMetadata)
Kent Hagermane6ff1012020-07-14 15:07:53 -0400611 // TODO: actually verify test cases
kdarapu3248f9a2019-10-03 13:54:52 +0530612 })
613 }
614}
615
616func TestOpenOltFlowMgr_UpdateOnuInfo(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530617 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
618 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530619
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700620 wg := sync.WaitGroup{}
621
Girish Gowdra9602eb42020-09-09 15:50:39 -0700622 intfCount := NumPonPorts
623 onuCount := OnuIDEnd - OnuIDStart + 1
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700624
625 for i := 0; i < intfCount; i++ {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700626 for j := 1; j <= onuCount; j++ {
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700627 wg.Add(1)
628 go func(i uint32, j uint32) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400629 // TODO: actually verify success
Girish Gowdra9602eb42020-09-09 15:50:39 -0700630 _ = flowMgr[i].UpdateOnuInfo(ctx, i, i, fmt.Sprintf("onu-%d", i))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700631 wg.Done()
632 }(uint32(i), uint32(j))
633 }
634
635 }
636
637 wg.Wait()
638}
639
640func TestOpenOltFlowMgr_addGemPortToOnuInfoMap(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700641 intfNum := NumPonPorts
642 onuNum := OnuIDEnd - OnuIDStart + 1
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700643
644 // clean the flowMgr
Girish Gowdra9602eb42020-09-09 15:50:39 -0700645 for i := 0; i < intfNum; i++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700646 flowMgr[i].onuGemInfoMap = make(map[uint32]*rsrcMgr.OnuGemInfo)
Girish Gowdra9602eb42020-09-09 15:50:39 -0700647 }
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700648
649 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
650 defer cancel()
651
652 // Create OnuInfo
653 for i := 0; i < intfNum; i++ {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700654 for o := 1; o <= onuNum; o++ {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400655 // TODO: actually verify success
Girish Gowdra9602eb42020-09-09 15:50:39 -0700656 _ = flowMgr[i].UpdateOnuInfo(ctx, uint32(i), uint32(o), fmt.Sprintf("i%do%d", i, o-1))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700657 }
658 }
659
660 // Add gemPorts to OnuInfo in parallel threads
661 wg := sync.WaitGroup{}
Girish Gowdra9602eb42020-09-09 15:50:39 -0700662 for o := 1; o <= onuNum; o++ {
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700663 for i := 0; i < intfNum; i++ {
664 wg.Add(1)
665 go func(intfId uint32, onuId uint32) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700666 gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", intfId, onuId-1))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700667
Girish Gowdra9602eb42020-09-09 15:50:39 -0700668 flowMgr[intfId].addGemPortToOnuInfoMap(ctx, intfId, onuId, uint32(gemID))
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700669 wg.Done()
670 }(uint32(i), uint32(o))
671 }
672 }
673
674 wg.Wait()
675
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700676 // check that each entry of onuGemInfoMap has the correct number of ONUs
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700677 for i := 0; i < intfNum; i++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700678 lenofOnu := len(flowMgr[i].onuGemInfoMap)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700679 if onuNum != lenofOnu {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700680 t.Errorf("onuGemInfoMap length is not as expected len = %d, want %d", lenofOnu, onuNum)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700681 }
682
Girish Gowdra9602eb42020-09-09 15:50:39 -0700683 for o := 1; o <= onuNum; o++ {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700684 lenOfGemPorts := len(flowMgr[i].onuGemInfoMap[uint32(o)].GemPorts)
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700685 // check that each onuEntry has 1 gemPort
686 if lenOfGemPorts != 1 {
687 t.Errorf("Expected 1 GemPort per ONU, found %d", lenOfGemPorts)
688 }
689
690 // check that the value of the gemport is correct
Girish Gowdra9602eb42020-09-09 15:50:39 -0700691 gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", i, o-1))
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700692 currentValue := flowMgr[i].onuGemInfoMap[uint32(o)].GemPorts[0]
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700693 if uint32(gemID) != currentValue {
694 t.Errorf("Expected GemPort value to be %d, found %d", gemID, currentValue)
695 }
696 }
kdarapu3248f9a2019-10-03 13:54:52 +0530697 }
698}
699
serkant.uluderya96af4932020-02-20 16:58:48 -0800700func TestOpenOltFlowMgr_deleteGemPortFromLocalCache(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700701 // Create fresh flowMgr instance
702 flowMgr = newMockFlowmgr()
serkant.uluderya96af4932020-02-20 16:58:48 -0800703 type args struct {
704 intfID uint32
705 onuID uint32
706 gemPortIDs []uint32
707 gemPortIDsToBeDeleted []uint32
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700708 gemPortIDsRemaining []uint32
serkant.uluderya96af4932020-02-20 16:58:48 -0800709 serialNum string
710 finalLength int
711 }
712 tests := []struct {
713 name string
714 args args
715 }{
716 // Add/Delete single gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700717 {"DeleteGemPortFromLocalCache1", args{0, 1, []uint32{1}, []uint32{1}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800718 // Delete all gemports
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700719 {"DeleteGemPortFromLocalCache2", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{1, 2, 3, 4}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800720 // Try to delete when there is no gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700721 {"DeleteGemPortFromLocalCache3", args{0, 1, []uint32{}, []uint32{1, 2}, []uint32{}, "onu1", 0}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800722 // Try to delete non-existent gem port
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700723 {"DeleteGemPortFromLocalCache4", args{0, 1, []uint32{1}, []uint32{2}, []uint32{1}, "onu1", 1}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800724 // Try to delete two of the gem ports
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700725 {"DeleteGemPortFromLocalCache5", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{2, 4}, []uint32{1, 3}, "onu1", 2}},
serkant.uluderya96af4932020-02-20 16:58:48 -0800726 }
727 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
728 defer cancel()
729 for _, tt := range tests {
730 t.Run(tt.name, func(t *testing.T) {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400731 // TODO: should check returned errors are as expected?
Girish Gowdra9602eb42020-09-09 15:50:39 -0700732 _ = flowMgr[tt.args.intfID].UpdateOnuInfo(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum)
serkant.uluderya96af4932020-02-20 16:58:48 -0800733 for _, gemPort := range tt.args.gemPortIDs {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700734 flowMgr[tt.args.intfID].addGemPortToOnuInfoMap(ctx, tt.args.intfID, tt.args.onuID, gemPort)
serkant.uluderya96af4932020-02-20 16:58:48 -0800735 }
736 for _, gemPortDeleted := range tt.args.gemPortIDsToBeDeleted {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700737 flowMgr[tt.args.intfID].deleteGemPortFromLocalCache(ctx, tt.args.intfID, tt.args.onuID, gemPortDeleted)
serkant.uluderya96af4932020-02-20 16:58:48 -0800738 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700739 lenofGemPorts := len(flowMgr[tt.args.intfID].onuGemInfoMap[1].GemPorts)
serkant.uluderya96af4932020-02-20 16:58:48 -0800740 if lenofGemPorts != tt.args.finalLength {
741 t.Errorf("GemPorts length is not as expected len = %d, want %d", lenofGemPorts, tt.args.finalLength)
742 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700743 gemPorts := flowMgr[tt.args.intfID].onuGemInfoMap[1].GemPorts
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700744 if !reflect.DeepEqual(tt.args.gemPortIDsRemaining, gemPorts) {
745 t.Errorf("GemPorts are not as expected = %v, want %v", gemPorts, tt.args.gemPortIDsRemaining)
746 }
serkant.uluderya96af4932020-02-20 16:58:48 -0800747
748 })
749 }
750}
751
kdarapu3248f9a2019-10-03 13:54:52 +0530752func TestOpenOltFlowMgr_GetLogicalPortFromPacketIn(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530753 type args struct {
754 packetIn *openoltpb2.PacketIndication
755 }
756 tests := []struct {
757 name string
758 args args
759 want uint32
760 wantErr bool
761 }{
762 // TODO: Add test cases.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700763 {"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},
764 {"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 +0530765 // Negative Test cases.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700766 {"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},
767 {"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 +0530768 }
npujarec5762e2020-01-01 14:08:48 +0530769 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
770 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530771 for _, tt := range tests {
772 t.Run(tt.name, func(t *testing.T) {
773
Girish Gowdra9602eb42020-09-09 15:50:39 -0700774 got, err := flowMgr[tt.args.packetIn.IntfId].GetLogicalPortFromPacketIn(ctx, tt.args.packetIn)
kdarapu3248f9a2019-10-03 13:54:52 +0530775 if (err != nil) != tt.wantErr {
776 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() error = %v, wantErr %v", err, tt.wantErr)
777 return
778 }
779 if got != tt.want {
780 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() = %v, want %v", got, tt.want)
781 }
782 })
783 }
784}
785
786func TestOpenOltFlowMgr_GetPacketOutGemPortID(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700787 // Create fresh flowMgr instance
788 flowMgr = newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530789
Esin Karaman7fb80c22020-07-16 14:23:33 +0000790 //untagged packet in hex string
791 untaggedStr := "01005e000002000000000001080046c00020000040000102fa140a000001e00000029404000017000705e10000fa"
792 untagged, err := hex.DecodeString(untaggedStr)
793 if err != nil {
794 t.Error("Unable to parse hex string", err)
795 panic(err)
796 }
Girish Gowdra9602eb42020-09-09 15:50:39 -0700797 //single-tagged packet in hex string. vlanID.pbit: 1.1
798 singleTaggedStr := "01005e0000010025ba48172481002001080046c0002000004000010257deab140023e0000001940400001164ee9b0000000000000000000000000000"
Esin Karaman7fb80c22020-07-16 14:23:33 +0000799 singleTagged, err := hex.DecodeString(singleTaggedStr)
800 if err != nil {
801 t.Error("Unable to parse hex string", err)
802 panic(err)
803 }
Girish Gowdra9602eb42020-09-09 15:50:39 -0700804 //double-tagged packet in hex string. vlanID.pbit: 210.0-0.0
805 doubleTaggedStr := "01005e000016deadbeefba118100021081000000080046000028000000000102c5b87f000001e0000016940400002200f8030000000104000000e10000fa"
Esin Karaman7fb80c22020-07-16 14:23:33 +0000806 doubleTagged, err := hex.DecodeString(doubleTaggedStr)
807 if err != nil {
808 t.Error("Unable to parse hex string", err)
809 panic(err)
810 }
811
kdarapu3248f9a2019-10-03 13:54:52 +0530812 type args struct {
813 intfID uint32
814 onuID uint32
815 portNum uint32
Esin Karaman7fb80c22020-07-16 14:23:33 +0000816 packet []byte
kdarapu3248f9a2019-10-03 13:54:52 +0530817 }
818 tests := []struct {
819 name string
820 args args
821 want uint32
822 wantErr bool
823 }{
824 // TODO: Add test cases.
Girish Gowdra9602eb42020-09-09 15:50:39 -0700825 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: untagged}, 1, false},
826 {"GetPacketOutGemPortID", args{intfID: 1, onuID: 2, portNum: 2, packet: singleTagged}, 2, false},
827 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: doubleTagged}, 1, false},
828 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 10, portNum: 10, packet: untagged}, 2, true},
829 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 3, packet: []byte{}}, 3, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530830 }
Esin Karaman7fb80c22020-07-16 14:23:33 +0000831
npujarec5762e2020-01-01 14:08:48 +0530832 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
833 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530834 for _, tt := range tests {
835 t.Run(tt.name, func(t *testing.T) {
836
Girish Gowdra9602eb42020-09-09 15:50:39 -0700837 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 +0000838 if tt.wantErr {
839 if err == nil {
840 //error expected but got value
841 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, wantErr %v", got, tt.wantErr)
842 }
843 } else {
844 if err != nil {
845 //error is not expected but got error
846 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() error = %v, wantErr %v", err, tt.wantErr)
847 return
848 }
849 if got != tt.want {
850 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, want %v", got, tt.want)
851 }
kdarapu3248f9a2019-10-03 13:54:52 +0530852 }
kdarapu3248f9a2019-10-03 13:54:52 +0530853 })
854 }
855}
856
857func TestOpenOltFlowMgr_DeleteTechProfileInstance(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530858 type args struct {
859 intfID uint32
860 onuID uint32
861 uniID uint32
862 sn string
Gamze Abakafee36392019-10-03 11:17:24 +0000863 tpID uint32
kdarapu3248f9a2019-10-03 13:54:52 +0530864 }
865 tests := []struct {
866 name string
867 args args
868 wantErr bool
869 }{
870 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000871 {"DeleteTechProfileInstance", args{intfID: 0, onuID: 1, uniID: 1, sn: "", tpID: 64}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530872 }
npujarec5762e2020-01-01 14:08:48 +0530873 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
874 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530875 for _, tt := range tests {
876 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700877 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 +0530878 t.Errorf("OpenOltFlowMgr.DeleteTechProfileInstance() error = %v, wantErr %v", err, tt.wantErr)
879 }
880 })
881 }
882}
kdarapub26b4502019-10-05 03:02:33 +0530883
884func TestOpenOltFlowMgr_checkAndAddFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000885 ctx := context.Background()
kdarapub26b4502019-10-05 03:02:33 +0530886 kw := make(map[string]uint64)
887 kw["table_id"] = 1
888 kw["meter_id"] = 1
889 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
890
891 // Upstream flow
892 fa := &fu.FlowArgs{
893 MatchFields: []*ofp.OfpOxmOfbField{
894 fu.InPort(536870912),
895 fu.Metadata_ofp(1),
896 fu.IpProto(17), // dhcp
Gamze Abakafee36392019-10-03 11:17:24 +0000897 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300898 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530899 },
900 Actions: []*ofp.OfpAction{
901 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
902 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800903 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530904 fu.PushVlan(0x8100),
905 },
906 KV: kw,
907 }
908
909 // EAPOL
910 fa2 := &fu.FlowArgs{
911 MatchFields: []*ofp.OfpOxmOfbField{
912 fu.InPort(536870912),
913 fu.Metadata_ofp(1),
914 fu.EthType(0x888E),
915 fu.VlanPcp(1),
916 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
917 },
918 Actions: []*ofp.OfpAction{
919 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
920 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800921 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530922 fu.PushVlan(0x8100),
923 },
924 KV: kw,
925 }
926
927 // HSIA
928 fa3 := &fu.FlowArgs{
929 MatchFields: []*ofp.OfpOxmOfbField{
930 fu.InPort(536870912),
931 fu.Metadata_ofp(1),
932 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300933 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530934 },
935 Actions: []*ofp.OfpAction{
936 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300937 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdra0aca4982021-01-04 12:44:27 -0800938 fu.Output(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530939 fu.PushVlan(0x8100),
940 },
941 KV: kw,
942 }
943
944 fa4 := &fu.FlowArgs{
945 MatchFields: []*ofp.OfpOxmOfbField{
Girish Gowdra0aca4982021-01-04 12:44:27 -0800946 fu.InPort(1048576),
kdarapub26b4502019-10-05 03:02:33 +0530947 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300948 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530949 fu.VlanPcp(1),
950 },
951 Actions: []*ofp.OfpAction{
952 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300953 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
kdarapub26b4502019-10-05 03:02:33 +0530954 fu.Output(536870912),
955 fu.PopVlan(),
956 },
957 KV: kw,
958 }
959
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300960 // PPPOED
961 pppoedFA := &fu.FlowArgs{
962 MatchFields: []*ofp.OfpOxmOfbField{
963 fu.InPort(536870912),
964 fu.Metadata_ofp(1),
965 fu.EthType(0x8863),
966 fu.VlanPcp(1),
967 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
968 },
969 Actions: []*ofp.OfpAction{
970 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
971 fu.Output(1048576),
972 fu.PushVlan(0x8100),
973 },
974 KV: kw,
975 }
976
kdarapub26b4502019-10-05 03:02:33 +0530977 classifierInfo := make(map[string]interface{})
978 actionInfo := make(map[string]interface{})
979 classifierInfo2 := make(map[string]interface{})
980 actionInfo2 := make(map[string]interface{})
981 classifierInfo3 := make(map[string]interface{})
982 actionInfo3 := make(map[string]interface{})
983 classifierInfo4 := make(map[string]interface{})
984 actionInfo4 := make(map[string]interface{})
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300985 classifierInfo5 := make(map[string]interface{})
986 actionInfo5 := make(map[string]interface{})
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700987 flow, _ := fu.MkFlowStat(fa)
988 flow2, _ := fu.MkFlowStat(fa2)
989 flow3, _ := fu.MkFlowStat(fa3)
990 flow4, _ := fu.MkFlowStat(fa4)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300991 flow5, _ := fu.MkFlowStat(pppoedFA)
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700992 formulateClassifierInfoFromFlow(ctx, classifierInfo, flow)
993 formulateClassifierInfoFromFlow(ctx, classifierInfo2, flow2)
994 formulateClassifierInfoFromFlow(ctx, classifierInfo3, flow3)
995 formulateClassifierInfoFromFlow(ctx, classifierInfo4, flow4)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300996 formulateClassifierInfoFromFlow(ctx, classifierInfo5, flow5)
kdarapub26b4502019-10-05 03:02:33 +0530997
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700998 err := formulateActionInfoFromFlow(ctx, actionInfo, classifierInfo, flow)
kdarapub26b4502019-10-05 03:02:33 +0530999 if err != nil {
1000 // Error logging is already done in the called function
1001 // So just return in case of error
1002 return
1003 }
1004
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001005 err = formulateActionInfoFromFlow(ctx, actionInfo2, classifierInfo2, flow2)
kdarapub26b4502019-10-05 03:02:33 +05301006 if err != nil {
1007 // Error logging is already done in the called function
1008 // So just return in case of error
1009 return
1010 }
1011
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001012 err = formulateActionInfoFromFlow(ctx, actionInfo3, classifierInfo3, flow3)
kdarapub26b4502019-10-05 03:02:33 +05301013 if err != nil {
1014 // Error logging is already done in the called function
1015 // So just return in case of error
1016 return
1017 }
1018
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001019 err = formulateActionInfoFromFlow(ctx, actionInfo4, classifierInfo4, flow4)
kdarapub26b4502019-10-05 03:02:33 +05301020 if err != nil {
1021 // Error logging is already done in the called function
1022 // So just return in case of error
1023 return
1024 }
1025
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001026 err = formulateActionInfoFromFlow(ctx, actionInfo5, classifierInfo5, flow5)
1027 if err != nil {
1028 // Error logging is already done in the called function
1029 // So just return in case of error
1030 return
1031 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001032 /*
1033 usGemList := make([]*tp_pb.GemPortAttributes, 4)
1034 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1035 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1036 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1037 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1038 dsGemList := make([]*tp_pb.GemPortAttributes, 4)
1039 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1040 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1041 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1042 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
1043 */
1044 TpInst := &tp_pb.TechProfileInstance{
kdarapub26b4502019-10-05 03:02:33 +05301045 Name: "Test-Tech-Profile",
1046 SubscriberIdentifier: "257",
1047 ProfileType: "Mock",
1048 Version: 1,
1049 NumGemPorts: 4,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001050 InstanceControl: &tp_pb.InstanceControl{
kdarapub26b4502019-10-05 03:02:33 +05301051 Onu: "1",
1052 Uni: "16",
1053 },
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001054 UsScheduler: &openoltpb2.SchedulerAttributes{},
1055 DsScheduler: &openoltpb2.SchedulerAttributes{},
kdarapub26b4502019-10-05 03:02:33 +05301056 }
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001057 TpInst.UsScheduler.Priority = 1
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001058 TpInst.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
1059 TpInst.UsScheduler.AllocId = 1
1060 TpInst.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
1061 TpInst.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001062 TpInst.UsScheduler.Weight = 4
1063
1064 TpInst.DsScheduler.Priority = 1
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001065 TpInst.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
1066 TpInst.DsScheduler.AllocId = 1
1067 TpInst.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
1068 TpInst.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001069 TpInst.DsScheduler.Weight = 4
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001070 TpInst.UpstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
1071 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
1072 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
1073 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
1074 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001075
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001076 TpInst.DownstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
1077 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
1078 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
1079 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
1080 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
kdarapub26b4502019-10-05 03:02:33 +05301081
kdarapub26b4502019-10-05 03:02:33 +05301082 type args struct {
1083 args map[string]uint32
1084 classifierInfo map[string]interface{}
1085 actionInfo map[string]interface{}
1086 flow *ofp.OfpFlowStats
1087 gemPort uint32
1088 intfID uint32
1089 onuID uint32
1090 uniID uint32
1091 portNo uint32
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001092 TpInst *tp_pb.TechProfileInstance
kdarapub26b4502019-10-05 03:02:33 +05301093 allocID []uint32
1094 gemPorts []uint32
1095 TpID uint32
1096 uni string
1097 }
1098 tests := []struct {
Kent Hagermane6ff1012020-07-14 15:07:53 -04001099 name string
1100 args args
kdarapub26b4502019-10-05 03:02:33 +05301101 }{
1102 {
1103 name: "checkAndAddFlow-1",
1104 args: args{
1105 args: nil,
1106 classifierInfo: classifierInfo,
1107 actionInfo: actionInfo,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001108 flow: flow,
kdarapub26b4502019-10-05 03:02:33 +05301109 gemPort: 1,
1110 intfID: 1,
1111 onuID: 1,
1112 uniID: 16,
1113 portNo: 1,
1114 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001115 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301116 gemPorts: []uint32{1, 2, 3, 4},
1117 TpID: 64,
1118 uni: "16",
1119 },
1120 },
1121 {
1122 name: "checkAndAddFlow-2",
1123 args: args{
1124 args: nil,
1125 classifierInfo: classifierInfo2,
1126 actionInfo: actionInfo2,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001127 flow: flow2,
kdarapub26b4502019-10-05 03:02:33 +05301128 gemPort: 1,
1129 intfID: 1,
1130 onuID: 1,
1131 uniID: 16,
1132 portNo: 1,
1133 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001134 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301135 gemPorts: []uint32{1, 2, 3, 4},
1136 TpID: 64,
1137 uni: "16",
1138 },
1139 },
1140 {
1141 name: "checkAndAddFlow-3",
1142 args: args{
1143 args: nil,
1144 classifierInfo: classifierInfo3,
1145 actionInfo: actionInfo3,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001146 flow: flow3,
kdarapub26b4502019-10-05 03:02:33 +05301147 gemPort: 1,
1148 intfID: 1,
1149 onuID: 1,
1150 uniID: 16,
1151 portNo: 1,
1152 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001153 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301154 gemPorts: []uint32{1, 2, 3, 4},
1155 TpID: 64,
1156 uni: "16",
1157 },
1158 },
1159 {
1160 name: "checkAndAddFlow-4",
1161 args: args{
1162 args: nil,
1163 classifierInfo: classifierInfo4,
1164 actionInfo: actionInfo4,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001165 flow: flow4,
kdarapub26b4502019-10-05 03:02:33 +05301166 gemPort: 1,
1167 intfID: 1,
1168 onuID: 1,
1169 uniID: 16,
1170 portNo: 1,
1171 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001172 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301173 gemPorts: []uint32{1, 2, 3, 4},
1174 TpID: 64,
1175 uni: "16",
1176 },
1177 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001178 {
1179 name: "checkAndAddFlow-5",
1180 args: args{
1181 args: nil,
1182 classifierInfo: classifierInfo5,
1183 actionInfo: actionInfo5,
1184 flow: flow5,
1185 gemPort: 1,
1186 intfID: 1,
1187 onuID: 1,
1188 uniID: 16,
1189 portNo: 1,
1190 TpInst: TpInst,
1191 allocID: []uint32{0x8001},
1192 gemPorts: []uint32{1, 2, 3, 4},
1193 TpID: 64,
1194 uni: "16",
1195 },
1196 },
kdarapub26b4502019-10-05 03:02:33 +05301197 }
npujarec5762e2020-01-01 14:08:48 +05301198 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1199 defer cancel()
kdarapub26b4502019-10-05 03:02:33 +05301200 for _, tt := range tests {
1201 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -07001202 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 +00001203 tt.args.TpInst, tt.args.gemPorts, tt.args.TpID, tt.args.uni)
kdarapub26b4502019-10-05 03:02:33 +05301204 })
1205 }
1206}
Esin Karamanccb714b2019-11-29 15:02:06 +00001207
Esin Karamand519bbf2020-07-01 11:16:03 +00001208func TestOpenOltFlowMgr_TestMulticastFlowAndGroup(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301209 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1210 defer cancel()
Esin Karamanccb714b2019-11-29 15:02:06 +00001211 //create group
1212 group := newGroup(2, []uint32{1})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001213 err := flowMgr[0].grpMgr.AddGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001214 if err != nil {
1215 t.Error("group-add failed", err)
1216 return
1217 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001218 //create multicast flow
1219 multicastFlowArgs := &fu.FlowArgs{
1220 MatchFields: []*ofp.OfpOxmOfbField{
Esin Karamand519bbf2020-07-01 11:16:03 +00001221 fu.InPort(1048576),
Esin Karamanccb714b2019-11-29 15:02:06 +00001222 fu.VlanVid(660), //vlan
1223 fu.Metadata_ofp(uint64(66)), //inner vlan
1224 fu.EthType(0x800), //ipv4
1225 fu.Ipv4Dst(3809869825), //227.22.0.1
1226 },
1227 Actions: []*ofp.OfpAction{
1228 fu.Group(1),
1229 },
1230 }
divyadesaid26f6b12020-03-19 06:30:28 +00001231 ofpStats, _ := fu.MkFlowStat(multicastFlowArgs)
Esin Karamand519bbf2020-07-01 11:16:03 +00001232 fmt.Println(ofpStats.Id)
Girish Gowdra9602eb42020-09-09 15:50:39 -07001233 err = flowMgr[0].AddFlow(ctx, ofpStats, &voltha.FlowMetadata{})
Esin Karamand519bbf2020-07-01 11:16:03 +00001234 if err != nil {
1235 t.Error("Multicast flow-add failed", err)
1236 return
1237 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001238
1239 //add bucket to the group
1240 group = newGroup(2, []uint32{1, 2})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001241 err = flowMgr[0].grpMgr.ModifyGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001242 if err != nil {
1243 t.Error("modify-group failed", err)
1244 return
1245 }
1246 //remove the multicast flow
Girish Gowdra9602eb42020-09-09 15:50:39 -07001247 err = flowMgr[0].RemoveFlow(ctx, ofpStats)
Esin Karamand519bbf2020-07-01 11:16:03 +00001248 if err != nil {
1249 t.Error("Multicast flow-remove failed", err)
1250 return
1251 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001252
Esin Karamand519bbf2020-07-01 11:16:03 +00001253 //remove the group
Girish Gowdra9602eb42020-09-09 15:50:39 -07001254 err = flowMgr[0].grpMgr.DeleteGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001255 if err != nil {
1256 t.Error("delete-group failed", err)
1257 return
1258 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001259}
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001260
1261func TestOpenOltFlowMgr_TestRouteFlowToOnuChannel(t *testing.T) {
1262 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1263 defer cancel()
1264 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/core", log.DebugLevel)
1265 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager", log.DebugLevel)
1266 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/pkg/mocks", log.DebugLevel)
Girish Gowdra0aca4982021-01-04 12:44:27 -08001267 kwTable1Meter1 := make(map[string]uint64)
1268 kwTable1Meter1["table_id"] = 1
1269 kwTable1Meter1["meter_id"] = 1
1270 kwTable1Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
1271
1272 kwTable0Meter1 := make(map[string]uint64)
1273 kwTable0Meter1["table_id"] = 0
1274 kwTable0Meter1["meter_id"] = 1
1275 kwTable0Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001276
1277 flowMetadata1 := voltha.FlowMetadata{Meters: []*voltha.OfpMeterConfig{
1278 {
1279 Flags: 5,
1280 MeterId: 1,
1281 Bands: []*voltha.OfpMeterBandHeader{
1282 {
1283 Type: voltha.OfpMeterBandType_OFPMBT_DROP,
1284 Rate: 16000,
Gamze Abaka01174422021-03-10 06:55:27 +00001285 BurstSize: 0,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001286 },
1287 {
1288 Type: voltha.OfpMeterBandType_OFPMBT_DROP,
1289 Rate: 32000,
1290 BurstSize: 30,
1291 },
1292 {
1293 Type: voltha.OfpMeterBandType_OFPMBT_DROP,
1294 Rate: 64000,
1295 BurstSize: 30,
1296 },
1297 },
1298 },
1299 }}
1300
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001301 // Downstream LLDP Trap from NNI0 flow
1302 fa0 := &fu.FlowArgs{
1303 MatchFields: []*ofp.OfpOxmOfbField{
1304 fu.InPort(1048576),
1305 fu.EthType(35020),
1306 },
1307 Actions: []*ofp.OfpAction{
1308 fu.Output(4294967293),
1309 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001310 KV: make(map[string]uint64),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001311 }
1312
1313 // Upstream flow DHCP flow - ONU1 UNI0 PON0
1314 fa1 := &fu.FlowArgs{
1315 MatchFields: []*ofp.OfpOxmOfbField{
1316 fu.InPort(536870912),
1317 fu.Metadata_ofp(1),
1318 fu.IpProto(17), // dhcp
1319 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001320 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001321 fu.TunnelId(16),
1322 },
1323 Actions: []*ofp.OfpAction{
1324 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1325 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1326 fu.Output(2147483645),
1327 fu.PushVlan(0x8100),
1328 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001329 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001330 }
1331
1332 // Upstream EAPOL - ONU1 UNI0 PON0
1333 fa2 := &fu.FlowArgs{
1334 MatchFields: []*ofp.OfpOxmOfbField{
1335 fu.InPort(536870912),
1336 fu.Metadata_ofp(1),
1337 fu.EthType(0x888E),
1338 fu.VlanPcp(1),
1339 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
1340 fu.TunnelId(16),
1341 },
1342 Actions: []*ofp.OfpAction{
1343 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1344 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1345 fu.Output(2147483645),
1346 fu.PushVlan(0x8100),
1347 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001348 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001349 }
1350
1351 // Upstream HSIA - ONU1 UNI0 PON0
1352 fa3 := &fu.FlowArgs{
1353 MatchFields: []*ofp.OfpOxmOfbField{
1354 fu.InPort(536870912),
1355 fu.Metadata_ofp(1),
1356 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001357 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001358 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001359 },
1360 Actions: []*ofp.OfpAction{
1361 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001362 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001363 fu.Output(1048576),
1364 fu.PushVlan(0x8100),
1365 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001366 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001367 }
1368
1369 // Downstream HSIA - ONU1 UNI0 PON0
1370 fa4 := &fu.FlowArgs{
1371 MatchFields: []*ofp.OfpOxmOfbField{
1372 fu.InPort(1048576),
1373 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001374 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001375 fu.VlanPcp(1),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001376 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001377 },
1378 Actions: []*ofp.OfpAction{
1379 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001380 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001381 fu.Output(536870912),
1382 fu.PopVlan(),
1383 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001384 KV: kwTable0Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001385 }
1386
1387 // Upstream flow DHCP flow - ONU1 UNI0 PON15
1388 fa5 := &fu.FlowArgs{
1389 MatchFields: []*ofp.OfpOxmOfbField{
1390 fu.InPort(536870927),
1391 fu.Metadata_ofp(1),
1392 fu.IpProto(17), // dhcp
1393 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001394 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001395 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001396 },
1397 Actions: []*ofp.OfpAction{
1398 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1399 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259)),
1400 fu.Output(2147483645),
1401 fu.PushVlan(0x8100),
1402 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001403 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001404 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001405
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001406 // Upstream EAPOL - ONU1 UNI0 PON15
1407 fa6 := &fu.FlowArgs{
1408 MatchFields: []*ofp.OfpOxmOfbField{
1409 fu.InPort(536870927),
1410 fu.Metadata_ofp(1),
1411 fu.EthType(0x888E),
1412 fu.VlanPcp(1),
1413 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
Girish Gowdra0aca4982021-01-04 12:44:27 -08001414 fu.TunnelId(16),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001415 },
1416 Actions: []*ofp.OfpAction{
1417 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1418 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1419 fu.Output(2147483645),
1420 fu.PushVlan(0x8100),
1421 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001422 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001423 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001424
1425 // Upstream PPPOED - ONU1 UNI0 PON0
1426 fa7 := &fu.FlowArgs{
1427 MatchFields: []*ofp.OfpOxmOfbField{
1428 fu.InPort(536870912),
1429 fu.Metadata_ofp(1),
1430 fu.EthType(0x8863),
1431 fu.VlanPcp(1),
1432 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
1433 fu.TunnelId(16),
1434 },
1435 Actions: []*ofp.OfpAction{
1436 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1437 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1438 fu.Output(2147483645),
1439 fu.PushVlan(0x8100),
1440 },
1441 KV: kwTable1Meter1,
1442 }
1443
1444 // Upstream PPPOED - ONU1 UNI0 PON15
1445 fa8 := &fu.FlowArgs{
1446 MatchFields: []*ofp.OfpOxmOfbField{
1447 fu.InPort(536870927),
1448 fu.Metadata_ofp(1),
1449 fu.EthType(0x8863),
1450 fu.VlanPcp(1),
1451 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
1452 fu.TunnelId(16),
1453 },
1454 Actions: []*ofp.OfpAction{
1455 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1456 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1457 fu.Output(2147483645),
1458 fu.PushVlan(0x8100),
1459 },
1460 KV: kwTable1Meter1,
1461 }
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001462 flow0, _ := fu.MkFlowStat(fa0)
1463 flow1, _ := fu.MkFlowStat(fa1)
1464 flow2, _ := fu.MkFlowStat(fa2)
1465 flow3, _ := fu.MkFlowStat(fa3)
1466 flow4, _ := fu.MkFlowStat(fa4)
1467
1468 flow5, _ := fu.MkFlowStat(fa5)
1469 flow6, _ := fu.MkFlowStat(fa6)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001470 flow7, _ := fu.MkFlowStat(fa7)
1471 flow8, _ := fu.MkFlowStat(fa8)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001472
1473 type args struct {
1474 ctx context.Context
1475 flow *ofp.OfpFlowStats
1476 addFlow bool
1477 flowMetadata *voltha.FlowMetadata
1478 }
1479 tests := []struct {
1480 name string
1481 args args
1482 wantErr bool
1483 returnedErr error
1484 }{
1485 {
1486 name: "RouteFlowToOnuChannel-0",
1487 args: args{
1488 ctx: ctx,
1489 flow: flow0,
1490 addFlow: true,
1491 flowMetadata: &flowMetadata1,
1492 },
1493 wantErr: false,
1494 },
1495 {
1496 name: "RouteFlowToOnuChannel-1",
1497 args: args{
1498 ctx: ctx,
1499 flow: flow1,
1500 addFlow: true,
1501 flowMetadata: &flowMetadata1,
1502 },
1503 wantErr: false,
1504 },
1505 {
1506 name: "RouteFlowToOnuChannel-2",
1507 args: args{
1508 ctx: ctx,
1509 flow: flow2,
1510 addFlow: true,
1511 flowMetadata: &flowMetadata1,
1512 },
1513 wantErr: false,
1514 },
1515 {
1516 name: "RouteFlowToOnuChannel-3",
1517 args: args{
1518 ctx: ctx,
1519 flow: flow3,
1520 addFlow: true,
1521 flowMetadata: &flowMetadata1,
1522 },
1523 wantErr: false,
1524 },
1525 {
1526 name: "RouteFlowToOnuChannel-4",
1527 args: args{
1528 ctx: ctx,
1529 flow: flow4,
1530 addFlow: true,
1531 flowMetadata: &flowMetadata1,
1532 },
1533 wantErr: false,
1534 },
1535 {
1536 name: "RouteFlowToOnuChannel-5",
1537 args: args{
1538 ctx: ctx,
1539 flow: flow1,
1540 addFlow: false,
1541 flowMetadata: &flowMetadata1,
1542 },
1543 wantErr: false,
1544 },
1545 {
1546 name: "RouteFlowToOnuChannel-6",
1547 args: args{
1548 ctx: ctx,
1549 flow: flow1,
1550 addFlow: true,
Girish Gowdra0aca4982021-01-04 12:44:27 -08001551 flowMetadata: &flowMetadata1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001552 },
1553 wantErr: true,
1554 },
1555 {
1556 name: "RouteFlowToOnuChannel-7",
1557 args: args{
1558 ctx: ctx,
1559 flow: flow5,
1560 addFlow: true,
1561 flowMetadata: &flowMetadata1,
1562 },
1563 wantErr: false,
1564 },
1565 {
1566 name: "RouteFlowToOnuChannel-8",
1567 args: args{
1568 ctx: ctx,
1569 flow: flow6,
1570 addFlow: true,
1571 flowMetadata: &flowMetadata1,
1572 },
1573 wantErr: false,
1574 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001575 {
1576 name: "RouteFlowToOnuChannel-9",
1577 args: args{
1578 ctx: ctx,
1579 flow: flow7,
1580 addFlow: true,
1581 flowMetadata: &flowMetadata1,
1582 },
1583 wantErr: false,
1584 },
1585 {
1586 name: "RouteFlowToOnuChannel-10",
1587 args: args{
1588 ctx: ctx,
1589 flow: flow8,
1590 addFlow: true,
1591 flowMetadata: &flowMetadata1,
1592 },
1593 wantErr: false,
1594 },
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001595 }
1596
1597 var wg sync.WaitGroup
1598 defer wg.Wait() // wait for all go routines to complete
1599 for _, tt := range tests {
1600 t.Run(tt.name, func(t *testing.T) {
1601 wg.Add(1) // one per go routine
1602 go func() {
1603 defer wg.Done()
1604 tt.returnedErr = flowMgr[0].RouteFlowToOnuChannel(tt.args.ctx, tt.args.flow, tt.args.addFlow, tt.args.flowMetadata)
1605 if (tt.wantErr == false && tt.returnedErr != nil) || (tt.wantErr == true && tt.returnedErr == nil) {
1606 t.Errorf("OpenOltFlowMgr.RouteFlowToOnuChannel() error = %v, wantErr %v", tt.returnedErr, tt.wantErr)
1607 }
1608 }()
1609 })
1610 }
1611}