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