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