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