blob: 644ddec100ecb45dd848bf2e05467eff3278fd6c [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_UTILS_H_
17#define OPENOLT_CORE_UTILS_H_
18#include <string>
19#include <unistd.h>
Thiyagarajan Subramani03bc66f2020-04-01 15:58:53 +053020#include <ifaddrs.h>
21#include <arpa/inet.h>
Humera Kouser6143c9e2020-06-17 22:37:31 +053022#include <sys/ioctl.h>
23#include <net/if.h>
Girish Gowdraddf9a162020-01-27 12:56:27 +053024
25#include "core.h"
26#include "core_data.h"
27#include "error_format.h"
Orhan Kupusoglu1fd77072021-03-23 08:13:25 -070028#include <grpc/grpc_security_constants.h>
Girish Gowdraddf9a162020-01-27 12:56:27 +053029
30extern "C"
31{
32#include <bcmolt_api.h>
33#include <bcmolt_host_api.h>
34#include <bcmolt_api_model_supporting_enums.h>
35#include <bcmolt_api_model_supporting_structs.h>
36
37#include <bcmolt_api_conn_mgr.h>
38//CLI header files
39#include <bcmcli_session.h>
40#include <bcmcli.h>
41#include <bcm_api_cli.h>
42
43#include <bcmos_common.h>
44#include <bcm_config.h>
45// FIXME : dependency problem
46// #include <bcm_common_gpon.h>
47// #include <bcm_dev_log_task.h>
48}
49
50
51std::string serial_number_to_str(bcmolt_serial_number* serial_number);
52std::string vendor_specific_to_str(const char* const serial_number);
53uint16_t get_dev_id(void);
54int get_default_tm_sched_id(int intf_id, std::string direction);
Burak Gurdag2f2618c2020-04-23 13:20:30 +000055uint32_t get_tm_sched_id(int pon_intf_id, int onu_id, int uni_id, std::string direction, int tech_profile_id);
56void free_tm_sched_id(int pon_intf_id, int onu_id, int uni_id, std::string direction, int tech_profile_id);
57bool is_tm_sched_id_present(int pon_intf_id, int onu_id, int uni_id, std::string direction, int tech_profile_id);
Girish Gowdraddf9a162020-01-27 12:56:27 +053058bool check_tm_qmp_equality(std::vector<uint32_t> tmq_map_profileA, std::vector<uint32_t> tmq_map_profileB);
59std::string* get_valid_queues_pbit_map(std::string *queues_pbit_map, uint32_t size);
60std::vector<uint32_t> get_tmq_map_profile(std::string *queues_pbit_map, uint32_t *queues_priority_q, uint32_t size);
61int get_tm_qmp_id(std::vector<uint32_t> tmq_map_profile);
62void update_sched_qmp_id_map(uint32_t sched_id,uint32_t pon_intf_id, uint32_t onu_id,
63 uint32_t uni_id, int tm_qmp_id);
64int get_tm_qmp_id(uint32_t sched_id,uint32_t pon_intf_id, uint32_t onu_id, uint32_t uni_id);
65int get_tm_qmp_id(uint32_t sched_id,uint32_t pon_intf_id, uint32_t onu_id, uint32_t uni_id,
66 std::vector<uint32_t> tmq_map_profile);
67bool free_tm_qmp_id(uint32_t sched_id,uint32_t pon_intf_id, uint32_t onu_id,
68 uint32_t uni_id, int tm_qmp_id);
69int get_acl_id();
70void free_acl_id (int acl_id);
Girish Gowdra252f4972020-09-07 21:24:01 -070071uint16_t get_flow_id();
72bool get_flow_ids(int num_of_flow_ids, uint16_t *flow_ids);
73void free_flow_id (uint16_t flow_id);
74void free_flow_ids(uint8_t num_flows, uint16_t *flow_ids);
Girish Gowdraddf9a162020-01-27 12:56:27 +053075std::string get_qos_type_as_string(bcmolt_egress_qos_type qos_type);
76bcmolt_egress_qos_type get_qos_type(uint32_t pon_intf_id, uint32_t onu_id, uint32_t uni_id, uint32_t queue_size=0);
77void clear_qos_type(uint32_t pon_intf_id, uint32_t onu_id, uint32_t uni_id);
78std::string GetDirection(int direction);
79bcmos_errno wait_for_alloc_action(uint32_t intf_id, uint32_t alloc_id, AllocCfgAction action);
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +053080bcmos_errno wait_for_gem_action(uint32_t intf_id, uint32_t gem_port_id, GemCfgAction action);
Girish Gowdra7a79dae2020-02-10 18:22:11 +053081bcmos_errno wait_for_onu_deactivate_complete(uint32_t intf_id, uint32_t onu_id);
Girish Gowdraddf9a162020-01-27 12:56:27 +053082char* openolt_read_sysinfo(const char* field_name, char* field_val);
83Status pushOltOperInd(uint32_t intf_id, const char *type, const char *state);
84void openolt_cli_get_prompt_cb(bcmcli_session *session, char *buf, uint32_t max_len);
85int _bal_apiend_cli_thread_handler(long data);
86bcmos_errno bcm_openolt_api_cli_init(bcmcli_entry *parent_dir, bcmcli_session *session);
87bcmos_errno bcm_cli_quit(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t n_parms);
88int get_status_bcm_cli_quit(void);
89bcmos_errno bcmolt_apiend_cli_init();
Thiyagarajan Subramaniad463232020-02-28 19:10:43 +053090bcmos_errno get_pon_interface_status(bcmolt_interface pon_ni, bcmolt_interface_state *state, bcmolt_status *los_status);
Girish Gowdra72cbee92021-11-05 15:16:18 -070091bcmos_errno get_onu_state(bcmolt_interface pon_ni, int onu_id, bcmolt_onu_state *onu_state);
nikesh.krishnan331d38c2023-04-06 03:24:53 +053092bcmos_errno get_gpon_onu_info(bcmolt_interface pon_ni, int onu_id, bcmolt_onu_state *onu_state, bcmolt_status *losi, bcmolt_status *lofi,bcmolt_status *loami);
Girish Gowdraddf9a162020-01-27 12:56:27 +053093bcmos_errno bcmolt_cfg_get_mult_retry(bcmolt_oltid olt, bcmolt_cfg *cfg);
94unsigned NumNniIf_();
95unsigned NumPonIf_();
96bcmos_errno get_nni_interface_status(bcmolt_interface id, bcmolt_interface_state *state);
Elia Battiston869a5de2022-02-08 11:40:58 +010097bcmos_errno get_nni_interface_speed(bcmolt_interface id, uint32_t *speed);
Thiyagarajan Subramani19168f52021-05-25 23:26:41 +053098Status install_gem_port(int32_t intf_id, int32_t onu_id, int32_t uni_id, int32_t gemport_id, std::string board_technology);
99Status remove_gem_port(int32_t intf_id, int32_t onu_id, int32_t uni_id, int32_t gemport_id, std::string board_technology);
100Status enable_encryption_for_gem_port(int32_t intf_id, int32_t gemport_id, std::string board_technology);
Girish Gowdraddf9a162020-01-27 12:56:27 +0530101Status update_acl_interface(int32_t intf_id, bcmolt_interface_type intf_type, uint32_t access_control_id,
102 bcmolt_members_update_command acl_cmd);
103Status install_acl(const acl_classifier_key acl_key);
104Status remove_acl(int acl_id);
105void formulate_acl_classifier_key(acl_classifier_key *key, const ::openolt::Classifier& classifier);
Girish Gowdra1935e6a2020-10-31 21:48:22 -0700106Status handle_acl_rule_install(int32_t onu_id, uint64_t flow_id, int32_t gemport_id,
Girish Gowdraddf9a162020-01-27 12:56:27 +0530107 const std::string flow_type, int32_t access_intf_id,
Girish Gowdra252f4972020-09-07 21:24:01 -0700108 int32_t network_intf_id,
Girish Gowdraddf9a162020-01-27 12:56:27 +0530109 const ::openolt::Classifier& classifier);
110void clear_gem_port(int gemport_id, int access_intf_id);
Girish Gowdra252f4972020-09-07 21:24:01 -0700111Status handle_acl_rule_cleanup(int16_t acl_id, int32_t intf_id, const std::string flow_type);
Girish Gowdraddf9a162020-01-27 12:56:27 +0530112Status check_bal_ready();
113Status check_connection();
Thiyagarajan Subramani03bc66f2020-04-01 15:58:53 +0530114std::string get_ip_address(const char* nw_intf);
Jason Huang1d9cfce2020-05-20 22:58:47 +0800115bcmos_errno getOnuMaxLogicalDistance(uint32_t intf_id, uint32_t *mld);
Humera Kouser6143c9e2020-06-17 22:37:31 +0530116char* get_intf_mac(const char* intf_name, char* mac_address, unsigned int max_size_of_mac_address);
Girish Gowdra252f4972020-09-07 21:24:01 -0700117void update_voltha_flow_to_cache(uint64_t voltha_flow_id, device_flow dev_flow);
118void remove_voltha_flow_from_cache(uint64_t voltha_flow_id);
119bool is_voltha_flow_installed(uint64_t voltha_flow_id );
120const device_flow* get_device_flow(uint64_t voltha_flow_id);
121const device_flow_params* get_device_flow_params(uint64_t voltha_flow_id);
Girish Gowdra1935e6a2020-10-31 21:48:22 -0700122trap_to_host_packet_type get_trap_to_host_packet_type(const ::openolt::Classifier& classifier);
123bool is_packet_allowed(bcmolt_access_control_receive_eth_packet_data *data, int32_t gemport_id);
Orhan Kupusoglu1fd77072021-03-23 08:13:25 -0700124std::pair<grpc_ssl_client_certificate_request_type, bool> get_grpc_tls_option(const char* tls_option);
125const std::string &get_grpc_tls_option();
126bool is_grpc_secure();
127std::pair<std::string, bool> read_from_txt_file(const std::string& file_name);
Orhan Kupusogluec57af02021-05-12 12:38:17 +0000128bool save_to_txt_file(const std::string& file_name, const std::string& content);
Girish Gowdracdd5e5f2021-12-05 16:48:08 +0530129bcmos_errno get_gem_obj_state(bcmolt_interface pon_ni, bcmolt_gem_port_id id, bcmolt_activation_state *state);
130bcmos_errno get_alloc_obj_state(bcmolt_interface pon_ni, bcmolt_alloc_id id, bcmolt_activation_state *state);
Girish Gowdrab0337eb2022-03-25 16:44:21 -0700131pair<string, bool> hex_to_ascii_string(unsigned char* ptr, int length);
132pair<uint32_t, bool> hex_to_uinteger(unsigned char *ptr, int length);
Girish Gowdraddf9a162020-01-27 12:56:27 +0530133#endif // OPENOLT_CORE_UTILS_H_