1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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
10 * Vincent Perot - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.pcap
.core
.protocol
.ipv4
;
15 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
17 import java
.net
.Inet4Address
;
19 import org
.eclipse
.jdt
.annotation
.Nullable
;
20 import org
.eclipse
.tracecompass
.internal
.pcap
.core
.endpoint
.ProtocolEndpoint
;
23 * Class that extends the {@link ProtocolEndpoint} class. It represents the
24 * endpoint at an IPv4 level.
26 * @author Vincent Perot
28 public class IPv4Endpoint
extends ProtocolEndpoint
{
30 private final Inet4Address fIPAddress
;
33 * Constructor of the {@link IPv4Endpoint} class. It takes a packet to get
34 * its endpoint. Since every packet has two endpoints (source and
35 * destination), the isSourceEndpoint parameter is used to specify which
39 * The packet that contains the endpoints.
40 * @param isSourceEndpoint
41 * Whether to take the source or the destination endpoint of the
44 public IPv4Endpoint(IPv4Packet packet
, boolean isSourceEndpoint
) {
45 super(packet
, isSourceEndpoint
);
46 fIPAddress
= isSourceEndpoint ? packet
.getSourceIpAddress() : packet
.getDestinationIpAddress();
50 public int hashCode() {
54 ProtocolEndpoint endpoint
= getParentEndpoint();
55 if (endpoint
== null) {
58 result
= endpoint
.hashCode();
61 result
= prime
* result
+ fIPAddress
.hashCode();
66 public boolean equals(@Nullable Object obj
) {
70 if (!(obj
instanceof IPv4Endpoint
)) {
74 IPv4Endpoint other
= (IPv4Endpoint
) obj
;
77 boolean localEquals
= fIPAddress
.equals(other
.fIPAddress
);
82 // Check above layers.
83 ProtocolEndpoint endpoint
= getParentEndpoint();
84 if (endpoint
!= null) {
85 return endpoint
.equals(other
.getParentEndpoint());
91 public String
toString() {
92 ProtocolEndpoint endpoint
= getParentEndpoint();
93 if (endpoint
== null) {
94 return checkNotNull(fIPAddress
.getHostAddress());
96 return endpoint
.toString() + '/' + fIPAddress
.getHostAddress();