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