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