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