[Olsr-cvs] olsrd-current/lib/dot_draw/src olsrd_dot_draw.c, 1.13, 1.14 olsrd_dot_draw.h, 1.6, 1.7 olsrd_plugin.c, 1.10, 1.11 olsrd_plugin.h, 1.17, NONE

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


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

Modified Files:
	olsrd_dot_draw.c olsrd_dot_draw.h olsrd_plugin.c 
Removed Files:
	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


--- olsrd_plugin.h DELETED ---

Index: olsrd_dot_draw.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/dot_draw/src/olsrd_dot_draw.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** olsrd_dot_draw.h	20 Feb 2005 15:51:15 -0000	1.6
--- olsrd_dot_draw.h	29 May 2005 12:47:40 -0000	1.7
***************
*** 45,82 ****
   */
  
! #ifndef _OLSRD_PLUGIN_TEST
! #define _OLSRD_PLUGIN_TEST
  
- #include "olsrd_plugin.h"
  
  
- char netmask[5];
  
- /* Event function to register with the sceduler */
  int
! pcf_event(int, int, int);
  
  void
! ipc_action(int);
! 
! static void inline
! ipc_print_neigh_link(struct neighbor_entry *neighbor);
! 
! static void inline
! ipc_print_tc_link(struct tc_entry *entry, struct topo_dst *dst_entry);
! 
! static void inline
! ipc_print_net(union olsr_ip_addr *, union olsr_ip_addr *, union hna_netmask *);
! 
! int
! ipc_send(char *, int);
! 
! char *
! olsr_ip_to_string(union olsr_ip_addr *);
! 
! char *
! olsr_netmask_to_string(union hna_netmask *);
! 
! struct link_entry *olsr_neighbor_best_link(union olsr_ip_addr *main);
  
  #endif
--- 45,61 ----
   */
  
! #ifndef _OLSRD_DOT_DRAW
! #define _OLSRD_DOT_DRAW
  
  
+ extern struct in_addr ipc_accept_ip;
+ extern int ipc_port;
  
  
  int
! olsrd_plugin_init(void);
  
  void
! olsr_plugin_exit(void);
  
  #endif

Index: olsrd_dot_draw.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/dot_draw/src/olsrd_dot_draw.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** olsrd_dot_draw.c	25 May 2005 16:33:24 -0000	1.13
--- olsrd_dot_draw.c	29 May 2005 12:47:40 -0000	1.14
***************
*** 45,49 ****
   */
  
! #include "olsrd_dot_draw.h"
  #include <stdio.h>
  #include <string.h>
--- 45,56 ----
   */
  
!  
! #include <sys/types.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
! #include <sys/time.h>
! #include <time.h>
! #include <math.h>
  #include <stdio.h>
  #include <string.h>
***************
*** 51,58 ****
--- 58,81 ----
  #include <unistd.h>
  #include <errno.h>
+ 
+ #include "olsr.h"
+ #include "olsr_types.h"
+ #include "neighbor_table.h"
+ #include "two_hop_neighbor_table.h"
+ #include "tc_set.h"
+ #include "hna_set.h"
+ #include "mid_set.h"
+ #include "link_set.h"
+ #include "socket_parser.h"
+ 
+ #include "olsrd_dot_draw.h"
+ #include "olsrd_plugin.h"
+ 
+ 
  #ifdef WIN32
  #define close(x) closesocket(x)
  #endif
  
+ 
  int ipc_socket;
  int ipc_open;
***************
*** 60,63 ****
--- 83,113 ----
  int ipc_socket_up;
  
+ 
+ /* IPC initialization function */
+ static int
+ plugin_ipc_init(void);
+ 
+ static char*
+ olsr_netmask_to_string(union hna_netmask *mask);
+ 
+ /* Event function to register with the sceduler */
+ static int
+ pcf_event(int, int, int);
+ 
+ static void
+ ipc_action(int);
+ 
+ static void inline
+ ipc_print_neigh_link(struct neighbor_entry *neighbor);
+ 
+ static void inline
+ ipc_print_tc_link(struct tc_entry *entry, struct topo_dst *dst_entry);
+ 
+ static void inline
+ ipc_print_net(union olsr_ip_addr *, union olsr_ip_addr *, union hna_netmask *);
+ 
+ static int
+ ipc_send(char *, int);
+ 
  static double 
  calc_etx(double, double);
***************
*** 67,70 ****
--- 117,149 ----
  
  
+ /**
+  *Do initialization here
+  *
+  *This function is called by the my_init
+  *function in uolsrd_plugin.c
+  */
+ int
+ olsrd_plugin_init()
+ {
+   /* Initial IPC value */
+   ipc_open = 0;
+   ipc_socket_up = 0;
+ 
+   /* Register the "ProcessChanges" function */
+   register_pcf(&pcf_event);
+ 
+   return 1;
+ }
+ 
+ 
+ /**
+  * destructor - called at unload
+  */
+ void
+ olsr_plugin_exit()
+ {
+   if(ipc_open)
+     close(ipc_socket);
+ }
  
  
***************
*** 78,82 ****
    char* style = "solid";
    struct link_entry* link;
!   adr = olsr_ip_to_string(main_addr);
    len = sprintf( buf, "\"%s\" -> ", adr );
    ipc_send(buf, len);
--- 157,161 ----
    char* style = "solid";
    struct link_entry* link;
!   adr = olsr_ip_to_string(&main_addr);
    len = sprintf( buf, "\"%s\" -> ", adr );
    ipc_send(buf, len);
***************
*** 87,101 ****
    	style = "dashed";
    }
!   else {
!     /* find best link to neighbor for the ETX */
!     //? why cant i just get it one time at fetch_olsrd_data??? (br1)
!     if(olsr_plugin_io(GETD__LINK_SET, &link, sizeof(link)) && link)
!     {
!       link_set = link; // for olsr_neighbor_best_link    
!       link = olsr_neighbor_best_link(&neighbor->neighbor_main_addr);
        if (link) {
          etx = calc_etx( link->loss_link_quality, link->neigh_link_quality);
        }
-     }
    }
      
--- 166,174 ----
    	style = "dashed";
    }
!   else {   
!       link = get_best_link_to_neighbor(&neighbor->neighbor_main_addr);
        if (link) {
          etx = calc_etx( link->loss_link_quality, link->neigh_link_quality);
        }
    }
      
***************
*** 109,133 ****
  }
  
- /**
-  *Do initialization here
-  *
-  *This function is called by the my_init
-  *function in uolsrd_plugin.c
-  */
- int
- olsr_plugin_init()
- {
  
!   /* Initial IPC value */
!   ipc_open = 0;
!   ipc_socket_up = 0;
! 
!   /* Register the "ProcessChanges" function */
!   register_pcf(&pcf_event);
! 
!   return 1;
! }
! 
! int
  plugin_ipc_init()
  {
--- 182,187 ----
  }
  
  
! static int
  plugin_ipc_init()
  {
***************
*** 188,192 ****
  }
  
! void
  ipc_action(int fd)
  {
--- 242,247 ----
  }
  
! 
! static void
  ipc_action(int fd)
  {
***************
*** 218,257 ****
  	}
      }
- 
  }
  
- /*
-  * destructor - called at unload
-  */
- void
- olsr_plugin_exit()
- {
-   if(ipc_open)
-     close(ipc_socket);
- }
- 
- 
- 
- /* Mulitpurpose funtion */
- int
- plugin_io(int cmd, void *data, size_t size)
- {
- 
-   switch(cmd)
-     {
-     default:
-       return 0;
-     }
-   
-   return 1;
- }
- 
- 
- 
  
  /**
   *Scheduled event
   */
! int
  pcf_event(int changes_neighborhood,
  	  int changes_topology,
--- 273,283 ----
  	}
      }
  }
  
  
  /**
   *Scheduled event
   */
! static int
  pcf_event(int changes_neighborhood,
  	  int changes_topology,
***************
*** 339,342 ****
--- 365,369 ----
  }
  
+ 
  #define MIN_LINK_QUALITY 0.01
  static double 
***************
*** 367,370 ****
--- 394,398 ----
  }
  
+ 
  static void inline
  ipc_print_net(union olsr_ip_addr *gw, union olsr_ip_addr *net, union hna_netmask *mask)
***************
*** 393,398 ****
  
  
! 
! int
  ipc_send(char *data, int size)
  {
--- 421,425 ----
  
  
! static int
  ipc_send(char *data, int size)
  {
***************
*** 416,470 ****
  
  
  
! 
! 
! /**
!  *Converts a olsr_ip_addr to a string
!  *Goes for both IPv4 and IPv6
!  *
!  *@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)
! {
!   static int index = 0;
!   static char buff[4][100];
!   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));
!     }
! 
!   strncpy(buff[index], ret, 100);
! 
!   ret = buff[index];
! 
!   index = (index + 1) & 3;
! 
!   return ret;
! }
! 
! 
! /**
!  *This function is just as bad as the previous one :-(
!  */
! char *
  olsr_netmask_to_string(union hna_netmask *mask)
  {
    char *ret;
    struct in_addr in;
!   
!   if(ipversion == AF_INET)
      {
        in.s_addr = mask->v4;
--- 443,455 ----
  
  
+ static char netmask[5];
  
! static char*
  olsr_netmask_to_string(union hna_netmask *mask)
  {
    char *ret;
    struct in_addr in;
! 
!   if(olsr_cnf->ip_version == AF_INET)
      {
        in.s_addr = mask->v4;
***************
*** 482,513 ****
    return ret;
  }
- 
- #define COMP_IP(ip1, ip2) (!memcmp(ip1, ip2, ipsize))
- struct link_entry *olsr_neighbor_best_link(union olsr_ip_addr *main)
- {
-   struct link_entry *walker;
-   double best = 0.0;
-   double curr;
-   struct link_entry *res = NULL;
- 
-   // loop through all links
- 
-   for (walker = link_set; walker != NULL; walker = walker->next)
-   {
-     // check whether it's a link to the requested neighbor and
-     // whether the link's quality is better than what we have
-     if(COMP_IP(main, &walker->neighbor->neighbor_main_addr))
-     {
-       curr = walker->loss_link_quality * walker->neigh_link_quality;
- 
-       if (curr >= best)
-       {
-         best = curr;
-         res = walker;
-       }
-     }
-   }
- 
-   return res;
- }
- 
--- 467,468 ----

Index: olsrd_plugin.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/dot_draw/src/olsrd_plugin.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** olsrd_plugin.c	25 Feb 2005 22:43:21 -0000	1.10
--- olsrd_plugin.c	29 May 2005 12:47:40 -0000	1.11
***************
*** 45,79 ****
  
  
- #include "olsrd_plugin.h"
  #include <stdio.h>
  #include <string.h>
  #include <stdlib.h>
! #include "plugin_loader.h"
  
  
- void __attribute__ ((constructor)) 
- my_init(void);
  
! void __attribute__ ((destructor)) 
! my_fini(void);
  
- int
- register_olsr_data(struct olsr_plugin_data *);
  
! int
! fetch_olsrd_data(void);
  
  
! /*
!  * Defines the version of the plugin interface that is used
!  * THIS IS NOT THE VERSION OF YOUR PLUGIN!
!  * Do not alter unless you know what you are doing!
!  */
! int 
! get_plugin_interface_version()
! {
!   return PLUGIN_INTERFACE_VERSION;
! }
  
  
  
--- 45,73 ----
  
  
  #include <stdio.h>
  #include <string.h>
  #include <stdlib.h>
! #include <arpa/inet.h>
  
+ #include "olsrd_plugin.h"
+ #include "olsrd_dot_draw.h"
  
  
! #define PLUGIN_NAME    "OLSRD dot draw plugin"
! #define PLUGIN_VERSION "0.3"
! #define PLUGIN_AUTHOR   "Andreas Tønnesen"
! #define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION " by " PLUGIN_AUTHOR
! #define PLUGIN_INTERFACE_VERSION 4
  
  
! struct in_addr ipc_accept_ip;
! int ipc_port;
  
  
! static void __attribute__ ((constructor)) 
! my_init(void);
  
+ static void __attribute__ ((destructor)) 
+ my_fini(void);
  
  
***************
*** 81,85 ****
   *Constructor
   */
! void
  my_init()
  {
--- 75,79 ----
   *Constructor
   */
! static void
  my_init()
  {
***************
*** 90,104 ****
    ipc_port = 2004;
    ipc_accept_ip.s_addr = htonl(INADDR_LOOPBACK);
-   
-   return;
  }
  
  /**
   *Destructor
   */
! void
  my_fini()
  {
- 
    /* Calls the destruction function
     * olsr_plugin_exit()
--- 84,96 ----
    ipc_port = 2004;
    ipc_accept_ip.s_addr = htonl(INADDR_LOOPBACK);
  }
  
+ 
  /**
   *Destructor
   */
! static void
  my_fini()
  {
    /* Calls the destruction function
     * olsr_plugin_exit()
***************
*** 108,117 ****
     */
    olsr_plugin_exit();
  
!   return;
  }
  
  int
! register_olsr_param(char *key, char *value)
  {
    if(!strcmp(key, "port"))
--- 100,115 ----
     */
    olsr_plugin_exit();
+ }
  
! 
! int 
! olsrd_plugin_interface_version()
! {
!   return PLUGIN_INTERFACE_VERSION;
  }
  
+ 
  int
! olsrd_plugin_register_param(char *key, char *value)
  {
    if(!strcmp(key, "port"))
***************
*** 128,282 ****
    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;
- 
-   
-   /* Neighbor table */
-   if(!olsr_plugin_io(GETD__NEIGHBORTABLE, 
- 		     &neighbortable, 
- 		     sizeof(neighbortable)))
-   {
-     neighbortable = NULL;
-     retval = 0;
-   }
-   
-   /* Two hop neighbor table */
-   if(!olsr_plugin_io(GETD__TWO_HOP_NEIGHBORTABLE, 
- 		     &two_hop_neighbortable, 
- 		     sizeof(two_hop_neighbortable)))
-   {
-     two_hop_neighbortable = NULL;
-     retval = 0;
-   }
- 
-   /* link set */
-   if(!olsr_plugin_io(GETD__LINK_SET, &link_set, sizeof(link_set))) {
-     link_set = NULL;
-     printf("********* err\n");
-     retval = 0;
-   }
-   
-   /* Topoloy table */
-   if(!olsr_plugin_io(GETD__TC_TABLE, 
- 		     &tc_table, 
- 		     sizeof(tc_table)))
-   {
-     tc_table = NULL;
-     retval = 0;
-   }
- 
-   /* HNA table */
-   if(!olsr_plugin_io(GETD__HNA_SET, 
- 		     &hna_set, 
- 		     sizeof(hna_set)))
-   {
-     hna_set = 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;
-   }
- 
-   /* "ProcessChanges" event registration */
-   if(!olsr_plugin_io(GETF__REGISTER_PCF, 
- 		     &register_pcf, 
- 		     sizeof(register_pcf)))
-   {
-     register_pcf = 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;
-   }
- 
-   /* Remove socket from OLSR select function */
-   if(!olsr_plugin_io(GETF__REMOVE_OLSR_SOCKET, &remove_olsr_socket, sizeof(remove_olsr_socket)))
-   {
-     remove_olsr_socket = NULL;
-     retval = 0;
-   }
- 
-   return retval;
- 
- }
--- 126,127 ----




More information about the Olsr-cvs mailing list