Support for error vectors 07/19907/1
authorOndrej Fabry <ofabry@cisco.com>
Fri, 31 May 2019 06:56:20 +0000 (08:56 +0200)
committerOndrej Fabry <ofabry@cisco.com>
Fri, 31 May 2019 06:56:20 +0000 (08:56 +0200)
- this fixes compilation error for VPP 19.08 and keeps
  backwards compatibility with previous versions

Change-Id: Ib58557a090caa5e8342c0cb21de8af684cb18137
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
adapter/stats_api.go
adapter/vppapiclient/stat_client.go
adapter/vppapiclient/stat_client_wrapper.h

index 4087865..146914d 100644 (file)
@@ -86,7 +86,7 @@ type Name string
 type ScalarStat float64
 
 // ErrorStat represents stat for ErrorIndex.
-type ErrorStat uint64
+type ErrorStat Counter
 
 // SimpleCounterStat represents stat for SimpleCounterVector.
 // The outer array represents workers and the inner array represents interface/node/.. indexes.
index 2615b65..389c93b 100644 (file)
@@ -71,6 +71,13 @@ func (c *statClient) Connect() error {
                sockName = c.socketName
        }
 
+       if _, err := os.Stat(sockName); err != nil {
+               if os.IsNotExist(err) {
+                       return fmt.Errorf("stats socket file %q does not exists, ensure that VPP is running with `statseg { ... }` section in config", sockName)
+               }
+               return fmt.Errorf("stats socket file error: %v", err)
+       }
+
        rc := C.govpp_stat_connect(C.CString(sockName))
        if rc != 0 {
                return fmt.Errorf("connecting to VPP stats API failed (rc=%v)", rc)
index 9178fb5..3fe0460 100644 (file)
 #if STAT_VERSION_MAJOR >= 1 && STAT_VERSION_MINOR >= 1
        #define SUPPORTS_NAME_VECTOR // VPP 19.04 is required!
 #endif
+// Error value was changed into vector in VPP 19.08
+#if STAT_VERSION_MAJOR >= 1 && STAT_VERSION_MINOR >= 2
+       #define SUPPORTS_ERROR_VECTOR // VPP 19.08 is required!
+#endif
 
 static int
 govpp_stat_connect(char *socket_name)
@@ -93,10 +97,18 @@ govpp_stat_segment_data_get_scalar_value(stat_segment_data_t *data)
        return data->scalar_value;
 }
 
-static double
+static counter_t
 govpp_stat_segment_data_get_error_value(stat_segment_data_t *data)
 {
-       return data->error_value;
+#ifdef SUPPORTS_ERROR_VECTOR
+       counter_t value = 0;
+       int j;
+       for (j = 0; j < stat_segment_vec_len(data->error_vector); j++) // VPP 19.08+ is required!
+       value += data->error_vector[j];
+       return value;
+#else
+       return data->error_value; // VPP <19.08
+#endif
 }
 
 static uint64_t**
@@ -168,9 +180,9 @@ govpp_stat_segment_data_free(stat_segment_data_t *data)
 }
 
 static uint8_t**
-govpp_stat_segment_string_vector(uint8_t ** string_vector, char *string)
+govpp_stat_segment_string_vector(uint8_t **string_vec, char *s)
 {
-       return stat_segment_string_vector(string_vector, string);
+       return stat_segment_string_vector(string_vec, s);
 }
 
 #endif /* included_stat_client_wrapper_h */