1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 École Polytechnique de Montréal
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
10 * Geneviève Bastien - Initial implementation and API
11 * Patrick Tasse - Remove getSubField
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.event
.matching
;
18 import org
.eclipse
.jdt
.annotation
.NonNull
;
19 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.TcpEventStrings
;
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
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.event
.matching
.IEventMatchingKey
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.event
.matching
.ITmfMatchEventDefinition
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.event
.matching
.TcpEventKey
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.event
.matching
.TmfEventMatching
.Direction
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTraceWithPreDefinedEvents
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfEventTypeCollectionHelper
;
31 import com
.google
.common
.collect
.ImmutableSet
;
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
38 * http://git.dorsal.polymtl.ca/~gbastien?p=lttng-modules.git;a=summary
39 * net_data_experimental branch.
41 * @author Geneviève Bastien
43 public class TcpLttngEventMatching
implements ITmfMatchEventDefinition
{
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
};
49 private static final ImmutableSet
<String
> REQUIRED_EVENTS
= ImmutableSet
.of(
50 TcpEventStrings
.NET_DEV_QUEUE
,
51 TcpEventStrings
.NETIF_RECEIVE_SKB
);
53 private static boolean canMatchPacket(final ITmfEvent event
) {
54 TmfEventField field
= (TmfEventField
) event
.getContent();
56 String
[] tcp_data
= { TcpEventStrings
.TRANSPORT_FIELDS
, TcpEventStrings
.TYPE_TCP
};
57 ITmfEventField data
= field
.getField(tcp_data
);
59 return (data
.getValue() != null);
65 public boolean canMatchTrace(ITmfTrace trace
) {
66 if (!(trace
instanceof ITmfTraceWithPreDefinedEvents
)) {
69 ITmfTraceWithPreDefinedEvents ktrace
= (ITmfTraceWithPreDefinedEvents
) trace
;
71 Set
<String
> traceEvents
= TmfEventTypeCollectionHelper
.getEventNames(ktrace
.getContainedEventTypes());
72 traceEvents
.retainAll(REQUIRED_EVENTS
);
73 return !traceEvents
.isEmpty();
80 public Direction
getDirection(ITmfEvent event
) {
81 String evname
= event
.getName();
83 /* Is the event a tcp socket in or out event */
84 if (evname
.equals(TcpEventStrings
.NETIF_RECEIVE_SKB
) && canMatchPacket(event
)) {
85 return Direction
.CAUSE
;
86 } else if (evname
.equals(TcpEventStrings
.NET_DEV_QUEUE
) && canMatchPacket(event
)) {
87 return Direction
.EFFECT
;
93 public IEventMatchingKey
getEventKey(ITmfEvent event
) {
94 TmfEventField field
= (TmfEventField
) event
.getContent();
97 long seq
= -1, ackseq
= -1, flags
= -1;
98 data
= field
.getField(KEY_SEQ
);
100 seq
= (long) data
.getValue();
104 data
= field
.getField(KEY_ACKSEQ
);
106 ackseq
= (long) data
.getValue();
110 data
= field
.getField(KEY_FLAGS
);
112 flags
= (long) data
.getValue();
117 IEventMatchingKey key
= new TcpEventKey(seq
, ackseq
, flags
);