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