khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 16 | package flowdecomposition |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 17 | |
| 18 | import ( |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 19 | "context" |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 20 | "errors" |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 21 | "testing" |
| 22 | |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 23 | "github.com/opencord/voltha-go/rw_core/mocks" |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 24 | "github.com/opencord/voltha-go/rw_core/route" |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 25 | fu "github.com/opencord/voltha-lib-go/v3/pkg/flows" |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 26 | ofp "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 27 | "github.com/opencord/voltha-protos/v3/go/voltha" |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 28 | "github.com/stretchr/testify/assert" |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 29 | "google.golang.org/grpc/codes" |
| 30 | "google.golang.org/grpc/status" |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 31 | ) |
| 32 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 33 | type testDeviceManager struct { |
khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 34 | mocks.DeviceManager |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 35 | devices map[string]*voltha.Device |
| 36 | devicePorts map[string]map[uint32]*voltha.Port |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | func newTestDeviceManager() *testDeviceManager { |
| 40 | var tdm testDeviceManager |
| 41 | tdm.devices = make(map[string]*voltha.Device) |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 42 | tdm.devicePorts = make(map[string]map[uint32]*voltha.Port) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 43 | tdm.devices["olt"] = &voltha.Device{ |
| 44 | Id: "olt", |
| 45 | Root: true, |
| 46 | ParentId: "logical_device", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 47 | } |
| 48 | tdm.devicePorts["olt"] = map[uint32]*voltha.Port{ |
| 49 | 1: {PortNo: 1, Label: "pon"}, |
| 50 | 2: {PortNo: 2, Label: "nni"}, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 51 | } |
| 52 | tdm.devices["onu1"] = &voltha.Device{ |
| 53 | Id: "onu1", |
| 54 | Root: false, |
| 55 | ParentId: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 56 | } |
| 57 | tdm.devicePorts["onu1"] = map[uint32]*voltha.Port{ |
| 58 | 1: {PortNo: 1, Label: "pon"}, |
| 59 | 2: {PortNo: 2, Label: "uni"}, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 60 | } |
| 61 | tdm.devices["onu2"] = &voltha.Device{ |
| 62 | Id: "onu2", |
| 63 | Root: false, |
| 64 | ParentId: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 65 | } |
| 66 | tdm.devicePorts["onu2"] = map[uint32]*voltha.Port{ |
| 67 | 1: {PortNo: 1, Label: "pon"}, |
| 68 | 2: {PortNo: 2, Label: "uni"}, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 69 | } |
| 70 | tdm.devices["onu3"] = &voltha.Device{ |
| 71 | Id: "onu3", |
| 72 | Root: false, |
| 73 | ParentId: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 74 | } |
| 75 | tdm.devicePorts["onu3"] = map[uint32]*voltha.Port{ |
| 76 | 1: {PortNo: 1, Label: "pon"}, |
| 77 | 2: {PortNo: 2, Label: "uni"}, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 78 | } |
| 79 | tdm.devices["onu4"] = &voltha.Device{ |
| 80 | Id: "onu4", |
| 81 | Root: false, |
| 82 | ParentId: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 83 | } |
| 84 | tdm.devicePorts["onu4"] = map[uint32]*voltha.Port{ |
| 85 | 1: {PortNo: 1, Label: "pon"}, |
| 86 | 2: {PortNo: 2, Label: "uni"}, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 87 | } |
| 88 | return &tdm |
| 89 | } |
| 90 | |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 91 | func (tdm *testDeviceManager) GetDevice(ctx context.Context, deviceID *voltha.ID) (*voltha.Device, error) { |
| 92 | if d, ok := tdm.devices[deviceID.Id]; ok { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 93 | return d, nil |
| 94 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 95 | return nil, errors.New("ABSENT") |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 96 | } |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 97 | func (tdm *testDeviceManager) listDevicePorts(ctx context.Context, deviceID string) (map[uint32]*voltha.Port, error) { |
| 98 | ports, have := tdm.devicePorts[deviceID] |
| 99 | if !have { |
| 100 | return nil, errors.New("ABSENT") |
| 101 | } |
| 102 | return ports, nil |
| 103 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 104 | func (tdm *testDeviceManager) IsRootDevice(deviceID string) (bool, error) { |
| 105 | if d, ok := tdm.devices[deviceID]; ok { |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 106 | return d.Root, nil |
| 107 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 108 | return false, errors.New("ABSENT") |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 109 | } |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 110 | |
| 111 | type testFlowDecomposer struct { |
Esin Karaman | 09959ae | 2019-11-29 13:59:58 +0000 | [diff] [blame] | 112 | dMgr *testDeviceManager |
| 113 | logicalPorts map[uint32]*voltha.LogicalPort |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 114 | routes map[route.OFPortLink][]route.Hop |
Esin Karaman | 09959ae | 2019-11-29 13:59:58 +0000 | [diff] [blame] | 115 | defaultRules *fu.DeviceRules |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 116 | deviceRoutes *route.DeviceRoutes |
Esin Karaman | 09959ae | 2019-11-29 13:59:58 +0000 | [diff] [blame] | 117 | fd *FlowDecomposer |
| 118 | logicalPortsNo map[uint32]bool |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 119 | } |
| 120 | |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 121 | func newTestFlowDecomposer(t *testing.T, deviceMgr *testDeviceManager) *testFlowDecomposer { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 122 | var tfd testFlowDecomposer |
| 123 | tfd.dMgr = deviceMgr |
| 124 | |
| 125 | tfd.logicalPorts = make(map[uint32]*voltha.LogicalPort) |
Esin Karaman | 09959ae | 2019-11-29 13:59:58 +0000 | [diff] [blame] | 126 | tfd.logicalPortsNo = make(map[uint32]bool) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 127 | // Go protobuf interpreted absence of a port as 0, so we can't use port #0 as an openflow |
| 128 | // port |
| 129 | tfd.logicalPorts[10] = &voltha.LogicalPort{Id: "10", DeviceId: "olt", DevicePortNo: 2} |
Esin Karaman | 09959ae | 2019-11-29 13:59:58 +0000 | [diff] [blame] | 130 | tfd.logicalPorts[65536] = &voltha.LogicalPort{Id: "65536", DeviceId: "olt", DevicePortNo: 65536} |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 131 | tfd.logicalPorts[1] = &voltha.LogicalPort{Id: "1", DeviceId: "onu1", DevicePortNo: 2} |
| 132 | tfd.logicalPorts[2] = &voltha.LogicalPort{Id: "2", DeviceId: "onu2", DevicePortNo: 2} |
| 133 | tfd.logicalPorts[3] = &voltha.LogicalPort{Id: "3", DeviceId: "onu3", DevicePortNo: 2} |
| 134 | tfd.logicalPorts[4] = &voltha.LogicalPort{Id: "4", DeviceId: "onu4", DevicePortNo: 2} |
| 135 | |
Esin Karaman | 09959ae | 2019-11-29 13:59:58 +0000 | [diff] [blame] | 136 | tfd.logicalPortsNo[10] = false |
| 137 | tfd.logicalPortsNo[65536] = true // nni |
| 138 | |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 139 | tfd.routes = make(map[route.OFPortLink][]route.Hop) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 140 | |
| 141 | //DOWNSTREAM ROUTES |
| 142 | |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 143 | tfd.routes[route.OFPortLink{Ingress: 10, Egress: 1}] = []route.Hop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 144 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 145 | DeviceID: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 146 | Ingress: 2, |
| 147 | Egress: 1, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 148 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 149 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 150 | DeviceID: "onu1", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 151 | Ingress: 1, |
| 152 | Egress: 2, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 153 | }, |
| 154 | } |
| 155 | |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 156 | tfd.routes[route.OFPortLink{Ingress: 10, Egress: 2}] = []route.Hop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 157 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 158 | DeviceID: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 159 | Ingress: 2, |
| 160 | Egress: 1, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 161 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 162 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 163 | DeviceID: "onu2", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 164 | Ingress: 1, |
| 165 | Egress: 2, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 166 | }, |
| 167 | } |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 168 | tfd.routes[route.OFPortLink{Ingress: 10, Egress: 3}] = []route.Hop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 169 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 170 | DeviceID: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 171 | Ingress: 2, |
| 172 | Egress: 1, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 173 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 174 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 175 | DeviceID: "onu3", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 176 | Ingress: 1, |
| 177 | Egress: 2, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 178 | }, |
| 179 | } |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 180 | tfd.routes[route.OFPortLink{Ingress: 10, Egress: 4}] = []route.Hop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 181 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 182 | DeviceID: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 183 | Ingress: 2, |
| 184 | Egress: 1, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 185 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 186 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 187 | DeviceID: "onu4", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 188 | Ingress: 1, |
| 189 | Egress: 2, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 190 | }, |
| 191 | } |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 192 | tfd.routes[route.OFPortLink{Ingress: 10, Egress: 10}] = []route.Hop{ |
Humera Kouser | 4ff8901 | 2019-08-25 19:01:51 -0400 | [diff] [blame] | 193 | { |
| 194 | DeviceID: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 195 | Ingress: 2, |
| 196 | Egress: 2, |
Humera Kouser | 4ff8901 | 2019-08-25 19:01:51 -0400 | [diff] [blame] | 197 | }, |
| 198 | { |
| 199 | DeviceID: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 200 | Ingress: 2, |
| 201 | Egress: 2, |
Humera Kouser | 4ff8901 | 2019-08-25 19:01:51 -0400 | [diff] [blame] | 202 | }, |
| 203 | } |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 204 | |
| 205 | //UPSTREAM DATA PLANE |
| 206 | |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 207 | tfd.routes[route.OFPortLink{Ingress: 1, Egress: 10}] = []route.Hop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 208 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 209 | DeviceID: "onu1", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 210 | Ingress: 2, |
| 211 | Egress: 1, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 212 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 213 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 214 | DeviceID: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 215 | Ingress: 1, |
| 216 | Egress: 2, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 217 | }, |
| 218 | } |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 219 | tfd.routes[route.OFPortLink{Ingress: 2, Egress: 10}] = []route.Hop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 220 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 221 | DeviceID: "onu2", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 222 | Ingress: 2, |
| 223 | Egress: 1, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 224 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 225 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 226 | DeviceID: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 227 | Ingress: 1, |
| 228 | Egress: 2, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 229 | }, |
| 230 | } |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 231 | tfd.routes[route.OFPortLink{Ingress: 3, Egress: 10}] = []route.Hop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 232 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 233 | DeviceID: "onu3", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 234 | Ingress: 2, |
| 235 | Egress: 1, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 236 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 237 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 238 | DeviceID: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 239 | Ingress: 1, |
| 240 | Egress: 2, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 241 | }, |
| 242 | } |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 243 | tfd.routes[route.OFPortLink{Ingress: 4, Egress: 10}] = []route.Hop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 244 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 245 | DeviceID: "onu4", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 246 | Ingress: 2, |
| 247 | Egress: 1, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 248 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 249 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 250 | DeviceID: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 251 | Ingress: 1, |
| 252 | Egress: 2, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 253 | }, |
| 254 | } |
| 255 | |
| 256 | //UPSTREAM NEXT TABLE BASED |
| 257 | |
| 258 | // openflow port 0 means absence of a port - go/protobuf interpretation |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 259 | tfd.routes[route.OFPortLink{Ingress: 1, Egress: 0}] = []route.Hop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 260 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 261 | DeviceID: "onu1", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 262 | Ingress: 2, |
| 263 | Egress: 1, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 264 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 265 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 266 | DeviceID: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 267 | Ingress: 1, |
| 268 | Egress: 2, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 269 | }, |
| 270 | } |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 271 | tfd.routes[route.OFPortLink{Ingress: 2, Egress: 0}] = []route.Hop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 272 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 273 | DeviceID: "onu2", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 274 | Ingress: 2, |
| 275 | Egress: 1, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 276 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 277 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 278 | DeviceID: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 279 | Ingress: 1, |
| 280 | Egress: 2, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 281 | }, |
| 282 | } |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 283 | tfd.routes[route.OFPortLink{Ingress: 3, Egress: 0}] = []route.Hop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 284 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 285 | DeviceID: "onu3", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 286 | Ingress: 2, |
| 287 | Egress: 1, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 288 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 289 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 290 | DeviceID: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 291 | Ingress: 1, |
| 292 | Egress: 2, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 293 | }, |
| 294 | } |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 295 | tfd.routes[route.OFPortLink{Ingress: 4, Egress: 0}] = []route.Hop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 296 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 297 | DeviceID: "onu4", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 298 | Ingress: 2, |
| 299 | Egress: 1, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 300 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 301 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 302 | DeviceID: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 303 | Ingress: 1, |
| 304 | Egress: 2, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 305 | }, |
| 306 | } |
| 307 | |
| 308 | // DOWNSTREAM NEXT TABLE BASED |
| 309 | |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 310 | tfd.routes[route.OFPortLink{Ingress: 10, Egress: 0}] = []route.Hop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 311 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 312 | DeviceID: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 313 | Ingress: 2, |
| 314 | Egress: 1, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 315 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 316 | {}, // 2nd hop is not known yet |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 317 | } |
| 318 | |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 319 | tfd.routes[route.OFPortLink{Ingress: 0, Egress: 10}] = []route.Hop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 320 | {}, // 1st hop is wildcard |
| 321 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 322 | DeviceID: "olt", |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 323 | Ingress: 1, |
| 324 | Egress: 2, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 325 | }, |
| 326 | } |
| 327 | |
| 328 | // DEFAULT RULES |
| 329 | |
| 330 | tfd.defaultRules = fu.NewDeviceRules() |
| 331 | fg := fu.NewFlowsAndGroups() |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 332 | fa := &fu.FlowArgs{ |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 333 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 334 | fu.InPort(2), |
| 335 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 336 | }, |
| 337 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 338 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 339 | fu.Output(1), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 340 | }, |
| 341 | } |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 342 | fs, err := fu.MkFlowStat(fa) |
| 343 | assert.Nil(t, err) |
| 344 | fg.AddFlow(fs) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 345 | tfd.defaultRules.AddFlowsAndGroup("onu1", fg) |
| 346 | |
| 347 | fg = fu.NewFlowsAndGroups() |
| 348 | fa = &fu.FlowArgs{ |
| 349 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 350 | fu.InPort(2), |
| 351 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 352 | }, |
| 353 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 354 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 102)), |
| 355 | fu.Output(1), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 356 | }, |
| 357 | } |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 358 | fs, err = fu.MkFlowStat(fa) |
| 359 | assert.Nil(t, err) |
| 360 | fg.AddFlow(fs) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 361 | tfd.defaultRules.AddFlowsAndGroup("onu2", fg) |
| 362 | |
| 363 | fg = fu.NewFlowsAndGroups() |
| 364 | fa = &fu.FlowArgs{ |
| 365 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 366 | fu.InPort(2), |
| 367 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 368 | }, |
| 369 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 370 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 103)), |
| 371 | fu.Output(1), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 372 | }, |
| 373 | } |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 374 | fs, err = fu.MkFlowStat(fa) |
| 375 | assert.Nil(t, err) |
| 376 | fg.AddFlow(fs) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 377 | tfd.defaultRules.AddFlowsAndGroup("onu3", fg) |
| 378 | |
| 379 | fg = fu.NewFlowsAndGroups() |
| 380 | fa = &fu.FlowArgs{ |
| 381 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 382 | fu.InPort(2), |
| 383 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 384 | }, |
| 385 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 386 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 104)), |
| 387 | fu.Output(1), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 388 | }, |
| 389 | } |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 390 | fs, err = fu.MkFlowStat(fa) |
| 391 | assert.Nil(t, err) |
| 392 | fg.AddFlow(fs) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 393 | tfd.defaultRules.AddFlowsAndGroup("onu4", fg) |
| 394 | |
| 395 | //Set up the device graph - flow decomposer uses it only to verify whether a port is a root port. |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame^] | 396 | tfd.deviceRoutes = route.NewDeviceRoutes("ldid", "olt", tfd.dMgr.listDevicePorts) |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 397 | tfd.deviceRoutes.RootPorts = make(map[uint32]uint32) |
| 398 | tfd.deviceRoutes.RootPorts[10] = 10 |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 399 | |
| 400 | tfd.fd = NewFlowDecomposer(tfd.dMgr) |
| 401 | |
| 402 | return &tfd |
| 403 | } |
| 404 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 405 | func (tfd *testFlowDecomposer) GetDeviceLogicalID() string { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 406 | return "" |
| 407 | } |
| 408 | |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 409 | func (tfd *testFlowDecomposer) GetLogicalDevice(ctx context.Context) (*voltha.LogicalDevice, error) { |
| 410 | return nil, nil |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 411 | } |
| 412 | |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 413 | func (tfd *testFlowDecomposer) GetDeviceRoutes() *route.DeviceRoutes { |
| 414 | return tfd.deviceRoutes |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | func (tfd *testFlowDecomposer) GetAllDefaultRules() *fu.DeviceRules { |
| 418 | return tfd.defaultRules |
| 419 | } |
| 420 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 421 | func (tfd *testFlowDecomposer) GetWildcardInputPorts(ctx context.Context, excludePort uint32) map[uint32]struct{} { |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 422 | lPorts := make(map[uint32]struct{}) |
| 423 | for portNo := range tfd.logicalPorts { |
| 424 | if portNo != excludePort { |
| 425 | lPorts[portNo] = struct{}{} |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | return lPorts |
| 429 | } |
| 430 | |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 431 | func (tfd *testFlowDecomposer) GetRoute(ctx context.Context, ingressPortNo uint32, egressPortNo uint32) ([]route.Hop, error) { |
| 432 | var portLink route.OFPortLink |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 433 | if egressPortNo == 0 { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 434 | portLink.Egress = 0 |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 435 | } else if egressPortNo&0x7fffffff == uint32(ofp.OfpPortNo_OFPP_CONTROLLER) { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 436 | portLink.Egress = 10 |
| 437 | } else { |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 438 | portLink.Egress = egressPortNo |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 439 | } |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 440 | if ingressPortNo == 0 { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 441 | portLink.Ingress = 0 |
| 442 | } else { |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 443 | portLink.Ingress = ingressPortNo |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 444 | } |
| 445 | for key, val := range tfd.routes { |
| 446 | if key.Ingress == portLink.Ingress && key.Egress == portLink.Egress { |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 447 | return val, nil |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 448 | } |
| 449 | } |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 450 | return nil, status.Errorf(codes.FailedPrecondition, "no route from:%d to:%d", ingressPortNo, egressPortNo) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 451 | } |
| 452 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 453 | func (tfd *testFlowDecomposer) GetNNIPorts() map[uint32]struct{} { |
| 454 | nniPorts := make(map[uint32]struct{}) |
Esin Karaman | 09959ae | 2019-11-29 13:59:58 +0000 | [diff] [blame] | 455 | for portNo, nni := range tfd.logicalPortsNo { |
| 456 | if nni { |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 457 | nniPorts[portNo] = struct{}{} |
Esin Karaman | 09959ae | 2019-11-29 13:59:58 +0000 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | return nniPorts |
| 461 | } |
| 462 | |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 463 | func TestEapolReRouteRuleVlanDecomposition(t *testing.T) { |
| 464 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 465 | fa := &fu.FlowArgs{ |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 466 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 467 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 468 | fu.InPort(1), |
| 469 | fu.VlanVid(50), |
| 470 | fu.EthType(0x888e), |
| 471 | }, |
| 472 | Actions: []*ofp.OfpAction{ |
| 473 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 474 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 475 | }, |
| 476 | } |
| 477 | |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 478 | fs, err := fu.MkFlowStat(fa) |
| 479 | assert.Nil(t, err) |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 480 | flows := map[uint64]*ofp.OfpFlowStats{fs.Id: fs} |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 481 | tfd := newTestFlowDecomposer(t, newTestDeviceManager()) |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 482 | |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 483 | deviceRules, err := tfd.fd.DecomposeRules(context.Background(), tfd, flows, nil) |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 484 | assert.Nil(t, err) |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 485 | onu1FlowAndGroup := deviceRules.Rules["onu1"] |
| 486 | oltFlowAndGroup := deviceRules.Rules["olt"] |
| 487 | assert.Equal(t, 1, onu1FlowAndGroup.Flows.Len()) |
| 488 | assert.Equal(t, 1, oltFlowAndGroup.Flows.Len()) |
| 489 | assert.Equal(t, 0, oltFlowAndGroup.Groups.Len()) |
| 490 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 491 | faParent := &fu.FlowArgs{ |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 492 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 493 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 494 | fu.InPort(1), |
| 495 | fu.TunnelId(uint64(1)), |
| 496 | fu.VlanVid(50), |
| 497 | fu.EthType(0x888e), |
| 498 | }, |
| 499 | Actions: []*ofp.OfpAction{ |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 500 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 501 | }, |
| 502 | } |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 503 | expectedOltFlow, err := fu.MkFlowStat(faParent) |
| 504 | assert.Nil(t, err) |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 505 | derivedFlow := oltFlowAndGroup.GetFlow(0) |
| 506 | assert.Equal(t, expectedOltFlow.String(), derivedFlow.String()) |
| 507 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 508 | faChild := &fu.FlowArgs{ |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 509 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 510 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 511 | fu.InPort(2), |
| 512 | fu.TunnelId(uint64(1)), |
| 513 | fu.EthType(0x888e), |
| 514 | }, |
| 515 | Actions: []*ofp.OfpAction{ |
| 516 | fu.PushVlan(0x8100), |
| 517 | fu.SetField(fu.VlanVid(50)), |
| 518 | fu.Output(1), |
| 519 | }, |
| 520 | } |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 521 | expectedOnuFlow, err := fu.MkFlowStat(faChild) |
| 522 | assert.Nil(t, err) |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 523 | derivedFlow = onu1FlowAndGroup.GetFlow(0) |
| 524 | assert.Equal(t, expectedOnuFlow.String(), derivedFlow.String()) |
| 525 | } |
| 526 | |
| 527 | func TestEapolReRouteRuleZeroVlanDecomposition(t *testing.T) { |
| 528 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 529 | fa := &fu.FlowArgs{ |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 530 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 531 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 532 | fu.InPort(1), |
| 533 | fu.VlanVid(0), |
| 534 | fu.EthType(0x888e), |
| 535 | }, |
| 536 | Actions: []*ofp.OfpAction{ |
| 537 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 538 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 539 | }, |
| 540 | } |
| 541 | |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 542 | fs, err := fu.MkFlowStat(fa) |
| 543 | assert.Nil(t, err) |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 544 | flows := map[uint64]*ofp.OfpFlowStats{fs.Id: fs} |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 545 | tfd := newTestFlowDecomposer(t, newTestDeviceManager()) |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 546 | |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 547 | deviceRules, err := tfd.fd.DecomposeRules(context.Background(), tfd, flows, nil) |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 548 | assert.Nil(t, err) |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 549 | onu1FlowAndGroup := deviceRules.Rules["onu1"] |
| 550 | oltFlowAndGroup := deviceRules.Rules["olt"] |
| 551 | assert.Equal(t, 1, onu1FlowAndGroup.Flows.Len()) |
| 552 | assert.Equal(t, 1, oltFlowAndGroup.Flows.Len()) |
| 553 | assert.Equal(t, 0, oltFlowAndGroup.Groups.Len()) |
| 554 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 555 | faParent := &fu.FlowArgs{ |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 556 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 557 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 558 | fu.InPort(1), |
| 559 | fu.TunnelId(uint64(1)), |
| 560 | fu.VlanVid(0), |
| 561 | fu.EthType(0x888e), |
| 562 | }, |
| 563 | Actions: []*ofp.OfpAction{ |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 564 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 565 | }, |
| 566 | } |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 567 | expectedOltFlow, err := fu.MkFlowStat(faParent) |
| 568 | assert.Nil(t, err) |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 569 | derivedFlow := oltFlowAndGroup.GetFlow(0) |
| 570 | assert.Equal(t, expectedOltFlow.String(), derivedFlow.String()) |
| 571 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 572 | faChild := &fu.FlowArgs{ |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 573 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 574 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 575 | fu.InPort(2), |
| 576 | fu.TunnelId(uint64(1)), |
| 577 | fu.EthType(0x888e), |
| 578 | }, |
| 579 | Actions: []*ofp.OfpAction{ |
| 580 | fu.PushVlan(0x8100), |
| 581 | fu.SetField(fu.VlanVid(0)), |
| 582 | fu.Output(1), |
| 583 | }, |
| 584 | } |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 585 | expectedOnuFlow, err := fu.MkFlowStat(faChild) |
| 586 | assert.Nil(t, err) |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 587 | derivedFlow = onu1FlowAndGroup.GetFlow(0) |
| 588 | assert.Equal(t, expectedOnuFlow.String(), derivedFlow.String()) |
| 589 | } |
| 590 | |
| 591 | func TestEapolReRouteRuleNoVlanDecomposition(t *testing.T) { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 592 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 593 | fa := &fu.FlowArgs{ |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 594 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 595 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 596 | fu.InPort(1), |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 597 | fu.EthType(0x888e), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 598 | }, |
| 599 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 600 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 601 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 602 | }, |
| 603 | } |
| 604 | |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 605 | fs, err := fu.MkFlowStat(fa) |
| 606 | assert.Nil(t, err) |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 607 | flows := map[uint64]*ofp.OfpFlowStats{fs.Id: fs} |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 608 | tfd := newTestFlowDecomposer(t, newTestDeviceManager()) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 609 | |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 610 | deviceRules, err := tfd.fd.DecomposeRules(context.Background(), tfd, flows, nil) |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 611 | assert.Nil(t, err) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 612 | onu1FlowAndGroup := deviceRules.Rules["onu1"] |
| 613 | oltFlowAndGroup := deviceRules.Rules["olt"] |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 614 | assert.Equal(t, 1, onu1FlowAndGroup.Flows.Len()) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 615 | assert.Equal(t, 1, oltFlowAndGroup.Flows.Len()) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 616 | assert.Equal(t, 0, oltFlowAndGroup.Groups.Len()) |
| 617 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 618 | faParent := &fu.FlowArgs{ |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 619 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 620 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 621 | fu.InPort(1), |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 622 | fu.TunnelId(uint64(1)), |
| 623 | fu.EthType(0x888e), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 624 | }, |
| 625 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 626 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 627 | }, |
| 628 | } |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 629 | expectedOltFlow, err := fu.MkFlowStat(faParent) |
| 630 | assert.Nil(t, err) |
khenaidoo | 3306c99 | 2019-05-24 16:57:35 -0400 | [diff] [blame] | 631 | derivedFlow := oltFlowAndGroup.GetFlow(0) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 632 | assert.Equal(t, expectedOltFlow.String(), derivedFlow.String()) |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 633 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 634 | faChild := &fu.FlowArgs{ |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 635 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 636 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 637 | fu.InPort(2), |
| 638 | fu.TunnelId(uint64(1)), |
| 639 | fu.EthType(0x888e), |
| 640 | }, |
| 641 | Actions: []*ofp.OfpAction{ |
| 642 | fu.Output(1), |
| 643 | }, |
| 644 | } |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 645 | expectedOnuFlow, err := fu.MkFlowStat(faChild) |
| 646 | assert.Nil(t, err) |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 647 | derivedFlow = onu1FlowAndGroup.GetFlow(0) |
| 648 | assert.Equal(t, expectedOnuFlow.String(), derivedFlow.String()) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | func TestDhcpReRouteRuleDecomposition(t *testing.T) { |
| 652 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 653 | fa := &fu.FlowArgs{ |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 654 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 655 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 656 | fu.InPort(1), |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 657 | fu.EthType(0x0800), |
| 658 | fu.Ipv4Dst(0xffffffff), |
| 659 | fu.IpProto(17), |
| 660 | fu.UdpSrc(68), |
| 661 | fu.UdpDst(67), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 662 | }, |
| 663 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 664 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 665 | }, |
| 666 | } |
| 667 | |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 668 | fs, err := fu.MkFlowStat(fa) |
| 669 | assert.Nil(t, err) |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 670 | flows := map[uint64]*ofp.OfpFlowStats{fs.Id: fs} |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 671 | tfd := newTestFlowDecomposer(t, newTestDeviceManager()) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 672 | |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 673 | deviceRules, err := tfd.fd.DecomposeRules(context.Background(), tfd, flows, nil) |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 674 | assert.Nil(t, err) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 675 | onu1FlowAndGroup := deviceRules.Rules["onu1"] |
| 676 | oltFlowAndGroup := deviceRules.Rules["olt"] |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 677 | assert.Equal(t, 1, onu1FlowAndGroup.Flows.Len()) |
| 678 | assert.Equal(t, 0, onu1FlowAndGroup.Groups.Len()) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 679 | assert.Equal(t, 1, oltFlowAndGroup.Flows.Len()) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 680 | assert.Equal(t, 0, oltFlowAndGroup.Groups.Len()) |
| 681 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 682 | faParent := &fu.FlowArgs{ |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 683 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 684 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 685 | fu.InPort(1), |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 686 | fu.TunnelId(uint64(1)), |
| 687 | fu.EthType(0x0800), |
| 688 | fu.Ipv4Dst(0xffffffff), |
| 689 | fu.IpProto(17), |
| 690 | fu.UdpSrc(68), |
| 691 | fu.UdpDst(67), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 692 | }, |
| 693 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 694 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 695 | }, |
| 696 | } |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 697 | expectedOltFlow, err := fu.MkFlowStat(faParent) |
| 698 | assert.Nil(t, err) |
khenaidoo | 3306c99 | 2019-05-24 16:57:35 -0400 | [diff] [blame] | 699 | derivedFlow := oltFlowAndGroup.GetFlow(0) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 700 | assert.Equal(t, expectedOltFlow.String(), derivedFlow.String()) |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 701 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 702 | faChild := &fu.FlowArgs{ |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 703 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 704 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 705 | fu.InPort(2), |
| 706 | fu.TunnelId(uint64(1)), |
| 707 | fu.EthType(0x0800), |
| 708 | fu.Ipv4Dst(0xffffffff), |
| 709 | fu.IpProto(17), |
| 710 | fu.UdpSrc(68), |
| 711 | fu.UdpDst(67), |
| 712 | }, |
| 713 | Actions: []*ofp.OfpAction{ |
| 714 | fu.Output(1), |
| 715 | }, |
| 716 | } |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 717 | expectedOnuFlow, err := fu.MkFlowStat(faChild) |
| 718 | assert.Nil(t, err) |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 719 | derivedFlow = onu1FlowAndGroup.GetFlow(0) |
| 720 | assert.Equal(t, expectedOnuFlow.String(), derivedFlow.String()) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 721 | } |
| 722 | |
Humera Kouser | 4ff8901 | 2019-08-25 19:01:51 -0400 | [diff] [blame] | 723 | func TestLldpReRouteRuleDecomposition(t *testing.T) { |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 724 | fa := &fu.FlowArgs{ |
Humera Kouser | 4ff8901 | 2019-08-25 19:01:51 -0400 | [diff] [blame] | 725 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 726 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 727 | fu.InPort(10), |
| 728 | fu.EthType(0x88CC), |
| 729 | }, |
| 730 | Actions: []*ofp.OfpAction{ |
| 731 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 732 | }, |
| 733 | } |
| 734 | |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 735 | fs, err := fu.MkFlowStat(fa) |
| 736 | assert.Nil(t, err) |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 737 | flows := map[uint64]*ofp.OfpFlowStats{fs.Id: fs} |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 738 | tfd := newTestFlowDecomposer(t, newTestDeviceManager()) |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 739 | deviceRules, err := tfd.fd.DecomposeRules(context.Background(), tfd, flows, nil) |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 740 | assert.Nil(t, err) |
Humera Kouser | 4ff8901 | 2019-08-25 19:01:51 -0400 | [diff] [blame] | 741 | onu1FlowAndGroup := deviceRules.Rules["onu1"] |
| 742 | oltFlowAndGroup := deviceRules.Rules["olt"] |
| 743 | assert.Nil(t, onu1FlowAndGroup) |
| 744 | assert.Equal(t, 1, oltFlowAndGroup.Flows.Len()) |
| 745 | assert.Equal(t, 0, oltFlowAndGroup.Groups.Len()) |
| 746 | |
| 747 | fa = &fu.FlowArgs{ |
| 748 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 749 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 750 | fu.InPort(2), |
| 751 | fu.EthType(0x88CC), |
| 752 | }, |
| 753 | Actions: []*ofp.OfpAction{ |
| 754 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
| 755 | }, |
| 756 | } |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 757 | expectedOltFlow, err := fu.MkFlowStat(fa) |
| 758 | assert.Nil(t, err) |
Humera Kouser | 4ff8901 | 2019-08-25 19:01:51 -0400 | [diff] [blame] | 759 | derivedFlow := oltFlowAndGroup.GetFlow(0) |
| 760 | assert.Equal(t, expectedOltFlow.String(), derivedFlow.String()) |
| 761 | } |
| 762 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 763 | func TestUnicastUpstreamRuleDecomposition(t *testing.T) { |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 764 | fa := &fu.FlowArgs{ |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 765 | KV: fu.OfpFlowModArgs{"priority": 5000, "table_id": 0}, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 766 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 767 | fu.InPort(1), |
| 768 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 769 | fu.VlanPcp(0), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 770 | }, |
| 771 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 772 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 773 | }, |
| 774 | } |
| 775 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 776 | fa2 := &fu.FlowArgs{ |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 777 | KV: fu.OfpFlowModArgs{"priority": 500, "table_id": 1}, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 778 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 779 | fu.InPort(1), |
| 780 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101), |
| 781 | fu.VlanPcp(0), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 782 | }, |
| 783 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 784 | fu.PushVlan(0x8100), |
| 785 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 1000)), |
| 786 | fu.SetField(fu.VlanPcp(0)), |
| 787 | fu.Output(10), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 788 | }, |
| 789 | } |
| 790 | |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 791 | fs, err := fu.MkFlowStat(fa) |
| 792 | assert.Nil(t, err) |
| 793 | fs2, err := fu.MkFlowStat(fa2) |
| 794 | assert.Nil(t, err) |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 795 | |
| 796 | fs.Instructions = []*ofp.OfpInstruction{{ |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 797 | Type: uint32(ofp.OfpInstructionType_OFPIT_GOTO_TABLE), |
| 798 | Data: &ofp.OfpInstruction_GotoTable{ |
| 799 | GotoTable: &ofp.OfpInstructionGotoTable{ |
| 800 | TableId: 1, |
| 801 | }, |
| 802 | }}} |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 803 | flows := map[uint64]*ofp.OfpFlowStats{fs.Id: fs, fs2.Id: fs2} |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 804 | |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 805 | tfd := newTestFlowDecomposer(t, newTestDeviceManager()) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 806 | |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 807 | deviceRules, err := tfd.fd.DecomposeRules(context.Background(), tfd, flows, nil) |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 808 | assert.Nil(t, err) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 809 | onu1FlowAndGroup := deviceRules.Rules["onu1"] |
| 810 | oltFlowAndGroup := deviceRules.Rules["olt"] |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 811 | assert.NotNil(t, onu1FlowAndGroup) |
| 812 | assert.NotNil(t, onu1FlowAndGroup.Flows) |
khenaidoo | 3306c99 | 2019-05-24 16:57:35 -0400 | [diff] [blame] | 813 | assert.Equal(t, 1, onu1FlowAndGroup.Flows.Len()) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 814 | assert.Equal(t, 0, onu1FlowAndGroup.Groups.Len()) |
| 815 | assert.Equal(t, 1, oltFlowAndGroup.Flows.Len()) |
| 816 | assert.Equal(t, 0, oltFlowAndGroup.Groups.Len()) |
| 817 | |
| 818 | fa = &fu.FlowArgs{ |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 819 | KV: fu.OfpFlowModArgs{"priority": 5000}, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 820 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 821 | fu.InPort(2), |
| 822 | fu.TunnelId(uint64(1)), |
| 823 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 824 | fu.VlanPcp(0), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 825 | }, |
| 826 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 827 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 828 | fu.Output(1), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 829 | }, |
| 830 | } |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 831 | |
khenaidoo | 3306c99 | 2019-05-24 16:57:35 -0400 | [diff] [blame] | 832 | derivedFlow := onu1FlowAndGroup.GetFlow(0) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 833 | // Form the expected flow |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 834 | expectedOnu1Flow, err := fu.MkFlowStat(fa) |
| 835 | assert.Nil(t, err) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 836 | expectedOnu1Flow.Instructions = []*ofp.OfpInstruction{{ |
| 837 | Type: uint32(ofp.OfpInstructionType_OFPIT_APPLY_ACTIONS), |
| 838 | Data: &ofp.OfpInstruction_Actions{ |
| 839 | Actions: &ofp.OfpInstructionActions{ |
| 840 | Actions: []*ofp.OfpAction{{ |
| 841 | Type: 0, |
| 842 | Action: &ofp.OfpAction_Output{ |
| 843 | Output: &ofp.OfpActionOutput{ |
| 844 | Port: 1, |
| 845 | MaxLen: 65509, |
| 846 | }, |
| 847 | }}}}}}} |
| 848 | |
| 849 | expectedOnu1Flow.Id = derivedFlow.Id // Assign same flow ID as derived flowID to match completely |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 850 | assert.Equal(t, expectedOnu1Flow.String(), derivedFlow.String()) |
| 851 | |
| 852 | fa = &fu.FlowArgs{ |
| 853 | KV: fu.OfpFlowModArgs{"priority": 500}, |
| 854 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 855 | fu.InPort(1), |
| 856 | fu.TunnelId(uint64(1)), |
| 857 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101), |
| 858 | fu.VlanPcp(0), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 859 | }, |
| 860 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 861 | fu.PushVlan(0x8100), |
| 862 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 1000)), |
| 863 | fu.SetField(fu.VlanPcp(0)), |
| 864 | fu.Output(2), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 865 | }, |
| 866 | } |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 867 | expectedOltFlow, err := fu.MkFlowStat(fa) |
| 868 | assert.Nil(t, err) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 869 | derivedFlow = oltFlowAndGroup.GetFlow(0) |
| 870 | assert.Equal(t, expectedOltFlow.String(), derivedFlow.String()) |
| 871 | } |
| 872 | |
| 873 | func TestUnicastDownstreamRuleDecomposition(t *testing.T) { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 874 | ctx := context.Background() |
| 875 | logger.Debugf(ctx, "Starting Test Unicast Downstream") |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 876 | fa1 := &fu.FlowArgs{ |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 877 | KV: fu.OfpFlowModArgs{"priority": 500, "table_id": 0}, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 878 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 879 | fu.InPort(10), |
| 880 | fu.Metadata_ofp((1000 << 32) | 1), |
| 881 | fu.VlanPcp(0), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 882 | }, |
| 883 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 884 | fu.PopVlan(), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 885 | }, |
| 886 | } |
| 887 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 888 | fa2 := &fu.FlowArgs{ |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 889 | KV: fu.OfpFlowModArgs{"priority": 500, "table_id": 1}, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 890 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 891 | fu.InPort(10), |
| 892 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101), |
| 893 | fu.VlanPcp(0), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 894 | }, |
| 895 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 896 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)), |
| 897 | fu.Output(1), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 898 | }, |
| 899 | } |
| 900 | |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 901 | fs1, err := fu.MkFlowStat(fa1) |
| 902 | assert.Nil(t, err) |
| 903 | fs2, err := fu.MkFlowStat(fa2) |
| 904 | assert.Nil(t, err) |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 905 | fs1.Instructions = []*ofp.OfpInstruction{{ |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 906 | Type: uint32(ofp.OfpInstructionType_OFPIT_GOTO_TABLE), |
| 907 | Data: &ofp.OfpInstruction_GotoTable{ |
| 908 | GotoTable: &ofp.OfpInstructionGotoTable{ |
| 909 | TableId: 1, |
| 910 | }, |
| 911 | }}} |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 912 | flows := map[uint64]*ofp.OfpFlowStats{fs1.Id: fs1, fs2.Id: fs2} |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 913 | |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 914 | tfd := newTestFlowDecomposer(t, newTestDeviceManager()) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 915 | |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 916 | deviceRules, err := tfd.fd.DecomposeRules(context.Background(), tfd, flows, nil) |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 917 | assert.Nil(t, err) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 918 | onu1FlowAndGroup := deviceRules.Rules["onu1"] |
| 919 | oltFlowAndGroup := deviceRules.Rules["olt"] |
khenaidoo | 3306c99 | 2019-05-24 16:57:35 -0400 | [diff] [blame] | 920 | assert.Equal(t, 1, onu1FlowAndGroup.Flows.Len()) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 921 | assert.Equal(t, 0, onu1FlowAndGroup.Groups.Len()) |
| 922 | assert.Equal(t, 1, oltFlowAndGroup.Flows.Len()) |
| 923 | assert.Equal(t, 0, oltFlowAndGroup.Groups.Len()) |
| 924 | |
| 925 | fa1 = &fu.FlowArgs{ |
| 926 | KV: fu.OfpFlowModArgs{"priority": 500}, |
| 927 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 928 | fu.InPort(2), |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 929 | fu.TunnelId(uint64(10)), |
| 930 | fu.Metadata_ofp(4294967296001), |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 931 | fu.VlanPcp(0), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 932 | }, |
| 933 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 934 | fu.PopVlan(), |
| 935 | fu.Output(1), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 936 | }, |
| 937 | } |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 938 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 939 | derivedFlow := oltFlowAndGroup.GetFlow(0) |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 940 | expectedOltFlow, err := fu.MkFlowStat(fa1) |
| 941 | assert.Nil(t, err) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 942 | expectedOltFlow.Instructions = []*ofp.OfpInstruction{{ |
| 943 | Type: uint32(ofp.OfpInstructionType_OFPIT_APPLY_ACTIONS), |
| 944 | Data: &ofp.OfpInstruction_Actions{ |
| 945 | Actions: &ofp.OfpInstructionActions{ |
| 946 | Actions: []*ofp.OfpAction{{ |
| 947 | Type: 0, |
| 948 | Action: &ofp.OfpAction_Output{ |
| 949 | Output: &ofp.OfpActionOutput{ |
| 950 | Port: 1, |
| 951 | MaxLen: 65509, |
| 952 | }, |
| 953 | }}}}}}} |
| 954 | expectedOltFlow.Id = derivedFlow.Id |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 955 | assert.Equal(t, expectedOltFlow.String(), derivedFlow.String()) |
| 956 | |
| 957 | fa1 = &fu.FlowArgs{ |
| 958 | KV: fu.OfpFlowModArgs{"priority": 500}, |
| 959 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 960 | fu.InPort(1), |
| 961 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101), |
| 962 | fu.VlanPcp(0), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 963 | }, |
| 964 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 965 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)), |
| 966 | fu.Output(2), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 967 | }, |
| 968 | } |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 969 | expectedOnu1Flow, err := fu.MkFlowStat(fa1) |
| 970 | assert.Nil(t, err) |
khenaidoo | 3306c99 | 2019-05-24 16:57:35 -0400 | [diff] [blame] | 971 | derivedFlow = onu1FlowAndGroup.GetFlow(0) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 972 | assert.Equal(t, expectedOnu1Flow.String(), derivedFlow.String()) |
| 973 | } |
| 974 | |
| 975 | func TestMulticastDownstreamRuleDecomposition(t *testing.T) { |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 976 | fa := &fu.FlowArgs{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 977 | KV: fu.OfpFlowModArgs{"priority": 500}, |
| 978 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 979 | fu.InPort(10), |
| 980 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 170), |
| 981 | fu.VlanPcp(0), |
| 982 | fu.EthType(0x800), |
| 983 | fu.Ipv4Dst(0xe00a0a0a), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 984 | }, |
| 985 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 986 | fu.Group(10), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 987 | }, |
| 988 | } |
| 989 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 990 | ga := &fu.GroupArgs{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 991 | GroupId: 10, |
| 992 | Buckets: []*ofp.OfpBucket{ |
| 993 | {Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 994 | fu.PopVlan(), |
| 995 | fu.Output(1), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 996 | }, |
| 997 | }, |
| 998 | }, |
| 999 | } |
| 1000 | |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 1001 | fs, err := fu.MkFlowStat(fa) |
| 1002 | assert.Nil(t, err) |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 1003 | flows := map[uint64]*ofp.OfpFlowStats{fs.Id: fs} |
| 1004 | groups := map[uint32]*ofp.OfpGroupEntry{ga.GroupId: fu.MkGroupStat(ga)} |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 1005 | tfd := newTestFlowDecomposer(t, newTestDeviceManager()) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 1006 | |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 1007 | deviceRules, err := tfd.fd.DecomposeRules(context.Background(), tfd, flows, groups) |
| 1008 | assert.Nil(t, err) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 1009 | oltFlowAndGroup := deviceRules.Rules["olt"] |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 1010 | assert.Equal(t, 1, oltFlowAndGroup.Flows.Len()) |
| 1011 | assert.Equal(t, 0, oltFlowAndGroup.Groups.Len()) |
| 1012 | |
| 1013 | fa = &fu.FlowArgs{ |
| 1014 | KV: fu.OfpFlowModArgs{"priority": 500}, |
| 1015 | MatchFields: []*ofp.OfpOxmOfbField{ |
Esin Karaman | 09959ae | 2019-11-29 13:59:58 +0000 | [diff] [blame] | 1016 | fu.InPort(10), |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 1017 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 170), |
| 1018 | fu.VlanPcp(0), |
| 1019 | fu.EthType(0x800), |
| 1020 | fu.Ipv4Dst(0xe00a0a0a), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 1021 | }, |
| 1022 | Actions: []*ofp.OfpAction{ |
Esin Karaman | 09959ae | 2019-11-29 13:59:58 +0000 | [diff] [blame] | 1023 | fu.Group(10), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 1024 | }, |
| 1025 | } |
Scott Baker | fdea1e3 | 2020-02-21 15:35:41 -0800 | [diff] [blame] | 1026 | expectedOltFlow, err := fu.MkFlowStat(fa) |
| 1027 | assert.Nil(t, err) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 1028 | derivedFlow := oltFlowAndGroup.GetFlow(0) |
| 1029 | assert.Equal(t, expectedOltFlow.String(), derivedFlow.String()) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 1030 | } |