Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions code/lspgen/src/lspgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1338,8 +1338,8 @@ main(int argc, char *argv[])
break;
case 'M':
ctx->lsp_lifetime = atoi(optarg);
if (ctx->lsp_lifetime < 120) {
ctx->lsp_lifetime = 120;
if (ctx->lsp_lifetime < LSP_LIFETIME_MIN) {
ctx->lsp_lifetime = LSP_LIFETIME_MIN;
LOG(ERROR, "Set lsp-lifetime to min %us\n", ctx->lsp_lifetime);
}
break;
Expand Down
43 changes: 31 additions & 12 deletions code/lspgen/src/lspgen_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ lspgen_write_node_common_config(lsdb_ctx_t *ctx, lsdb_node_t *node, json_t *node
}
if (node->attach) {
json_object_set_new(node_obj, "attach", json_boolean(1));
}
}
json_object_set_new(node_obj, "lsp_buffer_size", json_integer(ISIS_DEFAULT_LSP_BUFFER_SIZE));
break;
case PROTO_OSPF2:
Expand Down Expand Up @@ -647,6 +647,7 @@ lspgen_write_config(lsdb_ctx_t *ctx)
root_obj = json_object();
json_object_set_new(root_obj, "instance", json_string(ctx->instance_name));
json_object_set_new(root_obj, "protocol", json_string(lsdb_format_proto(ctx)));
json_object_set_new(root_obj, "lsp_lifetime", json_integer(ctx->lsp_lifetime));
arr = json_array();

switch (ctx->protocol_id) {
Expand Down Expand Up @@ -1160,7 +1161,17 @@ lspgen_read_node_config(lsdb_ctx_t *ctx, json_t *node_obj)
if (json_unpack(node_obj, "{s:s}", "hostname", &s) == 0) {
node_template.node_name = s;
}
node = lsdb_add_node(ctx, &node_template);

if (json_unpack(node_obj, "{s:s}", "sequence", &s) == 0) {
node_template.sequence = strtol(s, NULL, 0);
}

value = json_object_get(node_obj, "lsp_lifetime");
if (value && json_is_integer(value)) {
node_template.lsp_lifetime = json_integer_value(value);
}

node = lsdb_add_node(ctx, &node_template);

if (node_template.node_name) {
lsdb_reset_attr_template(&attr_template);
Expand Down Expand Up @@ -1192,15 +1203,6 @@ lspgen_read_node_config(lsdb_ctx_t *ctx, json_t *node_obj)
}
}

if (json_unpack(node_obj, "{s:s}", "sequence", &s) == 0) {
node->sequence = strtol(s, NULL, 0);
}

value = json_object_get(node_obj, "lsp_lifetime");
if (value && json_is_integer(value)) {
node->lsp_lifetime = json_integer_value(value);
}

value = json_object_get(node_obj, "adjacency_sid_base");
if (value && json_is_integer(value)) {
adj_sid = json_integer_value(value);
Expand Down Expand Up @@ -1324,7 +1326,7 @@ lspgen_read_config(lsdb_ctx_t *ctx)
{
json_t *root_obj;
json_error_t error;
json_t *protocol, *instance;
json_t *protocol, *instance, *lsp_lifetime;
json_t *lsdb;
bool lsdb_found;
const char *key;
Expand Down Expand Up @@ -1383,6 +1385,23 @@ lspgen_read_config(lsdb_ctx_t *ctx)
}
ctx->instance_name = strdup(json_string_value(instance));

/*
* LSP lifetime. Optional.
*/
lsp_lifetime = json_object_get(root_obj, "lsp_lifetime");
if (lsp_lifetime) {
if (!json_is_integer(lsp_lifetime)) {
LOG(ERROR, "Error reading config file %s, lsp_lifetime attribute is not an integer\n",
ctx->config_filename);
goto cleanup;
}
ctx->lsp_lifetime = json_integer_value(lsp_lifetime);
if (ctx->lsp_lifetime < LSP_LIFETIME_MIN) {
ctx->lsp_lifetime = LSP_LIFETIME_MIN;
LOG(ERROR, "Set lsp-lifetime to min %us\n", ctx->lsp_lifetime);
}
}

/* Iterate through all top level objects */
lsdb_found = false;
json_object_foreach(root_obj, key, lsdb) {
Expand Down
18 changes: 14 additions & 4 deletions code/lspgen/src/lspgen_lsdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,12 +553,22 @@ lsdb_add_node(struct lsdb_ctx_ *ctx, struct lsdb_node_ *node_template)
node->ctx = ctx;

/*
* Default sequence number to inherit from context.
* Get values from template if set, else read default values from context.
*/
node->sequence = ctx->sequence;
if (node_template->sequence) {
node->sequence = node_template->sequence;
} else {
node->sequence = ctx->sequence;
}

if (node_template->lsp_lifetime) {
node->lsp_lifetime = node_template->lsp_lifetime;
} else {
node->lsp_lifetime = ctx->lsp_lifetime;
}

LOG(LSDB, " Add node %s (%s)\n", lsdb_format_node(node),
lsdb_format_node_id(node->key.node_id));
LOG(LSDB, " Add node %s (%s), seq 0x%08x, lifetime %us\n", lsdb_format_node(node),
lsdb_format_node_id(node->key.node_id), node->sequence, node->lsp_lifetime);

return node;
}
Expand Down
2 changes: 2 additions & 0 deletions code/lspgen/src/lspgen_lsdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#define LSDB_NODE_HSIZE 997 /* hash table initial bucket size */
#define LSDB_LINK_HSIZE 9973 /* hash table initial bucket size */

#define LSP_LIFETIME_MIN 120 /* secs */

typedef enum {
PROTO_UNKNOWN = 0,
PROTO_ISIS = 1,
Expand Down
Loading