Added slice_whitelist match for VINI.
authorSapan Bhatia <sapanb@cs.princeton.edu>
Wed, 16 Sep 2009 00:15:21 +0000 (00:15 +0000)
committerSapan Bhatia <sapanb@cs.princeton.edu>
Wed, 16 Sep 2009 00:15:21 +0000 (00:15 +0000)
sfatables/processors/hrn.xsl
sfatables/processors/max_link_bandwidth.xsl
sfatables/processors/restrict_to_nodes.xsl
sfatables/processors/slice_whitelist.xsl [new file with mode: 0644]

index 65e85c6..318739a 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
 <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-    <xsl:variable name="context-hrn" select="hrn"/>
+    <xsl:variable name="context-hrn" select="//request-context//hrn"/>
 
     <!-- Magic sauce -->
 
index fe3ee24..37c56d4 100644 (file)
@@ -11,7 +11,7 @@
     <!-- 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-bandwidth" select="//RSpec//rule/argument[name='max-link-bandwidth']/value"/>
+    <xsl:variable name="max-link-bandwidth" select="//RSpec//sfatables-rule/argument[name='max-link-bandwidth']/value"/>
 
     <!-- Drop Linkspecs for which bw > max-link-bandwidth -->
     <xsl:template match="LinkSpec">
index 2ecba22..f09a56f 100644 (file)
@@ -9,8 +9,8 @@
         </xsl:copy>
     </xsl:template>
 
-    <xsl:variable name="whitelist_prefix" select="//rspec//rule/argument[name='whitelist']/value"/>
-    <xsl:variable name="blacklist_prefix" select="//rspec//rule/argument[name='blacklist']/value"/>
+    <xsl:variable name="whitelist_prefix" select="//rspec//sfatables-rule/argument[name='whitelist']/value"/>
+    <xsl:variable name="blacklist_prefix" select="//rspec//sfatables-rule/argument[name='blacklist']/value"/>
 
     <!-- Drop nodes that are not in the whitelist -->
     <xsl:template match="node">
@@ -22,5 +22,4 @@
             </xsl:choose>
     </xsl:template>
 
-    <xsl:template match="sfatables-input"/>
 </xsl:stylesheet>
diff --git a/sfatables/processors/slice_whitelist.xsl b/sfatables/processors/slice_whitelist.xsl
new file mode 100644 (file)
index 0000000..afe77f2
--- /dev/null
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!-- This is a good example of an sfatables match. It's function is to verify the slice in context against a whitelist -->
+
+<!-- The following lines should precede each match/target. -->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:exsl="http://exslt.org/common"
+    extension-element-prefixes="exsl"
+    version="1.0">
+
+    <!-- Enter your whitelist prefixes here. Since XSLT cannot read from/write to an external archive, we need to embed the whitelist in here -->
+
+    <xsl:variable name="whitelist_data">
+        <hrn>plc.princeton.acb</hrn>
+        <hrn>plc.princeton.sapanb</hrn>
+        <hrn>plc.princeton.codeen</hrn>
+    </xsl:variable>
+
+    <!-- Read the whitelist into a variable. Normally, one should be able to refer to $whitelist_data directly, but apparently this is something you need to do because libxml2 does not support xslt 2.0 -->
+
+    <xsl:variable name="whitelist" select="exsl:node-set($whitelist_data)/hrn"/>
+
+    <!-- Read the value of the current slice's hrn -->
+    <xsl:variable name="current_slice_hrn" select="//request-context/slice/hrn"/>
+
+    <!-- Define a function that checks if one of a list of prefixes (lst) matches $current_slice_hrn". It's a stupid idea to call a function a 'template' but whatever...  -->
+    <xsl:template name="recurse_list">
+        <xsl:param name="lst"/>
+        <xsl:choose>
+            <xsl:when test="count($lst)!=0">
+                <!-- Indexing in xpath has a base=1 -->
+                <xsl:variable name="head" select="$lst[1]"/>
+                <xsl:choose>
+                    <xsl:when test="starts-with($current_slice_hrn,$head)">
+                        <result verdict="True"/>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <xsl:call-template name="recurse_list">
+                            <xsl:with-param name="lst" select="$lst/following-sibling::*"/>
+                        </xsl:call-template>
+                    </xsl:otherwise>
+                </xsl:choose>
+            </xsl:when>
+            <xsl:otherwise>
+                <result verdict="False"/>
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:template>
+
+    <xsl:template match="/">
+        <xsl:call-template name="recurse_list">
+            <xsl:with-param name="lst" select="$whitelist"/>
+        </xsl:call-template>
+    </xsl:template>
+</xsl:stylesheet>