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