-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
128 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
vswitch('lsw') { | ||
datapath_id 0xabc | ||
datapath_id 0xdef | ||
} | ||
|
||
vhost ('host1') { | ||
|