DIY-pcap 0.0.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/pcap +62 -5
- data/bin/rpcap +62 -6
- data/lib/diy/builder.rb +14 -16
- data/lib/diy/controller.rb +50 -33
- data/lib/diy/device_finder.rb +26 -0
- data/lib/diy/dig.rb +7 -6
- data/lib/diy/logger.rb +7 -0
- data/lib/diy/offline.rb +98 -28
- data/lib/diy/packet.rb +17 -0
- data/lib/diy/pcap.rb +40 -17
- data/lib/diy/strategy_builder.rb +5 -12
- data/lib/diy/utils.rb +12 -0
- data/lib/diy/version.rb +5 -5
- data/lib/diy/worker.rb +49 -0
- data/lib/diy/worker_keeper.rb +25 -0
- data/simple/4000port.rb +20 -0
- data/simple/4000port/r1.dat +0 -0
- data/simple/4000port/r3.dat +0 -0
- data/simple/4000port/r4.dat +0 -0
- data/simple/4000port/r6.dat +0 -0
- data/simple/4000port/r7.dat +0 -0
- data/simple/4000port/s1.dat +0 -0
- data/simple/4000port/s2.dat +0 -0
- data/simple/4000port/s3.dat +0 -0
- data/simple/4000port/s4.dat +0 -0
- data/simple/4000port/s5.dat +0 -0
- data/simple/4000port/s6.dat +0 -0
- data/simple/4000port/s8.dat +0 -0
- data/simple/howto.vsd +0 -0
- data/spec/controller_spec.rb +36 -0
- data/spec/device_finder_spec.rb +16 -0
- data/spec/offline_spec.rb +26 -29
- data/spec/worker_spec.rb +58 -0
- metadata +24 -9
- data/lib/diy/queue.rb +0 -174
- data/lib/diy/recver.rb +0 -33
- data/lib/diy/sender.rb +0 -26
- data/spec/builder_spec.rb +0 -82
- data/spec/queue_spec.rb +0 -84
- data/spec/sender_spec.rb +0 -21
data/spec/queue_spec.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
describe DIY::Queue do
|
3
|
-
|
4
|
-
before(:each) do
|
5
|
-
@device_name = FFI::PCap.dump_devices[0][0]
|
6
|
-
@live = FFI::PCap::Live.new(:dev=>@device_name, :handler => FFI::PCap::Handler, :promisc => true)
|
7
|
-
@pcap_name = "../simple/pcaps/gre.pcap"
|
8
|
-
@offline = DIY::Offline.new(@pcap_name)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "#next_send_pkt" do
|
12
|
-
$SERVER = nil
|
13
|
-
q = DIY::Queue.new(@offline)
|
14
|
-
q.stub(:wait_until).and_return(true)
|
15
|
-
q.stub(:wait_for_seconds).and_return(nil)
|
16
|
-
q.next_send_pkt.should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt1' ) )
|
17
|
-
pkt1 = q.instance_variable_get("@expect_recv_queue")[0][0]
|
18
|
-
pkt2 = q.instance_variable_get("@expect_recv_queue")[1][0]
|
19
|
-
q.instance_variable_get("@expect_recv_queue").size.should == 2
|
20
|
-
pkt1.should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt2' ) )
|
21
|
-
pkt2.should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt3' ) )
|
22
|
-
q.instance_variable_set("@expect_recv_queue", [])
|
23
|
-
q.next_send_pkt.should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt4' ) )
|
24
|
-
q.instance_variable_get("@expect_recv_queue").should == []
|
25
|
-
lambda { loop { q.next_send_pkt } }.should raise_error
|
26
|
-
end
|
27
|
-
|
28
|
-
it "#next_send_pkt server" do
|
29
|
-
$SERVER = true
|
30
|
-
q = DIY::Queue.new(@offline)
|
31
|
-
q.stub(:wait_until).and_return(true)
|
32
|
-
q.stub(:wait_for_seconds).and_return(nil)
|
33
|
-
q.next_send_pkt.should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt2' ) )
|
34
|
-
q.instance_variable_get("@expect_recv_queue")[0][0].should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt1' ) )
|
35
|
-
q.instance_variable_set("@expect_recv_queue", [])
|
36
|
-
q.next_send_pkt.should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt3' ) )
|
37
|
-
q.instance_variable_get("@expect_recv_queue")[0][0].should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt4' ))
|
38
|
-
q.instance_variable_get("@expect_recv_queue")[1][0].should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt5' ))
|
39
|
-
$SERVER = nil
|
40
|
-
end
|
41
|
-
|
42
|
-
it "#comein? server" do
|
43
|
-
$SERVER = true
|
44
|
-
q = DIY::Queue.new(@offline)
|
45
|
-
q.stub(:wait_for_seconds).and_return(nil)
|
46
|
-
pkt = File.read( File.join( File.dirname(__FILE__), 'helper/pkt1' ) )
|
47
|
-
pkt2 = File.read( File.join( File.dirname(__FILE__), 'helper/pkt2' ) )
|
48
|
-
q.set_first_gout(pkt).should == pkt[6..11]
|
49
|
-
q.comein?(pkt).should == true
|
50
|
-
q.comein?(pkt2).should == false
|
51
|
-
$SERVER = nil
|
52
|
-
end
|
53
|
-
|
54
|
-
it "#peek #pop" do
|
55
|
-
q = DIY::Queue.new(@offline)
|
56
|
-
q.stub(:wait_until).and_return(true)
|
57
|
-
q.stub(:wait_for_seconds).and_return(nil)
|
58
|
-
q.next_send_pkt
|
59
|
-
q.peek.should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt2' ) )
|
60
|
-
q.pop.should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt2' ) )
|
61
|
-
q.peek.should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt3' ) )
|
62
|
-
q.pop
|
63
|
-
q.peek.should == nil
|
64
|
-
end
|
65
|
-
|
66
|
-
it "#delete" do
|
67
|
-
q = DIY::Queue.new(@offline)
|
68
|
-
q.stub(:wait_until).and_return(true)
|
69
|
-
q.stub(:wait_for_seconds).and_return(nil)
|
70
|
-
q.next_send_pkt
|
71
|
-
q.delete(File.read( File.join( File.dirname(__FILE__), 'helper/pkt2' ) )).should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt2' ) )
|
72
|
-
q.pop
|
73
|
-
q.peek.should == nil
|
74
|
-
end
|
75
|
-
|
76
|
-
it "#delete_at" do
|
77
|
-
q = DIY::Queue.new(@offline)
|
78
|
-
q.stub(:wait_until).and_return(true)
|
79
|
-
q.stub(:wait_for_seconds).and_return(nil)
|
80
|
-
q.next_send_pkt
|
81
|
-
q.delete_at(0).should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt2' ) )
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
data/spec/sender_spec.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe DIY::Sender do
|
4
|
-
|
5
|
-
class FakeLive
|
6
|
-
def inject
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
it "#before_send" do
|
11
|
-
live = double(FakeLive)
|
12
|
-
|
13
|
-
before_send_call = lambda { |pkt| pkt[0..2] = "111"; pkt }
|
14
|
-
pkt = "222222"
|
15
|
-
npkt = "111222"
|
16
|
-
live.should_receive(:inject).with(npkt).and_return(nil)
|
17
|
-
sender = DIY::Sender.new(live )
|
18
|
-
sender.before_send(&before_send_call)
|
19
|
-
lambda { sender.inject(pkt) }.should_not raise_error
|
20
|
-
end
|
21
|
-
end
|