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" |
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 { |
| 298 | return fmt.Sprintf(t.config.TPInstanceKVPath, t.resourceMgr.GetTechnology(), techProfiletblID, uniPortName) |
| 299 | } |
| 300 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 301 | 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] | 302 | var KvTpIns TechProfile |
| 303 | var resPtr *TechProfile = &KvTpIns |
| 304 | var err error |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 305 | var kvResult *kvstore.KVPair |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 306 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 307 | kvResult, _ = t.config.KVBackend.Get(ctx, path) |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 308 | if kvResult == nil { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 309 | logger.Infow("tp-instance-not-found-on-kv", log.Fields{"key": path}) |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 310 | return nil, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 311 | } else { |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 312 | if value, err := kvstore.ToByte(kvResult.Value); err == nil { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 313 | if err = json.Unmarshal(value, resPtr); err != nil { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 314 | logger.Errorw("error-unmarshal-kv-result", log.Fields{"key": path, "value": value}) |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 315 | return nil, errors.New("error-unmarshal-kv-result") |
| 316 | } else { |
| 317 | return resPtr, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | } |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 321 | return nil, err |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 322 | } |
| 323 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 324 | 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] | 325 | path := t.GetTechProfileInstanceKVPath(techProfiletblID, uniPortName) |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 326 | 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] | 327 | tpInstanceJson, err := json.Marshal(*tpInstance) |
| 328 | if err == nil { |
| 329 | // Backend will convert JSON byte array into string format |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 330 | 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] | 331 | err = t.config.KVBackend.Put(ctx, path, tpInstanceJson) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 332 | } else { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 333 | 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] | 334 | } |
| 335 | return err |
| 336 | } |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 337 | func (t *TechProfileMgr) getTPFromKVStore(ctx context.Context, techProfiletblID uint32) *DefaultTechProfile { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 338 | var kvtechprofile DefaultTechProfile |
| 339 | key := fmt.Sprintf(t.config.TPFileKVPath, t.resourceMgr.GetTechnology(), techProfiletblID) |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 340 | logger.Debugw("Getting techprofile from KV store", log.Fields{"techProfiletblID": techProfiletblID, "Key": key}) |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 341 | kvresult, err := t.config.KVBackend.Get(ctx, key) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 342 | if err != nil { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 343 | 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] | 344 | return nil |
| 345 | } |
| 346 | if kvresult != nil { |
| 347 | /* Backend will return Value in string format,needs to be converted to []byte before unmarshal*/ |
| 348 | if value, err := kvstore.ToByte(kvresult.Value); err == nil { |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 349 | if err = json.Unmarshal(value, &kvtechprofile); err != nil { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 350 | 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] | 351 | return nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 352 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 353 | |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 354 | 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] | 355 | return &kvtechprofile |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | return nil |
| 359 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 360 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 361 | 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] | 362 | var tpInstance *TechProfile |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 363 | 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] | 364 | |
| 365 | // Make sure the uniPortName is as per format pon-{[0-9]+}/onu-{[0-9]+}/uni-{[0-9]+} |
| 366 | if !uniPortNameFormat.Match([]byte(uniPortName)) { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 367 | 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] | 368 | return nil, errors.New("uni-port-name-not-confirming-to-format") |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 369 | } |
| 370 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 371 | tp := t.getTPFromKVStore(ctx, techProfiletblID) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 372 | if tp != nil { |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 373 | if err := t.validateInstanceControlAttr(tp.InstanceCtrl); err != nil { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 374 | logger.Error("invalid-instance-ctrl-attr--using-default-tp") |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 375 | tp = t.getDefaultTechProfile() |
| 376 | } else { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 377 | logger.Infow("using-specified-tp-from-kv-store", log.Fields{"tpid": techProfiletblID}) |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 378 | } |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 379 | } else { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 380 | logger.Info("tp-not-found-on-kv--creating-default-tp") |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 381 | tp = t.getDefaultTechProfile() |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 382 | } |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 383 | tpInstancePath := t.GetTechProfileInstanceKVPath(techProfiletblID, uniPortName) |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 384 | if tpInstance = t.allocateTPInstance(ctx, uniPortName, tp, intfId, tpInstancePath); tpInstance == nil { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 385 | logger.Error("tp-intance-allocation-failed") |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 386 | return nil, errors.New("tp-intance-allocation-failed") |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 387 | } |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 388 | if err := t.addTechProfInstanceToKVStore(ctx, techProfiletblID, uniPortName, tpInstance); err != nil { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 389 | 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] | 390 | return nil, errors.New("error-adding-tp-to-kv-store") |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 391 | } |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 392 | logger.Infow("tp-added-to-kv-store-successfully", |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 393 | log.Fields{"tpid": techProfiletblID, "uni": uniPortName, "intfId": intfId}) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 394 | return tpInstance, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 395 | } |
| 396 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 397 | func (t *TechProfileMgr) DeleteTechProfileInstance(ctx context.Context, techProfiletblID uint32, uniPortName string) error { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 398 | path := t.GetTechProfileInstanceKVPath(techProfiletblID, uniPortName) |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 399 | return t.config.KVBackend.Delete(ctx, path) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 402 | func (t *TechProfileMgr) validateInstanceControlAttr(instCtl InstanceControl) error { |
| 403 | if instCtl.Onu != "single-instance" && instCtl.Onu != "multi-instance" { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 404 | 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] | 405 | return errors.New("invalid-onu-instance-ctl-attr") |
| 406 | } |
| 407 | |
| 408 | if instCtl.Uni != "single-instance" && instCtl.Uni != "multi-instance" { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 409 | 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] | 410 | return errors.New("invalid-uni-instance-ctl-attr") |
| 411 | } |
| 412 | |
| 413 | if instCtl.Uni == "multi-instance" { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 414 | logger.Error("uni-multi-instance-tp-not-supported") |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 415 | return errors.New("uni-multi-instance-tp-not-supported") |
| 416 | } |
| 417 | |
| 418 | return nil |
| 419 | } |
| 420 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 421 | 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] | 422 | |
| 423 | var usGemPortAttributeList []iGemPortAttribute |
| 424 | var dsGemPortAttributeList []iGemPortAttribute |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 425 | var dsMulticastGemAttributeList []iGemPortAttribute |
| 426 | var dsUnicastGemAttributeList []iGemPortAttribute |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 427 | var tcontIDs []uint32 |
| 428 | var gemPorts []uint32 |
| 429 | var err error |
| 430 | |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 431 | 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] | 432 | |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 433 | if tp.InstanceCtrl.Onu == "multi-instance" { |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 434 | 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^] | 435 | logger.Errorw("Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId}) |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 436 | return nil |
| 437 | } |
| 438 | } else { // "single-instance" |
David K. Bainbridge | 7c75cac | 2020-02-19 08:53:46 -0800 | [diff] [blame] | 439 | if tpInst, err := t.getSingleInstanceTp(ctx, tpInstPath); err != nil { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 440 | 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] | 441 | return nil |
| 442 | } else if tpInst == nil { |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 443 | // No "single-instance" tp found on one any uni port for the given TP ID |
| 444 | // Allocate a new TcontID or AllocID |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 445 | 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^] | 446 | logger.Errorw("Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId}) |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 447 | return nil |
| 448 | } |
| 449 | } else { |
| 450 | // Use the alloc-id from the existing TpInstance |
| 451 | tcontIDs = append(tcontIDs, tpInst.UsScheduler.AllocID) |
| 452 | } |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 453 | } |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 454 | logger.Debugw("Num GEM ports in TP:", log.Fields{"NumGemPorts": tp.NumGemPorts}) |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 455 | 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^] | 456 | 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] | 457 | return nil |
| 458 | } |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 459 | 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] | 460 | for index := 0; index < int(tp.NumGemPorts); index++ { |
| 461 | usGemPortAttributeList = append(usGemPortAttributeList, |
| 462 | iGemPortAttribute{GemportID: gemPorts[index], |
| 463 | MaxQueueSize: tp.UpstreamGemPortAttributeList[index].MaxQueueSize, |
| 464 | PbitMap: tp.UpstreamGemPortAttributeList[index].PbitMap, |
| 465 | AesEncryption: tp.UpstreamGemPortAttributeList[index].AesEncryption, |
| 466 | SchedulingPolicy: tp.UpstreamGemPortAttributeList[index].SchedulingPolicy, |
| 467 | PriorityQueue: tp.UpstreamGemPortAttributeList[index].PriorityQueue, |
| 468 | Weight: tp.UpstreamGemPortAttributeList[index].Weight, |
| 469 | DiscardPolicy: tp.UpstreamGemPortAttributeList[index].DiscardPolicy, |
| 470 | DiscardConfig: tp.UpstreamGemPortAttributeList[index].DiscardConfig}) |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 471 | } |
| 472 | |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 473 | logger.Info("length of DownstreamGemPortAttributeList", len(tp.DownstreamGemPortAttributeList)) |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 474 | //put multicast and unicast downstream GEM port attributes in different lists first |
| 475 | for index := 0; index < int(len(tp.DownstreamGemPortAttributeList)); index++ { |
| 476 | if isMulticastGem(tp.DownstreamGemPortAttributeList[index].IsMulticast) { |
| 477 | dsMulticastGemAttributeList = append(dsMulticastGemAttributeList, |
| 478 | iGemPortAttribute{ |
| 479 | McastGemID: tp.DownstreamGemPortAttributeList[index].McastGemID, |
| 480 | MaxQueueSize: tp.DownstreamGemPortAttributeList[index].MaxQueueSize, |
| 481 | PbitMap: tp.DownstreamGemPortAttributeList[index].PbitMap, |
| 482 | AesEncryption: tp.DownstreamGemPortAttributeList[index].AesEncryption, |
| 483 | SchedulingPolicy: tp.DownstreamGemPortAttributeList[index].SchedulingPolicy, |
| 484 | PriorityQueue: tp.DownstreamGemPortAttributeList[index].PriorityQueue, |
| 485 | Weight: tp.DownstreamGemPortAttributeList[index].Weight, |
| 486 | DiscardPolicy: tp.DownstreamGemPortAttributeList[index].DiscardPolicy, |
| 487 | DiscardConfig: tp.DownstreamGemPortAttributeList[index].DiscardConfig, |
| 488 | IsMulticast: tp.DownstreamGemPortAttributeList[index].IsMulticast, |
| 489 | DControlList: tp.DownstreamGemPortAttributeList[index].DControlList, |
| 490 | SControlList: tp.DownstreamGemPortAttributeList[index].SControlList}) |
| 491 | } else { |
| 492 | dsUnicastGemAttributeList = append(dsUnicastGemAttributeList, |
| 493 | iGemPortAttribute{ |
| 494 | MaxQueueSize: tp.DownstreamGemPortAttributeList[index].MaxQueueSize, |
| 495 | PbitMap: tp.DownstreamGemPortAttributeList[index].PbitMap, |
| 496 | AesEncryption: tp.DownstreamGemPortAttributeList[index].AesEncryption, |
| 497 | SchedulingPolicy: tp.DownstreamGemPortAttributeList[index].SchedulingPolicy, |
| 498 | PriorityQueue: tp.DownstreamGemPortAttributeList[index].PriorityQueue, |
| 499 | Weight: tp.DownstreamGemPortAttributeList[index].Weight, |
| 500 | DiscardPolicy: tp.DownstreamGemPortAttributeList[index].DiscardPolicy, |
| 501 | DiscardConfig: tp.DownstreamGemPortAttributeList[index].DiscardConfig}) |
| 502 | } |
| 503 | } |
| 504 | //add unicast downstream GEM ports to dsGemPortAttributeList |
| 505 | for index := 0; index < int(tp.NumGemPorts); index++ { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 506 | dsGemPortAttributeList = append(dsGemPortAttributeList, |
| 507 | iGemPortAttribute{GemportID: gemPorts[index], |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 508 | MaxQueueSize: dsUnicastGemAttributeList[index].MaxQueueSize, |
| 509 | PbitMap: dsUnicastGemAttributeList[index].PbitMap, |
| 510 | AesEncryption: dsUnicastGemAttributeList[index].AesEncryption, |
| 511 | SchedulingPolicy: dsUnicastGemAttributeList[index].SchedulingPolicy, |
| 512 | PriorityQueue: dsUnicastGemAttributeList[index].PriorityQueue, |
| 513 | Weight: dsUnicastGemAttributeList[index].Weight, |
| 514 | DiscardPolicy: dsUnicastGemAttributeList[index].DiscardPolicy, |
| 515 | DiscardConfig: dsUnicastGemAttributeList[index].DiscardConfig}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 516 | } |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 517 | //add multicast GEM ports to dsGemPortAttributeList afterwards |
| 518 | for k := range dsMulticastGemAttributeList { |
| 519 | dsGemPortAttributeList = append(dsGemPortAttributeList, dsMulticastGemAttributeList[k]) |
| 520 | } |
| 521 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 522 | return &TechProfile{ |
| 523 | SubscriberIdentifier: uniPortName, |
| 524 | Name: tp.Name, |
| 525 | ProfileType: tp.ProfileType, |
| 526 | Version: tp.Version, |
| 527 | NumGemPorts: tp.NumGemPorts, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 528 | InstanceCtrl: tp.InstanceCtrl, |
| 529 | UsScheduler: iScheduler{ |
| 530 | AllocID: tcontIDs[0], |
| 531 | Direction: tp.UsScheduler.Direction, |
| 532 | AdditionalBw: tp.UsScheduler.AdditionalBw, |
| 533 | Priority: tp.UsScheduler.Priority, |
| 534 | Weight: tp.UsScheduler.Weight, |
| 535 | QSchedPolicy: tp.UsScheduler.QSchedPolicy}, |
| 536 | DsScheduler: iScheduler{ |
| 537 | AllocID: tcontIDs[0], |
| 538 | Direction: tp.DsScheduler.Direction, |
| 539 | AdditionalBw: tp.DsScheduler.AdditionalBw, |
| 540 | Priority: tp.DsScheduler.Priority, |
| 541 | Weight: tp.DsScheduler.Weight, |
| 542 | QSchedPolicy: tp.DsScheduler.QSchedPolicy}, |
| 543 | UpstreamGemPortAttributeList: usGemPortAttributeList, |
| 544 | DownstreamGemPortAttributeList: dsGemPortAttributeList} |
| 545 | } |
| 546 | |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 547 | // getSingleInstanceTp returns another TpInstance for an ONU on a different |
| 548 | // uni port for the same TP ID, if it finds one, else nil. |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 549 | func (t *TechProfileMgr) getSingleInstanceTp(ctx context.Context, tpPath string) (*TechProfile, error) { |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 550 | var tpInst TechProfile |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 551 | |
| 552 | // For example: |
| 553 | // tpPath like "service/voltha/technology_profiles/xgspon/64/pon-{0}/onu-{1}/uni-{1}" |
| 554 | // is broken into ["service/voltha/technology_profiles/xgspon/64/pon-{0}/onu-{1}" ""] |
| 555 | uniPathSlice := regexp.MustCompile(`/uni-{[0-9]+}$`).Split(tpPath, 2) |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 556 | kvPairs, _ := t.config.KVBackend.List(ctx, uniPathSlice[0]) |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 557 | |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 558 | // Find a valid TP Instance among all the UNIs of that ONU for the given TP ID |
| 559 | for keyPath, kvPair := range kvPairs { |
| 560 | if value, err := kvstore.ToByte(kvPair.Value); err == nil { |
| 561 | if err = json.Unmarshal(value, &tpInst); err != nil { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 562 | logger.Errorw("error-unmarshal-kv-pair", log.Fields{"keyPath": keyPath, "value": value}) |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 563 | return nil, errors.New("error-unmarshal-kv-pair") |
| 564 | } else { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 565 | 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] | 566 | return &tpInst, nil |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | } |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 570 | return nil, nil |
| 571 | } |
| 572 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 573 | func (t *TechProfileMgr) getDefaultTechProfile() *DefaultTechProfile { |
| 574 | |
| 575 | var usGemPortAttributeList []GemPortAttribute |
| 576 | var dsGemPortAttributeList []GemPortAttribute |
| 577 | |
| 578 | for _, pbit := range t.config.DefaultPbits { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 579 | logger.Debugw("Creating GEM port", log.Fields{"pbit": pbit}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 580 | usGemPortAttributeList = append(usGemPortAttributeList, |
| 581 | GemPortAttribute{ |
| 582 | MaxQueueSize: defaultMaxQueueSize, |
| 583 | PbitMap: pbit, |
| 584 | AesEncryption: defaultAESEncryption, |
| 585 | SchedulingPolicy: SchedulingPolicy_name[defaultSchedulePolicy], |
| 586 | PriorityQueue: defaultPriorityQueue, |
| 587 | Weight: defaultQueueWeight, |
| 588 | DiscardPolicy: DiscardPolicy_name[defaultdropPolicy], |
| 589 | DiscardConfig: DiscardConfig{ |
| 590 | MinThreshold: defaultMinThreshold, |
| 591 | MaxThreshold: defaultMaxThreshold, |
| 592 | MaxProbability: defaultMaxProbability}}) |
| 593 | dsGemPortAttributeList = append(dsGemPortAttributeList, |
| 594 | GemPortAttribute{ |
| 595 | MaxQueueSize: defaultMaxQueueSize, |
| 596 | PbitMap: pbit, |
| 597 | AesEncryption: defaultAESEncryption, |
| 598 | SchedulingPolicy: SchedulingPolicy_name[defaultSchedulePolicy], |
| 599 | PriorityQueue: defaultPriorityQueue, |
| 600 | Weight: defaultQueueWeight, |
| 601 | DiscardPolicy: DiscardPolicy_name[defaultdropPolicy], |
| 602 | DiscardConfig: DiscardConfig{ |
| 603 | MinThreshold: defaultMinThreshold, |
| 604 | MaxThreshold: defaultMaxThreshold, |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 605 | MaxProbability: defaultMaxProbability}, |
| 606 | IsMulticast: defaultIsMulticast, |
| 607 | DControlList: defaultAccessControlList, |
| 608 | SControlList: defaultAccessControlList, |
| 609 | McastGemID: defaultMcastGemID}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 610 | } |
| 611 | return &DefaultTechProfile{ |
| 612 | Name: t.config.DefaultTPName, |
| 613 | ProfileType: t.resourceMgr.GetTechnology(), |
| 614 | Version: t.config.TPVersion, |
| 615 | NumGemPorts: uint32(len(usGemPortAttributeList)), |
| 616 | InstanceCtrl: InstanceControl{ |
| 617 | Onu: defaultOnuInstance, |
| 618 | Uni: defaultUniInstance, |
| 619 | MaxGemPayloadSize: defaultGemPayloadSize}, |
| 620 | UsScheduler: Scheduler{ |
| 621 | Direction: Direction_name[Direction_UPSTREAM], |
| 622 | AdditionalBw: AdditionalBW_name[defaultAdditionalBw], |
| 623 | Priority: defaultPriority, |
| 624 | Weight: defaultWeight, |
| 625 | QSchedPolicy: SchedulingPolicy_name[defaultQueueSchedPolicy]}, |
| 626 | DsScheduler: Scheduler{ |
| 627 | Direction: Direction_name[Direction_DOWNSTREAM], |
| 628 | AdditionalBw: AdditionalBW_name[defaultAdditionalBw], |
| 629 | Priority: defaultPriority, |
| 630 | Weight: defaultWeight, |
| 631 | QSchedPolicy: SchedulingPolicy_name[defaultQueueSchedPolicy]}, |
| 632 | UpstreamGemPortAttributeList: usGemPortAttributeList, |
| 633 | DownstreamGemPortAttributeList: dsGemPortAttributeList} |
| 634 | } |
| 635 | |
| 636 | func (t *TechProfileMgr) GetprotoBufParamValue(paramType string, paramKey string) int32 { |
| 637 | var result int32 = -1 |
| 638 | |
| 639 | if paramType == "direction" { |
| 640 | for key, val := range tp_pb.Direction_value { |
| 641 | if key == paramKey { |
| 642 | result = val |
| 643 | } |
| 644 | } |
| 645 | } else if paramType == "discard_policy" { |
| 646 | for key, val := range tp_pb.DiscardPolicy_value { |
| 647 | if key == paramKey { |
| 648 | result = val |
| 649 | } |
| 650 | } |
| 651 | } else if paramType == "sched_policy" { |
| 652 | for key, val := range tp_pb.SchedulingPolicy_value { |
| 653 | if key == paramKey { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 654 | logger.Debugw("Got value in proto", log.Fields{"key": key, "value": val}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 655 | result = val |
| 656 | } |
| 657 | } |
| 658 | } else if paramType == "additional_bw" { |
| 659 | for key, val := range tp_pb.AdditionalBW_value { |
| 660 | if key == paramKey { |
| 661 | result = val |
| 662 | } |
| 663 | } |
| 664 | } else { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 665 | 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] | 666 | return -1 |
| 667 | } |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 668 | logger.Debugw("Got value in proto", log.Fields{"key": paramKey, "value": result}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 669 | return result |
| 670 | } |
| 671 | |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 672 | func (t *TechProfileMgr) GetUsScheduler(tpInstance *TechProfile) (*tp_pb.SchedulerConfig, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 673 | dir := tp_pb.Direction(t.GetprotoBufParamValue("direction", tpInstance.UsScheduler.Direction)) |
| 674 | if dir == -1 { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 675 | 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] | 676 | 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] | 677 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 678 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 679 | bw := tp_pb.AdditionalBW(t.GetprotoBufParamValue("additional_bw", tpInstance.UsScheduler.AdditionalBw)) |
| 680 | if bw == -1 { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 681 | 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] | 682 | 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] | 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 | policy := tp_pb.SchedulingPolicy(t.GetprotoBufParamValue("sched_policy", tpInstance.UsScheduler.QSchedPolicy)) |
| 686 | if policy == -1 { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 687 | 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] | 688 | 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] | 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 | return &tp_pb.SchedulerConfig{ |
| 692 | Direction: dir, |
| 693 | AdditionalBw: bw, |
| 694 | Priority: tpInstance.UsScheduler.Priority, |
| 695 | Weight: tpInstance.UsScheduler.Weight, |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 696 | SchedPolicy: policy}, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 697 | } |
| 698 | |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 699 | func (t *TechProfileMgr) GetDsScheduler(tpInstance *TechProfile) (*tp_pb.SchedulerConfig, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 700 | |
| 701 | dir := tp_pb.Direction(t.GetprotoBufParamValue("direction", tpInstance.DsScheduler.Direction)) |
| 702 | if dir == -1 { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 703 | 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] | 704 | 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] | 705 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 706 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 707 | bw := tp_pb.AdditionalBW(t.GetprotoBufParamValue("additional_bw", tpInstance.DsScheduler.AdditionalBw)) |
| 708 | if bw == -1 { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 709 | 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] | 710 | 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] | 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 | policy := tp_pb.SchedulingPolicy(t.GetprotoBufParamValue("sched_policy", tpInstance.DsScheduler.QSchedPolicy)) |
| 714 | if policy == -1 { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 715 | 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] | 716 | 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] | 717 | } |
| 718 | |
| 719 | return &tp_pb.SchedulerConfig{ |
| 720 | Direction: dir, |
| 721 | AdditionalBw: bw, |
| 722 | Priority: tpInstance.DsScheduler.Priority, |
| 723 | Weight: tpInstance.DsScheduler.Weight, |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 724 | SchedPolicy: policy}, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | func (t *TechProfileMgr) GetTrafficScheduler(tpInstance *TechProfile, SchedCfg *tp_pb.SchedulerConfig, |
| 728 | ShapingCfg *tp_pb.TrafficShapingInfo) *tp_pb.TrafficScheduler { |
| 729 | |
| 730 | tSched := &tp_pb.TrafficScheduler{ |
| 731 | Direction: SchedCfg.Direction, |
| 732 | AllocId: tpInstance.UsScheduler.AllocID, |
| 733 | TrafficShapingInfo: ShapingCfg, |
| 734 | Scheduler: SchedCfg} |
| 735 | |
| 736 | return tSched |
| 737 | } |
| 738 | |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 739 | 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] | 740 | |
| 741 | var encryp bool |
| 742 | if Dir == tp_pb.Direction_UPSTREAM { |
| 743 | // upstream GEM ports |
| 744 | NumGemPorts := len(tp.UpstreamGemPortAttributeList) |
| 745 | GemPorts := make([]*tp_pb.TrafficQueue, 0) |
| 746 | for Count := 0; Count < NumGemPorts; Count++ { |
| 747 | if tp.UpstreamGemPortAttributeList[Count].AesEncryption == "True" { |
| 748 | encryp = true |
| 749 | } else { |
| 750 | encryp = false |
| 751 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 752 | |
| 753 | schedPolicy := tpm.GetprotoBufParamValue("sched_policy", tp.UpstreamGemPortAttributeList[Count].SchedulingPolicy) |
| 754 | if schedPolicy == -1 { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 755 | 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] | 756 | return nil, fmt.Errorf("upstream gem port traffic queue creation failed due to unrecognized scheduling policy %s", tp.UpstreamGemPortAttributeList[Count].SchedulingPolicy) |
| 757 | } |
| 758 | |
| 759 | discardPolicy := tpm.GetprotoBufParamValue("discard_policy", tp.UpstreamGemPortAttributeList[Count].DiscardPolicy) |
| 760 | if discardPolicy == -1 { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 761 | 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] | 762 | return nil, fmt.Errorf("upstream gem port traffic queue creation failed due to unrecognized discard policy %s", tp.UpstreamGemPortAttributeList[Count].DiscardPolicy) |
| 763 | } |
| 764 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 765 | GemPorts = append(GemPorts, &tp_pb.TrafficQueue{ |
| 766 | Direction: tp_pb.Direction(tpm.GetprotoBufParamValue("direction", tp.UsScheduler.Direction)), |
| 767 | GemportId: tp.UpstreamGemPortAttributeList[Count].GemportID, |
| 768 | PbitMap: tp.UpstreamGemPortAttributeList[Count].PbitMap, |
| 769 | AesEncryption: encryp, |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 770 | SchedPolicy: tp_pb.SchedulingPolicy(schedPolicy), |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 771 | Priority: tp.UpstreamGemPortAttributeList[Count].PriorityQueue, |
| 772 | Weight: tp.UpstreamGemPortAttributeList[Count].Weight, |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 773 | DiscardPolicy: tp_pb.DiscardPolicy(discardPolicy), |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 774 | }) |
| 775 | } |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 776 | logger.Debugw("Upstream Traffic queue list ", log.Fields{"queuelist": GemPorts}) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 777 | return GemPorts, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 778 | } else if Dir == tp_pb.Direction_DOWNSTREAM { |
| 779 | //downstream GEM ports |
| 780 | NumGemPorts := len(tp.DownstreamGemPortAttributeList) |
| 781 | GemPorts := make([]*tp_pb.TrafficQueue, 0) |
| 782 | for Count := 0; Count < NumGemPorts; Count++ { |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 783 | if isMulticastGem(tp.DownstreamGemPortAttributeList[Count].IsMulticast) { |
| 784 | //do not take multicast GEM ports. They are handled separately. |
| 785 | continue |
| 786 | } |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 787 | if tp.DownstreamGemPortAttributeList[Count].AesEncryption == "True" { |
| 788 | encryp = true |
| 789 | } else { |
| 790 | encryp = false |
| 791 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 792 | |
| 793 | schedPolicy := tpm.GetprotoBufParamValue("sched_policy", tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy) |
| 794 | if schedPolicy == -1 { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 795 | 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] | 796 | return nil, fmt.Errorf("downstream gem port traffic queue creation failed due to unrecognized scheduling policy %s", tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy) |
| 797 | } |
| 798 | |
| 799 | discardPolicy := tpm.GetprotoBufParamValue("discard_policy", tp.DownstreamGemPortAttributeList[Count].DiscardPolicy) |
| 800 | if discardPolicy == -1 { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 801 | 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] | 802 | return nil, fmt.Errorf("downstream gem port traffic queue creation failed due to unrecognized discard policy %s", tp.DownstreamGemPortAttributeList[Count].DiscardPolicy) |
| 803 | } |
| 804 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 805 | GemPorts = append(GemPorts, &tp_pb.TrafficQueue{ |
| 806 | Direction: tp_pb.Direction(tpm.GetprotoBufParamValue("direction", tp.DsScheduler.Direction)), |
| 807 | GemportId: tp.DownstreamGemPortAttributeList[Count].GemportID, |
| 808 | PbitMap: tp.DownstreamGemPortAttributeList[Count].PbitMap, |
| 809 | AesEncryption: encryp, |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 810 | SchedPolicy: tp_pb.SchedulingPolicy(schedPolicy), |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 811 | Priority: tp.DownstreamGemPortAttributeList[Count].PriorityQueue, |
| 812 | Weight: tp.DownstreamGemPortAttributeList[Count].Weight, |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 813 | DiscardPolicy: tp_pb.DiscardPolicy(discardPolicy), |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 814 | }) |
| 815 | } |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 816 | logger.Debugw("Downstream Traffic queue list ", log.Fields{"queuelist": GemPorts}) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 817 | return GemPorts, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 818 | } |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 819 | |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 820 | logger.Errorf("Unsupported direction %s used for generating Traffic Queue list", Dir) |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 821 | 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] | 822 | } |
| 823 | |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 824 | //isMulticastGem returns true if isMulticast attribute value of a GEM port is true; false otherwise |
| 825 | func isMulticastGem(isMulticastAttrValue string) bool { |
| 826 | return isMulticastAttrValue != "" && |
| 827 | (isMulticastAttrValue == "True" || isMulticastAttrValue == "true" || isMulticastAttrValue == "TRUE") |
| 828 | } |
| 829 | |
| 830 | func (tpm *TechProfileMgr) GetMulticastTrafficQueues(tp *TechProfile) []*tp_pb.TrafficQueue { |
| 831 | var encryp bool |
| 832 | NumGemPorts := len(tp.DownstreamGemPortAttributeList) |
| 833 | mcastTrafficQueues := make([]*tp_pb.TrafficQueue, 0) |
| 834 | for Count := 0; Count < NumGemPorts; Count++ { |
| 835 | if !isMulticastGem(tp.DownstreamGemPortAttributeList[Count].IsMulticast) { |
| 836 | continue |
| 837 | } |
| 838 | if tp.DownstreamGemPortAttributeList[Count].AesEncryption == "True" { |
| 839 | encryp = true |
| 840 | } else { |
| 841 | encryp = false |
| 842 | } |
| 843 | mcastTrafficQueues = append(mcastTrafficQueues, &tp_pb.TrafficQueue{ |
| 844 | Direction: tp_pb.Direction(tpm.GetprotoBufParamValue("direction", tp.DsScheduler.Direction)), |
| 845 | GemportId: tp.DownstreamGemPortAttributeList[Count].McastGemID, |
| 846 | PbitMap: tp.DownstreamGemPortAttributeList[Count].PbitMap, |
| 847 | AesEncryption: encryp, |
| 848 | SchedPolicy: tp_pb.SchedulingPolicy(tpm.GetprotoBufParamValue("sched_policy", tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy)), |
| 849 | Priority: tp.DownstreamGemPortAttributeList[Count].PriorityQueue, |
| 850 | Weight: tp.DownstreamGemPortAttributeList[Count].Weight, |
| 851 | DiscardPolicy: tp_pb.DiscardPolicy(tpm.GetprotoBufParamValue("discard_policy", tp.DownstreamGemPortAttributeList[Count].DiscardPolicy)), |
| 852 | }) |
| 853 | } |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 854 | logger.Debugw("Downstream Multicast Traffic queue list ", log.Fields{"queuelist": mcastTrafficQueues}) |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 855 | return mcastTrafficQueues |
| 856 | } |
| 857 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 858 | func (tpm *TechProfileMgr) GetUsTrafficScheduler(tp *TechProfile) *tp_pb.TrafficScheduler { |
Girish Kumar | b3c52d5 | 2019-12-06 12:14:14 +0000 | [diff] [blame] | 859 | UsScheduler, _ := tpm.GetUsScheduler(tp) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 860 | |
| 861 | return &tp_pb.TrafficScheduler{Direction: UsScheduler.Direction, |
| 862 | AllocId: tp.UsScheduler.AllocID, |
| 863 | Scheduler: UsScheduler} |
| 864 | } |
| 865 | |
| 866 | func (t *TechProfileMgr) GetGemportIDForPbit(tp *TechProfile, Dir tp_pb.Direction, pbit uint32) uint32 { |
| 867 | /* |
| 868 | Function to get the Gemport ID mapped to a pbit. |
| 869 | */ |
| 870 | if Dir == tp_pb.Direction_UPSTREAM { |
| 871 | // upstream GEM ports |
| 872 | NumGemPorts := len(tp.UpstreamGemPortAttributeList) |
| 873 | for Count := 0; Count < NumGemPorts; Count++ { |
| 874 | NumPbitMaps := len(tp.UpstreamGemPortAttributeList[Count].PbitMap) |
| 875 | for ICount := 2; ICount < NumPbitMaps; ICount++ { |
| 876 | if p, err := strconv.Atoi(string(tp.UpstreamGemPortAttributeList[Count].PbitMap[ICount])); err == nil { |
| 877 | 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^] | 878 | 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] | 879 | return tp.UpstreamGemPortAttributeList[Count].GemportID |
| 880 | } |
| 881 | } |
| 882 | } |
| 883 | } |
| 884 | } else if Dir == tp_pb.Direction_DOWNSTREAM { |
| 885 | //downstream GEM ports |
| 886 | NumGemPorts := len(tp.DownstreamGemPortAttributeList) |
| 887 | for Count := 0; Count < NumGemPorts; Count++ { |
| 888 | NumPbitMaps := len(tp.DownstreamGemPortAttributeList[Count].PbitMap) |
| 889 | for ICount := 2; ICount < NumPbitMaps; ICount++ { |
| 890 | if p, err := strconv.Atoi(string(tp.DownstreamGemPortAttributeList[Count].PbitMap[ICount])); err == nil { |
| 891 | 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^] | 892 | 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] | 893 | return tp.DownstreamGemPortAttributeList[Count].GemportID |
| 894 | } |
| 895 | } |
| 896 | } |
| 897 | } |
| 898 | } |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 899 | logger.Errorw("No-GemportId-Found-For-Pcp", log.Fields{"pcpVlan": pbit}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 900 | return 0 |
| 901 | } |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 902 | |
| 903 | // 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] | 904 | 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] | 905 | var tp TechProfile |
Girish Gowdra | 6172a2e | 2019-11-27 14:37:58 +0530 | [diff] [blame] | 906 | 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] | 907 | |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 908 | if kvPairs, _ := t.config.KVBackend.List(ctx, onuTpInstancePath); kvPairs != nil { |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 909 | tpInstances := make([]TechProfile, 0, len(kvPairs)) |
| 910 | for kvPath, kvPair := range kvPairs { |
| 911 | if value, err := kvstore.ToByte(kvPair.Value); err == nil { |
| 912 | if err = json.Unmarshal(value, &tp); err != nil { |
Girish Kumar | e6f45e8 | 2020-03-20 10:46:54 +0000 | [diff] [blame^] | 913 | logger.Errorw("error-unmarshal-kv-pair", log.Fields{"kvPath": kvPath, "value": value}) |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 914 | continue |
| 915 | } else { |
| 916 | tpInstances = append(tpInstances, tp) |
| 917 | } |
| 918 | } |
| 919 | } |
| 920 | return tpInstances |
| 921 | } |
| 922 | return nil |
| 923 | } |