1.. highlight:: bash
2
3Click Modular Router Integration
4--------------------------------
5
6Click is a software architecture for building configurable routers.
7By using different combinations of packet processing units called elements,
8a Click router can be made to perform a specific kind of functionality.
9This flexibility provides a good platform for testing and experimenting with
10different protocols.
11
12Model Description
13*****************
14
15The source code for the Click model lives in the directory ``src/click``.
16
17Design
18======
19
20ns-3's design is well suited for an integration with Click due to the following reasons:
21
22* Packets in ns-3 are serialised/deserialised as they move up/down the stack. This allows ns-3 packets to be passed to and from Click as they are.
23* This also means that any kind of ns-3 traffic generator and transport should work easily on top of Click.
24* By striving to implement click as an Ipv4RoutingProtocol instance, we can avoid significant changes to the LL and MAC layer of the ns-3 code.
25
26The design goal was to make the ns-3-click public API simple enough such that the user needs to merely add an Ipv4ClickRouting instance to the node, and inform each Click node of the Click configuration file (.click file) that it is to use.
27
28This model implements the interface to the Click Modular Router and
29provides the Ipv4ClickRouting class to allow a node to use Click
30for external routing. Unlike normal Ipv4RoutingProtocol sub types,
31Ipv4ClickRouting doesn't use a RouteInput() method, but instead,
32receives a packet on the appropriate interface and processes it
33accordingly. Note that you need to have a routing table type element
34in your Click graph to use Click for external routing. This is needed
35by the RouteOutput() function inherited from Ipv4RoutingProtocol.
36Furthermore, a Click based node uses a different kind of L3 in the
37form of Ipv4L3ClickProtocol, which is a trimmed down version of
38Ipv4L3Protocol. Ipv4L3ClickProtocol passes on packets passing through
39the stack to Ipv4ClickRouting for processing.
40
41
42Developing a Simulator API to allow ns-3 to interact with Click
43###############################################################
44
45Much of the API is already well defined, which allows Click to probe for information from the simulator (like a Node's ID, an Interface ID and so forth). By retaining most of the methods, it should be possible to write new implementations specific to ns-3 for the same functionality.
46
47Hence, for the Click integration with ns-3, a class named Ipv4ClickRouting will handle the interaction with Click. The code for the same can be found in ``src/click/model/ipv4-click-routing.{cc,h}``.
48
49Packet hand off between ns-3 and Click
50######################################
51
52There are four kinds of packet hand-offs that can occur between ns-3 and Click.
53
54* L4 to L3
55* L3 to L4
56* L3 to L2
57* L2 to L3
58
59To overcome this, we implement Ipv4L3ClickProtocol, a stripped down version of Ipv4L3Protocol. Ipv4L3ClickProtocol passes packets to and from Ipv4ClickRouting appropriately to perform routing.
60
61Scope and Limitations
62=====================
63
64* In its current state, the NS-3 Click Integration is limited to use only with L3, leaving NS-3 to handle L2. We are currently working on adding Click MAC support as well. See the usage section to make sure that you design your Click graphs accordingly.
65* Furthermore, ns-3-click will work only with userlevel elements. The complete list of elements are available at http://read.cs.ucla.edu/click/elements. Elements that have 'all', 'userlevel' or 'ns' mentioned beside them may be used.
66* As of now, the ns-3 interface to Click is Ipv4 only. We will be adding Ipv6 support in the future.
67
68References
69==========
70
71* Eddie Kohler, Robert Morris, Benjie Chen, John Jannotti, and M. Frans Kaashoek. The click modular router. ACM Transactions on Computer Systems 18(3), August 2000, pages 263-297.
72* Lalith Suresh P., and Ruben Merz. Ns-3-click: click modular router integration for ns-3. In Proc. of 3rd International ICST Workshop on NS-3 (WNS3), Barcelona, Spain. March, 2011.
73* Michael Neufeld, Ashish Jain, and Dirk Grunwald. Nsclick: bridging network simulation and deployment. MSWiM '02: Proceedings of the 5th ACM international workshop on Modeling analysis and simulation of wireless and mobile systems, 2002, Atlanta, Georgia, USA. http://doi.acm.org/10.1145/570758.570772
74
75Usage
76*****
77
78Building Click
79==============
80
81The first step is to clone Click from the github repository and build it::
82
83  $ git clone https://github.com/kohler/click
84  $ cd click/
85  $ ./configure --disable-linuxmodule --enable-nsclick --enable-wifi
86  $ make
87
88The --enable-wifi flag may be skipped if you don't intend on using Click with Wifi.
89* Note: You don't need to do a 'make install'.
90
91Once Click has been built successfully, change into the ns-3 directory and
92configure ns-3 with Click Integration support::
93
94  $ ./waf configure --enable-examples --enable-tests --with-nsclick=/path/to/click/source
95
96Hint:  If you have click installed one directory above ns-3 (such as in the
97ns-3-allinone directory), and the name of the directory is 'click' (or
98a symbolic link to the directory is named 'click'), then the --with-nsclick
99specifier is not necessary; the ns-3 build system will successfully find
100the directory.
101
102If it says 'enabled' beside 'NS-3 Click Integration Support', then you're good to go. Note: If running modular ns-3, the minimum set of modules required to run all ns-3-click examples is wifi, csma and config-store.
103
104Next, try running one of the examples::
105
106  $ ./waf --run nsclick-simple-lan
107
108You may then view the resulting .pcap traces, which are named nsclick-simple-lan-0-0.pcap and nsclick-simple-lan-0-1.pcap.
109
110Click Graph Instructions
111========================
112
113The following should be kept in mind when making your Click graph:
114
115* Only userlevel elements can be used.
116* You will need to replace FromDevice and ToDevice elements with FromSimDevice and ToSimDevice elements.
117* Packets to the kernel are sent up using ToSimDevice(tap0,IP).
118* For any node, the device which sends/receives packets to/from the kernel, is named 'tap0'. The remaining interfaces should be named eth0, eth1 and so forth (even if you're using wifi). Please note that the device numbering should begin from 0. In future, this will be made flexible so that users can name devices in their Click file as they wish.
119* A routing table element is a mandatory. The OUTports of the routing table element should correspond to the interface number of the device through which the packet will ultimately be sent out. Violating this rule will lead to really weird packet traces. This routing table element's name should then be passed to the Ipv4ClickRouting protocol object as a simulation parameter. See the Click examples for details.
120* The current implementation leaves Click with mainly L3 functionality, with ns-3 handling L2. We will soon begin working to support the use of MAC protocols on Click as well. This means that as of now, Click's Wifi specific elements cannot be used with ns-3.
121
122Debugging Packet Flows from Click
123=================================
124
125From any point within a Click graph, you may use the Print (http://read.cs.ucla.edu/click/elements/print) element and its variants for pretty printing of packet contents. Furthermore, you may generate pcap traces of packets flowing through a Click graph by using the ToDump (http://read.cs.ucla.edu/click/elements/todump) element as well. For instance:
126
127.. sourcecode:: cpp
128
129  myarpquerier
130   -> Print(fromarpquery,64)
131   -> ToDump(out_arpquery,PER_NODE 1)
132   -> ethout;
133
134and ...will print the contents of packets that flow out of the ArpQuerier, then generate a pcap trace file which will have a suffix 'out_arpquery', for each node using the Click file, before pushing packets onto 'ethout'.
135
136Helper
137======
138
139To have a node run Click, the easiest way would be to use the ClickInternetStackHelper
140class in your simulation script. For instance:
141
142.. sourcecode:: cpp
143
144  ClickInternetStackHelper click;
145  click.SetClickFile (myNodeContainer, "nsclick-simple-lan.click");
146  click.SetRoutingTableElement (myNodeContainer, "u/rt");
147  click.Install (myNodeContainer);
148
149The example scripts inside ``src/click/examples/`` demonstrate the use of Click based nodes
150in different scenarios. The helper source can be found inside ``src/click/helper/click-internet-stack-helper.{h,cc}``
151
152Examples
153========
154
155The following examples have been written, which can be found in ``src/click/examples/``:
156
157* nsclick-simple-lan.cc and nsclick-raw-wlan.cc: A Click based node communicating with a normal ns-3 node without Click, using Csma and Wifi respectively. It also demonstrates the use of TCP on top of Click, something which the original nsclick implementation for NS-2 couldn't achieve.
158
159* nsclick-udp-client-server-csma.cc and nsclick-udp-client-server-wifi.cc: A 3 node LAN (Csma and Wifi respectively) wherein 2 Click based nodes run a UDP client, that sends packets to a third Click based node running a UDP server.
160
161* nsclick-routing.cc: One Click based node communicates to another via a third node that acts as an IP router (using the IP router Click configuration). This demonstrates routing using Click.
162
163Scripts are available within ``<click-dir>/conf/`` that allow you to generate Click files for some common scenarios. The IP Router used in ``nsclick-routing.cc`` was generated from the make-ip-conf.pl file and slightly adapted to work with ns-3-click.
164
165Validation
166**********
167
168This model has been tested as follows:
169
170* Unit tests have been written to verify the internals of Ipv4ClickRouting. This can be found in ``src/click/ipv4-click-routing-test.cc``. These tests verify whether the methods inside Ipv4ClickRouting which deal with Device name to ID, IP Address from device name and Mac Address from device name bindings work as expected.
171* The examples have been used to test Click with actual simulation scenarios. These can be found in ``src/click/examples/``. These tests cover the following: the use of different kinds of transports on top of Click, TCP/UDP, whether Click nodes can communicate with non-Click based nodes, whether Click nodes can communicate with each other, using Click to route packets using static routing.
172* Click has been tested with Csma, Wifi and Point-to-Point devices. Usage instructions are available in the preceding section.
173