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