[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-API] [PATCH 4 of 4] Create netdev interface definition



Restrict Netdev.{Internal,Bridge,Vswitch} modules from external visibility.
Other functions are exported based on being needed to compile than sanity of 
API.

Reworked accessors for Netdev.Link.speed in order to better hide the underlying 
type.

Tried to ocamldoc everything.

diff -r 8f62d72f7fad -r 91c85ce1be53 ocaml/netdev/netdev.ml
--- a/ocaml/netdev/netdev.ml    Tue Dec 15 12:30:48 2009 +0000
+++ b/ocaml/netdev/netdev.ml    Tue Dec 15 12:30:48 2009 +0000
@@ -279,8 +279,8 @@
        | "half"    -> Duplex_half
        | _         -> Duplex_unknown
 
-let string_of_speed = string_of_int
-let speed_of_string x = try int_of_string x with _ -> 0
+let int_of_speed x = x
+let speed_of_int x = x
 let speed_unknown = 0
 
 external _up : Unix.file_descr -> string -> unit = "stub_link_up"
@@ -342,7 +342,6 @@
 
 end
 
-(** List all the interfaces on the system *)
 let list () =
        Array.to_list (Sys.readdir "/sys/class/net")
 
@@ -355,7 +354,6 @@
        Internal.write_one_line (getpath name "mtu")
                                (string_of_int mtu)
 
-(** Returns the list of device names (eg physical + VLAN) which a particular 
MAC address *)
 let get_by_address address = 
   List.filter
     (fun device ->
@@ -385,7 +383,6 @@
        read_id_from (getpath name "device/vendor"),
        read_id_from (getpath name "device/device")
 
-(** Indicates whether the given interface is a physical interface *)
 let is_physical name = try Unix.access (getpath name "device") [ Unix.F_OK ]; 
true with _ -> false
 
 (* Dispatch network backend operations. *)
diff -r 8f62d72f7fad -r 91c85ce1be53 ocaml/netdev/netdev.mli
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/ocaml/netdev/netdev.mli   Tue Dec 15 12:30:48 2009 +0000
@@ -0,0 +1,138 @@
+(*
+ * Copyright (C) 2009 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+(** Interface to the domain 0 network stack. *)
+
+(** Enumerates possible network backend types. *)
+type kind = 
+    Bridge  (** Linux Bridge based networking *)
+  | Vswitch (** Vswitch based networking *)
+
+(** Possible operations on each network backend type. *)
+type network_ops = {
+  kind : kind;                              (** The type of network backend. *)
+  add : string -> unit;                     (** Add a bridge. *)
+  del : string -> unit;                     (** Remove a bridge. *)
+  list : unit -> string list;               (** List all bridges. *)
+  exists : string -> bool;                  (** Query the existance of a 
bridge. *)
+  intf_add : string -> string -> unit;      (** Add a network device as a port 
on a bridge. *)
+  intf_del : string -> string -> unit;      (** Remove a network device from a 
bridge. *)
+  intf_list : string -> string list;        (** List all network devices 
currently attached as a port on a bridge. *)
+  get_bridge : string -> string;            (** Return the bridge to which a 
network device is currently attached. *)
+  is_on_bridge : string -> bool;            (** Query whether a network device 
is currently attached to a bridge. *)
+  set_forward_delay : string -> int -> unit;(** Set the forwarding delay for a 
device on a bridge. *)
+}
+
+(** Raised when an invalid network backend is detected.  *)
+exception Unknown_network_backend of string
+
+(** Raised when an operation in network_ops is not valid for a particular kind 
*)
+exception Invalid_network_backend_operation of string * kind
+
+(** Returns string name of a network backend type. *)
+val string_of_kind : kind -> string
+
+(** Converts a string to a valid network backend type, or raises 
Unknown_network_backend. *)
+val kind_of_string : string -> kind
+
+(** Module dealing with network device link characteristics *)
+module Link :
+  sig
+    (** Link speed in megabits. *)
+    type speed
+
+    (** Convert speed to a string. *)
+    val int_of_speed : speed -> int
+
+    (** Create speed from a string. *)
+    val speed_of_int : int -> speed
+
+    (** Magic speed value representing Unknown. *)
+    val speed_unknown : speed
+
+    (** Device duplex. *)
+    type duplex = 
+      Duplex_unknown (** Device duplex is unknown. *)
+    | Duplex_half    (** Device is running half-duplex. *)
+    | Duplex_full    (** Device is running full-duplex. *)
+
+    (** Convert duplex setting to string. *)
+    val string_of_duplex : duplex -> string
+
+    (** Create duplex from a string *)
+    val duplex_of_string : string -> duplex
+
+    (** Bring up a network device. *)
+    val up : string -> unit
+
+    (** Determine if a network device is up. *)
+    val is_up : string -> bool
+
+    (** Bring down a network device. *)
+    val down : string -> unit
+
+    (** Configure a device to allow or disallow multicast. *)
+    val multicast : string -> bool -> unit
+
+    (** Configure a device to respond to or ignore ARP requests. *)
+    val arp : string -> bool -> unit
+
+    (** Change the name of a network device. *)
+    val change_name : string -> string -> unit
+
+    (** Set MAC address of a device. *)
+    val set_addr : string -> string -> unit
+
+    (** Get current speed a duplex settings for a device. *)
+    val get_status : string -> speed * duplex
+  end
+
+(** Module dealing with IP addresses on network devices. *)
+module Addr :
+  sig
+    (** Flush all the addresses configured on a device. *)
+    val flush : string -> unit
+
+    (** Get all IPV4 addresses associated with a device. *)
+    val get : string -> (Unix.inet_addr * Unix.inet_addr) list
+  end
+
+(** List all the interfaces on the system. *)
+val list : unit -> string list
+
+(** Return MAC address for a network device. *)
+val get_address : string -> string
+
+(** Get device MTU. *)
+val get_mtu : string -> string
+
+(** Set device MTU. *)
+val set_mtu : string -> int -> unit
+
+(** Returns the list of device names (eg physical + VLAN) which a particular 
MAC address. *)
+val get_by_address : string -> string list
+
+(** Returns the PCI bus path of a device. *)
+val get_pcibuspath : string -> string
+
+(** Returns the carrier status for a device. *)
+val get_carrier : string -> bool
+
+(** Returns PCI vendor and device ID for network device. *)
+val get_ids : string -> string * string
+
+(** Indicates whether the given interface is a physical interface *)
+val is_physical : string -> bool
+
+(** Dispatch operation to correct backend device *)
+val network : network_ops
diff -r 8f62d72f7fad -r 91c85ce1be53 ocaml/xapi/monitor_master.ml
--- a/ocaml/xapi/monitor_master.ml      Tue Dec 15 12:30:48 2009 +0000
+++ b/ocaml/xapi/monitor_master.ml      Tue Dec 15 12:30:48 2009 +0000
@@ -212,7 +212,7 @@
                        
                        let metrics = Db.PIF.get_metrics ~__context 
~self:pifdev in
                        let pmr = Db.PIF_metrics.get_record ~__context 
~self:metrics in
-                       let speed_db = Int64.of_int pif_stats.pif_speed in
+                       let speed_db = Int64.of_int (Netdev.Link.int_of_speed 
pif_stats.pif_speed) in
                        let duplex_db = match pif_stats.pif_duplex with
                          | Netdev.Link.Duplex_full    -> true
                          | Netdev.Link.Duplex_half    -> false
diff -r 8f62d72f7fad -r 91c85ce1be53 ocaml/xapi/monitor_transfer.ml
--- a/ocaml/xapi/monitor_transfer.ml    Tue Dec 15 12:30:48 2009 +0000
+++ b/ocaml/xapi/monitor_transfer.ml    Tue Dec 15 12:30:48 2009 +0000
@@ -137,7 +137,7 @@
                        XMLRPC.To.string (string_of_float pif.pif_tx);
                        XMLRPC.To.string (string_of_float pif.pif_rx);
                        XMLRPC.To.string (string_of_bool pif.pif_carrier);
-                       XMLRPC.To.string (Netdev.Link.string_of_speed 
pif.pif_speed);
+                       XMLRPC.To.string (string_of_int 
(Netdev.Link.int_of_speed pif.pif_speed));
                        XMLRPC.To.string (Netdev.Link.string_of_duplex 
pif.pif_duplex);
                        XMLRPC.To.string pif.pif_pci_bus_path;
                        XMLRPC.To.string pif.pif_vendor_id;
@@ -154,7 +154,7 @@
                 pif_raw_tx=0L;
                 pif_raw_rx=0L; (* Ignore these, for RRD only *)
                 pif_carrier=bool_of_string (XMLRPC.From.string carrier);
-                pif_speed=Netdev.Link.speed_of_string (XMLRPC.From.string 
speed);
+                pif_speed=Netdev.Link.speed_of_int (int_of_string 
(XMLRPC.From.string speed));
                 pif_duplex=Netdev.Link.duplex_of_string (XMLRPC.From.string 
duplex);
                 pif_pci_bus_path=XMLRPC.From.string pcibuspath;
                 pif_vendor_id=XMLRPC.From.string vendor;

_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.