openflow-protocol 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/lib/messages/echo_reply.rb +6 -0
  3. data/lib/openflow-protocol/version.rb +5 -0
  4. data/spec/actions/action_enqueue_spec.rb +30 -0
  5. data/spec/actions/action_output_spec.rb +29 -0
  6. data/spec/actions/action_set_destination_port_spec.rb +26 -0
  7. data/spec/actions/action_set_ip_destination_spec.rb +25 -0
  8. data/spec/actions/action_set_ip_source_spec.rb +25 -0
  9. data/spec/actions/action_set_ip_tos_spec.rb +26 -0
  10. data/spec/actions/action_set_mac_destination_spec.rb +26 -0
  11. data/spec/actions/action_set_mac_source_spec.rb +26 -0
  12. data/spec/actions/action_set_source_port_spec.rb +26 -0
  13. data/spec/actions/action_set_vlan_id_spec.rb +26 -0
  14. data/spec/actions/action_set_vlan_pcp_spec.rb +26 -0
  15. data/spec/actions/action_strip_vlan_spec.rb +17 -0
  16. data/spec/actions/action_vendor_spec.rb +25 -0
  17. data/spec/actions/actions_spec.rb +33 -0
  18. data/spec/messages/barrier_reply_spec.rb +25 -0
  19. data/spec/messages/barrier_request_spec.rb +25 -0
  20. data/spec/messages/echo_reply_spec.rb +44 -0
  21. data/spec/messages/echo_request_spec.rb +53 -0
  22. data/spec/messages/error_spec.rb +56 -0
  23. data/spec/messages/features_reply_spec.rb +204 -0
  24. data/spec/messages/features_request_spec.rb +25 -0
  25. data/spec/messages/flow_mod_spec.rb +139 -0
  26. data/spec/messages/flow_removed_spec.rb +109 -0
  27. data/spec/messages/get_config_reply_spec.rb +39 -0
  28. data/spec/messages/get_config_request_spec.rb +25 -0
  29. data/spec/messages/hello_spec.rb +25 -0
  30. data/spec/messages/packet_in_spec.rb +76 -0
  31. data/spec/messages/packet_out_spec.rb +56 -0
  32. data/spec/messages/parser_spec.rb +43 -0
  33. data/spec/messages/port_mod_spec.rb +64 -0
  34. data/spec/messages/port_status_spec.rb +52 -0
  35. data/spec/messages/set_config_spec.rb +39 -0
  36. data/spec/messages/statistics_reply_spec.rb +411 -0
  37. data/spec/messages/statistics_request_spec.rb +355 -0
  38. data/spec/messages/vendor_spec.rb +56 -0
  39. data/spec/spec_helper.rb +7 -0
  40. data/spec/statistics/aggregate_statistics_reply_spec.rb +31 -0
  41. data/spec/statistics/aggregate_statistics_request_spec.rb +46 -0
  42. data/spec/statistics/description_statistics_spec.rb +38 -0
  43. data/spec/statistics/flow_statistics_reply_spec.rb +74 -0
  44. data/spec/statistics/flow_statistics_request_spec.rb +46 -0
  45. data/spec/statistics/port_statistics_reply_spec.rb +81 -0
  46. data/spec/statistics/port_statistics_request_spec.rb +19 -0
  47. data/spec/statistics/queue_statistics_reply_spec.rb +42 -0
  48. data/spec/statistics/queue_statistics_request_spec.rb +26 -0
  49. data/spec/statistics/table_statistics_spec.rb +54 -0
  50. data/spec/statistics/vendor_statistics_spec.rb +25 -0
  51. data/spec/structs/match_spec.rb +143 -0
  52. data/spec/structs/physical_port_spec.rb +63 -0
  53. data/spec/structs/port_number_spec.rb +19 -0
  54. metadata +109 -8
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe OFVendor do
4
+ it 'should read binary' do
5
+ msg = OFVendor.read [
6
+ 1, 4, 0, 12, 0, 0, 0, 1, # header
7
+ 0, 0, 0, 1 # vendor
8
+ ].pack('C*')
9
+ expect(msg.version).to eq(OFMessage::OFP_VERSION)
10
+ expect(msg.type).to eq(:vendor)
11
+ expect(msg.len).to eq(12)
12
+ expect(msg.xid).to eq(1)
13
+ expect(msg.vendor).to eq(1)
14
+ expect(msg.data).to be_empty
15
+ end
16
+ it 'should read binary with data' do
17
+ msg = OFVendor.read [
18
+ 1, 4, 0, 14, 0, 0, 0, 1, # header
19
+ 0, 0, 0, 1, # vendor
20
+ 10, 20 # data
21
+ ].pack('C*')
22
+ expect(msg.version).to eq(OFMessage::OFP_VERSION)
23
+ expect(msg.type).to eq(:vendor)
24
+ expect(msg.len).to eq(14)
25
+ expect(msg.xid).to eq(1)
26
+ expect(msg.vendor).to eq(1)
27
+ expect(msg.data.length).to eq(2)
28
+ end
29
+ it 'should initialize with default values' do
30
+ msg = OFVendor.new
31
+ expect(msg.version).to eq(OFMessage::OFP_VERSION)
32
+ expect(msg.type).to eq(:vendor)
33
+ expect(msg.len).to eq(12)
34
+ expect(msg.xid).to eq(0)
35
+ expect(msg.vendor).to eq(0)
36
+ expect(msg.data).to be_empty
37
+ end
38
+ it 'should initialize with some values' do
39
+ msg = OFVendor.new(xid: 1, vendor: 1)
40
+ expect(msg.version).to eq(OFMessage::OFP_VERSION)
41
+ expect(msg.type).to eq(:vendor)
42
+ expect(msg.len).to eq(12)
43
+ expect(msg.xid).to eq(1)
44
+ expect(msg.vendor).to eq(1)
45
+ expect(msg.data).to be_empty
46
+ end
47
+ it 'should initialize with data' do
48
+ msg = OFVendor.new(vendor: 1, data: [10, 20].pack('C*'))
49
+ expect(msg.version).to eq(OFMessage::OFP_VERSION)
50
+ expect(msg.type).to eq(:vendor)
51
+ expect(msg.len).to eq(14)
52
+ expect(msg.xid).to eq(0)
53
+ expect(msg.vendor).to eq(1)
54
+ expect(msg.data.length).to eq(2)
55
+ end
56
+ end
@@ -0,0 +1,7 @@
1
+ require_relative '../lib/openflow-protocol'
2
+
3
+ class String
4
+ def pad(length, value = [0].pack('C*'))
5
+ self + value * (length - self.length)
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe OFAggregateStatisticsReply do
4
+ it 'should read binary' do
5
+ stats = OFAggregateStatisticsReply.read [
6
+ 0, 0, 0, 0, 0, 0, 0, 10, # packet_count
7
+ 0, 0, 0, 0, 0, 0, 0, 80, # byte_count
8
+ 0, 0, 0, 4, # flow_count
9
+ 0, 0, 0, 0 # padding
10
+ ].pack('C*')
11
+ expect(stats.packet_count).to eq(10)
12
+ expect(stats.byte_count).to eq(80)
13
+ expect(stats.flow_count).to eq(4)
14
+ end
15
+ it 'should initialize with default values' do
16
+ stats = OFAggregateStatisticsReply.new
17
+ expect(stats.packet_count).to eq(0)
18
+ expect(stats.byte_count).to eq(0)
19
+ expect(stats.flow_count).to eq(0)
20
+ end
21
+ it 'should initialize with some values' do
22
+ stats = OFAggregateStatisticsReply.new(
23
+ packet_count: 10,
24
+ byte_count: 80,
25
+ flow_count: 4
26
+ )
27
+ expect(stats.packet_count).to eq(10)
28
+ expect(stats.byte_count).to eq(80)
29
+ expect(stats.flow_count).to eq(4)
30
+ end
31
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe OFAggregateStatisticsRequest do
4
+ it 'should read binary' do
5
+ stats = OFAggregateStatisticsRequest.read [
6
+ # match
7
+ 0, 0x30, 0x20, 0x4f, # wildcards
8
+ 0, 0, # in_port
9
+ 0, 0, 0, 0, 0, 0, # mac_source
10
+ 0, 0, 0, 0, 0, 0, # mac_destination
11
+ 0xff, 0xff, # vlan_id
12
+ 0, # vlan_pcp
13
+ 0, # padding
14
+ 8, 0, # mac_protocol
15
+ 0, # ip_tos
16
+ 6, # ip_protocol
17
+ 0, 0, # padding
18
+ 0, 0, 0, 0, # ip_source
19
+ 192, 168, 0, 2, # ip_destination
20
+ 0, 0, # source_port
21
+ 0x0b, 0xb8, # destination_port
22
+
23
+ 1, # table_id
24
+ 0, # padding
25
+ 0, 1 # out_port
26
+ ].pack('C*')
27
+ expect(stats.match.ip_destination).to eq('192.168.0.2')
28
+ expect(stats.table_id).to eq(1)
29
+ expect(stats.out_port).to eq(1)
30
+ end
31
+ it 'should initialize with default values' do
32
+ stats = OFAggregateStatisticsRequest.new
33
+ expect(stats.match.ip_destination).to eq('0.0.0.0')
34
+ expect(stats.table_id).to eq(:all)
35
+ expect(stats.out_port).to eq(:none)
36
+ end
37
+ it 'should initialize with some values' do
38
+ stats = OFAggregateStatisticsRequest.new(
39
+ table_id: 1,
40
+ out_port: 1
41
+ )
42
+ expect(stats.match.ip_destination).to eq('0.0.0.0')
43
+ expect(stats.table_id).to eq(1)
44
+ expect(stats.out_port).to eq(1)
45
+ end
46
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe OFDescriptionStatistics do
4
+ it 'should read binary' do
5
+ stats = OFDescriptionStatistics.read 'Manufacturer description'.pad(256) +
6
+ 'Hardware description'.pad(256) +
7
+ 'Software description'.pad(256) +
8
+ '123456789'.pad(32) +
9
+ 'Datapath description'.pad(256)
10
+ expect(stats.manufacturer_description).to eq('Manufacturer description')
11
+ expect(stats.hardware_description).to eq('Hardware description')
12
+ expect(stats.software_description).to eq('Software description')
13
+ expect(stats.serial_number).to eq('123456789')
14
+ expect(stats.datapath_description).to eq('Datapath description')
15
+ end
16
+ it 'should initialize with default values' do
17
+ stats = OFDescriptionStatistics.new
18
+ expect(stats.manufacturer_description).to eq('')
19
+ expect(stats.hardware_description).to eq('')
20
+ expect(stats.software_description).to eq('')
21
+ expect(stats.serial_number).to eq('')
22
+ expect(stats.datapath_description).to eq('')
23
+ end
24
+ it 'should initialize with some values' do
25
+ stats = OFDescriptionStatistics.new(
26
+ manufacturer_description: 'Manufacturer description',
27
+ hardware_description: 'Hardware description',
28
+ software_description: 'Software description',
29
+ serial_number: '123456789',
30
+ datapath_description: 'Datapath description'
31
+ )
32
+ expect(stats.manufacturer_description).to eq('Manufacturer description')
33
+ expect(stats.hardware_description).to eq('Hardware description')
34
+ expect(stats.software_description).to eq('Software description')
35
+ expect(stats.serial_number).to eq('123456789')
36
+ expect(stats.datapath_description).to eq('Datapath description')
37
+ end
38
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe OFFlowStatisticsReply do
4
+ it 'should read binary' do
5
+ stats = OFFlowStatisticsReply.read [
6
+ 0, 96, # len
7
+ 1, # table_id
8
+ 0, # padding
9
+
10
+ # match
11
+ 0, 0x30, 0x20, 0x4f, # wildcards
12
+ 0, 0, # in_port
13
+ 0, 0, 0, 0, 0, 0, # mac_source
14
+ 0, 0, 0, 0, 0, 0, # mac_destination
15
+ 0xff, 0xff, # vlan_id
16
+ 0, # vlan_pcp
17
+ 0, # padding
18
+ 8, 0, # mac_protocol
19
+ 0, # ip_tos
20
+ 6, # ip_protocol
21
+ 0, 0, # padding
22
+ 0, 0, 0, 0, # ip_source
23
+ 192, 168, 0, 2, # ip_destination
24
+ 0, 0, # source_port
25
+ 0x0b, 0xb8, # destination_port
26
+
27
+ 0, 0, 0, 50, # duration_seconds
28
+ 0, 0, 0, 10, # duration_nanoseconds
29
+ 0x0b, 0xb8, # priority
30
+ 0, 100, # idle_timeout
31
+ 1, 0x2c, # hard_timeout
32
+ 0, 0, 0, 0, 0, 0, # padding
33
+ 0, 0, 0, 0, 0, 0, 0, 1, # cookie
34
+ 0, 0, 0, 0, 0, 0, 0, 10, # packet_count
35
+ 0, 0, 0, 0, 0, 0, 0, 80, # byte_count
36
+
37
+ # actions
38
+ # output
39
+ 0, 0, 0, 8, # header
40
+ 0, 1, # port
41
+ 0xff, 0xff # max_length
42
+ ].pack('C*')
43
+ expect(stats.len).to eq(96)
44
+ expect(stats.table_id).to eq(1)
45
+ expect(stats.match.ip_destination).to eq('192.168.0.2')
46
+ expect(stats.duration_seconds).to eq(50)
47
+ expect(stats.duration_nanoseconds).to eq(10)
48
+ expect(stats.idle_timeout).to eq(100)
49
+ expect(stats.hard_timeout).to eq(300)
50
+ expect(stats.cookie).to eq(1)
51
+ expect(stats.packet_count).to eq(10)
52
+ expect(stats.byte_count).to eq(80)
53
+ expect(stats.actions.length).to eq(1)
54
+ end
55
+ it 'should initialize with default values' do
56
+ stats = OFFlowStatisticsReply.new
57
+ expect(stats.len).to eq(88)
58
+ expect(stats.table_id).to eq(:all)
59
+ expect(stats.match.ip_destination).to eq('0.0.0.0')
60
+ expect(stats.duration_seconds).to eq(0)
61
+ expect(stats.duration_nanoseconds).to eq(0)
62
+ expect(stats.idle_timeout).to eq(0)
63
+ expect(stats.hard_timeout).to eq(0)
64
+ expect(stats.cookie).to eq(0)
65
+ expect(stats.packet_count).to eq(0)
66
+ expect(stats.byte_count).to eq(0)
67
+ expect(stats.actions).to be_empty
68
+ end
69
+ it 'should initialize with some values' do
70
+ stats = OFFlowStatisticsReply.new(
71
+ )
72
+
73
+ end
74
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe OFFlowStatisticsRequest do
4
+ it 'should read binary' do
5
+ stats = OFFlowStatisticsRequest.read [
6
+ # match
7
+ 0, 0x30, 0x20, 0x4f, # wildcards
8
+ 0, 0, # in_port
9
+ 0, 0, 0, 0, 0, 0, # mac_source
10
+ 0, 0, 0, 0, 0, 0, # mac_destination
11
+ 0xff, 0xff, # vlan_id
12
+ 0, # vlan_pcp
13
+ 0, # padding
14
+ 8, 0, # mac_protocol
15
+ 0, # ip_tos
16
+ 6, # ip_protocol
17
+ 0, 0, # padding
18
+ 0, 0, 0, 0, # ip_source
19
+ 192, 168, 0, 2, # ip_destination
20
+ 0, 0, # source_port
21
+ 0x0b, 0xb8, # destination_port
22
+
23
+ 1, # table_id
24
+ 0, # padding
25
+ 0, 1 # out_port
26
+ ].pack('C*')
27
+ expect(stats.match.ip_destination).to eq('192.168.0.2')
28
+ expect(stats.table_id).to eq(1)
29
+ expect(stats.out_port).to eq(1)
30
+ end
31
+ it 'should initialize with default values' do
32
+ stats = OFFlowStatisticsRequest.new
33
+ expect(stats.match.ip_destination).to eq('0.0.0.0')
34
+ expect(stats.table_id).to eq(:all)
35
+ expect(stats.out_port).to eq(:none)
36
+ end
37
+ it 'should initialize with some values' do
38
+ stats = OFFlowStatisticsRequest.new(
39
+ table_id: 1,
40
+ out_port: 1
41
+ )
42
+ expect(stats.match.ip_destination).to eq('0.0.0.0')
43
+ expect(stats.table_id).to eq(1)
44
+ expect(stats.out_port).to eq(1)
45
+ end
46
+ end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ describe OFPortStatisticsReply do
4
+ it 'should read binary' do
5
+ stats = OFPortStatisticsReply.read [
6
+ 0, 1, # port_number
7
+ 0, 0, 0, 0, 0, 0, # padding
8
+ 0, 0, 0, 0, 0, 0, 0, 10, # receive_packets
9
+ 0, 0, 0, 0, 0, 0, 0, 10, # transmit_packets
10
+ 0, 0, 0, 0, 0, 0, 0, 80, # receive_bytes
11
+ 0, 0, 0, 0, 0, 0, 0, 80, # transmit_bytes
12
+ 0, 0, 0, 0, 0, 0, 0, 5, # receive_dropped
13
+ 0, 0, 0, 0, 0, 0, 0, 5, # transmit_dropped
14
+ 0, 0, 0, 0, 0, 0, 0, 2, # receive_errors
15
+ 0, 0, 0, 0, 0, 0, 0, 2, # transmit_errors
16
+ 0, 0, 0, 0, 0, 0, 0, 1, # receive_frame_errors
17
+ 0, 0, 0, 0, 0, 0, 0, 0, # receive_overrun_errors
18
+ 0, 0, 0, 0, 0, 0, 0, 1, # receive_crc_errors
19
+ 0, 0, 0, 0, 0, 0, 0, 3 # collisions
20
+ ].pack('C*')
21
+ expect(stats.port_number).to eq(1)
22
+ expect(stats.receive_packets).to eq(10)
23
+ expect(stats.transmit_packets).to eq(10)
24
+ expect(stats.receive_bytes).to eq(80)
25
+ expect(stats.transmit_bytes).to eq(80)
26
+ expect(stats.receive_dropped).to eq(5)
27
+ expect(stats.transmit_dropped).to eq(5)
28
+ expect(stats.receive_errors).to eq(2)
29
+ expect(stats.transmit_errors).to eq(2)
30
+ expect(stats.receive_frame_errors).to eq(1)
31
+ expect(stats.receive_overrun_errors).to eq(0)
32
+ expect(stats.receive_crc_errors).to eq(1)
33
+ expect(stats.collisions).to eq(3)
34
+ end
35
+ it 'should initialize with default values' do
36
+ stats = OFPortStatisticsReply.new
37
+ expect(stats.port_number).to eq(0)
38
+ expect(stats.receive_packets).to eq(0)
39
+ expect(stats.transmit_packets).to eq(0)
40
+ expect(stats.receive_bytes).to eq(0)
41
+ expect(stats.transmit_bytes).to eq(0)
42
+ expect(stats.receive_dropped).to eq(0)
43
+ expect(stats.transmit_dropped).to eq(0)
44
+ expect(stats.receive_errors).to eq(0)
45
+ expect(stats.transmit_errors).to eq(0)
46
+ expect(stats.receive_frame_errors).to eq(0)
47
+ expect(stats.receive_overrun_errors).to eq(0)
48
+ expect(stats.receive_crc_errors).to eq(0)
49
+ expect(stats.collisions).to eq(0)
50
+ end
51
+ it 'should initialize with some values' do
52
+ stats = OFPortStatisticsReply.new(
53
+ port_number: 1,
54
+ receive_packets: 10,
55
+ transmit_packets: 10,
56
+ receive_bytes: 80,
57
+ transmit_bytes: 80,
58
+ receive_dropped: 5,
59
+ transmit_dropped: 5,
60
+ receive_errors: 2,
61
+ transmit_errors: 2,
62
+ receive_frame_errors: 1,
63
+ receive_overrun_errors: 0,
64
+ receive_crc_errors: 1,
65
+ collisions: 3
66
+ )
67
+ expect(stats.port_number).to eq(1)
68
+ expect(stats.receive_packets).to eq(10)
69
+ expect(stats.transmit_packets).to eq(10)
70
+ expect(stats.receive_bytes).to eq(80)
71
+ expect(stats.transmit_bytes).to eq(80)
72
+ expect(stats.receive_dropped).to eq(5)
73
+ expect(stats.transmit_dropped).to eq(5)
74
+ expect(stats.receive_errors).to eq(2)
75
+ expect(stats.transmit_errors).to eq(2)
76
+ expect(stats.receive_frame_errors).to eq(1)
77
+ expect(stats.receive_overrun_errors).to eq(0)
78
+ expect(stats.receive_crc_errors).to eq(1)
79
+ expect(stats.collisions).to eq(3)
80
+ end
81
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe OFPortStatisticsRequest do
4
+ it 'should read binary' do
5
+ stats = OFPortStatisticsRequest.read [
6
+ 0, 1, # port_number
7
+ 0, 0, 0, 0, 0, 0 # padding
8
+ ].pack('C*')
9
+ expect(stats.port_number).to eq(1)
10
+ end
11
+ it 'should initialize with default values' do
12
+ stats = OFPortStatisticsRequest.new
13
+ expect(stats.port_number).to eq(:none)
14
+ end
15
+ it 'should initialize with some values' do
16
+ stats = OFPortStatisticsRequest.new(port_number: 1)
17
+ expect(stats.port_number).to eq(1)
18
+ end
19
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe OFQueueStatisticsReply do
4
+ it 'should read binary' do
5
+ stats = OFQueueStatisticsReply.read [
6
+ 0, 1, # port_number
7
+ 0, 0, # padding
8
+ 0, 0, 0, 1, # queue_id
9
+ 0, 0, 0, 0, 0, 0, 0, 80, # transmit_bytes
10
+ 0, 0, 0, 0, 0, 0, 0, 10, # transmit_packets
11
+ 0, 0, 0, 0, 0, 0, 0, 2 # transmit_errors
12
+ ].pack('C*')
13
+ expect(stats.port_number).to eq(1)
14
+ expect(stats.queue_id).to eq(1)
15
+ expect(stats.transmit_bytes).to eq(80)
16
+ expect(stats.transmit_packets).to eq(10)
17
+ expect(stats.transmit_errors).to eq(2)
18
+ end
19
+ it 'should initialize with default values' do
20
+ stats = OFQueueStatisticsReply.new
21
+ expect(stats.port_number).to eq(0)
22
+ # expect(stats.queue_id).to eq(:all)
23
+ # TODO: QUEUE_IDS somewhere!
24
+ expect(stats.transmit_bytes).to eq(0)
25
+ expect(stats.transmit_packets).to eq(0)
26
+ expect(stats.transmit_errors).to eq(0)
27
+ end
28
+ it 'should initialize with some values' do
29
+ stats = OFQueueStatisticsReply.new(
30
+ port_number: 1,
31
+ queue_id: 1,
32
+ transmit_bytes: 80,
33
+ transmit_packets: 10,
34
+ transmit_errors: 2
35
+ )
36
+ expect(stats.port_number).to eq(1)
37
+ expect(stats.queue_id).to eq(1)
38
+ expect(stats.transmit_bytes).to eq(80)
39
+ expect(stats.transmit_packets).to eq(10)
40
+ expect(stats.transmit_errors).to eq(2)
41
+ end
42
+ end