Vnx-plugin-dhcp

From VNX
Revision as of 22:34, 11 September 2011 by David (talk | contribs) (DHCP Plugin Example Scenario)
Jump to: navigation, search

DHCP Plugin

...to be completed...


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:

...
CHANGE!!
<vm name="r1" type="quagga" subtype="lib-install">
  <hostname>r1</hostname>
  <password>xxxx</password>
  <network area="0.0.0.0">10.0.0.0/16</network>
  <passive_if>eth1</passive_if> 
  <binaries>
    <zebra>/usr/lib/quagga/zebra</zebra>
    <ospfd>/usr/lib/quagga/ospfd</ospfd>
  </binaries>
</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

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 stop the daemon in r1 with:

vnx -f example_ospf-plugin.xml -v -x ospf-stop -M r1

and edit example_ospf-plugin-conf.xml to make any change to r1 OSPF configuration (for example, change the hostname ro router1) and reload the configuration file with:

vnx -f example_ospf-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/quagga/zebra.conf and /etc/quagga/ospfd.conf files).

Finally, you can start the daemon with the new configuration with:

vnx -f example_ospf-plugin.xml -v -x ospf-start -M r1

Note: typically plugins provide the same basic 'start|stop|restart' commands with two sequence names: general (i.e. start) and specific (i.e. ospf-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_ospf-plugin
Description: Example scenario to show the use of ospf plugin. It is made of two 
             routers: r1 (ubuntu) and r2(uml) and two hosts: h1 (ubuntu) and h2 (uml).   

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_ospf-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"/>
    </vm_defaults>
    <extension plugin="ospf" conf="example_ospf-plugin-conf.xml" />
  </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>
    <forwarding type="ip" />
  </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>
    <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)

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

   <vm name="r1" type="quagga" subtype="lib-install">
      <hostname>r1</hostname>
      <password>xxxx</password>
      <network area="0.0.0.0">10.0.0.0/16</network>
      <passive_if>eth1</passive_if> 
      <binaries>
        <zebra>/usr/lib/quagga/zebra</zebra>
        <ospfd>/usr/lib/quagga/ospfd</ospfd>
      </binaries>
   </vm>

   <vm name="r2" type="quagga" subtype="lib-install">
      <hostname>r2</hostname>
      <password>xxxx</password>
      <network area="0.0.0.0">10.0.0.0/16</network>
      <passive_if>eth1</passive_if> 
   </vm>
</ospf_conf>