blob: d301a019c81b3659db1d7283d77686b5fc405ce1 [file] [log] [blame]
Shad Ansarib7b0ced2018-05-11 21:53:32 +00001/*
Girish Gowdraa707e7c2019-11-07 11:36:13 +05302 * Copyright 2018-present Open Networking Foundation
Shad Ansarib7b0ced2018-05-11 21:53:32 +00003
Girish Gowdraa707e7c2019-11-07 11:36:13 +05304 * 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
Shad Ansarib7b0ced2018-05-11 21:53:32 +00007
Girish Gowdraa707e7c2019-11-07 11:36:13 +05308 * http://www.apache.org/licenses/LICENSE-2.0
Shad Ansarib7b0ced2018-05-11 21:53:32 +00009
Girish Gowdraa707e7c2019-11-07 11:36:13 +053010 * 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 */
Shad Ansarib7b0ced2018-05-11 21:53:32 +000016
17#ifndef OPENOLT_CORE_H_
18#define OPENOLT_CORE_H_
19
20#include <grpc++/grpc++.h>
21using grpc::Status;
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000022#include <voltha_protos/openolt.grpc.pb.h>
kesavandc1f2db92020-08-31 15:32:06 +053023#include <voltha_protos/ext_config.grpc.pb.h>
Shad Ansarib7b0ced2018-05-11 21:53:32 +000024
Shad Ansariedef2132018-08-10 22:14:50 +000025#include "state.h"
26
Girish Gowdraddf9a162020-01-27 12:56:27 +053027extern "C"
28{
29#include <bcmolt_api.h>
30#include <bcmolt_api_model_supporting_enums.h>
31
32#include <bcmolt_api_conn_mgr.h>
33//CLI header files
34#include <bcmcli_session.h>
35#include <bcmcli.h>
36#include <bcm_api_cli.h>
37
38#include <bcmos_common.h>
39#include <bcm_config.h>
40// FIXME : dependency problem
41// #include <bcm_common_gpon.h>
42// #include <bcm_dev_log_task.h>
43}
44// ************************//
45// Macros used by the core //
46// ************************//
47
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +000048#define NONE "\033[m"
49#define LIGHT_RED "\033[1;31m"
50#define BROWN "\033[0;33m"
51#define LIGHT_GREEN "\033[1;32m"
52#define OPENOLT_LOG(level, id, fmt, ...) \
53 if (DEV_LOG_LEVEL_##level == DEV_LOG_LEVEL_ERROR) \
54 BCM_LOG(level, id, "%s" fmt "%s", LIGHT_RED, ##__VA_ARGS__, NONE); \
55 else if (DEV_LOG_LEVEL_##level == DEV_LOG_LEVEL_INFO) \
56 BCM_LOG(level, id, "%s" fmt "%s", NONE, ##__VA_ARGS__, NONE); \
57 else if (DEV_LOG_LEVEL_##level == DEV_LOG_LEVEL_WARNING) \
58 BCM_LOG(level, id, "%s" fmt "%s", BROWN, ##__VA_ARGS__, NONE); \
59 else if (DEV_LOG_LEVEL_##level == DEV_LOG_LEVEL_DEBUG) \
60 BCM_LOG(level, id, "%s" fmt "%s", LIGHT_GREEN, ##__VA_ARGS__, NONE); \
61 else \
62 BCM_LOG(INFO, id, fmt, ##__VA_ARGS__);
Girish Gowdraddf9a162020-01-27 12:56:27 +053063
64
65#define ACL_LOG(level,msg,err) \
66 do { \
67 OPENOLT_LOG(level, openolt_log_id, "--------> %s (acl_id %d) err: %d <--------\n", msg, key.id, err); \
68 OPENOLT_LOG(level, openolt_log_id, "action_type %s\n", \
69 GET_ACL_ACTION_TYPE(action_type)); \
70 OPENOLT_LOG(level, openolt_log_id, "classifier(ether type %d), ip_proto %d, src_port %d, dst_port %d\n", \
71 acl_key.ether_type, acl_key.ip_proto, acl_key.src_port, acl_key.dst_port); \
72 } while(0)
73
74#define FLOW_LOG(level,msg,err) \
75 do { \
76 OPENOLT_LOG(level, openolt_log_id, "--------> %s (flow_id %d) err: %d <--------\n", msg, key.flow_id, err); \
77 OPENOLT_LOG(level, openolt_log_id, "intf_id %d, onu_id %d, uni_id %d, port_no %u, cookie %"PRIu64"\n", \
78 access_intf_id, onu_id, uni_id, port_no, cookie); \
79 OPENOLT_LOG(level, openolt_log_id, "flow_type %s, queue_id %d, sched_id %d\n", flow_type.c_str(), \
80 cfg.data.egress_qos.u.fixed_queue.queue_id, cfg.data.egress_qos.tm_sched.id); \
81 OPENOLT_LOG(level, openolt_log_id, "Ingress(intfd_type %s, intf_id %d), Egress(intf_type %s, intf_id %d)\n", \
82 GET_FLOW_INTERFACE_TYPE(cfg.data.ingress_intf.intf_type), cfg.data.ingress_intf.intf_id, \
83 GET_FLOW_INTERFACE_TYPE(cfg.data.egress_intf.intf_type), cfg.data.egress_intf.intf_id); \
84 OPENOLT_LOG(level, openolt_log_id, "classifier(o_vid %d, o_pbits %d, i_vid %d, i_pbits %d, ether type 0x%x)\n", \
85 c_val.o_vid, c_val.o_pbits, c_val.i_vid, c_val.i_pbits, classifier.eth_type()); \
86 OPENOLT_LOG(level, openolt_log_id, "classifier(ip_proto 0x%x, gemport_id %d, src_port %d, dst_port %d, pkt_tag_type %s)\n", \
87 c_val.ip_proto, gemport_id, c_val.src_port, c_val.dst_port, GET_PKT_TAG_TYPE(c_val.pkt_tag_type)); \
88 OPENOLT_LOG(level, openolt_log_id, "action(cmds_bitmask %s, o_vid %d, o_pbits %d, i_vid %d, i_pbits %d)\n\n", \
89 get_flow_acton_command(a_val.cmds_bitmask), a_val.o_vid, a_val.o_pbits, a_val.i_vid, a_val.i_pbits); \
90 } while(0)
91
92#define FLOW_PARAM_LOG() \
93 do { \
94 OPENOLT_LOG(INFO, openolt_log_id, "--------> flow comparison (now before) <--------\n"); \
95 OPENOLT_LOG(INFO, openolt_log_id, "flow_id (%d %d)\n", \
96 key.flow_id, it->first.first); \
97 OPENOLT_LOG(INFO, openolt_log_id, "onu_id (%d %lu)\n", \
98 cfg.data.onu_id , get_flow_status(it->first.first, it->first.second, ONU_ID)); \
99 OPENOLT_LOG(INFO, openolt_log_id, "type (%d %lu)\n", \
100 key.flow_type, get_flow_status(it->first.first, it->first.second, FLOW_TYPE)); \
101 OPENOLT_LOG(INFO, openolt_log_id, "svc_port_id (%d %lu)\n", \
102 cfg.data.svc_port_id, get_flow_status(it->first.first, it->first.second, SVC_PORT_ID)); \
103 OPENOLT_LOG(INFO, openolt_log_id, "priority (%d %lu)\n", \
104 cfg.data.priority, get_flow_status(it->first.first, it->first.second, PRIORITY)); \
105 OPENOLT_LOG(INFO, openolt_log_id, "cookie (%lu %lu)\n", \
106 cfg.data.cookie, get_flow_status(it->first.first, it->first.second, COOKIE)); \
107 OPENOLT_LOG(INFO, openolt_log_id, "ingress intf_type (%s %s)\n", \
108 GET_FLOW_INTERFACE_TYPE(cfg.data.ingress_intf.intf_type), \
109 GET_FLOW_INTERFACE_TYPE(get_flow_status(it->first.first, it->first.second, INGRESS_INTF_TYPE))); \
110 OPENOLT_LOG(INFO, openolt_log_id, "ingress intf id (%d %lu)\n", \
111 cfg.data.ingress_intf.intf_id , get_flow_status(it->first.first, it->first.second, INGRESS_INTF_ID)); \
112 OPENOLT_LOG(INFO, openolt_log_id, "egress intf_type (%d %lu)\n", \
113 cfg.data.egress_intf.intf_type , get_flow_status(it->first.first, it->first.second, EGRESS_INTF_TYPE)); \
114 OPENOLT_LOG(INFO, openolt_log_id, "egress intf_id (%d %lu)\n", \
115 cfg.data.egress_intf.intf_id , get_flow_status(it->first.first, it->first.second, EGRESS_INTF_ID)); \
116 OPENOLT_LOG(INFO, openolt_log_id, "classifier o_vid (%d %lu)\n", \
117 c_val.o_vid , get_flow_status(it->first.first, it->first.second, CLASSIFIER_O_VID)); \
118 OPENOLT_LOG(INFO, openolt_log_id, "classifier o_pbits (%d %lu)\n", \
119 c_val.o_pbits , get_flow_status(it->first.first, it->first.second, CLASSIFIER_O_PBITS)); \
120 OPENOLT_LOG(INFO, openolt_log_id, "classifier i_vid (%d %lu)\n", \
121 c_val.i_vid , get_flow_status(it->first.first, it->first.second, CLASSIFIER_I_VID)); \
122 OPENOLT_LOG(INFO, openolt_log_id, "classifier i_pbits (%d %lu)\n", \
123 c_val.i_pbits , get_flow_status(it->first.first, it->first.second, CLASSIFIER_I_PBITS)); \
124 OPENOLT_LOG(INFO, openolt_log_id, "classifier ether_type (0x%x 0x%lx)\n", \
125 c_val.ether_type , get_flow_status(it->first.first, it->first.second, CLASSIFIER_ETHER_TYPE)); \
126 OPENOLT_LOG(INFO, openolt_log_id, "classifier ip_proto (%d %lu)\n", \
127 c_val.ip_proto , get_flow_status(it->first.first, it->first.second, CLASSIFIER_IP_PROTO)); \
128 OPENOLT_LOG(INFO, openolt_log_id, "classifier src_port (%d %lu)\n", \
129 c_val.src_port , get_flow_status(it->first.first, it->first.second, CLASSIFIER_SRC_PORT)); \
130 OPENOLT_LOG(INFO, openolt_log_id, "classifier dst_port (%d %lu)\n", \
131 c_val.dst_port , get_flow_status(it->first.first, it->first.second, CLASSIFIER_DST_PORT)); \
132 OPENOLT_LOG(INFO, openolt_log_id, "classifier pkt_tag_type (%s %s)\n", \
133 GET_PKT_TAG_TYPE(c_val.pkt_tag_type), \
134 GET_PKT_TAG_TYPE(get_flow_status(it->first.first, it->first.second, CLASSIFIER_PKT_TAG_TYPE))); \
135 OPENOLT_LOG(INFO, openolt_log_id, "classifier egress_qos type (%d %lu)\n", \
136 cfg.data.egress_qos.type , get_flow_status(it->first.first, it->first.second, EGRESS_QOS_TYPE)); \
137 OPENOLT_LOG(INFO, openolt_log_id, "classifier egress_qos queue_id (%d %lu)\n", \
138 cfg.data.egress_qos.u.fixed_queue.queue_id, \
139 get_flow_status(it->first.first, it->first.second, EGRESS_QOS_QUEUE_ID)); \
140 OPENOLT_LOG(INFO, openolt_log_id, "classifier egress_qos sched_id (%d %lu)\n", \
141 cfg.data.egress_qos.tm_sched.id, \
142 get_flow_status(it->first.first, it->first.second, EGRESS_QOS_TM_SCHED_ID)); \
143 OPENOLT_LOG(INFO, openolt_log_id, "classifier cmds_bitmask (%s %s)\n", \
144 get_flow_acton_command(a_val.cmds_bitmask), \
145 get_flow_acton_command(get_flow_status(it->first.first, it->first.second, ACTION_CMDS_BITMASK))); \
146 OPENOLT_LOG(INFO, openolt_log_id, "action o_vid (%d %lu)\n", \
147 a_val.o_vid , get_flow_status(it->first.first, it->first.second, ACTION_O_VID)); \
148 OPENOLT_LOG(INFO, openolt_log_id, "action i_vid (%d %lu)\n", \
149 a_val.i_vid , get_flow_status(it->first.first, it->first.second, ACTION_I_VID)); \
150 OPENOLT_LOG(INFO, openolt_log_id, "action o_pbits (%d %lu)\n", \
151 a_val.o_pbits , get_flow_status(it->first.first, it->first.second, ACTION_O_PBITS)); \
152 OPENOLT_LOG(INFO, openolt_log_id, "action i_pbits (%d %lu)\n\n", \
153 a_val.i_pbits, get_flow_status(it->first.first, it->first.second, ACTION_I_PBITS)); \
154 OPENOLT_LOG(INFO, openolt_log_id, "group_id (%d %lu)\n\n", \
155 a_val.group_id, get_flow_status(it->first.first, it->first.second, GROUP_ID)); \
156 } while(0)
157
Girish Gowdra96461052019-11-22 20:13:59 +0530158#define COLLECTION_PERIOD 15 // in seconds
Girish Gowdru376b33c2019-05-06 21:46:31 -0700159#define BAL_DYNAMIC_LIST_BUFFER_SIZE (32 * 1024)
160#define MAX_REGID_LENGTH 36
Shad Ansari627b5782018-08-13 22:49:32 +0000161
Girish Gowdraddf9a162020-01-27 12:56:27 +0530162#define BAL_RSC_MANAGER_BASE_TM_SCHED_ID 16384
163#define MAX_TM_QMP_ID 16
164#define TMQ_MAP_PROFILE_SIZE 8
165#define MAX_TM_SCHED_ID 1023
166#define MAX_SUBS_TM_SCHED_ID (MAX_SUPPORTED_PON == 16 ? MAX_TM_SCHED_ID-4-16 : MAX_TM_SCHED_ID-10-64)
167#define EAP_ETHER_TYPE 34958
168#define XGS_BANDWIDTH_GRANULARITY 16000
169#define GPON_BANDWIDTH_GRANULARITY 32000
170#define NUM_OF_PRIORITIES 8
171#define NUMBER_OF_DEFAULT_INTERFACE_QUEUES 4 // <= NUM_OF_PRIORITIES
172#define FILL_ARRAY(ARRAY,START,END,VALUE) for(int i=START;i<END;ARRAY[i++]=VALUE);
173#define COUNT_OF(array) (sizeof(array) / sizeof(array[0]))
174
175#define GET_FLOW_INTERFACE_TYPE(type) \
176 (type == BCMOLT_FLOW_INTERFACE_TYPE_PON) ? "PON" : \
177 (type == BCMOLT_FLOW_INTERFACE_TYPE_NNI) ? "NNI" : \
178 (type == BCMOLT_FLOW_INTERFACE_TYPE_HOST) ? "HOST" : "unknown"
179#define GET_PKT_TAG_TYPE(type) \
180 (type == BCMOLT_PKT_TAG_TYPE_UNTAGGED) ? "UNTAG" : \
181 (type == BCMOLT_PKT_TAG_TYPE_SINGLE_TAG) ? "SINGLE_TAG" : \
182 (type == BCMOLT_PKT_TAG_TYPE_DOUBLE_TAG) ? "DOUBLE_TAG" : "unknown"
183#define GET_ACL_ACTION_TYPE(type) \
184 (type == BCMOLT_ACCESS_CONTROL_FWD_ACTION_TYPE_TRAP_TO_HOST) ? "trap_to_host" : \
185 (type == BCMOLT_ACCESS_CONTROL_FWD_ACTION_TYPE_DROP) ? "drop" : \
186 (type == BCMOLT_ACCESS_CONTROL_FWD_ACTION_TYPE_REDIRECT) ? "redirction" : "unknown"
187#define GET_ACL_MEMBERS_UPDATE_COMMAND(command) \
188 (command == BCMOLT_MEMBERS_UPDATE_COMMAND_ADD) ? "add" : \
189 (command == BCMOLT_MEMBERS_UPDATE_COMMAND_REMOVE) ? "remove" : \
190 (command == BCMOLT_MEMBERS_UPDATE_COMMAND_SET) ? "set" : "unknown"
191#define GET_INTERFACE_TYPE(type) \
192 (type == BCMOLT_INTERFACE_TYPE_PON) ? "PON" : \
193 (type == BCMOLT_INTERFACE_TYPE_NNI) ? "NNI" : \
194 (type == BCMOLT_INTERFACE_TYPE_HOST) ? "HOST" : "unknown"
195
Jason Huang1d9cfce2020-05-20 22:58:47 +0800196#define LOGICAL_DISTANCE(MLD,EQD,TD) (MLD-(EQD*TD)*102) /* Round-trip time of 102 meters is 1us */
Shad Ansariedef2132018-08-10 22:14:50 +0000197extern State state;
198
Girish Gowdraddf9a162020-01-27 12:56:27 +0530199//***************************************//
200// Function declations used by the core. //
201//***************************************//
Shad Ansari627b5782018-08-13 22:49:32 +0000202Status Enable_(int argc, char *argv[]);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000203Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id,
kesavandc1f2db92020-08-31 15:32:06 +0530204 const char *vendor_id, const char *vendor_specific, uint32_t pir, bool omcc_encryption_mode);
Jonathan Davis70c21812018-07-19 15:32:10 -0400205Status DeactivateOnu_(uint32_t intf_id, uint32_t onu_id,
206 const char *vendor_id, const char *vendor_specific);
207Status DeleteOnu_(uint32_t intf_id, uint32_t onu_id,
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700208 const char *vendor_id, const char *vendor_specific);
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000209Status EnablePonIf_(uint32_t intf_id);
Nicolas Palpacuer05ea0ea2018-07-06 11:47:21 -0400210Status DisablePonIf_(uint32_t intf_id);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000211Status SetStateUplinkIf_(uint32_t intf_id, bool set_state);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500212unsigned NumNniIf_();
213unsigned NumPonIf_();
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000214Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -0800215Status OnuPacketOut_(uint32_t intf_id, uint32_t onu_id, uint32_t port_no, uint32_t gemport_id, const std::string pkt);
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500216Status ProbeDeviceCapabilities_();
217Status ProbePonIfTechnology_();
Nicolas Palpacuerb78def42018-06-07 12:55:26 -0400218Status UplinkPacketOut_(uint32_t intf_id, const std::string pkt);
Craig Lutgen967a1d02018-11-27 10:41:51 -0600219Status FlowAdd_(int32_t access_intf_id, int32_t onu_id, int32_t uni_id, uint32_t port_no,
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000220 uint32_t flow_id, const std::string flow_type,
Girish Gowdru7c4ec2d2018-10-25 00:29:54 -0700221 int32_t alloc_id, int32_t network_intf_id,
222 int32_t gemport_id, const ::openolt::Classifier& classifier,
Burak Gurdagc78b9e12019-11-29 11:14:51 +0000223 const ::openolt::Action& action, int32_t priority_value,
Burak Gurdag2f2618c2020-04-23 13:20:30 +0000224 uint64_t cookie, int32_t group_id, uint32_t tech_profile_id);
Nicolas Palpacueredfaa0c2018-07-05 15:05:27 -0400225Status FlowRemove_(uint32_t flow_id, const std::string flow_type);
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400226Status Disable_();
227Status Reenable_();
Nicolas Palpacuerdff96792018-09-06 14:59:32 -0400228Status GetDeviceInfo_(openolt::DeviceInfo* device_info);
Girish Gowdruc8ed2ef2019-02-13 08:18:44 -0800229Status CreateTrafficSchedulers_(const tech_profile::TrafficSchedulers *traffic_scheds);
230Status RemoveTrafficSchedulers_(const tech_profile::TrafficSchedulers *traffic_scheds);
231Status CreateTrafficQueues_(const tech_profile::TrafficQueues *traffic_queues);
232Status RemoveTrafficQueues_(const tech_profile::TrafficQueues *traffic_queues);
Burak Gurdagc78b9e12019-11-29 11:14:51 +0000233Status PerformGroupOperation_(const openolt::Group *group_cfg);
Burak Gurdageb4ca2e2020-06-15 07:48:26 +0000234Status DeleteGroup_(uint32_t group_id);
kesavandc1f2db92020-08-31 15:32:06 +0530235Status OnuItuPonAlarmSet_(const config::OnuItuPonAlarm* request);
Craig Lutgen967a1d02018-11-27 10:41:51 -0600236uint32_t GetPortNum_(uint32_t flow_id);
Jason Huang1d9cfce2020-05-20 22:58:47 +0800237Status GetLogicalOnuDistanceZero_(uint32_t intf_id, openolt::OnuLogicalDistance* response);
238Status GetLogicalOnuDistance_(uint32_t intf_id, uint32_t onu_id, openolt::OnuLogicalDistance* response);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000239int get_status_bcm_cli_quit(void);
Jason Huangbf45ffb2019-10-30 17:29:02 +0800240uint16_t get_dev_id(void);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000241Status pushOltOperInd(uint32_t intf_id, const char *type, const char *state);
242uint64_t get_flow_status(uint16_t flow_id, uint16_t flow_type, uint16_t data_id);
Nicolas Palpacuere3fc0d22018-08-02 16:51:05 -0400243
Nicolas Palpacuer6a63ea92018-09-05 17:21:37 -0400244void stats_collection();
Jason Huangbf45ffb2019-10-30 17:29:02 +0800245Status check_connection();
246Status check_bal_ready();
Thiyagarajan Subramani03bc66f2020-04-01 15:58:53 +0530247std::string get_ip_address(const char* nw_intf);
Girish Gowdraddf9a162020-01-27 12:56:27 +0530248
249// Stubbed defntions of bcmolt_cfg_get required for unit-test
250#ifdef TEST_MODE
251extern bcmos_errno bcmolt_cfg_get__bal_state_stub(bcmolt_oltid olt_id, void* ptr);
252extern bcmos_errno bcmolt_cfg_get__onu_state_stub(bcmolt_oltid olt_id, void* ptr);
253extern bcmos_errno bcmolt_cfg_get__tm_sched_stub(bcmolt_oltid olt_id, void* ptr);
254extern bcmos_errno bcmolt_cfg_get__pon_intf_stub(bcmolt_oltid olt_id, void* ptr);
255extern bcmos_errno bcmolt_cfg_get__nni_intf_stub(bcmolt_oltid olt_id, void* ptr);
256extern bcmos_errno bcmolt_cfg_get__olt_topology_stub(bcmolt_oltid olt_id, void* ptr);
257extern bcmos_errno bcmolt_cfg_get__flow_stub(bcmolt_oltid olt_id, void* ptr);
258#endif //TEST_MODE
259
Shad Ansarib7b0ced2018-05-11 21:53:32 +0000260#endif