lldp中与snmp相关内容agentx

struct lldpd {

 int    g_snmp;  

 struct event  *g_snmp_timeout;

 void   *g_snmp_fds;

 char   *g_snmp_agentx;

}

lldpd_main()

{

    struct lldpd *cfg;  

    // 初始化snmp相关参数  

   int snmp = 0;  

   char *agentx = NULL; /* AgentX socket */

    // lldpd进程支持的参数  

   char *popt, opts[] =   "H:vhkrdD:xX:m:u:4:6:I:C:p:M:P:S:iL:@                    ";  

     // 对参数进行解析  

   while ((ch = getopt(argc, argv, opts)) != -1) {  

      switch (ch) {            

           // 是否启用agentX      

           case 'x':     

      snmp = 1;     

      break;    

    case 'X':     

      snmp = 1;     

      agentx = optarg;     

      break;          

    // 是否启用lldpcli       

    case 'L':    

       if (strlen(optarg))     

         lldpcli = optarg;     

      else      

        lldpcli = NULL;    

    }  

   cfg->g_snmp = snmp;

  cfg->g_snmp_agentx = agentx;

}

 

 

static void levent_init(struct lldpd *cfg)

{  

  if (cfg->g_snmp) {     

    // 注册agentx   

    agent_init(cfg, cfg->g_snmp_agentx);  

     // 设置定时器  

       cfg->g_snmp_timeout = evtimer_new(cfg->g_base,       levent_snmp_timeout,       cfg);   

    if (!cfg->g_snmp_timeout)   

       fatalx("unable to setup timeout function for SNMP");   

    if ((cfg->g_snmp_fds =    malloc(sizeof(struct ev_l))) == NULL)    

      fatalx("unable to allocate memory for SNMP events");  

     TAILQ_INIT(levent_snmp_fds(cfg));

   }

}

 

void levent_loop(struct lldpd *cfg) {    

   // 更新snmp socket通信相关

    if (cfg->g_snmp)  

     levent_snmp_update(cfg);  

   // 关闭agetnx

   if (cfg->g_snmp)   

    agent_shutdown();

}

 

 

static void usage(void)

{  

  fprintf(stderr, "-x       Enable SNMP subagent.\n");

}

static void notify_clients_deletion(struct lldpd_hardware *hardware,struct lldpd_port *rport)

{

    agent_notify(hardware, NEIGHBOR_CHANGE_DELETED, rport);

}     

 

static void lldpd_decode(struct lldpd *cfg, char *frame, int s,struct lldpd_hardware *hardware)

{

    if (oport) {     

     agent_notify(hardware, NEIGHBOR_CHANGE_UPDATED, port);

   }  else  {   

    agent_notify(hardware, NEIGHBOR_CHANGE_ADDED, port);

   }   

posted @ 2015-11-23 19:44  hbg-rohens  阅读(1415)  评论(1编辑  收藏  举报