Skip to content

Commit

Permalink
Fix examples to reflect auto start topology(#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
y-higuchi committed Feb 20, 2013
1 parent e5d7645 commit 0847690
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 44 deletions.
7 changes: 7 additions & 0 deletions Rantfile
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,12 @@ gen DirectedRule, topology_examples_objects_dir => [ topology_examples_source_di
sys "gcc -I#{ Trema.include } -I#{ Trema.openflow } #{ var :CFLAGS } -c -o #{ t.name } #{ t.source }"
end

enable_discovery_objects = [
"enable_discovery.o",
].collect do | each |
File.join topology_examples_objects_dir, each
end

show_topology_objects = [
"show_topology.o",
].collect do | each |
Expand All @@ -586,6 +592,7 @@ show_switch_status_objects = [
end

topology_examples_binaries = {
"enable_discovery" => enable_discovery_objects,
"show_topology" => show_topology_objects,
"show_switch_status" => show_switch_status_objects,
}
Expand Down
107 changes: 94 additions & 13 deletions features/examples/topology.show_topology.feature
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
Feature: show topology

As a Trema user
I want to control multiple openflow switches using topology application
So that I can show topology
Feature: show_topology example.

show_topology is a simple usage example of topology C API.

show_topology command will query for all the link information that
the topology daemon hold and print them in trema network DSL style.

Topology daemon's link discovery feature must be enabled prior to running
show_topology command in order to obtain non-empty result.

Topology daemon's link discovery feature can be enabled
by specifing "--always_run_discovery" option when starting topology daemon,
or by calling enable_topology_discovery() API from client application.


Background:
Given I cd to "../../src/examples/topology/"

@slow_process
Scenario: Four openflow switches, four servers
Given a file named "topology.conf" with:
Scenario: [C API] Show discovered link topology. (Directly start topology daemon)
Given I compile "show_topology.c" into "show_topology"
Given I compile "enable_discovery.c" into "enable_discovery"
Given a file named "show_topology.conf" with:
"""
vswitch("topology1") { datapath_id "0x1" }
vswitch("topology2") { datapath_id "0x2" }
Expand All @@ -21,11 +34,10 @@ Feature: show topology
link "topology2", "topology4"
link "topology3", "topology4"
"""
And I run `trema run ../../objects/examples/dumper/dumper -c topology.conf -d`
And I run `trema run "../../objects/topology/topology --always_run_discovery -d"`
And wait until "topology" is up
And *** sleep 4 ***
And I run `trema run ../../objects/examples/topology/show_topology`
And I run `trema run ../repeater_hub/repeater-hub.rb -c show_topology.conf -d`
And I run `trema run "../../../objects/topology/topology -d --always_run_discovery"`
And *** sleep 4 ***
When I run `trema run ./show_topology`
Then the output should contain:
"""
vswitch {
Expand Down Expand Up @@ -75,4 +87,73 @@ Feature: show topology
link "0x4", "0x1"
"""


@slow_process
Scenario: [C API] Show discovered link topology. (Enable link discovery by API)
Given I compile "show_topology.c" into "show_topology"
Given I compile "enable_discovery.c" into "enable_discovery"
Given a file named "show_topology.conf" with:
"""
vswitch("topology1") { datapath_id "0x1" }
vswitch("topology2") { datapath_id "0x2" }
vswitch("topology3") { datapath_id "0x3" }
vswitch("topology4") { datapath_id "0x4" }
link "topology1", "topology2"
link "topology1", "topology3"
link "topology1", "topology4"
link "topology2", "topology3"
link "topology2", "topology4"
link "topology3", "topology4"
"""
And I run `trema run ../repeater_hub/repeater-hub.rb -c show_topology.conf -d`
And I run `trema run "./enable_discovery"`
And *** sleep 4 ***
When I run `trema run ./show_topology`
Then the output should contain:
"""
vswitch {
datapath_id "0x2"
}
"""
And the output should contain:
"""
vswitch {
datapath_id "0x3"
}
"""
And the output should contain:
"""
vswitch {
datapath_id "0x1"
}
"""
And the output should contain:
"""
vswitch {
datapath_id "0x4"
}
"""
And the output should contain:
"""
link "0x2", "0x1"
"""
And the output should contain:
"""
link "0x3", "0x2"
"""
And the output should contain:
"""
link "0x3", "0x1"
"""
And the output should contain:
"""
link "0x4", "0x2"
"""
And the output should contain:
"""
link "0x4", "0x3"
"""
And the output should contain:
"""
link "0x4", "0x1"
"""
4 changes: 4 additions & 0 deletions src/examples/topology/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
enable_discovery
show_topology
show_topology.conf

29 changes: 22 additions & 7 deletions src/examples/topology/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ This directory includes sample application using libtopology.
- `show_swith_status` is a command line application, which retrieves
switch and port information from Topology daemon and print them to stdout.

- `enable_discovery` is a command line application, which enables
link discovery feature using the topology API.


+----------+ +-----------+ +------+ +------------------+
| switch | * 1 | packet in | 1 * |dumper| |show_topology/ |
| daemon | --------> | filter | --------> | | |show_switch_status|
+----------+ packet in +-----------+ packet in +------+ +------------------+
^ 1 ^ | * ^
| | | libtopology |
| `-------. | |
| | | |
| `-------. | topology API |
v 1 | | 1 v
+----------+ | | packet in(LLDP) +-----------+
| openflow | | `------------------------->| topology |
Expand All @@ -32,19 +35,31 @@ How to run
$ cd $TREMA_HOME
$ ./build.rb

2. Start topology daemon
2. Start network to discover

$ ./trema run ./objects/examples/dumper/dumper -c src/examples/topology/topology_fullmesh.conf &

# dumper is used in the above example, only because trema cannot run without
# any controller specified.

3. Enable link discovery feature
by adding "--always_run_discovery" option when starting topology

$ ./trema run ./objects/examples/topology/topology -d --always_run_discovery

Or by using API call.

$ ./trema run -c src/examples/topology/topology_fullmesh.conf &
$ ./trema run ./objects/examples/topology/enable_discovery

3. Run show_topology/show_switch_status from trema run
4. Run show_topology/show_switch_status from trema run

$ ./trema run objects/examples/topology/show_topology
$ ./trema run objects/examples/topology/show_switch_status

Or invoke each commands directly

$ env TREMA_HOME=`pwd` objects/examples/topology/show_topology
$ env TREMA_HOME=`pwd` objects/examples/topology/show_switch_status
$ env TREMA_HOME=`pwd` src/examples/topology/show_topology
$ env TREMA_HOME=`pwd` src/examples/topology/show_switch_status


License & Terms
Expand Down
77 changes: 77 additions & 0 deletions src/examples/topology/enable_discovery.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (C) 2012 NEC Corporation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/


#include <assert.h>
#include <getopt.h>
#include <stdio.h>
#include <unistd.h>
#include "trema.h"


void
usage() {
topology_service_interface_usage( get_executable_name(), "Show switch status", NULL );
}


static void
timed_out( void *user_data ) {
UNUSED( user_data );

error( "timed out." );

stop_trema();
}


static void
result_response( void *user_data, const topology_response *res ) {
UNUSED( user_data );
if ( res->status != TD_RESPONSE_OK ) {
error( "Enable topology discovery failed" );
} else {
info( "Enabled topology discovery" );
}
stop_trema();
}

int
main( int argc, char *argv[] ) {
init_trema( &argc, &argv );
init_topology_service_interface_options( &argc, &argv );
init_libtopology( get_topology_service_interface_name() );

enable_topology_discovery( result_response, NULL );

add_periodic_event_callback( 15, timed_out, NULL );

start_trema();

finalize_libtopology();
finalize_topology_service_interface_options();

return 0;
}


/*
* Local variables:
* c-basic-offset: 2
* indent-tabs-mode: nil
* End:
*/
12 changes: 0 additions & 12 deletions src/examples/topology/topology.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,3 @@ vhost ("host2") {
link "0xe0", "host1"
link "0xe0", "host2"


run {
path "./objects/topology/topology"
options "--always_run_discovery"
}

run {
path "./objects/examples/dumper/dumper"
}

event :port_status => "topology", :packet_in => "filter", :state_notify => "topology"
filter :lldp => "topology", :packet_in => "dumper"
12 changes: 0 additions & 12 deletions src/examples/topology/topology_fullmesh.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,3 @@ link "0xe0", "0xe3"
link "0xe1", "0xe2"
link "0xe1", "0xe3"
link "0xe2", "0xe3"

run {
path "./objects/topology/topology"
options "--always_run_discovery"
}

run {
path "./objects/examples/dumper/dumper"
}

event :port_status => "topology", :packet_in => "filter", :state_notify => "topology"
filter :lldp => "topology", :packet_in => "dumper"

0 comments on commit 0847690

Please sign in to comment.