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 | 60913ed | 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 | 60913ed | 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 | 60913ed | 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) { |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 275 | // flowMgr := newMockFlowmgr() |
Girish Kumar | 2ad402b | 2020-03-20 19:45:12 +0000 | [diff] [blame] | 276 | logger.Debug("Info Warning Error: Starting RemoveFlow() test") |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 277 | fa := &fu.FlowArgs{ |
| 278 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 279 | fu.InPort(2), |
| 280 | fu.Metadata_ofp(2), |
| 281 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 282 | }, |
| 283 | Actions: []*ofp.OfpAction{ |
| 284 | fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 285 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 286 | fu.Output(1), |
| 287 | }, |
| 288 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 289 | ofpstats, _ := fu.MkFlowStat(fa) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 290 | ofpstats.Cookie = ofpstats.Id |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 291 | lldpFa := &fu.FlowArgs{ |
| 292 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 293 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 294 | fu.InPort(1), |
| 295 | fu.EthType(0x88CC), |
| 296 | fu.TunnelId(536870912), |
| 297 | }, |
| 298 | Actions: []*ofp.OfpAction{ |
| 299 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 300 | }, |
| 301 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 302 | lldpofpstats, _ := fu.MkFlowStat(lldpFa) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 303 | //lldpofpstats.Cookie = lldpofpstats.Id |
| 304 | |
| 305 | dhcpFa := &fu.FlowArgs{ |
| 306 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 307 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 308 | fu.InPort(1), |
| 309 | fu.UdpSrc(67), |
| 310 | //fu.TunnelId(536870912), |
| 311 | fu.IpProto(17), |
| 312 | }, |
| 313 | Actions: []*ofp.OfpAction{ |
| 314 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 315 | }, |
| 316 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 317 | dhcpofpstats, _ := fu.MkFlowStat(dhcpFa) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 318 | //dhcpofpstats.Cookie = dhcpofpstats.Id |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 319 | |
| 320 | //multicast flow |
| 321 | multicastFa := &fu.FlowArgs{ |
| 322 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 323 | fu.InPort(65536), |
| 324 | fu.VlanVid(660), //vlan |
| 325 | fu.Metadata_ofp(uint64(66)), //inner vlan |
| 326 | fu.EthType(0x800), //ipv4 |
| 327 | fu.Ipv4Dst(3809869825), //227.22.0.1 |
| 328 | }, |
| 329 | Actions: []*ofp.OfpAction{ |
| 330 | fu.Group(1), |
| 331 | }, |
| 332 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 333 | multicastOfpStats, _ := fu.MkFlowStat(multicastFa) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 334 | multicastOfpStats.Id = 1 |
| 335 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 336 | type args struct { |
| 337 | flow *ofp.OfpFlowStats |
| 338 | } |
| 339 | tests := []struct { |
| 340 | name string |
| 341 | args args |
| 342 | }{ |
| 343 | // TODO: Add test cases. |
| 344 | {"RemoveFlow", args{flow: ofpstats}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 345 | {"RemoveFlow", args{flow: lldpofpstats}}, |
| 346 | {"RemoveFlow", args{flow: dhcpofpstats}}, |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 347 | {"RemoveFlow", args{flow: multicastOfpStats}}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 348 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 349 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 350 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 351 | for _, tt := range tests { |
| 352 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 353 | flowMgr.RemoveFlow(ctx, tt.args.flow) |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 354 | }) |
| 355 | } |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 356 | // t.Error("=====") |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | func TestOpenOltFlowMgr_AddFlow(t *testing.T) { |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 360 | // flowMgr := newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 361 | kw := make(map[string]uint64) |
| 362 | kw["table_id"] = 1 |
| 363 | kw["meter_id"] = 1 |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 364 | kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64 |
| 365 | |
| 366 | // Upstream flow |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 367 | fa := &fu.FlowArgs{ |
| 368 | MatchFields: []*ofp.OfpOxmOfbField{ |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 369 | fu.InPort(536870912), |
| 370 | fu.Metadata_ofp(1), |
| 371 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 372 | }, |
| 373 | Actions: []*ofp.OfpAction{ |
| 374 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 375 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 376 | fu.Output(65536), |
| 377 | fu.PushVlan(0x8100), |
| 378 | }, |
| 379 | KV: kw, |
| 380 | } |
| 381 | |
| 382 | // Downstream flow |
| 383 | fa3 := &fu.FlowArgs{ |
| 384 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 385 | fu.InPort(65536), |
| 386 | fu.Metadata_ofp(1), |
| 387 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257), |
| 388 | }, |
| 389 | Actions: []*ofp.OfpAction{ |
| 390 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 391 | //fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 392 | fu.PopVlan(), |
| 393 | fu.Output(536870912), |
| 394 | }, |
| 395 | KV: kw, |
| 396 | } |
| 397 | |
| 398 | fa2 := &fu.FlowArgs{ |
| 399 | MatchFields: []*ofp.OfpOxmOfbField{ |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 400 | fu.InPort(1000), |
| 401 | fu.Metadata_ofp(1), |
| 402 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 403 | }, |
| 404 | Actions: []*ofp.OfpAction{ |
| 405 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 406 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 407 | fu.Output(65533), |
| 408 | }, |
| 409 | KV: kw, |
| 410 | } |
| 411 | |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 412 | // TODO Add LLDP flow |
| 413 | // TODO Add DHCP flow |
| 414 | |
| 415 | // Flows for negative scenarios |
| 416 | // Failure in formulateActionInfoFromFlow() |
| 417 | fa4 := &fu.FlowArgs{ |
| 418 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 419 | fu.InPort(1000), |
| 420 | fu.Metadata_ofp(1), |
| 421 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 422 | }, |
| 423 | Actions: []*ofp.OfpAction{ |
| 424 | fu.Experimenter(257, []byte{1, 2, 3, 4}), |
| 425 | }, |
| 426 | KV: kw, |
| 427 | } |
| 428 | |
| 429 | // Invalid Output |
| 430 | fa5 := &fu.FlowArgs{ |
| 431 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 432 | fu.InPort(1000), |
| 433 | fu.Metadata_ofp(1), |
| 434 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 435 | }, |
| 436 | Actions: []*ofp.OfpAction{ |
| 437 | fu.Output(0), |
| 438 | }, |
| 439 | KV: kw, |
| 440 | } |
| 441 | |
| 442 | // Tech-Profile-ID update (not supported) |
| 443 | kw6 := make(map[string]uint64) |
| 444 | kw6["table_id"] = 1 |
| 445 | kw6["meter_id"] = 1 |
| 446 | kw6["write_metadata"] = 0x4100000000 // TpID Other than the stored one |
| 447 | fa6 := &fu.FlowArgs{ |
| 448 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 449 | fu.InPort(536870912), |
| 450 | fu.TunnelId(16), |
| 451 | fu.Metadata_ofp(1), |
| 452 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 453 | }, |
| 454 | Actions: []*ofp.OfpAction{ |
| 455 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 456 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 457 | fu.Output(65535), |
| 458 | }, |
| 459 | KV: kw6, |
| 460 | } |
| 461 | |
| 462 | lldpFa := &fu.FlowArgs{ |
| 463 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 464 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 465 | fu.InPort(1), |
| 466 | fu.EthType(0x88CC), |
| 467 | fu.TunnelId(536870912), |
| 468 | }, |
| 469 | Actions: []*ofp.OfpAction{ |
| 470 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 471 | }, |
| 472 | } |
| 473 | |
| 474 | dhcpFa := &fu.FlowArgs{ |
| 475 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 476 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 477 | fu.InPort(1), |
| 478 | fu.UdpSrc(67), |
| 479 | //fu.TunnelId(536870912), |
| 480 | fu.IpProto(17), |
| 481 | }, |
| 482 | Actions: []*ofp.OfpAction{ |
| 483 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 484 | }, |
| 485 | } |
| 486 | igmpFa := &fu.FlowArgs{ |
| 487 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 488 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 489 | fu.InPort(1), |
| 490 | fu.UdpSrc(67), |
| 491 | //fu.TunnelId(536870912), |
| 492 | fu.IpProto(2), |
| 493 | }, |
| 494 | Actions: []*ofp.OfpAction{ |
| 495 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 496 | }, |
| 497 | } |
| 498 | |
| 499 | fa9 := &fu.FlowArgs{ |
| 500 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 501 | fu.InPort(536870912), |
| 502 | fu.TunnelId(16), |
| 503 | fu.Metadata_ofp(1), |
| 504 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 505 | fu.VlanPcp(1000), |
| 506 | fu.UdpDst(65535), |
| 507 | fu.UdpSrc(536870912), |
| 508 | fu.Ipv4Dst(65535), |
| 509 | fu.Ipv4Src(536870912), |
| 510 | }, |
| 511 | Actions: []*ofp.OfpAction{ |
| 512 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 513 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 514 | fu.Output(65535), |
| 515 | }, |
| 516 | KV: kw6, |
| 517 | } |
| 518 | |
| 519 | fa10 := &fu.FlowArgs{ |
| 520 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 521 | fu.InPort(65533), |
| 522 | // fu.TunnelId(16), |
| 523 | fu.Metadata_ofp(1), |
| 524 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 525 | fu.VlanPcp(1000), |
| 526 | fu.UdpDst(65535), |
| 527 | fu.UdpSrc(536870912), |
| 528 | fu.Ipv4Dst(65535), |
| 529 | fu.Ipv4Src(536870912), |
| 530 | }, |
| 531 | Actions: []*ofp.OfpAction{ |
| 532 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 533 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 534 | fu.Output(65535), |
| 535 | }, |
| 536 | KV: kw6, |
| 537 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 538 | //multicast flow |
| 539 | fa11 := &fu.FlowArgs{ |
| 540 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 541 | fu.InPort(65536), |
| 542 | fu.VlanVid(660), //vlan |
| 543 | fu.Metadata_ofp(uint64(66)), //inner vlan |
| 544 | fu.EthType(0x800), //ipv4 |
| 545 | fu.Ipv4Dst(3809869825), //227.22.0.1 |
| 546 | }, |
| 547 | Actions: []*ofp.OfpAction{ |
| 548 | fu.Group(1), |
| 549 | }, |
| 550 | KV: kw6, |
| 551 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 552 | ofpstats, _ := fu.MkFlowStat(fa) |
| 553 | ofpstats2, _ := fu.MkFlowStat(fa2) |
| 554 | ofpstats3, _ := fu.MkFlowStat(fa3) |
| 555 | ofpstats4, _ := fu.MkFlowStat(fa4) |
| 556 | ofpstats5, _ := fu.MkFlowStat(fa5) |
| 557 | ofpstats6, _ := fu.MkFlowStat(fa6) |
| 558 | ofpstats7, _ := fu.MkFlowStat(lldpFa) |
| 559 | ofpstats8, _ := fu.MkFlowStat(dhcpFa) |
| 560 | ofpstats9, _ := fu.MkFlowStat(fa9) |
| 561 | ofpstats10, _ := fu.MkFlowStat(fa10) |
| 562 | igmpstats, _ := fu.MkFlowStat(igmpFa) |
| 563 | ofpstats11, _ := fu.MkFlowStat(fa11) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 564 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 565 | fmt.Println(ofpstats6, ofpstats9, ofpstats10) |
| 566 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 567 | ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1} |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 568 | flowMetadata := &voltha.FlowMetadata{ |
| 569 | Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}, |
| 570 | } |
| 571 | type args struct { |
| 572 | flow *ofp.OfpFlowStats |
| 573 | flowMetadata *voltha.FlowMetadata |
| 574 | } |
| 575 | tests := []struct { |
| 576 | name string |
| 577 | args args |
| 578 | }{ |
| 579 | // TODO: Add test cases. |
| 580 | {"AddFlow", args{flow: ofpstats, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 581 | {"AddFlow", args{flow: ofpstats2, flowMetadata: flowMetadata}}, |
| 582 | {"AddFlow", args{flow: ofpstats3, flowMetadata: flowMetadata}}, |
| 583 | {"AddFlow", args{flow: ofpstats4, flowMetadata: flowMetadata}}, |
| 584 | {"AddFlow", args{flow: ofpstats5, flowMetadata: flowMetadata}}, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 585 | //{"AddFlow", args{flow: ofpstats6, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 586 | {"AddFlow", args{flow: ofpstats7, flowMetadata: flowMetadata}}, |
| 587 | {"AddFlow", args{flow: ofpstats8, flowMetadata: flowMetadata}}, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 588 | //{"AddFlow", args{flow: ofpstats9, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 589 | {"AddFlow", args{flow: igmpstats, flowMetadata: flowMetadata}}, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 590 | //{"AddFlow", args{flow: ofpstats10, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 591 | //ofpstats10 |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 592 | {"AddFlow", args{flow: ofpstats11, flowMetadata: flowMetadata}}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 593 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 594 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 595 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 596 | for _, tt := range tests { |
| 597 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 598 | flowMgr.AddFlow(ctx, tt.args.flow, tt.args.flowMetadata) |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 599 | }) |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | func TestOpenOltFlowMgr_UpdateOnuInfo(t *testing.T) { |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 604 | flwMgr := newMockFlowmgr() |
| 605 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 606 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 607 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 608 | |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 609 | wg := sync.WaitGroup{} |
| 610 | |
| 611 | intfCount := 16 |
| 612 | onuCount := 32 |
| 613 | |
| 614 | for i := 0; i < intfCount; i++ { |
| 615 | for j := 0; j < onuCount; j++ { |
| 616 | wg.Add(1) |
| 617 | go func(i uint32, j uint32) { |
| 618 | flwMgr.UpdateOnuInfo(ctx, i, i, fmt.Sprintf("onu-%d", i)) |
| 619 | wg.Done() |
| 620 | }(uint32(i), uint32(j)) |
| 621 | } |
| 622 | |
| 623 | } |
| 624 | |
| 625 | wg.Wait() |
| 626 | } |
| 627 | |
| 628 | func TestOpenOltFlowMgr_addGemPortToOnuInfoMap(t *testing.T) { |
| 629 | flowMgr = newMockFlowmgr() |
| 630 | intfNum := 16 |
| 631 | onuNum := 32 |
| 632 | |
| 633 | // clean the flowMgr |
| 634 | flowMgr.onuGemInfo = make(map[uint32][]rsrcMgr.OnuGemInfo, intfNum) |
| 635 | |
| 636 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 637 | defer cancel() |
| 638 | |
| 639 | // Create OnuInfo |
| 640 | for i := 0; i < intfNum; i++ { |
| 641 | for o := 0; o < onuNum; o++ { |
| 642 | flowMgr.UpdateOnuInfo(ctx, uint32(i), uint32(o), fmt.Sprintf("i%do%d", i, o)) |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | // Add gemPorts to OnuInfo in parallel threads |
| 647 | wg := sync.WaitGroup{} |
| 648 | |
| 649 | for o := 0; o < onuNum; o++ { |
| 650 | for i := 0; i < intfNum; i++ { |
| 651 | wg.Add(1) |
| 652 | go func(intfId uint32, onuId uint32) { |
| 653 | gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", intfId, onuId)) |
| 654 | |
| 655 | flowMgr.addGemPortToOnuInfoMap(ctx, intfId, onuId, uint32(gemID)) |
| 656 | wg.Done() |
| 657 | }(uint32(i), uint32(o)) |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | wg.Wait() |
| 662 | |
| 663 | // check that each entry of onuGemInfo has the correct number of ONUs |
| 664 | for i := 0; i < intfNum; i++ { |
| 665 | lenofOnu := len(flowMgr.onuGemInfo[uint32(i)]) |
| 666 | if onuNum != lenofOnu { |
| 667 | t.Errorf("OnuGemInfo length is not as expected len = %d, want %d", lenofOnu, onuNum) |
| 668 | } |
| 669 | |
| 670 | for o := 0; o < onuNum; o++ { |
| 671 | lenOfGemPorts := len(flowMgr.onuGemInfo[uint32(i)][o].GemPorts) |
| 672 | // check that each onuEntry has 1 gemPort |
| 673 | if lenOfGemPorts != 1 { |
| 674 | t.Errorf("Expected 1 GemPort per ONU, found %d", lenOfGemPorts) |
| 675 | } |
| 676 | |
| 677 | // check that the value of the gemport is correct |
| 678 | gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", i, o)) |
| 679 | currentValue := flowMgr.onuGemInfo[uint32(i)][o].GemPorts[0] |
| 680 | if uint32(gemID) != currentValue { |
| 681 | t.Errorf("Expected GemPort value to be %d, found %d", gemID, currentValue) |
| 682 | } |
| 683 | } |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 684 | } |
| 685 | } |
| 686 | |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 687 | func TestOpenOltFlowMgr_deleteGemPortFromLocalCache(t *testing.T) { |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 688 | flwMgr := newMockFlowmgr() |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 689 | type args struct { |
| 690 | intfID uint32 |
| 691 | onuID uint32 |
| 692 | gemPortIDs []uint32 |
| 693 | gemPortIDsToBeDeleted []uint32 |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 694 | gemPortIDsRemaining []uint32 |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 695 | serialNum string |
| 696 | finalLength int |
| 697 | } |
| 698 | tests := []struct { |
| 699 | name string |
| 700 | args args |
| 701 | }{ |
| 702 | // Add/Delete single gem port |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 703 | {"DeleteGemPortFromLocalCache1", args{0, 1, []uint32{1}, []uint32{1}, []uint32{}, "onu1", 0}}, |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 704 | // Delete all gemports |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 705 | {"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] | 706 | // Try to delete when there is no gem port |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 707 | {"DeleteGemPortFromLocalCache3", args{0, 1, []uint32{}, []uint32{1, 2}, []uint32{}, "onu1", 0}}, |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 708 | // Try to delete non-existent gem port |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 709 | {"DeleteGemPortFromLocalCache4", args{0, 1, []uint32{1}, []uint32{2}, []uint32{1}, "onu1", 1}}, |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 710 | // Try to delete two of the gem ports |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 711 | {"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] | 712 | } |
| 713 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 714 | defer cancel() |
| 715 | for _, tt := range tests { |
| 716 | t.Run(tt.name, func(t *testing.T) { |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 717 | flwMgr.UpdateOnuInfo(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum) |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 718 | for _, gemPort := range tt.args.gemPortIDs { |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 719 | flwMgr.addGemPortToOnuInfoMap(ctx, tt.args.intfID, tt.args.onuID, gemPort) |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 720 | } |
| 721 | for _, gemPortDeleted := range tt.args.gemPortIDsToBeDeleted { |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 722 | flwMgr.deleteGemPortFromLocalCache(tt.args.intfID, tt.args.onuID, gemPortDeleted) |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 723 | } |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 724 | lenofGemPorts := len(flwMgr.onuGemInfo[tt.args.intfID][0].GemPorts) |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 725 | if lenofGemPorts != tt.args.finalLength { |
| 726 | t.Errorf("GemPorts length is not as expected len = %d, want %d", lenofGemPorts, tt.args.finalLength) |
| 727 | } |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 728 | gemPorts := flwMgr.onuGemInfo[tt.args.intfID][0].GemPorts |
| 729 | if !reflect.DeepEqual(tt.args.gemPortIDsRemaining, gemPorts) { |
| 730 | t.Errorf("GemPorts are not as expected = %v, want %v", gemPorts, tt.args.gemPortIDsRemaining) |
| 731 | } |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 732 | |
| 733 | }) |
| 734 | } |
| 735 | } |
| 736 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 737 | func TestOpenOltFlowMgr_GetLogicalPortFromPacketIn(t *testing.T) { |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 738 | flwMgr := newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 739 | type args struct { |
| 740 | packetIn *openoltpb2.PacketIndication |
| 741 | } |
| 742 | tests := []struct { |
| 743 | name string |
| 744 | args args |
| 745 | want uint32 |
| 746 | wantErr bool |
| 747 | }{ |
| 748 | // TODO: Add test cases. |
| 749 | {"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] | 750 | {"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] | 751 | // Negative Test cases. |
| 752 | {"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] | 753 | {"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] | 754 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 755 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 756 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 757 | for _, tt := range tests { |
| 758 | t.Run(tt.name, func(t *testing.T) { |
| 759 | |
Matteo Scandolo | 60913ed | 2020-06-23 19:31:14 -0700 | [diff] [blame^] | 760 | got, err := flwMgr.GetLogicalPortFromPacketIn(ctx, tt.args.packetIn) |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 761 | if (err != nil) != tt.wantErr { |
| 762 | t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() error = %v, wantErr %v", err, tt.wantErr) |
| 763 | return |
| 764 | } |
| 765 | if got != tt.want { |
| 766 | t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() = %v, want %v", got, tt.want) |
| 767 | } |
| 768 | }) |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | func TestOpenOltFlowMgr_GetPacketOutGemPortID(t *testing.T) { |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 773 | // flwMgr := newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 774 | |
| 775 | type args struct { |
| 776 | intfID uint32 |
| 777 | onuID uint32 |
| 778 | portNum uint32 |
| 779 | } |
| 780 | tests := []struct { |
| 781 | name string |
| 782 | args args |
| 783 | want uint32 |
| 784 | wantErr bool |
| 785 | }{ |
| 786 | // TODO: Add test cases. |
| 787 | {"GetPacketOutGemPortID", args{intfID: 1, onuID: 1, portNum: 1}, 1, false}, |
| 788 | {"GetPacketOutGemPortID", args{intfID: 2, onuID: 2, portNum: 2}, 2, false}, |
| 789 | {"GetPacketOutGemPortID", args{intfID: 1, onuID: 2, portNum: 2}, 0, true}, |
| 790 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 791 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 792 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 793 | for _, tt := range tests { |
| 794 | t.Run(tt.name, func(t *testing.T) { |
| 795 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 796 | 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] | 797 | if (err != nil) != tt.wantErr { |
| 798 | t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() error = %v, wantErr %v", err, tt.wantErr) |
| 799 | return |
| 800 | } |
| 801 | if got != tt.want { |
| 802 | t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, want %v", got, tt.want) |
| 803 | } |
| 804 | |
| 805 | }) |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | func TestOpenOltFlowMgr_DeleteTechProfileInstance(t *testing.T) { |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 810 | // flwMgr := newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 811 | type args struct { |
| 812 | intfID uint32 |
| 813 | onuID uint32 |
| 814 | uniID uint32 |
| 815 | sn string |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 816 | tpID uint32 |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 817 | } |
| 818 | tests := []struct { |
| 819 | name string |
| 820 | args args |
| 821 | wantErr bool |
| 822 | }{ |
| 823 | // TODO: Add test cases. |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 824 | {"DeleteTechProfileInstance", args{intfID: 0, onuID: 1, uniID: 1, sn: "", tpID: 64}, false}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 825 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 826 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 827 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 828 | for _, tt := range tests { |
| 829 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 830 | 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] | 831 | t.Errorf("OpenOltFlowMgr.DeleteTechProfileInstance() error = %v, wantErr %v", err, tt.wantErr) |
| 832 | } |
| 833 | }) |
| 834 | } |
| 835 | } |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 836 | |
| 837 | func TestOpenOltFlowMgr_checkAndAddFlow(t *testing.T) { |
| 838 | // flowMgr := newMockFlowmgr() |
| 839 | kw := make(map[string]uint64) |
| 840 | kw["table_id"] = 1 |
| 841 | kw["meter_id"] = 1 |
| 842 | kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64 |
| 843 | |
| 844 | // Upstream flow |
| 845 | fa := &fu.FlowArgs{ |
| 846 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 847 | fu.InPort(536870912), |
| 848 | fu.Metadata_ofp(1), |
| 849 | fu.IpProto(17), // dhcp |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 850 | fu.VlanPcp(0), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 851 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 852 | }, |
| 853 | Actions: []*ofp.OfpAction{ |
| 854 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 855 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 856 | fu.Output(65536), |
| 857 | fu.PushVlan(0x8100), |
| 858 | }, |
| 859 | KV: kw, |
| 860 | } |
| 861 | |
| 862 | // EAPOL |
| 863 | fa2 := &fu.FlowArgs{ |
| 864 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 865 | fu.InPort(536870912), |
| 866 | fu.Metadata_ofp(1), |
| 867 | fu.EthType(0x888E), |
| 868 | fu.VlanPcp(1), |
| 869 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257), |
| 870 | }, |
| 871 | Actions: []*ofp.OfpAction{ |
| 872 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 873 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 874 | fu.Output(65536), |
| 875 | fu.PushVlan(0x8100), |
| 876 | }, |
| 877 | KV: kw, |
| 878 | } |
| 879 | |
| 880 | // HSIA |
| 881 | fa3 := &fu.FlowArgs{ |
| 882 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 883 | fu.InPort(536870912), |
| 884 | fu.Metadata_ofp(1), |
| 885 | //fu.EthType(0x8100), |
| 886 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 887 | }, |
| 888 | Actions: []*ofp.OfpAction{ |
| 889 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 890 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)), |
| 891 | fu.Output(65536), |
| 892 | fu.PushVlan(0x8100), |
| 893 | }, |
| 894 | KV: kw, |
| 895 | } |
| 896 | |
| 897 | fa4 := &fu.FlowArgs{ |
| 898 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 899 | fu.InPort(65535), |
| 900 | fu.Metadata_ofp(1), |
| 901 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 902 | fu.VlanPcp(1), |
| 903 | }, |
| 904 | Actions: []*ofp.OfpAction{ |
| 905 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 906 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)), |
| 907 | fu.Output(536870912), |
| 908 | fu.PopVlan(), |
| 909 | }, |
| 910 | KV: kw, |
| 911 | } |
| 912 | |
| 913 | classifierInfo := make(map[string]interface{}) |
| 914 | actionInfo := make(map[string]interface{}) |
| 915 | classifierInfo2 := make(map[string]interface{}) |
| 916 | actionInfo2 := make(map[string]interface{}) |
| 917 | classifierInfo3 := make(map[string]interface{}) |
| 918 | actionInfo3 := make(map[string]interface{}) |
| 919 | classifierInfo4 := make(map[string]interface{}) |
| 920 | actionInfo4 := make(map[string]interface{}) |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 921 | flowState, _ := fu.MkFlowStat(fa) |
| 922 | flowState2, _ := fu.MkFlowStat(fa2) |
| 923 | flowState3, _ := fu.MkFlowStat(fa3) |
| 924 | flowState4, _ := fu.MkFlowStat(fa4) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 925 | formulateClassifierInfoFromFlow(classifierInfo, flowState) |
| 926 | formulateClassifierInfoFromFlow(classifierInfo2, flowState2) |
| 927 | formulateClassifierInfoFromFlow(classifierInfo3, flowState3) |
| 928 | formulateClassifierInfoFromFlow(classifierInfo4, flowState4) |
| 929 | |
| 930 | err := formulateActionInfoFromFlow(actionInfo, classifierInfo, flowState) |
| 931 | 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 | |
| 937 | err = formulateActionInfoFromFlow(actionInfo2, classifierInfo2, flowState2) |
| 938 | 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 | |
| 944 | err = formulateActionInfoFromFlow(actionInfo3, classifierInfo3, flowState3) |
| 945 | 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 | |
| 951 | err = formulateActionInfoFromFlow(actionInfo4, classifierInfo4, flowState4) |
| 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 | } |
| 957 | |
| 958 | //ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1} |
| 959 | //flowMetadata := &voltha.FlowMetadata{ |
| 960 | // Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}, |
| 961 | //} |
| 962 | |
| 963 | TpInst := &tp.TechProfile{ |
| 964 | Name: "Test-Tech-Profile", |
| 965 | SubscriberIdentifier: "257", |
| 966 | ProfileType: "Mock", |
| 967 | Version: 1, |
| 968 | NumGemPorts: 4, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 969 | InstanceCtrl: tp.InstanceControl{ |
| 970 | Onu: "1", |
| 971 | Uni: "16", |
| 972 | }, |
| 973 | } |
| 974 | |
| 975 | type fields struct { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 976 | techprofile []tp.TechProfileIf |
| 977 | deviceHandler *DeviceHandler |
| 978 | resourceMgr *rsrcMgr.OpenOltResourceMgr |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 979 | } |
| 980 | type args struct { |
| 981 | args map[string]uint32 |
| 982 | classifierInfo map[string]interface{} |
| 983 | actionInfo map[string]interface{} |
| 984 | flow *ofp.OfpFlowStats |
| 985 | gemPort uint32 |
| 986 | intfID uint32 |
| 987 | onuID uint32 |
| 988 | uniID uint32 |
| 989 | portNo uint32 |
| 990 | TpInst *tp.TechProfile |
| 991 | allocID []uint32 |
| 992 | gemPorts []uint32 |
| 993 | TpID uint32 |
| 994 | uni string |
| 995 | } |
| 996 | tests := []struct { |
| 997 | name string |
| 998 | fields fields |
| 999 | args args |
| 1000 | }{ |
| 1001 | { |
| 1002 | name: "checkAndAddFlow-1", |
| 1003 | args: args{ |
| 1004 | args: nil, |
| 1005 | classifierInfo: classifierInfo, |
| 1006 | actionInfo: actionInfo, |
| 1007 | flow: flowState, |
| 1008 | gemPort: 1, |
| 1009 | intfID: 1, |
| 1010 | onuID: 1, |
| 1011 | uniID: 16, |
| 1012 | portNo: 1, |
| 1013 | TpInst: TpInst, |
| 1014 | allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004}, |
| 1015 | gemPorts: []uint32{1, 2, 3, 4}, |
| 1016 | TpID: 64, |
| 1017 | uni: "16", |
| 1018 | }, |
| 1019 | }, |
| 1020 | { |
| 1021 | name: "checkAndAddFlow-2", |
| 1022 | args: args{ |
| 1023 | args: nil, |
| 1024 | classifierInfo: classifierInfo2, |
| 1025 | actionInfo: actionInfo2, |
| 1026 | flow: flowState2, |
| 1027 | gemPort: 1, |
| 1028 | intfID: 1, |
| 1029 | onuID: 1, |
| 1030 | uniID: 16, |
| 1031 | portNo: 1, |
| 1032 | TpInst: TpInst, |
| 1033 | allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004}, |
| 1034 | gemPorts: []uint32{1, 2, 3, 4}, |
| 1035 | TpID: 64, |
| 1036 | uni: "16", |
| 1037 | }, |
| 1038 | }, |
| 1039 | { |
| 1040 | name: "checkAndAddFlow-3", |
| 1041 | args: args{ |
| 1042 | args: nil, |
| 1043 | classifierInfo: classifierInfo3, |
| 1044 | actionInfo: actionInfo3, |
| 1045 | flow: flowState3, |
| 1046 | gemPort: 1, |
| 1047 | intfID: 1, |
| 1048 | onuID: 1, |
| 1049 | uniID: 16, |
| 1050 | portNo: 1, |
| 1051 | TpInst: TpInst, |
| 1052 | allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004}, |
| 1053 | gemPorts: []uint32{1, 2, 3, 4}, |
| 1054 | TpID: 64, |
| 1055 | uni: "16", |
| 1056 | }, |
| 1057 | }, |
| 1058 | { |
| 1059 | name: "checkAndAddFlow-4", |
| 1060 | args: args{ |
| 1061 | args: nil, |
| 1062 | classifierInfo: classifierInfo4, |
| 1063 | actionInfo: actionInfo4, |
| 1064 | flow: flowState4, |
| 1065 | gemPort: 1, |
| 1066 | intfID: 1, |
| 1067 | onuID: 1, |
| 1068 | uniID: 16, |
| 1069 | portNo: 1, |
| 1070 | TpInst: TpInst, |
| 1071 | allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004}, |
| 1072 | gemPorts: []uint32{1, 2, 3, 4}, |
| 1073 | TpID: 64, |
| 1074 | uni: "16", |
| 1075 | }, |
| 1076 | }, |
| 1077 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1078 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1079 | defer cancel() |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1080 | for _, tt := range tests { |
| 1081 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1082 | 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] | 1083 | tt.args.TpInst, tt.args.gemPorts, tt.args.TpID, tt.args.uni) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1084 | }) |
| 1085 | } |
| 1086 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1087 | |
| 1088 | func TestOpenOltFlowMgr_TestMulticastFlow(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1089 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1090 | defer cancel() |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1091 | //create group |
| 1092 | group := newGroup(2, []uint32{1}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1093 | flowMgr.AddGroup(ctx, group) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1094 | |
| 1095 | //create multicast flow |
| 1096 | multicastFlowArgs := &fu.FlowArgs{ |
| 1097 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1098 | fu.InPort(65536), |
| 1099 | fu.VlanVid(660), //vlan |
| 1100 | fu.Metadata_ofp(uint64(66)), //inner vlan |
| 1101 | fu.EthType(0x800), //ipv4 |
| 1102 | fu.Ipv4Dst(3809869825), //227.22.0.1 |
| 1103 | }, |
| 1104 | Actions: []*ofp.OfpAction{ |
| 1105 | fu.Group(1), |
| 1106 | }, |
| 1107 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 1108 | ofpStats, _ := fu.MkFlowStat(multicastFlowArgs) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1109 | flowMgr.AddFlow(ctx, ofpStats, &voltha.FlowMetadata{}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1110 | |
| 1111 | //add bucket to the group |
| 1112 | group = newGroup(2, []uint32{1, 2}) |
| 1113 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1114 | flowMgr.ModifyGroup(ctx, group) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1115 | } |