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