Cap kbps values rather than discard LinkSpecs
authorAndy Bavier <acb@cs.princeton.edu>
Fri, 6 Nov 2009 15:01:09 +0000 (15:01 +0000)
committerAndy Bavier <acb@cs.princeton.edu>
Fri, 6 Nov 2009 15:01:09 +0000 (15:01 +0000)
sfatables/processors/max_link_kbps.xsl
sfatables/vini.rspec

index 575e92e..71d0abe 100644 (file)
@@ -1,28 +1,39 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-    <!-- Magic sauce copied from a manual. This fragment basically copies everything except for
-    stuff that explicitly matches with the templates defined below. In the case of such a match,
-    the matched node is treated differently.-->
-    <xsl:template match="@* | node()">
-        <xsl:copy>
-            <xsl:apply-templates select="@* | node()"/>
-        </xsl:copy>
-    </xsl:template>
-    <!-- End of magic sauce -->
+  <!-- Magic sauce copied from a manual. This fragment basically
+    copies everything except for stuff that explicitly matches with
+    the templates defined below. In the case of such a match, the
+    matched node is treated differently.-->
+  <xsl:template match="@* | node()">
+    <xsl:copy>
+      <xsl:apply-templates select="@* | node()"/>
+    </xsl:copy>
+  </xsl:template>
+  <!-- End of magic sauce -->
 
-    <!-- Read in the value of the argument. See 'example_vini_rspec.xml' for an example of such an argument -->
-    <xsl:variable name="max-link-kbps" select="//RSpec//target-context/argument[name='max-link-kbps']/value"/>
+  <!-- Read in the value of the argument. -->
+  <xsl:variable name="max-link-kbps" select="//RSpec//target-context/argument[name='max-link-kbps']/value"/>
 
-    <!-- Drop Linkspecs for which bw > max-link-bandwidth -->
-    <xsl:template match="LinkSpec">
-            <xsl:choose>
-                <xsl:when test="not (kbps &gt; $max-link-kbps)">
-                    <xsl:copy-of select="."/>
-                </xsl:when>
-                <xsl:otherwise/>
-            </xsl:choose> 
-    </xsl:template>
-
-    <xsl:template match="sfatables-input"/>
+  <!-- Modify LinkSpecs for which kbps > max-link-kbps -->
+  <xsl:template match="LinkSpec/kbps">
+    <xsl:choose>
+      <xsl:when test=". &gt; $max-link-kbps">
+       <kbps><xsl:value-of select="$max-link-kbps"/></kbps>
+      </xsl:when>
+      <xsl:otherwise>
+       <xsl:copy-of select="."/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+      
+  <!-- Fill in missing kbps values --> 
+  <xsl:template match="LinkSpec[not(kbps)]">
+    <LinkSpec>
+      <xsl:copy-of select="*"/>
+      <kbps><xsl:value-of select="$max-link-kbps"/></kbps>
+    </LinkSpec>
+  </xsl:template>
+  
+  <xsl:template match="sfatables-input"/>
 </xsl:stylesheet>
 
index 8922170..99f89e5 100644 (file)
@@ -8,5 +8,9 @@
       <endpoint>i2chic1</endpoint>
       <kbps>1001</kbps>
     </LinkSpec>
+    <LinkSpec name="baz">
+      <endpoint>i2hous1</endpoint>
+      <endpoint>i2newy1</endpoint>
+    </LinkSpec>
   </Request>
 </RSpec>