-
Notifications
You must be signed in to change notification settings - Fork 0
Quick Start
The best way to learn how to develop your own OpenFlow controller on top of Trema at this moment is to explore the sample applications in src/examples directory and trema/app repository.
Event dumper is an sample controller that outputs any OpenFlow related events to your terminal. With this sample, you can learn how to capture and handle OpenFlow related events with the manner of Trema.
You can run the event dumper with the following command:
$ ./trema run ./objects/examples/dumper/dumper -c ./src/examples/dumper/dumper.conf
This command starts a single OpenFlow switch (datapath ID = "0xabc") and two virtual hosts (named "host1" and "host2") connected to the switch as described in Trema configuration file.
vswitch {
datapath_id "0xabc"
}
vhost( "host1" ) {
ip "192.168.0.1"
netmask "255.255.0.0"
mac "00:00:00:01:00:01"
}
vhost( "host2" ) {
ip "192.168.0.2"
netmask "255.255.0.0"
mac "00:00:00:01:00:02"
}
link "0xabc", "host1"
link "0xabc", "host2"
Don't be surprised that Trema has an integrated OpenFlow network emulator and you do not need to prepare OpenFlow switches and end-hosts for testing controller applications!
After the environment is set up, the dumper application starts to capture OpenFlow related events from the switch.
Now you can send packets between these two virtual hosts using trema send_packets
command and see several OpenFlow events are captured by the dumper. Open another terminal and try to run the following command:
$ ./trema send_packets --source host1 --dest host2 --n_pkts 10
Now you can see some Packet-In events being captured:
[packet_in]
datapath_id: 0xe0
transaction_id: 0
buffer_id: 0x121
total_len: 64
in_port: 1
reason: 0
data:
000000010002000000010001080045000032000000004011ff67ffff0001f ...
Learning switch is an application that emulates a layer 2 switch consisting of a single OpenFlow switch.
From this application, you will learn how you can send OpenFlow messages to OpenFlow switches respond to Packet-In events and how you can set a periodic timer event with the manner of Trema.
You can run the learning switch with the following command:
$ ./trema run ./objects/examples/learning_switch/learning_switch -c ./src/examples/learning_switch/learning_switch.conf
This command starts a single OpenFlow switch and two virtual hosts (named "host1" and "host2") connected to the switch. Again please do not surprise that Trema has an integrated network emulator and you do not need to prepare OpenFlow switches and end-hosts for testing a controller.
Try trema send_packets
to send packets from host1 to host2. This eventually generates Packet-In events that are handled by the learning switch:
$ ./trema send_packets --source host1 --dest host2 --n_pkts 10
Let's see how packets are properly forwarded by the learning switch. You can view sender and receiver's statistics with trema show_stats
command.
$ ./trema show_stats host1 --tx
ip_dst,tp_dst,ip_src,tp_src,n_pkts,n_octets
192.168.0.2,1,192.168.0.1,1,10,500
$ ./trema show_stats host2 --rx
ip_dst,tp_dst,ip_src,tp_src,n_pkts,n_octets
192.168.0.2,1,192.168.0.1,1,10,500
If the learning switch works correctly, the tx and rx should be identical.