[PATCH 1/1] tc: custom qdisc pkt size translation table

2017-07-03 Thread McCabe, Robert J
Added the "custom" linklayer qdisc stab option.
Allows the user to specify the pkt size translation
parameters from stdin.
Example:
   tc qdisc add ... stab tsize 8 linklayer custom htb
  Custom size table:
  InputSizeStart -> IntputSizeEnd: OutputSize
  0  -> 511  : 600
  512-> 1023 : 1200
  1024   -> 1535 : 1800
  1536   -> 2047 : 2400
  2048   -> 2559 : 3000

blah

Signed-off-by: McCabe, Robert J 
---
 include/linux/pkt_sched.h |  1 +
 tc/tc_core.c  | 46 ++
 tc/tc_core.h  |  2 +-
 tc/tc_stab.c  | 20 +---
 tc/tc_util.c  |  5 +
 5 files changed, 62 insertions(+), 12 deletions(-)

diff --git a/include/linux/pkt_sched.h b/include/linux/pkt_sched.h
index 099bf55..289bb81 100644
--- a/include/linux/pkt_sched.h
+++ b/include/linux/pkt_sched.h
@@ -82,6 +82,7 @@ enum tc_link_layer {
TC_LINKLAYER_UNAWARE, /* Indicate unaware old iproute2 util */
TC_LINKLAYER_ETHERNET,
TC_LINKLAYER_ATM,
+   TC_LINKLAYER_CUSTOM,
 };
 #define TC_LINKLAYER_MASK 0x0F /* limit use to lower 4 bits */
 
diff --git a/tc/tc_core.c b/tc/tc_core.c
index 821b741..167f4d7 100644
--- a/tc/tc_core.c
+++ b/tc/tc_core.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "tc_core.h"
 #include 
@@ -28,6 +29,13 @@
 static double tick_in_usec = 1;
 static double clock_factor = 1;
 
+struct size_table_entry {
+   unsigned int input_size_boundary_start;
+   unsigned int output_size_bytes;
+};
+
+static struct size_table_entry* custom_size_table = NULL;
+static int num_size_table_entries = 0;
 int tc_core_time2big(unsigned int time)
 {
__u64 t = time;
@@ -89,6 +97,20 @@ static unsigned int tc_align_to_atm(unsigned int size)
return linksize;
 }
 
+static unsigned int tc_align_to_custom(unsigned int size)
+{
+   int i;
+
+   assert(custom_size_table != NULL);
+   for(i = num_size_table_entries -1; i >= 0 ; --i) {
+   if(custom_size_table[i].input_size_boundary_start < size) {
+   /* found it */
+   return custom_size_table[i].output_size_bytes;
+   }
+   }
+   return 0;
+}
+
 static unsigned int tc_adjust_size(unsigned int sz, unsigned int mpu, enum 
link_layer linklayer)
 {
if (sz < mpu)
@@ -97,6 +119,8 @@ static unsigned int tc_adjust_size(unsigned int sz, unsigned 
int mpu, enum link_
switch (linklayer) {
case LINKLAYER_ATM:
return tc_align_to_atm(sz);
+   case LINKLAYER_CUSTOM:
+   return tc_align_to_custom(sz);
case LINKLAYER_ETHERNET:
default:
/* No size adjustments on Ethernet */
@@ -185,6 +209,24 @@ int tc_calc_size_table(struct tc_sizespec *s, __u16 **stab)
if (!*stab)
return -1;
 
+   if(LINKLAYER_CUSTOM == linklayer) {
+custom_size_table = malloc(sizeof(struct size_table_entry)* 
s->tsize);
+if(!custom_size_table)
+ return -1;
+num_size_table_entries = s->tsize;
+
+printf("Custom size table:\n");
+printf("InputSizeStart -> IntputSizeEnd: OutputSize\n");
+for(i = 0; i <= s->tsize - 1; ++i) {
+ printf("%-14d -> %-13d: ", i << s->cell_log, ((i+1) 
<< s->cell_log) - 1);
+ if(!scanf("%u", 
_size_table[i].output_size_bytes)) {
+   fprintf(stderr, "Invalid custom stab 
table entry!\n");
+   return -1;
+ }
+ custom_size_table[i].input_size_boundary_start = i << 
s->cell_log;
+}
+   }
+
 again:
for (i = s->tsize - 1; i >= 0; i--) {
sz = tc_adjust_size((i + 1) << s->cell_log, s->mpu, linklayer);
@@ -196,6 +238,10 @@ again:
}
 
s->cell_align = -1; /* Due to the sz calc */
+   if(custom_size_table) {
+free(custom_size_table);
+num_size_table_entries = 0;
+   }
return 0;
 }
 
diff --git a/tc/tc_core.h b/tc/tc_core.h
index 8a63b79..8e97222 100644
--- a/tc/tc_core.h
+++ b/tc/tc_core.h
@@ -10,9 +10,9 @@ enum link_layer {
LINKLAYER_UNSPEC,
LINKLAYER_ETHERNET,
LINKLAYER_ATM,
+   LINKLAYER_CUSTOM,
 };
 
-
 int  tc_core_time2big(unsigned time);
 unsigned tc_core_time2tick(unsigned time);
 unsigned tc_core_tick2time(unsigned tick);
diff --git a/tc/tc_stab.c b/tc/tc_stab.c
index 1a0a3e3..a468a70 100644
--- a/tc/tc_stab.c
+++ b/tc/tc_stab.c
@@ -37,7 +37,9 @@ static void stab_help(void)
"   tsize : how many slots should size table have {512}\n"
"   mpu   : minimum packet size used in 

Re: [PATCH 1/1] tc: custom qdisc pkt size translation table

2017-06-27 Thread Eric Dumazet
On Tue, 2017-06-27 at 12:37 -0500, Robert McCabe wrote:
> Yeah, sorry didn't even think about that.
> I guess my first question would be is there another way via the
> iproute2 project where a user could
> configure the stab->data pkt size translation table used in the
> __qdisc_calculate_pkt_len method
> in the kernel source (net/sched/sched_api.c)?
> 
> Also, let's say I went ahead and made the added TC_LINK_LAYER_CUSTOM
> to the include/uapi/linux/pkt_sched.h
> file in the kernel source ... would I also need to make the same
> change in include/uapi/linux/pkt_sched.h in
> the iproute2 source?
> 
> Do you recommend an alternative (more elegant) approach to what I'm
> trying to accomplish?

Note that since you probably want to be able to dump the table
(tc -s -d qdisc show ), you might need a kernel change anyway.

Then the iproute2 change would be a companion.





Re: [PATCH 1/1] tc: custom qdisc pkt size translation table

2017-06-27 Thread Robert McCabe
Yeah, sorry didn't even think about that.
I guess my first question would be is there another way via the
iproute2 project where a user could
configure the stab->data pkt size translation table used in the
__qdisc_calculate_pkt_len method
in the kernel source (net/sched/sched_api.c)?

Also, let's say I went ahead and made the added TC_LINK_LAYER_CUSTOM
to the include/uapi/linux/pkt_sched.h
file in the kernel source ... would I also need to make the same
change in include/uapi/linux/pkt_sched.h in
the iproute2 source?

Do you recommend an alternative (more elegant) approach to what I'm
trying to accomplish?


On Tue, Jun 27, 2017 at 11:55 AM, Eric Dumazet  wrote:
> On Tue, 2017-06-27 at 11:29 -0500, McCabe, Robert J wrote:
>> Added the "custom" linklayer qdisc stab option.
>> This allows the user to specify the pkt size translation
>> parameters from stdin.
>> Example:
>>tc qdisc add ... stab tsize 8 linklayer custom htb
>>Custom size table:
>>InputSizeStart -> IntputSizeEnd: Output Pkt Size
>>0 - 255: 400
>>256 - 511: 800
>>512 - 767: 1200
>>768 - 1023: 1600
>>1024 - 1279: 2000
>>1280 - 1535: 2400
>>1536 - 1791: 2800
>>1792 - 2047: 3200
>>
>> Signed-off-by: McCabe, Robert J 
>> ---
>>  include/linux/pkt_sched.h |  1 +
>>  tc/tc_core.c  | 51 
>> +++
>>  tc/tc_core.h  |  2 +-
>>  tc/tc_stab.c  |  4 +++-
>>  tc/tc_util.c  |  5 +
>>  5 files changed, 61 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/linux/pkt_sched.h b/include/linux/pkt_sched.h
>> index 099bf55..289bb81 100644
>> --- a/include/linux/pkt_sched.h
>> +++ b/include/linux/pkt_sched.h
>> @@ -82,6 +82,7 @@ enum tc_link_layer {
>>   TC_LINKLAYER_UNAWARE, /* Indicate unaware old iproute2 util */
>>   TC_LINKLAYER_ETHERNET,
>>   TC_LINKLAYER_ATM,
>> + TC_LINKLAYER_CUSTOM,
>>  };
>>  #define TC_LINKLAYER_MASK 0x0F /* limit use to lower 4 bits */
>>
>
>
> You can not do this : This file is coming from the kernel
> ( include/uapi/linux/pkt_sched.h )
>
> Since your patch is user space only, you need to find another way ?
>
>
>


Re: [PATCH 1/1] tc: custom qdisc pkt size translation table

2017-06-27 Thread Eric Dumazet
On Tue, 2017-06-27 at 11:29 -0500, McCabe, Robert J wrote:
> Added the "custom" linklayer qdisc stab option.
> This allows the user to specify the pkt size translation
> parameters from stdin.
> Example:
>tc qdisc add ... stab tsize 8 linklayer custom htb
>Custom size table:
>InputSizeStart -> IntputSizeEnd: Output Pkt Size
>0 - 255: 400
>256 - 511: 800
>512 - 767: 1200
>768 - 1023: 1600
>1024 - 1279: 2000
>1280 - 1535: 2400
>1536 - 1791: 2800
>1792 - 2047: 3200
> 
> Signed-off-by: McCabe, Robert J 
> ---
>  include/linux/pkt_sched.h |  1 +
>  tc/tc_core.c  | 51 
> +++
>  tc/tc_core.h  |  2 +-
>  tc/tc_stab.c  |  4 +++-
>  tc/tc_util.c  |  5 +
>  5 files changed, 61 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/pkt_sched.h b/include/linux/pkt_sched.h
> index 099bf55..289bb81 100644
> --- a/include/linux/pkt_sched.h
> +++ b/include/linux/pkt_sched.h
> @@ -82,6 +82,7 @@ enum tc_link_layer {
>   TC_LINKLAYER_UNAWARE, /* Indicate unaware old iproute2 util */
>   TC_LINKLAYER_ETHERNET,
>   TC_LINKLAYER_ATM,
> + TC_LINKLAYER_CUSTOM,
>  };
>  #define TC_LINKLAYER_MASK 0x0F /* limit use to lower 4 bits */
>  


You can not do this : This file is coming from the kernel
( include/uapi/linux/pkt_sched.h )

Since your patch is user space only, you need to find another way ?





[PATCH 1/1] tc: custom qdisc pkt size translation table

2017-06-27 Thread McCabe, Robert J
Added the "custom" linklayer qdisc stab option.
This allows the user to specify the pkt size translation
parameters from stdin.
Example:
   tc qdisc add ... stab tsize 8 linklayer custom htb
   Custom size table:
   InputSizeStart -> IntputSizeEnd: Output Pkt Size
   0 - 255: 400
   256 - 511: 800
   512 - 767: 1200
   768 - 1023: 1600
   1024 - 1279: 2000
   1280 - 1535: 2400
   1536 - 1791: 2800
   1792 - 2047: 3200

Signed-off-by: McCabe, Robert J 
---
 include/linux/pkt_sched.h |  1 +
 tc/tc_core.c  | 51 +++
 tc/tc_core.h  |  2 +-
 tc/tc_stab.c  |  4 +++-
 tc/tc_util.c  |  5 +
 5 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/include/linux/pkt_sched.h b/include/linux/pkt_sched.h
index 099bf55..289bb81 100644
--- a/include/linux/pkt_sched.h
+++ b/include/linux/pkt_sched.h
@@ -82,6 +82,7 @@ enum tc_link_layer {
TC_LINKLAYER_UNAWARE, /* Indicate unaware old iproute2 util */
TC_LINKLAYER_ETHERNET,
TC_LINKLAYER_ATM,
+   TC_LINKLAYER_CUSTOM,
 };
 #define TC_LINKLAYER_MASK 0x0F /* limit use to lower 4 bits */
 
diff --git a/tc/tc_core.c b/tc/tc_core.c
index 821b741..fb04704 100644
--- a/tc/tc_core.c
+++ b/tc/tc_core.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "tc_core.h"
 #include 
@@ -28,6 +29,16 @@
 static double tick_in_usec = 1;
 static double clock_factor = 1;
 
+struct size_table_entry {
+   unsigned int input_size_boundary_start;
+   unsigned int output_size_bytes;
+};
+
+//TODO: free
+static struct size_table_entry* custom_size_table = NULL;
+static int num_size_table_entries = 0;
+
+
 int tc_core_time2big(unsigned int time)
 {
__u64 t = time;
@@ -89,6 +100,23 @@ static unsigned int tc_align_to_atm(unsigned int size)
return linksize;
 }
 
+static unsigned int tc_align_to_custom(unsigned int size)
+{
+   int i;
+
+   assert(custom_size_table != NULL);
+
+   for(i = num_size_table_entries -1; i >= 0 ; --i)
+   {
+   if(custom_size_table[i].input_size_boundary_start < size)
+   {
+   /* found it */
+   return custom_size_table[i].output_size_bytes;
+   }
+   }
+   return 0;
+}
+
 static unsigned int tc_adjust_size(unsigned int sz, unsigned int mpu, enum 
link_layer linklayer)
 {
if (sz < mpu)
@@ -97,6 +125,8 @@ static unsigned int tc_adjust_size(unsigned int sz, unsigned 
int mpu, enum link_
switch (linklayer) {
case LINKLAYER_ATM:
return tc_align_to_atm(sz);
+   case LINKLAYER_CUSTOM:
+   return tc_align_to_custom(sz);
case LINKLAYER_ETHERNET:
default:
/* No size adjustments on Ethernet */
@@ -185,6 +215,27 @@ int tc_calc_size_table(struct tc_sizespec *s, __u16 **stab)
if (!*stab)
return -1;
 
+   if(LINKLAYER_CUSTOM == linklayer)
+   {
+   custom_size_table = malloc(sizeof(struct size_table_entry)* 
s->tsize);
+   if(!custom_size_table)
+   return -1;
+   num_size_table_entries = s->tsize;
+
+   printf("Custom size table:\n");
+   printf("InputSizeStart -> IntputSizeEnd : Output Pkt Size\n");
+   for(i = 0; i <= s->tsize - 1; ++i)
+   {
+   printf("%d - %d: ", i << s->cell_log, ((i+1) << 
s->cell_log) - 1);
+   if(!scanf("%u", 
_size_table[i].output_size_bytes))
+   {
+   fprintf(stderr, "Invalid custom stab table 
entry!\n");
+   return -1;
+   }
+
+   custom_size_table[i].input_size_boundary_start = i << 
s->cell_log;
+   }
+   }
 again:
for (i = s->tsize - 1; i >= 0; i--) {
sz = tc_adjust_size((i + 1) << s->cell_log, s->mpu, linklayer);
diff --git a/tc/tc_core.h b/tc/tc_core.h
index 8a63b79..8e97222 100644
--- a/tc/tc_core.h
+++ b/tc/tc_core.h
@@ -10,9 +10,9 @@ enum link_layer {
LINKLAYER_UNSPEC,
LINKLAYER_ETHERNET,
LINKLAYER_ATM,
+   LINKLAYER_CUSTOM,
 };
 
-
 int  tc_core_time2big(unsigned time);
 unsigned tc_core_time2tick(unsigned time);
 unsigned tc_core_tick2time(unsigned tick);
diff --git a/tc/tc_stab.c b/tc/tc_stab.c
index 1a0a3e3..8374c76 100644
--- a/tc/tc_stab.c
+++ b/tc/tc_stab.c
@@ -37,7 +37,9 @@ static void stab_help(void)
"   tsize : how many slots should size table have {512}\n"
"   mpu   : minimum packet size used in rate computations\n"
"   overhead  : per-packet size overhead used in rate 
computations\n"
-   "   linklayer : adapting to a linklayer e.g. atm\n"
+   "   linklayer : adapting to a linklayer e.g. ethernet, atm or 
custom\n"
+