blob: 438ea4a99b03bd4bcc8682084b38648fb1509357 [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 Gowdraa09aeab2020-09-14 16:30:52 -070020 "github.com/opencord/voltha-lib-go/v4/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
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
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 {
Matteo Scandolod9d6f512020-11-24 13:57:53 -0800101 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 Jeanneretcab955f2019-04-10 15:45:57 -0400117}
118
Matteo Scandoloc858ab72020-11-16 12:44:51 -0800119func NewTechProfileFlags(KVStoreType string, KVStoreAddress string, basePathKvStore string) *TechProfileFlags {
Matt Jeanneretcab955f2019-04-10 15:45:57 -0400120 // initialize with default values
121 var techProfileFlags = TechProfileFlags{
Matteo Scandolod9d6f512020-11-24 13:57:53 -0800122 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 Jeanneretcab955f2019-04-10 15:45:57 -0400136 }
137
138 return &techProfileFlags
139}