3 # vsys.py: Python functions to wrap PlanetLab vsys API'
4 # Alina Quereilhac - 02/09/2012
6 # Copyright (c) 202 INRIA
9 ''' This extension provides easy to use Python functions to
10 interact with the PlanetLab vsys API.
12 The vsys API is presented in the following publication:
14 Vsys: A programmable sudo
15 S Bhatia, G Di Stasi, T Haddow, A Bavier, S Muir, L Peterson
23 def vif_up(if_name, ip, prefix, snat = False):
24 """ Configures a virtual interface with the values given by the user and
28 if_name: the name of the virtual interface
29 ip: the IP address to be assigned to the interface
30 prefix: the network prefix associated to the IP address
31 snat: whether to enable SNAT on the virtual interface.
35 On error, a RuntimeError is raised."""
38 (code, msg) = _vsys.vif_up(if_name, ip, str(prefix), snat)
41 raise RuntimeError(msg)
44 def vif_down(if_name):
45 """ Sets the state of a virtual interface DOWN
48 if_name: the name of the virtual interface
52 On error, a RuntimeError is raised."""
55 (code, msg) = _vsys.vif_down(if_name)
58 raise RuntimeError(msg)
60 def fd_tuntap(if_type, no_pi = False):
61 """Creates a TAP or TUN device in PlanetLab, and returns the device name and
62 the associated file descriptor.
65 if_type: the type of virtual device. Either IFF_TAP (0x0001) or
67 no_pi: set flag IFF_NO_PI
70 On success, fd_tuntap returns a tuple containing the file descriptor
71 associated to the device and the device name assigned by the PlanetLab
73 On error, a RuntimeError is raised."""
76 (fd, if_name) = _vsys.fd_tuntap(if_type, no_pi)
79 raise RuntimeError(if_name)
83 def vroute(action, network, prefix, host, device):
84 """ Adds or removes routes on PlanetLab virtual interfaces (TAP/TUN).
86 Note that all networks and gateways must belong to the virtual
87 network segment associated to the vsys_vnet tag for the slice.
90 action: either 'add' or 'del'
91 network: destintation network
92 prefix: destination network prefix
93 host: IP of gateway virtual interface
94 device: name of the gateway virtual interface
97 On success, vroute returns 0.
98 On error, a RuntimeError is raised."""
101 (code, msg) = _vsys.vroute(action, network, str(prefix), host, device)
104 raise RuntimeError(msg)