Skip to content

Commit

Permalink
Refactor Arp.read test scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuhito committed Jul 6, 2016
1 parent 0b63478 commit 1798e6c
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 11 deletions.
1 change: 1 addition & 0 deletions features/.nav
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- icmp.feature
- arp.feature
- arp_request.feature
- arp_reply.feature
- lldp.feature
Expand Down
45 changes: 45 additions & 0 deletions features/arp.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Feature: Arp
Background:
Given I use the fixture "arp"

Scenario: read an ARP request packet
When I create a packet with:
"""ruby
Pio::Arp.read(eval(IO.read('arp_request.rb')))
"""
Then the packet has the following fields and values:
| field | value |
| class | Pio::Arp::Request |
| destination_mac | ff:ff:ff:ff:ff:ff |
| source_mac | 00:26:82:eb:ea:d1 |
| ether_type | 2054 |
| hardware_type | 1 |
| protocol_type | 2048 |
| hardware_length | 6 |
| protocol_length | 4 |
| operation | 1 |
| sender_hardware_address | 00:26:82:eb:ea:d1 |
| sender_protocol_address | 192.168.83.3 |
| target_hardware_address | 00:00:00:00:00:00 |
| target_protocol_address | 192.168.83.254 |

Scenario: read an ARP reply packet
When I create a packet with:
"""ruby
Pio::Arp.read(eval(IO.read('arp_reply.rb')))
"""
Then the packet has the following fields and values:
| field | value |
| class | Pio::Arp::Reply |
| destination_mac | 00:26:82:eb:ea:d1 |
| source_mac | 00:16:9d:1d:9c:c4 |
| ether_type | 2054 |
| hardware_type | 1 |
| protocol_type | 2048 |
| hardware_length | 6 |
| protocol_length | 4 |
| operation | 2 |
| sender_hardware_address | 00:16:9d:1d:9c:c4 |
| sender_protocol_address | 192.168.83.254 |
| target_hardware_address | 00:26:82:eb:ea:d1 |
| target_protocol_address | 192.168.83.3 |
10 changes: 2 additions & 8 deletions features/arp_reply.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: Arp Reply
Feature: Arp::Reply
Scenario: create an ARP reply
When I create a packet with:
"""
"""ruby
Pio::Arp::Reply.new(
destination_mac: '00:26:82:eb:ea:d1',
source_mac: '00:16:9d:1d:9c:c4',
Expand Down Expand Up @@ -52,9 +52,3 @@ Feature: Arp Reply
0xc0, 0xa8, 0x53, 0x03, # target_protocol_address
].pack('C*')
"""

Scenario: parse arp.pcap
Then I parse a file named "arp.pcap" with "Pio::Arp" class

Scenario: parse arp-storm.pcap
Then I parse a file named "arp-storm.pcap" with "Pio::Arp" class
4 changes: 2 additions & 2 deletions features/arp_request.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: Arp Request
Feature: Arp::Request
Scenario: create an ARP request
When I create a packet with:
"""
"""ruby
Pio::Arp::Request.new(
source_mac: '00:26:82:eb:ea:d1',
sender_protocol_address: '192.168.83.3',
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/open_flow_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

When(/^I create a packet with:$/) do |ruby_code|
@result = Pio.module_eval(ruby_code)
cd('.') { @result = Pio.module_eval(ruby_code) }
end

When(/^I create an OpenFlow message with:$/) do |ruby_code|
Expand Down
Binary file removed fixtures/arp-storm.pcap
Binary file not shown.
Binary file removed fixtures/arp.pcap
Binary file not shown.
14 changes: 14 additions & 0 deletions fixtures/arp/arp_reply.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
0x00, 0x26, 0x82, 0xeb, 0xea, 0xd1, # destination_mac
0x00, 0x16, 0x9d, 0x1d, 0x9c, 0xc4, # source_mac
0x08, 0x06, # ether_type
0x00, 0x01, # hardware_type
0x08, 0x00, # protocol_type
0x06, # hardware_length
0x04, # protocol_length
0x00, 0x02, # operation
0x00, 0x16, 0x9d, 0x1d, 0x9c, 0xc4, # sender_hardware_address
0xc0, 0xa8, 0x53, 0xfe, # sender_protocol_address
0x00, 0x26, 0x82, 0xeb, 0xea, 0xd1, # target_hardware_address
0xc0, 0xa8, 0x53, 0x03, # target_protocol_address
].pack('C*')
14 changes: 14 additions & 0 deletions fixtures/arp/arp_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, # destination_mac
0x00, 0x26, 0x82, 0xeb, 0xea, 0xd1, # source_mac
0x08, 0x06, # ether_type
0x00, 0x01, # hardware_type
0x08, 0x00, # protocol_type
0x06, # hardware_length
0x04, # protocol_length
0x00, 0x01, # operation
0x00, 0x26, 0x82, 0xeb, 0xea, 0xd1, # sender_hardware_address
0xc0, 0xa8, 0x53, 0x03, # sender_protocol_address
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # target_hardware_address
0xc0, 0xa8, 0x53, 0xfe, # target_protocol_address
].pack('C*')

0 comments on commit 1798e6c

Please sign in to comment.