blob: 12edb9ee65ca481cd136d512542a9c439fe2334e [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
Girish Gowdra1935e6a2020-10-31 21:48:22 -070025// pcapplusplus packet decoder include files
26#include "Packet.h"
27#include "EthLayer.h"
28#include "IPv4Layer.h"
29#include "UdpLayer.h"
30#include "VlanLayer.h"
31
32#include <time.h>
33#include <arpa/inet.h>
34
Girish Gowdraddf9a162020-01-27 12:56:27 +053035extern "C"
36{
37#include <bcmolt_api.h>
38#include <bcmolt_api_model_supporting_enums.h>
39
40#include <bcmolt_api_conn_mgr.h>
41//CLI header files
42#include <bcmcli_session.h>
43#include <bcmcli.h>
44#include <bcm_api_cli.h>
45
46#include <bcmos_common.h>
47#include <bcm_config.h>
48// FIXME : dependency problem
49// #include <bcm_common_gpon.h>
50// #include <bcm_dev_log_task.h>
51}
52
Girish Gowdra5057a3d2020-05-29 18:49:56 -070053#define ALLOC_CFG_COMPLETE_WAIT_TIMEOUT 5000 // in milli-seconds
Girish Gowdraddf9a162020-01-27 12:56:27 +053054
Girish Gowdra5057a3d2020-05-29 18:49:56 -070055#define ONU_DEACTIVATE_COMPLETE_WAIT_TIMEOUT 5000 // in milli-seconds
Girish Gowdra7a79dae2020-02-10 18:22:11 +053056
Girish Gowdraddf9a162020-01-27 12:56:27 +053057
58#define MAX_ACL_ID 33
Girish Gowdra1935e6a2020-10-31 21:48:22 -070059#define MAX_ACL_WITH_VLAN_CLASSIFIER 10
60
61#define ANY_VLAN 4095
Girish Gowdraddf9a162020-01-27 12:56:27 +053062
63// **************************************//
64// Enums and structures used by the core //
65// **************************************//
66enum FLOW_CFG {
67 ONU_ID = 0,
68 FLOW_TYPE = 1,
69 SVC_PORT_ID = 2,
70 PRIORITY = 3,
71 COOKIE = 4,
72 INGRESS_INTF_TYPE= 5,
73 EGRESS_INTF_TYPE= 6,
74 INGRESS_INTF_ID = 7,
75 EGRESS_INTF_ID = 8,
76 CLASSIFIER_O_VID = 9,
77 CLASSIFIER_O_PBITS = 10,
78 CLASSIFIER_I_VID = 11,
79 CLASSIFIER_I_PBITS = 12,
80 CLASSIFIER_ETHER_TYPE = 13,
81 CLASSIFIER_IP_PROTO =14,
82 CLASSIFIER_SRC_PORT = 15,
83 CLASSIFIER_DST_PORT = 16,
84 CLASSIFIER_PKT_TAG_TYPE = 17,
85 EGRESS_QOS_TYPE = 18,
86 EGRESS_QOS_QUEUE_ID = 19,
87 EGRESS_QOS_TM_SCHED_ID = 20,
88 ACTION_CMDS_BITMASK = 21,
89 ACTION_O_VID = 22,
90 ACTION_O_PBITS = 23,
91 ACTION_I_VID = 24,
92 ACTION_I_PBITS = 25,
93 STATE = 26,
94 GROUP_ID = 27
95};
96
97enum AllocCfgAction {
98 ALLOC_OBJECT_CREATE,
99 ALLOC_OBJECT_DELETE
100};
101
102enum AllocObjectState {
103 ALLOC_OBJECT_STATE_NOT_CONFIGURED,
104 ALLOC_OBJECT_STATE_INACTIVE,
105 ALLOC_OBJECT_STATE_PROCESSING,
106 ALLOC_OBJECT_STATE_ACTIVE
107};
108
109enum AllocCfgStatus {
110 ALLOC_CFG_STATUS_SUCCESS,
111 ALLOC_CFG_STATUS_FAIL
112};
113
114typedef struct {
115 uint32_t pon_intf_id;
116 uint32_t alloc_id;
117 AllocObjectState state;
118 AllocCfgStatus status;
119} alloc_cfg_complete_result;
120
Girish Gowdra7a79dae2020-02-10 18:22:11 +0530121typedef struct {
122 uint32_t pon_intf_id;
123 uint32_t onu_id;
124 bcmolt_result result;
125 bcmolt_deactivation_fail_reason reason;
126} onu_deactivate_complete_result;
127
Girish Gowdraddf9a162020-01-27 12:56:27 +0530128// key for map used for tracking ITU PON Alloc Configuration results from BAL
129typedef std::tuple<uint32_t, uint32_t> alloc_cfg_compltd_key;
130
Girish Gowdra7a79dae2020-02-10 18:22:11 +0530131// key for map used for tracking Onu Deactivation Completed Indication
132typedef std::tuple<uint32_t, uint32_t> onu_deact_compltd_key;
133
Girish Gowdraddf9a162020-01-27 12:56:27 +0530134// The elements in this acl_classifier_key structure constitute key to
135// acl_classifier_to_acl_id_map.
136// Fill invalid values in the acl_classifier_key structure to -1.
137typedef struct acl_classifier_key {
138 int32_t ether_type;
139 int16_t ip_proto;
140 int32_t src_port;
141 int32_t dst_port;
Girish Gowdra1935e6a2020-10-31 21:48:22 -0700142 int16_t o_vid;
Girish Gowdraddf9a162020-01-27 12:56:27 +0530143 // Add more classifiers elements as needed here
144 // For now, ACLs will be classified only based on
145 // above elements.
146} acl_classifier_key;
147
Girish Gowdra252f4972020-09-07 21:24:01 -0700148typedef struct device_flow_params {
149 uint8_t pbit; // If pbit classifier is not present in flow, use 0xff to invalidate
150 uint32_t gemport_id;
151 uint16_t flow_id;
152} device_flow_params;
153
154typedef struct device_flow {
155 bool is_flow_replicated; // If true number of replicated flows is to the NUMBER_OF_PBITS, else 1
156 device_flow_params params[NUMBER_OF_REPLICATED_FLOWS]; // A voltha-flow cannot be replicated more than the number of pbits
157 uint64_t voltha_flow_id; // This is corresponding voltha flow-id.
158 uint64_t symmetric_voltha_flow_id; // Is not applicable for trap-to-controller voltha flows.
159 // 0 value means invalid or not-applicable
160 // Applicable for bi-directional data path flows (one flow per direction)
161 // Symmetric flows should share the same device_flow_id.
162
163} device_flow;
164
Orhan Kupusogluec57af02021-05-12 12:38:17 +0000165// key for map used for tracking Onu RSSI Measurement Completed Indication
166typedef std::tuple<uint32_t, uint32_t> onu_rssi_compltd_key;
167
168typedef struct {
169 uint32_t pon_intf_id;
170 uint32_t onu_id;
171 std::string status;
172 bcmolt_rssi_measurement_fail_reason reason;
173 double rx_power_mean_dbm;
174} onu_rssi_complete_result;
175
Girish Gowdraddf9a162020-01-27 12:56:27 +0530176// *******************************************************//
177// Extern Variable/Constant declarations used by the core //
178// *******************************************************//
179extern State state;
180
181extern dev_log_id openolt_log_id;
182extern dev_log_id omci_log_id;
183
184extern unsigned int num_of_nni_ports;
185extern unsigned int num_of_pon_ports;
186
187extern const uint32_t tm_upstream_sched_id_start;
188extern const uint32_t tm_downstream_sched_id_start;
189
190extern const uint32_t queue_id_list[8];
191
192extern const std::string upstream;
193extern const std::string downstream;
194extern const std::string multicast;
195extern bcmolt_oltid dev_id;
196
197extern const uint32_t BAL_API_RETRY_TIME_IN_USECS;
198extern const uint32_t MAX_BAL_API_RETRY_COUNT;
199
200extern const unsigned int OPENOLT_FIELD_LEN;
201
202/* Current session */
203extern bcmcli_session *current_session;
204extern bcmcli_entry *api_parent_dir;
205extern bcmos_bool status_bcm_cli_quit;
206extern bcmos_task bal_cli_thread;
207extern const char *bal_cli_thread_name;
208extern uint16_t flow_id_counters;
209
210extern std::map<uint32_t, uint32_t> flowid_to_port; // For mapping upstream flows to logical ports
211extern std::map<uint32_t, uint32_t> flowid_to_gemport; // For mapping downstream flows into gemports
212extern std::map<uint32_t, std::set<uint32_t> > port_to_flows; // For mapping logical ports to downstream flows
213
214/* This represents the Key to 'sched_map' map.
Burak Gurdag2f2618c2020-04-23 13:20:30 +0000215 Represents (pon_intf_id, onu_id, uni_id, direction, tech_profile_id) */
216typedef std::tuple<uint32_t, uint32_t, uint32_t, std::string, uint32_t> sched_map_key_tuple;
Girish Gowdraddf9a162020-01-27 12:56:27 +0530217/* 'sched_map' maps sched_map_key_tuple to DBA (Upstream) or
218 Subscriber (Downstream) Scheduler ID */
219extern std::map<sched_map_key_tuple, int> sched_map;
220
221/* Flow control is for flow_id and flow_type */
222typedef std::pair<uint16_t, uint16_t> flow_pair;
223extern std::map<flow_pair, int32_t> flow_map;
224
225/* This represents the Key to 'qos_type_map' map.
226 Represents (pon_intf_id, onu_id, uni_id) */
227typedef std::tuple<uint32_t, uint32_t, uint32_t> qos_type_map_key_tuple;
228/* 'qos_type_map' maps qos_type_map_key_tuple to qos_type*/
229extern std::map<qos_type_map_key_tuple, bcmolt_egress_qos_type> qos_type_map;
230
231/* This represents the Key to 'sched_qmp_id_map' map.
232Represents (sched_id, pon_intf_id, onu_id, uni_id) */
233typedef std::tuple<uint32_t, uint32_t, uint32_t, uint32_t> sched_qmp_id_map_key_tuple;
234/* 'sched_qmp_id_map' maps sched_qmp_id_map_key_tuple to TM Queue Mapping Profile ID */
235extern std::map<sched_qmp_id_map_key_tuple, int> sched_qmp_id_map;
236/* 'qmp_id_to_qmp_map' maps TM Queue Mapping Profile ID to TM Queue Mapping Profile */
237extern std::map<int, std::vector < uint32_t > > qmp_id_to_qmp_map;
238
Girish Gowdraddf9a162020-01-27 12:56:27 +0530239// Map used to track response from BAL for ITU PON Alloc Configuration.
240// The key is alloc_cfg_compltd_key and value is a concurrent thread-safe queue which is
241// used for pushing (from BAL) and popping (at application) the results.
242extern std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *> alloc_cfg_compltd_map;
Girish Gowdra7a79dae2020-02-10 18:22:11 +0530243// Map used to track response from BAL for Onu Deactivation Completed Indication
244// The key is alloc_cfg_compltd_key and value is a concurrent thread-safe queue which is
245// used for pushing (from BAL) and popping (at application) the results.
246extern std::map<onu_deact_compltd_key, Queue<onu_deactivate_complete_result> *> onu_deact_compltd_map;
247
Girish Gowdraddf9a162020-01-27 12:56:27 +0530248// Lock to protect critical section data structure used for handling AllocObject configuration response.
249extern bcmos_fastlock alloc_cfg_wait_lock;
Girish Gowdra7a79dae2020-02-10 18:22:11 +0530250// Lock to protect critical section data structure used for handling Onu deactivation completed Indication
251extern bcmos_fastlock onu_deactivate_wait_lock;
Girish Gowdraddf9a162020-01-27 12:56:27 +0530252
253
254/*** ACL Handling related data start ***/
255
256extern std::map<acl_classifier_key, uint16_t> acl_classifier_to_acl_id_map;
257extern bool operator<(const acl_classifier_key& a1, const acl_classifier_key& a2);
258
Girish Gowdra252f4972020-09-07 21:24:01 -0700259typedef std::tuple<uint64_t, std::string> flow_id_flow_direction;
260typedef std::tuple<int16_t, int32_t> acl_id_intf_id;
261extern std::map<flow_id_flow_direction, acl_id_intf_id> flow_to_acl_map;
Girish Gowdraddf9a162020-01-27 12:56:27 +0530262
263// Keeps a reference count of how many flows are referencing a given ACL ID.
264// Key represents the ACL-ID and value is number of flows referencing the given ACL-ID.
265// When there is at least one flow referencing the ACL-ID, the ACL should be installed.
266// When there are no flows referencing the ACL-ID, the ACL should be removed.
267extern std::map<uint16_t, uint16_t> acl_ref_cnt;
268
Girish Gowdraddf9a162020-01-27 12:56:27 +0530269// Needed to keep track of how many flows for a given acl_id, intf_id and intf_type are
270// installed. When there is at least on flow for this key, we should have interface registered
271// for the given ACL-ID. When there are no flows, the intf should unregister itself from
272// the ACL-ID.
273typedef std::tuple<uint16_t, uint8_t, std::string> acl_id_intf_id_intf_type;
274extern std::map<acl_id_intf_id_intf_type, uint16_t> intf_acl_registration_ref_cnt;
275
Girish Gowdra1935e6a2020-10-31 21:48:22 -0700276// Data structures to work around ACL limits on BAL -- start --
277
278enum trap_to_host_packet_type {
279 dhcpv4 = 0,
280 lldp = 1,
281 eap = 2,
282 igmpv4 = 3,
Marcos Aurelio Carrero (Furukawa)cfe3e0d2021-03-03 10:36:56 -0300283 pppoed = 4,
Girish Gowdra1935e6a2020-10-31 21:48:22 -0700284 unsupported_trap_to_host_pkt_type = 0xff
285};
286
287// Constants useful during trap-to-host packet header field classification
Marcos Aurelio Carrero (Furukawa)cfe3e0d2021-03-03 10:36:56 -0300288#define EAP_ETH_TYPE 0x888e
289#define LLDP_ETH_TYPE 0x88cc
290#define IPV4_ETH_TYPE 0x0800
291#define VLAN_ETH_TYPE 0x8100
292#define PPPoED_ETH_TYPE 0x8863
Girish Gowdra1935e6a2020-10-31 21:48:22 -0700293
294#define IGMPv4_PROTOCOL 2
295#define UDP_PROTOCOL 17
296
297#define DHCP_SERVER_SRC_PORT 67
298#define DHCP_CLIENT_SRC_PORT 68
299
300// This flag is set as soon as ACL count reaches MAX_ACL_WITH_VLAN_CLASSIFIER is hit.
301// It is not reset when ACL count comes below MAX_ACL_WITH_VLAN_CLASSIFIER again
302extern bool max_acls_with_vlan_classifiers_hit;
303
304// Tuple of -> {bcmolt_flow_interface_type, intf-id, trap_to_host_packet_type, gemport-id, c-vid}
305typedef std::tuple<int32_t, uint32_t, int32_t, int32_t, uint16_t> trap_to_host_pkt_info_with_vlan;
306
307// Tuple of -> {bcmolt_flow_interface_type, intf-id, trap_to_host_packet_type, gemport-id}
308typedef std::tuple<int32_t, uint32_t, int32_t, int32_t> trap_to_host_pkt_info;
309
310// Map of flow_id -> trap_to_host_pkt_info_with_vlan
311extern std::map<uint64_t, trap_to_host_pkt_info_with_vlan> trap_to_host_pkt_info_with_vlan_for_flow_id;
312
313// Map of trap_to_host_pkt_info -> cvid_list
314extern std::map<trap_to_host_pkt_info, std::list<uint16_t> > trap_to_host_vlan_ids_for_trap_to_host_pkt_info;
315
316// Data structures to work around ACL limits on BAL -- end --
317
Girish Gowdraddf9a162020-01-27 12:56:27 +0530318extern std::bitset<MAX_ACL_ID> acl_id_bitset;
Girish Gowdra252f4972020-09-07 21:24:01 -0700319extern bcmos_fastlock acl_id_bitset_lock;
Girish Gowdraddf9a162020-01-27 12:56:27 +0530320
321/*** ACL Handling related data end ***/
322
323extern std::bitset<MAX_TM_SCHED_ID> tm_sched_bitset;
Girish Gowdra252f4972020-09-07 21:24:01 -0700324extern bcmos_fastlock tm_sched_bitset_lock;
325
Girish Gowdraddf9a162020-01-27 12:56:27 +0530326extern std::bitset<MAX_TM_QMP_ID> tm_qmp_bitset;
Girish Gowdra252f4972020-09-07 21:24:01 -0700327extern bcmos_fastlock tm_qmp_bitset_lock;
328
329extern std::bitset<MAX_FLOW_ID> flow_id_bitset;
330extern bcmos_fastlock flow_id_bitset_lock;
331
332extern std::map<uint64_t, device_flow> voltha_flow_to_device_flow;
333extern bcmos_fastlock voltha_flow_to_device_flow_lock;
Girish Gowdraddf9a162020-01-27 12:56:27 +0530334
Girish Gowdra1935e6a2020-10-31 21:48:22 -0700335// Lock to protect critical section around handling data associated with ACL trap packet handling
336extern bcmos_fastlock acl_packet_trap_handler_lock;
337
Girish Gowdraddf9a162020-01-27 12:56:27 +0530338extern Queue<openolt::Indication> oltIndQ;
339
Girish Gowdra252f4972020-09-07 21:24:01 -0700340/*** ACL Handling related data end ***/
341
Girish Gowdraddf9a162020-01-27 12:56:27 +0530342extern bcmos_fastlock data_lock;
343
Humera Kouser6143c9e2020-06-17 22:37:31 +0530344// Interface name on which grpc server is running on
345// and this can be used to get the mac adress based on interface name.
346extern char* grpc_server_interface_name;
Orhan Kupusogluec57af02021-05-12 12:38:17 +0000347
348extern std::map<onu_rssi_compltd_key, Queue<onu_rssi_complete_result>*> onu_rssi_compltd_map;
349extern bcmos_fastlock onu_rssi_wait_lock;
Girish Gowdraddf9a162020-01-27 12:56:27 +0530350#endif // OPENOLT_CORE_DATA_H_