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