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