Commit | Line | Data |
---|---|---|
e73a4ba5 GB |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 É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 | ||
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.matching.TmfEventMatching.MatchingType; | |
22 | import org.eclipse.linuxtools.tmf.core.event.matching.TmfNetworkEventMatching.Direction; | |
23 | import org.eclipse.linuxtools.tmf.core.event.matching.TmfNetworkMatchDefinition; | |
24 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
25 | ||
26 | /** | |
27 | * Class to match tcp type events. This matching class applies to traces | |
28 | * obtained with the 'addons' lttng module. This module can be obtained with | |
29 | * lttng-modules to generate traces at | |
30 | * https://github.com/giraldeau/lttng-modules/tree/addons | |
31 | * | |
32 | * Note: this module only allows to generate traces to be read and analyzed by | |
33 | * TMF, no code from this module is being used here | |
34 | * | |
35 | * @author Geneviève Bastien | |
36 | * @since 3.0 | |
37 | */ | |
38 | public class TcpEventMatching extends TmfNetworkMatchDefinition { | |
39 | ||
40 | @Override | |
41 | public Direction getDirection(ITmfEvent event) { | |
42 | String evname = event.getType().getName(); | |
43 | /* Is the event a tcp socket in or out event */ | |
44 | if (evname.equals(TcpEventStrings.INET_SOCK_LOCAL_IN)) { | |
45 | return Direction.IN; | |
46 | } else if (evname.equals(TcpEventStrings.INET_SOCK_LOCAL_OUT)) { | |
47 | return Direction.OUT; | |
48 | } | |
49 | return null; | |
50 | } | |
51 | ||
52 | /** | |
53 | * The key to uniquely identify a TCP packet depends on many fields. This | |
54 | * method computes the key for a given event. | |
55 | * | |
56 | * @param event | |
57 | * The event for which to compute the key | |
58 | * @return the unique key for this event | |
59 | */ | |
60 | @Override | |
61 | public List<Object> getUniqueField(ITmfEvent event) { | |
62 | List<Object> keys = new ArrayList<Object>(); | |
63 | ||
64 | keys.add(event.getContent().getField(TcpEventStrings.SEQ).getValue()); | |
65 | keys.add(event.getContent().getField(TcpEventStrings.ACKSEQ).getValue()); | |
66 | keys.add(event.getContent().getField(TcpEventStrings.FLAGS).getValue()); | |
67 | ||
68 | return keys; | |
69 | } | |
70 | ||
71 | @Override | |
72 | public boolean canMatchTrace(ITmfTrace trace) { | |
73 | if (!(trace instanceof CtfTmfTrace)) { | |
74 | return false; | |
75 | } | |
76 | CtfTmfTrace ktrace = (CtfTmfTrace) trace; | |
77 | String[] events = { TcpEventStrings.INET_SOCK_LOCAL_IN, TcpEventStrings.INET_SOCK_LOCAL_OUT }; | |
78 | return ktrace.hasAtLeastOneOfEvents(events); | |
79 | } | |
80 | ||
81 | @Override | |
82 | public MatchingType[] getApplicableMatchingTypes() { | |
83 | MatchingType[] types = { MatchingType.NETWORK }; | |
84 | return types; | |
85 | } | |
86 | ||
87 | } |