Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


74c8fd6229f5d32826d295377a09e67f91434fa0
[palacios.git] / manual / manual.tex
1
2 \documentclass[11pt]{article}
3
4 \usepackage{calc}
5 \usepackage{graphics}
6 %\usepackage{latex8}
7 \usepackage{times}
8 \usepackage{epsf}
9 \usepackage{epsfig}
10 \usepackage{graphicx}
11 \usepackage{changebar}
12 \usepackage{portland}
13 \usepackage{lscape}
14
15 \setlength{\textheight}{8.50in}
16 \setlength{\textwidth}{6.5in}
17 \setlength{\topmargin}{-0.3in}
18 %\setlength{\leftmargin}{2.9in}
19 %\setlength{\rightmargin}{-2.9in}
20 \setlength{\oddsidemargin}{0in}
21 \setlength{\parindent}{0.5in}
22 \setlength\parindent{0in}
23 \setlength\parskip{0.1in} 
24
25 \newcommand{\note}[1]{{$\rightarrow$ \bf Note: \emph{#1}}}
26
27 \begin{document}
28
29 \title{
30 \includegraphics[height=1.5in]{v3vee.pdf}
31 \includegraphics[height=1.5in]{logo6.png} \\
32 \vspace{0.5in} 
33 Palacios Internal Developer Manual
34 }
35
36
37 \maketitle
38
39
40 This manual is written for internal Palacios developers. It contains
41 information on how to obtain the Palacios code base, how to go about
42 the development process, and how to commit those changes to the
43 mainline source tree.  This assumes that the reader has read {\em An
44 Introduction to the Palacios Virtual Machine Monitor -- Release 1.0}
45 and also has a slight working knowledge of {\em git}.
46
47
48 \section{Overview}
49
50
51 Both Palacios and Kitten follow a hybrid development process that
52 uses both the centralized repository and distributed development
53 models. A central repository exists that holds the master version of
54 the code base. This central repository is cloned by multiple people
55 and in multiple places to support various development efforts. A
56 feature of \texttt{git} is that every developer actually has a fully copy of
57 the entire repository, and so can function independently until such
58 time as they need to re-sync with the master version. 
59
60 There are typically multiple levels of access to the central
61 repository, that are granted based on the type of developer being
62 granted access. The three basic developer types and their access
63 privileges are:
64
65 \begin{itemize}
66 \item Core developers: These are the lead developers and are in
67 charge of managing the master repository. They have full read/write
68 access permissions to the central repository.
69
70 \item Internal developers: Formal members of the development
71 team. These people are capable of pulling directly from the central
72 repository, but lack the ability to write directly to it. 
73
74 \item External developers: People who are not actual members of the
75 development team. These people can only access the public repository
76 which is only updated to contain the release versions. 
77 \end{itemize}
78
79 Because internal and external developers cannot write directly to the
80 master repository, they need to first submit their changes to a core
81 developer before they can be added to the mainline. We will discuss
82 that process in Section~\ref{sec:submission}.
83
84
85 \section{Checking out Palacios}
86 The central Palacios repository is located on {\em
87 newskysaw.cs.northwestern.edu} in {\em /home/palacios/palacios}. All
88 internal developers have read access to the directory. Each developer
89 must create their own local version of the repository, this is done
90 with {\em git clone}.
91
92 \begin{verbatim}
93 git clone /home/palacios/palacios
94 \end{verbatim}
95
96 This creates a local copy of the repository at {\em ./palacios/}.
97
98
99 All development work is done in the {\em devel} branch of the
100 repository. The developer can access this branch via:
101
102 \begin{verbatim}
103 git checkout --track -b devel origin/devel
104 \end{verbatim}
105
106 or 
107
108 \begin{verbatim}
109 /opt/vmm-tools/bin/checkout_branch devel
110 \end{verbatim}
111
112 {\em Important:}
113 Note that Palacios is very actively developed so the contents of the
114 {\em devel} branch are frequently changing. In order to keep up to
115 date with the latest version, it is necessary to periodically pull the
116 latest changes from the master repository by running \verb.git pull..
117
118
119
120 \section{Checking out Kitten}
121
122 Kitten is available from Sandia National Labs, and is the main host OS
123 we are targeting with Palacios. Loosely speaking, core Palacios
124 developers are internal Kitten developers, and internal Palacios
125 developers are external Kitten developers. Because we have limited
126 access to the Kitten repository, we are maintaining a local mirror
127 copy in {\em /home/palacios/kitten}. 
128
129 Kitten uses Mercurial for their source management, so you will have to
130 make sure the local mercurial version is configured correctly.
131 Specifically you should add the following Python path to your shell environment.
132
133 \begin{verbatim}
134 export PYTHONPATH=/usr/local/lib64/python2.4/site-packages/
135 \end{verbatim}
136
137 You can then clone Kitten from the local mirror:
138 \begin{verbatim}
139 hg clone /home/palacios/kitten
140 \end{verbatim}
141
142 Both the Kitten and Palacios clone commands should be run from the
143 same directory. This means that both repositories should be located at
144 the same directory level. The Kitten build process depends on this.
145
146 {\em Important:} Like Palacios, Kitten is under active development,
147 and its source tree is frequently changing. In order to keep up to
148 date with the latest version, it is necessary to periodically pull the
149 latest changes from the mirror repository by running \verb.hg.
150 pull. followed by \verb.hg update..
151
152 \section{Compiling Palacios}
153 Palacios is capable of targeting 32-bit and 64-bit operating systems,
154 and includes a build process that supports both these
155 architectures. Furthermore, Palacios has multiple build locations,
156 with multiple Makefiles: a top level build directory and a
157 Palacios-specific build directory. The Palacios build process first
158 generates a static library that includes the Palacios VMM. This static
159 library is then linked into a host operating system. Palacios
160 internally supports GeekOS and can generate a complete OS image via a
161 unified build process. 
162
163 To combine Palacios with Kitten, it is necessary to first compile
164 Palacios and then to compile Kitten externally link it with
165 Palacios. The output of the compilation process is a bit more complex
166 and generates multiple binaries, and the specifics can be found in the
167 Makefiles.
168
169 The top level build directory provides a number of high level make
170 targets, and is located in {\em palacios/build/}. It supports building
171 32-bit and 64-bit versions of the Palacios library independently as well
172 as building an integrated version of GeekOS.   The basic targets are:
173 \begin{itemize}
174 \item \verb.make palacios-full32. -- Generates a 32 bit version of the Palacios static library 
175 \item \verb.make palacios-full64. -- Generates a 64 bit version of the
176 Palacios static library
177 \item \verb.make geekos. -- Compiles the GeekOS kernel, and link it with the
178 Palacios static library 
179 \item \verb.make geekos-iso. -- Generate an ISO boot disk image from the
180 GeekOS kernel that has been compiled
181 \end{itemize}
182
183 The second build directory is located at {\em palacios/palacios/build}
184 and handles only the Palacios compilation process. It supports a
185 different set of targets and arguments:
186 \begin{itemize}
187 \item \verb.make ARCH=32. -- iteratively compiles a 32 bit version of Palacios
188 \item \verb.make ARCH=64. -- iteratively compiles a 64 bit version of
189 Palacios
190 \item \verb.make ARCH=32 world. -- fully recompiles a 32 bit version of
191 Palacios
192 \item \verb.make ARCH=64 world. -- fully recompiles a 64 bit version of
193 Palacios
194 \end{itemize}
195
196 Both build levels support compilation directives that control the
197 debugging messages that are generated by Palacios. These are specified
198 by appending a \verb.DEBUG_<COMPONENT>=1. to the end of the
199 \verb.make. command. The components that are currently supported are:
200 \begin{itemize}
201 \item \verb.DEBUG_ALL=1. -- enables debugging for all the VMM components
202 ({\em Warning:} this generates a {\em lot} of debug information.
203 \item \verb.DEBUG_SHADOW_PAGING=1.
204 \item \verb.DEBUG_CTRL_REGS=1.
205 \item \verb.DEBUG_INTERRUPTS=1.
206 \item \verb.DEBUG_IO=1.
207 \item \verb.DEBUG_KEYBOARD=1.
208 \item \verb.DEBUG_PIC=1.
209 \item \verb.DEBUG_PIT=1.
210 \item \verb.DEBUG_NVRAM=1.
211 \item \verb.DEBUG_GENERIC=1.
212 \item \verb.DEBUG_EMULATOR=1.
213 \item \verb.DEBUG_RAMDISK=1.
214 \item \verb.DEBUG_XED=1.
215 \item \verb.DEBUG_HALT=1.
216 \item \verb.DEBUG_DEV_MGR=1.
217 \item \verb.DEBUG_APIC=1.
218 \end{itemize}
219
220
221
222 \section{Compiling Kitten}
223 Kitten requires a 64-bit version of Palacios, so make sure that
224 Palacios has been correctly compiled before compiling Kitten.
225
226 \subsection{Configuration}
227 Kitten borrows a lot of concepts from Linux, including the Linux build
228 process. As such it must be configured before it is actually compiled.
229 The Kitten configuration process is the same as Linux, and can be
230 accessed via any of these make targets.
231 \begin{itemize}
232 \item \verb.make xconfig.
233 \item \verb.make config.
234 \item \verb.make menuconfig.
235 \end{itemize}
236
237 There are some specific configuration options that should be disabled
238 to work with Palacios. Because Palacios is configured by default to
239 provide a guest with direct access to the VGA console, the {\em VGA
240 console} device driver should be disabled in the Kitten
241 configuration. Similarly the {\em VM console} driver should be
242 disabled as well.
243
244 Furthermore, because the VGA console is not being used the {\em Kernel
245 Command Line Arguments} must be modified to remove the {\em VGA}
246 device from the console list.
247
248 The guest OS that is booted as a VM is included as an ISO image in raw
249 binary format inside Kitten's {\em init\_task}. To change the guest
250 ISO, you must change the Makefile for the init\_task. This is located
251 in {\em user/hello\_world/Makefile} and the syntax is well commented.
252 On {\em newskysaw} a collection of guest ISO images are located in
253 {\em /opt/vmm-tools/isos/}. 
254
255
256 \subsection{Compilation}
257 After Kitten has been configured it can be compiled. The
258 general process is to compile a reference build of Kitten, followed by
259 compiling Palacios support as a kernel module, and then doing a new
260 full recompilation of Kitten.
261
262 The specific compilation steps are run from the top level Kitten directory:
263 \begin{verbatim}
264 make
265 cd palacios
266 make -C .. M=`pwd`
267 cp built-in.o ../modules/palacios-mod.o
268 cd ..
269 make
270 make isoimage
271 \end{verbatim}
272
273 \note{This should probably explain how to change the iso (helloworld,etc)}
274
275 This generates an ISO boot image containing Kitten, Palacios, and the
276 guest that will be run as a VM. The ISO image is located at {\em
277 ./arch/x86\_64/boot/image.iso}.
278
279
280 \section{Running Palacios/Kitten}
281 Kitten and Palacios are capable of running under QEMU, which makes
282 debugging much simpler.
283
284 The basic form of the command to start the Emu emulator is:
285 \begin{verbatim}
286 /usr/local/qemu/bin/qemu-system-x86_64 -smp 1 -m 1024 \
287         -serial file:./serial.out \
288         -cdrom ./arch/x86_64/boot/image.iso  \
289         < /dev/null
290 \end{verbatim}
291
292 The command starts up a single processor emulated machine, with 1GB of
293 RAM and a CD-ROM drive loaded with the Kitten ISO image.  All output
294 to the serial port is written directly to a file called {\em
295   serial.out}. This command can be copied into a shell script for easy
296 access.
297
298 \section{Development Guidelines}
299
300 There are standard requirements we have for code entering the mainline. 
301
302 First and foremost, Palacios is designed to be OS independent and
303 support 32-bit and 64-bit architectures. This means that developers should
304 not include any external OS specific dependencies in any Palacios
305 component. Also all changes need to be tested on both 32-bit and 64-bit
306 architectures to make sure that they compile as well as run correctly.
307
308 \paragraph*{Coding Style}
309
310 "The use of equal negative space, as a balance to positive space, in a
311 composition is considered by many as good design. This basic and often
312 overlooked principle of design gives the eye a "place to rest,"
313 increasing the appeal of a composition through subtle means."
314 \newline\newline
315 Translation: Use the space bar, newlines, and parentheses. 
316
317 Curly-brackets are not optional, even for single line conditionals. 
318
319 Tabs should be 4 characters in width.
320
321 {\em Special:} If you are using XEmacs add the following to your \verb.init\.el. file:
322 \begin{verbatim}
323 (setq c-basic-offset 4)
324 (c-set-offset 'case-label 4)
325 \end{verbatim}
326
327 {\em Bad}
328 \begin{verbatim}
329 if(a&&b==5||c!=0) return;
330 \end{verbatim}
331
332
333 {\em Good}
334 \begin{verbatim}
335 if (((a) && (b == 5)) || 
336     (c != 0)) {
337         return;
338 }
339 \end{verbatim}
340
341
342
343 \paragraph*{Fail Stop}
344 Because booting a basic Linux kernel results in over 1 million VM exits
345 catching silent errors is next to impossible. For this reason
346 ANY time your code has an error it should return -1, and expect the
347 execution to halt. 
348
349 This includes unimplemented features and unhandled cases. These cases
350 should ALWAYS return -1. 
351
352
353 \paragraph*{Function names}
354 Externally visible function names should be used rarely and have
355 unique names. Currently we have several techniques for achieving this:
356
357 \begin{enumerate}
358 \item \verb.#ifdefs. in the header file
359 \newline
360 When the V3 Hypervisor is compiled it defines the symbol
361 \verb.__V3VEE__. Any function that is not needed outside the Hypervisor
362 context should be inside an \verb.#ifdef __V3VEE__. block, this will make it
363 invisible to the host environment.
364
365 \item Static Functions
366 \newline
367 Any utility functions that are only needed in the .c file where they
368 are defined should be declared as static and not included in the
369 header file. You should make an effort to use static functions
370 whenever possible. 
371
372 \item \verb.v3_. prefix \newline Major interface functions should be
373   named with the prefix \verb.v3_. This allows easy understanding of
374   how to interact with the subsystems.  In the case that they need to
375   be externally visible to the host OS, make them unlikely to collide
376   with other functions.
377 \end{enumerate}
378
379 \paragraph*{Debugging Output}
380 Debugging output is sent through the host OS via functions in the
381 \verb.os_hooks. structure. These functions have various wrappers of the form
382 \verb.Print*., with \texttt{printf}-style semantics. 
383
384 Two functions of note are \verb.PrintDebug. and \verb.PrintError..
385
386 \begin{itemize}
387
388 \item PrintDebug:
389 \newline
390 Should be used for debugging output that will often be turned off
391 selectively by the VMM configuration.
392
393 \item PrintError
394 \newline
395 Should be used when an error occurs, this will never be optimized out
396 and will always print. 
397 \end{itemize}
398
399
400 \section{Code Submission}
401 \label{sec:submission}
402
403 To commit changes to the central repository they need to be exported
404 as a patch set that can be applied directly to a mainline. Both Git
405 and Mercurial contain functionality to allow developers to maintain
406 changes as a patch set. There are also a few options that make dealing
407 with patches easier.
408
409 \subsection{Palacios}
410
411 Git includes support for directly exporting local repository commits
412 as a patch set. The basic operation is for a developer to commit a
413 change to a local repository, and then export that change as a patch
414 that can be applied to another git repository. While this is
415 functionally possible, there are a number of issues. The main problem
416 is that it is difficult to fully encapsulate a new feature in a single
417 commit, and dealing with multiple patches that often overwrite each
418 other is not a viable option either. Furthermore, once a patch is
419 applied to the mainline, it will generate a conflicting commit that
420 will become present when the developer next pulls from the central
421 repository. This can result in both repositories getting out of
422 sync. It is possible to deal with this by manually re-basing the local
423 repository, but it is difficult and error-prone. 
424
425 This approach also does not map well when patches are being revised. A
426 normal patch will go through multiple revisions as it is reviewed and
427 modified by others. This often leads to synchronization issues as well
428 as errors with patch revisions. Ultimately it is the responsibility of
429 the developer to generate a patch that will apply cleanly to the
430 mainline.
431
432 For this reason most internal developers should seriously consider
433 {\em stacked git}. Stacked git is designed to make patch development
434 easier and less of a headache. The basic mode of operation is for a
435 developer to initialize a patch for a new feature and then continuously
436 apply changes to the patch. Stacked Git allows a developer to layer a
437 series of patches on top of a local git repository, without causing
438 the repository to unsync due to local commits. Basically, the
439 developer never commits changes to the repository itself but instead
440 commits the changes to a specific patch. The local patches are managed
441 using stack operations (push/pop) which allows a developer to apply
442 and unapply patches as needed. Stacked git also manages new changes to
443 the underlying git repository as a result of a pull operation and
444 prevents collisions as changes are propagated upstream. For instance
445 if you have a local patch that is applied to the mainline as a commit,
446 when the commit is pulled down the patch becomes empty because it is
447 effectively identical to the mainline. It also makes incorporating
448 external revisions to a patch easier. Stacked git is installed on {\em
449 newskysaw} in \verb./opt/vmm-tools/bin/. 
450
451 Brief command overview:
452 \begin{itemize}
453 \item \verb.stg init. -- Initialize stacked git in a given branch
454 \item \verb.stg new. -- create a new patch set, an editor will open
455 asking for a commit message that will be used when the patch is
456 ultimately committed.
457 \item \verb.stg pop. -- pops a patch off of the source tree.
458 \item \verb.stg push. -- pushes a patch back on to a source tree.
459 \item \verb.stg export. -- exports a patch to a directory as a file
460 that can then be emailed.
461 \item \verb.stg refresh. -- commits local changes to the patch set at
462 the top of the applied stack.
463 \item \verb.stg fold. -- Apply a patch file to the current
464 patch. (This is how you can manage revisions that are made by other developers).
465 \end{itemize}
466
467 You should definitely look at the online documentation to better
468 understand how stacked git works. It is not required of course, but if
469 you want your changes to be applied its up to you to generate a patch
470 that is acceptable to a core developer. Ultimately using Stacked git
471 should be easier than going it alone.
472
473
474 All patches should be emailed to Jack for inclusion in the
475 mainline. An overview of the organization is given in
476 Figure~\ref{fig:process}. You should assume that the first revision of
477 a patch will not be accepted, and that you will have to make
478 changes. Furthermore, the final form of the patch most likely will not
479 be exactly what you submitted. 
480
481  
482 \begin{figure}[t]
483 \begin{center}
484 \includegraphics[height=3.5in]{dev_chart.pdf}
485 \end{center}
486 \caption{Development organization}
487 \label{fig:process}
488 \end{figure}
489
490
491 \subsection{Kitten}
492
493 Writing code for Kitten follows essentially the same process as
494 Palacios. The difference is that the patches need to be emailed to the
495 Kitten developers. To send in a patch, you can just email it to the
496 V3Vee development list.
497
498
499 Also, instead of Stacked git you should use Mercurial patch
500 queues. This feature is enabled in your .hgrc file.
501 \begin{verbatim}
502 [extensions]
503 hgext.mq=
504 \end{verbatim}
505
506 Mercurial queues use the same stack operations as stacked git, however
507 it does not automatically handle the synchronization with pull
508 operations. Before you update from the central version of Kitten you
509 need to pop all of the patches, and then push them once the update is
510 complete.
511
512 Basically:
513 \begin{verbatim}
514 hg qpop -a
515 hg pull
516 hg update
517 hg qpush -a
518 \end{verbatim}
519
520
521 %Also, remember that Kitten is not a Northwestern project and is being
522 %developed by professional developers at Sandia National Labs. So keep
523 %in mind that you are representing Northwestern and the rest of the
524 %Palacios development group. We are collaborating with them because
525 %Kitten and the resources they have are very important for our research
526 %efforts. They are collaborating with us because they believe that
527 %Palacios might be able to help them. Therefore it is important that we
528 %continue to ensure that they see value in our collaboration. In plain
529 %terms, we need to make sure they think we're smart and know what we're
530 %doing. So please keep that in mind when dealing with the Kitten group.
531
532
533 \section{Networking}
534
535 Both the Kitten and GeekOS substrates on which Palacios can run
536 currently include drivers for two simple network cards, the NE2000,
537 and the RTL8139.  The Kitten substrate is acquiring an ever increasing
538 set of drivers for specialized network systems.   A lightweight
539 networking stack is included so that TCP/IP networking is possible
540 from within the host OS kernel and in Palacios.  
541
542 When debugging Palacios on QEMU, it is very convenient to add an
543 RTL8139 card to your QEMU configuration, and then drive it from within
544 Palacios.  QEMU can be configured to provide local connectivity to the
545 QEMU emulated machine, including bridging the emulated machine with a
546 physical network.  Local connectivity can be done with redirection, or
547 with a TAP interface.  For global connectivity, a TAP interface must
548 be used; it is bridged to a physical interface.
549
550 \section{Configuring the development host's QEMU network}
551
552 To get local connectivity with redirection, no networking changes on
553 the host are needed.  However, people usually want to use TAP-based
554 networking, which does require changes.  For one thing, TAP interfaces
555 can be inspected with tools like wireshark, which makes for much
556 easier debugging of network code.
557
558 In order to get QEMU networking to function, it is necessary to create
559 TAP interfaces, and, optionally, to bridge them to real networks.  A
560 development machine typically will have several TAP interfaces, and
561 more can be created.  Generally, each developer should have a TAP
562 interface of his or her own.  In the following, we will use our
563 development machine, newskysaw, as an example.
564
565 To set up a TAP interface on newskysaw, the following command is used:
566 \begin{verbatim}
567 /root/util/tap_create tapX
568 \end{verbatim}
569
570 When QEMU runs with a tap interface, it will use /etc/qemu-ifup to
571 bring up the interface.  On newskysaw, /etc/qemu-ifup looks like this:
572
573 \begin{verbatim}
574 #!/bin/bash
575 echo "Executing /etc/qemu-ifup - no external bridging"
576 echo "Bringing up $1 for bridged mode..."
577 NET=`echo $1 | cut -dp -f2` 
578 sudo /sbin/ifconfig $1 172.2${NET}.0.1 up
579 sleep 2
580 \end{verbatim}
581
582 The interface tap$N$ is brought up with the IP address 172.2$N$.0.1.
583 ifconfig will also create a routing rule that sends 172.2$N$.0.1/16
584 traffic to tap$N$.  The upshot is that if the code running in QEMU
585 uses an IP address in this network (for example: 172.2$N$.0.2), you
586 will be able to talk to it from newskysaw.  For example, from
587 newskysaw, if you ping 172.21.0.2, the packet (and ARP) will go out via
588 tap1.  The source address will appear to be 172.21.0.1.  The QEMU
589 machine will see these packets on its interface, and the software
590 controlling its interface can respond to 172.21.0.1.  
591
592 This form of networking is local to the machine.  You can also bridge
593 a TAP interface with a physical interface.  The result of this is that
594 a packet sent on it will be sent on the physical interface.  To do
595 this requires more effort (and is not set up by default on newskysaw).
596 As an example, consider that on newskysaw, the physical interface eth1
597 is connected to a private network switch to which the lab test
598 computers (v-test-amd, v-test-amd2, etc.) are connected.  To bridge,
599 for example, tap10, to this interface, you would do the following
600 (with root's help):
601 \begin{enumerate}
602 \item You need to bring up eth1 (ifconfig eth1 up {\em address}
603 netmask {\em mask}).  It is important that the address and mask you
604 choose are appropriate for the network eth1 is connected to.
605 \item You would bring up tap10 without an address:  /sbin/ifconfig
606 tap10 up
607 \item You would bridge tap10 and eth1:  /usr/sbin/brctl addif br0
608 tap10; /usr/sbin/brctl addif eth1.  This assumes that br0 was
609 previously created. 
610 \end{enumerate}
611
612 Bridging tap$N$ with eth1 will only work (where ``work'' means sending
613 a packet on the network and making the packet visible on localhost) if
614 the IP address in the code running in QEMU is set correctly.  This
615 means that it needs to be set to correspond to the network of eth1).  
616 For the newskysaw configuration, this is a 10-net address.
617
618
619 \subsection{Configuring Kitten}
620
621 Kitten needs to be explicitly configured to use networking. Currently
622 only a subset of the networking configurations are supported. To
623 enable an Ethernet network you should enable the following options:
624
625 \begin{itemize}
626 \item Enable TCP Support
627 \item Enable UDP Support
628 \item Enable socket API
629 \item Enable ARP support
630 \end{itemize}
631
632 The other options are not supported, and enabling them will probably
633 break the kernel compilation.
634
635 To allow Kitten to communicate with the QEMU network card you also
636 need to enable the appropriate device driver: \newline
637 \verb.NE2K Device Driver (rtl8139).
638
639 The driver then needs to be listed as a Kernel Command Line argument
640 in the {\em ISOIMAGE configuration}. To do this add
641 \verb.net=rtl819. to the end of the argument string.
642
643 Kitten currently does not support the dynamic assignment or IP
644 addresses at runtime. Because of this it is necessary to hardcode the
645 IP address into the device driver. For the rtl8139 network driver look
646 in the file {\em drivers/net/ne2k/rtl8139.c} for the function
647 \verb.rtl8139_init..
648
649 There should be a block of code that looks like the following:
650 \begin{verbatim}
651   struct ip_addr ipaddr = { htonl(0 | 10 << 24 | 0 << 16 | 2 << 8 | 16 << 0) }; 
652   struct ip_addr netmask = { htonl(0xffffff00) }; 
653   struct ip_addr gw = { htonl(0 | 10 << 24 | 0 << 16 | 2 << 8 | 2 << 0) };
654 \end{verbatim}
655
656 This sets the IP address as 10.0.2.16, netmask 255.255.255.0 and
657 gateway address 10.0.2.2. Change these assignments to match your configuration.
658
659
660 \paragraph*{Kitten as the Guest OS}
661
662 When running Kitten as a VM, the above applies except that you will
663 want to enable the {\em VMNET} device driver instead of the {\em rtl8139}.
664
665
666 \subsection{Running with networking}
667
668 \paragraph*{TAP Interface}
669 Running with a TAP interface provides either local or global
670 connectivity (depending on how the TAP interface is configured and/or
671 bridged).  From the perspective of the QEMU command line, both look
672 the same, however.  You simply add something like this to the command
673 line:
674 \begin{verbatim}
675 -net tap,ifname=tap2 -net nic,model=rtl8139
676 \end{verbatim}
677 The first \verb.-net. option indicates that you want to use a tap
678 interface, specifically \verb.tap2..   The second \verb.-net. option
679 specifies that this interface will appear to code in the QEMU machine
680 to be a network interface card of the specific model RTL8139.  Note
681 that this is a model for which we have a driver.  If tap2 were
682 bridged, we'd get global connectivity.  If not, we would just get
683 local connectivity.  
684
685
686 \paragraph*{Redirection}
687 It is also possible to achieve limited local connectivity even if you
688 have no TAP support on your development machine.  In redirection, QEMU
689 essentially acts as a proxy, translating TCP or other connections and
690 low-level packet operations on the network interface in the QEMU
691 machine.  For example, the following options will redirect the host's
692 9555 port to the QEMU machine's 80 port:
693 \begin{verbatim}
694 -net user -net nic,model=rtl8139  -redir tcp:9555:10.10.10.33:80
695 \end{verbatim}
696 The first \verb.-net. option indicates that we are using user-level
697 networking (proxying).  The second \verb.-net. option indicates that
698 this user-level network will appear in the QEMU machine as an RTL8139
699 network card.   The \verb.-redir. option indicates that connections on
700 localhost:9555 will be translated into equivalent packet exchanges on
701 the RTL8139 card in the QEMU machine.  However, we have to tell QEMU
702 which IP address and port to use on the QEMU machine's side.  This is
703 what the 10.10.10.33 address, and port 80 are.  In the example, if you
704 access port 9555 on localhost, say with:
705 \begin{verbatim}
706 telnet localhost 9555
707 \end{verbatim}
708 The packets that appear in the QEMU machine will be bound for
709 10.10.10.33, port 80.  Within the QEMU machine, your RTL8139 interface
710 had better then be up on that address. 
711
712 QEMU has many options to build up virtual or real networking. See
713 http://www.h7.dion.ne.jp/$\sim$qemu-win/HowToNetwork-en.html for more
714 information.
715
716
717 For more questions, talk to Jack, Lei, or Peter.
718
719 \end{document}