Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1 | /* |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 2 | * Copyright 2019-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 3 | |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 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 |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 7 | |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 9 | |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 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. |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 15 | */ |
| 16 | package techprofile |
| 17 | |
| 18 | import ( |
Matteo Scandolo | 866ac58 | 2020-11-09 12:18:31 -0800 | [diff] [blame] | 19 | "fmt" |
Neha Sharma | 130ac6d | 2020-04-08 08:46:32 +0000 | [diff] [blame] | 20 | "time" |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 21 | |
| 22 | "github.com/opencord/voltha-lib-go/v7/pkg/db" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | // tech profile default constants |
| 26 | const ( |
| 27 | defaultTechProfileName = "Default_1tcont_1gem_Profile" |
| 28 | DEFAULT_TECH_PROFILE_TABLE_ID = 64 |
| 29 | defaultVersion = 1.0 |
| 30 | defaultLogLevel = 0 |
| 31 | defaultGemportsCount = 1 |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 32 | defaultPbits = "0b11111111" |
| 33 | |
Neha Sharma | 130ac6d | 2020-04-08 08:46:32 +0000 | [diff] [blame] | 34 | defaultKVStoreTimeout = 5 * time.Second //in seconds |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 35 | |
Matteo Scandolo | f34d908 | 2020-11-24 13:56:34 -0800 | [diff] [blame] | 36 | // Tech profile path prefix in kv store (for the TP template) |
| 37 | // NOTE that this hardcoded to service/voltha as the TP template is shared across stacks |
| 38 | defaultTpKvPathPrefix = "service/voltha/technology_profiles" |
| 39 | |
| 40 | // Tech profile path prefix in kv store (for TP instances) |
Matteo Scandolo | 866ac58 | 2020-11-09 12:18:31 -0800 | [diff] [blame] | 41 | defaultKVPathPrefix = "%s/technology_profiles" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 42 | |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 43 | // Resource instance path prefix in KV store (for Resource Instances) |
| 44 | defaultResourceInstancePathPrefix = "%s/resource_instances" |
| 45 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 46 | // Tech profile path in kv store |
| 47 | defaultTechProfileKVPath = "%s/%d" // <technology>/<tech_profile_tableID> |
| 48 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 49 | ) |
| 50 | |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 51 | // Tech-Profile JSON String Keys |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 52 | // NOTE: Tech profile templeate JSON file should comply with below keys |
| 53 | const ( |
| 54 | NAME = "name" |
| 55 | PROFILE_TYPE = "profile_type" |
| 56 | VERSION = "version" |
| 57 | NUM_GEM_PORTS = "num_gem_ports" |
| 58 | INSTANCE_CONTROL = "instance_control" |
| 59 | US_SCHEDULER = "us_scheduler" |
| 60 | DS_SCHEDULER = "ds_scheduler" |
| 61 | UPSTREAM_GEM_PORT_ATTRIBUTE_LIST = "upstream_gem_port_attribute_list" |
| 62 | DOWNSTREAM_GEM_PORT_ATTRIBUTE_LIST = "downstream_gem_port_attribute_list" |
| 63 | ONU = "onu" |
| 64 | UNI = "uni" |
| 65 | MAX_GEM_PAYLOAD_SIZE = "max_gem_payload_size" |
| 66 | DIRECTION = "direction" |
| 67 | ADDITIONAL_BW = "additional_bw" |
| 68 | PRIORITY = "priority" |
| 69 | Q_SCHED_POLICY = "q_sched_policy" |
| 70 | WEIGHT = "weight" |
| 71 | PBIT_MAP = "pbit_map" |
| 72 | DISCARD_CONFIG = "discard_config" |
| 73 | MAX_THRESHOLD = "max_threshold" |
| 74 | MIN_THRESHOLD = "min_threshold" |
| 75 | MAX_PROBABILITY = "max_probability" |
| 76 | DISCARD_POLICY = "discard_policy" |
| 77 | PRIORITY_Q = "priority_q" |
| 78 | SCHEDULING_POLICY = "scheduling_policy" |
| 79 | MAX_Q_SIZE = "max_q_size" |
| 80 | AES_ENCRYPTION = "aes_encryption" |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 81 | // String Keys for EPON |
| 82 | EPON_ATTRIBUTE = "epon_attribute" |
| 83 | PACKAGE_TYPE = "package_type" |
| 84 | TRAFFIC_TYPE = "traffic type" |
| 85 | UNSOLICITED_GRANT_SIZE = "unsolicited_grant_size" |
| 86 | NOMINAL_INTERVAL = "nominal_interval" |
| 87 | TOLERATED_POLL_JITTER = "tolerated_poll_jitter" |
| 88 | REQUEST_TRANSMISSION_POLICY = "request_transmission_policy" |
| 89 | NUM_Q_SETS = "num_q_sets" |
| 90 | Q_THRESHOLDS = "q_thresholds" |
| 91 | Q_THRESHOLD1 = "q_threshold1" |
| 92 | Q_THRESHOLD2 = "q_threshold2" |
| 93 | Q_THRESHOLD3 = "q_threshold3" |
| 94 | Q_THRESHOLD4 = "q_threshold4" |
| 95 | Q_THRESHOLD5 = "q_threshold5" |
| 96 | Q_THRESHOLD6 = "q_threshold6" |
| 97 | Q_THRESHOLD7 = "q_threshold7" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 98 | ) |
| 99 | |
| 100 | // TechprofileFlags represents the set of configurations used |
| 101 | type TechProfileFlags struct { |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 102 | KVStoreAddress string |
| 103 | KVStoreType string |
| 104 | KVStoreTimeout time.Duration |
| 105 | KVBackend *db.Backend // this is the backend used to store TP instances |
| 106 | DefaultTpKVBackend *db.Backend // this is the backend used to read the TP profile |
| 107 | ResourceInstanceKVBacked *db.Backend // this is the backed used to read/write Resource Instances |
| 108 | TPKVPathPrefix string |
| 109 | defaultTpKvPathPrefix string |
| 110 | TPFileKVPath string |
| 111 | ResourceInstanceKVPathPrefix string |
| 112 | DefaultTPName string |
| 113 | TPVersion uint32 |
| 114 | NumGemPorts uint32 |
| 115 | DefaultPbits []string |
| 116 | LogLevel int |
| 117 | DefaultTechProfileID uint32 |
| 118 | DefaultNumGemPorts uint32 |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Matteo Scandolo | 866ac58 | 2020-11-09 12:18:31 -0800 | [diff] [blame] | 121 | func NewTechProfileFlags(KVStoreType string, KVStoreAddress string, basePathKvStore string) *TechProfileFlags { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 122 | // initialize with default values |
| 123 | var techProfileFlags = TechProfileFlags{ |
Girish Gowdra | 248971a | 2021-06-01 15:14:15 -0700 | [diff] [blame] | 124 | KVBackend: nil, |
| 125 | KVStoreAddress: KVStoreAddress, |
| 126 | KVStoreType: KVStoreType, |
| 127 | KVStoreTimeout: defaultKVStoreTimeout, |
| 128 | DefaultTPName: defaultTechProfileName, |
| 129 | TPKVPathPrefix: fmt.Sprintf(defaultKVPathPrefix, basePathKvStore), |
| 130 | defaultTpKvPathPrefix: defaultTpKvPathPrefix, |
| 131 | TPVersion: defaultVersion, |
| 132 | TPFileKVPath: defaultTechProfileKVPath, |
| 133 | ResourceInstanceKVPathPrefix: fmt.Sprintf(defaultResourceInstancePathPrefix, basePathKvStore), |
| 134 | DefaultTechProfileID: DEFAULT_TECH_PROFILE_TABLE_ID, |
| 135 | DefaultNumGemPorts: defaultGemportsCount, |
| 136 | DefaultPbits: []string{defaultPbits}, |
| 137 | LogLevel: defaultLogLevel, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | return &techProfileFlags |
| 141 | } |