From 0c45dfdcf726362a3b4c8856246c5929cdde4560 Mon Sep 17 00:00:00 2001 From: Thien Duc Nguyen Date: Wed, 2 Jul 2014 13:25:20 -0700 Subject: [PATCH] complete portDesc module --- lib/OpenFlow0x04.ml | 30 ++++++++++++++++++---------- lib/OpenFlow0x04_Core.ml | 10 +++++----- lib/OpenFlow0x04_Core.mli | 7 ++++--- quickcheck/Arbitrary_OpenFlow0x04.ml | 10 +++++++++- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/lib/OpenFlow0x04.ml b/lib/OpenFlow0x04.ml index 6310a03..9ee904f 100644 --- a/lib/OpenFlow0x04.ml +++ b/lib/OpenFlow0x04.ml @@ -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 diff --git a/lib/OpenFlow0x04_Core.ml b/lib/OpenFlow0x04_Core.ml index 82aace9..bae626e 100644 --- a/lib/OpenFlow0x04_Core.ml +++ b/lib/OpenFlow0x04_Core.ml @@ -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 diff --git a/lib/OpenFlow0x04_Core.mli b/lib/OpenFlow0x04_Core.mli index ce3935b..baa23da 100644 --- a/lib/OpenFlow0x04_Core.mli +++ b/lib/OpenFlow0x04_Core.mli @@ -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 diff --git a/quickcheck/Arbitrary_OpenFlow0x04.ml b/quickcheck/Arbitrary_OpenFlow0x04.ml index a796b89..1dff51e 100644 --- a/quickcheck/Arbitrary_OpenFlow0x04.ml +++ b/quickcheck/Arbitrary_OpenFlow0x04.ml @@ -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