8
8
#include < iostream>
9
9
#include < sstream>
10
10
#include < map>
11
+ #include < cstring>
12
+ #include < deque>
11
13
12
14
#include " bmt_common.h"
13
15
#include " logger.h"
14
- #include " bmt_common .h"
16
+ #include " bmt_orch_constants .h"
15
17
16
18
extern global_config_t g;
17
19
pthread_t debug_thread;
18
20
int sock = 0 ;
19
21
22
+ template <typename O> void split (const std::string &s, char delim, O result) {
23
+ std::stringstream ss;
24
+ ss.str (s);
25
+ std::string item;
26
+ while (getline (ss, item, delim)) {
27
+ if (!item.empty ()) *(result++) = item;
28
+ }
29
+ }
30
+
31
+ std::deque<std::string> split (const std::string &s, char delim) {
32
+ std::deque<std::string> elems;
33
+ split (s, delim, back_inserter (elems));
34
+ return elems;
35
+ }
36
+
20
37
/* *
21
38
* Simple command mapping:
22
39
* INPUT CFG OUTPUT
@@ -26,39 +43,85 @@ int sock = 0;
26
43
*
27
44
*/
28
45
void dispatch (std::string &input, global_config_t * cfg, std::ostringstream &stream) {
29
- (void )cfg;
30
- if (!input.compare (" evac-stop" )) {
31
- cfg->exitFlag = true ;
32
- stream << " Exiting evacuator thread" ;
33
- }
34
- else if (!input.compare (" insert-stop" )) {
35
- cfg->scanDpdkPort = true ;
36
- stream << " Exiting inserter thread" ;
37
- }
38
- else if (!input.compare (" flush" )) {
39
- cfg->flushCache = true ;
40
- stream << " Flushing the cache" ;
41
- }
42
- else if (!input.compare (" pause" )) {
43
- cfg->pauseCacheInsertion = true ;
44
- stream << " Insertion paused" ;
45
- }
46
- else if (!input.compare (" resume" )) {
47
- cfg->pauseCacheInsertion = false ;
48
- stream << " Insertion resumed" ;
49
- }
50
- else if (!input.compare (" status" ) || !input.compare (" s" )) {
51
- stream << " sampler init status " << cfg->sampler_init_status << std::endl;
52
- stream << " inserter is " << (cfg->pauseCacheInsertion ? " paused" : " running" ) << std::endl;
53
- stream << " cacheInsertCount " << cfg->cacheInsertCount << std::endl;
54
- stream << " cacheInsertSkip " << cfg->cacheInsertSkip << std::endl;
55
- stream << " cacheRemoveCount " << cfg->cacheRemoveCount << std::endl;
56
- stream << " flushCache " << cfg->flushCache << std::endl;
57
- stream << " exitFlag " << cfg->exitFlag << std::endl;
58
- stream << " scanDpdkPort " << cfg->scanDpdkPort << std::endl;
46
+ try {
47
+ std::deque<std::string> input_args;
48
+ input_args = split (input,' ' );
49
+ if (input_args.empty ()) {
50
+ stream << input << " ??? Try - status, flush, pause, resume, window, ithresh, ethresh, evac-stop, insert-stop" ;
51
+ }
52
+ else {
53
+ std::string first = input_args.front ();
54
+ input_args.pop_front ();
55
+ if (!first.compare (" evac-stop" )) {
56
+ cfg->exitFlag = true ;
57
+ stream << " Exiting evacuator thread" ;
58
+ }
59
+ else if (!first.compare (" insert-stop" )) {
60
+ cfg->scanDpdkPort = true ;
61
+ stream << " Exiting inserter thread" ;
62
+ }
63
+ else if (!first.compare (" flush" )) {
64
+ cfg->flushCache = true ;
65
+ stream << " Flushing the cache" ;
66
+ }
67
+ else if (!first.compare (" pause" )) {
68
+ cfg->pauseCacheInsertion = true ;
69
+ stream << " Insertion paused" ;
70
+ }
71
+ else if (!first.compare (" resume" )) {
72
+ cfg->pauseCacheInsertion = false ;
73
+ stream << " Insertion resumed" ;
74
+ }
75
+ else if (!first.compare (" window" )) {
76
+ if (!input_args.empty ()) {
77
+ std::string value = input_args.front ();
78
+ cfg->insertionWindowSize = (uint32_t ) stoul (value,nullptr ,0 );
79
+ input_args.pop_front ();
80
+ }
81
+ stream << " Insertion window size is " << cfg->insertionWindowSize ;
82
+ }
83
+ else if (!first.compare (" ithresh" )) {
84
+ if (!input_args.empty ()) {
85
+ std::string value = input_args.front ();
86
+ cfg->insertionThreshold = (uint32_t ) stoul (value,nullptr ,0 );
87
+ input_args.pop_front ();
88
+ }
89
+ stream << " Insertion threshold is " << cfg->insertionThreshold ;
90
+
91
+ }
92
+ else if (!first.compare (" ethresh" )) {
93
+ if (!input_args.empty ()) {
94
+ std::string value = input_args.front ();
95
+ cfg->evacuationThreshold = (uint32_t ) stoul (value,nullptr ,0 );
96
+ input_args.pop_front ();
97
+ }
98
+ stream << " Evacuation threshold is " << cfg->evacuationThreshold ;
99
+ }
100
+ else if (!first.compare (" status" ) || !input.compare (" s" )) {
101
+ stream << " sampler init status " << cfg->sampler_init_status << std::endl;
102
+ stream << " inserter is " << (cfg->pauseCacheInsertion ? " paused" : " running" ) << std::endl;
103
+ stream << " insert window size " << cfg->insertionWindowSize << std::endl;
104
+ stream << " insert threshold " << cfg->insertionThreshold << std::endl;
105
+ stream << " evacuation threshold " << cfg->evacuationThreshold << std::endl;
106
+ stream << " cache inserts " << cfg->cacheInsertCount
107
+ << " , skip " << cfg->cacheInsertSkip
108
+ << " , remove " << cfg->cacheRemoveCount << std::endl;
109
+ stream << " entry counter " ;
110
+ for (int i = 0 ; i < VHOST_TABLE_SIZE; i++) {
111
+ stream << " #" << i << " : " << cfg->entryCounters [i] << " , " ;
112
+ }
113
+ stream << std::endl;
114
+ stream << " flushCache " << cfg->flushCache << std::endl;
115
+ stream << " exitFlag " << cfg->exitFlag << std::endl;
116
+ stream << " scanDpdkPort " << cfg->scanDpdkPort << std::endl;
117
+ }
118
+ else {
119
+ stream << input << " ??? Try - status, flush, pause, resume, evac-stop, insert-stop" ;
120
+ }
121
+ }
59
122
}
60
- else {
61
- stream << input << " ??? Try - status, flush, pause, resume, evac-stop, insert-stop " ;
123
+ catch ( const std:: exception &e) {
124
+ stream << " Invalid command \" " << input << " \" " << " : " << e. what () << std::endl ;
62
125
}
63
126
}
64
127
0 commit comments