blob: 57732ca78ba19976fb9fa185b920c3d8d389ccd5 [file] [log] [blame]
Jian Li451175e2016-07-19 23:22:20 +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.protocols;
17
Jian Li20850d32016-08-04 02:15:57 +090018import com.google.common.base.Objects;
Jian Lif59c0ad2016-08-02 18:11:30 +090019import com.google.common.collect.ImmutableList;
20import com.google.common.collect.Lists;
Jian Li451175e2016-07-19 23:22:20 +090021import io.netty.buffer.ByteBuf;
Jian Li719b3bf2016-07-22 00:38:29 +090022import org.onosproject.lisp.msg.types.LispAfiAddress;
23
24import java.util.List;
Jian Li451175e2016-07-19 23:22:20 +090025
Jian Li20850d32016-08-04 02:15:57 +090026import static com.google.common.base.MoreObjects.toStringHelper;
27
Jian Li451175e2016-07-19 23:22:20 +090028/**
29 * Default LISP map request message class.
30 */
Jian Lif59c0ad2016-08-02 18:11:30 +090031public final class DefaultLispMapRequest implements LispMapRequest {
32
33 private final long nonce;
34 private final byte recordCount;
35 private final LispAfiAddress sourceEid;
36 private final List<LispAfiAddress> itrRlocs;
37 private final List<LispEidRecord> eidRecords;
38 private final boolean authoritative;
39 private final boolean mapDataPresent;
40 private final boolean probe;
41 private final boolean smr;
42 private final boolean pitr;
43 private final boolean smrInvoked;
44
45 /**
46 * A private constructor that protects object instantiation from external.
47 *
48 * @param nonce nonce
49 * @param recordCount record count number
50 * @param sourceEid source EID address
51 * @param itrRlocs a collection of ITR RLOCs
52 * @param eidRecords a collection of EID records
53 * @param authoritative authoritative flag
54 * @param mapDataPresent map data present flag
55 * @param probe probe flag
56 * @param smr smr flag
57 * @param pitr pitr flag
58 * @param smrInvoked smrInvoked flag
59 */
60 private DefaultLispMapRequest(long nonce, byte recordCount, LispAfiAddress sourceEid,
61 List<LispAfiAddress> itrRlocs, List<LispEidRecord> eidRecords,
62 boolean authoritative, boolean mapDataPresent, boolean probe,
63 boolean smr, boolean pitr, boolean smrInvoked) {
64 this.nonce = nonce;
65 this.recordCount = recordCount;
66 this.sourceEid = sourceEid;
67 this.itrRlocs = itrRlocs;
68 this.eidRecords = eidRecords;
69 this.authoritative = authoritative;
70 this.mapDataPresent = mapDataPresent;
71 this.probe = probe;
72 this.smr = smr;
73 this.pitr = pitr;
74 this.smrInvoked = smrInvoked;
75 }
76
Jian Li451175e2016-07-19 23:22:20 +090077 @Override
78 public LispType getType() {
Jian Lif59c0ad2016-08-02 18:11:30 +090079 return LispType.LISP_MAP_REQUEST;
Jian Li451175e2016-07-19 23:22:20 +090080 }
81
82 @Override
83 public void writeTo(ByteBuf byteBuf) {
Jian Lif59c0ad2016-08-02 18:11:30 +090084 // TODO: serialize LispMapRequest message
Jian Li451175e2016-07-19 23:22:20 +090085 }
86
87 @Override
88 public Builder createBuilder() {
Jian Li525fded2016-08-04 01:15:33 +090089 return new DefaultRequestBuilder();
Jian Li451175e2016-07-19 23:22:20 +090090 }
Jian Li719b3bf2016-07-22 00:38:29 +090091
92 @Override
93 public boolean isAuthoritative() {
Jian Lif59c0ad2016-08-02 18:11:30 +090094 return this.authoritative;
95 }
96
97 @Override
98 public boolean isMapDataPresent() {
99 return this.mapDataPresent;
Jian Li719b3bf2016-07-22 00:38:29 +0900100 }
101
102 @Override
103 public boolean isProbe() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900104 return this.probe;
Jian Li719b3bf2016-07-22 00:38:29 +0900105 }
106
107 @Override
108 public boolean isSmr() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900109 return this.smr;
Jian Li719b3bf2016-07-22 00:38:29 +0900110 }
111
112 @Override
113 public boolean isPitr() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900114 return this.pitr;
Jian Li719b3bf2016-07-22 00:38:29 +0900115 }
116
117 @Override
118 public boolean isSmrInvoked() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900119 return this.smrInvoked;
Jian Li719b3bf2016-07-22 00:38:29 +0900120 }
121
122 @Override
123 public byte getRecordCount() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900124 return this.recordCount;
Jian Li719b3bf2016-07-22 00:38:29 +0900125 }
126
127 @Override
128 public long getNonce() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900129 return this.nonce;
Jian Li719b3bf2016-07-22 00:38:29 +0900130 }
131
132 @Override
133 public LispAfiAddress getSourceEid() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900134 return this.sourceEid;
Jian Li719b3bf2016-07-22 00:38:29 +0900135 }
136
137 @Override
138 public List<LispAfiAddress> getItrRlocs() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900139 return ImmutableList.copyOf(itrRlocs);
Jian Li719b3bf2016-07-22 00:38:29 +0900140 }
141
142 @Override
Jian Li10a09062016-07-26 23:58:50 +0900143 public List<LispEidRecord> getEids() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900144 return ImmutableList.copyOf(eidRecords);
Jian Li719b3bf2016-07-22 00:38:29 +0900145 }
146
Jian Li20850d32016-08-04 02:15:57 +0900147 @Override
148 public String toString() {
149 return toStringHelper(this)
150 .add("type", getType())
151 .add("nonce", nonce)
152 .add("recordCount", recordCount)
153 .add("source EID", sourceEid)
154 .add("ITR rlocs", itrRlocs)
155 .add("EID records", eidRecords)
156 .add("authoritative", authoritative)
157 .add("mapDataPresent", mapDataPresent)
158 .add("probe", probe)
159 .add("SMR", smr)
160 .add("Proxy ITR", pitr)
161 .add("SMR Invoked", smrInvoked).toString();
162 }
163
164 @Override
165 public boolean equals(Object o) {
166 if (this == o) {
167 return true;
168 }
169 if (o == null || getClass() != o.getClass()) {
170 return false;
171 }
172 DefaultLispMapRequest that = (DefaultLispMapRequest) o;
173 return Objects.equal(nonce, that.nonce) &&
174 Objects.equal(recordCount, that.recordCount) &&
175 Objects.equal(sourceEid, that.sourceEid) &&
176 Objects.equal(itrRlocs, that.itrRlocs) &&
177 Objects.equal(eidRecords, that.eidRecords) &&
178 Objects.equal(authoritative, that.authoritative) &&
179 Objects.equal(mapDataPresent, that.mapDataPresent) &&
180 Objects.equal(probe, that.probe) &&
181 Objects.equal(smr, that.smr) &&
182 Objects.equal(pitr, that.pitr) &&
183 Objects.equal(smrInvoked, that.smrInvoked);
184 }
185
186 @Override
187 public int hashCode() {
188 return Objects.hashCode(nonce, recordCount, sourceEid, itrRlocs, eidRecords,
189 authoritative, mapDataPresent, probe, smr, pitr, smrInvoked);
190 }
191
Jian Li719b3bf2016-07-22 00:38:29 +0900192 public static final class DefaultRequestBuilder implements RequestBuilder {
193
Jian Lif59c0ad2016-08-02 18:11:30 +0900194 private long nonce;
195 private byte recordCount;
196 private LispAfiAddress sourceEid;
197 private List<LispAfiAddress> itrRlocs = Lists.newArrayList();
198 private List<LispEidRecord> eidRecords = Lists.newArrayList();
199 private boolean authoritative;
200 private boolean mapDataPresent;
201 private boolean probe;
202 private boolean smr;
203 private boolean pitr;
204 private boolean smrInvoked;
Jian Li719b3bf2016-07-22 00:38:29 +0900205
206 @Override
207 public LispType getType() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900208 return LispType.LISP_MAP_REQUEST;
Jian Li719b3bf2016-07-22 00:38:29 +0900209 }
210
211 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900212 public RequestBuilder withIsAuthoritative(boolean authoritative) {
213 this.authoritative = authoritative;
214 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900215 }
216
217 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900218 public RequestBuilder withIsProbe(boolean probe) {
219 this.probe = probe;
220 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900221 }
222
223 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900224 public RequestBuilder withIsMapDataPresent(boolean mapDataPresent) {
225 this.mapDataPresent = mapDataPresent;
226 return this;
227 }
228
229
230 @Override
231 public RequestBuilder withIsSmr(boolean smr) {
232 this.smr = smr;
233 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900234 }
235
236 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900237 public RequestBuilder withIsPitr(boolean pitr) {
238 this.pitr = pitr;
239 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900240 }
241
242 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900243 public RequestBuilder withIsSmrInvoked(boolean smrInvoked) {
244 this.smrInvoked = smrInvoked;
245 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900246 }
247
248 @Override
249 public RequestBuilder withRecordCount(byte recordCount) {
Jian Lif59c0ad2016-08-02 18:11:30 +0900250 this.recordCount = recordCount;
251 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900252 }
253
254 @Override
255 public RequestBuilder withNonce(long nonce) {
Jian Lif59c0ad2016-08-02 18:11:30 +0900256 this.nonce = nonce;
257 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900258 }
259
260 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900261 public RequestBuilder withSourceEid(LispAfiAddress sourceEid) {
262 this.sourceEid = sourceEid;
263 return this;
264 }
265
266 @Override
267 public RequestBuilder addItrRloc(LispAfiAddress itrRloc) {
268 this.itrRlocs.add(itrRloc);
269 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900270 }
271
272 @Override
Jian Li10a09062016-07-26 23:58:50 +0900273 public RequestBuilder addEidRecord(LispEidRecord record) {
Jian Lif59c0ad2016-08-02 18:11:30 +0900274 this.eidRecords.add(record);
275 return this;
276 }
277
278 @Override
Jian Li525fded2016-08-04 01:15:33 +0900279 public LispMapRequest build() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900280 return new DefaultLispMapRequest(nonce, recordCount, sourceEid, itrRlocs,
281 eidRecords, authoritative, mapDataPresent, probe, smr, pitr, smrInvoked);
Jian Li719b3bf2016-07-22 00:38:29 +0900282 }
283 }
Jian Li451175e2016-07-19 23:22:20 +0900284}