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.ITmfEventField; | |
22 | import org.eclipse.linuxtools.tmf.core.event.TmfEventField; | |
23 | import org.eclipse.linuxtools.tmf.core.event.matching.TmfEventMatching.MatchingType; | |
24 | import org.eclipse.linuxtools.tmf.core.event.matching.TmfNetworkEventMatching.Direction; | |
fa5993ff | 25 | import org.eclipse.linuxtools.tmf.core.event.matching.ITmfNetworkMatchDefinition; |
e73a4ba5 GB |
26 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
27 | ||
28 | /** | |
29 | * Class to match tcp type events. This class applies to traces obtained with | |
30 | * the full network tracepoint data available from an experimental branch of | |
31 | * lttng-modules. This branch is often rebased on lttng-modules master and is | |
32 | * available at | |
33 | * http://git.dorsal.polymtl.ca/~gbastien?p=lttng-modules.git;a=summary | |
34 | * net_data_experimental branch. | |
35 | * | |
36 | * @author Geneviève Bastien | |
37 | * @since 3.0 | |
38 | */ | |
fa5993ff | 39 | public class TcpLttngEventMatching implements ITmfNetworkMatchDefinition { |
e73a4ba5 GB |
40 | |
41 | private static final String[] key_seq = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.SEQ }; | |
42 | private static final String[] key_ackseq = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.ACKSEQ }; | |
43 | private static final String[] key_flags = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.FLAGS }; | |
44 | ||
45 | private static boolean canMatchPacket(final ITmfEvent event) { | |
46 | TmfEventField field = (TmfEventField) event.getContent(); | |
47 | ||
48 | String[] tcp_data = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP }; | |
49 | ITmfEventField data = field.getSubField(tcp_data); | |
50 | if (data != null) { | |
51 | return (data.getValue() != null); | |
52 | } | |
53 | return false; | |
54 | } | |
55 | ||
56 | /** | |
57 | * The key to uniquely identify a TCP packet depends on many fields. This | |
58 | * method computes the key for a given event. | |
59 | * | |
60 | * @param event | |
61 | * The event for which to compute the key | |
62 | * @return the unique key for this event | |
63 | */ | |
64 | @Override | |
65 | public List<Object> getUniqueField(ITmfEvent event) { | |
e0838ca1 | 66 | List<Object> keys = new ArrayList<>(); |
e73a4ba5 GB |
67 | |
68 | TmfEventField field = (TmfEventField) event.getContent(); | |
69 | ITmfEventField data; | |
70 | ||
71 | data = field.getSubField(key_seq); | |
72 | if (data != null) { | |
73 | keys.add(data.getValue()); | |
74 | } | |
75 | data = field.getSubField(key_ackseq); | |
76 | if (data != null) { | |
77 | keys.add(data.getValue()); | |
78 | } | |
79 | data = field.getSubField(key_flags); | |
80 | if (data != null) { | |
81 | keys.add(data.getValue()); | |
82 | } | |
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.NET_DEV_QUEUE, TcpEventStrings.NETIF_RECEIVE_SKB }; | |
94 | return (ktrace.hasAtLeastOneOfEvents(events)); | |
95 | } | |
96 | ||
97 | @Override | |
98 | public Direction getDirection(ITmfEvent event) { | |
99 | String evname = event.getType().getName(); | |
100 | ||
101 | /* Is the event a tcp socket in or out event */ | |
102 | if (evname.equals(TcpEventStrings.NETIF_RECEIVE_SKB) && canMatchPacket(event)) { | |
103 | return Direction.IN; | |
104 | } else if (evname.equals(TcpEventStrings.NET_DEV_QUEUE) && canMatchPacket(event)) { | |
105 | return Direction.OUT; | |
106 | } | |
107 | return null; | |
108 | } | |
109 | ||
110 | @Override | |
111 | public MatchingType[] getApplicableMatchingTypes() { | |
112 | MatchingType[] types = { MatchingType.NETWORK }; | |
113 | return types; | |
114 | } | |
115 | ||
116 | } |