1 /*******************************************************************************
2 * Copyright (c) 2013 É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
.TmfEventField
;
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
.event
.matching
.ITmfNetworkMatchDefinition
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
29 * Class to match tcp type events. This class applies to traces obtained with
30 * the full network tracepoint data available from an experimental branch of
31 * lttng-modules. This branch is often rebased on lttng-modules master and is
33 * http://git.dorsal.polymtl.ca/~gbastien?p=lttng-modules.git;a=summary
34 * net_data_experimental branch.
36 * @author Geneviève Bastien
39 public class TcpLttngEventMatching
implements ITmfNetworkMatchDefinition
{
41 private static final String
[] key_seq
= { TcpEventStrings
.TRANSPORT_FIELDS
, TcpEventStrings
.TYPE_TCP
, TcpEventStrings
.SEQ
};
42 private static final String
[] key_ackseq
= { TcpEventStrings
.TRANSPORT_FIELDS
, TcpEventStrings
.TYPE_TCP
, TcpEventStrings
.ACKSEQ
};
43 private static final String
[] key_flags
= { TcpEventStrings
.TRANSPORT_FIELDS
, TcpEventStrings
.TYPE_TCP
, TcpEventStrings
.FLAGS
};
45 private static boolean canMatchPacket(final ITmfEvent event
) {
46 TmfEventField field
= (TmfEventField
) event
.getContent();
48 String
[] tcp_data
= { TcpEventStrings
.TRANSPORT_FIELDS
, TcpEventStrings
.TYPE_TCP
};
49 ITmfEventField data
= field
.getSubField(tcp_data
);
51 return (data
.getValue() != null);
57 * The key to uniquely identify a TCP packet depends on many fields. This
58 * method computes the key for a given event.
61 * The event for which to compute the key
62 * @return the unique key for this event
65 public List
<Object
> getUniqueField(ITmfEvent event
) {
66 List
<Object
> keys
= new ArrayList
<Object
>();
68 TmfEventField field
= (TmfEventField
) event
.getContent();
71 data
= field
.getSubField(key_seq
);
73 keys
.add(data
.getValue());
75 data
= field
.getSubField(key_ackseq
);
77 keys
.add(data
.getValue());
79 data
= field
.getSubField(key_flags
);
81 keys
.add(data
.getValue());
88 public boolean canMatchTrace(ITmfTrace trace
) {
89 if (!(trace
instanceof CtfTmfTrace
)) {
92 CtfTmfTrace ktrace
= (CtfTmfTrace
) trace
;
93 String
[] events
= { TcpEventStrings
.NET_DEV_QUEUE
, TcpEventStrings
.NETIF_RECEIVE_SKB
};
94 return (ktrace
.hasAtLeastOneOfEvents(events
));
98 public Direction
getDirection(ITmfEvent event
) {
99 String evname
= event
.getType().getName();
101 /* Is the event a tcp socket in or out event */
102 if (evname
.equals(TcpEventStrings
.NETIF_RECEIVE_SKB
) && canMatchPacket(event
)) {
104 } else if (evname
.equals(TcpEventStrings
.NET_DEV_QUEUE
) && canMatchPacket(event
)) {
105 return Direction
.OUT
;
111 public MatchingType
[] getApplicableMatchingTypes() {
112 MatchingType
[] types
= { MatchingType
.NETWORK
};