blob: f7927152ac1f74187fb96512d1df85a3632a9c25 [file] [log] [blame]
Jian Li6b77dc02016-07-14 16:04:25 +09001/*
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 */
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
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 Li115d8602016-08-15 20:21:53 +090081
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 }
GUNiba871702016-08-22 21:06:02 +090092
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 Li6b77dc02016-07-14 16:04:25 +0900103}