1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 É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 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.event
.matching
;
17 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.TcpEventStrings
;
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
.matching
.IEventMatchingKey
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.matching
.ITmfMatchEventDefinition
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.matching
.TcpEventKey
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.event
.matching
.TmfEventMatching
.Direction
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTraceWithPreDefinedEvents
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfEventTypeCollectionHelper
;
28 import com
.google
.common
.collect
.ImmutableSet
;
31 * Class to match tcp type events. This matching class applies to traces
32 * obtained with the 'addons' lttng module. This module can be obtained with
33 * lttng-modules to generate traces at
34 * https://github.com/giraldeau/lttng-modules/tree/addons
36 * Note: this module only allows to generate traces to be read and analyzed by
37 * TMF, no code from this module is being used here
39 * @author Geneviève Bastien
41 public class TcpEventMatching
implements ITmfMatchEventDefinition
{
43 private static final ImmutableSet
<String
> REQUIRED_EVENTS
= ImmutableSet
.of(
44 TcpEventStrings
.INET_SOCK_LOCAL_IN
,
45 TcpEventStrings
.INET_SOCK_LOCAL_OUT
);
47 private static boolean canMatchPacket(final ITmfEvent event
) {
48 /* Make sure all required fields are present to match with this event */
49 ITmfEventField content
= event
.getContent();
50 if ((content
.getField(TcpEventStrings
.SEQ
) != null) &&
51 (content
.getField(TcpEventStrings
.ACKSEQ
) != null) && (content
.getField(TcpEventStrings
.FLAGS
) != null)) {
61 public Direction
getDirection(ITmfEvent event
) {
62 String evname
= event
.getType().getName();
64 if (!canMatchPacket(event
)) {
68 /* Is the event a tcp socket in or out event */
69 if (evname
.equals(TcpEventStrings
.INET_SOCK_LOCAL_IN
)) {
70 return Direction
.CAUSE
;
71 } else if (evname
.equals(TcpEventStrings
.INET_SOCK_LOCAL_OUT
)) {
72 return Direction
.EFFECT
;
78 public IEventMatchingKey
getEventKey(ITmfEvent event
) {
79 IEventMatchingKey key
= new TcpEventKey((long) event
.getContent().getField(TcpEventStrings
.SEQ
).getValue(),
80 (long) event
.getContent().getField(TcpEventStrings
.ACKSEQ
).getValue(),
81 (long) event
.getContent().getField(TcpEventStrings
.FLAGS
).getValue());
86 public boolean canMatchTrace(ITmfTrace trace
) {
87 if (!(trace
instanceof ITmfTraceWithPreDefinedEvents
)) {
90 ITmfTraceWithPreDefinedEvents ktrace
= (ITmfTraceWithPreDefinedEvents
) trace
;
92 Set
<String
> traceEvents
= TmfEventTypeCollectionHelper
.getEventNames(ktrace
.getContainedEventTypes());
93 traceEvents
.retainAll(REQUIRED_EVENTS
);
94 return !traceEvents
.isEmpty();