blob: 93ce78f233330f377c5fdc5146c543fcfbd38905 [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.
Jian Li8fc2d2f2016-08-08 14:43:53 +090024 * <p>
Jian Lic7e20a52016-07-18 19:03:49 +090025 * 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 *
Jian Li8fc2d2f2016-08-08 14:43:53 +090028 * <pre>
29 * {@literal
Jian Lic7e20a52016-07-18 19:03:49 +090030 * 0 1 2 3
31 * 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
32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 * | AFI = 16387 | Rsvd1 | Flags |
34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 * | Type = 4 | Rsvd2 | 12 + n |
36 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 * | IP TOS, IPv6 TC, or Flow Label | Protocol |
38 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 * | Local Port (lower-range) | Local Port (upper-range) |
40 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 * | Remote Port (lower-range) | Remote Port (upper-range) |
42 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 * | AFI = x | Address ... |
44 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Jian Li8fc2d2f2016-08-08 14:43:53 +090045 * }</pre>
Jian Lic7e20a52016-07-18 19:03:49 +090046 */
47public class LispAppDataLcafAddress extends LispLcafAddress {
48
49 private final byte protocol;
50 private final int ipTos;
51 private final short localPort;
52 private final short remotePort;
53 private LispAfiAddress address;
54
55 /**
56 * Initializes application data type LCAF address.
57 */
58 public LispAppDataLcafAddress() {
59 super(LispCanonicalAddressFormatEnum.APPLICATION_DATA);
60 this.protocol = 0;
61 this.ipTos = 0;
62 this.localPort = 0;
63 this.remotePort = 0;
64 }
65
66 /**
67 * Initializes application data type LCAF address.
68 *
69 * @param protocol protocol number
70 * @param ipTos ip type of service
71 * @param localPort local port number
72 * @param remotePort remote port number
73 * @param address address
74 */
75 public LispAppDataLcafAddress(byte protocol, int ipTos, short localPort, short remotePort,
76 LispAfiAddress address) {
77 super(LispCanonicalAddressFormatEnum.APPLICATION_DATA);
78 this.protocol = protocol;
79 this.ipTos = ipTos;
80 this.localPort = localPort;
81 this.remotePort = remotePort;
82 this.address = address;
83 }
84
85 /**
86 * Obtains protocol number.
87 *
88 * @return protocol number
89 */
90 public byte getProtocol() {
91 return protocol;
92 }
93
94 /**
95 * Obtains IP type of service.
96 *
97 * @return IP type of service
98 */
99 public int getIpTos() {
100 return ipTos;
101 }
102
103 /**
104 * Obtains local port number.
105 *
106 * @return local port number
107 */
108 public short getLocalPort() {
109 return localPort;
110 }
111
112 /**
113 * Obtains remote port number.
114 *
115 * @return remote port number
116 */
117 public short getRemotePort() {
118 return remotePort;
119 }
120
121 /**
122 * Obtains address.
123 *
124 * @return address
125 */
126 public LispAfiAddress getAddress() {
127 return address;
128 }
129
130 @Override
131 public int hashCode() {
Jian Lid56f97e2016-07-19 15:48:15 +0900132 return Objects.hash(address, protocol, ipTos, localPort, remotePort);
Jian Lic7e20a52016-07-18 19:03:49 +0900133 }
134
135 @Override
136 public boolean equals(Object obj) {
137 if (this == obj) {
138 return true;
139 }
140
141 if (obj instanceof LispAppDataLcafAddress) {
142 final LispAppDataLcafAddress other = (LispAppDataLcafAddress) obj;
143 return Objects.equals(this.address, other.address) &&
144 Objects.equals(this.protocol, other.protocol) &&
145 Objects.equals(this.ipTos, other.ipTos) &&
146 Objects.equals(this.localPort, other.localPort) &&
147 Objects.equals(this.remotePort, other.remotePort);
148 }
149 return false;
150 }
151
152 @Override
153 public String toString() {
154 return toStringHelper(this)
155 .add("address", address)
156 .add("protocol", protocol)
157 .add("ip type of service", ipTos)
158 .add("local port number", localPort)
159 .add("remote port number", remotePort)
160 .toString();
161 }
162}