blob: a0118a12391257700affaf5cd45325fe907c675c [file] [log] [blame]
Craig Lutgen88a22ad2018-10-04 12:30:46 -05001/*
Girish Gowdraa707e7c2019-11-07 11:36:13 +05302 * Copyright 2018-present Open Networking Foundation
Craig Lutgen88a22ad2018-10-04 12:30:46 -05003
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
Craig Lutgen88a22ad2018-10-04 12:30:46 -05007
Girish Gowdraa707e7c2019-11-07 11:36:13 +05308 * http://www.apache.org/licenses/LICENSE-2.0
Craig Lutgen88a22ad2018-10-04 12:30:46 -05009
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 */
Craig Lutgen88a22ad2018-10-04 12:30:46 -050016
17#ifndef __DEVICE_H__
18#define __DEVICE_H__
19
Girish Gowdrab0337eb2022-03-25 16:44:21 -070020#include <string>
21#include <fstream>
22#include <iostream>
23#include <algorithm>
24#include <cstdlib>
25#include <sstream>
26#include <new>
27#include <set>
28#include <map>
Craig Lutgen88a22ad2018-10-04 12:30:46 -050029
Girish Gowdrab0337eb2022-03-25 16:44:21 -070030extern "C"
31{
32#include <bcmolt_api.h>
33#include <bcmolt_api_model_supporting_enums.h>
34}
35
36using namespace std;
37
38/////////////////////////////////////////////////////
39
40// Constant definitions
41
42#define EEPROM_DATA_READ_SIZE 256 //bytes
43#define EEPROM_READ_PATH_SIZE 200
44#define PON_TRX_BUS_FORMAT_SIZE 64
45#define MAX_PONS_PER_TRX 2
46
47#define GPON_DOWNSTREAM_WAVELENGTH_NM 1490 // ITU-T G984.2 PMD specification
48#define XGSPON_DOWNSTREAM_WAVELENGTH_NM 1577 // ITU-T G9807.1 PMD specification
49
50
51/////////////////////////////////////////////////////
52
53// Structure definitions
54
55struct pon_data {
56 bool valid; // set to true if the below fields are set after reading eeprom data
57 uint32_t wavelength;
58 bcmolt_pon_type pon_type;
59 // add more fields as needed...
60};
61
62struct trx_data {
63 int sfp_index;
64 string vendor_name;
65 uint8_t vendor_oui[3];
66 string vendor_part_no;
67 string vendor_rev;
68 bcmolt_pon_type trx_type;
69 pon_data p_data[MAX_PONS_PER_TRX];
70};
71
72/////////////////////////////////////////////////////
73
74// Class Definitions
75
76// PonTrx: This class defines the member functions and attributes of the Pon Transceiver object
77class PonTrxBase {
78 public:
79
80 // Location of I2C file systems is pretty standard for Linux systems, and it is /sys/bus/i2c/devices
81 // Check here https://www.kernel.org/doc/html/latest/i2c/i2c-sysfs.html#location-of-i2c-sysfs for documentation on Linux I2C
82 // The OLTs we work with are based on Linux, however if it is something different this can be overridden.
83 PonTrxBase(string eeprom_file_name="sfp_eeprom",
84 int port_addr=50,
85 string eeprom_file_format_name="/sys/bus/i2c/devices/%d-00%d/%s",
86 string sfp_presence_command="/lib/platform-config/current/onl/bin/onlpdump -p");
87
88 // Reads, updates and returns the _sfp_presence_array from the OLT device
89 const set<int> read_sfp_presence_data();
90
91 // Returns the _sfp_presence_array
92 const set<int> get_sfp_presence_data();
93
94 // Reads the EEPROM data. The sfp_index is the bus index corresponding to the PON Trx
95 // returns true if success
96 bool read_eeprom_data_for_sfp(int sfp_index);
97
98 // Decodes the EEPROM data. The sfp_index is the bus index corresponding to the PON Trx
99 // returns true if success
100 bool decode_eeprom_data(int sfp_index);
101
102 // Get Trx Type based on SFP ID provided
103 bcmolt_pon_type get_sfp_mode(int sfp_index);
104
105 // Get PON Type based on optical wavelength specified
106 bcmolt_pon_type get_pon_type_from_wavelength(int wavelength);
107
108 // Get MAC System mode based on the olt mac id and the set of SFP IDs provided
109 pair<bcmolt_system_mode, bool> get_mac_system_mode(int, set<int>);
110
111 // Get Trx data
112 trx_data* get_trx_data(int sfp_index);
113
114 ~PonTrxBase();
115
116 protected:
117 set<int> _sfp_presence_data;
118 set<trx_data*> _t_data;
119 map<int, array<char, EEPROM_READ_PATH_SIZE>> _eeprom_read_path;
120 map<int, array<unsigned char, EEPROM_DATA_READ_SIZE>> _eeprom_data;
121 // Location of I2C file systems is pretty standard for Linux systems, and it is /sys/bus/i2c/devices
122 // Check here https://www.kernel.org/doc/html/latest/i2c/i2c-sysfs.html#location-of-i2c-sysfs for documentation on Linux I2C
123 // The OLTs we work with are based on Linux, however if it is something different this can be overridden during objection creation.
124 string _eeprom_file_path_format = "/sys/bus/i2c/devices/%d-00%d/%s";
125 string _eeprom_file_name;
126 string _sfp_presence_command = "/lib/platform-config/current/onl/bin/onlpdump -p";
127 int _port_addr;
128
129};
130
131/////////////////////////////////////////////////////
132
133// Extern definitions
Craig Lutgen88a22ad2018-10-04 12:30:46 -0500134extern void vendor_init();
135
136#endif