Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 1 | /* |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 3 | |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 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 |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 7 | |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 9 | |
Girish Gowdra | a707e7c | 2019-11-07 11:36:13 +0530 | [diff] [blame] | 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 | |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 17 | #include <iostream> |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 18 | #include <unistd.h> |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 19 | |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 20 | #include "server.h" |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 21 | #include "core.h" |
Humera Kouser | 6143c9e | 2020-06-17 22:37:31 +0530 | [diff] [blame] | 22 | #include "src/core_data.h" |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 23 | |
Humera Kouser | 5ac5661 | 2019-07-25 20:23:01 -0400 | [diff] [blame] | 24 | using 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 | */ |
| 33 | void 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 Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 79 | int main(int argc, char** argv) { |
| 80 | |
Humera Kouser | 5ac5661 | 2019-07-25 20:23:01 -0400 | [diff] [blame] | 81 | display_version_info(argc, argv); |
| 82 | |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 83 | Status status = Enable_(argc, argv); |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 84 | 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 Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 91 | // Wait for successful activation before allowing VOLTHA to connect. |
Craig Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 92 | // 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 Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 103 | 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 Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 109 | sleep(2); |
Orhan Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 110 | // Enable all PON interfaces. |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 111 | 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 Battiston | 869a5de | 2022-02-08 11:40:58 +0100 | [diff] [blame] | 115 | pushOltOperInd(i, "pon", "down", 0 /*Speed will be ignored in the adapter for PONs*/ ); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 116 | } |
| 117 | else |
Elia Battiston | 869a5de | 2022-02-08 11:40:58 +0100 | [diff] [blame] | 118 | pushOltOperInd(i, "pon", "up", 0 /*Speed will be ignored in the adapter for PONs*/); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 119 | } |
| 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 Battiston | 869a5de | 2022-02-08 11:40:58 +0100 | [diff] [blame] | 134 | uint32_t nni_speed = GetNniSpeed_(0); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 135 | status = SetStateUplinkIf_(0, true); |
| 136 | if (!status.ok()) { |
| 137 | // raise alarm to report error in enabling NNI |
Elia Battiston | 869a5de | 2022-02-08 11:40:58 +0100 | [diff] [blame] | 138 | pushOltOperInd(0, "nni", "down", nni_speed); |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 139 | } |
Elia Battiston | 869a5de | 2022-02-08 11:40:58 +0100 | [diff] [blame] | 140 | else{ |
| 141 | pushOltOperInd(0, "nni", "up", nni_speed); |
| 142 | } |
Humera Kouser | 6143c9e | 2020-06-17 22:37:31 +0530 | [diff] [blame] | 143 | |
| 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 Kupusoglu | 1fd7707 | 2021-03-23 08:13:25 -0700 | [diff] [blame] | 150 | |
| 151 | if (!RunServer(argc, argv)) { |
| 152 | std::cerr << "FATAL: gRPC server creation failed\n"; |
| 153 | return 2; |
| 154 | } |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 155 | |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 156 | return 0; |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 157 | } |