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
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
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
.matching
.ITmfNetworkMatchDefinition
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.event
.matching
.TmfEventMatching
.MatchingType
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.event
.matching
.TmfNetworkEventMatching
.Direction
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTraceWithPreDefinedEvents
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfEventTypeCollectionHelper
;
29 import com
.google
.common
.collect
.ImmutableSet
;
32 * Class to match tcp type events. This matching class applies to traces
33 * obtained with the 'addons' lttng module. This module can be obtained with
34 * lttng-modules to generate traces at
35 * https://github.com/giraldeau/lttng-modules/tree/addons
37 * Note: this module only allows to generate traces to be read and analyzed by
38 * TMF, no code from this module is being used here
40 * @author Geneviève Bastien
42 public class TcpEventMatching
implements ITmfNetworkMatchDefinition
{
44 private static final ImmutableSet
<String
> REQUIRED_EVENTS
= ImmutableSet
.of(
45 TcpEventStrings
.INET_SOCK_LOCAL_IN
,
46 TcpEventStrings
.INET_SOCK_LOCAL_OUT
);
48 private static boolean canMatchPacket(final ITmfEvent event
) {
49 /* Make sure all required fields are present to match with this event */
50 ITmfEventField content
= event
.getContent();
51 if ((content
.getField(TcpEventStrings
.SEQ
) != null) &&
52 (content
.getField(TcpEventStrings
.ACKSEQ
) != null) && (content
.getField(TcpEventStrings
.FLAGS
) != null)) {
59 public Direction
getDirection(ITmfEvent event
) {
60 String evname
= event
.getType().getName();
62 if (!canMatchPacket(event
)) {
66 /* Is the event a tcp socket in or out event */
67 if (evname
.equals(TcpEventStrings
.INET_SOCK_LOCAL_IN
)) {
69 } else if (evname
.equals(TcpEventStrings
.INET_SOCK_LOCAL_OUT
)) {
76 * The key to uniquely identify a TCP packet depends on many fields. This
77 * method computes the key for a given event.
80 * The event for which to compute the key
81 * @return the unique key for this event
84 public List
<Object
> getUniqueField(ITmfEvent event
) {
85 List
<Object
> keys
= new ArrayList
<>();
87 keys
.add(event
.getContent().getField(TcpEventStrings
.SEQ
).getValue());
88 keys
.add(event
.getContent().getField(TcpEventStrings
.ACKSEQ
).getValue());
89 keys
.add(event
.getContent().getField(TcpEventStrings
.FLAGS
).getValue());
95 public boolean canMatchTrace(ITmfTrace trace
) {
96 if (!(trace
instanceof ITmfTraceWithPreDefinedEvents
)) {
99 ITmfTraceWithPreDefinedEvents ktrace
= (ITmfTraceWithPreDefinedEvents
) trace
;
101 Set
<String
> traceEvents
= TmfEventTypeCollectionHelper
.getEventNames(ktrace
.getContainedEventTypes());
102 traceEvents
.retainAll(REQUIRED_EVENTS
);
103 return !traceEvents
.isEmpty();
107 public MatchingType
[] getApplicableMatchingTypes() {
108 MatchingType
[] types
= { MatchingType
.NETWORK
};