tutorial.html 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
  2. <html>
  3. <head>
  4. <title>OMNEST/OMNeT++ INET Framework - A Walkthrough</title>
  5. <meta name="Author" content="Andras Varga">
  6. <link href="opp.css" rel="stylesheet" type="text/css">
  7. </head>
  8. <body>
  9. <center style="background-color:#005e77; color:#ffffff; border:1px solid">
  10. <h1><font size="+2">INET Framework for OMNEST/OMNeT++</font></h1>
  11. <p><font size="+2"><i>A Guided Tour</i></font></p>
  12. </center>
  13. <h3>Contents</h3>
  14. <ul>
  15. <a href="#intro">Introduction</a><br>
  16. <a href="#launching">Launching the ARPTest simulation</a><br>
  17. <a href="#gui">The GUI at the first glance</a><br>
  18. <a href="#running">Let's run the simulation!</a><br>
  19. <a href="#restart">Over? You can restart it!</a><br>
  20. <a href="#linkcolors">OK, but what are those flashing link colors?</a><br>
  21. <a href="#inside">What is inside the hosts and routers?</a><br>
  22. <a href="#steps">Steps towards exploring ARP</a><br>
  23. <a href="#arpbegins">ARP begins</a><br>
  24. <a href="#requestpacket">The ARP Request packet</a><br>
  25. <a href="#pendingqueue">The pending queue</a><br>
  26. <a href="#arpcache">The ARP cache</a><br>
  27. <a href="#transmission">Transmission over Ethernet</a><br>
  28. <a href="#arpreply">ARP Reply</a><br>
  29. <a href="#procreply">Processing the ARP Reply</a><br>
  30. <a href="#syn">The client's SYN gets to the server</a><br>
  31. <a href="#discovering">Following ARP from the documentation</a><br>
  32. <a href="#conclusion">Conclusion</a><br>
  33. </ul>
  34. <a name="intro"/><h3>Introduction</h3>
  35. <p>
  36. The purpose of this tutorial is to get you familiar with the INET framework,
  37. a simulation model suite for TCP/IP and Internet-related protocols,
  38. written for the OMNeT++/OMNEST simulation environment.
  39. </p>
  40. <p>
  41. This tutorial is based on the ARPTest example simulation. To try it, you need
  42. a binary (executable) version of this simulation. The easiest is to download
  43. and install the Windows demo for INET. Alternatively (or if your platform is
  44. Linux or some other OS), you may download and compile the OMNeT++ and
  45. INET source packages.
  46. </p>
  47. <a name="launching"/><h3>Launching the ARPTest simulation</h3>
  48. <p>
  49. When you start the INET demo package (if you installed the Windows demo, you'll
  50. find the INET demo on the Start Menu; if you compiled INET yourself, find and
  51. run Examples/rundemo[.bat]), you'll see a window like this:
  52. </p>
  53. <p class="img"><a href="images/rundemo2.gif"><img src="thumbs/rundemo2.gif"/></a></p>
  54. <p>
  55. Click the button which says "ARP Test" on the left -- a description of the model
  56. should appear in the main window. Click the large "Launch" button on the bottom,
  57. and the ARP simulation model should start.
  58. </p>
  59. <a name="gui"/><h3>The GUI at the first glance</h3>
  60. <p>
  61. The picture you see will look like this.
  62. </p>
  63. <p class="img"><a href="images/arptest.gif"><img src="thumbs/arptest.gif"/></a></p>
  64. <p>
  65. The window in the back is the main OMNeT++/OMNEST window, closing it will exit
  66. the program. The large text window on the right side displays log messages
  67. from the simulation model (output from <tt>ev &lt;&lt;</tt> statements
  68. in the C++ code will write there), and the left-hand displays the model
  69. objects in a foldable tree form. There's a 3-line status bar at the top
  70. (we'll look at it later), and a toolbar to access frequently used functions
  71. of the GUI.
  72. </p>
  73. <p>
  74. The front window displays the simulation model. If you happen to accidentally
  75. close it, you can open it again by clicking the "Inspect network" toolbar icon.
  76. </p>
  77. <p class="img"><img src="images/tb-inspectnet.gif"/></p>
  78. <a name="running"/><h3>Let's run the simulation!</h3>
  79. <p>
  80. Click on the "Run" button on the main window's toolbar, or hit F5.
  81. </p>
  82. <p class="img"><img src="images/tb-run.gif"/></p>
  83. <p>
  84. First you should see messages labelled "autoconf" being exchanged by the nodes,
  85. as part of the Ethernet model autoconfiguration process:
  86. </p>
  87. <p class="img"><img src="images/autoconfmsg.gif"/></p>
  88. <p>
  89. Then, at about 1ms simulation time, autoconfig finishes, and simulating
  90. the network operation begins. In the model scenario, the client computer
  91. (laptop icon) opens a TCP connection to the server (server icon) at 1s,
  92. and starts sending a large data stream. The server will just echo the data
  93. sent by the client.
  94. </p>
  95. <p>
  96. Since the underlying network is Ethernet, before being able to send
  97. the TCP SYN packet the client has to perform an ARP request
  98. to learn the MAC address for the default router. After some more messaging,
  99. the TCP connection will be established and data transfer begins.
  100. </p>
  101. <p>
  102. We'll explore these happenings in the network later, but for now just
  103. sit back and watch the simulation. You can make the animation faster
  104. or slower by adjusting the slider at the top of the network window.
  105. </p>
  106. <p class="img"><img src="images/animspeed.gif"/></p>
  107. <p>
  108. You can stop the simulation by clicking the red "STOP" traffic
  109. sign icon (or by hitting F8), and resume it ("Run" icon or F5).
  110. </p>
  111. <p class="img"><img src="images/tb-run.gif"/></p>
  112. <p>The "Fast" icon or (F6) will turn off message animation and
  113. update the graphics only every 10 events or so (the exact number
  114. can be configured in the Simulation Options dialog,
  115. Options menu, accessible from via the toolbar as well). The "Express"
  116. icon provides the highest speed: it turns off all GUI functions while the
  117. simulation is running, even writing to the log is turned off.
  118. Express mode updates the display every 1000 events or so
  119. (also configurable in Simulation Options).
  120. </p>
  121. <p class="img"><img src="images/dlg-simoptions1.gif"/></p>
  122. <p>
  123. In Express mode you can only stop the simulation by clicking the
  124. "Big Red STOP Button" (see below). Simulation speed in Express mode may
  125. significantly depend on the state of the "auto update inspectors" checkbox.
  126. </p>
  127. <p class="img"><img src="images/dlg-stopexpress.gif"/></p>
  128. <p>
  129. You can read the speed of the simulation on the 3rd line of the main
  130. window status bar. Ev/sec tells you how many events your CPU crunches
  131. in a second -- this depends on the strength of your hardware, on the
  132. amount processing (C++ code) to be done for an average event
  133. (refer to the <tt>handleMessage(cMessage *)</tt> functions in the model
  134. source), and on the run mode (Normal, Fast or Express). It is not unusual
  135. for the Express mode to be 100-200 times faster than Fast mode.
  136. </p>
  137. <p class="img"><img src="images/speedbar.gif"/></p>
  138. <p>
  139. The other two readings on that status bar are simsec/sec (how many simulated
  140. seconds the model progresses in one "real" second) and ev/simsec (how many events
  141. your model contains per simulated second). The simsec/sec value is useful
  142. for estimating how long your simulation will take. Ev/simsec is independent
  143. of whether you use Normal, Fast or Express mode, and it only depends
  144. on the nature and size of your model (ATM cell-level simulations will have
  145. a few magnitudes higher ev/simsec values than call center simulations.)
  146. </p>
  147. <a name="restart"/><h3>Over? You can restart it!</h3>
  148. <p>
  149. While in Expess mode, you'll probably get the following dialog after a while:
  150. </p>
  151. <p class="img"><img src="images/dlg-nomoreevents.gif"/></p>
  152. <p>
  153. "No more events" is one way a simulation can terminate normally
  154. (i.e. not with an error). It means that there's nothing more to
  155. simulate -- in our simulation this occurs when the client has
  156. successfully closed the TCP connection and finished its operation,
  157. and there're no more packets underway and no timers running anywhere
  158. in the whole model.
  159. </p>
  160. <p>
  161. Other simulations may end with the "Simulation time limit reached -- simulation stopped"
  162. message which means that the simulation time configured in <tt>omnetpp.ini</tt>
  163. has been reached. (For completeness: other possibilities include
  164. "CPU time limit reached," and "Simulation stopped with endSimulation()"
  165. meaning that some component in the model called the <tt>endSimulation()</tt>
  166. C++ function -- for example when it detects that desired statistical accuracy
  167. has been reached).
  168. </p>
  169. <p>
  170. In both cases you can restart the simulation using the "Rebuild network"
  171. command on the Simulate menu. In fact, you can do that any time to start over.
  172. </p>
  173. <p class="img"><img src="images/m-restart.gif"/></p>
  174. <p>
  175. Note that some simulation models (none in INET, hopefully) may crash when
  176. you restart the simulation. This is usually due to badly written destructor
  177. code in the model C++ sources.
  178. </p>
  179. <p>
  180. Now that we've dealt with the basics, we can go back to our ARPTest network model.
  181. </p>
  182. <a name="linkcolors"/><h3>OK, but what are those flashing link colors?</h3>
  183. <p>
  184. You've probably seen something like this:
  185. </p>
  186. <p class="img"><a href="images/linkcolors.gif"><img src="thumbs/linkcolors.gif"/></a></p>
  187. <p>
  188. If a link is yellow, that means the node is transmitting on the link.
  189. If a node has collided and while it's backing off, the link is colored
  190. red. Link coloring has been programmed as part of the Ethernet model
  191. (the <tt>EtherMAC</tt> module).
  192. </p>
  193. <p>
  194. The wandering red frame (around <tt>router5</tt> on the screenshot)
  195. has nothing to do with Ethernet -- it simply indicates the location of the
  196. current/next event in the model, as dictated by the basic
  197. event processing algorithm of discrete event simulation.
  198. </p>
  199. <a name="inside"/><h3>What is inside the hosts and routers?</h3>
  200. <p>
  201. I bet you've found it out already, but here it is for the record: you
  202. can double-click on a node (client, server, router) to see its internals.
  203. </p>
  204. <p class="img">
  205. <a href="images/client.gif"><img src="thumbs/client.gif"/></a>
  206. <a href="images/server.gif"><img src="thumbs/server.gif"/></a>
  207. <a href="images/router.gif"><img src="thumbs/router.gif"/></a>
  208. </p>
  209. <p>
  210. Bottom up, the client model contains:
  211. </p>
  212. <ul>
  213. <li>an Ethernet interface (<tt>eth[0]</tt>);
  214. <li>network layer (<tt>networkLayer</tt>, a further double-click will
  215. reveal it's basically IP);
  216. <li>a pinger application (<tt>pingApp</tt>, defunct in this model);
  217. <li>UDP model (<tt>udp</tt>), also not used in the ARPTest model
  218. (no applications configured);
  219. <li>TCP model (<tt>tcp</tt>). The number of connections in various
  220. TCP states are displayed in blue above the icon;
  221. <li>an application model (<tt>tcpApp[0]</tt>)
  222. <li>the <tt>routingTable</tt> module contains, well, the routing table
  223. (number of unicast+multicast routes displayed above the icon)
  224. <li><tt>blackboard</tt> is there for future extensions (it will be used
  225. in in the future as a storage place for various parameters and
  226. state variables different protocol layers need to share)
  227. </ul>
  228. <p>
  229. A router is similar, but obviously it has nothing from L3 up. (You also see
  230. no routing protocols -- routing is static in this model.)
  231. </p>
  232. <p>
  233. If you further double-click on these components (TCP, UDP, etc.),
  234. most of the time you'll get an <i>inspector window</i> like this.
  235. </p>
  236. <p class="img"><a href="images/tcpmain.gif"><img src="thumbs/tcpmain.gif"/></a></p>
  237. <p>
  238. It means that the component is implemented in C++, and cannot be subdivided
  239. any further (it is a <i>simple module</i>, as opposed to <i>compund modules</i>
  240. which are composed of submodules). The inspector window exposes the internals
  241. of the module and we'll use it a lot later in this walkthrough, but let's just leave it
  242. for now.
  243. </p>
  244. <p>
  245. The ARPTest simulation is quite complex in that it has TCP, IP, ARP
  246. and Ethernet in it. In this walkthrough we'll go for ARP, but the steps you learn
  247. will be useful for exploring other protocols as well.
  248. </p>
  249. <a name="steps"/><h3>Steps towards exploring ARP</h3>
  250. <p>
  251. If we are interested in ARP, it's a bit annoying that we have to wade
  252. throught all those Ethernet autoconfig messages until we get to the first
  253. ARP request at 1s. Luckily, you can use the "Run until..." function to
  254. fast-forward past them.
  255. </p>
  256. <p>
  257. Restart the simulation (Simulate|Rebuild network), then click the
  258. "Run until..." icon on the toolbar.
  259. </p>
  260. <p class="img"><img src="images/tb-rununtil.gif"/></p>
  261. <p>
  262. We know autoconfig finishes at around 1ms simulation time and first ARP
  263. request is around 1s, so you can safely enter 2ms in the Run until dialog.
  264. </p>
  265. <p class="img"><img src="images/dlg-rununtil.gif"/></p>
  266. <p>
  267. After clicking OK, the simulation progresses past the autoconfig period in no time.
  268. Then, both the red frame around the laptop icon (the next event marker) and the
  269. top line of the status bar will show that the next event is going to take place
  270. in the client PC, at t=1s simulation time. Opening "scheduled-events" in the
  271. object tree (left side of main window) will also reveal that we have only
  272. one event, and it is going to occur in the client application (<tt>client.tcpApp[0]</tt>).
  273. </p>
  274. <p class="img"><a href="images/arptest-1s.gif"><img src="thumbs/arptest-1s.gif"/></a></p>
  275. <p>
  276. Pressing F4 (single-step) repeatedly will take you though the next events.
  277. You'll see as the application tells TCP to open a connection, as TCP obeys
  278. and sends a SYN (TCP connection request) packet, as IP encapsulates SYN into
  279. an IP datagram, and sends it down to the Ethernet interface. We could actually
  280. peek into those messages and find out about TCP ports and IP addresses and
  281. lots of interesting things, but let's resist the temptation and concentrate
  282. on ARP.
  283. </p>
  284. <p class="img">
  285. <a href="images/cli-activeopen.gif"><img src="thumbs/cli-activeopen.gif"/></a>
  286. <a href="images/cli-sendsyn.gif"><img src="thumbs/cli-sendsyn.gif"/></a>
  287. <a href="images/cli-encapsyn.gif"><img src="thumbs/cli-encapsyn.gif"/></a>
  288. </p>
  289. <p>
  290. You probably noticed that the IP datagram has disappeared in the Ethernet
  291. interface. This indicates that <tt>eth[0]</tt> is a compound module,
  292. and if you open it (double-click), you'll find that it consists of 3
  293. submodules (<tt>arp</tt>, <tt>encap</tt> and <tt>mac</tt>) and the IP datagram
  294. is sitting on the input of the <tt>arp</tt> module.
  295. </p>
  296. <p class="img"><a href="images/ethinterface.gif"><img src="thumbs/ethinterface.gif"/></a></p>
  297. <p>
  298. Here we are at the beginning of the interesting part. You may actually
  299. take a note that we are at event #94 (it's displayed in the top line of the
  300. main window status bar) so that next time you can quickly get here
  301. using the "Run until..." dialog (it can stop either at a simulation time or at
  302. an event number -- or if you enter both, it'll stop at whichever comes first.)
  303. </p>
  304. <a name="arpbegins"/><h3>ARP begins</h3>
  305. <p>
  306. The <tt>arp</tt> module will tell us what's going on by writing a log. These
  307. log messages (output via <tt>ev &lt;&lt;</tt> from the C++ code) will appear in the
  308. main text window, but that'll soon be useless because other modules
  309. dump their output there too. Luckily, we can open a window which
  310. contains <tt>arp</tt>'s messages only. Right-click on the <tt>arp</tt> module, and
  311. select "Module output" from the context menu. A new text window, titled
  312. "(ARP)arpTest.client.eth[0].arp" will appear.
  313. </p>
  314. <p class="img"><a href="images/arp-ctxmenu.gif"><img src="thumbs/arp-ctxmenu.gif"/></a></p>
  315. <p>
  316. Then press F4 (or click the "Step" icon on the main window's toolbar)
  317. to perform the next event and let <tt>arp</tt> process the datagram.
  318. You'll see that:
  319. </p>
  320. <ul>
  321. <li>the datagram disappers inside <tt>arp</tt>;
  322. <li><tt>arp</tt> sends an ARP request
  323. <li>the <tt>arp</tt> text window comments what happened
  324. </ul>
  325. <p>
  326. At this point your screen will look something like this.
  327. </p>
  328. <p class="img"><a href="images/arp-req-sent.gif"><img src="thumbs/arp-req-sent.gif"/></a></p>
  329. <p>
  330. ARP maps L3 addresses (IP address) to L2 addresses (Ethernet MAC address).
  331. It uses a lookup table (ARP cache) for this purpose, but if an IP address
  332. is not found in the table, ARP has to ask around by sending a broadcast
  333. ARP Request. That's what we have seen here. Let's check it in detail!
  334. </p>
  335. <a name="requestpacket"/><h3>The ARP Request packet</h3>
  336. <p>
  337. Double-click on the ARP request packet to open its inspector window,
  338. then click the "Fields" tab.
  339. </p>
  340. <p class="img"><a href="images/arpreq-fields.gif"><img src="thumbs/arpreq-fields.gif"/></a></p>
  341. <p>
  342. The "Fields" page shows the contents of the ARP packet: source MAC address,
  343. destination MAC address, source IP address, destination IP address.
  344. The source MAC and IP addresses are our own addresses (in the model,
  345. autoconfigured MAC addresses begin with "0A AA"); the destination IP
  346. address contains the address to be resolved, and the destination MAC
  347. address is empty because that's what we're requesting.
  348. </p>
  349. <p>
  350. The ARP packet is a single C++ object, with its class <tt>ARPPacket</tt>
  351. having an <tt>int _opcode</tt> data member, <tt>int opcode()</tt> and
  352. <tt>setOpcode(int)</tt> functions, and similar data and functions for the
  353. other data fields as well. However, the class was not hand-coded but
  354. generated from a <tt>.msg</tt> file, which has a very concise format:
  355. </p>
  356. <pre class="src">
  357. <i>// file: ARPPacket.msg</i>
  358. message ARPPacket
  359. {
  360. fields:
  361. int opcode enum(ARPOpcode);
  362. MACAddress srcMACAddress;
  363. MACAddress destMACAddress;
  364. IPAddress srcIPAddress;
  365. IPAddress destIPAddress;
  366. };
  367. </pre>
  368. <p>
  369. Definition via a <tt>.msg</tt> file not only saved a lot of programming effort,
  370. but it was also necessary for the packet's content to be displayed in the
  371. "Fields" page.
  372. </p>
  373. <p>
  374. So far so good, but how do lower layers (Ethernet) know which MAC address
  375. the ARP request should be sent to? That's not part of the packet!
  376. </p>
  377. <p>
  378. This information is attached to the packet in small data structure called
  379. "control info". Control info is also a C++ object and similarly to packets,
  380. its C++ source is generated from <tt>.msg</tt> files.
  381. You can view the contents of the control info attached to this ARP packet
  382. by clicking the "Control info" tab in the window.
  383. </p>
  384. <pre class="src">
  385. <i>// file: EtherCtrl.msg</i>
  386. class EtherCtrl
  387. {
  388. fields:
  389. MACAddress src; // used with ETHCTRL_DATA
  390. MACAddress dest; // used with ETHCTRL_DATA
  391. int etherType; // used with ETHCTRL_DATA and EthernetIIFrame
  392. int ssap; // used with ETHCTRL_DATA and EtherFrameWithLLC
  393. int dsap; // used with ETHCTRL_DATA/REGISTER_DSAP/DEREGISTER_DSAP
  394. int pauseUnits; // used with ETHCTRL_PAUSE
  395. };
  396. </pre>
  397. <p class="img"><a href="images/arpreq-ctrlinfo.gif"><img src="thumbs/arpreq-ctrlinfo.gif"/></a></p>
  398. <p>
  399. It says that source MAC address is not specified (all zero -- in this case
  400. it'll be filled in by Ethernet) and the destination MAC address is all FF's
  401. (the Ethernet broadcast address). SSAP and DSAP are unused here (they're for
  402. 802.3 frame type but we use Ethernet II frames in this simulation), and pauseUnits
  403. has also no significance (only used for telling MAC to send PAUSE frames).
  404. etherType is set to zero here. <!-- FIXME set etherType to proper value -->
  405. </p>
  406. <a name="pendingqueue"/><h3>The pending queue</h3>
  407. <p>
  408. While ARP resolution is pending, IP datagrams which wait for it have to be
  409. buffered somewhere. There's a <tt>"q=1"</tt> label next to the <tt>arp</tt>
  410. icon -- if you double-click on it (on the <tt>"q=1"</tt> text, not on the icon!),
  411. an inspector window will open displaying the queue of buffered datagrams.
  412. </p>
  413. <p class="img">
  414. <img src="images/arp-icon.gif"/>
  415. <a href="images/arp-queue.gif"><img src="thumbs/arp-queue.gif"/></a>
  416. </p>
  417. <p>
  418. You may double-click on the SYN line again, to view the datagram's contents
  419. (source and destination IP address, TTL, encapsulated protocol, etc.)
  420. in an inspector window, much the same way as it worked with the ARP request
  421. packet. One "extra" is worth mentioning, however: on the "General" page
  422. you'll find the "Encapsulated message" button which will take you to the
  423. TCP packet in the datagram -- and you can continue exploring the
  424. TCP header fields.
  425. </p>
  426. <p class="img"><a href="images/ipdgram.gif"><img src="thumbs/ipdgram.gif"/></a></p>
  427. <a name="arpcache"/><h3>The ARP cache</h3>
  428. <p>
  429. You've noticed the blue letters "1 cache entries, send req:1 repl:0 fail:0"
  430. above the <tt>arp</tt> icon, and wondering what the ARP cache contains right now.
  431. No problem, we can check it out!
  432. </p>
  433. <p>
  434. Double-click the <tt>arp</tt> icon (or right-click on it and select "As object..."
  435. from the context menu). An inspector window will open, with several pages like the
  436. message inspector -- you'll need the "Contents" page now.
  437. </p>
  438. <p class="img">
  439. <a href="images/arp-ctx-asobj.gif"><img src="thumbs/arp-ctx-asobj.gif"/></a>
  440. <a href="images/arp-contents.gif"><img src="thumbs/arp-contents.gif"/></a>
  441. </p>
  442. <p>
  443. The list reveals that we have several counters here for sent and received ARP requests
  444. etc, a queue for IP datagrams pending ARP resolution -- and also the ARP cache.
  445. Double-click on the <tt>arpCache</tt> line. Another inspector will open, this time
  446. the following one:
  447. </p>
  448. <p class="img">
  449. <a href="images/arpcache1.gif"><img src="thumbs/arpcache1.gif"/></a>
  450. <a href="images/arpcache2.gif"><img src="thumbs/arpcache2.gif"/></a>
  451. </p>
  452. <p>
  453. First of all, you'll notice that the cache contains what you'd probably expect:
  454. one entry, IP address 10.0.0.1, pending resolution. (The "Detailed info" line
  455. on the first page would show only the first three entries, hence the second page
  456. -- it is also easier to browse if there're many entries in the cache.)
  457. </p>
  458. <p>
  459. Second, if you're familiar with C++, you'll notice that the ARP cache is
  460. implemented with a standard STL <tt>map</tt>. The <i>key</i> in the map
  461. is <tt>class IPAddress</tt> and the <i>value</i> is
  462. <tt>struct ARPCacheEntry</tt> (or rather, a pointer to it). If you'd be
  463. looking in the C++ code to find out what makes STL map able appear like
  464. this in the GUI, you'd find only one extra statement:
  465. <tt>WATCH_PTRMAP(arpCache)</tt>, plus <tt>&lt;&lt;</tt> operators
  466. defined for <tt>IPAddress</tt> and <tt>ARPCacheEntry</tt>. That's all
  467. it takes -- the rest is up to the simulation environment.
  468. </p>
  469. <p>
  470. But let us follow the ARP request further.
  471. </p>
  472. <a name="transmission"/><h3>Transmission over Ethernet</h3>
  473. <p>
  474. With a further F4 key (or "Step" toolbar button), <tt>encap</tt>
  475. will encapsulate the ARP request into an Ethernet II frame.
  476. You can verify by double-clicking
  477. on the message and opening an inspector that the destination address
  478. in the frame has been set to broadcast (all FF's). The source address
  479. is still all zeros, it'll be set by MAC. On the "General" page you
  480. can verify that the ARP packet has been indeed encapsulated in an
  481. Ethernet frame. (You can close all other inspector windows now,
  482. except the <tt>arp</tt> text window.)
  483. </p>
  484. <p>
  485. The next F4 key, the frame gets into <tt>mac</tt>'s buffer. (Note that
  486. "q=0" has changed into "q=1" -- if you double-click on the text,
  487. you'll actually see the queue where the frame is buffered.) But why is it
  488. not transmitted immediately? If you peek into the log in the main
  489. window, the solution is there: it says <tt>"wait IFG first"</tt>. IFG stands for
  490. Inter-Frame Gap in the Ethernet standards, and it is the time needed
  491. by older Ethernet hardware to switch from receive (carrier sense)
  492. mode to transmit mode. In the model, end of the IFG is marked with
  493. an event which can also be seen in "scheduled-events".
  494. </p>
  495. <p class="img"><a href="images/wait-ifg.gif"><img src="thumbs/wait-ifg.gif"/></a></p>
  496. <p>
  497. Hitting F4 again makes <tt>mac</tt> process the EndIFG event, and
  498. start transmitting the frame. The icon and also the connection arrow
  499. turns yellow, indicating that a transmission is going on.
  500. </p>
  501. <p class="img">
  502. <img src="images/mac-tx.gif">
  503. <img src="images/arptest-startrx.gif">
  504. </p>
  505. <p>
  506. Most actions we've seen so far, from <tt>app</tt>'s TCP Active OPEN
  507. command to encapsulation of the ARP packet into an Ethernet frame,
  508. took zero simulation time. We assumed that -- compared
  509. to other time periods occurring in the model -- they take such a short
  510. time that it is not worth modelling explicitly (they wouldn't make
  511. a difference in the simulation results).
  512. </p>
  513. <p>
  514. However, the time an Ethernet frame transmission takes <i>is</i>
  515. interesting to us, and so is propagation delay on the cable (the cable may be
  516. long) -- so in fact we have four discrete points of time, and we need
  517. four simulation events to model them:
  518. </p>
  519. <ul>
  520. <li>transmitter starts transmitting the frame
  521. <li>beginning of frame reaches receiver (start receiving)
  522. <li>transmitter completes transmission
  523. <li>end of frame reaches receiver (end of reception)
  524. </ul>
  525. <p>
  526. The message which you've seen <tt>mac</tt> having sent (the Ethernet
  527. frame message object in fact) represents the <i>beginning</i> of the frame.
  528. End of transmission is an event you'll find in "scheduled-events", it is
  529. a self-message scheduled by the transmitting <tt>mac</tt>:
  530. </p>
  531. <p class="img"><img src="images/endtx-event.gif"></p>
  532. <p>
  533. The "start of reception" event will occur in the receiver of course,
  534. and will be represented by the arrival of the Ethernet frame message
  535. object. You can see in the first line of the status bar, in the
  536. "next event" field that it's going to be the next event, and will take
  537. place in <tt>router1</tt>'s second interface (<tt>eth[1]</tt>).
  538. </p>
  539. <p class="img"><img src="images/statusbar-startrx.gif"></p>
  540. <p>
  541. Open the graphics for this Ethernet interface by double-clicking
  542. on <tt>router1</tt>, then on <tt>eth[1]</tt> (just follow the red frames
  543. which indicate the location of the next event).
  544. </p>
  545. <p>
  546. Pressing F4 once more makes this <tt>mac</tt> process the event and
  547. go into "receiving" state -- its icon will also turn blueish to indicate
  548. it. From the frame length and the data rate <tt>mac</tt> has calculated
  549. the time the last bit will arrive (end reception), and scheduled an
  550. event accordingly (you can verify it in the "scheduled-events" list).
  551. </p>
  552. <p class="img">
  553. <a href="images/router1-rx.gif"><img src="thumbs/router1-rx.gif"/></a>
  554. <a href="images/router1eth1-rx.gif"><img src="thumbs/router1eth1-rx.gif"/></a>
  555. </p>
  556. <p>
  557. During the next few F4 keypresses, the client laptop <tt>mac</tt> will
  558. finish transmission, the <tt>router1</tt>'s <tt>mac</tt> will complete
  559. reception, and it will pass up the frame to <tt>encap</tt> which in turn will
  560. rip the Ethernet header and pass up the ARP Request packet to <tt>arp</tt>.
  561. </p>
  562. <a name="arpreply"/><h3>ARP Reply</h3>
  563. <p>
  564. In the next event, <tt>arp</tt> will process the request. Hit F4.
  565. If you had <tt>arp</tt>'s module output window open, it'll show what happened.
  566. </p>
  567. <p class="img"><a href="images/arp-reply-sent.gif"><img src="thumbs/arp-reply-sent.gif"/></a></p>
  568. <p>
  569. ARP took the source IP address and source MAC address, and added them
  570. to its own ARP cache. Then it had to determine whether to reply to the
  571. request. The destination IP address was did not belong to the router;
  572. however, proxy ARP is turned on (you can verify this in the ARP module's
  573. inspector window, "Params" page -- see below). With proxy ARP, the
  574. router has to reply to the ARP Request if it can route the address, and
  575. send back its own MAC address. That's what happened here.</p>
  576. <p class="img"><a href="images/arp-params.gif"><img src="thumbs/arp-params.gif"/></a></p>
  577. <p>
  578. While ARP processed the request packet, you probably saw a red flashing
  579. arrow, like this:
  580. </p>
  581. <p class="img"><a href="images/arp-outputport.gif"><img src="thumbs/arp-outputport.gif"/></a></p>
  582. <p>
  583. It indicates ARP asking the routing table component whether the address
  584. 10.0.0.1 is routable, as part of the proxy ARP process. (More precisely,
  585. ARP asks which is the output port for that address -- if the reply is "none"
  586. it means the address is not routable). In the C++ code, what you've seen
  587. was the animation of a direct method call -- ARP module's C++ code
  588. invoked the <tt>int outportNo(IPAddress)</tt> method of the routing table
  589. object (class <tt>RoutingTable</tt>) with 10.0.0.1 as argument.
  590. It was the simulation environment which made this request visible
  591. in the simulation GUI.
  592. </p>
  593. <p>
  594. The answer was probably "routable", because <tt>arp</tt> sent a reply.
  595. You can verify by opening the ARP Reply packet: source and destination
  596. fields have been swapped, and the now-source (formerly destination)
  597. MAC address field contains the MAC address of this interface.
  598. </p>
  599. <p class="img"><a href="images/arpreply-fields.gif"><img src="thumbs/arpreply-fields.gif"/></a></p>
  600. <p>
  601. The next few F4 keypresses will transmit the ARP Reply over Ethernet
  602. back to the client's ARP.
  603. </p>
  604. <a name="procreply"/><h3>Processing the ARP Reply</h3>
  605. <p>
  606. Results of processing the ARP reply can be seen in the next screenshot.
  607. The MAC address of the router's Ethernet interface has been added to the
  608. ARP cache. ("age=0" in the cache entry is needed because after certain
  609. period of inactivity [120s configured here] the entry is considered
  610. obsolete and gets thrown out of the cache. In fact, the entry really stores
  611. last update time, but age is more practical when displayed.)
  612. The datagram carrying the TCP SYN segment that was wainting in the queue
  613. has been sent down to Ethernet for transmission.
  614. </p>
  615. <p class="img"><a href="images/arp-resolved.gif"><img src="thumbs/arp-resolved.gif"/></a></p>
  616. <p>
  617. You can even verify that the control info attached to the datagram
  618. indeed contains the MAC address just received via ARP.
  619. </p>
  620. <p class="img"><a href="images/syn-ctrlinfo.gif"><img src="thumbs/syn-ctrlinfo.gif"/></a></p>
  621. <a name="syn"/><h3>The client's SYN gets to the server</h3>
  622. <p>
  623. Now that ARP has done its job, you can hit F5 (or click "Run" on the main
  624. window toolbar), sit back and watch as the SYN packet makes its way to the
  625. server. It is still not any easy job for SYN, because this example
  626. network is full of distinct Ethernet segments, so it'll take still
  627. a series of ARP requests and replies get to the server.
  628. </p>
  629. <p>
  630. You'd maybe think that the remote TCP's response, SYN+ACK will have easier
  631. job on the way back, because SYN paved the way for it. But not really:
  632. it was the IP addresses of routers initiating ARP resolutions that
  633. made it into the ARP caches, and not the client's IP address 10.0.0.10.
  634. So the series of ARP request/replies repeats as SYN+ACK progresses
  635. back to the client computer.
  636. </p>
  637. <p>
  638. But further packets really don't have to go through ARP resolution
  639. any more. If you kept the client's <tt>arp</tt> output window open,
  640. you can see it fill with reports about cache hits:
  641. </p>
  642. <p class="img"><a href="images/arp-log.gif"><img src="thumbs/arp-log.gif"/></a></p>
  643. <a name="discovering"/><h3>Following ARP from the documentation</h3>
  644. <p>
  645. In the above guided tour, you've seen how to run a simulation model,
  646. view logs, examine packet contents, look at queues, and explore internal
  647. tables and variables. But what do you do if something is still not
  648. clear? If log messages do not give enough information to find out how
  649. the thing works?
  650. </p>
  651. <p>
  652. The answer is: <i>documentation</i>. The INET framework's documentation
  653. essentially contains the <i>full source code (!!!)</i> -- in an organized,
  654. readable, searchable and cross-referenced manner.
  655. If you have the INET Framework demo, then you probably have the full
  656. documentation as well, in the <tt>Documentation/</tt> folder. You can
  657. open it from the demo application too:
  658. </p>
  659. <p class="img"><a href="images/rundemo-doc.gif"><img src="thumbs/rundemo-doc.gif"/></a></p>
  660. <p>
  661. When you open it, you should see in your browser something like the picture
  662. below. I marked the possible starting points for exploring ARP. Basically,
  663. if you know what you're looking for (we know now), just click <tt>ARP</tt>
  664. on the "All modules" list on the left (or click "modules, simple" link
  665. on the top of that frame, and choose from the shorter list). If you don't
  666. know, you can start from an example network (here: <tt>ARPTest</tt>),
  667. and click on submodules until you find what you're looking for.
  668. </p>
  669. <p class="img"><a href="images/doc-frontpage.gif"><img src="thumbs/doc-frontpage.gif"/></a></p>
  670. <p>
  671. ARP's page itself doesn't tell us too much about the ARP protocol or this
  672. particular implementation (this may improve in the future),
  673. but it does tell that it's employed as part of <tt>EthernetInterface</tt>
  674. (and by following that link you can learn where, in turn,
  675. <tt>EthernetInterface</tt> is used, etc.) and also lists the parameters
  676. and gates (or ports) (further below, not shown in the screenshot).
  677. It also contains its NED definition (also further below), and what's important
  678. for us now, there's a link to the C++ documentation.
  679. </p>
  680. <p class="img"><a href="images/doc-arp.gif"><img src="thumbs/doc-arp.gif"/></a></p>
  681. <p>
  682. Click the "C++ documentation" link. The C++ documentation that emerges
  683. has been generated from commented C++ source by the Doxygen tool, with its
  684. <tt>INLINE_SOURCES</tt> option turned on. The sheer size and detail of the
  685. C++ documentation might be overwhelming to you, but not if you know
  686. where to start looking.
  687. </p>
  688. <p>
  689. There are two good starting points: the <tt>handleMessage(cMessage*)</tt> member
  690. function, and the data structure used in the module (Doxygen lists data members
  691. under the <i>Protected</i> (or <i>Public</i> or <i>Private</i>) <i>Attributes</i>
  692. heading). <tt>handleMessage(cMessage*)</tt> is the function that gets invoked
  693. whenever a message (packet, etc) arrives at the module or a timer goes off
  694. (a message scheduled by the module itself comes back).
  695. </p>
  696. <p class="img"><a href="images/doxy-arpclass.gif"><img src="thumbs/doxy-arpclass.gif"/></a></p>
  697. <p>
  698. As a rule of thumb: whatever large number of functions you see in the
  699. documentation, always click at <tt>handleMessage()</tt> first. If the
  700. module code was well written, it'll lead you from there. Let's do that with
  701. <tt>ARP</tt> as well.
  702. </p>
  703. <p class="img"><a href="images/doxy-handlemsg.gif"><img src="thumbs/doxy-handlemsg.gif"/></a></p>
  704. <p>
  705. Function names are displayed in blue -- clicking one will take you to the
  706. code of that function. Combined with the browser's "Back" button, they offer
  707. a very convenient way to explore the source.
  708. </p>
  709. <p>
  710. Here's what <tt>handleMessage()</tt> says: if the message that arrived is a
  711. self-message (expired timer), it can only be that an ARP request has timed
  712. out, and we'll handle it. Otherwise the message can only be a packet which
  713. we got either from the higher layers (IP) or from the network.
  714. </p>
  715. <p>
  716. If it came from the network (arrived on our gate named <tt>"hwIn"</tt>),
  717. then we must differentiate if it's an ARP packet or something else
  718. (for example, IP datagram). This is done by trying to <tt>dynamic_cast&lt;&gt;</tt>
  719. the message to <tt>ARPPacket</tt> -- if the result is not <tt>NULL</tt>,
  720. it is an ARP packet and we process it accordingly. Otherwise we just process
  721. it as some other inbound packet (and we'll just pass it up).
  722. </p>
  723. <p>
  724. If didn't come it came from the network, then it must be an outbound
  725. packet, and we process it as such.
  726. </p>
  727. <p>
  728. Finally, we update the <i>display string</i> -- a property which controls
  729. how the module is presented on the GUI. Hence the <tt>if (ev.isGUI())</tt>
  730. statement in the code: we don't care about that if the simulation is running under
  731. a command-line user interface (that is, if the simulation program was
  732. linked with Cmdenv instead of Tkenv -- search for these two words in the
  733. OMNeT++/OMNEST documentation if you're interested.)
  734. </p>
  735. <p>
  736. The display string can also be viewed (and changed) in the GUI: it is on
  737. the "Info" page of the module's inspector window (the one that opens
  738. by double-clicking the icon or selecting "As object" from its context menu):
  739. </p>
  740. <p class="img"><a href="images/arp-dispstr.gif"><img src="thumbs/arp-dispstr.gif"/></a></p>
  741. <p>
  742. It consist of "tags" separated by semicolons. For example, <tt>"i=..."</tt>
  743. specifies the icon to display, <tt>"p=..."</tt> specifies position, and
  744. <tt>"t=..."</tt> specifies the text which appears (by default) in blue
  745. above the icon. (You can try: change the string on the GUI, press Enter
  746. or click the green checkmark, and see.) After this introduction, the
  747. meaning of the <tt>updateDisplayString()</tt> function is obvious:
  748. it <tt>sprintf</tt>'s together a suitable string, and sets it as value
  749. of the <tt>"t"</tt> tag, making it appear above the icon. The text will
  750. contain the number of entries in the <tt>arpCache</tt> variable (an STL map),
  751. and the values of the <tt>numRequestsSent</tt>, <tt>numRepliesSent</tt> and
  752. <tt>numFailedResolutions</tt> variables.
  753. </p>
  754. <p class="img"><a href="images/doxy-updatedispstr.gif"><img src="thumbs/doxy-updatedispstr.gif"/></a></p>
  755. <p>
  756. After this detour about display strings, let us return to ARP message
  757. processing. Processing non-ARP packets coming from the network
  758. will not cause you much surprise: they are just passed up to the higher
  759. layer (sent via the <tt>"hlOut"</tt> gate) after stripping the Ethernet's
  760. control info (which tells e.g. the source MAC address -- higher layers
  761. won't need it). As we already mentioned, the <tt>ev&lt;&lt;</tt> line
  762. writes to the main window and the module's output (log) window if it's open.
  763. </p>
  764. <p class="img"><a href="images/doxy-processinbound.gif"><img src="thumbs/doxy-processinbound.gif"/></a></p>
  765. <p>
  766. Processing an ARP packet (<tt>processARPPacket()</tt>) begins with
  767. a long comment quoting the message processing logic from RFC 826,
  768. and code below that follows the recipe almost word-by-word -- you'll
  769. surely manage to make sense of it.
  770. </p>
  771. <p class="img"><a href="images/doxy-processarp.gif"><img src="thumbs/doxy-processarp.gif"/></a></p>
  772. <p>
  773. Instead, let us have a look at the processing of packets coming from higher
  774. layers, that is, IP datagrams. If the MAC address for the destination IP address
  775. is in the cache, we just attach it to the packet in an Ethernet control info
  776. (<tt>EtherCtrl</tt> class), otherwise we have to start the ARP resolution process.
  777. Here're the crucial parts of the code (the full code has a bit longer if-ladder,
  778. because timed out cache entries and already pending resolution processes also
  779. have to be accounted for):
  780. </p>
  781. <p class="img"><a href="images/doxy-processoutbound.gif"><img src="thumbs/doxy-processoutbound.gif"/></a></p>
  782. <p>
  783. ... extract next hop IP address, or if not present the destination IP address
  784. into the <tt>nextHop</tt> variable ...
  785. </p>
  786. <p class="img"><a href="images/doxy-processoutbound1.gif"><img src="thumbs/doxy-processoutbound1.gif"/></a></p>
  787. <p>
  788. ... The code above added to the cache a new entry (which maps <tt>nextHopAddr</tt>
  789. to the newly added entry, with a blank MAC address and marked as pending),
  790. sent an ARP Request, and queued up the datagram. Next come some more
  791. <i>else if ()</i> clauses to check cache entry is not stale and not pending
  792. resolution, then ....
  793. </p>
  794. <p class="img"><a href="images/doxy-processoutbound2.gif"><img src="thumbs/doxy-processoutbound2.gif"/></a></p>
  795. <p>
  796. If you have some experience in using STL classes, reading the code should
  797. not be too difficult -- otherwise you may want to browse the web for STL tutorials
  798. or borrow a decent C++ book. (Or borrow a friend who explains it in a few words :))
  799. </p>
  800. <p>
  801. In the above code, after we successfully extracted the MAC address out of the cache,
  802. sending of the IP datagram was done via the <tt>sendPacketToMAC()</tt> function.
  803. This function has been copied below -- it just creates a control info object,
  804. puts the MAC address into it, attaches the object to the packet and sends it
  805. on gate <tt>"hwOut"</tt> which is connected to Ethernet's <tt>encap</tt> and
  806. <tt>mac</tt> modules.
  807. </p>
  808. <p class="img"><a href="images/doxy-sendtomac.gif"><img src="thumbs/doxy-sendtomac.gif"/></a></p>
  809. <p>
  810. Finally, as the last thing in this tutorial, we can have a look at the
  811. <tt>sendARPRequest()</tt> function which is the meat of the (otherwise very short)
  812. <tt>initiateARPResolution()</tt> function. It shows how to create
  813. an ARP packet, fill its fields and send it. (Sending actually uses the
  814. <tt>sendPacketToMAC()</tt> function from above.)
  815. </p>
  816. <p class="img"><a href="images/doxy-sendarpreq.gif"><img src="thumbs/doxy-sendarpreq.gif"/></a></p>
  817. <a name="conclusion"/><h3>Conclusion</h3>
  818. <p>
  819. While ARP might not be the most important protocol on earth, it was chosen as the
  820. topic of this tutorial because it is simple enough to be presented in such
  821. a short space, and yet it does something interesting -- with the results
  822. immediately visible. And not least, it is well known and on everybody's desk
  823. (who doesn't have Ethernet LAN?).
  824. </p>
  825. <p>
  826. It is not ARP which is important anyway. By following the tutorial, you've
  827. acquired significant knowledge which will be applicable whichever part
  828. of INET (or another OMNET++/OMNEST simulation model) you're going to explore.
  829. You've learned how to run a model, how to explore it by looking at
  830. module output, by peeking into packets, queues and internal tables, and
  831. how to browse the documentation and read the source code for answers.
  832. </p>
  833. <p>
  834. I hope you've found this tutorial useful. If you have questions, comments
  835. or suggestions to improve it, please write to <u>andras at omnetpp org</u>.
  836. </p>
  837. <br><br>
  838. </body>
  839. </html>