blob: 322c834fe2db8e8ea60063d36125dec500c19495 [file] [log] [blame]
Girish Gowdraddf9a162020-01-27 12:56:27 +05301/*
2 * Copyright 2018-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#ifndef OPENOLT_CORE_DATA_H_
17#define OPENOLT_CORE_DATA_H_
18
19#include <bitset>
20
21#include "core.h"
22#include "Queue.h"
Girish Gowdra252f4972020-09-07 21:24:01 -070023#include "device.h"
Girish Gowdraddf9a162020-01-27 12:56:27 +053024
25extern "C"
26{
27#include <bcmolt_api.h>
28#include <bcmolt_api_model_supporting_enums.h>
29
30#include <bcmolt_api_conn_mgr.h>
31//CLI header files
32#include <bcmcli_session.h>
33#include <bcmcli.h>
34#include <bcm_api_cli.h>
35
36#include <bcmos_common.h>
37#include <bcm_config.h>
38// FIXME : dependency problem
39// #include <bcm_common_gpon.h>
40// #include <bcm_dev_log_task.h>
41}
42
Girish Gowdra5057a3d2020-05-29 18:49:56 -070043#define ALLOC_CFG_COMPLETE_WAIT_TIMEOUT 5000 // in milli-seconds
Girish Gowdraddf9a162020-01-27 12:56:27 +053044
Girish Gowdra5057a3d2020-05-29 18:49:56 -070045#define ONU_DEACTIVATE_COMPLETE_WAIT_TIMEOUT 5000 // in milli-seconds
Girish Gowdra7a79dae2020-02-10 18:22:11 +053046
Girish Gowdraddf9a162020-01-27 12:56:27 +053047
48#define MAX_ACL_ID 33
49
50// **************************************//
51// Enums and structures used by the core //
52// **************************************//
53enum FLOW_CFG {
54 ONU_ID = 0,
55 FLOW_TYPE = 1,
56 SVC_PORT_ID = 2,
57 PRIORITY = 3,
58 COOKIE = 4,
59 INGRESS_INTF_TYPE= 5,
60 EGRESS_INTF_TYPE= 6,
61 INGRESS_INTF_ID = 7,
62 EGRESS_INTF_ID = 8,
63 CLASSIFIER_O_VID = 9,
64 CLASSIFIER_O_PBITS = 10,
65 CLASSIFIER_I_VID = 11,
66 CLASSIFIER_I_PBITS = 12,
67 CLASSIFIER_ETHER_TYPE = 13,
68 CLASSIFIER_IP_PROTO =14,
69 CLASSIFIER_SRC_PORT = 15,
70 CLASSIFIER_DST_PORT = 16,
71 CLASSIFIER_PKT_TAG_TYPE = 17,
72 EGRESS_QOS_TYPE = 18,
73 EGRESS_QOS_QUEUE_ID = 19,
74 EGRESS_QOS_TM_SCHED_ID = 20,
75 ACTION_CMDS_BITMASK = 21,
76 ACTION_O_VID = 22,
77 ACTION_O_PBITS = 23,
78 ACTION_I_VID = 24,
79 ACTION_I_PBITS = 25,
80 STATE = 26,
81 GROUP_ID = 27
82};
83
84enum AllocCfgAction {
85 ALLOC_OBJECT_CREATE,
86 ALLOC_OBJECT_DELETE
87};
88
89enum AllocObjectState {
90 ALLOC_OBJECT_STATE_NOT_CONFIGURED,
91 ALLOC_OBJECT_STATE_INACTIVE,
92 ALLOC_OBJECT_STATE_PROCESSING,
93 ALLOC_OBJECT_STATE_ACTIVE
94};
95
96enum AllocCfgStatus {
97 ALLOC_CFG_STATUS_SUCCESS,
98 ALLOC_CFG_STATUS_FAIL
99};
100
101typedef struct {
102 uint32_t pon_intf_id;
103 uint32_t alloc_id;
104 AllocObjectState state;
105 AllocCfgStatus status;
106} alloc_cfg_complete_result;
107
Girish Gowdra7a79dae2020-02-10 18:22:11 +0530108typedef struct {
109 uint32_t pon_intf_id;
110 uint32_t onu_id;
111 bcmolt_result result;
112 bcmolt_deactivation_fail_reason reason;
113} onu_deactivate_complete_result;
114
Girish Gowdraddf9a162020-01-27 12:56:27 +0530115// key for map used for tracking ITU PON Alloc Configuration results from BAL
116typedef std::tuple<uint32_t, uint32_t> alloc_cfg_compltd_key;
117
Girish Gowdra7a79dae2020-02-10 18:22:11 +0530118// key for map used for tracking Onu Deactivation Completed Indication
119typedef std::tuple<uint32_t, uint32_t> onu_deact_compltd_key;
120
Girish Gowdraddf9a162020-01-27 12:56:27 +0530121// The elements in this acl_classifier_key structure constitute key to
122// acl_classifier_to_acl_id_map.
123// Fill invalid values in the acl_classifier_key structure to -1.
124typedef struct acl_classifier_key {
125 int32_t ether_type;
126 int16_t ip_proto;
127 int32_t src_port;
128 int32_t dst_port;
129 // Add more classifiers elements as needed here
130 // For now, ACLs will be classified only based on
131 // above elements.
132} acl_classifier_key;
133
Girish Gowdra252f4972020-09-07 21:24:01 -0700134typedef struct device_flow_params {
135 uint8_t pbit; // If pbit classifier is not present in flow, use 0xff to invalidate
136 uint32_t gemport_id;
137 uint16_t flow_id;
138} device_flow_params;
139
140typedef struct device_flow {
141 bool is_flow_replicated; // If true number of replicated flows is to the NUMBER_OF_PBITS, else 1
142 device_flow_params params[NUMBER_OF_REPLICATED_FLOWS]; // A voltha-flow cannot be replicated more than the number of pbits
143 uint64_t voltha_flow_id; // This is corresponding voltha flow-id.
144 uint64_t symmetric_voltha_flow_id; // Is not applicable for trap-to-controller voltha flows.
145 // 0 value means invalid or not-applicable
146 // Applicable for bi-directional data path flows (one flow per direction)
147 // Symmetric flows should share the same device_flow_id.
148
149} device_flow;
150
Girish Gowdraddf9a162020-01-27 12:56:27 +0530151// *******************************************************//
152// Extern Variable/Constant declarations used by the core //
153// *******************************************************//
154extern State state;
155
156extern dev_log_id openolt_log_id;
157extern dev_log_id omci_log_id;
158
159extern unsigned int num_of_nni_ports;
160extern unsigned int num_of_pon_ports;
161
162extern const uint32_t tm_upstream_sched_id_start;
163extern const uint32_t tm_downstream_sched_id_start;
164
165extern const uint32_t queue_id_list[8];
166
167extern const std::string upstream;
168extern const std::string downstream;
169extern const std::string multicast;
170extern bcmolt_oltid dev_id;
171
172extern const uint32_t BAL_API_RETRY_TIME_IN_USECS;
173extern const uint32_t MAX_BAL_API_RETRY_COUNT;
174
175extern const unsigned int OPENOLT_FIELD_LEN;
176
177/* Current session */
178extern bcmcli_session *current_session;
179extern bcmcli_entry *api_parent_dir;
180extern bcmos_bool status_bcm_cli_quit;
181extern bcmos_task bal_cli_thread;
182extern const char *bal_cli_thread_name;
183extern uint16_t flow_id_counters;
184
185extern std::map<uint32_t, uint32_t> flowid_to_port; // For mapping upstream flows to logical ports
186extern std::map<uint32_t, uint32_t> flowid_to_gemport; // For mapping downstream flows into gemports
187extern std::map<uint32_t, std::set<uint32_t> > port_to_flows; // For mapping logical ports to downstream flows
188
189/* This represents the Key to 'sched_map' map.
Burak Gurdag2f2618c2020-04-23 13:20:30 +0000190 Represents (pon_intf_id, onu_id, uni_id, direction, tech_profile_id) */
191typedef std::tuple<uint32_t, uint32_t, uint32_t, std::string, uint32_t> sched_map_key_tuple;
Girish Gowdraddf9a162020-01-27 12:56:27 +0530192/* 'sched_map' maps sched_map_key_tuple to DBA (Upstream) or
193 Subscriber (Downstream) Scheduler ID */
194extern std::map<sched_map_key_tuple, int> sched_map;
195
196/* Flow control is for flow_id and flow_type */
197typedef std::pair<uint16_t, uint16_t> flow_pair;
198extern std::map<flow_pair, int32_t> flow_map;
199
200/* This represents the Key to 'qos_type_map' map.
201 Represents (pon_intf_id, onu_id, uni_id) */
202typedef std::tuple<uint32_t, uint32_t, uint32_t> qos_type_map_key_tuple;
203/* 'qos_type_map' maps qos_type_map_key_tuple to qos_type*/
204extern std::map<qos_type_map_key_tuple, bcmolt_egress_qos_type> qos_type_map;
205
206/* This represents the Key to 'sched_qmp_id_map' map.
207Represents (sched_id, pon_intf_id, onu_id, uni_id) */
208typedef std::tuple<uint32_t, uint32_t, uint32_t, uint32_t> sched_qmp_id_map_key_tuple;
209/* 'sched_qmp_id_map' maps sched_qmp_id_map_key_tuple to TM Queue Mapping Profile ID */
210extern std::map<sched_qmp_id_map_key_tuple, int> sched_qmp_id_map;
211/* 'qmp_id_to_qmp_map' maps TM Queue Mapping Profile ID to TM Queue Mapping Profile */
212extern std::map<int, std::vector < uint32_t > > qmp_id_to_qmp_map;
213
Girish Gowdraddf9a162020-01-27 12:56:27 +0530214// Map used to track response from BAL for ITU PON Alloc Configuration.
215// The key is alloc_cfg_compltd_key and value is a concurrent thread-safe queue which is
216// used for pushing (from BAL) and popping (at application) the results.
217extern std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *> alloc_cfg_compltd_map;
Girish Gowdra7a79dae2020-02-10 18:22:11 +0530218// Map used to track response from BAL for Onu Deactivation Completed Indication
219// The key is alloc_cfg_compltd_key and value is a concurrent thread-safe queue which is
220// used for pushing (from BAL) and popping (at application) the results.
221extern std::map<onu_deact_compltd_key, Queue<onu_deactivate_complete_result> *> onu_deact_compltd_map;
222
Girish Gowdraddf9a162020-01-27 12:56:27 +0530223// Lock to protect critical section data structure used for handling AllocObject configuration response.
224extern bcmos_fastlock alloc_cfg_wait_lock;
Girish Gowdra7a79dae2020-02-10 18:22:11 +0530225// Lock to protect critical section data structure used for handling Onu deactivation completed Indication
226extern bcmos_fastlock onu_deactivate_wait_lock;
Girish Gowdraddf9a162020-01-27 12:56:27 +0530227
228
229/*** ACL Handling related data start ***/
230
231extern std::map<acl_classifier_key, uint16_t> acl_classifier_to_acl_id_map;
232extern bool operator<(const acl_classifier_key& a1, const acl_classifier_key& a2);
233
Girish Gowdra252f4972020-09-07 21:24:01 -0700234typedef std::tuple<uint64_t, std::string> flow_id_flow_direction;
235typedef std::tuple<int16_t, int32_t> acl_id_intf_id;
236extern std::map<flow_id_flow_direction, acl_id_intf_id> flow_to_acl_map;
Girish Gowdraddf9a162020-01-27 12:56:27 +0530237
238// Keeps a reference count of how many flows are referencing a given ACL ID.
239// Key represents the ACL-ID and value is number of flows referencing the given ACL-ID.
240// When there is at least one flow referencing the ACL-ID, the ACL should be installed.
241// When there are no flows referencing the ACL-ID, the ACL should be removed.
242extern std::map<uint16_t, uint16_t> acl_ref_cnt;
243
Girish Gowdraddf9a162020-01-27 12:56:27 +0530244// Needed to keep track of how many flows for a given acl_id, intf_id and intf_type are
245// installed. When there is at least on flow for this key, we should have interface registered
246// for the given ACL-ID. When there are no flows, the intf should unregister itself from
247// the ACL-ID.
248typedef std::tuple<uint16_t, uint8_t, std::string> acl_id_intf_id_intf_type;
249extern std::map<acl_id_intf_id_intf_type, uint16_t> intf_acl_registration_ref_cnt;
250
251extern std::bitset<MAX_ACL_ID> acl_id_bitset;
Girish Gowdra252f4972020-09-07 21:24:01 -0700252extern bcmos_fastlock acl_id_bitset_lock;
Girish Gowdraddf9a162020-01-27 12:56:27 +0530253
254/*** ACL Handling related data end ***/
255
256extern std::bitset<MAX_TM_SCHED_ID> tm_sched_bitset;
Girish Gowdra252f4972020-09-07 21:24:01 -0700257extern bcmos_fastlock tm_sched_bitset_lock;
258
Girish Gowdraddf9a162020-01-27 12:56:27 +0530259extern std::bitset<MAX_TM_QMP_ID> tm_qmp_bitset;
Girish Gowdra252f4972020-09-07 21:24:01 -0700260extern bcmos_fastlock tm_qmp_bitset_lock;
261
262extern std::bitset<MAX_FLOW_ID> flow_id_bitset;
263extern bcmos_fastlock flow_id_bitset_lock;
264
265extern std::map<uint64_t, device_flow> voltha_flow_to_device_flow;
266extern bcmos_fastlock voltha_flow_to_device_flow_lock;
Girish Gowdraddf9a162020-01-27 12:56:27 +0530267
268extern Queue<openolt::Indication> oltIndQ;
269
Girish Gowdra252f4972020-09-07 21:24:01 -0700270/*** ACL Handling related data end ***/
271
Girish Gowdraddf9a162020-01-27 12:56:27 +0530272extern bcmos_fastlock data_lock;
273
Humera Kouser6143c9e2020-06-17 22:37:31 +0530274// Interface name on which grpc server is running on
275// and this can be used to get the mac adress based on interface name.
276extern char* grpc_server_interface_name;
Girish Gowdraddf9a162020-01-27 12:56:27 +0530277#endif // OPENOLT_CORE_DATA_H_