├── .gitignore ├── cucumber.yml ├── sliceable_switch ├── test │ ├── .gitignore │ ├── rest_if │ │ ├── result.stderr │ │ ├── modify_network.json │ │ ├── create_mac.json │ │ ├── show_mac.json │ │ ├── show_macs.json │ │ ├── create_port_mac.json │ │ ├── show_port_mac.json │ │ ├── show_port_macs.json │ │ ├── create_network.json │ │ ├── show_ports.json │ │ ├── create_port.json │ │ ├── list_networks.json │ │ ├── show_port.json │ │ ├── show_network.json │ │ ├── add_filter.json │ │ ├── httpc │ │ └── tests.sh │ ├── redirector │ │ ├── www │ │ │ ├── stop.png │ │ │ ├── index.html │ │ │ └── standard.css │ │ └── iptables.sh │ ├── filter │ │ ├── result.stderr │ │ └── tests.sh │ ├── slice │ │ ├── result.stderr │ │ └── tests.sh │ └── 65535_slices.pl ├── .gitignore ├── create_slice_table.sql ├── sliceable_switch_null.conf ├── sliceable_switch_rest_null.conf ├── features │ ├── step_definitions │ │ ├── reset_stats.rb │ │ ├── up_steps.rb │ │ ├── kill_steps.rb │ │ ├── misc_steps.rb │ │ ├── stats_steps.rb │ │ ├── send_packets_steps.rb │ │ ├── create_table_steps.rb │ │ └── dump_flows_steps.rb │ ├── support │ │ └── hooks.rb │ ├── help.feature │ └── port_mac_mixed_binding.feature ├── sliceable_switch.conf ├── sliceable_switch_external.conf ├── redirector.h ├── create_tables.sh ├── apache │ └── sliceable_switch ├── create_filter_table.sql ├── sample.conf ├── filter.h ├── sample_rest.conf ├── sliceable_switch.h ├── fdb.h ├── slice.h ├── libpathresolver.h ├── port.h ├── checker.c └── Makefile ├── simple_restapi_manager ├── examples │ ├── .gitignore │ ├── example.conf │ ├── Makefile │ └── example.c ├── .gitignore ├── README.md ├── Makefile ├── simple_restapi_manager.h └── librestapi.h ├── group_dumper ├── .gitignore ├── Makefile └── utility.h ├── learning_switch_edged ├── .gitignore ├── learning_switch.conf ├── Makefile ├── mac.rb ├── port.rb ├── datapath_db.h ├── fdb.h ├── flow_entry.h └── datapath-db.rb ├── flow_dumper ├── .gitignore ├── Makefile ├── README.md └── flow-dumper.rb ├── load_balance_switch ├── .gitignore ├── README.md ├── Makefile ├── switch.conf ├── fdb.h ├── path_resolver.h └── port.h ├── path_manager ├── .gitignore ├── README.md ├── Makefile └── path_manager.h ├── show_description ├── .gitignore ├── show_description.conf ├── Makefile └── README.md ├── routing_switch ├── .gitignore ├── routing_switch_null.conf ├── routing_switch_lldp_over_ip.conf ├── routing_switch.conf ├── features │ ├── support │ │ ├── hooks.rb │ │ └── env.rb │ └── step_definitions │ │ ├── up_steps.rb │ │ ├── kill_steps.rb │ │ ├── misc_steps.rb │ │ └── send_packets_steps.rb ├── routing_switch.h ├── routing_switch_fullmesh.conf ├── routing_switch_lldp_over_ip_fullmesh.conf ├── fdb.h ├── Makefile └── libpathresolver.h ├── transaction_manager ├── .gitignore ├── examples │ ├── example.conf │ └── Makefile ├── Makefile ├── README.md └── transaction_manager.h ├── broadcast_helper ├── .gitignore └── Makefile ├── packetin_dispatcher ├── .gitignore ├── README.md ├── packetin_dispatcher.conf └── Makefile ├── simple_load_balancer ├── .gitignore ├── README.md ├── simple_load_balancer.conf └── Makefile ├── redirectable_routing_switch ├── .gitignore ├── create_authorized_host_db.sh ├── iptables.sh ├── redirectable_routing_switch_null.conf ├── redirectable_routing_switch.conf ├── Makefile ├── redirectable_routing_switch.h ├── authenticator.h ├── redirector.h ├── fdb.h └── libpathresolver.h ├── topology ├── .gitignore ├── topology.conf ├── topology_fullmesh.conf ├── service_management.h ├── show_topology.h ├── topology_management.h ├── topology_service_interface_option_parser.h ├── subscriber_table.h ├── list_switch.c ├── topology_table.h ├── probe_timer_table.h ├── Makefile └── list_port.c ├── monitoring_manager ├── .gitignore ├── monitoring.conf ├── toolutils.h ├── examples │ ├── Makefile │ └── example1.conf ├── Makefile ├── toolutils.c └── libmonitoring.h ├── flow_manager ├── flow_manager.conf ├── .gitignore ├── examples │ ├── utils.h │ ├── Makefile │ └── utils.c └── Makefile ├── features ├── topology.feature ├── flow_dumper.feature ├── flow_manager.feature ├── path_manager.feature ├── group_dumper.feature ├── show_description.feature ├── packetin_dispatcher.feature ├── simple_load_balancer.feature ├── transaction_manager.feature ├── simple_restapi_manager.feature ├── learning_switch_edged.feature ├── support │ └── env.rb ├── routing_switch.feature ├── broadcast_helper.feature ├── load_balance_switch.feature ├── redirectable_routing_switch.feature ├── sliceable_switch.feature └── monitoring_manager.feature ├── simple_multicast ├── README ├── mfc.rb └── simple-multicast.rb ├── Gemfile ├── .travis.yml ├── traffic_monitor_memcached ├── traffic_monitor.conf ├── counter.rb └── fdb.rb ├── Rakefile ├── learning_switch_memcached ├── Makefile ├── learning_switch.feature ├── fdb.rb └── learning-switch.rb ├── multi_learning_switch_memcached └── Makefile ├── Guardfile └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock -------------------------------------------------------------------------------- /cucumber.yml: -------------------------------------------------------------------------------- 1 | default: --tags ~@wip 2 | -------------------------------------------------------------------------------- /sliceable_switch/test/.gitignore: -------------------------------------------------------------------------------- 1 | /httpd 2 | -------------------------------------------------------------------------------- /sliceable_switch/test/rest_if/result.stderr: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /simple_restapi_manager/examples/.gitignore: -------------------------------------------------------------------------------- 1 | example 2 | -------------------------------------------------------------------------------- /group_dumper/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | /.depends 3 | /group_dumper 4 | -------------------------------------------------------------------------------- /learning_switch_edged/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | /.depends 3 | /learning_switch 4 | -------------------------------------------------------------------------------- /flow_dumper/.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.o 3 | *.swp 4 | *~ 5 | .depends 6 | flow_dumper 7 | -------------------------------------------------------------------------------- /load_balance_switch/.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.o 3 | *.swp 4 | *~ 5 | .depends 6 | switch 7 | -------------------------------------------------------------------------------- /path_manager/.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.o 3 | *.swp 4 | *~ 5 | .depends 6 | path_manager 7 | -------------------------------------------------------------------------------- /show_description/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.swp 3 | *~ 4 | .depends 5 | show_description 6 | -------------------------------------------------------------------------------- /routing_switch/.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.o 3 | *.swp 4 | *~ 5 | .depends 6 | routing_switch 7 | -------------------------------------------------------------------------------- /transaction_manager/.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.o 3 | *.swp 4 | *~ 5 | .depends 6 | examples/example -------------------------------------------------------------------------------- /broadcast_helper/.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.o 3 | *.swp 4 | *~ 5 | .depends 6 | broadcast_helper 7 | -------------------------------------------------------------------------------- /simple_restapi_manager/.gitignore: -------------------------------------------------------------------------------- 1 | nbproject 2 | .depends 3 | *.o 4 | *.a 5 | monitoring 6 | 7 | -------------------------------------------------------------------------------- /sliceable_switch/test/rest_if/modify_network.json: -------------------------------------------------------------------------------- 1 | { "description": "new description here" } 2 | -------------------------------------------------------------------------------- /transaction_manager/examples/example.conf: -------------------------------------------------------------------------------- 1 | vswitch("switch") { 2 | datapath_id "0x1234" 3 | } 4 | -------------------------------------------------------------------------------- /packetin_dispatcher/.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.o 3 | *.swp 4 | *~ 5 | .depends 6 | packetin_dispatcher 7 | -------------------------------------------------------------------------------- /simple_load_balancer/.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.o 3 | *.swp 4 | *~ 5 | .depends 6 | simple_load_balancer 7 | -------------------------------------------------------------------------------- /simple_restapi_manager/examples/example.conf: -------------------------------------------------------------------------------- 1 | vswitch("switch") { 2 | datapath_id "0x1234" 3 | } 4 | -------------------------------------------------------------------------------- /sliceable_switch/.gitignore: -------------------------------------------------------------------------------- 1 | *.db 2 | *.o 3 | *~ 4 | /.depends 5 | /sliceable_switch 6 | /checker 7 | -------------------------------------------------------------------------------- /sliceable_switch/test/rest_if/create_mac.json: -------------------------------------------------------------------------------- 1 | { "id": "mac_created_via_rest_if", "mac": "01:00:00:00:00:01" } -------------------------------------------------------------------------------- /sliceable_switch/test/rest_if/show_mac.json: -------------------------------------------------------------------------------- 1 | {"id":"mac_created_via_rest_if","mac":"01:00:00:00:00:01"} 2 | -------------------------------------------------------------------------------- /sliceable_switch/test/rest_if/show_macs.json: -------------------------------------------------------------------------------- 1 | [{"id":"mac_created_via_rest_if","mac":"01:00:00:00:00:01"}] 2 | -------------------------------------------------------------------------------- /redirectable_routing_switch/.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.o 3 | *.swp 4 | *~ 5 | .depends 6 | redirectable_routing_switch 7 | -------------------------------------------------------------------------------- /sliceable_switch/test/rest_if/create_port_mac.json: -------------------------------------------------------------------------------- 1 | { "id": "port_mac_created_via_rest_if", "mac": "01:01:01:01:01:01" } -------------------------------------------------------------------------------- /sliceable_switch/test/rest_if/show_port_mac.json: -------------------------------------------------------------------------------- 1 | {"id":"port_mac_created_via_rest_if","mac":"01:01:01:01:01:01"} 2 | -------------------------------------------------------------------------------- /sliceable_switch/test/rest_if/show_port_macs.json: -------------------------------------------------------------------------------- 1 | [{"id":"port_mac_created_via_rest_if","mac":"01:01:01:01:01:01"}] 2 | -------------------------------------------------------------------------------- /topology/.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.o 3 | *.swp 4 | *~ 5 | .depends 6 | show_topology 7 | topology 8 | topology_discovery 9 | -------------------------------------------------------------------------------- /sliceable_switch/test/rest_if/create_network.json: -------------------------------------------------------------------------------- 1 | { "id": "slice_created_via_rest_if", "description": "description here" } 2 | -------------------------------------------------------------------------------- /sliceable_switch/test/rest_if/show_ports.json: -------------------------------------------------------------------------------- 1 | [{"vid":65535,"datapath_id":"1024","id":"port_created_via_rest_if","port":1}] 2 | -------------------------------------------------------------------------------- /sliceable_switch/test/rest_if/create_port.json: -------------------------------------------------------------------------------- 1 | { "id": "port_created_via_rest_if", "datapath_id": "1024", "port": 1, "vid": 65535 } -------------------------------------------------------------------------------- /monitoring_manager/.gitignore: -------------------------------------------------------------------------------- 1 | nbproject 2 | .depends 3 | *.o 4 | *.a 5 | monitoring 6 | examples/example1.o 7 | examples/example1 8 | 9 | -------------------------------------------------------------------------------- /sliceable_switch/test/redirector/www/stop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trema/apps/HEAD/sliceable_switch/test/redirector/www/stop.png -------------------------------------------------------------------------------- /flow_manager/flow_manager.conf: -------------------------------------------------------------------------------- 1 | vswitch { 2 | datapath_id "0x1" 3 | } 4 | 5 | vswitch { 6 | datapath_id "0x2" 7 | } 8 | 9 | link 0x1,0x2 10 | -------------------------------------------------------------------------------- /features/topology.feature: -------------------------------------------------------------------------------- 1 | Feature: topology app 2 | 3 | Scenario: compile topology 4 | When I cd to "topology" 5 | Then I successfully run `make` 6 | -------------------------------------------------------------------------------- /sliceable_switch/test/rest_if/list_networks.json: -------------------------------------------------------------------------------- 1 | [{"id":"slice1","description":"description for slice1"},{"id":"slice2","description":"description for slice2"}] -------------------------------------------------------------------------------- /packetin_dispatcher/README.md: -------------------------------------------------------------------------------- 1 | Packet in dispatch application 2 | ============================== 3 | 4 | This directory includes packet-in dispatch application. 5 | -------------------------------------------------------------------------------- /features/flow_dumper.feature: -------------------------------------------------------------------------------- 1 | Feature: flow_dumper app 2 | 3 | Scenario: compile flow_dumper 4 | When I cd to "flow_dumper" 5 | Then I successfully run `make` 6 | -------------------------------------------------------------------------------- /simple_multicast/README: -------------------------------------------------------------------------------- 1 | Simple multicast applicastion 2 | ============================== 3 | 4 | This directory includes a simple implementation of multicast switch. 5 | -------------------------------------------------------------------------------- /features/flow_manager.feature: -------------------------------------------------------------------------------- 1 | Feature: flow_manager app 2 | 3 | Scenario: compile flow_manager 4 | When I cd to "flow_manager" 5 | Then I successfully run `make` 6 | -------------------------------------------------------------------------------- /features/path_manager.feature: -------------------------------------------------------------------------------- 1 | Feature: path_manager app 2 | 3 | Scenario: compile path_manager 4 | When I cd to "path_manager" 5 | Then I successfully run `make` 6 | -------------------------------------------------------------------------------- /redirectable_routing_switch/create_authorized_host_db.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | sqlite3 authorized_host.db 'create table authorized_host (mac unsigned bigint, description text)' 4 | -------------------------------------------------------------------------------- /sliceable_switch/test/rest_if/show_port.json: -------------------------------------------------------------------------------- 1 | {"attachments":[{"id":"port_mac_created_via_rest_if","mac":"01:01:01:01:01:01"}],"config":{"vid":65535,"datapath_id":"1024","port":1}} 2 | -------------------------------------------------------------------------------- /features/group_dumper.feature: -------------------------------------------------------------------------------- 1 | Feature: group_dumper app 2 | 3 | @wip 4 | Scenario: compile group_dumper 5 | When I cd to "group_dumper" 6 | Then I successfully run `make` 7 | -------------------------------------------------------------------------------- /features/show_description.feature: -------------------------------------------------------------------------------- 1 | Feature: show_description app 2 | 3 | Scenario: compile show_description 4 | When I cd to "show_description" 5 | Then I successfully run `make` 6 | -------------------------------------------------------------------------------- /sliceable_switch/test/filter/result.stderr: -------------------------------------------------------------------------------- 1 | Usage: 2 | filter list 3 | filter show [FILTER_ID] 4 | filter add [FILTER_ID] [FILTER_CRITERIA] 5 | filter delete [FILTER_ID] [FILTER_CRITERIA] 6 | -------------------------------------------------------------------------------- /features/packetin_dispatcher.feature: -------------------------------------------------------------------------------- 1 | Feature: packetin_dispatcher app 2 | 3 | Scenario: compile packetin_dispatcher 4 | When I cd to "packetin_dispatcher" 5 | Then I successfully run `make` 6 | -------------------------------------------------------------------------------- /features/simple_load_balancer.feature: -------------------------------------------------------------------------------- 1 | Feature: simple_load_balancer app 2 | 3 | Scenario: compile simple_load_balancer 4 | When I cd to "simple_load_balancer" 5 | Then I successfully run `make` 6 | -------------------------------------------------------------------------------- /features/transaction_manager.feature: -------------------------------------------------------------------------------- 1 | Feature: transaction_manager app 2 | 3 | Scenario: compile transaction_manager 4 | When I cd to "transaction_manager" 5 | Then I successfully run `make` 6 | -------------------------------------------------------------------------------- /flow_manager/.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.o 3 | *.swp 4 | *~ 5 | .depends 6 | flow_manager 7 | examples/example1 8 | examples/example2 9 | examples/example3 10 | examples/example4 11 | examples/example5 12 | -------------------------------------------------------------------------------- /features/simple_restapi_manager.feature: -------------------------------------------------------------------------------- 1 | Feature: simple_restapi_manager app 2 | 3 | Scenario: compile simple_restapi_manager 4 | When I cd to "simple_restapi_manager" 5 | Then I successfully run `make` 6 | -------------------------------------------------------------------------------- /features/learning_switch_edged.feature: -------------------------------------------------------------------------------- 1 | Feature: learning_switch_edged app 2 | 3 | @wip 4 | Scenario: compile learning_switch_edged 5 | When I cd to "learning_switch_edged" 6 | Then I successfully run `make` 7 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | 4 | group :develop do 5 | gem "aruba" 6 | gem "cucumber" 7 | gem "guard" 8 | gem "guard-bundler" 9 | gem "guard-cucumber" 10 | gem "trema", "~> 0.4.2" 11 | end 12 | -------------------------------------------------------------------------------- /redirectable_routing_switch/iptables.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | IPTABLES=/sbin/iptables 4 | WWW_SERVER_HOST=172.16.17.200 5 | TUN_INTERFACE=of0 6 | 7 | $IPTABLES -t nat -A PREROUTING -i $TUN_INTERFACE -j DNAT --to $WWW_SERVER_HOST 8 | -------------------------------------------------------------------------------- /features/support/env.rb: -------------------------------------------------------------------------------- 1 | require "aruba/cucumber" 2 | 3 | 4 | Before do 5 | @dirs = [ File.join( File.dirname( __FILE__ ), "..", ".." ) ] 6 | @aruba_timeout_seconds = 30 7 | system "rake clean 1>/dev/null 2>/dev/null" 8 | end 9 | -------------------------------------------------------------------------------- /features/routing_switch.feature: -------------------------------------------------------------------------------- 1 | Feature: routing_switch app 2 | 3 | Scenario: compile routing_switch 4 | Given I cd to "topology" 5 | And I successfully run `make` 6 | When I cd to "../routing_switch" 7 | Then I successfully run `make` 8 | -------------------------------------------------------------------------------- /features/broadcast_helper.feature: -------------------------------------------------------------------------------- 1 | Feature: broadcast_helper app 2 | 3 | Scenario: compile broadcast_helper 4 | Given I cd to "topology" 5 | And I successfully run `make` 6 | When I cd to "../broadcast_helper" 7 | Then I successfully run `make` 8 | -------------------------------------------------------------------------------- /features/load_balance_switch.feature: -------------------------------------------------------------------------------- 1 | Feature: load_balance_switch app 2 | 3 | Scenario: compile load_balance_switch 4 | Given I cd to "topology" 5 | And I successfully run `make` 6 | When I cd to "../load_balance_switch" 7 | Then I successfully run `make` 8 | -------------------------------------------------------------------------------- /show_description/show_description.conf: -------------------------------------------------------------------------------- 1 | vswitch { 2 | datapath_id "0x1" 3 | } 4 | 5 | vhost ("host1") 6 | vhost ("host2") 7 | vhost ("host3") 8 | vhost ("host4") 9 | 10 | link "0x1", "host1" 11 | link "0x1", "host2" 12 | link "0x1", "host3" 13 | link "0x1", "host4" 14 | -------------------------------------------------------------------------------- /features/redirectable_routing_switch.feature: -------------------------------------------------------------------------------- 1 | Feature: redirectable_routing_switch app 2 | 3 | Scenario: compile redirectable_routing_switch 4 | Given I cd to "topology" 5 | And I successfully run `make` 6 | When I cd to "../redirectable_routing_switch" 7 | Then I successfully run `make` 8 | -------------------------------------------------------------------------------- /features/sliceable_switch.feature: -------------------------------------------------------------------------------- 1 | Feature: sliceable_switch app 2 | 3 | Scenario: compile sliceable_switch 4 | Given I cd to "topology" 5 | And I successfully run `make` 6 | And I cd to "../flow_manager" 7 | And I successfully run `make` 8 | When I cd to "../sliceable_switch" 9 | Then I successfully run `make` 10 | -------------------------------------------------------------------------------- /features/monitoring_manager.feature: -------------------------------------------------------------------------------- 1 | Feature: monitoring_manager app 2 | 3 | Scenario: compile monitoring_manager 4 | Given I cd to "topology" 5 | And I successfully run `make` 6 | And I cd to "../flow_manager" 7 | And I successfully run `make` 8 | When I cd to "../monitoring_manager" 9 | Then I successfully run `make` 10 | -------------------------------------------------------------------------------- /sliceable_switch/test/rest_if/show_network.json: -------------------------------------------------------------------------------- 1 | {"bindings":[{"type":2,"id":"mac_created_via_rest_if","mac":"01:00:00:00:00:01"},{"vid":65535,"datapath_id":"1024","type":4,"id":"port_mac_created_via_rest_if","mac":"01:01:01:01:01:01","port":1},{"vid":65535,"datapath_id":"1024","type":1,"id":"port_created_via_rest_if","port":1}],"description":"description here"} 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | 3 | script: "rake cucumber" 4 | 5 | rvm: 6 | - 1.8.7 7 | - 1.9.3 8 | - 2.0.0 9 | 10 | before_install: 11 | - sudo apt-get update -qq 12 | - sudo apt-get install libpcap-dev libjansson-dev -qq 13 | - gem install bundler 14 | 15 | notifications: 16 | webhooks: http://trema-hubot.herokuapp.com/hubot/travis?room=1 17 | -------------------------------------------------------------------------------- /path_manager/README.md: -------------------------------------------------------------------------------- 1 | Simple Path Management Application 2 | ================================== 3 | 4 | This application is created for the tutorial session at Tokyo Institute of 5 | Technology. It is intended for persons who want to understand how to install 6 | flow entries into OpenFlow switches and how to implement IPC among modules 7 | developed on top of Trema. 8 | -------------------------------------------------------------------------------- /traffic_monitor_memcached/traffic_monitor.conf: -------------------------------------------------------------------------------- 1 | vswitch { 2 | datapath_id "0x1" 3 | } 4 | 5 | vswitch { 6 | datapath_id "0x2" 7 | } 8 | 9 | vhost ("host1") { 10 | ip "192.168.0.1" 11 | mac "00:00:00:00:00:01" 12 | } 13 | 14 | vhost ("host2") { 15 | ip "192.168.0.2" 16 | mac "00:00:00:00:00:02" 17 | } 18 | 19 | link "0x1", "host1" 20 | link "0x2", "host2" 21 | link "0x1", "0x2" 22 | -------------------------------------------------------------------------------- /sliceable_switch/test/rest_if/add_filter.json: -------------------------------------------------------------------------------- 1 | [{"priority":0,"nw_dst":"1.1.1.1","wildcards":"in_datapath_id","ofp_wildcards":"in_port,nw_tos,tp_src,tp_dst","dl_src":"00:00:00:00:00:00","slice":"slice1","nw_proto":0,"dl_dst":"00:00:00:00:00:00","id":"13176184135067690516","in_datapath_id":0,"nw_tos":0,"dl_vlan":0,"in_port":0,"dl_vlan_pcp":0,"action":"DENY","tp_src":0,"dl_type":0,"nw_src":"10.0.0.2","tp_dst":0}] 2 | -------------------------------------------------------------------------------- /sliceable_switch/test/redirector/iptables.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | IPTABLES=/sbin/iptables 4 | WWW_SERVER_HOST=172.16.17.200 5 | WWW_SERVER_PORT=80 6 | TUN_INTERFACE=of0 7 | 8 | $IPTABLES -t nat -A PREROUTING -i $TUN_INTERFACE -p tcp --dport 80 -j DNAT --to $WWW_SERVER_HOST:$WWW_SERVER_PORT 9 | #$IPTABLES -A FORWARD -i $TUN_INTERFACE -p tcp --dport 80 -j ACCEPT 10 | #$IPTABLES -A FORWARD -i $TUN_INTERFACE -j DROP 11 | -------------------------------------------------------------------------------- /load_balance_switch/README.md: -------------------------------------------------------------------------------- 1 | Load Balance Switch Application 2 | =============================== 3 | 4 | This application is created for the tutorial session at Tokyo Institute of 5 | Technology. It is intended for persons who want to understand how to 6 | implement IPC among moudles developed on top of Trema. Thus, it does not 7 | provide full load balance functionality and definitely does not work in 8 | real network environment. 9 | -------------------------------------------------------------------------------- /simple_load_balancer/README.md: -------------------------------------------------------------------------------- 1 | Simple Server Load Balancer Application 2 | ======================================= 3 | 4 | This application is created for the tutorial session at Kyushu Institute of 5 | Technology. It is intended for persons who want to understand how to handle 6 | packet-in events and how to install flow entries to OpenFlow switches. Thus, 7 | it does not provide full load balancer functionality and definitely does not 8 | work in real network environment. 9 | -------------------------------------------------------------------------------- /learning_switch_edged/learning_switch.conf: -------------------------------------------------------------------------------- 1 | trema_switch( "sw1" ) { 2 | datapath_id "0x1" 3 | } 4 | 5 | trema_switch( "sw2" ) { 6 | datapath_id "0x2" 7 | } 8 | 9 | vhost ( "host1" ) { 10 | ip "192.168.0.1" 11 | netmask "255.255.0.0" 12 | mac "00:00:00:01:00:01" 13 | } 14 | 15 | vhost ( "host2" ) { 16 | ip "192.168.0.2" 17 | netmask "255.255.0.0" 18 | mac "00:00:00:01:00:02" 19 | } 20 | 21 | link "sw1", "host1" 22 | link "sw2", "host2" 23 | link "sw1", "sw2" 24 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "cucumber/rake/task" 2 | 3 | 4 | Cucumber::Rake::Task.new 5 | 6 | 7 | def apps 8 | ( Dir.glob( "*" ) - [ "features" ] ).select do | each | 9 | File.directory?( each ) 10 | end 11 | end 12 | 13 | 14 | def c_apps 15 | apps.select do | each | 16 | FileTest.exists? File.join( each, "Makefile" ) 17 | end 18 | end 19 | 20 | 21 | task :clean do 22 | c_apps.each do | each | 23 | cd each do 24 | sh "make clean" 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /sliceable_switch/test/redirector/www/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Unauthorized Access 6 | 7 | 8 |

Unauthorized Access

9 | 10 |

11 | 12 |

13 | 14 |
15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /learning_switch_memcached/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011 NEC Corporation 3 | # 4 | 5 | TREMA = ../../trema 6 | GEM_BIN = `ruby -e 'require "rubygems"; puts Gem::bindir'` 7 | SHEL = /bin/sh 8 | 9 | FEATURES = learning_switch.feature 10 | 11 | all: 12 | 13 | depend: 14 | 15 | clean: 16 | 17 | run_acceptance_test: 18 | @for feature in $(FEATURES); do \ 19 | ( \ 20 | file=`pwd`/$$feature; \ 21 | cd ${TREMA}; \ 22 | ${GEM_BIN}/cucumber -r features $$file; \ 23 | ) \ 24 | done 25 | -------------------------------------------------------------------------------- /multi_learning_switch_memcached/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011 NEC Corporation 3 | # 4 | 5 | TREMA = ../../trema 6 | GEM_BIN = `ruby -e 'require "rubygems"; puts Gem::bindir'` 7 | SHELL = /bin/sh 8 | 9 | FEATURES = multi_learning_switch.feature 10 | 11 | all: 12 | 13 | depend: 14 | 15 | clean: 16 | 17 | run_acceptance_test: 18 | @for feature in $(FEATURES); do \ 19 | ( \ 20 | file=`pwd`/$$feature; \ 21 | cd ${TREMA}; \ 22 | ${GEM_BIN}/cucumber -r features $$file; \ 23 | ) \ 24 | done 25 | -------------------------------------------------------------------------------- /routing_switch/routing_switch_null.conf: -------------------------------------------------------------------------------- 1 | $apps_dir = File.join( File.dirname( __FILE__ ), ".." ) 2 | 3 | run { 4 | path File.join( $apps_dir, "./topology/topology" ) 5 | } 6 | 7 | run { 8 | path File.join( $apps_dir, "./topology/topology_discovery" ) 9 | } 10 | 11 | run { 12 | path File.join( $apps_dir, "./routing_switch/routing_switch" ) 13 | } 14 | 15 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 16 | filter :lldp => "topology_discovery", :packet_in => "routing_switch" 17 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # A sample Guardfile 2 | # More info at https://github.com/guard/guard#readme 3 | 4 | guard 'bundler' do 5 | watch('Gemfile') 6 | # Uncomment next line if Gemfile contain `gemspec' command 7 | # watch(/^.+\.gemspec/) 8 | end 9 | 10 | guard 'cucumber', :cli => "--format progress --tags ~@wip" do 11 | watch(%r{^features/.+\.feature$}) 12 | watch(%r{^features/support/.+$}) { 'features' } 13 | watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' } 14 | end 15 | 16 | -------------------------------------------------------------------------------- /redirectable_routing_switch/redirectable_routing_switch_null.conf: -------------------------------------------------------------------------------- 1 | $apps_dir = File.join( File.dirname( __FILE__ ), ".." ) 2 | 3 | run { 4 | path File.join( $apps_dir, "./topology/topology" ) 5 | } 6 | 7 | run { 8 | path File.join( $apps_dir, "./topology/topology_discovery" ) 9 | } 10 | 11 | run { 12 | path File.join( $apps_dir, "./redirectable_routing_switch/redirectable_routing_switch" ) 13 | options "-a", File.join( $apps_dir, "./redirectable_routing_switch/authorized_host.db" ) 14 | } 15 | 16 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 17 | filter :lldp => "topology_discovery", :packet_in => "redirectable_routing_switch" 18 | -------------------------------------------------------------------------------- /sliceable_switch/test/slice/result.stderr: -------------------------------------------------------------------------------- 1 | Usage: 2 | slice list 3 | slice create SLICE_ID [DESCRIPTION] 4 | slice modify SLICE_ID DESCRIPTION 5 | slice destroy SLICE_ID 6 | slice add-port SLICE_ID DPID PORT VID [BINDING_ID] 7 | slice delete-port SLICE_ID BINDING_ID 8 | slice show-port SLICE_ID [BINDING_ID] 9 | slice add-mac SLICE_ID ADDRESS [BINDING_ID] 10 | slice delete-mac SLICE_ID BINDING_ID 11 | slice add-port-mac SLICE_ID PORT_BINDING_ID ADDRESS [BINDING_ID] 12 | slice delete-port-mac SLICE_ID PORT_BINDING_ID BINDING_ID 13 | slice show-port-mac SLICE_ID PORT_BINDING_ID [BINDING_ID] 14 | slice show-mac SLICE_ID [BINDING_ID] 15 | slice show SLICE_ID 16 | -------------------------------------------------------------------------------- /monitoring_manager/monitoring.conf: -------------------------------------------------------------------------------- 1 | 2 | # virtual switches 3 | vswitch("switch1") { datapath_id "0xe1" } 4 | vswitch("switch2") { datapath_id "0xe2" } 5 | vswitch("switch3") { datapath_id "0xe3" } 6 | 7 | 8 | # virtual links 9 | link "switch1", "switch2" 10 | link "switch1", "switch3" 11 | link "switch2", "switch3" 12 | 13 | run { 14 | path "../apps/topology/topology" 15 | } 16 | 17 | run { 18 | path "../apps/topology/topology_discovery" 19 | } 20 | 21 | run { 22 | path "../apps/monitoring/monitoring" 23 | } 24 | 25 | event :flow_removed => "monitoring", :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 26 | filter :lldp => "topology_discovery", :packet_in => "monitoring" -------------------------------------------------------------------------------- /simple_load_balancer/simple_load_balancer.conf: -------------------------------------------------------------------------------- 1 | vswitch ("switch") { 2 | datapath_id "0xdeadbeef" 3 | } 4 | 5 | vhost ("host1") { 6 | ip "1.1.1.2" 7 | netmask "255.255.255.0" 8 | mac "00:00:00:01:00:01" 9 | } 10 | 11 | vhost ("host2") { 12 | ip "1.1.1.1" 13 | netmask "255.255.255.0" 14 | mac "00:00:00:01:00:02" 15 | } 16 | 17 | vhost ("host3") { 18 | ip "1.1.1.1" 19 | netmask "255.255.255.0" 20 | mac "00:00:00:01:00:02" 21 | } 22 | 23 | link "switch", "host1" 24 | link "switch", "host2" 25 | link "switch", "host3" 26 | 27 | $apps_dir = File.join( File.dirname( __FILE__ ), ".." ) 28 | 29 | run { 30 | path File.join( $apps_dir, "./simple_load_balancer/simple_load_balancer" ) 31 | } 32 | -------------------------------------------------------------------------------- /routing_switch/routing_switch_lldp_over_ip.conf: -------------------------------------------------------------------------------- 1 | $apps_dir = File.join( File.dirname( __FILE__ ), ".." ) 2 | 3 | run { 4 | path File.join( $apps_dir, "./topology/topology" ) 5 | options "--lldp_over_ip", "--lldp_ip_src=10.42.122.202", "--lldp_ip_dst=10.42.122.212" 6 | } 7 | 8 | run { 9 | path File.join( $apps_dir, "./topology/topology_discovery" ) 10 | options "--lldp_over_ip", "--lldp_ip_src=10.42.122.202", "--lldp_ip_dst=10.42.122.212" 11 | } 12 | 13 | run { 14 | path File.join( $apps_dir, "./routing_switch/routing_switch" ) 15 | } 16 | 17 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 18 | filter :lldp => "topology_discovery", :packet_in => "routing_switch" 19 | -------------------------------------------------------------------------------- /sliceable_switch/create_slice_table.sql: -------------------------------------------------------------------------------- 1 | create table slices ( 2 | number unsigned smallint not null, 3 | id text not null, 4 | description text, 5 | constraint number_unique unique (number) on conflict fail, 6 | constraint id_unique unique (id) on conflict fail 7 | ); 8 | 9 | create table bindings ( 10 | type unsigned tinyint not null, 11 | datapath_id unsigned bigint, 12 | port unsigned smallint, 13 | vid unsigned smallint, 14 | mac unsigned bigint, 15 | id text not null, 16 | slice_number unsigned smallint, 17 | constraint binding_unique unique (id,slice_number) on conflict fail 18 | ); 19 | -------------------------------------------------------------------------------- /sliceable_switch/sliceable_switch_null.conf: -------------------------------------------------------------------------------- 1 | $apps_dir = File.join( File.dirname( __FILE__ ), ".." ) 2 | $db_dir = File.join( $apps_dir, "sliceable_switch" ) 3 | 4 | run { 5 | path File.join( $apps_dir, "./topology/topology" ) 6 | } 7 | 8 | run { 9 | path File.join( $apps_dir, "./topology/topology_discovery" ) 10 | } 11 | 12 | run { 13 | path File.join( $apps_dir, "./flow_manager/flow_manager" ) 14 | } 15 | 16 | run { 17 | path File.join( $apps_dir, "./sliceable_switch/sliceable_switch" ) 18 | options "-s", File.join( $db_dir, "slice.db" ), "-a", File.join( $db_dir, "filter.db" ) 19 | } 20 | 21 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 22 | filter :lldp => "topology_discovery", :packet_in => "sliceable_switch" 23 | -------------------------------------------------------------------------------- /topology/topology.conf: -------------------------------------------------------------------------------- 1 | vswitch { 2 | datapath_id "0x1" 3 | } 4 | 5 | vhost ("host1") { 6 | ip "192.168.0.1" 7 | netmask "255.255.0.0" 8 | mac "00:00:00:01:00:01" 9 | } 10 | 11 | vhost ("host2") { 12 | ip "192.168.0.2" 13 | netmask "255.255.0.0" 14 | mac "00:00:00:01:00:02" 15 | } 16 | 17 | link "0x1", "host1" 18 | link "0x1", "host2" 19 | 20 | $dir = File.dirname( __FILE__ ) 21 | 22 | run { 23 | path File.join( $dir, "./topology" ) 24 | } 25 | 26 | run { 27 | path File.join( $dir, "./topology_discovery" ) 28 | } 29 | 30 | run { 31 | path File.join( Trema.objects, "./examples/dumper/dumper" ) 32 | } 33 | 34 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 35 | filter :lldp => "topology_discovery", :packet_in => "dumper" 36 | -------------------------------------------------------------------------------- /sliceable_switch/sliceable_switch_rest_null.conf: -------------------------------------------------------------------------------- 1 | $apps_dir = File.join( File.dirname( __FILE__ ), ".." ) 2 | $rest_dir = "/home/sliceable_switch/" 3 | $db_dir = File.join( $rest_dir, "db" ) 4 | 5 | run { 6 | path File.join( $apps_dir, "./topology/topology" ) 7 | } 8 | 9 | run { 10 | path File.join( $apps_dir, "./topology/topology_discovery" ) 11 | } 12 | 13 | run { 14 | path File.join( $apps_dir, "./flow_manager/flow_manager" ) 15 | } 16 | 17 | run { 18 | path File.join( $apps_dir, "./sliceable_switch/sliceable_switch" ) 19 | options "-s", File.join( $db_dir, "slice.db" ), "-a", File.join( $db_dir, "filter.db" ) 20 | } 21 | 22 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 23 | filter :lldp => "topology_discovery", :packet_in => "sliceable_switch" 24 | -------------------------------------------------------------------------------- /packetin_dispatcher/packetin_dispatcher.conf: -------------------------------------------------------------------------------- 1 | $apps_dir = File.join( File.dirname( __FILE__ ), ".." ) 2 | 3 | run { 4 | path File.join( $apps_dir, "./topology/topology" ) 5 | } 6 | 7 | run { 8 | path File.join( $apps_dir, "./topology/topology_discovery" ) 9 | } 10 | 11 | run { 12 | path File.join( $apps_dir, "./routing_switch/routing_switch" ) 13 | } 14 | 15 | run { 16 | path File.join( $apps_dir, "./broadcast_helper/broadcast_helper" ) 17 | } 18 | 19 | run { 20 | path File.join( $apps_dir, "./packetin_dispatcher/packetin_dispatcher" ) 21 | options "--name=dispatcher", "arp_or_unicast::routing_switch", "broadcast::broadcast_helper" 22 | } 23 | 24 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 25 | filter :lldp => "topology_discovery", :packet_in => "dispatcher" 26 | -------------------------------------------------------------------------------- /flow_dumper/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011-2013 NEC Corporation 3 | # 4 | 5 | TREMA = ../../trema 6 | 7 | TREMA_CONFIG = $(shell which trema-config) 8 | ifeq ($(TREMA_CONFIG),) 9 | TREMA_CONFIG = $(TREMA)/trema-config 10 | endif 11 | 12 | CC = gcc 13 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -std=gnu99 -D_GNU_SOURCE -g -Wall 14 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) 15 | 16 | TARGET = flow_dumper 17 | SRCS = flow_dumper.c 18 | OBJS = $(SRCS:.c=.o) 19 | 20 | DEPENDS = .depends 21 | 22 | .PHONY: all clean 23 | 24 | .SUFFIXES: .c .o 25 | 26 | all: depend $(TARGET) 27 | 28 | $(TARGET): $(OBJS) 29 | $(CC) $(OBJS) $(LDFLAGS) -o $@ 30 | 31 | .c.o: 32 | $(CC) $(CFLAGS) -c $< 33 | 34 | depend: 35 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 36 | 37 | clean: 38 | @rm -rf $(DEPENDS) $(OBJS) $(TARGET) *~ 39 | 40 | -include $(DEPENDS) 41 | -------------------------------------------------------------------------------- /path_manager/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011-2013 NEC Corporation 3 | # 4 | 5 | TREMA = ../../trema 6 | 7 | TREMA_CONFIG = $(shell which trema-config) 8 | ifeq ($(TREMA_CONFIG),) 9 | TREMA_CONFIG = $(TREMA)/trema-config 10 | endif 11 | 12 | CC = gcc 13 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -std=gnu99 -D_GNU_SOURCE -Wall -g 14 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) 15 | 16 | TARGET = path_manager 17 | SRCS = path_manager.c 18 | OBJS = $(SRCS:.c=.o) 19 | 20 | DEPENDS = .depends 21 | 22 | .PHONY: all clean 23 | 24 | .SUFFIXES: .c .o 25 | 26 | all: depend $(TARGET) 27 | 28 | $(TARGET): $(OBJS) 29 | $(CC) $(OBJS) $(LDFLAGS) -o $@ 30 | 31 | .c.o: 32 | $(CC) $(CFLAGS) -c $< 33 | 34 | depend: 35 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 36 | 37 | clean: 38 | @rm -rf $(DEPENDS) $(OBJS) $(TARGET) *~ 39 | 40 | -include $(DEPENDS) 41 | -------------------------------------------------------------------------------- /routing_switch/routing_switch.conf: -------------------------------------------------------------------------------- 1 | vswitch { 2 | datapath_id "0x1" 3 | } 4 | 5 | vhost ("host1") { 6 | ip "192.168.0.1" 7 | netmask "255.255.0.0" 8 | mac "00:00:00:01:00:01" 9 | } 10 | 11 | vhost ("host2") { 12 | ip "192.168.0.2" 13 | netmask "255.255.0.0" 14 | mac "00:00:00:01:00:02" 15 | } 16 | 17 | link "0x1", "host1" 18 | link "0x1", "host2" 19 | 20 | $apps_dir = File.join( File.dirname( __FILE__ ), ".." ) 21 | 22 | run { 23 | path File.join( $apps_dir, "./topology/topology" ) 24 | } 25 | 26 | run { 27 | path File.join( $apps_dir, "./topology/topology_discovery" ) 28 | } 29 | 30 | run { 31 | path File.join( $apps_dir, "./routing_switch/routing_switch" ) 32 | } 33 | 34 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 35 | filter :lldp => "topology_discovery", :packet_in => "routing_switch" 36 | -------------------------------------------------------------------------------- /group_dumper/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011-2013 NEC Corporation 3 | # 4 | 5 | TREMA = ../../trema 6 | 7 | TREMA_CONFIG = $(shell which trema-config) 8 | ifeq ($(TREMA_CONFIG),) 9 | TREMA_CONFIG = $(TREMA)/trema-config 10 | endif 11 | 12 | CC = gcc 13 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -std=gnu99 -D_GNU_SOURCE -g -Wall 14 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) 15 | 16 | TARGET = group_desc_dumper 17 | SRCS = group_desc_dumper.c utility.c 18 | OBJS = $(SRCS:.c=.o) 19 | 20 | DEPENDS = .depends 21 | 22 | .PHONY: all clean 23 | 24 | .SUFFIXES: .c .o 25 | 26 | all: depend $(TARGET) 27 | 28 | $(TARGET): $(OBJS) 29 | $(CC) $(OBJS) $(LDFLAGS) -o $@ 30 | 31 | .c.o: 32 | $(CC) $(CFLAGS) -c $< 33 | 34 | depend: 35 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 36 | 37 | clean: 38 | @rm -rf $(DEPENDS) $(OBJS) $(TARGET) *~ 39 | 40 | -include $(DEPENDS) 41 | -------------------------------------------------------------------------------- /simple_load_balancer/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011-2013 NEC Corporation 3 | # 4 | 5 | TREMA = ../../trema 6 | 7 | TREMA_CONFIG = $(shell which trema-config) 8 | ifeq ($(TREMA_CONFIG),) 9 | TREMA_CONFIG = $(TREMA)/trema-config 10 | endif 11 | 12 | CC = gcc 13 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -std=gnu99 -D_GNU_SOURCE -Wall 14 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) 15 | 16 | TARGET = simple_load_balancer 17 | SRCS = simple_load_balancer.c 18 | OBJS = $(SRCS:.c=.o) 19 | 20 | DEPENDS = .depends 21 | 22 | .PHONY: all clean 23 | 24 | .SUFFIXES: .c .o 25 | 26 | all: depend $(TARGET) 27 | 28 | $(TARGET): $(OBJS) 29 | $(CC) $(OBJS) $(LDFLAGS) -o $@ 30 | 31 | .c.o: 32 | $(CC) $(CFLAGS) -c $< 33 | 34 | depend: 35 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 36 | 37 | clean: 38 | @rm -rf $(DEPENDS) $(OBJS) $(TARGET) *~ 39 | 40 | run_acceptance_test: 41 | 42 | -include $(DEPENDS) 43 | -------------------------------------------------------------------------------- /load_balance_switch/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011-2013 NEC Corporation 3 | # 4 | 5 | TREMA = ../../trema 6 | 7 | TREMA_CONFIG = $(shell which trema-config) 8 | ifeq ($(TREMA_CONFIG),) 9 | TREMA_CONFIG = $(TREMA)/trema-config 10 | endif 11 | 12 | CC = gcc 13 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -I../topology -I../path_manager -std=gnu99 -D_GNU_SOURCE -Wall -g 14 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) -L../topology -ltopology 15 | 16 | TARGET = switch 17 | SRCS = fdb.c path_resolver.c port.c switch.c 18 | OBJS = $(SRCS:.c=.o) 19 | 20 | DEPENDS = .depends 21 | 22 | .PHONY: all clean 23 | 24 | .SUFFIXES: .c .o 25 | 26 | all: depend $(TARGET) 27 | 28 | $(TARGET): $(OBJS) 29 | $(CC) $(OBJS) $(LDFLAGS) -o $@ 30 | 31 | .c.o: 32 | $(CC) $(CFLAGS) -c $< 33 | 34 | depend: 35 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 36 | 37 | clean: 38 | @rm -rf $(DEPENDS) $(OBJS) $(TARGET) *~ 39 | 40 | -include $(DEPENDS) 41 | -------------------------------------------------------------------------------- /redirectable_routing_switch/redirectable_routing_switch.conf: -------------------------------------------------------------------------------- 1 | vswitch { 2 | datapath_id "0x1" 3 | } 4 | 5 | vhost ("host1") { 6 | ip "192.168.0.1" 7 | netmask "255.255.0.0" 8 | mac "00:00:00:01:00:01" 9 | } 10 | 11 | vhost ("host2") { 12 | ip "192.168.0.2" 13 | netmask "255.255.0.0" 14 | mac "00:00:00:01:00:02" 15 | } 16 | 17 | link "0x1", "host1" 18 | link "0x1", "host2" 19 | 20 | 21 | $dir = File.dirname( __FILE__ ) 22 | $apps_dir = File.join( $dir, ".." ) 23 | 24 | run { 25 | path File.join( $apps_dir, "./topology/topology" ) 26 | } 27 | 28 | run { 29 | path File.join( $apps_dir, "./topology/topology_discovery" ) 30 | } 31 | 32 | run { 33 | path File.join( $dir, "./redirectable_routing_switch" ) 34 | options "-a", File.join( $dir, "./authorized_host.db" ) 35 | } 36 | 37 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 38 | filter :lldp => "topology_discovery", :packet_in => "redirectable_routing_switch" 39 | -------------------------------------------------------------------------------- /learning_switch_edged/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2012-2013 NEC Corporation 3 | # 4 | 5 | TREMA = ../../trema-edge 6 | SHELL = /bin/sh 7 | TREMA_CONFIG = $(TREMA)/trema-config 8 | 9 | CC = gcc 10 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -std=gnu99 -D_GNU_SOURCE -g \ 11 | -fno-strict-aliasing -Werror -Wall -Wextra -Wformat=2 -Wcast-qual \ 12 | -Wcast-align -Wwrite-strings -Wconversion -Wfloat-equal -Wpointer-arith 13 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) 14 | 15 | TARGET = learning_switch 16 | SRCS = learning_switch.c datapath_db.c fdb.c flow_entry.c 17 | OBJS = $(SRCS:.c=.o) 18 | 19 | DEPENDS = .depends 20 | 21 | .PHONY: all depend clean 22 | 23 | .SUFFIXES: .c .o 24 | 25 | all: depend $(TARGET) 26 | 27 | learning_switch: $(OBJS) 28 | $(CC) $(OBJS) $(LDFLAGS) -o $@ 29 | 30 | .c.o: 31 | $(CC) $(CFLAGS) -c $< 32 | 33 | depend: 34 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 35 | 36 | clean: 37 | @rm -rf $(DEPENDS) $(OBJS) $(TARGET) *~ 38 | 39 | -include $(DEPENDS) 40 | -------------------------------------------------------------------------------- /learning_switch_edged/mac.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2008-2013 NEC Corporation 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License, version 2, as 6 | # published by the Free Software Foundation. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License along 14 | # with this program; if not, write to the Free Software Foundation, Inc., 15 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16 | # 17 | 18 | 19 | class Mac 20 | def valid? 21 | not multicast? and @value != 0 22 | end 23 | end 24 | 25 | 26 | ### Local variables: 27 | ### mode: Ruby 28 | ### coding: utf-8 29 | ### indent-tabs-mode: nil 30 | ### End: 31 | -------------------------------------------------------------------------------- /packetin_dispatcher/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011-2013 NEC Corporation 3 | # 4 | 5 | TREMA = ../../trema 6 | SHELL = /bin/sh 7 | 8 | TREMA_CONFIG = $(shell which trema-config) 9 | ifeq ($(TREMA_CONFIG),) 10 | TREMA_CONFIG = $(TREMA)/trema-config 11 | endif 12 | 13 | CC = gcc 14 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -I../topology -g -std=gnu99 -D_GNU_SOURCE -fno-strict-aliasing -Werror -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wfloat-equal -Wpointer-arith 15 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) 16 | 17 | TARGET = packetin_dispatcher 18 | SRCS = packetin_dispatcher.c 19 | OBJS = $(SRCS:.c=.o) 20 | 21 | DEPENDS = .depends 22 | 23 | .PHONY: all clean 24 | 25 | .SUFFIXES: .c .o 26 | 27 | all: depend $(TARGET) 28 | 29 | $(TARGET): $(OBJS) 30 | $(CC) $(OBJS) $(LDFLAGS) -o $@ 31 | 32 | .c.o: 33 | $(CC) $(CFLAGS) -c $< 34 | 35 | depend: 36 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 37 | 38 | clean: 39 | @rm -rf $(DEPENDS) $(OBJS) $(TARGET) *~ 40 | 41 | -include $(DEPENDS) 42 | -------------------------------------------------------------------------------- /redirectable_routing_switch/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011-2013 NEC Corporation 3 | # 4 | 5 | TREMA = ../../trema 6 | 7 | TREMA_CONFIG = $(shell which trema-config) 8 | ifeq ($(TREMA_CONFIG),) 9 | TREMA_CONFIG = $(TREMA)/trema-config 10 | endif 11 | 12 | CC = gcc 13 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -I../topology -std=gnu99 -D_GNU_SOURCE -g -Wall 14 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) -L../topology -ltopology -lsqlite3 15 | 16 | TARGET = redirectable_routing_switch 17 | SRCS = authenticator.c fdb.c libpathresolver.c port.c redirectable_routing_switch.c redirector.c 18 | OBJS = $(SRCS:.c=.o) 19 | 20 | DEPENDS = .depends 21 | 22 | .PHONY: all clean 23 | 24 | .SUFFIXES: .c .o 25 | 26 | all: depend $(TARGET) 27 | 28 | $(TARGET): $(OBJS) 29 | $(CC) $(OBJS) $(LDFLAGS) -o $@ 30 | 31 | .c.o: 32 | $(CC) $(CFLAGS) -c $< 33 | 34 | depend: 35 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 36 | 37 | clean: 38 | @rm -rf $(DEPENDS) $(OBJS) $(TARGET) *~ 39 | 40 | run_acceptance_test: 41 | 42 | -include $(DEPENDS) 43 | -------------------------------------------------------------------------------- /sliceable_switch/features/step_definitions/reset_stats.rb: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2008-2011 NEC Corporation 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License, version 2, as 5 | # published by the Free Software Foundation. 6 | # 7 | # This program is distributed in the hope that it will be useful, 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | # GNU General Public License for more details. 11 | # 12 | # You should have received a copy of the GNU General Public License along 13 | # with this program; if not, write to the Free Software Foundation, Inc., 14 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 15 | # 16 | 17 | 18 | When /^I reset stats to (.+)$/ do | host | 19 | run "./trema reset_stats #{ host }" 20 | end 21 | 22 | 23 | ### Local variables: 24 | ### mode: Ruby 25 | ### coding: utf-8-unix 26 | ### indent-tabs-mode: nil 27 | ### End: 28 | -------------------------------------------------------------------------------- /simple_restapi_manager/examples/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013 TeYen Liu 3 | # 4 | 5 | TREMA = ../../../trema 6 | 7 | CC = gcc 8 | AR = ar 9 | RANLIB = ranlib 10 | 11 | TREMA_CONFIG = $(shell which trema-config) 12 | ifeq ($(TREMA_CONFIG),) 13 | TREMA_CONFIG = $(TREMA)/trema-config 14 | endif 15 | 16 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -std=gnu99 -D_GNU_SOURCE -g -fno-strict-aliasing -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wfloat-equal -Wpointer-arith -I. -I.. 17 | LDFLAGS = -L.. -ltrema_restapi_manager $(shell $(TREMA_CONFIG) --libs) 18 | 19 | TARGET = example 20 | SRCS = example.c 21 | OBJS = $(SRCS:.c=.o) 22 | 23 | DEPENDS = .depends 24 | 25 | .PHONY: all clean 26 | 27 | .SUFFIXES: .c .o 28 | 29 | all: depend $(TARGET) 30 | 31 | $(TARGET): $(OBJS) 32 | $(CC) $(OBJS) $(LDFLAGS) -o $@ 33 | 34 | .c.o: 35 | $(CC) $(CFLAGS) -c $< 36 | 37 | depend: 38 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 39 | 40 | clean: 41 | @rm -rf $(DEPENDS) $(OBJS) $(TARGET) *~ 42 | 43 | -include $(DEPENDS) 44 | -------------------------------------------------------------------------------- /transaction_manager/examples/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011 NEC Corporation 3 | # 4 | 5 | TREMA = ../../../trema 6 | 7 | CC = gcc 8 | AR = ar 9 | RANLIB = ranlib 10 | 11 | TREMA_CONFIG = $(shell which trema-config) 12 | ifeq ($(TREMA_CONFIG),) 13 | TREMA_CONFIG = $(TREMA)/trema-config 14 | endif 15 | 16 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -std=gnu99 -D_GNU_SOURCE -g -fno-strict-aliasing -Werror -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wfloat-equal -Wpointer-arith -I. -I.. 17 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) -L.. -ltrema_tm 18 | 19 | TARGET = example 20 | SRCS = example.c 21 | OBJS = $(SRCS:.c=.o) 22 | 23 | DEPENDS = .depends 24 | 25 | .PHONY: all clean 26 | 27 | .SUFFIXES: .c .o 28 | 29 | all: depend $(TARGET) 30 | 31 | $(TARGET): $(OBJS) 32 | $(CC) $(OBJS) $(LDFLAGS) -o $@ 33 | 34 | .c.o: 35 | $(CC) $(CFLAGS) -c $< 36 | 37 | depend: 38 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 39 | 40 | clean: 41 | @rm -rf $(DEPENDS) $(OBJS) $(TARGET) *~ 42 | 43 | -include $(DEPENDS) 44 | -------------------------------------------------------------------------------- /broadcast_helper/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011-2013 NEC Corporation 3 | # 4 | 5 | TREMA = ../../trema 6 | SHELL = /bin/sh 7 | 8 | TREMA_CONFIG = $(shell which trema-config) 9 | ifeq ($(TREMA_CONFIG),) 10 | TREMA_CONFIG = $(TREMA)/trema-config 11 | endif 12 | 13 | CC = gcc 14 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -I../topology -g -std=gnu99 -D_GNU_SOURCE -fno-strict-aliasing -Werror -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wfloat-equal -Wpointer-arith 15 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) -L../topology -ltopology 16 | 17 | TARGET = broadcast_helper 18 | SRCS = port.c broadcast_helper.c 19 | OBJS = $(SRCS:.c=.o) 20 | 21 | DEPENDS = .depends 22 | 23 | .PHONY: all clean 24 | 25 | .SUFFIXES: .c .o 26 | 27 | all: depend $(TARGET) 28 | 29 | $(TARGET): $(OBJS) 30 | $(CC) $(OBJS) $(LDFLAGS) -o $@ 31 | 32 | .c.o: 33 | $(CC) $(CFLAGS) -c $< 34 | 35 | depend: 36 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 37 | 38 | clean: 39 | @rm -rf $(DEPENDS) $(OBJS) $(TARGET) *~ 40 | 41 | -include $(DEPENDS) 42 | -------------------------------------------------------------------------------- /learning_switch_memcached/learning_switch.feature: -------------------------------------------------------------------------------- 1 | Feature: control one openflow switch using learning-switch controller 2 | 3 | As a Trema user 4 | I want to control one openflow switch using learning-switch controller 5 | So that I can send and receive packets 6 | 7 | 8 | Scenario: Send and receive packets (in Ruby) 9 | Given I try trema run "../apps/learning_switch_memcached/learning-switch.rb" with following configuration (backgrounded): 10 | """ 11 | vswitch("learning") { datapath_id "0xabc" } 12 | 13 | vhost("host1") 14 | vhost("host2") 15 | 16 | link "learning", "host1" 17 | link "learning", "host2" 18 | """ 19 | And wait until "LearningSwitch" is up 20 | When I send 1 packet from host1 to host2 21 | And I try to run "./trema show_stats host1 --tx" (log = "host1.LearningSwitch.log") 22 | And I try to run "./trema show_stats host2 --rx" (log = "host2.LearningSwitch.log") 23 | Then the content of "host1.LearningSwitch.log" and "host2.LearningSwitch.log" should be identical 24 | -------------------------------------------------------------------------------- /routing_switch/features/support/hooks.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2008-2012 NEC Corporation 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License, version 2, as 6 | # published by the Free Software Foundation. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License along 14 | # with this program; if not, write to the Free Software Foundation, Inc., 15 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16 | # 17 | 18 | 19 | Before do 20 | run "./trema killall" 21 | sleep 5 22 | end 23 | 24 | 25 | After do 26 | run "./trema killall" 27 | sleep 1 28 | end 29 | 30 | 31 | ### Local variables: 32 | ### mode: Ruby 33 | ### coding: utf-8-unix 34 | ### indent-tabs-mode: nil 35 | ### End: 36 | -------------------------------------------------------------------------------- /sliceable_switch/features/support/hooks.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2008-2012 NEC Corporation 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License, version 2, as 6 | # published by the Free Software Foundation. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License along 14 | # with this program; if not, write to the Free Software Foundation, Inc., 15 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16 | # 17 | 18 | 19 | Before do 20 | run "./trema killall" 21 | sleep 5 22 | end 23 | 24 | 25 | After do 26 | run "./trema killall" 27 | sleep 1 28 | end 29 | 30 | 31 | ### Local variables: 32 | ### mode: Ruby 33 | ### coding: utf-8-unix 34 | ### indent-tabs-mode: nil 35 | ### End: 36 | -------------------------------------------------------------------------------- /group_dumper/utility.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2013 NEC Corporation 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License, version 2, as 6 | * published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16 | */ 17 | 18 | 19 | 20 | #include "trema.h" 21 | 22 | 23 | bool buckets_to_string( const struct ofp_bucket *buckets, uint16_t buckets_length, char *str, size_t str_length ); 24 | 25 | 26 | /* 27 | * Local variables: 28 | * c-basic-offset: 2 29 | * indent-tabs-mode: nil 30 | * End: 31 | */ 32 | -------------------------------------------------------------------------------- /show_description/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2012-2013 NEC Corporation 3 | # 4 | 5 | TREMA = ../../trema 6 | GEM_BIN = `ruby -e 'require "rubygems"; puts Gem::bindir'` 7 | SHELL = /bin/sh 8 | 9 | TREMA_CONFIG = $(shell which trema-config) 10 | ifeq ($(TREMA_CONFIG),) 11 | TREMA_CONFIG = $(TREMA)/trema-config 12 | endif 13 | 14 | CC = gcc 15 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -g -std=gnu99 -D_GNU_SOURCE -fno-strict-aliasing -Werror -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wfloat-equal -Wpointer-arith 16 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) 17 | 18 | TARGET = show_description 19 | SRCS = show_description.c 20 | OBJS = $(SRCS:.c=.o) 21 | 22 | DEPENDS = .depends 23 | 24 | .PHONY: all clean 25 | 26 | .SUFFIXES: .c .o 27 | 28 | all: depend $(TARGET) 29 | 30 | show_description: $(OBJS) 31 | $(CC) $(OBJS) $(LDFLAGS) -o $@ 32 | 33 | .c.o: 34 | $(CC) $(CFLAGS) -c $< 35 | 36 | depend: 37 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 38 | 39 | clean: 40 | @rm -rf $(DEPENDS) $(OBJS) $(TARGET) *~ 41 | 42 | -include $(DEPENDS) 43 | -------------------------------------------------------------------------------- /routing_switch/features/step_definitions/up_steps.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author: Yasuhito Takamiya 3 | # 4 | # Copyright (C) 2008-2012 NEC Corporation 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License, version 2, as 8 | # published by the Free Software Foundation. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License along 16 | # with this program; if not, write to the Free Software Foundation, Inc., 17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | # 19 | 20 | 21 | When /^I try trema up "([^"]*)"$/ do | component | 22 | run "./trema up #{ component }" 23 | end 24 | 25 | 26 | ### Local variables: 27 | ### mode: Ruby 28 | ### coding: utf-8-unix 29 | ### indent-tabs-mode: nil 30 | ### End: 31 | -------------------------------------------------------------------------------- /sliceable_switch/features/step_definitions/up_steps.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author: Yasuhito Takamiya 3 | # 4 | # Copyright (C) 2008-2012 NEC Corporation 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License, version 2, as 8 | # published by the Free Software Foundation. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License along 16 | # with this program; if not, write to the Free Software Foundation, Inc., 17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | # 19 | 20 | 21 | When /^I try trema up "([^"]*)"$/ do | component | 22 | run "./trema up #{ component }" 23 | end 24 | 25 | 26 | ### Local variables: 27 | ### mode: Ruby 28 | ### coding: utf-8-unix 29 | ### indent-tabs-mode: nil 30 | ### End: 31 | -------------------------------------------------------------------------------- /load_balance_switch/switch.conf: -------------------------------------------------------------------------------- 1 | vswitch { 2 | datapath_id "0x1" 3 | } 4 | 5 | vswitch { 6 | datapath_id "0x2" 7 | } 8 | 9 | vswitch { 10 | datapath_id "0x3" 11 | } 12 | 13 | vhost ("host1") { 14 | ip "192.168.0.1" 15 | netmask "255.255.0.0" 16 | mac "00:00:00:01:00:01" 17 | } 18 | 19 | vhost ("host2") { 20 | ip "192.168.0.2" 21 | netmask "255.255.0.0" 22 | mac "00:00:00:01:00:02" 23 | } 24 | 25 | link "0x1", "host1" 26 | link "0x2", "host2" 27 | link "0x1", "0x2" 28 | link "0x1", "0x3" 29 | link "0x2", "0x3" 30 | 31 | $apps_dir = File.join( File.dirname( __FILE__ ), ".." ) 32 | 33 | run { 34 | path File.join( $apps_dir, "./topology/topology" ) 35 | } 36 | 37 | run { 38 | path File.join( $apps_dir, "./topology/topology_discovery" ) 39 | } 40 | 41 | run { 42 | path File.join( $apps_dir, "./path_manager/path_manager" ) 43 | } 44 | 45 | run { 46 | path File.join( $apps_dir, "./load_balance_switch/switch" ) 47 | } 48 | 49 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 50 | filter :lldp => "topology_discovery", :packet_in => "switch" 51 | -------------------------------------------------------------------------------- /routing_switch/features/step_definitions/kill_steps.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author: Yasuhito Takamiya 3 | # 4 | # Copyright (C) 2008-2012 NEC Corporation 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License, version 2, as 8 | # published by the Free Software Foundation. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License along 16 | # with this program; if not, write to the Free Software Foundation, Inc., 17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | # 19 | 20 | 21 | When /^I try trema kill "([^"]*)"$/ do | component | 22 | run "./trema kill #{ component }" 23 | end 24 | 25 | 26 | ### Local variables: 27 | ### mode: Ruby 28 | ### coding: utf-8-unix 29 | ### indent-tabs-mode: nil 30 | ### End: 31 | -------------------------------------------------------------------------------- /sliceable_switch/sliceable_switch.conf: -------------------------------------------------------------------------------- 1 | vswitch { 2 | datapath_id "0x1" 3 | } 4 | 5 | vhost ("host1") { 6 | ip "192.168.0.1" 7 | netmask "255.255.0.0" 8 | mac "00:00:00:00:00:01" 9 | } 10 | 11 | vhost ("host2") { 12 | ip "192.168.0.2" 13 | netmask "255.255.0.0" 14 | mac "00:00:00:00:00:02" 15 | } 16 | 17 | link "0x1", "host1" 18 | link "0x1", "host2" 19 | 20 | $apps_dir = File.join( File.dirname( __FILE__ ), ".." ) 21 | $db_dir = File.join( $apps_dir, "sliceable_switch" ) 22 | 23 | run { 24 | path File.join( $apps_dir, "./topology/topology" ) 25 | } 26 | 27 | run { 28 | path File.join( $apps_dir, "./topology/topology_discovery" ) 29 | } 30 | 31 | run { 32 | path File.join( $apps_dir, "./flow_manager/flow_manager" ) 33 | } 34 | 35 | run { 36 | path File.join( $apps_dir, "./sliceable_switch/sliceable_switch" ) 37 | options "-s", File.join( $db_dir, "slice.db" ), "-a", File.join( $db_dir, "filter.db" ) 38 | } 39 | 40 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 41 | filter :lldp => "topology_discovery", :packet_in => "sliceable_switch" 42 | -------------------------------------------------------------------------------- /sliceable_switch/features/step_definitions/kill_steps.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author: Yasuhito Takamiya 3 | # 4 | # Copyright (C) 2008-2012 NEC Corporation 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License, version 2, as 8 | # published by the Free Software Foundation. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License along 16 | # with this program; if not, write to the Free Software Foundation, Inc., 17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | # 19 | 20 | 21 | When /^I try trema kill "([^"]*)"$/ do | component | 22 | run "./trema kill #{ component }" 23 | end 24 | 25 | 26 | ### Local variables: 27 | ### mode: Ruby 28 | ### coding: utf-8-unix 29 | ### indent-tabs-mode: nil 30 | ### End: 31 | -------------------------------------------------------------------------------- /sliceable_switch/sliceable_switch_external.conf: -------------------------------------------------------------------------------- 1 | vswitch { 2 | datapath_id "0x1" 3 | } 4 | 5 | vswitch { 6 | datapath_id "0x2" 7 | } 8 | 9 | vswitch { 10 | datapath_id "0x3" 11 | } 12 | 13 | link "0x1", "eth0" 14 | link "0x1", "eth1" 15 | link "0x1", "0x2" 16 | link "0x2", "0x3" 17 | link "0x3", "eth2" 18 | link "0x3", "eth3" 19 | 20 | $apps_dir = File.join( File.dirname( __FILE__ ), ".." ) 21 | $rest_dir = "/home/sliceable_switch/" 22 | $db_dir = File.join( $rest_dir, "db" ) 23 | 24 | run { 25 | path File.join( $apps_dir, "./topology/topology" ) 26 | } 27 | 28 | run { 29 | path File.join( $apps_dir, "./topology/topology_discovery" ) 30 | } 31 | 32 | run { 33 | path File.join( $apps_dir, "./flow_manager/flow_manager" ) 34 | } 35 | 36 | run { 37 | path File.join( $apps_dir, "./sliceable_switch/sliceable_switch" ) 38 | options "-m", "-s", File.join( $db_dir, "slice.db" ), "-a", File.join( $db_dir, "filter.db" ) 39 | } 40 | 41 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 42 | filter :lldp => "topology_discovery", :packet_in => "sliceable_switch" 43 | -------------------------------------------------------------------------------- /sliceable_switch/test/redirector/www/standard.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 NEC Corporation 3 | */ 4 | 5 | body 6 | { 7 | background-color: #f8f8ff; 8 | border: 0px; 9 | margin: 0px; 10 | padding: 10px; 11 | font-family: Verdana, Arial, Helvetica, sans-serif; 12 | font-size: 62.5%; 13 | } 14 | 15 | #footer 16 | { 17 | font-size: 11px; 18 | margin: 0px; 19 | text-align: right; 20 | background: #f5f5f5; 21 | color: #808080; 22 | } 23 | 24 | p 25 | { 26 | margin-left: 10px; 27 | margin-right: 30px; 28 | font-size: 12px; 29 | } 30 | 31 | p.text 32 | { 33 | margin-left: 20px; 34 | } 35 | 36 | p.center 37 | { 38 | text-align: center; 39 | } 40 | 41 | h1.title 42 | { 43 | font-size : 20pt; 44 | border-left: 10px solid #1414a0; 45 | border-bottom: 1px solid #1414a0; 46 | padding: 2px 0 2px 10px; 47 | line-height: 120%; 48 | margin-top: 0px; 49 | margin-bottom: 8px; 50 | border-top: 0px; 51 | } 52 | 53 | h2.title 54 | { 55 | font-size : 16pt; 56 | } 57 | 58 | h3.title 59 | { 60 | font-size : 14pt; 61 | } 62 | -------------------------------------------------------------------------------- /simple_restapi_manager/README.md: -------------------------------------------------------------------------------- 1 | Simple REST API manager 2 | =================== 3 | 4 | What's this? 5 | ------------ 6 | 7 | Simple REST API manager is a library and provides the ability to add 8 | REST APIs in any Trema application that uses this library. This Simple 9 | REST API manager will start a mongoose web server and developers can 10 | add their callback functions mapping with URL. When the relation between 11 | URL and callback function is built, users or other applications can 12 | use REST APIs to operate the functions. 13 | 14 | How to use 15 | ---------- 16 | 17 | Please refer to simple_restapi_manager.h and examples as references for 18 | understanding how to use the APIs. 19 | 20 | How to build 21 | ------------ 22 | 23 | Get Trema and Apps 24 | 25 | $ sudo gem install trema 26 | $ git clone git://github.com/teyenliu/apps.git apps 27 | 28 | Build transaction manager and its examples 29 | 30 | $ cd ./apps/simple_restapi_manager 31 | $ make 32 | 33 | How to run examples 34 | ------------------- 35 | 36 | $ trema run ./examples/example -c ./examples/example.conf 37 | -------------------------------------------------------------------------------- /routing_switch/routing_switch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample routing switch (switching HUB) application. 3 | * 4 | * This application provides a switching HUB function using multiple 5 | * openflow switches. 6 | * 7 | * Author: Shuji Ishii 8 | * 9 | * Copyright (C) 2008-2011 NEC Corporation 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License, version 2, as 13 | * published by the Free Software Foundation. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License along 21 | * with this program; if not, write to the Free Software Foundation, Inc., 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 | */ 24 | 25 | 26 | /* 27 | * Local variables: 28 | * c-basic-offset: 2 29 | * indent-tabs-mode: nil 30 | * End: 31 | */ 32 | -------------------------------------------------------------------------------- /redirectable_routing_switch/redirectable_routing_switch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample routing switch (switching HUB) application. 3 | * 4 | * This application provides a switching HUB function using multiple 5 | * openflow switches. 6 | * 7 | * Author: Shuji Ishii 8 | * 9 | * Copyright (C) 2008-2011 NEC Corporation 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License, version 2, as 13 | * published by the Free Software Foundation. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License along 21 | * with this program; if not, write to the Free Software Foundation, Inc., 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 | */ 24 | 25 | 26 | /* 27 | * Local variables: 28 | * c-basic-offset: 2 29 | * indent-tabs-mode: nil 30 | * End: 31 | */ 32 | -------------------------------------------------------------------------------- /simple_restapi_manager/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013 TeYen Liu 3 | # 4 | 5 | TREMA = ../../trema 6 | 7 | CC = gcc 8 | AR = ar 9 | RANLIB = ranlib 10 | 11 | TREMA_CONFIG = $(shell which trema-config) 12 | ifeq ($(TREMA_CONFIG),) 13 | TREMA_CONFIG = $(TREMA)/trema-config 14 | endif 15 | 16 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -std=gnu99 -D_GNU_SOURCE -g -fno-strict-aliasing -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wfloat-equal -Wpointer-arith 17 | 18 | LIB = libtrema_restapi_manager.a 19 | SRCS = simple_restapi_manager.c librestapi.c mongoose.c 20 | OBJS = $(SRCS:.c=.o) 21 | 22 | TARGET = $(LIB) 23 | 24 | EXAMPLES = examples 25 | 26 | DEPENDS = .depends 27 | 28 | .PHONY: all depend clean examples 29 | 30 | .SUFFIXES: .c .o 31 | 32 | all: depend $(TARGET) examples 33 | 34 | $(TARGET): $(OBJS) 35 | $(AR) -cq $@ $(OBJS) 36 | $(RANLIB) $@ 37 | 38 | .c.o: 39 | $(CC) $(CFLAGS) -c $< 40 | 41 | depend: 42 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 43 | 44 | clean: 45 | @rm -rf $(DEPENDS) $(OBJS) $(TARGET) *~ 46 | 47 | examples: 48 | cd $(EXAMPLES) && $(MAKE) 49 | 50 | -include $(DEPENDS) 51 | -------------------------------------------------------------------------------- /transaction_manager/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011-2013 NEC Corporation 3 | # 4 | 5 | TREMA = ../../trema 6 | 7 | CC = gcc 8 | AR = ar 9 | RANLIB = ranlib 10 | 11 | TREMA_CONFIG = $(shell which trema-config) 12 | ifeq ($(TREMA_CONFIG),) 13 | TREMA_CONFIG = $(TREMA)/trema-config 14 | endif 15 | 16 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -std=gnu99 -D_GNU_SOURCE -g -fno-strict-aliasing -Werror -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wfloat-equal -Wpointer-arith 17 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) 18 | 19 | LIB = libtrema_tm.a 20 | SRCS = transaction_manager.c 21 | OBJS = $(SRCS:.c=.o) 22 | 23 | TARGET = $(LIB) 24 | 25 | EXAMPLES = examples 26 | 27 | DEPENDS = .depends 28 | 29 | .PHONY: all depend clean examples 30 | 31 | .SUFFIXES: .c .o 32 | 33 | all: depend $(TARGET) examples 34 | 35 | $(TARGET): $(OBJS) 36 | $(AR) -cq $@ $(OBJS) 37 | $(RANLIB) $@ 38 | 39 | .c.o: 40 | $(CC) $(CFLAGS) -c $< 41 | 42 | depend: 43 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 44 | 45 | clean: 46 | @rm -rf $(DEPENDS) $(OBJS) $(TARGET) *~ 47 | 48 | examples: 49 | cd $(EXAMPLES) && $(MAKE) 50 | 51 | -include $(DEPENDS) 52 | -------------------------------------------------------------------------------- /show_description/README.md: -------------------------------------------------------------------------------- 1 | Show Description Application 2 | ============================= 3 | 4 | What's this? 5 | ------------ 6 | 7 | This directory includes examples that shows how to get switch description 8 | using stats-request and features-request message. 9 | 10 | How to build 11 | ------------ 12 | 13 | Get Trema and Apps 14 | 15 | $ sudo gem install trema 16 | $ git clone git://github.com/trema/apps.git apps 17 | 18 | Build show desription application 19 | 20 | $ cd ./apps/show_description 21 | $ make 22 | 23 | How to Run 24 | ------------ 25 | 26 | $ trema run ./show_description -c ./show_description.conf 27 | 28 | License 29 | ------------ 30 | 31 | Copyright (C) 2011-2013 NEC Corporation 32 | 33 | This program is free software; you can redistribute it and/or modify 34 | it under the terms of the GNU General Public License, version 2, as 35 | published by the Free Software Foundation. 36 | 37 | This program is distributed in the hope that it will be useful, but 38 | WITHOUT ANY WARRANTY; without even the implied warranty of 39 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 40 | General Public License for more details. -------------------------------------------------------------------------------- /monitoring_manager/toolutils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Monitoring 3 | * 4 | * Author: TeYen Liu 5 | * 6 | * Copyright (C) 2013 TeYen Liu 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License, version 2, as 10 | * published by the Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | */ 21 | 22 | 23 | #ifndef TOOLUTILS_H 24 | #define TOOLUTILS_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | #include 31 | #include "trema.h" 32 | 33 | char* get_static_match_str( struct ofp_match *match ); 34 | char* get_static_actions_str( struct ofp_flow_stats *stats ); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif /* TOOLUTILS_H */ 41 | 42 | -------------------------------------------------------------------------------- /sliceable_switch/redirector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Yasunobu Chiba 3 | * 4 | * Copyright (C) 2008-2012 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #ifndef REDIRECTOR_H 22 | #define REDIRECTOR_H 23 | 24 | 25 | #include 26 | #include "trema.h" 27 | 28 | 29 | bool init_redirector(); 30 | bool finalize_redirector(); 31 | void redirect( uint64_t datapath_id, uint16_t in_port, const buffer *data ); 32 | 33 | 34 | #endif // REDIRECTOR_H 35 | 36 | 37 | /* 38 | * Local variables: 39 | * c-basic-offset: 2 40 | * indent-tabs-mode: nil 41 | * End: 42 | */ 43 | -------------------------------------------------------------------------------- /sliceable_switch/create_tables.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh - 2 | # 3 | # Copyright (C) 2011-2012 NEC Corporation 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License, version 2, as 7 | # published by the Free Software Foundation. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License along 15 | # with this program; if not, write to the Free Software Foundation, Inc., 16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | # 18 | PATH=/usr/bin:/bin 19 | 20 | if [ "x$FILTER_DB_FILE" = "x" ]; then 21 | FILTER_DB_FILE=./filter.db 22 | fi 23 | if [ "x$SLICE_DB_FILE" = "x" ]; then 24 | SLICE_DB_FILE=./slice.db 25 | fi 26 | 27 | if [ ! -e "$SLICE_DB_FILE" ]; then 28 | sqlite3 "$SLICE_DB_FILE" < ./create_slice_table.sql 29 | fi 30 | if [ ! -e "$FILTER_DB_FILE" ]; then 31 | sqlite3 "$FILTER_DB_FILE" < ./create_filter_table.sql 32 | ./filter add default priority=0 action=ALLOW 33 | fi 34 | -------------------------------------------------------------------------------- /flow_manager/examples/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Yasunobu Chiba 3 | * 4 | * Copyright (C) 2011 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #ifndef UTILS_H 22 | #define UTILS_H 23 | 24 | 25 | #include "libpath.h" 26 | #include "trema.h" 27 | 28 | 29 | void dump_hop( const hop *h ); 30 | void dump_path( const path *p ); 31 | const char *status_to_string( int status ); 32 | const char *reason_to_string( int reason ); 33 | 34 | 35 | #endif // UTILS_H 36 | 37 | 38 | /* 39 | * Local variables: 40 | * c-basic-offset: 2 41 | * indent-tabs-mode: nil 42 | * End: 43 | */ 44 | -------------------------------------------------------------------------------- /redirectable_routing_switch/authenticator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Yasunobu Chiba 3 | * 4 | * Copyright (C) 2008-2011 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #ifndef AUTHENTICATOR_H 22 | #define AUTHENTICATOR_H 23 | 24 | 25 | #include 26 | #include "trema.h" 27 | 28 | 29 | bool init_authenticator( const char *file ); 30 | bool finalize_authenticator(); 31 | bool authenticate( const uint8_t *mac ); 32 | 33 | 34 | #endif // AUTHENTICATIOR_H 35 | 36 | 37 | /* 38 | * Local variables: 39 | * c-basic-offset: 2 40 | * indent-tabs-mode: nil 41 | * End: 42 | */ 43 | -------------------------------------------------------------------------------- /redirectable_routing_switch/redirector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Yasunobu Chiba 3 | * 4 | * Copyright (C) 2008-2011 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #ifndef REDIRECTOR_H 22 | #define REDIRECTOR_H 23 | 24 | 25 | #include 26 | #include "trema.h" 27 | 28 | 29 | bool init_redirector(); 30 | bool finalize_redirector(); 31 | void redirect( uint64_t datapath_id, uint16_t in_port, const buffer *data ); 32 | 33 | 34 | #endif // REDIRECTOR_H 35 | 36 | 37 | /* 38 | * Local variables: 39 | * c-basic-offset: 2 40 | * indent-tabs-mode: nil 41 | * End: 42 | */ 43 | -------------------------------------------------------------------------------- /sliceable_switch/test/65535_slices.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | # perl thisfile.pl > slice.dump 4 | # rm slice.db 5 | # sqlite3 slice.db < slice.dump 6 | print<<_EOF_; 7 | PRAGMA foreign_keys=OFF; 8 | BEGIN TRANSACTION; 9 | CREATE TABLE slices ( 10 | number unsigned smallint not null, 11 | id text not null, 12 | description text, 13 | constraint number_unique unique (number) on conflict fail, 14 | constraint id_unique unique (id) on conflict fail 15 | ); 16 | _EOF_ 17 | for ($i = 0; $i < 65535; $i++ ) { 18 | printf "INSERT INTO \"slices\" VALUES(%d,'test%d','slice%d');\n", $i, $i, $i; 19 | } 20 | print<<_EOF_; 21 | CREATE TABLE bindings ( 22 | type unsigned tinyint not null, 23 | datapath_id unsigned bigint, 24 | port unsigned smallint, 25 | vid unsigned smallint, 26 | mac unsigned bigint, 27 | id text not null, 28 | slice_number unsigned smallint, 29 | constraint binding_unique unique (id,slice_number) on conflict fail 30 | ); 31 | _EOF_ 32 | for ($i = 0; $i < 65535*2; $i++ ) { 33 | printf "INSERT INTO \"bindings\" VALUES(2,NULL,NULL,NULL,%d,'host%d',%d);\n", $i+1, $i+1, $i/2; 34 | } 35 | print<<_EOF_; 36 | COMMIT; 37 | _EOF_ 38 | -------------------------------------------------------------------------------- /sliceable_switch/apache/sliceable_switch: -------------------------------------------------------------------------------- 1 | Listen 0.0.0.0:8888 2 | 3 | 4 | 5 | ServerAdmin administrator@example.com 6 | 7 | DocumentRoot /home/sliceable_switch/script 8 | 9 | 10 | Options FollowSymLinks 11 | AllowOverride None 12 | Order deny,allow 13 | Deny from all 14 | 15 | 16 | 17 | Options +ExecCGI 18 | Script GET /config.cgi 19 | Script PUT /config.cgi 20 | Script POST /config.cgi 21 | Script DELETE /config.cgi 22 | AllowOverride None 23 | Order deny,allow 24 | Deny from all 25 | 26 | 27 | 28 | Order allow,deny 29 | Allow from all 30 | 31 | 32 | RewriteEngine on 33 | RewriteRule ^/tenants/[^/]*/networks(.*)$ /networks$1? [QSA,L] 34 | RewriteRule ^/tenants/[^/]*/filters(.*)$ /filters$1? [QSA,L] 35 | RewriteRule ^/networks(.*)$ /networks$1? [QSA,L] 36 | RewriteRule ^/filters(.*)$ /filters$1? [QSA,L] 37 | 38 | AddHandler cgi-script .cgi 39 | 40 | ErrorLog ${APACHE_LOG_DIR}/sliceable_switch_error.log 41 | CustomLog ${APACHE_LOG_DIR}/sliceable_switch_access.log combined 42 | 43 | 44 | -------------------------------------------------------------------------------- /sliceable_switch/create_filter_table.sql: -------------------------------------------------------------------------------- 1 | create table filter ( 2 | priority unsigned smallint not null, 3 | 4 | ofp_wildcards unsigned int not null, 5 | in_port unsigned smallint not null, 6 | dl_src unsigned bigint not null, 7 | dl_dst unsigned bigint not null, 8 | dl_vlan unsigned smallint not null, 9 | dl_vlan_pcp unsigned tinyint not null, 10 | dl_type unsigned smallint not null, 11 | nw_tos unsigned tinyint not null, 12 | nw_proto unsigned tinyint not null, 13 | nw_src unsigned int not null, 14 | nw_dst unsigned int not null, 15 | tp_src unsigned smallint not null, 16 | tp_dst unsigned smallint not null, 17 | 18 | wildcards unsigned int not null, 19 | in_datapath_id unsigned bigint not null, 20 | slice_number unsigned smallint not null, 21 | 22 | action unsigned tinyint not null, 23 | 24 | id text not null, 25 | 26 | constraint filter_unique unique (priority,ofp_wildcards,in_port,dl_src,dl_dst,dl_vlan,dl_vlan_pcp,dl_type,nw_tos,nw_proto,nw_src,nw_dst,tp_src,tp_dst,wildcards,in_datapath_id,slice_number) on conflict fail, 27 | constraint id_unique unique (id) on conflict fail 28 | ); 29 | -------------------------------------------------------------------------------- /sliceable_switch/sample.conf: -------------------------------------------------------------------------------- 1 | # Sample configuration for the Trema book. 2 | 3 | vswitch { 4 | datapath_id "0x1" 5 | } 6 | 7 | vhost ("host1") { 8 | ip "192.168.0.1" 9 | netmask "255.255.0.0" 10 | mac "00:00:00:01:00:01" 11 | } 12 | 13 | vhost ("host2") { 14 | ip "192.168.0.2" 15 | netmask "255.255.0.0" 16 | mac "00:00:00:01:00:02" 17 | } 18 | 19 | vhost ("host3") { 20 | ip "192.168.0.1" 21 | netmask "255.255.0.0" 22 | mac "00:00:00:01:00:01" 23 | } 24 | 25 | vhost ("host4") { 26 | ip "192.168.0.2" 27 | netmask "255.255.0.0" 28 | mac "00:00:00:01:00:02" 29 | } 30 | 31 | link "0x1", "host1" 32 | link "0x1", "host2" 33 | link "0x1", "host3" 34 | link "0x1", "host4" 35 | 36 | $dir = File.dirname( __FILE__ ) 37 | $apps_dir = File.join( $dir, ".." ) 38 | 39 | run { 40 | path File.join( $apps_dir, "./topology/topology" ) 41 | } 42 | 43 | run { 44 | path File.join( $apps_dir, "./topology/topology_discovery" ) 45 | } 46 | 47 | run { 48 | path File.join( $apps_dir, "./flow_manager/flow_manager" ) 49 | } 50 | 51 | run { 52 | path File.join( $dir, "./sliceable_switch" ) 53 | options "-s", File.join( $dir, "./slice.db" ), "-a", File.join( $dir, "./filter.db" ) 54 | } 55 | 56 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 57 | filter :lldp => "topology_discovery", :packet_in => "sliceable_switch" 58 | -------------------------------------------------------------------------------- /sliceable_switch/filter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Packet filter functions. 3 | * 4 | * Author: Yasunobu Chiba 5 | * 6 | * Copyright (C) 2008-2012 NEC Corporation 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License, version 2, as 10 | * published by the Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | */ 21 | 22 | 23 | #ifndef FILTER_H 24 | #define FILTER_H 25 | 26 | 27 | #include "trema.h" 28 | 29 | 30 | enum { 31 | ALLOW = 0, 32 | DENY, 33 | LOCAL, 34 | }; 35 | 36 | 37 | bool init_filter( const char *file ); 38 | bool finalize_filter(); 39 | int filter( uint64_t in_datapath_id, uint16_t in_port, uint16_t slice_number, const buffer *packet ); 40 | 41 | 42 | #endif // FILTER_H 43 | 44 | 45 | /* 46 | * Local variables: 47 | * c-basic-offset: 2 48 | * indent-tabs-mode: nil 49 | * End: 50 | */ 51 | -------------------------------------------------------------------------------- /topology/topology_fullmesh.conf: -------------------------------------------------------------------------------- 1 | vswitch { 2 | datapath_id "0x1" 3 | } 4 | 5 | vswitch { 6 | datapath_id "0x2" 7 | } 8 | 9 | vswitch { 10 | datapath_id "0x3" 11 | } 12 | 13 | vswitch { 14 | datapath_id "0x4" 15 | } 16 | 17 | vhost ("host1") { 18 | ip "192.168.0.1" 19 | netmask "255.255.0.0" 20 | mac "00:00:00:01:00:01" 21 | } 22 | 23 | vhost ("host2") { 24 | ip "192.168.0.2" 25 | netmask "255.255.0.0" 26 | mac "00:00:00:01:00:02" 27 | } 28 | 29 | vhost ("host3") { 30 | ip "192.168.0.3" 31 | netmask "255.255.0.0" 32 | mac "00:00:00:01:00:03" 33 | } 34 | 35 | vhost ("host4") { 36 | ip "192.168.0.4" 37 | netmask "255.255.0.0" 38 | mac "00:00:00:01:00:04" 39 | } 40 | 41 | link "0x1", "host1" 42 | link "0x2", "host2" 43 | link "0x3", "host3" 44 | link "0x4", "host4" 45 | link "0x1", "0x2" 46 | link "0x1", "0x3" 47 | link "0x1", "0x4" 48 | link "0x2", "0x3" 49 | link "0x2", "0x4" 50 | link "0x3", "0x4" 51 | 52 | 53 | $dir = File.dirname( __FILE__ ) 54 | 55 | run { 56 | path File.join( $dir, "./topology" ) 57 | } 58 | 59 | run { 60 | path File.join( $dir, "./topology_discovery" ) 61 | } 62 | 63 | run { 64 | path File.join( Trema.objects, "./examples/dumper/dumper" ) 65 | } 66 | 67 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 68 | filter :lldp => "topology_discovery", :packet_in => "dumper" 69 | -------------------------------------------------------------------------------- /traffic_monitor_memcached/counter.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Traffic counter. 3 | # 4 | # Author: Yasuhito Takamiya 5 | # 6 | # Copyright (C) 2008-2012 NEC Corporation 7 | # 8 | # This program is free software; you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License, version 2, as 10 | # published by the Free Software Foundation. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License along 18 | # with this program; if not, write to the Free Software Foundation, Inc., 19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | # 21 | 22 | 23 | class Counter 24 | def initialize 25 | @db = MemCache.new( '127.0.0.1:11211', 26 | { 27 | :namespace => "counter", 28 | :namespace_separator => '-' 29 | } 30 | ) 31 | end 32 | 33 | 34 | def add mac, packet_count 35 | count = @db[ mac.to_s ].to_i + packet_count 36 | @db.set mac.to_s, count 37 | end 38 | end 39 | 40 | 41 | ### Local variables: 42 | ### mode: Ruby 43 | ### coding: utf-8 44 | ### indent-tabs-mode: nil 45 | ### End: 46 | -------------------------------------------------------------------------------- /topology/service_management.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Shuji Ishii, Kazushi SUGYO 3 | * 4 | * Copyright (C) 2008-2011 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #ifndef SERVICE_MANAGEMENT_H 22 | #define SERVICE_MANAGEMENT_H 23 | 24 | 25 | #include "trema.h" 26 | #include "topology_table.h" 27 | 28 | 29 | bool start_service_management( void ); 30 | void stop_service_management( void ); 31 | 32 | void notify_port_status_for_all_user( port_entry *port ); 33 | void notify_link_status_for_all_user( port_entry *port ); 34 | 35 | 36 | #endif // SERVICE_MANAGEMENT_H 37 | 38 | 39 | /* 40 | * Local variables: 41 | * c-basic-offset: 2 42 | * indent-tabs-mode: nil 43 | * End: 44 | */ 45 | -------------------------------------------------------------------------------- /routing_switch/features/step_definitions/misc_steps.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2008-2012 NEC Corporation 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License, version 2, as 6 | # published by the Free Software Foundation. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License along 14 | # with this program; if not, write to the Free Software Foundation, Inc., 15 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16 | # 17 | 18 | 19 | When /^\*\*\* sleep (\d+) \*\*\*$/ do | sec | 20 | sleep sec.to_i 21 | end 22 | 23 | 24 | When /^wait until "([^"]*)" is up$/ do | process | 25 | nloop = 0 26 | pid_file = File.join( Trema.pid, "#{ process }.pid" ) 27 | loop do 28 | nloop += 1 29 | raise "Timeout" if nloop > 60 # FIXME 30 | break if FileTest.exists?( pid_file ) and not ps_entry_of( process ).nil? 31 | sleep 0.1 32 | end 33 | sleep 1 # FIXME 34 | end 35 | 36 | 37 | ### Local variables: 38 | ### mode: Ruby 39 | ### coding: utf-8-unix 40 | ### indent-tabs-mode: nil 41 | ### End: 42 | -------------------------------------------------------------------------------- /sliceable_switch/features/step_definitions/misc_steps.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2008-2012 NEC Corporation 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License, version 2, as 6 | # published by the Free Software Foundation. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License along 14 | # with this program; if not, write to the Free Software Foundation, Inc., 15 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16 | # 17 | 18 | 19 | When /^\*\*\* sleep (\d+) \*\*\*$/ do | sec | 20 | sleep sec.to_i 21 | end 22 | 23 | 24 | When /^wait until "([^"]*)" is up$/ do | process | 25 | nloop = 0 26 | pid_file = File.join( Trema.pid, "#{ process }.pid" ) 27 | loop do 28 | nloop += 1 29 | raise "Timeout" if nloop > 60 # FIXME 30 | break if FileTest.exists?( pid_file ) and not ps_entry_of( process ).nil? 31 | sleep 0.1 32 | end 33 | sleep 1 # FIXME 34 | end 35 | 36 | 37 | ### Local variables: 38 | ### mode: Ruby 39 | ### coding: utf-8-unix 40 | ### indent-tabs-mode: nil 41 | ### End: 42 | -------------------------------------------------------------------------------- /learning_switch_edged/port.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2008-2013 NEC Corporation 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License, version 2, as 6 | # published by the Free Software Foundation. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License along 14 | # with this program; if not, write to the Free Software Foundation, Inc., 15 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16 | # 17 | 18 | 19 | module Messages 20 | class Port 21 | def delete? 22 | @reason == OFPPR_DELETE 23 | end 24 | 25 | 26 | def modify? 27 | @reason == OFPPR_MODIFY 28 | end 29 | 30 | 31 | def port_down? 32 | ( @config & OFPPC_PORT_DOWN ) == OFPPC_PORT_DOWN 33 | end 34 | 35 | 36 | def link_down? 37 | ( @state & OFPPS_LINK_DOWN ) == OFPPS_LINK_DOWN 38 | end 39 | 40 | def down? 41 | port_down? or link_down? 42 | end 43 | end 44 | end 45 | 46 | 47 | ### Local variables: 48 | ### mode: Ruby 49 | ### coding: utf-8 50 | ### indent-tabs-mode: nil 51 | ### End: 52 | -------------------------------------------------------------------------------- /sliceable_switch/sample_rest.conf: -------------------------------------------------------------------------------- 1 | # Sample configuration for the Trema book. 2 | 3 | vswitch { 4 | datapath_id "0x1" 5 | } 6 | 7 | vhost ("host1") { 8 | ip "192.168.0.1" 9 | netmask "255.255.0.0" 10 | mac "00:00:00:01:00:01" 11 | } 12 | 13 | vhost ("host2") { 14 | ip "192.168.0.2" 15 | netmask "255.255.0.0" 16 | mac "00:00:00:01:00:02" 17 | } 18 | 19 | vhost ("host3") { 20 | ip "192.168.0.1" 21 | netmask "255.255.0.0" 22 | mac "00:00:00:01:00:01" 23 | } 24 | 25 | vhost ("host4") { 26 | ip "192.168.0.2" 27 | netmask "255.255.0.0" 28 | mac "00:00:00:01:00:02" 29 | } 30 | 31 | link "0x1", "host1" 32 | link "0x1", "host2" 33 | link "0x1", "host3" 34 | link "0x1", "host4" 35 | 36 | $dir = File.dirname( __FILE__ ) 37 | $apps_dir = File.join( $dir, ".." ) 38 | $rest_dir = "/home/sliceable_switch/" 39 | 40 | run { 41 | path File.join( $apps_dir, "./topology/topology" ) 42 | } 43 | 44 | run { 45 | path File.join( $apps_dir, "./topology/topology_discovery" ) 46 | } 47 | 48 | run { 49 | path File.join( $apps_dir, "./flow_manager/flow_manager" ) 50 | } 51 | 52 | run { 53 | path File.join( $dir, "./sliceable_switch" ) 54 | options "-s", File.join( $rest_dir, "./db/slice.db" ), "-a", File.join( $rest_dir, "./db/filter.db" ) 55 | } 56 | 57 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 58 | filter :lldp => "topology_discovery", :packet_in => "sliceable_switch" 59 | -------------------------------------------------------------------------------- /topology/show_topology.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Shuji Ishii, Kazushi SUGYO 3 | * 4 | * Copyright (C) 2008-2011 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #ifndef SHOW_TOPOLOGY_H 22 | #define SHOW_TOPOLOGY_H 23 | 24 | 25 | #include 26 | #include "libtopology.h" 27 | 28 | 29 | void print_with_dsl_format( void *param, size_t entries, const topology_link_status *s ); 30 | void print_with_graph_easy_format( void *param, size_t entries, const topology_link_status *s ); 31 | void print_with_csv_format( void *param, size_t entries, const topology_link_status *s ); 32 | 33 | 34 | #endif // SHOW_TOPOLOGY_H 35 | 36 | 37 | /* 38 | * Local variables: 39 | * c-basic-offset: 2 40 | * indent-tabs-mode: nil 41 | * End: 42 | */ 43 | -------------------------------------------------------------------------------- /routing_switch/routing_switch_fullmesh.conf: -------------------------------------------------------------------------------- 1 | vswitch { 2 | datapath_id "0x1" 3 | } 4 | 5 | vswitch { 6 | datapath_id "0x2" 7 | } 8 | 9 | vswitch { 10 | datapath_id "0x3" 11 | } 12 | 13 | vswitch { 14 | datapath_id "0x4" 15 | } 16 | 17 | vhost ("host1") { 18 | ip "192.168.0.1" 19 | netmask "255.255.0.0" 20 | mac "00:00:00:01:00:01" 21 | } 22 | 23 | vhost ("host2") { 24 | ip "192.168.0.2" 25 | netmask "255.255.0.0" 26 | mac "00:00:00:01:00:02" 27 | } 28 | 29 | vhost ("host3") { 30 | ip "192.168.0.3" 31 | netmask "255.255.0.0" 32 | mac "00:00:00:01:00:03" 33 | } 34 | 35 | vhost ("host4") { 36 | ip "192.168.0.4" 37 | netmask "255.255.0.0" 38 | mac "00:00:00:01:00:04" 39 | } 40 | 41 | link "0x1", "host1" 42 | link "0x2", "host2" 43 | link "0x3", "host3" 44 | link "0x4", "host4" 45 | link "0x1", "0x2" 46 | link "0x1", "0x3" 47 | link "0x1", "0x4" 48 | link "0x2", "0x3" 49 | link "0x2", "0x4" 50 | link "0x3", "0x4" 51 | 52 | $apps_dir = File.join( File.dirname( __FILE__ ), ".." ) 53 | 54 | run { 55 | path File.join( $apps_dir, "./topology/topology" ) 56 | } 57 | 58 | run { 59 | path File.join( $apps_dir, "./topology/topology_discovery" ) 60 | } 61 | 62 | run { 63 | path File.join( $apps_dir, "./routing_switch/routing_switch" ) 64 | } 65 | 66 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 67 | filter :lldp => "topology_discovery", :packet_in => "routing_switch" 68 | -------------------------------------------------------------------------------- /sliceable_switch/features/step_definitions/stats_steps.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author: Yasuhito Takamiya 3 | # 4 | # Copyright (C) 2008-2012 NEC Corporation 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License, version 2, as 8 | # published by the Free Software Foundation. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License along 16 | # with this program; if not, write to the Free Software Foundation, Inc., 17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | # 19 | 20 | 21 | Then /^the total number of tx packets should be:$/ do | table | 22 | table.hashes[ 0 ].each_pair do | host, n | 23 | count_packets( `./trema show_stats #{ host } --tx` ).should == n.to_i 24 | end 25 | end 26 | 27 | 28 | Then /^the total number of rx packets should be:$/ do | table | 29 | table.hashes[ 0 ].each_pair do | host, n | 30 | count_packets( `./trema show_stats #{ host } --rx` ).should == n.to_i 31 | end 32 | end 33 | 34 | 35 | ### Local variables: 36 | ### mode: Ruby 37 | ### coding: utf-8-unix 38 | ### indent-tabs-mode: nil 39 | ### End: 40 | -------------------------------------------------------------------------------- /topology/topology_management.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Shuji Ishii, Kazushi SUGYO 3 | * 4 | * Copyright (C) 2008-2011 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #ifndef TOPOLOGY_MANAGEMENT_H 22 | #define TOPOLOGY_MANAGEMENT_H 23 | 24 | 25 | #include "trema.h" 26 | 27 | 28 | typedef struct { 29 | bool lldp_over_ip; 30 | uint32_t lldp_ip_src; 31 | uint32_t lldp_ip_dst; 32 | } topology_management_options; 33 | 34 | 35 | bool init_topology_management( topology_management_options new_options ); 36 | bool start_topology_management( void ); 37 | void stop_topology_management( void ); 38 | 39 | 40 | #endif // TOPOLOGY_MANAGEMENT_H 41 | 42 | 43 | /* 44 | * Local variables: 45 | * c-basic-offset: 2 46 | * indent-tabs-mode: nil 47 | * End: 48 | */ 49 | -------------------------------------------------------------------------------- /simple_multicast/mfc.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Multicast Forwarding Cache (MFC) 3 | # 4 | # Author: Kazuya Suzuki 5 | # 6 | # Copyright (C) 2012 NEC Corporation 7 | # 8 | # This program is free software; you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License, version 2, as 10 | # published by the Free Software Foundation. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License along 18 | # with this program; if not, write to the Free Software Foundation, Inc., 19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | # 21 | 22 | 23 | require "set" 24 | 25 | 26 | # 27 | # A database for multicast forwarding 28 | # 29 | class MFC 30 | def initialize 31 | @db = Hash.new do | hash, key | 32 | hash[ key ] = Set.new 33 | end 34 | end 35 | 36 | 37 | def learn group, port 38 | members( group ).add( port ) 39 | end 40 | 41 | 42 | def remove group, port 43 | members( group ).delete( port ) 44 | end 45 | 46 | 47 | def members group 48 | @db[ group.to_i ] 49 | end 50 | end 51 | 52 | 53 | ### Local variables: 54 | ### mode: Ruby 55 | ### coding: utf-8 56 | ### indent-tabs-mode: nil 57 | ### End: 58 | -------------------------------------------------------------------------------- /sliceable_switch/sliceable_switch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Sliceable switch application. 3 | * 4 | * Author: Shuji Ishii, Yasunobu Chiba, Lei SUN 5 | * 6 | * Copyright (C) 2008-2012 NEC Corporation 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License, version 2, as 10 | * published by the Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | */ 21 | 22 | 23 | #ifndef SLICEABLE_SWITCH_H 24 | #define SLICEABLE_SWITCH_H 25 | 26 | 27 | #include "libpathresolver.h" 28 | 29 | 30 | typedef struct { 31 | uint16_t idle_timeout; 32 | bool handle_arp_with_packetout; 33 | bool setup_reverse_flow; 34 | list_element *switches; 35 | hash_table *fdb; 36 | pathresolver *pathresolver; 37 | 38 | bool second_stage_down; 39 | bool last_stage_down; 40 | } sliceable_switch; 41 | 42 | 43 | #endif // SLICEABLE_SWITCH_H 44 | 45 | 46 | /* 47 | * Local variables: 48 | * c-basic-offset: 2 49 | * indent-tabs-mode: nil 50 | * End: 51 | */ 52 | -------------------------------------------------------------------------------- /learning_switch_edged/datapath_db.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2013 NEC Corporation 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License, version 2, as 6 | * published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16 | */ 17 | 18 | 19 | #ifndef DATAPATH_DB_H 20 | #define DATAPATH_DB_H 21 | 22 | #include "trema.h" 23 | 24 | 25 | hash_table *create_datapath_db( void ); 26 | void insert_datapath_entry( hash_table *db, uint64_t datapath_id, void *user_data, void delete_user_data( void *user_data ) ); 27 | void *lookup_datapath_entry( hash_table *db, uint64_t datapath_id ); 28 | void delete_datapath_entry( hash_table *db, uint64_t datapath_id ); 29 | void delete_datapath_db( hash_table *db ); 30 | void foreach_datapath_db( hash_table *db, void function( void *user_data ) ); 31 | 32 | #endif // DATAPATH_DB_H 33 | 34 | 35 | /* 36 | * Local variables: 37 | * c-basic-offset: 2 38 | * indent-tabs-mode: nil 39 | * End: 40 | */ 41 | -------------------------------------------------------------------------------- /topology/topology_service_interface_option_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Shuji Ishii, Kazushi SUGYO 3 | * 4 | * Copyright (C) 2008-2011 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #ifndef TOPOLOGY_SERVICE_INTERFACE_OPTION_PARSER_H 22 | #define TOPOLOGY_SERVICE_INTERFACE_OPTION_PARSER_H 23 | 24 | 25 | void topology_service_interface_usage( const char *progname, const char *description, const char *additional_options ); 26 | void init_topology_service_interface_options( int *argc, char **argv[] ); 27 | void finalize_topology_service_interface_options( void ); 28 | const char *get_topology_service_interface_name( void ); 29 | 30 | 31 | #endif // TOPOLOGY_SERVICE_INTERFACE_OPTION_PARSER_H 32 | 33 | 34 | /* 35 | * Local variables: 36 | * c-basic-offset: 2 37 | * indent-tabs-mode: nil 38 | * End: 39 | */ 40 | -------------------------------------------------------------------------------- /load_balance_switch/fdb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Shuji Ishii 3 | * 4 | * Copyright (C) 2008-2011 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #ifndef FDB_H 22 | #define FDB_H 23 | 24 | 25 | #include "trema.h" 26 | 27 | 28 | hash_table *create_fdb( void ); 29 | bool is_ether_multicast( const uint8_t mac[ OFP_ETH_ALEN ] ); 30 | void delete_fdb( hash_table *fdb ); 31 | bool update_fdb( hash_table *fdb, const uint8_t mac[ OFP_ETH_ALEN ], uint64_t dpid, uint16_t port ); 32 | bool lookup_fdb( hash_table *fdb, const uint8_t mac[ OFP_ETH_ALEN ], uint64_t *dpid, uint16_t *port ); 33 | void init_age_fdb( hash_table *fdb ); 34 | void delete_fdb_entries( hash_table *fdb, uint64_t dpid, uint16_t port ); 35 | 36 | 37 | #endif // FDB_H 38 | 39 | 40 | /* 41 | * Local variables: 42 | * c-basic-offset: 2 43 | * indent-tabs-mode: nil 44 | * End: 45 | */ 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | What's here? 2 | ============ 3 | 4 | [![Build Status](https://secure.travis-ci.org/trema/apps.png)](http://travis-ci.org/trema/apps) 5 | [![Code Climate](https://codeclimate.com/github/trema/apps.png)](https://codeclimate.com/github/trema/apps) 6 | [![Dependency Status](https://gemnasium.com/trema/apps.png)](https://gemnasium.com/trema/apps) 7 | 8 | This is the repository for listing OpenFlow controller applications 9 | developed on top of Trema. The applications are not main part of 10 | Trema framework but still you can refer to them as examples or 11 | references. 12 | 13 | Please note that since the applications are not main part of Trema, 14 | they may not be well-maintained and may or may not work expectedly. 15 | 16 | For usages of the applications distributed under this repository, 17 | please refer to documents found in subdirectories. 18 | 19 | 20 | Meta 21 | ==== 22 | 23 | * Main Trema Web Page: http://trema.github.com/trema/ 24 | * Twitter: http://twitter.com/trema_news 25 | * Mailing List: https://groups.google.com/group/trema-dev 26 | 27 | 28 | Authors 29 | ======= 30 | 31 | Please keep the list sorted. 32 | 33 | * Kazushi Sugyo 34 | * Kazuya Suzuki 35 | * Shuji Ishii 36 | * Lei Sun 37 | * Yasuhito Takamiya 38 | * Yasunobu Chiba 39 | 40 | 41 | License & Terms 42 | =============== 43 | 44 | Each software found in this directory is distributed under the terms 45 | and conditions described in the document of the software. Please 46 | carefully check the document before you build/run the software. 47 | -------------------------------------------------------------------------------- /monitoring_manager/examples/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013 TeYen Liu 3 | # 4 | 5 | TREMA = ../../../trema 6 | SHELL = /bin/sh 7 | 8 | TREMA_CONFIG = $(shell which trema-config) 9 | ifeq ($(TREMA_CONFIG),) 10 | TREMA_CONFIG = $(TREMA)/trema-config 11 | endif 12 | 13 | CC = gcc 14 | AR = ar 15 | RANLIB = ranlib 16 | 17 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -std=gnu99 -D_GNU_SOURCE -g -fno-strict-aliasing -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wfloat-equal -Wpointer-arith -I. -I.. 18 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) -L.. -lmonitoring 19 | 20 | SRCS_COMMON = 21 | OBJS_COMMON = $(SRCS_COMMON:.c=.o) 22 | 23 | TARGET_EXAMPLE1 = example1 24 | SRCS_EXAMPLE1 = example1.c 25 | OBJS_EXAMPLE1 = $(SRCS_EXAMPLE1:.c=.o) 26 | 27 | TARGETS = $(TARGET_EXAMPLE1) $(TARGET_EXAMPLE2) $(TARGET_EXAMPLE3) $(TARGET_EXAMPLE4) $(TARGET_EXAMPLE5) 28 | SRCS = $(SRCS_COMMON) $(SRCS_EXAMPLE1) $(SRCS_EXAMPLE2) $(SRCS_EXAMPLE3) $(SRCS_EXAMPLE4) $(SRCS_EXAMPLE5) 29 | OBJS = $(OBJS_COMMON) $(OBJS_EXAMPLE1) $(OBJS_EXAMPLE2) $(OBJS_EXAMPLE3) $(OBJS_EXAMPLE4) $(OBJS_EXAMPLE5) 30 | 31 | DEPENDS = .depends 32 | 33 | .PHONY: all clean 34 | 35 | .SUFFIXES: .c .o 36 | 37 | all: depend $(TARGETS) 38 | 39 | $(TARGET_EXAMPLE1): $(OBJS_EXAMPLE1) $(OBJS_COMMON) 40 | $(CC) $(OBJS_EXAMPLE1) $(OBJS_COMMON) $(LDFLAGS) -o $@ 41 | 42 | .c.o: 43 | $(CC) $(CFLAGS) -c $< 44 | 45 | depend: 46 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 47 | 48 | clean: 49 | @rm -rf $(DEPENDS) $(OBJS) $(TARGETS) *~ 50 | 51 | -include $(DEPENDS) 52 | -------------------------------------------------------------------------------- /traffic_monitor_memcached/fdb.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Forwarding database (FDB) of layer-2 switch. 3 | # 4 | # Author: Yasuhito Takamiya 5 | # 6 | # Copyright (C) 2008-2012 NEC Corporation 7 | # 8 | # This program is free software; you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License, version 2, as 10 | # published by the Free Software Foundation. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License along 18 | # with this program; if not, write to the Free Software Foundation, Inc., 19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | # 21 | 22 | 23 | require 'rubygems' 24 | require 'memcache' 25 | 26 | 27 | class FDB 28 | DEFAULT_AGE_MAX = 300 29 | 30 | def initialize namespace 31 | @db = MemCache.new( '127.0.0.1:11211', 32 | { 33 | :namespace => "fdb-" << namespace, 34 | :namespace_separator => ',' 35 | } 36 | ) 37 | end 38 | 39 | 40 | def lookup mac 41 | @db[ mac.to_s ] 42 | end 43 | 44 | 45 | def learn mac, port_number 46 | @db.set mac.to_s, port_number, DEFAULT_AGE_MAX 47 | end 48 | end 49 | 50 | 51 | ### Local variables: 52 | ### mode: Ruby 53 | ### coding: utf-8 54 | ### indent-tabs-mode: nil 55 | ### End: 56 | -------------------------------------------------------------------------------- /sliceable_switch/fdb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Forwarding database. 3 | * 4 | * Author: Shuji Ishii 5 | * 6 | * Copyright (C) 2008-2012 NEC Corporation 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License, version 2, as 10 | * published by the Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | */ 21 | 22 | 23 | #ifndef FDB_H 24 | #define FDB_H 25 | 26 | 27 | #include "trema.h" 28 | 29 | 30 | hash_table *create_fdb( void ); 31 | bool is_ether_multicast( const uint8_t mac[ OFP_ETH_ALEN ] ); 32 | void delete_fdb( hash_table *fdb ); 33 | bool update_fdb( hash_table *fdb, const uint8_t mac[ OFP_ETH_ALEN ], uint64_t dpid, uint16_t port ); 34 | bool lookup_fdb( hash_table *fdb, const uint8_t mac[ OFP_ETH_ALEN ], uint64_t *dpid, uint16_t *port ); 35 | void init_age_fdb( hash_table *fdb ); 36 | void delete_fdb_entries( hash_table *fdb, uint64_t dpid, uint16_t port ); 37 | 38 | 39 | #endif // FDB_H 40 | 41 | 42 | /* 43 | * Local variables: 44 | * c-basic-offset: 2 45 | * indent-tabs-mode: nil 46 | * End: 47 | */ 48 | -------------------------------------------------------------------------------- /flow_manager/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011-2013 NEC Corporation 3 | # 4 | 5 | TREMA = ../../trema 6 | 7 | CC = gcc 8 | AR = ar 9 | RANLIB = ranlib 10 | 11 | TREMA_CONFIG = $(shell which trema-config) 12 | ifeq ($(TREMA_CONFIG),) 13 | TREMA_CONFIG = $(TREMA)/trema-config 14 | endif 15 | 16 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -std=gnu99 -D_GNU_SOURCE -g -fno-strict-aliasing -Werror -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wfloat-equal -Wpointer-arith 17 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) 18 | 19 | TARGET_MANAGER = flow_manager 20 | SRCS_MANAGER = flow_manager.c flow_manager_interface.c 21 | OBJS_MANAGER = $(SRCS_MANAGER:.c=.o) 22 | 23 | TARGET_LIB = libpath.a 24 | SRCS_LIB = libpath.c flow_manager_interface.c 25 | OBJS_LIB = $(SRCS_LIB:.c=.o) 26 | 27 | TARGETS = $(TARGET_MANAGER) $(TARGET_LIB) 28 | SRCS = $(SRCS_MANAGER) $(SRCS_LIB) 29 | OBJS = $(OBJS_MANAGER) $(OBJS_LIB) 30 | 31 | EXAMPLES = examples 32 | 33 | DEPENDS = .depends 34 | 35 | .PHONY: all depend clean examples 36 | 37 | .SUFFIXES: .c .o 38 | 39 | all: depend $(TARGETS) examples 40 | 41 | $(TARGET_MANAGER): $(OBJS_MANAGER) 42 | $(CC) $(OBJS_MANAGER) $(LDFLAGS) -o $@ 43 | 44 | $(TARGET_LIB): $(OBJS_LIB) 45 | $(AR) -cq $@ $(OBJS_LIB) 46 | $(RANLIB) $@ 47 | 48 | .c.o: 49 | $(CC) $(CFLAGS) -c $< 50 | 51 | depend: 52 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 53 | 54 | clean: 55 | @rm -rf $(DEPENDS) $(OBJS) $(TARGETS) *~ 56 | cd $(EXAMPLES) && $(MAKE) clean 57 | 58 | examples: 59 | cd $(EXAMPLES) && $(MAKE) 60 | 61 | -include $(DEPENDS) 62 | -------------------------------------------------------------------------------- /topology/subscriber_table.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Shuji Ishii, Kazushi SUGYO 3 | * 4 | * Copyright (C) 2008-2011 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #ifndef SUBSCRIBER_TABLE_H 22 | #define SUBSCRIBER_TABLE_H 23 | 24 | 25 | #include "trema.h" 26 | 27 | 28 | typedef struct subscriber_entry { 29 | char *name; 30 | } subscriber_entry; 31 | 32 | 33 | void init_subscriber_table( void ); 34 | void finalize_subscriber_table( void ); 35 | bool insert_subscriber_entry( const char *name ); 36 | void delete_subscriber_entry( subscriber_entry *entry ); 37 | subscriber_entry *lookup_subscriber_entry( const char *name ); 38 | void foreach_subscriber( void function( subscriber_entry *entry, void *user_data ), void *user_data ); 39 | 40 | 41 | #endif // SUBSCRIBER_TABLE_H 42 | 43 | 44 | /* 45 | * Local variables: 46 | * c-basic-offset: 2 47 | * indent-tabs-mode: nil 48 | * End: 49 | */ 50 | -------------------------------------------------------------------------------- /learning_switch_edged/fdb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2013 NEC Corporation 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License, version 2, as 6 | * published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16 | */ 17 | 18 | 19 | #ifndef FDB_H 20 | #define FDB_H 21 | 22 | #include "trema.h" 23 | 24 | 25 | #define MAX_AGE 300 26 | #define ENTRY_NOT_FOUND_IN_FDB OFPP_ALL 27 | #define MAC_STRING_LENGTH 18 28 | 29 | 30 | bool mac_to_string( const uint8_t *mac, char *str, size_t size ); 31 | hash_table *create_fdb( void ); 32 | uint32_t lookup_fdb( hash_table *db, const uint8_t *mac, time_t *updated_at ); 33 | void update_fdb( hash_table *db, const uint8_t *mac, uint32_t port_number ); 34 | void delete_forwarding_entries_by_port_number( hash_table *db, uint32_t port_number ); 35 | void delete_aged_forwarding_entries( hash_table *db ); 36 | void delete_fdb( hash_table *db ); 37 | 38 | 39 | #endif // FDB_H 40 | 41 | 42 | /* 43 | * Local variables: 44 | * c-basic-offset: 2 45 | * indent-tabs-mode: nil 46 | * End: 47 | */ 48 | -------------------------------------------------------------------------------- /transaction_manager/README.md: -------------------------------------------------------------------------------- 1 | Transaction manager 2 | =================== 3 | 4 | What's this? 5 | ------------ 6 | 7 | Transaction manager is a library and provides a function to ensure any 8 | controller-generated transaction (operation) has been executed on a 9 | switch. Barrier request/reply messages are automatically sent by the 10 | transaction manager to complete the transaction. When the transaction 11 | has been completed successfully or unsuccessfully, the caller of the 12 | function is notified. 13 | 14 | How to use 15 | ---------- 16 | 17 | Please refer to transaction_manager.h and examples as references for 18 | understanding how to use the APIs. 19 | 20 | How to build 21 | ------------ 22 | 23 | Get Trema and Apps 24 | 25 | $ sudo gem install trema 26 | $ git clone git://github.com/trema/apps.git apps 27 | 28 | Build transaction manager and its examples 29 | 30 | $ cd ./apps/transaction_manager 31 | $ make 32 | 33 | How to run examples 34 | ------------------- 35 | 36 | $ trema run ./examples/example -c ./examples/example.conf 37 | 38 | License 39 | ------- 40 | 41 | Copyright (C) 2012-2013 NEC Corporation 42 | 43 | This program is free software; you can redistribute it and/or modify 44 | it under the terms of the GNU General Public License, version 2, as 45 | published by the Free Software Foundation. 46 | 47 | This program is distributed in the hope that it will be useful, but 48 | WITHOUT ANY WARRANTY; without even the implied warranty of 49 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 50 | General Public License for more details. 51 | -------------------------------------------------------------------------------- /learning_switch_memcached/fdb.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Forwarding database (FDB) 3 | # 4 | # Author: Yasuhito Takamiya 5 | # 6 | # Copyright (C) 2008-2011 NEC Corporation 7 | # 8 | # This program is free software; you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License, version 2, as 10 | # published by the Free Software Foundation. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License along 18 | # with this program; if not, write to the Free Software Foundation, Inc., 19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | # 21 | 22 | # 23 | # Forwarding database with memcached 24 | # 25 | # Author: Kazushi SUGYO 26 | # 27 | 28 | 29 | require 'rubygems' 30 | require 'memcache' 31 | 32 | 33 | # 34 | # A database that keep pairs of MAC address and port number 35 | # 36 | class FDB 37 | DEFAULT_AGE_MAX = 300 38 | 39 | 40 | def initialize namespace = nil 41 | @db = MemCache.new( '127.0.0.1:11211', { :namespace => namespace, :namespace_separator => '-' } ) 42 | end 43 | 44 | 45 | def port_no_of mac 46 | @db[ mac.to_s ] 47 | end 48 | 49 | 50 | def learn mac, port_no 51 | @db.set mac.to_s, port_no, DEFAULT_AGE_MAX 52 | end 53 | end 54 | 55 | 56 | ### Local variables: 57 | ### mode: Ruby 58 | ### coding: utf-8 59 | ### indent-tabs-mode: nil 60 | ### End: 61 | -------------------------------------------------------------------------------- /monitoring_manager/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013 TeYen Liu 3 | # 4 | 5 | TREMA = ../../trema 6 | CC = gcc 7 | AR = ar 8 | SHELL = /bin/sh 9 | RANLIB = ranlib 10 | TREMA_APPS = .. 11 | 12 | TREMA_CONFIG = $(shell which trema-config) 13 | ifeq ($(TREMA_CONFIG),) 14 | TREMA_CONFIG = $(TREMA)/trema-config 15 | endif 16 | 17 | CC = gcc 18 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -I$(TREMA_APPS)/topology -I$(TREMA_APPS)/flow_manager -std=gnu99 -g -D_GNU_SOURCE -Wall 19 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) -L$(TREMA_APPS)/topology -ltopology -L$(TREMA_APPS)/flow_manager -lpath 20 | 21 | TARGET_MANAGER = monitoring 22 | SRCS_MANAGER = monitoring.c libmonitoring.c monitoring_interface.c utilmonitoring.c toolutils.c 23 | OBJS_MANAGER = $(SRCS_MANAGER:.c=.o) 24 | 25 | TARGET_LIB = libmonitoring.a 26 | SRCS_LIB = libmonitoring.c monitoring_interface.c toolutils.c 27 | OBJS_LIB = $(SRCS_LIB:.c=.o) 28 | 29 | EXAMPLES = examples 30 | 31 | TARGETS = $(TARGET_MANAGER) $(TARGET_LIB) 32 | SRCS = $(SRCS_MANAGER) $(SRCS_LIB) 33 | OBJS = $(OBJS_MANAGER) $(OBJS_LIB) 34 | 35 | DEPENDS = .depends 36 | 37 | .PHONY: all depend clean examples 38 | 39 | .SUFFIXES: .c .o 40 | 41 | all: depend $(TARGETS) examples 42 | 43 | $(TARGET_MANAGER): $(OBJS_MANAGER) 44 | $(CC) $(OBJS_MANAGER) $(LDFLAGS) -o $@ 45 | 46 | $(TARGET_LIB): $(OBJS_LIB) 47 | $(AR) -cq $@ $(OBJS_LIB) 48 | $(RANLIB) $@ 49 | 50 | .c.o: 51 | $(CC) $(CFLAGS) -c $< 52 | 53 | depend: 54 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 55 | 56 | clean: 57 | @rm -rf $(DEPENDS) $(OBJS) $(TARGETS) *~ 58 | 59 | examples: 60 | cd $(EXAMPLES) && $(MAKE) 61 | 62 | -include $(DEPENDS) 63 | -------------------------------------------------------------------------------- /routing_switch/routing_switch_lldp_over_ip_fullmesh.conf: -------------------------------------------------------------------------------- 1 | vswitch { 2 | datapath_id "0x1" 3 | } 4 | 5 | vswitch { 6 | datapath_id "0x2" 7 | } 8 | 9 | vswitch { 10 | datapath_id "0x3" 11 | } 12 | 13 | vswitch { 14 | datapath_id "0x4" 15 | } 16 | 17 | vhost ("host1") { 18 | ip "192.168.0.1" 19 | netmask "255.255.0.0" 20 | mac "00:00:00:01:00:01" 21 | } 22 | 23 | vhost ("host2") { 24 | ip "192.168.0.2" 25 | netmask "255.255.0.0" 26 | mac "00:00:00:01:00:02" 27 | } 28 | 29 | vhost ("host3") { 30 | ip "192.168.0.3" 31 | netmask "255.255.0.0" 32 | mac "00:00:00:01:00:03" 33 | } 34 | 35 | vhost ("host4") { 36 | ip "192.168.0.4" 37 | netmask "255.255.0.0" 38 | mac "00:00:00:01:00:04" 39 | } 40 | 41 | link "0x1", "host1" 42 | link "0x2", "host2" 43 | link "0x3", "host3" 44 | link "0x4", "host4" 45 | link "0x1", "0x2" 46 | link "0x1", "0x3" 47 | link "0x1", "0x4" 48 | link "0x2", "0x3" 49 | link "0x2", "0x4" 50 | link "0x3", "0x4" 51 | 52 | $apps_dir = File.join( File.dirname( __FILE__ ), ".." ) 53 | 54 | run { 55 | path File.join( $apps_dir, "./topology/topology" ) 56 | options "--lldp_over_ip", "--lldp_ip_src=10.42.122.202", "--lldp_ip_dst=10.42.122.212" 57 | } 58 | 59 | run { 60 | path File.join( $apps_dir, "./topology/topology_discovery" ) 61 | options "--lldp_over_ip", "--lldp_ip_src=10.42.122.202", "--lldp_ip_dst=10.42.122.212" 62 | } 63 | 64 | run { 65 | path File.join( $apps_dir, "./routing_switch/routing_switch" ) 66 | } 67 | 68 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 69 | filter :lldp => "topology_discovery", :packet_in => "routing_switch" 70 | -------------------------------------------------------------------------------- /routing_switch/features/step_definitions/send_packets_steps.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2008-2012 NEC Corporation 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License, version 2, as 6 | # published by the Free Software Foundation. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License along 14 | # with this program; if not, write to the Free Software Foundation, Inc., 15 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16 | # 17 | 18 | 19 | When /^I send (\d+) packets from (.+) to (.+)$/ do | n_packets, host_a, host_b | 20 | run "./trema send_packets --source #{ host_a } --dest #{ host_b } --n_pkts #{ n_packets }" 21 | sleep 5 # ensure that all packets are sent 22 | end 23 | 24 | 25 | When /^I send 1 packet from (.+) to (.+)$/ do | host_a, host_b | 26 | step "I send 1 packets from #{ host_a } to #{ host_b }" 27 | sleep 1 # ensure that all packets are sent 28 | end 29 | 30 | 31 | When /^I send packets from (.+) to (.+) \(duration = (\d+)\)$/ do | host_a, host_b, duration | 32 | run "./trema send_packets --source #{ host_a } --dest #{ host_b } --duration #{ duration }" 33 | sleep 1 # ensure that all packets are sent 34 | end 35 | 36 | 37 | ### Local variables: 38 | ### mode: Ruby 39 | ### coding: utf-8-unix 40 | ### indent-tabs-mode: nil 41 | ### End: 42 | -------------------------------------------------------------------------------- /simple_restapi_manager/simple_restapi_manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: TeYen Liu 3 | * 4 | * Copyright (C) 2013 TeYen Liu 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #ifndef SIMPLE_RESTAPI_MANAGER_H 22 | #define SIMPLE_RESTAPI_MANAGER_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include "mongoose.h" 29 | 30 | /* define REST API Callback Function Pointer */ 31 | typedef char* ( *restapi_callback_func )( const struct mg_request_info *request_info, void *request_data ); 32 | 33 | bool start_restapi_manager(); 34 | bool add_restapi_url( const char *url_str, const char *method, restapi_callback_func restapi_callback ); 35 | bool delete_restapi_url(); 36 | 37 | bool init_restapi_manager(); 38 | bool finalize_restapi_manager(); 39 | 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif // SIMPLE_RESTAPI_MANAGER_H 46 | 47 | 48 | /* 49 | * Local variables: 50 | * c-basic-offset: 2 51 | * indent-tabs-mode: nil 52 | * End: 53 | */ 54 | -------------------------------------------------------------------------------- /sliceable_switch/features/step_definitions/send_packets_steps.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2008-2012 NEC Corporation 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License, version 2, as 6 | # published by the Free Software Foundation. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License along 14 | # with this program; if not, write to the Free Software Foundation, Inc., 15 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16 | # 17 | 18 | 19 | When /^I send (\d+) packets from (.+) to (.+)$/ do | n_packets, host_a, host_b | 20 | run "./trema send_packets --source #{ host_a } --dest #{ host_b } --n_pkts #{ n_packets }" 21 | sleep 5 # ensure that all packets are sent 22 | end 23 | 24 | 25 | When /^I send 1 packet from (.+) to (.+)$/ do | host_a, host_b | 26 | step "I send 1 packets from #{ host_a } to #{ host_b }" 27 | sleep 1 # ensure that all packets are sent 28 | end 29 | 30 | 31 | When /^I send packets from (.+) to (.+) \(duration = (\d+)\)$/ do | host_a, host_b, duration | 32 | run "./trema send_packets --source #{ host_a } --dest #{ host_b } --duration #{ duration }" 33 | sleep 1 # ensure that all packets are sent 34 | end 35 | 36 | 37 | ### Local variables: 38 | ### mode: Ruby 39 | ### coding: utf-8-unix 40 | ### indent-tabs-mode: nil 41 | ### End: 42 | -------------------------------------------------------------------------------- /path_manager/path_manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Yasunobu Chiba 3 | * 4 | * Copyright (C) 2008-2011 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #ifndef PATH_MANAGER_H 22 | #define PATH_MANAGER_H 23 | 24 | 25 | #include 26 | #include "trema.h" 27 | 28 | 29 | #define PATH_SETUP_SERVICE_NAME "path_setup_service" 30 | 31 | 32 | /** 33 | * Message type definition for path setup requests. 34 | */ 35 | enum { 36 | MESSENGER_PATH_SETUP_REQUEST = 0x9001, 37 | }; 38 | 39 | 40 | typedef struct { 41 | uint64_t datapath_id; 42 | uint16_t in_port; 43 | uint16_t out_port; 44 | } __attribute__( ( packed ) ) path_manager_hop; 45 | 46 | 47 | typedef struct { 48 | struct ofp_match match; 49 | uint16_t n_hops; 50 | path_manager_hop hops[ 0 ]; 51 | } __attribute__( ( packed ) ) path_manager_path; 52 | 53 | 54 | 55 | #endif // PATH_MANAGER_H 56 | 57 | 58 | /* 59 | * Local variables: 60 | * c-basic-offset: 2 61 | * indent-tabs-mode: nil 62 | * End: 63 | */ 64 | -------------------------------------------------------------------------------- /routing_switch/fdb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample routing switch (switching HUB) application. 3 | * 4 | * This application provides a switching HUB function using multiple 5 | * openflow switches. 6 | * 7 | * Author: Shuji Ishii 8 | * 9 | * Copyright (C) 2008-2011 NEC Corporation 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License, version 2, as 13 | * published by the Free Software Foundation. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License along 21 | * with this program; if not, write to the Free Software Foundation, Inc., 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 | */ 24 | 25 | 26 | #ifndef FDB_H 27 | #define FDB_H 28 | 29 | 30 | #include "trema.h" 31 | 32 | 33 | hash_table *create_fdb( void ); 34 | bool is_ether_multicast( const uint8_t mac[ OFP_ETH_ALEN ] ); 35 | void delete_fdb( hash_table *fdb ); 36 | bool update_fdb( hash_table *fdb, const uint8_t mac[ OFP_ETH_ALEN ], uint64_t dpid, uint16_t port ); 37 | bool lookup_fdb( hash_table *fdb, const uint8_t mac[ OFP_ETH_ALEN ], uint64_t *dpid, uint16_t *port ); 38 | void init_age_fdb( hash_table *fdb ); 39 | void delete_fdb_entries( hash_table *fdb, uint64_t dpid, uint16_t port ); 40 | 41 | 42 | #endif // FDB_H 43 | 44 | 45 | /* 46 | * Local variables: 47 | * c-basic-offset: 2 48 | * indent-tabs-mode: nil 49 | * End: 50 | */ 51 | -------------------------------------------------------------------------------- /redirectable_routing_switch/fdb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample routing switch (switching HUB) application. 3 | * 4 | * This application provides a switching HUB function using multiple 5 | * openflow switches. 6 | * 7 | * Author: Shuji Ishii 8 | * 9 | * Copyright (C) 2008-2011 NEC Corporation 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License, version 2, as 13 | * published by the Free Software Foundation. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License along 21 | * with this program; if not, write to the Free Software Foundation, Inc., 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 | */ 24 | 25 | 26 | #ifndef FDB_H 27 | #define FDB_H 28 | 29 | 30 | #include "trema.h" 31 | 32 | 33 | hash_table *create_fdb( void ); 34 | bool is_ether_multicast( const uint8_t mac[ OFP_ETH_ALEN ] ); 35 | void delete_fdb( hash_table *fdb ); 36 | bool update_fdb( hash_table *fdb, const uint8_t mac[ OFP_ETH_ALEN ], uint64_t dpid, uint16_t port ); 37 | bool lookup_fdb( hash_table *fdb, const uint8_t mac[ OFP_ETH_ALEN ], uint64_t *dpid, uint16_t *port ); 38 | void init_age_fdb( hash_table *fdb ); 39 | void delete_fdb_entries( hash_table *fdb, uint64_t dpid, uint16_t port ); 40 | 41 | 42 | #endif // FDB_H 43 | 44 | 45 | /* 46 | * Local variables: 47 | * c-basic-offset: 2 48 | * indent-tabs-mode: nil 49 | * End: 50 | */ 51 | -------------------------------------------------------------------------------- /transaction_manager/transaction_manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Yasunobu Chiba 3 | * 4 | * Copyright (C) 2012-2013 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #ifndef TRANSACTION_MANAGER_H 22 | #define TRANSACTION_MANAGER_H 23 | 24 | 25 | #include "trema.h" 26 | 27 | 28 | typedef void ( *succeeded_handler )( 29 | uint64_t datapath_id, 30 | const buffer *original_message, 31 | void *user_data 32 | ); 33 | 34 | 35 | typedef void ( *failed_handler )( 36 | uint64_t datapath_id, 37 | const buffer *original_message, 38 | void *user_data 39 | ); 40 | 41 | 42 | bool execute_transaction( uint64_t datapath_id, const buffer *message, 43 | succeeded_handler succeeded_callback, void *succeeded_user_data, 44 | failed_handler failed_callback, void *failed_user_data ); 45 | bool init_transaction_manager(); 46 | bool finalize_transaction_manager(); 47 | 48 | 49 | #endif // TRANSACTION_MANAGER_H 50 | 51 | 52 | /* 53 | * Local variables: 54 | * c-basic-offset: 2 55 | * indent-tabs-mode: nil 56 | * End: 57 | */ 58 | -------------------------------------------------------------------------------- /routing_switch/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011-2013 NEC Corporation 3 | # 4 | 5 | TREMA = ../../trema 6 | GEM_BIN = `ruby -e 'require "rubygems"; puts Gem::bindir'` 7 | SHELL = /bin/sh 8 | 9 | TREMA_CONFIG = $(shell which trema-config) 10 | ifeq ($(TREMA_CONFIG),) 11 | TREMA_CONFIG = $(TREMA)/trema-config 12 | endif 13 | 14 | CC = gcc 15 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -I../topology -g -std=gnu99 -D_GNU_SOURCE -fno-strict-aliasing -Werror -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wfloat-equal -Wpointer-arith 16 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) -L../topology -ltopology 17 | 18 | TARGET = routing_switch 19 | SRCS = fdb.c libpathresolver.c port.c routing_switch.c 20 | OBJS = $(SRCS:.c=.o) 21 | 22 | FEATURES = routing_switch.feature 23 | 24 | DEPENDS = .depends 25 | 26 | .PHONY: all clean 27 | 28 | .SUFFIXES: .c .o 29 | 30 | all: depend $(TARGET) 31 | 32 | $(TARGET): $(OBJS) 33 | $(CC) $(OBJS) $(LDFLAGS) -o $@ 34 | 35 | .c.o: 36 | $(CC) $(CFLAGS) -c $< 37 | 38 | depend: 39 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 40 | 41 | clean: 42 | @rm -rf $(DEPENDS) $(OBJS) $(TARGET) *~ 43 | 44 | run_acceptance_test: 45 | @for feature in $(FEATURES); do \ 46 | ( \ 47 | file=`pwd`/$$feature; \ 48 | cd ${TREMA}; \ 49 | ${GEM_BIN}/cucumber -r ../apps/routing_switch/features $$file; \ 50 | ) \ 51 | done 52 | 53 | cbench: 54 | ( \ 55 | set -x; \ 56 | cd ${TREMA}; \ 57 | ./trema run -c ../apps/routing_switch/routing_switch_null.conf -d; \ 58 | objects/oflops/bin/cbench --switches 1 --loops 10 --delay 15000; \ 59 | objects/oflops/bin/cbench --switches 1 --loops 10 --delay 15000 --throughput; \ 60 | ./trema killall; \ 61 | ) 62 | 63 | -include $(DEPENDS) 64 | -------------------------------------------------------------------------------- /routing_switch/features/support/env.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author: Kazushi SUGYO 3 | # 4 | # Copyright (C) 2008-2011 NEC Corporation 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License, version 2, as 8 | # published by the Free Software Foundation. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License along 16 | # with this program; if not, write to the Free Software Foundation, Inc., 17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | # 19 | 20 | $LOAD_PATH.unshift( File.expand_path( File.dirname( __FILE__ ) + "/../../../../trema/ruby" ) ) 21 | 22 | 23 | require "tempfile" 24 | require "trema/executables" 25 | 26 | 27 | def run command 28 | raise "Failed to execute #{ command }" unless system( command ) 29 | end 30 | 31 | 32 | def ps_entry_of name 33 | `ps -ef | grep -w "#{ name } " | grep -v grep` 34 | end 35 | 36 | 37 | def cucumber_log name 38 | File.join Trema.log, name 39 | end 40 | 41 | 42 | def new_tmp_log 43 | system "rm #{ Trema.log }/tmp.*" # cleanup 44 | `mktemp --tmpdir=#{ Trema.log }`.chomp 45 | end 46 | 47 | 48 | # show_stats output format: 49 | # ip_dst,tp_dst,ip_src,tp_src,n_pkts,n_octets 50 | def count_packets stats 51 | return 0 if stats.split.size <= 1 52 | stats.split[ 1..-1 ].inject( 0 ) do | sum, each | 53 | sum += each.split( "," )[ 4 ].to_i 54 | end 55 | end 56 | 57 | 58 | ### Local variables: 59 | ### mode: Ruby 60 | ### coding: utf-8-unix 61 | ### indent-tabs-mode: nil 62 | ### End: 63 | -------------------------------------------------------------------------------- /learning_switch_edged/flow_entry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2013 NEC Corporation 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License, version 2, as 6 | * published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along 14 | * with this program; if not, write to the Free Software Foundation, Inc., 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16 | */ 17 | 18 | 19 | #ifndef FLOW_ENTRY_H 20 | #define FLOW_ENTRY_H 21 | 22 | #include "trema.h" 23 | 24 | 25 | #define INPUT_TABLE_ID 0 26 | #define OUTPUT_TABLE_ID 3 27 | 28 | 29 | void insert_output_flow_entry( uint8_t mac[ OFP_ETH_ALEN ], uint64_t datapath_id, uint32_t port_number ); 30 | void delete_output_flow_entry( uint8_t mac[ OFP_ETH_ALEN ], uint64_t datapath_id, uint32_t port_number ); 31 | void delete_output_flow_entries_by_outport( uint64_t datapath_id, uint32_t port_number ); 32 | void insert_input_flow_entry( uint8_t mac[ OFP_ETH_ALEN ], uint64_t datapath_id, uint32_t port_number ); 33 | void delete_input_flow_entry( uint8_t mac[ OFP_ETH_ALEN ], uint64_t datapath_id, uint32_t port_number ); 34 | void delete_input_flow_entries_by_inport( uint64_t datapath_id, uint32_t port_number ); 35 | void insert_table_miss_flow_entry( uint64_t datapath_id, uint8_t table_id ); 36 | 37 | 38 | #endif // FLOW_ENTRY_H 39 | 40 | 41 | /* 42 | * Local variables: 43 | * c-basic-offset: 2 44 | * indent-tabs-mode: nil 45 | * End: 46 | */ 47 | -------------------------------------------------------------------------------- /monitoring_manager/examples/example1.conf: -------------------------------------------------------------------------------- 1 | # virtual switches 2 | vswitch("switch1") { datapath_id "0xe1" } 3 | vswitch("switch2") { datapath_id "0xe2" } 4 | vswitch("switch3") { datapath_id "0xe3" } 5 | vswitch("switch4") { datapath_id "0xe4" } 6 | vswitch("switch5") { datapath_id "0xe5" } 7 | 8 | # virtual hosts 9 | vhost("host1"){ 10 | ip "192.168.0.1" 11 | netmask "255.255.0.0" 12 | mac "00:00:00:01:00:01" 13 | } 14 | vhost("host2"){ 15 | ip "192.168.0.2" 16 | netmask "255.255.0.0" 17 | mac "00:00:00:01:00:02" 18 | } 19 | vhost("host3"){ 20 | ip "192.168.0.3" 21 | netmask "255.255.0.0" 22 | mac "00:00:00:01:00:03" 23 | } 24 | vhost("host4"){ 25 | ip "192.168.0.4" 26 | netmask "255.255.0.0" 27 | mac "00:00:00:01:00:04" 28 | } 29 | 30 | # virtual links 31 | link "switch1", "switch2" 32 | link "switch1", "switch3" 33 | link "switch2", "switch3" 34 | link "switch2", "switch4" 35 | link "switch2", "switch5" 36 | link "switch3", "switch4" 37 | link "switch3", "switch5" 38 | link "switch4", "host1" 39 | link "switch4", "host2" 40 | link "switch5", "host3" 41 | link "switch5", "host4" 42 | 43 | 44 | $apps_dir = File.join( File.dirname( __FILE__ ), "../" ) 45 | 46 | run { 47 | path File.join( $apps_dir, "../topology/topology" ) 48 | } 49 | 50 | run { 51 | path File.join( $apps_dir, "../topology/topology_discovery" ) 52 | } 53 | 54 | run { 55 | path File.join( $apps_dir, "monitoring" ) 56 | #You can uncomment these options to change the threshold conditions 57 | #options "-b", "4194304", "-t", "2", "-f", "104857600", "-p", "80" 58 | } 59 | 60 | run { 61 | path File.join( $apps_dir, "examples/example1" ) 62 | } 63 | 64 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 65 | filter :lldp => "topology_discovery", :packet_in => "example1" 66 | -------------------------------------------------------------------------------- /monitoring_manager/toolutils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Monitoring 3 | * 4 | * Author: TeYen Liu 5 | * 6 | * Copyright (C) 2013 TeYen Liu 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License, version 2, as 10 | * published by the Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | */ 21 | 22 | 23 | #include 24 | #include "toolutils.h" 25 | 26 | static char static_match_str[ 256 ]; 27 | static char static_actions_str[ 256 ]; 28 | 29 | char* get_static_match_str( struct ofp_match *match ) { 30 | memset( static_match_str, '\0', sizeof( static_match_str ) ); 31 | match_to_string( match, static_match_str, sizeof( static_match_str ) ); 32 | return static_match_str; 33 | } 34 | 35 | char* get_static_actions_str( struct ofp_flow_stats *stats ) { 36 | memset( static_actions_str, '\0', sizeof( static_actions_str ) ); 37 | uint16_t actions_length = (uint16_t) (stats->length - offsetof( struct ofp_flow_stats, actions )); 38 | if ( actions_length > 0 ) { 39 | actions_to_string( stats->actions, actions_length, static_actions_str, sizeof( static_actions_str ) ); 40 | } 41 | return static_actions_str; 42 | } -------------------------------------------------------------------------------- /learning_switch_edged/datapath-db.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2008-2013 NEC Corporation 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License, version 2, as 6 | # published by the Free Software Foundation. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License along 14 | # with this program; if not, write to the Free Software Foundation, Inc., 15 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16 | # 17 | 18 | 19 | class DatapathEntry 20 | attr_reader :id 21 | attr_reader :fdb 22 | 23 | 24 | def initialize datapath_id, fdb 25 | @id = datapath_id 26 | @fdb = fdb 27 | end 28 | end 29 | 30 | 31 | class DatapathDB 32 | include Trema::Logger 33 | 34 | 35 | def initialize 36 | @db = {} 37 | end 38 | 39 | 40 | def insert datapath_id, fdb 41 | debug "insert switch: #{ datapath_id }" 42 | if @db[ datapath_id ] 43 | warn "duplicated switch ( datapath_id = #{ datapath_id } )" 44 | end 45 | @db[ datapath_id ] = DatapathEntry.new( datapath_id, fdb ) 46 | end 47 | 48 | 49 | def lookup datapath_id 50 | debug "lookup switch: #{ datapath_id }" 51 | @db[ datapath_id ] 52 | end 53 | 54 | 55 | def delete datapath_id 56 | debug "delete switch: #{ datapath_id }" 57 | @db.delete( datapath_id ) 58 | end 59 | 60 | 61 | def each_value &block 62 | @db.each_value do | each | 63 | block.call each.fdb 64 | end 65 | end 66 | end 67 | 68 | 69 | ### Local variables: 70 | ### mode: Ruby 71 | ### coding: utf-8 72 | ### indent-tabs-mode: nil 73 | ### End: 74 | -------------------------------------------------------------------------------- /sliceable_switch/features/step_definitions/create_table_steps.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author: Kazushi SUGYO 3 | # 4 | # Copyright (C) 2008-2011 NEC Corporation 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License, version 2, as 8 | # published by the Free Software Foundation. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License along 16 | # with this program; if not, write to the Free Software Foundation, Inc., 17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | # 19 | 20 | 21 | Given /^the following filter records$/ do | table | 22 | create_filter_table 23 | table.hashes.each do | hash | 24 | filter_add hash 25 | end 26 | end 27 | 28 | 29 | Given /^the following slice records$/ do | table | 30 | create_slice_table 31 | table.hashes.each do | hash | 32 | slice_create hash 33 | end 34 | end 35 | 36 | 37 | Given /^the following port binding records$/ do | table | 38 | table.hashes.each do | hash | 39 | slice_add_port hash 40 | end 41 | end 42 | 43 | 44 | Given /^the following mac binding records$/ do | table | 45 | table.hashes.each do | hash | 46 | slice_add_mac hash 47 | end 48 | end 49 | 50 | 51 | 52 | Given /^the following port and mac binding records$/ do | table | 53 | table.hashes.each do | hash | 54 | slice_add_port_mac hash 55 | end 56 | end 57 | 58 | 59 | Given /^the slice table from script "([^"]*)"$/ do | script | 60 | create_slice_table_from script 61 | end 62 | 63 | 64 | ### Local variables: 65 | ### mode: Ruby 66 | ### coding: utf-8-unix 67 | ### indent-tabs-mode: nil 68 | ### End: 69 | -------------------------------------------------------------------------------- /flow_dumper/README.md: -------------------------------------------------------------------------------- 1 | Flow Dumper Application 2 | ======================= 3 | 4 | What's this? 5 | ------------ 6 | 7 | This application retrieves flow entries from all switches connected and 8 | outputs flow entries in text form on console terminal. 9 | 10 | How to build 11 | ------------ 12 | 13 | Get Trema and Apps 14 | 15 | $ sudo gem install trema 16 | $ git clone git://github.com/trema/apps.git apps 17 | 18 | Build flow dumper 19 | 20 | $ cd ./apps/flow_dumper 21 | $ make 22 | $ cd ../../ 23 | 24 | How to run 25 | ------------ 26 | 27 | Run a controller application developed on top of Trema which installs 28 | flow entries. For example: 29 | 30 | $ trema run -c ./apps/routing_switch.conf -d 31 | 32 | Run flow dumper 33 | 34 | $ trema run ./apps/flow_dumper/flow_dumper 35 | 36 | Or 37 | 38 | $ trema run ./apps/flow_dumper/flow-dumper.rb 39 | 40 | If you have any flow entries, you can see output like follows: 41 | 42 | $ trema run ./apps/flow_dumper/flow_dumper 43 | [0x00000000000abc] priority = 65535, match = [wildcards = 0, in_port = 1, 44 | dl_src = 00:00:00:01:00:02, dl_dst = 00:00:00:01:00:01, dl_vlan = 65535, 45 | dl_vlan_pcp = 0, dl_type = 0x800, nw_tos = 0, nw_proto = 17, 46 | nw_src = 192.168.0.2, nw_dst = 192.168.0.1, tp_src = 1, tp_dst = 1], 47 | actions = [output: port=2 max_len=65535] 48 | 49 | License 50 | ------------ 51 | 52 | Copyright (C) 2011-2013 NEC Corporation 53 | 54 | This program is free software; you can redistribute it and/or modify 55 | it under the terms of the GNU General Public License, version 2, as 56 | published by the Free Software Foundation. 57 | 58 | This program is distributed in the hope that it will be useful, but 59 | WITHOUT ANY WARRANTY; without even the implied warranty of 60 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 61 | General Public License for more details. 62 | -------------------------------------------------------------------------------- /load_balance_switch/path_resolver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Shuji Ishii 3 | * 4 | * Copyright (C) 2008-2011 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #ifndef PATH_RESOLVER_H 22 | #define PATH_RESOLVER_H 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | #include "libtopology.h" 29 | #include "hash_table.h" 30 | #include "doubly_linked_list.h" 31 | 32 | 33 | typedef struct { 34 | hash_table *topology_table; 35 | hash_table *node_table; 36 | hash_table *link_stats_table; 37 | } path_resolver; 38 | 39 | 40 | typedef struct { 41 | uint64_t dpid; 42 | uint16_t in_port_no; 43 | uint16_t out_port_no; 44 | } path_resolver_hop; 45 | 46 | 47 | dlist_element *resolve_path( path_resolver *table, uint64_t in_dpid, uint16_t in_port, 48 | uint64_t out_dpid, uint16_t out_port ); 49 | void free_hop_list( dlist_element *hops ); 50 | path_resolver *create_path_resolver( void ); 51 | bool delete_path_resolver( path_resolver *table ); 52 | void update_topology( path_resolver *table, const topology_link_status *s ); 53 | 54 | 55 | #endif // PATH_RESOLVER_H 56 | 57 | 58 | /* 59 | * Local variables: 60 | * c-basic-offset: 2 61 | * indent-tabs-mode: nil 62 | * End: 63 | */ 64 | -------------------------------------------------------------------------------- /sliceable_switch/slice.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Slicing functions for creating virtual layer 2 domains. 3 | * 4 | * Author: Yasunobu Chiba, Lei SUN 5 | * 6 | * Copyright (C) 2008-2012 NEC Corporation 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License, version 2, as 10 | * published by the Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | */ 21 | 22 | 23 | #ifndef SLICE_H 24 | #define SLICE_H 25 | 26 | 27 | #include 28 | #include "trema.h" 29 | #include "sliceable_switch.h" 30 | 31 | 32 | #define SLICE_NOT_FOUND 0xffff 33 | #define VLAN_NONE 0xffff 34 | 35 | #define LOOSE_MAC_BASED_SLICING 0x0001 36 | #define RESTRICT_HOSTS_ON_PORT 0x0002 37 | 38 | 39 | bool init_slice( const char *file, uint16_t mode, sliceable_switch *sliceable_switch ); 40 | bool finalize_slice(); 41 | uint16_t lookup_slice( uint64_t datapath_id, uint16_t port, uint16_t vid, const uint8_t *mac ); 42 | void delete_dynamic_port_slice_bindings( uint64_t datapath_id, uint16_t port ); 43 | bool get_port_vid( uint16_t slice, uint64_t datapath_id, uint16_t port, uint16_t *vid ); 44 | uint16_t lookup_slice_by_mac( const uint8_t *mac ); 45 | bool loose_mac_based_slicing_enabled(); 46 | bool mac_slice_maps_exist( uint16_t slice_number ); 47 | 48 | 49 | #endif // SLICE_H 50 | 51 | 52 | /* 53 | * Local variables: 54 | * c-basic-offset: 2 55 | * indent-tabs-mode: nil 56 | * End: 57 | */ 58 | -------------------------------------------------------------------------------- /routing_switch/libpathresolver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Path Resolver with dijkstra method 3 | * 4 | * Author: Shuji Ishii 5 | * 6 | * Copyright (C) 2008-2011 NEC Corporation 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License, version 2, as 10 | * published by the Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | */ 21 | 22 | 23 | #ifndef LIBPATHRESOLVER_H 24 | #define LIBPATHRESOLVER_H 25 | 26 | 27 | #include 28 | #include 29 | #include 30 | #include "libtopology.h" 31 | #include "hash_table.h" 32 | #include "doubly_linked_list.h" 33 | 34 | 35 | typedef struct { 36 | hash_table *topology_table; 37 | hash_table *node_table; 38 | } pathresolver; 39 | 40 | 41 | typedef struct { 42 | uint64_t dpid; 43 | uint16_t in_port_no; 44 | uint16_t out_port_no; 45 | } pathresolver_hop; 46 | 47 | 48 | dlist_element *resolve_path( pathresolver *table, uint64_t in_dpid, uint16_t in_port, 49 | uint64_t out_dpid, uint16_t out_port ); 50 | void free_hop_list( dlist_element *hops ); 51 | pathresolver *create_pathresolver( void ); 52 | bool delete_pathresolver( pathresolver *table ); 53 | void update_topology( pathresolver *table, const topology_link_status *s ); 54 | 55 | 56 | #endif // LIBPATHRESOLVER_H 57 | 58 | 59 | /* 60 | * Local variables: 61 | * c-basic-offset: 2 62 | * indent-tabs-mode: nil 63 | * End: 64 | */ 65 | -------------------------------------------------------------------------------- /sliceable_switch/libpathresolver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Path Resolver with dijkstra method 3 | * 4 | * Author: Shuji Ishii 5 | * 6 | * Copyright (C) 2008-2012 NEC Corporation 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License, version 2, as 10 | * published by the Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | */ 21 | 22 | 23 | #ifndef LIBPATHRESOLVER_H 24 | #define LIBPATHRESOLVER_H 25 | 26 | 27 | #include 28 | #include 29 | #include 30 | #include "libtopology.h" 31 | #include "hash_table.h" 32 | #include "doubly_linked_list.h" 33 | 34 | 35 | typedef struct { 36 | hash_table *topology_table; 37 | hash_table *node_table; 38 | } pathresolver; 39 | 40 | 41 | typedef struct { 42 | uint64_t dpid; 43 | uint16_t in_port_no; 44 | uint16_t out_port_no; 45 | } pathresolver_hop; 46 | 47 | 48 | dlist_element *resolve_path( pathresolver *table, uint64_t in_dpid, uint16_t in_port, 49 | uint64_t out_dpid, uint16_t out_port ); 50 | void free_hop_list( dlist_element *hops ); 51 | pathresolver *create_pathresolver( void ); 52 | bool delete_pathresolver( pathresolver *table ); 53 | void update_topology( pathresolver *table, const topology_link_status *s ); 54 | 55 | 56 | #endif // LIBPATHRESOLVER_H 57 | 58 | 59 | /* 60 | * Local variables: 61 | * c-basic-offset: 2 62 | * indent-tabs-mode: nil 63 | * End: 64 | */ 65 | -------------------------------------------------------------------------------- /redirectable_routing_switch/libpathresolver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Path Resolver with dijkstra method 3 | * 4 | * Author: Shuji Ishii 5 | * 6 | * Copyright (C) 2008-2011 NEC Corporation 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License, version 2, as 10 | * published by the Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | */ 21 | 22 | 23 | #ifndef LIBPATHRESOLVER_H 24 | #define LIBPATHRESOLVER_H 25 | 26 | 27 | #include 28 | #include 29 | #include 30 | #include "libtopology.h" 31 | #include "hash_table.h" 32 | #include "doubly_linked_list.h" 33 | 34 | 35 | typedef struct { 36 | hash_table *topology_table; 37 | hash_table *node_table; 38 | } pathresolver; 39 | 40 | 41 | typedef struct { 42 | uint64_t dpid; 43 | uint16_t in_port_no; 44 | uint16_t out_port_no; 45 | } pathresolver_hop; 46 | 47 | 48 | dlist_element *resolve_path( pathresolver *table, uint64_t in_dpid, uint16_t in_port, 49 | uint64_t out_dpid, uint16_t out_port ); 50 | void free_hop_list( dlist_element *hops ); 51 | pathresolver *create_pathresolver( void ); 52 | bool delete_pathresolver( pathresolver *table ); 53 | void update_topology( pathresolver *table, const topology_link_status *s ); 54 | 55 | 56 | #endif // LIBPATHRESOLVER_H 57 | 58 | 59 | /* 60 | * Local variables: 61 | * c-basic-offset: 2 62 | * indent-tabs-mode: nil 63 | * End: 64 | */ 65 | -------------------------------------------------------------------------------- /sliceable_switch/test/rest_if/httpc: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl 2 | # 3 | # Copyright (C) 2009-2011 NEC Corporation 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License, version 2, as 7 | # published by the Free Software Foundation. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License along 15 | # with this program; if not, write to the Free Software Foundation, Inc., 16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | # 18 | 19 | use strict; 20 | use warnings; 21 | use LWP::UserAgent; 22 | use JSON; 23 | 24 | my $URI = "http://127.0.0.1:8888/networks"; 25 | my $METHOD = "GET"; 26 | 27 | &main(); 28 | 29 | sub main() 30 | { 31 | my $file; 32 | 33 | if(@ARGV < 1){ 34 | printf("usage: httpc.pl method uri [file]\n"); 35 | exit; 36 | } 37 | if(defined($ARGV[0])){ 38 | $METHOD = $ARGV[0]; 39 | } 40 | if(defined($ARGV[1])){ 41 | $URI = $ARGV[1]; 42 | } 43 | if(defined($ARGV[2])){ 44 | $file = $ARGV[2]; 45 | } 46 | 47 | my $ua = LWP::UserAgent->new(); 48 | my $req = HTTP::Request->new(GET => $URI); 49 | $req->method($METHOD); 50 | 51 | if(defined($file)){ 52 | if(!open(FILE, $file)){ 53 | printf(STDERR "could not open file (%s)\n", $file); 54 | exit; 55 | } 56 | my $body = ''; 57 | while(){ 58 | $body .= $_; 59 | } 60 | close(FILE); 61 | $req->content_type("application/json"); 62 | $req->content($body); 63 | } 64 | 65 | my $res = $ua->request($req); 66 | 67 | printf("Status: %s\n", $res->status_line); 68 | if(defined($res->content) && length($res->content) > 0){ 69 | printf("Content:\n%s\n", $res->content); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /sliceable_switch/features/step_definitions/dump_flows_steps.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author: Ryota MIBU 3 | # 4 | # Copyright (C) 2013 NEC Corporation 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License, version 2, as 8 | # published by the Free Software Foundation. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License along 16 | # with this program; if not, write to the Free Software Foundation, Inc., 17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | # 19 | 20 | # dump_flows output example: 21 | # NXST_FLOW reply (xid=0x4): 22 | # cookie=0x3, duration=1.278s, table=0, n_packets=0, n_bytes=0, idle_timeout=60,priority=65535,udp,in_port=1,vlan_tci=0x0000,dl_src=00:00:00:00:00:02,dl_dst=00:00:00:00:00:01,nw_src=192.168.0.2,nw_dst=192.168.0.1,nw_tos=0,tp_src=1,tp_dst=1 actions=output:2 23 | 24 | def count_flow_entries switch, spec="" 25 | count = 0 26 | `./trema dump_flows #{ switch }`.each_line do | line | 27 | next if line =~ /^NXST_FLOW/ 28 | found = true 29 | spec.split(/[, ]+/).each do | param | 30 | found = false if not line.include?( param ) 31 | end 32 | count += 1 if found 33 | end 34 | return count 35 | end 36 | 37 | Then /^the number of flow entries on (.+) should be ([0-9]+)$/ do | switch, n | 38 | count_flow_entries( switch ).should == n.to_i 39 | end 40 | 41 | Then /^(.+) should have a flow entry like (.+)$/ do | switch, spec | 42 | count_flow_entries( switch, spec ).should == 1 43 | end 44 | 45 | Then /^(.+) should not have a flow entry like (.+)$/ do | switch, spec | 46 | count_flow_entries( switch, spec ).should == 0 47 | end 48 | 49 | ### Local variables: 50 | ### mode: Ruby 51 | ### coding: utf-8-unix 52 | ### indent-tabs-mode: nil 53 | ### End: 54 | -------------------------------------------------------------------------------- /sliceable_switch/port.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Shuji Ishii, Lei SUN 3 | * 4 | * Copyright (C) 2008-2012 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #ifndef PORT_H 22 | #define PORT_H 23 | 24 | 25 | #include "trema.h" 26 | 27 | 28 | typedef struct port_info { 29 | uint64_t dpid; 30 | uint16_t port_no; 31 | bool external_link; 32 | bool switch_to_switch_link; 33 | bool switch_to_switch_reverse_link; 34 | } port_info; 35 | 36 | 37 | typedef struct switch_info { 38 | uint64_t dpid; 39 | list_element *ports; // list of port_info 40 | } switch_info; 41 | 42 | 43 | void delete_port( list_element **switches, port_info *delete_port ); 44 | void add_port( list_element **switches, uint64_t dpid, uint16_t port_no, const char *name, uint8_t external ); 45 | void update_port( port_info *port, uint8_t external ); 46 | void delete_all_ports( list_element **switches ); 47 | port_info *lookup_port( list_element *switches, uint64_t dpid, uint16_t port_no ); 48 | int foreach_port( const list_element *ports, int ( *function )( port_info *port, void *user_data ), void *user_data ); 49 | void foreach_switch( const list_element *switches, void ( *function )( switch_info *sw, void *user_data ), void *user_data ); 50 | list_element *create_ports( list_element **switches ); 51 | 52 | 53 | #endif // PORT_H 54 | 55 | 56 | /* 57 | * Local variables: 58 | * c-basic-offset: 2 59 | * indent-tabs-mode: nil 60 | * End: 61 | */ 62 | -------------------------------------------------------------------------------- /sliceable_switch/test/slice/tests.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | PATH=/usr/bin:/bin 4 | 5 | CWD=`pwd` 6 | export FILTER_DB_FILE=$CWD/filter.db 7 | export SLICE_DB_FILE=$CWD/slice.db 8 | export PERL5LIB=$CWD/../.. 9 | 10 | delete_tables() { 11 | if [ -f "$FILTER_DB_FILE" ]; then 12 | rm "$FILTER_DB_FILE" 13 | fi 14 | if [ -f "$SLICE_DB_FILE" ]; then 15 | rm "$SLICE_DB_FILE" 16 | fi 17 | } 18 | 19 | create_tables() { 20 | delete_tables 21 | ( cd ../.. && ./create_tables.sh ) 22 | } 23 | 24 | create_mac_binding_tables() { 25 | ../../slice create mac_binding "Mac binding" 26 | ../../slice add-mac mac_binding 00:00:00:00:00:01 host1 27 | ../../slice add-mac mac_binding 00:00:00:00:00:02 host2 28 | } 29 | 30 | create_port_binding_tables() { 31 | ../../slice create port_binding "Port binding" 32 | ../../slice add-port port_binding 0xabc 3 0xffff host3 33 | ../../slice add-port port_binding 0xabc 4 0xffff host4 34 | } 35 | 36 | create_port_mac_binding_tables() { 37 | ../../slice create port_mac_binding "Port and mac binding" 38 | ../../slice add-mac port_mac_binding 00:00:00:00:00:05 host5 39 | ../../slice add-port port_mac_binding 0xabc 5 0xffff host6 40 | } 41 | 42 | show_slice() { 43 | slices=`../../slice list | awk 'NR > 1 { print $1 }' | sort` 44 | for slice in $slices 45 | do 46 | echo show $slice 47 | ../../slice show $slice 48 | done 49 | } 50 | 51 | tests() { 52 | create_tables 53 | echo slice help 54 | ../../slice 55 | 56 | show_slice 57 | 58 | echo create mac binding tables 59 | create_tables 60 | create_mac_binding_tables 61 | show_slice 62 | 63 | echo create port binding tables 64 | create_tables 65 | create_port_binding_tables 66 | show_slice 67 | 68 | echo create port and mac binding tables 69 | create_tables 70 | create_port_mac_binding_tables 71 | show_slice 72 | 73 | echo three slice 74 | create_tables 75 | create_mac_binding_tables 76 | create_port_binding_tables 77 | create_port_mac_binding_tables 78 | show_slice 79 | } 80 | 81 | tests 82 | -------------------------------------------------------------------------------- /sliceable_switch/checker.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Dumps packet-in message. 3 | * 4 | * Author: Yasuhito Takamiya 5 | * 6 | * Copyright (C) 2008-2012 NEC Corporation 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License, version 2, as 10 | * published by the Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | */ 21 | 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "trema.h" 29 | 30 | 31 | static void 32 | handle_packet_in( uint64_t datapath_id, packet_in message ) { 33 | if ( !packet_type_ipv4( message.data ) ) { 34 | return; 35 | } 36 | packet_info *packet_info = message.data->user_data; 37 | struct in_addr in; 38 | in.s_addr = htonl( packet_info->ipv4_saddr ); 39 | uint16_t vid = 0xffff; 40 | if ( packet_type_eth_vtag( message.data ) ) { 41 | vid = packet_info->vlan_vid; 42 | } 43 | info( "%s: datapath_id: %#" PRIx64 ", in_port: %u, vid: %#x, ether address: %02x:%02x:%02x:%02x:%02x:%02x", 44 | inet_ntoa( in ), datapath_id, message.in_port, vid, 45 | packet_info->eth_macsa[0], packet_info->eth_macsa[1], packet_info->eth_macsa[2], 46 | packet_info->eth_macsa[3], packet_info->eth_macsa[4], packet_info->eth_macsa[5] ); 47 | } 48 | 49 | 50 | int 51 | main( int argc, char *argv[] ) { 52 | init_trema( &argc, &argv ); 53 | set_packet_in_handler( handle_packet_in, NULL ); 54 | start_trema(); 55 | return 0; 56 | } 57 | 58 | 59 | /* 60 | * Local variables: 61 | * c-basic-offset: 2 62 | * indent-tabs-mode: nil 63 | * End: 64 | */ 65 | -------------------------------------------------------------------------------- /simple_restapi_manager/librestapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: TeYen Liu 3 | * 4 | * Copyright (C) 2013 TeYen Liu 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | #ifndef SFLOWCOLLECTOR_H 21 | #define SFLOWCOLLECTOR_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #include 28 | #include "mongoose.h" 29 | #include "trema.h" 30 | 31 | #define URL_PATTERN_LEN 1024 32 | #define METHOD_LEN 5 33 | 34 | typedef struct url_mapping { 35 | char url_pattern_key[URL_PATTERN_LEN]; 36 | char method[METHOD_LEN]; 37 | regex_t regex; 38 | char* ( *restapi_requested_callback )( const struct mg_request_info *request_info, void *request_data ); 39 | } url_mapping; 40 | 41 | typedef struct { 42 | hash_table *url_mapping; 43 | } url_mapping_table; 44 | 45 | 46 | url_mapping *lookup_url_mapping_by_match( url_mapping_table *mapping_db, char *url_key ); 47 | url_mapping *allocate_url_mapping( void ); 48 | bool add_url_mapping( char *url_key, url_mapping_table *mapping_db, url_mapping *mapping_data ); 49 | bool delete_url_mapping( url_mapping_table *mapping_db, url_mapping *mapping_data ); 50 | bool create_url_mapping_db( url_mapping_table *mapping_db ); 51 | bool delete_url_mapping_db( url_mapping_table *mapping_db ); 52 | void compile_url_mapping( url_mapping *url_mapping_data, url_mapping_table *mapping_db ); 53 | bool initialize_url_mapping( url_mapping_table *mapping_db ); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif /* SFLOWCOLLECTOR_H */ 60 | 61 | -------------------------------------------------------------------------------- /topology/list_switch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Shuji Ishii, Kazushi SUGYO 3 | * 4 | * Copyright (C) 2008-2011 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #include 22 | #include 23 | #include 24 | #include "trema.h" 25 | #include "libtopology.h" 26 | #include "topology_service_interface_option_parser.h" 27 | 28 | 29 | void 30 | usage() { 31 | topology_service_interface_usage( get_executable_name(), "list switch", NULL ); 32 | } 33 | 34 | 35 | static void 36 | print_switch_status( const topology_switch_status *s ) { 37 | printf( "0x%-16" PRIx64 "\n", s->dpid ); 38 | } 39 | 40 | 41 | static void 42 | print_all_switch_status( void *param, size_t entries, const topology_switch_status *s ) { 43 | size_t i; 44 | 45 | UNUSED( param ); 46 | 47 | printf( "datapath-id\n" ); 48 | for ( i = 0; i < entries; i++ ) { 49 | print_switch_status( &s[ i ] ); 50 | } 51 | 52 | stop_trema(); 53 | } 54 | 55 | 56 | int 57 | main( int argc, char *argv[] ) { 58 | init_trema( &argc, &argv ); 59 | init_topology_service_interface_options( &argc, &argv ); 60 | init_libtopology( get_topology_service_interface_name() ); 61 | 62 | get_all_switch_status( print_all_switch_status, NULL); 63 | start_trema(); 64 | 65 | finalize_libtopology(); 66 | finalize_topology_service_interface_options(); 67 | 68 | return 0; 69 | } 70 | 71 | 72 | /* 73 | * Local variables: 74 | * c-basic-offset: 2 75 | * indent-tabs-mode: nil 76 | * End: 77 | */ 78 | -------------------------------------------------------------------------------- /sliceable_switch/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011-2013 NEC Corporation 3 | # 4 | 5 | TREMA = ../../trema 6 | GEM_BIN = `ruby -e 'require "rubygems"; puts Gem::bindir'` 7 | TREMA_APPS = .. 8 | 9 | TREMA_CONFIG = $(shell which trema-config) 10 | ifeq ($(TREMA_CONFIG),) 11 | TREMA_CONFIG = $(TREMA)/trema-config 12 | endif 13 | 14 | CC = gcc 15 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -I$(TREMA_APPS)/topology -I$(TREMA_APPS)/flow_manager -std=gnu99 -g -D_GNU_SOURCE -Wall 16 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) -L$(TREMA_APPS)/topology -ltopology -L$(TREMA_APPS)/flow_manager -lpath 17 | 18 | TARGET = sliceable_switch 19 | SRCS = fdb.c filter.c libpathresolver.c port.c sliceable_switch.c slice.c redirector.c 20 | OBJS = $(SRCS:.c=.o) 21 | 22 | FEATURES = help.feature 23 | FEATURES += port_binding.feature 24 | FEATURES += mac_binding.feature mac_binding_loose_mode.feature 25 | FEATURES += port_mac_binding.feature 26 | FEATURES += port_mac_mixed_binding.feature 27 | FEATURES += port_port_mac_mixed_binding.feature mac_port_mac_mixed_binding.feature 28 | FEATURES += mac_binding_multiple_slices.feature port_binding_multiple_slices.feature 29 | FEATURES += mac_binding_65535_slices.feature 30 | FEATURES += switch_restart.feature 31 | FEATURES += set_reverse_flow.feature filter.feature 32 | FEATURES += rest_if_networks.feature rest_if_ports.feature rest_if_filters.feature 33 | FEATURES += vlan_mod.feature 34 | 35 | LOGGING_LEVEL=info 36 | 37 | DEPENDS = .depends 38 | 39 | .PHONY: all clean 40 | 41 | .SUFFIXES: .c .o 42 | 43 | all: depend $(TARGET) 44 | 45 | $(TARGET): $(OBJS) 46 | $(CC) $(OBJS) $(LDFLAGS) -o $@ 47 | 48 | .c.o: 49 | $(CC) $(CFLAGS) -c $< 50 | 51 | depend: 52 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 53 | 54 | clean: 55 | @rm -rf $(DEPENDS) $(OBJS) $(TARGET) *~ 56 | @rm -rf checker.o checker 57 | 58 | test: $(FEATURES) 59 | 60 | %.feature: sliceable_switch 61 | ( \ 62 | file=`pwd`/features/$@; \ 63 | cd ${TREMA}; \ 64 | sudo LOGGING_LEVEL=${LOGGING_LEVEL} ${GEM_BIN}/cucumber -r ../apps/sliceable_switch/features $$file || exit 1 \ 65 | ) 66 | 67 | checker.feature: checker 68 | 69 | checker: checker.o 70 | $(CC) $< $(LDFLAGS) -o $@ 71 | 72 | 73 | -include $(DEPENDS) 74 | -------------------------------------------------------------------------------- /flow_dumper/flow-dumper.rb: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Flow dumper 4 | # 5 | # Copyright (C) 2008-2012 NEC Corporation 6 | # 7 | # This program is free software; you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License, version 2, as 9 | # published by the Free Software Foundation. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License along 17 | # with this program; if not, write to the Free Software Foundation, Inc., 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | # 20 | 21 | 22 | module Trema 23 | class FlowStatsReply 24 | def to_s 25 | "table_id = #{ table_id }, " + 26 | "priority = #{ priority }, " + 27 | "cookie = #{ cookie.to_hex }, " + 28 | "idle_timeout = #{ idle_timeout }, " + 29 | "hard_timeout = #{ hard_timeout }, " + 30 | "duration = #{ duration_sec }, " + 31 | "packet_count = #{ packet_count }, " + 32 | "byte_count = #{ byte_count }, " + 33 | "match = [#{ match.to_s }], " + 34 | "actions = [#{ actions.to_s }]" 35 | end 36 | end 37 | end 38 | 39 | 40 | class FlowDumper < Controller 41 | periodic_timer_event :timed_out, 2 42 | 43 | 44 | def start 45 | send_list_switches_request 46 | end 47 | 48 | 49 | def list_switches_reply switches 50 | request = FlowStatsRequest.new( :match => Match.new ) 51 | switches.each do | each | 52 | send_message each, request 53 | end 54 | @num_switches = switches.size 55 | end 56 | 57 | 58 | def stats_reply datapath_id, message 59 | message.stats.each do | each | 60 | if each.is_a?( FlowStatsReply ) 61 | info "[#{ datapath_id.to_hex }] #{ each.to_s }" 62 | end 63 | end 64 | 65 | @num_switches -= 1 66 | if @num_switches == 0 67 | shutdown! 68 | end 69 | end 70 | 71 | 72 | def timed_out 73 | shutdown! 74 | end 75 | end 76 | 77 | 78 | ### Local variables: 79 | ### mode: Ruby 80 | ### coding: utf-8 81 | ### indent-tabs-mode: nil 82 | ### End: 83 | -------------------------------------------------------------------------------- /monitoring_manager/libmonitoring.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Monitoring 3 | * 4 | * Author: TeYen Liu 5 | * 6 | * Copyright (C) 2013 TeYen Liu 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License, version 2, as 10 | * published by the Free Software Foundation. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License along 18 | * with this program; if not, write to the Free Software Foundation, Inc., 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | */ 21 | 22 | 23 | #ifndef LIBPATH_H 24 | #define LIBPATH_H 25 | 26 | 27 | #include "trema.h" 28 | #include "monitoring_interface.h" 29 | 30 | bool add_callback_port_loading_requested ( 31 | void ( *callback )( void *, const port_loading *, uint64_t, uint16_t ), void *param ); 32 | bool add_callback_port_loading_notified ( 33 | void ( *callback )( void *, const port_loading *, uint64_t, uint16_t ), void *param ); 34 | bool add_callback_flow_loading_notified ( 35 | void ( *callback )( void *, const flow_loading *, uint64_t ), void *param ); 36 | 37 | bool send_monitoring_subscribe_request(); 38 | bool send_monitoring_unsubscribe_request(); 39 | void subscribe_or_unsubscribe_reply_completed( uint16_t result); 40 | 41 | bool send_port_loading_request( uint64_t datapathid, uint16_t port_no, 42 | void *user_data ); 43 | void port_loading_reply_completed( uint64_t datapath_id, uint64_t port_no, 44 | port_loading *port_loading_info, void *user_data ); 45 | void port_loading_notification_completed( uint16_t tag __attribute__((unused)), 46 | void *data, size_t len __attribute__((unused)) ); 47 | void flow_loading_notification_completed( uint16_t tag __attribute__((unused)), 48 | void *data, size_t len __attribute__((unused)) ); 49 | bool init_monitoring( void ); 50 | bool finalize_monitoring( void ); 51 | 52 | 53 | #endif // LIBPATH_H 54 | 55 | 56 | /* 57 | * Local variables: 58 | * c-basic-offset: 2 59 | * indent-tabs-mode: nil 60 | * End: 61 | */ 62 | -------------------------------------------------------------------------------- /sliceable_switch/test/rest_if/tests.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # Copyright (C) 2011 NEC Corporation 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License, version 2, as 7 | # published by the Free Software Foundation. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License along 15 | # with this program; if not, write to the Free Software Foundation, Inc., 16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | # 18 | 19 | BASE_URI="http://127.0.0.1:8888/networks" 20 | 21 | CLIENT="./httpc" 22 | 23 | run(){ 24 | method=$1 25 | target=$BASE_URI$2 26 | content=$3 27 | echo "#### BEGIN: $method $target ####" 28 | $CLIENT $method $target $content 29 | echo "#### END: $method $target ####" 30 | echo 31 | } 32 | 33 | tests(){ 34 | run GET "" 35 | run POST "" create_network.json 36 | run PUT "/slice_created_via_rest_if" modify_network.json 37 | run POST "/slice_created_via_rest_if/ports" create_port.json 38 | run GET "/slice_created_via_rest_if/ports" 39 | run POST "/slice_created_via_rest_if/ports/port_created_via_rest_if/attachments" create_port_mac.json 40 | run GET "/slice_created_via_rest_if/ports/port_created_via_rest_if/attachments" 41 | run GET "/slice_created_via_rest_if/ports/port_created_via_rest_if/attachments/port_mac_created_via_rest_if" 42 | run GET "/slice_created_via_rest_if/ports/port_created_via_rest_if" 43 | run POST "/slice_created_via_rest_if/attachments" create_mac.json 44 | run GET "/slice_created_via_rest_if/attachments" 45 | run GET "/slice_created_via_rest_if/attachments/mac_created_via_rest_if" 46 | run GET "/slice_created_via_rest_if" 47 | run DELETE "/slice_created_via_rest_if/ports/port_created_via_rest_if/attachments/port_mac_created_via_rest_if" 48 | run DELETE "/slice_created_via_rest_if/ports/port_created_via_rest_if" 49 | run DELETE "/slice_created_via_rest_if/attachments/mac_created_via_rest_if" 50 | run DELETE "/slice_created_via_rest_if" 51 | } 52 | 53 | tests 54 | -------------------------------------------------------------------------------- /learning_switch_memcached/learning-switch.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Simple learning switch application in Ruby 3 | # 4 | # Author: Yasuhito Takamiya 5 | # 6 | # Copyright (C) 2008-2011 NEC Corporation 7 | # 8 | # This program is free software; you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License, version 2, as 10 | # published by the Free Software Foundation. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License along 18 | # with this program; if not, write to the Free Software Foundation, Inc., 19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | # 21 | 22 | # 23 | # Learning switch with memcached 24 | # 25 | # Author: Kazushi SUGYO 26 | # 27 | 28 | 29 | require "fdb" 30 | 31 | 32 | # 33 | # A OpenFlow controller class that emulates a layer-2 switch. 34 | # 35 | class LearningSwitch < Trema::Controller 36 | def start 37 | @fdb = FDB.new 38 | end 39 | 40 | 41 | def packet_in datapath_id, message 42 | @fdb.learn message.macsa, message.in_port 43 | port_no = @fdb.port_no_of( message.macda ) 44 | if port_no 45 | flow_mod datapath_id, message, port_no 46 | packet_out datapath_id, message, port_no 47 | else 48 | flood datapath_id, message 49 | end 50 | end 51 | 52 | 53 | ############################################################################## 54 | private 55 | ############################################################################## 56 | 57 | 58 | def flow_mod datapath_id, message, port_no 59 | send_flow_mod_add( 60 | datapath_id, 61 | :match => ExactMatch.from( message ), 62 | :actions => Trema::ActionOutput.new( port_no ) 63 | ) 64 | end 65 | 66 | 67 | def packet_out datapath_id, message, port_no 68 | send_packet_out( 69 | datapath_id, 70 | :packet_in => message, 71 | :actions => Trema::ActionOutput.new( port_no ) 72 | ) 73 | end 74 | 75 | 76 | def flood datapath_id, message 77 | packet_out datapath_id, message, OFPP_FLOOD 78 | end 79 | end 80 | 81 | 82 | ### Local variables: 83 | ### mode: Ruby 84 | ### coding: utf-8 85 | ### indent-tabs-mode: nil 86 | ### End: 87 | -------------------------------------------------------------------------------- /flow_manager/examples/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011 NEC Corporation 3 | # 4 | 5 | TREMA = ../../../trema 6 | 7 | CC = gcc 8 | AR = ar 9 | RANLIB = ranlib 10 | 11 | TREMA_CONFIG = $(shell which trema-config) 12 | ifeq ($(TREMA_CONFIG),) 13 | TREMA_CONFIG = $(TREMA)/trema-config 14 | endif 15 | 16 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -std=gnu99 -D_GNU_SOURCE -g -fno-strict-aliasing -Werror -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wfloat-equal -Wpointer-arith -I. -I.. 17 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) -L.. -lpath 18 | 19 | SRCS_COMMON = utils.c 20 | OBJS_COMMON = $(SRCS_COMMON:.c=.o) 21 | 22 | TARGET_EXAMPLE1 = example1 23 | SRCS_EXAMPLE1 = example1.c 24 | OBJS_EXAMPLE1 = $(SRCS_EXAMPLE1:.c=.o) 25 | 26 | TARGET_EXAMPLE2 = example2 27 | SRCS_EXAMPLE2 = example2.c 28 | OBJS_EXAMPLE2 = $(SRCS_EXAMPLE2:.c=.o) 29 | 30 | TARGET_EXAMPLE3 = example3 31 | SRCS_EXAMPLE3 = example3.c 32 | OBJS_EXAMPLE3 = $(SRCS_EXAMPLE3:.c=.o) 33 | 34 | TARGET_EXAMPLE4 = example4 35 | SRCS_EXAMPLE4 = example4.c 36 | OBJS_EXAMPLE4 = $(SRCS_EXAMPLE4:.c=.o) 37 | 38 | TARGET_EXAMPLE5 = example5 39 | SRCS_EXAMPLE5 = example5.c 40 | OBJS_EXAMPLE5 = $(SRCS_EXAMPLE5:.c=.o) 41 | 42 | TARGETS = $(TARGET_EXAMPLE1) $(TARGET_EXAMPLE2) $(TARGET_EXAMPLE3) $(TARGET_EXAMPLE4) $(TARGET_EXAMPLE5) 43 | SRCS = $(SRCS_COMMON) $(SRCS_EXAMPLE1) $(SRCS_EXAMPLE2) $(SRCS_EXAMPLE3) $(SRCS_EXAMPLE4) $(SRCS_EXAMPLE5) 44 | OBJS = $(OBJS_COMMON) $(OBJS_EXAMPLE1) $(OBJS_EXAMPLE2) $(OBJS_EXAMPLE3) $(OBJS_EXAMPLE4) $(OBJS_EXAMPLE5) 45 | 46 | DEPENDS = .depends 47 | 48 | .PHONY: all clean 49 | 50 | .SUFFIXES: .c .o 51 | 52 | all: depend $(TARGETS) 53 | 54 | $(TARGET_EXAMPLE1): $(OBJS_EXAMPLE1) $(OBJS_COMMON) 55 | $(CC) $(OBJS_EXAMPLE1) $(OBJS_COMMON) $(LDFLAGS) -o $@ 56 | 57 | $(TARGET_EXAMPLE2): $(OBJS_EXAMPLE2) $(OBJS_COMMON) 58 | $(CC) $(OBJS_EXAMPLE2) $(OBJS_COMMON) $(LDFLAGS) -o $@ 59 | 60 | $(TARGET_EXAMPLE3): $(OBJS_EXAMPLE3) $(OBJS_COMMON) 61 | $(CC) $(OBJS_EXAMPLE3) $(OBJS_COMMON) $(LDFLAGS) -o $@ 62 | 63 | $(TARGET_EXAMPLE4): $(OBJS_EXAMPLE4) $(OBJS_COMMON) 64 | $(CC) $(OBJS_EXAMPLE4) $(OBJS_COMMON) $(LDFLAGS) -o $@ 65 | 66 | $(TARGET_EXAMPLE5): $(OBJS_EXAMPLE5) $(OBJS_COMMON) 67 | $(CC) $(OBJS_EXAMPLE5) $(OBJS_COMMON) $(LDFLAGS) -o $@ 68 | 69 | .c.o: 70 | $(CC) $(CFLAGS) -c $< 71 | 72 | depend: 73 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 74 | 75 | clean: 76 | @rm -rf $(DEPENDS) $(OBJS) $(TARGETS) *~ 77 | 78 | -include $(DEPENDS) 79 | -------------------------------------------------------------------------------- /topology/topology_table.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Shuji Ishii, Kazushi SUGYO 3 | * 4 | * Copyright (C) 2008-2011 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #ifndef TOPOLOGY_TABLE_H 22 | #define TOPOLOGY_TABLE_H 23 | 24 | 25 | #include "trema.h" 26 | 27 | 28 | typedef struct link_to { 29 | uint64_t datapath_id; 30 | uint16_t port_no; 31 | bool up; 32 | } link_to; 33 | 34 | 35 | typedef struct port_entry { 36 | struct sw_entry *sw; 37 | uint16_t port_no; 38 | char name[ OFP_MAX_PORT_NAME_LEN ]; 39 | uint8_t mac[ ETH_ADDRLEN ]; 40 | bool up; 41 | bool external; 42 | link_to *link_to; 43 | uint32_t id; 44 | } port_entry; 45 | 46 | 47 | typedef struct sw_entry { 48 | uint64_t datapath_id; 49 | uint32_t id; 50 | list_element *port_table; 51 | } sw_entry; 52 | 53 | 54 | void init_topology_table( void ); 55 | void finalize_topology_table( void ); 56 | 57 | sw_entry *update_sw_entry( uint64_t *datapath_id ); 58 | void delete_sw_entry( sw_entry *sw ); 59 | sw_entry *lookup_sw_entry( uint64_t *datapath_id ); 60 | void foreach_sw_entry( void function( sw_entry *entry, void *user_data ), void *user_data ); 61 | 62 | port_entry *update_port_entry( sw_entry *sw, uint16_t port_no, const char *name ); 63 | void delete_port_entry( sw_entry *sw, port_entry *port ); 64 | port_entry *lookup_port_entry( sw_entry *sw, uint16_t port_no, const char *name ); 65 | void foreach_port_entry( void function( port_entry *entry, void *user_data ), void *user_data ); 66 | 67 | link_to *update_link_to( port_entry *port, uint64_t *datapath_id, uint16_t port_no, bool up ); 68 | void delete_link_to( port_entry *port ); 69 | 70 | 71 | #endif // TOPOLOGY_TABLE_H 72 | 73 | 74 | /* 75 | * Local variables: 76 | * c-basic-offset: 2 77 | * indent-tabs-mode: nil 78 | * End: 79 | */ 80 | -------------------------------------------------------------------------------- /topology/probe_timer_table.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Shuji Ishii, Kazushi SUGYO 3 | * 4 | * Copyright (C) 2008-2011 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #ifndef PROBE_TIMER_TABLE_H 22 | #define PROBE_TIMER_TABLE_H 23 | 24 | 25 | #include 26 | #include "trema.h" 27 | 28 | 29 | typedef struct probe_timer_entry { 30 | struct timespec expires; 31 | uint64_t datapath_id; 32 | uint16_t port_no; 33 | uint8_t mac[ ETH_ADDRLEN ]; 34 | int state; 35 | int retry_count; 36 | bool link_up; 37 | uint64_t to_datapath_id; 38 | uint16_t to_port_no; 39 | bool dirty; 40 | } probe_timer_entry; 41 | 42 | 43 | enum probe_timer_state { 44 | PROBE_TIMER_STATE_INACTIVE = 0, 45 | PROBE_TIMER_STATE_SEND_DELAY, 46 | PROBE_TIMER_STATE_WAIT, 47 | PROBE_TIMER_STATE_CONFIRMED, 48 | }; 49 | 50 | 51 | enum probe_timer_event { 52 | PROBE_TIMER_EVENT_UP, 53 | PROBE_TIMER_EVENT_DOWN, 54 | PROBE_TIMER_EVENT_RECV_LLDP, 55 | PROBE_TIMER_EVENT_TIMEOUT, 56 | }; 57 | 58 | 59 | void probe_request( probe_timer_entry *entry, int event, uint64_t *dpid, uint16_t port_no ); 60 | 61 | void init_probe_timer_table( void ); 62 | void finalize_probe_timer_table( void ); 63 | 64 | probe_timer_entry *allocate_probe_timer_entry( const uint64_t *datapath_id, uint16_t port_no, const uint8_t *mac ); 65 | void free_probe_timer_entry( probe_timer_entry *free_entry ); 66 | void insert_probe_timer_entry( probe_timer_entry *entry ); 67 | probe_timer_entry *delete_probe_timer_entry( const uint64_t *datapath_id, uint16_t port_no ); 68 | probe_timer_entry *lookup_probe_timer_entry( const uint64_t *datapath_id, uint16_t port_no ); 69 | 70 | 71 | #endif // PROBE_TIMER_TABLE_H 72 | 73 | 74 | /* 75 | * Local variables: 76 | * c-basic-offset: 2 77 | * indent-tabs-mode: nil 78 | * End: 79 | */ 80 | -------------------------------------------------------------------------------- /simple_restapi_manager/examples/example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: TeYen Liu 3 | * 4 | * Copyright (C) 2013 TeYen Liu 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #include 22 | #include 23 | #include "trema.h" 24 | #include "simple_restapi_manager.h" 25 | 26 | 27 | static void 28 | handle_switch_ready( uint64_t datapath_id, void *user_data ) { 29 | UNUSED( user_data ); 30 | 31 | info( "%#" PRIx64 " is connected.", datapath_id ); 32 | } 33 | 34 | /*** Define your REST API callback function here ***/ 35 | static char * 36 | handle_query_test_restapi( const struct mg_request_info *request_info, void *request_data ) { 37 | return "It is from test rest api..."; 38 | } 39 | 40 | static char * 41 | handle_query_test2_restapi( const struct mg_request_info *request_info, void *request_data ) { 42 | return "It is from test2 rest api..."; 43 | } 44 | /***************************************************/ 45 | 46 | 47 | int 48 | main( int argc, char *argv[] ) { 49 | 50 | /* Initialize the Trema world */ 51 | init_trema( &argc, &argv ); 52 | 53 | /* Init restapi manager */ 54 | init_restapi_manager(); 55 | 56 | /* Start restapi manager */ 57 | start_restapi_manager(); 58 | 59 | /*** Add your REST API ***/ 60 | add_restapi_url( "^/test/abc$", "GET", handle_query_test_restapi ); 61 | add_restapi_url( "^/test2/def$", "GET", handle_query_test2_restapi ); 62 | /*************************/ 63 | 64 | /* Set switch ready handler */ 65 | set_switch_ready_handler( handle_switch_ready, NULL ); 66 | 67 | /* Main loop */ 68 | start_trema(); 69 | 70 | /* Finalize transaction manager */ 71 | finalize_restapi_manager(); 72 | 73 | return 0; 74 | } 75 | 76 | 77 | /* 78 | * Local variables: 79 | * c-basic-offset: 2 80 | * indent-tabs-mode: nil 81 | * End: 82 | */ 83 | -------------------------------------------------------------------------------- /topology/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011-2013 NEC Corporation 3 | # 4 | 5 | TREMA = ../../trema 6 | GEM_BIN = `ruby -e 'require "rubygems"; puts Gem::bindir'` 7 | SHELL = /bin/sh 8 | 9 | TREMA_CONFIG = $(shell which trema-config) 10 | ifeq ($(TREMA_CONFIG),) 11 | TREMA_CONFIG = $(TREMA)/trema-config 12 | endif 13 | 14 | CC = gcc 15 | AR = ar 16 | RANLIB = ranlib 17 | 18 | CFLAGS = $(shell $(TREMA_CONFIG) --cflags) -g -std=gnu99 -D_GNU_SOURCE -fno-strict-aliasing -Werror -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wfloat-equal -Wpointer-arith 19 | LDFLAGS = $(shell $(TREMA_CONFIG) --libs) 20 | 21 | TARGET_LIB = libtopology.a 22 | SRCS_LIB = libtopology.c topology_service_interface_option_parser.c 23 | OBJS_LIB = $(SRCS_LIB:.c=.o) 24 | 25 | TARGET_TOPOLOGY = topology 26 | SRCS_TOPOLOGY = service_management.c subscriber_table.c topology.c topology_management.c topology_table.c 27 | OBJS_TOPOLOGY = $(SRCS_TOPOLOGY:.c=.o) 28 | 29 | TARGET_DISCOVERY = topology_discovery 30 | SRCS_DISCOVERY = lldp.c probe_timer_table.c topology_discovery.c 31 | OBJS_DISCOVERY = $(SRCS_DISCOVERY:.c=.o) 32 | LDFLAGS_DISCOVERY = $(LDFLAGS) -L. -ltopology 33 | 34 | TARGET_SHOW = show_topology 35 | SRCS_SHOW = show_topology.c show_topology_dsl.c show_topology_graph_easy.c show_topology_csv.c 36 | OBJS_SHOW = $(SRCS_SHOW:.c=.o) 37 | LDFLAGS_SHOW = $(LDFLAGS) -L. -ltopology 38 | 39 | TARGETS = $(TARGET_LIB) $(TARGET_TOPOLOGY) $(TARGET_DISCOVERY) $(TARGET_SHOW) 40 | SRCS = $(SRCS_LIB) $(SRCS_TOPOLOGY) $(SRCS_DISCOVERY) $(SRCS_SHOW) 41 | OBJS = $(OBJS_LIB) $(OBJS_TOPOLOGY) $(OBJS_DISCOVERY) $(OBJS_SHOW) 42 | 43 | FEATURES = topology.feature 44 | 45 | DEPENDS = .depends 46 | 47 | .PHONY: all clean 48 | 49 | .SUFFIXES: .c .o 50 | 51 | all: depend $(TARGETS) 52 | 53 | $(TARGET_LIB): $(OBJS_LIB) 54 | $(AR) -cq $@ $(OBJS_LIB) 55 | $(RANLIB) $@ 56 | 57 | $(TARGET_TOPOLOGY): $(OBJS_TOPOLOGY) 58 | $(CC) $(OBJS_TOPOLOGY) $(LDFLAGS) -o $@ 59 | 60 | $(TARGET_DISCOVERY): $(OBJS_DISCOVERY) 61 | $(CC) $(OBJS_DISCOVERY) $(LDFLAGS_DISCOVERY) -o $@ 62 | 63 | $(TARGET_SHOW): $(OBJS_SHOW) 64 | $(CC) $(OBJS_SHOW) $(LDFLAGS_SHOW) -o $@ 65 | 66 | .c.o: 67 | $(CC) $(CFLAGS) -c $< 68 | 69 | depend: 70 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPENDS) 71 | 72 | clean: 73 | @rm -rf $(DEPENDS) $(OBJS) $(TARGETS) *~ 74 | 75 | run_acceptance_test: 76 | @for feature in $(FEATURES); do \ 77 | ( \ 78 | file=`pwd`/$$feature; \ 79 | cd ${TREMA}; \ 80 | ${GEM_BIN}/cucumber -r features $$file; \ 81 | ) \ 82 | done 83 | 84 | -include $(DEPENDS) 85 | -------------------------------------------------------------------------------- /load_balance_switch/port.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Shuji Ishii 3 | * 4 | * Copyright (C) 2008-2011 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #ifndef PORT_H 22 | #define PORT_H 23 | 24 | 25 | #include "trema.h" 26 | 27 | 28 | typedef struct port_info { 29 | uint64_t dpid; 30 | uint16_t port_no; 31 | bool external_link; 32 | bool switch_to_switch_link; 33 | bool switch_to_switch_reverse_link; 34 | } port_info; 35 | 36 | 37 | typedef struct switch_info { 38 | uint64_t dpid; 39 | list_element *ports; // list of port_info 40 | } switch_info; 41 | 42 | 43 | void delete_port( list_element **switches, port_info *delete_port ); 44 | void add_port( list_element **switches, uint64_t dpid, uint16_t port_no, uint8_t external ); 45 | void update_port( port_info *port, uint8_t external ); 46 | void delete_all_ports( list_element **switches ); 47 | port_info *lookup_port( list_element *switches, uint64_t dpid, uint16_t port_no ); 48 | int foreach_port( const list_element *ports, 49 | int ( *function )( port_info *port, 50 | openflow_actions *actions, 51 | uint64_t dpid, uint16_t in_port ), 52 | openflow_actions *actions, uint64_t dpid, uint16_t port ); 53 | void foreach_switch( const list_element *switches, 54 | void ( *function )( switch_info *sw, 55 | const buffer *packet, 56 | uint64_t dpid, 57 | uint16_t in_port ), 58 | const buffer *packet, uint64_t dpid, uint16_t in_port ); 59 | list_element *create_ports( list_element **switches ); 60 | 61 | 62 | #endif // PORT_H 63 | 64 | 65 | /* 66 | * Local variables: 67 | * c-basic-offset: 2 68 | * indent-tabs-mode: nil 69 | * End: 70 | */ 71 | -------------------------------------------------------------------------------- /flow_manager/examples/utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Yasunobu Chiba 3 | * 4 | * Copyright (C) 2011 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #include "libpath.h" 22 | #include "trema.h" 23 | 24 | 25 | void 26 | dump_hop( const hop *h ) { 27 | info( "Hop: datapath_id = %#" PRIx64 ", in_port = %u, out_port = %u, extra_actions = %p.", 28 | h->datapath_id, h->in_port, h->out_port, h->extra_actions ); 29 | } 30 | 31 | 32 | void 33 | dump_path( const path *p ) { 34 | char match_string[ 256 ]; 35 | match_to_string( &p->match, match_string, sizeof( match_string ) ); 36 | 37 | info( "Path: match = [%s], priority = %u, idle_timeout = %u, hard_timeout = %u, n_hops = %d, hops = %p.", 38 | match_string, p->priority, p->idle_timeout, p->hard_timeout, p->n_hops, p->hops ); 39 | if ( p->n_hops > 0 && p->hops != NULL ) { 40 | list_element *e = p->hops; 41 | while ( e != NULL ) { 42 | dump_hop( e->data ); 43 | e = e->next; 44 | } 45 | } 46 | } 47 | 48 | 49 | const char * 50 | status_to_string( int status ) { 51 | switch ( status ) { 52 | case SETUP_SUCCEEDED: 53 | return "succeeded"; 54 | break; 55 | case SETUP_CONFLICTED_ENTRY: 56 | return "conflicted entry"; 57 | break; 58 | case SETUP_SWITCH_ERROR: 59 | return "switch error"; 60 | break; 61 | default: 62 | break; 63 | } 64 | 65 | return "undefined"; 66 | } 67 | 68 | 69 | const char * 70 | reason_to_string( int reason ) { 71 | switch ( reason ) { 72 | case TEARDOWN_TIMEOUT: 73 | return "timeout"; 74 | break; 75 | case TEARDOWN_MANUALLY_REQUESTED: 76 | return "manually requested"; 77 | break; 78 | default: 79 | break; 80 | } 81 | 82 | return "undefined"; 83 | } 84 | 85 | 86 | /* 87 | * Local variables: 88 | * c-basic-offset: 2 89 | * indent-tabs-mode: nil 90 | * End: 91 | */ 92 | -------------------------------------------------------------------------------- /topology/list_port.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Shuji Ishii, Kazushi SUGYO 3 | * 4 | * Copyright (C) 2008-2011 NEC Corporation 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License, version 2, as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program; if not, write to the Free Software Foundation, Inc., 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "trema.h" 26 | #include "libtopology.h" 27 | #include "topology_service_interface_option_parser.h" 28 | 29 | 30 | void 31 | usage() { 32 | topology_service_interface_usage( get_executable_name(), "list port", NULL ); 33 | } 34 | 35 | 36 | static void 37 | print_port_status( const topology_port_status *s ) { 38 | printf( "0x%-14" PRIx64 " %-5u %-12s %-17s %-4s %s\n", 39 | s->dpid, s->port_no, s->name, 40 | ether_ntoa( ( const struct ether_addr * ) s->mac ), 41 | ( s->status == TD_PORT_UP ? "up" : "down" ), 42 | ( s->status == TD_PORT_UP ? 43 | ( s->external == TD_PORT_EXTERNAL ? "external" : "inactive-or-internal" ) 44 | : " -" ) ); 45 | } 46 | 47 | 48 | static void 49 | print_all_port_status( void *param, size_t entries, const topology_port_status *s ) { 50 | size_t i; 51 | 52 | UNUSED( param ); 53 | 54 | printf( "datapath-id no name ethernet-address state\n" ); 55 | for ( i = 0; i < entries; i++ ) { 56 | print_port_status( &s[ i ] ); 57 | } 58 | 59 | stop_trema(); 60 | } 61 | 62 | 63 | int 64 | main( int argc, char *argv[] ) { 65 | init_trema( &argc, &argv ); 66 | init_topology_service_interface_options( &argc, &argv ); 67 | init_libtopology( get_topology_service_interface_name() ); 68 | 69 | get_all_port_status( print_all_port_status, NULL); 70 | start_trema(); 71 | 72 | finalize_libtopology(); 73 | finalize_topology_service_interface_options(); 74 | 75 | return 0; 76 | } 77 | 78 | 79 | /* 80 | * Local variables: 81 | * c-basic-offset: 2 82 | * indent-tabs-mode: nil 83 | * End: 84 | */ 85 | -------------------------------------------------------------------------------- /sliceable_switch/test/filter/tests.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | PATH=/usr/bin:/bin 4 | 5 | CWD=`pwd` 6 | export FILTER_DB_FILE=$CWD/filter.db 7 | export SLICE_DB_FILE=$CWD/slice.db 8 | export PERL5LIB=$CWD/../.. 9 | 10 | delete_tables() { 11 | if [ -f "$FILTER_DB_FILE" ]; then 12 | rm "$FILTER_DB_FILE" 13 | fi 14 | if [ -f "$SLICE_DB_FILE" ]; then 15 | rm "$SLICE_DB_FILE" 16 | fi 17 | } 18 | 19 | create_tables() { 20 | delete_tables 21 | ( cd ../.. && ./create_tables.sh ) 22 | } 23 | 24 | show_filter() { 25 | filters=`../../filter list | awk 'NR > 1 { print $1 }' | sort` 26 | for filter in $filters 27 | do 28 | echo show $filter 29 | ../../filter show $filter 30 | done 31 | } 32 | 33 | set_default_deny() { 34 | ../../filter delete default 35 | ../../filter add default priority=0 action=DENY 36 | } 37 | 38 | add_dl_src_filter() { 39 | ../../filter add host1_mac priority=65535 dl_src=00:00:00:00:00:01 action=ALLOW 40 | ../../filter add host2_mac priority=65535 dl_src=00:00:00:00:00:02 action=ALLOW 41 | ../../filter add host3_mac priority=65535 dl_src=00:00:00:00:00:03 action=ALLOW 42 | ../../filter add host4_mac priority=65535 dl_src=00:00:00:00:00:04 action=ALLOW 43 | ../../filter add host5_mac priority=65535 dl_src=00:00:00:00:00:05 action=ALLOW 44 | } 45 | 46 | add_nw_src_filter() { 47 | ../../filter add host1_ip priority=0x8000 nw_src=192.168.0.1 action=ALLOW 48 | ../../filter add host2_ip priority=0x8000 nw_src=192.168.0.2 action=ALLOW 49 | ../../filter add host3_ip priority=0x8000 nw_src=192.168.0.3 action=ALLOW 50 | ../../filter add host4_ip priority=0x8000 nw_src=192.168.0.4 action=ALLOW 51 | ../../filter add host5_ip priority=0x8000 nw_src=192.168.0.5 action=ALLOW 52 | ../../filter add network192_168 priority=0x7000 nw_src=192.168.0.0/16 action=DENY 53 | ../../filter add network10 priority=0x9000 nw_src=10.0.0.0/8 action=ALLOW 54 | ../../filter add network172_16 priority=0x7000 nw_src=172.16.0.0/12 action=ALLOW 55 | ../../filter add network169_254 priority=0x7000 nw_src=169.254.0.0/16 action=ALLOW 56 | ../../filter add network127 priority=0xf000 nw_src=127.0.0.0/8 action=DENY 57 | } 58 | 59 | tests() { 60 | create_tables 61 | echo filter help 62 | ../../filter 63 | 64 | show_filter 65 | 66 | echo dl_src filter 67 | create_tables 68 | set_default_deny 69 | add_dl_src_filter 70 | show_filter 71 | 72 | echo nw_src filter 73 | create_tables 74 | set_default_deny 75 | add_nw_src_filter 76 | show_filter 77 | } 78 | 79 | tests 80 | -------------------------------------------------------------------------------- /simple_multicast/simple-multicast.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Simple multicast switch application in Ruby 3 | # 4 | # Author: Kazuya Suzuki 5 | # 6 | # Copyright (C) 2012 NEC Corporation 7 | # 8 | # This program is free software; you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License, version 2, as 10 | # published by the Free Software Foundation. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License along 18 | # with this program; if not, write to the Free Software Foundation, Inc., 19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | # 21 | 22 | 23 | require "mfc" 24 | 25 | # 26 | # A OpenFlow controller class which handles IPv4 multicast. 27 | # 28 | class SimpleMulticast < Controller 29 | 30 | 31 | def start 32 | @mfc = MFC.new 33 | end 34 | 35 | 36 | def packet_in datapath_id, message 37 | if message.igmp? 38 | handle_igmp message 39 | else 40 | members = @mfc.members( message.ipv4_daddr ) 41 | flow_mod datapath_id, members, message 42 | packet_out datapath_id, members, message 43 | end 44 | end 45 | 46 | 47 | ############################################################################## 48 | private 49 | ############################################################################## 50 | 51 | 52 | def handle_igmp message 53 | group = message.igmp_group 54 | port = message.in_port 55 | 56 | if message.igmp_v2_membership_report? 57 | @mfc.learn group, port 58 | elsif message.igmp_v2_leave_group? 59 | @mfc.remove group, port 60 | end 61 | end 62 | 63 | 64 | def flow_mod datapath_id, members, message 65 | send_flow_mod_add( 66 | datapath_id, 67 | :match => ExactMatch.from( message ), 68 | :actions => output_actions( members ), 69 | :hard_timeout => 5 70 | ) 71 | end 72 | 73 | 74 | def packet_out datapath_id, members, message 75 | send_packet_out( 76 | datapath_id, 77 | :packet_in => message, 78 | :actions => output_actions( members ) 79 | ) 80 | end 81 | 82 | 83 | def output_actions members 84 | members.collect do | each | 85 | ActionOutput.new( :port => each ) 86 | end 87 | end 88 | end 89 | 90 | 91 | ### Local variables: 92 | ### mode: Ruby 93 | ### coding: utf-8 94 | ### indent-tabs-mode: nil 95 | ### End: 96 | -------------------------------------------------------------------------------- /sliceable_switch/features/help.feature: -------------------------------------------------------------------------------- 1 | Feature: sliceable_switch help 2 | 3 | As a Trema user 4 | I want to see the help message of sliceable_switch command 5 | So that I can learn how to use sliceable_switch 6 | 7 | 8 | Scenario: sliceable_switch --help 9 | When I try to run "../apps/sliceable_switch/sliceable_switch --help" 10 | Then the output should be: 11 | """ 12 | Sliceable switch. 13 | Usage: sliceable_switch [OPTION]... 14 | 15 | -i, --idle_timeout=TIMEOUT idle timeout value of flow entry 16 | -A, --handle_arp_with_packetout handle ARP with packetout 17 | -s, --slice_db=DB_FILE slice database 18 | -a, --filter_db=DB_FILE filter database 19 | -m, --loose enable loose mac-based slicing 20 | -r, --restrict_hosts restrict hosts on switch port 21 | -u, --setup_reverse_flow setup going and returning flows 22 | -n, --name=SERVICE_NAME service name 23 | -t, --topology=SERVICE_NAME topology service name 24 | -d, --daemonize run in the background 25 | -l, --logging_level=LEVEL set logging level 26 | -g, --syslog output log messages to syslog 27 | -f, --logging_facility=FACILITY set syslog facility 28 | -h, --help display this help and exit 29 | """ 30 | 31 | Scenario: sliceable_switch -h 32 | When I try to run "../apps/sliceable_switch/sliceable_switch -h" 33 | Then the output should be: 34 | """ 35 | Sliceable switch. 36 | Usage: sliceable_switch [OPTION]... 37 | 38 | -i, --idle_timeout=TIMEOUT idle timeout value of flow entry 39 | -A, --handle_arp_with_packetout handle ARP with packetout 40 | -s, --slice_db=DB_FILE slice database 41 | -a, --filter_db=DB_FILE filter database 42 | -m, --loose enable loose mac-based slicing 43 | -r, --restrict_hosts restrict hosts on switch port 44 | -u, --setup_reverse_flow setup going and returning flows 45 | -n, --name=SERVICE_NAME service name 46 | -t, --topology=SERVICE_NAME topology service name 47 | -d, --daemonize run in the background 48 | -l, --logging_level=LEVEL set logging level 49 | -g, --syslog output log messages to syslog 50 | -f, --logging_facility=FACILITY set syslog facility 51 | -h, --help display this help and exit 52 | """ 53 | -------------------------------------------------------------------------------- /sliceable_switch/features/port_mac_mixed_binding.feature: -------------------------------------------------------------------------------- 1 | Feature: control multiple openflow switchies using sliceable_switch 2 | 3 | As a Trema user 4 | I want to control multiple openflow switches using sliceable_switch application 5 | So that I can send and receive packets 6 | 7 | 8 | Scenario: One openflow switch, one slices, two servers, one port binding, one mac binding 9 | Given the following slice records 10 | | slice_id | description | 11 | | test1 | slice1 | 12 | And the following port binding records 13 | | slice_id | dpid | port | vid | binding_id | 14 | | test1 | 0x1 | 2 | 0xffff | host1 | 15 | And the following mac binding records 16 | | slice_id | address | binding_id | 17 | | test1 | 00:00:00:00:00:02 | host2 | 18 | And the following filter records 19 | | filter_id | rule_specification | 20 | | default | priority=0 action=ALLOW | 21 | When I try trema run "../apps/sliceable_switch/sliceable_switch -s tmp/slice.db -a tmp/filter.db" with following configuration (backgrounded): 22 | """ 23 | vswitch("sliceable_switch1") { datapath_id "0x1" } 24 | 25 | vhost("host1") { mac "00:00:00:00:00:01" } 26 | vhost("host2") { mac "00:00:00:00:00:02" } 27 | 28 | link "sliceable_switch1", "host1" 29 | link "sliceable_switch1", "host2" 30 | 31 | run { path "../apps/topology/topology" } 32 | run { path "../apps/topology/topology_discovery" } 33 | run { path "../apps/flow_manager/flow_manager" } 34 | 35 | event :port_status => "topology", :packet_in => "filter", :state_notify => "topology" 36 | filter :lldp => "topology_discovery", :packet_in => "sliceable_switch" 37 | """ 38 | And wait until "sliceable_switch" is up 39 | And *** sleep 15 *** 40 | 41 | When I send 1 packets from host1 to host2 42 | Then the total number of tx packets should be: 43 | | host1 | host2 | 44 | | 1 | 0 | 45 | And the total number of rx packets should be: 46 | | host1 | host2 | 47 | | 0 | 0 | 48 | 49 | When I send 1 packets from host2 to host1 50 | Then the total number of tx packets should be: 51 | | host1 | host2 | 52 | | 1 | 1 | 53 | And the total number of rx packets should be: 54 | | host1 | host2 | 55 | | 1 | 0 | 56 | 57 | When I send 1 packets from host1 to host2 58 | Then the total number of tx packets should be: 59 | | host1 | host2 | 60 | | 2 | 1 | 61 | And the total number of rx packets should be: 62 | | host1 | host2 | 63 | | 1 | 1 | 64 | --------------------------------------------------------------------------------