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