|
| 1 | +// #include "bird_app.h" |
| 2 | +#include "common/define.h" |
| 3 | +#include "controlplane/libbird.h" |
| 4 | + |
| 5 | +#include <iostream> |
| 6 | +#include <variant> |
| 7 | + |
| 8 | +common::log::LogPriority common::log::logPriority = common::log::TLOG_DEBUG; |
| 9 | + |
| 10 | +std::ostream& operator<<(std::ostream& os, const common::community_t& lc) |
| 11 | +{ |
| 12 | + os << lc.toString(); |
| 13 | + return os; |
| 14 | +} |
| 15 | + |
| 16 | +std::ostream& operator<<(std::ostream& os, const common::large_community_t& lc) |
| 17 | +{ |
| 18 | + os << lc.toString(); |
| 19 | + return os; |
| 20 | +} |
| 21 | + |
| 22 | +template<typename T> |
| 23 | +std::ostream& PrintCollection(std::ostream& os, T& data, char left, char right) |
| 24 | +{ |
| 25 | + if (data.empty()) |
| 26 | + { |
| 27 | + os << "null"; |
| 28 | + return os; |
| 29 | + } |
| 30 | + |
| 31 | + os << left; |
| 32 | + bool first = true; |
| 33 | + for (const auto& value : data) |
| 34 | + { |
| 35 | + if (first) |
| 36 | + { |
| 37 | + first = false; |
| 38 | + } |
| 39 | + else |
| 40 | + { |
| 41 | + os << ", "; |
| 42 | + } |
| 43 | + os << value; |
| 44 | + } |
| 45 | + os << right; |
| 46 | + |
| 47 | + return os; |
| 48 | +} |
| 49 | + |
| 50 | +template<typename T> |
| 51 | +std::ostream& operator<<(std::ostream& os, const std::set<T>& data) |
| 52 | +{ |
| 53 | + return PrintCollection(os, data, '{', '}'); |
| 54 | +} |
| 55 | + |
| 56 | +template<typename T> |
| 57 | +std::ostream& operator<<(std::ostream& os, const std::vector<T>& data) |
| 58 | +{ |
| 59 | + return PrintCollection(os, data, '[', ']'); |
| 60 | +} |
| 61 | + |
| 62 | +void PrintRibRequests(common::icp::rib_update::request& requests) |
| 63 | +{ |
| 64 | + std::cout << "--------------------------------------------\n"; |
| 65 | + std::cout << "new requests: " << requests.size() << "\n"; |
| 66 | + for (const auto& action : requests) |
| 67 | + { |
| 68 | + if (std::holds_alternative<common::icp::rib_update::insert>(action)) |
| 69 | + { |
| 70 | + const auto& [protocol, vrf, priority, insert_data] = std::get<common::icp::rib_update::insert>(action); |
| 71 | + std::cout << "insert, protocol=" << protocol << ", vrf=" << vrf << ", priority=" << priority << "\n"; |
| 72 | + for (const auto& [key, tables] : insert_data) |
| 73 | + { |
| 74 | + const auto& [peer, origin, med, aspath, community, large_community, local_preference] = key; |
| 75 | + std::cout << "\tpeer=" << peer.toString() << ", origin=" << origin << ", med=" << med |
| 76 | + << ", aspath=" << aspath << ", community=" << community |
| 77 | + << ", large_community=" << large_community << "\n"; |
| 78 | + for (const auto& [table_name, nexthops] : tables) |
| 79 | + { |
| 80 | + std::cout << "\t\ttable_name=" << table_name << "\n"; |
| 81 | + for (const auto& [nexthop, prefixes] : nexthops) |
| 82 | + { |
| 83 | + std::cout << "\t\t\tnexthop=" << nexthop.toString() << "\n"; |
| 84 | + for (const auto& [prefix, path_information, labels] : prefixes) |
| 85 | + { |
| 86 | + std::cout << "\t\t\t\tprefix=" << prefix.toString() << ", path_information=" |
| 87 | + << path_information << ", labels=" << labels << "\n"; |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + else if (std::holds_alternative<common::icp::rib_update::remove>(action)) |
| 94 | + { |
| 95 | + const auto& [protocol, vrf, priority, peers] = std::get<common::icp::rib_update::remove>(action); |
| 96 | + std::cout << "remove, protocol=" << protocol << ", vrf=" << vrf << ", priority=" << priority << "\n"; |
| 97 | + for (const auto& [peer, tables] : peers) |
| 98 | + { |
| 99 | + std::cout << "\tpeer=" << peer.toString() << "\n"; |
| 100 | + for (const auto& [table_name, prefixes] : tables) |
| 101 | + { |
| 102 | + std::cout << "\t\ttable_name=" << table_name << "\n"; |
| 103 | + for (const auto& [prefix, path_information, labels] : prefixes) |
| 104 | + { |
| 105 | + std::cout << "\t\t\tprefix=" << prefix.toString() << ", path_information=" |
| 106 | + << path_information << ", labels=" << labels << "\n"; |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + else |
| 112 | + { |
| 113 | + std::cout << "bad action type\n"; |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + requests.clear(); |
| 118 | + std::cout.flush(); |
| 119 | +} |
| 120 | + |
| 121 | +int main(int argc, char** argv) |
| 122 | +{ |
| 123 | + if (argc != 2) |
| 124 | + { |
| 125 | + std::cout << "Usage: " << argv[0] << " <name_socket_from_bird>\n"; |
| 126 | + return 1; |
| 127 | + } |
| 128 | + |
| 129 | + const char* sock_name = argv[1]; |
| 130 | + const char* vrf = "default"; |
| 131 | + read_bird_feed(sock_name, vrf, PrintRibRequests); |
| 132 | + |
| 133 | + return 0; |
| 134 | +} |
0 commit comments