Virt (virtual machine)

group virt

Functions for manipulating and configuring virt objects.

Virt is a representation of a tenant in the virtual network. By default, it does not need any attributes. However, you can configure its MAC address on the virtual network (required for some network types), and set inbound and outbound QoS rates.

Virt is created as part of a network, but to participate in the network, it must first be connected, through a phys and a network interface on that phys. It is possible to disconnect a virt and reconnect it on a different phys, e.g., when the VM is migrated to a different physical host. The migration is transparent to the virtual network, but obviously, the virt is unreachable while disconnected.

Defines

lsdn_mk_virt_name(ctx)

Generate unique name for a virt.

See
lsdn_mk_name
Parameters
  • ctx: LSDN context.

Functions

struct lsdn_virt* lsdn_virt_new(struct lsdn_net * net)

Create a new virt.

Creates a virt as part of net.

Return
newly allocated lsdn_virt structure.

void lsdn_virt_free(struct lsdn_virt * vsirt)

Free a virt.

struct lsdn_net* lsdn_virt_get_net(struct lsdn_virt * virt)

Get the virt’s network.

Return
lsdn_net object of the network that this virt is part of.
Parameters
  • virt: Virt object.

lsdn_err_t lsdn_virt_set_name(struct lsdn_virt * virt, const char * name)

Set a name for the virt.

const char* lsdn_virt_get_name(struct lsdn_virt * virt)

Get the virt’s name.

struct lsdn_virt* lsdn_virt_by_name(struct lsdn_net * net, const char * name)

Find a virt by name.

Return
lsdn_virt structure if a network with this name exists.
Return
NULL otherwise.

lsdn_err_t lsdn_virt_connect(struct lsdn_virt * virt, struct lsdn_phys * phys, const char * iface)

Connect a virt to its network.

Associates a virt with a given phys and a network interface, and ensures that this interface will receive the network’s traffic.

See
lsdn-public
Parameters
  • virt: virt to connect.
  • phys: phys on which the virt exists.
  • iface: name of Linux network interface on the given phys, which will receive the virt’s traffic.

void lsdn_virt_disconnect(struct lsdn_virt * virt)

Disconnects a virt from its network.

Disconnected virt will no longer be able to send and receive traffic.

Get recommended MTU for a given virt.

Calculates the appropriate MTU value, taking into account the network’s tunneling method overhead.

The MTU is based on the current state and connection port of the virt (it is not based on the committed state). The phys interface must already exist.

Parameters
  • virt: Virt object.
  • mtu: Pointer into which the MTU is stored.
Return Value
  • LSDNE_OK: Operation was successful.
  • LSDNE_NETLINK: Netlink communication error.
  • LSDNE_NOIF: Virt’s connected interface does not exist.

lsdn_err_t lsdn_virt_set_mac(struct lsdn_virt * object, lsdn_mac_t value)

Set MAC address of a virt .

Parameters
  • object: virt to modify.
  • value: MAC address .

const lsdn_mac_t* lsdn_virt_get_mac(struct lsdn_virt * object)

Get MAC address of a virt .

The pointer is valid until the attribute is changed or object freed.

Return
value of MAC address attribute, or NULL if unset.
Parameters
  • object: virt to query.

void lsdn_virt_clear_mac(struct lsdn_virt * object)

Clear MAC address of a virt .

Parameters
  • object: virt to modify.

lsdn_err_t lsdn_virt_set_rate_in(struct lsdn_virt * object, lsdn_qos_rate_t value)

Set inbound bandwidth limit of a virt .

Parameters
  • object: virt to modify.
  • value: inbound bandwidth limit .

const lsdn_qos_rate_t* lsdn_virt_get_rate_in(struct lsdn_virt * object)

Get inbound bandwidth limit of a virt .

The pointer is valid until the attribute is changed or object freed.

Return
value of inbound bandwidth limit attribute, or NULL if unset.
Parameters
  • object: virt to query.

void lsdn_virt_clear_rate_in(struct lsdn_virt * object)

Clear inbound bandwidth limit of a virt .

Parameters
  • object: virt to modify.

lsdn_err_t lsdn_virt_set_rate_out(struct lsdn_virt * object, lsdn_qos_rate_t value)

Set outbound bandwidth limit of a virt .

Parameters
  • object: virt to modify.
  • value: outbound bandwidth limit .

const lsdn_qos_rate_t* lsdn_virt_get_rate_out(struct lsdn_virt * object)

Get outbound bandwidth limit of a virt .

The pointer is valid until the attribute is changed or object freed.

Return
value of outbound bandwidth limit attribute, or NULL if unset.
Parameters
  • object: virt to query.

void lsdn_virt_clear_rate_out(struct lsdn_virt * object)

Clear outbound bandwidth limit of a virt .

Parameters
  • object: virt to modify.

struct lsdn_qos_rate_t
#include <lsdn.h>

Bandwidth limit for virt’s interface (for one direction).

See
lsdn_virt_set_rate_out
See
lsdn_virt_set_rate_in

Public Members

float avg_rate

Bandwidth restriction in bytes per second.

uint32_t burst_size

A size of data burst that is allowed to exceed the avg_rate.

It is not possible to leave this field zero, because no packets would go through. Since each packet is considered as a short burst, the burst rate must be at least as big as your MTU.

float burst_rate

An absolute restriction on the bandwidth in bytes per second, even during bursting.

If zero is given, the peak rate is unrestricted.

struct lsdn_virt
#include <lsdn.h>

Virt.

A virtual machine (typically it may be any Linux interface).

Virts are tenants in networks. They must be connected through a phys. They can be migrated between physes at runtime.

See Virt (virtual machine).

See Phys (host machine).

See Virtual network.