net-spider-rpl 0.3.0.0 → 0.3.1.0
raw patch · 5 files changed
+64/−17 lines, 5 filesdep ~hashabledep ~ipdep ~timePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: hashable, ip, time
API changes (from Hackage documentation)
+ NetSpider.RPL.IPv6: getInterfaceID :: IPv6 -> InterfaceID
+ NetSpider.RPL.IPv6: getPrefix :: IPv6 -> Prefix
+ NetSpider.RPL.IPv6: isLinkLocal :: IPv6 -> Bool
+ NetSpider.RPL.IPv6: setPrefix :: Prefix -> IPv6 -> IPv6
+ NetSpider.RPL.IPv6: type InterfaceID = Word64
+ NetSpider.RPL.IPv6: type Prefix = Word64
Files
- ChangeLog.md +5/−0
- net-spider-rpl.cabal +9/−8
- src/NetSpider/RPL/FindingID.hs +6/−2
- src/NetSpider/RPL/IPv6.hs +25/−7
- test/NetSpider/RPL/IPv6Spec.hs +19/−0
ChangeLog.md view
@@ -1,5 +1,10 @@ # Revision history for net-spider-rpl +## 0.3.1.0 -- 2019-10-04++* Expose an internal module `NetSpider.RPL.IPv6`.+* Confirm test with `ip-1.5.1`, `ip-1.6.0`, `hashable-1.3.0.0`, `time-1.9.3`.+ ## 0.3.0.0 -- 2019-09-30 ### ContikiNG module
net-spider-rpl.cabal view
@@ -1,5 +1,5 @@ name: net-spider-rpl-version: 0.3.0.0+version: 0.3.1.0 author: Toshio Ito <debug.ito@gmail.com> maintainer: Toshio Ito <debug.ito@gmail.com> license: BSD3@@ -30,16 +30,16 @@ NetSpider.RPL.DIO, NetSpider.RPL.DAO, NetSpider.RPL.Combined,- NetSpider.RPL.ContikiNG- other-modules: NetSpider.RPL.IPv6+ NetSpider.RPL.ContikiNG,+ NetSpider.RPL.IPv6 build-depends: base >=4.11.1.0 && <4.13, aeson >=1.3.1.1 && <1.5, greskell >=0.2.3.0 && <0.3, net-spider >=0.3.1.0 && <0.4, text >=1.2.3.1 && <1.3,- ip >=1.3.0 && <1.5,- hashable >=1.2.7.0 && <1.3,- time >=1.8.0.2 && <1.9,+ ip >=1.3.0 && <1.7,+ hashable >=1.2.7.0 && <1.4,+ time >=1.8.0.2 && <1.10, conduit-parse >=0.2.1.0 && <0.3, conduit >=1.3.1 && <1.4, mtl >=2.2.2 && <2.3,@@ -64,8 +64,9 @@ main-is: Spec.hs -- default-extensions: other-extensions: OverloadedStrings- other-modules: NetSpider.RPL.ContikiNGSpec- build-depends: base, net-spider-rpl, net-spider, text, monad-logger,+ other-modules: NetSpider.RPL.ContikiNGSpec,+ NetSpider.RPL.IPv6Spec+ build-depends: base, net-spider-rpl, net-spider, text, monad-logger, ip, hspec >=2.5.5, bytestring >=0.10.8.2 && <0.11, fast-logger >=2.4.11 && <2.5
src/NetSpider/RPL/FindingID.hs view
@@ -23,18 +23,22 @@ import Control.Applicative ((<$>), (<*>)) import Control.Monad.Fail (MonadFail)+import Data.Bits (shiftL, (.|.)) import Data.Monoid ((<>)) import Data.Aeson (FromJSON(..), ToJSON(..)) import qualified Data.Aeson as Aeson import Data.Greskell (FromGraphSON(..)) import Data.Hashable (Hashable(..)) import Data.Text (Text)+import Data.Word (Word64, Word32) import qualified Data.Text as T import GHC.Generics (Generic)-import Net.IPv6 (IPv6(..))+import Net.IPv6 (IPv6) import qualified Net.IPv6 as IPv6 import NetSpider.GraphML.Writer (ToNodeID(..)) +import NetSpider.RPL.IPv6 (getPrefix, getInterfaceID)+ -- | Type of local finding. data FindingType = FindingDIO -- ^ Local finding about DIO (Upward) routes.@@ -116,7 +120,7 @@ instance Hashable IPv6ID where hashWithSalt s (IPv6ID a) =- s `hashWithSalt` (ipv6A a) `hashWithSalt` (ipv6B a)+ s `hashWithSalt` getPrefix a `hashWithSalt` getInterfaceID a ipv6ToText :: IPv6ID -> Text ipv6ToText (IPv6ID a) = IPv6.encode a
src/NetSpider/RPL/IPv6.hs view
@@ -1,20 +1,23 @@ -- | -- Module: NetSpider.RPL.IPv6--- Description: +-- Description: (INTERNAL) Basic routines for IPv6 type -- Maintainer: Toshio Ito <debug.ito@gmail.com> -- -- __This module is for internal use.__+--+-- @since 0.3.1.0 module NetSpider.RPL.IPv6 ( Prefix, InterfaceID, isLinkLocal, getPrefix,- setPrefix+ setPrefix,+ getInterfaceID ) where -import Data.Bits ((.&.), shift)-import Data.Word (Word64)-import Net.IPv6 (IPv6(..), toWord16s)+import Data.Bits ((.&.), shift, shiftL, (.|.), shiftR)+import Data.Word (Word64, Word32)+import Net.IPv6 (IPv6, toWord16s, toWord32s, fromWord32s) type Prefix = Word64 @@ -27,7 +30,22 @@ bit_mask = (2 ^ (10 :: Int) - 1) `shift` 6 getPrefix :: IPv6 -> Prefix-getPrefix = ipv6A+getPrefix addr = to64 u l+ where+ (u, l, _, _) = toWord32s addr setPrefix :: Prefix -> IPv6 -> IPv6-setPrefix p orig = orig { ipv6A = p }+setPrefix p orig = fromWord32s u1 u2 l1 l2+ where+ (_, _, l1, l2) = toWord32s orig+ u1 = fromIntegral ((p `shiftR` 32) .&. 0xFFFFFFFF)+ u2 = fromIntegral (p .&. 0xFFFFFFFF)++getInterfaceID :: IPv6 -> InterfaceID+getInterfaceID addr = to64 u l+ where+ (_, _, u, l) = toWord32s addr++to64 :: Word32 -> Word32 -> Word64+to64 u l = (fromIntegral u `shiftL` 32) .|. fromIntegral l+
+ test/NetSpider/RPL/IPv6Spec.hs view
@@ -0,0 +1,19 @@+module NetSpider.RPL.IPv6Spec (main,spec) where++import Net.IPv6 (ipv6)+import Test.Hspec++import NetSpider.RPL.IPv6 (getPrefix, setPrefix)++main :: IO ()+main = hspec spec++spec :: Spec+spec = describe "prefix" $ do+ let input = ipv6 0xfe00 0x0012 0x4310 0x0020 0xaa9d 0xd393 0xaa00 0x49be+ specify "getPrefix" $ do+ getPrefix input `shouldBe` 0xfe00001243100020+ specify "setPrefix" $ do+ let prefix = 0xf055aa0d00329391+ expected = ipv6 0xf055 0xaa0d 0x0032 0x9391 0xaa9d 0xd393 0xaa00 0x49be+ setPrefix prefix input `shouldBe` expected