-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed test command, added tests for the ip manager module
Signed-off-by: Tobias Bossert <[email protected]>
- Loading branch information
Showing
3 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/perl | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
|
||
use experimental 'signatures'; | ||
use FindBin; | ||
use lib $FindBin::Bin.'/../thirdparty/lib/perl5'; | ||
use lib $FindBin::Bin.'/../lib'; | ||
use Net::IPManager; | ||
use Net::IPManager::Constants; | ||
|
||
my $IPManager = Net::IPManager->new(); | ||
use constant TEST_INTERFACE => 'test-interface'; | ||
|
||
$IPManager->populate_range(TEST_INTERFACE, '192.168.0.0/24'); | ||
|
||
# acquire single ip and check if the suggestions are updated accordingly | ||
ok $IPManager->suggest_ip(TEST_INTERFACE) eq '192.168.0.1/32', "Single ip suggestion 1"; | ||
$IPManager->acquire_single(TEST_INTERFACE, '192.168.0.1/32'); | ||
ok $IPManager->suggest_ip(TEST_INTERFACE) eq '192.168.0.2/32', "Single ip suggestion 2"; | ||
|
||
# Release ip again and check if suggestions are updated accordingly | ||
$IPManager->release_ip(TEST_INTERFACE, '192.168.0.1/32'); | ||
ok $IPManager->suggest_ip(TEST_INTERFACE) eq '192.168.0.1/32', "Single ip successfully released"; | ||
|
||
# acquire other (higher) ip and check if suggestions are still returning the lowest possible address | ||
$IPManager->acquire_single(TEST_INTERFACE, '192.168.0.10/32'); | ||
ok $IPManager->suggest_ip(TEST_INTERFACE) eq '192.168.0.1/32', "Acquire arbitrary and suggest"; | ||
|
||
# Checks | ||
# Try to required already occupied address | ||
ok $IPManager->acquire_single(TEST_INTERFACE, '192.168.0.10/32') eq E_ALREADY_ACQUIRED, 'Already acquired'; | ||
|
||
# Try to acquire/release on unknown interface | ||
ok $IPManager->acquire_single('DOES NOT EXIST', '192.168.0.10/32') eq E_UNKNOWN_INTERFACE, 'Unknown interface (acquire)'; | ||
ok $IPManager->release_ip('DOES NOT EXIST', '192.168.0.10/32') eq E_UNKNOWN_INTERFACE, 'Unknown interface (acquire)'; | ||
|
||
# Wrong subnet | ||
ok $IPManager->acquire_single(TEST_INTERFACE, '192.168.2.10/32') eq E_SUBNET_NOT_MATCHING, 'Non matching subnet (acquire)'; | ||
|
||
# Entire networks (192.168.0.0 - 192.168.0.7) | ||
$IPManager->acquire_single(TEST_INTERFACE, '192.168.0.0/29'); | ||
ok $IPManager->suggest_ip(TEST_INTERFACE) eq '192.168.0.8/32', 'IP suggestions after network acquire'; | ||
ok $IPManager->acquire_single(TEST_INTERFACE, '192.168.0.6/32') eq E_ALREADY_ACQUIRED, 'Try acquiring ip inside acquired subnet'; | ||
ok $IPManager->acquire_single(TEST_INTERFACE, '192.168.0.8/29') eq E_ALREADY_ACQUIRED, 'Try acquiring with overlapping subnet'; | ||
|
||
# Multi acquire | ||
$IPManager->acquire_multiple(TEST_INTERFACE, '192.168.0.8/32,192.168.0.9/32'); | ||
ok $IPManager->suggest_ip(TEST_INTERFACE) eq '192.168.0.11/32', 'IP suggestion after multi-acquire'; | ||
|
||
# try release ip inside acquired subnet | ||
$IPManager->release_ip(TEST_INTERFACE, '192.168.0.4/32'); | ||
ok $IPManager->acquire_single(TEST_INTERFACE, '192.168.0.4/32') eq E_ALREADY_ACQUIRED, 'Try release ip inside subnet'; | ||
|
||
# try acquire with overlapping subnet | ||
ok $IPManager->acquire_single(TEST_INTERFACE, '192.168.0.8/29') eq E_ALREADY_ACQUIRED, 'Try acquire with overlapping address'; | ||
|
||
# try acquire first and last address of interface subnet | ||
ok $IPManager->acquire_single(TEST_INTERFACE, '192.168.0.0/32') eq E_CANNOT_ACQUIRE_FIRST_OR_LAST, 'Try acquire first'; | ||
ok $IPManager->acquire_single(TEST_INTERFACE, '192.168.0.255/32') eq E_CANNOT_ACQUIRE_FIRST_OR_LAST, 'Try acquire last'; | ||
|
||
done_testing(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/perl | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
|
||
use experimental 'signatures'; | ||
use FindBin; | ||
use lib $FindBin::Bin.'/../thirdparty/lib/perl5'; | ||
use lib $FindBin::Bin.'/../lib'; | ||
use Net::IPManager; | ||
use Net::IPManager::Constants; | ||
|
||
my $IPManager = Net::IPManager->new(); | ||
use constant TEST_INTERFACE => 'test-interface'; | ||
|
||
$IPManager->populate_range(TEST_INTERFACE, '2001:db8::/64'); | ||
|
||
# acquire single ip and check if the suggestions are updated accordingly | ||
ok $IPManager->suggest_ip(TEST_INTERFACE) eq '2001:0db8:0000:0000:0000:0000:0000:0001/128', "Single ip suggestion 1"; | ||
$IPManager->acquire_single(TEST_INTERFACE, '2001:db8::1/128'); | ||
ok $IPManager->suggest_ip(TEST_INTERFACE) eq '2001:0db8:0000:0000:0000:0000:0000:0002/128', "Single ip suggestion 2"; | ||
|
||
# Release ip again and check if suggestions are updated accordingly | ||
$IPManager->release_ip(TEST_INTERFACE, '2001:db8::1/128'); | ||
ok $IPManager->suggest_ip(TEST_INTERFACE) eq '2001:0db8:0000:0000:0000:0000:0000:0001/128', "Single ip successfully released"; | ||
|
||
# acquire other (higher) ip and check if suggestions are still returning the lowest possible address | ||
$IPManager->acquire_single(TEST_INTERFACE, '2001:db8::83/128'); | ||
ok $IPManager->suggest_ip(TEST_INTERFACE) eq '2001:0db8:0000:0000:0000:0000:0000:0001/128', "Acquire arbitrary and suggest"; | ||
|
||
# Checks | ||
# Try to required already occupied address | ||
ok $IPManager->acquire_single(TEST_INTERFACE, '2001:db8::83/128') eq E_ALREADY_ACQUIRED, 'Already acquired'; | ||
|
||
# Try to acquire/release on unknown interface | ||
ok $IPManager->acquire_single('DOES NOT EXIST', '2001:db8::a/128') eq E_UNKNOWN_INTERFACE, 'Unknown interface (acquire)'; | ||
ok $IPManager->release_ip('DOES NOT EXIST', '2001:0db8:0000:0000:0000:0000:0000:000a/128') eq E_UNKNOWN_INTERFACE, 'Unknown interface (acquire)'; | ||
|
||
# Wrong subnet | ||
ok $IPManager->acquire_single(TEST_INTERFACE, '2001:db9::a/128') eq E_SUBNET_NOT_MATCHING, 'Non matching subnet (acquire)'; | ||
|
||
# Entire networks (2001:db8:: - 2001:db8::7f) | ||
$IPManager->acquire_single(TEST_INTERFACE, '2001:db8::2/128'); | ||
ok $IPManager->acquire_single(TEST_INTERFACE, '2001:db8::/121') eq E_ALREADY_ACQUIRED, 'Try acquiring overlapping subnet'; | ||
# release ::2 and try again | ||
$IPManager->release_ip(TEST_INTERFACE, '2001:db8::2/128'); | ||
$IPManager->acquire_single(TEST_INTERFACE, '2001:db8::/121'); | ||
ok $IPManager->suggest_ip(TEST_INTERFACE) eq '2001:0db8:0000:0000:0000:0000:0000:0080/128', 'IP suggestions after network acquire'; | ||
ok $IPManager->acquire_single(TEST_INTERFACE, '2001:db8::6f') eq E_ALREADY_ACQUIRED, 'Try acquiring ip inside acquired subnet'; | ||
|
||
# Multi acquire | ||
$IPManager->acquire_single(TEST_INTERFACE, '2001:0db8:0000:0000:0000:0000:0000:0080/128'); | ||
ok $IPManager->suggest_ip(TEST_INTERFACE) eq '2001:0db8:0000:0000:0000:0000:0000:0081/128', 'IP suggestion after multi-acquire'; | ||
|
||
# try release ip inside acquired subnet | ||
$IPManager->release_ip(TEST_INTERFACE, '2001:db8::12/128'); | ||
ok $IPManager->acquire_single(TEST_INTERFACE, '2001:db8::12/128') eq E_ALREADY_ACQUIRED, 'Try release ip inside subnet'; | ||
|
||
# try acquire first and last address of interface subnet | ||
ok $IPManager->acquire_single(TEST_INTERFACE, '2001:db8::/128') eq E_CANNOT_ACQUIRE_FIRST_OR_LAST, 'Try acquire first'; | ||
ok $IPManager->acquire_single(TEST_INTERFACE, '2001:0db8:0000:0000:ffff:ffff:ffff:ffff/128') eq E_CANNOT_ACQUIRE_FIRST_OR_LAST, 'Try acquire last'; | ||
|
||
done_testing(); | ||
|