⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ospfh_feed.c

📁 实现禁位自动排列在禁位中具体实现了此方法所以这是一个创新很有应用价值在VC平台上调试通过
💻 C
字号:
/* The feed_up and feed_down mechanism*/

#include "ospfh.h"
#include "ospfh_patch.h"


void
ospfh_feed_up_timer(struct thread *thread)    
{
   // struct thread_master* master;
	struct ospf *top;


   top = THREAD_ARG (thread);
   top->t_ls_feed_up_timer = NULL;
   // master=top->master;
	ospfh_feed_up_send(top);
}




void
ospfh_feed_up_send(struct ospf *ospf_top)
{ 
	struct    ospf_packet *op;
    u_int16_t length=OSPF_HEADER_SIZE;
  struct    thread_master *master;


//还需要一个启动程序中写ospf_fifo_new();
  op = ospf_packet_new (ospf_top->mtu);
  master=ospf_top->master;

//填充ospf包头
  ospf_make_header(OSPF_MSG_LS_FEED_UP,ospf_top,op->s);

//feed_up没有内容

/* Fill OSPF header. */
ospf_fill_header(op->s,length);

 /* Set packet length. */
  op->length = length;

/* Add packet to the packet output queue. */
  ospf_fifo_push(ospf_top->outbuf,op);

    /* Hook thread to write packet. */
  OSPFH_WRITE_ON();
}


//feed_down 包有内容需要填写,所以形参更多
void
ospfh_feed_down_send(struct ospf *ospf_top,u_char lsdb_id, u_char index,struct ospf_lsa *lsa)
{ 
	struct  ospf_packet *op;
    u_int16_t length=OSPF_HEADER_SIZE;
    struct thread_master *master;
	int num;



  op = ospf_packet_new (ospf_top->mtu);
  master=ospf_top->master;
 if(lsa->lp->hierarchy_list.value[0].s_addr==inet_addr(DEFALT_IP_ADDRESS))
  lsa->lp->hierarchy_list.value[0]=ospf_top->self_rc_id;
else lsa->lp->hierarchy_list.value[1]=ospf_top->self_rc_id;
      num=id_to_layernum(lsa->data->adv_router);                            
	
	index=ospf_lsa_install (num, lsa);

//填充ospf包头
  ospf_make_header(OSPF_MSG_LS_FEED_DOWN,ospf_top,op->s);

//填充FEED_DOWN包
  stream_putc (op->s, lsdb_id);
//  stream_putc (op->s, NULL, OSPF_LS_FEED_DOWN_ENTRY_ID_SIZE);
//  stream_putc (op->s, NULL, OSPF_LS_FEED_DOWN_ENTRY_ID_SIZE);
  stream_putc (op->s, index-1);

//feed_down包有内容填写,所以长度有变化
  length+=OSPF_LS_FEED_DOWN_SIZE;

/* Fill OSPF header. */
ospf_fill_header(op->s,length);

 /* Set packet length. */
  op->length = length;
/* Add packet to the packet output queue. */
  ospf_fifo_push(ospf_top->outbuf,op);

    /* Hook thread to write packet. */
  OSPFH_WRITE_ON();
}


void
ospfh_feed_up_receive(struct ospf *top)
{
    struct list *lsalist;
	struct list *interlsalist;
	struct list *intralsalist;
    int layernum;

	layernum=id_to_layernum(top->self_rc_id);
//调用数据库读出函数,读出下一层所有的LSA
   lsalist=ospfh_lsalist_get(layernum-1) ;

    interlsalist=list_new ();
    intralsalist=list_new ();

	ospfh_lower_layer_lsalist_read(top,lsalist,interlsalist,intralsalist);

    ospfh_abstract(top,intralsalist,interlsalist);
  
//调用数据库写入函数  install to lsdb
    ospfh_lsalist_install(interlsalist,layernum); 

//在拓扑抽象模块中完成该功能	write_to_lsdb(newlist); 
//在拓扑抽象模块中完成该功能	ospfh_flood(newlist);
}


//分别形成域间和域内的lsa列表
void
ospfh_lower_layer_lsalist_read(struct ospf *top,struct list *lsa_list,struct list *interlsalist,struct list *intralsalist)

{  struct listnode *node;
   int    count = lsa_list->count;
   struct ospf_lsa *lsa;
   int  ancestor_num,self_num;

 if (count)
    {
	 for (node =lsa_list->head; node;  node = node->next)
     {
         if (count)
		 {
		   count--;
           lsa = (struct ospf_lsa *)(node->data);
		   self_num=id_to_layernum(top->self_rc_id);
		   ancestor_num=id_to_layernum(lsa->lp->ancestor_id.value);
//判断该lsa表征的这条链路是域间还是域内

		   if((self_num-1)<ancestor_num)  
		   { 
                 listnode_add(interlsalist,lsa); 
		         lsa->data->adv_router=top->self_rc_id;
		         lsa->data->ls_age=htons (0);
				 lsa->data->ls_seqnum=htonl(top->lsa_originate_count+1);
			     top->lsa_originate_count++;
		         ospf_flood_out(top,NULL,lsa);
           }

		   else  listnode_add(intralsalist,lsa);
		 }
	 }
 }

}


void
ospfh_feed_down_receive(struct ospf *top, struct stream *s)
{
	u_char num;
	u_char index;
//	struct list *lsalist;
	struct ospf_lsa *lsa;
	u_int16_t  length;

    num=stream_getc(s);

    index = stream_getc (s);
//调用数据库接口读出相应的LSA
     lsa=ospfh_lsa_get (num,index);
if (lsa->lp->hierarchy_list.value[1].s_addr==inet_addr(DEFALT_IP_ADDRESS))
  lsa->lp->hierarchy_list.value[1]=top->self_rc_id;
else  lsa->lp->hierarchy_list.value[2]=top->self_rc_id;
         length=ntohs(lsa->data->length);
		length+=4;
	lsa->data->length=htons(length);
    ospf_lsa_install (num, lsa);
//泛洪这条新的LSA
ospf_flood_out(top,NULL,lsa);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -