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