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