]> xenbits.xensource.com Git - xcp/xen-api.git/commitdiff
Tunnelling: creation and destruction of tunnels
authorRob Hoes <rob.hoes@citrix.com>
Wed, 14 Jul 2010 15:43:27 +0000 (16:43 +0100)
committerRob Hoes <rob.hoes@citrix.com>
Wed, 14 Jul 2010 15:43:27 +0000 (16:43 +0100)
Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
ocaml/xapi/xapi_tunnel.ml
ocaml/xapi/xapi_vif_helpers.mli

index 29850f453d2d55077bedf7723fb046ea9cf5b9c6..f557bcf8a2dec10201500e30d61b3f5315a9beaf 100644 (file)
 module D = Debug.Debugger(struct let name="xapi" end) 
 open D
 
+let choose_tunnel_device_name ~__context ~host = 
+       let pifs = List.filter (fun self -> Db.PIF.get_host ~__context ~self = host) (Db.PIF.get_all ~__context) in
+       let devices = List.map (fun self -> Db.PIF.get_device ~__context ~self) pifs in
+       let rec choose n = 
+               let name = Printf.sprintf "tunnel%d" n in
+               if List.mem name devices
+               then choose (n + 1)
+               else name in
+       choose 0
+
 let create ~__context ~transport_PIF ~network =
-       debug "CREATE TUNNEL";
-       Ref.make ()
+       let tunnel = Ref.make () in
+       let access_PIF = Ref.make () in
+       let host = Db.PIF.get_host ~__context ~self:transport_PIF in
+       let device = choose_tunnel_device_name ~__context ~host in
+       let device_name = device in
+       let mAC = Xapi_vif_helpers.gen_mac (0, Uuid.to_string (Uuid.make_uuid ())) in
+       Db.PIF.create ~__context ~ref:access_PIF ~uuid:(Uuid.to_string (Uuid.make_uuid ()))
+               ~device ~device_name ~network ~host ~mAC ~mTU:(-1L) ~vLAN:(-1L) ~metrics:Ref.null
+               ~physical:false ~currently_attached:false 
+               ~ip_configuration_mode:`None ~iP:"" ~netmask:"" ~gateway:"" ~dNS:"" ~bond_slave_of:Ref.null 
+               ~vLAN_master_of:Ref.null ~management:false ~other_config:[] ~disallow_unplug:false;
+       Db.Tunnel.create ~__context ~ref:tunnel ~uuid:(Uuid.to_string (Uuid.make_uuid ()))
+               ~access_PIF ~transport_PIF ~status:["active", "false"] ~other_config:[];
+       Xapi_pif.plug ~__context ~self:access_PIF;
+       tunnel
        
 let destroy ~__context ~self =
-       debug "DESTROY TUNNEL";
-       ()
+       let pif = Db.Tunnel.get_access_PIF ~__context ~self in
+       Xapi_pif.unplug ~__context ~self:pif;
+       Db.PIF.destroy ~__context ~self:pif;
+       Db.Tunnel.destroy ~__context ~self
 
index 4ca2ddd572806ab6d63fdbad17b8a7426f2a8fc6..28098d1f481be94c8ef65a50503a658cc648fb51 100644 (file)
@@ -64,4 +64,7 @@ val copy :
   __context:Context.t ->
   vm:[ `VM ] Ref.t ->
   preserve_mac_address:bool -> [ `VIF ] Ref.t -> API.ref_VIF
-  
+
+(** Generate a MAC address *)  
+val gen_mac : int * string -> string
+