blob: c4a0b5347802f12f85d620418ab6497779817b95 [file] [log] [blame]
Shad Ansari01b0e652018-04-05 21:02:53 +00001/*
2 Copyright (C) 2018 Open Networking Foundation
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#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"
Shad Ansari01b0e652018-04-05 21:02:53 +000022
Humera Kouser5ac56612019-07-25 20:23:01 -040023using namespace std;
24
25/*
26* This function displays openolt version, BAL version, openolt build date
27* and other VCS params like VCS url, VCS ref, commit date and exits.
28*
29* @param argc : number of arguments
30* @param argv : vector of arguments
31*/
32void display_version_info(int argc, char *argv[]) {
33
34 string version = "";
35 string bal_version = "";
36 string label_vcs_url = "";
37 string label_vcs_ref = "";
38 string label_build_date = "";
39 string label_commit_date = "";
40
41 #ifdef VERSION
42 version = VERSION;
43 #endif
44
45 #ifdef BAL_VER
46 bal_version = BAL_VER;
47 #endif
48
49 #ifdef LABEL_VCS_URL
50 label_vcs_url = LABEL_VCS_URL;
51 #endif
52
53 #ifdef LABEL_VCS_REF
54 label_vcs_ref = LABEL_VCS_REF;
55 #endif
56
57 #ifdef LABEL_BUILD_DATE
58 label_build_date = LABEL_BUILD_DATE;
59 #endif
60
61 #ifdef LABEL_COMMIT_DATE
62 label_commit_date = LABEL_COMMIT_DATE;
63 #endif
64
65 for (int i = 1; i < argc; ++i) {
66 if(strcmp(argv[i], "--version") == 0 || (strcmp(argv[i], "-v") == 0)) {
67 std::cout << "OpenOLT agent: " << version << "\n";
68 std::cout << "BAL version: " << bal_version << "\n";
69 std::cout << "Label VCS Url: " << label_vcs_url << "\n";
70 std::cout << "Label VCS Ref: " << label_vcs_ref << "\n";
71 std::cout << "Label build date: " << label_build_date << "\n";
72 std::cout << "Label commit date: " << label_commit_date << "\n";
73 exit(0);
74 }
75 }
76}
77
Shad Ansari01b0e652018-04-05 21:02:53 +000078int main(int argc, char** argv) {
79
Humera Kouser5ac56612019-07-25 20:23:01 -040080 display_version_info(argc, argv);
81
Shad Ansari627b5782018-08-13 22:49:32 +000082 Status status = Enable_(argc, argv);
Shad Ansari01b0e652018-04-05 21:02:53 +000083 if (!status.ok()) {
84 std::cout << "ERROR: Enable_ failed - "
85 << status.error_code() << ": " << status.error_message()
86 << std::endl;
87 return 1;
88 }
89
Craig Lutgen88a22ad2018-10-04 12:30:46 -050090 // Wait for successful activation before allowing VOLTHA to connect.
91 // This is necessary to allow the device topology to be dynamically
92 // queried from driver after initialization and activation is complete.
93 int maxTrials = 300;
94 while (!state.is_activated()) {
95 sleep(1);
96 if (--maxTrials == 0) {
97 std::cout << "ERROR: OLT/PON Activation failed" << std::endl;
98 return 1;
99 }
100 }
101
Shad Ansari01b0e652018-04-05 21:02:53 +0000102 RunServer();
103
Shad Ansari627b5782018-08-13 22:49:32 +0000104 return 0;
Shad Ansari01b0e652018-04-05 21:02:53 +0000105}