[netcf-devel] [PATCH 1/1] bonding: add montirong with mii or arp

David Lutterkort lutter at redhat.com
Fri Jun 19 01:40:35 UTC 2009


  * data/xml/interface.rng: add <arpmon> and <miimon> elements to set up
    monitoring of bonds
  * data/xml/initscripts-get.xsl, data/xml/initscripts-put.xsl: process new
    montiroing elements in both directions
  * tests/initscripts/bond.xml, tests/interface/bond.xml: amend with <miimon>
  * tests/initscripts/bond-arp.xml, tests/interface/bond-arp.xml: new test
    using <arpmon>
  * tests/test-initscripts.c: run bond-arp.xml test
---
 data/xml/initscripts-get.xsl   |   22 ++++++++++++++-
 data/xml/initscripts-put.xsl   |   30 +++++++++++++++++++-
 data/xml/interface.rng         |   58 ++++++++++++++++++++++++++++++++++++++-
 tests/initscripts/bond-arp.xml |   22 +++++++++++++++
 tests/initscripts/bond.xml     |    2 +-
 tests/interface/bond-arp.xml   |   14 +++++++++
 tests/interface/bond.xml       |    1 +
 tests/test-initscripts.c       |    1 +
 8 files changed, 144 insertions(+), 6 deletions(-)
 create mode 100644 tests/initscripts/bond-arp.xml
 create mode 100644 tests/interface/bond-arp.xml

diff --git a/data/xml/initscripts-get.xsl b/data/xml/initscripts-get.xsl
index 9774f11..9eca3e7 100644
--- a/data/xml/initscripts-get.xsl
+++ b/data/xml/initscripts-get.xsl
@@ -57,7 +57,27 @@
       <xsl:call-template name="startmode"/>
       <xsl:call-template name="interface-addressing"/>
       <node label="BONDING_OPTS">
-        <xsl:attribute name="value">'<xsl:if test="bond/@mode">mode=<xsl:value-of select='bond/@mode'/></xsl:if><xsl:if test="bond/@mode = 'active-backup'"> primary=<xsl:value-of select='bond/interface[1]/name'/></xsl:if>'</xsl:attribute>
+        <xsl:attribute name="value">
+          <xsl:text>'</xsl:text>
+          <xsl:if test="bond/@mode">mode=<xsl:value-of select='bond/@mode'/></xsl:if>
+          <xsl:if test="bond/@mode = 'active-backup'"> primary=<xsl:value-of select='bond/interface[1]/name'/></xsl:if>
+          <xsl:if test="bond/miimon">
+            <xsl:text> miimon=</xsl:text><xsl:value-of select='bond/miimon/@freq'/>
+            <xsl:if test="bond/miimon/@downdelay"><xsl:text> downdelay=</xsl:text><xsl:value-of select="bond/miimon/@downdelay"/></xsl:if>
+            <xsl:if test="bond/miimon/@updelay"><xsl:text> updelay=</xsl:text><xsl:value-of select="bond/miimon/@updelay"/></xsl:if>
+            <xsl:if test="bond/miimon/@carrier">
+              <xsl:text> use_carrier=</xsl:text>
+              <xsl:if test="bond/miimon/@carrier = 'ioctl'">0</xsl:if>
+              <xsl:if test="bond/miimon/@carrier = 'netif'">1</xsl:if>
+            </xsl:if>
+          </xsl:if>
+          <xsl:if test="bond/arpmon">
+            <xsl:text> arp_interval=</xsl:text><xsl:value-of select="bond/arpmon/@interval"/>
+            <xsl:text> arp_ip_target=</xsl:text><xsl:value-of select="bond/arpmon/@target"/>
+            <xsl:if test="bond/arpmon/@validate"><xsl:text> arp_validate=</xsl:text><xsl:value-of select="bond/arpmon/@validate"/></xsl:if>
+          </xsl:if>
+          <xsl:text>'</xsl:text>
+        </xsl:attribute>
       </node>
     </tree>
     <xsl:for-each select='bond/interface'>
diff --git a/data/xml/initscripts-put.xsl b/data/xml/initscripts-put.xsl
index f524179..8baae34 100644
--- a/data/xml/initscripts-put.xsl
+++ b/data/xml/initscripts-put.xsl
@@ -57,13 +57,39 @@
       <xsl:call-template name="basic-attrs"/>
       <xsl:call-template name="interface-addressing"/>
       <bond>
-        <xsl:variable name="mode" select="bond:option(node[@label = 'BONDING_OPTS']/@value, 'mode')"/>
-        <xsl:variable name="primary" select="bond:option(node[@label = 'BONDING_OPTS']/@value, 'primary')"/>
+        <xsl:variable name="opts" select="node[@label = 'BONDING_OPTS']/@value"/>
+        <xsl:variable name="mode" select="bond:option($opts, 'mode')"/>
+        <xsl:variable name="primary" select="bond:option($opts, 'primary')"/>
         <xsl:if test="string-length($mode) > 0">
           <xsl:attribute name="mode">
             <xsl:value-of select="$mode"/>
           </xsl:attribute>
         </xsl:if>
+        <xsl:if test="bond:option($opts, 'miimon')">
+          <miimon freq="{bond:option($opts, 'miimon')}">
+            <xsl:if test="bond:option($opts, 'downdelay')"><xsl:attribute name="downdelay"><xsl:value-of select="bond:option($opts, 'downdelay')"/></xsl:attribute></xsl:if>
+            <xsl:if test="bond:option($opts, 'updelay')"><xsl:attribute name="updelay"><xsl:value-of select="bond:option($opts, 'updelay')"/></xsl:attribute></xsl:if>
+            <xsl:if test="bond:option($opts, 'use_carrier')">
+              <xsl:attribute name="carrier">
+                <xsl:if test="bond:option($opts, 'use_carrier') = '0'">ioctl</xsl:if>
+                <xsl:if test="bond:option($opts, 'use_carrier') = '1'">netif</xsl:if>
+              </xsl:attribute>
+            </xsl:if>
+          </miimon>
+        </xsl:if>
+        <xsl:if test="bond:option($opts, 'arp_interval')">
+          <arpmon interval="{bond:option($opts, 'arp_interval')}" target="{bond:option($opts, 'arp_ip_target')}">
+            <xsl:variable name="val" select="bond:option($opts, 'arp_validate')"/>
+            <xsl:if test="$val">
+              <xsl:attribute name="validate">
+                <xsl:if test="$val = 'none' or $val = '0'">none</xsl:if>
+                <xsl:if test="$val = 'active' or $val = '1'">active</xsl:if>
+                <xsl:if test="$val = 'backup' or $val = '2'">backup</xsl:if>
+                <xsl:if test="$val = 'all' or $val = '3'">all</xsl:if>
+              </xsl:attribute>
+            </xsl:if>
+          </arpmon>
+        </xsl:if>
         <xsl:for-each select="/descendant-or-self::*[node[@label = 'MASTER' and @value = $iface]][node[@label = 'DEVICE' and @value = $primary]]">
           <xsl:call-template name='bare-ethernet-interface'/>
         </xsl:for-each>
diff --git a/data/xml/interface.rng b/data/xml/interface.rng
index b1a7026..340eb1f 100644
--- a/data/xml/interface.rng
+++ b/data/xml/interface.rng
@@ -104,6 +104,60 @@
             </choice>
           </attribute>
         </optional>
+
+        <!-- FIXME: add more attributes
+
+             mode == 802.3ad
+               ad_select
+               lacp_rate
+               xmit_hash_policy
+
+             mode == active-backup
+               fail_over_mac
+               num_grat_arp when mode == active-backup (since 3.3.0)
+               num_unsol_na when mode == active-backup (ipv6, since 3.4.0)
+
+             mode == balance-xor
+               xmit_hash_policy       (since 2.6.3/3.2.2)
+        -->
+
+        <choice>
+          <element name="miimon">
+            <!-- miimon frequency in ms -->
+            <attribute name="freq"><ref name="uint"/></attribute>
+            <optional>
+              <attribute name="downdelay"><ref name="uint"/></attribute>
+            </optional>
+            <optional>
+              <attribute name="updelay"><ref name="uint"/></attribute>
+            </optional>
+            <optional>
+              <!-- use_carrier -->
+              <attribute name="carrier">
+                <choice>
+                  <!-- use MII/ETHTOOL ioctl -->
+                  <value>ioctl</value>
+                  <!-- use netif_carrier_ok() -->
+                  <value>netif</value>
+                </choice>
+              </attribute>
+            </optional>
+          </element>
+          <element name="arpmon">
+            <attribute name="interval"><ref name="uint"/></attribute>
+            <attribute name="target"><ref name="ip-addr"/></attribute>
+            <optional>
+              <attribute name="validate">
+                <choice>
+                  <value>none</value>
+                  <value>active</value>
+                  <value>backup</value>
+                  <value>all</value>
+                </choice>
+              </attribute>
+            </optional>
+          </element>
+        </choice>
         <oneOrMore>
           <!-- The slave interfaces -->
           <ref name="bare-ethernet-interface"/>
@@ -118,7 +172,7 @@
     <element name="name"><ref name="device-name"/></element>
     <optional>
       <element name="mtu">
-        <attribute name="size"><ref name="unsigned-int"/></attribute>
+        <attribute name="size"><ref name="uint"/></attribute>
       </element>
     </optional>
   </define>
@@ -217,7 +271,7 @@
 
   <!-- Type library -->
 
-  <define name='unsigned-int'>
+  <define name='uint'>
     <data type='unsignedInt'>
       <param name="pattern">[0-9]+</param>
     </data>
diff --git a/tests/initscripts/bond-arp.xml b/tests/initscripts/bond-arp.xml
new file mode 100644
index 0000000..8d07e5f
--- /dev/null
+++ b/tests/initscripts/bond-arp.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<forest>
+  <tree path="/files/etc/sysconfig/network-scripts/ifcfg-bond0">
+    <node label="DEVICE" value="bond0"/>
+    <node label="ONBOOT" value="no"/>
+    <node label="BOOTPROTO" value="none"/>
+    <node label="IPADDR" value="192.168.50.7"/>
+    <node label="NETMASK" value="255.255.255.0"/>
+    <node label="GATEWAY" value="192.168.50.1"/>
+    <node label="BONDING_OPTS" value="'mode=active-backup primary=eth1 arp_interval=100 arp_ip_target=192.168.50.1 arp_validate=active'"/>
+  </tree>
+  <tree path="/files/etc/sysconfig/network-scripts/ifcfg-eth1">
+    <node label="DEVICE" value="eth1"/>
+    <node label="MASTER" value="bond0"/>
+    <node label="SLAVE" value="yes"/>
+  </tree>
+  <tree path="/files/etc/sysconfig/network-scripts/ifcfg-eth0">
+    <node label="DEVICE" value="eth0"/>
+    <node label="MASTER" value="bond0"/>
+    <node label="SLAVE" value="yes"/>
+  </tree>
+</forest>
diff --git a/tests/initscripts/bond.xml b/tests/initscripts/bond.xml
index c1cc12a..56461b7 100644
--- a/tests/initscripts/bond.xml
+++ b/tests/initscripts/bond.xml
@@ -11,7 +11,7 @@
     <node label="IPADDR" value="192.168.50.7"/>
     <node label="NETMASK" value="255.255.255.0"/>
     <node label="GATEWAY" value="192.168.50.1"/>
-    <node label="BONDING_OPTS" value="'mode=active-backup primary=eth1'"/>
+    <node label="BONDING_OPTS" value="'mode=active-backup primary=eth1 miimon=100 updelay=10 use_carrier=0'"/>
   </tree>
   <tree  path="/files/etc/sysconfig/network-scripts/ifcfg-eth1">
     <node label="DEVICE" value="eth1"/>
diff --git a/tests/interface/bond-arp.xml b/tests/interface/bond-arp.xml
new file mode 100644
index 0000000..fe550ca
--- /dev/null
+++ b/tests/interface/bond-arp.xml
@@ -0,0 +1,14 @@
+<interface type="bond" startmode="none">
+  <name>bond0</name>
+  <ip address="192.168.50.7" prefix="24"/>
+  <route gateway="192.168.50.1"/>
+  <bond mode="active-backup">
+    <arpmon interval="100" target="192.168.50.1" validate="active"/>
+    <interface type="ethernet">
+      <name>eth1</name>
+    </interface>
+    <interface type="ethernet">
+      <name>eth0</name>
+    </interface>
+  </bond>
+</interface>
diff --git a/tests/interface/bond.xml b/tests/interface/bond.xml
index 9308e17..df37de1 100644
--- a/tests/interface/bond.xml
+++ b/tests/interface/bond.xml
@@ -3,6 +3,7 @@
   <ip address="192.168.50.7" prefix="24"/>
   <route gateway="192.168.50.1"/>
   <bond mode="active-backup">
+    <miimon freq="100" updelay="10" carrier="ioctl"/>
     <interface type="ethernet">
       <name>eth1</name>
     </interface>
diff --git a/tests/test-initscripts.c b/tests/test-initscripts.c
index 0fe5ba7..88cd8de 100644
--- a/tests/test-initscripts.c
+++ b/tests/test-initscripts.c
@@ -238,6 +238,7 @@ static void assert_transforms(CuTest *tc, const char *base) {
 
 static void testTransforms(CuTest *tc) {
     assert_transforms(tc, "bond");
+    assert_transforms(tc, "bond-arp");
     assert_transforms(tc, "bridge");
     assert_transforms(tc, "ethernet-static");
     assert_transforms(tc, "ethernet-static-no-prefix");
-- 
1.6.0.6



More information about the netcf-devel mailing list