Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-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 techprofile |
| 18 | |
| 19 | import ( |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 20 | "context" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 21 | "encoding/json" |
| 22 | "errors" |
| 23 | "fmt" |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 24 | "regexp" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 25 | "strconv" |
Gamze Abaka | dfdd8f8 | 2020-05-04 08:39:50 +0000 | [diff] [blame] | 26 | "sync" |
Neha Sharma | 130ac6d | 2020-04-08 08:46:32 +0000 | [diff] [blame] | 27 | "time" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 28 | |
serkant.uluderya | b38671c | 2019-11-01 09:35:38 -0700 | [diff] [blame] | 29 | "github.com/opencord/voltha-lib-go/v3/pkg/db" |
| 30 | |
| 31 | "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore" |
| 32 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 33 | tp_pb "github.com/opencord/voltha-protos/v3/go/tech_profile" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 34 | ) |
| 35 | |
| 36 | // Interface to pon resource manager APIs |
| 37 | type iPonResourceMgr interface { |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 38 | GetResourceID(ctx context.Context, IntfID uint32, ResourceType string, NumIDs uint32) ([]uint32, error) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 39 | GetResourceTypeAllocID() string |
| 40 | GetResourceTypeGemPortID() string |
| 41 | GetTechnology() string |
| 42 | } |
| 43 | |
| 44 | type Direction int32 |
| 45 | |
| 46 | const ( |
| 47 | Direction_UPSTREAM Direction = 0 |
| 48 | Direction_DOWNSTREAM Direction = 1 |
| 49 | Direction_BIDIRECTIONAL Direction = 2 |
| 50 | ) |
| 51 | |
| 52 | var Direction_name = map[Direction]string{ |
| 53 | 0: "UPSTREAM", |
| 54 | 1: "DOWNSTREAM", |
| 55 | 2: "BIDIRECTIONAL", |
| 56 | } |
| 57 | |
| 58 | type SchedulingPolicy int32 |
| 59 | |
| 60 | const ( |
| 61 | SchedulingPolicy_WRR SchedulingPolicy = 0 |
| 62 | SchedulingPolicy_StrictPriority SchedulingPolicy = 1 |
| 63 | SchedulingPolicy_Hybrid SchedulingPolicy = 2 |
| 64 | ) |
| 65 | |
| 66 | var SchedulingPolicy_name = map[SchedulingPolicy]string{ |
| 67 | 0: "WRR", |
| 68 | 1: "StrictPriority", |
| 69 | 2: "Hybrid", |
| 70 | } |
| 71 | |
| 72 | type AdditionalBW int32 |
| 73 | |
| 74 | const ( |
| 75 | AdditionalBW_AdditionalBW_None AdditionalBW = 0 |
| 76 | AdditionalBW_AdditionalBW_NA AdditionalBW = 1 |
| 77 | AdditionalBW_AdditionalBW_BestEffort AdditionalBW = 2 |
| 78 | AdditionalBW_AdditionalBW_Auto AdditionalBW = 3 |
| 79 | ) |
| 80 | |
| 81 | var AdditionalBW_name = map[AdditionalBW]string{ |
| 82 | 0: "AdditionalBW_None", |
| 83 | 1: "AdditionalBW_NA", |
| 84 | 2: "AdditionalBW_BestEffort", |
| 85 | 3: "AdditionalBW_Auto", |
| 86 | } |
| 87 | |
| 88 | type DiscardPolicy int32 |
| 89 | |
| 90 | const ( |
| 91 | DiscardPolicy_TailDrop DiscardPolicy = 0 |
| 92 | DiscardPolicy_WTailDrop DiscardPolicy = 1 |
| 93 | DiscardPolicy_Red DiscardPolicy = 2 |
| 94 | DiscardPolicy_WRed DiscardPolicy = 3 |
| 95 | ) |
| 96 | |
| 97 | var DiscardPolicy_name = map[DiscardPolicy]string{ |
| 98 | 0: "TailDrop", |
| 99 | 1: "WTailDrop", |
| 100 | 2: "Red", |
| 101 | 3: "WRed", |
| 102 | } |
| 103 | |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 104 | // Required uniPortName format |
Matteo Scandolo | 4fca23a | 2020-04-07 07:55:08 -0700 | [diff] [blame] | 105 | var uniPortNameFormat = regexp.MustCompile(`^olt-{[a-z0-9\-]+}/pon-{[0-9]+}/onu-{[0-9]+}/uni-{[0-9]+}$`) |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 106 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 107 | /* |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 108 | type InferredAdditionBWIndication int32 |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 109 | |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 110 | const ( |
| 111 | InferredAdditionBWIndication_InferredAdditionBWIndication_None InferredAdditionBWIndication = 0 |
| 112 | InferredAdditionBWIndication_InferredAdditionBWIndication_Assured InferredAdditionBWIndication = 1 |
| 113 | InferredAdditionBWIndication_InferredAdditionBWIndication_BestEffort InferredAdditionBWIndication = 2 |
| 114 | ) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 115 | |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 116 | var InferredAdditionBWIndication_name = map[int32]string{ |
| 117 | 0: "InferredAdditionBWIndication_None", |
| 118 | 1: "InferredAdditionBWIndication_Assured", |
| 119 | 2: "InferredAdditionBWIndication_BestEffort", |
| 120 | } |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 121 | */ |
| 122 | // instance control defaults |
| 123 | const ( |
| 124 | defaultOnuInstance = "multi-instance" |
| 125 | defaultUniInstance = "single-instance" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 126 | defaultGemPayloadSize = "auto" |
| 127 | ) |
| 128 | |
| 129 | const MAX_GEM_PAYLOAD = "max_gem_payload_size" |
| 130 | |
| 131 | type InstanceControl struct { |
| 132 | Onu string `json:"ONU"` |
| 133 | Uni string `json:"uni"` |
| 134 | MaxGemPayloadSize string `json:"max_gem_payload_size"` |
| 135 | } |
| 136 | |
| 137 | // default discard config constants |
| 138 | const ( |
| 139 | defaultMinThreshold = 0 |
| 140 | defaultMaxThreshold = 0 |
| 141 | defaultMaxProbability = 0 |
| 142 | ) |
| 143 | |
| 144 | type DiscardConfig struct { |
| 145 | MinThreshold int `json:"min_threshold"` |
| 146 | MaxThreshold int `json:"max_threshold"` |
| 147 | MaxProbability int `json:"max_probability"` |
| 148 | } |
| 149 | |
| 150 | // default scheduler contants |
| 151 | const ( |
| 152 | defaultAdditionalBw = AdditionalBW_AdditionalBW_BestEffort |
| 153 | defaultPriority = 0 |
| 154 | defaultWeight = 0 |
| 155 | defaultQueueSchedPolicy = SchedulingPolicy_Hybrid |
| 156 | ) |
| 157 | |
| 158 | type Scheduler struct { |
| 159 | Direction string `json:"direction"` |
| 160 | AdditionalBw string `json:"additional_bw"` |
| 161 | Priority uint32 `json:"priority"` |
| 162 | Weight uint32 `json:"weight"` |
| 163 | QSchedPolicy string `json:"q_sched_policy"` |
| 164 | } |
| 165 | |
| 166 | // default GEM attribute constants |
| 167 | const ( |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 168 | defaultAESEncryption = "True" |
| 169 | defaultPriorityQueue = 0 |
| 170 | defaultQueueWeight = 0 |
| 171 | defaultMaxQueueSize = "auto" |
| 172 | defaultdropPolicy = DiscardPolicy_TailDrop |
| 173 | defaultSchedulePolicy = SchedulingPolicy_WRR |
| 174 | defaultIsMulticast = "False" |
| 175 | defaultAccessControlList = "224.0.0.0-239.255.255.255" |
| 176 | defaultMcastGemID = 4069 |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 177 | ) |
| 178 | |
| 179 | type GemPortAttribute struct { |
| 180 | MaxQueueSize string `json:"max_q_size"` |
| 181 | PbitMap string `json:"pbit_map"` |
| 182 | AesEncryption string `json:"aes_encryption"` |
| 183 | SchedulingPolicy string `json:"scheduling_policy"` |
| 184 | PriorityQueue uint32 `json:"priority_q"` |
| 185 | Weight uint32 `json:"weight"` |
| 186 | DiscardPolicy string `json:"discard_policy"` |
| 187 | DiscardConfig DiscardConfig `json:"discard_config"` |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 188 | IsMulticast string `json:"is_multicast"` |
| 189 | DControlList string `json:"dynamic_access_control_list"` |
| 190 | SControlList string `json:"static_access_control_list"` |
| 191 | McastGemID uint32 `json:"multicast_gem_id"` |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | type iScheduler struct { |
| 195 | AllocID uint32 `json:"alloc_id"` |
| 196 | Direction string `json:"direction"` |
| 197 | AdditionalBw string `json:"additional_bw"` |
| 198 | Priority uint32 `json:"priority"` |
| 199 | Weight uint32 `json:"weight"` |
| 200 | QSchedPolicy string `json:"q_sched_policy"` |
| 201 | } |
| 202 | type iGemPortAttribute struct { |
| 203 | GemportID uint32 `json:"gemport_id"` |
| 204 | MaxQueueSize string `json:"max_q_size"` |
| 205 | PbitMap string `json:"pbit_map"` |
| 206 | AesEncryption string `json:"aes_encryption"` |
| 207 | SchedulingPolicy string `json:"scheduling_policy"` |
| 208 | PriorityQueue uint32 `json:"priority_q"` |
| 209 | Weight uint32 `json:"weight"` |
| 210 | DiscardPolicy string `json:"discard_policy"` |
| 211 | DiscardConfig DiscardConfig `json:"discard_config"` |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 212 | IsMulticast string `json:"is_multicast"` |
| 213 | DControlList string `json:"dynamic_access_control_list"` |
| 214 | SControlList string `json:"static_access_control_list"` |
| 215 | McastGemID uint32 `json:"multicast_gem_id"` |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | type TechProfileMgr struct { |
Gamze Abaka | dfdd8f8 | 2020-05-04 08:39:50 +0000 | [diff] [blame] | 219 | config *TechProfileFlags |
| 220 | resourceMgr iPonResourceMgr |
| 221 | GemPortIDMgmtLock sync.RWMutex |
| 222 | AllocIDMgmtLock sync.RWMutex |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 223 | } |
| 224 | type DefaultTechProfile struct { |
| 225 | Name string `json:"name"` |
| 226 | ProfileType string `json:"profile_type"` |
| 227 | Version int `json:"version"` |
| 228 | NumGemPorts uint32 `json:"num_gem_ports"` |
| 229 | InstanceCtrl InstanceControl `json:"instance_control"` |
| 230 | UsScheduler Scheduler `json:"us_scheduler"` |
| 231 | DsScheduler Scheduler `json:"ds_scheduler"` |
| 232 | UpstreamGemPortAttributeList []GemPortAttribute `json:"upstream_gem_port_attribute_list"` |
| 233 | DownstreamGemPortAttributeList []GemPortAttribute `json:"downstream_gem_port_attribute_list"` |
| 234 | } |
| 235 | type TechProfile struct { |
| 236 | Name string `json:"name"` |
| 237 | SubscriberIdentifier string `json:"subscriber_identifier"` |
| 238 | ProfileType string `json:"profile_type"` |
| 239 | Version int `json:"version"` |
| 240 | NumGemPorts uint32 `json:"num_gem_ports"` |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 241 | InstanceCtrl InstanceControl `json:"instance_control"` |
| 242 | UsScheduler iScheduler `json:"us_scheduler"` |
| 243 | DsScheduler iScheduler `json:"ds_scheduler"` |
| 244 | UpstreamGemPortAttributeList []iGemPortAttribute `json:"upstream_gem_port_attribute_list"` |
| 245 | DownstreamGemPortAttributeList []iGemPortAttribute `json:"downstream_gem_port_attribute_list"` |
| 246 | } |
| 247 | |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 248 | // QThresholds struct for EPON |
| 249 | type QThresholds struct { |
| 250 | QThreshold1 uint32 `json:"q_threshold1"` |
| 251 | QThreshold2 uint32 `json:"q_threshold2"` |
| 252 | QThreshold3 uint32 `json:"q_threshold3"` |
| 253 | QThreshold4 uint32 `json:"q_threshold4"` |
| 254 | QThreshold5 uint32 `json:"q_threshold5"` |
| 255 | QThreshold6 uint32 `json:"q_threshold6"` |
| 256 | QThreshold7 uint32 `json:"q_threshold7"` |
| 257 | } |
| 258 | |
| 259 | // UpstreamQueueAttribute struct for EPON |
| 260 | type UpstreamQueueAttribute struct { |
| 261 | MaxQueueSize string `json:"max_q_size"` |
| 262 | PbitMap string `json:"pbit_map"` |
| 263 | AesEncryption string `json:"aes_encryption"` |
| 264 | TrafficType string `json:"traffic_type"` |
| 265 | UnsolicitedGrantSize uint32 `json:"unsolicited_grant_size"` |
| 266 | NominalInterval uint32 `json:"nominal_interval"` |
| 267 | ToleratedPollJitter uint32 `json:"tolerated_poll_jitter"` |
| 268 | RequestTransmissionPolicy uint32 `json:"request_transmission_policy"` |
| 269 | NumQueueSet uint32 `json:"num_q_sets"` |
| 270 | QThresholds QThresholds `json:"q_thresholds"` |
| 271 | SchedulingPolicy string `json:"scheduling_policy"` |
| 272 | PriorityQueue uint32 `json:"priority_q"` |
| 273 | Weight uint32 `json:"weight"` |
| 274 | DiscardPolicy string `json:"discard_policy"` |
| 275 | DiscardConfig DiscardConfig `json:"discard_config"` |
| 276 | } |
| 277 | |
| 278 | // Default EPON constants |
| 279 | const ( |
| 280 | defaultPakageType = "B" |
| 281 | ) |
| 282 | const ( |
| 283 | defaultTrafficType = "BE" |
| 284 | defaultUnsolicitedGrantSize = 0 |
| 285 | defaultNominalInterval = 0 |
| 286 | defaultToleratedPollJitter = 0 |
| 287 | defaultRequestTransmissionPolicy = 0 |
| 288 | defaultNumQueueSet = 2 |
| 289 | ) |
| 290 | const ( |
| 291 | defaultQThreshold1 = 5500 |
| 292 | defaultQThreshold2 = 0 |
| 293 | defaultQThreshold3 = 0 |
| 294 | defaultQThreshold4 = 0 |
| 295 | defaultQThreshold5 = 0 |
| 296 | defaultQThreshold6 = 0 |
| 297 | defaultQThreshold7 = 0 |
| 298 | ) |
| 299 | |
| 300 | // DownstreamQueueAttribute struct for EPON |
| 301 | type DownstreamQueueAttribute struct { |
| 302 | MaxQueueSize string `json:"max_q_size"` |
| 303 | PbitMap string `json:"pbit_map"` |
| 304 | AesEncryption string `json:"aes_encryption"` |
| 305 | SchedulingPolicy string `json:"scheduling_policy"` |
| 306 | PriorityQueue uint32 `json:"priority_q"` |
| 307 | Weight uint32 `json:"weight"` |
| 308 | DiscardPolicy string `json:"discard_policy"` |
| 309 | DiscardConfig DiscardConfig `json:"discard_config"` |
| 310 | } |
| 311 | |
| 312 | // iUpstreamQueueAttribute struct for EPON |
| 313 | type iUpstreamQueueAttribute struct { |
| 314 | GemportID uint32 `json:"q_id"` |
| 315 | MaxQueueSize string `json:"max_q_size"` |
| 316 | PbitMap string `json:"pbit_map"` |
| 317 | AesEncryption string `json:"aes_encryption"` |
| 318 | TrafficType string `json:"traffic_type"` |
| 319 | UnsolicitedGrantSize uint32 `json:"unsolicited_grant_size"` |
| 320 | NominalInterval uint32 `json:"nominal_interval"` |
| 321 | ToleratedPollJitter uint32 `json:"tolerated_poll_jitter"` |
| 322 | RequestTransmissionPolicy uint32 `json:"request_transmission_policy"` |
| 323 | NumQueueSet uint32 `json:"num_q_sets"` |
| 324 | QThresholds QThresholds `json:"q_thresholds"` |
| 325 | SchedulingPolicy string `json:"scheduling_policy"` |
| 326 | PriorityQueue uint32 `json:"priority_q"` |
| 327 | Weight uint32 `json:"weight"` |
| 328 | DiscardPolicy string `json:"discard_policy"` |
| 329 | DiscardConfig DiscardConfig `json:"discard_config"` |
| 330 | } |
| 331 | |
| 332 | // iDownstreamQueueAttribute struct for EPON |
| 333 | type iDownstreamQueueAttribute struct { |
| 334 | GemportID uint32 `json:"q_id"` |
| 335 | MaxQueueSize string `json:"max_q_size"` |
| 336 | PbitMap string `json:"pbit_map"` |
| 337 | AesEncryption string `json:"aes_encryption"` |
| 338 | SchedulingPolicy string `json:"scheduling_policy"` |
| 339 | PriorityQueue uint32 `json:"priority_q"` |
| 340 | Weight uint32 `json:"weight"` |
| 341 | DiscardPolicy string `json:"discard_policy"` |
| 342 | DiscardConfig DiscardConfig `json:"discard_config"` |
| 343 | } |
| 344 | |
| 345 | // EponAttribute struct for EPON |
| 346 | type EponAttribute struct { |
| 347 | PackageType string `json:"pakage_type"` |
| 348 | } |
| 349 | |
| 350 | // DefaultTechProfile struct for EPON |
| 351 | type DefaultEponProfile struct { |
| 352 | Name string `json:"name"` |
| 353 | ProfileType string `json:"profile_type"` |
| 354 | Version int `json:"version"` |
| 355 | NumGemPorts uint32 `json:"num_gem_ports"` |
| 356 | InstanceCtrl InstanceControl `json:"instance_control"` |
| 357 | EponAttribute EponAttribute `json:"epon_attribute"` |
| 358 | UpstreamQueueAttributeList []UpstreamQueueAttribute `json:"upstream_queue_attribute_list"` |
| 359 | DownstreamQueueAttributeList []DownstreamQueueAttribute `json:"downstream_queue_attribute_list"` |
| 360 | } |
| 361 | |
| 362 | // TechProfile struct for EPON |
| 363 | type EponProfile struct { |
| 364 | Name string `json:"name"` |
| 365 | SubscriberIdentifier string `json:"subscriber_identifier"` |
| 366 | ProfileType string `json:"profile_type"` |
| 367 | Version int `json:"version"` |
| 368 | NumGemPorts uint32 `json:"num_gem_ports"` |
| 369 | InstanceCtrl InstanceControl `json:"instance_control"` |
| 370 | EponAttribute EponAttribute `json:"epon_attribute"` |
| 371 | AllocID uint32 `json:"llid"` |
| 372 | UpstreamQueueAttributeList []iUpstreamQueueAttribute `json:"upstream_queue_attribute_list"` |
| 373 | DownstreamQueueAttributeList []iDownstreamQueueAttribute `json:"downstream_queue_attribute_list"` |
| 374 | } |
| 375 | |
| 376 | const ( |
Andrea Campanella | 904fe32 | 2020-06-26 18:56:51 +0200 | [diff] [blame] | 377 | xgspon = "XGS-PON" |
| 378 | gpon = "GPON" |
| 379 | epon = "EPON" |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 380 | ) |
| 381 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 382 | func (t *TechProfileMgr) SetKVClient(ctx context.Context) *db.Backend { |
| 383 | kvClient, err := newKVClient(ctx, t.config.KVStoreType, t.config.KVStoreAddress, t.config.KVStoreTimeout) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 384 | if err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 385 | logger.Errorw(ctx, "failed-to-create-kv-client", |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 386 | log.Fields{ |
Neha Sharma | dd9af39 | 2020-04-28 09:03:57 +0000 | [diff] [blame] | 387 | "type": t.config.KVStoreType, "address": t.config.KVStoreAddress, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 388 | "timeout": t.config.KVStoreTimeout, "prefix": t.config.TPKVPathPrefix, |
| 389 | "error": err.Error(), |
| 390 | }) |
| 391 | return nil |
| 392 | } |
sbarbari | 1e3e29c | 2019-11-05 10:06:50 -0500 | [diff] [blame] | 393 | return &db.Backend{ |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 394 | Client: kvClient, |
| 395 | StoreType: t.config.KVStoreType, |
Neha Sharma | dd9af39 | 2020-04-28 09:03:57 +0000 | [diff] [blame] | 396 | Address: t.config.KVStoreAddress, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 397 | Timeout: t.config.KVStoreTimeout, |
| 398 | PathPrefix: t.config.TPKVPathPrefix} |
| 399 | |
| 400 | /* TODO : Make sure direct call to NewBackend is working fine with backend , currently there is some |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 401 | issue between kv store and backend , core is not calling NewBackend directly |
| 402 | kv := model.NewBackend(t.config.KVStoreType, t.config.KVStoreHost, t.config.KVStorePort, |
| 403 | t.config.KVStoreTimeout, kvStoreTechProfilePathPrefix) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 404 | */ |
| 405 | } |
| 406 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 407 | func newKVClient(ctx context.Context, storeType string, address string, timeout time.Duration) (kvstore.Client, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 408 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 409 | logger.Infow(ctx, "kv-store", log.Fields{"storeType": storeType, "address": address}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 410 | switch storeType { |
| 411 | case "consul": |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 412 | return kvstore.NewConsulClient(ctx, address, timeout) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 413 | case "etcd": |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 414 | return kvstore.NewEtcdClient(ctx, address, timeout, log.WarnLevel) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 415 | } |
| 416 | return nil, errors.New("unsupported-kv-store") |
| 417 | } |
| 418 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 419 | func NewTechProfile(ctx context.Context, resourceMgr iPonResourceMgr, KVStoreType string, KVStoreAddress string) (*TechProfileMgr, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 420 | var techprofileObj TechProfileMgr |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 421 | logger.Debug(ctx, "Initializing techprofile Manager") |
Neha Sharma | dd9af39 | 2020-04-28 09:03:57 +0000 | [diff] [blame] | 422 | techprofileObj.config = NewTechProfileFlags(KVStoreType, KVStoreAddress) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 423 | techprofileObj.config.KVBackend = techprofileObj.SetKVClient(ctx) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 424 | if techprofileObj.config.KVBackend == nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 425 | logger.Error(ctx, "Failed to initialize KV backend\n") |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 426 | return nil, errors.New("KV backend init failed") |
| 427 | } |
| 428 | techprofileObj.resourceMgr = resourceMgr |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 429 | logger.Debug(ctx, "Initializing techprofile object instance success") |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 430 | return &techprofileObj, nil |
| 431 | } |
| 432 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 433 | func (t *TechProfileMgr) GetTechProfileInstanceKVPath(ctx context.Context, techProfiletblID uint32, uniPortName string) string { |
| 434 | logger.Debugw(ctx, "get-tp-instance-kv-path", log.Fields{ |
Matteo Scandolo | 4fca23a | 2020-04-07 07:55:08 -0700 | [diff] [blame] | 435 | "uniPortName": uniPortName, |
| 436 | "tpId": techProfiletblID, |
| 437 | }) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 438 | return fmt.Sprintf(t.config.TPInstanceKVPath, t.resourceMgr.GetTechnology(), techProfiletblID, uniPortName) |
| 439 | } |
| 440 | |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 441 | func (t *TechProfileMgr) GetTPInstanceFromKVStore(ctx context.Context, techProfiletblID uint32, path string) (interface{}, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 442 | var err error |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 443 | var kvResult *kvstore.KVPair |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 444 | var KvTpIns TechProfile |
| 445 | var KvEponIns EponProfile |
| 446 | var resPtr interface{} |
| 447 | // For example: |
| 448 | // tpInstPath like "XGS-PON/64/uni_port_name" |
| 449 | // is broken into ["XGS-PON" "64" ...] |
| 450 | pathSlice := regexp.MustCompile(`/`).Split(path, -1) |
| 451 | switch pathSlice[0] { |
Andrea Campanella | 904fe32 | 2020-06-26 18:56:51 +0200 | [diff] [blame] | 452 | case xgspon, gpon: |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 453 | resPtr = &KvTpIns |
| 454 | case epon: |
| 455 | resPtr = &KvEponIns |
| 456 | default: |
| 457 | log.Errorw("unknown-tech", log.Fields{"tech": pathSlice[0]}) |
| 458 | return nil, fmt.Errorf("unknown-tech-%s", pathSlice[0]) |
| 459 | } |
Matteo Scandolo | 4fca23a | 2020-04-07 07:55:08 -0700 | [diff] [blame] | 460 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 461 | kvResult, _ = t.config.KVBackend.Get(ctx, path) |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 462 | if kvResult == nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 463 | logger.Infow(ctx, "tp-instance-not-found-on-kv", log.Fields{"key": path}) |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 464 | return nil, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 465 | } else { |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 466 | if value, err := kvstore.ToByte(kvResult.Value); err == nil { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 467 | if err = json.Unmarshal(value, resPtr); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 468 | logger.Errorw(ctx, "error-unmarshal-kv-result", log.Fields{"key": path, "value": value}) |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 469 | return nil, errors.New("error-unmarshal-kv-result") |
| 470 | } else { |
| 471 | return resPtr, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 472 | } |
| 473 | } |
| 474 | } |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 475 | return nil, err |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 476 | } |
| 477 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 478 | func (t *TechProfileMgr) addTechProfInstanceToKVStore(ctx context.Context, techProfiletblID uint32, uniPortName string, tpInstance *TechProfile) error { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 479 | path := t.GetTechProfileInstanceKVPath(ctx, techProfiletblID, uniPortName) |
| 480 | logger.Debugw(ctx, "Adding techprof instance to kvstore", log.Fields{"key": path, "tpinstance": tpInstance}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 481 | tpInstanceJson, err := json.Marshal(*tpInstance) |
| 482 | if err == nil { |
| 483 | // Backend will convert JSON byte array into string format |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 484 | logger.Debugw(ctx, "Storing tech profile instance to KV Store", log.Fields{"key": path, "val": tpInstanceJson}) |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 485 | err = t.config.KVBackend.Put(ctx, path, tpInstanceJson) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 486 | } else { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 487 | logger.Errorw(ctx, "Error in marshaling into Json format", log.Fields{"key": path, "tpinstance": tpInstance}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 488 | } |
| 489 | return err |
| 490 | } |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 491 | |
| 492 | func (t *TechProfileMgr) addEponProfInstanceToKVStore(ctx context.Context, techProfiletblID uint32, uniPortName string, tpInstance *EponProfile) error { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 493 | path := t.GetTechProfileInstanceKVPath(ctx, techProfiletblID, uniPortName) |
| 494 | logger.Debugw(ctx, "Adding techprof instance to kvstore", log.Fields{"key": path, "tpinstance": tpInstance}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 495 | tpInstanceJson, err := json.Marshal(*tpInstance) |
| 496 | if err == nil { |
| 497 | // Backend will convert JSON byte array into string format |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 498 | logger.Debugw(ctx, "Storing tech profile instance to KV Store", log.Fields{"key": path, "val": tpInstanceJson}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 499 | err = t.config.KVBackend.Put(ctx, path, tpInstanceJson) |
| 500 | } else { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 501 | logger.Errorw(ctx, "Error in marshaling into Json format", log.Fields{"key": path, "tpinstance": tpInstance}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 502 | } |
| 503 | return err |
| 504 | } |
| 505 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 506 | func (t *TechProfileMgr) getTPFromKVStore(ctx context.Context, techProfiletblID uint32) *DefaultTechProfile { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 507 | var kvtechprofile DefaultTechProfile |
| 508 | key := fmt.Sprintf(t.config.TPFileKVPath, t.resourceMgr.GetTechnology(), techProfiletblID) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 509 | logger.Debugw(ctx, "Getting techprofile from KV store", log.Fields{"techProfiletblID": techProfiletblID, "Key": key}) |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 510 | kvresult, err := t.config.KVBackend.Get(ctx, key) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 511 | if err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 512 | logger.Errorw(ctx, "Error while fetching value from KV store", log.Fields{"key": key}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 513 | return nil |
| 514 | } |
| 515 | if kvresult != nil { |
| 516 | /* Backend will return Value in string format,needs to be converted to []byte before unmarshal*/ |
| 517 | if value, err := kvstore.ToByte(kvresult.Value); err == nil { |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 518 | if err = json.Unmarshal(value, &kvtechprofile); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 519 | logger.Errorw(ctx, "Error unmarshaling techprofile fetched from KV store", log.Fields{"techProfiletblID": techProfiletblID, "error": err, "techprofile_json": value}) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 520 | return nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 521 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 522 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 523 | logger.Debugw(ctx, "Success fetched techprofile from KV store", log.Fields{"techProfiletblID": techProfiletblID, "value": kvtechprofile}) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 524 | return &kvtechprofile |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | return nil |
| 528 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 529 | |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 530 | func (t *TechProfileMgr) getEponTPFromKVStore(ctx context.Context, techProfiletblID uint32) *DefaultEponProfile { |
| 531 | var kvtechprofile DefaultEponProfile |
| 532 | key := fmt.Sprintf(t.config.TPFileKVPath, t.resourceMgr.GetTechnology(), techProfiletblID) |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 533 | logger.Debugw(ctx, "Getting techprofile from KV store", log.Fields{"techProfiletblID": techProfiletblID, "Key": key}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 534 | kvresult, err := t.config.KVBackend.Get(ctx, key) |
| 535 | if err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 536 | logger.Errorw(ctx, "Error while fetching value from KV store", log.Fields{"key": key}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 537 | return nil |
| 538 | } |
| 539 | if kvresult != nil { |
| 540 | /* Backend will return Value in string format,needs to be converted to []byte before unmarshal*/ |
| 541 | if value, err := kvstore.ToByte(kvresult.Value); err == nil { |
| 542 | if err = json.Unmarshal(value, &kvtechprofile); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 543 | logger.Errorw(ctx, "Error unmarshaling techprofile fetched from KV store", log.Fields{"techProfiletblID": techProfiletblID, "error": err, "techprofile_json": value}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 544 | return nil |
| 545 | } |
| 546 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 547 | logger.Debugw(ctx, "Success fetched techprofile from KV store", log.Fields{"techProfiletblID": techProfiletblID, "value": kvtechprofile}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 548 | return &kvtechprofile |
| 549 | } |
| 550 | } |
| 551 | return nil |
| 552 | } |
| 553 | |
| 554 | func (t *TechProfileMgr) CreateTechProfInstance(ctx context.Context, techProfiletblID uint32, uniPortName string, intfId uint32) (interface{}, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 555 | var tpInstance *TechProfile |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 556 | var tpEponInstance *EponProfile |
| 557 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 558 | logger.Infow(ctx, "creating-tp-instance", log.Fields{"tableid": techProfiletblID, "uni": uniPortName, "intId": intfId}) |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 559 | |
| 560 | // Make sure the uniPortName is as per format pon-{[0-9]+}/onu-{[0-9]+}/uni-{[0-9]+} |
| 561 | if !uniPortNameFormat.Match([]byte(uniPortName)) { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 562 | logger.Errorw(ctx, "uni-port-name-not-confirming-to-format", log.Fields{"uniPortName": uniPortName}) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 563 | return nil, errors.New("uni-port-name-not-confirming-to-format") |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 564 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 565 | tpInstancePath := t.GetTechProfileInstanceKVPath(ctx, techProfiletblID, uniPortName) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 566 | // For example: |
| 567 | // tpInstPath like "XGS-PON/64/uni_port_name" |
| 568 | // is broken into ["XGS-PON" "64" ...] |
| 569 | pathSlice := regexp.MustCompile(`/`).Split(tpInstancePath, -1) |
| 570 | if pathSlice[0] == epon { |
| 571 | tp := t.getEponTPFromKVStore(ctx, techProfiletblID) |
| 572 | if tp != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 573 | if err := t.validateInstanceControlAttr(ctx, tp.InstanceCtrl); err != nil { |
| 574 | logger.Error(ctx, "invalid-instance-ctrl-attr--using-default-tp") |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 575 | tp = t.getDefaultEponProfile() |
| 576 | } else { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 577 | logger.Infow(ctx, "using-specified-tp-from-kv-store", log.Fields{"tpid": techProfiletblID}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 578 | } |
| 579 | } else { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 580 | logger.Info(ctx, "tp-not-found-on-kv--creating-default-tp") |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 581 | tp = t.getDefaultEponProfile() |
| 582 | } |
| 583 | |
| 584 | if tpEponInstance = t.allocateEponTPInstance(ctx, uniPortName, tp, intfId, tpInstancePath); tpEponInstance == nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 585 | logger.Error(ctx, "tp-intance-allocation-failed") |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 586 | return nil, errors.New("tp-intance-allocation-failed") |
| 587 | } |
| 588 | if err := t.addEponProfInstanceToKVStore(ctx, techProfiletblID, uniPortName, tpEponInstance); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 589 | logger.Errorw(ctx, "error-adding-tp-to-kv-store", log.Fields{"tableid": techProfiletblID, "uni": uniPortName}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 590 | return nil, errors.New("error-adding-tp-to-kv-store") |
| 591 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 592 | logger.Infow(ctx, "tp-added-to-kv-store-successfully", |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 593 | log.Fields{"tpid": techProfiletblID, "uni": uniPortName, "intfId": intfId}) |
| 594 | return tpEponInstance, nil |
| 595 | } else { |
| 596 | tp := t.getTPFromKVStore(ctx, techProfiletblID) |
| 597 | if tp != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 598 | if err := t.validateInstanceControlAttr(ctx, tp.InstanceCtrl); err != nil { |
| 599 | logger.Error(ctx, "invalid-instance-ctrl-attr--using-default-tp") |
| 600 | tp = t.getDefaultTechProfile(ctx) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 601 | } else { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 602 | logger.Infow(ctx, "using-specified-tp-from-kv-store", log.Fields{"tpid": techProfiletblID}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 603 | } |
| 604 | } else { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 605 | logger.Info(ctx, "tp-not-found-on-kv--creating-default-tp") |
| 606 | tp = t.getDefaultTechProfile(ctx) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | if tpInstance = t.allocateTPInstance(ctx, uniPortName, tp, intfId, tpInstancePath); tpInstance == nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 610 | logger.Error(ctx, "tp-intance-allocation-failed") |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 611 | return nil, errors.New("tp-intance-allocation-failed") |
| 612 | } |
| 613 | if err := t.addTechProfInstanceToKVStore(ctx, techProfiletblID, uniPortName, tpInstance); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 614 | logger.Errorw(ctx, "error-adding-tp-to-kv-store", log.Fields{"tableid": techProfiletblID, "uni": uniPortName}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 615 | return nil, errors.New("error-adding-tp-to-kv-store") |
| 616 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 617 | logger.Infow(ctx, "tp-added-to-kv-store-successfully", |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 618 | log.Fields{"tpid": techProfiletblID, "uni": uniPortName, "intfId": intfId}) |
| 619 | return tpInstance, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 620 | } |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 621 | } |
| 622 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 623 | func (t *TechProfileMgr) DeleteTechProfileInstance(ctx context.Context, techProfiletblID uint32, uniPortName string) error { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 624 | path := t.GetTechProfileInstanceKVPath(ctx, techProfiletblID, uniPortName) |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 625 | return t.config.KVBackend.Delete(ctx, path) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 628 | func (t *TechProfileMgr) validateInstanceControlAttr(ctx context.Context, instCtl InstanceControl) error { |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 629 | if instCtl.Onu != "single-instance" && instCtl.Onu != "multi-instance" { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 630 | logger.Errorw(ctx, "invalid-onu-instance-control-attribute", log.Fields{"onu-inst": instCtl.Onu}) |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 631 | return errors.New("invalid-onu-instance-ctl-attr") |
| 632 | } |
| 633 | |
| 634 | if instCtl.Uni != "single-instance" && instCtl.Uni != "multi-instance" { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 635 | logger.Errorw(ctx, "invalid-uni-instance-control-attribute", log.Fields{"uni-inst": instCtl.Uni}) |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 636 | return errors.New("invalid-uni-instance-ctl-attr") |
| 637 | } |
| 638 | |
| 639 | if instCtl.Uni == "multi-instance" { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 640 | logger.Error(ctx, "uni-multi-instance-tp-not-supported") |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 641 | return errors.New("uni-multi-instance-tp-not-supported") |
| 642 | } |
| 643 | |
| 644 | return nil |
| 645 | } |
| 646 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 647 | func (t *TechProfileMgr) allocateTPInstance(ctx context.Context, uniPortName string, tp *DefaultTechProfile, intfId uint32, tpInstPath string) *TechProfile { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 648 | |
| 649 | var usGemPortAttributeList []iGemPortAttribute |
| 650 | var dsGemPortAttributeList []iGemPortAttribute |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 651 | var dsMulticastGemAttributeList []iGemPortAttribute |
| 652 | var dsUnicastGemAttributeList []iGemPortAttribute |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 653 | var tcontIDs []uint32 |
| 654 | var gemPorts []uint32 |
| 655 | var err error |
| 656 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 657 | logger.Infow(ctx, "Allocating TechProfileMgr instance from techprofile template", log.Fields{"uniPortName": uniPortName, "intfId": intfId, "numGem": tp.NumGemPorts}) |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 658 | |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 659 | if tp.InstanceCtrl.Onu == "multi-instance" { |
Gamze Abaka | dfdd8f8 | 2020-05-04 08:39:50 +0000 | [diff] [blame] | 660 | t.AllocIDMgmtLock.Lock() |
| 661 | tcontIDs, err = t.resourceMgr.GetResourceID(ctx, intfId, t.resourceMgr.GetResourceTypeAllocID(), 1) |
| 662 | t.AllocIDMgmtLock.Unlock() |
| 663 | if err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 664 | logger.Errorw(ctx, "Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId}) |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 665 | return nil |
| 666 | } |
| 667 | } else { // "single-instance" |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 668 | if tpInst, err := t.getSingleInstanceTp(ctx, tpInstPath); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 669 | logger.Errorw(ctx, "Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId}) |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 670 | return nil |
| 671 | } else if tpInst == nil { |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 672 | // No "single-instance" tp found on one any uni port for the given TP ID |
| 673 | // Allocate a new TcontID or AllocID |
Gamze Abaka | dfdd8f8 | 2020-05-04 08:39:50 +0000 | [diff] [blame] | 674 | t.AllocIDMgmtLock.Lock() |
| 675 | tcontIDs, err = t.resourceMgr.GetResourceID(ctx, intfId, t.resourceMgr.GetResourceTypeAllocID(), 1) |
| 676 | t.AllocIDMgmtLock.Unlock() |
| 677 | if err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 678 | logger.Errorw(ctx, "Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId}) |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 679 | return nil |
| 680 | } |
| 681 | } else { |
| 682 | // Use the alloc-id from the existing TpInstance |
| 683 | tcontIDs = append(tcontIDs, tpInst.UsScheduler.AllocID) |
| 684 | } |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 685 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 686 | logger.Debugw(ctx, "Num GEM ports in TP:", log.Fields{"NumGemPorts": tp.NumGemPorts}) |
Gamze Abaka | dfdd8f8 | 2020-05-04 08:39:50 +0000 | [diff] [blame] | 687 | t.GemPortIDMgmtLock.Lock() |
| 688 | gemPorts, err = t.resourceMgr.GetResourceID(ctx, intfId, t.resourceMgr.GetResourceTypeGemPortID(), tp.NumGemPorts) |
| 689 | t.GemPortIDMgmtLock.Unlock() |
| 690 | if err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 691 | logger.Errorw(ctx, "Error getting gemport ids from rsrcrMgr", log.Fields{"intfId": intfId, "numGemports": tp.NumGemPorts}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 692 | return nil |
| 693 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 694 | logger.Infow(ctx, "Allocated tconts and GEM ports successfully", log.Fields{"tconts": tcontIDs, "gemports": gemPorts}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 695 | for index := 0; index < int(tp.NumGemPorts); index++ { |
| 696 | usGemPortAttributeList = append(usGemPortAttributeList, |
| 697 | iGemPortAttribute{GemportID: gemPorts[index], |
| 698 | MaxQueueSize: tp.UpstreamGemPortAttributeList[index].MaxQueueSize, |
| 699 | PbitMap: tp.UpstreamGemPortAttributeList[index].PbitMap, |
| 700 | AesEncryption: tp.UpstreamGemPortAttributeList[index].AesEncryption, |
| 701 | SchedulingPolicy: tp.UpstreamGemPortAttributeList[index].SchedulingPolicy, |
| 702 | PriorityQueue: tp.UpstreamGemPortAttributeList[index].PriorityQueue, |
| 703 | Weight: tp.UpstreamGemPortAttributeList[index].Weight, |
| 704 | DiscardPolicy: tp.UpstreamGemPortAttributeList[index].DiscardPolicy, |
| 705 | DiscardConfig: tp.UpstreamGemPortAttributeList[index].DiscardConfig}) |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 706 | } |
| 707 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 708 | logger.Info(ctx, "length of DownstreamGemPortAttributeList", len(tp.DownstreamGemPortAttributeList)) |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 709 | //put multicast and unicast downstream GEM port attributes in different lists first |
| 710 | for index := 0; index < int(len(tp.DownstreamGemPortAttributeList)); index++ { |
| 711 | if isMulticastGem(tp.DownstreamGemPortAttributeList[index].IsMulticast) { |
| 712 | dsMulticastGemAttributeList = append(dsMulticastGemAttributeList, |
| 713 | iGemPortAttribute{ |
| 714 | McastGemID: tp.DownstreamGemPortAttributeList[index].McastGemID, |
| 715 | MaxQueueSize: tp.DownstreamGemPortAttributeList[index].MaxQueueSize, |
| 716 | PbitMap: tp.DownstreamGemPortAttributeList[index].PbitMap, |
| 717 | AesEncryption: tp.DownstreamGemPortAttributeList[index].AesEncryption, |
| 718 | SchedulingPolicy: tp.DownstreamGemPortAttributeList[index].SchedulingPolicy, |
| 719 | PriorityQueue: tp.DownstreamGemPortAttributeList[index].PriorityQueue, |
| 720 | Weight: tp.DownstreamGemPortAttributeList[index].Weight, |
| 721 | DiscardPolicy: tp.DownstreamGemPortAttributeList[index].DiscardPolicy, |
| 722 | DiscardConfig: tp.DownstreamGemPortAttributeList[index].DiscardConfig, |
| 723 | IsMulticast: tp.DownstreamGemPortAttributeList[index].IsMulticast, |
| 724 | DControlList: tp.DownstreamGemPortAttributeList[index].DControlList, |
| 725 | SControlList: tp.DownstreamGemPortAttributeList[index].SControlList}) |
| 726 | } else { |
| 727 | dsUnicastGemAttributeList = append(dsUnicastGemAttributeList, |
| 728 | iGemPortAttribute{ |
| 729 | MaxQueueSize: tp.DownstreamGemPortAttributeList[index].MaxQueueSize, |
| 730 | PbitMap: tp.DownstreamGemPortAttributeList[index].PbitMap, |
| 731 | AesEncryption: tp.DownstreamGemPortAttributeList[index].AesEncryption, |
| 732 | SchedulingPolicy: tp.DownstreamGemPortAttributeList[index].SchedulingPolicy, |
| 733 | PriorityQueue: tp.DownstreamGemPortAttributeList[index].PriorityQueue, |
| 734 | Weight: tp.DownstreamGemPortAttributeList[index].Weight, |
| 735 | DiscardPolicy: tp.DownstreamGemPortAttributeList[index].DiscardPolicy, |
| 736 | DiscardConfig: tp.DownstreamGemPortAttributeList[index].DiscardConfig}) |
| 737 | } |
| 738 | } |
| 739 | //add unicast downstream GEM ports to dsGemPortAttributeList |
| 740 | for index := 0; index < int(tp.NumGemPorts); index++ { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 741 | dsGemPortAttributeList = append(dsGemPortAttributeList, |
| 742 | iGemPortAttribute{GemportID: gemPorts[index], |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 743 | MaxQueueSize: dsUnicastGemAttributeList[index].MaxQueueSize, |
| 744 | PbitMap: dsUnicastGemAttributeList[index].PbitMap, |
| 745 | AesEncryption: dsUnicastGemAttributeList[index].AesEncryption, |
| 746 | SchedulingPolicy: dsUnicastGemAttributeList[index].SchedulingPolicy, |
| 747 | PriorityQueue: dsUnicastGemAttributeList[index].PriorityQueue, |
| 748 | Weight: dsUnicastGemAttributeList[index].Weight, |
| 749 | DiscardPolicy: dsUnicastGemAttributeList[index].DiscardPolicy, |
| 750 | DiscardConfig: dsUnicastGemAttributeList[index].DiscardConfig}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 751 | } |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 752 | //add multicast GEM ports to dsGemPortAttributeList afterwards |
| 753 | for k := range dsMulticastGemAttributeList { |
| 754 | dsGemPortAttributeList = append(dsGemPortAttributeList, dsMulticastGemAttributeList[k]) |
| 755 | } |
| 756 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 757 | return &TechProfile{ |
| 758 | SubscriberIdentifier: uniPortName, |
| 759 | Name: tp.Name, |
| 760 | ProfileType: tp.ProfileType, |
| 761 | Version: tp.Version, |
| 762 | NumGemPorts: tp.NumGemPorts, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 763 | InstanceCtrl: tp.InstanceCtrl, |
| 764 | UsScheduler: iScheduler{ |
| 765 | AllocID: tcontIDs[0], |
| 766 | Direction: tp.UsScheduler.Direction, |
| 767 | AdditionalBw: tp.UsScheduler.AdditionalBw, |
| 768 | Priority: tp.UsScheduler.Priority, |
| 769 | Weight: tp.UsScheduler.Weight, |
| 770 | QSchedPolicy: tp.UsScheduler.QSchedPolicy}, |
| 771 | DsScheduler: iScheduler{ |
| 772 | AllocID: tcontIDs[0], |
| 773 | Direction: tp.DsScheduler.Direction, |
| 774 | AdditionalBw: tp.DsScheduler.AdditionalBw, |
| 775 | Priority: tp.DsScheduler.Priority, |
| 776 | Weight: tp.DsScheduler.Weight, |
| 777 | QSchedPolicy: tp.DsScheduler.QSchedPolicy}, |
| 778 | UpstreamGemPortAttributeList: usGemPortAttributeList, |
| 779 | DownstreamGemPortAttributeList: dsGemPortAttributeList} |
| 780 | } |
| 781 | |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 782 | // allocateTPInstance function for EPON |
| 783 | func (t *TechProfileMgr) allocateEponTPInstance(ctx context.Context, uniPortName string, tp *DefaultEponProfile, intfId uint32, tpInstPath string) *EponProfile { |
| 784 | |
| 785 | var usQueueAttributeList []iUpstreamQueueAttribute |
| 786 | var dsQueueAttributeList []iDownstreamQueueAttribute |
| 787 | var tcontIDs []uint32 |
| 788 | var gemPorts []uint32 |
| 789 | var err error |
| 790 | |
| 791 | log.Infow("Allocating TechProfileMgr instance from techprofile template", log.Fields{"uniPortName": uniPortName, "intfId": intfId, "numGem": tp.NumGemPorts}) |
| 792 | |
| 793 | if tp.InstanceCtrl.Onu == "multi-instance" { |
| 794 | if tcontIDs, err = t.resourceMgr.GetResourceID(ctx, intfId, t.resourceMgr.GetResourceTypeAllocID(), 1); err != nil { |
| 795 | log.Errorw("Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId}) |
| 796 | return nil |
| 797 | } |
| 798 | } else { // "single-instance" |
| 799 | if tpInst, err := t.getSingleInstanceEponTp(ctx, tpInstPath); err != nil { |
| 800 | log.Errorw("Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId}) |
| 801 | return nil |
| 802 | } else if tpInst == nil { |
| 803 | // No "single-instance" tp found on one any uni port for the given TP ID |
| 804 | // Allocate a new TcontID or AllocID |
| 805 | if tcontIDs, err = t.resourceMgr.GetResourceID(ctx, intfId, t.resourceMgr.GetResourceTypeAllocID(), 1); err != nil { |
| 806 | log.Errorw("Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId}) |
| 807 | return nil |
| 808 | } |
| 809 | } else { |
| 810 | // Use the alloc-id from the existing TpInstance |
| 811 | tcontIDs = append(tcontIDs, tpInst.AllocID) |
| 812 | } |
| 813 | } |
| 814 | log.Debugw("Num GEM ports in TP:", log.Fields{"NumGemPorts": tp.NumGemPorts}) |
| 815 | if gemPorts, err = t.resourceMgr.GetResourceID(ctx, intfId, t.resourceMgr.GetResourceTypeGemPortID(), tp.NumGemPorts); err != nil { |
| 816 | log.Errorw("Error getting gemport ids from rsrcrMgr", log.Fields{"intfId": intfId, "numGemports": tp.NumGemPorts}) |
| 817 | return nil |
| 818 | } |
| 819 | log.Infow("Allocated tconts and GEM ports successfully", log.Fields{"tconts": tcontIDs, "gemports": gemPorts}) |
| 820 | for index := 0; index < int(tp.NumGemPorts); index++ { |
| 821 | usQueueAttributeList = append(usQueueAttributeList, |
| 822 | iUpstreamQueueAttribute{GemportID: gemPorts[index], |
| 823 | MaxQueueSize: tp.UpstreamQueueAttributeList[index].MaxQueueSize, |
| 824 | PbitMap: tp.UpstreamQueueAttributeList[index].PbitMap, |
| 825 | AesEncryption: tp.UpstreamQueueAttributeList[index].AesEncryption, |
| 826 | TrafficType: tp.UpstreamQueueAttributeList[index].TrafficType, |
| 827 | UnsolicitedGrantSize: tp.UpstreamQueueAttributeList[index].UnsolicitedGrantSize, |
| 828 | NominalInterval: tp.UpstreamQueueAttributeList[index].NominalInterval, |
| 829 | ToleratedPollJitter: tp.UpstreamQueueAttributeList[index].ToleratedPollJitter, |
| 830 | RequestTransmissionPolicy: tp.UpstreamQueueAttributeList[index].RequestTransmissionPolicy, |
| 831 | NumQueueSet: tp.UpstreamQueueAttributeList[index].NumQueueSet, |
| 832 | QThresholds: tp.UpstreamQueueAttributeList[index].QThresholds, |
| 833 | SchedulingPolicy: tp.UpstreamQueueAttributeList[index].SchedulingPolicy, |
| 834 | PriorityQueue: tp.UpstreamQueueAttributeList[index].PriorityQueue, |
| 835 | Weight: tp.UpstreamQueueAttributeList[index].Weight, |
| 836 | DiscardPolicy: tp.UpstreamQueueAttributeList[index].DiscardPolicy, |
| 837 | DiscardConfig: tp.UpstreamQueueAttributeList[index].DiscardConfig}) |
| 838 | } |
| 839 | |
| 840 | log.Info("length of DownstreamGemPortAttributeList", len(tp.DownstreamQueueAttributeList)) |
| 841 | for index := 0; index < int(tp.NumGemPorts); index++ { |
| 842 | dsQueueAttributeList = append(dsQueueAttributeList, |
| 843 | iDownstreamQueueAttribute{GemportID: gemPorts[index], |
| 844 | MaxQueueSize: tp.DownstreamQueueAttributeList[index].MaxQueueSize, |
| 845 | PbitMap: tp.DownstreamQueueAttributeList[index].PbitMap, |
| 846 | AesEncryption: tp.DownstreamQueueAttributeList[index].AesEncryption, |
| 847 | SchedulingPolicy: tp.DownstreamQueueAttributeList[index].SchedulingPolicy, |
| 848 | PriorityQueue: tp.DownstreamQueueAttributeList[index].PriorityQueue, |
| 849 | Weight: tp.DownstreamQueueAttributeList[index].Weight, |
| 850 | DiscardPolicy: tp.DownstreamQueueAttributeList[index].DiscardPolicy, |
| 851 | DiscardConfig: tp.DownstreamQueueAttributeList[index].DiscardConfig}) |
| 852 | } |
| 853 | |
| 854 | return &EponProfile{ |
| 855 | SubscriberIdentifier: uniPortName, |
| 856 | Name: tp.Name, |
| 857 | ProfileType: tp.ProfileType, |
| 858 | Version: tp.Version, |
| 859 | NumGemPorts: tp.NumGemPorts, |
| 860 | InstanceCtrl: tp.InstanceCtrl, |
| 861 | EponAttribute: tp.EponAttribute, |
| 862 | AllocID: tcontIDs[0], |
| 863 | UpstreamQueueAttributeList: usQueueAttributeList, |
| 864 | DownstreamQueueAttributeList: dsQueueAttributeList} |
| 865 | } |
| 866 | |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 867 | // getSingleInstanceTp returns another TpInstance for an ONU on a different |
| 868 | // uni port for the same TP ID, if it finds one, else nil. |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 869 | func (t *TechProfileMgr) getSingleInstanceTp(ctx context.Context, tpPath string) (*TechProfile, error) { |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 870 | var tpInst TechProfile |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 871 | |
| 872 | // For example: |
| 873 | // tpPath like "service/voltha/technology_profiles/xgspon/64/pon-{0}/onu-{1}/uni-{1}" |
| 874 | // is broken into ["service/voltha/technology_profiles/xgspon/64/pon-{0}/onu-{1}" ""] |
| 875 | uniPathSlice := regexp.MustCompile(`/uni-{[0-9]+}$`).Split(tpPath, 2) |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 876 | kvPairs, _ := t.config.KVBackend.List(ctx, uniPathSlice[0]) |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 877 | |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 878 | // Find a valid TP Instance among all the UNIs of that ONU for the given TP ID |
| 879 | for keyPath, kvPair := range kvPairs { |
| 880 | if value, err := kvstore.ToByte(kvPair.Value); err == nil { |
| 881 | if err = json.Unmarshal(value, &tpInst); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 882 | logger.Errorw(ctx, "error-unmarshal-kv-pair", log.Fields{"keyPath": keyPath, "value": value}) |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 883 | return nil, errors.New("error-unmarshal-kv-pair") |
| 884 | } else { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 885 | logger.Debugw(ctx, "found-valid-tp-instance-on-another-uni", log.Fields{"keyPath": keyPath}) |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 886 | return &tpInst, nil |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 887 | } |
| 888 | } |
| 889 | } |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 890 | return nil, nil |
| 891 | } |
| 892 | |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 893 | func (t *TechProfileMgr) getSingleInstanceEponTp(ctx context.Context, tpPath string) (*EponProfile, error) { |
| 894 | var tpInst EponProfile |
| 895 | |
| 896 | // For example: |
| 897 | // tpPath like "service/voltha/technology_profiles/xgspon/64/pon-{0}/onu-{1}/uni-{1}" |
| 898 | // is broken into ["service/voltha/technology_profiles/xgspon/64/pon-{0}/onu-{1}" ""] |
| 899 | uniPathSlice := regexp.MustCompile(`/uni-{[0-9]+}$`).Split(tpPath, 2) |
| 900 | kvPairs, _ := t.config.KVBackend.List(ctx, uniPathSlice[0]) |
| 901 | |
| 902 | // Find a valid TP Instance among all the UNIs of that ONU for the given TP ID |
| 903 | for keyPath, kvPair := range kvPairs { |
| 904 | if value, err := kvstore.ToByte(kvPair.Value); err == nil { |
| 905 | if err = json.Unmarshal(value, &tpInst); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 906 | logger.Errorw(ctx, "error-unmarshal-kv-pair", log.Fields{"keyPath": keyPath, "value": value}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 907 | return nil, errors.New("error-unmarshal-kv-pair") |
| 908 | } else { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 909 | logger.Debugw(ctx, "found-valid-tp-instance-on-another-uni", log.Fields{"keyPath": keyPath}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 910 | return &tpInst, nil |
| 911 | } |
| 912 | } |
| 913 | } |
| 914 | return nil, nil |
| 915 | } |
| 916 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 917 | func (t *TechProfileMgr) getDefaultTechProfile(ctx context.Context) *DefaultTechProfile { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 918 | var usGemPortAttributeList []GemPortAttribute |
| 919 | var dsGemPortAttributeList []GemPortAttribute |
| 920 | |
| 921 | for _, pbit := range t.config.DefaultPbits { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 922 | logger.Debugw(ctx, "Creating GEM port", log.Fields{"pbit": pbit}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 923 | usGemPortAttributeList = append(usGemPortAttributeList, |
| 924 | GemPortAttribute{ |
| 925 | MaxQueueSize: defaultMaxQueueSize, |
| 926 | PbitMap: pbit, |
| 927 | AesEncryption: defaultAESEncryption, |
| 928 | SchedulingPolicy: SchedulingPolicy_name[defaultSchedulePolicy], |
| 929 | PriorityQueue: defaultPriorityQueue, |
| 930 | Weight: defaultQueueWeight, |
| 931 | DiscardPolicy: DiscardPolicy_name[defaultdropPolicy], |
| 932 | DiscardConfig: DiscardConfig{ |
| 933 | MinThreshold: defaultMinThreshold, |
| 934 | MaxThreshold: defaultMaxThreshold, |
| 935 | MaxProbability: defaultMaxProbability}}) |
| 936 | dsGemPortAttributeList = append(dsGemPortAttributeList, |
| 937 | GemPortAttribute{ |
| 938 | MaxQueueSize: defaultMaxQueueSize, |
| 939 | PbitMap: pbit, |
| 940 | AesEncryption: defaultAESEncryption, |
| 941 | SchedulingPolicy: SchedulingPolicy_name[defaultSchedulePolicy], |
| 942 | PriorityQueue: defaultPriorityQueue, |
| 943 | Weight: defaultQueueWeight, |
| 944 | DiscardPolicy: DiscardPolicy_name[defaultdropPolicy], |
| 945 | DiscardConfig: DiscardConfig{ |
| 946 | MinThreshold: defaultMinThreshold, |
| 947 | MaxThreshold: defaultMaxThreshold, |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 948 | MaxProbability: defaultMaxProbability}, |
| 949 | IsMulticast: defaultIsMulticast, |
| 950 | DControlList: defaultAccessControlList, |
| 951 | SControlList: defaultAccessControlList, |
| 952 | McastGemID: defaultMcastGemID}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 953 | } |
| 954 | return &DefaultTechProfile{ |
| 955 | Name: t.config.DefaultTPName, |
| 956 | ProfileType: t.resourceMgr.GetTechnology(), |
| 957 | Version: t.config.TPVersion, |
| 958 | NumGemPorts: uint32(len(usGemPortAttributeList)), |
| 959 | InstanceCtrl: InstanceControl{ |
| 960 | Onu: defaultOnuInstance, |
| 961 | Uni: defaultUniInstance, |
| 962 | MaxGemPayloadSize: defaultGemPayloadSize}, |
| 963 | UsScheduler: Scheduler{ |
| 964 | Direction: Direction_name[Direction_UPSTREAM], |
| 965 | AdditionalBw: AdditionalBW_name[defaultAdditionalBw], |
| 966 | Priority: defaultPriority, |
| 967 | Weight: defaultWeight, |
| 968 | QSchedPolicy: SchedulingPolicy_name[defaultQueueSchedPolicy]}, |
| 969 | DsScheduler: Scheduler{ |
| 970 | Direction: Direction_name[Direction_DOWNSTREAM], |
| 971 | AdditionalBw: AdditionalBW_name[defaultAdditionalBw], |
| 972 | Priority: defaultPriority, |
| 973 | Weight: defaultWeight, |
| 974 | QSchedPolicy: SchedulingPolicy_name[defaultQueueSchedPolicy]}, |
| 975 | UpstreamGemPortAttributeList: usGemPortAttributeList, |
| 976 | DownstreamGemPortAttributeList: dsGemPortAttributeList} |
| 977 | } |
| 978 | |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 979 | // getDefaultTechProfile function for EPON |
| 980 | func (t *TechProfileMgr) getDefaultEponProfile() *DefaultEponProfile { |
| 981 | |
| 982 | var usQueueAttributeList []UpstreamQueueAttribute |
| 983 | var dsQueueAttributeList []DownstreamQueueAttribute |
| 984 | |
| 985 | for _, pbit := range t.config.DefaultPbits { |
| 986 | log.Debugw("Creating Queue", log.Fields{"pbit": pbit}) |
| 987 | usQueueAttributeList = append(usQueueAttributeList, |
| 988 | UpstreamQueueAttribute{ |
| 989 | MaxQueueSize: defaultMaxQueueSize, |
| 990 | PbitMap: pbit, |
| 991 | AesEncryption: defaultAESEncryption, |
| 992 | TrafficType: defaultTrafficType, |
| 993 | UnsolicitedGrantSize: defaultUnsolicitedGrantSize, |
| 994 | NominalInterval: defaultNominalInterval, |
| 995 | ToleratedPollJitter: defaultToleratedPollJitter, |
| 996 | RequestTransmissionPolicy: defaultRequestTransmissionPolicy, |
| 997 | NumQueueSet: defaultNumQueueSet, |
| 998 | QThresholds: QThresholds{ |
| 999 | QThreshold1: defaultQThreshold1, |
| 1000 | QThreshold2: defaultQThreshold2, |
| 1001 | QThreshold3: defaultQThreshold3, |
| 1002 | QThreshold4: defaultQThreshold4, |
| 1003 | QThreshold5: defaultQThreshold5, |
| 1004 | QThreshold6: defaultQThreshold6, |
| 1005 | QThreshold7: defaultQThreshold7}, |
| 1006 | SchedulingPolicy: SchedulingPolicy_name[defaultSchedulePolicy], |
| 1007 | PriorityQueue: defaultPriorityQueue, |
| 1008 | Weight: defaultQueueWeight, |
| 1009 | DiscardPolicy: DiscardPolicy_name[defaultdropPolicy], |
| 1010 | DiscardConfig: DiscardConfig{ |
| 1011 | MinThreshold: defaultMinThreshold, |
| 1012 | MaxThreshold: defaultMaxThreshold, |
| 1013 | MaxProbability: defaultMaxProbability}}) |
| 1014 | dsQueueAttributeList = append(dsQueueAttributeList, |
| 1015 | DownstreamQueueAttribute{ |
| 1016 | MaxQueueSize: defaultMaxQueueSize, |
| 1017 | PbitMap: pbit, |
| 1018 | AesEncryption: defaultAESEncryption, |
| 1019 | SchedulingPolicy: SchedulingPolicy_name[defaultSchedulePolicy], |
| 1020 | PriorityQueue: defaultPriorityQueue, |
| 1021 | Weight: defaultQueueWeight, |
| 1022 | DiscardPolicy: DiscardPolicy_name[defaultdropPolicy], |
| 1023 | DiscardConfig: DiscardConfig{ |
| 1024 | MinThreshold: defaultMinThreshold, |
| 1025 | MaxThreshold: defaultMaxThreshold, |
| 1026 | MaxProbability: defaultMaxProbability}}) |
| 1027 | } |
| 1028 | return &DefaultEponProfile{ |
| 1029 | Name: t.config.DefaultTPName, |
| 1030 | ProfileType: t.resourceMgr.GetTechnology(), |
| 1031 | Version: t.config.TPVersion, |
| 1032 | NumGemPorts: uint32(len(usQueueAttributeList)), |
| 1033 | InstanceCtrl: InstanceControl{ |
| 1034 | Onu: defaultOnuInstance, |
| 1035 | Uni: defaultUniInstance, |
| 1036 | MaxGemPayloadSize: defaultGemPayloadSize}, |
| 1037 | EponAttribute: EponAttribute{ |
| 1038 | PackageType: defaultPakageType}, |
| 1039 | UpstreamQueueAttributeList: usQueueAttributeList, |
| 1040 | DownstreamQueueAttributeList: dsQueueAttributeList} |
| 1041 | } |
| 1042 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1043 | func (t *TechProfileMgr) GetprotoBufParamValue(ctx context.Context, paramType string, paramKey string) int32 { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1044 | var result int32 = -1 |
| 1045 | |
| 1046 | if paramType == "direction" { |
| 1047 | for key, val := range tp_pb.Direction_value { |
| 1048 | if key == paramKey { |
| 1049 | result = val |
| 1050 | } |
| 1051 | } |
| 1052 | } else if paramType == "discard_policy" { |
| 1053 | for key, val := range tp_pb.DiscardPolicy_value { |
| 1054 | if key == paramKey { |
| 1055 | result = val |
| 1056 | } |
| 1057 | } |
| 1058 | } else if paramType == "sched_policy" { |
| 1059 | for key, val := range tp_pb.SchedulingPolicy_value { |
| 1060 | if key == paramKey { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1061 | logger.Debugw(ctx, "Got value in proto", log.Fields{"key": key, "value": val}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1062 | result = val |
| 1063 | } |
| 1064 | } |
| 1065 | } else if paramType == "additional_bw" { |
| 1066 | for key, val := range tp_pb.AdditionalBW_value { |
| 1067 | if key == paramKey { |
| 1068 | result = val |
| 1069 | } |
| 1070 | } |
| 1071 | } else { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1072 | logger.Error(ctx, "Could not find proto parameter", log.Fields{"paramType": paramType, "key": paramKey}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1073 | return -1 |
| 1074 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1075 | logger.Debugw(ctx, "Got value in proto", log.Fields{"key": paramKey, "value": result}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1076 | return result |
| 1077 | } |
| 1078 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1079 | func (t *TechProfileMgr) GetUsScheduler(ctx context.Context, tpInstance *TechProfile) (*tp_pb.SchedulerConfig, error) { |
| 1080 | dir := tp_pb.Direction(t.GetprotoBufParamValue(ctx, "direction", tpInstance.UsScheduler.Direction)) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1081 | if dir == -1 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1082 | logger.Errorf(ctx, "Error in getting proto id for direction %s for upstream scheduler", tpInstance.UsScheduler.Direction) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1083 | return nil, fmt.Errorf("unable to get proto id for direction %s for upstream scheduler", tpInstance.UsScheduler.Direction) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1084 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1085 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1086 | bw := tp_pb.AdditionalBW(t.GetprotoBufParamValue(ctx, "additional_bw", tpInstance.UsScheduler.AdditionalBw)) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1087 | if bw == -1 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1088 | logger.Errorf(ctx, "Error in getting proto id for bandwidth %s for upstream scheduler", tpInstance.UsScheduler.AdditionalBw) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1089 | return nil, fmt.Errorf("unable to get proto id for bandwidth %s for upstream scheduler", tpInstance.UsScheduler.AdditionalBw) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1090 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1091 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1092 | policy := tp_pb.SchedulingPolicy(t.GetprotoBufParamValue(ctx, "sched_policy", tpInstance.UsScheduler.QSchedPolicy)) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1093 | if policy == -1 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1094 | logger.Errorf(ctx, "Error in getting proto id for scheduling policy %s for upstream scheduler", tpInstance.UsScheduler.QSchedPolicy) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1095 | return nil, fmt.Errorf("unable to get proto id for scheduling policy %s for upstream scheduler", tpInstance.UsScheduler.QSchedPolicy) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1096 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1097 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1098 | return &tp_pb.SchedulerConfig{ |
| 1099 | Direction: dir, |
| 1100 | AdditionalBw: bw, |
| 1101 | Priority: tpInstance.UsScheduler.Priority, |
| 1102 | Weight: tpInstance.UsScheduler.Weight, |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1103 | SchedPolicy: policy}, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1106 | func (t *TechProfileMgr) GetDsScheduler(ctx context.Context, tpInstance *TechProfile) (*tp_pb.SchedulerConfig, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1107 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1108 | dir := tp_pb.Direction(t.GetprotoBufParamValue(ctx, "direction", tpInstance.DsScheduler.Direction)) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1109 | if dir == -1 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1110 | logger.Errorf(ctx, "Error in getting proto id for direction %s for downstream scheduler", tpInstance.DsScheduler.Direction) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1111 | return nil, fmt.Errorf("unable to get proto id for direction %s for downstream scheduler", tpInstance.DsScheduler.Direction) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1112 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1113 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1114 | bw := tp_pb.AdditionalBW(t.GetprotoBufParamValue(ctx, "additional_bw", tpInstance.DsScheduler.AdditionalBw)) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1115 | if bw == -1 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1116 | logger.Errorf(ctx, "Error in getting proto id for bandwidth %s for downstream scheduler", tpInstance.DsScheduler.AdditionalBw) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1117 | return nil, fmt.Errorf("unable to get proto id for bandwidth %s for downstream scheduler", tpInstance.DsScheduler.AdditionalBw) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1118 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1119 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1120 | policy := tp_pb.SchedulingPolicy(t.GetprotoBufParamValue(ctx, "sched_policy", tpInstance.DsScheduler.QSchedPolicy)) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1121 | if policy == -1 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1122 | logger.Errorf(ctx, "Error in getting proto id for scheduling policy %s for downstream scheduler", tpInstance.DsScheduler.QSchedPolicy) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1123 | return nil, fmt.Errorf("unable to get proto id for scheduling policy %s for downstream scheduler", tpInstance.DsScheduler.QSchedPolicy) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | return &tp_pb.SchedulerConfig{ |
| 1127 | Direction: dir, |
| 1128 | AdditionalBw: bw, |
| 1129 | Priority: tpInstance.DsScheduler.Priority, |
| 1130 | Weight: tpInstance.DsScheduler.Weight, |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1131 | SchedPolicy: policy}, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | func (t *TechProfileMgr) GetTrafficScheduler(tpInstance *TechProfile, SchedCfg *tp_pb.SchedulerConfig, |
| 1135 | ShapingCfg *tp_pb.TrafficShapingInfo) *tp_pb.TrafficScheduler { |
| 1136 | |
| 1137 | tSched := &tp_pb.TrafficScheduler{ |
| 1138 | Direction: SchedCfg.Direction, |
| 1139 | AllocId: tpInstance.UsScheduler.AllocID, |
| 1140 | TrafficShapingInfo: ShapingCfg, |
| 1141 | Scheduler: SchedCfg} |
| 1142 | |
| 1143 | return tSched |
| 1144 | } |
| 1145 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1146 | func (tpm *TechProfileMgr) GetTrafficQueues(ctx context.Context, tp *TechProfile, Dir tp_pb.Direction) ([]*tp_pb.TrafficQueue, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1147 | |
| 1148 | var encryp bool |
| 1149 | if Dir == tp_pb.Direction_UPSTREAM { |
| 1150 | // upstream GEM ports |
| 1151 | NumGemPorts := len(tp.UpstreamGemPortAttributeList) |
| 1152 | GemPorts := make([]*tp_pb.TrafficQueue, 0) |
| 1153 | for Count := 0; Count < NumGemPorts; Count++ { |
| 1154 | if tp.UpstreamGemPortAttributeList[Count].AesEncryption == "True" { |
| 1155 | encryp = true |
| 1156 | } else { |
| 1157 | encryp = false |
| 1158 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1159 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1160 | schedPolicy := tpm.GetprotoBufParamValue(ctx, "sched_policy", tp.UpstreamGemPortAttributeList[Count].SchedulingPolicy) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1161 | if schedPolicy == -1 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1162 | logger.Errorf(ctx, "Error in getting Proto Id for scheduling policy %s for Upstream Gem Port %d", tp.UpstreamGemPortAttributeList[Count].SchedulingPolicy, Count) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1163 | return nil, fmt.Errorf("upstream gem port traffic queue creation failed due to unrecognized scheduling policy %s", tp.UpstreamGemPortAttributeList[Count].SchedulingPolicy) |
| 1164 | } |
| 1165 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1166 | discardPolicy := tpm.GetprotoBufParamValue(ctx, "discard_policy", tp.UpstreamGemPortAttributeList[Count].DiscardPolicy) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1167 | if discardPolicy == -1 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1168 | logger.Errorf(ctx, "Error in getting Proto Id for discard policy %s for Upstream Gem Port %d", tp.UpstreamGemPortAttributeList[Count].DiscardPolicy, Count) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1169 | return nil, fmt.Errorf("upstream gem port traffic queue creation failed due to unrecognized discard policy %s", tp.UpstreamGemPortAttributeList[Count].DiscardPolicy) |
| 1170 | } |
| 1171 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1172 | GemPorts = append(GemPorts, &tp_pb.TrafficQueue{ |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1173 | Direction: tp_pb.Direction(tpm.GetprotoBufParamValue(ctx, "direction", tp.UsScheduler.Direction)), |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1174 | GemportId: tp.UpstreamGemPortAttributeList[Count].GemportID, |
| 1175 | PbitMap: tp.UpstreamGemPortAttributeList[Count].PbitMap, |
| 1176 | AesEncryption: encryp, |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1177 | SchedPolicy: tp_pb.SchedulingPolicy(schedPolicy), |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1178 | Priority: tp.UpstreamGemPortAttributeList[Count].PriorityQueue, |
| 1179 | Weight: tp.UpstreamGemPortAttributeList[Count].Weight, |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1180 | DiscardPolicy: tp_pb.DiscardPolicy(discardPolicy), |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1181 | }) |
| 1182 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1183 | logger.Debugw(ctx, "Upstream Traffic queue list ", log.Fields{"queuelist": GemPorts}) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1184 | return GemPorts, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1185 | } else if Dir == tp_pb.Direction_DOWNSTREAM { |
| 1186 | //downstream GEM ports |
| 1187 | NumGemPorts := len(tp.DownstreamGemPortAttributeList) |
| 1188 | GemPorts := make([]*tp_pb.TrafficQueue, 0) |
| 1189 | for Count := 0; Count < NumGemPorts; Count++ { |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 1190 | if isMulticastGem(tp.DownstreamGemPortAttributeList[Count].IsMulticast) { |
| 1191 | //do not take multicast GEM ports. They are handled separately. |
| 1192 | continue |
| 1193 | } |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1194 | if tp.DownstreamGemPortAttributeList[Count].AesEncryption == "True" { |
| 1195 | encryp = true |
| 1196 | } else { |
| 1197 | encryp = false |
| 1198 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1199 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1200 | schedPolicy := tpm.GetprotoBufParamValue(ctx, "sched_policy", tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1201 | if schedPolicy == -1 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1202 | logger.Errorf(ctx, "Error in getting Proto Id for scheduling policy %s for Downstream Gem Port %d", tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy, Count) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1203 | return nil, fmt.Errorf("downstream gem port traffic queue creation failed due to unrecognized scheduling policy %s", tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy) |
| 1204 | } |
| 1205 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1206 | discardPolicy := tpm.GetprotoBufParamValue(ctx, "discard_policy", tp.DownstreamGemPortAttributeList[Count].DiscardPolicy) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1207 | if discardPolicy == -1 { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1208 | logger.Errorf(ctx, "Error in getting Proto Id for discard policy %s for Downstream Gem Port %d", tp.DownstreamGemPortAttributeList[Count].DiscardPolicy, Count) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1209 | return nil, fmt.Errorf("downstream gem port traffic queue creation failed due to unrecognized discard policy %s", tp.DownstreamGemPortAttributeList[Count].DiscardPolicy) |
| 1210 | } |
| 1211 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1212 | GemPorts = append(GemPorts, &tp_pb.TrafficQueue{ |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1213 | Direction: tp_pb.Direction(tpm.GetprotoBufParamValue(ctx, "direction", tp.DsScheduler.Direction)), |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1214 | GemportId: tp.DownstreamGemPortAttributeList[Count].GemportID, |
| 1215 | PbitMap: tp.DownstreamGemPortAttributeList[Count].PbitMap, |
| 1216 | AesEncryption: encryp, |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1217 | SchedPolicy: tp_pb.SchedulingPolicy(schedPolicy), |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1218 | Priority: tp.DownstreamGemPortAttributeList[Count].PriorityQueue, |
| 1219 | Weight: tp.DownstreamGemPortAttributeList[Count].Weight, |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1220 | DiscardPolicy: tp_pb.DiscardPolicy(discardPolicy), |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1221 | }) |
| 1222 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1223 | logger.Debugw(ctx, "Downstream Traffic queue list ", log.Fields{"queuelist": GemPorts}) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1224 | return GemPorts, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1225 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1226 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1227 | logger.Errorf(ctx, "Unsupported direction %s used for generating Traffic Queue list", Dir) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 1228 | return nil, fmt.Errorf("downstream gem port traffic queue creation failed due to unsupported direction %s", Dir) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1229 | } |
| 1230 | |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 1231 | //isMulticastGem returns true if isMulticast attribute value of a GEM port is true; false otherwise |
| 1232 | func isMulticastGem(isMulticastAttrValue string) bool { |
| 1233 | return isMulticastAttrValue != "" && |
| 1234 | (isMulticastAttrValue == "True" || isMulticastAttrValue == "true" || isMulticastAttrValue == "TRUE") |
| 1235 | } |
| 1236 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1237 | func (tpm *TechProfileMgr) GetMulticastTrafficQueues(ctx context.Context, tp *TechProfile) []*tp_pb.TrafficQueue { |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 1238 | var encryp bool |
| 1239 | NumGemPorts := len(tp.DownstreamGemPortAttributeList) |
| 1240 | mcastTrafficQueues := make([]*tp_pb.TrafficQueue, 0) |
| 1241 | for Count := 0; Count < NumGemPorts; Count++ { |
| 1242 | if !isMulticastGem(tp.DownstreamGemPortAttributeList[Count].IsMulticast) { |
| 1243 | continue |
| 1244 | } |
| 1245 | if tp.DownstreamGemPortAttributeList[Count].AesEncryption == "True" { |
| 1246 | encryp = true |
| 1247 | } else { |
| 1248 | encryp = false |
| 1249 | } |
| 1250 | mcastTrafficQueues = append(mcastTrafficQueues, &tp_pb.TrafficQueue{ |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1251 | Direction: tp_pb.Direction(tpm.GetprotoBufParamValue(ctx, "direction", tp.DsScheduler.Direction)), |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 1252 | GemportId: tp.DownstreamGemPortAttributeList[Count].McastGemID, |
| 1253 | PbitMap: tp.DownstreamGemPortAttributeList[Count].PbitMap, |
| 1254 | AesEncryption: encryp, |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1255 | SchedPolicy: tp_pb.SchedulingPolicy(tpm.GetprotoBufParamValue(ctx, "sched_policy", tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy)), |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 1256 | Priority: tp.DownstreamGemPortAttributeList[Count].PriorityQueue, |
| 1257 | Weight: tp.DownstreamGemPortAttributeList[Count].Weight, |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1258 | DiscardPolicy: tp_pb.DiscardPolicy(tpm.GetprotoBufParamValue(ctx, "discard_policy", tp.DownstreamGemPortAttributeList[Count].DiscardPolicy)), |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 1259 | }) |
| 1260 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1261 | logger.Debugw(ctx, "Downstream Multicast Traffic queue list ", log.Fields{"queuelist": mcastTrafficQueues}) |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 1262 | return mcastTrafficQueues |
| 1263 | } |
| 1264 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1265 | func (tpm *TechProfileMgr) GetUsTrafficScheduler(ctx context.Context, tp *TechProfile) *tp_pb.TrafficScheduler { |
| 1266 | UsScheduler, _ := tpm.GetUsScheduler(ctx, tp) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1267 | |
| 1268 | return &tp_pb.TrafficScheduler{Direction: UsScheduler.Direction, |
| 1269 | AllocId: tp.UsScheduler.AllocID, |
| 1270 | Scheduler: UsScheduler} |
| 1271 | } |
| 1272 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1273 | func (t *TechProfileMgr) GetGemportIDForPbit(ctx context.Context, tp interface{}, dir tp_pb.Direction, pbit uint32) uint32 { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1274 | /* |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1275 | Function to get the Gemport ID mapped to a pbit. |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1276 | */ |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1277 | switch tp := tp.(type) { |
| 1278 | case *TechProfile: |
| 1279 | if dir == tp_pb.Direction_UPSTREAM { |
| 1280 | // upstream GEM ports |
| 1281 | numGemPorts := len(tp.UpstreamGemPortAttributeList) |
| 1282 | for gemCnt := 0; gemCnt < numGemPorts; gemCnt++ { |
| 1283 | lenOfPbitMap := len(tp.UpstreamGemPortAttributeList[gemCnt].PbitMap) |
| 1284 | for pbitMapIdx := 2; pbitMapIdx < lenOfPbitMap; pbitMapIdx++ { |
| 1285 | // Given a sample pbit map string "0b00000001", lenOfPbitMap is 10 |
| 1286 | // "lenOfPbitMap - pbitMapIdx + 1" will give pbit-i th value from LSB position in the pbit map string |
| 1287 | if p, err := strconv.Atoi(string(tp.UpstreamGemPortAttributeList[gemCnt].PbitMap[lenOfPbitMap-pbitMapIdx+1])); err == nil { |
| 1288 | if uint32(pbitMapIdx-2) == pbit && p == 1 { // Check this p-bit is set |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1289 | logger.Debugw(ctx, "Found-US-GEMport-for-Pcp", log.Fields{"pbit": pbit, "GEMport": tp.UpstreamGemPortAttributeList[gemCnt].GemportID}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1290 | return tp.UpstreamGemPortAttributeList[gemCnt].GemportID |
| 1291 | } |
| 1292 | } |
| 1293 | } |
| 1294 | } |
| 1295 | } else if dir == tp_pb.Direction_DOWNSTREAM { |
| 1296 | //downstream GEM ports |
| 1297 | numGemPorts := len(tp.DownstreamGemPortAttributeList) |
| 1298 | for gemCnt := 0; gemCnt < numGemPorts; gemCnt++ { |
| 1299 | lenOfPbitMap := len(tp.DownstreamGemPortAttributeList[gemCnt].PbitMap) |
| 1300 | for pbitMapIdx := 2; pbitMapIdx < lenOfPbitMap; pbitMapIdx++ { |
| 1301 | // Given a sample pbit map string "0b00000001", lenOfPbitMap is 10 |
| 1302 | // "lenOfPbitMap - pbitMapIdx + 1" will give pbit-i th value from LSB position in the pbit map string |
| 1303 | if p, err := strconv.Atoi(string(tp.DownstreamGemPortAttributeList[gemCnt].PbitMap[lenOfPbitMap-pbitMapIdx+1])); err == nil { |
| 1304 | if uint32(pbitMapIdx-2) == pbit && p == 1 { // Check this p-bit is set |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1305 | logger.Debugw(ctx, "Found-DS-GEMport-for-Pcp", log.Fields{"pbit": pbit, "GEMport": tp.DownstreamGemPortAttributeList[gemCnt].GemportID}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1306 | return tp.DownstreamGemPortAttributeList[gemCnt].GemportID |
| 1307 | } |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1308 | } |
| 1309 | } |
| 1310 | } |
| 1311 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1312 | logger.Errorw(ctx, "No-GemportId-Found-For-Pcp", log.Fields{"pcpVlan": pbit}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1313 | case *EponProfile: |
| 1314 | if dir == tp_pb.Direction_UPSTREAM { |
| 1315 | // upstream GEM ports |
| 1316 | numGemPorts := len(tp.UpstreamQueueAttributeList) |
| 1317 | for gemCnt := 0; gemCnt < numGemPorts; gemCnt++ { |
| 1318 | lenOfPbitMap := len(tp.UpstreamQueueAttributeList[gemCnt].PbitMap) |
| 1319 | for pbitMapIdx := 2; pbitMapIdx < lenOfPbitMap; pbitMapIdx++ { |
| 1320 | // Given a sample pbit map string "0b00000001", lenOfPbitMap is 10 |
| 1321 | // "lenOfPbitMap - pbitMapIdx + 1" will give pbit-i th value from LSB position in the pbit map string |
| 1322 | if p, err := strconv.Atoi(string(tp.UpstreamQueueAttributeList[gemCnt].PbitMap[lenOfPbitMap-pbitMapIdx+1])); err == nil { |
| 1323 | if uint32(pbitMapIdx-2) == pbit && p == 1 { // Check this p-bit is set |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1324 | logger.Debugw(ctx, "Found-US-Queue-for-Pcp", log.Fields{"pbit": pbit, "Queue": tp.UpstreamQueueAttributeList[gemCnt].GemportID}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1325 | return tp.UpstreamQueueAttributeList[gemCnt].GemportID |
| 1326 | } |
| 1327 | } |
| 1328 | } |
| 1329 | } |
| 1330 | } else if dir == tp_pb.Direction_DOWNSTREAM { |
| 1331 | //downstream GEM ports |
| 1332 | numGemPorts := len(tp.DownstreamQueueAttributeList) |
| 1333 | for gemCnt := 0; gemCnt < numGemPorts; gemCnt++ { |
| 1334 | lenOfPbitMap := len(tp.DownstreamQueueAttributeList[gemCnt].PbitMap) |
| 1335 | for pbitMapIdx := 2; pbitMapIdx < lenOfPbitMap; pbitMapIdx++ { |
| 1336 | // Given a sample pbit map string "0b00000001", lenOfPbitMap is 10 |
| 1337 | // "lenOfPbitMap - pbitMapIdx + 1" will give pbit-i th value from LSB position in the pbit map string |
| 1338 | if p, err := strconv.Atoi(string(tp.DownstreamQueueAttributeList[gemCnt].PbitMap[lenOfPbitMap-pbitMapIdx+1])); err == nil { |
| 1339 | if uint32(pbitMapIdx-2) == pbit && p == 1 { // Check this p-bit is set |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1340 | logger.Debugw(ctx, "Found-DS-Queue-for-Pcp", log.Fields{"pbit": pbit, "Queue": tp.DownstreamQueueAttributeList[gemCnt].GemportID}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1341 | return tp.DownstreamQueueAttributeList[gemCnt].GemportID |
| 1342 | } |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1343 | } |
| 1344 | } |
| 1345 | } |
| 1346 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1347 | logger.Errorw(ctx, "No-QueueId-Found-For-Pcp", log.Fields{"pcpVlan": pbit}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1348 | default: |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1349 | logger.Errorw(ctx, "unknown-tech", log.Fields{"tp": tp}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1350 | } |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1351 | return 0 |
| 1352 | } |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 1353 | |
| 1354 | // FindAllTpInstances returns all TechProfile instances for a given TechProfile table-id, pon interface ID and onu ID. |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1355 | func (t *TechProfileMgr) FindAllTpInstances(ctx context.Context, techProfiletblID uint32, ponIntf uint32, onuID uint32) interface{} { |
| 1356 | var tpTech TechProfile |
| 1357 | var tpEpon EponProfile |
| 1358 | |
Girish Gowdra | 6172a2e | 2019-11-27 14:37:58 +0530 | [diff] [blame] | 1359 | onuTpInstancePath := fmt.Sprintf("%s/%d/pon-{%d}/onu-{%d}", t.resourceMgr.GetTechnology(), techProfiletblID, ponIntf, onuID) |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 1360 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 1361 | if kvPairs, _ := t.config.KVBackend.List(ctx, onuTpInstancePath); kvPairs != nil { |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1362 | tech := t.resourceMgr.GetTechnology() |
| 1363 | tpInstancesTech := make([]TechProfile, 0, len(kvPairs)) |
| 1364 | tpInstancesEpon := make([]EponProfile, 0, len(kvPairs)) |
| 1365 | |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 1366 | for kvPath, kvPair := range kvPairs { |
| 1367 | if value, err := kvstore.ToByte(kvPair.Value); err == nil { |
Andrea Campanella | 904fe32 | 2020-06-26 18:56:51 +0200 | [diff] [blame] | 1368 | if tech == xgspon || tech == gpon { |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1369 | if err = json.Unmarshal(value, &tpTech); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1370 | logger.Errorw(ctx, "error-unmarshal-kv-pair", log.Fields{"kvPath": kvPath, "value": value}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1371 | continue |
| 1372 | } else { |
| 1373 | tpInstancesTech = append(tpInstancesTech, tpTech) |
| 1374 | } |
| 1375 | } else if tech == epon { |
| 1376 | if err = json.Unmarshal(value, &tpEpon); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 1377 | logger.Errorw(ctx, "error-unmarshal-kv-pair", log.Fields{"kvPath": kvPath, "value": value}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1378 | continue |
| 1379 | } else { |
| 1380 | tpInstancesEpon = append(tpInstancesEpon, tpEpon) |
| 1381 | } |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 1382 | } |
| 1383 | } |
| 1384 | } |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1385 | |
| 1386 | switch tech { |
Andrea Campanella | 904fe32 | 2020-06-26 18:56:51 +0200 | [diff] [blame] | 1387 | case xgspon, gpon: |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1388 | return tpInstancesTech |
| 1389 | case epon: |
| 1390 | return tpInstancesEpon |
| 1391 | default: |
| 1392 | log.Errorw("unknown-technology", log.Fields{"tech": tech}) |
| 1393 | return nil |
| 1394 | } |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 1395 | } |
| 1396 | return nil |
| 1397 | } |