* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.openflowplugin.libraries.liblldp;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Arrays;
import java.util.Map;
import java.util.Map.Entry;
import org.slf4j.LoggerFactory;
/**
- * Abstract class which represents the generic network packet object It provides
+ * Abstract class which represents the generic network packet object. It provides
* the basic methods which are common for all the packets, like serialize and
* deserialize.
*/
public abstract class Packet {
- protected static final Logger LOG = LoggerFactory.getLogger(Packet.class);
+
+ private static final Logger LOG = LoggerFactory.getLogger(Packet.class);
+
// Access level granted to this packet
protected boolean writeAccess;
+
// When deserialized from wire, packet could result corrupted
protected boolean corrupted;
+
// The packet that encapsulate this packet
protected Packet parent;
+
// The packet encapsulated by this packet
protected Packet payload;
+
// The unparsed raw payload carried by this packet
protected byte[] rawPayload;
+
// Bit coordinates of packet header fields
protected Map<String, Pair<Integer, Integer>> hdrFieldCoordMap;
+
// Header fields values: Map<FieldName,Value>
protected Map<String, byte[]> hdrFieldsMap;
+
// The class of the encapsulated packet object
protected Class<? extends Packet> payloadClass;
startOffset = bitOffset + this.getfieldOffset(hdrField);
numBits = this.getfieldnumBits(hdrField);
- byte[] hdrFieldBytes = null;
+ byte[] hdrFieldBytes;
try {
hdrFieldBytes = BitBufferHelper.getBits(data, startOffset,
numBits);
postSerializeCustomOperation(packetBytes);
if (LOG.isTraceEnabled()) {
- LOG.trace("{}: {}", this.getClass().getSimpleName(),
+ LOG.trace("packet {}: {}", this.getClass().getSimpleName(),
HexEncode.bytesToHexString(packetBytes));
}
*
* @return The raw payload if not parsable as an array of bytes, null otherwise
*/
+ @SuppressFBWarnings("EI_EXPOSE_REP")
public byte[] getRawPayload() {
return rawPayload;
}
@Override
public boolean equals(final Object obj) {
+ if (obj == null) {
+ return false;
+ }
+
if (this == obj) {
return true;
}
if (hdrFieldsMap == null || other.hdrFieldsMap == null) {
return false;
}
- if (hdrFieldsMap != null && other.hdrFieldsMap != null) {
- for (String field : hdrFieldsMap.keySet()) {
- if (!Arrays.equals(hdrFieldsMap.get(field), other.hdrFieldsMap.get(field))) {
- return false;
- }
+ for (Entry<String, byte[]> entry : hdrFieldsMap.entrySet()) {
+ String field = entry.getKey();
+ if (!Arrays.equals(entry.getValue(), other.hdrFieldsMap.get(field))) {
+ return false;
}
- } else {
- return false;
}
return true;
}