mirror of
https://github.com/rtbrick/bngblaster.git
synced 2024-05-06 15:54:57 +00:00
preparation lspgen support for ospf
This commit is contained in:
committed by
Christian Giese
parent
0e6f052d99
commit
75e5692396
@@ -11,8 +11,8 @@
|
||||
#include <strings.h>
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @brief
|
||||
*
|
||||
* @param text pointer to data stream
|
||||
* @param text_len length of data stream
|
||||
* @param key pointer to authentication key
|
||||
@@ -20,8 +20,8 @@
|
||||
* @param digest caller digest to be filled in
|
||||
*/
|
||||
void
|
||||
hmac_md5(unsigned char* text, int text_len,
|
||||
unsigned char* key, int key_len,
|
||||
hmac_md5(unsigned char* text, int text_len,
|
||||
unsigned char* key, int key_len,
|
||||
uint8_t* digest)
|
||||
{
|
||||
HMAC_CTX *hmac = HMAC_CTX_new();
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#define __HMAC_MD5_H__
|
||||
|
||||
void
|
||||
hmac_md5(unsigned char* text, int text_len,
|
||||
unsigned char*key, int key_len,
|
||||
hmac_md5(unsigned char* text, int text_len,
|
||||
unsigned char*key, int key_len,
|
||||
uint8_t* digest);
|
||||
|
||||
#endif
|
||||
@@ -39,6 +39,7 @@ const char banner[] = "\n"
|
||||
static struct option long_options[] = {
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{"area", required_argument, NULL, 'a'},
|
||||
{"protocol", required_argument, NULL, 'P'},
|
||||
{"authentication-key", required_argument, NULL, 'K'},
|
||||
{"authentication-type", required_argument, NULL, 'T'},
|
||||
{"read-config-file", required_argument, NULL, 'r'},
|
||||
@@ -87,6 +88,23 @@ struct keyval_ log_names[] = {
|
||||
{ 0, NULL}
|
||||
};
|
||||
|
||||
/*
|
||||
* Protocool / name translation table.
|
||||
*/
|
||||
struct keyval_ proto_names[] = {
|
||||
{ PROTO_ISIS, "isis" },
|
||||
{ PROTO_OSPF2, "ospf2" },
|
||||
{ PROTO_OSPF2, "ospf" }, /* "ospf" is an alias for ospf2 */
|
||||
{ PROTO_OSPF3, "ospf3" },
|
||||
{ 0, NULL}
|
||||
};
|
||||
|
||||
const char *
|
||||
lsdb_format_proto (struct lsdb_ctx_ *ctx)
|
||||
{
|
||||
return val2key(proto_names, ctx->protocol_id);
|
||||
}
|
||||
|
||||
/*
|
||||
* IS-IS authentication type / name translation table.
|
||||
*/
|
||||
@@ -501,6 +519,8 @@ lspgen_init_ctx(struct lsdb_ctx_ *ctx)
|
||||
CIRCLEQ_INIT(&ctx->packet_change_qhead);
|
||||
timer_init_root(&ctx->timer_root);
|
||||
|
||||
ctx->protocol_id = PROTO_ISIS;
|
||||
|
||||
ctx->num_nodes = 10; /* Number of nodes */
|
||||
|
||||
/* IS-IS area */
|
||||
@@ -595,6 +615,7 @@ lspgen_log_ctx(struct lsdb_ctx_ *ctx)
|
||||
uint32_t idx;
|
||||
|
||||
LOG_NOARG(NORMAL, "LSP generation parameters\n");
|
||||
LOG(NORMAL, " Protocol %s\n", lsdb_format_proto(ctx));
|
||||
|
||||
/*
|
||||
* No Area specified ? SHow at least the default
|
||||
@@ -602,11 +623,14 @@ lspgen_log_ctx(struct lsdb_ctx_ *ctx)
|
||||
if (!ctx->num_area) {
|
||||
ctx->num_area = 1;
|
||||
}
|
||||
for (idx = 0; idx < ctx->num_area; idx++) {
|
||||
LOG(NORMAL, " Area %s\n", format_iso_prefix(&ctx->area[idx]));
|
||||
|
||||
if (ctx->protocol_id == PROTO_ISIS) {
|
||||
for (idx = 0; idx < ctx->num_area; idx++) {
|
||||
LOG(NORMAL, " Area %s\n", format_iso_prefix(&ctx->area[idx]));
|
||||
}
|
||||
LOG(NORMAL, " Level %u, sequence 0x%x, lsp-lifetime %u\n",
|
||||
ctx->topology_id.level, ctx->sequence, ctx->lsp_lifetime);
|
||||
}
|
||||
LOG(NORMAL, " Level %u, sequence 0x%x, lsp-lifetime %u\n",
|
||||
ctx->topology_id.level, ctx->sequence, ctx->lsp_lifetime);
|
||||
if (ctx->authentication_key) {
|
||||
LOG(NORMAL, " Authentication-key %s, Authentication-type %s\n",
|
||||
ctx->authentication_key, val2key(isis_auth_names, ctx->authentication_type));
|
||||
@@ -756,7 +780,7 @@ main(int argc, char *argv[])
|
||||
log_id[NORMAL].enable = true;
|
||||
log_id[ERROR].enable = true;
|
||||
|
||||
ctx = lsdb_alloc_ctx("default", "isis", "unicast");
|
||||
ctx = lsdb_alloc_ctx("default");
|
||||
if (!ctx) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -766,12 +790,15 @@ main(int argc, char *argv[])
|
||||
* Parse options.
|
||||
*/
|
||||
idx = 0;
|
||||
while ((opt = getopt_long(argc, argv, "vha:c:C:e:f:g:l:L:m:M:n:K:N:p:q:Qr:s:S:t:T:V:w:x:X:yzZ",
|
||||
while ((opt = getopt_long(argc, argv, "vha:c:C:e:f:g:l:L:m:M:n:K:N:p:P:q:Qr:s:S:t:T:V:w:x:X:yzZ",
|
||||
long_options, &idx)) != -1) {
|
||||
switch (opt) {
|
||||
case 'v':
|
||||
lspgen_print_version();
|
||||
exit(0);
|
||||
case 'P':
|
||||
ctx->protocol_id = key2val(proto_names, optarg);
|
||||
break;
|
||||
case 'r':
|
||||
if (ctx->config_filename) {
|
||||
ctx->config_write = false;
|
||||
|
||||
@@ -94,7 +94,7 @@ lsdb_format_link(lsdb_link_t *link)
|
||||
remote_node = NULL;
|
||||
}
|
||||
|
||||
if (!strcmp(ctx->protocol_name, "isis")) {
|
||||
if (ctx->protocol_id == PROTO_ISIS) {
|
||||
if (node->node_name) {
|
||||
idx = snprintf(buffer, sizeof(buffer), "%s", node->node_name);
|
||||
} else {
|
||||
@@ -107,7 +107,7 @@ lsdb_format_link(lsdb_link_t *link)
|
||||
idx += snprintf(buffer + idx, sizeof(buffer) - idx, " -> %s",
|
||||
lsdb_format_node_id(link->key.remote_node_id));
|
||||
}
|
||||
} else if (!strcmp(ctx->protocol_name, "ospf")) {
|
||||
} else if (ctx->protocol_id == PROTO_OSPF2) {
|
||||
if (node->node_name) {
|
||||
idx = snprintf(buffer, sizeof(buffer), "%s", node->node_name);
|
||||
} else {
|
||||
@@ -167,13 +167,13 @@ lsdb_format_node(lsdb_node_t *node)
|
||||
|
||||
ctx = node->ctx;
|
||||
|
||||
if (!strcmp(ctx->protocol_name, "isis")) {
|
||||
if (ctx->protocol_id == PROTO_ISIS) {
|
||||
if (node->node_name) {
|
||||
snprintf(buffer, sizeof(buffer), "%s", node->node_name);
|
||||
} else {
|
||||
snprintf(buffer, sizeof(buffer), "%s", lsdb_format_node_id(node->key.node_id));
|
||||
}
|
||||
} else if (!strcmp(ctx->protocol_name, "ospf")) {
|
||||
} else if (ctx->protocol_id == PROTO_OSPF2) {
|
||||
if (node->node_name) {
|
||||
snprintf(buffer, sizeof(buffer), "%s", node->node_name);
|
||||
} else {
|
||||
@@ -290,7 +290,7 @@ lsdb_compare_packet(void *key1, void *key2)
|
||||
|
||||
|
||||
struct lsdb_ctx_ *
|
||||
lsdb_alloc_ctx(char *instance, char *protocol, char *topology)
|
||||
lsdb_alloc_ctx(char *instance)
|
||||
{
|
||||
struct lsdb_ctx_ *ctx;
|
||||
|
||||
@@ -305,12 +305,6 @@ lsdb_alloc_ctx(char *instance, char *protocol, char *topology)
|
||||
if (instance) {
|
||||
ctx->instance_name = strdup(instance);
|
||||
}
|
||||
if (instance) {
|
||||
ctx->protocol_name = strdup(protocol);
|
||||
}
|
||||
if (instance) {
|
||||
ctx->topology_name = strdup(topology);
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize node DB.
|
||||
@@ -322,8 +316,7 @@ lsdb_alloc_ctx(char *instance, char *protocol, char *topology)
|
||||
*/
|
||||
ctx->link_dict = hashtable2_dict_new((dict_compare_func) lsdb_compare_link, dict_str_hash, LSDB_LINK_HSIZE);
|
||||
|
||||
LOG(NORMAL, "Add context for instance %s, protocol %s, topology %s\n",
|
||||
ctx->instance_name, ctx->protocol_name, ctx->topology_name);
|
||||
LOG(NORMAL, "Add context for instance %s\n", ctx->instance_name);
|
||||
|
||||
return ctx;
|
||||
}
|
||||
@@ -832,8 +825,6 @@ lsdb_delete_ctx(struct lsdb_ctx_ *ctx)
|
||||
ctx->node_dict = NULL;
|
||||
|
||||
lsdb_free_name(&ctx->instance_name);
|
||||
lsdb_free_name(&ctx->protocol_name);
|
||||
lsdb_free_name(&ctx->topology_name);
|
||||
lsdb_free_name(&ctx->graphviz_filename);
|
||||
lsdb_free_name(&ctx->pcap_filename);
|
||||
lsdb_free_name(&ctx->mrt_filename);
|
||||
@@ -895,7 +886,7 @@ lsdb_dump_graphviz(lsdb_ctx_t *ctx)
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(graphviz, "digraph \"%s.%s.%s\" {\n", ctx->instance_name, ctx->protocol_name, ctx->topology_name);
|
||||
fprintf(graphviz, "digraph \"%s.%s\" {\n", ctx->instance_name, lsdb_format_proto(ctx));
|
||||
|
||||
/*
|
||||
* First lookup the root node.
|
||||
|
||||
@@ -22,6 +22,13 @@
|
||||
#define LSDB_NODE_HSIZE 997 /* hash table initial bucket size */
|
||||
#define LSDB_LINK_HSIZE 9973 /* hash table initial bucket size */
|
||||
|
||||
typedef enum {
|
||||
PROTO_UNKNOWN = 0,
|
||||
PROTO_ISIS = 1,
|
||||
PROTO_OSPF2 = 2,
|
||||
PROTO_OSPF3 = 3
|
||||
} lsdb_proto_id_t;
|
||||
|
||||
typedef struct lsdb_node_id_ {
|
||||
uint8_t node_id[LSDB_MAX_NODE_ID_SIZE];
|
||||
} lsdb_node_id_t;
|
||||
@@ -45,10 +52,10 @@ typedef struct lsdb_ctx_
|
||||
uint8_t root_node_id[LSDB_MAX_NODE_ID_SIZE];
|
||||
|
||||
char *instance_name; /* Name for this instance e.g. "default" */
|
||||
char *protocol_name; /* Name for this protocol e.g. "isis, ospf" */
|
||||
char *topology_name; /* Name for this topology e.g. "level-1", "area 51" */
|
||||
lsdb_proto_id_t protocol_id; /* e.g. "isis, ospf2, ospf3" */
|
||||
union {
|
||||
uint8_t level; /* IS-IS */
|
||||
uint32_t area; /* OSPF */
|
||||
} topology_id;
|
||||
|
||||
/*
|
||||
@@ -305,6 +312,7 @@ char *lsdb_format_node(lsdb_node_t *);
|
||||
char *lsdb_format_node_id(unsigned char *);
|
||||
char *lsdb_format_link(lsdb_link_t *);
|
||||
void lsdb_scan_node_id(uint8_t *, char *);
|
||||
const char *lsdb_format_proto(struct lsdb_ctx_ *);
|
||||
|
||||
lsdb_link_t *lsdb_add_link(lsdb_ctx_t *, lsdb_node_t *, lsdb_link_t *);
|
||||
lsdb_link_t *lsdb_get_link(lsdb_ctx_t *, lsdb_link_t *);
|
||||
@@ -314,7 +322,7 @@ lsdb_attr_t *lsdb_add_node_attr(lsdb_node_t *, lsdb_attr_t *);
|
||||
void lsdb_reset_attr_template(lsdb_attr_t *);
|
||||
void lsdb_delete_link(lsdb_ctx_t *, lsdb_link_t *);
|
||||
void lsdb_delete_node(lsdb_ctx_t *, lsdb_node_t *);
|
||||
lsdb_ctx_t *lsdb_alloc_ctx(char *, char *, char *);
|
||||
lsdb_ctx_t *lsdb_alloc_ctx(char *);
|
||||
void lsdb_delete_ctx(lsdb_ctx_t *);
|
||||
void lsdb_dump_graphviz(lsdb_ctx_t *);
|
||||
int lsdb_compare_node(void *, void *);
|
||||
|
||||
Reference in New Issue
Block a user