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 | |
| 17 | package flow_decomposition |
| 18 | |
| 19 | import ( |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 20 | "github.com/gogo/protobuf/proto" |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 21 | "github.com/opencord/voltha-go/common/log" |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 22 | "github.com/opencord/voltha-go/rw_core/coreIf" |
| 23 | "github.com/opencord/voltha-go/rw_core/graph" |
| 24 | fu "github.com/opencord/voltha-go/rw_core/utils" |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 25 | ofp "github.com/opencord/voltha-protos/go/openflow_13" |
| 26 | "github.com/opencord/voltha-protos/go/voltha" |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | func init() { |
| 30 | log.AddPackage(log.JSON, log.DebugLevel, nil) |
| 31 | } |
| 32 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 33 | type FlowDecomposer struct { |
| 34 | deviceMgr coreIf.DeviceManager |
| 35 | } |
| 36 | |
| 37 | func NewFlowDecomposer(deviceMgr coreIf.DeviceManager) *FlowDecomposer { |
| 38 | var decomposer FlowDecomposer |
| 39 | decomposer.deviceMgr = deviceMgr |
| 40 | return &decomposer |
| 41 | } |
| 42 | |
| 43 | //DecomposeRules decomposes per-device flows and flow-groups from the flows and groups defined on a logical device |
khenaidoo | 3306c99 | 2019-05-24 16:57:35 -0400 | [diff] [blame^] | 44 | func (fd *FlowDecomposer) DecomposeRules(agent coreIf.LogicalDeviceAgent, flows ofp.Flows, groups ofp.FlowGroups) *fu.DeviceRules { |
| 45 | deviceRules := *fu.NewDeviceRules() |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 46 | devicesToUpdate := make(map[string]string) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 47 | |
| 48 | groupMap := make(map[uint32]*ofp.OfpGroupEntry) |
| 49 | for _, groupEntry := range groups.Items { |
| 50 | groupMap[groupEntry.Desc.GroupId] = groupEntry |
| 51 | } |
| 52 | |
| 53 | var decomposedRules *fu.DeviceRules |
| 54 | for _, flow := range flows.Items { |
| 55 | decomposedRules = fd.decomposeFlow(agent, flow, groupMap) |
| 56 | for deviceId, flowAndGroups := range decomposedRules.Rules { |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 57 | deviceRules.CreateEntryIfNotExist(deviceId) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 58 | deviceRules.Rules[deviceId].AddFrom(flowAndGroups) |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 59 | devicesToUpdate[deviceId] = deviceId |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 60 | } |
| 61 | } |
khenaidoo | 3306c99 | 2019-05-24 16:57:35 -0400 | [diff] [blame^] | 62 | return deviceRules.FilterRules(devicesToUpdate) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 63 | } |
| 64 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 65 | // Handles special case of any controller-bound flow for a parent device |
| 66 | func (fd *FlowDecomposer) updateOutputPortForControllerBoundFlowForParentDevide(flow *ofp.OfpFlowStats, |
| 67 | dr *fu.DeviceRules) *fu.DeviceRules { |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 68 | EAPOL := fu.EthType(0x888e) |
| 69 | IGMP := fu.IpProto(2) |
| 70 | UDP := fu.IpProto(17) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 71 | |
| 72 | newDeviceRules := dr.Copy() |
| 73 | // Check whether we are dealing with a parent device |
| 74 | for deviceId, fg := range dr.GetRules() { |
| 75 | if root, _ := fd.deviceMgr.IsRootDevice(deviceId); root { |
| 76 | newDeviceRules.ClearFlows(deviceId) |
| 77 | for i := 0; i < fg.Flows.Len(); i++ { |
| 78 | f := fg.GetFlow(i) |
| 79 | UpdateOutPortNo := false |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 80 | for _, field := range fu.GetOfbFields(f) { |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 81 | UpdateOutPortNo = (field.String() == EAPOL.String()) |
| 82 | UpdateOutPortNo = UpdateOutPortNo || (field.String() == IGMP.String()) |
| 83 | UpdateOutPortNo = UpdateOutPortNo || (field.String() == UDP.String()) |
| 84 | if UpdateOutPortNo { |
| 85 | break |
| 86 | } |
| 87 | } |
| 88 | if UpdateOutPortNo { |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 89 | f = fu.UpdateOutputPortByActionType(f, uint32(ofp.OfpInstructionType_OFPIT_APPLY_ACTIONS), |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 90 | uint32(ofp.OfpPortNo_OFPP_CONTROLLER)) |
| 91 | } |
| 92 | // Update flow Id as a change in the instruction field will result in a new flow ID |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 93 | f.Id = fu.HashFlowStats(f) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 94 | newDeviceRules.AddFlow(deviceId, (proto.Clone(f)).(*ofp.OfpFlowStats)) |
| 95 | } |
| 96 | } |
| 97 | } |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 98 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 99 | return newDeviceRules |
| 100 | } |
| 101 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 102 | //processControllerBoundFlow decomposes trap flows |
| 103 | func (fd *FlowDecomposer) processControllerBoundFlow(agent coreIf.LogicalDeviceAgent, route []graph.RouteHop, |
| 104 | inPortNo uint32, outPortNo uint32, flow *ofp.OfpFlowStats) *fu.DeviceRules { |
| 105 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 106 | log.Debugw("trap-flow", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo, "flow": flow}) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 107 | deviceRules := fu.NewDeviceRules() |
| 108 | |
| 109 | egressHop := route[1] |
| 110 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 111 | fg := fu.NewFlowsAndGroups() |
| 112 | if agent.GetDeviceGraph().IsRootPort(inPortNo) { |
| 113 | log.Debug("trap-nni") |
khenaidoo | 8f47419 | 2019-04-03 17:20:44 -0400 | [diff] [blame] | 114 | // no decomposition required - it is already an OLT flow from NNI |
| 115 | fg.AddFlow(flow) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 116 | } else { |
| 117 | // Trap flow for UNI port |
| 118 | log.Debug("trap-uni") |
| 119 | |
| 120 | //inPortNo is 0 for wildcard input case, do not include upstream port for 4000 flow in input |
| 121 | var inPorts []uint32 |
| 122 | if inPortNo == 0 { |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 123 | inPorts = agent.GetWildcardInputPorts(egressHop.Egress) // exclude egress_hop.egress_port.port_no |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 124 | } else { |
| 125 | inPorts = []uint32{inPortNo} |
| 126 | } |
| 127 | for _, inputPort := range inPorts { |
| 128 | var fa *fu.FlowArgs |
| 129 | // Upstream flow |
| 130 | fa = &fu.FlowArgs{ |
| 131 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie}, |
| 132 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 133 | fu.InPort(egressHop.Ingress), |
| 134 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | inputPort), |
| 135 | fu.TunnelId(uint64(inputPort)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 136 | }, |
| 137 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 138 | fu.PushVlan(0x8100), |
| 139 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 4000)), |
| 140 | fu.Output(egressHop.Egress), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 141 | }, |
| 142 | } |
| 143 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 144 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT, fu.VLAN_VID)...) |
| 145 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 146 | |
| 147 | // Downstream flow |
| 148 | fa = &fu.FlowArgs{ |
| 149 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority)}, |
| 150 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 151 | fu.InPort(egressHop.Egress), |
| 152 | fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 4000), |
| 153 | fu.VlanPcp(0), |
| 154 | fu.Metadata_ofp(uint64(inputPort)), |
| 155 | fu.TunnelId(uint64(inputPort)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 156 | }, |
| 157 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 158 | fu.PopVlan(), |
| 159 | fu.Output(egressHop.Ingress), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 160 | }, |
| 161 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 162 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 163 | } |
| 164 | } |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 165 | deviceRules.AddFlowsAndGroup(egressHop.DeviceID, fg) |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 166 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 167 | return deviceRules |
| 168 | } |
| 169 | |
| 170 | // processUpstreamNonControllerBoundFlow processes non-controller bound flow. We assume that anything that is |
| 171 | // upstream needs to get Q-in-Q treatment and that this is expressed via two flow rules, the first using the |
| 172 | // goto-statement. We also assume that the inner tag is applied at the ONU, while the outer tag is |
| 173 | // applied at the OLT |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 174 | func (fd *FlowDecomposer) processUpstreamNonControllerBoundFlow(agent coreIf.LogicalDeviceAgent, |
| 175 | route []graph.RouteHop, inPortNo uint32, outPortNo uint32, flow *ofp.OfpFlowStats) *fu.DeviceRules { |
| 176 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 177 | log.Debugw("upstream-non-controller-bound-flow", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo}) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 178 | deviceRules := fu.NewDeviceRules() |
| 179 | |
| 180 | ingressHop := route[0] |
| 181 | egressHop := route[1] |
| 182 | |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 183 | if fu.HasNextTable(flow) { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 184 | log.Debugw("has-next-table", log.Fields{"table_id": flow.TableId}) |
| 185 | if outPortNo != 0 { |
| 186 | log.Warnw("outPort-should-not-be-specified", log.Fields{"outPortNo": outPortNo}) |
| 187 | } |
| 188 | var fa *fu.FlowArgs |
| 189 | fa = &fu.FlowArgs{ |
| 190 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie}, |
| 191 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 192 | fu.InPort(ingressHop.Ingress), |
| 193 | fu.TunnelId(uint64(inPortNo)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 194 | }, |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 195 | Actions: fu.GetActions(flow), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 196 | } |
| 197 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 198 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 199 | |
| 200 | // Augment the Actions |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 201 | fa.Actions = append(fa.Actions, fu.Output(ingressHop.Egress)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 202 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 203 | fg := fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 204 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 205 | deviceRules.AddFlowsAndGroup(ingressHop.DeviceID, fg) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 206 | } else { |
| 207 | var actions []ofp.OfpActionType |
| 208 | var isOutputTypeInActions bool |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 209 | for _, action := range fu.GetActions(flow) { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 210 | actions = append(actions, action.Type) |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 211 | if !isOutputTypeInActions && action.Type == fu.OUTPUT { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 212 | isOutputTypeInActions = true |
| 213 | } |
| 214 | } |
| 215 | if len(actions) == 1 && isOutputTypeInActions { |
| 216 | var fa *fu.FlowArgs |
| 217 | // child device flow |
| 218 | fa = &fu.FlowArgs{ |
| 219 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie}, |
| 220 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 221 | fu.InPort(ingressHop.Ingress), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 222 | }, |
| 223 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 224 | fu.Output(ingressHop.Egress), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 225 | }, |
| 226 | } |
| 227 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 228 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 229 | fg := fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 230 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 231 | deviceRules.AddFlowsAndGroup(ingressHop.DeviceID, fg) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 232 | |
| 233 | // parent device flow |
| 234 | fa = &fu.FlowArgs{ |
| 235 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie}, |
| 236 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 237 | fu.InPort(egressHop.Ingress), //egress_hop.ingress_port.port_no |
| 238 | fu.TunnelId(uint64(inPortNo)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 239 | }, |
| 240 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 241 | fu.Output(egressHop.Egress), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 242 | }, |
| 243 | } |
| 244 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 245 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 246 | fg = fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 247 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 248 | deviceRules.AddFlowsAndGroup(egressHop.DeviceID, fg) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 249 | } else { |
| 250 | if outPortNo == 0 { |
| 251 | log.Warnw("outPort-should-be-specified", log.Fields{"outPortNo": outPortNo}) |
| 252 | } |
| 253 | var fa *fu.FlowArgs |
| 254 | fa = &fu.FlowArgs{ |
| 255 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie}, |
| 256 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 257 | fu.InPort(egressHop.Ingress), |
| 258 | fu.TunnelId(uint64(inPortNo)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 259 | }, |
| 260 | } |
| 261 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 262 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 263 | |
| 264 | //Augment the actions |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 265 | filteredAction := fu.GetActions(flow, fu.OUTPUT) |
| 266 | filteredAction = append(filteredAction, fu.Output(egressHop.Egress)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 267 | fa.Actions = filteredAction |
| 268 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 269 | fg := fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 270 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 271 | deviceRules.AddFlowsAndGroup(egressHop.DeviceID, fg) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | return deviceRules |
| 275 | } |
| 276 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 277 | // processDownstreamFlowWithNextTable decomposes downstream flows containing next table ID instructions |
| 278 | func (fd *FlowDecomposer) processDownstreamFlowWithNextTable(agent coreIf.LogicalDeviceAgent, route []graph.RouteHop, |
| 279 | inPortNo uint32, outPortNo uint32, flow *ofp.OfpFlowStats) *fu.DeviceRules { |
| 280 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 281 | log.Debugw("downstream-flow-with-next-table", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo}) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 282 | deviceRules := fu.NewDeviceRules() |
| 283 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 284 | if outPortNo != 0 { |
| 285 | log.Warnw("outPort-should-not-be-specified", log.Fields{"outPortNo": outPortNo}) |
| 286 | } |
| 287 | ingressHop := route[0] |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 288 | egressHop := route[1] |
| 289 | |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 290 | if fu.GetMetaData(flow) != 0 { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 291 | log.Debugw("creating-metadata-flow", log.Fields{"flow": flow}) |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 292 | portNumber := uint32(fu.GetPortNumberFromMetadata(flow)) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 293 | if portNumber != 0 { |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 294 | recalculatedRoute := agent.GetRoute(inPortNo, portNumber) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 295 | switch len(recalculatedRoute) { |
| 296 | case 0: |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 297 | log.Errorw("no-route-double-tag", log.Fields{"inPortNo": inPortNo, "outPortNo": portNumber, "comment": "deleting-flow", "metadata": fu.GetMetaData64Bit(flow)}) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 298 | // TODO: Delete flow |
| 299 | return deviceRules |
| 300 | case 2: |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 301 | log.Debugw("route-found", log.Fields{"ingressHop": ingressHop, "egressHop": egressHop}) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 302 | break |
| 303 | default: |
| 304 | log.Errorw("invalid-route-length", log.Fields{"routeLen": len(route)}) |
| 305 | return deviceRules |
| 306 | } |
| 307 | ingressHop = recalculatedRoute[0] |
| 308 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 309 | innerTag := fu.GetInnerTagFromMetaData(flow) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 310 | if innerTag == 0 { |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 311 | log.Errorw("no-inner-route-double-tag", log.Fields{"inPortNo": inPortNo, "outPortNo": portNumber, "comment": "deleting-flow", "metadata": fu.GetMetaData64Bit(flow)}) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 312 | // TODO: Delete flow |
| 313 | return deviceRules |
| 314 | } |
| 315 | var fa *fu.FlowArgs |
| 316 | fa = &fu.FlowArgs{ |
| 317 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie}, |
| 318 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 319 | fu.InPort(ingressHop.Ingress), |
| 320 | fu.Metadata_ofp(innerTag), |
| 321 | fu.TunnelId(uint64(portNumber)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 322 | }, |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 323 | Actions: fu.GetActions(flow), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 324 | } |
| 325 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 326 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT, fu.METADATA)...) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 327 | |
| 328 | // Augment the Actions |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 329 | fa.Actions = append(fa.Actions, fu.Output(ingressHop.Egress)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 330 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 331 | fg := fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 332 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 333 | deviceRules.AddFlowsAndGroup(ingressHop.DeviceID, fg) |
| 334 | } else { // Create standard flow |
| 335 | log.Debugw("creating-standard-flow", log.Fields{"flow": flow}) |
| 336 | var fa *fu.FlowArgs |
| 337 | fa = &fu.FlowArgs{ |
| 338 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie}, |
| 339 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 340 | fu.InPort(ingressHop.Ingress), |
| 341 | fu.TunnelId(uint64(inPortNo)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 342 | }, |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 343 | Actions: fu.GetActions(flow), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 344 | } |
| 345 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 346 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 347 | |
| 348 | // Augment the Actions |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 349 | fa.Actions = append(fa.Actions, fu.Output(ingressHop.Egress)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 350 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 351 | fg := fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 352 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 353 | deviceRules.AddFlowsAndGroup(ingressHop.DeviceID, fg) |
| 354 | } |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 355 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 356 | return deviceRules |
| 357 | } |
| 358 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 359 | // processUnicastFlow decomposes unicast flows |
| 360 | func (fd *FlowDecomposer) processUnicastFlow(agent coreIf.LogicalDeviceAgent, route []graph.RouteHop, |
| 361 | inPortNo uint32, outPortNo uint32, flow *ofp.OfpFlowStats) *fu.DeviceRules { |
| 362 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 363 | log.Debugw("unicast-flow", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo}) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 364 | deviceRules := fu.NewDeviceRules() |
| 365 | |
| 366 | ingressHop := route[0] |
| 367 | egressHop := route[1] |
| 368 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 369 | var actions []ofp.OfpActionType |
| 370 | var isOutputTypeInActions bool |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 371 | for _, action := range fu.GetActions(flow) { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 372 | actions = append(actions, action.Type) |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 373 | if !isOutputTypeInActions && action.Type == fu.OUTPUT { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 374 | isOutputTypeInActions = true |
| 375 | } |
| 376 | } |
| 377 | if len(actions) == 1 && isOutputTypeInActions { |
| 378 | var fa *fu.FlowArgs |
| 379 | // Parent device flow |
| 380 | fa = &fu.FlowArgs{ |
| 381 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie}, |
| 382 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 383 | fu.InPort(ingressHop.Ingress), |
| 384 | fu.TunnelId(uint64(inPortNo)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 385 | }, |
| 386 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 387 | fu.Output(ingressHop.Egress), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 388 | }, |
| 389 | } |
| 390 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 391 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 392 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 393 | fg := fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 394 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 395 | deviceRules.AddFlowsAndGroup(ingressHop.DeviceID, fg) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 396 | |
| 397 | // Child device flow |
| 398 | fa = &fu.FlowArgs{ |
| 399 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie}, |
| 400 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 401 | fu.InPort(egressHop.Ingress), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 402 | }, |
| 403 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 404 | fu.Output(egressHop.Egress), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 405 | }, |
| 406 | } |
| 407 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 408 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 409 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 410 | fg = fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 411 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 412 | deviceRules.AddFlowsAndGroup(egressHop.DeviceID, fg) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 413 | } else { |
| 414 | var fa *fu.FlowArgs |
| 415 | fa = &fu.FlowArgs{ |
| 416 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie}, |
| 417 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 418 | fu.InPort(egressHop.Ingress), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 419 | }, |
| 420 | } |
| 421 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 422 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 423 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 424 | // Augment the Actions |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 425 | filteredAction := fu.GetActions(flow, fu.OUTPUT) |
| 426 | filteredAction = append(filteredAction, fu.Output(egressHop.Egress)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 427 | fa.Actions = filteredAction |
| 428 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 429 | fg := fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 430 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 431 | deviceRules.AddFlowsAndGroup(egressHop.DeviceID, fg) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 432 | } |
| 433 | return deviceRules |
| 434 | } |
| 435 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 436 | // processMulticastFlow decompose multicast flows |
| 437 | func (fd *FlowDecomposer) processMulticastFlow(agent coreIf.LogicalDeviceAgent, route []graph.RouteHop, |
| 438 | inPortNo uint32, outPortNo uint32, flow *ofp.OfpFlowStats, grpId uint32, |
| 439 | groupMap map[uint32]*ofp.OfpGroupEntry) *fu.DeviceRules { |
| 440 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 441 | log.Debugw("multicast-flow", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo}) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 442 | deviceRules := fu.NewDeviceRules() |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 443 | |
| 444 | //having no Group yet is the same as having a Group with no buckets |
| 445 | var grp *ofp.OfpGroupEntry |
| 446 | var ok bool |
| 447 | if grp, ok = groupMap[grpId]; !ok { |
| 448 | log.Warnw("Group-id-not-present-in-map", log.Fields{"grpId": grpId, "groupMap": groupMap}) |
| 449 | return deviceRules |
| 450 | } |
| 451 | if grp == nil || grp.Desc == nil { |
| 452 | log.Warnw("Group-or-desc-nil", log.Fields{"grpId": grpId, "grp": grp}) |
| 453 | return deviceRules |
| 454 | } |
| 455 | for _, bucket := range grp.Desc.Buckets { |
| 456 | otherActions := make([]*ofp.OfpAction, 0) |
| 457 | for _, action := range bucket.Actions { |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 458 | if action.Type == fu.OUTPUT { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 459 | outPortNo = action.GetOutput().Port |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 460 | } else if action.Type != fu.POP_VLAN { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 461 | otherActions = append(otherActions, action) |
| 462 | } |
| 463 | } |
| 464 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 465 | route2 := agent.GetRoute(inPortNo, outPortNo) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 466 | switch len(route2) { |
| 467 | case 0: |
| 468 | log.Errorw("mc-no-route", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo, "comment": "deleting flow"}) |
| 469 | // TODO: Delete flow |
| 470 | return deviceRules |
| 471 | case 2: |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 472 | log.Debugw("route-found", log.Fields{"ingressHop": route2[0], "egressHop": route2[1]}) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 473 | break |
| 474 | default: |
| 475 | log.Errorw("invalid-route-length", log.Fields{"routeLen": len(route)}) |
| 476 | return deviceRules |
| 477 | } |
| 478 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 479 | ingressHop := route[0] |
| 480 | ingressHop2 := route2[0] |
| 481 | egressHop := route2[1] |
| 482 | |
| 483 | if ingressHop.Ingress != ingressHop2.Ingress { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 484 | log.Errorw("mc-ingress-hop-hop2-mismatch", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo, "comment": "ignoring flow"}) |
| 485 | return deviceRules |
| 486 | } |
| 487 | // Set the parent device flow |
| 488 | var fa *fu.FlowArgs |
| 489 | fa = &fu.FlowArgs{ |
| 490 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie}, |
| 491 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 492 | fu.InPort(ingressHop.Ingress), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 493 | }, |
| 494 | } |
| 495 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 496 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 497 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 498 | // Augment the Actions |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 499 | filteredAction := fu.GetActions(flow, fu.GROUP) |
| 500 | filteredAction = append(filteredAction, fu.PopVlan()) |
| 501 | filteredAction = append(filteredAction, fu.Output(route2[1].Ingress)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 502 | fa.Actions = filteredAction |
| 503 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 504 | fg := fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 505 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 506 | deviceRules.AddFlowsAndGroup(ingressHop.DeviceID, fg) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 507 | |
| 508 | // Set the child device flow |
| 509 | fa = &fu.FlowArgs{ |
| 510 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie}, |
| 511 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 512 | fu.InPort(egressHop.Ingress), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 513 | }, |
| 514 | } |
| 515 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 516 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT, fu.VLAN_VID, fu.VLAN_PCP)...) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 517 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 518 | // Augment the Actions |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 519 | otherActions = append(otherActions, fu.Output(egressHop.Egress)) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 520 | fa.Actions = otherActions |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 521 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 522 | fg = fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 523 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 524 | deviceRules.AddFlowsAndGroup(egressHop.DeviceID, fg) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 525 | } |
| 526 | return deviceRules |
| 527 | } |
| 528 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 529 | // decomposeFlow decomposes a flow for a logical device into flows for each physical device |
| 530 | func (fd *FlowDecomposer) decomposeFlow(agent coreIf.LogicalDeviceAgent, flow *ofp.OfpFlowStats, |
| 531 | groupMap map[uint32]*ofp.OfpGroupEntry) *fu.DeviceRules { |
| 532 | |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 533 | inPortNo := fu.GetInPort(flow) |
| 534 | outPortNo := fu.GetOutPort(flow) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 535 | deviceRules := fu.NewDeviceRules() |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 536 | route := agent.GetRoute(inPortNo, outPortNo) |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 537 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 538 | switch len(route) { |
| 539 | case 0: |
| 540 | log.Errorw("no-route", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo, "comment": "deleting-flow"}) |
| 541 | // TODO: Delete flow |
| 542 | return deviceRules |
| 543 | case 2: |
| 544 | log.Debugw("route-found", log.Fields{"ingressHop": route[0], "egressHop": route[1]}) |
| 545 | break |
| 546 | default: |
| 547 | log.Errorw("invalid-route-length", log.Fields{"routeLen": len(route)}) |
| 548 | return deviceRules |
| 549 | } |
| 550 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 551 | // Process controller bound flow |
| 552 | if outPortNo != 0 && (outPortNo&0x7fffffff) == uint32(ofp.OfpPortNo_OFPP_CONTROLLER) { |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 553 | deviceRules = fd.processControllerBoundFlow(agent, route, inPortNo, outPortNo, flow) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 554 | } else { |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 555 | var ingressDevice *voltha.Device |
| 556 | var err error |
| 557 | if ingressDevice, err = fd.deviceMgr.GetDevice(route[0].DeviceID); err != nil { |
| 558 | log.Errorw("ingress-device-not-found", log.Fields{"deviceId": route[0].DeviceID, "flow": flow}) |
| 559 | return deviceRules |
| 560 | } |
| 561 | isUpstream := !ingressDevice.Root |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 562 | if isUpstream { |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 563 | deviceRules = fd.processUpstreamNonControllerBoundFlow(agent, route, inPortNo, outPortNo, flow) |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 564 | } else if fu.HasNextTable(flow) { |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 565 | deviceRules = fd.processDownstreamFlowWithNextTable(agent, route, inPortNo, outPortNo, flow) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 566 | } else if outPortNo != 0 { // Unicast |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 567 | deviceRules = fd.processUnicastFlow(agent, route, inPortNo, outPortNo, flow) |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 568 | } else if grpId := fu.GetGroup(flow); grpId != 0 { //Multicast |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 569 | deviceRules = fd.processMulticastFlow(agent, route, inPortNo, outPortNo, flow, grpId, groupMap) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 570 | } |
| 571 | } |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 572 | deviceRules = fd.updateOutputPortForControllerBoundFlowForParentDevide(flow, deviceRules) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 573 | return deviceRules |
| 574 | } |