9c35b41a0067716173e2dd1c26de576402d28ceb
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.core / src / org / eclipse / linuxtools / lttng2 / kernel / core / event / matching / TcpLttngEventMatching.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal
3 *
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
8 *
9 * Contributors:
10 * Geneviève Bastien - Initial implementation and API
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.lttng2.kernel.core.event.matching;
14
15 import java.util.ArrayList;
16 import java.util.List;
17 import java.util.Set;
18
19 import org.eclipse.linuxtools.internal.lttng2.kernel.core.TcpEventStrings;
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.ITmfNetworkMatchDefinition;
24 import org.eclipse.linuxtools.tmf.core.event.matching.TmfEventMatching.MatchingType;
25 import org.eclipse.linuxtools.tmf.core.event.matching.TmfNetworkEventMatching.Direction;
26 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
27 import org.eclipse.linuxtools.tmf.core.trace.TmfEventTypeCollectionHelper;
28 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
29
30 import com.google.common.collect.ImmutableSet;
31
32 /**
33 * Class to match tcp type events. This class applies to traces obtained with
34 * the full network tracepoint data available from an experimental branch of
35 * lttng-modules. This branch is often rebased on lttng-modules master and is
36 * available at
37 * http://git.dorsal.polymtl.ca/~gbastien?p=lttng-modules.git;a=summary
38 * net_data_experimental branch.
39 *
40 * @author Geneviève Bastien
41 * @since 3.0
42 */
43 public class TcpLttngEventMatching implements ITmfNetworkMatchDefinition {
44
45 private static final String[] key_seq = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.SEQ };
46 private static final String[] key_ackseq = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.ACKSEQ };
47 private static final String[] key_flags = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.FLAGS };
48
49 private static final ImmutableSet<String> REQUIRED_EVENTS = ImmutableSet.of(
50 TcpEventStrings.NET_DEV_QUEUE,
51 TcpEventStrings.NETIF_RECEIVE_SKB);
52
53 private static boolean canMatchPacket(final ITmfEvent event) {
54 TmfEventField field = (TmfEventField) event.getContent();
55
56 String[] tcp_data = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP };
57 ITmfEventField data = field.getSubField(tcp_data);
58 if (data != null) {
59 return (data.getValue() != null);
60 }
61 return false;
62 }
63
64 /**
65 * The key to uniquely identify a TCP packet depends on many fields. This
66 * method computes the key for a given event.
67 *
68 * @param event
69 * The event for which to compute the key
70 * @return the unique key for this event
71 */
72 @Override
73 public List<Object> getUniqueField(ITmfEvent event) {
74 List<Object> keys = new ArrayList<>();
75
76 TmfEventField field = (TmfEventField) event.getContent();
77 ITmfEventField data;
78
79 data = field.getSubField(key_seq);
80 if (data != null) {
81 keys.add(data.getValue());
82 }
83 data = field.getSubField(key_ackseq);
84 if (data != null) {
85 keys.add(data.getValue());
86 }
87 data = field.getSubField(key_flags);
88 if (data != null) {
89 keys.add(data.getValue());
90 }
91
92 return keys;
93 }
94
95 @Override
96 public boolean canMatchTrace(ITmfTrace trace) {
97 if (!(trace instanceof CtfTmfTrace)) {
98 return false;
99 }
100 CtfTmfTrace ktrace = (CtfTmfTrace) trace;
101
102 Set<String> traceEvents = TmfEventTypeCollectionHelper.getEventNames(ktrace.getContainedEventTypes());
103 traceEvents.retainAll(REQUIRED_EVENTS);
104 return !traceEvents.isEmpty();
105 }
106
107 @Override
108 public Direction getDirection(ITmfEvent event) {
109 String evname = event.getType().getName();
110
111 /* Is the event a tcp socket in or out event */
112 if (evname.equals(TcpEventStrings.NETIF_RECEIVE_SKB) && canMatchPacket(event)) {
113 return Direction.IN;
114 } else if (evname.equals(TcpEventStrings.NET_DEV_QUEUE) && canMatchPacket(event)) {
115 return Direction.OUT;
116 }
117 return null;
118 }
119
120 @Override
121 public MatchingType[] getApplicableMatchingTypes() {
122 MatchingType[] types = { MatchingType.NETWORK };
123 return types;
124 }
125
126 }
This page took 0.037386 seconds and 4 git commands to generate.