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 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 30 | "github.com/opencord/voltha-protos/v4/go/voltha" |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 31 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 32 | "github.com/opencord/voltha-lib-go/v4/pkg/db" |
| 33 | fu "github.com/opencord/voltha-lib-go/v4/pkg/flows" |
| 34 | "github.com/opencord/voltha-lib-go/v4/pkg/log" |
| 35 | tp "github.com/opencord/voltha-lib-go/v4/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" |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 39 | ofp "github.com/opencord/voltha-protos/v4/go/openflow_13" |
| 40 | "github.com/opencord/voltha-protos/v4/go/openolt" |
| 41 | openoltpb2 "github.com/opencord/voltha-protos/v4/go/openolt" |
| 42 | tp_pb "github.com/opencord/voltha-protos/v4/go/tech_profile" |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 43 | ) |
| 44 | |
Girish Gowdra | 9602eb4 | 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 | 9602eb4 | 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() |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 67 | rsrMgr := resourcemanager.NewResourceMgr(ctx, "olt", "127.0.0.1:2379", "etcd", "olt", deviceinfo, "service/voltha") |
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 | 9602eb4 | 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 | 9602eb4 | 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 | 9602eb4 | 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 | 9602eb4 | 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 | 9602eb4 | 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" |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 115 | tprofile.UsScheduler.QSchedPolicy = "WRR" |
| 116 | |
| 117 | tprofile2 := tprofile |
| 118 | tprofile2.DsScheduler.Direction = "DOWNSTREAM" |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 119 | tprofile2.DsScheduler.QSchedPolicy = "WRR" |
Gamze Abaka | 0117442 | 2021-03-10 06:55:27 +0000 | [diff] [blame] | 120 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 121 | tests := []struct { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 122 | name string |
| 123 | schedQueue schedQueue |
| 124 | wantErr bool |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 125 | }{ |
| 126 | // TODO: Add test cases. |
Gamze Abaka | 0117442 | 2021-03-10 06:55:27 +0000 | [diff] [blame] | 127 | {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 1, Upstream)}, false}, |
| 128 | {"CreateSchedulerQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 1, Downstream)}, false}, |
| 129 | {"CreateSchedulerQueues-13", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 2, Upstream)}, false}, |
| 130 | {"CreateSchedulerQueues-14", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 2, Downstream)}, false}, |
| 131 | {"CreateSchedulerQueues-15", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 3, Upstream)}, false}, |
| 132 | {"CreateSchedulerQueues-16", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 3, Downstream)}, false}, |
| 133 | {"CreateSchedulerQueues-17", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 4, Upstream)}, false}, |
| 134 | {"CreateSchedulerQueues-18", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 4, Downstream)}, false}, |
| 135 | {"CreateSchedulerQueues-19", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 5, Upstream)}, false}, |
| 136 | {"CreateSchedulerQueues-20", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 5, Downstream)}, false}, |
| 137 | |
| 138 | {"CreateSchedulerQueues-1", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, createFlowMetadata(tprofile, 0, Upstream)}, true}, |
| 139 | {"CreateSchedulerQueues-2", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, createFlowMetadata(tprofile2, 0, Downstream)}, true}, |
| 140 | {"CreateSchedulerQueues-3", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, createFlowMetadata(tprofile, 2, Upstream)}, true}, |
| 141 | {"CreateSchedulerQueues-4", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, createFlowMetadata(tprofile2, 2, Downstream)}, true}, |
| 142 | {"CreateSchedulerQueues-5", schedQueue{tp_pb.Direction_UPSTREAM, 1, 2, 2, 64, 2, tprofile, 2, createFlowMetadata(tprofile, 3, Upstream)}, true}, |
| 143 | {"CreateSchedulerQueues-6", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 2, 2, 65, 2, tprofile2, 2, createFlowMetadata(tprofile2, 3, Downstream)}, true}, |
| 144 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 145 | //Negative testcases |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 146 | {"CreateSchedulerQueues-7", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 1, &voltha.FlowMetadata{}}, true}, |
| 147 | {"CreateSchedulerQueues-8", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 0, &voltha.FlowMetadata{}}, true}, |
| 148 | {"CreateSchedulerQueues-9", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 1, &voltha.FlowMetadata{}}, true}, |
| 149 | {"CreateSchedulerQueues-10", schedQueue{tp_pb.Direction_UPSTREAM, 0, 1, 1, 64, 1, tprofile, 2, &voltha.FlowMetadata{}}, true}, |
| 150 | {"CreateSchedulerQueues-11", schedQueue{tp_pb.Direction_DOWNSTREAM, 0, 1, 1, 65, 1, tprofile2, 2, &voltha.FlowMetadata{}}, true}, |
| 151 | {"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] | 152 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 153 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 154 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 155 | for _, tt := range tests { |
| 156 | t.Run(tt.name, func(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 157 | 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] | 158 | t.Errorf("OpenOltFlowMgr.CreateSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr) |
| 159 | } |
| 160 | }) |
| 161 | } |
| 162 | } |
| 163 | |
Gamze Abaka | 0117442 | 2021-03-10 06:55:27 +0000 | [diff] [blame] | 164 | func createFlowMetadata(techProfile *tp.TechProfile, tcontType int, direction string) *voltha.FlowMetadata { |
| 165 | var additionalBw string |
| 166 | bands := make([]*ofp.OfpMeterBandHeader, 0) |
| 167 | switch tcontType { |
| 168 | case 1: |
| 169 | //tcont-type-1 |
| 170 | bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}}) |
| 171 | bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}}) |
| 172 | additionalBw = "AdditionalBW_None" |
| 173 | case 2: |
| 174 | //tcont-type-2 |
| 175 | bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 60000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}}) |
| 176 | bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}}) |
| 177 | additionalBw = "AdditionalBW_None" |
| 178 | case 3: |
| 179 | //tcont-type-3 |
| 180 | bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}}) |
| 181 | bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 20000, Data: &ofp.OfpMeterBandHeader_Drop{}}) |
| 182 | additionalBw = "AdditionalBW_NA" |
| 183 | case 4: |
| 184 | //tcont-type-4 |
| 185 | bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 200000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}}) |
| 186 | additionalBw = "AdditionalBW_BestEffort" |
| 187 | case 5: |
| 188 | //tcont-type-5 |
| 189 | bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 50000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}}) |
| 190 | bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 100000, BurstSize: 10000, Data: &ofp.OfpMeterBandHeader_Drop{}}) |
| 191 | bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 10000, BurstSize: 0, Data: &ofp.OfpMeterBandHeader_Drop{}}) |
| 192 | additionalBw = "AdditionalBW_BestEffort" |
| 193 | default: |
| 194 | // do nothing, we will return meter config with no meter bands |
| 195 | } |
| 196 | |
| 197 | if direction == Downstream { |
| 198 | techProfile.DsScheduler.AdditionalBw = additionalBw |
| 199 | } else { |
| 200 | techProfile.UsScheduler.AdditionalBw = additionalBw |
| 201 | } |
| 202 | |
| 203 | ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands} |
| 204 | return &voltha.FlowMetadata{ |
| 205 | Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}} |
| 206 | } |
| 207 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 208 | func TestOpenOltFlowMgr_RemoveSchedulerQueues(t *testing.T) { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 209 | tprofile := &tp.TechProfile{Name: "tp1", SubscriberIdentifier: "subscriber1", |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 210 | ProfileType: "pt1", NumGemPorts: 1, Version: 1, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 211 | InstanceCtrl: tp.InstanceControl{Onu: "1", Uni: "1", MaxGemPayloadSize: "1"}, |
| 212 | } |
| 213 | tprofile.UsScheduler.Direction = "UPSTREAM" |
| 214 | tprofile.UsScheduler.AdditionalBw = "AdditionalBW_None" |
| 215 | tprofile.UsScheduler.QSchedPolicy = "WRR" |
| 216 | |
| 217 | tprofile2 := tprofile |
| 218 | tprofile2.DsScheduler.Direction = "DOWNSTREAM" |
| 219 | tprofile2.DsScheduler.AdditionalBw = "AdditionalBW_None" |
| 220 | tprofile2.DsScheduler.QSchedPolicy = "WRR" |
| 221 | //defTprofile := &tp.DefaultTechProfile{} |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 222 | tests := []struct { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 223 | name string |
| 224 | schedQueue schedQueue |
| 225 | wantErr bool |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 226 | }{ |
| 227 | // TODO: Add test cases. |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 228 | {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_UPSTREAM, 1, 1, 1, 64, 1, tprofile, 0, nil}, false}, |
| 229 | {"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] | 230 | // negative test cases |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 231 | {"RemoveSchedulerQueues", schedQueue{tp_pb.Direction_DOWNSTREAM, 1, 1, 1, 65, 1, tprofile2, 0, nil}, false}, |
| 232 | {"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] | 233 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 234 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 235 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 236 | for _, tt := range tests { |
| 237 | t.Run(tt.name, func(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 238 | 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] | 239 | t.Errorf("OpenOltFlowMgr.RemoveSchedulerQueues() error = %v, wantErr %v", err, tt.wantErr) |
| 240 | } |
| 241 | }) |
| 242 | } |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 243 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 244 | } |
| 245 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 246 | func TestOpenOltFlowMgr_createTcontGemports(t *testing.T) { |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 247 | bands := make([]*ofp.OfpMeterBandHeader, 2) |
| 248 | bands[0] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 1000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}} |
| 249 | bands[1] = &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 2000, BurstSize: 5000, Data: &ofp.OfpMeterBandHeader_Drop{}} |
| 250 | ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands} |
| 251 | flowmetadata := &voltha.FlowMetadata{ |
| 252 | Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}, |
| 253 | } |
| 254 | type args struct { |
| 255 | intfID uint32 |
| 256 | onuID uint32 |
| 257 | uniID uint32 |
| 258 | uni string |
| 259 | uniPort uint32 |
| 260 | TpID uint32 |
| 261 | UsMeterID uint32 |
| 262 | DsMeterID uint32 |
| 263 | flowMetadata *voltha.FlowMetadata |
| 264 | } |
| 265 | tests := []struct { |
| 266 | name string |
| 267 | args args |
| 268 | }{ |
| 269 | {"createTcontGemports-1", args{intfID: 0, onuID: 1, uniID: 1, uni: "16", uniPort: 1, TpID: 64, UsMeterID: 1, DsMeterID: 1, flowMetadata: flowmetadata}}, |
| 270 | {"createTcontGemports-1", args{intfID: 0, onuID: 1, uniID: 1, uni: "16", uniPort: 1, TpID: 65, UsMeterID: 1, DsMeterID: 1, flowMetadata: flowmetadata}}, |
| 271 | } |
| 272 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 273 | defer cancel() |
| 274 | for _, tt := range tests { |
| 275 | t.Run(tt.name, func(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 276 | _, _, 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] | 277 | switch tpInst := tpInst.(type) { |
| 278 | case *tp.TechProfile: |
| 279 | if tt.args.TpID != 64 { |
| 280 | t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst) |
| 281 | } |
| 282 | case *tp.EponProfile: |
| 283 | if tt.args.TpID != 65 { |
| 284 | t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst) |
| 285 | } |
| 286 | default: |
| 287 | t.Errorf("OpenOltFlowMgr.createTcontGemports() error = different tech, tech %v", tpInst) |
| 288 | } |
| 289 | }) |
| 290 | } |
| 291 | } |
| 292 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 293 | func TestOpenOltFlowMgr_RemoveFlow(t *testing.T) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 294 | ctx := context.Background() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 295 | logger.Debug(ctx, "Info Warning Error: Starting RemoveFlow() test") |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 296 | fa := &fu.FlowArgs{ |
| 297 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 298 | fu.InPort(2), |
| 299 | fu.Metadata_ofp(2), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 300 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)), |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 301 | }, |
| 302 | Actions: []*ofp.OfpAction{ |
| 303 | fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 304 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 305 | fu.Output(1), |
| 306 | }, |
| 307 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 308 | ofpstats, _ := fu.MkFlowStat(fa) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 309 | ofpstats.Cookie = ofpstats.Id |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 310 | lldpFa := &fu.FlowArgs{ |
| 311 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 312 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 313 | fu.InPort(1), |
| 314 | fu.EthType(0x88CC), |
| 315 | fu.TunnelId(536870912), |
| 316 | }, |
| 317 | Actions: []*ofp.OfpAction{ |
| 318 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 319 | }, |
| 320 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 321 | lldpofpstats, _ := fu.MkFlowStat(lldpFa) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 322 | //lldpofpstats.Cookie = lldpofpstats.Id |
| 323 | |
| 324 | dhcpFa := &fu.FlowArgs{ |
| 325 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 326 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 327 | fu.InPort(1), |
| 328 | fu.UdpSrc(67), |
| 329 | //fu.TunnelId(536870912), |
| 330 | fu.IpProto(17), |
| 331 | }, |
| 332 | Actions: []*ofp.OfpAction{ |
| 333 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 334 | }, |
| 335 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 336 | dhcpofpstats, _ := fu.MkFlowStat(dhcpFa) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 337 | //dhcpofpstats.Cookie = dhcpofpstats.Id |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 338 | |
| 339 | //multicast flow |
| 340 | multicastFa := &fu.FlowArgs{ |
| 341 | MatchFields: []*ofp.OfpOxmOfbField{ |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 342 | fu.InPort(1048576), |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 343 | fu.VlanVid(660), //vlan |
| 344 | fu.Metadata_ofp(uint64(66)), //inner vlan |
| 345 | fu.EthType(0x800), //ipv4 |
| 346 | fu.Ipv4Dst(3809869825), //227.22.0.1 |
| 347 | }, |
| 348 | Actions: []*ofp.OfpAction{ |
| 349 | fu.Group(1), |
| 350 | }, |
| 351 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 352 | multicastOfpStats, _ := fu.MkFlowStat(multicastFa) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 353 | multicastOfpStats.Id = 1 |
| 354 | |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 355 | pppoedFa := &fu.FlowArgs{ |
| 356 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 357 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 358 | fu.InPort(1), |
| 359 | fu.EthType(0x8863), |
| 360 | fu.TunnelId(536870912), |
| 361 | }, |
| 362 | Actions: []*ofp.OfpAction{ |
| 363 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 364 | }, |
| 365 | } |
| 366 | pppoedOfpStats, _ := fu.MkFlowStat(pppoedFa) |
| 367 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 368 | type args struct { |
| 369 | flow *ofp.OfpFlowStats |
| 370 | } |
| 371 | tests := []struct { |
| 372 | name string |
| 373 | args args |
| 374 | }{ |
| 375 | // TODO: Add test cases. |
| 376 | {"RemoveFlow", args{flow: ofpstats}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 377 | {"RemoveFlow", args{flow: lldpofpstats}}, |
| 378 | {"RemoveFlow", args{flow: dhcpofpstats}}, |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 379 | {"RemoveFlow", args{flow: multicastOfpStats}}, |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 380 | {"RemoveFlow", args{flow: pppoedOfpStats}}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 381 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 382 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 383 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 384 | for _, tt := range tests { |
| 385 | t.Run(tt.name, func(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 386 | if err := flowMgr[0].RemoveFlow(ctx, tt.args.flow); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 387 | logger.Warn(ctx, err) |
| 388 | } |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 389 | }) |
| 390 | } |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 391 | // t.Error("=====") |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | func TestOpenOltFlowMgr_AddFlow(t *testing.T) { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 395 | kw := make(map[string]uint64) |
| 396 | kw["table_id"] = 1 |
| 397 | kw["meter_id"] = 1 |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 398 | kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64 |
| 399 | |
| 400 | // Upstream flow |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 401 | fa := &fu.FlowArgs{ |
| 402 | MatchFields: []*ofp.OfpOxmOfbField{ |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 403 | fu.InPort(536870912), |
| 404 | fu.Metadata_ofp(1), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 405 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 406 | }, |
| 407 | Actions: []*ofp.OfpAction{ |
| 408 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 409 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 410 | fu.Output(1048576), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 411 | fu.PushVlan(0x8100), |
| 412 | }, |
| 413 | KV: kw, |
| 414 | } |
| 415 | |
| 416 | // Downstream flow |
| 417 | fa3 := &fu.FlowArgs{ |
| 418 | MatchFields: []*ofp.OfpOxmOfbField{ |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 419 | fu.InPort(1048576), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 420 | fu.Metadata_ofp(1), |
| 421 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257), |
| 422 | }, |
| 423 | Actions: []*ofp.OfpAction{ |
| 424 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 425 | //fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 426 | fu.PopVlan(), |
| 427 | fu.Output(536870912), |
| 428 | }, |
| 429 | KV: kw, |
| 430 | } |
| 431 | |
| 432 | fa2 := &fu.FlowArgs{ |
| 433 | MatchFields: []*ofp.OfpOxmOfbField{ |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 434 | fu.InPort(1000), |
| 435 | fu.Metadata_ofp(1), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 436 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)), |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 437 | }, |
| 438 | Actions: []*ofp.OfpAction{ |
| 439 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 440 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 441 | fu.Output(65533), |
| 442 | }, |
| 443 | KV: kw, |
| 444 | } |
| 445 | |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 446 | // TODO Add LLDP flow |
| 447 | // TODO Add DHCP flow |
| 448 | |
| 449 | // Flows for negative scenarios |
| 450 | // Failure in formulateActionInfoFromFlow() |
| 451 | fa4 := &fu.FlowArgs{ |
| 452 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 453 | fu.InPort(1000), |
| 454 | fu.Metadata_ofp(1), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 455 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 456 | }, |
| 457 | Actions: []*ofp.OfpAction{ |
| 458 | fu.Experimenter(257, []byte{1, 2, 3, 4}), |
| 459 | }, |
| 460 | KV: kw, |
| 461 | } |
| 462 | |
| 463 | // Invalid Output |
| 464 | fa5 := &fu.FlowArgs{ |
| 465 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 466 | fu.InPort(1000), |
| 467 | fu.Metadata_ofp(1), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 468 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 469 | }, |
| 470 | Actions: []*ofp.OfpAction{ |
| 471 | fu.Output(0), |
| 472 | }, |
| 473 | KV: kw, |
| 474 | } |
| 475 | |
| 476 | // Tech-Profile-ID update (not supported) |
| 477 | kw6 := make(map[string]uint64) |
| 478 | kw6["table_id"] = 1 |
| 479 | kw6["meter_id"] = 1 |
| 480 | kw6["write_metadata"] = 0x4100000000 // TpID Other than the stored one |
| 481 | fa6 := &fu.FlowArgs{ |
| 482 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 483 | fu.InPort(536870912), |
| 484 | fu.TunnelId(16), |
| 485 | fu.Metadata_ofp(1), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 486 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 487 | }, |
| 488 | Actions: []*ofp.OfpAction{ |
| 489 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 490 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 491 | fu.Output(65535), |
| 492 | }, |
| 493 | KV: kw6, |
| 494 | } |
| 495 | |
| 496 | lldpFa := &fu.FlowArgs{ |
| 497 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 498 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 499 | fu.InPort(1), |
| 500 | fu.EthType(0x88CC), |
| 501 | fu.TunnelId(536870912), |
| 502 | }, |
| 503 | Actions: []*ofp.OfpAction{ |
| 504 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 505 | }, |
| 506 | } |
| 507 | |
| 508 | dhcpFa := &fu.FlowArgs{ |
| 509 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 510 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 511 | fu.InPort(1), |
| 512 | fu.UdpSrc(67), |
| 513 | //fu.TunnelId(536870912), |
| 514 | fu.IpProto(17), |
| 515 | }, |
| 516 | Actions: []*ofp.OfpAction{ |
| 517 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 518 | }, |
| 519 | } |
| 520 | igmpFa := &fu.FlowArgs{ |
| 521 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 522 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 523 | fu.InPort(1), |
| 524 | fu.UdpSrc(67), |
| 525 | //fu.TunnelId(536870912), |
| 526 | fu.IpProto(2), |
| 527 | }, |
| 528 | Actions: []*ofp.OfpAction{ |
| 529 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 530 | }, |
| 531 | } |
| 532 | |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 533 | pppoedFa := &fu.FlowArgs{ |
| 534 | KV: fu.OfpFlowModArgs{"priority": 1000, "cookie": 48132224281636694}, |
| 535 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 536 | fu.InPort(1), |
| 537 | fu.EthType(0x8863), |
| 538 | fu.TunnelId(536870912), |
| 539 | }, |
| 540 | Actions: []*ofp.OfpAction{ |
| 541 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 542 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 543 | }, |
| 544 | } |
| 545 | |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 546 | fa9 := &fu.FlowArgs{ |
| 547 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 548 | fu.InPort(536870912), |
| 549 | fu.TunnelId(16), |
| 550 | fu.Metadata_ofp(1), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 551 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 552 | fu.VlanPcp(1000), |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 553 | fu.UdpDst(1048576), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 554 | fu.UdpSrc(536870912), |
| 555 | fu.Ipv4Dst(65535), |
| 556 | fu.Ipv4Src(536870912), |
| 557 | }, |
| 558 | Actions: []*ofp.OfpAction{ |
| 559 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 560 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 561 | fu.Output(65535), |
| 562 | }, |
| 563 | KV: kw6, |
| 564 | } |
| 565 | |
| 566 | fa10 := &fu.FlowArgs{ |
| 567 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 568 | fu.InPort(65533), |
| 569 | // fu.TunnelId(16), |
| 570 | fu.Metadata_ofp(1), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 571 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 572 | fu.VlanPcp(1000), |
| 573 | fu.UdpDst(65535), |
| 574 | fu.UdpSrc(536870912), |
| 575 | fu.Ipv4Dst(65535), |
| 576 | fu.Ipv4Src(536870912), |
| 577 | }, |
| 578 | Actions: []*ofp.OfpAction{ |
| 579 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 580 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 581 | fu.Output(65535), |
| 582 | }, |
| 583 | KV: kw6, |
| 584 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 585 | //multicast flow |
| 586 | fa11 := &fu.FlowArgs{ |
| 587 | MatchFields: []*ofp.OfpOxmOfbField{ |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 588 | fu.InPort(1048576), |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 589 | fu.VlanVid(660), //vlan |
| 590 | fu.Metadata_ofp(uint64(66)), //inner vlan |
| 591 | fu.EthType(0x800), //ipv4 |
| 592 | fu.Ipv4Dst(3809869825), //227.22.0.1 |
| 593 | }, |
| 594 | Actions: []*ofp.OfpAction{ |
| 595 | fu.Group(1), |
| 596 | }, |
| 597 | KV: kw6, |
| 598 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 599 | ofpstats, _ := fu.MkFlowStat(fa) |
| 600 | ofpstats2, _ := fu.MkFlowStat(fa2) |
| 601 | ofpstats3, _ := fu.MkFlowStat(fa3) |
| 602 | ofpstats4, _ := fu.MkFlowStat(fa4) |
| 603 | ofpstats5, _ := fu.MkFlowStat(fa5) |
| 604 | ofpstats6, _ := fu.MkFlowStat(fa6) |
| 605 | ofpstats7, _ := fu.MkFlowStat(lldpFa) |
| 606 | ofpstats8, _ := fu.MkFlowStat(dhcpFa) |
| 607 | ofpstats9, _ := fu.MkFlowStat(fa9) |
| 608 | ofpstats10, _ := fu.MkFlowStat(fa10) |
| 609 | igmpstats, _ := fu.MkFlowStat(igmpFa) |
| 610 | ofpstats11, _ := fu.MkFlowStat(fa11) |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 611 | pppoedstats, _ := fu.MkFlowStat(pppoedFa) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 612 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 613 | fmt.Println(ofpstats6, ofpstats9, ofpstats10) |
| 614 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 615 | ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1} |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 616 | flowMetadata := &voltha.FlowMetadata{ |
| 617 | Meters: []*ofp.OfpMeterConfig{ofpMeterConfig}, |
| 618 | } |
| 619 | type args struct { |
| 620 | flow *ofp.OfpFlowStats |
| 621 | flowMetadata *voltha.FlowMetadata |
| 622 | } |
| 623 | tests := []struct { |
| 624 | name string |
| 625 | args args |
| 626 | }{ |
| 627 | // TODO: Add test cases. |
| 628 | {"AddFlow", args{flow: ofpstats, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 629 | {"AddFlow", args{flow: ofpstats2, flowMetadata: flowMetadata}}, |
| 630 | {"AddFlow", args{flow: ofpstats3, flowMetadata: flowMetadata}}, |
| 631 | {"AddFlow", args{flow: ofpstats4, flowMetadata: flowMetadata}}, |
| 632 | {"AddFlow", args{flow: ofpstats5, flowMetadata: flowMetadata}}, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 633 | //{"AddFlow", args{flow: ofpstats6, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 634 | {"AddFlow", args{flow: ofpstats7, flowMetadata: flowMetadata}}, |
| 635 | {"AddFlow", args{flow: ofpstats8, flowMetadata: flowMetadata}}, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 636 | //{"AddFlow", args{flow: ofpstats9, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 637 | {"AddFlow", args{flow: igmpstats, flowMetadata: flowMetadata}}, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 638 | //{"AddFlow", args{flow: ofpstats10, flowMetadata: flowMetadata}}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 639 | //ofpstats10 |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 640 | {"AddFlow", args{flow: ofpstats11, flowMetadata: flowMetadata}}, |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 641 | {"AddFlow", args{flow: pppoedstats, flowMetadata: flowMetadata}}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 642 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 643 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 644 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 645 | for _, tt := range tests { |
| 646 | t.Run(tt.name, func(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 647 | _ = flowMgr[0].AddFlow(ctx, tt.args.flow, tt.args.flowMetadata) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 648 | // TODO: actually verify test cases |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 649 | }) |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | func TestOpenOltFlowMgr_UpdateOnuInfo(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 654 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 655 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 656 | |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 657 | wg := sync.WaitGroup{} |
| 658 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 659 | intfCount := NumPonPorts |
| 660 | onuCount := OnuIDEnd - OnuIDStart + 1 |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 661 | |
| 662 | for i := 0; i < intfCount; i++ { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 663 | for j := 1; j <= onuCount; j++ { |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 664 | wg.Add(1) |
| 665 | go func(i uint32, j uint32) { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 666 | // TODO: actually verify success |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 667 | _ = flowMgr[i].UpdateOnuInfo(ctx, i, i, fmt.Sprintf("onu-%d", i)) |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 668 | wg.Done() |
| 669 | }(uint32(i), uint32(j)) |
| 670 | } |
| 671 | |
| 672 | } |
| 673 | |
| 674 | wg.Wait() |
| 675 | } |
| 676 | |
| 677 | func TestOpenOltFlowMgr_addGemPortToOnuInfoMap(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 678 | intfNum := NumPonPorts |
| 679 | onuNum := OnuIDEnd - OnuIDStart + 1 |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 680 | |
| 681 | // clean the flowMgr |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 682 | for i := 0; i < intfNum; i++ { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 683 | flowMgr[i].onuGemInfo = make([]rsrcMgr.OnuGemInfo, 0) |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 684 | } |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 685 | |
| 686 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 687 | defer cancel() |
| 688 | |
| 689 | // Create OnuInfo |
| 690 | for i := 0; i < intfNum; i++ { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 691 | for o := 1; o <= onuNum; o++ { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 692 | // TODO: actually verify success |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 693 | _ = 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] | 694 | } |
| 695 | } |
| 696 | |
| 697 | // Add gemPorts to OnuInfo in parallel threads |
| 698 | wg := sync.WaitGroup{} |
| 699 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 700 | for o := 1; o <= onuNum; o++ { |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 701 | for i := 0; i < intfNum; i++ { |
| 702 | wg.Add(1) |
| 703 | go func(intfId uint32, onuId uint32) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 704 | gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", intfId, onuId-1)) |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 705 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 706 | flowMgr[intfId].addGemPortToOnuInfoMap(ctx, intfId, onuId, uint32(gemID)) |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 707 | wg.Done() |
| 708 | }(uint32(i), uint32(o)) |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | wg.Wait() |
| 713 | |
| 714 | // check that each entry of onuGemInfo has the correct number of ONUs |
| 715 | for i := 0; i < intfNum; i++ { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 716 | lenofOnu := len(flowMgr[i].onuGemInfo) |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 717 | if onuNum != lenofOnu { |
| 718 | t.Errorf("OnuGemInfo length is not as expected len = %d, want %d", lenofOnu, onuNum) |
| 719 | } |
| 720 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 721 | for o := 1; o <= onuNum; o++ { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 722 | lenOfGemPorts := len(flowMgr[i].onuGemInfo[o-1].GemPorts) |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 723 | // check that each onuEntry has 1 gemPort |
| 724 | if lenOfGemPorts != 1 { |
| 725 | t.Errorf("Expected 1 GemPort per ONU, found %d", lenOfGemPorts) |
| 726 | } |
| 727 | |
| 728 | // check that the value of the gemport is correct |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 729 | gemID, _ := strconv.Atoi(fmt.Sprintf("90%d%d", i, o-1)) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 730 | currentValue := flowMgr[i].onuGemInfo[o-1].GemPorts[0] |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 731 | if uint32(gemID) != currentValue { |
| 732 | t.Errorf("Expected GemPort value to be %d, found %d", gemID, currentValue) |
| 733 | } |
| 734 | } |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 735 | } |
| 736 | } |
| 737 | |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 738 | func TestOpenOltFlowMgr_deleteGemPortFromLocalCache(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 739 | // Create fresh flowMgr instance |
| 740 | flowMgr = newMockFlowmgr() |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 741 | type args struct { |
| 742 | intfID uint32 |
| 743 | onuID uint32 |
| 744 | gemPortIDs []uint32 |
| 745 | gemPortIDsToBeDeleted []uint32 |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 746 | gemPortIDsRemaining []uint32 |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 747 | serialNum string |
| 748 | finalLength int |
| 749 | } |
| 750 | tests := []struct { |
| 751 | name string |
| 752 | args args |
| 753 | }{ |
| 754 | // Add/Delete single gem port |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 755 | {"DeleteGemPortFromLocalCache1", args{0, 1, []uint32{1}, []uint32{1}, []uint32{}, "onu1", 0}}, |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 756 | // Delete all gemports |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 757 | {"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] | 758 | // Try to delete when there is no gem port |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 759 | {"DeleteGemPortFromLocalCache3", args{0, 1, []uint32{}, []uint32{1, 2}, []uint32{}, "onu1", 0}}, |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 760 | // Try to delete non-existent gem port |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 761 | {"DeleteGemPortFromLocalCache4", args{0, 1, []uint32{1}, []uint32{2}, []uint32{1}, "onu1", 1}}, |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 762 | // Try to delete two of the gem ports |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 763 | {"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] | 764 | } |
| 765 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 766 | defer cancel() |
| 767 | for _, tt := range tests { |
| 768 | t.Run(tt.name, func(t *testing.T) { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 769 | // TODO: should check returned errors are as expected? |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 770 | _ = 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] | 771 | for _, gemPort := range tt.args.gemPortIDs { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 772 | 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] | 773 | } |
| 774 | for _, gemPortDeleted := range tt.args.gemPortIDsToBeDeleted { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 775 | 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] | 776 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 777 | lenofGemPorts := len(flowMgr[tt.args.intfID].onuGemInfo[0].GemPorts) |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 778 | if lenofGemPorts != tt.args.finalLength { |
| 779 | t.Errorf("GemPorts length is not as expected len = %d, want %d", lenofGemPorts, tt.args.finalLength) |
| 780 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 781 | gemPorts := flowMgr[tt.args.intfID].onuGemInfo[0].GemPorts |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 782 | if !reflect.DeepEqual(tt.args.gemPortIDsRemaining, gemPorts) { |
| 783 | t.Errorf("GemPorts are not as expected = %v, want %v", gemPorts, tt.args.gemPortIDsRemaining) |
| 784 | } |
serkant.uluderya | 96af493 | 2020-02-20 16:58:48 -0800 | [diff] [blame] | 785 | |
| 786 | }) |
| 787 | } |
| 788 | } |
| 789 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 790 | func TestOpenOltFlowMgr_GetLogicalPortFromPacketIn(t *testing.T) { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 791 | type args struct { |
| 792 | packetIn *openoltpb2.PacketIndication |
| 793 | } |
| 794 | tests := []struct { |
| 795 | name string |
| 796 | args args |
| 797 | want uint32 |
| 798 | wantErr bool |
| 799 | }{ |
| 800 | // TODO: Add test cases. |
Esin Karaman | df392e1 | 2020-12-16 13:33:09 +0000 | [diff] [blame] | 801 | {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 0, GemportId: 255, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 1, false}, |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 802 | {"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] | 803 | // Negative Test cases. |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 804 | {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 1, GemportId: 1, FlowId: 100, PortNo: 1, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 0, true}, |
Esin Karaman | df392e1 | 2020-12-16 13:33:09 +0000 | [diff] [blame] | 805 | {"GetLogicalPortFromPacketIn", args{packetIn: &openoltpb2.PacketIndication{IntfType: "pon", IntfId: 0, GemportId: 257, FlowId: 100, PortNo: 0, Cookie: 100, Pkt: []byte("GetLogicalPortFromPacketIn")}}, 16, false}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 806 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 807 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 808 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 809 | for _, tt := range tests { |
| 810 | t.Run(tt.name, func(t *testing.T) { |
| 811 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 812 | got, err := flowMgr[tt.args.packetIn.IntfId].GetLogicalPortFromPacketIn(ctx, tt.args.packetIn) |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 813 | if (err != nil) != tt.wantErr { |
| 814 | t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() error = %v, wantErr %v", err, tt.wantErr) |
| 815 | return |
| 816 | } |
| 817 | if got != tt.want { |
| 818 | t.Errorf("OpenOltFlowMgr.GetLogicalPortFromPacketIn() = %v, want %v", got, tt.want) |
| 819 | } |
| 820 | }) |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | func TestOpenOltFlowMgr_GetPacketOutGemPortID(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 825 | // Create fresh flowMgr instance |
| 826 | flowMgr = newMockFlowmgr() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 827 | |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 828 | //untagged packet in hex string |
| 829 | untaggedStr := "01005e000002000000000001080046c00020000040000102fa140a000001e00000029404000017000705e10000fa" |
| 830 | untagged, err := hex.DecodeString(untaggedStr) |
| 831 | if err != nil { |
| 832 | t.Error("Unable to parse hex string", err) |
| 833 | panic(err) |
| 834 | } |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 835 | //single-tagged packet in hex string. vlanID.pbit: 1.1 |
| 836 | singleTaggedStr := "01005e0000010025ba48172481002001080046c0002000004000010257deab140023e0000001940400001164ee9b0000000000000000000000000000" |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 837 | singleTagged, err := hex.DecodeString(singleTaggedStr) |
| 838 | if err != nil { |
| 839 | t.Error("Unable to parse hex string", err) |
| 840 | panic(err) |
| 841 | } |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 842 | //double-tagged packet in hex string. vlanID.pbit: 210.0-0.0 |
| 843 | doubleTaggedStr := "01005e000016deadbeefba118100021081000000080046000028000000000102c5b87f000001e0000016940400002200f8030000000104000000e10000fa" |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 844 | doubleTagged, err := hex.DecodeString(doubleTaggedStr) |
| 845 | if err != nil { |
| 846 | t.Error("Unable to parse hex string", err) |
| 847 | panic(err) |
| 848 | } |
| 849 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 850 | type args struct { |
| 851 | intfID uint32 |
| 852 | onuID uint32 |
| 853 | portNum uint32 |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 854 | packet []byte |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 855 | } |
| 856 | tests := []struct { |
| 857 | name string |
| 858 | args args |
| 859 | want uint32 |
| 860 | wantErr bool |
| 861 | }{ |
| 862 | // TODO: Add test cases. |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 863 | {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: untagged}, 1, false}, |
| 864 | {"GetPacketOutGemPortID", args{intfID: 1, onuID: 2, portNum: 2, packet: singleTagged}, 2, false}, |
| 865 | {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 1, packet: doubleTagged}, 1, false}, |
| 866 | {"GetPacketOutGemPortID", args{intfID: 0, onuID: 10, portNum: 10, packet: untagged}, 2, true}, |
| 867 | {"GetPacketOutGemPortID", args{intfID: 0, onuID: 1, portNum: 3, packet: []byte{}}, 3, true}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 868 | } |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 869 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 870 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 871 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 872 | for _, tt := range tests { |
| 873 | t.Run(tt.name, func(t *testing.T) { |
| 874 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 875 | 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] | 876 | if tt.wantErr { |
| 877 | if err == nil { |
| 878 | //error expected but got value |
| 879 | t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, wantErr %v", got, tt.wantErr) |
| 880 | } |
| 881 | } else { |
| 882 | if err != nil { |
| 883 | //error is not expected but got error |
| 884 | t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() error = %v, wantErr %v", err, tt.wantErr) |
| 885 | return |
| 886 | } |
| 887 | if got != tt.want { |
| 888 | t.Errorf("OpenOltFlowMgr.GetPacketOutGemPortID() = %v, want %v", got, tt.want) |
| 889 | } |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 890 | } |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 891 | }) |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | func TestOpenOltFlowMgr_DeleteTechProfileInstance(t *testing.T) { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 896 | type args struct { |
| 897 | intfID uint32 |
| 898 | onuID uint32 |
| 899 | uniID uint32 |
| 900 | sn string |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 901 | tpID uint32 |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 902 | } |
| 903 | tests := []struct { |
| 904 | name string |
| 905 | args args |
| 906 | wantErr bool |
| 907 | }{ |
| 908 | // TODO: Add test cases. |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 909 | {"DeleteTechProfileInstance", args{intfID: 0, onuID: 1, uniID: 1, sn: "", tpID: 64}, false}, |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 910 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 911 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 912 | defer cancel() |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 913 | for _, tt := range tests { |
| 914 | t.Run(tt.name, func(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 915 | 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] | 916 | t.Errorf("OpenOltFlowMgr.DeleteTechProfileInstance() error = %v, wantErr %v", err, tt.wantErr) |
| 917 | } |
| 918 | }) |
| 919 | } |
| 920 | } |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 921 | |
| 922 | func TestOpenOltFlowMgr_checkAndAddFlow(t *testing.T) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 923 | ctx := context.Background() |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 924 | kw := make(map[string]uint64) |
| 925 | kw["table_id"] = 1 |
| 926 | kw["meter_id"] = 1 |
| 927 | kw["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64 |
| 928 | |
| 929 | // Upstream flow |
| 930 | fa := &fu.FlowArgs{ |
| 931 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 932 | fu.InPort(536870912), |
| 933 | fu.Metadata_ofp(1), |
| 934 | fu.IpProto(17), // dhcp |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 935 | fu.VlanPcp(0), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 936 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 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) | 257)), |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 941 | fu.Output(1048576), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 942 | fu.PushVlan(0x8100), |
| 943 | }, |
| 944 | KV: kw, |
| 945 | } |
| 946 | |
| 947 | // EAPOL |
| 948 | fa2 := &fu.FlowArgs{ |
| 949 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 950 | fu.InPort(536870912), |
| 951 | fu.Metadata_ofp(1), |
| 952 | fu.EthType(0x888E), |
| 953 | fu.VlanPcp(1), |
| 954 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257), |
| 955 | }, |
| 956 | Actions: []*ofp.OfpAction{ |
| 957 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 958 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 959 | fu.Output(1048576), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 960 | fu.PushVlan(0x8100), |
| 961 | }, |
| 962 | KV: kw, |
| 963 | } |
| 964 | |
| 965 | // HSIA |
| 966 | fa3 := &fu.FlowArgs{ |
| 967 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 968 | fu.InPort(536870912), |
| 969 | fu.Metadata_ofp(1), |
| 970 | //fu.EthType(0x8100), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 971 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 972 | }, |
| 973 | Actions: []*ofp.OfpAction{ |
| 974 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 975 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))), |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 976 | fu.Output(1048576), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 977 | fu.PushVlan(0x8100), |
| 978 | }, |
| 979 | KV: kw, |
| 980 | } |
| 981 | |
| 982 | fa4 := &fu.FlowArgs{ |
| 983 | MatchFields: []*ofp.OfpOxmOfbField{ |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 984 | fu.InPort(1048576), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 985 | fu.Metadata_ofp(1), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 986 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 987 | fu.VlanPcp(1), |
| 988 | }, |
| 989 | Actions: []*ofp.OfpAction{ |
| 990 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 991 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))), |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 992 | fu.Output(536870912), |
| 993 | fu.PopVlan(), |
| 994 | }, |
| 995 | KV: kw, |
| 996 | } |
| 997 | |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 998 | // PPPOED |
| 999 | pppoedFA := &fu.FlowArgs{ |
| 1000 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1001 | fu.InPort(536870912), |
| 1002 | fu.Metadata_ofp(1), |
| 1003 | fu.EthType(0x8863), |
| 1004 | fu.VlanPcp(1), |
| 1005 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257), |
| 1006 | }, |
| 1007 | Actions: []*ofp.OfpAction{ |
| 1008 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 1009 | fu.Output(1048576), |
| 1010 | fu.PushVlan(0x8100), |
| 1011 | }, |
| 1012 | KV: kw, |
| 1013 | } |
| 1014 | |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1015 | classifierInfo := make(map[string]interface{}) |
| 1016 | actionInfo := make(map[string]interface{}) |
| 1017 | classifierInfo2 := make(map[string]interface{}) |
| 1018 | actionInfo2 := make(map[string]interface{}) |
| 1019 | classifierInfo3 := make(map[string]interface{}) |
| 1020 | actionInfo3 := make(map[string]interface{}) |
| 1021 | classifierInfo4 := make(map[string]interface{}) |
| 1022 | actionInfo4 := make(map[string]interface{}) |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1023 | classifierInfo5 := make(map[string]interface{}) |
| 1024 | actionInfo5 := make(map[string]interface{}) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1025 | flow, _ := fu.MkFlowStat(fa) |
| 1026 | flow2, _ := fu.MkFlowStat(fa2) |
| 1027 | flow3, _ := fu.MkFlowStat(fa3) |
| 1028 | flow4, _ := fu.MkFlowStat(fa4) |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1029 | flow5, _ := fu.MkFlowStat(pppoedFA) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1030 | formulateClassifierInfoFromFlow(ctx, classifierInfo, flow) |
| 1031 | formulateClassifierInfoFromFlow(ctx, classifierInfo2, flow2) |
| 1032 | formulateClassifierInfoFromFlow(ctx, classifierInfo3, flow3) |
| 1033 | formulateClassifierInfoFromFlow(ctx, classifierInfo4, flow4) |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1034 | formulateClassifierInfoFromFlow(ctx, classifierInfo5, flow5) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1035 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1036 | err := formulateActionInfoFromFlow(ctx, actionInfo, classifierInfo, flow) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1037 | if err != nil { |
| 1038 | // Error logging is already done in the called function |
| 1039 | // So just return in case of error |
| 1040 | return |
| 1041 | } |
| 1042 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1043 | err = formulateActionInfoFromFlow(ctx, actionInfo2, classifierInfo2, flow2) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1044 | if err != nil { |
| 1045 | // Error logging is already done in the called function |
| 1046 | // So just return in case of error |
| 1047 | return |
| 1048 | } |
| 1049 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1050 | err = formulateActionInfoFromFlow(ctx, actionInfo3, classifierInfo3, flow3) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1051 | if err != nil { |
| 1052 | // Error logging is already done in the called function |
| 1053 | // So just return in case of error |
| 1054 | return |
| 1055 | } |
| 1056 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1057 | err = formulateActionInfoFromFlow(ctx, actionInfo4, classifierInfo4, flow4) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1058 | if err != nil { |
| 1059 | // Error logging is already done in the called function |
| 1060 | // So just return in case of error |
| 1061 | return |
| 1062 | } |
| 1063 | |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1064 | err = formulateActionInfoFromFlow(ctx, actionInfo5, classifierInfo5, flow5) |
| 1065 | if err != nil { |
| 1066 | // Error logging is already done in the called function |
| 1067 | // So just return in case of error |
| 1068 | return |
| 1069 | } |
| 1070 | |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1071 | TpInst := &tp.TechProfile{ |
| 1072 | Name: "Test-Tech-Profile", |
| 1073 | SubscriberIdentifier: "257", |
| 1074 | ProfileType: "Mock", |
| 1075 | Version: 1, |
| 1076 | NumGemPorts: 4, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1077 | InstanceCtrl: tp.InstanceControl{ |
| 1078 | Onu: "1", |
| 1079 | Uni: "16", |
| 1080 | }, |
| 1081 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1082 | TpInst.UsScheduler.Priority = 1 |
| 1083 | TpInst.UsScheduler.Direction = "upstream" |
| 1084 | TpInst.UsScheduler.AllocID = 1 |
| 1085 | TpInst.UsScheduler.AdditionalBw = "None" |
| 1086 | TpInst.UsScheduler.QSchedPolicy = "PQ" |
| 1087 | TpInst.UsScheduler.Weight = 4 |
| 1088 | |
| 1089 | TpInst.DsScheduler.Priority = 1 |
| 1090 | TpInst.DsScheduler.Direction = "upstream" |
| 1091 | TpInst.DsScheduler.AllocID = 1 |
| 1092 | TpInst.DsScheduler.AdditionalBw = "None" |
| 1093 | TpInst.DsScheduler.QSchedPolicy = "PQ" |
| 1094 | TpInst.DsScheduler.Weight = 4 |
| 1095 | |
| 1096 | TpInst.UpstreamGemPortAttributeList = make([]tp.IGemPortAttribute, 4) |
| 1097 | TpInst.UpstreamGemPortAttributeList[0].GemportID = 1 |
| 1098 | TpInst.UpstreamGemPortAttributeList[0].PbitMap = "0b00000011" |
| 1099 | TpInst.UpstreamGemPortAttributeList[0].GemportID = 2 |
| 1100 | TpInst.UpstreamGemPortAttributeList[0].PbitMap = "0b00001100" |
| 1101 | TpInst.UpstreamGemPortAttributeList[0].GemportID = 3 |
| 1102 | TpInst.UpstreamGemPortAttributeList[0].PbitMap = "0b00110000" |
| 1103 | TpInst.UpstreamGemPortAttributeList[0].GemportID = 4 |
| 1104 | TpInst.UpstreamGemPortAttributeList[0].PbitMap = "0b11000000" |
| 1105 | |
| 1106 | TpInst.DownstreamGemPortAttributeList = make([]tp.IGemPortAttribute, 4) |
| 1107 | TpInst.DownstreamGemPortAttributeList[0].GemportID = 1 |
| 1108 | TpInst.DownstreamGemPortAttributeList[0].PbitMap = "0b00000011" |
| 1109 | TpInst.DownstreamGemPortAttributeList[0].GemportID = 2 |
| 1110 | TpInst.DownstreamGemPortAttributeList[0].PbitMap = "0b00001100" |
| 1111 | TpInst.DownstreamGemPortAttributeList[0].GemportID = 3 |
| 1112 | TpInst.DownstreamGemPortAttributeList[0].PbitMap = "0b00110000" |
| 1113 | TpInst.DownstreamGemPortAttributeList[0].GemportID = 4 |
| 1114 | TpInst.DownstreamGemPortAttributeList[0].PbitMap = "0b11000000" |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1115 | |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1116 | type args struct { |
| 1117 | args map[string]uint32 |
| 1118 | classifierInfo map[string]interface{} |
| 1119 | actionInfo map[string]interface{} |
| 1120 | flow *ofp.OfpFlowStats |
| 1121 | gemPort uint32 |
| 1122 | intfID uint32 |
| 1123 | onuID uint32 |
| 1124 | uniID uint32 |
| 1125 | portNo uint32 |
| 1126 | TpInst *tp.TechProfile |
| 1127 | allocID []uint32 |
| 1128 | gemPorts []uint32 |
| 1129 | TpID uint32 |
| 1130 | uni string |
| 1131 | } |
| 1132 | tests := []struct { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 1133 | name string |
| 1134 | args args |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1135 | }{ |
| 1136 | { |
| 1137 | name: "checkAndAddFlow-1", |
| 1138 | args: args{ |
| 1139 | args: nil, |
| 1140 | classifierInfo: classifierInfo, |
| 1141 | actionInfo: actionInfo, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1142 | flow: flow, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1143 | gemPort: 1, |
| 1144 | intfID: 1, |
| 1145 | onuID: 1, |
| 1146 | uniID: 16, |
| 1147 | portNo: 1, |
| 1148 | TpInst: TpInst, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1149 | allocID: []uint32{0x8001}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1150 | gemPorts: []uint32{1, 2, 3, 4}, |
| 1151 | TpID: 64, |
| 1152 | uni: "16", |
| 1153 | }, |
| 1154 | }, |
| 1155 | { |
| 1156 | name: "checkAndAddFlow-2", |
| 1157 | args: args{ |
| 1158 | args: nil, |
| 1159 | classifierInfo: classifierInfo2, |
| 1160 | actionInfo: actionInfo2, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1161 | flow: flow2, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1162 | gemPort: 1, |
| 1163 | intfID: 1, |
| 1164 | onuID: 1, |
| 1165 | uniID: 16, |
| 1166 | portNo: 1, |
| 1167 | TpInst: TpInst, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1168 | allocID: []uint32{0x8001}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1169 | gemPorts: []uint32{1, 2, 3, 4}, |
| 1170 | TpID: 64, |
| 1171 | uni: "16", |
| 1172 | }, |
| 1173 | }, |
| 1174 | { |
| 1175 | name: "checkAndAddFlow-3", |
| 1176 | args: args{ |
| 1177 | args: nil, |
| 1178 | classifierInfo: classifierInfo3, |
| 1179 | actionInfo: actionInfo3, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1180 | flow: flow3, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1181 | gemPort: 1, |
| 1182 | intfID: 1, |
| 1183 | onuID: 1, |
| 1184 | uniID: 16, |
| 1185 | portNo: 1, |
| 1186 | TpInst: TpInst, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1187 | allocID: []uint32{0x8001}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1188 | gemPorts: []uint32{1, 2, 3, 4}, |
| 1189 | TpID: 64, |
| 1190 | uni: "16", |
| 1191 | }, |
| 1192 | }, |
| 1193 | { |
| 1194 | name: "checkAndAddFlow-4", |
| 1195 | args: args{ |
| 1196 | args: nil, |
| 1197 | classifierInfo: classifierInfo4, |
| 1198 | actionInfo: actionInfo4, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1199 | flow: flow4, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1200 | gemPort: 1, |
| 1201 | intfID: 1, |
| 1202 | onuID: 1, |
| 1203 | uniID: 16, |
| 1204 | portNo: 1, |
| 1205 | TpInst: TpInst, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1206 | allocID: []uint32{0x8001}, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1207 | gemPorts: []uint32{1, 2, 3, 4}, |
| 1208 | TpID: 64, |
| 1209 | uni: "16", |
| 1210 | }, |
| 1211 | }, |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1212 | { |
| 1213 | name: "checkAndAddFlow-5", |
| 1214 | args: args{ |
| 1215 | args: nil, |
| 1216 | classifierInfo: classifierInfo5, |
| 1217 | actionInfo: actionInfo5, |
| 1218 | flow: flow5, |
| 1219 | gemPort: 1, |
| 1220 | intfID: 1, |
| 1221 | onuID: 1, |
| 1222 | uniID: 16, |
| 1223 | portNo: 1, |
| 1224 | TpInst: TpInst, |
| 1225 | allocID: []uint32{0x8001}, |
| 1226 | gemPorts: []uint32{1, 2, 3, 4}, |
| 1227 | TpID: 64, |
| 1228 | uni: "16", |
| 1229 | }, |
| 1230 | }, |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1231 | } |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1232 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1233 | defer cancel() |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1234 | for _, tt := range tests { |
| 1235 | t.Run(tt.name, func(t *testing.T) { |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 1236 | 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] | 1237 | tt.args.TpInst, tt.args.gemPorts, tt.args.TpID, tt.args.uni) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 1238 | }) |
| 1239 | } |
| 1240 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1241 | |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1242 | func TestOpenOltFlowMgr_TestMulticastFlowAndGroup(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1243 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1244 | defer cancel() |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1245 | //create group |
| 1246 | group := newGroup(2, []uint32{1}) |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 1247 | err := flowMgr[0].grpMgr.AddGroup(ctx, group) |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1248 | if err != nil { |
| 1249 | t.Error("group-add failed", err) |
| 1250 | return |
| 1251 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1252 | //create multicast flow |
| 1253 | multicastFlowArgs := &fu.FlowArgs{ |
| 1254 | MatchFields: []*ofp.OfpOxmOfbField{ |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1255 | fu.InPort(1048576), |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1256 | fu.VlanVid(660), //vlan |
| 1257 | fu.Metadata_ofp(uint64(66)), //inner vlan |
| 1258 | fu.EthType(0x800), //ipv4 |
| 1259 | fu.Ipv4Dst(3809869825), //227.22.0.1 |
| 1260 | }, |
| 1261 | Actions: []*ofp.OfpAction{ |
| 1262 | fu.Group(1), |
| 1263 | }, |
| 1264 | } |
divyadesai | d26f6b1 | 2020-03-19 06:30:28 +0000 | [diff] [blame] | 1265 | ofpStats, _ := fu.MkFlowStat(multicastFlowArgs) |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1266 | fmt.Println(ofpStats.Id) |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 1267 | err = flowMgr[0].AddFlow(ctx, ofpStats, &voltha.FlowMetadata{}) |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1268 | if err != nil { |
| 1269 | t.Error("Multicast flow-add failed", err) |
| 1270 | return |
| 1271 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1272 | |
| 1273 | //add bucket to the group |
| 1274 | group = newGroup(2, []uint32{1, 2}) |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 1275 | err = flowMgr[0].grpMgr.ModifyGroup(ctx, group) |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1276 | if err != nil { |
| 1277 | t.Error("modify-group failed", err) |
| 1278 | return |
| 1279 | } |
| 1280 | //remove the multicast flow |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 1281 | err = flowMgr[0].RemoveFlow(ctx, ofpStats) |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1282 | if err != nil { |
| 1283 | t.Error("Multicast flow-remove failed", err) |
| 1284 | return |
| 1285 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1286 | |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1287 | //remove the group |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 1288 | err = flowMgr[0].grpMgr.DeleteGroup(ctx, group) |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 1289 | if err != nil { |
| 1290 | t.Error("delete-group failed", err) |
| 1291 | return |
| 1292 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1293 | } |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1294 | |
| 1295 | func TestOpenOltFlowMgr_TestRouteFlowToOnuChannel(t *testing.T) { |
| 1296 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1297 | defer cancel() |
| 1298 | log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/core", log.DebugLevel) |
| 1299 | log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager", log.DebugLevel) |
| 1300 | log.SetPackageLogLevel("github.com/opencord/voltha-openolt-adapter/pkg/mocks", log.DebugLevel) |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1301 | kwTable1Meter1 := make(map[string]uint64) |
| 1302 | kwTable1Meter1["table_id"] = 1 |
| 1303 | kwTable1Meter1["meter_id"] = 1 |
| 1304 | kwTable1Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64 |
| 1305 | |
| 1306 | kwTable0Meter1 := make(map[string]uint64) |
| 1307 | kwTable0Meter1["table_id"] = 0 |
| 1308 | kwTable0Meter1["meter_id"] = 1 |
| 1309 | kwTable0Meter1["write_metadata"] = 0x4000000000 // Tech-Profile-ID 64 |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1310 | |
| 1311 | flowMetadata1 := voltha.FlowMetadata{Meters: []*voltha.OfpMeterConfig{ |
| 1312 | { |
| 1313 | Flags: 5, |
| 1314 | MeterId: 1, |
| 1315 | Bands: []*voltha.OfpMeterBandHeader{ |
| 1316 | { |
| 1317 | Type: voltha.OfpMeterBandType_OFPMBT_DROP, |
| 1318 | Rate: 16000, |
Gamze Abaka | 0117442 | 2021-03-10 06:55:27 +0000 | [diff] [blame] | 1319 | BurstSize: 0, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1320 | }, |
| 1321 | { |
| 1322 | Type: voltha.OfpMeterBandType_OFPMBT_DROP, |
| 1323 | Rate: 32000, |
| 1324 | BurstSize: 30, |
| 1325 | }, |
| 1326 | { |
| 1327 | Type: voltha.OfpMeterBandType_OFPMBT_DROP, |
| 1328 | Rate: 64000, |
| 1329 | BurstSize: 30, |
| 1330 | }, |
| 1331 | }, |
| 1332 | }, |
| 1333 | }} |
| 1334 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1335 | // Downstream LLDP Trap from NNI0 flow |
| 1336 | fa0 := &fu.FlowArgs{ |
| 1337 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1338 | fu.InPort(1048576), |
| 1339 | fu.EthType(35020), |
| 1340 | }, |
| 1341 | Actions: []*ofp.OfpAction{ |
| 1342 | fu.Output(4294967293), |
| 1343 | }, |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1344 | KV: make(map[string]uint64), |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | // Upstream flow DHCP flow - ONU1 UNI0 PON0 |
| 1348 | fa1 := &fu.FlowArgs{ |
| 1349 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1350 | fu.InPort(536870912), |
| 1351 | fu.Metadata_ofp(1), |
| 1352 | fu.IpProto(17), // dhcp |
| 1353 | fu.VlanPcp(0), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 1354 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)), |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1355 | fu.TunnelId(16), |
| 1356 | }, |
| 1357 | Actions: []*ofp.OfpAction{ |
| 1358 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 1359 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 1360 | fu.Output(2147483645), |
| 1361 | fu.PushVlan(0x8100), |
| 1362 | }, |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1363 | KV: kwTable1Meter1, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | // Upstream EAPOL - ONU1 UNI0 PON0 |
| 1367 | fa2 := &fu.FlowArgs{ |
| 1368 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1369 | fu.InPort(536870912), |
| 1370 | fu.Metadata_ofp(1), |
| 1371 | fu.EthType(0x888E), |
| 1372 | fu.VlanPcp(1), |
| 1373 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257), |
| 1374 | fu.TunnelId(16), |
| 1375 | }, |
| 1376 | Actions: []*ofp.OfpAction{ |
| 1377 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 1378 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 1379 | fu.Output(2147483645), |
| 1380 | fu.PushVlan(0x8100), |
| 1381 | }, |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1382 | KV: kwTable1Meter1, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | // Upstream HSIA - ONU1 UNI0 PON0 |
| 1386 | fa3 := &fu.FlowArgs{ |
| 1387 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1388 | fu.InPort(536870912), |
| 1389 | fu.Metadata_ofp(1), |
| 1390 | //fu.EthType(0x8100), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 1391 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)), |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1392 | fu.TunnelId(16), |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1393 | }, |
| 1394 | Actions: []*ofp.OfpAction{ |
| 1395 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 1396 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))), |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1397 | fu.Output(1048576), |
| 1398 | fu.PushVlan(0x8100), |
| 1399 | }, |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1400 | KV: kwTable1Meter1, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | // Downstream HSIA - ONU1 UNI0 PON0 |
| 1404 | fa4 := &fu.FlowArgs{ |
| 1405 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1406 | fu.InPort(1048576), |
| 1407 | fu.Metadata_ofp(1), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 1408 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)), |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1409 | fu.VlanPcp(1), |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1410 | fu.TunnelId(16), |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1411 | }, |
| 1412 | Actions: []*ofp.OfpAction{ |
| 1413 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 1414 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT))), |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1415 | fu.Output(536870912), |
| 1416 | fu.PopVlan(), |
| 1417 | }, |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1418 | KV: kwTable0Meter1, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | // Upstream flow DHCP flow - ONU1 UNI0 PON15 |
| 1422 | fa5 := &fu.FlowArgs{ |
| 1423 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1424 | fu.InPort(536870927), |
| 1425 | fu.Metadata_ofp(1), |
| 1426 | fu.IpProto(17), // dhcp |
| 1427 | fu.VlanPcp(0), |
Andrey Pozolotin | 32b3656 | 2021-06-02 10:23:26 +0300 | [diff] [blame^] | 1428 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT)), |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1429 | fu.TunnelId(16), |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1430 | }, |
| 1431 | Actions: []*ofp.OfpAction{ |
| 1432 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 1433 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259)), |
| 1434 | fu.Output(2147483645), |
| 1435 | fu.PushVlan(0x8100), |
| 1436 | }, |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1437 | KV: kwTable1Meter1, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1438 | } |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1439 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1440 | // Upstream EAPOL - ONU1 UNI0 PON15 |
| 1441 | fa6 := &fu.FlowArgs{ |
| 1442 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1443 | fu.InPort(536870927), |
| 1444 | fu.Metadata_ofp(1), |
| 1445 | fu.EthType(0x888E), |
| 1446 | fu.VlanPcp(1), |
| 1447 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259), |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1448 | fu.TunnelId(16), |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1449 | }, |
| 1450 | Actions: []*ofp.OfpAction{ |
| 1451 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 1452 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 1453 | fu.Output(2147483645), |
| 1454 | fu.PushVlan(0x8100), |
| 1455 | }, |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1456 | KV: kwTable1Meter1, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1457 | } |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1458 | |
| 1459 | // Upstream PPPOED - ONU1 UNI0 PON0 |
| 1460 | fa7 := &fu.FlowArgs{ |
| 1461 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1462 | fu.InPort(536870912), |
| 1463 | fu.Metadata_ofp(1), |
| 1464 | fu.EthType(0x8863), |
| 1465 | fu.VlanPcp(1), |
| 1466 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257), |
| 1467 | fu.TunnelId(16), |
| 1468 | }, |
| 1469 | Actions: []*ofp.OfpAction{ |
| 1470 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 1471 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 1472 | fu.Output(2147483645), |
| 1473 | fu.PushVlan(0x8100), |
| 1474 | }, |
| 1475 | KV: kwTable1Meter1, |
| 1476 | } |
| 1477 | |
| 1478 | // Upstream PPPOED - ONU1 UNI0 PON15 |
| 1479 | fa8 := &fu.FlowArgs{ |
| 1480 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 1481 | fu.InPort(536870927), |
| 1482 | fu.Metadata_ofp(1), |
| 1483 | fu.EthType(0x8863), |
| 1484 | fu.VlanPcp(1), |
| 1485 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 259), |
| 1486 | fu.TunnelId(16), |
| 1487 | }, |
| 1488 | Actions: []*ofp.OfpAction{ |
| 1489 | //fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA | 2))), |
| 1490 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 257)), |
| 1491 | fu.Output(2147483645), |
| 1492 | fu.PushVlan(0x8100), |
| 1493 | }, |
| 1494 | KV: kwTable1Meter1, |
| 1495 | } |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1496 | flow0, _ := fu.MkFlowStat(fa0) |
| 1497 | flow1, _ := fu.MkFlowStat(fa1) |
| 1498 | flow2, _ := fu.MkFlowStat(fa2) |
| 1499 | flow3, _ := fu.MkFlowStat(fa3) |
| 1500 | flow4, _ := fu.MkFlowStat(fa4) |
| 1501 | |
| 1502 | flow5, _ := fu.MkFlowStat(fa5) |
| 1503 | flow6, _ := fu.MkFlowStat(fa6) |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1504 | flow7, _ := fu.MkFlowStat(fa7) |
| 1505 | flow8, _ := fu.MkFlowStat(fa8) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1506 | |
| 1507 | type args struct { |
| 1508 | ctx context.Context |
| 1509 | flow *ofp.OfpFlowStats |
| 1510 | addFlow bool |
| 1511 | flowMetadata *voltha.FlowMetadata |
| 1512 | } |
| 1513 | tests := []struct { |
| 1514 | name string |
| 1515 | args args |
| 1516 | wantErr bool |
| 1517 | returnedErr error |
| 1518 | }{ |
| 1519 | { |
| 1520 | name: "RouteFlowToOnuChannel-0", |
| 1521 | args: args{ |
| 1522 | ctx: ctx, |
| 1523 | flow: flow0, |
| 1524 | addFlow: true, |
| 1525 | flowMetadata: &flowMetadata1, |
| 1526 | }, |
| 1527 | wantErr: false, |
| 1528 | }, |
| 1529 | { |
| 1530 | name: "RouteFlowToOnuChannel-1", |
| 1531 | args: args{ |
| 1532 | ctx: ctx, |
| 1533 | flow: flow1, |
| 1534 | addFlow: true, |
| 1535 | flowMetadata: &flowMetadata1, |
| 1536 | }, |
| 1537 | wantErr: false, |
| 1538 | }, |
| 1539 | { |
| 1540 | name: "RouteFlowToOnuChannel-2", |
| 1541 | args: args{ |
| 1542 | ctx: ctx, |
| 1543 | flow: flow2, |
| 1544 | addFlow: true, |
| 1545 | flowMetadata: &flowMetadata1, |
| 1546 | }, |
| 1547 | wantErr: false, |
| 1548 | }, |
| 1549 | { |
| 1550 | name: "RouteFlowToOnuChannel-3", |
| 1551 | args: args{ |
| 1552 | ctx: ctx, |
| 1553 | flow: flow3, |
| 1554 | addFlow: true, |
| 1555 | flowMetadata: &flowMetadata1, |
| 1556 | }, |
| 1557 | wantErr: false, |
| 1558 | }, |
| 1559 | { |
| 1560 | name: "RouteFlowToOnuChannel-4", |
| 1561 | args: args{ |
| 1562 | ctx: ctx, |
| 1563 | flow: flow4, |
| 1564 | addFlow: true, |
| 1565 | flowMetadata: &flowMetadata1, |
| 1566 | }, |
| 1567 | wantErr: false, |
| 1568 | }, |
| 1569 | { |
| 1570 | name: "RouteFlowToOnuChannel-5", |
| 1571 | args: args{ |
| 1572 | ctx: ctx, |
| 1573 | flow: flow1, |
| 1574 | addFlow: false, |
| 1575 | flowMetadata: &flowMetadata1, |
| 1576 | }, |
| 1577 | wantErr: false, |
| 1578 | }, |
| 1579 | { |
| 1580 | name: "RouteFlowToOnuChannel-6", |
| 1581 | args: args{ |
| 1582 | ctx: ctx, |
| 1583 | flow: flow1, |
| 1584 | addFlow: true, |
Girish Gowdra | 0aca498 | 2021-01-04 12:44:27 -0800 | [diff] [blame] | 1585 | flowMetadata: &flowMetadata1, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1586 | }, |
| 1587 | wantErr: true, |
| 1588 | }, |
| 1589 | { |
| 1590 | name: "RouteFlowToOnuChannel-7", |
| 1591 | args: args{ |
| 1592 | ctx: ctx, |
| 1593 | flow: flow5, |
| 1594 | addFlow: true, |
| 1595 | flowMetadata: &flowMetadata1, |
| 1596 | }, |
| 1597 | wantErr: false, |
| 1598 | }, |
| 1599 | { |
| 1600 | name: "RouteFlowToOnuChannel-8", |
| 1601 | args: args{ |
| 1602 | ctx: ctx, |
| 1603 | flow: flow6, |
| 1604 | addFlow: true, |
| 1605 | flowMetadata: &flowMetadata1, |
| 1606 | }, |
| 1607 | wantErr: false, |
| 1608 | }, |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1609 | { |
| 1610 | name: "RouteFlowToOnuChannel-9", |
| 1611 | args: args{ |
| 1612 | ctx: ctx, |
| 1613 | flow: flow7, |
| 1614 | addFlow: true, |
| 1615 | flowMetadata: &flowMetadata1, |
| 1616 | }, |
| 1617 | wantErr: false, |
| 1618 | }, |
| 1619 | { |
| 1620 | name: "RouteFlowToOnuChannel-10", |
| 1621 | args: args{ |
| 1622 | ctx: ctx, |
| 1623 | flow: flow8, |
| 1624 | addFlow: true, |
| 1625 | flowMetadata: &flowMetadata1, |
| 1626 | }, |
| 1627 | wantErr: false, |
| 1628 | }, |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
| 1631 | var wg sync.WaitGroup |
| 1632 | defer wg.Wait() // wait for all go routines to complete |
| 1633 | for _, tt := range tests { |
| 1634 | t.Run(tt.name, func(t *testing.T) { |
| 1635 | wg.Add(1) // one per go routine |
| 1636 | go func() { |
| 1637 | defer wg.Done() |
| 1638 | tt.returnedErr = flowMgr[0].RouteFlowToOnuChannel(tt.args.ctx, tt.args.flow, tt.args.addFlow, tt.args.flowMetadata) |
| 1639 | if (tt.wantErr == false && tt.returnedErr != nil) || (tt.wantErr == true && tt.returnedErr == nil) { |
| 1640 | t.Errorf("OpenOltFlowMgr.RouteFlowToOnuChannel() error = %v, wantErr %v", tt.returnedErr, tt.wantErr) |
| 1641 | } |
| 1642 | }() |
| 1643 | }) |
| 1644 | } |
| 1645 | } |