trema 0.2.8 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ruby/trema/send-out-port.rb +7 -2
- data/ruby/trema/set-eth-dst-addr.rb +5 -0
- data/ruby/trema/set-eth-src-addr.rb +5 -0
- data/ruby/trema/stats-reply.c +41 -32
- data/ruby/trema/version.rb +1 -1
- data/spec/trema/send-out-port_spec.rb +3 -0
- data/spec/trema/set-eth-dst-addr_spec.rb +2 -0
- data/spec/trema/set-eth-src-addr_spec.rb +2 -0
- data/src/examples/simple_router/README +18 -0
- data/src/examples/simple_router/routing-table.rb +1 -1
- data/src/examples/simple_router/simple-router.rb +6 -6
- data/src/examples/simple_router/simple_router.conf +7 -1
- metadata +6 -5
data/ruby/trema/send-out-port.rb
CHANGED
@@ -74,9 +74,14 @@ module Trema
|
|
74
74
|
end
|
75
75
|
|
76
76
|
|
77
|
-
|
77
|
+
def to_s
|
78
|
+
"SendOutPort: port=#{ @port_number }, max_len=#{ @max_len }"
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
############################################################################
|
78
83
|
private
|
79
|
-
|
84
|
+
############################################################################
|
80
85
|
|
81
86
|
|
82
87
|
def check_port_number
|
data/ruby/trema/stats-reply.c
CHANGED
@@ -168,69 +168,65 @@ Init_stats_reply() {
|
|
168
168
|
static VALUE
|
169
169
|
get_action( const struct ofp_action_header *ah ) {
|
170
170
|
VALUE action = Qnil;
|
171
|
-
VALUE options = rb_hash_new();
|
172
171
|
|
173
172
|
switch ( ah->type ) {
|
174
173
|
case OFPAT_OUTPUT:
|
175
174
|
{
|
176
175
|
const struct ofp_action_output *ao = ( const struct ofp_action_output * ) ah;
|
177
176
|
|
178
|
-
|
179
|
-
|
177
|
+
VALUE options = rb_hash_new();
|
178
|
+
rb_hash_aset( options, ID2SYM( rb_intern( "port_number" ) ), UINT2NUM( ao->port ) );
|
179
|
+
rb_hash_aset( options, ID2SYM( rb_intern( "max_len" ) ), UINT2NUM( ao->max_len ) );
|
180
|
+
action = rb_funcall( rb_eval_string( "Trema::SendOutPort" ), rb_intern( "new" ), 1, options );
|
180
181
|
}
|
181
182
|
break;
|
182
183
|
case OFPAT_SET_VLAN_VID:
|
183
184
|
{
|
184
185
|
const struct ofp_action_vlan_vid *action_vlan_vid = ( const struct ofp_action_vlan_vid * ) ah;
|
185
186
|
|
186
|
-
|
187
|
-
action = rb_funcall( rb_eval_string( "Trema::
|
187
|
+
VALUE vlan_id = UINT2NUM( action_vlan_vid->vlan_vid );
|
188
|
+
action = rb_funcall( rb_eval_string( "Trema::SetVlanVid" ), rb_intern( "new" ), 1, vlan_id );
|
188
189
|
}
|
189
190
|
break;
|
190
191
|
case OFPAT_SET_VLAN_PCP:
|
191
192
|
{
|
192
193
|
const struct ofp_action_vlan_pcp *action_vlan_pcp = ( const struct ofp_action_vlan_pcp * ) ah;
|
193
194
|
|
194
|
-
|
195
|
-
action = rb_funcall( rb_eval_string( "Trema::
|
195
|
+
VALUE vlan_priority = UINT2NUM( action_vlan_pcp->vlan_pcp );
|
196
|
+
action = rb_funcall( rb_eval_string( "Trema::SetVlanPriority" ), rb_intern( "new" ), 1, vlan_priority );
|
196
197
|
}
|
197
198
|
break;
|
198
199
|
case OFPAT_STRIP_VLAN:
|
199
200
|
{
|
200
|
-
action = rb_funcall( rb_eval_string( "Trema::
|
201
|
+
action = rb_funcall( rb_eval_string( "Trema::StripVlanHeader" ), rb_intern( "new" ), 0 );
|
201
202
|
}
|
202
203
|
break;
|
203
204
|
case OFPAT_SET_DL_SRC:
|
204
205
|
case OFPAT_SET_DL_DST:
|
205
206
|
{
|
206
|
-
VALUE
|
207
|
+
VALUE mac_address;
|
207
208
|
const struct ofp_action_dl_addr *action_dl_addr = ( const struct ofp_action_dl_addr * ) ah;
|
208
209
|
|
209
|
-
|
210
|
+
mac_address = rb_funcall( rb_eval_string( "Trema::Mac" ), rb_intern( "new" ), 1, ULL2NUM( mac_to_uint64( action_dl_addr->dl_addr ) ) );
|
210
211
|
if ( ah->type == OFPAT_SET_DL_SRC ) {
|
211
|
-
|
212
|
-
action = rb_funcall( rb_eval_string( "Trema::ActionSetDlSrc" ), rb_intern( "new" ), 1, options );
|
212
|
+
action = rb_funcall( rb_eval_string( "Trema::SetEthSrcAddr" ), rb_intern( "new" ), 1, mac_address );
|
213
213
|
}
|
214
214
|
else {
|
215
|
-
|
216
|
-
action = rb_funcall( rb_eval_string( "Trema::ActionSetDlDst" ), rb_intern( "new" ), 1, options );
|
215
|
+
action = rb_funcall( rb_eval_string( "Trema::SetEthDstAddr" ), rb_intern( "new" ), 1, mac_address );
|
217
216
|
}
|
218
217
|
}
|
219
218
|
break;
|
220
219
|
case OFPAT_SET_NW_SRC:
|
221
220
|
case OFPAT_SET_NW_DST:
|
222
221
|
{
|
223
|
-
VALUE nw_addr;
|
224
222
|
const struct ofp_action_nw_addr *action_nw_addr = ( const struct ofp_action_nw_addr * ) ah;
|
225
223
|
|
226
|
-
|
224
|
+
VALUE ip_address = rb_funcall( rb_eval_string( "Trema::IP " ), rb_intern( "new" ), 1, UINT2NUM( action_nw_addr->nw_addr ) );
|
227
225
|
if ( ah->type == OFPAT_SET_NW_SRC ) {
|
228
|
-
|
229
|
-
action = rb_funcall( rb_eval_string( "Trema::ActionSetNwSrc" ), rb_intern( "new" ), 1, options );
|
226
|
+
action = rb_funcall( rb_eval_string( "Trema::SetIpSrcAddr" ), rb_intern( "new" ), 1, rb_funcall( ip_address, rb_intern( "to_s" ), 0 ) );
|
230
227
|
}
|
231
228
|
else {
|
232
|
-
|
233
|
-
action = rb_funcall( rb_eval_string( "Trema::ActionSetNwDst" ), rb_intern( "new" ), 1, options );
|
229
|
+
action = rb_funcall( rb_eval_string( "Trema::SetIpDstAddr" ), rb_intern( "new" ), 1, rb_funcall( ip_address, rb_intern( "to_s" ), 0 ) );
|
234
230
|
}
|
235
231
|
}
|
236
232
|
break;
|
@@ -238,40 +234,53 @@ get_action( const struct ofp_action_header *ah ) {
|
|
238
234
|
{
|
239
235
|
const struct ofp_action_nw_tos *action_nw_tos = ( const struct ofp_action_nw_tos * ) ah;
|
240
236
|
|
241
|
-
|
242
|
-
action = rb_funcall( rb_eval_string( "Trema::
|
237
|
+
VALUE type_of_service = ULL2NUM( action_nw_tos->nw_tos );
|
238
|
+
action = rb_funcall( rb_eval_string( "Trema::SetIpTos" ), rb_intern( "new" ), 1, type_of_service );
|
243
239
|
}
|
244
240
|
break;
|
245
241
|
case OFPAT_SET_TP_SRC:
|
246
242
|
{
|
247
243
|
const struct ofp_action_tp_port *action_tp_port = ( const struct ofp_action_tp_port * ) ah;
|
248
244
|
|
249
|
-
|
250
|
-
action = rb_funcall( rb_eval_string( "Trema::
|
245
|
+
VALUE port_number = ULL2NUM( action_tp_port->tp_port );
|
246
|
+
action = rb_funcall( rb_eval_string( "Trema::SetTransportSrcPort" ), rb_intern( "new" ), 1, port_number );
|
251
247
|
}
|
252
248
|
break;
|
253
249
|
case OFPAT_SET_TP_DST:
|
254
250
|
{
|
255
251
|
const struct ofp_action_tp_port *action_tp_port = ( const struct ofp_action_tp_port * ) ah;
|
256
252
|
|
257
|
-
|
258
|
-
action = rb_funcall( rb_eval_string( "Trema::
|
253
|
+
VALUE port_number = ULL2NUM( action_tp_port->tp_port );
|
254
|
+
action = rb_funcall( rb_eval_string( "Trema::SetTransportDstPort" ), rb_intern( "new" ), 1, port_number );
|
259
255
|
}
|
260
256
|
break;
|
261
257
|
case OFPAT_ENQUEUE:
|
262
258
|
{
|
263
259
|
const struct ofp_action_enqueue *action_enqueue = ( const struct ofp_action_enqueue * ) ah;
|
264
|
-
|
260
|
+
VALUE options = rb_hash_new();
|
261
|
+
rb_hash_aset( options, ID2SYM( rb_intern( "port_number" ) ), UINT2NUM( action_enqueue->port ) );
|
265
262
|
rb_hash_aset( options, ID2SYM( rb_intern( "queue_id" ) ), ULL2NUM( action_enqueue->queue_id ) );
|
266
|
-
action = rb_funcall( rb_eval_string( "Trema::
|
263
|
+
action = rb_funcall( rb_eval_string( "Trema::Enqueue" ), rb_intern( "new" ), 1, options );
|
267
264
|
}
|
268
265
|
break;
|
269
266
|
case OFPAT_VENDOR:
|
270
267
|
{
|
271
|
-
const struct ofp_action_vendor_header *
|
272
|
-
|
273
|
-
|
274
|
-
|
268
|
+
const struct ofp_action_vendor_header *vendor_header = ( const struct ofp_action_vendor_header * ) ah;
|
269
|
+
|
270
|
+
VALUE vendor_id = ULL2NUM( vendor_header->vendor );
|
271
|
+
if ( vendor_header->len > ( uint16_t ) sizeof( *vendor_header ) ) {
|
272
|
+
long length = ( long ) ( vendor_header->len - sizeof( *vendor_header ) );
|
273
|
+
VALUE data_array = rb_ary_new2( length );
|
274
|
+
const uint8_t *data = ( const uint8_t * ) ( ( const char * ) vendor_header + sizeof( *vendor_header ) );
|
275
|
+
long i;
|
276
|
+
for ( i = 0; i < length; i++ ) {
|
277
|
+
rb_ary_push( data_array, UINT2NUM( data[ i ] ) );
|
278
|
+
}
|
279
|
+
action = rb_funcall( rb_eval_string( "Trema::VendorAction" ), rb_intern( "new" ), 2, vendor_id, data_array );
|
280
|
+
}
|
281
|
+
else {
|
282
|
+
action = rb_funcall( rb_eval_string( "Trema::VendorAction" ), rb_intern( "new" ), 1, vendor_id );
|
283
|
+
}
|
275
284
|
}
|
276
285
|
break;
|
277
286
|
}
|
data/ruby/trema/version.rb
CHANGED
@@ -24,6 +24,7 @@ describe SendOutPort, ".new( 1 )" do
|
|
24
24
|
subject { SendOutPort.new( 1 ) }
|
25
25
|
its( :port_number ) { should == 1 }
|
26
26
|
its( :max_len ) { should == 2 ** 16 - 1 }
|
27
|
+
its( :to_s ) { should == "SendOutPort: port=1, max_len=65535" }
|
27
28
|
end
|
28
29
|
|
29
30
|
|
@@ -34,6 +35,7 @@ describe SendOutPort, ".new( :port_number => number )" do
|
|
34
35
|
context "when :port_number == 1" do
|
35
36
|
let( :port_number ) { 1 }
|
36
37
|
its( :port_number ) { should == 1 }
|
38
|
+
its( :to_s ) { should == "SendOutPort: port=1, max_len=65535" }
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
@@ -45,6 +47,7 @@ describe SendOutPort, ".new( :port_number => 1, :max_len => number )" do
|
|
45
47
|
context "when :max_len == 256" do
|
46
48
|
let( :max_len ) { 256 }
|
47
49
|
its( :max_len ) { should == 256 }
|
50
|
+
its( :to_s ) { should == "SendOutPort: port=1, max_len=256" }
|
48
51
|
end
|
49
52
|
end
|
50
53
|
|
@@ -23,12 +23,14 @@ require "trema"
|
|
23
23
|
describe SetEthDstAddr, %{.new( "52:54:00:a8:ad:8c" )} do
|
24
24
|
subject { SetEthDstAddr.new( "52:54:00:a8:ad:8c" ) }
|
25
25
|
its( :mac_address ) { should == Mac.new( "52:54:00:a8:ad:8c" ) }
|
26
|
+
its( :to_s ) { should == "SetEthDstAddr: mac_address=52:54:00:a8:ad:8c" }
|
26
27
|
end
|
27
28
|
|
28
29
|
|
29
30
|
describe SetEthDstAddr, %{.new( Mac.new( "52:54:00:a8:ad:8c" ) )} do
|
30
31
|
subject { SetEthDstAddr.new( Mac.new( "52:54:00:a8:ad:8c" ) )}
|
31
32
|
its( :mac_address ) { should == Mac.new( "52:54:00:a8:ad:8c" ) }
|
33
|
+
its( :to_s ) { should == "SetEthDstAddr: mac_address=52:54:00:a8:ad:8c" }
|
32
34
|
end
|
33
35
|
|
34
36
|
|
@@ -23,12 +23,14 @@ require "trema"
|
|
23
23
|
describe SetEthSrcAddr, %{.new( "52:54:00:a8:ad:8c" )} do
|
24
24
|
subject { SetEthSrcAddr.new( "52:54:00:a8:ad:8c" ) }
|
25
25
|
its( :mac_address ) { should == Mac.new( "52:54:00:a8:ad:8c" ) }
|
26
|
+
its( :to_s ) { should == "SetEthSrcAddr: mac_address=52:54:00:a8:ad:8c" }
|
26
27
|
end
|
27
28
|
|
28
29
|
|
29
30
|
describe SetEthSrcAddr, %{.new( Mac.new( "52:54:00:a8:ad:8c" ) )} do
|
30
31
|
subject { SetEthSrcAddr.new( Mac.new( "52:54:00:a8:ad:8c" ) )}
|
31
32
|
its( :mac_address ) { should == Mac.new( "52:54:00:a8:ad:8c" ) }
|
33
|
+
its( :to_s ) { should == "SetEthSrcAddr: mac_address=52:54:00:a8:ad:8c" }
|
32
34
|
end
|
33
35
|
|
34
36
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
This directory includes an OpenFlow controller that controls a single
|
2
|
+
OpenFlow switch and emulates a router.
|
3
|
+
|
4
|
+
# How to run
|
5
|
+
|
6
|
+
Run this
|
7
|
+
|
8
|
+
% sudo trema run ./src/examples/simple_router/simple-router.rb -c ./src/examples/simple_router/simple_router_netns.conf -d
|
9
|
+
|
10
|
+
and send packets like as follows.
|
11
|
+
|
12
|
+
% sudo ip netns exec host1 ping 192.168.2.2
|
13
|
+
|
14
|
+
Then check flow entries in OpenFlow switch.
|
15
|
+
|
16
|
+
% sudo trema dump_flows 0x1
|
17
|
+
|
18
|
+
This will display flow entries created by the controller.
|
@@ -37,7 +37,7 @@ class RoutingTable
|
|
37
37
|
dest = IPAddr.new( options[ :destination ] )
|
38
38
|
masklen = options[ :masklen ]
|
39
39
|
prefix = dest.mask( masklen )
|
40
|
-
@db[ masklen ][ prefix.to_i ] = IPAddr.new( options[ :
|
40
|
+
@db[ masklen ][ prefix.to_i ] = IPAddr.new( options[ :nexthop ] )
|
41
41
|
end
|
42
42
|
|
43
43
|
|
@@ -130,11 +130,11 @@ class SimpleRouter < Controller
|
|
130
130
|
|
131
131
|
|
132
132
|
def resolve_next_hop( daddr )
|
133
|
-
|
134
|
-
if
|
135
|
-
next_hop
|
136
|
-
else
|
133
|
+
interface = @interfaces.find_by_prefix( daddr.value )
|
134
|
+
if interface
|
137
135
|
daddr.value
|
136
|
+
else
|
137
|
+
@routing_table.lookup( daddr.value )
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
@@ -165,8 +165,8 @@ class SimpleRouter < Controller
|
|
165
165
|
|
166
166
|
def create_action_from( macsa, macda, port )
|
167
167
|
[
|
168
|
-
SetEthSrcAddr.new( macsa
|
169
|
-
SetEthDstAddr.new( macda
|
168
|
+
SetEthSrcAddr.new( macsa ),
|
169
|
+
SetEthDstAddr.new( macda ),
|
170
170
|
SendOutPort.new( port )
|
171
171
|
]
|
172
172
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Yasuhito Takamiya
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: .
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-01-
|
18
|
+
date: 2013-01-07 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
prerelease: false
|
@@ -466,6 +466,7 @@ files:
|
|
466
466
|
- src/examples/repeater_hub/repeater-hub_spec.rb
|
467
467
|
- src/examples/repeater_hub/repeater_hub.c
|
468
468
|
- src/examples/repeater_hub/repeater_hub.conf
|
469
|
+
- src/examples/simple_router/README
|
469
470
|
- src/examples/simple_router/arp-table.rb
|
470
471
|
- src/examples/simple_router/interface.rb
|
471
472
|
- src/examples/simple_router/router-utils.rb
|