blob: 1e43c11ec09169d13ebcafbed0ad25285a35ae97 [file] [log] [blame]
Jian Li6b77dc02016-07-14 16:04:25 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Jian Li6b77dc02016-07-14 16:04:25 +09003 *
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 */
16package org.onosproject.lisp.msg.types;
17
Jian Li115d8602016-08-15 20:21:53 +090018import io.netty.buffer.ByteBuf;
19import org.onosproject.lisp.msg.exceptions.LispParseError;
20import org.onosproject.lisp.msg.exceptions.LispReaderException;
GUNiba871702016-08-22 21:06:02 +090021import org.onosproject.lisp.msg.exceptions.LispWriterException;
Jian Li115d8602016-08-15 20:21:53 +090022
Jian Lid56f97e2016-07-19 15:48:15 +090023import java.util.Objects;
24
Jian Li6b77dc02016-07-14 16:04:25 +090025/**
26 * The identifier of Autonomous System (AS).
27 */
28public 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 Lid56f97e2016-07-19 15:48:15 +090053 return Objects.hash(asNum);
Jian Li6b77dc02016-07-14 16:04:25 +090054 }
55
56 @Override
57 public boolean equals(Object obj) {
58 if (this == obj) {
59 return true;
60 }
61
Ray Milkeyfe6afd82018-11-26 14:03:20 -080062 if (obj == null || getClass() != obj.getClass()) {
Jian Li6b77dc02016-07-14 16:04:25 +090063 return false;
64 }
65
Ray Milkeyfe6afd82018-11-26 14:03:20 -080066 if (!super.equals(obj)) {
Jian Li6b77dc02016-07-14 16:04:25 +090067 return false;
68 }
69
70 LispAsAddress other = (LispAsAddress) obj;
Jian Lif25adf02017-05-23 14:54:24 +090071 return asNum == other.asNum;
Jian Li6b77dc02016-07-14 16:04:25 +090072 }
73
74 @Override
75 public String toString() {
76 return String.valueOf(asNum);
77 }
Jian Li115d8602016-08-15 20:21:53 +090078
79 /**
80 * Autonomous system address reader class.
81 */
82 public static class AsAddressReader implements LispAddressReader<LispAsAddress> {
83
84 @Override
85 public LispAsAddress readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException {
86 throw new LispReaderException("Unimplemented method");
87 }
88 }
GUNiba871702016-08-22 21:06:02 +090089
90 /**
91 * Autonomous system address writer class.
92 */
93 public static class AsAddressWriter implements LispAddressWriter<LispAsAddress> {
94
95 @Override
96 public void writeTo(ByteBuf byteBuf, LispAsAddress address) throws LispWriterException {
97 throw new LispWriterException("Unimplemented method");
98 }
99 }
Jian Li6b77dc02016-07-14 16:04:25 +0900100}