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 | |
| 17 | //Package adaptercore provides the utility for olt devices, flows and statistics |
| 18 | package adaptercore |
| 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" |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 32 | "github.com/opencord/voltha-openolt-adapter/adaptercore/resourcemanager" |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 33 | rsrcMgr "github.com/opencord/voltha-openolt-adapter/adaptercore/resourcemanager" |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 34 | "github.com/opencord/voltha-openolt-adapter/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 | |
| 219 | func TestOpenOltFlowMgr_RemoveFlow(t *testing.T) { |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 220 | // flowMgr := newMockFlowmgr() |
| 221 | log.Debug("Info Warning Error: Starting RemoveFlow() test") |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 222 | fa := &fu.FlowArgs{ |
| 223 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 224 | fu.InPort(2), |
| 225 | fu.Metadata_ofp(2), |
| 226 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 227 | }, |
| 228 | Actions: []*ofp.OfpAction{ |
| 229 | fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 230 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 231 | fu.Output(1), |
| 232 | }, |
| 233 | } |
| 234 | ofpstats := fu.MkFlowStat(fa) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 235 | ofpstats.Cookie = ofpstats.Id |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 236 | lldpFa := &fu.FlowArgs{ |
| 237 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 238 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 239 | fu.InPort(1), |
| 240 | fu.EthType(0x88CC), |
| 241 | fu.TunnelId(536870912), |
| 242 | }, |
| 243 | Actions: []*ofp.OfpAction{ |
| 244 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 245 | }, |
| 246 | } |
| 247 | lldpofpstats := fu.MkFlowStat(lldpFa) |
| 248 | //lldpofpstats.Cookie = lldpofpstats.Id |
| 249 | |
| 250 | dhcpFa := &fu.FlowArgs{ |
| 251 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 252 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 253 | fu.InPort(1), |
| 254 | fu.UdpSrc(67), |
| 255 | //fu.TunnelId(536870912), |
| 256 | fu.IpProto(17), |
| 257 | }, |
| 258 | Actions: []*ofp.OfpAction{ |
| 259 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 260 | }, |
| 261 | } |
| 262 | dhcpofpstats := fu.MkFlowStat(dhcpFa) |
| 263 | //dhcpofpstats.Cookie = dhcpofpstats.Id |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 264 | |
| 265 | //multicast flow |
| 266 | multicastFa := &fu.FlowArgs{ |
| 267 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 268 | fu.InPort(65536), |
| 269 | fu.VlanVid(660), //vlan |
| 270 | fu.Metadata_ofp(uint64(66)), //inner vlan |
| 271 | fu.EthType(0x800), //ipv4 |
| 272 | fu.Ipv4Dst(3809869825), //227.22.0.1 |
| 273 | }, |
| 274 | Actions: []*ofp.OfpAction{ |
| 275 | fu.Group(1), |
| 276 | }, |
| 277 | } |
| 278 | multicastOfpStats := fu.MkFlowStat(multicastFa) |
| 279 | multicastOfpStats.Id = 1 |
| 280 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 281 | type args struct { |
| 282 | flow *ofp.OfpFlowStats |
| 283 | } |
| 284 | tests := []struct { |
| 285 | name string |
| 286 | args args |
| 287 | }{ |
| 288 | // TODO: Add test cases. |
| 289 | {"RemoveFlow", args{flow: ofpstats}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 290 | {"RemoveFlow", args{flow: lldpofpstats}}, |
| 291 | {"RemoveFlow", args{flow: dhcpofpstats}}, |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 292 | {"RemoveFlow", args{flow: multicastOfpStats}}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 293 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 294 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 295 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 296 | for _, tt := range tests { |
| 297 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 298 | flowMgr.RemoveFlow(ctx, tt.args.flow) |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 299 | }) |
| 300 | } |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 301 | // t.Error("=====") |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | func TestOpenOltFlowMgr_AddFlow(t *testing.T) { |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 305 | // flowMgr := newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 306 | kw := make(map[string]uint64) |
| 307 | kw["table_id"] = 1 |
| 308 | kw["meter_id"] = 1 |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 309 | kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64 |
| 310 | |
| 311 | // Upstream flow |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 312 | fa := &fu.FlowArgs{ |
| 313 | MatchFields: []*ofp.OfpOxmOfbField{ |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 314 | fu.InPort(536870912), |
| 315 | fu.Metadata_ofp(1), |
| 316 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 317 | }, |
| 318 | Actions: []*ofp.OfpAction{ |
| 319 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 320 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 321 | fu.Output(65536), |
| 322 | fu.PushVlan(0x8100), |
| 323 | }, |
| 324 | KV: kw, |
| 325 | } |
| 326 | |
| 327 | // Downstream flow |
| 328 | fa3 := &fu.FlowArgs{ |
| 329 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 330 | fu.InPort(65536), |
| 331 | fu.Metadata_ofp(1), |
| 332 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257), |
| 333 | }, |
| 334 | Actions: []*ofp.OfpAction{ |
| 335 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 336 | //fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 337 | fu.PopVlan(), |
| 338 | fu.Output(536870912), |
| 339 | }, |
| 340 | KV: kw, |
| 341 | } |
| 342 | |
| 343 | fa2 := &fu.FlowArgs{ |
| 344 | MatchFields: []*ofp.OfpOxmOfbField{ |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 345 | fu.InPort(1000), |
| 346 | fu.Metadata_ofp(1), |
| 347 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 348 | }, |
| 349 | Actions: []*ofp.OfpAction{ |
| 350 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 351 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 352 | fu.Output(65533), |
| 353 | }, |
| 354 | KV: kw, |
| 355 | } |
| 356 | |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 357 | // TODO Add LLDP flow |
| 358 | // TODO Add DHCP flow |
| 359 | |
| 360 | // Flows for negative scenarios |
| 361 | // Failure in formulateActionInfoFromFlow() |
| 362 | fa4 := &fu.FlowArgs{ |
| 363 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 364 | fu.InPort(1000), |
| 365 | fu.Metadata_ofp(1), |
| 366 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 367 | }, |
| 368 | Actions: []*ofp.OfpAction{ |
| 369 | fu.Experimenter(257, []byte{1, 2, 3, 4}), |
| 370 | }, |
| 371 | KV: kw, |
| 372 | } |
| 373 | |
| 374 | // Invalid Output |
| 375 | fa5 := &fu.FlowArgs{ |
| 376 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 377 | fu.InPort(1000), |
| 378 | fu.Metadata_ofp(1), |
| 379 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 380 | }, |
| 381 | Actions: []*ofp.OfpAction{ |
| 382 | fu.Output(0), |
| 383 | }, |
| 384 | KV: kw, |
| 385 | } |
| 386 | |
| 387 | // Tech-Profile-ID update (not supported) |
| 388 | kw6 := make(map[string]uint64) |
| 389 | kw6["table_id"] = 1 |
| 390 | kw6["meter_id"] = 1 |
| 391 | kw6["write_metadata"] = 0x4100000000 // TpID Other than the stored one |
| 392 | fa6 := &fu.FlowArgs{ |
| 393 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 394 | fu.InPort(536870912), |
| 395 | fu.TunnelId(16), |
| 396 | fu.Metadata_ofp(1), |
| 397 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 398 | }, |
| 399 | Actions: []*ofp.OfpAction{ |
| 400 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 401 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 402 | fu.Output(65535), |
| 403 | }, |
| 404 | KV: kw6, |
| 405 | } |
| 406 | |
| 407 | lldpFa := &fu.FlowArgs{ |
| 408 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 409 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 410 | fu.InPort(1), |
| 411 | fu.EthType(0x88CC), |
| 412 | fu.TunnelId(536870912), |
| 413 | }, |
| 414 | Actions: []*ofp.OfpAction{ |
| 415 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 416 | }, |
| 417 | } |
| 418 | |
| 419 | dhcpFa := &fu.FlowArgs{ |
| 420 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 421 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 422 | fu.InPort(1), |
| 423 | fu.UdpSrc(67), |
| 424 | //fu.TunnelId(536870912), |
| 425 | fu.IpProto(17), |
| 426 | }, |
| 427 | Actions: []*ofp.OfpAction{ |
| 428 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 429 | }, |
| 430 | } |
| 431 | igmpFa := &fu.FlowArgs{ |
| 432 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 433 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 434 | fu.InPort(1), |
| 435 | fu.UdpSrc(67), |
| 436 | //fu.TunnelId(536870912), |
| 437 | fu.IpProto(2), |
| 438 | }, |
| 439 | Actions: []*ofp.OfpAction{ |
| 440 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 441 | }, |
| 442 | } |
| 443 | |
| 444 | fa9 := &fu.FlowArgs{ |
| 445 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 446 | fu.InPort(536870912), |
| 447 | fu.TunnelId(16), |
| 448 | fu.Metadata_ofp(1), |
| 449 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 450 | fu.VlanPcp(1000), |
| 451 | fu.UdpDst(65535), |
| 452 | fu.UdpSrc(536870912), |
| 453 | fu.Ipv4Dst(65535), |
| 454 | fu.Ipv4Src(536870912), |
| 455 | }, |
| 456 | Actions: []*ofp.OfpAction{ |
| 457 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 458 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 459 | fu.Output(65535), |
| 460 | }, |
| 461 | KV: kw6, |
| 462 | } |
| 463 | |
| 464 | fa10 := &fu.FlowArgs{ |
| 465 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 466 | fu.InPort(65533), |
| 467 | // fu.TunnelId(16), |
| 468 | fu.Metadata_ofp(1), |
| 469 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 470 | fu.VlanPcp(1000), |
| 471 | fu.UdpDst(65535), |
| 472 | fu.UdpSrc(536870912), |
| 473 | fu.Ipv4Dst(65535), |
| 474 | fu.Ipv4Src(536870912), |
| 475 | }, |
| 476 | Actions: []*ofp.OfpAction{ |
| 477 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 478 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 479 | fu.Output(65535), |
| 480 | }, |
| 481 | KV: kw6, |
| 482 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 483 | //multicast flow |
| 484 | fa11 := &fu.FlowArgs{ |
| 485 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 486 | fu.InPort(65536), |
| 487 | fu.VlanVid(660), //vlan |
| 488 | fu.Metadata_ofp(uint64(66)), //inner vlan |
| 489 | fu.EthType(0x800), //ipv4 |
| 490 | fu.Ipv4Dst(3809869825), //227.22.0.1 |
| 491 | }, |
| 492 | Actions: []*ofp.OfpAction{ |
| 493 | fu.Group(1), |
| 494 | }, |
| 495 | KV: kw6, |
| 496 | } |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 497 | ofpstats := fu.MkFlowStat(fa) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 498 | ofpstats2 := fu.MkFlowStat(fa2) |
| 499 | ofpstats3 := fu.MkFlowStat(fa3) |
| 500 | ofpstats4 := fu.MkFlowStat(fa4) |
| 501 | ofpstats5 := fu.MkFlowStat(fa5) |
| 502 | ofpstats6 := fu.MkFlowStat(fa6) |
| 503 | ofpstats7 := fu.MkFlowStat(lldpFa) |
| 504 | ofpstats8 := fu.MkFlowStat(dhcpFa) |
| 505 | ofpstats9 := fu.MkFlowStat(fa9) |
| 506 | ofpstats10 := fu.MkFlowStat(fa10) |
| 507 | igmpstats := fu.MkFlowStat(igmpFa) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 508 | ofpstats11 := fu.MkFlowStat(fa11) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 509 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 510 | fmt.Println(ofpstats6, ofpstats9, ofpstats10) |
| 511 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 512 | ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1} |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 513 | flowMetadata := &voltha.FlowMetadata{ |
| 514 | Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}, |
| 515 | } |
| 516 | type args struct { |
| 517 | flow *ofp.OfpFlowStats |
| 518 | flowMetadata *voltha.FlowMetadata |
| 519 | } |
| 520 | tests := []struct { |
| 521 | name string |
| 522 | args args |
| 523 | }{ |
| 524 | // TODO: Add test cases. |
| 525 | {"AddFlow", args{flow: ofpstats, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 526 | {"AddFlow", args{flow: ofpstats2, flowMetadata: flowMetadata}}, |
| 527 | {"AddFlow", args{flow: ofpstats3, flowMetadata: flowMetadata}}, |
| 528 | {"AddFlow", args{flow: ofpstats4, flowMetadata: flowMetadata}}, |
| 529 | {"AddFlow", args{flow: ofpstats5, flowMetadata: flowMetadata}}, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 530 | //{"AddFlow", args{flow: ofpstats6, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 531 | {"AddFlow", args{flow: ofpstats7, flowMetadata: flowMetadata}}, |
| 532 | {"AddFlow", args{flow: ofpstats8, flowMetadata: flowMetadata}}, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 533 | //{"AddFlow", args{flow: ofpstats9, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 534 | {"AddFlow", args{flow: igmpstats, flowMetadata: flowMetadata}}, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 535 | //{"AddFlow", args{flow: ofpstats10, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 536 | //ofpstats10 |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 537 | {"AddFlow", args{flow: ofpstats11, flowMetadata: flowMetadata}}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 538 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 539 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 540 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 541 | for _, tt := range tests { |
| 542 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 543 | flowMgr.AddFlow(ctx, tt.args.flow, tt.args.flowMetadata) |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 544 | }) |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | func TestOpenOltFlowMgr_UpdateOnuInfo(t *testing.T) { |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 549 | // flowMgr := newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 550 | type args struct { |
| 551 | intfID uint32 |
| 552 | onuID uint32 |
| 553 | serialNum string |
| 554 | } |
| 555 | tests := []struct { |
| 556 | name string |
| 557 | args args |
| 558 | }{ |
| 559 | // TODO: Add test cases. |
| 560 | {"UpdateOnuInfo", args{1, 1, "onu1"}}, |
| 561 | {"UpdateOnuInfo", args{2, 3, "onu1"}}, |
| 562 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 563 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 564 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 565 | for _, tt := range tests { |
| 566 | t.Run(tt.name, func(t *testing.T) { |
| 567 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 568 | flowMgr.UpdateOnuInfo(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum) |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 569 | }) |
| 570 | } |
| 571 | } |
| 572 | |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 573 | func TestOpenOltFlowMgr_deleteGemPortFromLocalCache(t *testing.T) { |
| 574 | // flowMgr := newMockFlowmgr() |
| 575 | type args struct { |
| 576 | intfID uint32 |
| 577 | onuID uint32 |
| 578 | gemPortIDs []uint32 |
| 579 | gemPortIDsToBeDeleted []uint32 |
| 580 | serialNum string |
| 581 | finalLength int |
| 582 | } |
| 583 | tests := []struct { |
| 584 | name string |
| 585 | args args |
| 586 | }{ |
| 587 | // Add/Delete single gem port |
| 588 | {"DeleteGemPortFromLocalCache1", args{0, 1, []uint32{1}, []uint32{1}, "onu1", 0}}, |
| 589 | // Delete all gemports |
| 590 | {"DeleteGemPortFromLocalCache2", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{1, 2, 3, 4}, "onu1", 0}}, |
| 591 | // Try to delete when there is no gem port |
| 592 | {"DeleteGemPortFromLocalCache3", args{0, 1, []uint32{}, []uint32{1, 2}, "onu1", 0}}, |
| 593 | // Try to delete non-existent gem port |
| 594 | {"DeleteGemPortFromLocalCache4", args{0, 1, []uint32{1}, []uint32{2}, "onu1", 1}}, |
| 595 | // Try to delete two of the gem ports |
| 596 | {"DeleteGemPortFromLocalCache5", args{0, 1, []uint32{1, 2, 3, 4}, []uint32{2, 4}, "onu1", 2}}, |
| 597 | } |
| 598 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 599 | defer cancel() |
| 600 | for _, tt := range tests { |
| 601 | t.Run(tt.name, func(t *testing.T) { |
| 602 | flowMgr.UpdateOnuInfo(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum) |
| 603 | for _, gemPort := range tt.args.gemPortIDs { |
| 604 | flowMgr.addGemPortToOnuInfoMap(ctx, tt.args.intfID, tt.args.onuID, gemPort) |
| 605 | } |
| 606 | for _, gemPortDeleted := range tt.args.gemPortIDsToBeDeleted { |
| 607 | flowMgr.deleteGemPortFromLocalCache(tt.args.intfID, tt.args.onuID, gemPortDeleted) |
| 608 | } |
| 609 | lenofGemPorts := len(flowMgr.onuGemInfo[tt.args.intfID][0].GemPorts) |
| 610 | if lenofGemPorts != tt.args.finalLength { |
| 611 | t.Errorf("GemPorts length is not as expected len = %d, want %d", lenofGemPorts, tt.args.finalLength) |
| 612 | } |
| 613 | |
| 614 | }) |
| 615 | } |
| 616 | } |
| 617 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 618 | func TestOpenOltFlowMgr_GetLogicalPortFromPacketIn(t *testing.T) { |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 619 | // flowMgr := newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 620 | type args struct { |
| 621 | packetIn *openoltpb2.PacketIndication |
| 622 | } |
| 623 | tests := []struct { |
| 624 | name string |
| 625 | args args |
| 626 | want uint32 |
| 627 | wantErr bool |
| 628 | }{ |
| 629 | // TODO: Add test cases. |
| 630 | {"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] | 631 | {"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] | 632 | // Negative Test cases. |
| 633 | {"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] | 634 | {"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] | 635 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 636 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 637 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 638 | for _, tt := range tests { |
| 639 | t.Run(tt.name, func(t *testing.T) { |
| 640 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 641 | got, err := flowMgr.GetLogicalPortFromPacketIn(ctx, tt.args.packetIn) |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 642 | if (err != nil) != tt.wantErr { |
| 643 | t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() error = %v, wantErr %v", err, tt.wantErr) |
| 644 | return |
| 645 | } |
| 646 | if got != tt.want { |
| 647 | t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() = %v, want %v", got, tt.want) |
| 648 | } |
| 649 | }) |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | func TestOpenOltFlowMgr_GetPacketOutGemPortID(t *testing.T) { |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 654 | // flwMgr := newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 655 | |
| 656 | type args struct { |
| 657 | intfID uint32 |
| 658 | onuID uint32 |
| 659 | portNum uint32 |
| 660 | } |
| 661 | tests := []struct { |
| 662 | name string |
| 663 | args args |
| 664 | want uint32 |
| 665 | wantErr bool |
| 666 | }{ |
| 667 | // TODO: Add test cases. |
| 668 | {"GetPacketOutGemPortID", args{intfID: 1, onuID: 1, portNum: 1}, 1, false}, |
| 669 | {"GetPacketOutGemPortID", args{intfID: 2, onuID: 2, portNum: 2}, 2, false}, |
| 670 | {"GetPacketOutGemPortID", args{intfID: 1, onuID: 2, portNum: 2}, 0, true}, |
| 671 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 672 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 673 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 674 | for _, tt := range tests { |
| 675 | t.Run(tt.name, func(t *testing.T) { |
| 676 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 677 | 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] | 678 | if (err != nil) != tt.wantErr { |
| 679 | t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() error = %v, wantErr %v", err, tt.wantErr) |
| 680 | return |
| 681 | } |
| 682 | if got != tt.want { |
| 683 | t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, want %v", got, tt.want) |
| 684 | } |
| 685 | |
| 686 | }) |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | func TestOpenOltFlowMgr_DeleteTechProfileInstance(t *testing.T) { |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 691 | // flwMgr := newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 692 | type args struct { |
| 693 | intfID uint32 |
| 694 | onuID uint32 |
| 695 | uniID uint32 |
| 696 | sn string |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 697 | tpID uint32 |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 698 | } |
| 699 | tests := []struct { |
| 700 | name string |
| 701 | args args |
| 702 | wantErr bool |
| 703 | }{ |
| 704 | // TODO: Add test cases. |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 705 | {"DeleteTechProfileInstance", args{intfID: 0, onuID: 1, uniID: 1, sn: "", tpID: 64}, false}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 706 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 707 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 708 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 709 | for _, tt := range tests { |
| 710 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 711 | 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] | 712 | t.Errorf("OpenOltFlowMgr.DeleteTechProfileInstance() error = %v, wantErr %v", err, tt.wantErr) |
| 713 | } |
| 714 | }) |
| 715 | } |
| 716 | } |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 717 | |
| 718 | func TestOpenOltFlowMgr_checkAndAddFlow(t *testing.T) { |
| 719 | // flowMgr := newMockFlowmgr() |
| 720 | kw := make(map[string]uint64) |
| 721 | kw["table_id"] = 1 |
| 722 | kw["meter_id"] = 1 |
| 723 | kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64 |
| 724 | |
| 725 | // Upstream flow |
| 726 | fa := &fu.FlowArgs{ |
| 727 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 728 | fu.InPort(536870912), |
| 729 | fu.Metadata_ofp(1), |
| 730 | fu.IpProto(17), // dhcp |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 731 | fu.VlanPcp(0), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 732 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 733 | }, |
| 734 | Actions: []*ofp.OfpAction{ |
| 735 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 736 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 737 | fu.Output(65536), |
| 738 | fu.PushVlan(0x8100), |
| 739 | }, |
| 740 | KV: kw, |
| 741 | } |
| 742 | |
| 743 | // EAPOL |
| 744 | fa2 := &fu.FlowArgs{ |
| 745 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 746 | fu.InPort(536870912), |
| 747 | fu.Metadata_ofp(1), |
| 748 | fu.EthType(0x888E), |
| 749 | fu.VlanPcp(1), |
| 750 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257), |
| 751 | }, |
| 752 | Actions: []*ofp.OfpAction{ |
| 753 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 754 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 755 | fu.Output(65536), |
| 756 | fu.PushVlan(0x8100), |
| 757 | }, |
| 758 | KV: kw, |
| 759 | } |
| 760 | |
| 761 | // HSIA |
| 762 | fa3 := &fu.FlowArgs{ |
| 763 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 764 | fu.InPort(536870912), |
| 765 | fu.Metadata_ofp(1), |
| 766 | //fu.EthType(0x8100), |
| 767 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 768 | }, |
| 769 | Actions: []*ofp.OfpAction{ |
| 770 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 771 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)), |
| 772 | fu.Output(65536), |
| 773 | fu.PushVlan(0x8100), |
| 774 | }, |
| 775 | KV: kw, |
| 776 | } |
| 777 | |
| 778 | fa4 := &fu.FlowArgs{ |
| 779 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 780 | fu.InPort(65535), |
| 781 | fu.Metadata_ofp(1), |
| 782 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 783 | fu.VlanPcp(1), |
| 784 | }, |
| 785 | Actions: []*ofp.OfpAction{ |
| 786 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 787 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)), |
| 788 | fu.Output(536870912), |
| 789 | fu.PopVlan(), |
| 790 | }, |
| 791 | KV: kw, |
| 792 | } |
| 793 | |
| 794 | classifierInfo := make(map[string]interface{}) |
| 795 | actionInfo := make(map[string]interface{}) |
| 796 | classifierInfo2 := make(map[string]interface{}) |
| 797 | actionInfo2 := make(map[string]interface{}) |
| 798 | classifierInfo3 := make(map[string]interface{}) |
| 799 | actionInfo3 := make(map[string]interface{}) |
| 800 | classifierInfo4 := make(map[string]interface{}) |
| 801 | actionInfo4 := make(map[string]interface{}) |
| 802 | flowState := fu.MkFlowStat(fa) |
| 803 | flowState2 := fu.MkFlowStat(fa2) |
| 804 | flowState3 := fu.MkFlowStat(fa3) |
| 805 | flowState4 := fu.MkFlowStat(fa4) |
| 806 | formulateClassifierInfoFromFlow(classifierInfo, flowState) |
| 807 | formulateClassifierInfoFromFlow(classifierInfo2, flowState2) |
| 808 | formulateClassifierInfoFromFlow(classifierInfo3, flowState3) |
| 809 | formulateClassifierInfoFromFlow(classifierInfo4, flowState4) |
| 810 | |
| 811 | err := formulateActionInfoFromFlow(actionInfo, classifierInfo, flowState) |
| 812 | if err != nil { |
| 813 | // Error logging is already done in the called function |
| 814 | // So just return in case of error |
| 815 | return |
| 816 | } |
| 817 | |
| 818 | err = formulateActionInfoFromFlow(actionInfo2, classifierInfo2, flowState2) |
| 819 | if err != nil { |
| 820 | // Error logging is already done in the called function |
| 821 | // So just return in case of error |
| 822 | return |
| 823 | } |
| 824 | |
| 825 | err = formulateActionInfoFromFlow(actionInfo3, classifierInfo3, flowState3) |
| 826 | if err != nil { |
| 827 | // Error logging is already done in the called function |
| 828 | // So just return in case of error |
| 829 | return |
| 830 | } |
| 831 | |
| 832 | err = formulateActionInfoFromFlow(actionInfo4, classifierInfo4, flowState4) |
| 833 | if err != nil { |
| 834 | // Error logging is already done in the called function |
| 835 | // So just return in case of error |
| 836 | return |
| 837 | } |
| 838 | |
| 839 | //ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1} |
| 840 | //flowMetadata := &voltha.FlowMetadata{ |
| 841 | // Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}, |
| 842 | //} |
| 843 | |
| 844 | TpInst := &tp.TechProfile{ |
| 845 | Name: "Test-Tech-Profile", |
| 846 | SubscriberIdentifier: "257", |
| 847 | ProfileType: "Mock", |
| 848 | Version: 1, |
| 849 | NumGemPorts: 4, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 850 | InstanceCtrl: tp.InstanceControl{ |
| 851 | Onu: "1", |
| 852 | Uni: "16", |
| 853 | }, |
| 854 | } |
| 855 | |
| 856 | type fields struct { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 857 | techprofile []tp.TechProfileIf |
| 858 | deviceHandler *DeviceHandler |
| 859 | resourceMgr *rsrcMgr.OpenOltResourceMgr |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 860 | } |
| 861 | type args struct { |
| 862 | args map[string]uint32 |
| 863 | classifierInfo map[string]interface{} |
| 864 | actionInfo map[string]interface{} |
| 865 | flow *ofp.OfpFlowStats |
| 866 | gemPort uint32 |
| 867 | intfID uint32 |
| 868 | onuID uint32 |
| 869 | uniID uint32 |
| 870 | portNo uint32 |
| 871 | TpInst *tp.TechProfile |
| 872 | allocID []uint32 |
| 873 | gemPorts []uint32 |
| 874 | TpID uint32 |
| 875 | uni string |
| 876 | } |
| 877 | tests := []struct { |
| 878 | name string |
| 879 | fields fields |
| 880 | args args |
| 881 | }{ |
| 882 | { |
| 883 | name: "checkAndAddFlow-1", |
| 884 | args: args{ |
| 885 | args: nil, |
| 886 | classifierInfo: classifierInfo, |
| 887 | actionInfo: actionInfo, |
| 888 | flow: flowState, |
| 889 | gemPort: 1, |
| 890 | intfID: 1, |
| 891 | onuID: 1, |
| 892 | uniID: 16, |
| 893 | portNo: 1, |
| 894 | TpInst: TpInst, |
| 895 | allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004}, |
| 896 | gemPorts: []uint32{1, 2, 3, 4}, |
| 897 | TpID: 64, |
| 898 | uni: "16", |
| 899 | }, |
| 900 | }, |
| 901 | { |
| 902 | name: "checkAndAddFlow-2", |
| 903 | args: args{ |
| 904 | args: nil, |
| 905 | classifierInfo: classifierInfo2, |
| 906 | actionInfo: actionInfo2, |
| 907 | flow: flowState2, |
| 908 | gemPort: 1, |
| 909 | intfID: 1, |
| 910 | onuID: 1, |
| 911 | uniID: 16, |
| 912 | portNo: 1, |
| 913 | TpInst: TpInst, |
| 914 | allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004}, |
| 915 | gemPorts: []uint32{1, 2, 3, 4}, |
| 916 | TpID: 64, |
| 917 | uni: "16", |
| 918 | }, |
| 919 | }, |
| 920 | { |
| 921 | name: "checkAndAddFlow-3", |
| 922 | args: args{ |
| 923 | args: nil, |
| 924 | classifierInfo: classifierInfo3, |
| 925 | actionInfo: actionInfo3, |
| 926 | flow: flowState3, |
| 927 | gemPort: 1, |
| 928 | intfID: 1, |
| 929 | onuID: 1, |
| 930 | uniID: 16, |
| 931 | portNo: 1, |
| 932 | TpInst: TpInst, |
| 933 | allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004}, |
| 934 | gemPorts: []uint32{1, 2, 3, 4}, |
| 935 | TpID: 64, |
| 936 | uni: "16", |
| 937 | }, |
| 938 | }, |
| 939 | { |
| 940 | name: "checkAndAddFlow-4", |
| 941 | args: args{ |
| 942 | args: nil, |
| 943 | classifierInfo: classifierInfo4, |
| 944 | actionInfo: actionInfo4, |
| 945 | flow: flowState4, |
| 946 | gemPort: 1, |
| 947 | intfID: 1, |
| 948 | onuID: 1, |
| 949 | uniID: 16, |
| 950 | portNo: 1, |
| 951 | TpInst: TpInst, |
| 952 | allocID: []uint32{0x8001, 0x8002, 0x8003, 0x8004}, |
| 953 | gemPorts: []uint32{1, 2, 3, 4}, |
| 954 | TpID: 64, |
| 955 | uni: "16", |
| 956 | }, |
| 957 | }, |
| 958 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 959 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 960 | defer cancel() |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 961 | for _, tt := range tests { |
| 962 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 963 | 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] | 964 | tt.args.TpInst, tt.args.gemPorts, tt.args.TpID, tt.args.uni) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 965 | }) |
| 966 | } |
| 967 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 968 | |
| 969 | func TestOpenOltFlowMgr_TestMulticastFlow(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 970 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 971 | defer cancel() |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 972 | //create group |
| 973 | group := newGroup(2, []uint32{1}) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 974 | flowMgr.AddGroup(ctx, group) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 975 | |
| 976 | //create multicast flow |
| 977 | multicastFlowArgs := &fu.FlowArgs{ |
| 978 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 979 | fu.InPort(65536), |
| 980 | fu.VlanVid(660), //vlan |
| 981 | fu.Metadata_ofp(uint64(66)), //inner vlan |
| 982 | fu.EthType(0x800), //ipv4 |
| 983 | fu.Ipv4Dst(3809869825), //227.22.0.1 |
| 984 | }, |
| 985 | Actions: []*ofp.OfpAction{ |
| 986 | fu.Group(1), |
| 987 | }, |
| 988 | } |
| 989 | ofpStats := fu.MkFlowStat(multicastFlowArgs) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 990 | flowMgr.AddFlow(ctx, ofpStats, &voltha.FlowMetadata{}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 991 | |
| 992 | //add bucket to the group |
| 993 | group = newGroup(2, []uint32{1, 2}) |
| 994 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 995 | flowMgr.ModifyGroup(ctx, group) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 996 | } |