blob: be2bffa3f791e1da1882703e6e732f8bdeab6ffd [file] [log] [blame]
Scott Baker2c1c4822019-10-16 11:02:41 -07001/*
Joey Armstrong9cdee9f2024-01-03 04:56:14 -05002* Copyright 2019-2024 Open Networking Foundation (ONF) and the ONF Contributors
Scott Baker2c1c4822019-10-16 11:02:41 -07003
Joey Armstrong7f8436c2023-07-09 20:23:27 -04004* 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 Baker2c1c4822019-10-16 11:02:41 -07007
Joey Armstrong7f8436c2023-07-09 20:23:27 -04008* http://www.apache.org/licenses/LICENSE-2.0
Scott Baker2c1c4822019-10-16 11:02:41 -07009
Joey Armstrong7f8436c2023-07-09 20:23:27 -040010* 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 Baker2c1c4822019-10-16 11:02:41 -070015 */
16package techprofile
17
18import (
Matteo Scandolo866ac582020-11-09 12:18:31 -080019 "fmt"
Neha Sharma130ac6d2020-04-08 08:46:32 +000020 "time"
khenaidoo26721882021-08-11 17:42:52 -040021
22 "github.com/opencord/voltha-lib-go/v7/pkg/db"
Scott Baker2c1c4822019-10-16 11:02:41 -070023)
24
25// tech profile default constants
26const (
27 defaultTechProfileName = "Default_1tcont_1gem_Profile"
28 DEFAULT_TECH_PROFILE_TABLE_ID = 64
29 defaultVersion = 1.0
30 defaultLogLevel = 0
31 defaultGemportsCount = 1
Scott Baker2c1c4822019-10-16 11:02:41 -070032 defaultPbits = "0b11111111"
33
Neha Sharma130ac6d2020-04-08 08:46:32 +000034 defaultKVStoreTimeout = 5 * time.Second //in seconds
Scott Baker2c1c4822019-10-16 11:02:41 -070035
Matteo Scandolof34d9082020-11-24 13:56:34 -080036 // 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 Scandolo866ac582020-11-09 12:18:31 -080041 defaultKVPathPrefix = "%s/technology_profiles"
Scott Baker2c1c4822019-10-16 11:02:41 -070042
Girish Gowdra248971a2021-06-01 15:14:15 -070043 // Resource instance path prefix in KV store (for Resource Instances)
44 defaultResourceInstancePathPrefix = "%s/resource_instances"
45
Scott Baker2c1c4822019-10-16 11:02:41 -070046 // Tech profile path in kv store
47 defaultTechProfileKVPath = "%s/%d" // <technology>/<tech_profile_tableID>
48
Scott Baker2c1c4822019-10-16 11:02:41 -070049)
50
Joey Armstrong7f8436c2023-07-09 20:23:27 -040051// Tech-Profile JSON String Keys
Scott Baker2c1c4822019-10-16 11:02:41 -070052// NOTE: Tech profile templeate JSON file should comply with below keys
53const (
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 Suzuki98cd2b92020-03-13 14:50:08 -070081 // 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 Baker2c1c4822019-10-16 11:02:41 -070098)
99
100// TechprofileFlags represents the set of configurations used
101type TechProfileFlags struct {
Girish Gowdra248971a2021-06-01 15:14:15 -0700102 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 Baker2c1c4822019-10-16 11:02:41 -0700119}
120
Matteo Scandolo866ac582020-11-09 12:18:31 -0800121func NewTechProfileFlags(KVStoreType string, KVStoreAddress string, basePathKvStore string) *TechProfileFlags {
Scott Baker2c1c4822019-10-16 11:02:41 -0700122 // initialize with default values
123 var techProfileFlags = TechProfileFlags{
Girish Gowdra248971a2021-06-01 15:14:15 -0700124 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 Baker2c1c4822019-10-16 11:02:41 -0700138 }
139
140 return &techProfileFlags
141}