Module Sim.Net

module Net: sig .. end
A network is a set of equipments, and some optionaly named "plugs" where to attach another network to form a new one. We keep track of the equipement because we want to be able to delete a whole network at once, to iter on all hosts of a network, and so on. The underlying connections are not materialized beyond the emit/recv function pointers, so contrary to one would expect a net is not a graph but a mere list of equipment (and available plugs). Connecting two nets make the used plugs disapear, but other than that the two nets stay the same. To group two nets (either connected or not) use the union function which will return the union of the two nets.

module Plug: sig .. end
A plug is a named entry/exit point to a networks.
type equipment = 
| Host of Host.host_trx
| Hub of Hub.Repeater.t
| Switch of Hub.Switch.t
| Trx of Tools.trx
type t = {
   equip : equipment list;
   mutable plugs : Plug.t list;
}
A net is a mere list of equipment and another one for available plugs. Plugs get consumed as they are used.
val make_empty : unit -> t
val union : t list -> t
val find_named_plug : t ->
string option ->
(Plug.t, [> `Unknown_plug of string option ]) Batteries.Result.t
remove the matching plug and return it
val connect : ?plug1:string ->
t ->
?plug2:string ->
t -> (unit, [> `Unknown_plug of string option ]) Batteries.Result.t
connect t1 ~name1:"plug1" t2 ~name2:"plug2" will change the plugs emiting and receiving functions such that t1 and t2 start exchanging messages at this point. Will return BatResult.Bad (`Unknown_plug of string) if name1 or name2 can not be found. If a name for the plug is not given then anyone will do. Notice that the used plugs are consumed (ie. removed from the passed nets).
val make_sink : string -> t * Thread.t
Return a net representing the external network via the given interface, and the thread that sniffs packets.
val make_internet : unit -> t
Returns a net with an unlimited supply of plugs that performs as a router.
val make_simple_lan : ?name:string ->
?nameserver:Ip.Addr.t -> ?public_ip:Ip.Addr.t -> int -> t
Returns a lan consisting of n hosts connected to a switch connected to a router/dhcp server/nater with an "exit" plug.