info: add netjson commands
authorFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 14 Apr 2016 11:36:40 +0000 (13:36 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Fri, 15 Apr 2016 11:16:17 +0000 (13:16 +0200)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/info/info_types.h
lib/info/olsrd_info.c

index 7bac96b..d3887f7 100644 (file)
@@ -99,8 +99,16 @@ typedef struct {
 /* this data is not normal format but olsrd.conf format */
 #define SIW_OLSRD_CONF                   (1ULL << 13)
 
+/* netjson */
+#define SIW_NETJSON_NETWORK_ROUTES       (1ULL << 14)
+#define SIW_NETJSON_NETWORK_GRAPH        (1ULL << 15)
+#define SIW_NETJSON_DEVICE_CONFIGURATION (1ULL << 16)
+#define SIW_NETJSON_DEVICE_MONITORING    (1ULL << 17)
+#define SIW_NETJSON_NETWORK_COLLECTION   (1ULL << 18)
+#define SIW_NETJSON                      (SIW_NETJSON_NETWORK_ROUTES | SIW_NETJSON_NETWORK_GRAPH | SIW_NETJSON_DEVICE_CONFIGURATION | SIW_NETJSON_DEVICE_MONITORING | SIW_NETJSON_NETWORK_COLLECTION)
+
 /* everything */
-#define SIW_EVERYTHING                   ((1ULL << 14) - 1)
+#define SIW_EVERYTHING                   ((1ULL << 19) - 1)
 
 typedef void (*init_plugin)(const char *plugin_name);
 typedef unsigned long long (*supported_commands_mask_func)(void);
@@ -135,6 +143,12 @@ typedef struct {
     printer_generic twohop;
     printer_generic config;
     printer_generic plugins;
+
+    printer_generic networkRoutes;
+    printer_generic networkGraph;
+    printer_generic deviceConfiguration;
+    printer_generic deviceMonitoring;
+    printer_generic networkCollection;
 } info_plugin_functions_t;
 
 struct info_cache_entry_t {
@@ -158,6 +172,12 @@ struct info_cache_t {
     struct info_cache_entry_t version;
     struct info_cache_entry_t config;
     struct info_cache_entry_t plugins;
+
+    struct info_cache_entry_t networkRoutes;
+    struct info_cache_entry_t networkGraph;
+    struct info_cache_entry_t deviceConfiguration;
+    struct info_cache_entry_t deviceMonitoring;
+    struct info_cache_entry_t networkCollection;
 };
 
 static INLINE struct info_cache_entry_t * info_cache_get_entry(struct info_cache_t * cache, unsigned long long siw) {
@@ -220,6 +240,26 @@ static INLINE struct info_cache_entry_t * info_cache_get_entry(struct info_cache
       r = &cache->plugins;
       break;
 
+    case SIW_NETJSON_NETWORK_ROUTES:
+      r = &cache->networkRoutes;
+      break;
+
+    case SIW_NETJSON_NETWORK_GRAPH:
+      r = &cache->networkGraph;
+      break;
+
+    case SIW_NETJSON_DEVICE_CONFIGURATION:
+      r = &cache->deviceConfiguration;
+      break;
+
+    case SIW_NETJSON_DEVICE_MONITORING:
+      r = &cache->deviceMonitoring;
+      break;
+
+    case SIW_NETJSON_NETWORK_COLLECTION:
+      r = &cache->networkCollection;
+      break;
+
     default:
       /* not cached */
       break;
index 00ccdc6..27b58ab 100644 (file)
@@ -139,7 +139,13 @@ static unsigned long long SIW_ENTRIES_ALL[] = {
     //
     SIW_ALL, //
     //
-    SIW_OLSRD_CONF //
+    SIW_OLSRD_CONF, //
+    //
+    SIW_NETJSON_NETWORK_ROUTES,
+    SIW_NETJSON_NETWORK_GRAPH,
+    SIW_NETJSON_DEVICE_CONFIGURATION,
+    SIW_NETJSON_DEVICE_MONITORING,
+    SIW_NETJSON_NETWORK_COLLECTION
     };
 
 long cache_timeout_generic(info_plugin_config_t *plugin_config, unsigned long long siw) {
@@ -159,6 +165,12 @@ long cache_timeout_generic(info_plugin_config_t *plugin_config, unsigned long lo
     case SIW_INTERFACES:
     case SIW_2HOP:
     case SIW_SGW:
+
+    case SIW_NETJSON_NETWORK_ROUTES:
+    case SIW_NETJSON_NETWORK_GRAPH:
+    case SIW_NETJSON_DEVICE_CONFIGURATION:
+    case SIW_NETJSON_DEVICE_MONITORING:
+    case SIW_NETJSON_NETWORK_COLLECTION:
       return timeout;
 
     case SIW_VERSION:
@@ -457,6 +469,16 @@ static void send_info(const char * req, unsigned int send_what, int the_socket,
         { SIW_PLUGINS   , functions->plugins    } //
       };
 
+      send_info_from_table(&abuf, send_what, funcs, ARRAY_SIZE(funcs), &outputLength);
+    } else if (send_what & SIW_NETJSON) {
+      SiwLookupTableEntry funcs[] = {
+        { SIW_NETJSON_NETWORK_ROUTES      , functions->networkRoutes      }, //
+        { SIW_NETJSON_NETWORK_GRAPH       , functions->networkGraph       }, //
+        { SIW_NETJSON_DEVICE_CONFIGURATION, functions->deviceConfiguration}, //
+        { SIW_NETJSON_DEVICE_MONITORING   , functions->deviceMonitoring   }, //
+        { SIW_NETJSON_NETWORK_COLLECTION  , functions->networkCollection  } //
+      };
+
       send_info_from_table(&abuf, send_what, funcs, ARRAY_SIZE(funcs), &outputLength);
     } else if ((send_what & SIW_OLSRD_CONF) && functions->olsrd_conf) {
       /* this outputs the olsrd.conf text directly, not normal format */