Skip to content

Commit e1bfc89

Browse files
squidarthSidharth Shanker
authored andcommitted
Refactored the arguments to be a ParsedArguments class.
1 parent 421f42f commit e1bfc89

12 files changed

+91
-50
lines changed

src/frontend/linkshell.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "link_queue.hh"
1313
#include "packetshell.cc"
1414
#include "tokenize.hh"
15+
#include "parsed_arguments.hh"
1516

1617
using namespace std;
1718

@@ -27,15 +28,15 @@ void usage_error( const string & program_name )
2728
cerr << " --uplink-queue=QUEUE_TYPE --downlink-queue=QUEUE_TYPE" << endl;
2829
cerr << " --uplink-queue-args=QUEUE_ARGS --downlink-queue-args=QUEUE_ARGS" << endl;
2930
cerr << endl;
30-
cerr << " QUEUE_TYPE = infinite | droptail | drophead | codel | pie" << endl;
31+
cerr << " QUEUE_TYPE = infinite | droptail | drophead | codel | pie | red" << endl;
3132
cerr << " QUEUE_ARGS = \"NAME=NUMBER[, NAME2=NUMBER2, ...]\"" << endl;
3233
cerr << " (with NAME = bytes | packets | target | interval | qdelay_ref | max_burst)" << endl;
3334
cerr << " target, interval, qdelay_ref, max_burst are in milli-second" << endl << endl;
3435

3536
throw runtime_error( "invalid arguments" );
3637
}
3738

38-
unique_ptr<AbstractPacketQueue> get_packet_queue( const string & type, const map<string, string> & args, const string & program_name )
39+
unique_ptr<AbstractPacketQueue> get_packet_queue( const string & type, ParsedArguments args, const string & program_name )
3940
{
4041
if ( type == "infinite" ) {
4142
return unique_ptr<AbstractPacketQueue>( new InfinitePacketQueue( args ) );
@@ -73,10 +74,10 @@ string shell_quote( const string & arg )
7374
return ret;
7475
}
7576

76-
map<string, string> parse_queue_args( const string & arg) {
77+
ParsedArguments parse_queue_args( const string & arg) {
7778
map<string, string> argMap = map<string, string>();
7879
if (arg.size() == 0) {
79-
return argMap;
80+
return ParsedArguments( argMap );
8081
}
8182
vector<string> argList = split(arg, ",");
8283

@@ -90,7 +91,7 @@ map<string, string> parse_queue_args( const string & arg) {
9091
argMap.insert(pair<string, string>(argParts[0], argParts[1]));
9192
}
9293

93-
return argMap;
94+
return ParsedArguments( argMap );
9495
}
9596

9697
int main( int argc, char *argv[] )

src/packet/abstract_packet_queue.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <string>
77

88
#include "queued_packet.hh"
9+
#include "parsed_arguments.hh"
910

1011
class AbstractPacketQueue
1112
{

src/packet/codel_packet_queue.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@
55

66
using namespace std;
77

8-
CODELPacketQueue::CODELPacketQueue( const map<string, string> & args )
8+
CODELPacketQueue::CODELPacketQueue( ParsedArguments & args )
99
: DroppingPacketQueue(args),
10-
target_ ( get_int_arg( args, "target") ),
11-
interval_ ( get_int_arg( args, "interval") ),
10+
target_ ( args.get_int_arg("target") ),
11+
interval_ ( args.get_int_arg( "interval") ),
1212
first_above_time_ ( 0 ),
1313
drop_next_( 0 ),
1414
count_ ( 0 ),
1515
lastcount_ ( 0 ),
1616
dropping_ ( 0 )
1717
{
18-
if ( target_ == 0 || interval_ == 0 ) {
19-
throw runtime_error( "CoDel queue must have target and interval arguments." );
20-
}
2118
}
2219

2320
//NOTE: CoDel makes drop decisions at dequeueing.

src/packet/codel_packet_queue.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private:
4545
uint64_t control_law ( uint64_t t, uint32_t count );
4646

4747
public:
48-
CODELPacketQueue( const std::map<std::string, std::string> & args );
48+
CODELPacketQueue( ParsedArguments & args );
4949

5050
void enqueue( QueuedPacket && p ) override;
5151

src/packet/dropping_packet_queue.cc

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,15 @@
88

99
using namespace std;
1010

11-
DroppingPacketQueue::DroppingPacketQueue( const map<string, string> & args )
12-
: packet_limit_( get_int_arg( args, "packets" ) ),
13-
byte_limit_( get_int_arg( args, "bytes" ) )
11+
DroppingPacketQueue::DroppingPacketQueue( ParsedArguments & args )
12+
: packet_limit_( args.get_int_arg( "packets", 0 ) ),
13+
byte_limit_( args.get_int_arg( "bytes", 0 ) )
1414
{
1515
if ( packet_limit_ == 0 and byte_limit_ == 0 ) {
1616
throw runtime_error( "Dropping queue must have a byte or packet limit." );
1717
}
1818
}
1919

20-
unsigned int DroppingPacketQueue::get_int_arg(const map<string, string> & args, const string & name) {
21-
if (args.count(name) > 0) {
22-
return myatoi(args.at(name));
23-
} else {
24-
return 0;
25-
}
26-
}
27-
28-
double DroppingPacketQueue::get_float_arg(const map<string, string> & args, const string & name) {
29-
if (args.count(name) > 0) {
30-
return myatof(args.at(name));
31-
} else {
32-
return 0;
33-
}
34-
}
35-
3620
QueuedPacket DroppingPacketQueue::dequeue( void )
3721
{
3822
assert( not internal_queue_.empty() );

src/packet/dropping_packet_queue.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected:
3232
const unsigned int size_in_packets ) const;
3333

3434
public:
35-
DroppingPacketQueue( const std::map<std::string, std::string> & args );
35+
DroppingPacketQueue( ParsedArguments & args );
3636

3737
virtual void enqueue( QueuedPacket && p ) = 0;
3838

src/packet/infinite_packet_queue.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private:
1818
int queue_size_in_bytes_ = 0, queue_size_in_packets_ = 0;
1919

2020
public:
21-
InfinitePacketQueue( const std::map<std::string, std::string> & args )
21+
InfinitePacketQueue( ParsedArguments & args )
2222
{
2323
if ( not args.empty() ) {
2424
throw std::runtime_error( "InfinitePacketQueue does not take arguments." );

src/packet/pie_packet_queue.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ using namespace std;
88

99
#define DQ_COUNT_INVALID (uint32_t)-1
1010

11-
PIEPacketQueue::PIEPacketQueue( const map<string, string> & args )
11+
PIEPacketQueue::PIEPacketQueue( ParsedArguments & args )
1212
: DroppingPacketQueue(args),
13-
qdelay_ref_ ( get_int_arg( args, "qdelay_ref" ) ),
14-
max_burst_ ( get_int_arg( args, "max_burst" ) ),
13+
qdelay_ref_ ( args.get_int_arg( "qdelay_ref" ) ),
14+
max_burst_ ( args.get_int_arg( "max_burst" ) ),
1515
alpha_ ( 0.125 ),
1616
beta_ ( 1.25 ),
1717
t_update_ ( 30 ),

src/packet/pie_packet_queue.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private:
5252
void calculate_drop_prob ( void );
5353

5454
public:
55-
PIEPacketQueue( const std::map<std::string, std::string> & args );
55+
PIEPacketQueue( ParsedArguments & args );
5656

5757
void enqueue( QueuedPacket && p ) override;
5858

src/packet/red_packet_queue.cc

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,18 @@
44

55
using namespace std;
66

7-
REDPacketQueue::REDPacketQueue( const map<string, string> & args)
7+
REDPacketQueue::REDPacketQueue( ParsedArguments & args)
88
: DroppingPacketQueue(args),
9-
wq_(get_float_arg(args, "wq")),
10-
min_thresh_(get_float_arg(args, "minthresh")),
11-
max_thresh_(get_float_arg(args, "maxthresh")),
12-
transmission_time_(get_int_arg(args, "transmission_time")),
9+
wq_(args.get_float_arg("wq")),
10+
min_thresh_(args.get_float_arg("minthresh")),
11+
max_thresh_(args.get_float_arg("maxthresh")),
12+
transmission_time_(args.get_int_arg("transmission_time")),
1313
time_at_zero_q_(0),
1414
prng_( random_device()() ),
1515
drop_dist_ (0, 1),
1616
current_random_val_(0),
1717
count_(0)
1818
{
19-
if (packet_limit_ == 0) {
20-
throw runtime_error( "RED queue must have packet limit." );
21-
}
22-
23-
if ( wq_ == 0.0 || min_thresh_ == 0.0 || max_thresh_ == 0.0 || transmission_time_ == 0 ) {
24-
throw runtime_error( "RED queue must have wq, minthresh, maxthresh, and transmission_time arguments." );
25-
}
2619

2720
}
2821

0 commit comments

Comments
 (0)