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 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 17 | package flowdecomposition |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 18 | |
| 19 | import ( |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 20 | "context" |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 21 | "github.com/gogo/protobuf/proto" |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 22 | "github.com/opencord/voltha-go/rw_core/coreif" |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 23 | "github.com/opencord/voltha-go/rw_core/route" |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 24 | fu "github.com/opencord/voltha-lib-go/v3/pkg/flows" |
| 25 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 26 | ofp "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 27 | "github.com/opencord/voltha-protos/v3/go/voltha" |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 28 | "google.golang.org/grpc/codes" |
| 29 | "google.golang.org/grpc/status" |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 30 | ) |
| 31 | |
| 32 | func init() { |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 33 | _, err := log.AddPackage(log.JSON, log.DebugLevel, nil) |
| 34 | if err != nil { |
| 35 | log.Errorw("unable-to-register-package-to-the-log-map", log.Fields{"error": err}) |
| 36 | } |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 37 | } |
| 38 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 39 | // FlowDecomposer represent flow decomposer attribute |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 40 | type FlowDecomposer struct { |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 41 | deviceMgr coreif.DeviceManager |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 42 | } |
| 43 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 44 | // NewFlowDecomposer creates flow decomposer instance |
| 45 | func NewFlowDecomposer(deviceMgr coreif.DeviceManager) *FlowDecomposer { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 46 | var decomposer FlowDecomposer |
| 47 | decomposer.deviceMgr = deviceMgr |
| 48 | return &decomposer |
| 49 | } |
| 50 | |
| 51 | //DecomposeRules decomposes per-device flows and flow-groups from the flows and groups defined on a logical device |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 52 | func (fd *FlowDecomposer) DecomposeRules(ctx context.Context, agent coreif.LogicalDeviceAgent, flows ofp.Flows, groups ofp.FlowGroups) (*fu.DeviceRules, error) { |
khenaidoo | 3306c99 | 2019-05-24 16:57:35 -0400 | [diff] [blame] | 53 | deviceRules := *fu.NewDeviceRules() |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 54 | devicesToUpdate := make(map[string]string) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 55 | |
| 56 | groupMap := make(map[uint32]*ofp.OfpGroupEntry) |
| 57 | for _, groupEntry := range groups.Items { |
| 58 | groupMap[groupEntry.Desc.GroupId] = groupEntry |
| 59 | } |
| 60 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 61 | for _, flow := range flows.Items { |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 62 | decomposedRules, err := fd.decomposeFlow(ctx, agent, flow, groupMap) |
| 63 | if err != nil { |
| 64 | return nil, err |
| 65 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 66 | for deviceID, flowAndGroups := range decomposedRules.Rules { |
| 67 | deviceRules.CreateEntryIfNotExist(deviceID) |
| 68 | deviceRules.Rules[deviceID].AddFrom(flowAndGroups) |
| 69 | devicesToUpdate[deviceID] = deviceID |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 70 | } |
| 71 | } |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 72 | return deviceRules.FilterRules(devicesToUpdate), nil |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 73 | } |
| 74 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 75 | // Handles special case of any controller-bound flow for a parent device |
| 76 | func (fd *FlowDecomposer) updateOutputPortForControllerBoundFlowForParentDevide(flow *ofp.OfpFlowStats, |
| 77 | dr *fu.DeviceRules) *fu.DeviceRules { |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 78 | EAPOL := fu.EthType(0x888e) |
| 79 | IGMP := fu.IpProto(2) |
| 80 | UDP := fu.IpProto(17) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 81 | |
| 82 | newDeviceRules := dr.Copy() |
| 83 | // Check whether we are dealing with a parent device |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 84 | for deviceID, fg := range dr.GetRules() { |
| 85 | if root, _ := fd.deviceMgr.IsRootDevice(deviceID); root { |
| 86 | newDeviceRules.ClearFlows(deviceID) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 87 | for i := 0; i < fg.Flows.Len(); i++ { |
| 88 | f := fg.GetFlow(i) |
| 89 | UpdateOutPortNo := false |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 90 | for _, field := range fu.GetOfbFields(f) { |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 91 | UpdateOutPortNo = (field.String() == EAPOL.String()) |
| 92 | UpdateOutPortNo = UpdateOutPortNo || (field.String() == IGMP.String()) |
| 93 | UpdateOutPortNo = UpdateOutPortNo || (field.String() == UDP.String()) |
| 94 | if UpdateOutPortNo { |
| 95 | break |
| 96 | } |
| 97 | } |
| 98 | if UpdateOutPortNo { |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 99 | f = fu.UpdateOutputPortByActionType(f, uint32(ofp.OfpInstructionType_OFPIT_APPLY_ACTIONS), |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 100 | uint32(ofp.OfpPortNo_OFPP_CONTROLLER)) |
| 101 | } |
| 102 | // 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] | 103 | f.Id = fu.HashFlowStats(f) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 104 | newDeviceRules.AddFlow(deviceID, (proto.Clone(f)).(*ofp.OfpFlowStats)) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | } |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 108 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 109 | return newDeviceRules |
| 110 | } |
| 111 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 112 | //processControllerBoundFlow decomposes trap flows |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 113 | func (fd *FlowDecomposer) processControllerBoundFlow(ctx context.Context, agent coreif.LogicalDeviceAgent, path []route.Hop, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 114 | inPortNo uint32, outPortNo uint32, flow *ofp.OfpFlowStats) *fu.DeviceRules { |
| 115 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 116 | log.Debugw("trap-flow", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo, "flow": flow}) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 117 | deviceRules := fu.NewDeviceRules() |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 118 | meterID := fu.GetMeterIdFromFlow(flow) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 119 | metadataFromwriteMetadata := fu.GetMetadataFromWriteMetadataAction(flow) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 120 | |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 121 | ingressHop := path[0] |
| 122 | egressHop := path[1] |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 123 | |
Humera Kouser | 4ff8901 | 2019-08-25 19:01:51 -0400 | [diff] [blame] | 124 | //case of packet_in from NNI port rule |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 125 | if agent.GetDeviceRoutes().IsRootPort(inPortNo) { |
Humera Kouser | 4ff8901 | 2019-08-25 19:01:51 -0400 | [diff] [blame] | 126 | // Trap flow for NNI port |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 127 | log.Debug("trap-nni") |
Humera Kouser | 4ff8901 | 2019-08-25 19:01:51 -0400 | [diff] [blame] | 128 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 129 | fa := &fu.FlowArgs{ |
Humera Kouser | 4ff8901 | 2019-08-25 19:01:51 -0400 | [diff] [blame] | 130 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie}, |
| 131 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 132 | fu.InPort(egressHop.Egress), |
| 133 | }, |
| 134 | Actions: fu.GetActions(flow), |
| 135 | } |
| 136 | // Augment the matchfields with the ofpfields from the flow |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 137 | fg := fu.NewFlowsAndGroups() |
Humera Kouser | 4ff8901 | 2019-08-25 19:01:51 -0400 | [diff] [blame] | 138 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
| 139 | fg.AddFlow(fu.MkFlowStat(fa)) |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 140 | deviceRules.AddFlowsAndGroup(egressHop.DeviceID, fg) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 141 | } else { |
| 142 | // Trap flow for UNI port |
| 143 | log.Debug("trap-uni") |
| 144 | |
| 145 | //inPortNo is 0 for wildcard input case, do not include upstream port for 4000 flow in input |
| 146 | var inPorts []uint32 |
| 147 | if inPortNo == 0 { |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 148 | inPorts = agent.GetWildcardInputPorts(egressHop.Egress) // exclude egress_hop.egress_port.port_no |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 149 | } else { |
| 150 | inPorts = []uint32{inPortNo} |
| 151 | } |
| 152 | for _, inputPort := range inPorts { |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 153 | // Upstream flow on parent (olt) device |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 154 | faParent := &fu.FlowArgs{ |
| 155 | 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] | 156 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 157 | fu.InPort(egressHop.Ingress), |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 158 | fu.TunnelId(uint64(inputPort)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 159 | }, |
| 160 | Actions: []*ofp.OfpAction{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 161 | fu.PushVlan(0x8100), |
| 162 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 4000)), |
| 163 | fu.Output(egressHop.Egress), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 164 | }, |
| 165 | } |
| 166 | // Augment the matchfields with the ofpfields from the flow |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 167 | faParent.MatchFields = append(faParent.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
| 168 | fgParent := fu.NewFlowsAndGroups() |
| 169 | fgParent.AddFlow(fu.MkFlowStat(faParent)) |
| 170 | deviceRules.AddFlowsAndGroup(egressHop.DeviceID, fgParent) |
| 171 | log.Debugw("parent-trap-flow-set", log.Fields{"flow": faParent}) |
| 172 | |
| 173 | // Upstream flow on child (onu) device |
| 174 | var actions []*ofp.OfpAction |
| 175 | setvid := fu.GetVlanVid(flow) |
| 176 | if setvid != nil { |
| 177 | // have this child push the vlan the parent is matching/trapping on above |
| 178 | actions = []*ofp.OfpAction{ |
| 179 | fu.PushVlan(0x8100), |
| 180 | fu.SetField(fu.VlanVid(*setvid)), |
| 181 | fu.Output(ingressHop.Egress), |
| 182 | } |
| 183 | } else { |
| 184 | // otherwise just set the egress port |
| 185 | actions = []*ofp.OfpAction{ |
| 186 | fu.Output(ingressHop.Egress), |
| 187 | } |
| 188 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 189 | faChild := &fu.FlowArgs{ |
| 190 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie, "meter_id": uint64(meterID), "write_metadata": metadataFromwriteMetadata}, |
Matt Jeanneret | b423bad | 2019-10-10 20:42:19 -0400 | [diff] [blame] | 191 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 192 | fu.InPort(ingressHop.Ingress), |
| 193 | fu.TunnelId(uint64(inputPort)), |
| 194 | }, |
| 195 | Actions: actions, |
| 196 | } |
| 197 | // Augment the matchfields with the ofpfields from the flow. |
| 198 | // If the parent has a match vid and the child is setting that match vid exclude the the match vlan |
| 199 | // for the child given it will be setting that vlan and the parent will be matching on it |
| 200 | if setvid != nil { |
| 201 | faChild.MatchFields = append(faChild.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT, fu.VLAN_VID)...) |
| 202 | } else { |
| 203 | faChild.MatchFields = append(faChild.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
| 204 | } |
| 205 | fgChild := fu.NewFlowsAndGroups() |
| 206 | fgChild.AddFlow(fu.MkFlowStat(faChild)) |
| 207 | deviceRules.AddFlowsAndGroup(ingressHop.DeviceID, fgChild) |
| 208 | log.Debugw("child-trap-flow-set", log.Fields{"flow": faChild}) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 209 | } |
| 210 | } |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 211 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 212 | return deviceRules |
| 213 | } |
| 214 | |
| 215 | // processUpstreamNonControllerBoundFlow processes non-controller bound flow. We assume that anything that is |
| 216 | // upstream needs to get Q-in-Q treatment and that this is expressed via two flow rules, the first using the |
| 217 | // goto-statement. We also assume that the inner tag is applied at the ONU, while the outer tag is |
| 218 | // applied at the OLT |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 219 | func (fd *FlowDecomposer) processUpstreamNonControllerBoundFlow(ctx context.Context, |
| 220 | path []route.Hop, inPortNo uint32, outPortNo uint32, flow *ofp.OfpFlowStats) *fu.DeviceRules { |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 221 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 222 | log.Debugw("upstream-non-controller-bound-flow", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo}) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 223 | deviceRules := fu.NewDeviceRules() |
| 224 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 225 | meterID := fu.GetMeterIdFromFlow(flow) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 226 | metadataFromwriteMetadata := fu.GetMetadataFromWriteMetadataAction(flow) |
| 227 | |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 228 | ingressHop := path[0] |
| 229 | egressHop := path[1] |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 230 | |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 231 | if flow.TableId == 0 && fu.HasNextTable(flow) { |
| 232 | 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] | 233 | if outPortNo != 0 { |
| 234 | log.Warnw("outPort-should-not-be-specified", log.Fields{"outPortNo": outPortNo}) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 235 | return deviceRules |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 236 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 237 | fa := &fu.FlowArgs{ |
| 238 | 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] | 239 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 240 | fu.InPort(ingressHop.Ingress), |
| 241 | fu.TunnelId(uint64(inPortNo)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 242 | }, |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 243 | Actions: fu.GetActions(flow), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 244 | } |
| 245 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 246 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 247 | |
| 248 | // Augment the Actions |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 249 | fa.Actions = append(fa.Actions, fu.Output(ingressHop.Egress)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 250 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 251 | fg := fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 252 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 253 | deviceRules.AddFlowsAndGroup(ingressHop.DeviceID, fg) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 254 | } else if flow.TableId == 1 && outPortNo != 0 { |
| 255 | log.Debugw("decomposing-olt-flow-in-upstream-has-next-table", log.Fields{"table_id": flow.TableId}) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 256 | fa := &fu.FlowArgs{ |
| 257 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie, "meter_id": uint64(meterID), "write_metadata": metadataFromwriteMetadata}, |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 258 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 259 | fu.InPort(egressHop.Ingress), |
| 260 | fu.TunnelId(uint64(inPortNo)), |
| 261 | }, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 262 | } |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 263 | // Augment the matchfields with the ofpfields from the flow |
| 264 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 265 | |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 266 | //Augment the actions |
| 267 | filteredAction := fu.GetActions(flow, fu.OUTPUT) |
| 268 | filteredAction = append(filteredAction, fu.Output(egressHop.Egress)) |
| 269 | fa.Actions = filteredAction |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 270 | |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 271 | fg := fu.NewFlowsAndGroups() |
| 272 | fg.AddFlow(fu.MkFlowStat(fa)) |
| 273 | deviceRules.AddFlowsAndGroup(egressHop.DeviceID, fg) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 274 | } |
| 275 | return deviceRules |
| 276 | } |
| 277 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 278 | // processDownstreamFlowWithNextTable decomposes downstream flows containing next table ID instructions |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 279 | func (fd *FlowDecomposer) processDownstreamFlowWithNextTable(ctx context.Context, agent coreif.LogicalDeviceAgent, path []route.Hop, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 280 | inPortNo uint32, outPortNo uint32, flow *ofp.OfpFlowStats) *fu.DeviceRules { |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 281 | 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] | 282 | deviceRules := fu.NewDeviceRules() |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 283 | meterID := fu.GetMeterIdFromFlow(flow) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 284 | metadataFromwriteMetadata := fu.GetMetadataFromWriteMetadataAction(flow) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 285 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 286 | if outPortNo != 0 { |
| 287 | log.Warnw("outPort-should-not-be-specified", log.Fields{"outPortNo": outPortNo}) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 288 | return deviceRules |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 289 | } |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 290 | |
| 291 | if flow.TableId != 0 { |
| 292 | log.Warnw("This is not olt pipeline table, so skipping", log.Fields{"tableId": flow.TableId}) |
| 293 | return deviceRules |
| 294 | } |
| 295 | |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 296 | ingressHop := path[0] |
| 297 | egressHop := path[1] |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 298 | if metadataFromwriteMetadata != 0 { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 299 | log.Debugw("creating-metadata-flow", log.Fields{"flow": flow}) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 300 | portNumber := fu.GetEgressPortNumberFromWriteMetadata(flow) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 301 | if portNumber != 0 { |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 302 | recalculatedRoute, err := agent.GetRoute(ctx, inPortNo, portNumber) |
| 303 | if err != nil { |
| 304 | log.Errorw("no-route-double-tag", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo, "metadata": metadataFromwriteMetadata, "error": err}) |
| 305 | return deviceRules |
| 306 | } |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 307 | switch len(recalculatedRoute) { |
| 308 | case 0: |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 309 | log.Errorw("no-route-double-tag", log.Fields{"inPortNo": inPortNo, "outPortNo": portNumber, "comment": "deleting-flow", "metadata": metadataFromwriteMetadata}) |
| 310 | //TODO: Delete flow |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 311 | return deviceRules |
| 312 | case 2: |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 313 | log.Debugw("route-found", log.Fields{"ingressHop": ingressHop, "egressHop": egressHop}) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 314 | default: |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 315 | log.Errorw("invalid-route-length", log.Fields{"routeLen": len(path)}) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 316 | return deviceRules |
| 317 | } |
| 318 | ingressHop = recalculatedRoute[0] |
| 319 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 320 | innerTag := fu.GetInnerTagFromMetaData(flow) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 321 | if innerTag == 0 { |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 322 | log.Errorw("no-inner-route-double-tag", log.Fields{"inPortNo": inPortNo, "outPortNo": portNumber, "comment": "deleting-flow", "metadata": metadataFromwriteMetadata}) |
| 323 | //TODO: Delete flow |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 324 | return deviceRules |
| 325 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 326 | fa := &fu.FlowArgs{ |
| 327 | 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] | 328 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 329 | fu.InPort(ingressHop.Ingress), |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 330 | fu.Metadata_ofp(uint64(innerTag)), |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 331 | fu.TunnelId(uint64(portNumber)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 332 | }, |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 333 | Actions: fu.GetActions(flow), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 334 | } |
| 335 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 336 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT, fu.METADATA)...) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 337 | |
| 338 | // Augment the Actions |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 339 | fa.Actions = append(fa.Actions, fu.Output(ingressHop.Egress)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 340 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 341 | fg := fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 342 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 343 | deviceRules.AddFlowsAndGroup(ingressHop.DeviceID, fg) |
| 344 | } else { // Create standard flow |
| 345 | log.Debugw("creating-standard-flow", log.Fields{"flow": flow}) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 346 | fa := &fu.FlowArgs{ |
| 347 | 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] | 348 | MatchFields: []*ofp.OfpOxmOfbField{ |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 349 | fu.InPort(ingressHop.Ingress), |
| 350 | fu.TunnelId(uint64(inPortNo)), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 351 | }, |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 352 | Actions: fu.GetActions(flow), |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 353 | } |
| 354 | // Augment the matchfields with the ofpfields from the flow |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 355 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 356 | |
| 357 | // Augment the Actions |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 358 | fa.Actions = append(fa.Actions, fu.Output(ingressHop.Egress)) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 359 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 360 | fg := fu.NewFlowsAndGroups() |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 361 | fg.AddFlow(fu.MkFlowStat(fa)) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 362 | deviceRules.AddFlowsAndGroup(ingressHop.DeviceID, fg) |
| 363 | } |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 364 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 365 | return deviceRules |
| 366 | } |
| 367 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 368 | // processUnicastFlow decomposes unicast flows |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 369 | func (fd *FlowDecomposer) processUnicastFlow(ctx context.Context, path []route.Hop, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 370 | inPortNo uint32, outPortNo uint32, flow *ofp.OfpFlowStats) *fu.DeviceRules { |
| 371 | |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 372 | 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] | 373 | deviceRules := fu.NewDeviceRules() |
| 374 | |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 375 | egressHop := path[1] |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 376 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 377 | meterID := fu.GetMeterIdFromFlow(flow) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 378 | metadataFromwriteMetadata := fu.GetMetadataFromWriteMetadataAction(flow) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 379 | fa := &fu.FlowArgs{ |
| 380 | KV: fu.OfpFlowModArgs{"priority": uint64(flow.Priority), "cookie": flow.Cookie, "meter_id": uint64(meterID), "write_metadata": metadataFromwriteMetadata}, |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 381 | MatchFields: []*ofp.OfpOxmOfbField{ |
| 382 | fu.InPort(egressHop.Ingress), |
| 383 | }, |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 384 | } |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 385 | // Augment the matchfields with the ofpfields from the flow |
| 386 | fa.MatchFields = append(fa.MatchFields, fu.GetOfbFields(flow, fu.IN_PORT)...) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 387 | |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 388 | // Augment the Actions |
| 389 | filteredAction := fu.GetActions(flow, fu.OUTPUT) |
| 390 | filteredAction = append(filteredAction, fu.Output(egressHop.Egress)) |
| 391 | fa.Actions = filteredAction |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 392 | |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 393 | fg := fu.NewFlowsAndGroups() |
| 394 | fg.AddFlow(fu.MkFlowStat(fa)) |
| 395 | deviceRules.AddFlowsAndGroup(egressHop.DeviceID, fg) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 396 | return deviceRules |
| 397 | } |
| 398 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 399 | // processMulticastFlow decompose multicast flows |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 400 | func (fd *FlowDecomposer) processMulticastFlow(ctx context.Context, path []route.Hop, |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 401 | inPortNo uint32, outPortNo uint32, flow *ofp.OfpFlowStats, grpID uint32, |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 402 | groupMap map[uint32]*ofp.OfpGroupEntry) *fu.DeviceRules { |
| 403 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 404 | log.Debugw("multicast-flow", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo}) |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 405 | deviceRules := fu.NewDeviceRules() |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 406 | |
| 407 | //having no Group yet is the same as having a Group with no buckets |
| 408 | var grp *ofp.OfpGroupEntry |
| 409 | var ok bool |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 410 | if grp, ok = groupMap[grpID]; !ok { |
| 411 | log.Warnw("Group-id-not-present-in-map", log.Fields{"grpId": grpID, "groupMap": groupMap}) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 412 | return deviceRules |
| 413 | } |
| 414 | if grp == nil || grp.Desc == nil { |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 415 | log.Warnw("Group-or-desc-nil", log.Fields{"grpId": grpID, "grp": grp}) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 416 | return deviceRules |
| 417 | } |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 418 | |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 419 | deviceRules.CreateEntryIfNotExist(path[0].DeviceID) |
Esin Karaman | 09959ae | 2019-11-29 13:59:58 +0000 | [diff] [blame] | 420 | fg := fu.NewFlowsAndGroups() |
| 421 | fg.AddFlow(flow) |
| 422 | //return the multicast flow without decomposing it |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 423 | deviceRules.AddFlowsAndGroup(path[0].DeviceID, fg) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 424 | return deviceRules |
| 425 | } |
| 426 | |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 427 | // decomposeFlow decomposes a flow for a logical device into flows for each physical device |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 428 | func (fd *FlowDecomposer) decomposeFlow(ctx context.Context, agent coreif.LogicalDeviceAgent, flow *ofp.OfpFlowStats, |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 429 | groupMap map[uint32]*ofp.OfpGroupEntry) (*fu.DeviceRules, error) { |
khenaidoo | d20a585 | 2018-10-22 22:09:55 -0400 | [diff] [blame] | 430 | |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 431 | inPortNo := fu.GetInPort(flow) |
Esin Karaman | 09959ae | 2019-11-29 13:59:58 +0000 | [diff] [blame] | 432 | if fu.HasGroup(flow) && inPortNo == 0 { |
| 433 | //if no in-port specified for a multicast flow, put NNI port as in-port |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 434 | //so that a valid path can be found for the flow |
Esin Karaman | 09959ae | 2019-11-29 13:59:58 +0000 | [diff] [blame] | 435 | nniPorts := agent.GetNNIPorts() |
| 436 | if len(nniPorts) > 0 { |
| 437 | inPortNo = nniPorts[0] |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 438 | log.Debugw("assigning-nni-port-as-in-port-for-multicast-flow", log.Fields{"nni": nniPorts[0], "flow:": flow}) |
Esin Karaman | 09959ae | 2019-11-29 13:59:58 +0000 | [diff] [blame] | 439 | } |
| 440 | } |
khenaidoo | 68c930b | 2019-05-13 11:46:51 -0400 | [diff] [blame] | 441 | outPortNo := fu.GetOutPort(flow) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 442 | deviceRules := fu.NewDeviceRules() |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 443 | path, err := agent.GetRoute(ctx, inPortNo, outPortNo) |
| 444 | if err != nil { |
| 445 | log.Errorw("no-route", log.Fields{"inPortNo": inPortNo, "outPortNo": outPortNo, "error": err}) |
| 446 | return deviceRules, err |
| 447 | } |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 448 | |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 449 | switch len(path) { |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 450 | case 0: |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 451 | return deviceRules, status.Errorf(codes.FailedPrecondition, "no route from:%d to:%d", inPortNo, outPortNo) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 452 | case 2: |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 453 | log.Debugw("route-found", log.Fields{"ingressHop": path[0], "egressHop": path[1]}) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 454 | default: |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 455 | return deviceRules, status.Errorf(codes.Aborted, "invalid route length %d", len(path)) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 456 | } |
| 457 | |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 458 | // Process controller bound flow |
| 459 | if outPortNo != 0 && (outPortNo&0x7fffffff) == uint32(ofp.OfpPortNo_OFPP_CONTROLLER) { |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 460 | deviceRules = fd.processControllerBoundFlow(ctx, agent, path, inPortNo, outPortNo, flow) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 461 | } else { |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 462 | var ingressDevice *voltha.Device |
| 463 | var err error |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 464 | if ingressDevice, err = fd.deviceMgr.GetDevice(ctx, path[0].DeviceID); err != nil { |
| 465 | return deviceRules, err |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 466 | } |
| 467 | isUpstream := !ingressDevice.Root |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 468 | if isUpstream { // Unicast OLT and ONU UL |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 469 | log.Debug("process-olt-nd-onu-upstream-noncontrollerbound-unicast-flows", log.Fields{"flows": flow}) |
| 470 | deviceRules = fd.processUpstreamNonControllerBoundFlow(ctx, path, inPortNo, outPortNo, flow) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 471 | } else if fu.HasNextTable(flow) && flow.TableId == 0 { // Unicast OLT flow DL |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 472 | log.Debugw("process-olt-downstream-noncontrollerbound-flow-with-nexttable", log.Fields{"flows": flow}) |
| 473 | deviceRules = fd.processDownstreamFlowWithNextTable(ctx, agent, path, inPortNo, outPortNo, flow) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 474 | } else if flow.TableId == 1 && outPortNo != 0 { // Unicast ONU flow DL |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 475 | log.Debugw("process-onu-downstream-unicast-flow", log.Fields{"flows": flow}) |
| 476 | deviceRules = fd.processUnicastFlow(ctx, path, inPortNo, outPortNo, flow) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 477 | } else if grpID := fu.GetGroup(flow); grpID != 0 && flow.TableId == 0 { //Multicast |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 478 | log.Debugw("process-multicast-flow", log.Fields{"flows": flow}) |
| 479 | deviceRules = fd.processMulticastFlow(ctx, path, inPortNo, outPortNo, flow, grpID, groupMap) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 480 | } else { |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 481 | return deviceRules, status.Errorf(codes.Aborted, "unknown downstream flow %v", *flow) |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 482 | } |
| 483 | } |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 484 | deviceRules = fd.updateOutputPortForControllerBoundFlowForParentDevide(flow, deviceRules) |
khenaidoo | 820197c | 2020-02-13 16:35:33 -0500 | [diff] [blame] | 485 | return deviceRules, nil |
khenaidoo | 89b0e94 | 2018-10-21 21:11:33 -0400 | [diff] [blame] | 486 | } |