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
.linuxtools
.lttng2
.kernel
.core
.event
.matching
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.core
.TcpEventStrings
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.event
.matching
.ITmfNetworkMatchDefinition
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.matching
.TmfEventMatching
.MatchingType
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.event
.matching
.TmfNetworkEventMatching
.Direction
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
28 * Class to match tcp type events. This matching class applies to traces
29 * obtained with the 'addons' lttng module. This module can be obtained with
30 * lttng-modules to generate traces at
31 * https://github.com/giraldeau/lttng-modules/tree/addons
33 * Note: this module only allows to generate traces to be read and analyzed by
34 * TMF, no code from this module is being used here
36 * @author Geneviève Bastien
39 public class TcpEventMatching
implements ITmfNetworkMatchDefinition
{
41 private static boolean canMatchPacket(final ITmfEvent event
) {
42 /* Make sure all required fields are present to match with this event */
43 ITmfEventField content
= event
.getContent();
44 if ((content
.getField(TcpEventStrings
.SEQ
) != null) &&
45 (content
.getField(TcpEventStrings
.ACKSEQ
) != null) && (content
.getField(TcpEventStrings
.FLAGS
) != null)) {
52 public Direction
getDirection(ITmfEvent event
) {
53 String evname
= event
.getType().getName();
55 if (!canMatchPacket(event
)) {
59 /* Is the event a tcp socket in or out event */
60 if (evname
.equals(TcpEventStrings
.INET_SOCK_LOCAL_IN
)) {
62 } else if (evname
.equals(TcpEventStrings
.INET_SOCK_LOCAL_OUT
)) {
69 * The key to uniquely identify a TCP packet depends on many fields. This
70 * method computes the key for a given event.
73 * The event for which to compute the key
74 * @return the unique key for this event
77 public List
<Object
> getUniqueField(ITmfEvent event
) {
78 List
<Object
> keys
= new ArrayList
<>();
80 keys
.add(event
.getContent().getField(TcpEventStrings
.SEQ
).getValue());
81 keys
.add(event
.getContent().getField(TcpEventStrings
.ACKSEQ
).getValue());
82 keys
.add(event
.getContent().getField(TcpEventStrings
.FLAGS
).getValue());
88 public boolean canMatchTrace(ITmfTrace trace
) {
89 if (!(trace
instanceof CtfTmfTrace
)) {
92 CtfTmfTrace ktrace
= (CtfTmfTrace
) trace
;
93 String
[] events
= { TcpEventStrings
.INET_SOCK_LOCAL_IN
, TcpEventStrings
.INET_SOCK_LOCAL_OUT
};
94 return ktrace
.hasAtLeastOneOfEvents(events
);
98 public MatchingType
[] getApplicableMatchingTypes() {
99 MatchingType
[] types
= { MatchingType
.NETWORK
};