tmf: Split "CTF adaptor" into separate plugins/feature
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.core / src / org / eclipse / linuxtools / lttng2 / kernel / core / event / matching / TcpEventMatching.java
CommitLineData
e73a4ba5 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal
e73a4ba5
GB
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
13package org.eclipse.linuxtools.lttng2.kernel.core.event.matching;
14
15import java.util.ArrayList;
16import java.util.List;
17
18import org.eclipse.linuxtools.internal.lttng2.kernel.core.TcpEventStrings;
e73a4ba5 19import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
b2b36236
GB
20import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
21import org.eclipse.linuxtools.tmf.core.event.matching.ITmfNetworkMatchDefinition;
e73a4ba5
GB
22import org.eclipse.linuxtools.tmf.core.event.matching.TmfEventMatching.MatchingType;
23import org.eclipse.linuxtools.tmf.core.event.matching.TmfNetworkEventMatching.Direction;
e73a4ba5 24import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
91e7f946 25import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
e73a4ba5
GB
26
27/**
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
32 *
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
35 *
36 * @author Geneviève Bastien
37 * @since 3.0
38 */
fa5993ff 39public class TcpEventMatching implements ITmfNetworkMatchDefinition {
e73a4ba5 40
b2b36236
GB
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)) {
46 return true;
47 }
48 return false;
49 }
50
e73a4ba5
GB
51 @Override
52 public Direction getDirection(ITmfEvent event) {
53 String evname = event.getType().getName();
b2b36236
GB
54
55 if (!canMatchPacket(event)) {
56 return null;
57 }
58
e73a4ba5
GB
59 /* Is the event a tcp socket in or out event */
60 if (evname.equals(TcpEventStrings.INET_SOCK_LOCAL_IN)) {
61 return Direction.IN;
62 } else if (evname.equals(TcpEventStrings.INET_SOCK_LOCAL_OUT)) {
63 return Direction.OUT;
64 }
65 return null;
66 }
67
68 /**
69 * The key to uniquely identify a TCP packet depends on many fields. This
70 * method computes the key for a given event.
71 *
72 * @param event
73 * The event for which to compute the key
74 * @return the unique key for this event
75 */
76 @Override
77 public List<Object> getUniqueField(ITmfEvent event) {
e0838ca1 78 List<Object> keys = new ArrayList<>();
e73a4ba5
GB
79
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());
83
84 return keys;
85 }
86
87 @Override
88 public boolean canMatchTrace(ITmfTrace trace) {
89 if (!(trace instanceof CtfTmfTrace)) {
90 return false;
91 }
92 CtfTmfTrace ktrace = (CtfTmfTrace) trace;
93 String[] events = { TcpEventStrings.INET_SOCK_LOCAL_IN, TcpEventStrings.INET_SOCK_LOCAL_OUT };
94 return ktrace.hasAtLeastOneOfEvents(events);
95 }
96
97 @Override
98 public MatchingType[] getApplicableMatchingTypes() {
99 MatchingType[] types = { MatchingType.NETWORK };
100 return types;
101 }
102
103}
This page took 0.036083 seconds and 5 git commands to generate.