• No results found

3.4 Internal Routing

This section provides information on how the routing of packets is handled initially within the routing simulation environment. Routing, as found in real world applica-tion, can be defined in its simplest form as a rule-based lookup table. This is achieved through the destination IP being used as a key to define the interface through which a packet should be forwarded (Doyle and Carroll, 2005).

This concept was brought forward into the design of this implementation. Simply, a packet should be received into the routing simulator; it should then be identified as to whether it should be routed or not. If it should be routed, then placement into the sim-ulated network should be defined. From there routing should continue until the packet is dropped due to the packet loss feature, modified (as though even corrupted there is a chance that the packet is still deemed legitimate and thus won’t be dropped), or passed to its destination.

3.4.1 Use of Forwarding Tables

Each simulated node contains its own forwarding table. The motivation for this was based on memory usage and stateless routing. The other options available were to pre-process every route and store it in a source-to-destination based table, or to have a global routing table that is accessed each time a node needs to forward a packet.

As one may wish to reconfigure this implementation at runtime, the use of pre-processing every route within the simulated network would prove problematic. This approach would lead to major pauses at runtime whenever a network is reconfigured, due to the program having to reprocess large parts of the simulated network, if not all of the routes in the simulated network, as would be necessary when core nodes in the simulated network are modified.

A global routing table, although algorithmically easier to implement, has its drawbacks in memory usage. In short, for every node added to the routing table, every other node has to be updated as to whether it can or cannot directly route to it, and if so, metadata then has to be added to this. It is also notable that at runtime this method has a higher CPU usage than the preprocessed method, however it saves in memory and real time recalculation is faster.

3.4. INTERNAL ROUTING 53

Figure 3.10: Single Copy of Accepted Packet into Structure

The third method, which was ultimately used in this implementation, is a stateless ap-proach where each node has its own forwarding table. This means that no node needs to interact with any other node when an update occurs. The only interaction that happens between the nodes in the simulated network is the forwarding of packets to each.

Although a preprocessed network would be most ideal at runtime, as there would be little to no processing time required to route a packet, the memory footprint at runtime and CPU overhead when it comes to reconfiguration at runtime are far from ideal when com-pared to a global routing table approach. The third method, in which nodes are seen as stateless entities, can be seen as a refined implementation of the global routing method.

Even though this stateless method does require more CPU resources at runtime, it is easily configurable, easy to re-use, and uses the least memory out of the three methods discussed.

As this implementation simulates large scale networks, it is more likely to be memory bound than CPU bound. This is due to the fact that comparing a destination address with a mask to a key in a table is a relatively low memory cost function. With this in mind, the focus in the design of this implementation was to cut down on memory usage so one could simulate as large scale a network as possible in software.

3.4. INTERNAL ROUTING 54

3.4.2 Single Copy Packet Buffer Routing

When a packet is introduced into this simulator via netfilter, as discussed in Section 3.2.1, the way in which the packet is stored in memory is important to determine the efficiency of the routing in this implementation. If one were to make a copy of the packet to each node in the route, this would prove resource heavy. It would also be necessary to include in this the wait times by the CPU for the copy in memory to occur.

Instead, a single data structure is used and when a packet is received into this implemen-tation and a single copy occurs, copying the packet into this data structure as shown in Figure 3.10. Furthermore, all relevant routing information is extracted from the packet at time of initial copy. This allows for a simple pointer dereference to occur in order to get information such as TTL, source IP, destination IP and protocol used.

At time of routing, instead of this data structure, which includes the packet, being copied from node to node in the network, there is simply a field in which to store the current location of the packet in the network. This is then used as a lookup into the node’s routing table (in which the packet is now located) to determine the next hop in routing.

This means that in routing through this virtual network, there is only ever one copy made of the packet, metadata is extracted and routing occurs by simply updating the packet’s location in the routing process within this data structure.

3.4.3 Protocols

This routing simulator was designed to support the routing of the three primary layer 4 protocols over the layer 3 IPv4 protocol, these are: ICMP (Postel, 1981b), TCP (Postel, 1981c), UDP (Postel, 1980). These protocols make up the basis upon which many higher level protocols base their transport8. For this reason, this implementation was aimed at these protocols as this would allow for testing to be aimed at well-known applications such as file transfer, web hosting and streaming connections.

One must also realise that the packet manipulation (to allow for external host interfac-ing) cannot be generalized for all protocols. Both UDP and TCP protocols require the inclusion of an IP pseudo-header; this contains the source and destination IP from the IPv4 header (Postel, 1980, 1981c). This brings up the need to recalculate both UDP

8At time of writing, all other layer 4 protocols are ignored and packets using layer 4 protocols other than the fore mentioned are not introduced into the simulated network at runtime.