]> xenbits.xensource.com Git - unikraft/libs/click.git/commitdiff
support for loading click configs
authorFlorian Schmidt <florian.schmidt@neclab.eu>
Wed, 5 Jun 2019 12:43:30 +0000 (14:43 +0200)
committerFelipe Huici <felipe.huici@neclab.eu>
Wed, 5 Jun 2019 12:57:29 +0000 (14:57 +0200)
The expected way is to provide a (plain-text) config file as initrd. If
no initrd is provided, click will fall back to a static, compiled-in
config that replies to pings.

Signed-off-by: Florian Schmidt <florian.schmidt@neclab.eu>
Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
click.cc
include/static_config.h [new file with mode: 0644]

index a3bfba8b239acef44da37afc93b5e93161f8ca86..85a938b9ecc61999525820f46610687d8d194c55 100644 (file)
--- a/click.cc
+++ b/click.cc
@@ -52,11 +52,14 @@ extern "C"{
 #include <click/straccum.hh>
 #include <click/driver.hh>
 
+#include <static_config.h>
+
 #include <uk/sched.h>
 #include <uk/thread.h>
+#include <uk/netdev.h>
+#include <uk/plat/memory.h>
 
 int click_nthreads = 1;
-
 void *__dso_handle = NULL;
 
 #define NLOG(fmt, ...)
@@ -119,6 +122,32 @@ read_config(u_int rid = 0)
 static ErrorHandler *errh;
 static Master master(1);
 
+static String *
+get_config()
+{
+       String *cfg;
+       struct ukplat_memregion_desc img;
+       char *cstr;
+       size_t cstr_len;
+
+       /* First, try initrd */
+       if (ukplat_memregion_find_initrd0(&img) >= 0) {
+               cstr = (char *)img.base;
+               cstr_len = img.len;
+       } else {
+               /* If we can't find a config: use a fallback one statically
+                * compiled in.
+                */
+               uk_pr_warn("Could not find a config, using standard config!\n");
+               cstr = CONFIGSTRING;
+               cstr_len = strlen(CONFIGSTRING);
+       }
+       cfg = new String(cstr, cstr_len);
+       printf("Received config (length %d):\n", cfg->length());
+       printf("%s\n", cfg->c_str());
+       return cfg;
+}
+
 struct router_instance {
        Router *r;
        u_int f_stop;
@@ -127,9 +156,8 @@ struct router_instance {
 void
 router_thread(void *thread_data)
 {
-       u_int *rid = (u_int*) thread_data;
-       String *config = new String; //read_config(*rid);
-       struct router_instance *ri = &router_list[*rid];
+       struct router_instance *ri = &router_list[(unsigned long)thread_data];
+       String *config = get_config();
 
        ri->r = click_read_router(*config, true, errh, false, &master);
        if (ri->r->initialize(errh) < 0) {
@@ -150,7 +178,6 @@ router_thread(void *thread_data)
 
        LOG("Master/driver stopped, closing router_thread");
        free(config);
-       free(rid);
 }
 
 void
diff --git a/include/static_config.h b/include/static_config.h
new file mode 100644 (file)
index 0000000..85c5d12
--- /dev/null
@@ -0,0 +1,22 @@
+static char CONFIGSTRING[] = "    define($IP 10.0.10.123);\n\
+    define($MAC0 11:22:33:44:55:66);\n\
+\n\
+    source :: FromDevice;\n\
+    sink   :: ToDevice;\n\
+    // classifies packets \n\
+    c :: Classifier(\n\
+        12/0806 20/0001, // ARP Requests goes to output 0\n\
+        12/0806 20/0002, // ARP Replies to output 1\n\
+        12/0800 14/45 34/08, // ICMP Requests to output 2\n\
+        -); // without a match to output 3\n\
+\n\
+    arpq :: ARPQuerier($IP, $MAC0);\n\
+    arpr :: ARPResponder($IP $MAC0);\n\
+\n\
+    source -> c;\n\
+    c[0] -> CheckARPHeader(14) -> ARPPrint -> arpr -> ARPPrint -> sink;\n\
+    c[1] -> [1]arpq;\n\
+    Idle -> [0]arpq;\n\
+    arpq -> sink;\n\
+    c[2] -> CheckIPHeader(14) -> IPPrint -> ICMPPingResponder() -> EtherMirror() -> IPPrint -> sink;\n\
+    c[3] -> Discard;";