Module: Mu::Scenario::Pcap::Rtp

Defined in:
lib/mu/scenario/pcap/rtp.rb

Constant Summary collapse

TRUNC_COUNT =
5

Class Method Summary collapse

Class Method Details

.preprocess(packets, fields_per_packet) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/mu/scenario/pcap/rtp.rb', line 12

def self.preprocess packets, fields_per_packet
    signaled_by = []
    prev_signal_frame = {}
    packets.each_with_index do |packet, idx|
        fields = fields_per_packet[idx]
        if fields and fields[:rtp]
            flow_id = packet.flow_id
            if frame = fields[:"rtp.setup-frame"]
                prev_signal_frame[flow_id] = frame
            else
                if frame = prev_signal_frame[flow_id]
                    fields[:"rtp.setup-frame"] = frame
                else
                    packets[idx] = nil
                    fields_per_packet[idx] = nil
                    next
               end
            end
            sig_idx = frame.to_i 
            signaled_by[idx] = sig_idx
        end
    end

    flow_to_count = Hash.new 0
    prev_setup_frame = {} 
    keep_frames = []
    packets.each_with_index do |packet, idx|
        if setup_frame = signaled_by[idx]
            flow = packet.flow_id
            count = flow_to_count[flow]
            if setup_frame != prev_setup_frame[flow]
                prev_setup_frame[flow] = setup_frame
                count = 1
            else
                count += 1 
            end
            if count <= TRUNC_COUNT
                keep_frames << idx + 1
            else
                packets[idx] = nil
                fields_per_packet[idx] = nil
            end
            flow_to_count[flow] = count
        end
    end

    packets.reject! {|p| not p }
    fields_per_packet.reject! {|p| not p }

    filter = "not rtp"
    keep_frames.each do |frame|
        filter << " or frame.number == #{frame}"
    end

    return filter
end