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