Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [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 | |
| 17 | package core |
| 18 | |
| 19 | import ( |
| 20 | "errors" |
| 21 | |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame] | 22 | "github.com/opencord/openolt-scale-tester/config" |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 23 | "github.com/opencord/voltha-lib-go/v2/pkg/log" |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame] | 24 | "github.com/opencord/voltha-lib-go/v2/pkg/ponresourcemanager" |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 25 | oop "github.com/opencord/voltha-protos/v2/go/openolt" |
| 26 | tp_pb "github.com/opencord/voltha-protos/v2/go/tech_profile" |
| 27 | "golang.org/x/net/context" |
| 28 | "google.golang.org/grpc/codes" |
| 29 | "google.golang.org/grpc/status" |
| 30 | ) |
| 31 | |
| 32 | const ( |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 33 | DhcpIPProto = 17 |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 34 | |
| 35 | //Constants utilised while forming HSIA Flow |
| 36 | HsiaFlow = "HSIA_FLOW" |
| 37 | |
| 38 | //Constants utilised while forming DHCP IPV4 Flow |
| 39 | DhcpFlowIPV4 = "DHCP_FLOW_IPV4" |
| 40 | IPv4EthType = 0x800 //2048 |
| 41 | DhcpSrcPortIPV4 = 68 |
| 42 | DhcpDstPortIPV4 = 67 |
| 43 | |
| 44 | //Constants utilised while forming DHCP IPV6 Flow |
| 45 | DhcpFlowIPV6 = "DHCP_FLOW_IPV6" |
| 46 | IPv6EthType = 0x86dd //34525 |
| 47 | DhcpSrcPortIPV6 = 547 |
| 48 | DhcpDstPortIPV6 = 546 |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 49 | |
| 50 | //Constants utilised while forming EAPOL Flow |
| 51 | EapolFlow = "EAPOL_FLOW" |
| 52 | EapEthType = 0x888e //34958 |
| 53 | |
| 54 | //Direction constant |
| 55 | Upstream = "upstream" |
| 56 | Downstream = "downstream" |
| 57 | |
| 58 | //PacketTagType constant |
| 59 | PacketTagType = "pkt_tag_type" |
| 60 | Untagged = "untagged" |
| 61 | SingleTag = "single_tag" |
| 62 | DoubleTag = "double_tag" |
| 63 | ) |
| 64 | |
| 65 | func getTrafficSched(subs *Subscriber, direction tp_pb.Direction) []*tp_pb.TrafficScheduler { |
| 66 | var SchedCfg *tp_pb.SchedulerConfig |
| 67 | |
| 68 | if direction == tp_pb.Direction_DOWNSTREAM { |
| 69 | SchedCfg = subs.RsrMgr.ResourceMgrs[subs.PonIntf].TechProfileMgr. |
| 70 | GetDsScheduler(subs.TpInstance[subs.TestConfig.TpIDList[0]]) |
| 71 | |
| 72 | } else { |
| 73 | SchedCfg = subs.RsrMgr.ResourceMgrs[subs.PonIntf].TechProfileMgr. |
| 74 | GetUsScheduler(subs.TpInstance[subs.TestConfig.TpIDList[0]]) |
| 75 | } |
| 76 | |
| 77 | // hard-code for now |
| 78 | cir := 16000 |
| 79 | cbs := 5000 |
| 80 | eir := 16000 |
| 81 | ebs := 5000 |
| 82 | pir := cir + eir |
| 83 | pbs := cbs + ebs |
| 84 | |
| 85 | TrafficShaping := &tp_pb.TrafficShapingInfo{Cir: uint32(cir), Cbs: uint32(cbs), Pir: uint32(pir), Pbs: uint32(pbs)} |
| 86 | |
| 87 | TrafficSched := []*tp_pb.TrafficScheduler{subs.RsrMgr.ResourceMgrs[subs.PonIntf].TechProfileMgr. |
| 88 | GetTrafficScheduler(subs.TpInstance[subs.TestConfig.TpIDList[0]], SchedCfg, TrafficShaping)} |
| 89 | |
| 90 | return TrafficSched |
| 91 | } |
| 92 | |
| 93 | func getTrafficQueues(subs *Subscriber, direction tp_pb.Direction) []*tp_pb.TrafficQueue { |
| 94 | |
| 95 | trafficQueues := subs.RsrMgr.ResourceMgrs[subs.PonIntf].TechProfileMgr. |
| 96 | GetTrafficQueues(subs.TpInstance[subs.TestConfig.TpIDList[0]], direction) |
| 97 | |
| 98 | return trafficQueues |
| 99 | } |
| 100 | |
| 101 | func FormatClassfierAction(flowType string, direction string, subs *Subscriber) (oop.Classifier, oop.Action) { |
| 102 | var flowClassifier oop.Classifier |
| 103 | var actionCmd oop.ActionCmd |
| 104 | var actionInfo oop.Action |
| 105 | |
| 106 | if direction == Upstream { |
| 107 | switch flowType { |
| 108 | case EapolFlow: |
| 109 | flowClassifier.EthType = EapEthType |
| 110 | flowClassifier.OVid = subs.Ctag |
| 111 | flowClassifier.PktTagType = SingleTag |
| 112 | actionCmd.TrapToHost = true |
| 113 | actionInfo.Cmd = &actionCmd |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 114 | case DhcpFlowIPV4: |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 115 | flowClassifier.EthType = IPv4EthType |
| 116 | flowClassifier.IpProto = DhcpIPProto |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 117 | flowClassifier.SrcPort = DhcpSrcPortIPV4 |
| 118 | flowClassifier.DstPort = DhcpDstPortIPV4 |
| 119 | flowClassifier.PktTagType = SingleTag |
| 120 | actionCmd.TrapToHost = true |
| 121 | actionInfo.Cmd = &actionCmd |
| 122 | case DhcpFlowIPV6: |
| 123 | flowClassifier.EthType = IPv6EthType |
| 124 | flowClassifier.IpProto = DhcpIPProto |
| 125 | flowClassifier.SrcPort = DhcpSrcPortIPV6 |
| 126 | flowClassifier.DstPort = DhcpDstPortIPV6 |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 127 | flowClassifier.PktTagType = SingleTag |
| 128 | actionCmd.TrapToHost = true |
| 129 | actionInfo.Cmd = &actionCmd |
| 130 | case HsiaFlow: |
| 131 | flowClassifier.OVid = subs.Ctag |
| 132 | flowClassifier.PktTagType = SingleTag |
| 133 | actionCmd.AddOuterTag = true |
| 134 | actionInfo.Cmd = &actionCmd |
| 135 | actionInfo.OVid = subs.Stag |
| 136 | default: |
| 137 | log.Errorw("Unsupported flow type", log.Fields{"flowtype": flowType, |
| 138 | "direction": direction}) |
| 139 | } |
| 140 | } else if direction == Downstream { |
| 141 | switch flowType { |
| 142 | case EapolFlow: |
| 143 | log.Errorw("Downstream EAP flows are not required instead controller "+ |
| 144 | "packet outs EAP response directly to onu in downstream", log.Fields{"flowtype": flowType, |
| 145 | "direction": direction}) |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 146 | case DhcpFlowIPV4: |
| 147 | log.Errorw("Downstream DHCPIPV4 flows are not required instead we have "+ |
| 148 | "NNI trap flows already installed", log.Fields{"flowtype": flowType, |
| 149 | "direction": direction}) |
| 150 | case DhcpFlowIPV6: |
| 151 | log.Errorw("Downstream DHCPIPV6 flows are not required instead we have "+ |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 152 | "NNI trap flows already installed", log.Fields{"flowtype": flowType, |
| 153 | "direction": direction}) |
| 154 | case HsiaFlow: |
| 155 | flowClassifier.OVid = subs.Stag |
| 156 | flowClassifier.IVid = subs.Ctag |
| 157 | flowClassifier.PktTagType = DoubleTag |
| 158 | actionCmd.RemoveOuterTag = true |
| 159 | actionInfo.Cmd = &actionCmd |
Girish Gowdra | 187322d | 2020-01-20 18:59:21 +0530 | [diff] [blame] | 160 | actionInfo.OVid = subs.Stag |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 161 | default: |
| 162 | log.Errorw("Unsupported flow type", log.Fields{"flowtype": flowType, |
| 163 | "direction": direction}) |
| 164 | } |
| 165 | } |
| 166 | return flowClassifier, actionInfo |
| 167 | } |
| 168 | |
| 169 | func AddFlow(subs *Subscriber, flowType string, direction string, flowID uint32, |
Girish Gowdra | d4bdd37 | 2020-03-09 14:56:15 -0700 | [diff] [blame^] | 170 | allocID uint32, gemID uint32, pcp uint32) error { |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 171 | log.Infow("add-flow", log.Fields{"WorkFlow": subs.TestConfig.WorkflowName, "FlowType": flowType, |
| 172 | "direction": direction, "flowID": flowID}) |
| 173 | var err error |
| 174 | |
| 175 | flowClassifier, actionInfo := FormatClassfierAction(flowType, direction, subs) |
Girish Gowdra | d4bdd37 | 2020-03-09 14:56:15 -0700 | [diff] [blame^] | 176 | // Update the o_pbit for which this flow has to be classified |
| 177 | flowClassifier.OPbits = pcp |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 178 | flow := oop.Flow{AccessIntfId: int32(subs.PonIntf), OnuId: int32(subs.OnuID), |
| 179 | UniId: int32(subs.UniID), FlowId: flowID, |
| 180 | FlowType: direction, AllocId: int32(allocID), GemportId: int32(gemID), |
| 181 | Classifier: &flowClassifier, Action: &actionInfo, |
| 182 | Priority: 1000, PortNo: subs.UniPortNo} |
| 183 | |
| 184 | _, err = subs.OpenOltClient.FlowAdd(context.Background(), &flow) |
| 185 | |
| 186 | st, _ := status.FromError(err) |
| 187 | if st.Code() == codes.AlreadyExists { |
| 188 | log.Debugw("Flow already exists", log.Fields{"err": err, "deviceFlow": flow}) |
| 189 | return nil |
| 190 | } |
| 191 | |
| 192 | if err != nil { |
| 193 | log.Errorw("Failed to Add flow to device", log.Fields{"err": err, "deviceFlow": flow}) |
| 194 | return errors.New(ReasonCodeToReasonString(FLOW_ADD_FAILED)) |
| 195 | } |
| 196 | log.Debugw("Flow added to device successfully ", log.Fields{"flow": flow}) |
| 197 | |
| 198 | return nil |
| 199 | } |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame] | 200 | |
| 201 | func AddLldpFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error { |
| 202 | var flowID []uint32 |
| 203 | var err error |
| 204 | |
| 205 | if flowID, err = rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].GetResourceID(uint32(config.NniIntfID), |
| 206 | ponresourcemanager.FLOW_ID, 1); err != nil { |
| 207 | return err |
| 208 | } |
| 209 | |
| 210 | flowClassifier := &oop.Classifier{EthType: 35020, PktTagType: "untagged"} |
| 211 | actionCmd := &oop.ActionCmd{TrapToHost: true} |
| 212 | actionInfo := &oop.Action{Cmd: actionCmd} |
| 213 | |
| 214 | flow := oop.Flow{AccessIntfId: -1, OnuId: -1, UniId: -1, FlowId: flowID[0], |
| 215 | FlowType: "downstream", AllocId: -1, GemportId: -1, |
| 216 | Classifier: flowClassifier, Action: actionInfo, |
| 217 | Priority: 1000, PortNo: uint32(config.NniIntfID)} |
| 218 | |
| 219 | _, err = oo.FlowAdd(context.Background(), &flow) |
| 220 | |
| 221 | st, _ := status.FromError(err) |
| 222 | if st.Code() == codes.AlreadyExists { |
| 223 | log.Debugw("Flow already exists", log.Fields{"err": err, "deviceFlow": flow}) |
| 224 | return nil |
| 225 | } |
| 226 | |
| 227 | if err != nil { |
| 228 | log.Errorw("Failed to Add LLDP flow to device", log.Fields{"err": err, "deviceFlow": flow}) |
| 229 | rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].FreeResourceID(uint32(config.NniIntfID), |
| 230 | ponresourcemanager.FLOW_ID, flowID) |
| 231 | return err |
| 232 | } |
| 233 | log.Debugw("LLDP flow added to device successfully ", log.Fields{"flow": flow}) |
| 234 | |
| 235 | return nil |
| 236 | } |