A class to contain IPv4 and IPv6.
Moduleiproute-1.7.15Haskell2010
Data.IP.RouteTable
IP routing table is a tree of IPRange
to search one of them on the longest
match base. It is a kind of TRIE with one
way branching removed. Both IPv4 and IPv6
are supported.
For more information, see: http://www.mew.org/~kazu/proj/iproute/
- 1 type
- 1 class
- 11 values
- Packageiproute-1.7.15
- Exports13
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceRouteTable.hs
Documentation
0 declarationsRoutable class
Type for IP routing table
Instances11Generic1, Functor, Foldable, Traversable, Eq, Show, …
Generic1 (IPRTable k)Defined in iproute-1.7.15 · Data.IP.RouteTable.InternalFunctor (IPRTable k)Defined in iproute-1.7.15 · Data.IP.RouteTable.InternalFoldable (IPRTable k)Defined in iproute-1.7.15 · Data.IP.RouteTable.InternalTraversable (IPRTable k)Defined in iproute-1.7.15 · Data.IP.RouteTable.Internal(Eq k, Eq a) => Eq (IPRTable k a)Defined in iproute-1.7.15 · Data.IP.RouteTable.Internal(Show k, Show a) => Show (IPRTable k a)Defined in iproute-1.7.15 · Data.IP.RouteTable.InternalGeneric (IPRTable k a)Defined in iproute-1.7.15 · Data.IP.RouteTable.InternalRoutable k => Semigroup (IPRTable k a)Defined in iproute-1.7.15 · Data.IP.RouteTable.InternalNote that Semigroup and Monoid instances are right-biased. That is, if both arguments have the same key, the value from the right argument will be used. Since: 1.7.5
Routable k => Monoid (IPRTable k a)Defined in iproute-1.7.15 · Data.IP.RouteTable.InternalSince: 1.7.5
type Rep (IPRTable k a) = D1 ('MetaDataDefined in iproute-1.7.15 · Data.IP.RouteTable.Internal"IPRTable"
"Data.IP.RouteTable.Internal"
"iproute-1.7.15-3X50rHbdFZS8qgLxLNnKxb"
'False) (C1 ('MetaCons"Nil"
'PrefixI 'False) U1 :+: C1 ('MetaCons"Node"
'PrefixI 'False) ((S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (AddrRange k)) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 k)) :*: (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe a)) :*: (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (IPRTable k a)) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (IPRTable k a))))))type Rep1 (IPRTable k) = D1 ('MetaDataDefined in iproute-1.7.15 · Data.IP.RouteTable.Internal"IPRTable"
"Data.IP.RouteTable.Internal"
"iproute-1.7.15-3X50rHbdFZS8qgLxLNnKxb"
'False) (C1 ('MetaCons"Nil"
'PrefixI 'False) U1 :+: C1 ('MetaCons"Node"
'PrefixI 'False) ((S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (AddrRange k)) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 k)) :*: (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec1 Maybe) :*: (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec1 (IPRTable k)) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec1 (IPRTable k))))))
Functions to manipulate an IP routing table
The empty function returns an empty IP routing table.
(empty :: IPRTable IPv4 ()) == fromList []True
The lookup function looks up IPRTable with a key of AddrRange. If a routing information in IPRTable matches the key, its value is returned.
let v4 = ["133.4.0.0/16","133.5.0.0/16","133.5.16.0/24","133.5.23.0/24"] :: [AddrRange IPv4]let rt = fromList $ zip v4 v4lookup "127.0.0.1" rtNothinglookup "133.3.0.1" rtNothinglookup "133.4.0.0" rtJust 133.4.0.0/16lookup "133.4.0.1" rtJust 133.4.0.0/16lookup "133.5.16.0" rtJust 133.5.16.0/24lookup "133.5.16.1" rtJust 133.5.16.0/24
The lookupKeyValue function looks up IPRTable with a key of AddrRange. If a routing information in IPRTable matches the key, both key and value are returned.
:set -XOverloadedStringslet rt = fromList ([("192.168.0.0/24", 1), ("10.10.0.0/16", 2)] :: [(AddrRange IPv4, Int)])lookupKeyValue "127.0.0.1" rtNothinglookupKeyValue "192.168.0.1" rtJust (192.168.0.0/24,1)lookupKeyValue "10.10.0.1" rtJust (10.10.0.0/16,2)
lookupAll is a version of lookup that returns all entries matching the given key, not just the longest match.
:set -XOverloadedStringslet rt = fromList ([("192.168.0.0/24", 1), ("10.10.0.0/16", 2), ("10.0.0.0/8", 3)] :: [(AddrRange IPv4, Int)])lookupAll "127.0.0.1" rt[]lookupAll "192.168.0.1" rt[(192.168.0.0/24,1)]lookupAll "10.10.0.1" rt[(10.10.0.0/16,2),(10.0.0.0/8,3)]
The findMatch function looks up IPRTable with a key of AddrRange. If the key matches routing informations in IPRTable, they are returned.
let v4 = ["133.4.0.0/16","133.5.0.0/16","133.5.16.0/24","133.5.23.0/24"] :: [AddrRange IPv4]let rt = fromList $ zip v4 $ repeat ()findMatch "133.4.0.0/15" rt :: [(AddrRange IPv4,())][(133.4.0.0/16,()),(133.5.0.0/16,()),(133.5.16.0/24,()),(133.5.23.0/24,())]
The fromList function creates a new IP routing table from
a list of a pair of IPrange and value.
O(n). Fold the keys and values in the IPRTable using the given left-associative binary operator. This function is equivalent to Data.Map.foldlWithKey with necessary to IPRTable changes. Since: 1.7.5
O(n). Fold the keys and values in the IPRTable using the given right-associative binary operator. This function is equivalent to Data.Map.foldrWithKey with necessary to IPRTable changes. Since: 1.7.5