Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ipv4 connectivity #262

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions common/define.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ extern LogPriority logPriority;
#define YANET_RIB_PRIORITY_ROUTE_REPEAT ((uint32_t)12000)

#define YANET_DEFAULT_BGP_AS ((uint32_t)13238)
#define YANET_DEFAULT_ROUTE_TUNNEL_LABEL ((uint32_t)3199)
#define YANET_DEFAULT_ROUTE_TUNNEL_PATH_INFORMATION "127.0.0.1:10000"

#define YANET_NETWORK_FLAG_FRAGMENT ((uint8_t)(1u << 0))
#define YANET_NETWORK_FLAG_NOT_FIRST_FRAGMENT ((uint8_t)(1u << 1))
Expand Down
3 changes: 3 additions & 0 deletions controlplane/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ class base_rib
public:
ip_prefix_t prefix;
ip_address_t nexthop;
bool is_tunnel;
std::string path_information;
uint32_t label;
};

//
Expand Down
6 changes: 6 additions & 0 deletions controlplane/configparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,12 @@ void config_parser_t::loadConfig_rib(controlplane::base_t& baseNext,
controlplane::base_rib base_rib;
base_rib.prefix = json_rib_item["prefix"].get<std::string>();
base_rib.nexthop = json_rib_item["nexthop"].get<std::string>();
base_rib.is_tunnel = (exist(json_rib_item, "tunnel") && json_rib_item["tunnel"].get<bool>());
if (base_rib.is_tunnel)
{
base_rib.path_information = (exist(json_rib_item, "path_information") ? json_rib_item["path_information"].get<std::string>() : YANET_DEFAULT_ROUTE_TUNNEL_PATH_INFORMATION);
base_rib.label = (exist(json_rib_item, "label") ? json_rib_item["label"].get<uint32_t>() : YANET_DEFAULT_ROUTE_TUNNEL_LABEL);
}
Comment on lines +1908 to +1913
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nlohman lib has value method for this purpose, to extract value if it exists, or set default value if it does not:

base_rib.is_tunnel = json_rib_item.value("tunnel", false);

if (base_rib.is_tunnel)
{
    base_rib.path_information = json_rib_item.value("path_information", YANET_DEFAULT_ROUTE_TUNNEL_PATH_INFORMATION);
    base_rib.label = json_rib_item.value("label", YANET_DEFAULT_ROUTE_TUNNEL_LABEL);
}


vrf.emplace_back(std::move(base_rib));
}
Expand Down
19 changes: 15 additions & 4 deletions controlplane/rib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,21 @@ void rib_t::reload([[maybe_unused]] const controlplane::base_t& base_prev,

for (const auto& rib_item : rib_items)
{
auto& prefixes = std::get<3>(request_insert)[{ip_address_t("::"), "", 0, {}, {}, {}, 0}]
[""]
[rib_item.nexthop];
prefixes.emplace_back(rib_item.prefix, "", std::vector<uint32_t>());
if (rib_item.is_tunnel)
{
common::large_community_t large_community(YANET_DEFAULT_BGP_AS, 1, 1);
auto& prefixes = std::get<3>(request_insert)[{ip_address_t("::"), "", 0, {}, {}, {large_community}, 0}]
[""]
[rib_item.nexthop];
prefixes.emplace_back(rib_item.prefix, rib_item.path_information, std::vector<uint32_t>(1, rib_item.label));
}
else
{
auto& prefixes = std::get<3>(request_insert)[{ip_address_t("::"), "", 0, {}, {}, {}, 0}]
[""]
[rib_item.nexthop];
prefixes.emplace_back(rib_item.prefix, "", std::vector<uint32_t>());
}
}

request.emplace_back(std::move(request_insert));
Expand Down