btf: Move the plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.pcap.core / src / org / eclipse / tracecompass / internal / pcap / core / protocol / tcp / TCPEndpoint.java
CommitLineData
5255c030
VP
1/*******************************************************************************
2 * Copyright (c) 2014 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made 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 * Vincent Perot - Initial API and implementation
11 *******************************************************************************/
12
71f2817f 13package org.eclipse.tracecompass.internal.pcap.core.protocol.tcp;
5255c030 14
5db5a3a4
AM
15import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
16
5255c030 17import org.eclipse.jdt.annotation.Nullable;
71f2817f 18import org.eclipse.tracecompass.internal.pcap.core.endpoint.ProtocolEndpoint;
5255c030
VP
19
20/**
21 * Class that extends the {@link ProtocolEndpoint} class. It represents the
22 * endpoint at a TCP level.
23 *
24 * @author Vincent Perot
25 */
26public class TCPEndpoint extends ProtocolEndpoint {
27
28 private final int fPort;
29
30 /**
31 * Constructor of the {@link TCPEndpoint} class. It takes a packet to get
32 * its endpoint. Since every packet has two endpoints (source and
33 * destination), the isSourceEndpoint parameter is used to specify which
34 * endpoint to take.
35 *
36 * @param packet
37 * The packet that contains the endpoints.
38 * @param isSourceEndpoint
39 * Whether to take the source or the destination endpoint of the
40 * packet.
41 */
42 public TCPEndpoint(TCPPacket packet, boolean isSourceEndpoint) {
43 super(packet, isSourceEndpoint);
44 fPort = isSourceEndpoint ? packet.getSourcePort() : packet.getDestinationPort();
45 }
46
47 @Override
48 public int hashCode() {
49 final int prime = 31;
50 int result = 1;
51 ProtocolEndpoint endpoint = getParentEndpoint();
52 if (endpoint == null) {
53 result = 0;
54 } else {
55 result = endpoint.hashCode();
56 }
57 result = prime * result + fPort;
58 return result;
59 }
60
61 @Override
62 public boolean equals(@Nullable Object obj) {
63 if (this == obj) {
64 return true;
65 }
66 if (!(obj instanceof TCPEndpoint)) {
67 return false;
68 }
69
70 TCPEndpoint other = (TCPEndpoint) obj;
71
72 // Check on layer
73 boolean localEquals = (fPort == other.fPort);
74 if (!localEquals) {
75 return false;
76 }
77
78 // Check above layers.
79 ProtocolEndpoint endpoint = getParentEndpoint();
80 if (endpoint != null) {
81 return endpoint.equals(other.getParentEndpoint());
82 }
83 return true;
84 }
85
86 @Override
87 public String toString() {
88 ProtocolEndpoint endpoint = getParentEndpoint();
89 if (endpoint == null) {
5db5a3a4 90 return checkNotNull(String.valueOf(fPort));
5255c030
VP
91 }
92 return endpoint.toString() + '/' + fPort;
93 }
94
95}
This page took 0.04977 seconds and 5 git commands to generate.