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