kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 1 | /* |
| 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 Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 17 | //Package core provides the utility for olt devices, flows and statistics |
| 18 | package core |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 19 | |
| 20 | import ( |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 21 | "context" |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 22 | "fmt" |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 23 | "reflect" |
| 24 | "strconv" |
| 25 | "sync" |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 26 | "testing" |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 27 | "time" |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 28 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 29 | "github.com/opencord/voltha-protos/v3/go/voltha" |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 30 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 31 | "github.com/opencord/voltha-lib-go/v3/pkg/db" |
| 32 | fu "github.com/opencord/voltha-lib-go/v3/pkg/flows" |
| 33 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 34 | tp "github.com/opencord/voltha-lib-go/v3/pkg/techprofile" |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 35 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager" |
| 36 | rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager" |
| 37 | "github.com/opencord/voltha-openolt-adapter/pkg/mocks" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 38 | ofp "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 39 | "github.com/opencord/voltha-protos/v3/go/openolt" |
| 40 | openoltpb2 "github.com/opencord/voltha-protos/v3/go/openolt" |
| 41 | tp_pb "github.com/opencord/voltha-protos/v3/go/tech_profile" |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 42 | ) |
| 43 | |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 44 | var flowMgr *OpenOltFlowMgr |
| 45 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 46 | func init() { |
| 47 | log.SetDefaultLogger(log.JSON, log.DebugLevel, nil) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 48 | flowMgr = newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 49 | } |
| 50 | func newMockResourceMgr() *resourcemanager.OpenOltResourceMgr { |
| 51 | ranges := []*openolt.DeviceInfo_DeviceResourceRanges{ |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 52 | { |
| 53 | IntfIds: []uint32{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, |
| 54 | Technology: "Default", |
| 55 | }, |
| 56 | } |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 57 | |
| 58 | deviceinfo := &openolt.DeviceInfo{Vendor: "openolt", Model: "openolt", HardwareVersion: "1.0", FirmwareVersion: "1.0", |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 59 | DeviceId: "olt", DeviceSerialNumber: "openolt", PonPorts: 16, Technology: "Default", |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 60 | OnuIdStart: 1, OnuIdEnd: 1, AllocIdStart: 1, AllocIdEnd: 1, |
| 61 | GemportIdStart: 1, GemportIdEnd: 1, FlowIdStart: 1, FlowIdEnd: 1, |
| 62 | Ranges: ranges, |
| 63 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 64 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 65 | defer cancel() |
| 66 | rsrMgr := resourcemanager.NewResourceMgr(ctx, "olt", "127.0.0.1:2379", "etcd", "olt", deviceinfo) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 67 | for key := range rsrMgr.ResourceMgrs { |
sbarbari | a8910ba | 2019-11-05 10:12:23 -0500 | [diff] [blame] | 68 | rsrMgr.ResourceMgrs[key].KVStore = &db.Backend{} |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 69 | rsrMgr.ResourceMgrs[key].KVStore.Client = &mocks.MockKVClient{} |
| 70 | rsrMgr.ResourceMgrs[key].TechProfileMgr = mocks.MockTechProfile{TpID: key} |
| 71 | } |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 72 | return rsrMgr |
| 73 | } |
| 74 | |
| 75 | func newMockFlowmgr() *OpenOltFlowMgr { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 76 | rMgr := newMockResourceMgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 77 | dh := newMockDeviceHandler() |
| 78 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 79 | rMgr.KVStore = &db.Backend{} |
| 80 | rMgr.KVStore.Client = &mocks.MockKVClient{} |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 81 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 82 | dh.resourceMgr = rMgr |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 83 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 84 | defer cancel() |
| 85 | flwMgr := NewFlowManager(ctx, dh, rMgr) |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 86 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 87 | onuGemInfo1 := make([]rsrcMgr.OnuGemInfo, 2) |
| 88 | onuGemInfo2 := make([]rsrcMgr.OnuGemInfo, 2) |
| 89 | onuGemInfo1[0] = rsrcMgr.OnuGemInfo{OnuID: 1, SerialNumber: "1", IntfID: 1, GemPorts: []uint32{1}} |
| 90 | onuGemInfo2[1] = rsrcMgr.OnuGemInfo{OnuID: 2, SerialNumber: "2", IntfID: 2, GemPorts: []uint32{2}} |
| 91 | flwMgr.onuGemInfo[1] = onuGemInfo1 |
| 92 | flwMgr.onuGemInfo[2] = onuGemInfo2 |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 93 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 94 | packetInGemPort := make(map[rsrcMgr.PacketInInfoKey]uint32) |
| 95 | packetInGemPort[rsrcMgr.PacketInInfoKey{IntfID: 1, OnuID: 1, LogicalPort: 1}] = 1 |
| 96 | packetInGemPort[rsrcMgr.PacketInInfoKey{IntfID: 2, OnuID: 2, LogicalPort: 2}] = 2 |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 97 | |
| 98 | flwMgr.packetInGemPort = packetInGemPort |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 99 | tps := make(map[uint32]tp.TechProfileIf) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 100 | for key := range rMgr.ResourceMgrs { |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 101 | tps[key] = mocks.MockTechProfile{TpID: key} |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 102 | } |
| 103 | flwMgr.techprofile = tps |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 104 | |
| 105 | interface2mcastQeueuMap := make(map[uint32]*queueInfoBrief) |
| 106 | interface2mcastQeueuMap[0] = &queueInfoBrief{ |
| 107 | gemPortID: 4000, |
| 108 | servicePriority: 3, |
| 109 | } |
| 110 | flwMgr.interfaceToMcastQueueMap = interface2mcastQeueuMap |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 111 | return flwMgr |
| 112 | } |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 113 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 114 | func TestOpenOltFlowMgr_CreateSchedulerQueues(t *testing.T) { |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 115 | // flowMgr := newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 116 | |
| 117 | tprofile := &tp.TechProfile{Name: "tp1", SubscriberIdentifier: "subscriber1", |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 118 | ProfileType: "pt1", NumGemPorts: 1, Version: 1, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 119 | InstanceCtrl: tp.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"}, |
| 120 | } |
| 121 | tprofile.UsScheduler.Direction = "UPSTREAM" |
| 122 | tprofile.UsScheduler.AdditionalBw = "AdditionalBW_None" |
| 123 | tprofile.UsScheduler.QSchedPolicy = "WRR" |
| 124 | |
| 125 | tprofile2 := tprofile |
| 126 | tprofile2.DsScheduler.Direction = "DOWNSTREAM" |
| 127 | tprofile2.DsScheduler.AdditionalBw = "AdditionalBW_None" |
| 128 | tprofile2.DsScheduler.QSchedPolicy = "WRR" |
| 129 | bands := make([]*ofp.OfpMeterBandHeader, 2) |
| 130 | bands[0] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 1000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}} |
| 131 | bands[1] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 2000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}} |
| 132 | ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands} |
| 133 | flowmetadata := &voltha.FlowMetadata{ |
| 134 | Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}, |
| 135 | } |
| 136 | type args struct { |
| 137 | Dir tp_pb.Direction |
| 138 | IntfID uint32 |
| 139 | OnuID uint32 |
| 140 | UniID uint32 |
| 141 | UniPort uint32 |
| 142 | TpInst *tp.TechProfile |
| 143 | MeterID uint32 |
| 144 | flowMetadata *voltha.FlowMetadata |
| 145 | } |
| 146 | tests := []struct { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 147 | name string |
| 148 | schedQueue schedQueue |
| 149 | wantErr bool |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 150 | }{ |
| 151 | // TODO: Add test cases. |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 152 | {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 1, flowmetadata}, false}, |
| 153 | {"CreateSchedulerQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 1, flowmetadata}, false}, |
| 154 | {"CreateSchedulerQueues-3", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 2, flowmetadata}, true}, |
| 155 | {"CreateSchedulerQueues-4", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 2, flowmetadata}, true}, |
| 156 | {"CreateSchedulerQueues-5", schedQueue{tp_pb.Direction_UPSTREAM, 2, 2, 2, 64, 2, tprofile, 2, flowmetadata}, true}, |
| 157 | {"CreateSchedulerQueues-6", schedQueue{tp_pb.Direction_DOWNSTREAM, 2, 2, 2, 65, 2, tprofile2, 2, flowmetadata}, true}, |
| 158 | {"CreateSchedulerQueues-13", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 1, flowmetadata}, false}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 159 | //Negative testcases |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 160 | {"CreateSchedulerQueues-7", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 1, &voltha.FlowMetadata{}}, true}, |
| 161 | {"CreateSchedulerQueues-8", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 0, &voltha.FlowMetadata{}}, true}, |
| 162 | {"CreateSchedulerQueues-9", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 1, &voltha.FlowMetadata{}}, true}, |
| 163 | {"CreateSchedulerQueues-10", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 2, &voltha.FlowMetadata{}}, true}, |
| 164 | {"CreateSchedulerQueues-11", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 2, &voltha.FlowMetadata{}}, true}, |
| 165 | {"CreateSchedulerQueues-12", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 2, nil}, true}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 166 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 167 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 168 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 169 | for _, tt := range tests { |
| 170 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 171 | if err := flowMgr.CreateSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 172 | t.Errorf("OpenOltFlowMgr.CreateSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr) |
| 173 | } |
| 174 | }) |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | func TestOpenOltFlowMgr_RemoveSchedulerQueues(t *testing.T) { |
| 179 | |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 180 | // flowMgr := newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 181 | tprofile := &tp.TechProfile{Name: "tp1", SubscriberIdentifier: "subscriber1", |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 182 | ProfileType: "pt1", NumGemPorts: 1, Version: 1, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 183 | InstanceCtrl: tp.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"}, |
| 184 | } |
| 185 | tprofile.UsScheduler.Direction = "UPSTREAM" |
| 186 | tprofile.UsScheduler.AdditionalBw = "AdditionalBW_None" |
| 187 | tprofile.UsScheduler.QSchedPolicy = "WRR" |
| 188 | |
| 189 | tprofile2 := tprofile |
| 190 | tprofile2.DsScheduler.Direction = "DOWNSTREAM" |
| 191 | tprofile2.DsScheduler.AdditionalBw = "AdditionalBW_None" |
| 192 | tprofile2.DsScheduler.QSchedPolicy = "WRR" |
| 193 | //defTprofile := &tp.DefaultTechProfile{} |
| 194 | type args struct { |
| 195 | Dir tp_pb.Direction |
| 196 | IntfID uint32 |
| 197 | OnuID uint32 |
| 198 | UniID uint32 |
| 199 | UniPort uint32 |
| 200 | TpInst *tp.TechProfile |
| 201 | } |
| 202 | tests := []struct { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 203 | name string |
| 204 | schedQueue schedQueue |
| 205 | wantErr bool |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 206 | }{ |
| 207 | // TODO: Add test cases. |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 208 | {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 0, nil}, false}, |
| 209 | {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 210 | // negative test cases |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 211 | {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false}, |
| 212 | {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 213 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 214 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 215 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 216 | for _, tt := range tests { |
| 217 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 218 | if err := flowMgr.RemoveSchedulerQueues(ctx, tt.schedQueue); (err != nil) != tt.wantErr { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 219 | t.Errorf("OpenOltFlowMgr.RemoveSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr) |
| 220 | } |
| 221 | }) |
| 222 | } |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 223 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 224 | } |
| 225 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 226 | func TestOpenOltFlowMgr_createTcontGemports(t *testing.T) { |
| 227 | // flowMgr := newMockFlowmgr() |
| 228 | bands := make([]*ofp.OfpMeterBandHeader, 2) |
| 229 | bands[0] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 1000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}} |
| 230 | bands[1] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 2000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}} |
| 231 | ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands} |
| 232 | flowmetadata := &voltha.FlowMetadata{ |
| 233 | Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}, |
| 234 | } |
| 235 | type args struct { |
| 236 | intfID uint32 |
| 237 | onuID uint32 |
| 238 | uniID uint32 |
| 239 | uni string |
| 240 | uniPort uint32 |
| 241 | TpID uint32 |
| 242 | UsMeterID uint32 |
| 243 | DsMeterID uint32 |
| 244 | flowMetadata *voltha.FlowMetadata |
| 245 | } |
| 246 | tests := []struct { |
| 247 | name string |
| 248 | args args |
| 249 | }{ |
| 250 | {"createTcontGemports-1", args{intfID: 0, onuID: 1, uniID: 1, uni: "16", uniPort: 1, TpID: 64, UsMeterID: 1, DsMeterID: 1, flowMetadata: flowmetadata}}, |
| 251 | {"createTcontGemports-1", args{intfID: 0, onuID: 1, uniID: 1, uni: "16", uniPort: 1, TpID: 65, UsMeterID: 1, DsMeterID: 1, flowMetadata: flowmetadata}}, |
| 252 | } |
| 253 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 254 | defer cancel() |
| 255 | for _, tt := range tests { |
| 256 | t.Run(tt.name, func(t *testing.T) { |
| 257 | _, _, tpInst := flowMgr.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) |
| 258 | switch tpInst := tpInst.(type) { |
| 259 | case *tp.TechProfile: |
| 260 | if tt.args.TpID != 64 { |
| 261 | t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst) |
| 262 | } |
| 263 | case *tp.EponProfile: |
| 264 | if tt.args.TpID != 65 { |
| 265 | t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst) |
| 266 | } |
| 267 | default: |
| 268 | t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst) |
| 269 | } |
| 270 | }) |
| 271 | } |
| 272 | } |
| 273 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 274 | func TestOpenOltFlowMgr_RemoveFlow(t *testing.T) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 275 | ctx := context.Background() |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 276 | // flowMgr := newMockFlowmgr() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 277 | logger.Debug(ctx, "Info Warning Error: Starting RemoveFlow() test") |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 278 | fa := &fu.FlowArgs{ |
| 279 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 280 | fu.InPort(2), |
| 281 | fu.Metadata_ofp(2), |
| 282 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 283 | }, |
| 284 | Actions: []*ofp.OfpAction{ |
| 285 | fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 286 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 287 | fu.Output(1), |
| 288 | }, |
| 289 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 290 | ofpstats, _ := fu.MkFlowStat(fa) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 291 | ofpstats.Cookie = ofpstats.Id |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 292 | lldpFa := &fu.FlowArgs{ |
| 293 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 294 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 295 | fu.InPort(1), |
| 296 | fu.EthType(0x88CC), |
| 297 | fu.TunnelId(536870912), |
| 298 | }, |
| 299 | Actions: []*ofp.OfpAction{ |
| 300 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 301 | }, |
| 302 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 303 | lldpofpstats, _ := fu.MkFlowStat(lldpFa) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 304 | //lldpofpstats.Cookie = lldpofpstats.Id |
| 305 | |
| 306 | dhcpFa := &fu.FlowArgs{ |
| 307 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 308 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 309 | fu.InPort(1), |
| 310 | fu.UdpSrc(67), |
| 311 | //fu.TunnelId(536870912), |
| 312 | fu.IpProto(17), |
| 313 | }, |
| 314 | Actions: []*ofp.OfpAction{ |
| 315 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 316 | }, |
| 317 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 318 | dhcpofpstats, _ := fu.MkFlowStat(dhcpFa) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 319 | //dhcpofpstats.Cookie = dhcpofpstats.Id |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 320 | |
| 321 | //multicast flow |
| 322 | multicastFa := &fu.FlowArgs{ |
| 323 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 324 | fu.InPort(65536), |
| 325 | fu.VlanVid(660), //vlan |
| 326 | fu.Metadata_ofp(uint64(66)), //inner vlan |
| 327 | fu.EthType(0x800), //ipv4 |
| 328 | fu.Ipv4Dst(3809869825), //227.22.0.1 |
| 329 | }, |
| 330 | Actions: []*ofp.OfpAction{ |
| 331 | fu.Group(1), |
| 332 | }, |
| 333 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 334 | multicastOfpStats, _ := fu.MkFlowStat(multicastFa) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 335 | multicastOfpStats.Id = 1 |
| 336 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 337 | type args struct { |
| 338 | flow *ofp.OfpFlowStats |
| 339 | } |
| 340 | tests := []struct { |
| 341 | name string |
| 342 | args args |
| 343 | }{ |
| 344 | // TODO: Add test cases. |
| 345 | {"RemoveFlow", args{flow: ofpstats}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 346 | {"RemoveFlow", args{flow: lldpofpstats}}, |
| 347 | {"RemoveFlow", args{flow: dhcpofpstats}}, |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 348 | {"RemoveFlow", args{flow: multicastOfpStats}}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 349 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 350 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 351 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 352 | for _, tt := range tests { |
| 353 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 354 | flowMgr.RemoveFlow(ctx, tt.args.flow) |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 355 | }) |
| 356 | } |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 357 | // t.Error("=====") |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | func TestOpenOltFlowMgr_AddFlow(t *testing.T) { |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 361 | // flowMgr := newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 362 | kw := make(map[string]uint64) |
| 363 | kw["table_id"] = 1 |
| 364 | kw["meter_id"] = 1 |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 365 | kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64 |
| 366 | |
| 367 | // Upstream flow |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 368 | fa := &fu.FlowArgs{ |
| 369 | MatchFields: []*ofp.OfpOxmOfbField{ |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 370 | fu.InPort(536870912), |
| 371 | fu.Metadata_ofp(1), |
| 372 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 373 | }, |
| 374 | Actions: []*ofp.OfpAction{ |
| 375 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 376 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 377 | fu.Output(65536), |
| 378 | fu.PushVlan(0x8100), |
| 379 | }, |
| 380 | KV: kw, |
| 381 | } |
| 382 | |
| 383 | // Downstream flow |
| 384 | fa3 := &fu.FlowArgs{ |
| 385 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 386 | fu.InPort(65536), |
| 387 | fu.Metadata_ofp(1), |
| 388 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257), |
| 389 | }, |
| 390 | Actions: []*ofp.OfpAction{ |
| 391 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 392 | //fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 393 | fu.PopVlan(), |
| 394 | fu.Output(536870912), |
| 395 | }, |
| 396 | KV: kw, |
| 397 | } |
| 398 | |
| 399 | fa2 := &fu.FlowArgs{ |
| 400 | MatchFields: []*ofp.OfpOxmOfbField{ |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 401 | fu.InPort(1000), |
| 402 | fu.Metadata_ofp(1), |
| 403 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 404 | }, |
| 405 | Actions: []*ofp.OfpAction{ |
| 406 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 407 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 408 | fu.Output(65533), |
| 409 | }, |
| 410 | KV: kw, |
| 411 | } |
| 412 | |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 413 | // TODO Add LLDP flow |
| 414 | // TODO Add DHCP flow |
| 415 | |
| 416 | // Flows for negative scenarios |
| 417 | // Failure in formulateActionInfoFromFlow() |
| 418 | fa4 := &fu.FlowArgs{ |
| 419 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 420 | fu.InPort(1000), |
| 421 | fu.Metadata_ofp(1), |
| 422 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 423 | }, |
| 424 | Actions: []*ofp.OfpAction{ |
| 425 | fu.Experimenter(257, []byte{1, 2, 3, 4}), |
| 426 | }, |
| 427 | KV: kw, |
| 428 | } |
| 429 | |
| 430 | // Invalid Output |
| 431 | fa5 := &fu.FlowArgs{ |
| 432 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 433 | fu.InPort(1000), |
| 434 | fu.Metadata_ofp(1), |
| 435 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 436 | }, |
| 437 | Actions: []*ofp.OfpAction{ |
| 438 | fu.Output(0), |
| 439 | }, |
| 440 | KV: kw, |
| 441 | } |
| 442 | |
| 443 | // Tech-Profile-ID update (not supported) |
| 444 | kw6 := make(map[string]uint64) |
| 445 | kw6["table_id"] = 1 |
| 446 | kw6["meter_id"] = 1 |
| 447 | kw6["write_metadata"] = 0x4100000000 // TpID Other than the stored one |
| 448 | fa6 := &fu.FlowArgs{ |
| 449 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 450 | fu.InPort(536870912), |
| 451 | fu.TunnelId(16), |
| 452 | fu.Metadata_ofp(1), |
| 453 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 454 | }, |
| 455 | Actions: []*ofp.OfpAction{ |
| 456 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 457 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 458 | fu.Output(65535), |
| 459 | }, |
| 460 | KV: kw6, |
| 461 | } |
| 462 | |
| 463 | lldpFa := &fu.FlowArgs{ |
| 464 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 465 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 466 | fu.InPort(1), |
| 467 | fu.EthType(0x88CC), |
| 468 | fu.TunnelId(536870912), |
| 469 | }, |
| 470 | Actions: []*ofp.OfpAction{ |
| 471 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 472 | }, |
| 473 | } |
| 474 | |
| 475 | dhcpFa := &fu.FlowArgs{ |
| 476 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 477 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 478 | fu.InPort(1), |
| 479 | fu.UdpSrc(67), |
| 480 | //fu.TunnelId(536870912), |
| 481 | fu.IpProto(17), |
| 482 | }, |
| 483 | Actions: []*ofp.OfpAction{ |
| 484 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 485 | }, |
| 486 | } |
| 487 | igmpFa := &fu.FlowArgs{ |
| 488 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 489 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 490 | fu.InPort(1), |
| 491 | fu.UdpSrc(67), |
| 492 | //fu.TunnelId(536870912), |
| 493 | fu.IpProto(2), |
| 494 | }, |
| 495 | Actions: []*ofp.OfpAction{ |
| 496 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 497 | }, |
| 498 | } |
| 499 | |
| 500 | fa9 := &fu.FlowArgs{ |
| 501 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 502 | fu.InPort(536870912), |
| 503 | fu.TunnelId(16), |
| 504 | fu.Metadata_ofp(1), |
| 505 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 506 | fu.VlanPcp(1000), |
| 507 | fu.UdpDst(65535), |
| 508 | fu.UdpSrc(536870912), |
| 509 | fu.Ipv4Dst(65535), |
| 510 | fu.Ipv4Src(536870912), |
| 511 | }, |
| 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 | fa10 := &fu.FlowArgs{ |
| 521 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 522 | fu.InPort(65533), |
| 523 | // fu.TunnelId(16), |
| 524 | fu.Metadata_ofp(1), |
| 525 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 526 | fu.VlanPcp(1000), |
| 527 | fu.UdpDst(65535), |
| 528 | fu.UdpSrc(536870912), |
| 529 | fu.Ipv4Dst(65535), |
| 530 | fu.Ipv4Src(536870912), |
| 531 | }, |
| 532 | Actions: []*ofp.OfpAction{ |
| 533 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 534 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 535 | fu.Output(65535), |
| 536 | }, |
| 537 | KV: kw6, |
| 538 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 539 | //multicast flow |
| 540 | fa11 := &fu.FlowArgs{ |
| 541 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 542 | fu.InPort(65536), |
| 543 | fu.VlanVid(660), //vlan |
| 544 | fu.Metadata_ofp(uint64(66)), //inner vlan |
| 545 | fu.EthType(0x800), //ipv4 |
| 546 | fu.Ipv4Dst(3809869825), //227.22.0.1 |
| 547 | }, |
| 548 | Actions: []*ofp.OfpAction{ |
| 549 | fu.Group(1), |
| 550 | }, |
| 551 | KV: kw6, |
| 552 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 553 | ofpstats, _ := fu.MkFlowStat(fa) |
| 554 | ofpstats2, _ := fu.MkFlowStat(fa2) |
| 555 | ofpstats3, _ := fu.MkFlowStat(fa3) |
| 556 | ofpstats4, _ := fu.MkFlowStat(fa4) |
| 557 | ofpstats5, _ := fu.MkFlowStat(fa5) |
| 558 | ofpstats6, _ := fu.MkFlowStat(fa6) |
| 559 | ofpstats7, _ := fu.MkFlowStat(lldpFa) |
| 560 | ofpstats8, _ := fu.MkFlowStat(dhcpFa) |
| 561 | ofpstats9, _ := fu.MkFlowStat(fa9) |
| 562 | ofpstats10, _ := fu.MkFlowStat(fa10) |
| 563 | igmpstats, _ := fu.MkFlowStat(igmpFa) |
| 564 | ofpstats11, _ := fu.MkFlowStat(fa11) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 565 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 566 | fmt.Println(ofpstats6, ofpstats9, ofpstats10) |
| 567 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 568 | ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1} |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 569 | flowMetadata := &voltha.FlowMetadata{ |
| 570 | Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}, |
| 571 | } |
| 572 | type args struct { |
| 573 | flow *ofp.OfpFlowStats |
| 574 | flowMetadata *voltha.FlowMetadata |
| 575 | } |
| 576 | tests := []struct { |
| 577 | name string |
| 578 | args args |
| 579 | }{ |
| 580 | // TODO: Add test cases. |
| 581 | {"AddFlow", args{flow: ofpstats, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 582 | {"AddFlow", args{flow: ofpstats2, flowMetadata: flowMetadata}}, |
| 583 | {"AddFlow", args{flow: ofpstats3, flowMetadata: flowMetadata}}, |
| 584 | {"AddFlow", args{flow: ofpstats4, flowMetadata: flowMetadata}}, |
| 585 | {"AddFlow", args{flow: ofpstats5, flowMetadata: flowMetadata}}, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 586 | //{"AddFlow", args{flow: ofpstats6, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 587 | {"AddFlow", args{flow: ofpstats7, flowMetadata: flowMetadata}}, |
| 588 | {"AddFlow", args{flow: ofpstats8, flowMetadata: flowMetadata}}, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 589 | //{"AddFlow", args{flow: ofpstats9, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 590 | {"AddFlow", args{flow: igmpstats, flowMetadata: flowMetadata}}, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 591 | //{"AddFlow", args{flow: ofpstats10, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 592 | //ofpstats10 |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 593 | {"AddFlow", args{flow: ofpstats11, flowMetadata: flowMetadata}}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 594 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 595 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 596 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 597 | for _, tt := range tests { |
| 598 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 599 | flowMgr.AddFlow(ctx, tt.args.flow, tt.args.flowMetadata) |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 600 | }) |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | func TestOpenOltFlowMgr_UpdateOnuInfo(t *testing.T) { |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 605 | flwMgr := newMockFlowmgr() |
| 606 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 607 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 608 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 609 | |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 610 | wg := sync.WaitGroup{} |
| 611 | |
| 612 | intfCount := 16 |
| 613 | onuCount := 32 |
| 614 | |
| 615 | for i := 0; i < intfCount; i++ { |
| 616 | for j := 0; j < onuCount; j++ { |
| 617 | wg.Add(1) |
| 618 | go func(i uint32, j uint32) { |
| 619 | flwMgr.UpdateOnuInfo(ctx, i, i, fmt.Sprintf("onu-%d", i)) |
| 620 | wg.Done() |
| 621 | }(uint32(i), uint32(j)) |
| 622 | } |
| 623 | |
| 624 | } |
| 625 | |
| 626 | wg.Wait() |
| 627 | } |
| 628 | |
| 629 | func TestOpenOltFlowMgr_addGemPortToOnuInfoMap(t *testing.T) { |
| 630 | flowMgr = newMockFlowmgr() |
| 631 | intfNum := 16 |
| 632 | onuNum := 32 |
| 633 | |
| 634 | // clean the flowMgr |
| 635 | flowMgr.onuGemInfo = make(map[uint32][]rsrcMgr.OnuGemInfo, intfNum) |
| 636 | |
| 637 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 638 | defer cancel() |
| 639 | |
| 640 | // Create OnuInfo |
| 641 | for i := 0; i < intfNum; i++ { |
| 642 | for o := 0; o < onuNum; o++ { |
| 643 | flowMgr.UpdateOnuInfo(ctx, uint32(i), uint32(o), fmt.Sprintf("i%do%d", i, o)) |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | // Add gemPorts to OnuInfo in parallel threads |
| 648 | wg := sync.WaitGroup{} |
| 649 | |
| 650 | for o := 0; o < onuNum; o++ { |
| 651 | for i := 0; i < intfNum; i++ { |
| 652 | wg.Add(1) |
| 653 | go func(intfId uint32, onuId uint32) { |
| 654 | gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", intfId, onuId)) |
| 655 | |
| 656 | flowMgr.addGemPortToOnuInfoMap(ctx, intfId, onuId, uint32(gemID)) |
| 657 | wg.Done() |
| 658 | }(uint32(i), uint32(o)) |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | wg.Wait() |
| 663 | |
| 664 | // check that each entry of onuGemInfo has the correct number of ONUs |
| 665 | for i := 0; i < intfNum; i++ { |
| 666 | lenofOnu := len(flowMgr.onuGemInfo[uint32(i)]) |
| 667 | if onuNum != lenofOnu { |
| 668 | t.Errorf("OnuGemInfo length is not as expected len = %d, want %d", lenofOnu, onuNum) |
| 669 | } |
| 670 | |
| 671 | for o := 0; o < onuNum; o++ { |
| 672 | lenOfGemPorts := len(flowMgr.onuGemInfo[uint32(i)][o].GemPorts) |
| 673 | // check that each onuEntry has 1 gemPort |
| 674 | if lenOfGemPorts != 1 { |
| 675 | t.Errorf("Expected 1 GemPort per ONU, found %d", lenOfGemPorts) |
| 676 | } |
| 677 | |
| 678 | // check that the value of the gemport is correct |
| 679 | gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", i, o)) |
| 680 | currentValue := flowMgr.onuGemInfo[uint32(i)][o].GemPorts[0] |
| 681 | if uint32(gemID) != currentValue { |
| 682 | t.Errorf("Expected GemPort value to be %d, found %d", gemID, currentValue) |
| 683 | } |
| 684 | } |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 688 | func TestOpenOltFlowMgr_deleteGemPortFromLocalCache(t *testing.T) { |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 689 | flwMgr := newMockFlowmgr() |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 690 | type args struct { |
| 691 | intfID uint32 |
| 692 | onuID uint32 |
| 693 | gemPortIDs []uint32 |
| 694 | gemPortIDsToBeDeleted []uint32 |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 695 | gemPortIDsRemaining []uint32 |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 696 | serialNum string |
| 697 | finalLength int |
| 698 | } |
| 699 | tests := []struct { |
| 700 | name string |
| 701 | args args |
| 702 | }{ |
| 703 | // Add/Delete single gem port |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 704 | {"DeleteGemPortFromLocalCache1", args{0, 1, []uint32{1}, []uint32{1}, []uint32{}, "onu1", 0}}, |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 705 | // Delete all gemports |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 706 | {"DeleteGemPortFromLocalCache2", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{1, 2, 3, 4}, []uint32{}, "onu1", 0}}, |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 707 | // Try to delete when there is no gem port |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 708 | {"DeleteGemPortFromLocalCache3", args{0, 1, []uint32{}, []uint32{1, 2}, []uint32{}, "onu1", 0}}, |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 709 | // Try to delete non-existent gem port |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 710 | {"DeleteGemPortFromLocalCache4", args{0, 1, []uint32{1}, []uint32{2}, []uint32{1}, "onu1", 1}}, |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 711 | // Try to delete two of the gem ports |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 712 | {"DeleteGemPortFromLocalCache5", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{2, 4}, []uint32{1, 3}, "onu1", 2}}, |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 713 | } |
| 714 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 715 | defer cancel() |
| 716 | for _, tt := range tests { |
| 717 | t.Run(tt.name, func(t *testing.T) { |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 718 | flwMgr.UpdateOnuInfo(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum) |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 719 | for _, gemPort := range tt.args.gemPortIDs { |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 720 | flwMgr.addGemPortToOnuInfoMap(ctx, tt.args.intfID, tt.args.onuID, gemPort) |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 721 | } |
| 722 | for _, gemPortDeleted := range tt.args.gemPortIDsToBeDeleted { |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 723 | flwMgr.deleteGemPortFromLocalCache(ctx, tt.args.intfID, tt.args.onuID, gemPortDeleted) |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 724 | } |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 725 | lenofGemPorts := len(flwMgr.onuGemInfo[tt.args.intfID][0].GemPorts) |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 726 | if lenofGemPorts != tt.args.finalLength { |
| 727 | t.Errorf("GemPorts length is not as expected len = %d, want %d", lenofGemPorts, tt.args.finalLength) |
| 728 | } |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 729 | gemPorts := flwMgr.onuGemInfo[tt.args.intfID][0].GemPorts |
| 730 | if !reflect.DeepEqual(tt.args.gemPortIDsRemaining, gemPorts) { |
| 731 | t.Errorf("GemPorts are not as expected = %v, want %v", gemPorts, tt.args.gemPortIDsRemaining) |
| 732 | } |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 733 | |
| 734 | }) |
| 735 | } |
| 736 | } |
| 737 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 738 | func TestOpenOltFlowMgr_GetLogicalPortFromPacketIn(t *testing.T) { |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 739 | flwMgr := newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 740 | type args struct { |
| 741 | packetIn *openoltpb2.PacketIndication |
| 742 | } |
| 743 | tests := []struct { |
| 744 | name string |
| 745 | args args |
| 746 | want uint32 |
| 747 | wantErr bool |
| 748 | }{ |
| 749 | // TODO: Add test cases. |
| 750 | {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 1, GemportId: 1, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 1, false}, |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 751 | {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "nni", IntfId: 1, GemportId: 1, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 1048577, false}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 752 | // Negative Test cases. |
| 753 | {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 2, GemportId: 1, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 0, true}, |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 754 | {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 1, GemportId: 1, FlowId: 100, PortNo: 0, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 4112, false}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 755 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 756 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 757 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 758 | for _, tt := range tests { |
| 759 | t.Run(tt.name, func(t *testing.T) { |
| 760 | |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 761 | got, err := flwMgr.GetLogicalPortFromPacketIn(ctx, tt.args.packetIn) |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 762 | if (err != nil) != tt.wantErr { |
| 763 | t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() error = %v, wantErr %v", err, tt.wantErr) |
| 764 | return |
| 765 | } |
| 766 | if got != tt.want { |
| 767 | t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() = %v, want %v", got, tt.want) |
| 768 | } |
| 769 | }) |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | func TestOpenOltFlowMgr_GetPacketOutGemPortID(t *testing.T) { |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 774 | // flwMgr := newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 775 | |
| 776 | type args struct { |
| 777 | intfID uint32 |
| 778 | onuID uint32 |
| 779 | portNum uint32 |
| 780 | } |
| 781 | tests := []struct { |
| 782 | name string |
| 783 | args args |
| 784 | want uint32 |
| 785 | wantErr bool |
| 786 | }{ |
| 787 | // TODO: Add test cases. |
| 788 | {"GetPacketOutGemPortID", args{intfID: 1, onuID: 1, portNum: 1}, 1, false}, |
| 789 | {"GetPacketOutGemPortID", args{intfID: 2, onuID: 2, portNum: 2}, 2, false}, |
| 790 | {"GetPacketOutGemPortID", args{intfID: 1, onuID: 2, portNum: 2}, 0, true}, |
| 791 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 792 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 793 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 794 | for _, tt := range tests { |
| 795 | t.Run(tt.name, func(t *testing.T) { |
| 796 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 797 | got, err := flowMgr.GetPacketOutGemPortID(ctx, tt.args.intfID, tt.args.onuID, tt.args.portNum) |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 798 | if (err != nil) != tt.wantErr { |
| 799 | t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() error = %v, wantErr %v", err, tt.wantErr) |
| 800 | return |
| 801 | } |
| 802 | if got != tt.want { |
| 803 | t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, want %v", got, tt.want) |
| 804 | } |
| 805 | |
| 806 | }) |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | func TestOpenOltFlowMgr_DeleteTechProfileInstance(t *testing.T) { |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 811 | // flwMgr := newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 812 | type args struct { |
| 813 | intfID uint32 |
| 814 | onuID uint32 |
| 815 | uniID uint32 |
| 816 | sn string |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 817 | tpID uint32 |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 818 | } |
| 819 | tests := []struct { |
| 820 | name string |
| 821 | args args |
| 822 | wantErr bool |
| 823 | }{ |
| 824 | // TODO: Add test cases. |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 825 | {"DeleteTechProfileInstance", args{intfID: 0, onuID: 1, uniID: 1, sn: "", tpID: 64}, false}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 826 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 827 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 828 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 829 | for _, tt := range tests { |
| 830 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 831 | if err := flowMgr.DeleteTechProfileInstance(ctx, tt.args.intfID, tt.args.onuID, tt.args.uniID, tt.args.sn, tt.args.tpID); (err != nil) != tt.wantErr { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 832 | t.Errorf("OpenOltFlowMgr.DeleteTechProfileInstance() error = %v, wantErr %v", err, tt.wantErr) |
| 833 | } |
| 834 | }) |
| 835 | } |
| 836 | } |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 837 | |
| 838 | func TestOpenOltFlowMgr_checkAndAddFlow(t *testing.T) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 839 | ctx := context.Background() |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 840 | // flowMgr := newMockFlowmgr() |
| 841 | kw := make(map[string]uint64) |
| 842 | kw["table_id"] = 1 |
| 843 | kw["meter_id"] = 1 |
| 844 | kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64 |
| 845 | |
| 846 | // Upstream flow |
| 847 | fa := &fu.FlowArgs{ |
| 848 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 849 | fu.InPort(536870912), |
| 850 | fu.Metadata_ofp(1), |
| 851 | fu.IpProto(17), // dhcp |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 852 | fu.VlanPcp(0), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 853 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 854 | }, |
| 855 | Actions: []*ofp.OfpAction{ |
| 856 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 857 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 858 | fu.Output(65536), |
| 859 | fu.PushVlan(0x8100), |
| 860 | }, |
| 861 | KV: kw, |
| 862 | } |
| 863 | |
| 864 | // EAPOL |
| 865 | fa2 := &fu.FlowArgs{ |
| 866 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 867 | fu.InPort(536870912), |
| 868 | fu.Metadata_ofp(1), |
| 869 | fu.EthType(0x888E), |
| 870 | fu.VlanPcp(1), |
| 871 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257), |
| 872 | }, |
| 873 | Actions: []*ofp.OfpAction{ |
| 874 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 875 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 876 | fu.Output(65536), |
| 877 | fu.PushVlan(0x8100), |
| 878 | }, |
| 879 | KV: kw, |
| 880 | } |
| 881 | |
| 882 | // HSIA |
| 883 | fa3 := &fu.FlowArgs{ |
| 884 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 885 | fu.InPort(536870912), |
| 886 | fu.Metadata_ofp(1), |
| 887 | //fu.EthType(0x8100), |
| 888 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 889 | }, |
| 890 | Actions: []*ofp.OfpAction{ |
| 891 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 892 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)), |
| 893 | fu.Output(65536), |
| 894 | fu.PushVlan(0x8100), |
| 895 | }, |
| 896 | KV: kw, |
| 897 | } |
| 898 | |
| 899 | fa4 := &fu.FlowArgs{ |
| 900 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 901 | fu.InPort(65535), |
| 902 | fu.Metadata_ofp(1), |
| 903 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 904 | fu.VlanPcp(1), |
| 905 | }, |
| 906 | Actions: []*ofp.OfpAction{ |
| 907 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 908 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)), |
| 909 | fu.Output(536870912), |
| 910 | fu.PopVlan(), |
| 911 | }, |
| 912 | KV: kw, |
| 913 | } |
| 914 | |
| 915 | classifierInfo := make(map[string]interface{}) |
| 916 | actionInfo := make(map[string]interface{}) |
| 917 | classifierInfo2 := make(map[string]interface{}) |
| 918 | actionInfo2 := make(map[string]interface{}) |
| 919 | classifierInfo3 := make(map[string]interface{}) |
| 920 | actionInfo3 := make(map[string]interface{}) |
| 921 | classifierInfo4 := make(map[string]interface{}) |
| 922 | actionInfo4 := make(map[string]interface{}) |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 923 | flowState, _ := fu.MkFlowStat(fa) |
| 924 | flowState2, _ := fu.MkFlowStat(fa2) |
| 925 | flowState3, _ := fu.MkFlowStat(fa3) |
| 926 | flowState4, _ := fu.MkFlowStat(fa4) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 927 | formulateClassifierInfoFromFlow(ctx, classifierInfo, flowState) |
| 928 | formulateClassifierInfoFromFlow(ctx, classifierInfo2, flowState2) |
| 929 | formulateClassifierInfoFromFlow(ctx, classifierInfo3, flowState3) |
| 930 | formulateClassifierInfoFromFlow(ctx, classifierInfo4, flowState4) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 931 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 932 | err := formulateActionInfoFromFlow(ctx, actionInfo, classifierInfo, flowState) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 933 | if err != nil { |
| 934 | // Error logging is already done in the called function |
| 935 | // So just return in case of error |
| 936 | return |
| 937 | } |
| 938 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 939 | err = formulateActionInfoFromFlow(ctx, actionInfo2, classifierInfo2, flowState2) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 940 | if err != nil { |
| 941 | // Error logging is already done in the called function |
| 942 | // So just return in case of error |
| 943 | return |
| 944 | } |
| 945 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 946 | err = formulateActionInfoFromFlow(ctx, actionInfo3, classifierInfo3, flowState3) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 947 | if err != nil { |
| 948 | // Error logging is already done in the called function |
| 949 | // So just return in case of error |
| 950 | return |
| 951 | } |
| 952 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 953 | err = formulateActionInfoFromFlow(ctx, actionInfo4, classifierInfo4, flowState4) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 954 | if err != nil { |
| 955 | // Error logging is already done in the called function |
| 956 | // So just return in case of error |
| 957 | return |
| 958 | } |
| 959 | |
| 960 | //ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1} |
| 961 | //flowMetadata := &voltha.FlowMetadata{ |
| 962 | // Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}, |
| 963 | //} |
| 964 | |
| 965 | TpInst := &tp.TechProfile{ |
| 966 | Name: "Test-Tech-Profile", |
| 967 | SubscriberIdentifier: "257", |
| 968 | ProfileType: "Mock", |
| 969 | Version: 1, |
| 970 | NumGemPorts: 4, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 971 | InstanceCtrl: tp.InstanceControl{ |
| 972 | Onu: "1", |
| 973 | Uni: "16", |
| 974 | }, |
| 975 | } |
| 976 | |
| 977 | type fields struct { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 978 | techprofile []tp.TechProfileIf |
| 979 | deviceHandler *DeviceHandler |
| 980 | resourceMgr *rsrcMgr.OpenOltResourceMgr |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 981 | } |
| 982 | type args struct { |
| 983 | args map[string]uint32 |
| 984 | classifierInfo map[string]interface{} |
| 985 | actionInfo map[string]interface{} |
| 986 | flow *ofp.OfpFlowStats |
| 987 | gemPort uint32 |
| 988 | intfID uint32 |
| 989 | onuID uint32 |
| 990 | uniID uint32 |
| 991 | portNo uint32 |
| 992 | TpInst *tp.TechProfile |
| 993 | allocID []uint32 |
| 994 | gemPorts []uint32 |
| 995 | TpID uint32 |
| 996 | uni string |
| 997 | } |
| 998 | tests := []struct { |
| 999 | name string |
| 1000 | fields fields |
| 1001 | args args |
| 1002 | }{ |
| 1003 | { |
| 1004 | name: "checkAndAddFlow-1", |
| 1005 | args: args{ |
| 1006 | args: nil, |
| 1007 | classifierInfo: classifierInfo, |
| 1008 | actionInfo: actionInfo, |
| 1009 | flow: flowState, |
| 1010 | gemPort: 1, |
| 1011 | intfID: 1, |
| 1012 | onuID: 1, |
| 1013 | uniID: 16, |
| 1014 | portNo: 1, |
| 1015 | TpInst: TpInst, |
| 1016 | allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004}, |
| 1017 | gemPorts: []uint32{1, 2, 3, 4}, |
| 1018 | TpID: 64, |
| 1019 | uni: "16", |
| 1020 | }, |
| 1021 | }, |
| 1022 | { |
| 1023 | name: "checkAndAddFlow-2", |
| 1024 | args: args{ |
| 1025 | args: nil, |
| 1026 | classifierInfo: classifierInfo2, |
| 1027 | actionInfo: actionInfo2, |
| 1028 | flow: flowState2, |
| 1029 | gemPort: 1, |
| 1030 | intfID: 1, |
| 1031 | onuID: 1, |
| 1032 | uniID: 16, |
| 1033 | portNo: 1, |
| 1034 | TpInst: TpInst, |
| 1035 | allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004}, |
| 1036 | gemPorts: []uint32{1, 2, 3, 4}, |
| 1037 | TpID: 64, |
| 1038 | uni: "16", |
| 1039 | }, |
| 1040 | }, |
| 1041 | { |
| 1042 | name: "checkAndAddFlow-3", |
| 1043 | args: args{ |
| 1044 | args: nil, |
| 1045 | classifierInfo: classifierInfo3, |
| 1046 | actionInfo: actionInfo3, |
| 1047 | flow: flowState3, |
| 1048 | gemPort: 1, |
| 1049 | intfID: 1, |
| 1050 | onuID: 1, |
| 1051 | uniID: 16, |
| 1052 | portNo: 1, |
| 1053 | TpInst: TpInst, |
| 1054 | allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004}, |
| 1055 | gemPorts: []uint32{1, 2, 3, 4}, |
| 1056 | TpID: 64, |
| 1057 | uni: "16", |
| 1058 | }, |
| 1059 | }, |
| 1060 | { |
| 1061 | name: "checkAndAddFlow-4", |
| 1062 | args: args{ |
| 1063 | args: nil, |
| 1064 | classifierInfo: classifierInfo4, |
| 1065 | actionInfo: actionInfo4, |
| 1066 | flow: flowState4, |
| 1067 | gemPort: 1, |
| 1068 | intfID: 1, |
| 1069 | onuID: 1, |
| 1070 | uniID: 16, |
| 1071 | portNo: 1, |
| 1072 | TpInst: TpInst, |
| 1073 | allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004}, |
| 1074 | gemPorts: []uint32{1, 2, 3, 4}, |
| 1075 | TpID: 64, |
| 1076 | uni: "16", |
| 1077 | }, |
| 1078 | }, |
| 1079 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1080 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1081 | defer cancel() |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1082 | for _, tt := range tests { |
| 1083 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1084 | flowMgr.checkAndAddFlow(ctx, tt.args.args, tt.args.classifierInfo, tt.args.actionInfo, tt.args.flow, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1085 | tt.args.TpInst, tt.args.gemPorts, tt.args.TpID, tt.args.uni) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1086 | }) |
| 1087 | } |
| 1088 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1089 | |
| 1090 | func TestOpenOltFlowMgr_TestMulticastFlow(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1091 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1092 | defer cancel() |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1093 | //create group |
| 1094 | group := newGroup(2, []uint32{1}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1095 | flowMgr.AddGroup(ctx, group) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1096 | |
| 1097 | //create multicast flow |
| 1098 | multicastFlowArgs := &fu.FlowArgs{ |
| 1099 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1100 | fu.InPort(65536), |
| 1101 | fu.VlanVid(660), //vlan |
| 1102 | fu.Metadata_ofp(uint64(66)), //inner vlan |
| 1103 | fu.EthType(0x800), //ipv4 |
| 1104 | fu.Ipv4Dst(3809869825), //227.22.0.1 |
| 1105 | }, |
| 1106 | Actions: []*ofp.OfpAction{ |
| 1107 | fu.Group(1), |
| 1108 | }, |
| 1109 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 1110 | ofpStats, _ := fu.MkFlowStat(multicastFlowArgs) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1111 | flowMgr.AddFlow(ctx, ofpStats, &voltha.FlowMetadata{}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1112 | |
| 1113 | //add bucket to the group |
| 1114 | group = newGroup(2, []uint32{1, 2}) |
| 1115 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1116 | flowMgr.ModifyGroup(ctx, group) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1117 | } |