Sha256: cff40911b31b20fde1807463aadd39e8959c6ebc35b4dbfc6d7d42d798f1d343

Contents?: true

Size: 1.37 KB

Versions: 6

Compression:

Stored size: 1.37 KB

Contents

#!/usr/bin/env ruby

require 'packet_via_dmem'

# takes 1 or more argument pointing to filename as 'input-something.txt'
# this input should be data gathered from juniper
# writes to output received-something.txt, sent-something.txt,
#  original-something.txt and header-something.txt
# This is used to generate files for testing

class PacketViaDMEM
  class CreateTestFiles
    def initialize
      @dmem = PacketViaDMEM.new
    end
    def run file
      name, ext = file.split '.'
      return unless ext == 'txt'
      direction, name  = name.split '-'
      return unless direction == 'input'
      headers, received, sent, originals = [], [], [], []
      @dmem.parse(File.read(file)).each do |packet|
        case packet.type
        when :received then received << packet.packet.join
        when :sent     then sent     << packet.packet.join
        else raise StandardError, "invalid type #{type}"
        end
        headers   << packet.header.to_s.split(/\n/).join('---')
        originals << packet.original.join
      end
      File.write('header-'   + name + '.txt', headers.join("\n"))
      File.write('sent-'     + name + '.txt', sent.join("\n"))
      File.write('received-' + name + '.txt', received.join("\n"))
      File.write('original-' + name + '.txt', originals.join("\n"))
    end
  end
end

runner = PacketViaDMEM::CreateTestFiles.new
ARGV.each do |arg|
  runner.run arg
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
packet_via_dmem-0.0.18 capture/generate.rb
packet_via_dmem-0.0.17 capture/generate.rb
packet_via_dmem-0.0.16 capture/generate.rb
packet_via_dmem-0.0.15 capture/generate.rb
packet_via_dmem-0.0.14 capture/generate.rb
packet_via_dmem-0.0.12 capture/generate.rb