Jian Li | 6b77dc0 | 2016-07-14 16:04:25 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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 | package org.onosproject.lisp.msg.types; |
| 17 | |
Jian Li | 115d860 | 2016-08-15 20:21:53 +0900 | [diff] [blame] | 18 | import io.netty.buffer.ByteBuf; |
| 19 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
| 20 | import org.onosproject.lisp.msg.exceptions.LispReaderException; |
GUNi | ba87170 | 2016-08-22 21:06:02 +0900 | [diff] [blame] | 21 | import org.onosproject.lisp.msg.exceptions.LispWriterException; |
Jian Li | 115d860 | 2016-08-15 20:21:53 +0900 | [diff] [blame] | 22 | |
Jian Li | d56f97e | 2016-07-19 15:48:15 +0900 | [diff] [blame] | 23 | import java.util.Objects; |
| 24 | |
Jian Li | 6b77dc0 | 2016-07-14 16:04:25 +0900 | [diff] [blame] | 25 | /** |
| 26 | * The identifier of Autonomous System (AS). |
| 27 | */ |
| 28 | public class LispAsAddress extends LispAfiAddress { |
| 29 | |
| 30 | private final int asNum; |
| 31 | |
| 32 | /** |
| 33 | * Initializes AS identifier number. |
| 34 | * |
| 35 | * @param num AS number |
| 36 | */ |
| 37 | public LispAsAddress(int num) { |
| 38 | super(AddressFamilyIdentifierEnum.AS); |
| 39 | this.asNum = num; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Obtains AS identifier number. |
| 44 | * |
| 45 | * @return AS number |
| 46 | */ |
| 47 | public int getASNum() { |
| 48 | return asNum; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public int hashCode() { |
Jian Li | d56f97e | 2016-07-19 15:48:15 +0900 | [diff] [blame] | 53 | return Objects.hash(asNum); |
Jian Li | 6b77dc0 | 2016-07-14 16:04:25 +0900 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public boolean equals(Object obj) { |
| 58 | if (this == obj) { |
| 59 | return true; |
| 60 | } |
| 61 | |
| 62 | if (!super.equals(obj)) { |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | if (getClass() != obj.getClass()) { |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | LispAsAddress other = (LispAsAddress) obj; |
| 71 | if (asNum != other.asNum) { |
| 72 | return false; |
| 73 | } |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public String toString() { |
| 79 | return String.valueOf(asNum); |
| 80 | } |
Jian Li | 115d860 | 2016-08-15 20:21:53 +0900 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * Autonomous system address reader class. |
| 84 | */ |
| 85 | public static class AsAddressReader implements LispAddressReader<LispAsAddress> { |
| 86 | |
| 87 | @Override |
| 88 | public LispAsAddress readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { |
| 89 | throw new LispReaderException("Unimplemented method"); |
| 90 | } |
| 91 | } |
GUNi | ba87170 | 2016-08-22 21:06:02 +0900 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * Autonomous system address writer class. |
| 95 | */ |
| 96 | public static class AsAddressWriter implements LispAddressWriter<LispAsAddress> { |
| 97 | |
| 98 | @Override |
| 99 | public void writeTo(ByteBuf byteBuf, LispAsAddress address) throws LispWriterException { |
| 100 | throw new LispWriterException("Unimplemented method"); |
| 101 | } |
| 102 | } |
Jian Li | 6b77dc0 | 2016-07-14 16:04:25 +0900 | [diff] [blame] | 103 | } |