Masanobu Yasui authored on 2010/03/30 18:51:07
Showing 7 changed files
... ...
@@ -1,3 +1,6 @@
1
+1.3.1:
2
+ - add -T option (traffic-shape, Mbps order)
3
+
1 4
 1.3.0:
2 5
  - add -R option (RCVBUF socket option value)
3 6
  - add -S option (SNDBUF socket option value)
... ...
@@ -1,7 +1,11 @@
1
+1.3.1:
2
+ - Tオプションを追加
3
+   Mbps単位で最大転送レートを指定
4
+
1 5
 1.3.0: 2010/3/1
2 6
  - ソケットバッファサイズを指定できるオプションを追加
3
- - -R オプション (SO_RCVBUF)
4
- - -S オプション (SO_SNDBUF)
7
+ - R オプション (SO_RCVBUF)
8
+ - S オプション (SO_SNDBUF)
5 9
 
6 10
 1.2.2: 2010/2/25
7 11
  - makuosan.sysvをstatusとrestartに対応
... ...
@@ -5,11 +5,13 @@
5 5
 #include "makuosan.h"
6 6
 
7 7
 mopt moption;
8
-mfile *mftop[2] = {NULL,NULL};
9
-mfile *mfreeobj = NULL;
10
-mhost *members  = NULL;
11
-int loop_flag   = 1;
12
-int send_rate   = 0;
8
+mfile *mftop[2]  = {NULL,NULL};
9
+mfile *mfreeobj  = NULL;
10
+mhost *members   = NULL;
11
+int loop_flag    = 1;
12
+int send_rate    = 0;
13
+int view_rate    = 0;
14
+time_t send_time = 0;
13 15
 struct timeval curtime;
14 16
 struct timeval lastpong;
15 17
 BF_KEY EncKey;
... ...
@@ -308,6 +308,8 @@ extern int optopt;
308 308
 extern int optreset;
309 309
 extern int loop_flag;
310 310
 extern int send_rate;
311
+extern int view_rate;
312
+extern time_t send_time;
311 313
 extern char *tzname[2];
312 314
 extern int daylight;
313 315
 extern char TZ[256];
... ...
@@ -382,6 +382,7 @@ int mexec_send(mcomm *c, int n, int sync)
382 382
   }
383 383
   argv[i] = NULL;
384 384
   optind  = 1;
385
+  opterr  = 1;
385 386
 #ifdef HAVE_GETOPT_OPTRESET
386 387
   optreset = 1;
387 388
 #endif
... ...
@@ -564,6 +565,7 @@ int mexec_check(mcomm *c, int n)
564 564
     argv[i] = c->parse[n][i];
565 565
   argv[i] = NULL;
566 566
   optind  = 1;
567
+  opterr  = 1;
567 568
 #ifdef HAVE_GETOPT_OPTRESET
568 569
   optreset = 1;
569 570
 #endif
... ...
@@ -670,6 +672,7 @@ int mexec_dsync(mcomm *c, int n)
670 670
     argv[i] = c->parse[n][i];
671 671
   argv[i] = NULL;
672 672
   optind  = 1;
673
+  opterr  = 1;
673 674
 #ifdef HAVE_GETOPT_OPTRESET
674 675
   optreset = 1;
675 676
 #endif
... ...
@@ -905,6 +908,9 @@ int mexec_status(mcomm *c, int n)
905 905
   /*----- RCVBUF/SNDBUF -----*/
906 906
   cprintf(0, c, "recvsize: %d\n", moption.recvsize);
907 907
   cprintf(0, c, "sendsize: %d\n", moption.sendsize);
908
+  
909
+  /*----- send rate -----*/
910
+  cprintf(0, c, "sendrate: %d/%d\n", view_rate * 8 / 1024 / 1024, moption.sendrate * 8 / 1024 / 1024);
908 911
 
909 912
   /*----- command -----*/
910 913
   count = 0;
... ...
@@ -28,6 +28,7 @@ static void usage()
28 28
   printf("  -f num   # parallel send count(default: 5) \n");
29 29
   printf("  -R num   # recv buffer size [bytes]\n");
30 30
   printf("  -S num   # send buffer size [bytes]\n");
31
+  printf("  -T num   # traffic rate     [Mbps]\n");
31 32
   printf("  -c       # chroot to base dir\n");
32 33
   printf("  -n       # don't fork\n");
33 34
   printf("  -r       # don't recv\n");
... ...
@@ -318,7 +319,7 @@ static void minit_getopt(int argc, char *argv[])
318 318
         exit(0);
319 319
 
320 320
       case 'T':
321
-        moption.sendrate = atoi(optarg);
321
+        moption.sendrate = atoi(optarg) * 1024 * 1024 / 8;
322 322
         break;
323 323
 
324 324
       case 'R':
... ...
@@ -670,7 +671,7 @@ static void minit_bootlog()
670 670
   lprintf(0, "passwoed  : %s\n", yesno(moption.commpass));
671 671
   lprintf(0, "ownermatch: %s\n", yesno(moption.ownmatch));
672 672
   if(moption.sendrate){
673
-    lprintf(0, "rate      : %d[Mbps]\n", moption.sendrate);
673
+    lprintf(0, "rate      : %d[Mbps]\n", moption.sendrate * 8 / 1024 / 1024);
674 674
   }
675 675
   if(moption.comm_ena){
676 676
     if(moption.uaddr.sun_path[0]){
... ...
@@ -59,7 +59,22 @@ static int msend_encrypt(mdata *data)
59 59
 static int msend_readywait()
60 60
 {
61 61
   fd_set fds;
62
+  time_t tm;
62 63
   struct timeval tv;
64
+
65
+  tm = time(NULL);
66
+  while(tm == send_time){
67
+    if(moption.sendrate > send_rate){
68
+      break;
69
+    }
70
+    usleep(1000);
71
+    tm = time(NULL);
72
+  }
73
+  if(tm != send_time){
74
+    view_rate = send_rate;
75
+    send_rate =  0;
76
+    send_time = tm;
77
+  }
63 78
   while(!moption.sendready){
64 79
     FD_ZERO(&fds);
65 80
     FD_SET(moption.mcsocket, &fds);
... ...
@@ -100,6 +115,7 @@ static int msend_packet(int s, mdata *data, struct sockaddr_in *addr)
100 100
     moption.sendready = 0;
101 101
     r = sendto(s, &senddata, szdata, 0, (struct sockaddr*)addr, sizeof(struct sockaddr_in));
102 102
     if(r == szdata){
103
+      send_rate += r;
103 104
       return(0); /* success */
104 105
     }
105 106
     if(r == -1){