Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from trema/feature/exact_match
Add Pio::ExactMatch.
- Loading branch information
Showing
13 changed files
with
197 additions
and
28 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 |
---|---|---|
|
@@ -13,6 +13,7 @@ spec/reports | |
test/tmp | ||
test/version_tmp | ||
tmp | ||
vendor/ | ||
|
||
# YARD artifacts | ||
.yardoc | ||
|
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: Pio::ExactMatch.new | ||
Scenario: packet_in_arp_request.raw | ||
Given a packet data file "packet_in_arp_request.raw" | ||
When I try to create an exact match from the packet | ||
And the parsed data have the following field and value: | ||
| field | value | | ||
| wildcards | {} | | ||
| in_port | 1 | | ||
| dl_src | ac:5d:10:31:37:79 | | ||
| dl_dst | ff:ff:ff:ff:ff:ff | | ||
| dl_vlan | 65535 | | ||
| dl_vlan_pcp | 0 | | ||
| dl_type | 2054 | | ||
| nw_tos | 0 | | ||
| nw_proto | 1 | | ||
| nw_src | 192.168.2.254 | | ||
| nw_dst | 192.168.2.5 | | ||
| tp_src | 0 | | ||
| tp_dst | 0 | | ||
|
||
Scenario: packet_in_cbench.raw (ARP request) | ||
Given a packet data file "packet_in_cbench.raw" | ||
When I try to create an exact match from the packet | ||
And the parsed data have the following field and value: | ||
| field | value | | ||
| wildcards | {} | | ||
| in_port | 1 | | ||
| dl_src | 00:00:00:00:00:01 | | ||
| dl_dst | 80:00:00:00:00:01 | | ||
| dl_vlan | 65535 | | ||
| dl_vlan_pcp | 0 | | ||
| dl_type | 2048 | | ||
| nw_tos | 0 | | ||
| nw_proto | 255 | | ||
| nw_src | 192.168.0.40 | | ||
| nw_dst | 192.168.1.40 | | ||
| tp_src | 31256 | | ||
| tp_dst | 22635 | |
File renamed without changes.
Binary file not shown.
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
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,32 +1,19 @@ | ||
require 'forwardable' | ||
require 'pio/arp/format' | ||
|
||
module Pio | ||
class Arp | ||
# Base class of ARP Request and Reply | ||
class Message | ||
extend Forwardable | ||
|
||
def_delegators :@format, :destination_mac | ||
def_delegators :@format, :source_mac | ||
def_delegators :@format, :ether_type | ||
def_delegators :@format, :hardware_type | ||
def_delegators :@format, :protocol_type | ||
def_delegators :@format, :hardware_length | ||
def_delegators :@format, :protocol_length | ||
def_delegators :@format, :operation | ||
def_delegators :@format, :sender_hardware_address | ||
def_delegators :@format, :sender_protocol_address | ||
def_delegators :@format, :target_hardware_address | ||
def_delegators :@format, :target_protocol_address | ||
def_delegators :@format, :to_binary | ||
|
||
private_class_method :new | ||
|
||
def initialize(user_options) | ||
options = self.class.const_get(:Options).new(user_options.dup.freeze) | ||
@format = Arp::Format.new(options.to_hash) | ||
end | ||
|
||
def method_missing(method, *args) | ||
@format.__send__ method, *args | ||
end | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
require 'pio/match' | ||
require 'pio/type/ethernet_header' | ||
|
||
module Pio | ||
# OpenFlow 1.0 exact match | ||
class ExactMatch | ||
# Pio::PacketIn#data parser | ||
class PacketInDataParser | ||
# Ethernet header parser | ||
class EthernetHeaderParser < BinData::Record | ||
extend Pio::Type::EthernetHeader | ||
|
||
endian :big | ||
|
||
ethernet_header | ||
rest :payload | ||
end | ||
|
||
# IPv4 packet parser | ||
class IPv4Packet < BinData::Record | ||
extend Pio::Type::EthernetHeader | ||
extend Type::IPv4Header | ||
|
||
endian :big | ||
|
||
ethernet_header | ||
ipv4_header | ||
|
||
uint16 :transport_source_port | ||
uint16 :transport_destination_port | ||
rest :rest | ||
end | ||
|
||
def self.read(raw_data) | ||
ethernet_header = EthernetHeaderParser.read(raw_data) | ||
case ethernet_header.ether_type | ||
when 0x0800 | ||
IPv4Packet.read raw_data | ||
when 0x0806 | ||
Pio::Arp.read raw_data | ||
else | ||
fail 'Failed to parse packet_in data.' | ||
end | ||
end | ||
end | ||
|
||
extend Forwardable | ||
|
||
# rubocop:disable MethodLength | ||
# rubocop:disable AbcSize | ||
def initialize(packet_in) | ||
data = PacketInDataParser.read(packet_in.data) | ||
case data | ||
when PacketInDataParser::IPv4Packet | ||
options = { | ||
in_port: packet_in.in_port, | ||
dl_src: data.source_mac, | ||
dl_dst: data.destination_mac, | ||
dl_vlan: data.vlan_vid, | ||
dl_vlan_pcp: data.vlan_pcp, | ||
dl_type: data.ether_type, | ||
nw_tos: data.ip_type_of_service, | ||
nw_proto: data.ip_protocol, | ||
nw_src: data.ip_source_address, | ||
nw_dst: data.ip_destination_address, | ||
tp_src: data.transport_source_port, | ||
tp_dst: data.transport_destination_port | ||
} | ||
when Arp::Request | ||
options = { | ||
in_port: packet_in.in_port, | ||
dl_src: data.source_mac, | ||
dl_dst: data.destination_mac, | ||
dl_vlan: data.vlan_vid, | ||
dl_vlan_pcp: data.vlan_pcp, | ||
dl_type: data.ether_type, | ||
nw_tos: 0, | ||
nw_proto: data.operation, | ||
nw_src: data.sender_protocol_address, | ||
nw_dst: data.target_protocol_address, | ||
tp_src: 0, | ||
tp_dst: 0 | ||
} | ||
end | ||
@match = Pio::Match.new(options) | ||
end | ||
# rubocop:enable MethodLength | ||
# rubocop:enable AbcSize | ||
|
||
def_delegator :@match, :wildcards | ||
def_delegator :@match, :in_port | ||
def_delegator :@match, :dl_src | ||
def_delegator :@match, :dl_dst | ||
def_delegator :@match, :dl_vlan | ||
def_delegator :@match, :dl_vlan_pcp | ||
def_delegator :@match, :dl_type | ||
def_delegator :@match, :nw_tos | ||
def_delegator :@match, :nw_proto | ||
def_delegator :@match, :nw_src | ||
def_delegator :@match, :nw_dst | ||
def_delegator :@match, :tp_src | ||
def_delegator :@match, :tp_dst | ||
def_delegator :@match, :to_binary_s | ||
def_delegator :@match, :to_binary_s, :to_binary | ||
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
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