Skip to content

Commit 575ddd6

Browse files
committed
Refactored the arguments to be a ParsedArguments class.
1 parent f2f5e7d commit 575ddd6

12 files changed

+26
-50
lines changed

src/frontend/linkshell.cc

Lines changed: 5 additions & 4 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

@@ -35,7 +36,7 @@ void usage_error( const string & program_name )
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/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ libpacket_a_SOURCES = packetshell.hh packetshell.cc queued_packet.hh \
99
codel_packet_queue.cc codel_packet_queue.hh \
1010
red_packet_queue.cc red_packet_queue.hh \
1111
pie_packet_queue.cc pie_packet_queue.hh \
12-
bindworkaround.hh
12+
bindworkaround.hh ../frontend/parsed_arguments.hh

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
@@ -35,7 +35,7 @@ protected:
3535
const unsigned int size_in_packets ) const;
3636

3737
public:
38-
DroppingPacketQueue( const std::map<std::string, std::string> & args );
38+
DroppingPacketQueue( ParsedArguments & args );
3939

4040
virtual void enqueue( QueuedPacket && p ) = 0;
4141

src/packet/infinite_packet_queue.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private:
1717
std::queue<QueuedPacket> internal_queue_ {};
1818

1919
public:
20-
InfinitePacketQueue( const std::map<std::string, std::string> & args )
20+
InfinitePacketQueue( ParsedArguments & args )
2121
{
2222
if ( not args.empty() ) {
2323
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

0 commit comments

Comments
 (0)