blob: 5c900f5ab9704cdf0fbbb15af703f6f7ff696d77 [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"
23
24extern "C"
25{
26#include <bcmolt_api.h>
27#include <bcmolt_api_model_supporting_enums.h>
28
29#include <bcmolt_api_conn_mgr.h>
30//CLI header files
31#include <bcmcli_session.h>
32#include <bcmcli.h>
33#include <bcm_api_cli.h>
34
35#include <bcmos_common.h>
36#include <bcm_config.h>
37// FIXME : dependency problem
38// #include <bcm_common_gpon.h>
39// #include <bcm_dev_log_task.h>
40}
41
42#define ALLOC_CFG_COMPLETE_WAIT_TIMEOUT 1000 // in milli-seconds
43
44#define MIN_ALLOC_ID_GPON 256
45#define MIN_ALLOC_ID_XGSPON 1024
46
47#define MAX_ACL_ID 33
48
49// **************************************//
50// Enums and structures used by the core //
51// **************************************//
52enum FLOW_CFG {
53 ONU_ID = 0,
54 FLOW_TYPE = 1,
55 SVC_PORT_ID = 2,
56 PRIORITY = 3,
57 COOKIE = 4,
58 INGRESS_INTF_TYPE= 5,
59 EGRESS_INTF_TYPE= 6,
60 INGRESS_INTF_ID = 7,
61 EGRESS_INTF_ID = 8,
62 CLASSIFIER_O_VID = 9,
63 CLASSIFIER_O_PBITS = 10,
64 CLASSIFIER_I_VID = 11,
65 CLASSIFIER_I_PBITS = 12,
66 CLASSIFIER_ETHER_TYPE = 13,
67 CLASSIFIER_IP_PROTO =14,
68 CLASSIFIER_SRC_PORT = 15,
69 CLASSIFIER_DST_PORT = 16,
70 CLASSIFIER_PKT_TAG_TYPE = 17,
71 EGRESS_QOS_TYPE = 18,
72 EGRESS_QOS_QUEUE_ID = 19,
73 EGRESS_QOS_TM_SCHED_ID = 20,
74 ACTION_CMDS_BITMASK = 21,
75 ACTION_O_VID = 22,
76 ACTION_O_PBITS = 23,
77 ACTION_I_VID = 24,
78 ACTION_I_PBITS = 25,
79 STATE = 26,
80 GROUP_ID = 27
81};
82
83enum AllocCfgAction {
84 ALLOC_OBJECT_CREATE,
85 ALLOC_OBJECT_DELETE
86};
87
88enum AllocObjectState {
89 ALLOC_OBJECT_STATE_NOT_CONFIGURED,
90 ALLOC_OBJECT_STATE_INACTIVE,
91 ALLOC_OBJECT_STATE_PROCESSING,
92 ALLOC_OBJECT_STATE_ACTIVE
93};
94
95enum AllocCfgStatus {
96 ALLOC_CFG_STATUS_SUCCESS,
97 ALLOC_CFG_STATUS_FAIL
98};
99
100typedef struct {
101 uint32_t pon_intf_id;
102 uint32_t alloc_id;
103 AllocObjectState state;
104 AllocCfgStatus status;
105} alloc_cfg_complete_result;
106
107// key for map used for tracking ITU PON Alloc Configuration results from BAL
108typedef std::tuple<uint32_t, uint32_t> alloc_cfg_compltd_key;
109
110// The elements in this acl_classifier_key structure constitute key to
111// acl_classifier_to_acl_id_map.
112// Fill invalid values in the acl_classifier_key structure to -1.
113typedef struct acl_classifier_key {
114 int32_t ether_type;
115 int16_t ip_proto;
116 int32_t src_port;
117 int32_t dst_port;
118 // Add more classifiers elements as needed here
119 // For now, ACLs will be classified only based on
120 // above elements.
121} acl_classifier_key;
122
123// *******************************************************//
124// Extern Variable/Constant declarations used by the core //
125// *******************************************************//
126extern State state;
127
128extern dev_log_id openolt_log_id;
129extern dev_log_id omci_log_id;
130
131extern unsigned int num_of_nni_ports;
132extern unsigned int num_of_pon_ports;
133
134extern const uint32_t tm_upstream_sched_id_start;
135extern const uint32_t tm_downstream_sched_id_start;
136
137extern const uint32_t queue_id_list[8];
138
139extern const std::string upstream;
140extern const std::string downstream;
141extern const std::string multicast;
142extern bcmolt_oltid dev_id;
143
144extern const uint32_t BAL_API_RETRY_TIME_IN_USECS;
145extern const uint32_t MAX_BAL_API_RETRY_COUNT;
146
147extern const unsigned int OPENOLT_FIELD_LEN;
148
149/* Current session */
150extern bcmcli_session *current_session;
151extern bcmcli_entry *api_parent_dir;
152extern bcmos_bool status_bcm_cli_quit;
153extern bcmos_task bal_cli_thread;
154extern const char *bal_cli_thread_name;
155extern uint16_t flow_id_counters;
156
157extern std::map<uint32_t, uint32_t> flowid_to_port; // For mapping upstream flows to logical ports
158extern std::map<uint32_t, uint32_t> flowid_to_gemport; // For mapping downstream flows into gemports
159extern std::map<uint32_t, std::set<uint32_t> > port_to_flows; // For mapping logical ports to downstream flows
160
161/* This represents the Key to 'sched_map' map.
162 Represents (pon_intf_id, onu_id, uni_id, direction) */
163typedef std::tuple<uint32_t, uint32_t, uint32_t, std::string> sched_map_key_tuple;
164/* 'sched_map' maps sched_map_key_tuple to DBA (Upstream) or
165 Subscriber (Downstream) Scheduler ID */
166extern std::map<sched_map_key_tuple, int> sched_map;
167
168/* Flow control is for flow_id and flow_type */
169typedef std::pair<uint16_t, uint16_t> flow_pair;
170extern std::map<flow_pair, int32_t> flow_map;
171
172/* This represents the Key to 'qos_type_map' map.
173 Represents (pon_intf_id, onu_id, uni_id) */
174typedef std::tuple<uint32_t, uint32_t, uint32_t> qos_type_map_key_tuple;
175/* 'qos_type_map' maps qos_type_map_key_tuple to qos_type*/
176extern std::map<qos_type_map_key_tuple, bcmolt_egress_qos_type> qos_type_map;
177
178/* This represents the Key to 'sched_qmp_id_map' map.
179Represents (sched_id, pon_intf_id, onu_id, uni_id) */
180typedef std::tuple<uint32_t, uint32_t, uint32_t, uint32_t> sched_qmp_id_map_key_tuple;
181/* 'sched_qmp_id_map' maps sched_qmp_id_map_key_tuple to TM Queue Mapping Profile ID */
182extern std::map<sched_qmp_id_map_key_tuple, int> sched_qmp_id_map;
183/* 'qmp_id_to_qmp_map' maps TM Queue Mapping Profile ID to TM Queue Mapping Profile */
184extern std::map<int, std::vector < uint32_t > > qmp_id_to_qmp_map;
185
186// Flag used to watch whether mocked alloc_cfg_compltd_key is added to alloc_cfg_compltd_map
187#ifdef TEST_MODE
188extern bool ALLOC_CFG_FLAG;
189#endif
190
191// Map used to track response from BAL for ITU PON Alloc Configuration.
192// The key is alloc_cfg_compltd_key and value is a concurrent thread-safe queue which is
193// used for pushing (from BAL) and popping (at application) the results.
194extern std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *> alloc_cfg_compltd_map;
195// Lock to protect critical section data structure used for handling AllocObject configuration response.
196extern bcmos_fastlock alloc_cfg_wait_lock;
197
198
199/*** ACL Handling related data start ***/
200
201extern std::map<acl_classifier_key, uint16_t> acl_classifier_to_acl_id_map;
202extern bool operator<(const acl_classifier_key& a1, const acl_classifier_key& a2);
203
204typedef std::tuple<uint16_t, std::string> flow_id_flow_direction;
205typedef std::tuple<int16_t, uint16_t, int32_t> acl_id_gem_id_intf_id;
206extern std::map<flow_id_flow_direction, acl_id_gem_id_intf_id> flow_to_acl_map;
207
208// Keeps a reference count of how many flows are referencing a given ACL ID.
209// Key represents the ACL-ID and value is number of flows referencing the given ACL-ID.
210// When there is at least one flow referencing the ACL-ID, the ACL should be installed.
211// When there are no flows referencing the ACL-ID, the ACL should be removed.
212extern std::map<uint16_t, uint16_t> acl_ref_cnt;
213
214typedef std::tuple<uint16_t, uint16_t> gem_id_intf_id; // key to gem_ref_cnt
215// Keeps a reference count of how many ACL related flows are referencing a given (gem-id, pon_intf_id).
216// When there is at least on flow, we should install the gem. When there are no flows
217// the gem should be removed.
218extern std::map<gem_id_intf_id, uint16_t> gem_ref_cnt;
219
220// Needed to keep track of how many flows for a given acl_id, intf_id and intf_type are
221// installed. When there is at least on flow for this key, we should have interface registered
222// for the given ACL-ID. When there are no flows, the intf should unregister itself from
223// the ACL-ID.
224typedef std::tuple<uint16_t, uint8_t, std::string> acl_id_intf_id_intf_type;
225extern std::map<acl_id_intf_id_intf_type, uint16_t> intf_acl_registration_ref_cnt;
226
227extern std::bitset<MAX_ACL_ID> acl_id_bitset;
228
229/*** ACL Handling related data end ***/
230
231extern std::bitset<MAX_TM_SCHED_ID> tm_sched_bitset;
232extern std::bitset<MAX_TM_QMP_ID> tm_qmp_bitset;
233
234extern Queue<openolt::Indication> oltIndQ;
235
236extern bcmos_fastlock data_lock;
237
238
239#endif // OPENOLT_CORE_DATA_H_