Skip to content

Commit

Permalink
Merge pull request #129 from fugitifduck/portDesc
Browse files Browse the repository at this point in the history
complete PortDesc module
  • Loading branch information
seliopou committed Jul 7, 2014
2 parents cb40c98 + 0c45dfd commit 104e0e1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
30 changes: 19 additions & 11 deletions lib/OpenFlow0x04.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2412,51 +2412,59 @@ module PortDesc = struct
let size = sizeof_ofp_port in
set_ofp_port_port_no buf desc.port_no;
set_ofp_port_pad buf 0l;
(* set_ofp_port_hw_addr NIY *)
set_ofp_port_hw_addr (bytes_of_mac desc.hw_addr) 0 buf;
set_ofp_port_pad2 buf 0;
set_ofp_port_pad3 buf 0;
(* set_ofp_port_name NIY *)
set_ofp_port_name desc.name 0 buf;
set_ofp_port_config buf (PortConfig.marshal desc.config);
set_ofp_port_state buf (PortState.marshal desc.state);
set_ofp_port_curr buf (PortFeatures.marshal desc.curr);
set_ofp_port_advertised buf (PortFeatures.marshal desc.advertised);
set_ofp_port_supported buf (PortFeatures.marshal desc.supported);
set_ofp_port_peer buf (PortFeatures.marshal desc.peer);
(* set_ofp_port_curr_speed NIY *)
(* set_ofp_port_max_speed NIY *)
set_ofp_port_curr_speed buf desc.curr_speed;
set_ofp_port_max_speed buf desc.max_speed;
size

let parse (bits : Cstruct.t) : portDesc =
let port_no = get_ofp_port_port_no bits in
let hw_addr = mac_of_bytes (copy_ofp_port_hw_addr bits) in
let name = copy_ofp_port_name bits in
let state = PortState.parse (get_ofp_port_state bits) in
let config = PortConfig.parse (get_ofp_port_config bits) in
let curr = PortFeatures.parse (get_ofp_port_curr bits) in
let advertised = PortFeatures.parse (get_ofp_port_advertised bits) in
let supported = PortFeatures.parse (get_ofp_port_supported bits) in
let peer = PortFeatures.parse (get_ofp_port_peer bits) in
let curr_speed = get_ofp_port_curr_speed bits in
let max_speed = get_ofp_port_max_speed bits in
{ port_no;
(* hw_addr; *)
(* name; *)
hw_addr;
name;
config;
state;
curr;
advertised;
supported;
peer
(* curr_speed; *)
(* max_speed *) }
peer;
curr_speed;
max_speed }

let to_string (port : portDesc) =
Format.sprintf
"port_no:%lu,config:%s,state:%s,curr:%s,advertised:%s\
supported:%s,peer:%s"
"port_no:%lu,hw_addr:%s,name:%s,config:%s,state:%s,curr:%s,advertised:%s\
supported:%s,peer:%s,curr_speed:%lu,max_speed:%lu"
port.port_no
(string_of_mac port.hw_addr)
port.name
(PortConfig.to_string port.config)
(PortState.to_string port.state)
(PortFeatures.to_string port.curr)
(PortFeatures.to_string port.advertised)
(PortFeatures.to_string port.supported)
(PortFeatures.to_string port.peer)
port.curr_speed
port.max_speed

end

Expand Down
10 changes: 5 additions & 5 deletions lib/OpenFlow0x04_Core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,16 @@ type portFeatures = { rate_10mb_hd : bool; rate_10mb_fd : bool;
autoneg : bool; pause : bool; pause_asym : bool }

type portDesc = { port_no : portId;
(* hw_addr : int48; *)
(* name; *)
hw_addr : int48;
name : string;
config : portConfig;
state : portState;
curr : portFeatures;
advertised : portFeatures;
supported : portFeatures;
peer : portFeatures
(* curr_speed; *)
(* max_speed *) }
peer : portFeatures;
curr_speed : int32;
max_speed : int32}

type portReason =
| PortAdd
Expand Down
7 changes: 4 additions & 3 deletions lib/OpenFlow0x04_Core.mli
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@ type portFeatures = { rate_10mb_hd : bool; rate_10mb_fd : bool;
autoneg : bool; pause : bool; pause_asym : bool }


type portDesc = { port_no : portId; config : portConfig; state : portState;
curr : portFeatures; advertised : portFeatures; supported :
portFeatures; peer : portFeatures }
type portDesc = { port_no : portId; hw_addr : int48; name : string; config :
portConfig; state : portState; curr : portFeatures;
advertised : portFeatures; supported : portFeatures; peer :
portFeatures; curr_speed : int32; max_speed : int32}

type portReason =
| PortAdd
Expand Down
10 changes: 9 additions & 1 deletion quickcheck/Arbitrary_OpenFlow0x04.ml
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,28 @@ module PortDesc = struct
let open Gen in
let open PortDesc in
arbitrary_uint32 >>= fun port_no ->
arbitrary_uint48 >>= fun hw_addr ->
arbitrary_stringN 16 >>= fun name ->
PortConfig.arbitrary >>= fun config ->
PortState.arbitrary >>= fun state ->
PortFeatures.arbitrary >>= fun curr ->
PortFeatures.arbitrary >>= fun advertised ->
PortFeatures.arbitrary >>= fun supported ->
PortFeatures.arbitrary >>= fun peer ->
arbitrary_uint32 >>= fun curr_speed ->
arbitrary_uint32 >>= fun max_speed ->
ret_gen {
port_no;
hw_addr;
name;
config;
state;
curr;
advertised;
supported;
peer
peer;
curr_speed;
max_speed
}

let to_string = PortDesc.to_string
Expand Down

0 comments on commit 104e0e1

Please sign in to comment.