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
.ethernet2
;
15 import java
.util
.Arrays
;
17 import org
.eclipse
.jdt
.annotation
.Nullable
;
18 import org
.eclipse
.tracecompass
.internal
.pcap
.core
.endpoint
.ProtocolEndpoint
;
19 import org
.eclipse
.tracecompass
.internal
.pcap
.core
.util
.ConversionHelper
;
22 * Class that extends the {@link ProtocolEndpoint} class. It represents the
23 * endpoint at an Ethernet II level.
25 * @author Vincent Perot
27 public class EthernetIIEndpoint
extends ProtocolEndpoint
{
29 private final byte[] fMacAddress
;
32 * Constructor of the {@link EthernetIIEndpoint} class. It takes a packet to
33 * get its endpoint. Since every packet has two endpoints (source and
34 * destination), the isSourceEndpoint parameter is used to specify which
38 * The packet that contains the endpoints.
39 * @param isSourceEndpoint
40 * Whether to take the source or the destination endpoint of the
43 public EthernetIIEndpoint(EthernetIIPacket packet
, boolean isSourceEndpoint
) {
44 super(packet
, isSourceEndpoint
);
45 fMacAddress
= isSourceEndpoint ? packet
.getSourceMacAddress() : packet
.getDestinationMacAddress();
49 public int hashCode() {
52 ProtocolEndpoint endpoint
= getParentEndpoint();
53 if (endpoint
== null) {
56 result
= endpoint
.hashCode();
58 result
= prime
* result
+ Arrays
.hashCode(fMacAddress
);
63 public boolean equals(@Nullable Object obj
) {
67 if (!(obj
instanceof EthernetIIEndpoint
)) {
71 EthernetIIEndpoint other
= (EthernetIIEndpoint
) obj
;
74 boolean localEquals
= Arrays
.equals(fMacAddress
, other
.fMacAddress
);
79 // Check above layers.
80 ProtocolEndpoint endpoint
= getParentEndpoint();
81 if (endpoint
!= null) {
82 return endpoint
.equals(other
.getParentEndpoint());
88 public String
toString() {
89 ProtocolEndpoint endpoint
= getParentEndpoint();
90 if (endpoint
== null) {
91 return ConversionHelper
.toMacAddress(fMacAddress
);
93 return (endpoint
.toString().equals(EMPTY_STRING
) ?
94 ConversionHelper
.toMacAddress(fMacAddress
) :
95 endpoint
.toString() + '/' + ConversionHelper
.toMacAddress(fMacAddress
));