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