iproute 1.2.3 → 1.2.4
raw patch · 4 files changed
+49/−11 lines, 4 files
Files
- Data/IP.hs +2/−2
- Data/IP/Addr.hs +20/−0
- iproute.cabal +1/−1
- test/Tests.hs +26/−8
Data/IP.hs view
@@ -5,8 +5,8 @@ -- * Documentation -- ** IP data IP (..)- , IPv4, toIPv4- , IPv6, toIPv6+ , IPv4, toIPv4, fromIPv4+ , IPv6, toIPv6, fromIPv6 -- ** IP range data , IPRange (..) , AddrRange (addr, mask, mlen)
Data/IP/Addr.hs view
@@ -101,6 +101,26 @@ ---------------------------------------------------------------- --+-- IPToInt+--++{-|+ The 'fromIPv4' function convert 'IPv4' to a list of 'Int'.+-}+fromIPv4 :: IPv4 -> [Int]+fromIPv4 (IP4 w) = map (\n -> fromEnum $ (w `shiftR` n) .&. 0xff) [0o30, 0o20, 0o10, 0o00]++{-|+ The 'toIPv6' function convert 'IPv6' to a list of 'Int'.+-}+fromIPv6 :: IPv6 -> [Int]+fromIPv6 (IP6 (w1, w2, w3, w4)) = map fromEnum (concatMap split [w1,w2,w3,w4])+ where+ split :: Word32 -> [Word32]+ split n = [n `shiftR` 0x10 .&. 0xffff, n .&. 0xffff]++----------------------------------------------------------------+-- -- Read --
iproute.cabal view
@@ -1,5 +1,5 @@ Name: iproute-Version: 1.2.3+Version: 1.2.4 Author: Kazu Yamamoto <kazu@iij.ad.jp> Maintainer: Kazu Yamamoto <kazu@iij.ad.jp> License: BSD3
test/Tests.hs view
@@ -40,6 +40,8 @@ , testProperty "Delete insert IPv6" prop_delete_insert_ipv6 , testProperty "Delete lookup IPv4" prop_delete_lookup_ipv4 , testProperty "Delete lookup IPv6" prop_delete_lookup_ipv6+ , testProperty "Convert fromto [Int] IPv4" prop_convert_ipv4+ , testProperty "Convert fromto [Int] IPv6" prop_convert_ipv6 ] , testGroup "Test case for routing table" [ testCase "fromto IPv4" test_fromto_ipv4@@ -81,18 +83,28 @@ -- instance Arbitrary (AddrRange IPv4) where- arbitrary = arbitraryIP toIPv4 255 4 32+ arbitrary = arbitraryIP arbitrary 32 instance Arbitrary (AddrRange IPv6) where- arbitrary = arbitraryIP toIPv6 65535 8 128+ arbitrary = arbitraryIP arbitrary 128 -arbitraryIP :: Routable a => ([Int] -> a) -> Int -> Int -> Int -> Gen (AddrRange a)-arbitraryIP func width adrlen msklen = do- a <- replicateM adrlen (choose (0,width))- let adr = func a- len <- choose (0,msklen)- return $ makeAddrRange adr len+instance Arbitrary IPv4 where+ arbitrary = arbitraryAdr toIPv4 255 4 +instance Arbitrary IPv6 where+ arbitrary = arbitraryAdr toIPv6 65535 8++arbitraryAdr :: Routable a => ([Int] -> a) -> Int -> Int -> Gen a+arbitraryAdr func width adrlen = do+ a <- replicateM adrlen (choose (0, width))+ return $ func a++arbitraryIP :: Routable a => Gen a -> Int -> Gen (AddrRange a)+arbitraryIP adrGen msklen = do+ adr <- adrGen+ len <- choose (0,msklen)+ return $ makeAddrRange adr len+ ---------------------------------------------------------------- -- -- Properties@@ -233,6 +245,12 @@ rs = zip xs xs t = fromList rs k = head xs++prop_convert_ipv4 :: IPv4 -> Property+prop_convert_ipv4 ip = True ==> (toIPv4 . fromIPv4) ip == ip++prop_convert_ipv6 :: IPv6 -> Property+prop_convert_ipv6 ip = True ==> (toIPv6 . fromIPv6) ip == ip ----------------------------------------------------------------