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