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