[Olsr-cvs] olsrd-current/lib/powerinfo/src olsrd_plugin.c, 1.6, 1.7 olsrd_power.c, 1.12, 1.13 olsrd_power.h, 1.3, 1.4 olsr_plugin_io.h, 1.5, NONE olsrd_plugin.h, 1.11, NONE

Bruno Randolf (spam-protected)
Sun May 29 14:47:45 CEST 2005


Update of /cvsroot/olsrd/olsrd-current/lib/powerinfo/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25973/lib/powerinfo/src

Modified Files:
	olsrd_plugin.c olsrd_power.c olsrd_power.h 
Removed Files:
	olsr_plugin_io.h olsrd_plugin.h 
Log Message:
new plugin interface:
  - plugins can now directly access all olsrd data structures
  - a plugin only has to include "olsrd_plugin.h" and provide 3 interface functions:
      1. olsrd_plugin_interface_version()
      2. olsrd_plugin_register_param()
      3. olsrd_plugin_init()
    which are called in the above order
  - moved all plugins to the new interface


Index: olsrd_power.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/powerinfo/src/olsrd_power.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** olsrd_power.c	25 May 2005 16:33:24 -0000	1.12
--- olsrd_power.c	29 May 2005 12:47:43 -0000	1.13
***************
*** 37,40 ****
--- 37,52 ----
  
  #include "olsrd_power.h"
+ #include "olsrd_plugin.h"
+ 
+ #include "olsr.h"
+ #include "mantissa.h"
+ #include "parser.h"
+ #include "scheduler.h"
+ #include "link_set.h"
+ #include "socket_parser.h"
+ #include "interfaces.h"
+ #include "duplicate_set.h"
+ #include "apm.h"
+ 
  #include <stdio.h>
  #include <string.h>
***************
*** 61,64 ****
--- 73,85 ----
  #endif
  
+ /* The database - (using hashing) */
+ static struct pwrentry list[HASHSIZE];
+ 
+ 
+ static int has_apm;
+ 
+ /* set buffer to size of IPv6 message */
+ static char buffer[sizeof(struct olsrmsg6)];
+ 
  int ipc_socket;
  int ipc_open;
***************
*** 77,86 ****
   */
  int
! olsr_plugin_init()
  {
    int i;
    struct olsr_apm_info apm_info;
  
!   if(ipversion != AF_INET)
      {
        fprintf(stderr, "This plugin only supports IPv4!\n");
--- 98,107 ----
   */
  int
! olsrd_plugin_init()
  {
    int i;
    struct olsr_apm_info apm_info;
  
!   if(olsr_cnf->ip_version != AF_INET)
      {
        fprintf(stderr, "This plugin only supports IPv4!\n");
***************
*** 220,240 ****
  
  
- 
- /* Mulitpurpose funtion */
- int
- plugin_io(int cmd, void *data, size_t size)
- {
- 
-   switch(cmd)
-     {
-     default:
-       return 0;
-     }
-   
-   return 1;
- }
- 
- 
- 
  /**
   *A timeoutfunction called every time
--- 241,244 ----
***************
*** 285,289 ****
  olsr_event(void *foo)
  {
!   union olsr_message *message = (union olsr_message*)buffer;
    struct interface *ifn;
  
--- 289,293 ----
  olsr_event(void *foo)
  {
!   union p_olsr_message *message = (union p_olsr_message*)buffer;
    struct interface *ifn;
  
***************
*** 295,303 ****
  
    /* looping trough interfaces */
!   for (ifn = ifs; ifn ; ifn = ifn->int_next) 
      {
        olsr_printf(3, "[%s]  ", ifn->int_name);
        /* Fill message */
!       if(ipversion == AF_INET)
  	{
  	  /* IPv4 */
--- 299,307 ----
  
    /* looping trough interfaces */
!   for (ifn = ifnet; ifn ; ifn = ifn->int_next) 
      {
        olsr_printf(3, "[%s]  ", ifn->int_name);
        /* Fill message */
!       if(olsr_cnf->ip_version == AF_INET)
  	{
  	  /* IPv4 */
***************
*** 305,309 ****
  	  message->v4.olsr_vtime = double_to_me(7.5);
  	  message->v4.olsr_msgsize = htons(sizeof(struct olsrmsg));
! 	  memcpy(&message->v4.originator, main_addr, ipsize);
  	  message->v4.ttl = MAX_TTL;
  	  message->v4.hopcnt = 0;
--- 309,313 ----
  	  message->v4.olsr_vtime = double_to_me(7.5);
  	  message->v4.olsr_msgsize = htons(sizeof(struct olsrmsg));
! 	  memcpy(&message->v4.originator, &main_addr, ipsize);
  	  message->v4.ttl = MAX_TTL;
  	  message->v4.hopcnt = 0;
***************
*** 328,332 ****
  	  message->v6.olsr_vtime = double_to_me(7.5);
  	  message->v6.olsr_msgsize = htons(sizeof(struct olsrmsg));
! 	  memcpy(&message->v6.originator, main_addr, ipsize);
  	  message->v6.ttl = MAX_TTL;
  	  message->v6.hopcnt = 0;
--- 332,336 ----
  	  message->v6.olsr_vtime = double_to_me(7.5);
  	  message->v6.olsr_msgsize = htons(sizeof(struct olsrmsg));
! 	  memcpy(&message->v6.originator, &main_addr, ipsize);
  	  message->v6.ttl = MAX_TTL;
  	  message->v6.hopcnt = 0;
***************
*** 362,368 ****
--- 366,375 ----
  olsr_parser(union olsr_message *m, struct interface *in_if, union olsr_ip_addr *in_addr)
  {
+   union p_olsr_message* pm;
    struct  powermsg *message;
    union olsr_ip_addr originator;
    double vtime;
+   
+   pm = (union p_olsr_message*)m;
  
    /* Fetch the originator of the messsage */
***************
*** 370,386 ****
  
    /* Fetch the message based on IP version */
!   if(ipversion == AF_INET)
      {
!       message = &m->v4.msg;
        vtime = ME_TO_DOUBLE(m->v4.olsr_vtime);
      }
    else
      {
!       message = &m->v6.msg;
        vtime = ME_TO_DOUBLE(m->v6.olsr_vtime);
      }
  
    /* Check if message originated from this node */
!   if(memcmp(&originator, main_addr, ipsize) == 0)
      /* If so - back off */
      return;
--- 377,393 ----
  
    /* Fetch the message based on IP version */
!   if(olsr_cnf->ip_version == AF_INET)
      {
!       message = &pm->v4.msg;
        vtime = ME_TO_DOUBLE(m->v4.olsr_vtime);
      }
    else
      {
!       message = &pm->v6.msg;
        vtime = ME_TO_DOUBLE(m->v6.olsr_vtime);
      }
  
    /* Check if message originated from this node */
!   if(memcmp(&originator, &main_addr, ipsize) == 0)
      /* If so - back off */
      return;
***************
*** 399,403 ****
     * processed if nessecary
     */
!   if(!check_dup_proc(&originator,
                       ntohs(m->v4.seqno))) /* REMEMBER NTOHS!! */
      {
--- 406,410 ----
     * processed if nessecary
     */
!   if(!olsr_check_dup_table_proc(&originator,
                       ntohs(m->v4.seqno))) /* REMEMBER NTOHS!! */
      {
***************
*** 420,424 ****
     * default_fwd does all the work for us!
     */
!   default_fwd(m,
                &originator,
                ntohs(m->v4.seqno), /* IMPORTANT!!! */
--- 427,431 ----
     * default_fwd does all the work for us!
     */
!   olsr_forward_message(m,
                &originator,
                ntohs(m->v4.seqno), /* IMPORTANT!!! */
***************
*** 605,609 ****
    char *tmp;
  
!   if(ipversion == AF_INET)
      /* IPv4 */  
      hash = (ntohl(address->v4));
--- 612,616 ----
    char *tmp;
  
!   if(olsr_cnf->ip_version == AF_INET)
      /* IPv4 */  
      hash = (ntohl(address->v4));
***************
*** 634,638 ****
  olsr_timed_out(struct timeval *timer)
  {
!   return(timercmp(timer, now, <));
  }
  
--- 641,645 ----
  olsr_timed_out(struct timeval *timer)
  {
!   return(timercmp(timer, &now, <));
  }
  
***************
*** 680,723 ****
    time_value_msec= delay - (delay*1000);
  
!   hold_timer->tv_sec = now->tv_sec + time_value_sec;
!   hold_timer->tv_usec = now->tv_usec + (time_value_msec*1000);   
  }
  
  
- /**
-  *Converts a olsr_ip_addr to a string
-  *Goes for both IPv4 and IPv6
-  *
-  *NON REENTRANT! If you need to use this
-  *function twice in e.g. the same printf
-  *it will not work.
-  *You must use it in different calls e.g.
-  *two different printfs
-  *
-  *@param the IP to convert
-  *@return a pointer to a static string buffer
-  *representing the address in "dots and numbers"
-  *
-  */
- char *
- olsr_ip_to_string(union olsr_ip_addr *addr)
- {
- 
-   char *ret;
-   struct in_addr in;
-   
-   if(ipversion == AF_INET)
-     {
-       in.s_addr=addr->v4;
-       ret = inet_ntoa(in);
-     }
-   else
-     {
-       /* IPv6 */
-       ret = (char *)inet_ntop(AF_INET6, &addr->v6, ipv6_buf, sizeof(ipv6_buf));
-     }
- 
-   return ret;
- }
- 
  
--- 687,694 ----
    time_value_msec= delay - (delay*1000);
  
!   hold_timer->tv_sec = now.tv_sec + time_value_sec;
!   hold_timer->tv_usec = now.tv_usec + (time_value_msec*1000);   
  }
  
  
  

Index: olsrd_power.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/powerinfo/src/olsrd_power.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** olsrd_power.h	30 Nov 2004 17:04:45 -0000	1.3
--- olsrd_power.h	29 May 2005 12:47:43 -0000	1.4
***************
*** 37,40 ****
--- 37,43 ----
  #define _OLSRD_PLUGIN_TEST
  
+ #include "hashing.h"
+ #include "defs.h"
+ 
  #include "olsrd_plugin.h"
  
***************
*** 56,67 ****
  
  
! /* The database - (using hashing) */
! struct pwrentry list[HASHSIZE];
  
  
! int has_apm;
  
! /* set buffer to size of IPv6 message */
! static char buffer[sizeof(struct olsrmsg6)];
  
  
--- 59,143 ----
  
  
! /*****************************************************************************
!  *                               Plugin data                                 *
!  *                       ALTER THIS TO YOUR OWN NEED                         *
!  *****************************************************************************/
! 
! #define PLUGIN_NAME    "OLSRD Powerstatus plugin"
! #define PLUGIN_VERSION "0.3"
! #define PLUGIN_AUTHOR   "Andreas Tønnesen"
! #define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION " by " PLUGIN_AUTHOR
  
+ /* The type of message you will use */
+ #define MESSAGE_TYPE 128
  
! /* The type of messages we will receive - can be set to promiscuous */
! #define PARSER_TYPE MESSAGE_TYPE
  
! 
! /****************************************************************************
!  *                            PACKET SECTION                                *
!  ****************************************************************************/
! 
! 
! /**********************************
!  * DEFINE YOUR CUSTOM PACKET HERE *
!  **********************************/
! 
! struct powermsg
! {
!   olsr_u8_t       source_type;
!   olsr_u8_t       percentage;
!   olsr_u16_t      time_left;
! };
! 
! /*
!  * OLSR message (several can exist in one OLSR packet)
!  */
! 
! struct p_olsrmsg
! {
!   olsr_u8_t     olsr_msgtype;
!   olsr_u8_t     olsr_vtime;
!   olsr_u16_t    olsr_msgsize;
!   olsr_u32_t    originator;
!   olsr_u8_t     ttl;
!   olsr_u8_t     hopcnt;
!   olsr_u16_t    seqno;
! 
!   /* YOUR PACKET GOES HERE */
!   struct powermsg msg;
! 
! };
! 
! /*
!  *IPv6
!  */
! 
! struct p_olsrmsg6
! {
!   olsr_u8_t        olsr_msgtype;
!   olsr_u8_t        olsr_vtime;
!   olsr_u16_t       olsr_msgsize;
!   struct in6_addr  originator;
!   olsr_u8_t        ttl;
!   olsr_u8_t        hopcnt;
!   olsr_u16_t       seqno;
! 
!   /* YOUR PACKET GOES HERE */
!   struct powermsg msg;
! 
! };
! 
! /* 
!  * ALWAYS USE THESE WRAPPERS TO
!  * ENSURE IPv4 <-> IPv6 compability 
!  */
! 
! union p_olsr_message
! {
!   struct p_olsrmsg v4;
!   struct p_olsrmsg6 v6;
! };
  
  
***************
*** 90,92 ****
--- 166,186 ----
  print_power_table(void);
  
+ int
+ olsrd_plugin_init(void);
+ 
+ int
+ plugin_ipc_init(void);
+ 
+ void
+ olsr_plugin_exit(void);
+ 
+ void
+ olsr_get_timestamp(olsr_u32_t, struct timeval *);
+ 
+ void
+ olsr_init_timer(olsr_u32_t, struct timeval *);
+ 
+ int
+ olsr_timed_out(struct timeval *);
+ 
  #endif

--- olsrd_plugin.h DELETED ---

--- olsr_plugin_io.h DELETED ---

Index: olsrd_plugin.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/powerinfo/src/olsrd_plugin.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** olsrd_plugin.c	25 May 2005 13:41:47 -0000	1.6
--- olsrd_plugin.c	29 May 2005 12:47:43 -0000	1.7
***************
*** 39,44 ****
  
  #include "olsrd_plugin.h"
  #include <stdio.h>
- #include "plugin_loader.h"
  
  void __attribute__ ((constructor)) 
--- 39,44 ----
  
  #include "olsrd_plugin.h"
+ #include "olsrd_power.h"
  #include <stdio.h>
  
  void __attribute__ ((constructor)) 
***************
*** 48,56 ****
  my_fini(void);
  
- int
- register_olsr_data(struct olsr_plugin_data *);
- 
- int
- fetch_olsrd_data(void);
  
  /*
--- 48,51 ----
***************
*** 59,65 ****
   */
  int 
! get_plugin_interface_version()
  {
!   return PLUGIN_INTERFACE_VERSION;
  }
  
--- 54,66 ----
   */
  int 
! olsrd_plugin_interface_version()
  {
!   return OLSRD_PLUGIN_INTERFACE_VERSION;
! }
! 
! int
! olsrd_plugin_register_param(char *key, char *value)
! {
!   return 1;
  }
  
***************
*** 72,79 ****
    /* Print plugin info to stdout */
    printf("%s\n", MOD_DESC);
- 
-   ifs = NULL;
- 
-   return;
  }
  
--- 73,76 ----
***************
*** 92,295 ****
     */
    olsr_plugin_exit();
- 
-   return;
- }
- 
- int
- register_olsr_param(char *key, char *value)
- {
-   return 1;
- }
- 
- /**
-  *Register needed functions and pointers
-  *
-  *This function should not be changed!
-  *
-  */
- int
- register_olsr_data(struct olsr_plugin_data *data)
- {
-   /* IPversion */
-   ipversion = data->ipversion;
-   /* Main address */
-   main_addr = data->main_addr;
- 
-   /* Multi-purpose function */
-   olsr_plugin_io = data->olsr_plugin_io;
- 
-   /* Set size of IP address */
-   if(ipversion == AF_INET)
-     {
-       ipsize = sizeof(olsr_u32_t);
-     }
-   else
-     {
-       ipsize = sizeof(struct in6_addr);
-     }
- 
-   if(!fetch_olsrd_data())
-     {
-       fprintf(stderr, "Could not fetch the neccessary functions from olsrd!\n");
-       return 0;
-     }
- 
-   /* Calls the initialization function
-    * olsr_plugin_init()
-    * This function should be present in your
-    * sourcefile and all data initialization
-    * should happen there - NOT HERE!
-    */
-   if(!olsr_plugin_init())
-     {
-       fprintf(stderr, "Could not initialize plugin!\n");
-       return 0;
-     }
- 
-   if(!plugin_ipc_init())
-     {
-       fprintf(stderr, "Could not initialize plugin IPC!\n");
-       return 0;
-     }
- 
-   return 1;
- }
- 
- 
- 
- int
- fetch_olsrd_data()
- {
-   int retval = 1;
- 
- 
-   /* Packet buffer */
-   if(!olsr_plugin_io(GETF__NET_OUTBUFFER_PUSH, &net_outbuffer_push, sizeof(net_outbuffer_push)))
-   {
-     net_outbuffer_push = NULL;
-     retval = 0;
-   }
- 
-   /* Olsr debug output function */
-   if(!olsr_plugin_io(GETF__OLSR_PRINTF, 
- 		     &olsr_printf, 
- 		     sizeof(olsr_printf)))
-   {
-     olsr_printf = NULL;
-     retval = 0;
-   }
- 
- 
-   /* Olsr malloc wrapper */
-   if(!olsr_plugin_io(GETF__OLSR_MALLOC, 
- 		     &olsr_malloc, 
- 		     sizeof(olsr_malloc)))
-   {
-     olsr_malloc = NULL;
-     retval = 0;
-   }
- 
-   /* Parser registration */
-   if(!olsr_plugin_io(GETF__OLSR_PARSER_ADD_FUNCTION, 
- 		     &olsr_parser_add_function, 
- 		     sizeof(olsr_parser_add_function)))
-   {
-     olsr_parser_add_function = NULL;
-     retval = 0;
-   }
- 
-   /* Scheduler timeout registration */
-   if(!olsr_plugin_io(GETF__OLSR_REGISTER_TIMEOUT_FUNCTION, 
- 		     &olsr_register_timeout_function, 
- 		     sizeof(olsr_register_timeout_function)))
-   {
-     olsr_register_timeout_function = NULL;
-     retval = 0;
-   }
- 
-   /* Scheduler event registration */
-   if(!olsr_plugin_io(GETF__OLSR_REGISTER_SCHEDULER_EVENT, 
- 		     &olsr_register_scheduler_event, 
- 		     sizeof(olsr_register_scheduler_event)))
-   {
-     olsr_register_scheduler_event = NULL;
-     retval = 0;
-   }
- 
-   /* Double to mantissa/exponent */
-   if(!olsr_plugin_io(GETF__DOUBLE_TO_ME, 
- 		     &double_to_me, 
- 		     sizeof(double_to_me)))
-   {
-     double_to_me = NULL;
-     retval = 0;
-   }
- 
-   /* Interface list */
-   if(!olsr_plugin_io(GETD__IFNET, &ifs, sizeof(ifs)))
-   {
-     ifs = NULL;
-     retval = 0;
-   }
- 
-   /* Messageseqno fetch function */
-   if(!olsr_plugin_io(GETF__GET_MSG_SEQNO, &get_msg_seqno, sizeof(get_msg_seqno)))
-   {
-     get_msg_seqno = NULL;
-     retval = 0;
-   }
- 
-   /* Scheduler maintained timestamp */
-   if(!olsr_plugin_io(GETD__NOW, &now, sizeof(now)))
-   {
-     now = NULL;
-     retval = 0;
-   }
- 
-   /* Output function */
-   if(!olsr_plugin_io(GETF__NET_OUTPUT, &net_output, sizeof(net_output)))
-   {
-     net_output = NULL;
-     retval = 0;
-   }
- 
-   /* Duplicate check (for processing) */
-   if(!olsr_plugin_io(GETF__OLSR_CHECK_DUP_TABLE_PROC, &check_dup_proc, sizeof(check_dup_proc)))
-   {
-     check_dup_proc = NULL;
-     retval = 0;
-   }
- 
-   /* Default forward function */
-   if(!olsr_plugin_io(GETF__OLSR_FORWARD_MESSAGE, &default_fwd, sizeof(default_fwd)))
-   {
-     default_fwd = NULL;
-     retval = 0;
-   }
- 
- 
-   /* Add socket to OLSR select function */
-   if(!olsr_plugin_io(GETF__ADD_OLSR_SOCKET, &add_olsr_socket, sizeof(add_olsr_socket)))
-   {
-     add_olsr_socket = NULL;
-     retval = 0;
-   }
- 
-   /* Neighbor link status lookup */
-   if(!olsr_plugin_io(GETF__CHECK_NEIGHBOR_LINK, &check_neighbor_link, sizeof(check_neighbor_link)))
-   {
-     check_neighbor_link = NULL;
-     retval = 0;
-   }
- 
- 
-   /* Apm info */
-   if(!olsr_plugin_io(GETF__APM_READ, &apm_read, sizeof(apm_read)))
-   {
-     apm_read = NULL;
-     retval = 0;
-   }
- 
-   return retval;
- 
  }
--- 89,91 ----




More information about the Olsr-cvs mailing list