Vnx-plugin-dhcp

From VNX
Jump to: navigation, search

DHCP Plugin

Authors:
David Fernández (david at dit.upm.es)
Jorge Somavilla (somavilla at dit.upm.es)
Miguel Ferrer (mferrer at dit.upm.es)
Francisco Jose Martin (fjmarin at dit.upm.es)
Fermín Galán (galan at dit.upm.es)
version 2.0, September 11th, 2011

Introduction

DHCP plugin is an example VNX extension plugin designed to facilitate the configuration of DHCP in virtual machines. It provides a simple XML language to express DHCP configurations which are independent of the DHCP implementation used in the virtual machine. At present, DHCP Plugin is implemented only for ISC DHCP based servers and relays, but can be extended to support other implementations.

To use DHCP plugin in a VNX scenario, you have to add the following tag after <vm_defaults> section of <global> tag:

<extension plugin="dhcp" conf="dhcp_conf.xml" />

The plugin configuration file or PCF contains the DHCP configuration written in a XML language. Using that language the configuration of a router looks like:

...
<vm name="r1" type="dhcp3-isc">
    <server>
      <subnet>
        <network>10.0.1.0/24</network>
        <range>
          <first>10.0.1.10</first>
          <last>10.0.1.20</last>
        </range>
        <router>10.0.1.1</router>
        <dns>10.0.1.2</dns>
        <domain>dominio1.org</domain>
      </subnet>
    </server>
  </vm>
...

DHCP plugin just processes that configuration and translates it into the necessary DHCP configuration file (dhcp.conf) and manages the DHCP daemons. See the complete example below to know more about DHCP plugin capabilities.

DHCP Plugin Example Scenario

DHCP Plugin example is a simple scenario made of two routers (r1 and r2) and two hosts (h1 and h2) designed to show the capabilities of the plugin. r1 runs a DHCP server; r2 runs a DHCP relay that retransmits requests to r1; and h1 and h2 autoconfigure themselves from r1 and r2 using DHCP. This example is included in VNX distribution.

DHCP Plugin example scenario map
(generated using "vnx -f example_dhcp-plugin.xml -v --show-map")

To start the scenario, just type:

cd /usr/share/vnx/plugins/examples
vnx -f example_dhcp-plugin.xml -v -t

Note: in case you get an error related with the existance of '/root/.ssh/id_dsa.pub' file, either create that file executing "ssh-keygen -t dsa" or delete or modify the <ssh_key> tag on the scenario.

Once started, you can check that the hosts have been configured:

root@h1:~# ifconfig eth1
eth1      Link encap:Ethernet  direcciónHW 02:fd:00:04:03:01  
          Direc. inet:10.0.1.10  Difus.:10.0.1.255  Másc:255.255.255.0
          Dirección inet6: fe80::fd:ff:fe04:301/64 Alcance:Enlace
          ....

And the daemons are running over r1 and r2:

root@r1:~# ps uax | grep dhcpd
dhcpd      841  0.0  0.9   4668  2320 ?        Ss   23:28   0:00 /usr/sbin/dhcp -q -pf /var/run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf

r2:~# ps uax | grep dhcrelay
root      2110  0.0  0.7   3160   456 ?        Ss   23:27   0:00 /usr/sbin/dhcrelay3 -q 10.0.0.1

To know the scenario commands made available to the user by the plugin, you can use the "exe-info" mode of VNX:


# vnx -f example_dhcp-plugin.xml --exe-info
----------------------------------------------------------------------------------
Virtual Networks over LinuX (VNX) -- http://www.dit.upm.es/vnx - vnx@dit.upm.es
Version: 2.0b.894 (built on 11/09/2011_12:20)
----------------------------------------------------------------------------------
Using configuration file: /etc/vnx.conf
  TMP dir=/tmp
  VNX dir=/root/.vnx
----------------------------------------------------------------------------------

VNX exe-info mode:

User-defined command sequences for scenario 'example_dhcp_plugin'
----------------------------------------------------------------------------------
 stop-www                 Stop apache2 web server
 start-www                Start apache2 web server

Plugin 'dhcp' command sequences for scenario 'example_dhcp_plugin'
----------------------------------------------------------------------------------
 dhcp-server-stop         Stops DHCP servers
 on_shutdown              Stops all DHCP daemons
 dhcp-relay-start         Starts DHCP relays
 dhcp-stop                Synonym of stop
 dhcp-start               Synonym of start
 dhcp-client-restart      Releases client IP configurations and rexecutes DHCP clients
 dhcp-relay-stop          Stops DHCP relays
 restart                  Restarts all DHCP daemons and clients
 dhcp-client-start        Executes DHCP clients
 dhcp-relay-force-reload  Restarts DHCP relays using 'force-reload'
 stop                     Stops all DHCP daemons and releases client configurations
 dhcp-server-force-reload Restarts DHCP servers using 'force-reload'
 dhcp-relay-restart       Restarts DHCP relays
 dhcp-restart             Synonym of restart
 on_boot                  Creates DHCP config files and starts services
 dhcp-server-start        Starts DHCP servers
 dhcp-client-stop         Releases client IP configurations
 redoconf                 Creates DHCP config files
 dhcp-server-restart      Restarts DHCP servers
 start                    Starts all DHCP daemons and clients
----------------------------------------------------------------------------------
Total time elapsed: 0 seconds

For example, you can edit example_dhcp-plugin-conf.xml to change the range of addresses asigned to subnet 10.0.1.0/24. Just edit the value of <first> tag and change it to 10.0.1.15 and reload the configuration file with:

vnx -f example_dhcp-plugin.xml -v -x redoconf -M r1

After 'redoconf' command you can check the changes have been made to configuration files by accessing r1 and having a look at /etc/dhcp/dhcp.conf file.

After that, you can restart the DHCP server in r1 with:

vnx -f example_dhcp-plugin.xml -v -x dhcp-server-restart -M r1

An renew the address of h1 with:

vnx -f example_dhcp-plugin.xml -vvv -x dhcp-client-restart -M h1

Note: typically plugins provide the same basic 'start|stop|restart' commands with two sequence names: general (i.e. start) and specific (i.e. dhcp-start). Both execute the same actions, but the specific one is used when you want to execute commands only over a specific plugin. Selecting the general one will tipically execute commands over all plugings and some user-defined commands.

Scenario Specification

<?xml version="1.0" encoding="UTF-8"?>

<!--
~~~~~~~~~~~~~~~~~~~~
VNX Sample scenarios
~~~~~~~~~~~~~~~~~~~~

Name:        example_dhcp-plugin
Description: Simple example that shows dhcp plugin capabilities.  

This file is part of the Virtual Networks over LinuX (VNX) Project distribution. 
(www: http://www.dit.upm.es/vnx - e-mail: vnx@dit.upm.es) 

Departamento de Ingenieria de Sistemas Telematicos (DIT)
Universidad Politecnica de Madrid
SPAIN
-->

<vnx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="/usr/share/xml/vnx/vnx-2.00.xsd">
  <global>
    <version>2.0</version>
    <scenario_name>example_dhcp_plugin</scenario_name>
    <ssh_key>~/.ssh/id_dsa.pub</ssh_key>
    <automac offset="4"/>
    <!--vm_mgmt type="none" /-->
    <vm_mgmt type="private" network="10.250.0.0" mask="24" offset="16">
       <host_mapping />
    </vm_mgmt> 
    <vm_defaults>
        <console id="0" display="no"/>
        <console id="1" display="yes"/>
        <exec_mode type="uml">mconsole</exec_mode>
        <exec_mode type="libvirt" subtype="kvm">cdrom</exec_mode>
        <exec_mode type="libvirt" subtype="kvm" os="windows">cdrom</exec_mode>
        <exec_mode type="libvirt" subtype="kvm" os="olive">sdisk</exec_mode>
    </vm_defaults>
    <extension plugin="dhcp" conf="example_dhcp-plugin-conf.xml" />
    
    <help>
        <exec_help seq='start-www'>Start apache2 web server</exec_help>
        <exec_help seq='stop-www'>Stop apache2 web server</exec_help>
    </help>

  </global>
    
  <net name="lan1" mode="virtual_bridge" />
  <net name="lan2" mode="virtual_bridge" />
  <net name="ptp12" mode="virtual_bridge" />
  
  <!-- NODES -->
  <vm name="r1" type="libvirt" subtype="kvm" os="linux" exec_mode="cdrom">
    <filesystem type="cow">/usr/share/vnx/filesystems/rootfs_ubuntu</filesystem>
    <mem>256M</mem>
    <if id="1" net="lan1">
      <ipv4>10.0.1.1/24</ipv4>
      <ipv6>2001:db8:1::1/64</ipv6>
    </if>
    <if id="2" net="ptp12">
      <ipv4>10.0.0.1/30</ipv4>
      <ipv6>2001:db8:12::1/64</ipv6>
    </if>
    <route type="ipv4" gw="10.0.0.2">10.0.2.0/24</route>    
    <forwarding type="ip" />
    <filetree seq="start-www" root="/var/www/" user="www-data" group="www-data" perms="644">conf/txtfile</filetree>
    <exec seq="start-www" type="verbatim" ostype="system">service apache2 start</exec>
    <exec seq="stop-www" type="verbatim"  ostype="system">service apache2 stop</exec>    
  </vm>

  <vm name="r2" type="uml" subtype="" os="" exec_mode="mconsole">
    <filesystem type="cow">/usr/share/vnx/filesystems/rootfs_uml</filesystem>
    <mem>64M</mem>
    <kernel>/usr/share/vnx/kernels/linux</kernel>
    <if id="1" net="lan2" name="fxp0">
      <ipv4>10.0.2.1/24</ipv4>
      <ipv6>2001:db8:2::1/64</ipv6>
    </if>
    <if id="2" net="ptp12" name="fxp1">
      <ipv4>10.0.0.2/30</ipv4>
      <ipv6>2001:db8:12::2/64</ipv6>
    </if>
    <route type="ipv4" gw="10.0.0.1">10.0.1.0/24</route>    
    <forwarding type="ip" />
  </vm>

  <vm name="h1" type="libvirt" subtype="kvm" os="linux" exec_mode="cdrom">
    <filesystem type="cow">/usr/share/vnx/filesystems/rootfs_ubuntu</filesystem>
    <mem>256M</mem>
    <if id="1" net="lan1">
      <!--ipv4>10.0.1.2/24</ipv4>
      <ipv6>2001:db8:1::2/64</ipv6-->
    </if>
    <!--route type="ipv4" gw="10.0.1.1">default</route>    
    <route type="ipv6" gw="2001:db8:1::1">default</route-->       
  </vm>

  <vm name="h2" type="uml" exec_mode="mconsole">
    <filesystem type="cow">/usr/share/vnx/filesystems/rootfs_uml</filesystem>
    <mem>64M</mem>
    <kernel>/usr/share/vnx/kernels/linux</kernel>
    <if id="1" net="lan2">
      <!--ipv4>10.0.2.2/24</ipv4>
      <ipv6>2001:db8:2::2/64</ipv6-->
    </if>
    <!--route type="ipv4" gw="10.0.2.1">default</route>    
    <route type="ipv6" gw="2001:db8:2::1">default</route-->       
  </vm>
  

  <host>
    <hostif net="lan1">
       <ipv4>10.0.1.3/24</ipv4>
       <ipv6>2001:db8:1::3/64</ipv6>
    </hostif>
    <route type="ipv4" gw="10.0.1.1">10.0.0.0/16</route>    
    <route type="ipv6" gw="2001:db8:1::1">2001:db8::/32</route>    
  </host>
  
</vnx>

Plugin Configuration File (PCF)

<dhcp_conf xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="/usr/share/xml/vnx/dhcp.xsd">

  <vm name="r1" type="dhcp3-isc">
    <server>
      <subnet>
        <network>10.0.1.0/24</network>
        <range>
          <first>10.0.1.10</first>
          <last>10.0.1.20</last>
        </range>
        <router>10.0.1.1</router>
        <dns>10.0.1.2</dns>
        <domain>dominio1.org</domain>
      </subnet>
      <subnet>
        <network>10.0.2.0/24</network>
        <range>
          <first>10.0.2.10</first>
          <last>10.0.2.20</last>
        </range>
        <router>10.0.2.1</router>
        <host name="Unicum" mac="AA:BB:CC:DD:EE:FF" ip="10.0.2.28"/>
      </subnet>
      <subnet>
        <network>10.0.0.0/30</network>
      </subnet>
    </server>
  </vm>

  <vm name="h1" type="dhcp3">
    <client>
      <if>eth1</if>
    </client>
  </vm>

  <vm name="r2" type="dhcp3">
    <relay>
      <toserver>10.0.0.1</toserver>
    </relay>
  </vm>

  <vm name="h2" type="dhcp3">
    <client>
      <if>eth1</if>
    </client>
  </vm>

</dhcp_conf>