Comments (2)
👍
from trema-edge.
@yasuhito I started porting the rspec into trema-edge but I found that the network{} block is a bit restrictive ( to be able to receive multiple events like switch_ready and/or packet_in or others ) so I am thinking about the following modifications but not really completely different from the original source:
Create a MockController class that accepts a network configuration block so when we set up all the conditions we can start the controller. Finally when we complete the test we stop the controller. An example is always better.
class MockController < Controller
def initialize network_blk
@network_blk = network_blk
@context = Trema::DSL::Parser.new.eval( &network_blk )
end
def start_receiving
if @network_blk.respond_to? :call
trema_run
else
raise ArgumentError, "Network configuration should be a proc block"
end
end
def stop_receiving
trema_kill
end
def time_sleep interval
sleep interval
yield
end
# nearly the same as before.
def trema_run
controller = self
if not controller.is_a?( Trema::Controller )
raise "#{ controller_class } is not a subclass of Trema::Controller"
end
Trema::DSL::Context.new( @context ).dump
app_name = controller.name
rule = { :port_status => app_name, :packet_in => app_name, :state_notify => app_name }
sm = SwitchManager.new( rule, @context.port )
sm.no_flow_cleanup = true
sm.run!
@context.links.each do | name, each |
each.add!
end
@context.hosts.each do | name, each |
each.run!
end
@context.trema_switches.each do | name, each |
each.run!
end
@context.links.each do | name, each |
each.up!
end
@context.hosts.each do | name, each |
each.add_arp_entry @context.hosts.values - [ each ]
end
@th_controller = Thread.start do
controller.run!
end
sleep 2 # FIXME: wait until controller.up?
end
def trema_kill
cleanup_current_session
@th_controller.join if @th_controller
sleep 2 # FIXME: wait until switch_manager.down?
end
end
An example to show its use.
describe Trema::ArpOp, ".new( VALID OPTIONS )" do
context "when setting a flow with a match field arp_op set to 1 and sending a ping packet" do
it "should have its arp_op set to 1 when #packet-in" do
network_blk = Proc.new {
trema_switch( "lsw" ) { datapath_id 0xabc }
vhost( "host1" ) {
ip "192.168.0.1"
netmask "255.255.255.0"
mac "00:00:00:00:00:01"
}
vhost( "host2" ) {
ip "192.168.0.2"
netmask "255.255.255.0"
mac "00:00:00:00:00:02"
}
link "host1", "lsw:1"
link "host2", "lsw:2"
}
mc = MockController.new( network_blk )
mc.should_receive( :switch_ready ) do | datapath_id |
action = SendOutPort.new( port_number: OFPP_CONTROLLER )
apply_ins = ApplyAction.new( actions: [ action ] )
match_fields = Match.new( in_port: 1, eth_type: 2054, arp_op: 1 )
mc.send_flow_mod_add( datapath_id,
cookie: 1111,
match: match_fields,
instructions: [ apply_ins ] )
end
mc.should_receive( :packet_in ).at_least( :once ) do | datapath_id, message |
action = Trema::ArpOp.new( arp_op: 1 )
expect( action.arp_op ).to eq( message.packet_info.arp_op )
end
mc.start_receiving
system( "ping -I trema1-0 -c 1 192.168.0.1" )
mc.time_sleep( 2 ) {
mc.stop_receiving
}
end
end
end
The above describes one way to verify ArpOp flexible action. If you have any comments please inform me. I am planning to use the above spec_helper.rb to start creating rspecs for some more complicated cases and see if it meets all the needs or not.
from trema-edge.
Related Issues (20)
- Dumper.rb の port_status メソッド が正しく動作しない HOT 1
- trema version コマンドの出力 HOT 2
- Multiple table usage error HOT 2
- make失敗およびlearning-switchの実行失敗 HOT 1
- FLOW_MODに使用するバイトオーダ HOT 1
- Trema::Match*_mask does not work HOT 6
- 生成したフレームをpacket_outのdata:として指定した際にエラーが出力される HOT 5
- ExactMatch.from is not fully implemented yet
- LoggerモジュールがSinatraと衝突して動かない HOT 1
- Trema::Controller::send_list_switches_request is not implemented yet
- send_flow_mod_delete
- Trema::Controller#switch_disconnected is not implemented
- Trema::Match#compare is not implemented
- FlowMultipartRequestがエラーになる HOT 2
- FlowMultipartRequestがエラーになる。 (Ipv4SrcAddr) HOT 1
- action buckets に複数の action を定義できない HOT 2
- OpenFLow 1.3.3 HOT 3
- Write-Action instruction does not allow to modify multiple header fields HOT 1
- TremaEdgeでPioが動作しない HOT 3
- trema-edge does not pass the unit tests
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from trema-edge.