File: v4-splitplan.t

package info (click to toggle)
libnetaddr-ip-perl 4.079%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,568 kB
  • sloc: perl: 1,417; cpp: 67; makefile: 9
file content (73 lines) | stat: -rw-r--r-- 2,286 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

use Test::More tests => 28;

use_ok('NetAddr::IP');

my $ip = new NetAddr::IP('192.168.21.13/15');
my $rv;
ok(($rv = sprintf("%s",$ip)) eq '192.168.21.13/15',"$rv eq 192.168.21.13/15");

my($plan,$masks) = $ip->_splitplan(15);
ok($plan,'there is a plan');
ok(!$masks,'plan returns the orignal net');
ok(@$plan == 1,'one item plan');
ok(($rv = $plan->[0]) == 15,"plan $rv is original cidr 15");

my $cmask = new NetAddr::IP('255.126.0.0');
ok(($rv = sprintf("%s",$cmask)) eq '255.126.0.0/32',"$rv eq 255.126.0.0/32");

($plan,$masks) = $ip->_splitplan($cmask);
ok(!$plan,'failing because of bits in mask');

$cmask = new NetAddr::IP('255.254.0.0');
ok(($rv = sprintf("%s",$cmask)) eq '255.254.0.0/32',"$rv eq 255.254.0.0/32");

($plan,$masks) = $ip->_splitplan($cmask);
ok($plan,'there is a plan');

ok(!$masks,'plan returns the orignal net');
ok(@$plan == 1,'one item plan');
ok(($rv = $plan->[0]) == 15,"plan $rv is original cidr 15");

$cmask = '255.254.0.0';			# ipV4 text cmask
($plan,$masks) = $ip->_splitplan($cmask);
ok($plan,'there is a plan');
ok(!$masks,'plan returns the orignal net');
ok(@$plan == 1,'one item plan');
ok(($rv = $plan->[0]) == 15,"plan $rv is original cidr 15");

$cmask = '255.126.0.0';                    # ipV4 text cmask
($plan,$masks) = $ip->_splitplan($cmask);
ok(!$plan,'failing because of bits in mask');

$cmask = 'garbage';
($plan,$masks) = $ip->_splitplan($cmask);
ok(!$plan,'failing because of garbage');

$cmask = 14;	# cidr is bigger than requested
($plan,$masks) = $ip->_splitplan($cmask);
ok(!$plan,'failing because of 15 overange');

# cidr makes more nets than 2**16
($plan,$masks) = $ip->_splitplan(32);
ok(!$plan,'failing to many nets 32 - 15 = 2**17');

($plan,$masks) = $ip->_splitplan(16,16,16);
ok(!$plan,'failing because of 3 * 16 overange');

# test for plan that just fits
($plan,$masks) = $ip->_splitplan(31);
ok($plan,'there is a plan 31');
ok($masks,'plan has masks');
ok(($rv = @{$plan}) == 2 ** 16,"$rv should = 65536");

# set netlimit internal to 4 nets
$NetAddr::IP::_netlimit = 4;
($plan,$masks) = $ip->_splitplan(17);	# should fit
ok($plan,"plan of 4 17's");

($plan,$masks) = $ip->_splitplan(17,17,17,17,18);
ok(!plan,"fail plan of 4 17's + 18");

($plan,$masks) = $ip->_splitplan(18);
ok(!plan,"fail plan of 8 18's");