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/rw_core/coreIf" |
| 22 | "github.com/opencord/voltha-go/rw_core/graph" |
Scott Baker | b671a86 | 2019-10-24 10:53:40 -0700 | [diff] [blame] | 23 | fu "github.com/opencord/voltha-lib-go/pkg/flows" |
Scott Baker | cb7c88a | 2019-10-16 18:32:48 -0700 | [diff] [blame] | 24 | "github.com/opencord/voltha-lib-go/pkg/log" |
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() |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 108 | meterId := fu.GetMeterIdFromFlow(flow) |
| 109 | metadataFromwriteMetadata := fu.GetMetadataFromWriteMetadataAction(flow) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 110 | |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 111 | ingressHop := route[0] |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 112 | egressHop := route[1] |
| 113 | |
Humera Kouser | 4ff8901 | 2019-08-25 19:01:51 -0400 | [diff] [blame] | 114 | //case of packet_in from NNI port rule |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 115 | if agent.GetDeviceGraph().IsRootPort(inPortNo) { |
Humera Kouser | 4ff8901 | 2019-08-25 19:01:51 -0400 | [diff] [blame] | 116 | // Trap flow for NNI port |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 117 | log.Debug("trap-nni") |
Humera Kouser | 4ff8901 | 2019-08-25 19:01:51 -0400 | [diff] [blame] | 118 | |
| 119 | var fa *fu.FlowArgs |
| 120 | fa = &fu.FlowArgs{ |
| 121 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie}, |
| 122 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 123 | fu.InPort(egressHop.Egress), |
| 124 | }, |
| 125 | Actions: fu.GetActions(flow), |
| 126 | } |
| 127 | // Augment the matchfields with the ofpfields from the flow |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 128 | fg := fu.NewFlowsAndGroups() |
Humera Kouser | 4ff8901 | 2019-08-25 19:01:51 -0400 | [diff] [blame] | 129 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
| 130 | fg.AddFlow(fu.MkFlowStat(fa)) |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 131 | deviceRules.AddFlowsAndGroup(egressHop.DeviceID, fg) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 132 | } else { |
| 133 | // Trap flow for UNI port |
| 134 | log.Debug("trap-uni") |
| 135 | |
| 136 | //inPortNo is 0 for wildcard input case, do not include upstream port for 4000 flow in input |
| 137 | var inPorts []uint32 |
| 138 | if inPortNo == 0 { |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 139 | inPorts = agent.GetWildcardInputPorts(egressHop.Egress) // exclude egress_hop.egress_port.port_no |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 140 | } else { |
| 141 | inPorts = []uint32{inPortNo} |
| 142 | } |
| 143 | for _, inputPort := range inPorts { |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 144 | // Upstream flow on parent (olt) device |
| 145 | var faParent *fu.FlowArgs |
| 146 | faParent = &fu.FlowArgs{ |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 147 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie, "meter_id": uint64(meterId), "write_metadata": metadataFromwriteMetadata}, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 148 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 149 | fu.InPort(egressHop.Ingress), |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 150 | fu.TunnelId(uint64(inputPort)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 151 | }, |
| 152 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 153 | fu.PushVlan(0x8100), |
| 154 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 4000)), |
| 155 | fu.Output(egressHop.Egress), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 156 | }, |
| 157 | } |
| 158 | // Augment the matchfields with the ofpfields from the flow |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 159 | faParent.MatchFields = append(faParent.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
| 160 | fgParent := fu.NewFlowsAndGroups() |
| 161 | fgParent.AddFlow(fu.MkFlowStat(faParent)) |
| 162 | deviceRules.AddFlowsAndGroup(egressHop.DeviceID, fgParent) |
| 163 | log.Debugw("parent-trap-flow-set", log.Fields{"flow": faParent}) |
| 164 | |
| 165 | // Upstream flow on child (onu) device |
| 166 | var actions []*ofp.OfpAction |
| 167 | setvid := fu.GetVlanVid(flow) |
| 168 | if setvid != nil { |
| 169 | // have this child push the vlan the parent is matching/trapping on above |
| 170 | actions = []*ofp.OfpAction{ |
| 171 | fu.PushVlan(0x8100), |
| 172 | fu.SetField(fu.VlanVid(*setvid)), |
| 173 | fu.Output(ingressHop.Egress), |
| 174 | } |
| 175 | } else { |
| 176 | // otherwise just set the egress port |
| 177 | actions = []*ofp.OfpAction{ |
| 178 | fu.Output(ingressHop.Egress), |
| 179 | } |
| 180 | } |
| 181 | var faChild *fu.FlowArgs |
| 182 | faChild = &fu.FlowArgs{ |
| 183 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie, "meter_id": uint64(meterId), "write_metadata": metadataFromwriteMetadata}, |
| 184 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 185 | fu.InPort(ingressHop.Ingress), |
| 186 | fu.TunnelId(uint64(inputPort)), |
| 187 | }, |
| 188 | Actions: actions, |
| 189 | } |
| 190 | // Augment the matchfields with the ofpfields from the flow. |
| 191 | // If the parent has a match vid and the child is setting that match vid exclude the the match vlan |
| 192 | // for the child given it will be setting that vlan and the parent will be matching on it |
| 193 | if setvid != nil { |
| 194 | faChild.MatchFields = append(faChild.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT, fu.VLAN_VID)...) |
| 195 | } else { |
| 196 | faChild.MatchFields = append(faChild.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
| 197 | } |
| 198 | fgChild := fu.NewFlowsAndGroups() |
| 199 | fgChild.AddFlow(fu.MkFlowStat(faChild)) |
| 200 | deviceRules.AddFlowsAndGroup(ingressHop.DeviceID, fgChild) |
| 201 | log.Debugw("child-trap-flow-set", log.Fields{"flow": faChild}) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 202 | } |
| 203 | } |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 204 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 205 | return deviceRules |
| 206 | } |
| 207 | |
| 208 | // processUpstreamNonControllerBoundFlow processes non-controller bound flow. We assume that anything that is |
| 209 | // upstream needs to get Q-in-Q treatment and that this is expressed via two flow rules, the first using the |
| 210 | // goto-statement. We also assume that the inner tag is applied at the ONU, while the outer tag is |
| 211 | // applied at the OLT |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 212 | func (fd *FlowDecomposer) processUpstreamNonControllerBoundFlow(agent coreIf.LogicalDeviceAgent, |
| 213 | route []graph.RouteHop, inPortNo uint32, outPortNo uint32, flow *ofp.OfpFlowStats) *fu.DeviceRules { |
| 214 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 215 | log.Debugw("upstream-non-controller-bound-flow", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo}) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 216 | deviceRules := fu.NewDeviceRules() |
| 217 | |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 218 | meterId := fu.GetMeterIdFromFlow(flow) |
| 219 | metadataFromwriteMetadata := fu.GetMetadataFromWriteMetadataAction(flow) |
| 220 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 221 | ingressHop := route[0] |
| 222 | egressHop := route[1] |
| 223 | |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 224 | if flow.TableId == 0 && fu.HasNextTable(flow) { |
| 225 | log.Debugw("decomposing-onu-flow-in-upstream-has-next-table", log.Fields{"table_id": flow.TableId}) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 226 | if outPortNo != 0 { |
| 227 | log.Warnw("outPort-should-not-be-specified", log.Fields{"outPortNo": outPortNo}) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 228 | return deviceRules |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 229 | } |
| 230 | var fa *fu.FlowArgs |
| 231 | fa = &fu.FlowArgs{ |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 232 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie, "meter_id": uint64(meterId), "write_metadata": metadataFromwriteMetadata}, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 233 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 234 | fu.InPort(ingressHop.Ingress), |
| 235 | fu.TunnelId(uint64(inPortNo)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 236 | }, |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 237 | Actions: fu.GetActions(flow), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 238 | } |
| 239 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 240 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 241 | |
| 242 | // Augment the Actions |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 243 | fa.Actions = append(fa.Actions, fu.Output(ingressHop.Egress)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 244 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 245 | fg := fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 246 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 247 | deviceRules.AddFlowsAndGroup(ingressHop.DeviceID, fg) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 248 | } else if flow.TableId == 1 && outPortNo != 0 { |
| 249 | log.Debugw("decomposing-olt-flow-in-upstream-has-next-table", log.Fields{"table_id": flow.TableId}) |
| 250 | var fa *fu.FlowArgs |
| 251 | fa = &fu.FlowArgs{ |
| 252 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie, "meter_id": uint64(meterId), "write_metadata": metadataFromwriteMetadata}, |
| 253 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 254 | fu.InPort(egressHop.Ingress), |
| 255 | fu.TunnelId(uint64(inPortNo)), |
| 256 | }, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 257 | } |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 258 | // Augment the matchfields with the ofpfields from the flow |
| 259 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 260 | |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 261 | //Augment the actions |
| 262 | filteredAction := fu.GetActions(flow, fu.OUTPUT) |
| 263 | filteredAction = append(filteredAction, fu.Output(egressHop.Egress)) |
| 264 | fa.Actions = filteredAction |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 265 | |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 266 | fg := fu.NewFlowsAndGroups() |
| 267 | fg.AddFlow(fu.MkFlowStat(fa)) |
| 268 | deviceRules.AddFlowsAndGroup(egressHop.DeviceID, fg) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 269 | } |
| 270 | return deviceRules |
| 271 | } |
| 272 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 273 | // processDownstreamFlowWithNextTable decomposes downstream flows containing next table ID instructions |
| 274 | func (fd *FlowDecomposer) processDownstreamFlowWithNextTable(agent coreIf.LogicalDeviceAgent, route []graph.RouteHop, |
| 275 | inPortNo uint32, outPortNo uint32, flow *ofp.OfpFlowStats) *fu.DeviceRules { |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 276 | log.Debugw("decomposing-olt-flow-in-downstream-flow-with-next-table", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo}) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 277 | deviceRules := fu.NewDeviceRules() |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 278 | meterId := fu.GetMeterIdFromFlow(flow) |
| 279 | metadataFromwriteMetadata := fu.GetMetadataFromWriteMetadataAction(flow) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 280 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 281 | if outPortNo != 0 { |
| 282 | log.Warnw("outPort-should-not-be-specified", log.Fields{"outPortNo": outPortNo}) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 283 | return deviceRules |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 284 | } |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 285 | |
| 286 | if flow.TableId != 0 { |
| 287 | log.Warnw("This is not olt pipeline table, so skipping", log.Fields{"tableId": flow.TableId}) |
| 288 | return deviceRules |
| 289 | } |
| 290 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 291 | ingressHop := route[0] |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 292 | egressHop := route[1] |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 293 | if metadataFromwriteMetadata != 0 { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 294 | log.Debugw("creating-metadata-flow", log.Fields{"flow": flow}) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 295 | portNumber := fu.GetEgressPortNumberFromWriteMetadata(flow) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 296 | if portNumber != 0 { |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 297 | recalculatedRoute := agent.GetRoute(inPortNo, portNumber) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 298 | switch len(recalculatedRoute) { |
| 299 | case 0: |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 300 | log.Errorw("no-route-double-tag", log.Fields{"inPortNo": inPortNo, "outPortNo": portNumber, "comment": "deleting-flow", "metadata": metadataFromwriteMetadata}) |
| 301 | //TODO: Delete flow |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 302 | return deviceRules |
| 303 | case 2: |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 304 | log.Debugw("route-found", log.Fields{"ingressHop": ingressHop, "egressHop": egressHop}) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 305 | break |
| 306 | default: |
| 307 | log.Errorw("invalid-route-length", log.Fields{"routeLen": len(route)}) |
| 308 | return deviceRules |
| 309 | } |
| 310 | ingressHop = recalculatedRoute[0] |
| 311 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 312 | innerTag := fu.GetInnerTagFromMetaData(flow) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 313 | if innerTag == 0 { |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 314 | log.Errorw("no-inner-route-double-tag", log.Fields{"inPortNo": inPortNo, "outPortNo": portNumber, "comment": "deleting-flow", "metadata": metadataFromwriteMetadata}) |
| 315 | //TODO: Delete flow |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 316 | return deviceRules |
| 317 | } |
| 318 | var fa *fu.FlowArgs |
| 319 | fa = &fu.FlowArgs{ |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 320 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie, "meter_id": uint64(meterId), "write_metadata": metadataFromwriteMetadata}, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 321 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 322 | fu.InPort(ingressHop.Ingress), |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 323 | fu.Metadata_ofp(uint64(innerTag)), |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 324 | fu.TunnelId(uint64(portNumber)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 325 | }, |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 326 | Actions: fu.GetActions(flow), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 327 | } |
| 328 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 329 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT, fu.METADATA)...) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 330 | |
| 331 | // Augment the Actions |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 332 | fa.Actions = append(fa.Actions, fu.Output(ingressHop.Egress)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 333 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 334 | fg := fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 335 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 336 | deviceRules.AddFlowsAndGroup(ingressHop.DeviceID, fg) |
| 337 | } else { // Create standard flow |
| 338 | log.Debugw("creating-standard-flow", log.Fields{"flow": flow}) |
| 339 | var fa *fu.FlowArgs |
| 340 | fa = &fu.FlowArgs{ |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 341 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie, "meter_id": uint64(meterId), "write_metadata": metadataFromwriteMetadata}, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 342 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 343 | fu.InPort(ingressHop.Ingress), |
| 344 | fu.TunnelId(uint64(inPortNo)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 345 | }, |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 346 | Actions: fu.GetActions(flow), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 347 | } |
| 348 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 349 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 350 | |
| 351 | // Augment the Actions |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 352 | fa.Actions = append(fa.Actions, fu.Output(ingressHop.Egress)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 353 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 354 | fg := fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 355 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 356 | deviceRules.AddFlowsAndGroup(ingressHop.DeviceID, fg) |
| 357 | } |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 358 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 359 | return deviceRules |
| 360 | } |
| 361 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 362 | // processUnicastFlow decomposes unicast flows |
| 363 | func (fd *FlowDecomposer) processUnicastFlow(agent coreIf.LogicalDeviceAgent, route []graph.RouteHop, |
| 364 | inPortNo uint32, outPortNo uint32, flow *ofp.OfpFlowStats) *fu.DeviceRules { |
| 365 | |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 366 | log.Debugw("decomposing-onu-flow-in-downstream-unicast-flow", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo}) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 367 | deviceRules := fu.NewDeviceRules() |
| 368 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 369 | egressHop := route[1] |
| 370 | |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 371 | meterId := fu.GetMeterIdFromFlow(flow) |
| 372 | metadataFromwriteMetadata := fu.GetMetadataFromWriteMetadataAction(flow) |
| 373 | var fa *fu.FlowArgs |
| 374 | fa = &fu.FlowArgs{ |
| 375 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie, "meter_id": uint64(meterId), "write_metadata": metadataFromwriteMetadata}, |
| 376 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 377 | fu.InPort(egressHop.Ingress), |
| 378 | }, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 379 | } |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 380 | // Augment the matchfields with the ofpfields from the flow |
| 381 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 382 | |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 383 | // Augment the Actions |
| 384 | filteredAction := fu.GetActions(flow, fu.OUTPUT) |
| 385 | filteredAction = append(filteredAction, fu.Output(egressHop.Egress)) |
| 386 | fa.Actions = filteredAction |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 387 | |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 388 | fg := fu.NewFlowsAndGroups() |
| 389 | fg.AddFlow(fu.MkFlowStat(fa)) |
| 390 | deviceRules.AddFlowsAndGroup(egressHop.DeviceID, fg) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 391 | return deviceRules |
| 392 | } |
| 393 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 394 | // processMulticastFlow decompose multicast flows |
| 395 | func (fd *FlowDecomposer) processMulticastFlow(agent coreIf.LogicalDeviceAgent, route []graph.RouteHop, |
| 396 | inPortNo uint32, outPortNo uint32, flow *ofp.OfpFlowStats, grpId uint32, |
| 397 | groupMap map[uint32]*ofp.OfpGroupEntry) *fu.DeviceRules { |
| 398 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 399 | log.Debugw("multicast-flow", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo}) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 400 | deviceRules := fu.NewDeviceRules() |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 401 | |
| 402 | //having no Group yet is the same as having a Group with no buckets |
| 403 | var grp *ofp.OfpGroupEntry |
| 404 | var ok bool |
| 405 | if grp, ok = groupMap[grpId]; !ok { |
| 406 | log.Warnw("Group-id-not-present-in-map", log.Fields{"grpId": grpId, "groupMap": groupMap}) |
| 407 | return deviceRules |
| 408 | } |
| 409 | if grp == nil || grp.Desc == nil { |
| 410 | log.Warnw("Group-or-desc-nil", log.Fields{"grpId": grpId, "grp": grp}) |
| 411 | return deviceRules |
| 412 | } |
| 413 | for _, bucket := range grp.Desc.Buckets { |
| 414 | otherActions := make([]*ofp.OfpAction, 0) |
| 415 | for _, action := range bucket.Actions { |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 416 | if action.Type == fu.OUTPUT { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 417 | outPortNo = action.GetOutput().Port |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 418 | } else if action.Type != fu.POP_VLAN { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 419 | otherActions = append(otherActions, action) |
| 420 | } |
| 421 | } |
| 422 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 423 | route2 := agent.GetRoute(inPortNo, outPortNo) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 424 | switch len(route2) { |
| 425 | case 0: |
| 426 | log.Errorw("mc-no-route", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo, "comment": "deleting flow"}) |
| 427 | // TODO: Delete flow |
| 428 | return deviceRules |
| 429 | case 2: |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 430 | log.Debugw("route-found", log.Fields{"ingressHop": route2[0], "egressHop": route2[1]}) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 431 | break |
| 432 | default: |
| 433 | log.Errorw("invalid-route-length", log.Fields{"routeLen": len(route)}) |
| 434 | return deviceRules |
| 435 | } |
| 436 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 437 | ingressHop := route[0] |
| 438 | ingressHop2 := route2[0] |
| 439 | egressHop := route2[1] |
| 440 | |
| 441 | if ingressHop.Ingress != ingressHop2.Ingress { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 442 | log.Errorw("mc-ingress-hop-hop2-mismatch", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo, "comment": "ignoring flow"}) |
| 443 | return deviceRules |
| 444 | } |
| 445 | // Set the parent device flow |
| 446 | var fa *fu.FlowArgs |
| 447 | fa = &fu.FlowArgs{ |
| 448 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie}, |
| 449 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 450 | fu.InPort(ingressHop.Ingress), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 451 | }, |
| 452 | } |
| 453 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 454 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 455 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 456 | // Augment the Actions |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 457 | filteredAction := fu.GetActions(flow, fu.GROUP) |
| 458 | filteredAction = append(filteredAction, fu.PopVlan()) |
| 459 | filteredAction = append(filteredAction, fu.Output(route2[1].Ingress)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 460 | fa.Actions = filteredAction |
| 461 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 462 | fg := fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 463 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 464 | deviceRules.AddFlowsAndGroup(ingressHop.DeviceID, fg) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 465 | |
| 466 | // Set the child device flow |
| 467 | fa = &fu.FlowArgs{ |
| 468 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie}, |
| 469 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 470 | fu.InPort(egressHop.Ingress), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 471 | }, |
| 472 | } |
| 473 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 474 | 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] | 475 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 476 | // Augment the Actions |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 477 | otherActions = append(otherActions, fu.Output(egressHop.Egress)) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 478 | fa.Actions = otherActions |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 479 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 480 | fg = fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 481 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 482 | deviceRules.AddFlowsAndGroup(egressHop.DeviceID, fg) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 483 | } |
| 484 | return deviceRules |
| 485 | } |
| 486 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 487 | // decomposeFlow decomposes a flow for a logical device into flows for each physical device |
| 488 | func (fd *FlowDecomposer) decomposeFlow(agent coreIf.LogicalDeviceAgent, flow *ofp.OfpFlowStats, |
| 489 | groupMap map[uint32]*ofp.OfpGroupEntry) *fu.DeviceRules { |
| 490 | |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 491 | inPortNo := fu.GetInPort(flow) |
| 492 | outPortNo := fu.GetOutPort(flow) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 493 | deviceRules := fu.NewDeviceRules() |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 494 | route := agent.GetRoute(inPortNo, outPortNo) |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 495 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 496 | switch len(route) { |
| 497 | case 0: |
| 498 | log.Errorw("no-route", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo, "comment": "deleting-flow"}) |
| 499 | // TODO: Delete flow |
| 500 | return deviceRules |
| 501 | case 2: |
| 502 | log.Debugw("route-found", log.Fields{"ingressHop": route[0], "egressHop": route[1]}) |
| 503 | break |
| 504 | default: |
| 505 | log.Errorw("invalid-route-length", log.Fields{"routeLen": len(route)}) |
| 506 | return deviceRules |
| 507 | } |
| 508 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 509 | // Process controller bound flow |
| 510 | if outPortNo != 0 && (outPortNo&0x7fffffff) == uint32(ofp.OfpPortNo_OFPP_CONTROLLER) { |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 511 | deviceRules = fd.processControllerBoundFlow(agent, route, inPortNo, outPortNo, flow) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 512 | } else { |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 513 | var ingressDevice *voltha.Device |
| 514 | var err error |
| 515 | if ingressDevice, err = fd.deviceMgr.GetDevice(route[0].DeviceID); err != nil { |
| 516 | log.Errorw("ingress-device-not-found", log.Fields{"deviceId": route[0].DeviceID, "flow": flow}) |
| 517 | return deviceRules |
| 518 | } |
| 519 | isUpstream := !ingressDevice.Root |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 520 | if isUpstream { // Unicast OLT and ONU UL |
| 521 | log.Info("processOltAndOnuUpstreamNonControllerBoundUnicastFlows", log.Fields{"flows": flow}) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 522 | deviceRules = fd.processUpstreamNonControllerBoundFlow(agent, route, inPortNo, outPortNo, flow) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 523 | } else if fu.HasNextTable(flow) && flow.TableId == 0 { // Unicast OLT flow DL |
| 524 | log.Debugw("processOltDownstreamNonControllerBoundFlowWithNextTable", log.Fields{"flows": flow}) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 525 | deviceRules = fd.processDownstreamFlowWithNextTable(agent, route, inPortNo, outPortNo, flow) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 526 | } else if flow.TableId == 1 && outPortNo != 0 { // Unicast ONU flow DL |
| 527 | log.Debugw("processOnuDownstreamUnicastFlow", log.Fields{"flows": flow}) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 528 | deviceRules = fd.processUnicastFlow(agent, route, inPortNo, outPortNo, flow) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 529 | } else if grpId := fu.GetGroup(flow); grpId != 0 && flow.TableId == 0 { //Multicast |
| 530 | log.Debugw("processMulticastFlow", log.Fields{"flows": flow}) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 531 | deviceRules = fd.processMulticastFlow(agent, route, inPortNo, outPortNo, flow, grpId, groupMap) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 532 | } else { |
| 533 | log.Errorw("unknown-downstream-flow", log.Fields{"flow": *flow}) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 534 | } |
| 535 | } |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 536 | deviceRules = fd.updateOutputPortForControllerBoundFlowForParentDevide(flow, deviceRules) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 537 | return deviceRules |
| 538 | } |