packet_via_dmem 0.0.14 → 0.0.15

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: 8817b2bac1c9fe1cdf6a2f24c90508bfb5bddc54
4
- data.tar.gz: 092b207f0481c995223532662c21d37c001e42b1
3
+ metadata.gz: cf0a459e14095b84895caa6e51e0e091ea79e7e5
4
+ data.tar.gz: 36878c10f2139b87e7ddfc16f0e1d320eca7b071
5
5
  SHA512:
6
- metadata.gz: 79f503258a66b6e81d43fb2c5e0d2109172172fbb0cb6942d19d2ac250ea6c2f2e4a142f8b3bb156e6ea50ea68c0c1ce80a36ffd37fc03bbeed73bbc01025856
7
- data.tar.gz: a54c11bbc0021679f9dc45ca181cab80c99011bf6e1891e3aa1f9e9ac56ae923c84a1fea96f5ddbf1dd7ebc5af599fcd5468cda4c8b869fb32f47819d6840bd2
6
+ metadata.gz: a19d2c19db3f377685c02a2516d76294c35ca506c591e4a541e27eade78da36d6d52012ac522299d0c81cf46a8da15971affc03c8de674a27b08880d1200688e
7
+ data.tar.gz: 662664c85751129cb1b39b2317040994c0642b91dd7e82d24c480e6f5d32c244257e18b13e64d1623368c4dabbf20761782777c9d47acbff4be6f6dc40934060
data/README.md CHANGED
@@ -14,6 +14,21 @@ To capture say packets with IP address 10.11.12.13
14
14
  MX104-ABB-0(test2nqe31-re1.dk vty)# test jnh 0 packet-via-dmem dump
15
15
  MX104-ABB-0(test2nqe31-re1.dk vty)# test jnh 0 packet-via-dmem disable
16
16
 
17
+ * in capture the 0x3 sets flags for what type of packets we want, for 0x3 we
18
+ set two flags on, 'Packet' and 'PacketHead' (show mqchip N lo stats). These
19
+ two cover all real traffic.
20
+ 1. Packet (whole packet seen)
21
+ 2. PacketHead (334B packet, inclusive internal headers)
22
+
23
+ * after capture flags we can set up-to 8 bytes of data to match anywhere in
24
+ 32B window
25
+
26
+ * after match trigger we have optional 3rd argument which gives the byte
27
+ offset where our 32B window starts from, default to 0. If you're capturing
28
+ IPv6, the DADDR won't fit in the first 32B window, so you might give offest
29
+ of say 19B to get DADDR there too (in case of L2 MAC headers, without VLAN
30
+ or MPLS)
31
+
17
32
  ## Install
18
33
  % gem install packet_via_dmem
19
34
 
@@ -68,6 +83,11 @@ To capture say packets with IP address 10.11.12.13
68
83
  -h, --help
69
84
  %
70
85
 
86
+ You can also read from STDIN for live capture, some thing like this should work:
87
+
88
+ % sshfs nms: nms
89
+ % tail -fn 10000 nms/output.txt|packet-via-dmem -|text2pcap - -|wireshark -k -i -
90
+
71
91
  ## Library
72
92
  require 'packet_via_dmem'
73
93
  dmem = PacketViaDMEM.new
@@ -181,17 +201,7 @@ Example from MX80
181
201
  10 0b 00 f0 02 28 81 08
182
202
 
183
203
  ### Sent header
184
- I'm really not sure about sent headers, need more data to figure out what is
185
- our type. For all my examples, when we sent frame without L2 headers for
186
- fabric, it was MPLS, but almost certainly it can be IPv4, IPv6, ARP etc too.
187
- Need data to know which header tells that. So we are going to pop wrong amount
188
- of bytes in many sent cases.
189
-
190
- * first byte is output
191
- * 0x00 == to fabric
192
- * 0x08 == to wan
193
-
194
- * byte 6, 7, 9, 11 or 21 probably defines type (different if we sent layer2 to fabric or if we don't)
204
+ *FIXME* check the source...
195
205
 
196
206
  Example from MX960
197
207
 
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ Dir.glob('input-*.txt') do |file|
4
+ name, _ext = file.split '.'
5
+ _, name = name.split '-'
6
+ output = "pcap-#{name}.pcap"
7
+ system("/home/ytti/usr/git/pkt-via-dmem/bin/packet-via-dmem -b #{file}|text2pcap - #{output}")
8
+ end
@@ -9,23 +9,19 @@ class PacketViaDMEM
9
9
 
10
10
  def initialize
11
11
  @opts = opts_parse
12
+ @debug = @opts.debug?
12
13
  @log = Logger.new STDERR
13
- @log.level = Logger::INFO unless @opts.debug?
14
+ @log.level = Logger::INFO unless @debug
14
15
  end
15
16
 
16
17
  def run
17
- file = @opts.arguments.shift
18
- raise NoFile, 'filename is mandatory argument' unless file
19
- begin
20
- file = File.read(file)
21
- rescue
22
- raise InvalidFile, "unable to read #{file}"
23
- end
24
- packets = PacketViaDMEM.new(:received=>@opts.received?,
25
- :sent=>@opts.sent?,
26
- :log=>@log).parse file
18
+ file = get_file if not @opts.stdin?
19
+ dmem = PacketViaDMEM.new :received=>@opts.received?,
20
+ :sent=>@opts.sent?,
21
+ :log=>@log
22
+
27
23
  count = 0
28
- packets.each do |pkt|
24
+ block = Proc.new do |pkt|
29
25
  pop = false
30
26
  if pkt.type == :received
31
27
  next if @opts.sent?
@@ -41,12 +37,24 @@ class PacketViaDMEM
41
37
  $stderr.puts pkt.popped.join(' ') if @opts.popped?
42
38
  puts
43
39
  end
40
+ packets = @opts.stdin? ? dmem.stream($stdin, &block) : dmdm.parse(file).each(&block)
44
41
  end
45
42
 
46
43
  private
47
44
 
45
+ def get_file
46
+ file = @opts.arguments.shift
47
+ raise NoFile, 'filename is mandatory argument' unless file
48
+ begin
49
+ file = File.read(file)
50
+ rescue
51
+ raise InvalidFile, "unable to read #{file}"
52
+ end
53
+ end
54
+
48
55
  def opts_parse
49
56
  Slop.parse do |o|
57
+ o.bool '-', '--stdin', 'stream from STDIN'
50
58
  o.bool '--popped', 'print popped bytes to stderr'
51
59
  o.bool '-o', '--original', 'print original frames'
52
60
  o.bool '-r', '--received', 'print received frames only (DEFAULT)'
@@ -31,7 +31,7 @@ class Header
31
31
  str << (decrement_reference ? 'D' : 'd')
32
32
  str << (prequeue_priority ? 'P' : 'p')
33
33
  str << ' # '
34
- str << 'port: %x (%s) # ' % [port, port.divmod(64) ]
34
+ str << 'port: %x (%s) # ' % [port, port.divmod(64).join('/')]
35
35
  str << 'type: %x # ' % type
36
36
  str << 'QoS: %d@%d # ' % [queue_number, queue_system]
37
37
  str << "QueueDropOp: %d\n" % [queue_drop_opcode]
@@ -28,6 +28,20 @@ class PacketViaDMEM
28
28
  @sc = StringScanner.new ''
29
29
  end
30
30
 
31
+ def stream io
32
+ packet = ''
33
+ while not io.eof?
34
+ line = io.readline
35
+ if line.match PACKET
36
+ packet = parse(packet).first
37
+ yield packet if packet
38
+ packet = line
39
+ else
40
+ packet << line
41
+ end
42
+ end
43
+ end
44
+
31
45
  def parse str
32
46
  packets = Packets.new @log
33
47
  @sc.string = str
@@ -42,6 +56,7 @@ class PacketViaDMEM
42
56
  pkt = parse_packet pkt
43
57
  packets.add pkt, type
44
58
  end
59
+ @sc.string = ''
45
60
  packets
46
61
  end
47
62
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'packet_via_dmem'
3
- s.version = '0.0.14'
3
+ s.version = '0.0.15'
4
4
  s.licenses = %w( Apache-2.0 )
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = [ 'Saku Ytti' ]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packet_via_dmem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saku Ytti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-01 00:00:00.000000000 Z
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop
@@ -38,6 +38,7 @@ files:
38
38
  - README.md
39
39
  - Rakefile
40
40
  - bin/packet-via-dmem
41
+ - capture/do_pcaps.rb
41
42
  - capture/generate.rb
42
43
  - lib/packet_via_dmem.rb
43
44
  - lib/packet_via_dmem/cli.rb