Skip to content

Commit

Permalink
More updates to networking tutorial
Browse files Browse the repository at this point in the history
Fixes mirage#279.
  • Loading branch information
talex5 committed Feb 12, 2015
1 parent e1ca4cc commit 6adbb52
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions tmpl/wiki/hello-world.md
Expand Up @@ -422,38 +422,36 @@ directory in `mirage-skeleton`.
```
open Mirage
let handler = foreign "Unikernel.Main" (console @-> stackv4 @-> job)
let main = foreign "Unikernel.Main" (console @-> stackv4 @-> job)
let net =
try match Sys.getenv "NET" with
| "direct" -> `Direct
| "socket" -> `Socket
| _ -> `Direct
| _ -> `Direct
with Not_found -> `Direct
let dhcp =
try match Sys.getenv "DHCP" with
| "" -> false
| _ -> true
with Not_found -> false
try match Sys.getenv "ADDR" with
| "dhcp" -> `Dhcp
| "static" -> `Static
with Not_found -> `Dhcp
let stack =
let stack console =
match net, dhcp with
| `Direct, true -> direct_stackv4_with_dhcp default_console tap0
| `Direct, false -> direct_stackv4_with_default_ipv4 default_console tap0
| `Socket, _ -> socket_stackv4 default_console [Ipaddr.V4.any]
| `Direct, `Dhcp -> direct_stackv4_with_dhcp console tap0
| `Direct, `Static -> direct_stackv4_with_default_ipv4 console tap0
| `Socket, _ -> socket_stackv4 console [Ipaddr.V4.any]
let () =
add_to_opam_packages ["mirage-http"];
add_to_ocamlfind_libraries ["mirage-http"];
register "stackv4" [
handler $ default_console $ stack;
register "network" [
main $ default_console $ stack default_console
]
```

This configuration shows how composable the network stack subsystem is, by
simultaneously listening on a socket port (using the Linux kernel) *and*
a direct tuntap for the same webcode. The definition of `handler` just
a direct tuntap for the same webcode. The definition of `main` just
adds a new `stackv4` device driver.

The `net` handler checks to see if it's building for a socket or direct network stack.
Expand All @@ -472,11 +470,11 @@ The definition of `stack` then uses `dhcp` and `net` accordingly to set up the n
<br />
<div class="panel callout">
<i class="fa fa-info fa-3x pull-left"> </i>
<p>You will have noticed by this stage that the `Makefile` generated by <code>mirage configure</code>
<p>You will have noticed by this stage that <code>mirage configure</code>
invokes OPAM to install any libraries that it needs. If your application
needs some extra packages, you can use the <code>add_to_opam_packages</code>
and <code>add_to_ocamlfind_libraries</code> functions to hook in the extra
packages and libraries. The example above does this to add the HTTP library.</p>
needs some extra packages, you can use the optional <code>~packages</code>
and <code>~libraries</code> arguments to <code>foreign</code> to add the extra
OPAM packages and ocamlfind libraries. For example, you could modify the code above to add an <a href='https://github.com/mirage/mirage-http'>HTTP library</a>.</p>
</div>

Let's get the network stack compiling on Unix first. On a Mac, be sure
Expand Down Expand Up @@ -515,7 +513,7 @@ hello!

The `ifconfig` call binds `10.0.0.1` as the gateway IP address to
our unikernel. We then test our userspace network stack by pinging
it, and if that succeeds, the subsequent `telent` call now retrieves
it, and if that succeeds, the subsequent `telnet` call now retrieves
the request via the OCaml TCP/IP stack!

At this point, recompiling a Xen unikernel is pretty straightforward.
Expand Down

0 comments on commit 6adbb52

Please sign in to comment.