Commit | Line | Data |
---|---|---|
e73a4ba5 | 1 | /******************************************************************************* |
97de0bca | 2 | * Copyright (c) 2013, 2015 École Polytechnique de Montréal |
e73a4ba5 GB |
3 | * |
4 | * All rights reserved. This program and the accompanying materials are made | |
5 | * available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Geneviève Bastien - Initial implementation and API | |
97de0bca | 11 | * Patrick Tasse - Remove getSubField |
e73a4ba5 GB |
12 | *******************************************************************************/ |
13 | ||
dc327459 | 14 | package org.eclipse.tracecompass.internal.lttng2.kernel.core.event.matching; |
e73a4ba5 | 15 | |
409bea20 | 16 | import java.util.Set; |
e73a4ba5 | 17 | |
97de0bca | 18 | import org.eclipse.jdt.annotation.NonNull; |
9bc60be7 | 19 | import org.eclipse.tracecompass.internal.lttng2.kernel.core.TcpEventStrings; |
2bdf0193 AM |
20 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
21 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; | |
22 | import org.eclipse.tracecompass.tmf.core.event.TmfEventField; | |
f44be666 | 23 | import org.eclipse.tracecompass.tmf.core.event.matching.IEventMatchingKey; |
92bf3802 | 24 | import org.eclipse.tracecompass.tmf.core.event.matching.ITmfMatchEventDefinition; |
f44be666 | 25 | import org.eclipse.tracecompass.tmf.core.event.matching.TcpEventKey; |
92bf3802 | 26 | import org.eclipse.tracecompass.tmf.core.event.matching.TmfEventMatching.Direction; |
2bdf0193 | 27 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
dc327459 | 28 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceWithPreDefinedEvents; |
2bdf0193 | 29 | import org.eclipse.tracecompass.tmf.core.trace.TmfEventTypeCollectionHelper; |
e73a4ba5 | 30 | |
409bea20 GB |
31 | import com.google.common.collect.ImmutableSet; |
32 | ||
e73a4ba5 GB |
33 | /** |
34 | * Class to match tcp type events. This class applies to traces obtained with | |
35 | * the full network tracepoint data available from an experimental branch of | |
36 | * lttng-modules. This branch is often rebased on lttng-modules master and is | |
37 | * available at | |
38 | * http://git.dorsal.polymtl.ca/~gbastien?p=lttng-modules.git;a=summary | |
39 | * net_data_experimental branch. | |
40 | * | |
41 | * @author Geneviève Bastien | |
e73a4ba5 | 42 | */ |
92bf3802 | 43 | public class TcpLttngEventMatching implements ITmfMatchEventDefinition { |
e73a4ba5 | 44 | |
97de0bca PT |
45 | private static final @NonNull String[] KEY_SEQ = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.SEQ }; |
46 | private static final @NonNull String[] KEY_ACKSEQ = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.ACKSEQ }; | |
47 | private static final @NonNull String[] KEY_FLAGS = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.FLAGS }; | |
e73a4ba5 | 48 | |
409bea20 GB |
49 | private static final ImmutableSet<String> REQUIRED_EVENTS = ImmutableSet.of( |
50 | TcpEventStrings.NET_DEV_QUEUE, | |
51 | TcpEventStrings.NETIF_RECEIVE_SKB); | |
52 | ||
e73a4ba5 GB |
53 | private static boolean canMatchPacket(final ITmfEvent event) { |
54 | TmfEventField field = (TmfEventField) event.getContent(); | |
55 | ||
56 | String[] tcp_data = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP }; | |
97de0bca | 57 | ITmfEventField data = field.getField(tcp_data); |
e73a4ba5 GB |
58 | if (data != null) { |
59 | return (data.getValue() != null); | |
60 | } | |
61 | return false; | |
62 | } | |
63 | ||
e73a4ba5 GB |
64 | @Override |
65 | public boolean canMatchTrace(ITmfTrace trace) { | |
dc327459 GB |
66 | if (!(trace instanceof ITmfTraceWithPreDefinedEvents)) { |
67 | return true; | |
e73a4ba5 | 68 | } |
dc327459 | 69 | ITmfTraceWithPreDefinedEvents ktrace = (ITmfTraceWithPreDefinedEvents) trace; |
409bea20 GB |
70 | |
71 | Set<String> traceEvents = TmfEventTypeCollectionHelper.getEventNames(ktrace.getContainedEventTypes()); | |
72 | traceEvents.retainAll(REQUIRED_EVENTS); | |
73 | return !traceEvents.isEmpty(); | |
e73a4ba5 GB |
74 | } |
75 | ||
dbc7991d AM |
76 | /** |
77 | * @since 1.0 | |
78 | */ | |
e73a4ba5 GB |
79 | @Override |
80 | public Direction getDirection(ITmfEvent event) { | |
578716e6 | 81 | String evname = event.getName(); |
e73a4ba5 GB |
82 | |
83 | /* Is the event a tcp socket in or out event */ | |
84 | if (evname.equals(TcpEventStrings.NETIF_RECEIVE_SKB) && canMatchPacket(event)) { | |
92bf3802 | 85 | return Direction.CAUSE; |
e73a4ba5 | 86 | } else if (evname.equals(TcpEventStrings.NET_DEV_QUEUE) && canMatchPacket(event)) { |
92bf3802 | 87 | return Direction.EFFECT; |
e73a4ba5 GB |
88 | } |
89 | return null; | |
90 | } | |
91 | ||
f44be666 GB |
92 | @Override |
93 | public IEventMatchingKey getEventKey(ITmfEvent event) { | |
94 | TmfEventField field = (TmfEventField) event.getContent(); | |
95 | ITmfEventField data; | |
96 | ||
97 | long seq = -1, ackseq = -1, flags = -1; | |
97de0bca | 98 | data = field.getField(KEY_SEQ); |
f44be666 GB |
99 | if (data != null) { |
100 | seq = (long) data.getValue(); | |
101 | } else { | |
102 | return null; | |
103 | } | |
97de0bca | 104 | data = field.getField(KEY_ACKSEQ); |
f44be666 GB |
105 | if (data != null) { |
106 | ackseq = (long) data.getValue(); | |
107 | } else { | |
108 | return null; | |
109 | } | |
97de0bca | 110 | data = field.getField(KEY_FLAGS); |
f44be666 GB |
111 | if (data != null) { |
112 | flags = (long) data.getValue(); | |
113 | } else { | |
114 | return null; | |
115 | } | |
116 | ||
117 | IEventMatchingKey key = new TcpEventKey(seq, ackseq, flags); | |
118 | ||
119 | return key; | |
120 | } | |
121 | ||
e73a4ba5 | 122 | } |