blob: ce55e4d1b3f0da23c197c1ebbbe739de9c4ca4c4 [file] [log] [blame]
Shad Ansari01b0e652018-04-05 21:02:53 +00001/*
Girish Gowdraa707e7c2019-11-07 11:36:13 +05302 * Copyright 2018-present Open Networking Foundation
Shad Ansari01b0e652018-04-05 21:02:53 +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 Ansari01b0e652018-04-05 21:02:53 +00007
Girish Gowdraa707e7c2019-11-07 11:36:13 +05308 * http://www.apache.org/licenses/LICENSE-2.0
Shad Ansari01b0e652018-04-05 21:02:53 +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 */
16
Shad Ansari01b0e652018-04-05 21:02:53 +000017#include <iostream>
Craig Lutgen88a22ad2018-10-04 12:30:46 -050018#include <unistd.h>
Shad Ansari01b0e652018-04-05 21:02:53 +000019
Shad Ansari01b0e652018-04-05 21:02:53 +000020#include "server.h"
Shad Ansarib7b0ced2018-05-11 21:53:32 +000021#include "core.h"
Humera Kouser6143c9e2020-06-17 22:37:31 +053022#include "src/core_data.h"
Shad Ansari01b0e652018-04-05 21:02:53 +000023
Humera Kouser5ac56612019-07-25 20:23:01 -040024using namespace std;
25
26/*
27* This function displays openolt version, BAL version, openolt build date
28* and other VCS params like VCS url, VCS ref, commit date and exits.
29*
30* @param argc : number of arguments
31* @param argv : vector of arguments
32*/
33void display_version_info(int argc, char *argv[]) {
34
35 string version = "";
36 string bal_version = "";
37 string label_vcs_url = "";
38 string label_vcs_ref = "";
39 string label_build_date = "";
40 string label_commit_date = "";
41
42 #ifdef VERSION
43 version = VERSION;
44 #endif
45
46 #ifdef BAL_VER
47 bal_version = BAL_VER;
48 #endif
49
50 #ifdef LABEL_VCS_URL
51 label_vcs_url = LABEL_VCS_URL;
52 #endif
53
54 #ifdef LABEL_VCS_REF
55 label_vcs_ref = LABEL_VCS_REF;
56 #endif
57
58 #ifdef LABEL_BUILD_DATE
59 label_build_date = LABEL_BUILD_DATE;
60 #endif
61
62 #ifdef LABEL_COMMIT_DATE
63 label_commit_date = LABEL_COMMIT_DATE;
64 #endif
65
66 for (int i = 1; i < argc; ++i) {
67 if(strcmp(argv[i], "--version") == 0 || (strcmp(argv[i], "-v") == 0)) {
68 std::cout << "OpenOLT agent: " << version << "\n";
69 std::cout << "BAL version: " << bal_version << "\n";
70 std::cout << "Label VCS Url: " << label_vcs_url << "\n";
71 std::cout << "Label VCS Ref: " << label_vcs_ref << "\n";
72 std::cout << "Label build date: " << label_build_date << "\n";
73 std::cout << "Label commit date: " << label_commit_date << "\n";
74 exit(0);
75 }
76 }
77}
78
Shad Ansari01b0e652018-04-05 21:02:53 +000079int main(int argc, char** argv) {
80
Humera Kouser5ac56612019-07-25 20:23:01 -040081 display_version_info(argc, argv);
82
Shad Ansari627b5782018-08-13 22:49:32 +000083 Status status = Enable_(argc, argv);
Shad Ansari01b0e652018-04-05 21:02:53 +000084 if (!status.ok()) {
85 std::cout << "ERROR: Enable_ failed - "
86 << status.error_code() << ": " << status.error_message()
87 << std::endl;
88 return 1;
89 }
90
Orhan Kupusoglu1fd77072021-03-23 08:13:25 -070091 // Wait for successful activation before allowing VOLTHA to connect.
Craig Lutgen88a22ad2018-10-04 12:30:46 -050092 // This is necessary to allow the device topology to be dynamically
93 // queried from driver after initialization and activation is complete.
94 int maxTrials = 300;
95 while (!state.is_activated()) {
96 sleep(1);
97 if (--maxTrials == 0) {
98 std::cout << "ERROR: OLT/PON Activation failed" << std::endl;
99 return 1;
100 }
101 }
102
Amit Ghoshfcad4d32019-11-13 10:24:55 +0000103 status = ProbeDeviceCapabilities_();
104 if (!status.ok()) {
105 std::cout << "ERROR: Could not find the OLT Device capabilities" << std::endl;
106 return 1;
107 }
108
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000109 sleep(2);
Orhan Kupusoglu1fd77072021-03-23 08:13:25 -0700110 // Enable all PON interfaces.
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000111 for (int i = 0; i < NumPonIf_(); i++) {
112 status = EnablePonIf_(i);
113 if (!status.ok()) {
114 // raise alarm to report error in enabling PON
Elia Battiston869a5de2022-02-08 11:40:58 +0100115 pushOltOperInd(i, "pon", "down", 0 /*Speed will be ignored in the adapter for PONs*/ );
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000116 }
117 else
Elia Battiston869a5de2022-02-08 11:40:58 +0100118 pushOltOperInd(i, "pon", "up", 0 /*Speed will be ignored in the adapter for PONs*/);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000119 }
120 sleep(2);
121 // Enable all NNI interfaces.
122#if 0
123 for (int i = 0; i < NumNniIf_(); i++) {
124 status = EnableUplinkIf_(i);
125 if (!status.ok()) {
126 // raise alarm to report error in enabling PON
127 pushOltOperInd(i, "nni", "down");
128 }
129 else
130 pushOltOperInd(i, "nni", "up");
131 }
132#endif
133 //only for nni-65536 mapping to intf_id 0
Elia Battiston869a5de2022-02-08 11:40:58 +0100134 uint32_t nni_speed = GetNniSpeed_(0);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000135 status = SetStateUplinkIf_(0, true);
136 if (!status.ok()) {
137 // raise alarm to report error in enabling NNI
Elia Battiston869a5de2022-02-08 11:40:58 +0100138 pushOltOperInd(0, "nni", "down", nni_speed);
Thiyagarajan Subramani89fffc02019-05-13 21:33:20 +0000139 }
Elia Battiston869a5de2022-02-08 11:40:58 +0100140 else{
141 pushOltOperInd(0, "nni", "up", nni_speed);
142 }
Humera Kouser6143c9e2020-06-17 22:37:31 +0530143
144 for (int i = 1; i < argc; ++i) {
145 if(strcmp(argv[i-1], "--interface") == 0 || (strcmp(argv[i-1], "--intf") == 0)) {
146 grpc_server_interface_name = argv[i];
147 break;
148 }
149 }
Orhan Kupusoglu1fd77072021-03-23 08:13:25 -0700150
151 if (!RunServer(argc, argv)) {
152 std::cerr << "FATAL: gRPC server creation failed\n";
153 return 2;
154 }
Shad Ansari01b0e652018-04-05 21:02:53 +0000155
Shad Ansari627b5782018-08-13 22:49:32 +0000156 return 0;
Shad Ansari01b0e652018-04-05 21:02:53 +0000157}