blob: 65fc62c4debb259a0238d28e7f96900626470b17 [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#include <iostream>
17#include <memory>
18#include <string>
19
20#include "Queue.h"
21#include <sstream>
22#include <chrono>
23#include <thread>
24#include <bitset>
25#include <inttypes.h>
26#include <unistd.h>
27#include <sys/socket.h>
28#include <netinet/in.h>
29#include <arpa/inet.h>
30
31#include "device.h"
32#include "core.h"
33#include "core_data.h"
34#include "indications.h"
35#include "stats_collection.h"
36#include "error_format.h"
37#include "state.h"
38#include "core_utils.h"
39
40extern "C"
41{
42#include <bcmolt_api.h>
43#include <bcmolt_host_api.h>
44#include <bcmolt_api_model_supporting_enums.h>
45
46#include <bcmolt_api_conn_mgr.h>
47//CLI header files
48#include <bcmcli_session.h>
49#include <bcmcli.h>
50#include <bcm_api_cli.h>
51
52#include <bcmos_common.h>
53#include <bcm_config.h>
54// FIXME : dependency problem
55// #include <bcm_common_gpon.h>
56// #include <bcm_dev_log_task.h>
57}
58
59dev_log_id openolt_log_id = bcm_dev_log_id_register("OPENOLT", DEV_LOG_LEVEL_INFO, DEV_LOG_ID_TYPE_BOTH);
60dev_log_id omci_log_id = bcm_dev_log_id_register("OMCI", DEV_LOG_LEVEL_INFO, DEV_LOG_ID_TYPE_BOTH);
61
62
63unsigned int num_of_nni_ports = 0;
64unsigned int num_of_pon_ports = 0;
65
66const uint32_t tm_upstream_sched_id_start = (MAX_SUPPORTED_PON == 16 ? \
67 MAX_TM_SCHED_ID-3 : MAX_TM_SCHED_ID-9);
68const uint32_t tm_downstream_sched_id_start = (MAX_SUPPORTED_PON == 16 ? \
69 tm_upstream_sched_id_start-16 : tm_upstream_sched_id_start-64);
70
71/* Max Queue ID supported is 7 so based on priority_q configured for GEMPORTS
72in TECH PROFILE respective Queue ID from this list will be used for both
73US and DS Queues*/
74const uint32_t queue_id_list[8] = {0, 1, 2, 3, 4, 5, 6, 7};
75
76const std::string upstream = "upstream";
77const std::string downstream = "downstream";
78const std::string multicast = "multicast";
79bcmolt_oltid dev_id = 0;
80
81/* Constants used for retrying some BAL APIs */
82const uint32_t BAL_API_RETRY_TIME_IN_USECS = 1000000;
83const uint32_t MAX_BAL_API_RETRY_COUNT = 5;
84
85const unsigned int OPENOLT_FIELD_LEN = 200;
86
87/* Current session */
88bcmcli_session *current_session;
89bcmcli_entry *api_parent_dir;
90bcmos_bool status_bcm_cli_quit = BCMOS_FALSE;
91bcmos_task bal_cli_thread;
92const char *bal_cli_thread_name = "bal_cli_thread";
93uint16_t flow_id_counters = 0;
94State state;
95
96std::map<uint32_t, uint32_t> flowid_to_port; // For mapping upstream flows to logical ports
97std::map<uint32_t, uint32_t> flowid_to_gemport; // For mapping downstream flows into gemports
98std::map<uint32_t, std::set<uint32_t> > port_to_flows; // For mapping logical ports to downstream flows
99
100/* This represents the Key to 'sched_map' map.
Burak Gurdag2f2618c2020-04-23 13:20:30 +0000101 Represents (pon_intf_id, onu_id, uni_id, direction, tech_profile_id) */
102typedef std::tuple<uint32_t, uint32_t, uint32_t, std::string, uint32_t> sched_map_key_tuple;
Girish Gowdraddf9a162020-01-27 12:56:27 +0530103/* 'sched_map' maps sched_map_key_tuple to DBA (Upstream) or
104 Subscriber (Downstream) Scheduler ID */
105std::map<sched_map_key_tuple, int> sched_map;
106
107/* Flow control is for flow_id and flow_type */
108typedef std::pair<uint16_t, uint16_t> flow_pair;
109std::map<flow_pair, int32_t> flow_map;
110
111/* This represents the Key to 'qos_type_map' map.
112 Represents (pon_intf_id, onu_id, uni_id) */
113typedef std::tuple<uint32_t, uint32_t, uint32_t> qos_type_map_key_tuple;
114/* 'qos_type_map' maps qos_type_map_key_tuple to qos_type*/
115std::map<qos_type_map_key_tuple, bcmolt_egress_qos_type> qos_type_map;
116
117/* This represents the Key to 'sched_qmp_id_map' map.
118Represents (sched_id, pon_intf_id, onu_id, uni_id) */
119typedef std::tuple<uint32_t, uint32_t, uint32_t, uint32_t> sched_qmp_id_map_key_tuple;
120/* 'sched_qmp_id_map' maps sched_qmp_id_map_key_tuple to TM Queue Mapping Profile ID */
121std::map<sched_qmp_id_map_key_tuple, int> sched_qmp_id_map;
122/* 'qmp_id_to_qmp_map' maps TM Queue Mapping Profile ID to TM Queue Mapping Profile */
123std::map<int, std::vector < uint32_t > > qmp_id_to_qmp_map;
124
Girish Gowdraddf9a162020-01-27 12:56:27 +0530125// Map used to track response from BAL for ITU PON Alloc Configuration.
126// The key is alloc_cfg_compltd_key and value is a concurrent thread-safe queue which is
127// used for pushing (from BAL) and popping (at application) the results.
128std::map<alloc_cfg_compltd_key, Queue<alloc_cfg_complete_result> *> alloc_cfg_compltd_map;
129// Lock to protect critical section data structure used for handling AllocObject configuration response.
130bcmos_fastlock alloc_cfg_wait_lock;
131
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +0530132// Map used to track response from BAL for ITU PON Gem Configuration.
133// The key is gem_cfg_compltd_key and value is a concurrent thread-safe queue which is
134// used for pushing (from BAL) and popping (at application) the results.
135std::map<gem_cfg_compltd_key, Queue<gem_cfg_complete_result> *> gem_cfg_compltd_map;
136// Lock to protect critical section data structure used for handling GemObject configuration response.
137bcmos_fastlock gem_cfg_wait_lock;
138
139/* This represents the Key to 'gemport_status_map' map.
140 Represents (pon_intf_id, onu_id, uni_id, gemport_id) */
141typedef std::tuple<uint32_t, uint32_t, uint32_t, uint32_t> gemport_status_map_key_tuple;
142/* 'gemport_status_map' maps gemport_status_map_key_tuple to boolean value */
143std::map<gemport_status_map_key_tuple, bool> gemport_status_map;
144
Girish Gowdra7a79dae2020-02-10 18:22:11 +0530145// Map used to track response from BAL for Onu Deactivation Completed Indication
Thiyagarajan Subramanie976fcf2021-05-07 22:46:57 +0530146// The key is onu_deact_compltd_key and value is a concurrent thread-safe queue which is
Girish Gowdra7a79dae2020-02-10 18:22:11 +0530147// used for pushing (from BAL) and popping (at application) the results.
148std::map<onu_deact_compltd_key, Queue<onu_deactivate_complete_result> *> onu_deact_compltd_map;
149// Lock to protect critical section data structure used for handling Onu Deactivation Completed Indication
150bcmos_fastlock onu_deactivate_wait_lock;
Girish Gowdraddf9a162020-01-27 12:56:27 +0530151
152/*** ACL Handling related data start ***/
153
154std::map<acl_classifier_key, uint16_t> acl_classifier_to_acl_id_map;
155
156bool operator<(const acl_classifier_key& a1, const acl_classifier_key& a2)
157{
Girish Gowdra1935e6a2020-10-31 21:48:22 -0700158 return ((a1.ether_type + 2*a1.ip_proto + 3*a1.src_port + 4*a1.dst_port + 5*a1.o_vid) <
159 (a2.ether_type + 2*a2.ip_proto + 3*a2.src_port + 4*a2.dst_port + 5*a2.o_vid));
Girish Gowdraddf9a162020-01-27 12:56:27 +0530160}
161
Girish Gowdra252f4972020-09-07 21:24:01 -0700162typedef std::tuple<uint64_t, std::string> flow_id_flow_direction;
163
164typedef std::tuple<int16_t, int32_t> acl_id_intf_id;
165std::map<flow_id_flow_direction, acl_id_intf_id> flow_to_acl_map;
Girish Gowdraddf9a162020-01-27 12:56:27 +0530166
167// Keeps a reference count of how many flows are referencing a given ACL ID.
168// Key represents the ACL-ID and value is number of flows referencing the given ACL-ID.
169// When there is at least one flow referencing the ACL-ID, the ACL should be installed.
170// When there are no flows referencing the ACL-ID, the ACL should be removed.
171std::map<uint16_t, uint16_t> acl_ref_cnt;
172
Girish Gowdraddf9a162020-01-27 12:56:27 +0530173// Needed to keep track of how many flows for a given acl_id, intf_id and intf_type are
174// installed. When there is at least on flow for this key, we should have interface registered
175// for the given ACL-ID. When there are no flows, the intf should unregister itself from
176// the ACL-ID.
177typedef std::tuple<uint16_t, uint8_t, std::string> acl_id_intf_id_intf_type;
178std::map<acl_id_intf_id_intf_type, uint16_t> intf_acl_registration_ref_cnt;
179
Girish Gowdra1935e6a2020-10-31 21:48:22 -0700180// Data structures to work around ACL limits on BAL -- start --
181
182// This flag is set as soon as ACL count reaches MAX_ACL_WITH_VLAN_CLASSIFIER is hit.
183// It is not reset when ACL count comes below MAX_ACL_WITH_VLAN_CLASSIFIER again
184bool max_acls_with_vlan_classifiers_hit = false;
185// Map of flow_id -> trap_to_host_pkt_info_with_vlan
186std::map<uint64_t, trap_to_host_pkt_info_with_vlan> trap_to_host_pkt_info_with_vlan_for_flow_id;
187// Map of trap_to_host_pkt_info -> cvid_list
188std::map<trap_to_host_pkt_info, std::list<uint16_t> > trap_to_host_vlan_ids_for_trap_to_host_pkt_info;
189
190// Data structures to work around ACL limits on BAL -- end --
191
192
Girish Gowdraddf9a162020-01-27 12:56:27 +0530193std::bitset<MAX_ACL_ID> acl_id_bitset;
Girish Gowdra252f4972020-09-07 21:24:01 -0700194bcmos_fastlock acl_id_bitset_lock;
Girish Gowdraddf9a162020-01-27 12:56:27 +0530195
196/*** ACL Handling related data end ***/
197
Girish Gowdra252f4972020-09-07 21:24:01 -0700198// Used to manage a pool of Scheduler IDs
Girish Gowdraddf9a162020-01-27 12:56:27 +0530199std::bitset<MAX_TM_SCHED_ID> tm_sched_bitset;
Girish Gowdra252f4972020-09-07 21:24:01 -0700200bcmos_fastlock tm_sched_bitset_lock;
Girish Gowdraddf9a162020-01-27 12:56:27 +0530201
Girish Gowdra252f4972020-09-07 21:24:01 -0700202// Used to manage a pool of TM_QMP IDs
203std::bitset<MAX_TM_QMP_ID> tm_qmp_bitset;
204bcmos_fastlock tm_qmp_bitset_lock;
205
206// Used to manage a pool of Flow IDs
207std::bitset<MAX_FLOW_ID> flow_id_bitset;
208bcmos_fastlock flow_id_bitset_lock;
209
210// Maps voltha flow-id to device flow
211std::map<uint64_t, device_flow> voltha_flow_to_device_flow;
212bcmos_fastlock voltha_flow_to_device_flow_lock;
213
Girish Gowdra1935e6a2020-10-31 21:48:22 -0700214// Lock to protect critical section around handling data associated with ACL trap packet handling
215bcmos_fastlock acl_packet_trap_handler_lock;
Girish Gowdra252f4972020-09-07 21:24:01 -0700216
217// General purpose lock used to gaurd critical section during various API handling at the core_api_handler
Girish Gowdraddf9a162020-01-27 12:56:27 +0530218bcmos_fastlock data_lock;
Humera Kouser6143c9e2020-06-17 22:37:31 +0530219
Girish Gowdra252f4972020-09-07 21:24:01 -0700220
Humera Kouser6143c9e2020-06-17 22:37:31 +0530221char* grpc_server_interface_name = NULL;
Orhan Kupusogluec57af02021-05-12 12:38:17 +0000222
223// Read Rx optical power
224std::map<onu_rssi_compltd_key, Queue<onu_rssi_complete_result>*> onu_rssi_compltd_map;
225bcmos_fastlock onu_rssi_wait_lock;