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
.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
.TmfEventTypeCollectionHelper
;
27 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.CtfTmfTrace
;
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
43 public class TcpEventMatching
implements ITmfNetworkMatchDefinition
{
45 private static final ImmutableSet
<String
> REQUIRED_EVENTS
= ImmutableSet
.of(
46 TcpEventStrings
.INET_SOCK_LOCAL_IN
,
47 TcpEventStrings
.INET_SOCK_LOCAL_OUT
);
49 private static boolean canMatchPacket(final ITmfEvent event
) {
50 /* Make sure all required fields are present to match with this event */
51 ITmfEventField content
= event
.getContent();
52 if ((content
.getField(TcpEventStrings
.SEQ
) != null) &&
53 (content
.getField(TcpEventStrings
.ACKSEQ
) != null) && (content
.getField(TcpEventStrings
.FLAGS
) != null)) {
60 public Direction
getDirection(ITmfEvent event
) {
61 String evname
= event
.getType().getName();
63 if (!canMatchPacket(event
)) {
67 /* Is the event a tcp socket in or out event */
68 if (evname
.equals(TcpEventStrings
.INET_SOCK_LOCAL_IN
)) {
70 } else if (evname
.equals(TcpEventStrings
.INET_SOCK_LOCAL_OUT
)) {
77 * The key to uniquely identify a TCP packet depends on many fields. This
78 * method computes the key for a given event.
81 * The event for which to compute the key
82 * @return the unique key for this event
85 public List
<Object
> getUniqueField(ITmfEvent event
) {
86 List
<Object
> keys
= new ArrayList
<>();
88 keys
.add(event
.getContent().getField(TcpEventStrings
.SEQ
).getValue());
89 keys
.add(event
.getContent().getField(TcpEventStrings
.ACKSEQ
).getValue());
90 keys
.add(event
.getContent().getField(TcpEventStrings
.FLAGS
).getValue());
96 public boolean canMatchTrace(ITmfTrace trace
) {
97 if (!(trace
instanceof CtfTmfTrace
)) {
100 CtfTmfTrace ktrace
= (CtfTmfTrace
) trace
;
102 Set
<String
> traceEvents
= TmfEventTypeCollectionHelper
.getEventNames(ktrace
.getContainedEventTypes());
103 traceEvents
.retainAll(REQUIRED_EVENTS
);
104 return !traceEvents
.isEmpty();
108 public MatchingType
[] getApplicableMatchingTypes() {
109 MatchingType
[] types
= { MatchingType
.NETWORK
};