|
|
|
|
@ -88,9 +88,9 @@ static void route_bgp_broadcast_route(struct ROUTE_BGP* bgp, const struct ROUTE_
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char net_buf[16]; |
|
|
|
|
format_ip(route->network, net_buf); |
|
|
|
|
format_ip(route->peer_info.network, net_buf); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Broadcasted route %s/%d to %d connections", |
|
|
|
|
net_buf, route->prefix_length, sent_count); |
|
|
|
|
net_buf, route->peer_info.prefix_length, sent_count); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -128,11 +128,11 @@ static void route_bgp_send_route(struct ROUTE_BGP* bgp, struct ETCP_CONN* conn,
|
|
|
|
|
|
|
|
|
|
pkt->cmd = ETCP_ID_ROUTE_ENTRY; |
|
|
|
|
pkt->subcmd = ROUTE_SUBCMD_ENTRY; |
|
|
|
|
pkt->peer_info.node_id = htobe64(route->node_id); |
|
|
|
|
pkt->peer_info.network = htonl(route->network); |
|
|
|
|
pkt->peer_info.prefix_length = route->prefix_length; |
|
|
|
|
pkt->peer_info.hop_count = route->hop_count; |
|
|
|
|
pkt->peer_info.latency = htons(route->latency); |
|
|
|
|
pkt->peer_info.node_id = htobe64(route->peer_info.node_id); |
|
|
|
|
pkt->peer_info.network = htonl(route->peer_info.network); |
|
|
|
|
pkt->peer_info.prefix_length = route->peer_info.prefix_length; |
|
|
|
|
pkt->peer_info.hop_count = route->peer_info.hop_count; |
|
|
|
|
pkt->peer_info.latency = htons(route->peer_info.latency); |
|
|
|
|
// Add other fields if present, e.g., bandwidth
|
|
|
|
|
|
|
|
|
|
struct ll_entry *send_entry = queue_entry_new(0); |
|
|
|
|
@ -163,11 +163,11 @@ static void route_bgp_send_reroute(struct ROUTE_BGP* bgp, struct ETCP_CONN* conn
|
|
|
|
|
pkt->cmd = ETCP_ID_ROUTE_ENTRY; |
|
|
|
|
pkt->subcmd = ROUTE_SUBCMD_ENTRY_REROUTE; |
|
|
|
|
pkt->old_node_id = htobe64(old_node_id); |
|
|
|
|
pkt->peer_info.node_id = htobe64(route->node_id); |
|
|
|
|
pkt->peer_info.network = htonl(route->network); |
|
|
|
|
pkt->peer_info.prefix_length = route->prefix_length; |
|
|
|
|
pkt->peer_info.hop_count = route->hop_count; |
|
|
|
|
pkt->peer_info.latency = htons(route->latency); |
|
|
|
|
pkt->peer_info.node_id = htobe64(route->peer_info.node_id); |
|
|
|
|
pkt->peer_info.network = htonl(route->peer_info.network); |
|
|
|
|
pkt->peer_info.prefix_length = route->peer_info.prefix_length; |
|
|
|
|
pkt->peer_info.hop_count = route->peer_info.hop_count; |
|
|
|
|
pkt->peer_info.latency = htons(route->peer_info.latency); |
|
|
|
|
|
|
|
|
|
struct ll_entry *send_entry = queue_entry_new(0); |
|
|
|
|
if (!send_entry) { |
|
|
|
|
@ -227,7 +227,7 @@ static void route_bgp_send_withdraw_for_conn(struct ROUTE_BGP* bgp, struct ETCP_
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < table->count; i++) { |
|
|
|
|
if (table->entries[i].next_hop == conn) { |
|
|
|
|
uint64_t nid = table->entries[i].node_id; |
|
|
|
|
uint64_t nid = table->entries[i].peer_info.node_id; |
|
|
|
|
found = false; |
|
|
|
|
for (size_t j = 0; j < unique_count; j++) { |
|
|
|
|
if (unique_nodes[j] == nid) { |
|
|
|
|
@ -344,15 +344,15 @@ static void route_bgp_receive_cbk(struct ETCP_CONN* from_conn, struct ll_entry*
|
|
|
|
|
struct ROUTE_ENTRY new_route; |
|
|
|
|
memset(&new_route, 0, sizeof(new_route)); |
|
|
|
|
|
|
|
|
|
new_route.node_id = node_id; |
|
|
|
|
new_route.network = network; |
|
|
|
|
new_route.prefix_length = prefix_length; |
|
|
|
|
new_route.peer_info.node_id = node_id; |
|
|
|
|
new_route.peer_info.network = network; |
|
|
|
|
new_route.peer_info.prefix_length = prefix_length; |
|
|
|
|
new_route.next_hop = from_conn; |
|
|
|
|
new_route.type = ROUTE_TYPE_LEARNED; |
|
|
|
|
new_route.flags = ROUTE_FLAG_ACTIVE | ROUTE_FLAG_LEARNED; |
|
|
|
|
new_route.hop_count = hop_count + 1; |
|
|
|
|
new_route.latency = latency + (from_conn->rtt_last * 10); |
|
|
|
|
new_route.metrics.latency_ms = new_route.latency / 10; |
|
|
|
|
new_route.peer_info.hop_count = hop_count + 1; |
|
|
|
|
new_route.peer_info.latency = latency + (from_conn->rtt_last * 10); |
|
|
|
|
new_route.metrics.latency_ms = new_route.peer_info.latency / 10; |
|
|
|
|
// Set defaults for other metrics
|
|
|
|
|
new_route.metrics.bandwidth_kbps = 100000; // example default
|
|
|
|
|
new_route.metrics.packet_loss_rate = 0; |
|
|
|
|
@ -364,13 +364,13 @@ static void route_bgp_receive_cbk(struct ETCP_CONN* from_conn, struct ll_entry*
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < table->count; i++) { |
|
|
|
|
struct ROUTE_ENTRY* existing = &table->entries[i]; |
|
|
|
|
if (existing->network == network && existing->prefix_length == prefix_length) { |
|
|
|
|
if (existing->peer_info.network == network && existing->peer_info.prefix_length == prefix_length) { |
|
|
|
|
exists = true; |
|
|
|
|
if (new_route.hop_count < existing->hop_count) { |
|
|
|
|
if (new_route.peer_info.hop_count < existing->peer_info.hop_count) { |
|
|
|
|
// Update to better route
|
|
|
|
|
existing->next_hop = new_route.next_hop; |
|
|
|
|
existing->hop_count = new_route.hop_count; |
|
|
|
|
existing->latency = new_route.latency; |
|
|
|
|
existing->peer_info.hop_count = new_route.peer_info.hop_count; |
|
|
|
|
existing->peer_info.latency = new_route.peer_info.latency; |
|
|
|
|
existing->metrics = new_route.metrics; |
|
|
|
|
existing->last_update = get_time_tb(); |
|
|
|
|
if (table->change_callback) { |
|
|
|
|
@ -415,9 +415,9 @@ static void route_bgp_receive_cbk(struct ETCP_CONN* from_conn, struct ll_entry*
|
|
|
|
|
size_t i = 0; |
|
|
|
|
while (i < table->count) { |
|
|
|
|
struct ROUTE_ENTRY* rte = &table->entries[i]; |
|
|
|
|
if (rte->node_id == withdrawn_node_id) { |
|
|
|
|
if (rte->peer_info.node_id == withdrawn_node_id) { |
|
|
|
|
if (rte->next_hop == from_conn) { |
|
|
|
|
route_table_delete_entry(table, rte->network, rte->prefix_length, from_conn); |
|
|
|
|
route_table_delete_entry(table, rte->peer_info.network, rte->peer_info.prefix_length, from_conn); |
|
|
|
|
// Do not increment i, array shifted
|
|
|
|
|
} else { |
|
|
|
|
has_alternative = true; |
|
|
|
|
@ -431,7 +431,7 @@ static void route_bgp_receive_cbk(struct ETCP_CONN* from_conn, struct ll_entry*
|
|
|
|
|
if (has_alternative) { |
|
|
|
|
// Send reroute for each remaining route to from_conn
|
|
|
|
|
for (size_t j = 0; j < table->count; j++) { |
|
|
|
|
if (table->entries[j].node_id == withdrawn_node_id) { |
|
|
|
|
if (table->entries[j].peer_info.node_id == withdrawn_node_id) { |
|
|
|
|
route_bgp_send_reroute(bgp, from_conn, withdrawn_node_id, &table->entries[j]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -458,7 +458,7 @@ static void route_bgp_receive_cbk(struct ETCP_CONN* from_conn, struct ll_entry*
|
|
|
|
|
|
|
|
|
|
struct ROUTE_TABLE* table = instance->rt; |
|
|
|
|
for (size_t i = 0; i < table->count; i++) { |
|
|
|
|
if (table->entries[i].node_id == target_node_id) { |
|
|
|
|
if (table->entries[i].peer_info.node_id == target_node_id) { |
|
|
|
|
size_t size = sizeof(struct NODE_CONNS_INFO) +
|
|
|
|
|
sizeof(struct NODE_CONN_INFO); |
|
|
|
|
struct NODE_CONNS_INFO *new_list = u_malloc(size); |
|
|
|
|
|