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