blob: 7dc83b703f1dc47b474a6d45cc5d6db49d73148c [file] [log] [blame]
kdarapu3248f9a2019-10-03 13:54:52 +05301/*
Joey Armstrongf9bffdf2022-12-27 07:05:28 -05002 * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors
kdarapu3248f9a2019-10-03 13:54:52 +05303
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 "sync"
kdarapu3248f9a2019-10-03 13:54:52 +053025 "testing"
npujarec5762e2020-01-01 14:08:48 +053026 "time"
kdarapu3248f9a2019-10-03 13:54:52 +053027
khenaidoo106c61a2021-08-11 18:05:46 -040028 "github.com/opencord/voltha-openolt-adapter/pkg/mocks"
kdarapub26b4502019-10-05 03:02:33 +053029
khenaidoo106c61a2021-08-11 18:05:46 -040030 fu "github.com/opencord/voltha-lib-go/v7/pkg/flows"
31 "github.com/opencord/voltha-lib-go/v7/pkg/log"
Scott Bakerdbd960e2020-02-28 08:57:51 -080032 rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager"
khenaidoo106c61a2021-08-11 18:05:46 -040033 ofp "github.com/opencord/voltha-protos/v5/go/openflow_13"
34 openoltpb2 "github.com/opencord/voltha-protos/v5/go/openolt"
35 tp_pb "github.com/opencord/voltha-protos/v5/go/tech_profile"
kdarapu3248f9a2019-10-03 13:54:52 +053036)
37
Girish Gowdra9602eb42020-09-09 15:50:39 -070038var flowMgr []*OpenOltFlowMgr
kdarapub26b4502019-10-05 03:02:33 +053039
kdarapu3248f9a2019-10-03 13:54:52 +053040func init() {
Kent Hagermane6ff1012020-07-14 15:07:53 -040041 _, _ = log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
kdarapub26b4502019-10-05 03:02:33 +053042 flowMgr = newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +053043}
kdarapu3248f9a2019-10-03 13:54:52 +053044
Girish Gowdra9602eb42020-09-09 15:50:39 -070045func newMockFlowmgr() []*OpenOltFlowMgr {
kdarapu3248f9a2019-10-03 13:54:52 +053046 dh := newMockDeviceHandler()
47
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070048 // onuGemInfoMap := make([]rsrcMgr.onuGemInfoMap, NumPonPorts)
Girish Gowdra9602eb42020-09-09 15:50:39 -070049 var i uint32
kdarapu3248f9a2019-10-03 13:54:52 +053050
yasin saplid0566272021-12-21 09:10:30 +000051 for i = 0; i < NumPonPorts+1; i++ {
Girish Gowdra9602eb42020-09-09 15:50:39 -070052 packetInGemPort := make(map[rsrcMgr.PacketInInfoKey]uint32)
53 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 +053054
Girish Gowdra9602eb42020-09-09 15:50:39 -070055 dh.flowMgr[i].packetInGemPort = packetInGemPort
Girish Gowdra4c3d4602021-07-22 16:33:37 -070056 dh.flowMgr[i].techprofile = mocks.MockTechProfile{}
57
Girish Gowdra9602eb42020-09-09 15:50:39 -070058 interface2mcastQeueuMap := make(map[uint32]*QueueInfoBrief)
59 interface2mcastQeueuMap[0] = &QueueInfoBrief{
60 gemPortID: 4000,
61 servicePriority: 3,
62 }
63 dh.flowMgr[i].grpMgr.interfaceToMcastQueueMap = interface2mcastQeueuMap
kdarapu3248f9a2019-10-03 13:54:52 +053064 }
Girish Gowdra9602eb42020-09-09 15:50:39 -070065 return dh.flowMgr
kdarapu3248f9a2019-10-03 13:54:52 +053066}
kdarapub26b4502019-10-05 03:02:33 +053067
kdarapu3248f9a2019-10-03 13:54:52 +053068func TestOpenOltFlowMgr_CreateSchedulerQueues(t *testing.T) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070069 tprofile := &tp_pb.TechProfileInstance{Name: "tp1", SubscriberIdentifier: "subscriber1",
Girish Gowdra54934262019-11-13 14:19:55 +053070 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070071 InstanceControl: &tp_pb.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"},
kdarapu3248f9a2019-10-03 13:54:52 +053072 }
khenaidoodc2116e2021-10-19 17:33:19 -040073 tprofile.UsScheduler = &tp_pb.SchedulerAttributes{}
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070074 tprofile.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
75 tprofile.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +053076
77 tprofile2 := tprofile
khenaidoodc2116e2021-10-19 17:33:19 -040078 tprofile2.DsScheduler = &tp_pb.SchedulerAttributes{}
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070079 tprofile2.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
80 tprofile2.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Gamze Abaka01174422021-03-10 06:55:27 +000081
kdarapu3248f9a2019-10-03 13:54:52 +053082 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +000083 name string
84 schedQueue schedQueue
85 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +053086 }{
87 // TODO: Add test cases.
Gamze Abaka01174422021-03-10 06:55:27 +000088 {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 1, Upstream)}, false},
89 {"CreateSchedulerQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 1, Downstream)}, false},
90 {"CreateSchedulerQueues-13", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 2, Upstream)}, false},
91 {"CreateSchedulerQueues-14", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 2, Downstream)}, false},
92 {"CreateSchedulerQueues-15", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 3, Upstream)}, false},
93 {"CreateSchedulerQueues-16", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 3, Downstream)}, false},
94 {"CreateSchedulerQueues-17", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 4, Upstream)}, false},
95 {"CreateSchedulerQueues-18", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 4, Downstream)}, false},
96 {"CreateSchedulerQueues-19", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 5, Upstream)}, false},
97 {"CreateSchedulerQueues-20", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 5, Downstream)}, false},
98
Girish Gowdraf3728b12022-02-02 21:46:51 -080099 //Negative testcases
100 {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 0, Upstream)}, true},
101 {"CreateSchedulerQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 0, Downstream)}, true},
Gamze Abaka01174422021-03-10 06:55:27 +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},
Girish Gowdraf3728b12022-02-02 21:46:51 -0800106 {"CreateSchedulerQueues-7", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, &ofp.FlowMetadata{}}, true},
khenaidoodc2116e2021-10-19 17:33:19 -0400107 {"CreateSchedulerQueues-8", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 0, &ofp.FlowMetadata{}}, true},
Girish Gowdraf3728b12022-02-02 21:46:51 -0800108 {"CreateSchedulerQueues-9", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, &ofp.FlowMetadata{}}, true},
khenaidoodc2116e2021-10-19 17:33:19 -0400109 {"CreateSchedulerQueues-10", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, &ofp.FlowMetadata{}}, true},
110 {"CreateSchedulerQueues-11", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, &ofp.FlowMetadata{}}, true},
Girish Gowdra9602eb42020-09-09 15:50:39 -0700111 {"CreateSchedulerQueues-12", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, nil}, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530112 }
npujarec5762e2020-01-01 14:08:48 +0530113 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
114 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530115 for _, tt := range tests {
116 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700117 if err := flowMgr[tt.schedQueue.intfID].CreateSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
kdarapu3248f9a2019-10-03 13:54:52 +0530118 t.Errorf("OpenOltFlowMgr.CreateSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr)
119 }
120 })
121 }
122}
123
khenaidoodc2116e2021-10-19 17:33:19 -0400124func createFlowMetadata(techProfile *tp_pb.TechProfileInstance, tcontType int, direction string) *ofp.FlowMetadata {
125 var additionalBw tp_pb.AdditionalBW
Gamze Abaka01174422021-03-10 06:55:27 +0000126 bands := make([]*ofp.OfpMeterBandHeader, 0)
127 switch tcontType {
128 case 1:
129 //tcont-type-1
130 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}})
131 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 -0700132 additionalBw = tp_pb.AdditionalBW_AdditionalBW_None
Gamze Abaka01174422021-03-10 06:55:27 +0000133 case 2:
134 //tcont-type-2
135 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 60000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
136 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 -0700137 additionalBw = tp_pb.AdditionalBW_AdditionalBW_None
Gamze Abaka01174422021-03-10 06:55:27 +0000138 case 3:
139 //tcont-type-3
140 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
141 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 -0700142 additionalBw = tp_pb.AdditionalBW_AdditionalBW_NA
Gamze Abaka01174422021-03-10 06:55:27 +0000143 case 4:
144 //tcont-type-4
145 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 -0700146 additionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
Gamze Abaka01174422021-03-10 06:55:27 +0000147 case 5:
148 //tcont-type-5
149 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
150 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}})
151 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 -0700152 additionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
Gamze Abaka01174422021-03-10 06:55:27 +0000153 default:
154 // do nothing, we will return meter config with no meter bands
155 }
156
157 if direction == Downstream {
158 techProfile.DsScheduler.AdditionalBw = additionalBw
159 } else {
160 techProfile.UsScheduler.AdditionalBw = additionalBw
161 }
162
163 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
khenaidoodc2116e2021-10-19 17:33:19 -0400164 return &ofp.FlowMetadata{
Gamze Abaka01174422021-03-10 06:55:27 +0000165 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}}
166}
167
Girish Gowdraf3728b12022-02-02 21:46:51 -0800168func TestOpenOltFlowMgr_RemoveScheduler(t *testing.T) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700169 tprofile := &tp_pb.TechProfileInstance{Name: "tp1", SubscriberIdentifier: "subscriber1",
Girish Gowdra54934262019-11-13 14:19:55 +0530170 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700171 InstanceControl: &tp_pb.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"},
kdarapu3248f9a2019-10-03 13:54:52 +0530172 }
khenaidoodc2116e2021-10-19 17:33:19 -0400173 tprofile.UsScheduler = &tp_pb.SchedulerAttributes{}
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700174 tprofile.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
175 tprofile.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
176 tprofile.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +0530177
178 tprofile2 := tprofile
khenaidoodc2116e2021-10-19 17:33:19 -0400179 tprofile2.DsScheduler = &tp_pb.SchedulerAttributes{}
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700180 tprofile2.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
181 tprofile2.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
182 tprofile2.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
kdarapu3248f9a2019-10-03 13:54:52 +0530183 //defTprofile := &tp.DefaultTechProfile{}
kdarapu3248f9a2019-10-03 13:54:52 +0530184 tests := []struct {
Gamze Abakafee36392019-10-03 11:17:24 +0000185 name string
186 schedQueue schedQueue
187 wantErr bool
kdarapu3248f9a2019-10-03 13:54:52 +0530188 }{
Girish Gowdraf3728b12022-02-02 21:46:51 -0800189 {"RemoveScheduler-1", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 0, nil}, false},
190 {"RemoveScheduler-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
191 {"RemoveScheduler-3", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
192 {"RemoveScheduler-4", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530193 }
npujarec5762e2020-01-01 14:08:48 +0530194 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
195 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530196 for _, tt := range tests {
197 t.Run(tt.name, func(t *testing.T) {
Girish Gowdraf3728b12022-02-02 21:46:51 -0800198 if err := flowMgr[tt.schedQueue.intfID].RemoveScheduler(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
199 t.Errorf("OpenOltFlowMgr.RemoveScheduler() error = %v, wantErr %v", err, tt.wantErr)
200 }
201 })
202 }
203
204}
205
206func TestOpenOltFlowMgr_RemoveQueues(t *testing.T) {
207 tprofile := &tp_pb.TechProfileInstance{Name: "tp1", SubscriberIdentifier: "subscriber1",
208 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
209 InstanceControl: &tp_pb.InstanceControl{Onu: "single-instance", Uni: "single-instance", MaxGemPayloadSize: "1"},
210 }
211 tprofile.UsScheduler = &tp_pb.SchedulerAttributes{}
212 tprofile.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
213 tprofile.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
214 tprofile.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
215 tprofile.DsScheduler = &tp_pb.SchedulerAttributes{}
216 tprofile.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
217 tprofile.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
218 tprofile.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_StrictPriority
219 tprofile.UpstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
220 tprofile.UpstreamGemPortAttributeList = append(tprofile.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
221 tprofile.UpstreamGemPortAttributeList = append(tprofile.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
222 tprofile.UpstreamGemPortAttributeList = append(tprofile.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
223 tprofile.UpstreamGemPortAttributeList = append(tprofile.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
224
225 tprofile.DownstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
226 tprofile.DownstreamGemPortAttributeList = append(tprofile.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
227 tprofile.DownstreamGemPortAttributeList = append(tprofile.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
228 tprofile.DownstreamGemPortAttributeList = append(tprofile.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
229 tprofile.DownstreamGemPortAttributeList = append(tprofile.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
230
231 tprofile2 := &tp_pb.TechProfileInstance{Name: "tp2", SubscriberIdentifier: "subscriber2",
232 ProfileType: "pt1", NumGemPorts: 1, Version: 1,
233 InstanceControl: &tp_pb.InstanceControl{Onu: "multi-instance", Uni: "single-instance", MaxGemPayloadSize: "1"},
234 }
235 tprofile2.UsScheduler = &tp_pb.SchedulerAttributes{}
236 tprofile2.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
237 tprofile2.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
238 tprofile2.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
239 tprofile2.DsScheduler = &tp_pb.SchedulerAttributes{}
240 tprofile2.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
241 tprofile2.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_BestEffort
242 tprofile2.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_StrictPriority
243 tprofile2.UpstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
244 tprofile2.UpstreamGemPortAttributeList = append(tprofile.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b11111111"})
245 tprofile2.DownstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
246 tprofile2.DownstreamGemPortAttributeList = append(tprofile.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b11111111"})
247
248 //defTprofile := &tp.DefaultTechProfile{}
249 tests := []struct {
250 name string
251 schedQueue schedQueue
252 wantErr bool
253 }{
254 {"RemoveQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 0, nil}, false},
255 {"RemoveQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
256 {"RemoveQueues-3", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
257 {"RemoveQueues-4", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false},
258 }
259 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
260 defer cancel()
261 for _, tt := range tests {
262 t.Run(tt.name, func(t *testing.T) {
263 if err := flowMgr[tt.schedQueue.intfID].RemoveQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr {
264 t.Errorf("OpenOltFlowMgr.RemoveQueues() error = %v, wantErr %v", err, tt.wantErr)
kdarapu3248f9a2019-10-03 13:54:52 +0530265 }
266 })
267 }
kdarapub26b4502019-10-05 03:02:33 +0530268
kdarapu3248f9a2019-10-03 13:54:52 +0530269}
270
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700271func TestOpenOltFlowMgr_createTcontGemports(t *testing.T) {
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700272 bands := make([]*ofp.OfpMeterBandHeader, 2)
273 bands[0] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 1000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
274 bands[1] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 2000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}}
275 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands}
khenaidoodc2116e2021-10-19 17:33:19 -0400276 flowmetadata := &ofp.FlowMetadata{
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700277 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
278 }
279 type args struct {
280 intfID uint32
281 onuID uint32
282 uniID uint32
283 uni string
284 uniPort uint32
285 TpID uint32
286 UsMeterID uint32
287 DsMeterID uint32
khenaidoodc2116e2021-10-19 17:33:19 -0400288 flowMetadata *ofp.FlowMetadata
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700289 }
290 tests := []struct {
291 name string
292 args args
293 }{
294 {"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 -0700295 }
296 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
297 defer cancel()
298 for _, tt := range tests {
299 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700300 _, _, 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 -0700301 switch tpInst := tpInst.(type) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700302 case *tp_pb.TechProfileInstance:
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700303 if tt.args.TpID != 64 {
304 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
305 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700306 case *tp_pb.EponTechProfileInstance:
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700307 if tt.args.TpID != 65 {
308 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
309 }
310 default:
311 t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst)
312 }
313 })
314 }
315}
316
kdarapu3248f9a2019-10-03 13:54:52 +0530317func TestOpenOltFlowMgr_RemoveFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000318 ctx := context.Background()
Neha Sharma96b7bf22020-06-15 10:37:32 +0000319 logger.Debug(ctx, "Info Warning Error: Starting RemoveFlow() test")
kdarapu3248f9a2019-10-03 13:54:52 +0530320 fa := &fu.FlowArgs{
321 MatchFields: []*ofp.OfpOxmOfbField{
322 fu.InPort(2),
323 fu.Metadata_ofp(2),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300324 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapu3248f9a2019-10-03 13:54:52 +0530325 },
326 Actions: []*ofp.OfpAction{
327 fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
328 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
329 fu.Output(1),
330 },
331 }
divyadesaid26f6b12020-03-19 06:30:28 +0000332 ofpstats, _ := fu.MkFlowStat(fa)
kdarapub26b4502019-10-05 03:02:33 +0530333 ofpstats.Cookie = ofpstats.Id
kdarapub26b4502019-10-05 03:02:33 +0530334 lldpFa := &fu.FlowArgs{
335 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
336 MatchFields: []*ofp.OfpOxmOfbField{
337 fu.InPort(1),
338 fu.EthType(0x88CC),
339 fu.TunnelId(536870912),
340 },
341 Actions: []*ofp.OfpAction{
342 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
343 },
344 }
divyadesaid26f6b12020-03-19 06:30:28 +0000345 lldpofpstats, _ := fu.MkFlowStat(lldpFa)
kdarapub26b4502019-10-05 03:02:33 +0530346 //lldpofpstats.Cookie = lldpofpstats.Id
347
348 dhcpFa := &fu.FlowArgs{
349 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
350 MatchFields: []*ofp.OfpOxmOfbField{
351 fu.InPort(1),
352 fu.UdpSrc(67),
353 //fu.TunnelId(536870912),
354 fu.IpProto(17),
355 },
356 Actions: []*ofp.OfpAction{
357 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
358 },
359 }
divyadesaid26f6b12020-03-19 06:30:28 +0000360 dhcpofpstats, _ := fu.MkFlowStat(dhcpFa)
kdarapub26b4502019-10-05 03:02:33 +0530361 //dhcpofpstats.Cookie = dhcpofpstats.Id
Esin Karamanccb714b2019-11-29 15:02:06 +0000362
363 //multicast flow
364 multicastFa := &fu.FlowArgs{
365 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700366 fu.InPort(16777216),
Esin Karamanccb714b2019-11-29 15:02:06 +0000367 fu.VlanVid(660), //vlan
368 fu.Metadata_ofp(uint64(66)), //inner vlan
369 fu.EthType(0x800), //ipv4
370 fu.Ipv4Dst(3809869825), //227.22.0.1
371 },
372 Actions: []*ofp.OfpAction{
373 fu.Group(1),
374 },
375 }
divyadesaid26f6b12020-03-19 06:30:28 +0000376 multicastOfpStats, _ := fu.MkFlowStat(multicastFa)
Esin Karamanccb714b2019-11-29 15:02:06 +0000377 multicastOfpStats.Id = 1
378
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300379 pppoedFa := &fu.FlowArgs{
380 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
381 MatchFields: []*ofp.OfpOxmOfbField{
382 fu.InPort(1),
383 fu.EthType(0x8863),
384 fu.TunnelId(536870912),
385 },
386 Actions: []*ofp.OfpAction{
387 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
388 },
389 }
390 pppoedOfpStats, _ := fu.MkFlowStat(pppoedFa)
391
kdarapu3248f9a2019-10-03 13:54:52 +0530392 type args struct {
393 flow *ofp.OfpFlowStats
394 }
395 tests := []struct {
396 name string
397 args args
398 }{
399 // TODO: Add test cases.
400 {"RemoveFlow", args{flow: ofpstats}},
kdarapub26b4502019-10-05 03:02:33 +0530401 {"RemoveFlow", args{flow: lldpofpstats}},
402 {"RemoveFlow", args{flow: dhcpofpstats}},
Esin Karamanccb714b2019-11-29 15:02:06 +0000403 {"RemoveFlow", args{flow: multicastOfpStats}},
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300404 {"RemoveFlow", args{flow: pppoedOfpStats}},
kdarapu3248f9a2019-10-03 13:54:52 +0530405 }
npujarec5762e2020-01-01 14:08:48 +0530406 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
407 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530408 for _, tt := range tests {
409 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700410 if err := flowMgr[0].RemoveFlow(ctx, tt.args.flow); err != nil {
Kent Hagermane6ff1012020-07-14 15:07:53 -0400411 logger.Warn(ctx, err)
412 }
kdarapu3248f9a2019-10-03 13:54:52 +0530413 })
414 }
kdarapub26b4502019-10-05 03:02:33 +0530415 // t.Error("=====")
kdarapu3248f9a2019-10-03 13:54:52 +0530416}
417
418func TestOpenOltFlowMgr_AddFlow(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530419 kw := make(map[string]uint64)
420 kw["table_id"] = 1
421 kw["meter_id"] = 1
kdarapub26b4502019-10-05 03:02:33 +0530422 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
423
424 // Upstream flow
kdarapu3248f9a2019-10-03 13:54:52 +0530425 fa := &fu.FlowArgs{
426 MatchFields: []*ofp.OfpOxmOfbField{
kdarapub26b4502019-10-05 03:02:33 +0530427 fu.InPort(536870912),
428 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300429 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530430 },
431 Actions: []*ofp.OfpAction{
432 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
433 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700434 fu.Output(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530435 fu.PushVlan(0x8100),
436 },
437 KV: kw,
438 }
439
440 // Downstream flow
441 fa3 := &fu.FlowArgs{
442 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700443 fu.InPort(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530444 fu.Metadata_ofp(1),
445 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
446 },
447 Actions: []*ofp.OfpAction{
448 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
449 //fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
450 fu.PopVlan(),
451 fu.Output(536870912),
452 },
453 KV: kw,
454 }
455
456 fa2 := &fu.FlowArgs{
457 MatchFields: []*ofp.OfpOxmOfbField{
kdarapu3248f9a2019-10-03 13:54:52 +0530458 fu.InPort(1000),
459 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300460 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapu3248f9a2019-10-03 13:54:52 +0530461 },
462 Actions: []*ofp.OfpAction{
463 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
464 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)),
465 fu.Output(65533),
466 },
467 KV: kw,
468 }
469
kdarapub26b4502019-10-05 03:02:33 +0530470 // TODO Add LLDP flow
471 // TODO Add DHCP flow
472
473 // Flows for negative scenarios
474 // Failure in formulateActionInfoFromFlow()
475 fa4 := &fu.FlowArgs{
476 MatchFields: []*ofp.OfpOxmOfbField{
477 fu.InPort(1000),
478 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300479 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530480 },
481 Actions: []*ofp.OfpAction{
482 fu.Experimenter(257, []byte{1, 2, 3, 4}),
483 },
484 KV: kw,
485 }
486
487 // Invalid Output
488 fa5 := &fu.FlowArgs{
489 MatchFields: []*ofp.OfpOxmOfbField{
490 fu.InPort(1000),
491 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300492 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530493 },
494 Actions: []*ofp.OfpAction{
495 fu.Output(0),
496 },
497 KV: kw,
498 }
499
500 // Tech-Profile-ID update (not supported)
501 kw6 := make(map[string]uint64)
502 kw6["table_id"] = 1
503 kw6["meter_id"] = 1
504 kw6["write_metadata"] = 0x4100000000 // TpID Other than the stored one
505 fa6 := &fu.FlowArgs{
506 MatchFields: []*ofp.OfpOxmOfbField{
507 fu.InPort(536870912),
508 fu.TunnelId(16),
509 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300510 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530511 },
512 Actions: []*ofp.OfpAction{
513 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
514 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
515 fu.Output(65535),
516 },
517 KV: kw6,
518 }
519
520 lldpFa := &fu.FlowArgs{
521 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
522 MatchFields: []*ofp.OfpOxmOfbField{
523 fu.InPort(1),
524 fu.EthType(0x88CC),
525 fu.TunnelId(536870912),
526 },
527 Actions: []*ofp.OfpAction{
528 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
529 },
530 }
531
532 dhcpFa := &fu.FlowArgs{
533 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
534 MatchFields: []*ofp.OfpOxmOfbField{
535 fu.InPort(1),
536 fu.UdpSrc(67),
537 //fu.TunnelId(536870912),
538 fu.IpProto(17),
539 },
540 Actions: []*ofp.OfpAction{
541 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
542 },
543 }
544 igmpFa := &fu.FlowArgs{
545 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
546 MatchFields: []*ofp.OfpOxmOfbField{
547 fu.InPort(1),
548 fu.UdpSrc(67),
549 //fu.TunnelId(536870912),
550 fu.IpProto(2),
551 },
552 Actions: []*ofp.OfpAction{
553 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
554 },
555 }
556
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300557 pppoedFa := &fu.FlowArgs{
558 KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694},
559 MatchFields: []*ofp.OfpOxmOfbField{
560 fu.InPort(1),
561 fu.EthType(0x8863),
562 fu.TunnelId(536870912),
563 },
564 Actions: []*ofp.OfpAction{
565 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
566 fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)),
567 },
568 }
569
kdarapub26b4502019-10-05 03:02:33 +0530570 fa9 := &fu.FlowArgs{
571 MatchFields: []*ofp.OfpOxmOfbField{
572 fu.InPort(536870912),
573 fu.TunnelId(16),
574 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300575 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530576 fu.VlanPcp(1000),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700577 fu.UdpDst(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530578 fu.UdpSrc(536870912),
579 fu.Ipv4Dst(65535),
580 fu.Ipv4Src(536870912),
581 },
582 Actions: []*ofp.OfpAction{
583 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
584 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
585 fu.Output(65535),
586 },
587 KV: kw6,
588 }
589
590 fa10 := &fu.FlowArgs{
591 MatchFields: []*ofp.OfpOxmOfbField{
592 fu.InPort(65533),
593 // fu.TunnelId(16),
594 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300595 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530596 fu.VlanPcp(1000),
597 fu.UdpDst(65535),
598 fu.UdpSrc(536870912),
599 fu.Ipv4Dst(65535),
600 fu.Ipv4Src(536870912),
601 },
602 Actions: []*ofp.OfpAction{
603 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
604 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
605 fu.Output(65535),
606 },
607 KV: kw6,
608 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000609 //multicast flow
610 fa11 := &fu.FlowArgs{
611 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700612 fu.InPort(16777216),
Esin Karamanccb714b2019-11-29 15:02:06 +0000613 fu.VlanVid(660), //vlan
614 fu.Metadata_ofp(uint64(66)), //inner vlan
615 fu.EthType(0x800), //ipv4
616 fu.Ipv4Dst(3809869825), //227.22.0.1
617 },
618 Actions: []*ofp.OfpAction{
619 fu.Group(1),
620 },
621 KV: kw6,
622 }
divyadesaid26f6b12020-03-19 06:30:28 +0000623 ofpstats, _ := fu.MkFlowStat(fa)
624 ofpstats2, _ := fu.MkFlowStat(fa2)
625 ofpstats3, _ := fu.MkFlowStat(fa3)
626 ofpstats4, _ := fu.MkFlowStat(fa4)
627 ofpstats5, _ := fu.MkFlowStat(fa5)
628 ofpstats6, _ := fu.MkFlowStat(fa6)
629 ofpstats7, _ := fu.MkFlowStat(lldpFa)
630 ofpstats8, _ := fu.MkFlowStat(dhcpFa)
631 ofpstats9, _ := fu.MkFlowStat(fa9)
632 ofpstats10, _ := fu.MkFlowStat(fa10)
633 igmpstats, _ := fu.MkFlowStat(igmpFa)
634 ofpstats11, _ := fu.MkFlowStat(fa11)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300635 pppoedstats, _ := fu.MkFlowStat(pppoedFa)
kdarapub26b4502019-10-05 03:02:33 +0530636
Gamze Abakafee36392019-10-03 11:17:24 +0000637 fmt.Println(ofpstats6, ofpstats9, ofpstats10)
638
kdarapu3248f9a2019-10-03 13:54:52 +0530639 ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1}
khenaidoodc2116e2021-10-19 17:33:19 -0400640 flowMetadata := &ofp.FlowMetadata{
kdarapu3248f9a2019-10-03 13:54:52 +0530641 Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
642 }
643 type args struct {
644 flow *ofp.OfpFlowStats
khenaidoodc2116e2021-10-19 17:33:19 -0400645 flowMetadata *ofp.FlowMetadata
kdarapu3248f9a2019-10-03 13:54:52 +0530646 }
647 tests := []struct {
648 name string
649 args args
650 }{
651 // TODO: Add test cases.
652 {"AddFlow", args{flow: ofpstats, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530653 {"AddFlow", args{flow: ofpstats2, flowMetadata: flowMetadata}},
654 {"AddFlow", args{flow: ofpstats3, flowMetadata: flowMetadata}},
655 {"AddFlow", args{flow: ofpstats4, flowMetadata: flowMetadata}},
656 {"AddFlow", args{flow: ofpstats5, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000657 //{"AddFlow", args{flow: ofpstats6, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530658 {"AddFlow", args{flow: ofpstats7, flowMetadata: flowMetadata}},
659 {"AddFlow", args{flow: ofpstats8, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000660 //{"AddFlow", args{flow: ofpstats9, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530661 {"AddFlow", args{flow: igmpstats, flowMetadata: flowMetadata}},
Gamze Abakafee36392019-10-03 11:17:24 +0000662 //{"AddFlow", args{flow: ofpstats10, flowMetadata: flowMetadata}},
kdarapub26b4502019-10-05 03:02:33 +0530663 //ofpstats10
Esin Karamanccb714b2019-11-29 15:02:06 +0000664 {"AddFlow", args{flow: ofpstats11, flowMetadata: flowMetadata}},
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300665 {"AddFlow", args{flow: pppoedstats, flowMetadata: flowMetadata}},
kdarapu3248f9a2019-10-03 13:54:52 +0530666 }
npujarec5762e2020-01-01 14:08:48 +0530667 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
668 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530669 for _, tt := range tests {
670 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700671 _ = flowMgr[0].AddFlow(ctx, tt.args.flow, tt.args.flowMetadata)
Kent Hagermane6ff1012020-07-14 15:07:53 -0400672 // TODO: actually verify test cases
kdarapu3248f9a2019-10-03 13:54:52 +0530673 })
674 }
675}
676
kdarapu3248f9a2019-10-03 13:54:52 +0530677func TestOpenOltFlowMgr_GetLogicalPortFromPacketIn(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530678 type args struct {
679 packetIn *openoltpb2.PacketIndication
680 }
681 tests := []struct {
682 name string
683 args args
684 want uint32
685 wantErr bool
686 }{
687 // TODO: Add test cases.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700688 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 0, GemportId: 255, OnuId: 1, UniId: 0, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 1, false},
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700689 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "nni", IntfId: 0, GemportId: 1, OnuId: 1, UniId: 0, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 16777216, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530690 // Negative Test cases.
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700691 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 1, GemportId: 1, OnuId: 1, UniId: 0, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 1, false},
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700692 {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 0, GemportId: 257, OnuId: 1, UniId: 0, FlowId: 100, PortNo: 0, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 256, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530693 }
npujarec5762e2020-01-01 14:08:48 +0530694 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
695 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530696 for _, tt := range tests {
697 t.Run(tt.name, func(t *testing.T) {
698
Girish Gowdra9602eb42020-09-09 15:50:39 -0700699 got, err := flowMgr[tt.args.packetIn.IntfId].GetLogicalPortFromPacketIn(ctx, tt.args.packetIn)
kdarapu3248f9a2019-10-03 13:54:52 +0530700 if (err != nil) != tt.wantErr {
701 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() error = %v, wantErr %v", err, tt.wantErr)
702 return
703 }
704 if got != tt.want {
705 t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() = %v, want %v", got, tt.want)
706 }
707 })
708 }
709}
710
711func TestOpenOltFlowMgr_GetPacketOutGemPortID(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700712 // Create fresh flowMgr instance
713 flowMgr = newMockFlowmgr()
kdarapu3248f9a2019-10-03 13:54:52 +0530714
Esin Karaman7fb80c22020-07-16 14:23:33 +0000715 //untagged packet in hex string
716 untaggedStr := "01005e000002000000000001080046c00020000040000102fa140a000001e00000029404000017000705e10000fa"
717 untagged, err := hex.DecodeString(untaggedStr)
718 if err != nil {
719 t.Error("Unable to parse hex string", err)
720 panic(err)
721 }
Girish Gowdra9602eb42020-09-09 15:50:39 -0700722 //single-tagged packet in hex string. vlanID.pbit: 1.1
723 singleTaggedStr := "01005e0000010025ba48172481002001080046c0002000004000010257deab140023e0000001940400001164ee9b0000000000000000000000000000"
Esin Karaman7fb80c22020-07-16 14:23:33 +0000724 singleTagged, err := hex.DecodeString(singleTaggedStr)
725 if err != nil {
726 t.Error("Unable to parse hex string", err)
727 panic(err)
728 }
Girish Gowdra9602eb42020-09-09 15:50:39 -0700729 //double-tagged packet in hex string. vlanID.pbit: 210.0-0.0
730 doubleTaggedStr := "01005e000016deadbeefba118100021081000000080046000028000000000102c5b87f000001e0000016940400002200f8030000000104000000e10000fa"
Esin Karaman7fb80c22020-07-16 14:23:33 +0000731 doubleTagged, err := hex.DecodeString(doubleTaggedStr)
732 if err != nil {
733 t.Error("Unable to parse hex string", err)
734 panic(err)
735 }
736
kdarapu3248f9a2019-10-03 13:54:52 +0530737 type args struct {
738 intfID uint32
739 onuID uint32
740 portNum uint32
Esin Karaman7fb80c22020-07-16 14:23:33 +0000741 packet []byte
kdarapu3248f9a2019-10-03 13:54:52 +0530742 }
743 tests := []struct {
744 name string
745 args args
746 want uint32
747 wantErr bool
748 }{
749 // TODO: Add test cases.
Girish Gowdra9602eb42020-09-09 15:50:39 -0700750 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: untagged}, 1, false},
751 {"GetPacketOutGemPortID", args{intfID: 1, onuID: 2, portNum: 2, packet: singleTagged}, 2, false},
752 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: doubleTagged}, 1, false},
753 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 10, portNum: 10, packet: untagged}, 2, true},
754 {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 3, packet: []byte{}}, 3, true},
kdarapu3248f9a2019-10-03 13:54:52 +0530755 }
Esin Karaman7fb80c22020-07-16 14:23:33 +0000756
npujarec5762e2020-01-01 14:08:48 +0530757 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
758 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530759 for _, tt := range tests {
760 t.Run(tt.name, func(t *testing.T) {
761
Girish Gowdra9602eb42020-09-09 15:50:39 -0700762 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 +0000763 if tt.wantErr {
764 if err == nil {
765 //error expected but got value
766 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, wantErr %v", got, tt.wantErr)
767 }
768 } else {
769 if err != nil {
770 //error is not expected but got error
771 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() error = %v, wantErr %v", err, tt.wantErr)
772 return
773 }
774 if got != tt.want {
775 t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, want %v", got, tt.want)
776 }
kdarapu3248f9a2019-10-03 13:54:52 +0530777 }
kdarapu3248f9a2019-10-03 13:54:52 +0530778 })
779 }
780}
781
782func TestOpenOltFlowMgr_DeleteTechProfileInstance(t *testing.T) {
kdarapu3248f9a2019-10-03 13:54:52 +0530783 type args struct {
784 intfID uint32
785 onuID uint32
786 uniID uint32
787 sn string
Gamze Abakafee36392019-10-03 11:17:24 +0000788 tpID uint32
kdarapu3248f9a2019-10-03 13:54:52 +0530789 }
790 tests := []struct {
791 name string
792 args args
793 wantErr bool
794 }{
795 // TODO: Add test cases.
Gamze Abakafee36392019-10-03 11:17:24 +0000796 {"DeleteTechProfileInstance", args{intfID: 0, onuID: 1, uniID: 1, sn: "", tpID: 64}, false},
kdarapu3248f9a2019-10-03 13:54:52 +0530797 }
npujarec5762e2020-01-01 14:08:48 +0530798 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
799 defer cancel()
kdarapu3248f9a2019-10-03 13:54:52 +0530800 for _, tt := range tests {
801 t.Run(tt.name, func(t *testing.T) {
Girish Gowdra9602eb42020-09-09 15:50:39 -0700802 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 +0530803 t.Errorf("OpenOltFlowMgr.DeleteTechProfileInstance() error = %v, wantErr %v", err, tt.wantErr)
804 }
805 })
806 }
807}
kdarapub26b4502019-10-05 03:02:33 +0530808
809func TestOpenOltFlowMgr_checkAndAddFlow(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000810 ctx := context.Background()
kdarapub26b4502019-10-05 03:02:33 +0530811 kw := make(map[string]uint64)
812 kw["table_id"] = 1
813 kw["meter_id"] = 1
814 kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
815
816 // Upstream flow
817 fa := &fu.FlowArgs{
818 MatchFields: []*ofp.OfpOxmOfbField{
819 fu.InPort(536870912),
820 fu.Metadata_ofp(1),
821 fu.IpProto(17), // dhcp
Gamze Abakafee36392019-10-03 11:17:24 +0000822 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300823 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530824 },
825 Actions: []*ofp.OfpAction{
826 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
827 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700828 fu.Output(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530829 fu.PushVlan(0x8100),
830 },
831 KV: kw,
832 }
833
834 // EAPOL
835 fa2 := &fu.FlowArgs{
836 MatchFields: []*ofp.OfpOxmOfbField{
837 fu.InPort(536870912),
838 fu.Metadata_ofp(1),
839 fu.EthType(0x888E),
840 fu.VlanPcp(1),
841 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
842 },
843 Actions: []*ofp.OfpAction{
844 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
845 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700846 fu.Output(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530847 fu.PushVlan(0x8100),
848 },
849 KV: kw,
850 }
851
852 // HSIA
853 fa3 := &fu.FlowArgs{
854 MatchFields: []*ofp.OfpOxmOfbField{
855 fu.InPort(536870912),
856 fu.Metadata_ofp(1),
857 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300858 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530859 },
860 Actions: []*ofp.OfpAction{
861 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300862 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700863 fu.Output(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530864 fu.PushVlan(0x8100),
865 },
866 KV: kw,
867 }
868
869 fa4 := &fu.FlowArgs{
870 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700871 fu.InPort(16777216),
kdarapub26b4502019-10-05 03:02:33 +0530872 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300873 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
kdarapub26b4502019-10-05 03:02:33 +0530874 fu.VlanPcp(1),
875 },
876 Actions: []*ofp.OfpAction{
877 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +0300878 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
kdarapub26b4502019-10-05 03:02:33 +0530879 fu.Output(536870912),
880 fu.PopVlan(),
881 },
882 KV: kw,
883 }
884
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300885 // PPPOED
886 pppoedFA := &fu.FlowArgs{
887 MatchFields: []*ofp.OfpOxmOfbField{
888 fu.InPort(536870912),
889 fu.Metadata_ofp(1),
890 fu.EthType(0x8863),
891 fu.VlanPcp(1),
892 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
893 },
894 Actions: []*ofp.OfpAction{
895 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -0700896 fu.Output(16777216),
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300897 fu.PushVlan(0x8100),
898 },
899 KV: kw,
900 }
901
kdarapub26b4502019-10-05 03:02:33 +0530902 classifierInfo := make(map[string]interface{})
903 actionInfo := make(map[string]interface{})
904 classifierInfo2 := make(map[string]interface{})
905 actionInfo2 := make(map[string]interface{})
906 classifierInfo3 := make(map[string]interface{})
907 actionInfo3 := make(map[string]interface{})
908 classifierInfo4 := make(map[string]interface{})
909 actionInfo4 := make(map[string]interface{})
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300910 classifierInfo5 := make(map[string]interface{})
911 actionInfo5 := make(map[string]interface{})
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700912 flow, _ := fu.MkFlowStat(fa)
913 flow2, _ := fu.MkFlowStat(fa2)
914 flow3, _ := fu.MkFlowStat(fa3)
915 flow4, _ := fu.MkFlowStat(fa4)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300916 flow5, _ := fu.MkFlowStat(pppoedFA)
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700917 formulateClassifierInfoFromFlow(ctx, classifierInfo, flow)
918 formulateClassifierInfoFromFlow(ctx, classifierInfo2, flow2)
919 formulateClassifierInfoFromFlow(ctx, classifierInfo3, flow3)
920 formulateClassifierInfoFromFlow(ctx, classifierInfo4, flow4)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300921 formulateClassifierInfoFromFlow(ctx, classifierInfo5, flow5)
kdarapub26b4502019-10-05 03:02:33 +0530922
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700923 err := formulateActionInfoFromFlow(ctx, actionInfo, classifierInfo, flow)
kdarapub26b4502019-10-05 03:02:33 +0530924 if err != nil {
925 // Error logging is already done in the called function
926 // So just return in case of error
927 return
928 }
929
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700930 err = formulateActionInfoFromFlow(ctx, actionInfo2, classifierInfo2, flow2)
kdarapub26b4502019-10-05 03:02:33 +0530931 if err != nil {
932 // Error logging is already done in the called function
933 // So just return in case of error
934 return
935 }
936
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700937 err = formulateActionInfoFromFlow(ctx, actionInfo3, classifierInfo3, flow3)
kdarapub26b4502019-10-05 03:02:33 +0530938 if err != nil {
939 // Error logging is already done in the called function
940 // So just return in case of error
941 return
942 }
943
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700944 err = formulateActionInfoFromFlow(ctx, actionInfo4, classifierInfo4, flow4)
kdarapub26b4502019-10-05 03:02:33 +0530945 if err != nil {
946 // Error logging is already done in the called function
947 // So just return in case of error
948 return
949 }
950
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -0300951 err = formulateActionInfoFromFlow(ctx, actionInfo5, classifierInfo5, flow5)
952 if err != nil {
953 // Error logging is already done in the called function
954 // So just return in case of error
955 return
956 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700957 /*
958 usGemList := make([]*tp_pb.GemPortAttributes, 4)
959 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
960 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
961 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
962 usGemList = append(usGemList, &tp_pb.GemPortAttributes{})
963 dsGemList := make([]*tp_pb.GemPortAttributes, 4)
964 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
965 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
966 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
967 dsGemList = append(usGemList, &tp_pb.GemPortAttributes{})
968 */
969 TpInst := &tp_pb.TechProfileInstance{
kdarapub26b4502019-10-05 03:02:33 +0530970 Name: "Test-Tech-Profile",
971 SubscriberIdentifier: "257",
972 ProfileType: "Mock",
973 Version: 1,
974 NumGemPorts: 4,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700975 InstanceControl: &tp_pb.InstanceControl{
kdarapub26b4502019-10-05 03:02:33 +0530976 Onu: "1",
977 Uni: "16",
978 },
khenaidoodc2116e2021-10-19 17:33:19 -0400979 UsScheduler: &tp_pb.SchedulerAttributes{},
980 DsScheduler: &tp_pb.SchedulerAttributes{},
kdarapub26b4502019-10-05 03:02:33 +0530981 }
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700982 TpInst.UsScheduler.Priority = 1
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700983 TpInst.UsScheduler.Direction = tp_pb.Direction_UPSTREAM
984 TpInst.UsScheduler.AllocId = 1
985 TpInst.UsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
986 TpInst.UsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700987 TpInst.UsScheduler.Weight = 4
988
989 TpInst.DsScheduler.Priority = 1
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700990 TpInst.DsScheduler.Direction = tp_pb.Direction_DOWNSTREAM
991 TpInst.DsScheduler.AllocId = 1
992 TpInst.DsScheduler.AdditionalBw = tp_pb.AdditionalBW_AdditionalBW_None
993 TpInst.DsScheduler.QSchedPolicy = tp_pb.SchedulingPolicy_WRR
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700994 TpInst.DsScheduler.Weight = 4
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700995 TpInst.UpstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
996 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
997 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
998 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
999 TpInst.UpstreamGemPortAttributeList = append(TpInst.UpstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001000
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001001 TpInst.DownstreamGemPortAttributeList = make([]*tp_pb.GemPortAttributes, 0)
1002 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 1, PbitMap: "0b00000011"})
1003 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 2, PbitMap: "0b00001100"})
1004 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 3, PbitMap: "0b00110000"})
1005 TpInst.DownstreamGemPortAttributeList = append(TpInst.DownstreamGemPortAttributeList, &tp_pb.GemPortAttributes{GemportId: 4, PbitMap: "0b11000000"})
kdarapub26b4502019-10-05 03:02:33 +05301006
kdarapub26b4502019-10-05 03:02:33 +05301007 type args struct {
1008 args map[string]uint32
1009 classifierInfo map[string]interface{}
1010 actionInfo map[string]interface{}
1011 flow *ofp.OfpFlowStats
1012 gemPort uint32
1013 intfID uint32
1014 onuID uint32
1015 uniID uint32
1016 portNo uint32
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -07001017 TpInst *tp_pb.TechProfileInstance
kdarapub26b4502019-10-05 03:02:33 +05301018 allocID []uint32
1019 gemPorts []uint32
1020 TpID uint32
1021 uni string
1022 }
1023 tests := []struct {
Kent Hagermane6ff1012020-07-14 15:07:53 -04001024 name string
1025 args args
kdarapub26b4502019-10-05 03:02:33 +05301026 }{
1027 {
1028 name: "checkAndAddFlow-1",
1029 args: args{
1030 args: nil,
1031 classifierInfo: classifierInfo,
1032 actionInfo: actionInfo,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001033 flow: flow,
kdarapub26b4502019-10-05 03:02:33 +05301034 gemPort: 1,
1035 intfID: 1,
1036 onuID: 1,
1037 uniID: 16,
1038 portNo: 1,
1039 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001040 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301041 gemPorts: []uint32{1, 2, 3, 4},
1042 TpID: 64,
1043 uni: "16",
1044 },
1045 },
1046 {
1047 name: "checkAndAddFlow-2",
1048 args: args{
1049 args: nil,
1050 classifierInfo: classifierInfo2,
1051 actionInfo: actionInfo2,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001052 flow: flow2,
kdarapub26b4502019-10-05 03:02:33 +05301053 gemPort: 1,
1054 intfID: 1,
1055 onuID: 1,
1056 uniID: 16,
1057 portNo: 1,
1058 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001059 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301060 gemPorts: []uint32{1, 2, 3, 4},
1061 TpID: 64,
1062 uni: "16",
1063 },
1064 },
1065 {
1066 name: "checkAndAddFlow-3",
1067 args: args{
1068 args: nil,
1069 classifierInfo: classifierInfo3,
1070 actionInfo: actionInfo3,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001071 flow: flow3,
kdarapub26b4502019-10-05 03:02:33 +05301072 gemPort: 1,
1073 intfID: 1,
1074 onuID: 1,
1075 uniID: 16,
1076 portNo: 1,
1077 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001078 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301079 gemPorts: []uint32{1, 2, 3, 4},
1080 TpID: 64,
1081 uni: "16",
1082 },
1083 },
1084 {
1085 name: "checkAndAddFlow-4",
1086 args: args{
1087 args: nil,
1088 classifierInfo: classifierInfo4,
1089 actionInfo: actionInfo4,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001090 flow: flow4,
kdarapub26b4502019-10-05 03:02:33 +05301091 gemPort: 1,
1092 intfID: 1,
1093 onuID: 1,
1094 uniID: 16,
1095 portNo: 1,
1096 TpInst: TpInst,
Girish Gowdraa09aeab2020-09-14 16:30:52 -07001097 allocID: []uint32{0x8001},
kdarapub26b4502019-10-05 03:02:33 +05301098 gemPorts: []uint32{1, 2, 3, 4},
1099 TpID: 64,
1100 uni: "16",
1101 },
1102 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001103 {
1104 name: "checkAndAddFlow-5",
1105 args: args{
1106 args: nil,
1107 classifierInfo: classifierInfo5,
1108 actionInfo: actionInfo5,
1109 flow: flow5,
1110 gemPort: 1,
1111 intfID: 1,
1112 onuID: 1,
1113 uniID: 16,
1114 portNo: 1,
1115 TpInst: TpInst,
1116 allocID: []uint32{0x8001},
1117 gemPorts: []uint32{1, 2, 3, 4},
1118 TpID: 64,
1119 uni: "16",
1120 },
1121 },
kdarapub26b4502019-10-05 03:02:33 +05301122 }
npujarec5762e2020-01-01 14:08:48 +05301123 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1124 defer cancel()
kdarapub26b4502019-10-05 03:02:33 +05301125 for _, tt := range tests {
1126 t.Run(tt.name, func(t *testing.T) {
Gamze Abaka6d0a64f2021-11-18 08:08:33 +00001127 err := flowMgr[tt.args.intfID].checkAndAddFlow(ctx, tt.args.args, tt.args.classifierInfo, tt.args.actionInfo, tt.args.flow,
Gamze Abakafee36392019-10-03 11:17:24 +00001128 tt.args.TpInst, tt.args.gemPorts, tt.args.TpID, tt.args.uni)
Gamze Abaka6d0a64f2021-11-18 08:08:33 +00001129 if err != nil {
1130 t.Error("check-and-add-flow failed", err)
1131 return
1132 }
kdarapub26b4502019-10-05 03:02:33 +05301133 })
1134 }
1135}
Esin Karamanccb714b2019-11-29 15:02:06 +00001136
Esin Karamand519bbf2020-07-01 11:16:03 +00001137func TestOpenOltFlowMgr_TestMulticastFlowAndGroup(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +05301138 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1139 defer cancel()
Esin Karamanccb714b2019-11-29 15:02:06 +00001140 //create group
1141 group := newGroup(2, []uint32{1})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001142 err := flowMgr[0].grpMgr.AddGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001143 if err != nil {
1144 t.Error("group-add failed", err)
1145 return
1146 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001147 //create multicast flow
1148 multicastFlowArgs := &fu.FlowArgs{
1149 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001150 fu.InPort(16777216),
Esin Karamanccb714b2019-11-29 15:02:06 +00001151 fu.VlanVid(660), //vlan
1152 fu.Metadata_ofp(uint64(66)), //inner vlan
1153 fu.EthType(0x800), //ipv4
1154 fu.Ipv4Dst(3809869825), //227.22.0.1
1155 },
1156 Actions: []*ofp.OfpAction{
1157 fu.Group(1),
1158 },
1159 }
divyadesaid26f6b12020-03-19 06:30:28 +00001160 ofpStats, _ := fu.MkFlowStat(multicastFlowArgs)
Esin Karamand519bbf2020-07-01 11:16:03 +00001161 fmt.Println(ofpStats.Id)
khenaidoodc2116e2021-10-19 17:33:19 -04001162 err = flowMgr[0].AddFlow(ctx, ofpStats, &ofp.FlowMetadata{})
Esin Karamand519bbf2020-07-01 11:16:03 +00001163 if err != nil {
1164 t.Error("Multicast flow-add failed", err)
1165 return
1166 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001167
1168 //add bucket to the group
1169 group = newGroup(2, []uint32{1, 2})
Girish Gowdra9602eb42020-09-09 15:50:39 -07001170 err = flowMgr[0].grpMgr.ModifyGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001171 if err != nil {
1172 t.Error("modify-group failed", err)
1173 return
1174 }
1175 //remove the multicast flow
Girish Gowdra9602eb42020-09-09 15:50:39 -07001176 err = flowMgr[0].RemoveFlow(ctx, ofpStats)
Esin Karamand519bbf2020-07-01 11:16:03 +00001177 if err != nil {
1178 t.Error("Multicast flow-remove failed", err)
1179 return
1180 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001181
Esin Karamand519bbf2020-07-01 11:16:03 +00001182 //remove the group
Girish Gowdra9602eb42020-09-09 15:50:39 -07001183 err = flowMgr[0].grpMgr.DeleteGroup(ctx, group)
Esin Karamand519bbf2020-07-01 11:16:03 +00001184 if err != nil {
1185 t.Error("delete-group failed", err)
1186 return
1187 }
Esin Karamanccb714b2019-11-29 15:02:06 +00001188}
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001189
1190func TestOpenOltFlowMgr_TestRouteFlowToOnuChannel(t *testing.T) {
1191 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
1192 defer cancel()
1193 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/core", log.DebugLevel)
1194 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager", log.DebugLevel)
1195 log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/pkg/mocks", log.DebugLevel)
Girish Gowdra0aca4982021-01-04 12:44:27 -08001196 kwTable1Meter1 := make(map[string]uint64)
1197 kwTable1Meter1["table_id"] = 1
1198 kwTable1Meter1["meter_id"] = 1
1199 kwTable1Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
1200
1201 kwTable0Meter1 := make(map[string]uint64)
1202 kwTable0Meter1["table_id"] = 0
1203 kwTable0Meter1["meter_id"] = 1
1204 kwTable0Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001205
Girish Gowdraffa52e52022-02-16 15:48:10 -08001206 kwTable0Meter1WithCvid := make(map[string]uint64)
1207 kwTable0Meter1WithCvid["table_id"] = 0
1208 kwTable0Meter1WithCvid["meter_id"] = 1
1209 kwTable0Meter1WithCvid["write_metadata"] = 0x3c004000000000 // Tech-Profile-ID 64, cvid 60 in write metadata
1210
1211 kwTable1Meter1WithCvid := make(map[string]uint64)
1212 kwTable1Meter1WithCvid["table_id"] = 1
1213 kwTable1Meter1WithCvid["meter_id"] = 1
1214 kwTable1Meter1WithCvid["write_metadata"] = 0x3c004000000000 // Tech-Profile-ID 64, cvid 60 in write metadata
1215
khenaidoodc2116e2021-10-19 17:33:19 -04001216 flowMetadata1 := ofp.FlowMetadata{Meters: []*ofp.OfpMeterConfig{
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001217 {
1218 Flags: 5,
1219 MeterId: 1,
khenaidoodc2116e2021-10-19 17:33:19 -04001220 Bands: []*ofp.OfpMeterBandHeader{
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001221 {
khenaidoodc2116e2021-10-19 17:33:19 -04001222 Type: ofp.OfpMeterBandType_OFPMBT_DROP,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001223 Rate: 16000,
Gamze Abaka01174422021-03-10 06:55:27 +00001224 BurstSize: 0,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001225 },
1226 {
khenaidoodc2116e2021-10-19 17:33:19 -04001227 Type: ofp.OfpMeterBandType_OFPMBT_DROP,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001228 Rate: 32000,
1229 BurstSize: 30,
1230 },
1231 {
khenaidoodc2116e2021-10-19 17:33:19 -04001232 Type: ofp.OfpMeterBandType_OFPMBT_DROP,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001233 Rate: 64000,
1234 BurstSize: 30,
1235 },
1236 },
1237 },
1238 }}
1239
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001240 // Downstream LLDP Trap from NNI0 flow
1241 fa0 := &fu.FlowArgs{
1242 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001243 fu.InPort(16777216),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001244 fu.EthType(35020),
1245 },
1246 Actions: []*ofp.OfpAction{
1247 fu.Output(4294967293),
1248 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001249 KV: make(map[string]uint64),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001250 }
1251
1252 // Upstream flow DHCP flow - ONU1 UNI0 PON0
1253 fa1 := &fu.FlowArgs{
1254 MatchFields: []*ofp.OfpOxmOfbField{
1255 fu.InPort(536870912),
1256 fu.Metadata_ofp(1),
1257 fu.IpProto(17), // dhcp
1258 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001259 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001260 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001261 },
1262 Actions: []*ofp.OfpAction{
1263 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1264 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1265 fu.Output(2147483645),
1266 fu.PushVlan(0x8100),
1267 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001268 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001269 }
1270
1271 // Upstream EAPOL - ONU1 UNI0 PON0
1272 fa2 := &fu.FlowArgs{
1273 MatchFields: []*ofp.OfpOxmOfbField{
1274 fu.InPort(536870912),
1275 fu.Metadata_ofp(1),
1276 fu.EthType(0x888E),
1277 fu.VlanPcp(1),
1278 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001279 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001280 },
1281 Actions: []*ofp.OfpAction{
1282 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1283 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1284 fu.Output(2147483645),
1285 fu.PushVlan(0x8100),
1286 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001287 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001288 }
1289
1290 // Upstream HSIA - ONU1 UNI0 PON0
1291 fa3 := &fu.FlowArgs{
1292 MatchFields: []*ofp.OfpOxmOfbField{
1293 fu.InPort(536870912),
1294 fu.Metadata_ofp(1),
1295 //fu.EthType(0x8100),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001296 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001297 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001298 },
1299 Actions: []*ofp.OfpAction{
1300 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001301 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001302 fu.Output(16777216),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001303 fu.PushVlan(0x8100),
1304 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001305 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001306 }
1307
1308 // Downstream HSIA - ONU1 UNI0 PON0
1309 fa4 := &fu.FlowArgs{
1310 MatchFields: []*ofp.OfpOxmOfbField{
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001311 fu.InPort(16777216),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001312 fu.Metadata_ofp(1),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001313 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001314 fu.VlanPcp(1),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001315 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001316 },
1317 Actions: []*ofp.OfpAction{
1318 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001319 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001320 fu.Output(536870912),
1321 fu.PopVlan(),
1322 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001323 KV: kwTable0Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001324 }
1325
1326 // Upstream flow DHCP flow - ONU1 UNI0 PON15
1327 fa5 := &fu.FlowArgs{
1328 MatchFields: []*ofp.OfpOxmOfbField{
1329 fu.InPort(536870927),
1330 fu.Metadata_ofp(1),
1331 fu.IpProto(17), // dhcp
1332 fu.VlanPcp(0),
Andrey Pozolotin32b36562021-06-02 10:23:26 +03001333 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001334 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001335 },
1336 Actions: []*ofp.OfpAction{
1337 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1338 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259)),
1339 fu.Output(2147483645),
1340 fu.PushVlan(0x8100),
1341 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001342 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001343 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001344
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001345 // Upstream EAPOL - ONU1 UNI0 PON15
1346 fa6 := &fu.FlowArgs{
1347 MatchFields: []*ofp.OfpOxmOfbField{
1348 fu.InPort(536870927),
1349 fu.Metadata_ofp(1),
1350 fu.EthType(0x888E),
1351 fu.VlanPcp(1),
1352 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001353 fu.TunnelId(256),
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001354 },
1355 Actions: []*ofp.OfpAction{
1356 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1357 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1358 fu.Output(2147483645),
1359 fu.PushVlan(0x8100),
1360 },
Girish Gowdra0aca4982021-01-04 12:44:27 -08001361 KV: kwTable1Meter1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001362 }
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001363
1364 // Upstream PPPOED - ONU1 UNI0 PON0
1365 fa7 := &fu.FlowArgs{
1366 MatchFields: []*ofp.OfpOxmOfbField{
1367 fu.InPort(536870912),
1368 fu.Metadata_ofp(1),
1369 fu.EthType(0x8863),
1370 fu.VlanPcp(1),
1371 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001372 fu.TunnelId(256),
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001373 },
1374 Actions: []*ofp.OfpAction{
1375 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1376 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1377 fu.Output(2147483645),
1378 fu.PushVlan(0x8100),
1379 },
1380 KV: kwTable1Meter1,
1381 }
1382
1383 // Upstream PPPOED - ONU1 UNI0 PON15
1384 fa8 := &fu.FlowArgs{
1385 MatchFields: []*ofp.OfpOxmOfbField{
1386 fu.InPort(536870927),
1387 fu.Metadata_ofp(1),
1388 fu.EthType(0x8863),
1389 fu.VlanPcp(1),
1390 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259),
Mahir Gunyel0c009fc2021-10-22 17:47:16 -07001391 fu.TunnelId(256),
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001392 },
1393 Actions: []*ofp.OfpAction{
1394 //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))),
1395 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)),
1396 fu.Output(2147483645),
1397 fu.PushVlan(0x8100),
1398 },
1399 KV: kwTable1Meter1,
1400 }
Girish Gowdraffa52e52022-02-16 15:48:10 -08001401
1402 // Downstream FTTB Subscriber flow - ONU1 UNI0 PON0, write metadata with cvid
1403 // match outer vid 100, with inner cvid 60 -> modify outer vid to 200 and output on pon port
1404 fa9 := &fu.FlowArgs{
1405 MatchFields: []*ofp.OfpOxmOfbField{
1406 fu.InPort(16777216),
1407 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT | 100)),
1408 fu.TunnelId(256),
1409 },
1410 Actions: []*ofp.OfpAction{
1411 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT | 200))),
1412 fu.Output(536870912),
1413 },
1414 KV: kwTable0Meter1WithCvid,
1415 }
1416
1417 // Upstream FTTB Subscriber flow - ONU1 UNI0 PON0, write metadata with cvid
1418 // match outer vid 200, with inner cvid 60 -> modify outer vid to 100 and output on nni port
1419 fa10 := &fu.FlowArgs{
1420 MatchFields: []*ofp.OfpOxmOfbField{
1421 fu.InPort(536870912),
1422 fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT | 200)),
1423 fu.TunnelId(256),
1424 },
1425 Actions: []*ofp.OfpAction{
1426 fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT | 100))),
1427 fu.Output(2147483645),
1428 },
1429 KV: kwTable1Meter1WithCvid,
1430 }
1431
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001432 flow0, _ := fu.MkFlowStat(fa0)
1433 flow1, _ := fu.MkFlowStat(fa1)
1434 flow2, _ := fu.MkFlowStat(fa2)
1435 flow3, _ := fu.MkFlowStat(fa3)
1436 flow4, _ := fu.MkFlowStat(fa4)
1437
1438 flow5, _ := fu.MkFlowStat(fa5)
1439 flow6, _ := fu.MkFlowStat(fa6)
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001440 flow7, _ := fu.MkFlowStat(fa7)
1441 flow8, _ := fu.MkFlowStat(fa8)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001442
Girish Gowdraffa52e52022-02-16 15:48:10 -08001443 flow9, _ := fu.MkFlowStat(fa9)
1444 flow10, _ := fu.MkFlowStat(fa10)
1445
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001446 type args struct {
1447 ctx context.Context
yasin saplid0566272021-12-21 09:10:30 +00001448 intfID int32
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001449 flow *ofp.OfpFlowStats
1450 addFlow bool
khenaidoodc2116e2021-10-19 17:33:19 -04001451 flowMetadata *ofp.FlowMetadata
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001452 }
1453 tests := []struct {
1454 name string
1455 args args
1456 wantErr bool
1457 returnedErr error
1458 }{
1459 {
1460 name: "RouteFlowToOnuChannel-0",
1461 args: args{
1462 ctx: ctx,
yasin saplid0566272021-12-21 09:10:30 +00001463 intfID: NumPonPorts,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001464 flow: flow0,
1465 addFlow: true,
1466 flowMetadata: &flowMetadata1,
1467 },
1468 wantErr: false,
1469 },
1470 {
1471 name: "RouteFlowToOnuChannel-1",
1472 args: args{
1473 ctx: ctx,
yasin saplid0566272021-12-21 09:10:30 +00001474 intfID: 0,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001475 flow: flow1,
1476 addFlow: true,
1477 flowMetadata: &flowMetadata1,
1478 },
1479 wantErr: false,
1480 },
1481 {
1482 name: "RouteFlowToOnuChannel-2",
1483 args: args{
1484 ctx: ctx,
yasin saplid0566272021-12-21 09:10:30 +00001485 intfID: 0,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001486 flow: flow2,
1487 addFlow: true,
1488 flowMetadata: &flowMetadata1,
1489 },
1490 wantErr: false,
1491 },
1492 {
1493 name: "RouteFlowToOnuChannel-3",
1494 args: args{
1495 ctx: ctx,
yasin saplid0566272021-12-21 09:10:30 +00001496 intfID: 0,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001497 flow: flow3,
1498 addFlow: true,
1499 flowMetadata: &flowMetadata1,
1500 },
1501 wantErr: false,
1502 },
1503 {
1504 name: "RouteFlowToOnuChannel-4",
1505 args: args{
1506 ctx: ctx,
yasin saplid0566272021-12-21 09:10:30 +00001507 intfID: 0,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001508 flow: flow4,
1509 addFlow: true,
1510 flowMetadata: &flowMetadata1,
1511 },
1512 wantErr: false,
1513 },
1514 {
1515 name: "RouteFlowToOnuChannel-5",
1516 args: args{
1517 ctx: ctx,
yasin saplid0566272021-12-21 09:10:30 +00001518 intfID: 0,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001519 flow: flow1,
1520 addFlow: false,
1521 flowMetadata: &flowMetadata1,
1522 },
1523 wantErr: false,
1524 },
1525 {
1526 name: "RouteFlowToOnuChannel-6",
1527 args: args{
1528 ctx: ctx,
yasin saplid0566272021-12-21 09:10:30 +00001529 intfID: 0,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001530 flow: flow1,
1531 addFlow: true,
Girish Gowdra0aca4982021-01-04 12:44:27 -08001532 flowMetadata: &flowMetadata1,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001533 },
Girish Gowdrad23ce662021-10-20 16:48:28 -07001534 wantErr: false,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001535 },
1536 {
1537 name: "RouteFlowToOnuChannel-7",
1538 args: args{
1539 ctx: ctx,
yasin saplid0566272021-12-21 09:10:30 +00001540 intfID: 15,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001541 flow: flow5,
1542 addFlow: true,
1543 flowMetadata: &flowMetadata1,
1544 },
1545 wantErr: false,
1546 },
1547 {
1548 name: "RouteFlowToOnuChannel-8",
1549 args: args{
1550 ctx: ctx,
yasin saplid0566272021-12-21 09:10:30 +00001551 intfID: 15,
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001552 flow: flow6,
1553 addFlow: true,
1554 flowMetadata: &flowMetadata1,
1555 },
1556 wantErr: false,
1557 },
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001558 {
1559 name: "RouteFlowToOnuChannel-9",
1560 args: args{
1561 ctx: ctx,
yasin saplid0566272021-12-21 09:10:30 +00001562 intfID: 0,
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001563 flow: flow7,
1564 addFlow: true,
1565 flowMetadata: &flowMetadata1,
1566 },
1567 wantErr: false,
1568 },
1569 {
1570 name: "RouteFlowToOnuChannel-10",
1571 args: args{
1572 ctx: ctx,
yasin saplid0566272021-12-21 09:10:30 +00001573 intfID: 15,
Marcos Aurelio Carrero (Furukawa)388fb0a2021-02-04 18:05:11 -03001574 flow: flow8,
1575 addFlow: true,
1576 flowMetadata: &flowMetadata1,
1577 },
1578 wantErr: false,
1579 },
Girish Gowdra5c00ef12021-12-01 17:19:41 +05301580 {
1581 name: "RouteFlowToOnuChannel-11", // Test Remove trap-from-nni LLDP flow
1582 args: args{
1583 ctx: ctx,
yasin saplid0566272021-12-21 09:10:30 +00001584 intfID: NumPonPorts,
Girish Gowdra5c00ef12021-12-01 17:19:41 +05301585 flow: flow0,
1586 addFlow: false,
1587 flowMetadata: &flowMetadata1,
1588 },
1589 wantErr: false,
1590 },
Girish Gowdraffa52e52022-02-16 15:48:10 -08001591 {
1592 name: "RouteFlowToOnuChannel-fttb-subscriber-downstream-12",
1593 args: args{
1594 ctx: ctx,
1595 intfID: 0,
1596 flow: flow9,
1597 addFlow: true,
1598 flowMetadata: &flowMetadata1,
1599 },
1600 wantErr: false,
1601 },
1602 {
1603 name: "RouteFlowToOnuChannel-fttb-subscriber-upstream-13",
1604 args: args{
1605 ctx: ctx,
1606 intfID: 0,
1607 flow: flow10,
1608 addFlow: true,
1609 flowMetadata: &flowMetadata1,
1610 },
1611 wantErr: false,
1612 },
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001613 }
1614
1615 var wg sync.WaitGroup
1616 defer wg.Wait() // wait for all go routines to complete
1617 for _, tt := range tests {
Girish Gowdrad23ce662021-10-20 16:48:28 -07001618 wg.Add(1) // one per go routine
1619 // The flows needs to be pushed in a particular order as they are stateful - meaning a flow delete can happen only if a flow add was done
1620 // This delay is needed so that flows arrive in order. Otherwise if all flows are pushed at once the go routine can get scheduled
1621 // in random order causing flows to come out of order and test fails
1622 time.Sleep(5 * time.Millisecond)
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001623 t.Run(tt.name, func(t *testing.T) {
Girish Gowdrad23ce662021-10-20 16:48:28 -07001624 defer wg.Done()
yasin saplid0566272021-12-21 09:10:30 +00001625 tt.returnedErr = flowMgr[tt.args.intfID].RouteFlowToOnuChannel(tt.args.ctx, tt.args.flow, tt.args.addFlow, tt.args.flowMetadata)
Girish Gowdrad23ce662021-10-20 16:48:28 -07001626 if (tt.wantErr == false && tt.returnedErr != nil) || (tt.wantErr == true && tt.returnedErr == nil) {
1627 t.Errorf("OpenOltFlowMgr.RouteFlowToOnuChannel() error = %v, wantErr %v", tt.returnedErr, tt.wantErr)
1628 }
Girish Gowdrafb3d6102020-10-16 16:32:36 -07001629 })
1630 }
1631}