11/* -*-mode:c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
22
33#include < getopt.h>
4+ #include < map>
45
56#include " infinite_packet_queue.hh"
67#include " drop_tail_packet_queue.hh"
1011#include " red_packet_queue.hh"
1112#include " link_queue.hh"
1213#include " packetshell.cc"
14+ #include " tokenize.hh"
1315
1416using namespace std ;
1517
@@ -33,7 +35,7 @@ void usage_error( const string & program_name )
3335 throw runtime_error ( " invalid arguments" );
3436}
3537
36- unique_ptr<AbstractPacketQueue> get_packet_queue ( const string & type, const string & args, const string & program_name )
38+ unique_ptr<AbstractPacketQueue> get_packet_queue ( const string & type, const map< string, string> & args, const string & program_name )
3739{
3840 if ( type == " infinite" ) {
3941 return unique_ptr<AbstractPacketQueue>( new InfinitePacketQueue ( args ) );
@@ -71,6 +73,26 @@ string shell_quote( const string & arg )
7173 return ret;
7274}
7375
76+ map<string, string> parse_queue_args ( const string & arg) {
77+ map<string, string> argMap = map<string, string>();
78+ if (arg.size () == 0 ) {
79+ return argMap;
80+ }
81+ vector<string> argList = split (arg, " ," );
82+
83+ for (size_t i = 0 ;i < argList.size ();i++) {
84+ string s = argList[i];
85+ vector<string> argParts = split (s, " =" );
86+ if (argParts.size () != 2 ) {
87+ throw runtime_error (" Queue args passed in wrong format" );
88+ }
89+
90+ argMap.insert (pair<string, string>(argParts[0 ], argParts[1 ]));
91+ }
92+
93+ return argMap;
94+ }
95+
7496int main ( int argc, char *argv[] )
7597{
7698 try {
@@ -99,7 +121,7 @@ int main( int argc, char *argv[] )
99121 { " meter-downlink-delay" , no_argument, nullptr , ' y' },
100122 { " meter-all" , no_argument, nullptr , ' z' },
101123 { " uplink-queue" , required_argument, nullptr , ' q' },
102- { " downlink-queue" , required_argument, nullptr , ' w' },
124+ { " downlink-queue" , required_argument, nullptr , ' w' },
103125 { " uplink-queue-args" , required_argument, nullptr , ' a' },
104126 { " downlink-queue-args" , required_argument, nullptr , ' b' },
105127 { 0 , 0 , nullptr , 0 }
@@ -186,11 +208,11 @@ int main( int argc, char *argv[] )
186208
187209 link_shell_app.start_uplink ( " [link] " , command,
188210 " Uplink" , uplink_filename, uplink_logfile, repeat, meter_uplink, meter_uplink_delay,
189- get_packet_queue ( uplink_queue_type, uplink_queue_args, argv[ 0 ] ),
211+ get_packet_queue ( uplink_queue_type, parse_queue_args ( uplink_queue_args) , argv[ 0 ] ),
190212 command_line );
191213
192214 link_shell_app.start_downlink ( " Downlink" , downlink_filename, downlink_logfile, repeat, meter_downlink, meter_downlink_delay,
193- get_packet_queue ( downlink_queue_type, downlink_queue_args, argv[ 0 ] ),
215+ get_packet_queue ( downlink_queue_type, parse_queue_args ( downlink_queue_args) , argv[ 0 ] ),
194216 command_line );
195217
196218 return link_shell_app.wait_for_exit ();
0 commit comments