mirror of
https://github.com/rtbrick/bngblaster.git
synced 2024-05-06 15:54:57 +00:00
add support for ospf sequence number caching
This commit is contained in:
committed by
Christian Giese
parent
2f9d4538d7
commit
5c4f9575da
@@ -324,7 +324,7 @@ lspgen_get_prefix_inc(uint32_t afi, uint32_t prefix_len)
|
||||
* Walk the graph of the LSDB and add the required node/link attributes for LSP generation.
|
||||
*/
|
||||
void
|
||||
lspgen_gen_attr(struct lsdb_ctx_ *ctx)
|
||||
lspgen_gen_isis_attr(struct lsdb_ctx_ *ctx)
|
||||
{
|
||||
struct lsdb_node_ *node;
|
||||
struct lsdb_link_ *link;
|
||||
@@ -937,6 +937,10 @@ main(int argc, char *argv[])
|
||||
break;
|
||||
case 'V':
|
||||
/* level */
|
||||
if (ctx->protocol_id != PROTO_ISIS) {
|
||||
LOG(ERROR, "Level may not be set for protocol %s\n", lsdb_format_proto(ctx));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
ctx->topology_id.level = atoi(optarg);
|
||||
if (ctx->topology_id.level < 1 || ctx->topology_id.level > 2) {
|
||||
LOG(ERROR, "Level %u is not supported\n", ctx->topology_id.level);
|
||||
@@ -968,7 +972,9 @@ main(int argc, char *argv[])
|
||||
/*
|
||||
* Generate the node and link attributes.
|
||||
*/
|
||||
lspgen_gen_attr(ctx);
|
||||
if (ctx->protocol_id == PROTO_ISIS) {
|
||||
lspgen_gen_isis_attr(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -30,6 +30,26 @@ lspgen_write_node_seq_cache(lsdb_node_t *node, json_t *level_arr)
|
||||
json_decref(node_obj);
|
||||
}
|
||||
|
||||
char *
|
||||
lspgen_seq_cache_filename(lsdb_ctx_t *ctx)
|
||||
{
|
||||
static char seq_cache_filename[64];
|
||||
|
||||
if (ctx->protocol_id == PROTO_ISIS) {
|
||||
snprintf(seq_cache_filename, sizeof(seq_cache_filename),
|
||||
"isis-level%u-sequence-cache.json", ctx->topology_id.level);
|
||||
return seq_cache_filename;
|
||||
}
|
||||
|
||||
if (ctx->protocol_id == PROTO_OSPF2 || ctx->protocol_id == PROTO_OSPF3) {
|
||||
snprintf(seq_cache_filename, sizeof(seq_cache_filename),
|
||||
"ospf-area%s-sequence-cache.json", format_ipv4_address(&ctx->topology_id.area));
|
||||
return seq_cache_filename;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
lspgen_write_seq_cache(lsdb_ctx_t *ctx)
|
||||
{
|
||||
@@ -38,10 +58,13 @@ lspgen_write_seq_cache(lsdb_ctx_t *ctx)
|
||||
json_t *root_obj, *arr;
|
||||
int res;
|
||||
uint32_t num_nodes;
|
||||
char seq_cache_filename[32];
|
||||
char *seq_cache_filename;
|
||||
|
||||
snprintf(seq_cache_filename, sizeof(seq_cache_filename),
|
||||
"level%u-sequence-cache.json", ctx->topology_id.level);
|
||||
seq_cache_filename = lspgen_seq_cache_filename(ctx);
|
||||
if (!seq_cache_filename) {
|
||||
LOG(ERROR, "Error building sequence cache file\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->seq_cache_file = fopen(seq_cache_filename, "w");
|
||||
if (!ctx->seq_cache_file) {
|
||||
@@ -133,11 +156,13 @@ lspgen_read_seq_cache(lsdb_ctx_t *ctx)
|
||||
json_t *root_obj;
|
||||
json_error_t error;
|
||||
json_t *level;
|
||||
char *seq_cache_filename;
|
||||
|
||||
char seq_cache_filename[32];
|
||||
|
||||
snprintf(seq_cache_filename, sizeof(seq_cache_filename),
|
||||
"level%u-sequence-cache.json", ctx->topology_id.level);
|
||||
seq_cache_filename = lspgen_seq_cache_filename(ctx);
|
||||
if (!seq_cache_filename) {
|
||||
LOG(ERROR, "Error building sequence cache file\n");
|
||||
return;
|
||||
}
|
||||
|
||||
root_obj = json_load_file(seq_cache_filename, 0, &error);
|
||||
if (!root_obj) {
|
||||
|
||||
Reference in New Issue
Block a user