in reply to IP generation algorithm (tc)
My solution is similar to NetWallah's, but it allows subnet customization in the %special_subnets data, rather than in code.
Since you are pre-pending '0x' to $count, I added code to convert $count to hex first; ignore if inappropriate.
Working, lightly tested code:
my $DEV = 'dev eth1'; my $count = 500; my %special_subnets = ( 6 => [ 0, 1, 2], 17 => [ 0, 1], 19 => [ 0, 1, 2], ); foreach my $oct1 ( 10 ) { foreach my $oct2 ( 1 .. 22 ) { my $third_octets_aref = $special_subnets{$oct2} || [ 0 ]; foreach my $oct3 ( @{ $third_octets_aref } ) { foreach my $oct4 ( 1 .. 254 ) { # 253 ?? print HTB generate_rule( $DEV, $count, $oct1, $oct2, $oct3, $o +ct4 ); $count++; } } } } sub generate_rule { my ( $dev, $count, @octets ) = @_; my $ip = join '.', @octets; # my $countx = '0x' . $count; my $countx = sprintf '0x%04x', $count; return <<"END_RULE"; class add $dev parent 1:7 classid 1:$countx rate 4kbit ceil 512Kbit +burst 4kbit prio 1 quantum 2000 filter add $dev protocol ip parent 1:0 prio 1 u32 match ip dst $ip/32 + match ip src 0.0.0.0/0 flowid 1:$countx qdisc add $dev parent 1:$countx handle $countx: pfifo limit 5 END_RULE }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: IP generation algorithm (tc)
by giany (Acolyte) on Feb 10, 2006 at 16:41 UTC | |
by giany (Acolyte) on Feb 10, 2006 at 17:27 UTC |