releng: Transition to jdt.annotation 2.0
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core / src / org / eclipse / tracecompass / internal / lttng2 / kernel / core / event / matching / TcpLttngEventMatching.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 É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 * Patrick Tasse - Remove getSubField
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.internal.lttng2.kernel.core.event.matching;
15
16 import java.util.Set;
17
18 import org.eclipse.jdt.annotation.NonNull;
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.TmfEventField;
23 import org.eclipse.tracecompass.tmf.core.event.matching.IEventMatchingKey;
24 import org.eclipse.tracecompass.tmf.core.event.matching.ITmfMatchEventDefinition;
25 import org.eclipse.tracecompass.tmf.core.event.matching.TcpEventKey;
26 import org.eclipse.tracecompass.tmf.core.event.matching.TmfEventMatching.Direction;
27 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
28 import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceWithPreDefinedEvents;
29 import org.eclipse.tracecompass.tmf.core.trace.TmfEventTypeCollectionHelper;
30
31 import com.google.common.collect.ImmutableSet;
32
33 /**
34 * Class to match tcp type events. This class applies to traces obtained with
35 * the full network tracepoint data available from an experimental branch of
36 * lttng-modules. This branch is often rebased on lttng-modules master and is
37 * available at
38 * http://git.dorsal.polymtl.ca/~gbastien?p=lttng-modules.git;a=summary
39 * net_data_experimental branch.
40 *
41 * @author Geneviève Bastien
42 */
43 public class TcpLttngEventMatching implements ITmfMatchEventDefinition {
44
45 private static final String @NonNull [] KEY_SEQ = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.SEQ };
46 private static final String @NonNull [] KEY_ACKSEQ = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.ACKSEQ };
47 private static final String @NonNull [] 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.getField(tcp_data);
58 if (data != null) {
59 return (data.getValue() != null);
60 }
61 return false;
62 }
63
64 @Override
65 public boolean canMatchTrace(ITmfTrace trace) {
66 if (!(trace instanceof ITmfTraceWithPreDefinedEvents)) {
67 return true;
68 }
69 ITmfTraceWithPreDefinedEvents ktrace = (ITmfTraceWithPreDefinedEvents) trace;
70
71 Set<String> traceEvents = TmfEventTypeCollectionHelper.getEventNames(ktrace.getContainedEventTypes());
72 traceEvents.retainAll(REQUIRED_EVENTS);
73 return !traceEvents.isEmpty();
74 }
75
76 /**
77 * @since 1.0
78 */
79 @Override
80 public Direction getDirection(ITmfEvent event) {
81 String evname = event.getName();
82
83 /* Is the event a tcp socket in or out event */
84 if (evname.equals(TcpEventStrings.NETIF_RECEIVE_SKB) && canMatchPacket(event)) {
85 return Direction.CAUSE;
86 } else if (evname.equals(TcpEventStrings.NET_DEV_QUEUE) && canMatchPacket(event)) {
87 return Direction.EFFECT;
88 }
89 return null;
90 }
91
92 @Override
93 public IEventMatchingKey getEventKey(ITmfEvent event) {
94 TmfEventField field = (TmfEventField) event.getContent();
95 ITmfEventField data;
96
97 long seq = -1, ackseq = -1, flags = -1;
98 data = field.getField(KEY_SEQ);
99 if (data != null) {
100 seq = (long) data.getValue();
101 } else {
102 return null;
103 }
104 data = field.getField(KEY_ACKSEQ);
105 if (data != null) {
106 ackseq = (long) data.getValue();
107 } else {
108 return null;
109 }
110 data = field.getField(KEY_FLAGS);
111 if (data != null) {
112 flags = (long) data.getValue();
113 } else {
114 return null;
115 }
116
117 IEventMatchingKey key = new TcpEventKey(seq, ackseq, flags);
118
119 return key;
120 }
121
122 }
This page took 0.054849 seconds and 5 git commands to generate.