Daniele Moro | 94660a0 | 2019-12-02 12:02:07 -0800 | [diff] [blame] | 1 | /* |
Joey Armstrong | 0964a2c | 2023-01-05 14:26:05 -0500 | [diff] [blame^] | 2 | * Copyright 2019-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Daniele Moro | 94660a0 | 2019-12-02 12:02:07 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.opencord.bng.packets; |
| 18 | |
| 19 | import com.google.common.base.Objects; |
| 20 | import org.onlab.packet.BasePacket; |
| 21 | |
| 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 23 | |
| 24 | /** |
| 25 | * Implements a generic PPP header. |
| 26 | */ |
| 27 | |
| 28 | public abstract class Ppp extends BasePacket { |
| 29 | |
| 30 | static final int MIN_HEADER_LENGTH = 4; |
| 31 | |
| 32 | byte code; |
| 33 | byte identifier; |
| 34 | short length; // Length includes the code, identifier, length and data fields |
| 35 | |
| 36 | /** |
| 37 | * Gets the LCP code. |
| 38 | * |
| 39 | * @return the LCP code |
| 40 | */ |
| 41 | public byte getCode() { |
| 42 | return code; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Sets the LCP code. |
| 47 | * |
| 48 | * @param code the LCP code to set |
| 49 | */ |
| 50 | public void setCode(byte code) { |
| 51 | this.code = code; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Gets the LCP identifier. |
| 56 | * |
| 57 | * @return the LCP identifier |
| 58 | */ |
| 59 | public byte getIdentifier() { |
| 60 | return identifier; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Sets the LCP identifier. |
| 65 | * |
| 66 | * @param identifier the LCP identifier to set |
| 67 | */ |
| 68 | public void setIdentifier(byte identifier) { |
| 69 | this.identifier = identifier; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Gets the length. |
| 74 | * |
| 75 | * @return the length |
| 76 | */ |
| 77 | public short getLength() { |
| 78 | return length; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Sets the length. |
| 83 | * |
| 84 | * @param length the length to set |
| 85 | */ |
| 86 | public void setLength(short length) { |
| 87 | this.length = length; |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public String toString() { |
| 92 | return toStringHelper(getClass()) |
| 93 | // .add("PPPType", pppProtocol) |
| 94 | .add("code", code) |
| 95 | .add("identifier", identifier) |
| 96 | .add("length", length) |
| 97 | .toString(); |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public int hashCode() { |
| 102 | return 31 * super.hashCode() + Objects.hashCode(code, identifier, length); |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public boolean equals(Object obj) { |
| 107 | if (this == obj) { |
| 108 | return true; |
| 109 | } |
| 110 | if (obj == null || getClass() != obj.getClass()) { |
| 111 | return false; |
| 112 | } |
| 113 | if (!super.equals(obj)) { |
| 114 | return false; |
| 115 | } |
| 116 | final Ppp other = (Ppp) obj; |
| 117 | return Objects.equal(this.code, other.code) |
| 118 | && Objects.equal(this.identifier, other.identifier) |
| 119 | && Objects.equal(this.length, other.length); |
| 120 | } |
| 121 | } |