blob: 208b7fbf32e899bd750b9ea88acf55114a862851 [file] [log] [blame]
Jian Lic7e20a52016-07-18 19:03:49 +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
18import java.util.Objects;
19
20import static com.google.common.base.MoreObjects.toStringHelper;
21
22/**
23 * Application data type LCAF address class.
24 *
25 * Application data type is defined in draft-ietf-lisp-lcaf-13
26 * https://tools.ietf.org/html/draft-ietf-lisp-lcaf-13#page-26
27 *
28 * 0 1 2 3
29 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
30 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31 * | AFI = 16387 | Rsvd1 | Flags |
32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 * | Type = 4 | Rsvd2 | 12 + n |
34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 * | IP TOS, IPv6 TC, or Flow Label | Protocol |
36 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 * | Local Port (lower-range) | Local Port (upper-range) |
38 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 * | Remote Port (lower-range) | Remote Port (upper-range) |
40 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 * | AFI = x | Address ... |
42 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 */
44public class LispAppDataLcafAddress extends LispLcafAddress {
45
46 private final byte protocol;
47 private final int ipTos;
48 private final short localPort;
49 private final short remotePort;
50 private LispAfiAddress address;
51
52 /**
53 * Initializes application data type LCAF address.
54 */
55 public LispAppDataLcafAddress() {
56 super(LispCanonicalAddressFormatEnum.APPLICATION_DATA);
57 this.protocol = 0;
58 this.ipTos = 0;
59 this.localPort = 0;
60 this.remotePort = 0;
61 }
62
63 /**
64 * Initializes application data type LCAF address.
65 *
66 * @param protocol protocol number
67 * @param ipTos ip type of service
68 * @param localPort local port number
69 * @param remotePort remote port number
70 * @param address address
71 */
72 public LispAppDataLcafAddress(byte protocol, int ipTos, short localPort, short remotePort,
73 LispAfiAddress address) {
74 super(LispCanonicalAddressFormatEnum.APPLICATION_DATA);
75 this.protocol = protocol;
76 this.ipTos = ipTos;
77 this.localPort = localPort;
78 this.remotePort = remotePort;
79 this.address = address;
80 }
81
82 /**
83 * Obtains protocol number.
84 *
85 * @return protocol number
86 */
87 public byte getProtocol() {
88 return protocol;
89 }
90
91 /**
92 * Obtains IP type of service.
93 *
94 * @return IP type of service
95 */
96 public int getIpTos() {
97 return ipTos;
98 }
99
100 /**
101 * Obtains local port number.
102 *
103 * @return local port number
104 */
105 public short getLocalPort() {
106 return localPort;
107 }
108
109 /**
110 * Obtains remote port number.
111 *
112 * @return remote port number
113 */
114 public short getRemotePort() {
115 return remotePort;
116 }
117
118 /**
119 * Obtains address.
120 *
121 * @return address
122 */
123 public LispAfiAddress getAddress() {
124 return address;
125 }
126
127 @Override
128 public int hashCode() {
Jian Lid56f97e2016-07-19 15:48:15 +0900129 return Objects.hash(address, protocol, ipTos, localPort, remotePort);
Jian Lic7e20a52016-07-18 19:03:49 +0900130 }
131
132 @Override
133 public boolean equals(Object obj) {
134 if (this == obj) {
135 return true;
136 }
137
138 if (obj instanceof LispAppDataLcafAddress) {
139 final LispAppDataLcafAddress other = (LispAppDataLcafAddress) obj;
140 return Objects.equals(this.address, other.address) &&
141 Objects.equals(this.protocol, other.protocol) &&
142 Objects.equals(this.ipTos, other.ipTos) &&
143 Objects.equals(this.localPort, other.localPort) &&
144 Objects.equals(this.remotePort, other.remotePort);
145 }
146 return false;
147 }
148
149 @Override
150 public String toString() {
151 return toStringHelper(this)
152 .add("address", address)
153 .add("protocol", protocol)
154 .add("ip type of service", ipTos)
155 .add("local port number", localPort)
156 .add("remote port number", remotePort)
157 .toString();
158 }
159}