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" |
| 26 | |
serkant.uluderya | b38671c | 2019-11-01 09:35:38 -0700 | [diff] [blame] | 27 | "github.com/opencord/voltha-lib-go/v3/pkg/db" |
| 28 | |
| 29 | "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore" |
| 30 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 31 | tp_pb "github.com/opencord/voltha-protos/v3/go/tech_profile" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 32 | ) |
| 33 | |
| 34 | // Interface to pon resource manager APIs |
| 35 | type iPonResourceMgr interface { |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 36 | GetResourceID(ctx context.Context, IntfID uint32, ResourceType string, NumIDs uint32) ([]uint32, error) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 37 | GetResourceTypeAllocID() string |
| 38 | GetResourceTypeGemPortID() string |
| 39 | GetTechnology() string |
| 40 | } |
| 41 | |
| 42 | type Direction int32 |
| 43 | |
| 44 | const ( |
| 45 | Direction_UPSTREAM Direction = 0 |
| 46 | Direction_DOWNSTREAM Direction = 1 |
| 47 | Direction_BIDIRECTIONAL Direction = 2 |
| 48 | ) |
| 49 | |
| 50 | var Direction_name = map[Direction]string{ |
| 51 | 0: "UPSTREAM", |
| 52 | 1: "DOWNSTREAM", |
| 53 | 2: "BIDIRECTIONAL", |
| 54 | } |
| 55 | |
| 56 | type SchedulingPolicy int32 |
| 57 | |
| 58 | const ( |
| 59 | SchedulingPolicy_WRR SchedulingPolicy = 0 |
| 60 | SchedulingPolicy_StrictPriority SchedulingPolicy = 1 |
| 61 | SchedulingPolicy_Hybrid SchedulingPolicy = 2 |
| 62 | ) |
| 63 | |
| 64 | var SchedulingPolicy_name = map[SchedulingPolicy]string{ |
| 65 | 0: "WRR", |
| 66 | 1: "StrictPriority", |
| 67 | 2: "Hybrid", |
| 68 | } |
| 69 | |
| 70 | type AdditionalBW int32 |
| 71 | |
| 72 | const ( |
| 73 | AdditionalBW_AdditionalBW_None AdditionalBW = 0 |
| 74 | AdditionalBW_AdditionalBW_NA AdditionalBW = 1 |
| 75 | AdditionalBW_AdditionalBW_BestEffort AdditionalBW = 2 |
| 76 | AdditionalBW_AdditionalBW_Auto AdditionalBW = 3 |
| 77 | ) |
| 78 | |
| 79 | var AdditionalBW_name = map[AdditionalBW]string{ |
| 80 | 0: "AdditionalBW_None", |
| 81 | 1: "AdditionalBW_NA", |
| 82 | 2: "AdditionalBW_BestEffort", |
| 83 | 3: "AdditionalBW_Auto", |
| 84 | } |
| 85 | |
| 86 | type DiscardPolicy int32 |
| 87 | |
| 88 | const ( |
| 89 | DiscardPolicy_TailDrop DiscardPolicy = 0 |
| 90 | DiscardPolicy_WTailDrop DiscardPolicy = 1 |
| 91 | DiscardPolicy_Red DiscardPolicy = 2 |
| 92 | DiscardPolicy_WRed DiscardPolicy = 3 |
| 93 | ) |
| 94 | |
| 95 | var DiscardPolicy_name = map[DiscardPolicy]string{ |
| 96 | 0: "TailDrop", |
| 97 | 1: "WTailDrop", |
| 98 | 2: "Red", |
| 99 | 3: "WRed", |
| 100 | } |
| 101 | |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 102 | // Required uniPortName format |
| 103 | var uniPortNameFormat = regexp.MustCompile(`^pon-{[0-9]+}/onu-{[0-9]+}/uni-{[0-9]+}$`) |
| 104 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 105 | /* |
| 106 | type InferredAdditionBWIndication int32 |
| 107 | |
| 108 | const ( |
| 109 | InferredAdditionBWIndication_InferredAdditionBWIndication_None InferredAdditionBWIndication = 0 |
| 110 | InferredAdditionBWIndication_InferredAdditionBWIndication_Assured InferredAdditionBWIndication = 1 |
| 111 | InferredAdditionBWIndication_InferredAdditionBWIndication_BestEffort InferredAdditionBWIndication = 2 |
| 112 | ) |
| 113 | |
| 114 | var InferredAdditionBWIndication_name = map[int32]string{ |
| 115 | 0: "InferredAdditionBWIndication_None", |
| 116 | 1: "InferredAdditionBWIndication_Assured", |
| 117 | 2: "InferredAdditionBWIndication_BestEffort", |
| 118 | } |
| 119 | */ |
| 120 | // instance control defaults |
| 121 | const ( |
| 122 | defaultOnuInstance = "multi-instance" |
| 123 | defaultUniInstance = "single-instance" |
| 124 | defaultNumGemPorts = 1 |
| 125 | defaultGemPayloadSize = "auto" |
| 126 | ) |
| 127 | |
| 128 | const MAX_GEM_PAYLOAD = "max_gem_payload_size" |
| 129 | |
| 130 | type InstanceControl struct { |
| 131 | Onu string `json:"ONU"` |
| 132 | Uni string `json:"uni"` |
| 133 | MaxGemPayloadSize string `json:"max_gem_payload_size"` |
| 134 | } |
| 135 | |
| 136 | // default discard config constants |
| 137 | const ( |
| 138 | defaultMinThreshold = 0 |
| 139 | defaultMaxThreshold = 0 |
| 140 | defaultMaxProbability = 0 |
| 141 | ) |
| 142 | |
| 143 | type DiscardConfig struct { |
| 144 | MinThreshold int `json:"min_threshold"` |
| 145 | MaxThreshold int `json:"max_threshold"` |
| 146 | MaxProbability int `json:"max_probability"` |
| 147 | } |
| 148 | |
| 149 | // default scheduler contants |
| 150 | const ( |
| 151 | defaultAdditionalBw = AdditionalBW_AdditionalBW_BestEffort |
| 152 | defaultPriority = 0 |
| 153 | defaultWeight = 0 |
| 154 | defaultQueueSchedPolicy = SchedulingPolicy_Hybrid |
| 155 | ) |
| 156 | |
| 157 | type Scheduler struct { |
| 158 | Direction string `json:"direction"` |
| 159 | AdditionalBw string `json:"additional_bw"` |
| 160 | Priority uint32 `json:"priority"` |
| 161 | Weight uint32 `json:"weight"` |
| 162 | QSchedPolicy string `json:"q_sched_policy"` |
| 163 | } |
| 164 | |
| 165 | // default GEM attribute constants |
| 166 | const ( |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 167 | defaultAESEncryption = "True" |
| 168 | defaultPriorityQueue = 0 |
| 169 | defaultQueueWeight = 0 |
| 170 | defaultMaxQueueSize = "auto" |
| 171 | defaultdropPolicy = DiscardPolicy_TailDrop |
| 172 | defaultSchedulePolicy = SchedulingPolicy_WRR |
| 173 | defaultIsMulticast = "False" |
| 174 | defaultAccessControlList = "224.0.0.0-239.255.255.255" |
| 175 | defaultMcastGemID = 4069 |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 176 | ) |
| 177 | |
| 178 | type GemPortAttribute struct { |
| 179 | MaxQueueSize string `json:"max_q_size"` |
| 180 | PbitMap string `json:"pbit_map"` |
| 181 | AesEncryption string `json:"aes_encryption"` |
| 182 | SchedulingPolicy string `json:"scheduling_policy"` |
| 183 | PriorityQueue uint32 `json:"priority_q"` |
| 184 | Weight uint32 `json:"weight"` |
| 185 | DiscardPolicy string `json:"discard_policy"` |
| 186 | DiscardConfig DiscardConfig `json:"discard_config"` |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 187 | IsMulticast string `json:"is_multicast"` |
| 188 | DControlList string `json:"dynamic_access_control_list"` |
| 189 | SControlList string `json:"static_access_control_list"` |
| 190 | McastGemID uint32 `json:"multicast_gem_id"` |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | type iScheduler struct { |
| 194 | AllocID uint32 `json:"alloc_id"` |
| 195 | Direction string `json:"direction"` |
| 196 | AdditionalBw string `json:"additional_bw"` |
| 197 | Priority uint32 `json:"priority"` |
| 198 | Weight uint32 `json:"weight"` |
| 199 | QSchedPolicy string `json:"q_sched_policy"` |
| 200 | } |
| 201 | type iGemPortAttribute struct { |
| 202 | GemportID uint32 `json:"gemport_id"` |
| 203 | MaxQueueSize string `json:"max_q_size"` |
| 204 | PbitMap string `json:"pbit_map"` |
| 205 | AesEncryption string `json:"aes_encryption"` |
| 206 | SchedulingPolicy string `json:"scheduling_policy"` |
| 207 | PriorityQueue uint32 `json:"priority_q"` |
| 208 | Weight uint32 `json:"weight"` |
| 209 | DiscardPolicy string `json:"discard_policy"` |
| 210 | DiscardConfig DiscardConfig `json:"discard_config"` |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 211 | IsMulticast string `json:"is_multicast"` |
| 212 | DControlList string `json:"dynamic_access_control_list"` |
| 213 | SControlList string `json:"static_access_control_list"` |
| 214 | McastGemID uint32 `json:"multicast_gem_id"` |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | type TechProfileMgr struct { |
| 218 | config *TechProfileFlags |
| 219 | resourceMgr iPonResourceMgr |
| 220 | } |
| 221 | type DefaultTechProfile struct { |
| 222 | Name string `json:"name"` |
| 223 | ProfileType string `json:"profile_type"` |
| 224 | Version int `json:"version"` |
| 225 | NumGemPorts uint32 `json:"num_gem_ports"` |
| 226 | InstanceCtrl InstanceControl `json:"instance_control"` |
| 227 | UsScheduler Scheduler `json:"us_scheduler"` |
| 228 | DsScheduler Scheduler `json:"ds_scheduler"` |
| 229 | UpstreamGemPortAttributeList []GemPortAttribute `json:"upstream_gem_port_attribute_list"` |
| 230 | DownstreamGemPortAttributeList []GemPortAttribute `json:"downstream_gem_port_attribute_list"` |
| 231 | } |
| 232 | type TechProfile struct { |
| 233 | Name string `json:"name"` |
| 234 | SubscriberIdentifier string `json:"subscriber_identifier"` |
| 235 | ProfileType string `json:"profile_type"` |
| 236 | Version int `json:"version"` |
| 237 | NumGemPorts uint32 `json:"num_gem_ports"` |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 238 | InstanceCtrl InstanceControl `json:"instance_control"` |
| 239 | UsScheduler iScheduler `json:"us_scheduler"` |
| 240 | DsScheduler iScheduler `json:"ds_scheduler"` |
| 241 | UpstreamGemPortAttributeList []iGemPortAttribute `json:"upstream_gem_port_attribute_list"` |
| 242 | DownstreamGemPortAttributeList []iGemPortAttribute `json:"downstream_gem_port_attribute_list"` |
| 243 | } |
| 244 | |
sbarbari | 1e3e29c | 2019-11-05 10:06:50 -0500 | [diff] [blame] | 245 | func (t *TechProfileMgr) SetKVClient() *db.Backend { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 246 | addr := t.config.KVStoreHost + ":" + strconv.Itoa(t.config.KVStorePort) |
| 247 | kvClient, err := newKVClient(t.config.KVStoreType, addr, t.config.KVStoreTimeout) |
| 248 | if err != nil { |
| 249 | log.Errorw("failed-to-create-kv-client", |
| 250 | log.Fields{ |
| 251 | "type": t.config.KVStoreType, "host": t.config.KVStoreHost, "port": t.config.KVStorePort, |
| 252 | "timeout": t.config.KVStoreTimeout, "prefix": t.config.TPKVPathPrefix, |
| 253 | "error": err.Error(), |
| 254 | }) |
| 255 | return nil |
| 256 | } |
sbarbari | 1e3e29c | 2019-11-05 10:06:50 -0500 | [diff] [blame] | 257 | return &db.Backend{ |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 258 | Client: kvClient, |
| 259 | StoreType: t.config.KVStoreType, |
| 260 | Host: t.config.KVStoreHost, |
| 261 | Port: t.config.KVStorePort, |
| 262 | Timeout: t.config.KVStoreTimeout, |
| 263 | PathPrefix: t.config.TPKVPathPrefix} |
| 264 | |
| 265 | /* TODO : Make sure direct call to NewBackend is working fine with backend , currently there is some |
| 266 | issue between kv store and backend , core is not calling NewBackend directly |
| 267 | kv := model.NewBackend(t.config.KVStoreType, t.config.KVStoreHost, t.config.KVStorePort, |
| 268 | t.config.KVStoreTimeout, kvStoreTechProfilePathPrefix) |
| 269 | */ |
| 270 | } |
| 271 | |
| 272 | func newKVClient(storeType string, address string, timeout int) (kvstore.Client, error) { |
| 273 | |
| 274 | log.Infow("kv-store", log.Fields{"storeType": storeType, "address": address}) |
| 275 | switch storeType { |
| 276 | case "consul": |
| 277 | return kvstore.NewConsulClient(address, timeout) |
| 278 | case "etcd": |
| 279 | return kvstore.NewEtcdClient(address, timeout) |
| 280 | } |
| 281 | return nil, errors.New("unsupported-kv-store") |
| 282 | } |
| 283 | |
| 284 | func NewTechProfile(resourceMgr iPonResourceMgr, KVStoreType string, KVStoreHost string, KVStorePort int) (*TechProfileMgr, error) { |
| 285 | var techprofileObj TechProfileMgr |
| 286 | log.Debug("Initializing techprofile Manager") |
| 287 | techprofileObj.config = NewTechProfileFlags(KVStoreType, KVStoreHost, KVStorePort) |
| 288 | techprofileObj.config.KVBackend = techprofileObj.SetKVClient() |
| 289 | if techprofileObj.config.KVBackend == nil { |
| 290 | log.Error("Failed to initialize KV backend\n") |
| 291 | return nil, errors.New("KV backend init failed") |
| 292 | } |
| 293 | techprofileObj.resourceMgr = resourceMgr |
| 294 | log.Debug("Initializing techprofile object instance success") |
| 295 | return &techprofileObj, nil |
| 296 | } |
| 297 | |
| 298 | func (t *TechProfileMgr) GetTechProfileInstanceKVPath(techProfiletblID uint32, uniPortName string) string { |
| 299 | return fmt.Sprintf(t.config.TPInstanceKVPath, t.resourceMgr.GetTechnology(), techProfiletblID, uniPortName) |
| 300 | } |
| 301 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 302 | func (t *TechProfileMgr) GetTPInstanceFromKVStore(ctx context.Context, techProfiletblID uint32, path string) (*TechProfile, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 303 | var KvTpIns TechProfile |
| 304 | var resPtr *TechProfile = &KvTpIns |
| 305 | var err error |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 306 | var kvResult *kvstore.KVPair |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 307 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 308 | kvResult, _ = t.config.KVBackend.Get(ctx, path) |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 309 | if kvResult == nil { |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 310 | log.Infow("tp-instance-not-found-on-kv", log.Fields{"key": path}) |
| 311 | return nil, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 312 | } else { |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 313 | if value, err := kvstore.ToByte(kvResult.Value); err == nil { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 314 | if err = json.Unmarshal(value, resPtr); err != nil { |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 315 | log.Errorw("error-unmarshal-kv-result", log.Fields{"key": path, "value": value}) |
| 316 | return nil, errors.New("error-unmarshal-kv-result") |
| 317 | } else { |
| 318 | return resPtr, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | } |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 322 | return nil, err |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 323 | } |
| 324 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 325 | func (t *TechProfileMgr) addTechProfInstanceToKVStore(ctx context.Context, techProfiletblID uint32, uniPortName string, tpInstance *TechProfile) error { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 326 | path := t.GetTechProfileInstanceKVPath(techProfiletblID, uniPortName) |
| 327 | log.Debugw("Adding techprof instance to kvstore", log.Fields{"key": path, "tpinstance": tpInstance}) |
| 328 | tpInstanceJson, err := json.Marshal(*tpInstance) |
| 329 | if err == nil { |
| 330 | // Backend will convert JSON byte array into string format |
| 331 | log.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] | 332 | err = t.config.KVBackend.Put(ctx, path, tpInstanceJson) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 333 | } else { |
| 334 | log.Errorw("Error in marshaling into Json format", log.Fields{"key": path, "tpinstance": tpInstance}) |
| 335 | } |
| 336 | return err |
| 337 | } |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 338 | func (t *TechProfileMgr) getTPFromKVStore(ctx context.Context, techProfiletblID uint32) *DefaultTechProfile { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 339 | var kvtechprofile DefaultTechProfile |
| 340 | key := fmt.Sprintf(t.config.TPFileKVPath, t.resourceMgr.GetTechnology(), techProfiletblID) |
| 341 | log.Debugw("Getting techprofile from KV store", log.Fields{"techProfiletblID": techProfiletblID, "Key": key}) |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 342 | kvresult, err := t.config.KVBackend.Get(ctx, key) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 343 | if err != nil { |
| 344 | log.Errorw("Error while fetching value from KV store", log.Fields{"key": key}) |
| 345 | return nil |
| 346 | } |
| 347 | if kvresult != nil { |
| 348 | /* Backend will return Value in string format,needs to be converted to []byte before unmarshal*/ |
| 349 | if value, err := kvstore.ToByte(kvresult.Value); err == nil { |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 350 | if err = json.Unmarshal(value, &kvtechprofile); err != nil { |
| 351 | log.Errorw("Error unmarshaling techprofile fetched from KV store", log.Fields{"techProfiletblID": techProfiletblID, "error": err, "techprofile_json": value}) |
| 352 | return nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 353 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 354 | |
| 355 | log.Debugw("Success fetched techprofile from KV store", log.Fields{"techProfiletblID": techProfiletblID, "value": kvtechprofile}) |
| 356 | return &kvtechprofile |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 357 | } |
| 358 | } |
| 359 | return nil |
| 360 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 361 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 362 | func (t *TechProfileMgr) CreateTechProfInstance(ctx context.Context, techProfiletblID uint32, uniPortName string, intfId uint32) (*TechProfile, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 363 | var tpInstance *TechProfile |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 364 | log.Infow("creating-tp-instance", log.Fields{"tableid": techProfiletblID, "uni": uniPortName, "intId": intfId}) |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 365 | |
| 366 | // Make sure the uniPortName is as per format pon-{[0-9]+}/onu-{[0-9]+}/uni-{[0-9]+} |
| 367 | if !uniPortNameFormat.Match([]byte(uniPortName)) { |
| 368 | log.Errorw("uni-port-name-not-confirming-to-format", log.Fields{"uniPortName": uniPortName}) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 369 | return nil, errors.New("uni-port-name-not-confirming-to-format") |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 370 | } |
| 371 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 372 | tp := t.getTPFromKVStore(ctx, techProfiletblID) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 373 | if tp != nil { |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 374 | if err := t.validateInstanceControlAttr(tp.InstanceCtrl); err != nil { |
| 375 | log.Error("invalid-instance-ctrl-attr--using-default-tp") |
| 376 | tp = t.getDefaultTechProfile() |
| 377 | } else { |
| 378 | log.Infow("using-specified-tp-from-kv-store", log.Fields{"tpid": techProfiletblID}) |
| 379 | } |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 380 | } else { |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 381 | log.Info("tp-not-found-on-kv--creating-default-tp") |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 382 | tp = t.getDefaultTechProfile() |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 383 | } |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 384 | tpInstancePath := t.GetTechProfileInstanceKVPath(techProfiletblID, uniPortName) |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 385 | if tpInstance = t.allocateTPInstance(ctx, uniPortName, tp, intfId, tpInstancePath); tpInstance == nil { |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 386 | log.Error("tp-intance-allocation-failed") |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 387 | return nil, errors.New("tp-intance-allocation-failed") |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 388 | } |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 389 | if err := t.addTechProfInstanceToKVStore(ctx, techProfiletblID, uniPortName, tpInstance); err != nil { |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 390 | log.Errorw("error-adding-tp-to-kv-store", log.Fields{"tableid": techProfiletblID, "uni": uniPortName}) |
| 391 | return nil, errors.New("error-adding-tp-to-kv-store") |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 392 | } |
| 393 | log.Infow("tp-added-to-kv-store-successfully", |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 394 | log.Fields{"tpid": techProfiletblID, "uni": uniPortName, "intfId": intfId}) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 395 | return tpInstance, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 396 | } |
| 397 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 398 | func (t *TechProfileMgr) DeleteTechProfileInstance(ctx context.Context, techProfiletblID uint32, uniPortName string) error { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 399 | path := t.GetTechProfileInstanceKVPath(techProfiletblID, uniPortName) |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 400 | return t.config.KVBackend.Delete(ctx, path) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 403 | func (t *TechProfileMgr) validateInstanceControlAttr(instCtl InstanceControl) error { |
| 404 | if instCtl.Onu != "single-instance" && instCtl.Onu != "multi-instance" { |
| 405 | log.Errorw("invalid-onu-instance-control-attribute", log.Fields{"onu-inst": instCtl.Onu}) |
| 406 | return errors.New("invalid-onu-instance-ctl-attr") |
| 407 | } |
| 408 | |
| 409 | if instCtl.Uni != "single-instance" && instCtl.Uni != "multi-instance" { |
| 410 | log.Errorw("invalid-uni-instance-control-attribute", log.Fields{"uni-inst": instCtl.Uni}) |
| 411 | return errors.New("invalid-uni-instance-ctl-attr") |
| 412 | } |
| 413 | |
| 414 | if instCtl.Uni == "multi-instance" { |
| 415 | log.Error("uni-multi-instance-tp-not-supported") |
| 416 | return errors.New("uni-multi-instance-tp-not-supported") |
| 417 | } |
| 418 | |
| 419 | return nil |
| 420 | } |
| 421 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 422 | 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] | 423 | |
| 424 | var usGemPortAttributeList []iGemPortAttribute |
| 425 | var dsGemPortAttributeList []iGemPortAttribute |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 426 | var dsMulticastGemAttributeList []iGemPortAttribute |
| 427 | var dsUnicastGemAttributeList []iGemPortAttribute |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 428 | var tcontIDs []uint32 |
| 429 | var gemPorts []uint32 |
| 430 | var err error |
| 431 | |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 432 | log.Infow("Allocating TechProfileMgr instance from techprofile template", log.Fields{"uniPortName": uniPortName, "intfId": intfId, "numGem": tp.NumGemPorts}) |
| 433 | |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 434 | if tp.InstanceCtrl.Onu == "multi-instance" { |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 435 | if tcontIDs, err = t.resourceMgr.GetResourceID(ctx, intfId, t.resourceMgr.GetResourceTypeAllocID(), 1); err != nil { |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 436 | log.Errorw("Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId}) |
| 437 | return nil |
| 438 | } |
| 439 | } else { // "single-instance" |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 440 | tpInst, err := t.getSingleInstanceTp(ctx, tpInstPath) |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 441 | if tpInst == nil { |
| 442 | // No "single-instance" tp found on one any uni port for the given TP ID |
| 443 | // Allocate a new TcontID or AllocID |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 444 | if tcontIDs, err = t.resourceMgr.GetResourceID(ctx, intfId, t.resourceMgr.GetResourceTypeAllocID(), 1); err != nil { |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 445 | log.Errorw("Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId}) |
| 446 | return nil |
| 447 | } |
| 448 | } else { |
| 449 | // Use the alloc-id from the existing TpInstance |
| 450 | tcontIDs = append(tcontIDs, tpInst.UsScheduler.AllocID) |
| 451 | } |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 452 | } |
| 453 | log.Debugw("Num GEM ports in TP:", log.Fields{"NumGemPorts": tp.NumGemPorts}) |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 454 | if gemPorts, err = t.resourceMgr.GetResourceID(ctx, intfId, t.resourceMgr.GetResourceTypeGemPortID(), tp.NumGemPorts); err != nil { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 455 | log.Errorw("Error getting gemport ids from rsrcrMgr", log.Fields{"intfId": intfId, "numGemports": tp.NumGemPorts}) |
| 456 | return nil |
| 457 | } |
| 458 | log.Infow("Allocated tconts and GEM ports successfully", log.Fields{"tconts": tcontIDs, "gemports": gemPorts}) |
| 459 | for index := 0; index < int(tp.NumGemPorts); index++ { |
| 460 | usGemPortAttributeList = append(usGemPortAttributeList, |
| 461 | iGemPortAttribute{GemportID: gemPorts[index], |
| 462 | MaxQueueSize: tp.UpstreamGemPortAttributeList[index].MaxQueueSize, |
| 463 | PbitMap: tp.UpstreamGemPortAttributeList[index].PbitMap, |
| 464 | AesEncryption: tp.UpstreamGemPortAttributeList[index].AesEncryption, |
| 465 | SchedulingPolicy: tp.UpstreamGemPortAttributeList[index].SchedulingPolicy, |
| 466 | PriorityQueue: tp.UpstreamGemPortAttributeList[index].PriorityQueue, |
| 467 | Weight: tp.UpstreamGemPortAttributeList[index].Weight, |
| 468 | DiscardPolicy: tp.UpstreamGemPortAttributeList[index].DiscardPolicy, |
| 469 | DiscardConfig: tp.UpstreamGemPortAttributeList[index].DiscardConfig}) |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | log.Info("length of DownstreamGemPortAttributeList", len(tp.DownstreamGemPortAttributeList)) |
| 473 | //put multicast and unicast downstream GEM port attributes in different lists first |
| 474 | for index := 0; index < int(len(tp.DownstreamGemPortAttributeList)); index++ { |
| 475 | if isMulticastGem(tp.DownstreamGemPortAttributeList[index].IsMulticast) { |
| 476 | dsMulticastGemAttributeList = append(dsMulticastGemAttributeList, |
| 477 | iGemPortAttribute{ |
| 478 | McastGemID: tp.DownstreamGemPortAttributeList[index].McastGemID, |
| 479 | MaxQueueSize: tp.DownstreamGemPortAttributeList[index].MaxQueueSize, |
| 480 | PbitMap: tp.DownstreamGemPortAttributeList[index].PbitMap, |
| 481 | AesEncryption: tp.DownstreamGemPortAttributeList[index].AesEncryption, |
| 482 | SchedulingPolicy: tp.DownstreamGemPortAttributeList[index].SchedulingPolicy, |
| 483 | PriorityQueue: tp.DownstreamGemPortAttributeList[index].PriorityQueue, |
| 484 | Weight: tp.DownstreamGemPortAttributeList[index].Weight, |
| 485 | DiscardPolicy: tp.DownstreamGemPortAttributeList[index].DiscardPolicy, |
| 486 | DiscardConfig: tp.DownstreamGemPortAttributeList[index].DiscardConfig, |
| 487 | IsMulticast: tp.DownstreamGemPortAttributeList[index].IsMulticast, |
| 488 | DControlList: tp.DownstreamGemPortAttributeList[index].DControlList, |
| 489 | SControlList: tp.DownstreamGemPortAttributeList[index].SControlList}) |
| 490 | } else { |
| 491 | dsUnicastGemAttributeList = append(dsUnicastGemAttributeList, |
| 492 | iGemPortAttribute{ |
| 493 | MaxQueueSize: tp.DownstreamGemPortAttributeList[index].MaxQueueSize, |
| 494 | PbitMap: tp.DownstreamGemPortAttributeList[index].PbitMap, |
| 495 | AesEncryption: tp.DownstreamGemPortAttributeList[index].AesEncryption, |
| 496 | SchedulingPolicy: tp.DownstreamGemPortAttributeList[index].SchedulingPolicy, |
| 497 | PriorityQueue: tp.DownstreamGemPortAttributeList[index].PriorityQueue, |
| 498 | Weight: tp.DownstreamGemPortAttributeList[index].Weight, |
| 499 | DiscardPolicy: tp.DownstreamGemPortAttributeList[index].DiscardPolicy, |
| 500 | DiscardConfig: tp.DownstreamGemPortAttributeList[index].DiscardConfig}) |
| 501 | } |
| 502 | } |
| 503 | //add unicast downstream GEM ports to dsGemPortAttributeList |
| 504 | for index := 0; index < int(tp.NumGemPorts); index++ { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 505 | dsGemPortAttributeList = append(dsGemPortAttributeList, |
| 506 | iGemPortAttribute{GemportID: gemPorts[index], |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 507 | MaxQueueSize: dsUnicastGemAttributeList[index].MaxQueueSize, |
| 508 | PbitMap: dsUnicastGemAttributeList[index].PbitMap, |
| 509 | AesEncryption: dsUnicastGemAttributeList[index].AesEncryption, |
| 510 | SchedulingPolicy: dsUnicastGemAttributeList[index].SchedulingPolicy, |
| 511 | PriorityQueue: dsUnicastGemAttributeList[index].PriorityQueue, |
| 512 | Weight: dsUnicastGemAttributeList[index].Weight, |
| 513 | DiscardPolicy: dsUnicastGemAttributeList[index].DiscardPolicy, |
| 514 | DiscardConfig: dsUnicastGemAttributeList[index].DiscardConfig}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 515 | } |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 516 | //add multicast GEM ports to dsGemPortAttributeList afterwards |
| 517 | for k := range dsMulticastGemAttributeList { |
| 518 | dsGemPortAttributeList = append(dsGemPortAttributeList, dsMulticastGemAttributeList[k]) |
| 519 | } |
| 520 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 521 | return &TechProfile{ |
| 522 | SubscriberIdentifier: uniPortName, |
| 523 | Name: tp.Name, |
| 524 | ProfileType: tp.ProfileType, |
| 525 | Version: tp.Version, |
| 526 | NumGemPorts: tp.NumGemPorts, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 527 | InstanceCtrl: tp.InstanceCtrl, |
| 528 | UsScheduler: iScheduler{ |
| 529 | AllocID: tcontIDs[0], |
| 530 | Direction: tp.UsScheduler.Direction, |
| 531 | AdditionalBw: tp.UsScheduler.AdditionalBw, |
| 532 | Priority: tp.UsScheduler.Priority, |
| 533 | Weight: tp.UsScheduler.Weight, |
| 534 | QSchedPolicy: tp.UsScheduler.QSchedPolicy}, |
| 535 | DsScheduler: iScheduler{ |
| 536 | AllocID: tcontIDs[0], |
| 537 | Direction: tp.DsScheduler.Direction, |
| 538 | AdditionalBw: tp.DsScheduler.AdditionalBw, |
| 539 | Priority: tp.DsScheduler.Priority, |
| 540 | Weight: tp.DsScheduler.Weight, |
| 541 | QSchedPolicy: tp.DsScheduler.QSchedPolicy}, |
| 542 | UpstreamGemPortAttributeList: usGemPortAttributeList, |
| 543 | DownstreamGemPortAttributeList: dsGemPortAttributeList} |
| 544 | } |
| 545 | |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 546 | // getSingleInstanceTp returns another TpInstance for an ONU on a different |
| 547 | // uni port for the same TP ID, if it finds one, else nil. |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 548 | func (t *TechProfileMgr) getSingleInstanceTp(ctx context.Context, tpPath string) (*TechProfile, error) { |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 549 | var tpInst TechProfile |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 550 | |
| 551 | // For example: |
| 552 | // tpPath like "service/voltha/technology_profiles/xgspon/64/pon-{0}/onu-{1}/uni-{1}" |
| 553 | // is broken into ["service/voltha/technology_profiles/xgspon/64/pon-{0}/onu-{1}" ""] |
| 554 | uniPathSlice := regexp.MustCompile(`/uni-{[0-9]+}$`).Split(tpPath, 2) |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 555 | kvPairs, _ := t.config.KVBackend.List(ctx, uniPathSlice[0]) |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 556 | |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 557 | // Find a valid TP Instance among all the UNIs of that ONU for the given TP ID |
| 558 | for keyPath, kvPair := range kvPairs { |
| 559 | if value, err := kvstore.ToByte(kvPair.Value); err == nil { |
| 560 | if err = json.Unmarshal(value, &tpInst); err != nil { |
| 561 | log.Errorw("error-unmarshal-kv-pair", log.Fields{"keyPath": keyPath, "value": value}) |
| 562 | return nil, errors.New("error-unmarshal-kv-pair") |
| 563 | } else { |
| 564 | log.Debugw("found-valid-tp-instance-on-another-uni", log.Fields{"keyPath": keyPath}) |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 565 | return &tpInst, nil |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 566 | } |
| 567 | } |
| 568 | } |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 569 | return nil, nil |
| 570 | } |
| 571 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 572 | func (t *TechProfileMgr) getDefaultTechProfile() *DefaultTechProfile { |
| 573 | |
| 574 | var usGemPortAttributeList []GemPortAttribute |
| 575 | var dsGemPortAttributeList []GemPortAttribute |
| 576 | |
| 577 | for _, pbit := range t.config.DefaultPbits { |
| 578 | log.Debugw("Creating GEM port", log.Fields{"pbit": pbit}) |
| 579 | usGemPortAttributeList = append(usGemPortAttributeList, |
| 580 | GemPortAttribute{ |
| 581 | MaxQueueSize: defaultMaxQueueSize, |
| 582 | PbitMap: pbit, |
| 583 | AesEncryption: defaultAESEncryption, |
| 584 | SchedulingPolicy: SchedulingPolicy_name[defaultSchedulePolicy], |
| 585 | PriorityQueue: defaultPriorityQueue, |
| 586 | Weight: defaultQueueWeight, |
| 587 | DiscardPolicy: DiscardPolicy_name[defaultdropPolicy], |
| 588 | DiscardConfig: DiscardConfig{ |
| 589 | MinThreshold: defaultMinThreshold, |
| 590 | MaxThreshold: defaultMaxThreshold, |
| 591 | MaxProbability: defaultMaxProbability}}) |
| 592 | dsGemPortAttributeList = append(dsGemPortAttributeList, |
| 593 | GemPortAttribute{ |
| 594 | MaxQueueSize: defaultMaxQueueSize, |
| 595 | PbitMap: pbit, |
| 596 | AesEncryption: defaultAESEncryption, |
| 597 | SchedulingPolicy: SchedulingPolicy_name[defaultSchedulePolicy], |
| 598 | PriorityQueue: defaultPriorityQueue, |
| 599 | Weight: defaultQueueWeight, |
| 600 | DiscardPolicy: DiscardPolicy_name[defaultdropPolicy], |
| 601 | DiscardConfig: DiscardConfig{ |
| 602 | MinThreshold: defaultMinThreshold, |
| 603 | MaxThreshold: defaultMaxThreshold, |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 604 | MaxProbability: defaultMaxProbability}, |
| 605 | IsMulticast: defaultIsMulticast, |
| 606 | DControlList: defaultAccessControlList, |
| 607 | SControlList: defaultAccessControlList, |
| 608 | McastGemID: defaultMcastGemID}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 609 | } |
| 610 | return &DefaultTechProfile{ |
| 611 | Name: t.config.DefaultTPName, |
| 612 | ProfileType: t.resourceMgr.GetTechnology(), |
| 613 | Version: t.config.TPVersion, |
| 614 | NumGemPorts: uint32(len(usGemPortAttributeList)), |
| 615 | InstanceCtrl: InstanceControl{ |
| 616 | Onu: defaultOnuInstance, |
| 617 | Uni: defaultUniInstance, |
| 618 | MaxGemPayloadSize: defaultGemPayloadSize}, |
| 619 | UsScheduler: Scheduler{ |
| 620 | Direction: Direction_name[Direction_UPSTREAM], |
| 621 | AdditionalBw: AdditionalBW_name[defaultAdditionalBw], |
| 622 | Priority: defaultPriority, |
| 623 | Weight: defaultWeight, |
| 624 | QSchedPolicy: SchedulingPolicy_name[defaultQueueSchedPolicy]}, |
| 625 | DsScheduler: Scheduler{ |
| 626 | Direction: Direction_name[Direction_DOWNSTREAM], |
| 627 | AdditionalBw: AdditionalBW_name[defaultAdditionalBw], |
| 628 | Priority: defaultPriority, |
| 629 | Weight: defaultWeight, |
| 630 | QSchedPolicy: SchedulingPolicy_name[defaultQueueSchedPolicy]}, |
| 631 | UpstreamGemPortAttributeList: usGemPortAttributeList, |
| 632 | DownstreamGemPortAttributeList: dsGemPortAttributeList} |
| 633 | } |
| 634 | |
| 635 | func (t *TechProfileMgr) GetprotoBufParamValue(paramType string, paramKey string) int32 { |
| 636 | var result int32 = -1 |
| 637 | |
| 638 | if paramType == "direction" { |
| 639 | for key, val := range tp_pb.Direction_value { |
| 640 | if key == paramKey { |
| 641 | result = val |
| 642 | } |
| 643 | } |
| 644 | } else if paramType == "discard_policy" { |
| 645 | for key, val := range tp_pb.DiscardPolicy_value { |
| 646 | if key == paramKey { |
| 647 | result = val |
| 648 | } |
| 649 | } |
| 650 | } else if paramType == "sched_policy" { |
| 651 | for key, val := range tp_pb.SchedulingPolicy_value { |
| 652 | if key == paramKey { |
| 653 | log.Debugw("Got value in proto", log.Fields{"key": key, "value": val}) |
| 654 | result = val |
| 655 | } |
| 656 | } |
| 657 | } else if paramType == "additional_bw" { |
| 658 | for key, val := range tp_pb.AdditionalBW_value { |
| 659 | if key == paramKey { |
| 660 | result = val |
| 661 | } |
| 662 | } |
| 663 | } else { |
| 664 | log.Error("Could not find proto parameter", log.Fields{"paramType": paramType, "key": paramKey}) |
| 665 | return -1 |
| 666 | } |
| 667 | log.Debugw("Got value in proto", log.Fields{"key": paramKey, "value": result}) |
| 668 | return result |
| 669 | } |
| 670 | |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 671 | func (t *TechProfileMgr) GetUsScheduler(tpInstance *TechProfile) (*tp_pb.SchedulerConfig, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 672 | dir := tp_pb.Direction(t.GetprotoBufParamValue("direction", tpInstance.UsScheduler.Direction)) |
| 673 | if dir == -1 { |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 674 | log.Errorf("Error in getting proto id for direction %s for upstream scheduler", tpInstance.UsScheduler.Direction) |
| 675 | 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] | 676 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 677 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 678 | bw := tp_pb.AdditionalBW(t.GetprotoBufParamValue("additional_bw", tpInstance.UsScheduler.AdditionalBw)) |
| 679 | if bw == -1 { |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 680 | log.Errorf("Error in getting proto id for bandwidth %s for upstream scheduler", tpInstance.UsScheduler.AdditionalBw) |
| 681 | 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] | 682 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 683 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 684 | policy := tp_pb.SchedulingPolicy(t.GetprotoBufParamValue("sched_policy", tpInstance.UsScheduler.QSchedPolicy)) |
| 685 | if policy == -1 { |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 686 | log.Errorf("Error in getting proto id for scheduling policy %s for upstream scheduler", tpInstance.UsScheduler.QSchedPolicy) |
| 687 | 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] | 688 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 689 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 690 | return &tp_pb.SchedulerConfig{ |
| 691 | Direction: dir, |
| 692 | AdditionalBw: bw, |
| 693 | Priority: tpInstance.UsScheduler.Priority, |
| 694 | Weight: tpInstance.UsScheduler.Weight, |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 695 | SchedPolicy: policy}, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 696 | } |
| 697 | |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 698 | func (t *TechProfileMgr) GetDsScheduler(tpInstance *TechProfile) (*tp_pb.SchedulerConfig, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 699 | |
| 700 | dir := tp_pb.Direction(t.GetprotoBufParamValue("direction", tpInstance.DsScheduler.Direction)) |
| 701 | if dir == -1 { |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 702 | log.Errorf("Error in getting proto id for direction %s for downstream scheduler", tpInstance.DsScheduler.Direction) |
| 703 | 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] | 704 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 705 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 706 | bw := tp_pb.AdditionalBW(t.GetprotoBufParamValue("additional_bw", tpInstance.DsScheduler.AdditionalBw)) |
| 707 | if bw == -1 { |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 708 | log.Errorf("Error in getting proto id for bandwidth %s for downstream scheduler", tpInstance.DsScheduler.AdditionalBw) |
| 709 | 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] | 710 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 711 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 712 | policy := tp_pb.SchedulingPolicy(t.GetprotoBufParamValue("sched_policy", tpInstance.DsScheduler.QSchedPolicy)) |
| 713 | if policy == -1 { |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 714 | log.Errorf("Error in getting proto id for scheduling policy %s for downstream scheduler", tpInstance.DsScheduler.QSchedPolicy) |
| 715 | 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] | 716 | } |
| 717 | |
| 718 | return &tp_pb.SchedulerConfig{ |
| 719 | Direction: dir, |
| 720 | AdditionalBw: bw, |
| 721 | Priority: tpInstance.DsScheduler.Priority, |
| 722 | Weight: tpInstance.DsScheduler.Weight, |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 723 | SchedPolicy: policy}, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | func (t *TechProfileMgr) GetTrafficScheduler(tpInstance *TechProfile, SchedCfg *tp_pb.SchedulerConfig, |
| 727 | ShapingCfg *tp_pb.TrafficShapingInfo) *tp_pb.TrafficScheduler { |
| 728 | |
| 729 | tSched := &tp_pb.TrafficScheduler{ |
| 730 | Direction: SchedCfg.Direction, |
| 731 | AllocId: tpInstance.UsScheduler.AllocID, |
| 732 | TrafficShapingInfo: ShapingCfg, |
| 733 | Scheduler: SchedCfg} |
| 734 | |
| 735 | return tSched |
| 736 | } |
| 737 | |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 738 | 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] | 739 | |
| 740 | var encryp bool |
| 741 | if Dir == tp_pb.Direction_UPSTREAM { |
| 742 | // upstream GEM ports |
| 743 | NumGemPorts := len(tp.UpstreamGemPortAttributeList) |
| 744 | GemPorts := make([]*tp_pb.TrafficQueue, 0) |
| 745 | for Count := 0; Count < NumGemPorts; Count++ { |
| 746 | if tp.UpstreamGemPortAttributeList[Count].AesEncryption == "True" { |
| 747 | encryp = true |
| 748 | } else { |
| 749 | encryp = false |
| 750 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 751 | |
| 752 | schedPolicy := tpm.GetprotoBufParamValue("sched_policy", tp.UpstreamGemPortAttributeList[Count].SchedulingPolicy) |
| 753 | if schedPolicy == -1 { |
| 754 | log.Errorf("Error in getting Proto Id for scheduling policy %s for Upstream Gem Port %d", tp.UpstreamGemPortAttributeList[Count].SchedulingPolicy, Count) |
| 755 | return nil, fmt.Errorf("upstream gem port traffic queue creation failed due to unrecognized scheduling policy %s", tp.UpstreamGemPortAttributeList[Count].SchedulingPolicy) |
| 756 | } |
| 757 | |
| 758 | discardPolicy := tpm.GetprotoBufParamValue("discard_policy", tp.UpstreamGemPortAttributeList[Count].DiscardPolicy) |
| 759 | if discardPolicy == -1 { |
| 760 | log.Errorf("Error in getting Proto Id for discard policy %s for Upstream Gem Port %d", tp.UpstreamGemPortAttributeList[Count].DiscardPolicy, Count) |
| 761 | return nil, fmt.Errorf("upstream gem port traffic queue creation failed due to unrecognized discard policy %s", tp.UpstreamGemPortAttributeList[Count].DiscardPolicy) |
| 762 | } |
| 763 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 764 | GemPorts = append(GemPorts, &tp_pb.TrafficQueue{ |
| 765 | Direction: tp_pb.Direction(tpm.GetprotoBufParamValue("direction", tp.UsScheduler.Direction)), |
| 766 | GemportId: tp.UpstreamGemPortAttributeList[Count].GemportID, |
| 767 | PbitMap: tp.UpstreamGemPortAttributeList[Count].PbitMap, |
| 768 | AesEncryption: encryp, |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 769 | SchedPolicy: tp_pb.SchedulingPolicy(schedPolicy), |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 770 | Priority: tp.UpstreamGemPortAttributeList[Count].PriorityQueue, |
| 771 | Weight: tp.UpstreamGemPortAttributeList[Count].Weight, |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 772 | DiscardPolicy: tp_pb.DiscardPolicy(discardPolicy), |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 773 | }) |
| 774 | } |
| 775 | log.Debugw("Upstream Traffic queue list ", log.Fields{"queuelist": GemPorts}) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 776 | return GemPorts, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 777 | } else if Dir == tp_pb.Direction_DOWNSTREAM { |
| 778 | //downstream GEM ports |
| 779 | NumGemPorts := len(tp.DownstreamGemPortAttributeList) |
| 780 | GemPorts := make([]*tp_pb.TrafficQueue, 0) |
| 781 | for Count := 0; Count < NumGemPorts; Count++ { |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 782 | if isMulticastGem(tp.DownstreamGemPortAttributeList[Count].IsMulticast) { |
| 783 | //do not take multicast GEM ports. They are handled separately. |
| 784 | continue |
| 785 | } |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 786 | if tp.DownstreamGemPortAttributeList[Count].AesEncryption == "True" { |
| 787 | encryp = true |
| 788 | } else { |
| 789 | encryp = false |
| 790 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 791 | |
| 792 | schedPolicy := tpm.GetprotoBufParamValue("sched_policy", tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy) |
| 793 | if schedPolicy == -1 { |
| 794 | log.Errorf("Error in getting Proto Id for scheduling policy %s for Downstream Gem Port %d", tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy, Count) |
| 795 | return nil, fmt.Errorf("downstream gem port traffic queue creation failed due to unrecognized scheduling policy %s", tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy) |
| 796 | } |
| 797 | |
| 798 | discardPolicy := tpm.GetprotoBufParamValue("discard_policy", tp.DownstreamGemPortAttributeList[Count].DiscardPolicy) |
| 799 | if discardPolicy == -1 { |
| 800 | log.Errorf("Error in getting Proto Id for discard policy %s for Downstream Gem Port %d", tp.DownstreamGemPortAttributeList[Count].DiscardPolicy, Count) |
| 801 | return nil, fmt.Errorf("downstream gem port traffic queue creation failed due to unrecognized discard policy %s", tp.DownstreamGemPortAttributeList[Count].DiscardPolicy) |
| 802 | } |
| 803 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 804 | GemPorts = append(GemPorts, &tp_pb.TrafficQueue{ |
| 805 | Direction: tp_pb.Direction(tpm.GetprotoBufParamValue("direction", tp.DsScheduler.Direction)), |
| 806 | GemportId: tp.DownstreamGemPortAttributeList[Count].GemportID, |
| 807 | PbitMap: tp.DownstreamGemPortAttributeList[Count].PbitMap, |
| 808 | AesEncryption: encryp, |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 809 | SchedPolicy: tp_pb.SchedulingPolicy(schedPolicy), |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 810 | Priority: tp.DownstreamGemPortAttributeList[Count].PriorityQueue, |
| 811 | Weight: tp.DownstreamGemPortAttributeList[Count].Weight, |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 812 | DiscardPolicy: tp_pb.DiscardPolicy(discardPolicy), |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 813 | }) |
| 814 | } |
| 815 | log.Debugw("Downstream Traffic queue list ", log.Fields{"queuelist": GemPorts}) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 816 | return GemPorts, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 817 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 818 | |
| 819 | log.Errorf("Unsupported direction %s used for generating Traffic Queue list", Dir) |
| 820 | 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] | 821 | } |
| 822 | |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 823 | //isMulticastGem returns true if isMulticast attribute value of a GEM port is true; false otherwise |
| 824 | func isMulticastGem(isMulticastAttrValue string) bool { |
| 825 | return isMulticastAttrValue != "" && |
| 826 | (isMulticastAttrValue == "True" || isMulticastAttrValue == "true" || isMulticastAttrValue == "TRUE") |
| 827 | } |
| 828 | |
| 829 | func (tpm *TechProfileMgr) GetMulticastTrafficQueues(tp *TechProfile) []*tp_pb.TrafficQueue { |
| 830 | var encryp bool |
| 831 | NumGemPorts := len(tp.DownstreamGemPortAttributeList) |
| 832 | mcastTrafficQueues := make([]*tp_pb.TrafficQueue, 0) |
| 833 | for Count := 0; Count < NumGemPorts; Count++ { |
| 834 | if !isMulticastGem(tp.DownstreamGemPortAttributeList[Count].IsMulticast) { |
| 835 | continue |
| 836 | } |
| 837 | if tp.DownstreamGemPortAttributeList[Count].AesEncryption == "True" { |
| 838 | encryp = true |
| 839 | } else { |
| 840 | encryp = false |
| 841 | } |
| 842 | mcastTrafficQueues = append(mcastTrafficQueues, &tp_pb.TrafficQueue{ |
| 843 | Direction: tp_pb.Direction(tpm.GetprotoBufParamValue("direction", tp.DsScheduler.Direction)), |
| 844 | GemportId: tp.DownstreamGemPortAttributeList[Count].McastGemID, |
| 845 | PbitMap: tp.DownstreamGemPortAttributeList[Count].PbitMap, |
| 846 | AesEncryption: encryp, |
| 847 | SchedPolicy: tp_pb.SchedulingPolicy(tpm.GetprotoBufParamValue("sched_policy", tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy)), |
| 848 | Priority: tp.DownstreamGemPortAttributeList[Count].PriorityQueue, |
| 849 | Weight: tp.DownstreamGemPortAttributeList[Count].Weight, |
| 850 | DiscardPolicy: tp_pb.DiscardPolicy(tpm.GetprotoBufParamValue("discard_policy", tp.DownstreamGemPortAttributeList[Count].DiscardPolicy)), |
| 851 | }) |
| 852 | } |
| 853 | log.Debugw("Downstream Multicast Traffic queue list ", log.Fields{"queuelist": mcastTrafficQueues}) |
| 854 | return mcastTrafficQueues |
| 855 | } |
| 856 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 857 | func (tpm *TechProfileMgr) GetUsTrafficScheduler(tp *TechProfile) *tp_pb.TrafficScheduler { |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 858 | UsScheduler, _ := tpm.GetUsScheduler(tp) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 859 | |
| 860 | return &tp_pb.TrafficScheduler{Direction: UsScheduler.Direction, |
| 861 | AllocId: tp.UsScheduler.AllocID, |
| 862 | Scheduler: UsScheduler} |
| 863 | } |
| 864 | |
| 865 | func (t *TechProfileMgr) GetGemportIDForPbit(tp *TechProfile, Dir tp_pb.Direction, pbit uint32) uint32 { |
| 866 | /* |
| 867 | Function to get the Gemport ID mapped to a pbit. |
| 868 | */ |
| 869 | if Dir == tp_pb.Direction_UPSTREAM { |
| 870 | // upstream GEM ports |
| 871 | NumGemPorts := len(tp.UpstreamGemPortAttributeList) |
| 872 | for Count := 0; Count < NumGemPorts; Count++ { |
| 873 | NumPbitMaps := len(tp.UpstreamGemPortAttributeList[Count].PbitMap) |
| 874 | for ICount := 2; ICount < NumPbitMaps; ICount++ { |
| 875 | if p, err := strconv.Atoi(string(tp.UpstreamGemPortAttributeList[Count].PbitMap[ICount])); err == nil { |
| 876 | if uint32(ICount-2) == pbit && p == 1 { // Check this p-bit is set |
| 877 | log.Debugw("Found-US-GEMport-for-Pcp", log.Fields{"pbit": pbit, "GEMport": tp.UpstreamGemPortAttributeList[Count].GemportID}) |
| 878 | return tp.UpstreamGemPortAttributeList[Count].GemportID |
| 879 | } |
| 880 | } |
| 881 | } |
| 882 | } |
| 883 | } else if Dir == tp_pb.Direction_DOWNSTREAM { |
| 884 | //downstream GEM ports |
| 885 | NumGemPorts := len(tp.DownstreamGemPortAttributeList) |
| 886 | for Count := 0; Count < NumGemPorts; Count++ { |
| 887 | NumPbitMaps := len(tp.DownstreamGemPortAttributeList[Count].PbitMap) |
| 888 | for ICount := 2; ICount < NumPbitMaps; ICount++ { |
| 889 | if p, err := strconv.Atoi(string(tp.DownstreamGemPortAttributeList[Count].PbitMap[ICount])); err == nil { |
| 890 | if uint32(ICount-2) == pbit && p == 1 { // Check this p-bit is set |
| 891 | log.Debugw("Found-DS-GEMport-for-Pcp", log.Fields{"pbit": pbit, "GEMport": tp.DownstreamGemPortAttributeList[Count].GemportID}) |
| 892 | return tp.DownstreamGemPortAttributeList[Count].GemportID |
| 893 | } |
| 894 | } |
| 895 | } |
| 896 | } |
| 897 | } |
| 898 | log.Errorw("No-GemportId-Found-For-Pcp", log.Fields{"pcpVlan": pbit}) |
| 899 | return 0 |
| 900 | } |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 901 | |
| 902 | // FindAllTpInstances returns all TechProfile instances for a given TechProfile table-id, pon interface ID and onu ID. |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 903 | func (t *TechProfileMgr) FindAllTpInstances(ctx context.Context, techProfiletblID uint32, ponIntf uint32, onuID uint32) []TechProfile { |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 904 | var tp TechProfile |
Girish Gowdra | 6172a2e | 2019-11-27 14:37:58 +0530 | [diff] [blame] | 905 | 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] | 906 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 907 | if kvPairs, _ := t.config.KVBackend.List(ctx, onuTpInstancePath); kvPairs != nil { |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 908 | tpInstances := make([]TechProfile, 0, len(kvPairs)) |
| 909 | for kvPath, kvPair := range kvPairs { |
| 910 | if value, err := kvstore.ToByte(kvPair.Value); err == nil { |
| 911 | if err = json.Unmarshal(value, &tp); err != nil { |
| 912 | log.Errorw("error-unmarshal-kv-pair", log.Fields{"kvPath": kvPath, "value": value}) |
| 913 | continue |
| 914 | } else { |
| 915 | tpInstances = append(tpInstances, tp) |
| 916 | } |
| 917 | } |
| 918 | } |
| 919 | return tpInstances |
| 920 | } |
| 921 | return nil |
| 922 | } |