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