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" |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 22 | |
Humera Kouser | 5ac5661 | 2019-07-25 20:23:01 -0400 | [diff] [blame] | 23 | using 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 | */ |
| 32 | void 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 Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 78 | int main(int argc, char** argv) { |
| 79 | |
Humera Kouser | 5ac5661 | 2019-07-25 20:23:01 -0400 | [diff] [blame] | 80 | display_version_info(argc, argv); |
| 81 | |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 82 | Status status = Enable_(argc, argv); |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 83 | 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 Lutgen | 88a22ad | 2018-10-04 12:30:46 -0500 | [diff] [blame] | 90 | // 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 | |
Amit Ghosh | fcad4d3 | 2019-11-13 10:24:55 +0000 | [diff] [blame] | 102 | status = ProbeDeviceCapabilities_(); |
| 103 | if (!status.ok()) { |
| 104 | std::cout << "ERROR: Could not find the OLT Device capabilities" << std::endl; |
| 105 | return 1; |
| 106 | } |
| 107 | |
Thiyagarajan Subramani | 89fffc0 | 2019-05-13 21:33:20 +0000 | [diff] [blame] | 108 | sleep(2); |
| 109 | // Enable all PON interfaces. |
| 110 | for (int i = 0; i < NumPonIf_(); i++) { |
| 111 | status = EnablePonIf_(i); |
| 112 | if (!status.ok()) { |
| 113 | // raise alarm to report error in enabling PON |
| 114 | pushOltOperInd(i, "pon", "down"); |
| 115 | } |
| 116 | else |
| 117 | pushOltOperInd(i, "pon", "up"); |
| 118 | } |
| 119 | sleep(2); |
| 120 | // Enable all NNI interfaces. |
| 121 | #if 0 |
| 122 | for (int i = 0; i < NumNniIf_(); i++) { |
| 123 | status = EnableUplinkIf_(i); |
| 124 | if (!status.ok()) { |
| 125 | // raise alarm to report error in enabling PON |
| 126 | pushOltOperInd(i, "nni", "down"); |
| 127 | } |
| 128 | else |
| 129 | pushOltOperInd(i, "nni", "up"); |
| 130 | } |
| 131 | #endif |
| 132 | //only for nni-65536 mapping to intf_id 0 |
| 133 | status = SetStateUplinkIf_(0, true); |
| 134 | if (!status.ok()) { |
| 135 | // raise alarm to report error in enabling NNI |
| 136 | pushOltOperInd(0, "nni", "down"); |
| 137 | } |
| 138 | else |
| 139 | pushOltOperInd(0, "nni", "up"); |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 140 | RunServer(); |
| 141 | |
Shad Ansari | 627b578 | 2018-08-13 22:49:32 +0000 | [diff] [blame] | 142 | return 0; |
Shad Ansari | 01b0e65 | 2018-04-05 21:02:53 +0000 | [diff] [blame] | 143 | } |