khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package flow_decomposition |
| 17 | |
| 18 | import ( |
| 19 | "errors" |
| 20 | "github.com/opencord/voltha-go/common/log" |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 21 | "github.com/opencord/voltha-go/rw_core/graph" |
| 22 | fu "github.com/opencord/voltha-go/rw_core/utils" |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 23 | ofp "github.com/opencord/voltha-protos/go/openflow_13" |
| 24 | "github.com/opencord/voltha-protos/go/voltha" |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 25 | "github.com/stretchr/testify/assert" |
| 26 | |
| 27 | "testing" |
| 28 | ) |
| 29 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 30 | func init() { |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 31 | log.AddPackage(log.JSON, log.WarnLevel, nil) |
khenaidoo | 910204f | 2019-04-08 17:56:40 -0400 | [diff] [blame] | 32 | log.UpdateAllLoggers(log.Fields{"instanceId": "flow-decomposition"}) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 33 | log.SetAllLogLevel(log.WarnLevel) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | type testDeviceManager struct { |
| 37 | devices map[string]*voltha.Device |
| 38 | } |
| 39 | |
| 40 | func newTestDeviceManager() *testDeviceManager { |
| 41 | var tdm testDeviceManager |
| 42 | tdm.devices = make(map[string]*voltha.Device) |
| 43 | tdm.devices["olt"] = &voltha.Device{ |
| 44 | Id: "olt", |
| 45 | Root: true, |
| 46 | ParentId: "logical_device", |
| 47 | Ports: []*voltha.Port{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 48 | {PortNo: 1, Label: "pon"}, |
| 49 | {PortNo: 2, Label: "nni"}, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 50 | }, |
| 51 | } |
| 52 | tdm.devices["onu1"] = &voltha.Device{ |
| 53 | Id: "onu1", |
| 54 | Root: false, |
| 55 | ParentId: "olt", |
| 56 | Ports: []*voltha.Port{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 57 | {PortNo: 1, Label: "pon"}, |
| 58 | {PortNo: 2, Label: "uni"}, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 59 | }, |
| 60 | } |
| 61 | tdm.devices["onu2"] = &voltha.Device{ |
| 62 | Id: "onu2", |
| 63 | Root: false, |
| 64 | ParentId: "olt", |
| 65 | Ports: []*voltha.Port{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 66 | {PortNo: 1, Label: "pon"}, |
| 67 | {PortNo: 2, Label: "uni"}, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 68 | }, |
| 69 | } |
| 70 | tdm.devices["onu3"] = &voltha.Device{ |
| 71 | Id: "onu3", |
| 72 | Root: false, |
| 73 | ParentId: "olt", |
| 74 | Ports: []*voltha.Port{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 75 | {PortNo: 1, Label: "pon"}, |
| 76 | {PortNo: 2, Label: "uni"}, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 77 | }, |
| 78 | } |
| 79 | tdm.devices["onu4"] = &voltha.Device{ |
| 80 | Id: "onu4", |
| 81 | Root: false, |
| 82 | ParentId: "olt", |
| 83 | Ports: []*voltha.Port{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 84 | {PortNo: 1, Label: "pon"}, |
| 85 | {PortNo: 2, Label: "uni"}, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 86 | }, |
| 87 | } |
| 88 | return &tdm |
| 89 | } |
| 90 | |
| 91 | func (tdm *testDeviceManager) GetDevice(deviceId string) (*voltha.Device, error) { |
| 92 | if d, ok := tdm.devices[deviceId]; ok { |
| 93 | return d, nil |
| 94 | } |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 95 | return nil, errors.New("ABSENT.") |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 96 | } |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 97 | func (tdm *testDeviceManager) IsRootDevice(deviceId string) (bool, error) { |
| 98 | if d, ok := tdm.devices[deviceId]; ok { |
| 99 | return d.Root, nil |
| 100 | } |
| 101 | return false, errors.New("ABSENT.") |
| 102 | } |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 103 | |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 104 | func (tdm *testDeviceManager) NotifyInvalidTransition(pcDevice *voltha.Device) error { |
| 105 | return nil |
| 106 | } |
| 107 | |
| 108 | func (tdm *testDeviceManager) SetAdminStateToEnable(cDevice *voltha.Device) error { |
| 109 | return nil |
| 110 | } |
| 111 | |
| 112 | func (tdm *testDeviceManager) CreateLogicalDevice(cDevice *voltha.Device) error { |
| 113 | return nil |
| 114 | } |
| 115 | |
| 116 | func (tdm *testDeviceManager) SetupUNILogicalPorts(cDevice *voltha.Device) error { |
| 117 | return nil |
| 118 | } |
| 119 | |
| 120 | func (tdm *testDeviceManager) DisableAllChildDevices(cDevice *voltha.Device) error { |
| 121 | return nil |
| 122 | } |
| 123 | |
| 124 | func (tdm *testDeviceManager) DeleteLogicalDevice(cDevice *voltha.Device) error { |
| 125 | return nil |
| 126 | } |
| 127 | |
| 128 | func (tdm *testDeviceManager) DeleteLogicalPorts(cDevice *voltha.Device) error { |
| 129 | return nil |
| 130 | } |
| 131 | |
| 132 | func (tdm *testDeviceManager) DeleteAllChildDevices(cDevice *voltha.Device) error { |
| 133 | return nil |
| 134 | } |
| 135 | |
| 136 | func (tdm *testDeviceManager) RunPostDeviceDelete(cDevice *voltha.Device) error { |
| 137 | return nil |
| 138 | } |
| 139 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 140 | type testFlowDecomposer struct { |
| 141 | dMgr *testDeviceManager |
| 142 | logicalPorts map[uint32]*voltha.LogicalPort |
| 143 | routes map[graph.OFPortLink][]graph.RouteHop |
| 144 | defaultRules *fu.DeviceRules |
| 145 | deviceGraph *graph.DeviceGraph |
| 146 | fd *FlowDecomposer |
| 147 | } |
| 148 | |
| 149 | func newTestFlowDecomposer(deviceMgr *testDeviceManager) *testFlowDecomposer { |
| 150 | var tfd testFlowDecomposer |
| 151 | tfd.dMgr = deviceMgr |
| 152 | |
| 153 | tfd.logicalPorts = make(map[uint32]*voltha.LogicalPort) |
| 154 | // Go protobuf interpreted absence of a port as 0, so we can't use port #0 as an openflow |
| 155 | // port |
| 156 | tfd.logicalPorts[10] = &voltha.LogicalPort{Id: "10", DeviceId: "olt", DevicePortNo: 2} |
| 157 | tfd.logicalPorts[1] = &voltha.LogicalPort{Id: "1", DeviceId: "onu1", DevicePortNo: 2} |
| 158 | tfd.logicalPorts[2] = &voltha.LogicalPort{Id: "2", DeviceId: "onu2", DevicePortNo: 2} |
| 159 | tfd.logicalPorts[3] = &voltha.LogicalPort{Id: "3", DeviceId: "onu3", DevicePortNo: 2} |
| 160 | tfd.logicalPorts[4] = &voltha.LogicalPort{Id: "4", DeviceId: "onu4", DevicePortNo: 2} |
| 161 | |
| 162 | tfd.routes = make(map[graph.OFPortLink][]graph.RouteHop) |
| 163 | |
| 164 | //DOWNSTREAM ROUTES |
| 165 | |
| 166 | tfd.routes[graph.OFPortLink{Ingress: 10, Egress: 1}] = []graph.RouteHop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 167 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 168 | DeviceID: "olt", |
| 169 | Ingress: tfd.dMgr.devices["olt"].Ports[1].PortNo, |
| 170 | Egress: tfd.dMgr.devices["olt"].Ports[0].PortNo, |
| 171 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 172 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 173 | DeviceID: "onu1", |
| 174 | Ingress: tfd.dMgr.devices["onu1"].Ports[0].PortNo, |
| 175 | Egress: tfd.dMgr.devices["onu1"].Ports[1].PortNo, |
| 176 | }, |
| 177 | } |
| 178 | |
| 179 | tfd.routes[graph.OFPortLink{Ingress: 10, Egress: 2}] = []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: "onu2", |
| 187 | Ingress: tfd.dMgr.devices["onu2"].Ports[0].PortNo, |
| 188 | Egress: tfd.dMgr.devices["onu2"].Ports[1].PortNo, |
| 189 | }, |
| 190 | } |
| 191 | tfd.routes[graph.OFPortLink{Ingress: 10, Egress: 3}] = []graph.RouteHop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 192 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 193 | DeviceID: "olt", |
| 194 | Ingress: tfd.dMgr.devices["olt"].Ports[1].PortNo, |
| 195 | Egress: tfd.dMgr.devices["olt"].Ports[0].PortNo, |
| 196 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 197 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 198 | DeviceID: "onu3", |
| 199 | Ingress: tfd.dMgr.devices["onu3"].Ports[0].PortNo, |
| 200 | Egress: tfd.dMgr.devices["onu3"].Ports[1].PortNo, |
| 201 | }, |
| 202 | } |
| 203 | tfd.routes[graph.OFPortLink{Ingress: 10, Egress: 4}] = []graph.RouteHop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 204 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 205 | DeviceID: "olt", |
| 206 | Ingress: tfd.dMgr.devices["olt"].Ports[1].PortNo, |
| 207 | Egress: tfd.dMgr.devices["olt"].Ports[0].PortNo, |
| 208 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 209 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 210 | DeviceID: "onu4", |
| 211 | Ingress: tfd.dMgr.devices["onu4"].Ports[0].PortNo, |
| 212 | Egress: tfd.dMgr.devices["onu4"].Ports[1].PortNo, |
| 213 | }, |
| 214 | } |
| 215 | |
| 216 | //UPSTREAM DATA PLANE |
| 217 | |
| 218 | tfd.routes[graph.OFPortLink{Ingress: 1, 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: "onu1", |
| 221 | Ingress: tfd.dMgr.devices["onu1"].Ports[1].PortNo, |
| 222 | Egress: tfd.dMgr.devices["onu1"].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: 2, 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: "onu2", |
| 233 | Ingress: tfd.dMgr.devices["onu2"].Ports[1].PortNo, |
| 234 | Egress: tfd.dMgr.devices["onu2"].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: 3, 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: "onu3", |
| 245 | Ingress: tfd.dMgr.devices["onu3"].Ports[1].PortNo, |
| 246 | Egress: tfd.dMgr.devices["onu3"].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 | tfd.routes[graph.OFPortLink{Ingress: 4, Egress: 10}] = []graph.RouteHop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 255 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 256 | DeviceID: "onu4", |
| 257 | Ingress: tfd.dMgr.devices["onu4"].Ports[1].PortNo, |
| 258 | Egress: tfd.dMgr.devices["onu4"].Ports[0].PortNo, |
| 259 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 260 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 261 | DeviceID: "olt", |
| 262 | Ingress: tfd.dMgr.devices["olt"].Ports[0].PortNo, |
| 263 | Egress: tfd.dMgr.devices["olt"].Ports[1].PortNo, |
| 264 | }, |
| 265 | } |
| 266 | |
| 267 | //UPSTREAM NEXT TABLE BASED |
| 268 | |
| 269 | // openflow port 0 means absence of a port - go/protobuf interpretation |
| 270 | tfd.routes[graph.OFPortLink{Ingress: 1, 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: "onu1", |
| 273 | Ingress: tfd.dMgr.devices["onu1"].Ports[1].PortNo, |
| 274 | Egress: tfd.dMgr.devices["onu1"].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: 2, 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: "onu2", |
| 285 | Ingress: tfd.dMgr.devices["onu2"].Ports[1].PortNo, |
| 286 | Egress: tfd.dMgr.devices["onu2"].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: 3, 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: "onu3", |
| 297 | Ingress: tfd.dMgr.devices["onu3"].Ports[1].PortNo, |
| 298 | Egress: tfd.dMgr.devices["onu3"].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 | tfd.routes[graph.OFPortLink{Ingress: 4, Egress: 0}] = []graph.RouteHop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 307 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 308 | DeviceID: "onu4", |
| 309 | Ingress: tfd.dMgr.devices["onu4"].Ports[1].PortNo, |
| 310 | Egress: tfd.dMgr.devices["onu4"].Ports[0].PortNo, |
| 311 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 312 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 313 | DeviceID: "olt", |
| 314 | Ingress: tfd.dMgr.devices["olt"].Ports[0].PortNo, |
| 315 | Egress: tfd.dMgr.devices["olt"].Ports[1].PortNo, |
| 316 | }, |
| 317 | } |
| 318 | |
| 319 | // DOWNSTREAM NEXT TABLE BASED |
| 320 | |
| 321 | tfd.routes[graph.OFPortLink{Ingress: 10, Egress: 0}] = []graph.RouteHop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 322 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 323 | DeviceID: "olt", |
| 324 | Ingress: tfd.dMgr.devices["olt"].Ports[1].PortNo, |
| 325 | Egress: tfd.dMgr.devices["olt"].Ports[0].PortNo, |
| 326 | }, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 327 | {}, // 2nd hop is not known yet |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | tfd.routes[graph.OFPortLink{Ingress: 0, Egress: 10}] = []graph.RouteHop{ |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 331 | {}, // 1st hop is wildcard |
| 332 | { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 333 | DeviceID: "olt", |
| 334 | Ingress: tfd.dMgr.devices["olt"].Ports[0].PortNo, |
| 335 | Egress: tfd.dMgr.devices["olt"].Ports[1].PortNo, |
| 336 | }, |
| 337 | } |
| 338 | |
| 339 | // DEFAULT RULES |
| 340 | |
| 341 | tfd.defaultRules = fu.NewDeviceRules() |
| 342 | fg := fu.NewFlowsAndGroups() |
| 343 | var fa *fu.FlowArgs |
| 344 | fa = &fu.FlowArgs{ |
| 345 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 346 | fu.InPort(2), |
| 347 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 348 | }, |
| 349 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 350 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 351 | fu.Output(1), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 352 | }, |
| 353 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 354 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 355 | tfd.defaultRules.AddFlowsAndGroup("onu1", fg) |
| 356 | |
| 357 | fg = fu.NewFlowsAndGroups() |
| 358 | fa = &fu.FlowArgs{ |
| 359 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 360 | fu.InPort(2), |
| 361 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 362 | }, |
| 363 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 364 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 102)), |
| 365 | fu.Output(1), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 366 | }, |
| 367 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 368 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 369 | tfd.defaultRules.AddFlowsAndGroup("onu2", fg) |
| 370 | |
| 371 | fg = fu.NewFlowsAndGroups() |
| 372 | fa = &fu.FlowArgs{ |
| 373 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 374 | fu.InPort(2), |
| 375 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 376 | }, |
| 377 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 378 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 103)), |
| 379 | fu.Output(1), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 380 | }, |
| 381 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 382 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 383 | tfd.defaultRules.AddFlowsAndGroup("onu3", fg) |
| 384 | |
| 385 | fg = fu.NewFlowsAndGroups() |
| 386 | fa = &fu.FlowArgs{ |
| 387 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 388 | fu.InPort(2), |
| 389 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 390 | }, |
| 391 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 392 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 104)), |
| 393 | fu.Output(1), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 394 | }, |
| 395 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 396 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 397 | tfd.defaultRules.AddFlowsAndGroup("onu4", fg) |
| 398 | |
| 399 | //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] | 400 | tfd.deviceGraph = graph.NewDeviceGraph("ldid", tfd.getDeviceHelper) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 401 | tfd.deviceGraph.RootPorts = make(map[uint32]uint32) |
| 402 | tfd.deviceGraph.RootPorts[10] = 10 |
| 403 | |
| 404 | tfd.fd = NewFlowDecomposer(tfd.dMgr) |
| 405 | |
| 406 | return &tfd |
| 407 | } |
| 408 | |
| 409 | func (tfd *testFlowDecomposer) getDeviceHelper(deviceId string) (*voltha.Device, error) { |
| 410 | return tfd.dMgr.GetDevice(deviceId) |
| 411 | } |
| 412 | |
| 413 | func (tfd *testFlowDecomposer) GetDeviceLogicalId() string { |
| 414 | return "" |
| 415 | } |
| 416 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 417 | func (tfd *testFlowDecomposer) GetLogicalDevice() (*voltha.LogicalDevice, error) { |
| 418 | return nil, nil |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | func (tfd *testFlowDecomposer) GetDeviceGraph() *graph.DeviceGraph { |
| 422 | return tfd.deviceGraph |
| 423 | } |
| 424 | |
| 425 | func (tfd *testFlowDecomposer) GetAllDefaultRules() *fu.DeviceRules { |
| 426 | return tfd.defaultRules |
| 427 | } |
| 428 | |
| 429 | func (tfd *testFlowDecomposer) GetWildcardInputPorts(excludePort ...uint32) []uint32 { |
| 430 | lPorts := make([]uint32, 0) |
| 431 | var exclPort uint32 |
| 432 | if len(excludePort) == 1 { |
| 433 | exclPort = excludePort[0] |
| 434 | } |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 435 | for portno := range tfd.logicalPorts { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 436 | if portno != exclPort { |
| 437 | lPorts = append(lPorts, portno) |
| 438 | } |
| 439 | } |
| 440 | return lPorts |
| 441 | } |
| 442 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 443 | func (tfd *testFlowDecomposer) GetRoute(ingressPortNo uint32, egressPortNo uint32) []graph.RouteHop { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 444 | var portLink graph.OFPortLink |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 445 | if egressPortNo == 0 { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 446 | portLink.Egress = 0 |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 447 | } else if egressPortNo&0x7fffffff == uint32(ofp.OfpPortNo_OFPP_CONTROLLER) { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 448 | portLink.Egress = 10 |
| 449 | } else { |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 450 | portLink.Egress = egressPortNo |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 451 | } |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 452 | if ingressPortNo == 0 { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 453 | portLink.Ingress = 0 |
| 454 | } else { |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 455 | portLink.Ingress = ingressPortNo |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 456 | } |
| 457 | for key, val := range tfd.routes { |
| 458 | if key.Ingress == portLink.Ingress && key.Egress == portLink.Egress { |
| 459 | return val |
| 460 | } |
| 461 | } |
| 462 | return nil |
| 463 | } |
| 464 | |
| 465 | func TestEapolReRouteRuleDecomposition(t *testing.T) { |
| 466 | |
| 467 | var fa *fu.FlowArgs |
| 468 | fa = &fu.FlowArgs{ |
| 469 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 470 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 471 | fu.InPort(1), |
| 472 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 473 | fu.EthType(0x888e), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 474 | }, |
| 475 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 476 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 477 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 478 | }, |
| 479 | } |
| 480 | |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 481 | flows := ofp.Flows{Items: []*ofp.OfpFlowStats{fu.MkFlowStat(fa)}} |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 482 | groups := ofp.FlowGroups{} |
| 483 | tfd := newTestFlowDecomposer(newTestDeviceManager()) |
| 484 | |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 485 | deviceRules := tfd.fd.DecomposeRules(tfd, flows, groups, true) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 486 | onu1FlowAndGroup := deviceRules.Rules["onu1"] |
| 487 | oltFlowAndGroup := deviceRules.Rules["olt"] |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 488 | assert.Equal(t, 1, onu1FlowAndGroup.Flows.Len()) |
| 489 | assert.Equal(t, 0, onu1FlowAndGroup.Groups.Len()) |
| 490 | assert.Equal(t, 2, oltFlowAndGroup.Flows.Len()) |
| 491 | assert.Equal(t, 0, oltFlowAndGroup.Groups.Len()) |
| 492 | |
| 493 | fa = &fu.FlowArgs{ |
| 494 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 495 | fu.InPort(2), |
| 496 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 497 | }, |
| 498 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 499 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 500 | fu.Output(1), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 501 | }, |
| 502 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 503 | expectedOnu1Flow := fu.MkFlowStat(fa) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 504 | derivedFlow := onu1FlowAndGroup.GetFlow(0) |
| 505 | assert.Equal(t, expectedOnu1Flow.String(), derivedFlow.String()) |
| 506 | |
| 507 | fa = &fu.FlowArgs{ |
| 508 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 509 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 510 | fu.InPort(1), |
| 511 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 1), |
| 512 | fu.TunnelId(uint64(1)), |
| 513 | fu.EthType(0x888e), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 514 | }, |
| 515 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 516 | fu.PushVlan(0x8100), |
| 517 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 4000)), |
| 518 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 519 | }, |
| 520 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 521 | expectedOltFlow := fu.MkFlowStat(fa) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 522 | derivedFlow = oltFlowAndGroup.GetFlow(0) |
| 523 | assert.Equal(t, expectedOltFlow.String(), derivedFlow.String()) |
| 524 | |
| 525 | fa = &fu.FlowArgs{ |
| 526 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 527 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 528 | fu.InPort(2), |
| 529 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 4000), |
| 530 | fu.VlanPcp(0), |
| 531 | fu.Metadata_ofp(1), |
| 532 | fu.TunnelId(uint64(1)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 533 | }, |
| 534 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 535 | fu.PopVlan(), |
| 536 | fu.Output(1), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 537 | }, |
| 538 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 539 | expectedOltFlow = fu.MkFlowStat(fa) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 540 | derivedFlow = oltFlowAndGroup.GetFlow(1) |
| 541 | assert.Equal(t, expectedOltFlow.String(), derivedFlow.String()) |
| 542 | } |
| 543 | |
| 544 | func TestDhcpReRouteRuleDecomposition(t *testing.T) { |
| 545 | |
| 546 | var fa *fu.FlowArgs |
| 547 | fa = &fu.FlowArgs{ |
| 548 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 549 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 550 | fu.InPort(1), |
| 551 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 552 | fu.EthType(0x0800), |
| 553 | fu.Ipv4Dst(0xffffffff), |
| 554 | fu.IpProto(17), |
| 555 | fu.UdpSrc(68), |
| 556 | fu.UdpDst(67), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 557 | }, |
| 558 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 559 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 560 | }, |
| 561 | } |
| 562 | |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 563 | flows := ofp.Flows{Items: []*ofp.OfpFlowStats{fu.MkFlowStat(fa)}} |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 564 | groups := ofp.FlowGroups{} |
| 565 | tfd := newTestFlowDecomposer(newTestDeviceManager()) |
| 566 | |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 567 | deviceRules := tfd.fd.DecomposeRules(tfd, flows, groups, true) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 568 | onu1FlowAndGroup := deviceRules.Rules["onu1"] |
| 569 | oltFlowAndGroup := deviceRules.Rules["olt"] |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 570 | assert.Equal(t, 1, onu1FlowAndGroup.Flows.Len()) |
| 571 | assert.Equal(t, 0, onu1FlowAndGroup.Groups.Len()) |
| 572 | assert.Equal(t, 2, oltFlowAndGroup.Flows.Len()) |
| 573 | assert.Equal(t, 0, oltFlowAndGroup.Groups.Len()) |
| 574 | |
| 575 | fa = &fu.FlowArgs{ |
| 576 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 577 | fu.InPort(2), |
| 578 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 579 | }, |
| 580 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 581 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 582 | fu.Output(1), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 583 | }, |
| 584 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 585 | expectedOnu1Flow := fu.MkFlowStat(fa) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 586 | derivedFlow := onu1FlowAndGroup.GetFlow(0) |
| 587 | assert.Equal(t, expectedOnu1Flow.String(), derivedFlow.String()) |
| 588 | |
| 589 | fa = &fu.FlowArgs{ |
| 590 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 591 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 592 | fu.InPort(1), |
| 593 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 1), |
| 594 | fu.TunnelId(uint64(1)), |
| 595 | fu.EthType(0x0800), |
| 596 | fu.Ipv4Dst(0xffffffff), |
| 597 | fu.IpProto(17), |
| 598 | fu.UdpSrc(68), |
| 599 | fu.UdpDst(67), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 600 | }, |
| 601 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 602 | fu.PushVlan(0x8100), |
| 603 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 4000)), |
| 604 | fu.Output(uint32(ofp.OfpPortNo_OFPP_CONTROLLER)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 605 | }, |
| 606 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 607 | expectedOltFlow := fu.MkFlowStat(fa) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 608 | derivedFlow = oltFlowAndGroup.GetFlow(0) |
| 609 | assert.Equal(t, expectedOltFlow.String(), derivedFlow.String()) |
| 610 | |
| 611 | fa = &fu.FlowArgs{ |
| 612 | KV: fu.OfpFlowModArgs{"priority": 1000}, |
| 613 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 614 | fu.InPort(2), |
| 615 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 4000), |
| 616 | fu.VlanPcp(0), |
| 617 | fu.Metadata_ofp(1), |
| 618 | fu.TunnelId(uint64(1)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 619 | }, |
| 620 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 621 | fu.PopVlan(), |
| 622 | fu.Output(1), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 623 | }, |
| 624 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 625 | expectedOltFlow = fu.MkFlowStat(fa) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 626 | derivedFlow = oltFlowAndGroup.GetFlow(1) |
| 627 | assert.Equal(t, expectedOltFlow.String(), derivedFlow.String()) |
| 628 | } |
| 629 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 630 | func TestUnicastUpstreamRuleDecomposition(t *testing.T) { |
| 631 | |
| 632 | var fa *fu.FlowArgs |
| 633 | fa = &fu.FlowArgs{ |
| 634 | KV: fu.OfpFlowModArgs{"priority": 500, "table_id": 1}, |
| 635 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 636 | fu.InPort(1), |
| 637 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 638 | fu.VlanPcp(0), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 639 | }, |
| 640 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 641 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 642 | }, |
| 643 | } |
| 644 | |
| 645 | var fa2 *fu.FlowArgs |
| 646 | fa2 = &fu.FlowArgs{ |
| 647 | KV: fu.OfpFlowModArgs{"priority": 500}, |
| 648 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 649 | fu.InPort(1), |
| 650 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101), |
| 651 | fu.VlanPcp(0), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 652 | }, |
| 653 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 654 | fu.PushVlan(0x8100), |
| 655 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 1000)), |
| 656 | fu.SetField(fu.VlanPcp(0)), |
| 657 | fu.Output(10), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 658 | }, |
| 659 | } |
| 660 | |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 661 | flows := ofp.Flows{Items: []*ofp.OfpFlowStats{fu.MkFlowStat(fa), fu.MkFlowStat(fa2)}} |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 662 | groups := ofp.FlowGroups{} |
| 663 | tfd := newTestFlowDecomposer(newTestDeviceManager()) |
| 664 | |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 665 | deviceRules := tfd.fd.DecomposeRules(tfd, flows, groups, true) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 666 | onu1FlowAndGroup := deviceRules.Rules["onu1"] |
| 667 | oltFlowAndGroup := deviceRules.Rules["olt"] |
| 668 | assert.Equal(t, 2, onu1FlowAndGroup.Flows.Len()) |
| 669 | assert.Equal(t, 0, onu1FlowAndGroup.Groups.Len()) |
| 670 | assert.Equal(t, 1, oltFlowAndGroup.Flows.Len()) |
| 671 | assert.Equal(t, 0, oltFlowAndGroup.Groups.Len()) |
| 672 | |
| 673 | fa = &fu.FlowArgs{ |
| 674 | KV: fu.OfpFlowModArgs{"priority": 500}, |
| 675 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 676 | fu.InPort(2), |
| 677 | fu.TunnelId(uint64(1)), |
| 678 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0), |
| 679 | fu.VlanPcp(0), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 680 | }, |
| 681 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 682 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 683 | fu.Output(1), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 684 | }, |
| 685 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 686 | expectedOnu1Flow := fu.MkFlowStat(fa) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 687 | derivedFlow := onu1FlowAndGroup.GetFlow(1) |
| 688 | assert.Equal(t, expectedOnu1Flow.String(), derivedFlow.String()) |
| 689 | |
| 690 | fa = &fu.FlowArgs{ |
| 691 | KV: fu.OfpFlowModArgs{"priority": 500}, |
| 692 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 693 | fu.InPort(1), |
| 694 | fu.TunnelId(uint64(1)), |
| 695 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101), |
| 696 | fu.VlanPcp(0), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 697 | }, |
| 698 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 699 | fu.PushVlan(0x8100), |
| 700 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 1000)), |
| 701 | fu.SetField(fu.VlanPcp(0)), |
| 702 | fu.Output(2), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 703 | }, |
| 704 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 705 | expectedOltFlow := fu.MkFlowStat(fa) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 706 | derivedFlow = oltFlowAndGroup.GetFlow(0) |
| 707 | assert.Equal(t, expectedOltFlow.String(), derivedFlow.String()) |
| 708 | } |
| 709 | |
| 710 | func TestUnicastDownstreamRuleDecomposition(t *testing.T) { |
| 711 | var fa1 *fu.FlowArgs |
| 712 | fa1 = &fu.FlowArgs{ |
| 713 | KV: fu.OfpFlowModArgs{"priority": 500, "table_id": 1}, |
| 714 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 715 | fu.InPort(10), |
| 716 | fu.Metadata_ofp((1000 << 32) | 1), |
| 717 | fu.VlanPcp(0), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 718 | }, |
| 719 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 720 | fu.PopVlan(), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 721 | }, |
| 722 | } |
| 723 | |
| 724 | var fa2 *fu.FlowArgs |
| 725 | fa2 = &fu.FlowArgs{ |
| 726 | KV: fu.OfpFlowModArgs{"priority": 500}, |
| 727 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 728 | fu.InPort(10), |
| 729 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101), |
| 730 | fu.VlanPcp(0), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 731 | }, |
| 732 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 733 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)), |
| 734 | fu.Output(1), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 735 | }, |
| 736 | } |
| 737 | |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 738 | flows := ofp.Flows{Items: []*ofp.OfpFlowStats{fu.MkFlowStat(fa1), fu.MkFlowStat(fa2)}} |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 739 | groups := ofp.FlowGroups{} |
| 740 | tfd := newTestFlowDecomposer(newTestDeviceManager()) |
| 741 | |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 742 | deviceRules := tfd.fd.DecomposeRules(tfd, flows, groups, true) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 743 | onu1FlowAndGroup := deviceRules.Rules["onu1"] |
| 744 | oltFlowAndGroup := deviceRules.Rules["olt"] |
| 745 | assert.Equal(t, 2, onu1FlowAndGroup.Flows.Len()) |
| 746 | assert.Equal(t, 0, onu1FlowAndGroup.Groups.Len()) |
| 747 | assert.Equal(t, 1, oltFlowAndGroup.Flows.Len()) |
| 748 | assert.Equal(t, 0, oltFlowAndGroup.Groups.Len()) |
| 749 | |
| 750 | fa1 = &fu.FlowArgs{ |
| 751 | KV: fu.OfpFlowModArgs{"priority": 500}, |
| 752 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 753 | fu.InPort(2), |
| 754 | fu.Metadata_ofp(1000), |
| 755 | fu.TunnelId(uint64(1)), |
| 756 | fu.VlanPcp(0), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 757 | }, |
| 758 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 759 | fu.PopVlan(), |
| 760 | fu.Output(1), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 761 | }, |
| 762 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 763 | expectedOltFlow := fu.MkFlowStat(fa1) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 764 | derivedFlow := oltFlowAndGroup.GetFlow(0) |
| 765 | assert.Equal(t, expectedOltFlow.String(), derivedFlow.String()) |
| 766 | |
| 767 | fa1 = &fu.FlowArgs{ |
| 768 | KV: fu.OfpFlowModArgs{"priority": 500}, |
| 769 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 770 | fu.InPort(1), |
| 771 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101), |
| 772 | fu.VlanPcp(0), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 773 | }, |
| 774 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 775 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 0)), |
| 776 | fu.Output(2), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 777 | }, |
| 778 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 779 | expectedOnu1Flow := fu.MkFlowStat(fa1) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 780 | derivedFlow = onu1FlowAndGroup.GetFlow(1) |
| 781 | assert.Equal(t, expectedOnu1Flow.String(), derivedFlow.String()) |
| 782 | } |
| 783 | |
| 784 | func TestMulticastDownstreamRuleDecomposition(t *testing.T) { |
| 785 | var fa *fu.FlowArgs |
| 786 | fa = &fu.FlowArgs{ |
| 787 | KV: fu.OfpFlowModArgs{"priority": 500}, |
| 788 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 789 | fu.InPort(10), |
| 790 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 170), |
| 791 | fu.VlanPcp(0), |
| 792 | fu.EthType(0x800), |
| 793 | fu.Ipv4Dst(0xe00a0a0a), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 794 | }, |
| 795 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 796 | fu.Group(10), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 797 | }, |
| 798 | } |
| 799 | |
| 800 | var ga *fu.GroupArgs |
| 801 | ga = &fu.GroupArgs{ |
| 802 | GroupId: 10, |
| 803 | Buckets: []*ofp.OfpBucket{ |
| 804 | {Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 805 | fu.PopVlan(), |
| 806 | fu.Output(1), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 807 | }, |
| 808 | }, |
| 809 | }, |
| 810 | } |
| 811 | |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 812 | flows := ofp.Flows{Items: []*ofp.OfpFlowStats{fu.MkFlowStat(fa)}} |
| 813 | groups := ofp.FlowGroups{Items: []*ofp.OfpGroupEntry{fu.MkGroupStat(ga)}} |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 814 | tfd := newTestFlowDecomposer(newTestDeviceManager()) |
| 815 | |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 816 | deviceRules := tfd.fd.DecomposeRules(tfd, flows, groups, true) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 817 | onu1FlowAndGroup := deviceRules.Rules["onu1"] |
| 818 | oltFlowAndGroup := deviceRules.Rules["olt"] |
| 819 | assert.Equal(t, 2, onu1FlowAndGroup.Flows.Len()) |
| 820 | assert.Equal(t, 0, onu1FlowAndGroup.Groups.Len()) |
| 821 | assert.Equal(t, 1, oltFlowAndGroup.Flows.Len()) |
| 822 | assert.Equal(t, 0, oltFlowAndGroup.Groups.Len()) |
| 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(2), |
| 828 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 170), |
| 829 | fu.VlanPcp(0), |
| 830 | fu.EthType(0x800), |
| 831 | fu.Ipv4Dst(0xe00a0a0a), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 832 | }, |
| 833 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 834 | fu.PopVlan(), |
| 835 | fu.Output(1), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 836 | }, |
| 837 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 838 | expectedOltFlow := fu.MkFlowStat(fa) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 839 | derivedFlow := oltFlowAndGroup.GetFlow(0) |
| 840 | assert.Equal(t, expectedOltFlow.String(), derivedFlow.String()) |
| 841 | |
| 842 | fa = &fu.FlowArgs{ |
| 843 | KV: fu.OfpFlowModArgs{"priority": 500}, |
| 844 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 845 | fu.InPort(1), |
| 846 | fu.EthType(0x800), |
| 847 | fu.Ipv4Dst(0xe00a0a0a), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 848 | }, |
| 849 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 850 | fu.Output(2), |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 851 | }, |
| 852 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 853 | expectedOnu1Flow := fu.MkFlowStat(fa) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 854 | derivedFlow = onu1FlowAndGroup.GetFlow(1) |
| 855 | assert.Equal(t, expectedOnu1Flow.String(), derivedFlow.String()) |
| 856 | } |