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