Commit | Line | Data |
---|---|---|
e73a4ba5 | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2013, 2014 É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 | |
11 | *******************************************************************************/ | |
12 | ||
dc327459 | 13 | package org.eclipse.tracecompass.internal.lttng2.kernel.core.event.matching; |
e73a4ba5 | 14 | |
409bea20 | 15 | import java.util.Set; |
e73a4ba5 | 16 | |
9bc60be7 | 17 | import org.eclipse.tracecompass.internal.lttng2.kernel.core.TcpEventStrings; |
2bdf0193 AM |
18 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
19 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; | |
20 | import org.eclipse.tracecompass.tmf.core.event.TmfEventField; | |
f44be666 | 21 | import org.eclipse.tracecompass.tmf.core.event.matching.IEventMatchingKey; |
2bdf0193 | 22 | import org.eclipse.tracecompass.tmf.core.event.matching.ITmfNetworkMatchDefinition; |
f44be666 | 23 | import org.eclipse.tracecompass.tmf.core.event.matching.TcpEventKey; |
2bdf0193 AM |
24 | import org.eclipse.tracecompass.tmf.core.event.matching.TmfEventMatching.MatchingType; |
25 | import org.eclipse.tracecompass.tmf.core.event.matching.TmfNetworkEventMatching.Direction; | |
26 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
dc327459 | 27 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceWithPreDefinedEvents; |
2bdf0193 | 28 | import org.eclipse.tracecompass.tmf.core.trace.TmfEventTypeCollectionHelper; |
e73a4ba5 | 29 | |
409bea20 GB |
30 | import com.google.common.collect.ImmutableSet; |
31 | ||
e73a4ba5 GB |
32 | /** |
33 | * Class to match tcp type events. This class applies to traces obtained with | |
34 | * the full network tracepoint data available from an experimental branch of | |
35 | * lttng-modules. This branch is often rebased on lttng-modules master and is | |
36 | * available at | |
37 | * http://git.dorsal.polymtl.ca/~gbastien?p=lttng-modules.git;a=summary | |
38 | * net_data_experimental branch. | |
39 | * | |
40 | * @author Geneviève Bastien | |
e73a4ba5 | 41 | */ |
fa5993ff | 42 | public class TcpLttngEventMatching implements ITmfNetworkMatchDefinition { |
e73a4ba5 | 43 | |
d20ae610 GB |
44 | private static final String[] KEY_SEQ = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.SEQ }; |
45 | private static final String[] KEY_ACKSEQ = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.ACKSEQ }; | |
46 | private static final String[] KEY_FLAGS = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.FLAGS }; | |
e73a4ba5 | 47 | |
409bea20 GB |
48 | private static final ImmutableSet<String> REQUIRED_EVENTS = ImmutableSet.of( |
49 | TcpEventStrings.NET_DEV_QUEUE, | |
50 | TcpEventStrings.NETIF_RECEIVE_SKB); | |
51 | ||
e73a4ba5 GB |
52 | private static boolean canMatchPacket(final ITmfEvent event) { |
53 | TmfEventField field = (TmfEventField) event.getContent(); | |
54 | ||
55 | String[] tcp_data = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP }; | |
56 | ITmfEventField data = field.getSubField(tcp_data); | |
57 | if (data != null) { | |
58 | return (data.getValue() != null); | |
59 | } | |
60 | return false; | |
61 | } | |
62 | ||
e73a4ba5 GB |
63 | @Override |
64 | public boolean canMatchTrace(ITmfTrace trace) { | |
dc327459 GB |
65 | if (!(trace instanceof ITmfTraceWithPreDefinedEvents)) { |
66 | return true; | |
e73a4ba5 | 67 | } |
dc327459 | 68 | ITmfTraceWithPreDefinedEvents ktrace = (ITmfTraceWithPreDefinedEvents) trace; |
409bea20 GB |
69 | |
70 | Set<String> traceEvents = TmfEventTypeCollectionHelper.getEventNames(ktrace.getContainedEventTypes()); | |
71 | traceEvents.retainAll(REQUIRED_EVENTS); | |
72 | return !traceEvents.isEmpty(); | |
e73a4ba5 GB |
73 | } |
74 | ||
75 | @Override | |
76 | public Direction getDirection(ITmfEvent event) { | |
77 | String evname = event.getType().getName(); | |
78 | ||
79 | /* Is the event a tcp socket in or out event */ | |
80 | if (evname.equals(TcpEventStrings.NETIF_RECEIVE_SKB) && canMatchPacket(event)) { | |
81 | return Direction.IN; | |
82 | } else if (evname.equals(TcpEventStrings.NET_DEV_QUEUE) && canMatchPacket(event)) { | |
83 | return Direction.OUT; | |
84 | } | |
85 | return null; | |
86 | } | |
87 | ||
88 | @Override | |
89 | public MatchingType[] getApplicableMatchingTypes() { | |
90 | MatchingType[] types = { MatchingType.NETWORK }; | |
91 | return types; | |
92 | } | |
93 | ||
f44be666 GB |
94 | @Override |
95 | public IEventMatchingKey getEventKey(ITmfEvent event) { | |
96 | TmfEventField field = (TmfEventField) event.getContent(); | |
97 | ITmfEventField data; | |
98 | ||
99 | long seq = -1, ackseq = -1, flags = -1; | |
d20ae610 | 100 | data = field.getSubField(KEY_SEQ); |
f44be666 GB |
101 | if (data != null) { |
102 | seq = (long) data.getValue(); | |
103 | } else { | |
104 | return null; | |
105 | } | |
d20ae610 | 106 | data = field.getSubField(KEY_ACKSEQ); |
f44be666 GB |
107 | if (data != null) { |
108 | ackseq = (long) data.getValue(); | |
109 | } else { | |
110 | return null; | |
111 | } | |
d20ae610 | 112 | data = field.getSubField(KEY_FLAGS); |
f44be666 GB |
113 | if (data != null) { |
114 | flags = (long) data.getValue(); | |
115 | } else { | |
116 | return null; | |
117 | } | |
118 | ||
119 | IEventMatchingKey key = new TcpEventKey(seq, ackseq, flags); | |
120 | ||
121 | return key; | |
122 | } | |
123 | ||
e73a4ba5 | 124 | } |