Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1 | /* |
Joey Armstrong | 9cdee9f | 2024-01-03 04:56:14 -0500 | [diff] [blame] | 2 | * Copyright 2019-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 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 ( |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 20 | "bytes" |
npujar | 5bf737f | 2020-01-16 19:35:25 +0530 | [diff] [blame] | 21 | "context" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 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" |
pnalmas | 23a77d0 | 2025-01-15 11:52:48 +0530 | [diff] [blame^] | 26 | "strings" |
Gamze Abaka | dfdd8f8 | 2020-05-04 08:39:50 +0000 | [diff] [blame] | 27 | "sync" |
Neha Sharma | 130ac6d | 2020-04-08 08:46:32 +0000 | [diff] [blame] | 28 | "time" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 29 | |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 30 | "github.com/golang/protobuf/jsonpb" |
| 31 | "github.com/golang/protobuf/proto" |
| 32 | "github.com/opencord/voltha-lib-go/v7/pkg/db" |
| 33 | "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
| 34 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 35 | tp_pb "github.com/opencord/voltha-protos/v5/go/tech_profile" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 36 | ) |
| 37 | |
| 38 | // Interface to pon resource manager APIs |
| 39 | type iPonResourceMgr interface { |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 40 | GetResourceID(ctx context.Context, intfID uint32, resourceType string, numIDs uint32) ([]uint32, error) |
| 41 | FreeResourceID(ctx context.Context, intfID uint32, resourceType string, ReleaseContent []uint32) error |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 42 | GetResourceTypeAllocID() string |
| 43 | GetResourceTypeGemPortID() string |
Matteo Scandolo | b85b2f0 | 2021-03-18 14:44:41 -0700 | [diff] [blame] | 44 | GetResourceTypeOnuID() string |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 45 | GetTechnology() string |
| 46 | } |
| 47 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 48 | type SchedulingPolicy int32 |
| 49 | |
| 50 | const ( |
| 51 | SchedulingPolicy_WRR SchedulingPolicy = 0 |
| 52 | SchedulingPolicy_StrictPriority SchedulingPolicy = 1 |
| 53 | SchedulingPolicy_Hybrid SchedulingPolicy = 2 |
| 54 | ) |
| 55 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 56 | type AdditionalBW int32 |
| 57 | |
| 58 | const ( |
| 59 | AdditionalBW_AdditionalBW_None AdditionalBW = 0 |
| 60 | AdditionalBW_AdditionalBW_NA AdditionalBW = 1 |
| 61 | AdditionalBW_AdditionalBW_BestEffort AdditionalBW = 2 |
| 62 | AdditionalBW_AdditionalBW_Auto AdditionalBW = 3 |
| 63 | ) |
| 64 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 65 | type DiscardPolicy int32 |
| 66 | |
| 67 | const ( |
| 68 | DiscardPolicy_TailDrop DiscardPolicy = 0 |
| 69 | DiscardPolicy_WTailDrop DiscardPolicy = 1 |
| 70 | DiscardPolicy_Red DiscardPolicy = 2 |
| 71 | DiscardPolicy_WRed DiscardPolicy = 3 |
| 72 | ) |
| 73 | |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 74 | // Required uniPortName format |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 75 | var uniPortNameFormatRegexp = 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] | 76 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 77 | // instance control defaults |
| 78 | const ( |
| 79 | defaultOnuInstance = "multi-instance" |
| 80 | defaultUniInstance = "single-instance" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 81 | defaultGemPayloadSize = "auto" |
| 82 | ) |
| 83 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 84 | // default discard config constants |
| 85 | const ( |
| 86 | defaultMinThreshold = 0 |
| 87 | defaultMaxThreshold = 0 |
| 88 | defaultMaxProbability = 0 |
| 89 | ) |
| 90 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 91 | // default scheduler contants |
| 92 | const ( |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 93 | defaultPriority = 0 |
| 94 | defaultWeight = 0 |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 95 | ) |
| 96 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 97 | // default GEM attribute constants |
| 98 | const ( |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 99 | defaultAESEncryption = "True" |
| 100 | defaultPriorityQueue = 0 |
| 101 | defaultQueueWeight = 0 |
| 102 | defaultMaxQueueSize = "auto" |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 103 | defaultIsMulticast = "False" |
| 104 | defaultAccessControlList = "224.0.0.0-239.255.255.255" |
| 105 | defaultMcastGemID = 4069 |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 106 | ) |
| 107 | |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 108 | // Default EPON constants |
| 109 | const ( |
| 110 | defaultPakageType = "B" |
| 111 | ) |
| 112 | const ( |
| 113 | defaultTrafficType = "BE" |
| 114 | defaultUnsolicitedGrantSize = 0 |
| 115 | defaultNominalInterval = 0 |
| 116 | defaultToleratedPollJitter = 0 |
| 117 | defaultRequestTransmissionPolicy = 0 |
| 118 | defaultNumQueueSet = 2 |
| 119 | ) |
| 120 | const ( |
| 121 | defaultQThreshold1 = 5500 |
| 122 | defaultQThreshold2 = 0 |
| 123 | defaultQThreshold3 = 0 |
| 124 | defaultQThreshold4 = 0 |
| 125 | defaultQThreshold5 = 0 |
| 126 | defaultQThreshold6 = 0 |
| 127 | defaultQThreshold7 = 0 |
| 128 | ) |
| 129 | |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 130 | const ( |
Andrea Campanella | 904fe32 | 2020-06-26 18:56:51 +0200 | [diff] [blame] | 131 | xgspon = "XGS-PON" |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 132 | xgpon = "XGPON" |
Andrea Campanella | 904fe32 | 2020-06-26 18:56:51 +0200 | [diff] [blame] | 133 | gpon = "GPON" |
| 134 | epon = "EPON" |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 135 | ) |
| 136 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 137 | const ( |
| 138 | MaxUniPortPerOnu = 16 // TODO: Adapter uses its own constant for MaxUniPort. How to synchronize this and have a single source of truth? |
| 139 | ) |
| 140 | |
| 141 | type TechProfileMgr struct { |
| 142 | config *TechProfileFlags |
| 143 | resourceMgr iPonResourceMgr |
| 144 | OnuIDMgmtLock sync.RWMutex |
| 145 | GemPortIDMgmtLock sync.RWMutex |
| 146 | AllocIDMgmtLock sync.RWMutex |
| 147 | tpInstanceMap map[string]*tp_pb.TechProfileInstance // Map of tp path to tp instance |
| 148 | tpInstanceMapLock sync.RWMutex |
| 149 | eponTpInstanceMap map[string]*tp_pb.EponTechProfileInstance // Map of tp path to epon tp instance |
| 150 | epontpInstanceMapLock sync.RWMutex |
| 151 | tpMap map[uint32]*tp_pb.TechProfile // Map of tp id to tp |
| 152 | tpMapLock sync.RWMutex |
| 153 | eponTpMap map[uint32]*tp_pb.EponTechProfile // map of tp id to epon tp |
| 154 | eponTpMapLock sync.RWMutex |
| 155 | } |
| 156 | |
Matteo Scandolo | f34d908 | 2020-11-24 13:56:34 -0800 | [diff] [blame] | 157 | func (t *TechProfileMgr) SetKVClient(ctx context.Context, pathPrefix string) *db.Backend { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 158 | 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] | 159 | if err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 160 | logger.Errorw(ctx, "failed-to-create-kv-client", |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 161 | log.Fields{ |
Neha Sharma | dd9af39 | 2020-04-28 09:03:57 +0000 | [diff] [blame] | 162 | "type": t.config.KVStoreType, "address": t.config.KVStoreAddress, |
Matteo Scandolo | f34d908 | 2020-11-24 13:56:34 -0800 | [diff] [blame] | 163 | "timeout": t.config.KVStoreTimeout, "prefix": pathPrefix, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 164 | "error": err.Error(), |
| 165 | }) |
| 166 | return nil |
| 167 | } |
sbarbari | 1e3e29c | 2019-11-05 10:06:50 -0500 | [diff] [blame] | 168 | return &db.Backend{ |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 169 | Client: kvClient, |
| 170 | StoreType: t.config.KVStoreType, |
Neha Sharma | dd9af39 | 2020-04-28 09:03:57 +0000 | [diff] [blame] | 171 | Address: t.config.KVStoreAddress, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 172 | Timeout: t.config.KVStoreTimeout, |
Matteo Scandolo | f34d908 | 2020-11-24 13:56:34 -0800 | [diff] [blame] | 173 | PathPrefix: pathPrefix} |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 174 | |
| 175 | /* TODO : Make sure direct call to NewBackend is working fine with backend , currently there is some |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 176 | issue between kv store and backend , core is not calling NewBackend directly |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 177 | kv := model.NewBackend(t.config.kvStoreType, t.config.KVStoreHost, t.config.KVStorePort, |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 178 | t.config.KVStoreTimeout, kvStoreTechProfilePathPrefix) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 179 | */ |
| 180 | } |
| 181 | |
Holger Hildebrandt | 40bd267 | 2023-02-10 08:14:26 +0000 | [diff] [blame] | 182 | func (t *TechProfileMgr) CloseKVClient(ctx context.Context) { |
| 183 | if t.config.KVBackend != nil { |
| 184 | t.config.KVBackend.Client.Close(ctx) |
| 185 | t.config.KVBackend = nil |
| 186 | } |
| 187 | if t.config.DefaultTpKVBackend != nil { |
| 188 | t.config.DefaultTpKVBackend.Client.Close(ctx) |
| 189 | t.config.DefaultTpKVBackend = nil |
| 190 | } |
| 191 | if t.config.ResourceInstanceKVBacked != nil { |
| 192 | t.config.ResourceInstanceKVBacked.Client.Close(ctx) |
| 193 | t.config.ResourceInstanceKVBacked = nil |
| 194 | } |
| 195 | } |
| 196 | |
pnalmas | 23a77d0 | 2025-01-15 11:52:48 +0530 | [diff] [blame^] | 197 | func NewTechProfile(ctx context.Context, IntfId uint32, deviceId string, resourceMgr iPonResourceMgr, kvStoreType string, kvStoreAddress string, basePathKvStore string) (*TechProfileMgr, error) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 198 | var techprofileObj TechProfileMgr |
pnalmas | 23a77d0 | 2025-01-15 11:52:48 +0530 | [diff] [blame^] | 199 | logger.Debug(ctx, "initializing-techprofile-mananger ", log.Fields{"IntId": IntfId, "device-id": deviceId}) |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 200 | techprofileObj.config = NewTechProfileFlags(kvStoreType, kvStoreAddress, basePathKvStore) |
Matteo Scandolo | f34d908 | 2020-11-24 13:56:34 -0800 | [diff] [blame] | 201 | techprofileObj.config.KVBackend = techprofileObj.SetKVClient(ctx, techprofileObj.config.TPKVPathPrefix) |
| 202 | techprofileObj.config.DefaultTpKVBackend = techprofileObj.SetKVClient(ctx, techprofileObj.config.defaultTpKvPathPrefix) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 203 | if techprofileObj.config.KVBackend == nil { |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 204 | logger.Error(ctx, "failed-to-initialize-backend") |
| 205 | return nil, errors.New("kv-backend-init-failed") |
| 206 | } |
| 207 | techprofileObj.config.ResourceInstanceKVBacked = techprofileObj.SetKVClient(ctx, techprofileObj.config.ResourceInstanceKVPathPrefix) |
| 208 | if techprofileObj.config.ResourceInstanceKVBacked == nil { |
| 209 | logger.Error(ctx, "failed-to-initialize-resource-instance-kv-backend") |
| 210 | return nil, errors.New("resource-instance-kv-backend-init-failed") |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 211 | } |
| 212 | techprofileObj.resourceMgr = resourceMgr |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 213 | techprofileObj.tpInstanceMap = make(map[string]*tp_pb.TechProfileInstance) |
| 214 | techprofileObj.eponTpInstanceMap = make(map[string]*tp_pb.EponTechProfileInstance) |
| 215 | techprofileObj.tpMap = make(map[uint32]*tp_pb.TechProfile) |
| 216 | techprofileObj.eponTpMap = make(map[uint32]*tp_pb.EponTechProfile) |
| 217 | logger.Debug(ctx, "reconcile-tp-instance-cache-start") |
pnalmas | 23a77d0 | 2025-01-15 11:52:48 +0530 | [diff] [blame^] | 218 | if err := techprofileObj.reconcileTpInstancesToCache(ctx, IntfId, deviceId); err != nil { |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 219 | logger.Errorw(ctx, "failed-to-reconcile-tp-instances", log.Fields{"err": err}) |
| 220 | return nil, err |
| 221 | } |
| 222 | logger.Debug(ctx, "reconcile-tp-instance-cache-end") |
| 223 | logger.Debug(ctx, "initializing-tech-profile-manager-object-success") |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 224 | return &techprofileObj, nil |
| 225 | } |
| 226 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 227 | // GetTechProfileInstanceKey returns the tp instance key that is used to reference TP Instance Map |
| 228 | func (t *TechProfileMgr) GetTechProfileInstanceKey(ctx context.Context, tpID uint32, uniPortName string) string { |
| 229 | logger.Debugw(ctx, "get-tp-instance-kv-key", log.Fields{ |
Matteo Scandolo | 4fca23a | 2020-04-07 07:55:08 -0700 | [diff] [blame] | 230 | "uniPortName": uniPortName, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 231 | "tpId": tpID, |
Matteo Scandolo | 4fca23a | 2020-04-07 07:55:08 -0700 | [diff] [blame] | 232 | }) |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 233 | // Make sure the uniPortName is as per format olt-{[a-z0-9\-]+}/pon-{[0-9]+}/onu-{[0-9]+}/uni-{[0-9]+} |
| 234 | if !uniPortNameFormatRegexp.Match([]byte(uniPortName)) { |
| 235 | logger.Warnw(ctx, "uni-port-name-not-confirming-to-format", log.Fields{"uniPortName": uniPortName}) |
| 236 | } |
| 237 | // The key path prefix (like service/voltha/technology_profiles or service/voltha_voltha/technology_profiles) |
| 238 | // is expected to be attached by the components that use this path as part of the KVBackend configuration. |
| 239 | resourceInstanceKvPathSuffix := "%s/%d/%s" // <technology>/<tpID>/<uni-port-name> |
| 240 | // <uni-port-name> must be of the format pon-{\d+}/onu-{\d+}/uni-{\d+} |
| 241 | return fmt.Sprintf(resourceInstanceKvPathSuffix, t.resourceMgr.GetTechnology(), tpID, uniPortName) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 244 | // GetTPInstance gets TP instance from cache if found |
| 245 | func (t *TechProfileMgr) GetTPInstance(ctx context.Context, path string) (interface{}, error) { |
| 246 | tech := t.resourceMgr.GetTechnology() |
| 247 | switch tech { |
| 248 | case xgspon, xgpon, gpon: |
| 249 | t.tpInstanceMapLock.RLock() |
| 250 | defer t.tpInstanceMapLock.RUnlock() |
| 251 | tpInst, ok := t.tpInstanceMap[path] |
| 252 | if !ok { |
| 253 | return nil, fmt.Errorf("tp-instance-not-found-tp-path-%v", path) |
| 254 | } |
| 255 | return tpInst, nil |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 256 | case epon: |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 257 | t.epontpInstanceMapLock.RLock() |
| 258 | defer t.epontpInstanceMapLock.RUnlock() |
| 259 | tpInst, ok := t.eponTpInstanceMap[path] |
| 260 | if !ok { |
| 261 | return nil, fmt.Errorf("tp-instance-not-found-tp-path-%v", path) |
| 262 | } |
| 263 | return tpInst, nil |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 264 | default: |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 265 | logger.Errorw(ctx, "unknown-tech", log.Fields{"tech": tech}) |
| 266 | return nil, fmt.Errorf("unknown-tech-%s-tp-path-%v", tech, path) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 267 | } |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 270 | // CreateTechProfileInstance creates a new TP instance. |
| 271 | func (t *TechProfileMgr) CreateTechProfileInstance(ctx context.Context, tpID uint32, uniPortName string, intfID uint32) (interface{}, error) { |
| 272 | var tpInstance *tp_pb.TechProfileInstance |
| 273 | var eponTpInstance *tp_pb.EponTechProfileInstance |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 274 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 275 | logger.Infow(ctx, "creating-tp-instance", log.Fields{"tpID": tpID, "uni": uniPortName, "intId": intfID}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 276 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 277 | // Make sure the uniPortName is as per format olt-{[a-z0-9\-]+}/pon-{[0-9]+}/onu-{[0-9]+}/uni-{[0-9]+} |
| 278 | if !uniPortNameFormatRegexp.Match([]byte(uniPortName)) { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 279 | logger.Errorw(ctx, "uni-port-name-not-confirming-to-format", log.Fields{"uniPortName": uniPortName}) |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 280 | return nil, fmt.Errorf("uni-port-name-not-confirming-to-format-%s", uniPortName) |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 281 | } |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 282 | tpInstancePathSuffix := t.GetTechProfileInstanceKey(ctx, tpID, uniPortName) |
| 283 | |
| 284 | if t.resourceMgr.GetTechnology() == epon { |
| 285 | tp := t.getEponTPFromKVStore(ctx, tpID) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 286 | if tp != nil { |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 287 | if err := t.validateInstanceControlAttr(ctx, *tp.InstanceControl); err != nil { |
| 288 | logger.Error(ctx, "invalid-instance-ctrl-attr-using-default-tp") |
Girish Kumar | 950f21e | 2020-08-19 17:42:29 +0000 | [diff] [blame] | 289 | tp = t.getDefaultEponProfile(ctx) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 290 | } else { |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 291 | logger.Infow(ctx, "using-specified-tp-from-kv-store", log.Fields{"tpID": tpID}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 292 | } |
| 293 | } else { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 294 | logger.Info(ctx, "tp-not-found-on-kv--creating-default-tp") |
Girish Kumar | 950f21e | 2020-08-19 17:42:29 +0000 | [diff] [blame] | 295 | tp = t.getDefaultEponProfile(ctx) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 296 | } |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 297 | // Store TP in cache |
| 298 | t.eponTpMapLock.Lock() |
| 299 | t.eponTpMap[tpID] = tp |
| 300 | t.eponTpMapLock.Unlock() |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 301 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 302 | if eponTpInstance = t.allocateEponTPInstance(ctx, uniPortName, tp, intfID, tpInstancePathSuffix); eponTpInstance == nil { |
| 303 | logger.Error(ctx, "tp-instance-allocation-failed") |
| 304 | return nil, errors.New("tp-instance-allocation-failed") |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 305 | } |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 306 | t.epontpInstanceMapLock.Lock() |
| 307 | t.eponTpInstanceMap[tpInstancePathSuffix] = eponTpInstance |
| 308 | t.epontpInstanceMapLock.Unlock() |
| 309 | resInst := tp_pb.ResourceInstance{ |
| 310 | TpId: tpID, |
| 311 | ProfileType: eponTpInstance.ProfileType, |
| 312 | SubscriberIdentifier: eponTpInstance.SubscriberIdentifier, |
| 313 | AllocId: eponTpInstance.AllocId, |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 314 | } |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 315 | for _, usQAttr := range eponTpInstance.UpstreamQueueAttributeList { |
| 316 | resInst.GemportIds = append(resInst.GemportIds, usQAttr.GemportId) |
| 317 | } |
| 318 | |
| 319 | logger.Infow(ctx, "epon-tp-instance-created-successfully", |
| 320 | log.Fields{"tpID": tpID, "uni": uniPortName, "intfID": intfID}) |
| 321 | if err := t.addResourceInstanceToKVStore(ctx, tpID, uniPortName, resInst); err != nil { |
| 322 | logger.Errorw(ctx, "failed-to-update-resource-instance-to-kv-store--freeing-up-resources", log.Fields{"err": err, "tpID": tpID, "uniPortName": uniPortName}) |
| 323 | allocIDs := make([]uint32, 0) |
| 324 | allocIDs = append(allocIDs, resInst.AllocId) |
| 325 | errList := make([]error, 0) |
| 326 | errList = append(errList, t.FreeResourceID(ctx, intfID, t.resourceMgr.GetResourceTypeAllocID(), allocIDs)) |
| 327 | errList = append(errList, t.FreeResourceID(ctx, intfID, t.resourceMgr.GetResourceTypeGemPortID(), resInst.GemportIds)) |
| 328 | if len(errList) > 0 { |
| 329 | logger.Errorw(ctx, "failed-to-free-up-resources-on-kv-store--system-behavior-has-become-erratic", log.Fields{"tpID": tpID, "uniPortName": uniPortName, "errList": errList}) |
| 330 | } |
| 331 | return nil, err |
| 332 | } |
| 333 | return eponTpInstance, nil |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 334 | } else { |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 335 | tp := t.getTPFromKVStore(ctx, tpID) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 336 | if tp != nil { |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 337 | if err := t.validateInstanceControlAttr(ctx, *tp.InstanceControl); err != nil { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 338 | logger.Error(ctx, "invalid-instance-ctrl-attr--using-default-tp") |
| 339 | tp = t.getDefaultTechProfile(ctx) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 340 | } else { |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 341 | logger.Infow(ctx, "using-specified-tp-from-kv-store", log.Fields{"tpID": tpID}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 342 | } |
| 343 | } else { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 344 | logger.Info(ctx, "tp-not-found-on-kv--creating-default-tp") |
| 345 | tp = t.getDefaultTechProfile(ctx) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 346 | } |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 347 | // Store TP in cache |
| 348 | t.tpMapLock.Lock() |
| 349 | t.tpMap[tpID] = tp |
| 350 | t.tpMapLock.Unlock() |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 351 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 352 | if tpInstance = t.allocateTPInstance(ctx, uniPortName, tp, intfID, tpInstancePathSuffix); tpInstance == nil { |
| 353 | logger.Error(ctx, "tp-instance-allocation-failed") |
| 354 | return nil, errors.New("tp-instance-allocation-failed") |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 355 | } |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 356 | t.tpInstanceMapLock.Lock() |
| 357 | t.tpInstanceMap[tpInstancePathSuffix] = tpInstance |
| 358 | t.tpInstanceMapLock.Unlock() |
| 359 | |
| 360 | resInst := tp_pb.ResourceInstance{ |
| 361 | TpId: tpID, |
| 362 | ProfileType: tpInstance.ProfileType, |
| 363 | SubscriberIdentifier: tpInstance.SubscriberIdentifier, |
| 364 | AllocId: tpInstance.UsScheduler.AllocId, |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 365 | } |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 366 | for _, usQAttr := range tpInstance.UpstreamGemPortAttributeList { |
| 367 | resInst.GemportIds = append(resInst.GemportIds, usQAttr.GemportId) |
| 368 | } |
| 369 | |
| 370 | logger.Infow(ctx, "tp-instance-created-successfully", |
| 371 | log.Fields{"tpID": tpID, "uni": uniPortName, "intfID": intfID}) |
| 372 | if err := t.addResourceInstanceToKVStore(ctx, tpID, uniPortName, resInst); err != nil { |
| 373 | logger.Errorw(ctx, "failed-to-update-resource-instance-to-kv-store--freeing-up-resources", log.Fields{"err": err, "tpID": tpID, "uniPortName": uniPortName}) |
| 374 | allocIDs := make([]uint32, 0) |
| 375 | allocIDs = append(allocIDs, resInst.AllocId) |
| 376 | errList := make([]error, 0) |
| 377 | errList = append(errList, t.FreeResourceID(ctx, intfID, t.resourceMgr.GetResourceTypeAllocID(), allocIDs)) |
| 378 | errList = append(errList, t.FreeResourceID(ctx, intfID, t.resourceMgr.GetResourceTypeGemPortID(), resInst.GemportIds)) |
| 379 | if len(errList) > 0 { |
| 380 | logger.Fatalw(ctx, "failed-to-free-up-resources-on-kv-store--system-behavior-has-become-erratic", log.Fields{"err": err, "tpID": tpID, "uniPortName": uniPortName}) |
| 381 | } |
| 382 | return nil, err |
| 383 | } |
| 384 | |
| 385 | logger.Infow(ctx, "resource-instance-added-to-kv-store-successfully", |
| 386 | log.Fields{"tpID": tpID, "uni": uniPortName, "intfID": intfID}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 387 | return tpInstance, nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 388 | } |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 391 | // DeleteTechProfileInstance deletes the TP instance from the local cache as well as deletes the corresponding |
| 392 | // resource instance from the KV store. |
| 393 | func (t *TechProfileMgr) DeleteTechProfileInstance(ctx context.Context, tpID uint32, uniPortName string) error { |
| 394 | // Make sure the uniPortName is as per format olt-{[a-z0-9\-]+}/pon-{[0-9]+}/onu-{[0-9]+}/uni-{[0-9]+} |
| 395 | if !uniPortNameFormatRegexp.Match([]byte(uniPortName)) { |
| 396 | logger.Errorw(ctx, "uni-port-name-not-confirming-to-format", log.Fields{"uniPortName": uniPortName}) |
| 397 | return fmt.Errorf("uni-port-name-not-confirming-to-format--%s", uniPortName) |
| 398 | } |
| 399 | path := t.GetTechProfileInstanceKey(ctx, tpID, uniPortName) |
| 400 | logger.Infow(ctx, "delete-tp-instance-from-cache", log.Fields{"key": path}) |
| 401 | t.tpInstanceMapLock.Lock() |
| 402 | delete(t.tpInstanceMap, path) |
| 403 | t.tpInstanceMapLock.Unlock() |
| 404 | if err := t.removeResourceInstanceFromKVStore(ctx, tpID, uniPortName); err != nil { |
| 405 | return err |
| 406 | } |
| 407 | return nil |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 410 | func (t *TechProfileMgr) GetMulticastTrafficQueues(ctx context.Context, tp *tp_pb.TechProfileInstance) []*tp_pb.TrafficQueue { |
| 411 | var encryp bool |
| 412 | NumGemPorts := len(tp.DownstreamGemPortAttributeList) |
| 413 | mcastTrafficQueues := make([]*tp_pb.TrafficQueue, 0) |
| 414 | for Count := 0; Count < NumGemPorts; Count++ { |
| 415 | if !isMulticastGem(tp.DownstreamGemPortAttributeList[Count].IsMulticast) { |
| 416 | continue |
| 417 | } |
| 418 | if tp.DownstreamGemPortAttributeList[Count].AesEncryption == "True" { |
| 419 | encryp = true |
| 420 | } else { |
| 421 | encryp = false |
| 422 | } |
| 423 | mcastTrafficQueues = append(mcastTrafficQueues, &tp_pb.TrafficQueue{ |
| 424 | Direction: tp_pb.Direction_DOWNSTREAM, |
| 425 | GemportId: tp.DownstreamGemPortAttributeList[Count].MulticastGemId, |
| 426 | PbitMap: tp.DownstreamGemPortAttributeList[Count].PbitMap, |
| 427 | AesEncryption: encryp, |
| 428 | SchedPolicy: tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy, |
| 429 | Priority: tp.DownstreamGemPortAttributeList[Count].PriorityQ, |
| 430 | Weight: tp.DownstreamGemPortAttributeList[Count].Weight, |
| 431 | DiscardPolicy: tp.DownstreamGemPortAttributeList[Count].DiscardPolicy, |
| 432 | }) |
| 433 | } |
| 434 | logger.Debugw(ctx, "Downstream Multicast Traffic queue list ", log.Fields{"queuelist": mcastTrafficQueues}) |
| 435 | return mcastTrafficQueues |
| 436 | } |
| 437 | |
| 438 | func (t *TechProfileMgr) GetGemportForPbit(ctx context.Context, tp interface{}, dir tp_pb.Direction, pbit uint32) interface{} { |
| 439 | /* |
| 440 | Function to get the Gemport mapped to a pbit. |
| 441 | */ |
| 442 | switch tp := tp.(type) { |
| 443 | case *tp_pb.TechProfileInstance: |
| 444 | if dir == tp_pb.Direction_UPSTREAM { |
| 445 | // upstream GEM ports |
| 446 | numGemPorts := len(tp.UpstreamGemPortAttributeList) |
| 447 | for gemCnt := 0; gemCnt < numGemPorts; gemCnt++ { |
| 448 | lenOfPbitMap := len(tp.UpstreamGemPortAttributeList[gemCnt].PbitMap) |
| 449 | for pbitMapIdx := 2; pbitMapIdx < lenOfPbitMap; pbitMapIdx++ { |
| 450 | // Given a sample pbit map string "0b00000001", lenOfPbitMap is 10 |
| 451 | // "lenOfPbitMap - pbitMapIdx + 1" will give pbit-i th value from LSB position in the pbit map string |
| 452 | if p, err := strconv.Atoi(string(tp.UpstreamGemPortAttributeList[gemCnt].PbitMap[lenOfPbitMap-pbitMapIdx+1])); err == nil { |
| 453 | if uint32(pbitMapIdx-2) == pbit && p == 1 { // Check this p-bit is set |
| 454 | logger.Debugw(ctx, "Found-US-GEMport-for-Pcp", log.Fields{"pbit": pbit, "GEMport": tp.UpstreamGemPortAttributeList[gemCnt].GemportId}) |
| 455 | return tp.UpstreamGemPortAttributeList[gemCnt] |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | } else if dir == tp_pb.Direction_DOWNSTREAM { |
| 461 | //downstream GEM ports |
| 462 | numGemPorts := len(tp.DownstreamGemPortAttributeList) |
| 463 | for gemCnt := 0; gemCnt < numGemPorts; gemCnt++ { |
| 464 | lenOfPbitMap := len(tp.DownstreamGemPortAttributeList[gemCnt].PbitMap) |
| 465 | for pbitMapIdx := 2; pbitMapIdx < lenOfPbitMap; pbitMapIdx++ { |
| 466 | // Given a sample pbit map string "0b00000001", lenOfPbitMap is 10 |
| 467 | // "lenOfPbitMap - pbitMapIdx + 1" will give pbit-i th value from LSB position in the pbit map string |
| 468 | if p, err := strconv.Atoi(string(tp.DownstreamGemPortAttributeList[gemCnt].PbitMap[lenOfPbitMap-pbitMapIdx+1])); err == nil { |
| 469 | if uint32(pbitMapIdx-2) == pbit && p == 1 { // Check this p-bit is set |
| 470 | logger.Debugw(ctx, "Found-DS-GEMport-for-Pcp", log.Fields{"pbit": pbit, "GEMport": tp.DownstreamGemPortAttributeList[gemCnt].GemportId}) |
| 471 | return tp.DownstreamGemPortAttributeList[gemCnt] |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | logger.Errorw(ctx, "No-GemportId-Found-For-Pcp", log.Fields{"pcpVlan": pbit}) |
khenaidoo | a5feb8e | 2021-10-19 17:29:22 -0400 | [diff] [blame] | 478 | case *tp_pb.EponTechProfileInstance: |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 479 | if dir == tp_pb.Direction_UPSTREAM { |
| 480 | // upstream GEM ports |
| 481 | numGemPorts := len(tp.UpstreamQueueAttributeList) |
| 482 | for gemCnt := 0; gemCnt < numGemPorts; gemCnt++ { |
| 483 | lenOfPbitMap := len(tp.UpstreamQueueAttributeList[gemCnt].PbitMap) |
| 484 | for pbitMapIdx := 2; pbitMapIdx < lenOfPbitMap; pbitMapIdx++ { |
| 485 | // Given a sample pbit map string "0b00000001", lenOfPbitMap is 10 |
| 486 | // "lenOfPbitMap - pbitMapIdx + 1" will give pbit-i th value from LSB position in the pbit map string |
| 487 | if p, err := strconv.Atoi(string(tp.UpstreamQueueAttributeList[gemCnt].PbitMap[lenOfPbitMap-pbitMapIdx+1])); err == nil { |
| 488 | if uint32(pbitMapIdx-2) == pbit && p == 1 { // Check this p-bit is set |
| 489 | logger.Debugw(ctx, "Found-US-Queue-for-Pcp", log.Fields{"pbit": pbit, "Queue": tp.UpstreamQueueAttributeList[gemCnt].GemportId}) |
| 490 | return tp.UpstreamQueueAttributeList[gemCnt] |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | } else if dir == tp_pb.Direction_DOWNSTREAM { |
| 496 | //downstream GEM ports |
| 497 | numGemPorts := len(tp.DownstreamQueueAttributeList) |
| 498 | for gemCnt := 0; gemCnt < numGemPorts; gemCnt++ { |
| 499 | lenOfPbitMap := len(tp.DownstreamQueueAttributeList[gemCnt].PbitMap) |
| 500 | for pbitMapIdx := 2; pbitMapIdx < lenOfPbitMap; pbitMapIdx++ { |
| 501 | // Given a sample pbit map string "0b00000001", lenOfPbitMap is 10 |
| 502 | // "lenOfPbitMap - pbitMapIdx + 1" will give pbit-i th value from LSB position in the pbit map string |
| 503 | if p, err := strconv.Atoi(string(tp.DownstreamQueueAttributeList[gemCnt].PbitMap[lenOfPbitMap-pbitMapIdx+1])); err == nil { |
| 504 | if uint32(pbitMapIdx-2) == pbit && p == 1 { // Check this p-bit is set |
| 505 | logger.Debugw(ctx, "Found-DS-Queue-for-Pcp", log.Fields{"pbit": pbit, "Queue": tp.DownstreamQueueAttributeList[gemCnt].GemportId}) |
| 506 | return tp.DownstreamQueueAttributeList[gemCnt] |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | logger.Errorw(ctx, "No-QueueId-Found-For-Pcp", log.Fields{"pcpVlan": pbit}) |
| 513 | default: |
| 514 | logger.Errorw(ctx, "unknown-tech", log.Fields{"tp": tp}) |
| 515 | } |
| 516 | return nil |
| 517 | } |
| 518 | |
| 519 | // FindAllTpInstances returns all TechProfile instances for a given TechProfile table-id, pon interface ID and onu ID. |
| 520 | func (t *TechProfileMgr) FindAllTpInstances(ctx context.Context, oltDeviceID string, tpID uint32, intfID uint32, onuID uint32) interface{} { |
| 521 | onuTpInstancePathSuffix := fmt.Sprintf("%s/%d/olt-{%s}/pon-{%d}/onu-{%d}", t.resourceMgr.GetTechnology(), tpID, oltDeviceID, intfID, onuID) |
| 522 | tech := t.resourceMgr.GetTechnology() |
| 523 | if tech == xgspon || tech == xgpon || tech == gpon { |
| 524 | t.tpInstanceMapLock.RLock() |
| 525 | defer t.tpInstanceMapLock.RUnlock() |
| 526 | tpInstancesTech := make([]tp_pb.TechProfileInstance, 0) |
| 527 | for i := 0; i < MaxUniPortPerOnu; i++ { |
| 528 | key := onuTpInstancePathSuffix + fmt.Sprintf("/uni-{%d}", i) |
| 529 | if tpInst, ok := t.tpInstanceMap[key]; ok { |
| 530 | tpInstancesTech = append(tpInstancesTech, *tpInst) |
| 531 | } |
| 532 | } |
| 533 | return tpInstancesTech |
| 534 | } else if tech == epon { |
| 535 | t.epontpInstanceMapLock.RLock() |
| 536 | defer t.epontpInstanceMapLock.RUnlock() |
| 537 | tpInstancesTech := make([]tp_pb.EponTechProfileInstance, 0) |
| 538 | for i := 0; i < MaxUniPortPerOnu; i++ { |
| 539 | key := onuTpInstancePathSuffix + fmt.Sprintf("/uni-{%d}", i) |
| 540 | if tpInst, ok := t.eponTpInstanceMap[key]; ok { |
| 541 | tpInstancesTech = append(tpInstancesTech, *tpInst) |
| 542 | } |
| 543 | } |
| 544 | return tpInstancesTech |
| 545 | } else { |
| 546 | logger.Errorw(ctx, "unknown-tech", log.Fields{"tech": tech, "tpID": tpID, "onuID": onuID, "intfID": intfID}) |
| 547 | } |
| 548 | return nil |
| 549 | } |
| 550 | |
| 551 | func (t *TechProfileMgr) GetResourceID(ctx context.Context, intfID uint32, resourceType string, numIDs uint32) ([]uint32, error) { |
| 552 | logger.Debugw(ctx, "getting-resource-id", log.Fields{ |
| 553 | "intf-id": intfID, |
| 554 | "resource-type": resourceType, |
| 555 | "num": numIDs, |
| 556 | }) |
| 557 | var err error |
| 558 | var ids []uint32 |
| 559 | switch resourceType { |
| 560 | case t.resourceMgr.GetResourceTypeAllocID(): |
| 561 | t.AllocIDMgmtLock.Lock() |
| 562 | ids, err = t.resourceMgr.GetResourceID(ctx, intfID, resourceType, numIDs) |
| 563 | t.AllocIDMgmtLock.Unlock() |
| 564 | case t.resourceMgr.GetResourceTypeGemPortID(): |
| 565 | t.GemPortIDMgmtLock.Lock() |
| 566 | ids, err = t.resourceMgr.GetResourceID(ctx, intfID, resourceType, numIDs) |
| 567 | t.GemPortIDMgmtLock.Unlock() |
| 568 | case t.resourceMgr.GetResourceTypeOnuID(): |
| 569 | t.OnuIDMgmtLock.Lock() |
| 570 | ids, err = t.resourceMgr.GetResourceID(ctx, intfID, resourceType, numIDs) |
| 571 | t.OnuIDMgmtLock.Unlock() |
| 572 | default: |
| 573 | return nil, fmt.Errorf("resourceType %s not supported", resourceType) |
| 574 | } |
| 575 | if err != nil { |
| 576 | return nil, err |
| 577 | } |
| 578 | return ids, nil |
| 579 | } |
| 580 | |
| 581 | func (t *TechProfileMgr) FreeResourceID(ctx context.Context, intfID uint32, resourceType string, ReleaseContent []uint32) error { |
| 582 | logger.Debugw(ctx, "freeing-resource-id", log.Fields{ |
| 583 | "intf-id": intfID, |
| 584 | "resource-type": resourceType, |
| 585 | "release-content": ReleaseContent, |
| 586 | }) |
| 587 | var err error |
| 588 | switch resourceType { |
| 589 | case t.resourceMgr.GetResourceTypeAllocID(): |
| 590 | t.AllocIDMgmtLock.Lock() |
| 591 | err = t.resourceMgr.FreeResourceID(ctx, intfID, resourceType, ReleaseContent) |
| 592 | t.AllocIDMgmtLock.Unlock() |
| 593 | case t.resourceMgr.GetResourceTypeGemPortID(): |
| 594 | t.GemPortIDMgmtLock.Lock() |
| 595 | err = t.resourceMgr.FreeResourceID(ctx, intfID, resourceType, ReleaseContent) |
| 596 | t.GemPortIDMgmtLock.Unlock() |
| 597 | case t.resourceMgr.GetResourceTypeOnuID(): |
| 598 | t.OnuIDMgmtLock.Lock() |
| 599 | err = t.resourceMgr.FreeResourceID(ctx, intfID, resourceType, ReleaseContent) |
| 600 | t.OnuIDMgmtLock.Unlock() |
| 601 | default: |
| 602 | return fmt.Errorf("resourceType %s not supported", resourceType) |
| 603 | } |
| 604 | if err != nil { |
| 605 | return err |
| 606 | } |
| 607 | return nil |
| 608 | } |
| 609 | |
| 610 | func (t *TechProfileMgr) GetUsScheduler(tpInstance *tp_pb.TechProfileInstance) *tp_pb.SchedulerConfig { |
| 611 | return &tp_pb.SchedulerConfig{ |
| 612 | Direction: tpInstance.UsScheduler.Direction, |
| 613 | AdditionalBw: tpInstance.UsScheduler.AdditionalBw, |
| 614 | Priority: tpInstance.UsScheduler.Priority, |
| 615 | Weight: tpInstance.UsScheduler.Weight, |
| 616 | SchedPolicy: tpInstance.UsScheduler.QSchedPolicy} |
| 617 | } |
| 618 | |
| 619 | func (t *TechProfileMgr) GetDsScheduler(tpInstance *tp_pb.TechProfileInstance) *tp_pb.SchedulerConfig { |
| 620 | return &tp_pb.SchedulerConfig{ |
| 621 | Direction: tpInstance.DsScheduler.Direction, |
| 622 | AdditionalBw: tpInstance.DsScheduler.AdditionalBw, |
| 623 | Priority: tpInstance.DsScheduler.Priority, |
| 624 | Weight: tpInstance.DsScheduler.Weight, |
| 625 | SchedPolicy: tpInstance.DsScheduler.QSchedPolicy} |
| 626 | } |
| 627 | |
| 628 | func (t *TechProfileMgr) GetTrafficScheduler(tpInstance *tp_pb.TechProfileInstance, SchedCfg *tp_pb.SchedulerConfig, |
| 629 | ShapingCfg *tp_pb.TrafficShapingInfo) *tp_pb.TrafficScheduler { |
| 630 | |
| 631 | tSched := &tp_pb.TrafficScheduler{ |
| 632 | Direction: SchedCfg.Direction, |
| 633 | AllocId: tpInstance.UsScheduler.AllocId, |
| 634 | TrafficShapingInfo: ShapingCfg, |
| 635 | Scheduler: SchedCfg} |
| 636 | |
| 637 | return tSched |
| 638 | } |
| 639 | |
| 640 | func (t *TechProfileMgr) GetTrafficQueues(ctx context.Context, tp *tp_pb.TechProfileInstance, direction tp_pb.Direction) ([]*tp_pb.TrafficQueue, error) { |
| 641 | |
| 642 | var encryp bool |
| 643 | if direction == tp_pb.Direction_UPSTREAM { |
| 644 | // upstream GEM ports |
| 645 | NumGemPorts := len(tp.UpstreamGemPortAttributeList) |
| 646 | GemPorts := make([]*tp_pb.TrafficQueue, 0) |
| 647 | for Count := 0; Count < NumGemPorts; Count++ { |
| 648 | if tp.UpstreamGemPortAttributeList[Count].AesEncryption == "True" { |
| 649 | encryp = true |
| 650 | } else { |
| 651 | encryp = false |
| 652 | } |
| 653 | |
| 654 | GemPorts = append(GemPorts, &tp_pb.TrafficQueue{ |
| 655 | Direction: direction, |
| 656 | GemportId: tp.UpstreamGemPortAttributeList[Count].GemportId, |
| 657 | PbitMap: tp.UpstreamGemPortAttributeList[Count].PbitMap, |
| 658 | AesEncryption: encryp, |
| 659 | SchedPolicy: tp.UpstreamGemPortAttributeList[Count].SchedulingPolicy, |
| 660 | Priority: tp.UpstreamGemPortAttributeList[Count].PriorityQ, |
| 661 | Weight: tp.UpstreamGemPortAttributeList[Count].Weight, |
| 662 | DiscardPolicy: tp.UpstreamGemPortAttributeList[Count].DiscardPolicy, |
| 663 | }) |
| 664 | } |
| 665 | logger.Debugw(ctx, "Upstream Traffic queue list ", log.Fields{"queuelist": GemPorts}) |
| 666 | return GemPorts, nil |
| 667 | } else if direction == tp_pb.Direction_DOWNSTREAM { |
| 668 | //downstream GEM ports |
| 669 | NumGemPorts := len(tp.DownstreamGemPortAttributeList) |
| 670 | GemPorts := make([]*tp_pb.TrafficQueue, 0) |
| 671 | for Count := 0; Count < NumGemPorts; Count++ { |
| 672 | if isMulticastGem(tp.DownstreamGemPortAttributeList[Count].IsMulticast) { |
| 673 | //do not take multicast GEM ports. They are handled separately. |
| 674 | continue |
| 675 | } |
| 676 | if tp.DownstreamGemPortAttributeList[Count].AesEncryption == "True" { |
| 677 | encryp = true |
| 678 | } else { |
| 679 | encryp = false |
| 680 | } |
| 681 | |
| 682 | GemPorts = append(GemPorts, &tp_pb.TrafficQueue{ |
| 683 | Direction: direction, |
| 684 | GemportId: tp.DownstreamGemPortAttributeList[Count].GemportId, |
| 685 | PbitMap: tp.DownstreamGemPortAttributeList[Count].PbitMap, |
| 686 | AesEncryption: encryp, |
| 687 | SchedPolicy: tp.DownstreamGemPortAttributeList[Count].SchedulingPolicy, |
| 688 | Priority: tp.DownstreamGemPortAttributeList[Count].PriorityQ, |
| 689 | Weight: tp.DownstreamGemPortAttributeList[Count].Weight, |
| 690 | DiscardPolicy: tp.DownstreamGemPortAttributeList[Count].DiscardPolicy, |
| 691 | }) |
| 692 | } |
| 693 | logger.Debugw(ctx, "Downstream Traffic queue list ", log.Fields{"queuelist": GemPorts}) |
| 694 | return GemPorts, nil |
| 695 | } |
| 696 | |
| 697 | logger.Errorf(ctx, "Unsupported direction %s used for generating Traffic Queue list", direction) |
| 698 | return nil, fmt.Errorf("downstream gem port traffic queue creation failed due to unsupported direction %s", direction) |
| 699 | } |
| 700 | |
| 701 | func (t *TechProfileMgr) validateInstanceControlAttr(ctx context.Context, instCtl tp_pb.InstanceControl) error { |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 702 | if instCtl.Onu != "single-instance" && instCtl.Onu != "multi-instance" { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 703 | 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] | 704 | return errors.New("invalid-onu-instance-ctl-attr") |
| 705 | } |
| 706 | |
| 707 | if instCtl.Uni != "single-instance" && instCtl.Uni != "multi-instance" { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 708 | 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] | 709 | return errors.New("invalid-uni-instance-ctl-attr") |
| 710 | } |
| 711 | |
| 712 | if instCtl.Uni == "multi-instance" { |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 713 | logger.Error(ctx, "uni-multi-instance-tp-not-supported") |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 714 | return errors.New("uni-multi-instance-tp-not-supported") |
| 715 | } |
| 716 | |
| 717 | return nil |
| 718 | } |
| 719 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 720 | // allocateTPInstance for GPON, XGPON and XGS-PON technology |
| 721 | func (t *TechProfileMgr) allocateTPInstance(ctx context.Context, uniPortName string, tp *tp_pb.TechProfile, intfID uint32, tpInstPathSuffix string) *tp_pb.TechProfileInstance { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 722 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 723 | var usGemPortAttributeList []*tp_pb.GemPortAttributes |
| 724 | var dsGemPortAttributeList []*tp_pb.GemPortAttributes |
| 725 | var dsMulticastGemAttributeList []*tp_pb.GemPortAttributes |
| 726 | var dsUnicastGemAttributeList []*tp_pb.GemPortAttributes |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 727 | var tcontIDs []uint32 |
| 728 | var gemPorts []uint32 |
| 729 | var err error |
| 730 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 731 | 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] | 732 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 733 | if tp.InstanceControl.Onu == "multi-instance" { |
| 734 | tcontIDs, err = t.GetResourceID(ctx, intfID, t.resourceMgr.GetResourceTypeAllocID(), 1) |
Gamze Abaka | dfdd8f8 | 2020-05-04 08:39:50 +0000 | [diff] [blame] | 735 | if err != nil { |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 736 | logger.Errorw(ctx, "Error getting alloc id from rsrcrMgr", log.Fields{"err": err, "intfID": intfID}) |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 737 | return nil |
| 738 | } |
| 739 | } else { // "single-instance" |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 740 | if tpInst := t.getSingleInstanceTp(ctx, tpInstPathSuffix); tpInst == nil { |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 741 | // No "single-instance" tp found on one any uni port for the given TP ID |
| 742 | // Allocate a new TcontID or AllocID |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 743 | tcontIDs, err = t.GetResourceID(ctx, intfID, t.resourceMgr.GetResourceTypeAllocID(), 1) |
Gamze Abaka | dfdd8f8 | 2020-05-04 08:39:50 +0000 | [diff] [blame] | 744 | if err != nil { |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 745 | logger.Errorw(ctx, "Error getting alloc id from rsrcrMgr", log.Fields{"err": err, "intfID": intfID}) |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 746 | return nil |
| 747 | } |
| 748 | } else { |
| 749 | // Use the alloc-id from the existing TpInstance |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 750 | tcontIDs = append(tcontIDs, tpInst.UsScheduler.AllocId) |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 751 | } |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 752 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 753 | logger.Debugw(ctx, "Num GEM ports in TP:", log.Fields{"NumGemPorts": tp.NumGemPorts}) |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 754 | gemPorts, err = t.GetResourceID(ctx, intfID, t.resourceMgr.GetResourceTypeGemPortID(), tp.NumGemPorts) |
Gamze Abaka | dfdd8f8 | 2020-05-04 08:39:50 +0000 | [diff] [blame] | 755 | if err != nil { |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 756 | logger.Errorw(ctx, "Error getting gemport ids from rsrcrMgr", log.Fields{"err": err, "intfID": intfID, "numGemports": tp.NumGemPorts}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 757 | return nil |
| 758 | } |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 759 | 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] | 760 | for index := 0; index < int(tp.NumGemPorts); index++ { |
| 761 | usGemPortAttributeList = append(usGemPortAttributeList, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 762 | &tp_pb.GemPortAttributes{GemportId: gemPorts[index], |
| 763 | MaxQSize: tp.UpstreamGemPortAttributeList[index].MaxQSize, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 764 | PbitMap: tp.UpstreamGemPortAttributeList[index].PbitMap, |
| 765 | AesEncryption: tp.UpstreamGemPortAttributeList[index].AesEncryption, |
| 766 | SchedulingPolicy: tp.UpstreamGemPortAttributeList[index].SchedulingPolicy, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 767 | PriorityQ: tp.UpstreamGemPortAttributeList[index].PriorityQ, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 768 | Weight: tp.UpstreamGemPortAttributeList[index].Weight, |
| 769 | DiscardPolicy: tp.UpstreamGemPortAttributeList[index].DiscardPolicy, |
| 770 | DiscardConfig: tp.UpstreamGemPortAttributeList[index].DiscardConfig}) |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 771 | } |
| 772 | |
Neha Sharma | 94f16a9 | 2020-06-26 04:17:55 +0000 | [diff] [blame] | 773 | logger.Info(ctx, "length of DownstreamGemPortAttributeList", len(tp.DownstreamGemPortAttributeList)) |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 774 | //put multicast and unicast downstream GEM port attributes in different lists first |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 775 | for index := 0; index < len(tp.DownstreamGemPortAttributeList); index++ { |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 776 | if isMulticastGem(tp.DownstreamGemPortAttributeList[index].IsMulticast) { |
| 777 | dsMulticastGemAttributeList = append(dsMulticastGemAttributeList, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 778 | &tp_pb.GemPortAttributes{ |
| 779 | MulticastGemId: tp.DownstreamGemPortAttributeList[index].MulticastGemId, |
| 780 | MaxQSize: tp.DownstreamGemPortAttributeList[index].MaxQSize, |
| 781 | PbitMap: tp.DownstreamGemPortAttributeList[index].PbitMap, |
| 782 | AesEncryption: tp.DownstreamGemPortAttributeList[index].AesEncryption, |
| 783 | SchedulingPolicy: tp.DownstreamGemPortAttributeList[index].SchedulingPolicy, |
| 784 | PriorityQ: tp.DownstreamGemPortAttributeList[index].PriorityQ, |
| 785 | Weight: tp.DownstreamGemPortAttributeList[index].Weight, |
| 786 | DiscardPolicy: tp.DownstreamGemPortAttributeList[index].DiscardPolicy, |
| 787 | DiscardConfig: tp.DownstreamGemPortAttributeList[index].DiscardConfig, |
| 788 | IsMulticast: tp.DownstreamGemPortAttributeList[index].IsMulticast, |
| 789 | DynamicAccessControlList: tp.DownstreamGemPortAttributeList[index].DynamicAccessControlList, |
| 790 | StaticAccessControlList: tp.DownstreamGemPortAttributeList[index].StaticAccessControlList}) |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 791 | } else { |
| 792 | dsUnicastGemAttributeList = append(dsUnicastGemAttributeList, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 793 | &tp_pb.GemPortAttributes{ |
| 794 | MaxQSize: tp.DownstreamGemPortAttributeList[index].MaxQSize, |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 795 | PbitMap: tp.DownstreamGemPortAttributeList[index].PbitMap, |
| 796 | AesEncryption: tp.DownstreamGemPortAttributeList[index].AesEncryption, |
| 797 | SchedulingPolicy: tp.DownstreamGemPortAttributeList[index].SchedulingPolicy, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 798 | PriorityQ: tp.DownstreamGemPortAttributeList[index].PriorityQ, |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 799 | Weight: tp.DownstreamGemPortAttributeList[index].Weight, |
| 800 | DiscardPolicy: tp.DownstreamGemPortAttributeList[index].DiscardPolicy, |
| 801 | DiscardConfig: tp.DownstreamGemPortAttributeList[index].DiscardConfig}) |
| 802 | } |
| 803 | } |
| 804 | //add unicast downstream GEM ports to dsGemPortAttributeList |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 805 | if dsUnicastGemAttributeList != nil { |
| 806 | for index := 0; index < int(tp.NumGemPorts); index++ { |
| 807 | dsGemPortAttributeList = append(dsGemPortAttributeList, |
| 808 | &tp_pb.GemPortAttributes{GemportId: gemPorts[index], |
| 809 | MaxQSize: dsUnicastGemAttributeList[index].MaxQSize, |
| 810 | PbitMap: dsUnicastGemAttributeList[index].PbitMap, |
| 811 | AesEncryption: dsUnicastGemAttributeList[index].AesEncryption, |
| 812 | SchedulingPolicy: dsUnicastGemAttributeList[index].SchedulingPolicy, |
| 813 | PriorityQ: dsUnicastGemAttributeList[index].PriorityQ, |
| 814 | Weight: dsUnicastGemAttributeList[index].Weight, |
| 815 | DiscardPolicy: dsUnicastGemAttributeList[index].DiscardPolicy, |
| 816 | DiscardConfig: dsUnicastGemAttributeList[index].DiscardConfig}) |
| 817 | } |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 818 | } |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 819 | //add multicast GEM ports to dsGemPortAttributeList afterwards |
| 820 | for k := range dsMulticastGemAttributeList { |
| 821 | dsGemPortAttributeList = append(dsGemPortAttributeList, dsMulticastGemAttributeList[k]) |
| 822 | } |
| 823 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 824 | return &tp_pb.TechProfileInstance{ |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 825 | SubscriberIdentifier: uniPortName, |
| 826 | Name: tp.Name, |
| 827 | ProfileType: tp.ProfileType, |
| 828 | Version: tp.Version, |
| 829 | NumGemPorts: tp.NumGemPorts, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 830 | InstanceControl: tp.InstanceControl, |
| 831 | UsScheduler: &tp_pb.SchedulerAttributes{ |
| 832 | AllocId: tcontIDs[0], |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 833 | Direction: tp.UsScheduler.Direction, |
| 834 | AdditionalBw: tp.UsScheduler.AdditionalBw, |
| 835 | Priority: tp.UsScheduler.Priority, |
| 836 | Weight: tp.UsScheduler.Weight, |
| 837 | QSchedPolicy: tp.UsScheduler.QSchedPolicy}, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 838 | DsScheduler: &tp_pb.SchedulerAttributes{ |
| 839 | AllocId: tcontIDs[0], |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 840 | Direction: tp.DsScheduler.Direction, |
| 841 | AdditionalBw: tp.DsScheduler.AdditionalBw, |
| 842 | Priority: tp.DsScheduler.Priority, |
| 843 | Weight: tp.DsScheduler.Weight, |
| 844 | QSchedPolicy: tp.DsScheduler.QSchedPolicy}, |
| 845 | UpstreamGemPortAttributeList: usGemPortAttributeList, |
| 846 | DownstreamGemPortAttributeList: dsGemPortAttributeList} |
| 847 | } |
| 848 | |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 849 | // allocateTPInstance function for EPON |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 850 | func (t *TechProfileMgr) allocateEponTPInstance(ctx context.Context, uniPortName string, tp *tp_pb.EponTechProfile, intfID uint32, tpInstPath string) *tp_pb.EponTechProfileInstance { |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 851 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 852 | var usQueueAttributeList []*tp_pb.EPONQueueAttributes |
| 853 | var dsQueueAttributeList []*tp_pb.EPONQueueAttributes |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 854 | var tcontIDs []uint32 |
| 855 | var gemPorts []uint32 |
| 856 | var err error |
| 857 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 858 | logger.Infow(ctx, "allocating-tp-instance-from-tp-template", log.Fields{"uniPortName": uniPortName, "intfID": intfID, "numGem": tp.NumGemPorts}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 859 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 860 | if tp.InstanceControl.Onu == "multi-instance" { |
| 861 | if tcontIDs, err = t.GetResourceID(ctx, intfID, t.resourceMgr.GetResourceTypeAllocID(), 1); err != nil { |
| 862 | logger.Errorw(ctx, "Error getting alloc id from rsrcrMgr", log.Fields{"err": err, "intfID": intfID}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 863 | return nil |
| 864 | } |
| 865 | } else { // "single-instance" |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 866 | if tpInst := t.getSingleInstanceEponTp(ctx, tpInstPath); tpInst == nil { |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 867 | // No "single-instance" tp found on one any uni port for the given TP ID |
| 868 | // Allocate a new TcontID or AllocID |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 869 | if tcontIDs, err = t.GetResourceID(ctx, intfID, t.resourceMgr.GetResourceTypeAllocID(), 1); err != nil { |
| 870 | logger.Errorw(ctx, "error-getting-alloc-id-from-resource-mgr", log.Fields{"err": err, "intfID": intfID}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 871 | return nil |
| 872 | } |
| 873 | } else { |
| 874 | // Use the alloc-id from the existing TpInstance |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 875 | tcontIDs = append(tcontIDs, tpInst.AllocId) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 876 | } |
| 877 | } |
Girish Kumar | 950f21e | 2020-08-19 17:42:29 +0000 | [diff] [blame] | 878 | logger.Debugw(ctx, "Num GEM ports in TP:", log.Fields{"NumGemPorts": tp.NumGemPorts}) |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 879 | if gemPorts, err = t.GetResourceID(ctx, intfID, t.resourceMgr.GetResourceTypeGemPortID(), tp.NumGemPorts); err != nil { |
| 880 | logger.Errorw(ctx, "error-getting-gemport-id-from-resource-mgr", log.Fields{"err": err, "intfID": intfID, "numGemports": tp.NumGemPorts}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 881 | return nil |
| 882 | } |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 883 | logger.Infow(ctx, "allocated-alloc-id-and-gemport-successfully", log.Fields{"tconts": tcontIDs, "gemports": gemPorts}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 884 | for index := 0; index < int(tp.NumGemPorts); index++ { |
| 885 | usQueueAttributeList = append(usQueueAttributeList, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 886 | &tp_pb.EPONQueueAttributes{GemportId: gemPorts[index], |
| 887 | MaxQSize: tp.UpstreamQueueAttributeList[index].MaxQSize, |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 888 | PbitMap: tp.UpstreamQueueAttributeList[index].PbitMap, |
| 889 | AesEncryption: tp.UpstreamQueueAttributeList[index].AesEncryption, |
| 890 | TrafficType: tp.UpstreamQueueAttributeList[index].TrafficType, |
| 891 | UnsolicitedGrantSize: tp.UpstreamQueueAttributeList[index].UnsolicitedGrantSize, |
| 892 | NominalInterval: tp.UpstreamQueueAttributeList[index].NominalInterval, |
| 893 | ToleratedPollJitter: tp.UpstreamQueueAttributeList[index].ToleratedPollJitter, |
| 894 | RequestTransmissionPolicy: tp.UpstreamQueueAttributeList[index].RequestTransmissionPolicy, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 895 | NumQSets: tp.UpstreamQueueAttributeList[index].NumQSets, |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 896 | QThresholds: tp.UpstreamQueueAttributeList[index].QThresholds, |
| 897 | SchedulingPolicy: tp.UpstreamQueueAttributeList[index].SchedulingPolicy, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 898 | PriorityQ: tp.UpstreamQueueAttributeList[index].PriorityQ, |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 899 | Weight: tp.UpstreamQueueAttributeList[index].Weight, |
| 900 | DiscardPolicy: tp.UpstreamQueueAttributeList[index].DiscardPolicy, |
| 901 | DiscardConfig: tp.UpstreamQueueAttributeList[index].DiscardConfig}) |
| 902 | } |
| 903 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 904 | logger.Info(ctx, "length-of-downstream-gemport-attribute-list", len(tp.DownstreamQueueAttributeList)) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 905 | for index := 0; index < int(tp.NumGemPorts); index++ { |
| 906 | dsQueueAttributeList = append(dsQueueAttributeList, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 907 | &tp_pb.EPONQueueAttributes{GemportId: gemPorts[index], |
| 908 | MaxQSize: tp.DownstreamQueueAttributeList[index].MaxQSize, |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 909 | PbitMap: tp.DownstreamQueueAttributeList[index].PbitMap, |
| 910 | AesEncryption: tp.DownstreamQueueAttributeList[index].AesEncryption, |
| 911 | SchedulingPolicy: tp.DownstreamQueueAttributeList[index].SchedulingPolicy, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 912 | PriorityQ: tp.DownstreamQueueAttributeList[index].PriorityQ, |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 913 | Weight: tp.DownstreamQueueAttributeList[index].Weight, |
| 914 | DiscardPolicy: tp.DownstreamQueueAttributeList[index].DiscardPolicy, |
| 915 | DiscardConfig: tp.DownstreamQueueAttributeList[index].DiscardConfig}) |
| 916 | } |
| 917 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 918 | return &tp_pb.EponTechProfileInstance{ |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 919 | SubscriberIdentifier: uniPortName, |
| 920 | Name: tp.Name, |
| 921 | ProfileType: tp.ProfileType, |
| 922 | Version: tp.Version, |
| 923 | NumGemPorts: tp.NumGemPorts, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 924 | InstanceControl: tp.InstanceControl, |
| 925 | PackageType: tp.PackageType, |
| 926 | AllocId: tcontIDs[0], |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 927 | UpstreamQueueAttributeList: usQueueAttributeList, |
| 928 | DownstreamQueueAttributeList: dsQueueAttributeList} |
| 929 | } |
| 930 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 931 | // getSingleInstanceTp returns another TpInstance (GPON, XGPON, XGS-PON) for an ONU on a different |
Girish Gowdra | 32f0eff | 2019-11-17 09:53:29 +0530 | [diff] [blame] | 932 | // uni port for the same TP ID, if it finds one, else nil. |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 933 | func (t *TechProfileMgr) getSingleInstanceTp(ctx context.Context, tpPathSuffix string) *tp_pb.TechProfileInstance { |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 934 | |
| 935 | // For example: |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 936 | // tpPathSuffix like "XGS-PON/64/olt-{1234}/pon-{0}/onu-{1}/uni-{1}" |
| 937 | // is broken into ["XGS-PON/64/olt-{1234}/pon-{0}/onu-{1}" ""] |
| 938 | uniPathSlice := regexp.MustCompile(`/uni-{[0-9]+}$`).Split(tpPathSuffix, 2) |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 939 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 940 | t.tpInstanceMapLock.RLock() |
| 941 | defer t.tpInstanceMapLock.RUnlock() |
| 942 | for i := 0; i < MaxUniPortPerOnu; i++ { |
| 943 | key := fmt.Sprintf(uniPathSlice[0]+"/uni-{%d}", i) |
| 944 | if tpInst, ok := t.tpInstanceMap[key]; ok { |
| 945 | logger.Debugw(ctx, "found-single-instance-tp", log.Fields{"key": key}) |
| 946 | return tpInst |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 947 | } |
| 948 | } |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 949 | return nil |
Girish Gowdra | 9447baf | 2019-11-05 16:42:37 +0530 | [diff] [blame] | 950 | } |
| 951 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 952 | // getSingleInstanceTp returns another TpInstance (EPON) for an ONU on a different |
| 953 | // uni port for the same TP ID, if it finds one, else nil. |
| 954 | func (t *TechProfileMgr) getSingleInstanceEponTp(ctx context.Context, tpPathSuffix string) *tp_pb.EponTechProfileInstance { |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 955 | // For example: |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 956 | // tpPathSuffix like "EPON/64/olt-{1234}/pon-{0}/onu-{1}/uni-{1}" |
| 957 | // is broken into ["EPON/64/-{1234}/pon-{0}/onu-{1}" ""] |
| 958 | uniPathSlice := regexp.MustCompile(`/uni-{[0-9]+}$`).Split(tpPathSuffix, 2) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 959 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 960 | t.epontpInstanceMapLock.RLock() |
| 961 | defer t.epontpInstanceMapLock.RUnlock() |
| 962 | for i := 0; i < MaxUniPortPerOnu; i++ { |
| 963 | key := fmt.Sprintf(uniPathSlice[0]+"/uni-{%d}", i) |
| 964 | if tpInst, ok := t.eponTpInstanceMap[key]; ok { |
| 965 | logger.Debugw(ctx, "found-single-instance-tp", log.Fields{"key": key}) |
| 966 | return tpInst |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 967 | } |
| 968 | } |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 969 | return nil |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 970 | } |
| 971 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 972 | // getDefaultTechProfile returns a default TechProfile for GPON, XGPON, XGS-PON |
| 973 | func (t *TechProfileMgr) getDefaultTechProfile(ctx context.Context) *tp_pb.TechProfile { |
| 974 | var usGemPortAttributeList []*tp_pb.GemPortAttributes |
| 975 | var dsGemPortAttributeList []*tp_pb.GemPortAttributes |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 976 | |
| 977 | for _, pbit := range t.config.DefaultPbits { |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 978 | logger.Debugw(ctx, "creating-gem-port-profile-profile", log.Fields{"pbit": pbit}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 979 | usGemPortAttributeList = append(usGemPortAttributeList, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 980 | &tp_pb.GemPortAttributes{ |
| 981 | MaxQSize: defaultMaxQueueSize, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 982 | PbitMap: pbit, |
| 983 | AesEncryption: defaultAESEncryption, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 984 | SchedulingPolicy: tp_pb.SchedulingPolicy_WRR, |
| 985 | PriorityQ: defaultPriorityQueue, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 986 | Weight: defaultQueueWeight, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 987 | DiscardPolicy: tp_pb.DiscardPolicy_TailDrop, |
| 988 | DiscardConfigV2: &tp_pb.DiscardConfig{ |
| 989 | DiscardPolicy: tp_pb.DiscardPolicy_Red, |
| 990 | DiscardConfig: &tp_pb.DiscardConfig_RedDiscardConfig{ |
| 991 | RedDiscardConfig: &tp_pb.RedDiscardConfig{ |
| 992 | MinThreshold: defaultMinThreshold, |
| 993 | MaxThreshold: defaultMaxThreshold, |
| 994 | MaxProbability: defaultMaxProbability, |
| 995 | }, |
| 996 | }, |
| 997 | }, |
| 998 | DiscardConfig: &tp_pb.RedDiscardConfig{ |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 999 | MinThreshold: defaultMinThreshold, |
| 1000 | MaxThreshold: defaultMaxThreshold, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1001 | MaxProbability: defaultMaxProbability, |
| 1002 | }, |
| 1003 | }) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1004 | dsGemPortAttributeList = append(dsGemPortAttributeList, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1005 | &tp_pb.GemPortAttributes{ |
| 1006 | MaxQSize: defaultMaxQueueSize, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1007 | PbitMap: pbit, |
| 1008 | AesEncryption: defaultAESEncryption, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1009 | SchedulingPolicy: tp_pb.SchedulingPolicy_WRR, |
| 1010 | PriorityQ: defaultPriorityQueue, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1011 | Weight: defaultQueueWeight, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1012 | DiscardPolicy: tp_pb.DiscardPolicy_TailDrop, |
| 1013 | DiscardConfigV2: &tp_pb.DiscardConfig{ |
| 1014 | DiscardPolicy: tp_pb.DiscardPolicy_Red, |
| 1015 | DiscardConfig: &tp_pb.DiscardConfig_RedDiscardConfig{ |
| 1016 | RedDiscardConfig: &tp_pb.RedDiscardConfig{ |
| 1017 | MinThreshold: defaultMinThreshold, |
| 1018 | MaxThreshold: defaultMaxThreshold, |
| 1019 | MaxProbability: defaultMaxProbability, |
| 1020 | }, |
| 1021 | }, |
| 1022 | }, |
| 1023 | DiscardConfig: &tp_pb.RedDiscardConfig{ |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1024 | MinThreshold: defaultMinThreshold, |
| 1025 | MaxThreshold: defaultMaxThreshold, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1026 | MaxProbability: defaultMaxProbability, |
| 1027 | }, |
| 1028 | IsMulticast: defaultIsMulticast, |
| 1029 | DynamicAccessControlList: defaultAccessControlList, |
| 1030 | StaticAccessControlList: defaultAccessControlList, |
| 1031 | MulticastGemId: defaultMcastGemID}) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1032 | } |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1033 | return &tp_pb.TechProfile{ |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1034 | Name: t.config.DefaultTPName, |
| 1035 | ProfileType: t.resourceMgr.GetTechnology(), |
| 1036 | Version: t.config.TPVersion, |
| 1037 | NumGemPorts: uint32(len(usGemPortAttributeList)), |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1038 | InstanceControl: &tp_pb.InstanceControl{ |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1039 | Onu: defaultOnuInstance, |
| 1040 | Uni: defaultUniInstance, |
| 1041 | MaxGemPayloadSize: defaultGemPayloadSize}, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1042 | UsScheduler: &tp_pb.SchedulerAttributes{ |
| 1043 | Direction: tp_pb.Direction_UPSTREAM, |
| 1044 | AdditionalBw: tp_pb.AdditionalBW_AdditionalBW_BestEffort, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1045 | Priority: defaultPriority, |
| 1046 | Weight: defaultWeight, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1047 | QSchedPolicy: tp_pb.SchedulingPolicy_Hybrid}, |
| 1048 | DsScheduler: &tp_pb.SchedulerAttributes{ |
| 1049 | Direction: tp_pb.Direction_DOWNSTREAM, |
| 1050 | AdditionalBw: tp_pb.AdditionalBW_AdditionalBW_BestEffort, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1051 | Priority: defaultPriority, |
| 1052 | Weight: defaultWeight, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1053 | QSchedPolicy: tp_pb.SchedulingPolicy_Hybrid}, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1054 | UpstreamGemPortAttributeList: usGemPortAttributeList, |
| 1055 | DownstreamGemPortAttributeList: dsGemPortAttributeList} |
| 1056 | } |
| 1057 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1058 | // getDefaultEponProfile returns a default TechProfile for EPON |
| 1059 | func (t *TechProfileMgr) getDefaultEponProfile(ctx context.Context) *tp_pb.EponTechProfile { |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1060 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1061 | var usQueueAttributeList []*tp_pb.EPONQueueAttributes |
| 1062 | var dsQueueAttributeList []*tp_pb.EPONQueueAttributes |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1063 | |
| 1064 | for _, pbit := range t.config.DefaultPbits { |
Girish Kumar | 950f21e | 2020-08-19 17:42:29 +0000 | [diff] [blame] | 1065 | logger.Debugw(ctx, "Creating Queue", log.Fields{"pbit": pbit}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1066 | usQueueAttributeList = append(usQueueAttributeList, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1067 | &tp_pb.EPONQueueAttributes{ |
| 1068 | MaxQSize: defaultMaxQueueSize, |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1069 | PbitMap: pbit, |
| 1070 | AesEncryption: defaultAESEncryption, |
| 1071 | TrafficType: defaultTrafficType, |
| 1072 | UnsolicitedGrantSize: defaultUnsolicitedGrantSize, |
| 1073 | NominalInterval: defaultNominalInterval, |
| 1074 | ToleratedPollJitter: defaultToleratedPollJitter, |
| 1075 | RequestTransmissionPolicy: defaultRequestTransmissionPolicy, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1076 | NumQSets: defaultNumQueueSet, |
| 1077 | QThresholds: &tp_pb.QThresholds{ |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1078 | QThreshold1: defaultQThreshold1, |
| 1079 | QThreshold2: defaultQThreshold2, |
| 1080 | QThreshold3: defaultQThreshold3, |
| 1081 | QThreshold4: defaultQThreshold4, |
| 1082 | QThreshold5: defaultQThreshold5, |
| 1083 | QThreshold6: defaultQThreshold6, |
| 1084 | QThreshold7: defaultQThreshold7}, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1085 | SchedulingPolicy: tp_pb.SchedulingPolicy_WRR, |
| 1086 | PriorityQ: defaultPriorityQueue, |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1087 | Weight: defaultQueueWeight, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1088 | DiscardPolicy: tp_pb.DiscardPolicy_TailDrop, |
| 1089 | DiscardConfigV2: &tp_pb.DiscardConfig{ |
| 1090 | DiscardPolicy: tp_pb.DiscardPolicy_Red, |
| 1091 | DiscardConfig: &tp_pb.DiscardConfig_RedDiscardConfig{ |
| 1092 | RedDiscardConfig: &tp_pb.RedDiscardConfig{ |
| 1093 | MinThreshold: defaultMinThreshold, |
| 1094 | MaxThreshold: defaultMaxThreshold, |
| 1095 | MaxProbability: defaultMaxProbability, |
| 1096 | }, |
| 1097 | }, |
| 1098 | }, |
| 1099 | DiscardConfig: &tp_pb.RedDiscardConfig{ |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1100 | MinThreshold: defaultMinThreshold, |
| 1101 | MaxThreshold: defaultMaxThreshold, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1102 | MaxProbability: defaultMaxProbability, |
| 1103 | }}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1104 | dsQueueAttributeList = append(dsQueueAttributeList, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1105 | &tp_pb.EPONQueueAttributes{ |
| 1106 | MaxQSize: defaultMaxQueueSize, |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1107 | PbitMap: pbit, |
| 1108 | AesEncryption: defaultAESEncryption, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1109 | SchedulingPolicy: tp_pb.SchedulingPolicy_WRR, |
| 1110 | PriorityQ: defaultPriorityQueue, |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1111 | Weight: defaultQueueWeight, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1112 | DiscardPolicy: tp_pb.DiscardPolicy_TailDrop, |
| 1113 | DiscardConfigV2: &tp_pb.DiscardConfig{ |
| 1114 | DiscardPolicy: tp_pb.DiscardPolicy_Red, |
| 1115 | DiscardConfig: &tp_pb.DiscardConfig_RedDiscardConfig{ |
| 1116 | RedDiscardConfig: &tp_pb.RedDiscardConfig{ |
| 1117 | MinThreshold: defaultMinThreshold, |
| 1118 | MaxThreshold: defaultMaxThreshold, |
| 1119 | MaxProbability: defaultMaxProbability, |
| 1120 | }, |
| 1121 | }, |
| 1122 | }, |
| 1123 | DiscardConfig: &tp_pb.RedDiscardConfig{ |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1124 | MinThreshold: defaultMinThreshold, |
| 1125 | MaxThreshold: defaultMaxThreshold, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1126 | MaxProbability: defaultMaxProbability, |
| 1127 | }}) |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1128 | } |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1129 | return &tp_pb.EponTechProfile{ |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1130 | Name: t.config.DefaultTPName, |
| 1131 | ProfileType: t.resourceMgr.GetTechnology(), |
| 1132 | Version: t.config.TPVersion, |
| 1133 | NumGemPorts: uint32(len(usQueueAttributeList)), |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1134 | InstanceControl: &tp_pb.InstanceControl{ |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1135 | Onu: defaultOnuInstance, |
| 1136 | Uni: defaultUniInstance, |
| 1137 | MaxGemPayloadSize: defaultGemPayloadSize}, |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1138 | PackageType: defaultPakageType, |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 1139 | UpstreamQueueAttributeList: usQueueAttributeList, |
| 1140 | DownstreamQueueAttributeList: dsQueueAttributeList} |
| 1141 | } |
| 1142 | |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 1143 | // isMulticastGem returns true if isMulticast attribute value of a GEM port is true; false otherwise |
Esin Karaman | 8aa75a7 | 2019-12-20 13:11:59 +0000 | [diff] [blame] | 1144 | func isMulticastGem(isMulticastAttrValue string) bool { |
| 1145 | return isMulticastAttrValue != "" && |
| 1146 | (isMulticastAttrValue == "True" || isMulticastAttrValue == "true" || isMulticastAttrValue == "TRUE") |
| 1147 | } |
| 1148 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1149 | func (t *TechProfileMgr) addResourceInstanceToKVStore(ctx context.Context, tpID uint32, uniPortName string, resInst tp_pb.ResourceInstance) error { |
| 1150 | logger.Debugw(ctx, "adding-resource-instance-to-kv-store", log.Fields{"tpID": tpID, "uniPortName": uniPortName, "resInst": resInst}) |
| 1151 | val, err := proto.Marshal(&resInst) |
Matteo Scandolo | b85b2f0 | 2021-03-18 14:44:41 -0700 | [diff] [blame] | 1152 | if err != nil { |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1153 | logger.Errorw(ctx, "failed-to-marshall-resource-instance", log.Fields{"err": err, "tpID": tpID, "uniPortName": uniPortName, "resInst": resInst}) |
Matteo Scandolo | b85b2f0 | 2021-03-18 14:44:41 -0700 | [diff] [blame] | 1154 | return err |
| 1155 | } |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1156 | err = t.config.ResourceInstanceKVBacked.Put(ctx, fmt.Sprintf("%s/%d/%s", t.resourceMgr.GetTechnology(), tpID, uniPortName), val) |
| 1157 | return err |
| 1158 | } |
| 1159 | |
| 1160 | func (t *TechProfileMgr) removeResourceInstanceFromKVStore(ctx context.Context, tpID uint32, uniPortName string) error { |
| 1161 | logger.Debugw(ctx, "removing-resource-instance-to-kv-store", log.Fields{"tpID": tpID, "uniPortName": uniPortName}) |
| 1162 | if err := t.config.ResourceInstanceKVBacked.Delete(ctx, fmt.Sprintf("%s/%d/%s", t.resourceMgr.GetTechnology(), tpID, uniPortName)); err != nil { |
| 1163 | logger.Errorw(ctx, "error-removing-resource-instance-to-kv-store", log.Fields{"err": err, "tpID": tpID, "uniPortName": uniPortName}) |
| 1164 | return err |
| 1165 | } |
| 1166 | return nil |
| 1167 | } |
| 1168 | |
| 1169 | func (t *TechProfileMgr) getTPFromKVStore(ctx context.Context, tpID uint32) *tp_pb.TechProfile { |
| 1170 | var tp *tp_pb.TechProfile |
| 1171 | t.tpMapLock.RLock() |
| 1172 | tp, ok := t.tpMap[tpID] |
| 1173 | t.tpMapLock.RUnlock() |
| 1174 | if ok { |
| 1175 | logger.Debugw(ctx, "found-tp-in-cache", log.Fields{"tpID": tpID}) |
| 1176 | return tp |
| 1177 | } |
| 1178 | key := fmt.Sprintf(t.config.TPFileKVPath, t.resourceMgr.GetTechnology(), tpID) |
| 1179 | logger.Debugw(ctx, "getting-tp-from-kv-store", log.Fields{"tpID": tpID, "Key": key}) |
| 1180 | kvresult, err := t.config.DefaultTpKVBackend.Get(ctx, key) |
| 1181 | if err != nil { |
| 1182 | logger.Errorw(ctx, "error-fetching-from-kv-store", log.Fields{"err": err, "key": key}) |
| 1183 | return nil |
| 1184 | } |
| 1185 | if kvresult != nil { |
| 1186 | /* Backend will return Value in string format,needs to be converted to []byte before unmarshal*/ |
| 1187 | if value, err := kvstore.ToByte(kvresult.Value); err == nil { |
| 1188 | lTp := &tp_pb.TechProfile{} |
| 1189 | reader := bytes.NewReader(value) |
| 1190 | if err = jsonpb.Unmarshal(reader, lTp); err != nil { |
| 1191 | logger.Errorw(ctx, "error-unmarshalling-tp-from-kv-store", log.Fields{"err": err, "tpID": tpID, "error": err}) |
| 1192 | return nil |
| 1193 | } |
| 1194 | |
| 1195 | logger.Debugw(ctx, "success-fetched-tp-from-kv-store", log.Fields{"tpID": tpID, "value": *lTp}) |
| 1196 | return lTp |
| 1197 | } else { |
| 1198 | logger.Errorw(ctx, "error-decoding-tp", log.Fields{"err": err, "tpID": tpID}) |
| 1199 | // We we create a default profile in this case. |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | return nil |
| 1204 | } |
| 1205 | |
| 1206 | func (t *TechProfileMgr) getEponTPFromKVStore(ctx context.Context, tpID uint32) *tp_pb.EponTechProfile { |
| 1207 | var eponTp *tp_pb.EponTechProfile |
| 1208 | t.eponTpMapLock.RLock() |
| 1209 | eponTp, ok := t.eponTpMap[tpID] |
| 1210 | t.eponTpMapLock.RUnlock() |
| 1211 | if ok { |
| 1212 | logger.Debugw(ctx, "found-tp-in-cache", log.Fields{"tpID": tpID}) |
| 1213 | return eponTp |
| 1214 | } |
| 1215 | key := fmt.Sprintf(t.config.TPFileKVPath, t.resourceMgr.GetTechnology(), tpID) |
| 1216 | logger.Debugw(ctx, "getting-epon-tp-from-kv-store", log.Fields{"tpID": tpID, "Key": key}) |
| 1217 | kvresult, err := t.config.DefaultTpKVBackend.Get(ctx, key) |
| 1218 | if err != nil { |
| 1219 | logger.Errorw(ctx, "error-fetching-from-kv-store", log.Fields{"err": err, "key": key}) |
| 1220 | return nil |
| 1221 | } |
| 1222 | if kvresult != nil { |
| 1223 | /* Backend will return Value in string format,needs to be converted to []byte before unmarshal*/ |
| 1224 | if value, err := kvstore.ToByte(kvresult.Value); err == nil { |
| 1225 | lEponTp := &tp_pb.EponTechProfile{} |
| 1226 | reader := bytes.NewReader(value) |
| 1227 | if err = jsonpb.Unmarshal(reader, lEponTp); err != nil { |
| 1228 | logger.Errorw(ctx, "error-unmarshalling-epon-tp-from-kv-store", log.Fields{"err": err, "tpID": tpID, "error": err}) |
| 1229 | return nil |
| 1230 | } |
| 1231 | |
| 1232 | logger.Debugw(ctx, "success-fetching-epon-tp-from-kv-store", log.Fields{"tpID": tpID, "value": *lEponTp}) |
| 1233 | return lEponTp |
| 1234 | } |
| 1235 | } |
| 1236 | return nil |
| 1237 | } |
| 1238 | |
| 1239 | func newKVClient(ctx context.Context, storeType string, address string, timeout time.Duration) (kvstore.Client, error) { |
| 1240 | |
| 1241 | logger.Infow(ctx, "kv-store", log.Fields{"storeType": storeType, "address": address}) |
| 1242 | switch storeType { |
| 1243 | case "etcd": |
| 1244 | return kvstore.NewEtcdClient(ctx, address, timeout, log.WarnLevel) |
serkant.uluderya | e5afeff | 2021-02-23 18:00:23 +0300 | [diff] [blame] | 1245 | case "redis": |
| 1246 | return kvstore.NewRedisClient(address, timeout, false) |
| 1247 | case "redis-sentinel": |
| 1248 | return kvstore.NewRedisClient(address, timeout, true) |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1249 | } |
serkant.uluderya | e5afeff | 2021-02-23 18:00:23 +0300 | [diff] [blame] | 1250 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1251 | return nil, errors.New("unsupported-kv-store") |
| 1252 | } |
| 1253 | |
| 1254 | // buildTpInstanceFromResourceInstance for GPON, XGPON and XGS-PON technology - build TpInstance from TechProfile template and ResourceInstance |
| 1255 | func (t *TechProfileMgr) buildTpInstanceFromResourceInstance(ctx context.Context, tp *tp_pb.TechProfile, resInst *tp_pb.ResourceInstance) *tp_pb.TechProfileInstance { |
| 1256 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1257 | if len(resInst.GemportIds) != int(tp.NumGemPorts) { |
| 1258 | logger.Errorw(ctx, "mismatch-in-number-of-gemports-between-template-and-resource-instance", |
| 1259 | log.Fields{"tpID": resInst.TpId, "totalResInstGemPortIDs": len(resInst.GemportIds), "totalTpTemplateGemPorts": tp.NumGemPorts}) |
| 1260 | return nil |
| 1261 | } |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1262 | |
pnalmas | 23a77d0 | 2025-01-15 11:52:48 +0530 | [diff] [blame^] | 1263 | usGemPortAttributeList := make([]*tp_pb.GemPortAttributes, 0, tp.NumGemPorts) |
| 1264 | dsGemPortAttributeList := make([]*tp_pb.GemPortAttributes, 0, tp.NumGemPorts) |
| 1265 | dsMulticastGemAttributeList := make([]*tp_pb.GemPortAttributes, 0) |
| 1266 | dsUnicastGemAttributeList := make([]*tp_pb.GemPortAttributes, 0) |
| 1267 | |
| 1268 | logger.Debugw(ctx, "Building TP Instance", |
| 1269 | log.Fields{"tpID": resInst.TpId, "totalResInstGemPortIDs": len(resInst.GemportIds), "totalTpTemplateGemPorts": tp.NumGemPorts}) |
| 1270 | |
| 1271 | usGemPortAttributeList = t.buildUpstreamGemPortAttributes(ctx, tp, resInst, usGemPortAttributeList) |
| 1272 | dsUnicastGemAttributeList, dsMulticastGemAttributeList = t.separateDownstreamGemPortAttributes(ctx, tp, dsUnicastGemAttributeList, dsMulticastGemAttributeList) |
| 1273 | dsGemPortAttributeList = t.buildDownstreamGemPortAttributes(ctx, tp, resInst, dsUnicastGemAttributeList, dsMulticastGemAttributeList, dsGemPortAttributeList) |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1274 | |
| 1275 | return &tp_pb.TechProfileInstance{ |
| 1276 | SubscriberIdentifier: resInst.SubscriberIdentifier, |
| 1277 | Name: tp.Name, |
| 1278 | ProfileType: tp.ProfileType, |
| 1279 | Version: tp.Version, |
| 1280 | NumGemPorts: tp.NumGemPorts, |
| 1281 | InstanceControl: tp.InstanceControl, |
| 1282 | UsScheduler: &tp_pb.SchedulerAttributes{ |
| 1283 | AllocId: resInst.AllocId, |
| 1284 | Direction: tp.UsScheduler.Direction, |
| 1285 | AdditionalBw: tp.UsScheduler.AdditionalBw, |
| 1286 | Priority: tp.UsScheduler.Priority, |
| 1287 | Weight: tp.UsScheduler.Weight, |
| 1288 | QSchedPolicy: tp.UsScheduler.QSchedPolicy}, |
| 1289 | DsScheduler: &tp_pb.SchedulerAttributes{ |
| 1290 | AllocId: resInst.AllocId, |
| 1291 | Direction: tp.DsScheduler.Direction, |
| 1292 | AdditionalBw: tp.DsScheduler.AdditionalBw, |
| 1293 | Priority: tp.DsScheduler.Priority, |
| 1294 | Weight: tp.DsScheduler.Weight, |
| 1295 | QSchedPolicy: tp.DsScheduler.QSchedPolicy}, |
| 1296 | UpstreamGemPortAttributeList: usGemPortAttributeList, |
| 1297 | DownstreamGemPortAttributeList: dsGemPortAttributeList} |
| 1298 | } |
| 1299 | |
| 1300 | // buildEponTpInstanceFromResourceInstance for EPON technology - build EponTpInstance from EponTechProfile template and ResourceInstance |
| 1301 | func (t *TechProfileMgr) buildEponTpInstanceFromResourceInstance(ctx context.Context, tp *tp_pb.EponTechProfile, resInst *tp_pb.ResourceInstance) *tp_pb.EponTechProfileInstance { |
| 1302 | |
| 1303 | var usQueueAttributeList []*tp_pb.EPONQueueAttributes |
| 1304 | var dsQueueAttributeList []*tp_pb.EPONQueueAttributes |
| 1305 | |
| 1306 | if len(resInst.GemportIds) != int(tp.NumGemPorts) { |
| 1307 | logger.Errorw(ctx, "mismatch-in-number-of-gemports-between-epon-tp-template-and-resource-instance", |
| 1308 | log.Fields{"tpID": resInst.TpId, "totalResInstGemPortIDs": len(resInst.GemportIds), "totalTpTemplateGemPorts": tp.NumGemPorts}) |
| 1309 | return nil |
| 1310 | } |
| 1311 | |
| 1312 | for index := 0; index < int(tp.NumGemPorts); index++ { |
| 1313 | usQueueAttributeList = append(usQueueAttributeList, |
| 1314 | &tp_pb.EPONQueueAttributes{GemportId: resInst.GemportIds[index], |
| 1315 | MaxQSize: tp.UpstreamQueueAttributeList[index].MaxQSize, |
| 1316 | PbitMap: tp.UpstreamQueueAttributeList[index].PbitMap, |
| 1317 | AesEncryption: tp.UpstreamQueueAttributeList[index].AesEncryption, |
| 1318 | TrafficType: tp.UpstreamQueueAttributeList[index].TrafficType, |
| 1319 | UnsolicitedGrantSize: tp.UpstreamQueueAttributeList[index].UnsolicitedGrantSize, |
| 1320 | NominalInterval: tp.UpstreamQueueAttributeList[index].NominalInterval, |
| 1321 | ToleratedPollJitter: tp.UpstreamQueueAttributeList[index].ToleratedPollJitter, |
| 1322 | RequestTransmissionPolicy: tp.UpstreamQueueAttributeList[index].RequestTransmissionPolicy, |
| 1323 | NumQSets: tp.UpstreamQueueAttributeList[index].NumQSets, |
| 1324 | QThresholds: tp.UpstreamQueueAttributeList[index].QThresholds, |
| 1325 | SchedulingPolicy: tp.UpstreamQueueAttributeList[index].SchedulingPolicy, |
| 1326 | PriorityQ: tp.UpstreamQueueAttributeList[index].PriorityQ, |
| 1327 | Weight: tp.UpstreamQueueAttributeList[index].Weight, |
| 1328 | DiscardPolicy: tp.UpstreamQueueAttributeList[index].DiscardPolicy, |
| 1329 | DiscardConfig: tp.UpstreamQueueAttributeList[index].DiscardConfig}) |
| 1330 | } |
| 1331 | |
| 1332 | for index := 0; index < int(tp.NumGemPorts); index++ { |
| 1333 | dsQueueAttributeList = append(dsQueueAttributeList, |
| 1334 | &tp_pb.EPONQueueAttributes{GemportId: resInst.GemportIds[index], |
| 1335 | MaxQSize: tp.DownstreamQueueAttributeList[index].MaxQSize, |
| 1336 | PbitMap: tp.DownstreamQueueAttributeList[index].PbitMap, |
| 1337 | AesEncryption: tp.DownstreamQueueAttributeList[index].AesEncryption, |
| 1338 | SchedulingPolicy: tp.DownstreamQueueAttributeList[index].SchedulingPolicy, |
| 1339 | PriorityQ: tp.DownstreamQueueAttributeList[index].PriorityQ, |
| 1340 | Weight: tp.DownstreamQueueAttributeList[index].Weight, |
| 1341 | DiscardPolicy: tp.DownstreamQueueAttributeList[index].DiscardPolicy, |
| 1342 | DiscardConfig: tp.DownstreamQueueAttributeList[index].DiscardConfig}) |
| 1343 | } |
| 1344 | |
| 1345 | return &tp_pb.EponTechProfileInstance{ |
| 1346 | SubscriberIdentifier: resInst.SubscriberIdentifier, |
| 1347 | Name: tp.Name, |
| 1348 | ProfileType: tp.ProfileType, |
| 1349 | Version: tp.Version, |
| 1350 | NumGemPorts: tp.NumGemPorts, |
| 1351 | InstanceControl: tp.InstanceControl, |
| 1352 | PackageType: tp.PackageType, |
| 1353 | AllocId: resInst.AllocId, |
| 1354 | UpstreamQueueAttributeList: usQueueAttributeList, |
| 1355 | DownstreamQueueAttributeList: dsQueueAttributeList} |
| 1356 | } |
| 1357 | |
| 1358 | func (t *TechProfileMgr) getTpInstanceFromResourceInstance(ctx context.Context, resInst *tp_pb.ResourceInstance) *tp_pb.TechProfileInstance { |
| 1359 | if resInst == nil { |
| 1360 | logger.Error(ctx, "resource-instance-nil") |
| 1361 | return nil |
| 1362 | } |
| 1363 | tp := t.getTPFromKVStore(ctx, resInst.TpId) |
| 1364 | if tp == nil { |
| 1365 | logger.Warnw(ctx, "tp-not-found-on-kv--creating-default-tp", log.Fields{"tpID": resInst.TpId}) |
| 1366 | tp = t.getDefaultTechProfile(ctx) |
| 1367 | } |
| 1368 | return t.buildTpInstanceFromResourceInstance(ctx, tp, resInst) |
| 1369 | } |
| 1370 | |
| 1371 | func (t *TechProfileMgr) getEponTpInstanceFromResourceInstance(ctx context.Context, resInst *tp_pb.ResourceInstance) *tp_pb.EponTechProfileInstance { |
| 1372 | if resInst == nil { |
| 1373 | logger.Error(ctx, "resource-instance-nil") |
| 1374 | return nil |
| 1375 | } |
| 1376 | eponTp := t.getEponTPFromKVStore(ctx, resInst.TpId) |
| 1377 | if eponTp == nil { |
| 1378 | logger.Warnw(ctx, "tp-not-found-on-kv--creating-default-tp", log.Fields{"tpID": resInst.TpId}) |
| 1379 | eponTp = t.getDefaultEponProfile(ctx) |
| 1380 | } |
| 1381 | return t.buildEponTpInstanceFromResourceInstance(ctx, eponTp, resInst) |
| 1382 | } |
| 1383 | |
pnalmas | 23a77d0 | 2025-01-15 11:52:48 +0530 | [diff] [blame^] | 1384 | func (t *TechProfileMgr) reconcileTpInstancesToCache(ctx context.Context, IntfId uint32, deviceId string) error { |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1385 | |
| 1386 | tech := t.resourceMgr.GetTechnology() |
| 1387 | newCtx, cancel := context.WithTimeout(ctx, 30*time.Second) |
| 1388 | defer cancel() |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1389 | |
pnalmas | 23a77d0 | 2025-01-15 11:52:48 +0530 | [diff] [blame^] | 1390 | //VOL-5417:Only reconcile the tech profiles for the subscribers associated with this PON port on this device. |
| 1391 | //Getting the list of supported tech profile IDs and then reconciling the tech profiles for these IDs associated |
| 1392 | //with the subscribers on this device for this PON port. |
| 1393 | |
| 1394 | //Fetching the techprofile Keys from the KV Store. |
| 1395 | tpkeys, _ := t.config.DefaultTpKVBackend.GetWithPrefixKeysOnly(ctx, tech) |
| 1396 | |
| 1397 | // Extract the techprofile Ids from the keys |
| 1398 | // The tpkeys will be of the format "service/voltha/technology_profiles/GPON/65" |
| 1399 | // where 65 is the techprofile Id |
| 1400 | tpIds := make([]uint32, 0) |
| 1401 | |
| 1402 | for _, key := range tpkeys { |
| 1403 | parts := strings.Split(key, "/") |
| 1404 | // Ensure the key has the expected format |
| 1405 | if len(parts) < 5 { |
| 1406 | logger.Errorw(ctx, "Key does not match expected format", log.Fields{"key": key}) |
| 1407 | continue |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1408 | } |
pnalmas | 23a77d0 | 2025-01-15 11:52:48 +0530 | [diff] [blame^] | 1409 | // Convert the last part of the key to uint32 (techprofile Id) |
| 1410 | tpId, err := strconv.Atoi(parts[len(parts)-1]) |
| 1411 | if err != nil { |
| 1412 | logger.Errorw(ctx, "Error converting techprofile Id to int", log.Fields{"key": key, "error": err}) |
| 1413 | continue |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1414 | } |
pnalmas | 23a77d0 | 2025-01-15 11:52:48 +0530 | [diff] [blame^] | 1415 | tpIds = append(tpIds, uint32(tpId)) |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
pnalmas | 23a77d0 | 2025-01-15 11:52:48 +0530 | [diff] [blame^] | 1418 | //for each tpid form a prefix and get the resource instance |
| 1419 | for _, tpId := range tpIds { |
| 1420 | prefix := fmt.Sprintf("%s/%d/olt-{%s}/pon-{%d}", tech, tpId, deviceId, IntfId) |
| 1421 | kvPairs, _ := t.config.ResourceInstanceKVBacked.GetWithPrefix(newCtx, prefix) |
| 1422 | //check if KvPairs is empty and if not then reconcile the techprofile instance |
| 1423 | if len(kvPairs) > 0 { |
| 1424 | for keyPath, kvPair := range kvPairs { |
| 1425 | if value, err := kvstore.ToByte(kvPair.Value); err == nil { |
| 1426 | var resInst tp_pb.ResourceInstance |
| 1427 | if err = proto.Unmarshal(value, &resInst); err != nil { |
| 1428 | logger.Errorw(ctx, "error-unmarshal-kv-pair", log.Fields{"err": err, "keyPath": keyPath, "value": value}) |
| 1429 | continue |
| 1430 | } else { |
| 1431 | if tech == xgspon || tech == xgpon || tech == gpon { |
| 1432 | if tpInst := t.getTpInstanceFromResourceInstance(ctx, &resInst); tpInst != nil { |
| 1433 | keySuffixSlice := regexp.MustCompile(t.config.ResourceInstanceKVPathPrefix+"/").Split(keyPath, 2) |
| 1434 | if len(keySuffixSlice) == 2 { |
| 1435 | keySuffixFormatRegexp := regexp.MustCompile(`^[a-zA-Z\-]+/[0-9]+/olt-{[a-z0-9\-]+}/pon-{[0-9]+}/onu-{[0-9]+}/uni-{[0-9]+}$`) |
| 1436 | if !keySuffixFormatRegexp.Match([]byte(keySuffixSlice[1])) { |
| 1437 | logger.Errorw(ctx, "kv-path-not-confirming-to-format", log.Fields{"kvPath": keySuffixSlice[1]}) |
| 1438 | continue |
| 1439 | } |
| 1440 | } else { |
| 1441 | logger.Errorw(ctx, "kv-instance-key-path-not-in-the-expected-format", log.Fields{"kvPath": keyPath}) |
| 1442 | continue |
| 1443 | } |
| 1444 | t.tpInstanceMapLock.Lock() |
| 1445 | t.tpInstanceMap[keySuffixSlice[1]] = tpInst |
| 1446 | t.tpInstanceMapLock.Unlock() |
| 1447 | logger.Infow(ctx, "reconciled-tp-success", log.Fields{"keyPath": keyPath}) |
| 1448 | } |
| 1449 | } else if tech == epon { |
| 1450 | if eponTpInst := t.getEponTpInstanceFromResourceInstance(ctx, &resInst); eponTpInst != nil { |
| 1451 | keySuffixSlice := regexp.MustCompile(t.config.ResourceInstanceKVPathPrefix+"/").Split(keyPath, 2) |
| 1452 | if len(keySuffixSlice) == 2 { |
| 1453 | keySuffixFormatRegexp := regexp.MustCompile(`^[a-zA-Z\-]+/[0-9]+/olt-{[a-z0-9\-]+}/pon-{[0-9]+}/onu-{[0-9]+}/uni-{[0-9]+}$`) |
| 1454 | if !keySuffixFormatRegexp.Match([]byte(keySuffixSlice[1])) { |
| 1455 | logger.Errorw(ctx, "kv-path-not-confirming-to-format", log.Fields{"kvPath": keySuffixSlice[1]}) |
| 1456 | continue |
| 1457 | } |
| 1458 | } else { |
| 1459 | logger.Errorw(ctx, "kv-instance-key-path-not-in-the-expected-format", log.Fields{"kvPath": keyPath}) |
| 1460 | continue |
| 1461 | } |
| 1462 | t.epontpInstanceMapLock.Lock() |
| 1463 | t.eponTpInstanceMap[keySuffixSlice[1]] = eponTpInst |
| 1464 | t.epontpInstanceMapLock.Unlock() |
| 1465 | logger.Debugw(ctx, "reconciled-epon-tp-success", log.Fields{"keyPath": keyPath}) |
| 1466 | } |
| 1467 | } else { |
| 1468 | logger.Errorw(ctx, "unknown-tech", log.Fields{"tech": tech}) |
| 1469 | return fmt.Errorf("unknown-tech-%v", tech) |
| 1470 | } |
| 1471 | } |
| 1472 | } else { |
| 1473 | logger.Errorw(ctx, "error-converting-kv-pair-value-to-byte", log.Fields{"err": err}) |
| 1474 | } |
| 1475 | |
| 1476 | } |
| 1477 | |
| 1478 | return nil |
| 1479 | } |
| 1480 | } |
Matteo Scandolo | b85b2f0 | 2021-03-18 14:44:41 -0700 | [diff] [blame] | 1481 | return nil |
| 1482 | } |
pnalmas | 23a77d0 | 2025-01-15 11:52:48 +0530 | [diff] [blame^] | 1483 | |
| 1484 | func (t *TechProfileMgr) buildUpstreamGemPortAttributes(ctx context.Context, tp *tp_pb.TechProfile, resInst *tp_pb.ResourceInstance, usGemPortAttributeList []*tp_pb.GemPortAttributes) []*tp_pb.GemPortAttributes { |
| 1485 | for index := 0; index < int(tp.NumGemPorts); index++ { |
| 1486 | usGemPortAttributeList = append(usGemPortAttributeList, &tp_pb.GemPortAttributes{ |
| 1487 | GemportId: resInst.GemportIds[index], |
| 1488 | MaxQSize: tp.UpstreamGemPortAttributeList[index].MaxQSize, |
| 1489 | PbitMap: tp.UpstreamGemPortAttributeList[index].PbitMap, |
| 1490 | AesEncryption: tp.UpstreamGemPortAttributeList[index].AesEncryption, |
| 1491 | SchedulingPolicy: tp.UpstreamGemPortAttributeList[index].SchedulingPolicy, |
| 1492 | PriorityQ: tp.UpstreamGemPortAttributeList[index].PriorityQ, |
| 1493 | Weight: tp.UpstreamGemPortAttributeList[index].Weight, |
| 1494 | DiscardPolicy: tp.UpstreamGemPortAttributeList[index].DiscardPolicy, |
| 1495 | DiscardConfig: tp.UpstreamGemPortAttributeList[index].DiscardConfig, |
| 1496 | }) |
| 1497 | } |
| 1498 | logger.Debugw(ctx, "Processed upstream GEM port attributes", log.Fields{"count": len(usGemPortAttributeList)}) |
| 1499 | return usGemPortAttributeList |
| 1500 | } |
| 1501 | |
| 1502 | func (t *TechProfileMgr) separateDownstreamGemPortAttributes(ctx context.Context, tp *tp_pb.TechProfile, dsUnicastGemAttributeList, dsMulticastGemAttributeList []*tp_pb.GemPortAttributes) ([]*tp_pb.GemPortAttributes, []*tp_pb.GemPortAttributes) { |
| 1503 | for _, attr := range tp.DownstreamGemPortAttributeList { |
| 1504 | if isMulticastGem(attr.IsMulticast) { |
| 1505 | dsMulticastGemAttributeList = append(dsMulticastGemAttributeList, &tp_pb.GemPortAttributes{ |
| 1506 | MulticastGemId: attr.MulticastGemId, |
| 1507 | MaxQSize: attr.MaxQSize, |
| 1508 | PbitMap: attr.PbitMap, |
| 1509 | AesEncryption: attr.AesEncryption, |
| 1510 | SchedulingPolicy: attr.SchedulingPolicy, |
| 1511 | PriorityQ: attr.PriorityQ, |
| 1512 | Weight: attr.Weight, |
| 1513 | DiscardPolicy: attr.DiscardPolicy, |
| 1514 | DiscardConfig: attr.DiscardConfig, |
| 1515 | IsMulticast: attr.IsMulticast, |
| 1516 | DynamicAccessControlList: attr.DynamicAccessControlList, |
| 1517 | StaticAccessControlList: attr.StaticAccessControlList, |
| 1518 | }) |
| 1519 | } else { |
| 1520 | dsUnicastGemAttributeList = append(dsUnicastGemAttributeList, &tp_pb.GemPortAttributes{ |
| 1521 | MaxQSize: attr.MaxQSize, |
| 1522 | PbitMap: attr.PbitMap, |
| 1523 | AesEncryption: attr.AesEncryption, |
| 1524 | SchedulingPolicy: attr.SchedulingPolicy, |
| 1525 | PriorityQ: attr.PriorityQ, |
| 1526 | Weight: attr.Weight, |
| 1527 | DiscardPolicy: attr.DiscardPolicy, |
| 1528 | DiscardConfig: attr.DiscardConfig, |
| 1529 | }) |
| 1530 | } |
| 1531 | } |
| 1532 | logger.Debugw(ctx, "Processed downstream GEM port attributes", log.Fields{ |
| 1533 | "unicastCount": len(dsUnicastGemAttributeList), "multicastCount": len(dsMulticastGemAttributeList)}) |
| 1534 | return dsUnicastGemAttributeList, dsMulticastGemAttributeList |
| 1535 | } |
| 1536 | |
| 1537 | func (t *TechProfileMgr) buildDownstreamGemPortAttributes(ctx context.Context, tp *tp_pb.TechProfile, resInst *tp_pb.ResourceInstance, dsUnicastGemAttributeList, dsMulticastGemAttributeList, dsGemPortAttributeList []*tp_pb.GemPortAttributes) []*tp_pb.GemPortAttributes { |
| 1538 | for index := 0; index < int(tp.NumGemPorts) && index < len(dsUnicastGemAttributeList); index++ { |
| 1539 | dsGemPortAttributeList = append(dsGemPortAttributeList, &tp_pb.GemPortAttributes{ |
| 1540 | GemportId: resInst.GemportIds[index], |
| 1541 | MaxQSize: dsUnicastGemAttributeList[index].MaxQSize, |
| 1542 | PbitMap: dsUnicastGemAttributeList[index].PbitMap, |
| 1543 | AesEncryption: dsUnicastGemAttributeList[index].AesEncryption, |
| 1544 | SchedulingPolicy: dsUnicastGemAttributeList[index].SchedulingPolicy, |
| 1545 | PriorityQ: dsUnicastGemAttributeList[index].PriorityQ, |
| 1546 | Weight: dsUnicastGemAttributeList[index].Weight, |
| 1547 | DiscardPolicy: dsUnicastGemAttributeList[index].DiscardPolicy, |
| 1548 | DiscardConfig: dsUnicastGemAttributeList[index].DiscardConfig, |
| 1549 | }) |
| 1550 | } |
| 1551 | dsGemPortAttributeList = append(dsGemPortAttributeList, dsMulticastGemAttributeList...) |
| 1552 | logger.Debugw(ctx, "Processed downstream GEM port attributes for final list", log.Fields{"count": len(dsGemPortAttributeList)}) |
| 1553 | return dsGemPortAttributeList |
| 1554 | } |