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" |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 21 | "math/rand" |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 22 | "time" |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 23 | |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame] | 24 | "github.com/opencord/openolt-scale-tester/config" |
Girish Gowdra | 390f12f | 2021-07-01 15:53:49 -0700 | [diff] [blame^] | 25 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
| 26 | oop "github.com/opencord/voltha-protos/v5/go/openolt" |
| 27 | tp_pb "github.com/opencord/voltha-protos/v5/go/tech_profile" |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 28 | "golang.org/x/net/context" |
| 29 | "google.golang.org/grpc/codes" |
| 30 | "google.golang.org/grpc/status" |
| 31 | ) |
| 32 | |
| 33 | const ( |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 34 | DhcpIPProto = 17 |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 35 | |
| 36 | //Constants utilised while forming HSIA Flow |
| 37 | HsiaFlow = "HSIA_FLOW" |
| 38 | |
| 39 | //Constants utilised while forming DHCP IPV4 Flow |
| 40 | DhcpFlowIPV4 = "DHCP_FLOW_IPV4" |
| 41 | IPv4EthType = 0x800 //2048 |
| 42 | DhcpSrcPortIPV4 = 68 |
| 43 | DhcpDstPortIPV4 = 67 |
| 44 | |
| 45 | //Constants utilised while forming DHCP IPV6 Flow |
| 46 | DhcpFlowIPV6 = "DHCP_FLOW_IPV6" |
| 47 | IPv6EthType = 0x86dd //34525 |
| 48 | DhcpSrcPortIPV6 = 547 |
| 49 | DhcpDstPortIPV6 = 546 |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 50 | |
| 51 | //Constants utilised while forming EAPOL Flow |
| 52 | EapolFlow = "EAPOL_FLOW" |
| 53 | EapEthType = 0x888e //34958 |
| 54 | |
| 55 | //Direction constant |
| 56 | Upstream = "upstream" |
| 57 | Downstream = "downstream" |
| 58 | |
| 59 | //PacketTagType constant |
| 60 | PacketTagType = "pkt_tag_type" |
| 61 | Untagged = "untagged" |
| 62 | SingleTag = "single_tag" |
| 63 | DoubleTag = "double_tag" |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 64 | |
| 65 | VoipFlow = "VOIP_FLOW" |
| 66 | |
| 67 | VodFlow = "VOD_FLOW" |
| 68 | |
| 69 | MgmtFlow = "MGMT_FLOW" |
| 70 | |
| 71 | IgmpProto = 2 |
| 72 | IgmpFlow = "IGMP_FLOW" |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 73 | ) |
| 74 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 75 | const ( |
| 76 | MacSize = 6 |
| 77 | MacMin = 0x0 |
| 78 | MacMax = 0xFF |
| 79 | ) |
| 80 | |
| 81 | type GroupData struct { |
| 82 | Subs Subscriber `json:"subscriber"` |
| 83 | GroupID uint32 `json:"groupID"` |
| 84 | Weight uint32 `json:"weight"` |
| 85 | Priority uint32 `json:"priority"` |
| 86 | OnuID uint32 `json:"onuID"` |
| 87 | UniID uint32 `json:"uniID"` |
| 88 | AllocID uint32 `json:"allocId"` |
| 89 | GemPortID uint32 `json:"gemPortIds"` |
| 90 | SchedPolicy tp_pb.SchedulingPolicy `json:"schedPolicy"` |
| 91 | AddGroup bool `json:"addGroup"` |
| 92 | AddFlow bool `json:"addFlow"` |
| 93 | AddSched bool `json:"addSched"` |
| 94 | AddQueue bool `json:"addQueue"` |
| 95 | AddMember bool `json:"addMember"` |
| 96 | } |
| 97 | |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 98 | func getTrafficSched(subs *Subscriber, direction tp_pb.Direction) []*tp_pb.TrafficScheduler { |
| 99 | var SchedCfg *tp_pb.SchedulerConfig |
| 100 | |
| 101 | if direction == tp_pb.Direction_DOWNSTREAM { |
Girish Gowdra | 390f12f | 2021-07-01 15:53:49 -0700 | [diff] [blame^] | 102 | SchedCfg = subs.RsrMgr.TechprofileRef. |
| 103 | GetDsScheduler(subs.TpInstance[subs.TestConfig.TpIDList[0]]) |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 104 | } else { |
Girish Gowdra | 390f12f | 2021-07-01 15:53:49 -0700 | [diff] [blame^] | 105 | SchedCfg = subs.RsrMgr.TechprofileRef. |
| 106 | GetUsScheduler(subs.TpInstance[subs.TestConfig.TpIDList[0]]) |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 107 | } |
| 108 | |
Girish Gowdra | 390f12f | 2021-07-01 15:53:49 -0700 | [diff] [blame^] | 109 | if SchedCfg == nil { |
| 110 | logger.Errorw(nil, "Failed to create traffic schedulers", log.Fields{"direction": direction}) |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 111 | return nil |
| 112 | } |
| 113 | |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 114 | // hard-code for now |
| 115 | cir := 16000 |
| 116 | cbs := 5000 |
| 117 | eir := 16000 |
| 118 | ebs := 5000 |
| 119 | pir := cir + eir |
| 120 | pbs := cbs + ebs |
| 121 | |
| 122 | TrafficShaping := &tp_pb.TrafficShapingInfo{Cir: uint32(cir), Cbs: uint32(cbs), Pir: uint32(pir), Pbs: uint32(pbs)} |
| 123 | |
Girish Gowdra | 390f12f | 2021-07-01 15:53:49 -0700 | [diff] [blame^] | 124 | TrafficSched := []*tp_pb.TrafficScheduler{subs.RsrMgr.TechprofileRef. |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 125 | GetTrafficScheduler(subs.TpInstance[subs.TestConfig.TpIDList[0]], SchedCfg, TrafficShaping)} |
| 126 | |
| 127 | return TrafficSched |
| 128 | } |
| 129 | |
| 130 | func getTrafficQueues(subs *Subscriber, direction tp_pb.Direction) []*tp_pb.TrafficQueue { |
| 131 | |
Girish Gowdra | 390f12f | 2021-07-01 15:53:49 -0700 | [diff] [blame^] | 132 | trafficQueues, err := subs.RsrMgr.TechprofileRef. |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 133 | GetTrafficQueues(nil, subs.TpInstance[subs.TestConfig.TpIDList[0]], direction) |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 134 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 135 | if err == nil { |
| 136 | return trafficQueues |
| 137 | } |
| 138 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 139 | logger.Errorw(nil, "Failed to create traffic queues", log.Fields{"direction": direction, "error": err}) |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 140 | return nil |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | func FormatClassfierAction(flowType string, direction string, subs *Subscriber) (oop.Classifier, oop.Action) { |
| 144 | var flowClassifier oop.Classifier |
| 145 | var actionCmd oop.ActionCmd |
| 146 | var actionInfo oop.Action |
| 147 | |
| 148 | if direction == Upstream { |
| 149 | switch flowType { |
| 150 | case EapolFlow: |
| 151 | flowClassifier.EthType = EapEthType |
| 152 | flowClassifier.OVid = subs.Ctag |
| 153 | flowClassifier.PktTagType = SingleTag |
| 154 | actionCmd.TrapToHost = true |
| 155 | actionInfo.Cmd = &actionCmd |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 156 | case DhcpFlowIPV4: |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 157 | flowClassifier.EthType = IPv4EthType |
| 158 | flowClassifier.IpProto = DhcpIPProto |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 159 | flowClassifier.SrcPort = DhcpSrcPortIPV4 |
| 160 | flowClassifier.DstPort = DhcpDstPortIPV4 |
| 161 | flowClassifier.PktTagType = SingleTag |
| 162 | actionCmd.TrapToHost = true |
| 163 | actionInfo.Cmd = &actionCmd |
| 164 | case DhcpFlowIPV6: |
| 165 | flowClassifier.EthType = IPv6EthType |
| 166 | flowClassifier.IpProto = DhcpIPProto |
| 167 | flowClassifier.SrcPort = DhcpSrcPortIPV6 |
| 168 | flowClassifier.DstPort = DhcpDstPortIPV6 |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 169 | flowClassifier.PktTagType = SingleTag |
| 170 | actionCmd.TrapToHost = true |
| 171 | actionInfo.Cmd = &actionCmd |
| 172 | case HsiaFlow: |
| 173 | flowClassifier.OVid = subs.Ctag |
| 174 | flowClassifier.PktTagType = SingleTag |
| 175 | actionCmd.AddOuterTag = true |
| 176 | actionInfo.Cmd = &actionCmd |
| 177 | actionInfo.OVid = subs.Stag |
| 178 | default: |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 179 | logger.Errorw(nil, "Unsupported flow type", log.Fields{"flowtype": flowType, |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 180 | "direction": direction}) |
| 181 | } |
| 182 | } else if direction == Downstream { |
| 183 | switch flowType { |
| 184 | case EapolFlow: |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 185 | logger.Errorw(nil, "Downstream EAP flows are not required instead controller "+ |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 186 | "packet outs EAP response directly to onu in downstream", log.Fields{"flowtype": flowType, |
| 187 | "direction": direction}) |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 188 | case DhcpFlowIPV4: |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 189 | logger.Errorw(nil, "Downstream DHCPIPV4 flows are not required instead we have "+ |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 190 | "NNI trap flows already installed", log.Fields{"flowtype": flowType, |
| 191 | "direction": direction}) |
| 192 | case DhcpFlowIPV6: |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 193 | logger.Errorw(nil, "Downstream DHCPIPV6 flows are not required instead we have "+ |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 194 | "NNI trap flows already installed", log.Fields{"flowtype": flowType, |
| 195 | "direction": direction}) |
| 196 | case HsiaFlow: |
| 197 | flowClassifier.OVid = subs.Stag |
| 198 | flowClassifier.IVid = subs.Ctag |
| 199 | flowClassifier.PktTagType = DoubleTag |
| 200 | actionCmd.RemoveOuterTag = true |
| 201 | actionInfo.Cmd = &actionCmd |
Girish Gowdra | 187322d | 2020-01-20 18:59:21 +0530 | [diff] [blame] | 202 | actionInfo.OVid = subs.Stag |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 203 | default: |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 204 | logger.Errorw(nil, "Unsupported flow type", log.Fields{"flowtype": flowType, |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 205 | "direction": direction}) |
| 206 | } |
| 207 | } |
| 208 | return flowClassifier, actionInfo |
| 209 | } |
| 210 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 211 | func AddFlow(subs *Subscriber, flowType string, direction string, flowID uint64, |
| 212 | allocID uint32, gemID uint32, pcp uint32, replicateFlow bool, symmetricFlowID uint64, |
| 213 | pbitToGem map[uint32]uint32) error { |
| 214 | logger.Infow(nil, "add-flow", log.Fields{"WorkFlow": subs.TestConfig.WorkflowName, "FlowType": flowType, |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 215 | "direction": direction, "flowID": flowID}) |
| 216 | var err error |
| 217 | |
| 218 | flowClassifier, actionInfo := FormatClassfierAction(flowType, direction, subs) |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 219 | // Update the o_pbit (if valid) for which this flow has to be classified |
| 220 | if pcp != 0xff { |
| 221 | flowClassifier.OPbits = pcp |
| 222 | } |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 223 | flow := oop.Flow{AccessIntfId: int32(subs.PonIntf), OnuId: int32(subs.OnuID), |
| 224 | UniId: int32(subs.UniID), FlowId: flowID, |
| 225 | FlowType: direction, AllocId: int32(allocID), GemportId: int32(gemID), |
| 226 | Classifier: &flowClassifier, Action: &actionInfo, |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 227 | Priority: 1000, PortNo: subs.UniPortNo, SymmetricFlowId: symmetricFlowID, |
| 228 | ReplicateFlow: replicateFlow, PbitToGemport: pbitToGem} |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 229 | |
| 230 | _, err = subs.OpenOltClient.FlowAdd(context.Background(), &flow) |
| 231 | |
| 232 | st, _ := status.FromError(err) |
| 233 | if st.Code() == codes.AlreadyExists { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 234 | logger.Debugw(nil, "Flow already exists", log.Fields{"err": err, "deviceFlow": flow}) |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 235 | return nil |
| 236 | } |
| 237 | |
| 238 | if err != nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 239 | logger.Errorw(nil, "Failed to Add flow to device", log.Fields{"err": err, "deviceFlow": flow}) |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 240 | return errors.New(ReasonCodeToReasonString(FLOW_ADD_FAILED)) |
| 241 | } |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 242 | logger.Debugw(nil, "Flow added to device successfully ", log.Fields{"flow": flow}) |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 243 | |
| 244 | return nil |
| 245 | } |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame] | 246 | |
| 247 | func AddLldpFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 248 | var flowID uint64 |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame] | 249 | var err error |
| 250 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 251 | if flowID, err = rsrMgr.GetFlowID(context.Background(), uint32(config.NniIntfID)); err != nil { |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame] | 252 | return err |
| 253 | } |
| 254 | |
| 255 | flowClassifier := &oop.Classifier{EthType: 35020, PktTagType: "untagged"} |
| 256 | actionCmd := &oop.ActionCmd{TrapToHost: true} |
| 257 | actionInfo := &oop.Action{Cmd: actionCmd} |
| 258 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 259 | flow := oop.Flow{AccessIntfId: -1, OnuId: -1, UniId: -1, FlowId: flowID, |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame] | 260 | FlowType: "downstream", AllocId: -1, GemportId: -1, |
| 261 | Classifier: flowClassifier, Action: actionInfo, |
| 262 | Priority: 1000, PortNo: uint32(config.NniIntfID)} |
| 263 | |
| 264 | _, err = oo.FlowAdd(context.Background(), &flow) |
| 265 | |
| 266 | st, _ := status.FromError(err) |
| 267 | if st.Code() == codes.AlreadyExists { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 268 | logger.Debugw(nil, "Flow already exists", log.Fields{"err": err, "deviceFlow": flow}) |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame] | 269 | return nil |
| 270 | } |
| 271 | |
| 272 | if err != nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 273 | logger.Errorw(nil, "Failed to Add LLDP flow to device", log.Fields{"err": err, "deviceFlow": flow}) |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame] | 274 | return err |
| 275 | } |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 276 | logger.Debugw(nil, "LLDP flow added to device successfully ", log.Fields{"flow": flow}) |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame] | 277 | |
| 278 | return nil |
| 279 | } |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 280 | |
| 281 | func GenerateMac(isRand bool) []byte { |
| 282 | var mac []byte |
| 283 | |
| 284 | if isRand { |
| 285 | for i := 0; i < MacSize; i++ { |
| 286 | mac = append(mac, byte(rand.Intn(MacMax-MacMin)+MacMin)) |
| 287 | } |
| 288 | } else { |
| 289 | mac = []byte{0x12, 0xAB, 0x34, 0xCD, 0x56, 0xEF} |
| 290 | } |
| 291 | |
| 292 | return mac |
| 293 | } |
| 294 | |
| 295 | func GenerateMulticastMac(onu_id uint32, group_id uint32) []byte { |
| 296 | var mac []byte |
| 297 | |
| 298 | mac = []byte{0x01, 0x00, 0x5E} |
| 299 | |
| 300 | mac = append(mac, byte(onu_id%255)) |
| 301 | mac = append(mac, byte(rand.Intn(MacMax-MacMin)+MacMin)) |
| 302 | mac = append(mac, byte(group_id)) |
| 303 | |
| 304 | return mac |
| 305 | } |
| 306 | |
| 307 | func PerformGroupOperation(grp *GroupData, groupCfg *oop.Group) (*oop.Empty, error) { |
| 308 | oo := grp.Subs.OpenOltClient |
| 309 | |
| 310 | var err error |
| 311 | var res *oop.Empty |
| 312 | |
| 313 | if res, err = oop.OpenoltClient.PerformGroupOperation(oo, context.Background(), groupCfg); err != nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 314 | logger.Errorw(nil, "Failed to perform - PerformGroupOperation()", log.Fields{"err": err}) |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 315 | return nil, err |
| 316 | } |
| 317 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 318 | logger.Info(nil, "Successfully called - PerformGroupOperation()") |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 319 | |
| 320 | return res, nil |
| 321 | } |
| 322 | |
| 323 | func CreateGroup(grp *GroupData) (*oop.Empty, error) { |
| 324 | var groupCfg oop.Group |
| 325 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 326 | logger.Infow(nil, "creating group", log.Fields{"GroupID": grp.GroupID}) |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 327 | |
| 328 | groupCfg.Command = oop.Group_SET_MEMBERS |
| 329 | groupCfg.GroupId = grp.GroupID |
| 330 | |
| 331 | return PerformGroupOperation(grp, &groupCfg) |
| 332 | } |
| 333 | |
| 334 | func OpMulticastTrafficQueue(grp *GroupData, isCreating bool) (*oop.Empty, error) { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 335 | logger.Infow(nil, "operating on multicast traffic queue", log.Fields{"Creating": isCreating, "GroupID": grp.GroupID}) |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 336 | |
| 337 | oo := grp.Subs.OpenOltClient |
| 338 | |
| 339 | var request tp_pb.TrafficQueues |
| 340 | request.IntfId = grp.Subs.PonIntf |
| 341 | request.OnuId = grp.Subs.OnuID |
| 342 | request.UniId = grp.Subs.UniID |
| 343 | |
| 344 | var trafficQueues []*tp_pb.TrafficQueue |
| 345 | |
| 346 | var trafficQueue tp_pb.TrafficQueue |
| 347 | trafficQueue.Direction = tp_pb.Direction_DOWNSTREAM |
| 348 | trafficQueue.Priority = grp.Priority |
| 349 | trafficQueue.Weight = grp.Weight |
| 350 | trafficQueue.GemportId = grp.GemPortID |
| 351 | trafficQueue.SchedPolicy = grp.SchedPolicy |
| 352 | |
| 353 | trafficQueues = append(trafficQueues, &trafficQueue) |
| 354 | |
| 355 | request.TrafficQueues = trafficQueues |
| 356 | |
| 357 | var err error |
| 358 | var res *oop.Empty |
| 359 | |
| 360 | if isCreating { |
| 361 | if res, err = oop.OpenoltClient.CreateTrafficQueues(oo, context.Background(), &request); err != nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 362 | logger.Errorw(nil, "Failed to perform - CreateTrafficQueues()", log.Fields{"err": err}) |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 363 | return nil, err |
| 364 | } |
| 365 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 366 | logger.Info(nil, "Successfully called - CreateTrafficQueues()") |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 367 | } else { |
| 368 | if res, err = oop.OpenoltClient.RemoveTrafficQueues(oo, context.Background(), &request); err != nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 369 | logger.Errorw(nil, "Failed to perform - RemoveTrafficQueues()", log.Fields{"err": err}) |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 370 | return nil, err |
| 371 | } |
| 372 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 373 | logger.Info(nil, "Successfully called - RemoveTrafficQueues()") |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | return res, nil |
| 377 | } |
| 378 | |
| 379 | func AddMulticastFlow(grp *GroupData) error { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 380 | logger.Infow(nil, "add multicast flow", log.Fields{"GroupID": grp.GroupID}) |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 381 | |
| 382 | oo := grp.Subs.OpenOltClient |
| 383 | config := grp.Subs.TestConfig |
| 384 | rsrMgr := grp.Subs.RsrMgr |
| 385 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 386 | var flowID uint64 |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 387 | var err error |
| 388 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 389 | if flowID, err = rsrMgr.GetFlowID(context.Background(), uint32(config.NniIntfID)); err != nil { |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 390 | return err |
| 391 | } |
| 392 | |
| 393 | flowClassifier := &oop.Classifier{ |
| 394 | IPbits: 255, |
| 395 | OPbits: 255, |
| 396 | IVid: 55, |
| 397 | OVid: 255, |
| 398 | DstMac: GenerateMulticastMac(grp.Subs.OnuID, grp.GroupID), |
| 399 | PktTagType: DoubleTag} |
| 400 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 401 | flow := oop.Flow{AccessIntfId: int32(grp.Subs.PonIntf), OnuId: int32(grp.Subs.OnuID), UniId: int32(grp.Subs.UniID), FlowId: flowID, |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 402 | FlowType: "multicast", AllocId: int32(grp.AllocID), GemportId: int32(grp.GemPortID), |
| 403 | Classifier: flowClassifier, Priority: int32(grp.Priority), PortNo: uint32(grp.Subs.UniPortNo), GroupId: uint32(grp.GroupID)} |
| 404 | |
| 405 | _, err = oo.FlowAdd(context.Background(), &flow) |
| 406 | |
| 407 | st, _ := status.FromError(err) |
| 408 | if st.Code() == codes.AlreadyExists { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 409 | logger.Debugw(nil, "Flow already exists", log.Fields{"err": err, "deviceFlow": flow}) |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 410 | return nil |
| 411 | } |
| 412 | |
| 413 | if err != nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 414 | logger.Errorw(nil, "Failed to add multicast flow to device", log.Fields{"err": err, "deviceFlow": flow}) |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 415 | return err |
| 416 | } |
| 417 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 418 | logger.Debugw(nil, "Multicast flow added to device successfully ", log.Fields{"flow": flow}) |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 419 | |
| 420 | return nil |
| 421 | } |
| 422 | |
| 423 | func AddMulticastSched(grp *GroupData) error { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 424 | logger.Infow(nil, "creating multicast sched", log.Fields{"GroupID": grp.GroupID}) |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 425 | |
| 426 | SchedCfg := &tp_pb.SchedulerConfig{ |
| 427 | Direction: tp_pb.Direction_DOWNSTREAM, |
| 428 | AdditionalBw: tp_pb.AdditionalBW_AdditionalBW_BestEffort, |
| 429 | Priority: grp.Priority, |
| 430 | Weight: grp.Weight, |
| 431 | SchedPolicy: tp_pb.SchedulingPolicy_WRR} |
| 432 | |
| 433 | // hard-code for now |
| 434 | cir := 1948 |
| 435 | cbs := 31768 |
| 436 | eir := 100 |
| 437 | ebs := 1000 |
| 438 | pir := cir + eir |
| 439 | pbs := cbs + ebs |
| 440 | |
| 441 | TfShInfo := &tp_pb.TrafficShapingInfo{Cir: uint32(cir), Cbs: uint32(cbs), Pir: uint32(pir), Pbs: uint32(pbs)} |
| 442 | |
Girish Gowdra | 390f12f | 2021-07-01 15:53:49 -0700 | [diff] [blame^] | 443 | TrafficSched := []*tp_pb.TrafficScheduler{grp.Subs.RsrMgr.TechprofileRef. |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 444 | GetTrafficScheduler(grp.Subs.TpInstance[grp.Subs.TestConfig.TpIDList[0]], SchedCfg, TfShInfo)} |
| 445 | |
| 446 | if TrafficSched == nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 447 | logger.Error(nil, "Create scheduler for multicast traffic failed") |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 448 | return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED)) |
| 449 | } |
| 450 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 451 | logger.Debugw(nil, "Sending Traffic scheduler create to device", |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 452 | log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficScheds": TrafficSched}) |
| 453 | |
| 454 | if _, err := grp.Subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{ |
| 455 | IntfId: grp.Subs.PonIntf, OnuId: grp.Subs.OnuID, |
| 456 | UniId: grp.Subs.UniID, PortNo: grp.Subs.UniPortNo, |
| 457 | TrafficScheds: TrafficSched}); err != nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 458 | logger.Errorw(nil, "Failed to create traffic schedulers", log.Fields{"error": err}) |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 459 | return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED)) |
| 460 | } |
| 461 | |
| 462 | return nil |
| 463 | } |
| 464 | |
| 465 | func OpMemberToGroup(grp *GroupData, isAdding bool) (*oop.Empty, error) { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 466 | logger.Infow(nil, "operating on group", log.Fields{"Adding": isAdding}) |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 467 | |
| 468 | var groupCfg oop.Group |
| 469 | |
| 470 | if isAdding { |
| 471 | groupCfg.Command = oop.Group_ADD_MEMBERS |
| 472 | } else { |
| 473 | groupCfg.Command = oop.Group_REMOVE_MEMBERS |
| 474 | } |
| 475 | |
| 476 | groupCfg.GroupId = grp.GroupID |
| 477 | |
| 478 | var members []*oop.GroupMember |
| 479 | |
| 480 | var member0 oop.GroupMember |
| 481 | member0.InterfaceId = grp.Subs.PonIntf |
| 482 | member0.GemPortId = grp.GemPortID |
| 483 | member0.Priority = grp.Priority |
| 484 | //member0.SchedPolicy = tp_pb.SchedulingPolicy_WRR |
| 485 | member0.InterfaceType = oop.GroupMember_PON |
| 486 | |
| 487 | members = append(members, &member0) |
| 488 | |
| 489 | groupCfg.Members = members |
| 490 | |
| 491 | return PerformGroupOperation(grp, &groupCfg) |
| 492 | } |
| 493 | |
| 494 | func AddMulticastQueueFlow(grp *GroupData) error { |
| 495 | var err error |
| 496 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 497 | logger.Debugw(nil, "Create multicast queue flow", log.Fields{"GroupID": grp.GroupID, "AddGroup": grp.AddGroup, |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 498 | "AddFlow": grp.AddFlow, "AddSched": grp.AddSched, "AddQueue": grp.AddQueue, "AddMember": grp.AddMember}) |
| 499 | |
| 500 | if grp.AddGroup { |
| 501 | if _, err = CreateGroup(grp); err != nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 502 | logger.Error(nil, "Failed to add group to device") |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 503 | return err |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | if grp.AddFlow { |
| 508 | if err = AddMulticastFlow(grp); err != nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 509 | logger.Error(nil, "Failed to add multicast flow to device") |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 510 | return err |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | if grp.AddSched { |
| 515 | if err = AddMulticastSched(grp); err != nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 516 | logger.Error(nil, "Failed to add multicast sched to device") |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 517 | return err |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | if grp.AddQueue { |
| 522 | if _, err = OpMulticastTrafficQueue(grp, true); err != nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 523 | logger.Error(nil, "Failed to add multicast queue to device") |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 524 | return err |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | if grp.AddMember { |
| 529 | if _, err = OpMemberToGroup(grp, true); err != nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 530 | logger.Error(nil, "Failed to add member to group") |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 531 | return err |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | return nil |
| 536 | } |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 537 | |
| 538 | func CreateTrafficSchedWithRetry(OpenOltClient oop.OpenoltClient, sched *oop.TrafficSchedulers) error { |
| 539 | maxRetry := 20 |
| 540 | if _, err := OpenOltClient.CreateTrafficSchedulers(context.Background(), sched); err == nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 541 | logger.Info(nil, "succeeded in first attempt") |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 542 | return nil |
| 543 | } else { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 544 | logger.Info(nil, "going for a retry") |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 545 | } |
| 546 | for i := 0; i < maxRetry; i++ { |
| 547 | if _, err := OpenOltClient.CreateTrafficSchedulers(context.Background(), sched); err != nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 548 | logger.Error(nil, "retying after delay") |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 549 | time.Sleep(50 * time.Millisecond) |
| 550 | continue |
| 551 | } else { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 552 | logger.Infow(nil, "succeeded in retry iteration=%d!!", log.Fields{"i": i}) |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 553 | return nil |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | return errors.New("failed-to-create-traffic-sched-after-all-retries") |
| 558 | } |
| 559 | |
| 560 | func CreateTrafficQueuesWithRetry(OpenOltClient oop.OpenoltClient, queue *oop.TrafficQueues) error { |
| 561 | maxRetry := 20 |
| 562 | if _, err := OpenOltClient.CreateTrafficQueues(context.Background(), queue); err == nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 563 | logger.Info(nil, "succeeded in first attempt") |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 564 | return nil |
| 565 | } |
| 566 | for i := 0; i < maxRetry; i++ { |
| 567 | if _, err := OpenOltClient.CreateTrafficQueues(context.Background(), queue); err != nil { |
| 568 | time.Sleep(50 * time.Millisecond) |
| 569 | continue |
| 570 | } else { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 571 | logger.Infow(nil, "succeeded in retry iteration=%d!!", log.Fields{"i": i}) |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 572 | return nil |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | return errors.New("failed-to-create-traffic-queue-after-all-retries") |
| 577 | } |
| 578 | |
| 579 | func AddFlowWithRetry(OpenOltClient oop.OpenoltClient, flow *oop.Flow) error { |
| 580 | |
| 581 | var err error |
| 582 | maxRetry := 20 |
| 583 | |
| 584 | _, err = OpenOltClient.FlowAdd(context.Background(), flow) |
| 585 | |
| 586 | st, _ := status.FromError(err) |
| 587 | if st.Code() == codes.AlreadyExists { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 588 | logger.Debugw(nil, "Flow already exists", log.Fields{"err": err, "deviceFlow": flow}) |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 589 | return nil |
| 590 | } |
| 591 | if st.Code() == codes.ResourceExhausted { |
| 592 | for i := 0; i < maxRetry; i++ { |
| 593 | _, err = OpenOltClient.FlowAdd(context.Background(), flow) |
| 594 | st, _ := status.FromError(err) |
| 595 | if st.Code() == codes.ResourceExhausted { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 596 | logger.Error(nil, "flow-install-failed--retrying") |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 597 | continue |
| 598 | } else if st.Code() == codes.OK { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 599 | logger.Infow(nil, "flow-install-succeeded-on-retry", log.Fields{"i": i, "flow": flow}) |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 600 | return nil |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | } |
| 605 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 606 | logger.Debugw(nil, "Flow install failed on all retries ", log.Fields{"flow": flow}) |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 607 | |
| 608 | return err |
| 609 | } |