pio 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2bb4195ca95f655a64ce7c02ec9884a3bad1fd7c
4
- data.tar.gz: 33cd84c8eb3e5289672c80e27d27b9c189b71303
3
+ metadata.gz: 961afabded91db3ee0c2cc5958abdd2477a5c735
4
+ data.tar.gz: e7d5dd569c6a0138e2e8868aec8d16ce8db91597
5
5
  SHA512:
6
- metadata.gz: cea7f5346912379c9f0cf5800a8f57d997694126679c241dacefaeb0f4bcc0597f5debfd63ca151d8e2226418b59beba0aa8fabab5cb60068f4ba0751dffedad
7
- data.tar.gz: 98b9e42fc3995ba700d0d1d75bc852bd3bd9a4a1c30b538802b6b56b8d80f95ce53d0711226bd778aca87d1f7d3736976d124fd98add04843302a6d8847c2e12
6
+ metadata.gz: c313331ac7d13721206b253ffcc7069bc080c9c91f237d6315bc0c31609085b187d40bac070bf4d320696b457e3a40033cb2d004edcb927c256eb55bcd5cecdc
7
+ data.tar.gz: df35e068243c4a509b8e06109198dce31850a1bdbfb9943fe234ce3654a50587266954629336b4379cde355fc224b5f028b97ef6d3a96e77260a419181beebf7
data/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  ## develop (unreleased)
4
4
 
5
5
 
6
+ ## 0.13.0 (2/6/2015)
7
+
8
+ ### New features
9
+ * [#124](https://github.com/trema/pio/pull/124): Add new methods `Pio::PacketIn#source_mac` and `Pio::PacketIn#destination_mac`.
10
+
11
+
6
12
  ## 0.12.0 (2/5/2015)
7
13
 
8
14
  ### New features
@@ -4,15 +4,17 @@ Feature: Pio::PacketIn.read
4
4
  When I try to parse the file with "PacketIn" class
5
5
  Then it should finish successfully
6
6
  And the parsed data have the following field and value:
7
- | field | value |
8
- | class | Pio::PacketIn |
9
- | ofp_version | 1 |
10
- | message_type | 10 |
11
- | message_length | 78 |
12
- | transaction_id | 0 |
13
- | xid | 0 |
14
- | buffer_id | 4294967040 |
15
- | total_len | 60 |
16
- | in_port | 1 |
17
- | reason | no_match |
18
- | data.length | 60 |
7
+ | field | value |
8
+ | class | Pio::PacketIn |
9
+ | ofp_version | 1 |
10
+ | message_type | 10 |
11
+ | message_length | 78 |
12
+ | transaction_id | 0 |
13
+ | xid | 0 |
14
+ | buffer_id | 4294967040 |
15
+ | total_len | 60 |
16
+ | in_port | 1 |
17
+ | reason | no_match |
18
+ | data.length | 60 |
19
+ | source_mac | ac:5d:10:31:37:79 |
20
+ | destination_mac | ff:ff:ff:ff:ff:ff |
@@ -4,58 +4,16 @@ require 'pio/type/ethernet_header'
4
4
  module Pio
5
5
  # OpenFlow 1.0 exact match
6
6
  class ExactMatch
7
- # Pio::PacketIn#data parser
8
- class PacketInDataParser
9
- # Ethernet header parser
10
- class EthernetHeaderParser < BinData::Record
11
- extend Pio::Type::EthernetHeader
12
-
13
- endian :big
14
-
15
- ethernet_header
16
- rest :payload
17
- end
18
-
19
- # IPv4 packet parser
20
- class IPv4Packet < BinData::Record
21
- extend Pio::Type::EthernetHeader
22
- extend Type::IPv4Header
23
-
24
- endian :big
25
-
26
- ethernet_header
27
- ipv4_header
28
-
29
- uint16 :transport_source_port
30
- uint16 :transport_destination_port
31
- rest :rest
32
- end
33
-
34
- def self.read(raw_data)
35
- ethernet_header = EthernetHeaderParser.read(raw_data)
36
- case ethernet_header.ether_type
37
- when 0x0800
38
- IPv4Packet.read raw_data
39
- when 0x0806
40
- Pio::Arp.read raw_data
41
- else
42
- fail 'Failed to parse packet_in data.'
43
- end
44
- end
45
- end
46
-
47
- extend Forwardable
48
-
49
7
  # rubocop:disable MethodLength
50
8
  # rubocop:disable AbcSize
51
9
  def initialize(packet_in)
52
- data = PacketInDataParser.read(packet_in.data)
10
+ data = packet_in.parsed_data
53
11
  case data
54
- when PacketInDataParser::IPv4Packet
12
+ when PacketIn::DataParser::IPv4Packet
55
13
  options = {
56
14
  in_port: packet_in.in_port,
57
- dl_src: data.source_mac,
58
- dl_dst: data.destination_mac,
15
+ dl_src: packet_in.source_mac,
16
+ dl_dst: packet_in.destination_mac,
59
17
  dl_vlan: data.vlan_vid,
60
18
  dl_vlan_pcp: data.vlan_pcp,
61
19
  dl_type: data.ether_type,
@@ -69,8 +27,8 @@ module Pio
69
27
  when Arp::Request
70
28
  options = {
71
29
  in_port: packet_in.in_port,
72
- dl_src: data.source_mac,
73
- dl_dst: data.destination_mac,
30
+ dl_src: packet_in.source_mac,
31
+ dl_dst: packet_in.destination_mac,
74
32
  dl_vlan: data.vlan_vid,
75
33
  dl_vlan_pcp: data.vlan_pcp,
76
34
  dl_type: data.ether_type,
@@ -87,6 +45,8 @@ module Pio
87
45
  # rubocop:enable MethodLength
88
46
  # rubocop:enable AbcSize
89
47
 
48
+ extend Forwardable
49
+
90
50
  def_delegator :@match, :wildcards
91
51
  def_delegator :@match, :in_port
92
52
  def_delegator :@match, :dl_src
data/lib/pio/packet_in.rb CHANGED
@@ -42,10 +42,62 @@ module Pio
42
42
  end
43
43
  end
44
44
 
45
+ # Pio::PacketIn#data parser
46
+ class DataParser
47
+ # Ethernet header parser
48
+ class EthernetHeaderParser < BinData::Record
49
+ extend Pio::Type::EthernetHeader
50
+
51
+ endian :big
52
+
53
+ ethernet_header
54
+ rest :payload
55
+ end
56
+
57
+ # IPv4 packet parser
58
+ class IPv4Packet < BinData::Record
59
+ extend Pio::Type::EthernetHeader
60
+ extend Type::IPv4Header
61
+
62
+ endian :big
63
+
64
+ ethernet_header
65
+ ipv4_header
66
+
67
+ uint16 :transport_source_port
68
+ uint16 :transport_destination_port
69
+ rest :rest
70
+ end
71
+
72
+ def self.read(raw_data)
73
+ ethernet_header = EthernetHeaderParser.read(raw_data)
74
+ case ethernet_header.ether_type
75
+ when 0x0800
76
+ IPv4Packet.read raw_data
77
+ when 0x0806
78
+ Pio::Arp.read raw_data
79
+ else
80
+ fail 'Failed to parse packet_in data.'
81
+ end
82
+ end
83
+ end
84
+
45
85
  def_delegators :body, :buffer_id
46
86
  def_delegators :body, :total_len
47
87
  def_delegators :body, :in_port
48
88
  def_delegators :body, :reason
49
89
  def_delegators :body, :data
90
+
91
+ def parsed_data
92
+ @parsed_data ||= DataParser.read(data)
93
+ end
94
+
95
+ def source_mac
96
+ parsed_data.source_mac
97
+ end
98
+
99
+ def destination_mac
100
+ parsed_data.destination_mac
101
+ end
50
102
  end
51
103
  end
data/lib/pio/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # Base module.
2
2
  module Pio
3
3
  # gem version.
4
- VERSION = '0.12.0'.freeze
4
+ VERSION = '0.13.0'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yasuhito Takamiya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-05 00:00:00.000000000 Z
11
+ date: 2015-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -586,7 +586,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
586
586
  version: '0'
587
587
  requirements: []
588
588
  rubyforge_project:
589
- rubygems_version: 2.2.2
589
+ rubygems_version: 2.4.3
590
590
  signing_key:
591
591
  specification_version: 4
592
592
  summary: Packet parser and generator.