Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding read_exactly method and default gw routing. #37

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e41e797
fixing code to detach net device
Dec 16, 2012
ac9db4d
A nimor fix to make ocaml-openflow compile
Dec 17, 2012
e07c717
Merge branch 'master' of git://github.com/mirage/mirage-net
Dec 17, 2012
2193241
Adding ipv4_addr_to_uint32 method in socket backend
Dec 23, 2012
60d1680
Adding checksumming on socket backend
Dec 28, 2012
e43bc5f
merging
Dec 28, 2012
6a0bce0
fixing manager
Dec 28, 2012
39a4d31
add checksum module in socket net-backend
Dec 29, 2012
df87d60
Adding a bit of debugging info to check an error I find
Dec 30, 2012
47b8c7f
fixing socket manager API to match new direct manager API
Dec 30, 2012
0ff3500
match socket API with direct API
Jan 4, 2013
40d2b3a
handle device down exception from the netif module
Jan 7, 2013
29f5025
Merge branch 'master' of git://github.com/mirage/mirage-net
Jan 11, 2013
d4781f1
Merge branch 'master' of https://github.com/mirage/mirage-net
Jan 14, 2013
e249de3
adding the read_exactly method
Jan 17, 2013
69d3add
merging
Jan 17, 2013
5f77a9a
Merge branch 'master' of git://github.com/mirage/mirage-net
Jan 17, 2013
8f7c69c
Adding read exactly method on system
Jan 24, 2013
69f6df8
Merge branch 'master' of github.com:crotsos/mirage-net
Jan 24, 2013
e48f91f
Add routing capability on the Manager
Jan 29, 2013
0e419e8
add Channel.read_exactly on socket backend
Jan 29, 2013
17c12aa
adding ipv4_addr_of_uint32 on socket backend
Jan 29, 2013
ef1004d
Merge github.com:mirage/mirage-net
Jan 29, 2013
5d526fe
fixing the manager intf on socket backend
Jan 29, 2013
19308dd
Merge branch 'master' of github.com:crotsos/mirage-net
crotsos Mar 1, 2013
a8ed867
adding a read_exactly method in Channel module
Sep 20, 2013
d0f3090
merging with main mirage-net repo
Sep 20, 2013
6e80e53
suppressing white space differences with mirage/mirage-net to reduce …
Sep 20, 2013
b6ce0e3
reducing difference for pull request
Sep 27, 2013
124d139
multiple identical definitions of the read exactly method in socket b…
Sep 27, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion direct/lib/channel.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -84,8 +84,40 @@ module Make(Flow:FLOW) :
t.ibuf <- None; t.ibuf <- None;
return buf return buf
end end

(* Read exactly len characters from the input channel
and at most a full view. If not specified, read all *)
let read_exactly t len =
let rec read_exactly_inner t len =
lwt buf = get_ibuf t in
let avail = Cstruct.len buf in
match (len - avail) with
| l when l < 0 ->
let hd,tl = Cstruct.split buf len in
t.ibuf <- Some tl;
return [hd]
| l when l = 0 ->
t.ibuf <- None;
return [buf]
| l ->
t.ibuf <- None;
lwt rest = read_exactly_inner t l in
return (buf::rest)
in
lwt buf = read_exactly_inner t len in
match buf with
| [buf] -> return buf
| _ ->
let ret = OS.Io_page.to_cstruct (OS.Io_page.get 1) in
let a =
List.fold_right (
fun a off ->
let l = Cstruct.len a in
let _ = Cstruct.blit a 0 ret (off-l) l in
off - l) buf len in
return (Cstruct.sub ret 0 len)


(* Read up to len characters from the input channel as a (* Read up to len characters from the input channel as a
stream (and read all available if no length specified *) stream (and read all available if no length specified *)
let read_stream ?len t = let read_stream ?len t =
Lwt_stream.from (fun () -> Lwt_stream.from (fun () ->
Expand Down Expand Up @@ -241,6 +273,11 @@ let read_line = function
| TCPv4 t -> TCPv4.read_line t | TCPv4 t -> TCPv4.read_line t
| Shmem t -> Shmem.read_line t | Shmem t -> Shmem.read_line t


let read_exactly t len =
match t with
| TCPv4 t -> TCPv4.read_exactly t len
| Shmem t -> Shmem.read_exactly t len

let write_char = function let write_char = function
| TCPv4 t -> TCPv4.write_char t | TCPv4 t -> TCPv4.write_char t
| Shmem t -> Shmem.write_char t | Shmem t -> Shmem.write_char t
Expand Down
5 changes: 5 additions & 0 deletions direct/lib/channel.mli
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ val read_until: t -> char -> (bool * Cstruct.t) Lwt.t
belongs to the set of characters in the channel, or reads until belongs to the set of characters in the channel, or reads until
EOF otherwise. *) EOF otherwise. *)


val read_exactly: t -> int -> Cstruct.t Lwt.t
(** [read_exactly len c] reads exactly [len] characters from [c] and blocks until
* [len] characters are available. *)


val read_line: t -> Cstruct.t list Lwt.t val read_line: t -> Cstruct.t list Lwt.t
(** [read_line c] returns a list of views corresponding to one line (** [read_line c] returns a list of views corresponding to one line
(e.g. that finishes by LF or CRLF). *) (e.g. that finishes by LF or CRLF). *)
Expand Down
1 change: 1 addition & 0 deletions direct/lib/ipv4.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ let set_netmask t netmask =
let set_gateways t gateways = let set_gateways t gateways =
t.gateways <- gateways; t.gateways <- gateways;
return () return ()
let get_gateways t = t.gateways


let mac t = Ethif.mac t.ethif let mac t = Ethif.mac t.ethif


Expand Down
1 change: 1 addition & 0 deletions direct/lib/ipv4.mli
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ val get_ip: t -> Ipaddr.V4.t
val mac: t -> Macaddr.t val mac: t -> Macaddr.t
val set_netmask: t -> Ipaddr.V4.t -> unit Lwt.t val set_netmask: t -> Ipaddr.V4.t -> unit Lwt.t
val set_gateways: t -> Ipaddr.V4.t list -> unit Lwt.t val set_gateways: t -> Ipaddr.V4.t list -> unit Lwt.t
val get_gateways: t -> Ipaddr.V4.t list
val create : Ethif.t -> t * unit Lwt.t val create : Ethif.t -> t * unit Lwt.t


val attach : t -> val attach : t ->
Expand Down
7 changes: 5 additions & 2 deletions direct/lib/manager.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ let i_of_dst_ip t addr =
ret := Some(i); ret := Some(i);
netmask := Ipaddr.V4.to_int32 netmask := Ipaddr.V4.to_int32
(Ipv4.get_netmask i.ipv4) (Ipv4.get_netmask i.ipv4)
) ) else (
(* In case no match is found use the default gw of my routing table*)
if (List.length (Ipv4.get_gateways i.ipv4) > 0) then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a style thing, but it's usual to write

match Ipv4.get_gateways i.ipv4 with
| [] -> ()
| x -> ret := Some x

In this case the rest is imperative so I dont think it matters too much

ret := Some(i)
)
) t.listeners in ) t.listeners in
match !ret with match !ret with
| None -> failwith("No_Path_dst") | None -> failwith("No_Path_dst")
Expand Down Expand Up @@ -176,4 +180,3 @@ let get_intf_ipv4addr t id =
let set_promiscuous t id f = let set_promiscuous t id f =
let intf = Hashtbl.find t.listeners id in let intf = Hashtbl.find t.listeners id in
Ethif.set_promiscuous intf.ethif (f id) Ethif.set_promiscuous intf.ethif (f id)

1 change: 1 addition & 0 deletions direct/lib/nettypes.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ module type CHANNEL = sig


val read_char: t -> char Lwt.t val read_char: t -> char Lwt.t
val read_until: t -> char -> (bool * Cstruct.t) Lwt.t val read_until: t -> char -> (bool * Cstruct.t) Lwt.t
val read_exactly: t -> int -> Cstruct.t Lwt.t
val read_some: ?len:int -> t -> Cstruct.t Lwt.t val read_some: ?len:int -> t -> Cstruct.t Lwt.t
val read_stream: ?len:int -> t -> Cstruct.t Lwt_stream.t val read_stream: ?len:int -> t -> Cstruct.t Lwt_stream.t
val read_line: t -> Cstruct.t list Lwt.t val read_line: t -> Cstruct.t list Lwt.t
Expand Down
1 change: 1 addition & 0 deletions direct/lib/nettypes.mli
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ module type CHANNEL = sig


val read_char : t -> char Lwt.t val read_char : t -> char Lwt.t
val read_until : t -> char -> (bool * Cstruct.t) Lwt.t val read_until : t -> char -> (bool * Cstruct.t) Lwt.t
val read_exactly : t -> int -> Cstruct.t Lwt.t
val read_some : ?len:int -> t -> Cstruct.t Lwt.t val read_some : ?len:int -> t -> Cstruct.t Lwt.t
val read_stream : ?len: int -> t -> Cstruct.t Lwt_stream.t val read_stream : ?len: int -> t -> Cstruct.t Lwt_stream.t
val read_line : t -> Cstruct.t list Lwt.t val read_line : t -> Cstruct.t list Lwt.t
Expand Down
35 changes: 35 additions & 0 deletions socket/lib/channel.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -70,6 +70,38 @@ module Make(Flow:FLOW) :
t.ibuf <- Some (Cstruct.shift buf 1); t.ibuf <- Some (Cstruct.shift buf 1);
return c return c


(* Read exactly len characters from the input channel
and at most a full view. If not specified, read all *)
let read_exactly t len =
let rec read_exactly_inner t len =
lwt buf = get_ibuf t in
let avail = Cstruct.len buf in
match (len - avail) with
| l when l < 0 ->
let hd,tl = Cstruct.split buf len in
t.ibuf <- Some tl;
return [hd]
| l when l = 0 ->
t.ibuf <- None;
return [buf]
| l ->
t.ibuf <- None;
lwt rest = read_exactly_inner t l in
return (buf::rest)
in
lwt buf = read_exactly_inner t len in
match buf with
| [buf] -> return buf
| _ ->
let ret = OS.Io_page.to_cstruct (OS.Io_page.get 1) in
let a =
List.fold_right (
fun a off ->
let l = Cstruct.len a in
let _ = Cstruct.blit a 0 ret (off-l) l in
off - l) buf len in
return (Cstruct.sub ret 0 len)

(* Read up to len characters from the input channel (* Read up to len characters from the input channel
and at most a full view. If not specified, read all *) and at most a full view. If not specified, read all *)
let read_some ?len t = let read_some ?len t =
Expand Down Expand Up @@ -227,6 +259,9 @@ let read_until = function


let read_some ?len = function let read_some ?len = function
| TCPv4 t -> TCPv4.read_some ?len t | TCPv4 t -> TCPv4.read_some ?len t
let read_exactly t len =
match t with
| TCPv4 t -> TCPv4.read_exactly t len


let read_stream ?len = function let read_stream ?len = function
| TCPv4 t -> TCPv4.read_stream ?len t | TCPv4 t -> TCPv4.read_stream ?len t
Expand Down
1 change: 1 addition & 0 deletions socket/lib/channel.mli
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type t


val read_char: t -> char Lwt.t val read_char: t -> char Lwt.t
val read_some: ?len:int -> t -> Cstruct.t Lwt.t val read_some: ?len:int -> t -> Cstruct.t Lwt.t
val read_exactly: t -> int -> Cstruct.t Lwt.t
val read_until: t -> char -> (bool * Cstruct.t) Lwt.t val read_until: t -> char -> (bool * Cstruct.t) Lwt.t
val read_stream: ?len:int -> t -> Cstruct.t Lwt_stream.t val read_stream: ?len:int -> t -> Cstruct.t Lwt_stream.t
val read_line: t -> Cstruct.t list Lwt.t val read_line: t -> Cstruct.t list Lwt.t
Expand Down
1 change: 1 addition & 0 deletions socket/lib/net.mlpack
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Manager
Flow Flow
Datagram Datagram
Channel Channel
Checksum
1 change: 1 addition & 0 deletions socket/lib/nettypes.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ module type CHANNEL = sig


val read_char: t -> char Lwt.t val read_char: t -> char Lwt.t
val read_until: t -> char -> (bool * Cstruct.t) Lwt.t val read_until: t -> char -> (bool * Cstruct.t) Lwt.t
val read_exactly: t -> int -> Cstruct.t Lwt.t
val read_some: ?len:int -> t -> Cstruct.t Lwt.t val read_some: ?len:int -> t -> Cstruct.t Lwt.t
val read_stream: ?len:int -> t -> Cstruct.t Lwt_stream.t val read_stream: ?len:int -> t -> Cstruct.t Lwt_stream.t
val read_line: t -> Cstruct.t list Lwt.t val read_line: t -> Cstruct.t list Lwt.t
Expand Down
1 change: 1 addition & 0 deletions socket/lib/nettypes.mli
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ module type CHANNEL = sig


val read_char : t -> char Lwt.t val read_char : t -> char Lwt.t
val read_until : t -> char -> (bool * Cstruct.t) Lwt.t val read_until : t -> char -> (bool * Cstruct.t) Lwt.t
val read_exactly: t -> int -> Cstruct.t Lwt.t
val read_some : ?len:int -> t -> Cstruct.t Lwt.t val read_some : ?len:int -> t -> Cstruct.t Lwt.t
val read_stream : ?len: int -> t -> Cstruct.t Lwt_stream.t val read_stream : ?len: int -> t -> Cstruct.t Lwt_stream.t
val read_line : t -> Cstruct.t list Lwt.t val read_line : t -> Cstruct.t list Lwt.t
Expand Down