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