Chapter 7: Shortest Path Forwarding with Ox

In this exercise, we will write an application that forwards packets along the shortest paths in a static network topology. This is an essential application that provides the foundation of most networks.

Exercise 1: The Shortest Path Forwarding Function

Solution

More specifically, this application will implement the following functionality:

Topology

We will represent network topologies using the data types defined in the [Frenetic_Topology.Net module]. For simplicity, in this tutorial, we will test our code on the tree topologies. The following figure depicts a tree with 5 hosts and 3 switches in a tree of depth 2:

images

However, the application itself should work with any Frenetic_Topology.Net.Topology.t.

Programming Task

Fill in the missing code in the template below. Save it in a file called Routing.ml and place it in the directory ~/ox-tutorial-solutions/Routing.ml.

 open Frenetic_Ox
 open Frenetic_OpenFlow0x01
 open Frenetic_Topology

 module Topology = Net.Topology
 
 module MyApplication = struct
   include DefaultHandlers
   open Platform

   let topology = Net.Parse.from_dotfile "topology.dot"
   
   (* creates Mininet script to generate the topology *)
   let () = 
     let fd = open_out "topology.py" in 
     Printf.fprintf fd "%s" (Net.Pretty.to_mininet topology);
     close_out fd

   let is_host v = 
     match Node.device (Topology.vertex_to_label topology v) with 
     | Node.Host -> true 
     | _ -> false  
  
   (* Creates a list of hosts *)
   let hosts = 
     Topology.VertexSet.filter is_host (Topology.vertexes topology)

   (* [FILL] Install rules for each switch *)
   let switch_connected (sw: switchId) (feats : SwitchFeatures.t) : unit = 
     ()
    
   (* [FILL] drop all packets that reach the controller *)
   let packet_in (sw : switchId) (xid : xid) (pk : packetIn) : unit =
     ()

 end
  
let _ =
  let module C = Make (MyApplication) in
  C.start ();

In more detail:

Compiling and Testing

Launching the controller generates a python script topology.py that starts Mininet with the topology given above.

This should show that 0% of the packets have been dropped.

Verify that the packets are being forwarded out of the correct port based on their destination MAC address. Using ovs-ofctl, dump the flows on all switches to ensure that packets are being forwarded along the shortest paths.

API Reference

OpenFlow_Core

send_stats_request

header accessor functions

send_flow_mod

pattern

match_all

Action

PacketIn

PacketOut

OxPlatform

Match

Packet

Network module

Topology