Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package techprofile |
| 17 | |
| 18 | import ( |
Matteo Scandolo | 866ac58 | 2020-11-09 12:18:31 -0800 | [diff] [blame^] | 19 | "fmt" |
Girish Gowdra | 89c985b | 2020-10-14 15:02:09 -0700 | [diff] [blame] | 20 | "github.com/opencord/voltha-lib-go/v4/pkg/db" |
Neha Sharma | 130ac6d | 2020-04-08 08:46:32 +0000 | [diff] [blame] | 21 | "time" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | // tech profile default constants |
| 25 | const ( |
| 26 | defaultTechProfileName = "Default_1tcont_1gem_Profile" |
| 27 | DEFAULT_TECH_PROFILE_TABLE_ID = 64 |
| 28 | defaultVersion = 1.0 |
| 29 | defaultLogLevel = 0 |
| 30 | defaultGemportsCount = 1 |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 31 | defaultPbits = "0b11111111" |
| 32 | |
Neha Sharma | 130ac6d | 2020-04-08 08:46:32 +0000 | [diff] [blame] | 33 | defaultKVStoreTimeout = 5 * time.Second //in seconds |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 34 | |
| 35 | // Tech profile path prefix in kv store |
Matteo Scandolo | 866ac58 | 2020-11-09 12:18:31 -0800 | [diff] [blame^] | 36 | defaultKVPathPrefix = "%s/technology_profiles" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 37 | |
| 38 | // Tech profile path in kv store |
| 39 | defaultTechProfileKVPath = "%s/%d" // <technology>/<tech_profile_tableID> |
| 40 | |
| 41 | // Tech profile instance path in kv store |
| 42 | // Format: <technology>/<tech_profile_tableID>/<uni_port_name> |
| 43 | defaultTPInstanceKVPath = "%s/%d/%s" |
| 44 | ) |
| 45 | |
| 46 | //Tech-Profile JSON String Keys |
| 47 | // NOTE: Tech profile templeate JSON file should comply with below keys |
| 48 | const ( |
| 49 | NAME = "name" |
| 50 | PROFILE_TYPE = "profile_type" |
| 51 | VERSION = "version" |
| 52 | NUM_GEM_PORTS = "num_gem_ports" |
| 53 | INSTANCE_CONTROL = "instance_control" |
| 54 | US_SCHEDULER = "us_scheduler" |
| 55 | DS_SCHEDULER = "ds_scheduler" |
| 56 | UPSTREAM_GEM_PORT_ATTRIBUTE_LIST = "upstream_gem_port_attribute_list" |
| 57 | DOWNSTREAM_GEM_PORT_ATTRIBUTE_LIST = "downstream_gem_port_attribute_list" |
| 58 | ONU = "onu" |
| 59 | UNI = "uni" |
| 60 | MAX_GEM_PAYLOAD_SIZE = "max_gem_payload_size" |
| 61 | DIRECTION = "direction" |
| 62 | ADDITIONAL_BW = "additional_bw" |
| 63 | PRIORITY = "priority" |
| 64 | Q_SCHED_POLICY = "q_sched_policy" |
| 65 | WEIGHT = "weight" |
| 66 | PBIT_MAP = "pbit_map" |
| 67 | DISCARD_CONFIG = "discard_config" |
| 68 | MAX_THRESHOLD = "max_threshold" |
| 69 | MIN_THRESHOLD = "min_threshold" |
| 70 | MAX_PROBABILITY = "max_probability" |
| 71 | DISCARD_POLICY = "discard_policy" |
| 72 | PRIORITY_Q = "priority_q" |
| 73 | SCHEDULING_POLICY = "scheduling_policy" |
| 74 | MAX_Q_SIZE = "max_q_size" |
| 75 | AES_ENCRYPTION = "aes_encryption" |
Takahiro Suzuki | 98cd2b9 | 2020-03-13 14:50:08 -0700 | [diff] [blame] | 76 | // String Keys for EPON |
| 77 | EPON_ATTRIBUTE = "epon_attribute" |
| 78 | PACKAGE_TYPE = "package_type" |
| 79 | TRAFFIC_TYPE = "traffic type" |
| 80 | UNSOLICITED_GRANT_SIZE = "unsolicited_grant_size" |
| 81 | NOMINAL_INTERVAL = "nominal_interval" |
| 82 | TOLERATED_POLL_JITTER = "tolerated_poll_jitter" |
| 83 | REQUEST_TRANSMISSION_POLICY = "request_transmission_policy" |
| 84 | NUM_Q_SETS = "num_q_sets" |
| 85 | Q_THRESHOLDS = "q_thresholds" |
| 86 | Q_THRESHOLD1 = "q_threshold1" |
| 87 | Q_THRESHOLD2 = "q_threshold2" |
| 88 | Q_THRESHOLD3 = "q_threshold3" |
| 89 | Q_THRESHOLD4 = "q_threshold4" |
| 90 | Q_THRESHOLD5 = "q_threshold5" |
| 91 | Q_THRESHOLD6 = "q_threshold6" |
| 92 | Q_THRESHOLD7 = "q_threshold7" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 93 | ) |
| 94 | |
| 95 | // TechprofileFlags represents the set of configurations used |
| 96 | type TechProfileFlags struct { |
Neha Sharma | dd9af39 | 2020-04-28 09:03:57 +0000 | [diff] [blame] | 97 | KVStoreAddress string |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 98 | KVStoreType string |
Neha Sharma | 130ac6d | 2020-04-08 08:46:32 +0000 | [diff] [blame] | 99 | KVStoreTimeout time.Duration |
sbarbari | 1e3e29c | 2019-11-05 10:06:50 -0500 | [diff] [blame] | 100 | KVBackend *db.Backend |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 101 | TPKVPathPrefix string |
| 102 | TPFileKVPath string |
| 103 | TPInstanceKVPath string |
| 104 | DefaultTPName string |
| 105 | TPVersion int |
| 106 | NumGemPorts uint32 |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 107 | DefaultPbits []string |
| 108 | LogLevel int |
| 109 | DefaultTechProfileID uint32 |
| 110 | DefaultNumGemPorts uint32 |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Matteo Scandolo | 866ac58 | 2020-11-09 12:18:31 -0800 | [diff] [blame^] | 113 | func NewTechProfileFlags(KVStoreType string, KVStoreAddress string, basePathKvStore string) *TechProfileFlags { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 114 | // initialize with default values |
| 115 | var techProfileFlags = TechProfileFlags{ |
| 116 | KVBackend: nil, |
Neha Sharma | dd9af39 | 2020-04-28 09:03:57 +0000 | [diff] [blame] | 117 | KVStoreAddress: KVStoreAddress, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 118 | KVStoreType: KVStoreType, |
| 119 | KVStoreTimeout: defaultKVStoreTimeout, |
| 120 | DefaultTPName: defaultTechProfileName, |
Matteo Scandolo | 866ac58 | 2020-11-09 12:18:31 -0800 | [diff] [blame^] | 121 | TPKVPathPrefix: fmt.Sprintf(defaultKVPathPrefix, basePathKvStore), |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 122 | TPVersion: defaultVersion, |
| 123 | TPFileKVPath: defaultTechProfileKVPath, |
| 124 | TPInstanceKVPath: defaultTPInstanceKVPath, |
| 125 | DefaultTechProfileID: DEFAULT_TECH_PROFILE_TABLE_ID, |
| 126 | DefaultNumGemPorts: defaultGemportsCount, |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 127 | DefaultPbits: []string{defaultPbits}, |
| 128 | LogLevel: defaultLogLevel, |
| 129 | } |
| 130 | |
| 131 | return &techProfileFlags |
| 132 | } |