📄 ospfh.h
字号:
u_int32_t ls_ack_in; /* LS Ack message input count. */
u_int32_t ls_ack_out; /* LS Ack message output count. */
u_int32_t discarded; /* discarded input count by error. */
/*record the thread master*/
struct thread_master *master;
struct cmd_element conf_cmd[CONF_CMD_NUM];
};
struct ospf_neighbor
{
struct ospf *top;
struct in_addr nbr_id; /*Neighbor id*/
// u_char nbr_priority; /*Neighbor Priority*/
// u_char options; /* Options. */
/* LSA data. */
struct list *ls_rxmt; //link state update retransmit
u_int32_t v_ls_upd;
/* Threads. */
struct thread *t_ls_upd; /*ls upd retransmit*/
};
/* 函数声明 */
///////////////////////////////////////////////////////////////
/*thread.c中的函数*/
struct thread_master *thread_master_create ();
struct thread *thread_add_read (struct thread_master *,
int (*)(struct thread *), void *, int);
struct thread *thread_add_write (struct thread_master *,
int (*)(struct thread *), void *, int);
struct thread *thread_add_timer (struct thread_master *,
int (*)(struct thread *), void *, long);
struct thread *thread_add_event (struct thread_master *,
int (*)(struct thread *), void *, int );
void thread_cancel (struct thread *);
void thread_cancel_event (struct thread_master *, void *);
struct thread *thread_fetch (struct thread_master *, struct thread *);
struct thread *thread_execute (struct thread_master *,
int (*)(struct thread *), void *, int);
void thread_call (struct thread *);
unsigned long thread_timer_remain_second (struct thread *);
//线程函数 end
/////////////////////////////////////////////////////////////////
//linklist函数
struct list *list_new();
void list_free (struct list *);
struct listnode * listnode_new ();
void listnode_add (struct list *, void *);
void listnode_add_sort (struct list *, void *);
void listnode_add_after (struct list *, struct listnode *, void *);
void listnode_free (struct listnode *node);
void listnode_delete (struct list *, void *);
struct listnode *listnode_lookup (struct list *, void *);
void *listnode_head (struct list *);
void list_delete (struct list *);
void list_delete_all_node (struct list *);
/* For ospfd and ospf6d. */
void list_delete_node (struct list *, struct listnode*);
/* For ospf_spf.c */
void list_add_node_prev (struct list*, struct listnode*, void *);
void list_add_node_next (struct list*, struct listnode*, void *);
void list_add_list (struct list*, struct list*);
//linklist函数end
/////////////////////////////////////////////////////////////////////////////
//stream 函数
struct stream * stream_new (size_t);
/* Free it now. */
void stream_free (struct stream *);
unsigned long stream_get_getp (struct stream *);
unsigned long stream_get_putp (struct stream *);
unsigned long stream_get_endp (struct stream *);
unsigned long stream_get_size (struct stream *);
/* Stream structre' stream pointer related functions. */
void stream_set_getp (struct stream *, unsigned long );
void stream_set_putp (struct stream *, unsigned long );
/* Forward pointer. */
void stream_forward (struct stream *, int );
/* Copy from stream to destination. */
void stream_get (void *, struct stream *, size_t );
/* Get next character from the stream. */
u_char stream_getc (struct stream *);
/* Get next character from the stream. */
u_char stream_getc_from (struct stream *, unsigned long );
/* Get next word from the stream. */
u_int16_t stream_getw (struct stream *);
/* Get next word from the stream. */
u_int16_t stream_getw_from (struct stream *, unsigned long );
/* Get next long word from the stream. */
u_int32_t stream_getl (struct stream *);
/* Get next long word from the stream. */
u_int32_t stream_get_ipv4 (struct stream *);
/* Copy to source to stream. */
void stream_put (struct stream *, void *, size_t );
/* Put character to the stream. */
int stream_putc (struct stream *, u_char );
/* Put word to the stream. */
int stream_putw (struct stream *, u_int16_t );
/* Put long word to the stream. */
int stream_putl (struct stream *, u_int32_t);
int stream_putc_at (struct stream *, unsigned long , u_char );
int stream_putw_at (struct stream *, unsigned long , u_int16_t );
int stream_putl_at (struct stream *, unsigned long, u_int32_t);
/* Put long word to the stream. */
int stream_put_ipv4 (struct stream *, u_int32_t);
/* Put long word to the stream. */
int stream_put_in_addr (struct stream *, struct in_addr *);
/* Put prefix by nlri type format. */
int stream_put_prefix (struct stream *, struct prefix *);
/* Read size from fd. */
int stream_read (struct stream *, int , size_t);
/* Read size from fd. */
int stream_read_unblock (struct stream *, int , size_t);
/* Write data to buffer. */
int stream_write (struct stream *, u_char *, size_t);
/* Return current read pointer. */
u_char * stream_pnt (struct stream *);
/* Check does this stream empty? */
int stream_empty (struct stream *);
/* Reset stream. */
void stream_reset (struct stream *);
/* Write stream contens to the file discriptor. */
int stream_flush (struct stream *, int );
/* Stream first in first out queue. */
struct stream_fifo * stream_fifo_new ();
/* Add new stream to fifo. */
void stream_fifo_push (struct stream_fifo *, struct stream *);
/* Delete first stream from fifo. */
struct stream * stream_fifo_pop (struct stream_fifo *);
/* Return first fifo entry. */
struct stream * stream_fifo_head (struct stream_fifo *);
void stream_fifo_clean (struct stream_fifo *);
void stream_fifo_free (struct stream_fifo *);
//以下补充各个功能模块中的函数原型声明
//abstract.c
void ospfh_abstract(struct ospf *, struct list *, struct list *);
int ** topology_matrix_create(struct list *,int , struct in_addr*);
int nodenum_caculate(struct list *, struct in_addr*);
int bordernodenum_caculate(struct list *,struct in_addr*);
int dijkstra(int ** , int , int ,int);
//command.c
int router_id_set(int , char** , void *);
char * ip_addr_set(int , char** , void * );
int nbr_id_set(int , char** , void * );
int speaker_rc_id_set(int, char** , void *);
int uplayer_rc_id_set(int , char** , void *);
int downlayer_rc_id_set(int , char** , void * );
struct cmd_element * cmd_filter_by_string (char *, struct ospf *);
int cmd_execute_command_strict (struct vector* , struct cmd_element ** , struct ospf *);
struct vector * cmd_make_strvec (char *);
void cmd_free_strvec (struct vector *);
//d.c
struct ospf * ospfh_init(struct thread_master *);
void ospf_read_config (char *, struct ospf *);
void ospfh_init_continue(struct ospf *);
struct ospf_neighbor * ospf_nbr_new (struct ospf *);
int ospf_read_file (FILE * , struct ospf *);
//feed.c
void ospfh_feed_up_timer(struct thread *);
void ospfh_feed_up_send(struct ospf *);
void ospfh_feed_down_send(struct ospf *,u_char, u_char ,struct ospf_lsa *);
void ospfh_feed_up_receive(struct ospf *);
void ospfh_lower_layer_lsalist_read(struct ospf *,struct list *,struct list *,struct list *);
void ospfh_feed_down_receive(struct ospf * , struct stream *);
//flood.c
void ospf_ls_upd (struct ip *, struct ospf_header *,struct stream *, u_int16_t , struct ospf *);
int id_to_layernum (struct in_addr ) ;
static struct list* ospf_ls_upd_list_lsa (struct ospf_neighbor *, struct stream *,u_int16_t) ;
struct ospf_neighbor * ospf_nbr_lookup_by_addr (struct list *,struct in_addr *);
void ospf_ls_upd_send (struct ospf_neighbor *, struct list *, int );
int ospf_make_ls_upd (struct ospf *, struct list *, struct stream *);
int ls_age_increment (struct ospf_lsa *, int );
int ospf_ls_upd_timer (struct thread *);
void ospf_ls_ack (struct ip *, struct ospf_header *, struct stream *, struct ospf *, u_int16_t);
void ospf_ls_ack_send (struct ospf_neighbor *, struct ospf_lsa *);
void ospf_ls_ack_send_list (struct ospf *, struct list *) ;
int ospf_make_ls_ack (struct list *, struct stream *);
void ospf_ls_ack_send_delayed (struct ospf * );
int ospf_ls_ack_timer (struct thread *);
int ospf_flood (struct ospf_neighbor *, struct ospf_lsa *,struct ospf_lsa *, struct ospf *);
int ospf_flood_through_area (struct ospf* ,struct ospf_neighbor *,struct ospf_lsa *);
int ospf_flood_out (struct ospf *, struct ospf_neighbor *,struct ospf_lsa *);
void ospf_ls_retransmit_delete_nbr_all (struct ospf *,struct ospf_lsa *);
void ospf_ls_retransmit_delete (struct ospf_neighbor *, struct ospf_lsa *);
struct ospf_lsa * ospf_ls_retransmit_lookup (struct ospf_neighbor *, struct ospf_lsa *);
void ospf_ls_retransmit_add (struct ospf_neighbor *, struct ospf_lsa *);
//int ospf_lsa_is_self_originated (struct ospf_lsa *, struct ospf *);
//void ospf_process_self_originated_lsa (struct ospf_lsa *, struct ospf *);
void ospf_flood_delayed_lsa_ack (struct ospf*, struct ospf_lsa *); //temp
//lsa.c
int get_age (struct ospf_lsa *);
struct ospf_neighbor *ospf_nbr_lookup_by_addr (struct list *, struct in_addr *);
struct ospf_neighbor *ospf_nbr_lookup_ptop (struct list *, struct ospf *);
int ospf_nbr_count (struct list *, int , struct ospf *);
u_int16_t ospf_lsa_checksum (struct lsa_header *);
int ospf_lsa_is_self_originated (struct ospf_lsa *, struct ospf *);
struct ospf_lsa *ospf_lsa_lock (struct ospf_lsa *);
void ospf_lsa_unlock (struct ospf_lsa *);
void ospf_lsa_discard (struct ospf_lsa *);
void ospf_lsa_new (struct ospf_lsa *);
struct lsa_header *ospf_lsa_data_new (u_int32_t );
void ospf_lsa_free (struct ospf_lsa *);
void ospf_lsa_data_free (struct lsa_header *);
int ospf_lsa_more_recent (struct ospf_lsa *, struct ospf_lsa *);
struct ospf_lsa *ospf_router_lsa_originate (struct ospf_area *, struct ospf *);
struct ospf_lsa *ospf_router_lsa_refresh (struct ospf_lsa *);
int ospf_router_lsa_timer (struct thread *);
void ospf_router_lsa_timer_add (struct ospf_area *);
struct ospf_lsa *ospf_router_lsa_new (struct ospf_area *);
//void lsa_header_set (struct stream *, u_char , u_char , u_int32_t, struct ospf *);
void ospf_router_lsa_body_set (struct stream *, struct ospf_area *);
void link_info_set (struct stream *, struct in_addr , struct in_addr , u_char , u_char , u_int16_t );
int router_lsa_link_set (struct stream *, struct ospf_area *);
//struct ospf_lsa *ospf_lsa_install (struct ospf_interface *, struct ospf_lsa *);
struct ospf_lsa *ospf_router_lsa_install (struct ospf_lsa *, int );
void ospf_discard_from_db (struct ospf *, struct ospf_lsa *);
void ospf_lsa_maxage (struct ospf_lsa *, struct ospf *);
int ospf_lsa_maxage_exist (struct ospf_lsa *, struct ospf *ospf_top);
int ospf_maxage_lsa_remover (struct thread *);
int ospf_lsa_maxage_walker (struct thread *);
int ospf_lsa_maxage_walker_remover (struct ospf_lsa *, void *, int );
int ospf_lsa_different (struct ospf_lsa *, struct ospf_lsa *);
int ospf_lsa_refresh_delay (struct ospf_lsa *);
struct timeval tv_adjust (struct timeval );
int tv_ceil (struct timeval );
int tv_cmp (struct timeval , struct timeval );
struct timeval tv_sub (struct timeval, struct timeval);
struct timeval int2tv (int );
struct ospf_lsa *ospf_lsa_lookup_in_list ( struct list *, struct ospf_lsa *);
//packet.c
struct ospf_packet * ospf_packet_new (size_t);
struct ospf_fifo * ospf_fifo_new ();
void ospf_fifo_push (struct ospf_fifo *, struct ospf_packet *);
struct ospf_packet * ospf_fifo_head (struct ospf_fifo *);
struct ospf_packet * ospf_fifo_pop (struct ospf_fifo *);
void ospf_packet_free (struct ospf_packet *);
void ospf_packet_delete (struct ospf *);
int ospfh_write_and_send (struct thread *);
struct stream * ospf_recv_packet (int );
int ospf_read (struct thread *);
void ospf_make_header (int ,struct ospf *, struct stream *);
void ospf_output_forward (struct stream *, int );
void ospf_fill_header (struct stream *, u_int16_t );
int in_cksum(register u_short *, register int);
//te.c
static void set_linkparams_link_type (struct mpls_te_link *);
static void set_linkparams_link_id (struct mpls_te_link *);
static void set_linkparams_te_metric (struct mpls_te_link *, u_int32_t );
static void set_linkparams_rsc_clsclr (struct mpls_te_link *);
static void set_linkparams_id_identifier(struct mpls_te_link *);
static void set_linkparams_local_node_id(struct mpls_te_link *, struct in_addr);
static void set_linkparams_remote_node_id(struct mpls_te_link *,struct in_addr);
static void set_linkparams_switch_cap(struct mpls_te_link *);
static void set_linkparams_ancestor_node_id(struct mpls_te_link *);
static void set_linkparams_hierarchy_list(struct mpls_te_link *);
void initialize_linkparams (struct mpls_te_link *, int, struct in_addr, struct in_addr/* struct in_addr, struct in_addr, struct in_addr*/);
static int is_mandated_params_set (struct mpls_te_link *);
static void set_linkparams_link_header (struct mpls_te_link * );
static void build_tlv_header (struct stream *, struct te_tlv_header *);
static void build_link_subtlv_link_type (struct stream *, struct mpls_te_link *);
static void build_link_subtlv_link_id (struct stream *, struct mpls_te_link *);
static void build_link_subtlv_te_metric (struct stream *, struct mpls_te_link *);
static void build_link_subtlv_rsc_clsclr (struct stream *, struct mpls_te_link *);
static void build_link_subtlv_id_identifier (struct stream *, struct mpls_te_link *);
static void build_link_subtlv_local_id (struct stream *, struct mpls_te_link *);
static void build_link_subtlv_remote_id (struct stream *, struct mpls_te_link *);
static void build_link_subtlv_switch_cap (struct stream *, struct mpls_te_link *);
static void build_link_subtlv_ancestor_id (struct stream *, struct mpls_te_link *);
static void build_link_subtlv_hierarchy_list (struct stream *, struct mpls_te_link *);
static void build_link_tlv (struct stream *, struct mpls_te_link *);
static void ospf_mpls_te_lsa_body_set (struct stream *, struct mpls_te_link *);
struct ospf_lsa * ospf_mpls_te_lsa_new (struct ospf *, struct mpls_te_link *);
//configure
void ospf_read_config (char *, struct ospf * );
int vector_set (struct vector *, char *);
struct vector* vector_init (unsigned int );
void vector_free (struct vector* );
//socket.c
void ospf_sock_init ();
int ospf_sock(struct in_addr);
//数据库接口函数
void delete_list(int lsdb);
int insert_lsa ( struct ospf_lsa *lsa , int lsdb); //改动
void ospfh_lsalist_install ( struct list *lsalist , int layer );
//void ospfh_lsa_install ( struct ospf_lsa *lsa , int layer );
struct ospf_lsa *ospfh_lsa_get ( int lsdb , unsigned char entry_id );
struct ospf_lsa *ospf_lsa_lookup_in_lsdb ( int lsdb , struct ospf_lsa *lsa );\
void ospf_lsa_delete_in_lsdb( int lsdb , struct ospf_lsa *oldlsa);
MYSQL *connect_mysql(char *hostname, char *username, char *passwd, char *dbname,
unsigned portnum, char *socketname, unsigned flags);
struct ospf_lsa *set_ospf_lsa_value (char *row[]);
char *ipcon(struct in_addr ip);
struct list *ospfh_lsalist_get ( int lsdb );
int ospf_lsa_install ( int lsdb , struct ospf_lsa *newlsa );
//测试函数
void out( struct ospf_lsa *lsa);
#define LS_AGE(x) (OSPF_LSA_MAXAGE < get_age(x) ? OSPF_LSA_MAXAGE : get_age(x))
#define OSPF_SCHEDULE_MAXAGE(T, F) \
do { \
if (!(T)) \
(T) = thread_add_timer (master, (F), 0, 2); \
} while (0)
/* Macro for OSPF ISM timer turn on. */
#define OSPF_ISM_TIMER_ON(T,F,V) \
if (!(T)) \
(T) = thread_add_timer (master, (F), top, (V))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -