blob: f3f3808468b57c312df7d93a418a17364c435e8a [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() {
129 final int prime = 31;
130 int result = super.hashCode();
131 result = prime * result + ((address == null) ? 0 : address.hashCode());
132 result = prime * result + protocol;
133 result = prime * result + ipTos;
134 result = prime * result + localPort;
135 result = prime * result + remotePort;
136 return result;
137 }
138
139 @Override
140 public boolean equals(Object obj) {
141 if (this == obj) {
142 return true;
143 }
144
145 if (obj instanceof LispAppDataLcafAddress) {
146 final LispAppDataLcafAddress other = (LispAppDataLcafAddress) obj;
147 return Objects.equals(this.address, other.address) &&
148 Objects.equals(this.protocol, other.protocol) &&
149 Objects.equals(this.ipTos, other.ipTos) &&
150 Objects.equals(this.localPort, other.localPort) &&
151 Objects.equals(this.remotePort, other.remotePort);
152 }
153 return false;
154 }
155
156 @Override
157 public String toString() {
158 return toStringHelper(this)
159 .add("address", address)
160 .add("protocol", protocol)
161 .add("ip type of service", ipTos)
162 .add("local port number", localPort)
163 .add("remote port number", remotePort)
164 .toString();
165 }
166}