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