TMF: Change some constant names to comply with a naming convention
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.kernel.core / src / org / eclipse / tracecompass / internal / 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.tracecompass.internal.lttng2.kernel.core.event.matching;
14
15 import java.util.Set;
16
17 import org.eclipse.tracecompass.internal.lttng2.kernel.core.TcpEventStrings;
18 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
19 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
20 import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
21 import org.eclipse.tracecompass.tmf.core.event.matching.IEventMatchingKey;
22 import org.eclipse.tracecompass.tmf.core.event.matching.ITmfNetworkMatchDefinition;
23 import org.eclipse.tracecompass.tmf.core.event.matching.TcpEventKey;
24 import org.eclipse.tracecompass.tmf.core.event.matching.TmfEventMatching.MatchingType;
25 import org.eclipse.tracecompass.tmf.core.event.matching.TmfNetworkEventMatching.Direction;
26 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
27 import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceWithPreDefinedEvents;
28 import org.eclipse.tracecompass.tmf.core.trace.TmfEventTypeCollectionHelper;
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 */
42 public class TcpLttngEventMatching implements ITmfNetworkMatchDefinition {
43
44 private static final String[] KEY_SEQ = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.SEQ };
45 private static final String[] KEY_ACKSEQ = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.ACKSEQ };
46 private static final String[] KEY_FLAGS = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.FLAGS };
47
48 private static final ImmutableSet<String> REQUIRED_EVENTS = ImmutableSet.of(
49 TcpEventStrings.NET_DEV_QUEUE,
50 TcpEventStrings.NETIF_RECEIVE_SKB);
51
52 private static boolean canMatchPacket(final ITmfEvent event) {
53 TmfEventField field = (TmfEventField) event.getContent();
54
55 String[] tcp_data = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP };
56 ITmfEventField data = field.getSubField(tcp_data);
57 if (data != null) {
58 return (data.getValue() != null);
59 }
60 return false;
61 }
62
63 @Override
64 public boolean canMatchTrace(ITmfTrace trace) {
65 if (!(trace instanceof ITmfTraceWithPreDefinedEvents)) {
66 return true;
67 }
68 ITmfTraceWithPreDefinedEvents ktrace = (ITmfTraceWithPreDefinedEvents) trace;
69
70 Set<String> traceEvents = TmfEventTypeCollectionHelper.getEventNames(ktrace.getContainedEventTypes());
71 traceEvents.retainAll(REQUIRED_EVENTS);
72 return !traceEvents.isEmpty();
73 }
74
75 @Override
76 public Direction getDirection(ITmfEvent event) {
77 String evname = event.getType().getName();
78
79 /* Is the event a tcp socket in or out event */
80 if (evname.equals(TcpEventStrings.NETIF_RECEIVE_SKB) && canMatchPacket(event)) {
81 return Direction.IN;
82 } else if (evname.equals(TcpEventStrings.NET_DEV_QUEUE) && canMatchPacket(event)) {
83 return Direction.OUT;
84 }
85 return null;
86 }
87
88 @Override
89 public MatchingType[] getApplicableMatchingTypes() {
90 MatchingType[] types = { MatchingType.NETWORK };
91 return types;
92 }
93
94 @Override
95 public IEventMatchingKey getEventKey(ITmfEvent event) {
96 TmfEventField field = (TmfEventField) event.getContent();
97 ITmfEventField data;
98
99 long seq = -1, ackseq = -1, flags = -1;
100 data = field.getSubField(KEY_SEQ);
101 if (data != null) {
102 seq = (long) data.getValue();
103 } else {
104 return null;
105 }
106 data = field.getSubField(KEY_ACKSEQ);
107 if (data != null) {
108 ackseq = (long) data.getValue();
109 } else {
110 return null;
111 }
112 data = field.getSubField(KEY_FLAGS);
113 if (data != null) {
114 flags = (long) data.getValue();
115 } else {
116 return null;
117 }
118
119 IEventMatchingKey key = new TcpEventKey(seq, ackseq, flags);
120
121 return key;
122 }
123
124 }
This page took 0.034617 seconds and 5 git commands to generate.