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