Skip to content

Commit

Permalink
Merge 7c4ebe3 into 5d12fce
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuhito committed Oct 8, 2015
2 parents 5d12fce + 7c4ebe3 commit 58f84a4
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/bin/
/coverage/
/pkg/
/spec/reports/
/test/tmp/
Expand Down
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
AllCops:
Exclude:
- bin/*
- tmp/**/*
- vendor/**/*

Style/StringLiterals:
EnforcedStyle: single_quotes

Style/DotPosition:
EnforcedStyle: trailing
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ GEM
adamantium (~> 0.2.0)
equalizer (~> 0.0.9)
contracts (0.12.0)
coveralls (0.8.2)
coveralls (0.8.3)
json (~> 1.8)
rest-client (>= 1.6.8, < 2)
simplecov (~> 0.10.0)
Expand All @@ -43,7 +43,7 @@ GEM
gherkin3 (~> 3.1.0)
diff-lcs (1.2.5)
docile (1.1.5)
domain_name (0.5.24)
domain_name (0.5.25)
unf (>= 0.0.5, < 1.0.0)
equalizer (0.0.11)
ffi (1.9.10)
Expand All @@ -54,7 +54,7 @@ GEM
ruby_parser (~> 3.1, > 3.1.0)
sexp_processor (~> 4.4)
formatador (0.2.5)
gherkin3 (3.1.1)
gherkin3 (3.1.2)
given_core (3.7.1)
sorcerer (>= 0.3.7)
gli (2.13.2)
Expand Down
14 changes: 7 additions & 7 deletions features/learning_switch.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Feature: "Learning Switch" example
@sudo @open_flow13
Feature: Learning Switch example (OpenFlow1.3).
Background:
Given a file named "trema.conf" with:
Given I use OpenFlow 1.3
And a file named "trema.conf" with:
"""
vswitch('learning') { datapath_id 0xabc }
Expand All @@ -11,9 +13,8 @@ Feature: "Learning Switch" example
link 'learning', 'host2'
"""

@sudo
Scenario: Run as a daemon
Given I run `trema run ../../lib/learning_switch.rb -c trema.conf` interactively
Scenario: Run
Given I trema run "lib/learning_switch13.rb" interactively with the configuration "trema.conf"
And I run `sleep 8`
When I run `trema send_packets --source host1 --dest host2`
And I run `trema send_packets --source host2 --dest host1 --npackets 2`
Expand All @@ -24,9 +25,8 @@ Feature: "Learning Switch" example
| source | #packets |
| 192.168.0.1 | 1 |

@sudo
Scenario: Run as a daemon
Given I successfully run `trema run ../../lib/learning_switch.rb -c trema.conf -d`
Given I trema run "lib/learning_switch13.rb" with the configuration "trema.conf"
And I run `sleep 8`
When I successfully run `trema send_packets --source host1 --dest host2`
And I successfully run `trema send_packets --source host2 --dest host1 --npackets 2`
Expand Down
38 changes: 38 additions & 0 deletions features/learning_switch13.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Feature: Learning Switch example (OpenFlow1.3 support).
Background:
Given a file named "trema.conf" with:
"""
vswitch('learning') { datapath_id 0xabc }
vhost('host1') { ip '192.168.0.1' }
vhost('host2') { ip '192.168.0.2' }
link 'learning', 'host1'
link 'learning', 'host2'
"""

@sudo
Scenario: Run
Given I run `trema run ../../lib/learning_switch13.rb -c trema.conf --openflow13` interactively
And I run `sleep 8`
When I run `trema send_packets --source host1 --dest host2`
And I run `trema send_packets --source host2 --dest host1 --npackets 2`
Then the number of packets received by "host1" should be:
| source | #packets |
| 192.168.0.2 | 2 |
And the number of packets received by "host2" should be:
| source | #packets |
| 192.168.0.1 | 1 |

@sudo
Scenario: Run as a daemon
Given I successfully run `trema run ../../lib/learning_switch13.rb -c trema.conf --openflow13 -d`
And I run `sleep 8`
When I successfully run `trema send_packets --source host1 --dest host2`
And I successfully run `trema send_packets --source host2 --dest host1 --npackets 2`
Then the number of packets received by "host1" should be:
| source | #packets |
| 192.168.0.2 | 2 |
And the number of packets received by "host2" should be:
| source | #packets |
| 192.168.0.1 | 1 |
68 changes: 68 additions & 0 deletions lib/learning_switch13.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# An OpenFlow controller that emulates a layer-2 switch.
class LearningSwitch13 < Trema::Controller
INGRESS_FILTERING_TABLE_ID = 0
FORWARDING_TABLE_ID = 1

AGING_TIME = 180

def start(_args)
logger.info 'LearningSwitch started.'
end

def switch_ready(datapath_id)
add_multicast_mac_drop_flow_entry datapath_id
add_default_forwarding_flow_entry datapath_id
add_default_flooding_flow_entry datapath_id
end

def packet_in(datapath_id, message)
add_forwarding_flow_entry(datapath_id, message)
end

private

def add_forwarding_flow_entry(datapath_id, message)
send_flow_mod_add(
datapath_id,
table_id: FORWARDING_TABLE_ID,
idle_timeout: AGING_TIME,
priority: 2,
match: Match.new(ether_destination_address: message.source_mac),
instructions: Apply.new(SendOutPort.new(message.in_port))
)
end

def add_default_flooding_flow_entry(datapath_id)
send_flow_mod_add(
datapath_id,
table_id: FORWARDING_TABLE_ID,
idle_timeout: 0,
priority: 1,
match: Match.new,
instructions: Apply.new([SendOutPort.new(:controller),
SendOutPort.new(:flood)])
)
end

def add_multicast_mac_drop_flow_entry(datapath_id)
send_flow_mod_add(
datapath_id,
table_id: INGRESS_FILTERING_TABLE_ID,
idle_timeout: 0,
priority: 2,
match: Match.new(ether_destination_address: '01:00:5e:00:00:00',
ether_destination_address_mask: 'ff:ff:ff:00:00:00')
)
end

def add_default_forwarding_flow_entry(datapath_id)
send_flow_mod_add(
datapath_id,
table_id: INGRESS_FILTERING_TABLE_ID,
idle_timeout: 0,
priority: 2,
match: Match.new,
instructions: GotoTable.new(FORWARDING_TABLE_ID)
)
end
end
2 changes: 1 addition & 1 deletion trema.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
vswitch('lsw') {
datapath_id 0xabc
datapath_id 0xdef
}

vhost ('host1') {
Expand Down

0 comments on commit 58f84a4

Please sign in to comment.