blob: 394bff6d73d932a98b739a87dbbfd938ff416b40 [file] [log] [blame]
Matt Jeanneretcab955f2019-04-10 15:45:57 -04001/*
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 */
16package techprofile
17
18import (
Matteo Scandoloc858ab72020-11-16 12:44:51 -080019 "fmt"
Girish Gowdra4c3d4602021-07-22 16:33:37 -070020 "github.com/opencord/voltha-lib-go/v6/pkg/db"
Neha Sharmacc656962020-04-14 14:26:11 +000021 "time"
Matt Jeanneretcab955f2019-04-10 15:45:57 -040022)
23
24// tech profile default constants
25const (
26 defaultTechProfileName = "Default_1tcont_1gem_Profile"
27 DEFAULT_TECH_PROFILE_TABLE_ID = 64
28 defaultVersion = 1.0
29 defaultLogLevel = 0
30 defaultGemportsCount = 1
Matt Jeanneretcab955f2019-04-10 15:45:57 -040031 defaultPbits = "0b11111111"
32
Neha Sharmacc656962020-04-14 14:26:11 +000033 defaultKVStoreTimeout = 5 * time.Second //in seconds
Matt Jeanneretcab955f2019-04-10 15:45:57 -040034
Matteo Scandolod9d6f512020-11-24 13:57:53 -080035 // 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 Scandoloc858ab72020-11-16 12:44:51 -080040 defaultKVPathPrefix = "%s/technology_profiles"
Matt Jeanneretcab955f2019-04-10 15:45:57 -040041
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070042 // Resource instance path prefix in KV store (for Resource Instances)
43 defaultResourceInstancePathPrefix = "%s/resource_instances"
44
Matt Jeanneretcab955f2019-04-10 15:45:57 -040045 // Tech profile path in kv store
46 defaultTechProfileKVPath = "%s/%d" // <technology>/<tech_profile_tableID>
47
Matt Jeanneretcab955f2019-04-10 15:45:57 -040048)
49
50//Tech-Profile JSON String Keys
51// NOTE: Tech profile templeate JSON file should comply with below keys
52const (
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 Suzuki2ba0e0b2020-06-05 14:23:03 -070080 // 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 Jeanneretcab955f2019-04-10 15:45:57 -040097)
98
99// TechprofileFlags represents the set of configurations used
100type TechProfileFlags struct {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700101 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 ResourceInstanceKVBacked *db.Backend // this is the backed used to read/write Resource Instances
107 TPKVPathPrefix string
108 defaultTpKvPathPrefix string
109 TPFileKVPath string
110 ResourceInstanceKVPathPrefix string
111 DefaultTPName string
112 TPVersion uint32
113 NumGemPorts uint32
114 DefaultPbits []string
115 LogLevel int
116 DefaultTechProfileID uint32
117 DefaultNumGemPorts uint32
Matt Jeanneretcab955f2019-04-10 15:45:57 -0400118}
119
Matteo Scandoloc858ab72020-11-16 12:44:51 -0800120func NewTechProfileFlags(KVStoreType string, KVStoreAddress string, basePathKvStore string) *TechProfileFlags {
Matt Jeanneretcab955f2019-04-10 15:45:57 -0400121 // initialize with default values
122 var techProfileFlags = TechProfileFlags{
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700123 KVBackend: nil,
124 KVStoreAddress: KVStoreAddress,
125 KVStoreType: KVStoreType,
126 KVStoreTimeout: defaultKVStoreTimeout,
127 DefaultTPName: defaultTechProfileName,
128 TPKVPathPrefix: fmt.Sprintf(defaultKVPathPrefix, basePathKvStore),
129 defaultTpKvPathPrefix: defaultTpKvPathPrefix,
130 TPVersion: defaultVersion,
131 TPFileKVPath: defaultTechProfileKVPath,
132 ResourceInstanceKVPathPrefix: fmt.Sprintf(defaultResourceInstancePathPrefix, basePathKvStore),
133 DefaultTechProfileID: DEFAULT_TECH_PROFILE_TABLE_ID,
134 DefaultNumGemPorts: defaultGemportsCount,
135 DefaultPbits: []string{defaultPbits},
136 LogLevel: defaultLogLevel,
Matt Jeanneretcab955f2019-04-10 15:45:57 -0400137 }
138
139 return &techProfileFlags
140}