Enum type on the API for QoS sources 80/14680/3
authorNeale Ranns <nranns@cisco.com>
Wed, 5 Sep 2018 16:36:05 +0000 (09:36 -0700)
committerDamjan Marion <dmarion@me.com>
Thu, 6 Sep 2018 08:14:02 +0000 (08:14 +0000)
Change-Id: I877541ede6e26581c659821502f23b777903b82f
Signed-off-by: Neale Ranns <nranns@cisco.com>
src/vnet/qos/qos.api
src/vnet/qos/qos_api.c
src/vpp/api/custom_dump.c

index a7bd19a..720c417 100644 (file)
@@ -1,5 +1,6 @@
+/* Hey Emacs use -*- mode: C -*- */
 /*
- * Copyright (c) 2016 Cisco and/or its affiliates.
+ * Copyright (c) 2018 Cisco and/or its affiliates.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
 
 option version = "1.0.0";
 
+enum qos_source
+{
+  QOS_API_SOURCE_EXT = 0,
+  QOS_API_SOURCE_VLAN = 1,
+  QOS_API_SOURCE_MPLS = 2,
+  QOS_API_SOURCE_IP = 3,
+};
+
 /** \brief Enable/Disable QoS recording
     The QoS bits from the packet at the specified input layer are copied
     into the packet. Recording should be used in conjunction with marking
@@ -34,7 +43,7 @@ autoreply define qos_record_enable_disable
   u32 client_index;
   u32 context;
   u32 sw_if_index;
-  u8 input_source;
+  vl_api_qos_source_t input_source;
   u8 enable;
 };
 
@@ -89,7 +98,7 @@ autoreply define qos_mark_enable_disable
   u32 context;
   u32 map_id;
   u32 sw_if_index;
-  u8 output_source;
+  vl_api_qos_source_t output_source;
   u8 enable;
 };
 
index e239313..6297c24 100644 (file)
   _(QOS_EGRESS_MAP_UPDATE, qos_egress_map_update)                       \
   _(QOS_MARK_ENABLE_DISABLE, qos_mark_enable_disable)
 
+static int
+qos_source_decode (vl_api_qos_source_t v, qos_source_t * q)
+{
+  v = ntohl (v);
+
+  switch (v)
+    {
+    case QOS_API_SOURCE_EXT:
+      *q = QOS_SOURCE_EXT;
+      return 0;
+    case QOS_API_SOURCE_VLAN:
+      *q = QOS_SOURCE_VLAN;
+      return 0;
+    case QOS_API_SOURCE_MPLS:
+      *q = QOS_SOURCE_MPLS;
+      return 0;
+    case QOS_API_SOURCE_IP:
+      *q = QOS_SOURCE_IP;
+      return 0;
+    }
+
+  return (VNET_API_ERROR_INVALID_VALUE);
+}
+
 void
 vl_api_qos_record_enable_disable_t_handler (vl_api_qos_record_enable_disable_t
                                            * mp)
 {
   vl_api_qos_record_enable_disable_reply_t *rmp;
+  qos_source_t qs;
   int rv = 0;
 
-  if (mp->input_source >= QOS_N_SOURCES)
-    rv = VNET_API_ERROR_INVALID_VALUE;
-  else
+  rv = qos_source_decode (mp->input_source, &qs);
+
+  if (0 == rv)
     {
       if (mp->enable)
-       rv = qos_record_enable (ntohl (mp->sw_if_index), mp->input_source);
+       rv = qos_record_enable (ntohl (mp->sw_if_index), qs);
       else
-       rv = qos_record_disable (ntohl (mp->sw_if_index), mp->input_source);
+       rv = qos_record_disable (ntohl (mp->sw_if_index), qs);
     }
 
   REPLY_MACRO (VL_API_QOS_RECORD_ENABLE_DISABLE_REPLY);
@@ -99,17 +124,18 @@ void
   (vl_api_qos_mark_enable_disable_t * mp)
 {
   vl_api_qos_mark_enable_disable_reply_t *rmp;
+  qos_source_t qs;
   int rv = 0;
 
-  if (mp->output_source >= QOS_N_SOURCES)
-    rv = VNET_API_ERROR_INVALID_VALUE;
-  else
+  rv = qos_source_decode (mp->output_source, &qs);
+
+  if (0 == rv)
     {
       if (mp->enable)
-       rv = qos_mark_enable (ntohl (mp->sw_if_index),
-                             mp->output_source, ntohl (mp->map_id));
+       rv =
+         qos_mark_enable (ntohl (mp->sw_if_index), qs, ntohl (mp->map_id));
       else
-       rv = qos_mark_disable (ntohl (mp->sw_if_index), mp->output_source);
+       rv = qos_mark_disable (ntohl (mp->sw_if_index), qs);
     }
 
   REPLY_MACRO (VL_API_QOS_MARK_ENABLE_DISABLE_REPLY);
index 39f1640..2a8cd78 100644 (file)
@@ -3509,7 +3509,9 @@ static void *vl_api_qos_record_enable_disable_t_print
 
   s = format (0, "SCRIPT: qos_record_enable_disable ");
   s = format (s, "sw_if_index %d ", ntohl (mp->sw_if_index));
-  s = format (s, "input_source %U ", format_qos_source, mp->input_source);
+  s =
+    format (s, "input_source %U ", format_qos_source,
+           ntohl (mp->input_source));
 
   if (!mp->enable)
     s = format (s, "disable ");