Jian Li | 451175e | 2016-07-19 23:22:20 +0900 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.lisp.msg.protocols; |
| 17 | |
Jian Li | 20850d3 | 2016-08-04 02:15:57 +0900 | [diff] [blame] | 18 | import com.google.common.base.Objects; |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableList; |
| 20 | import com.google.common.collect.Lists; |
Jian Li | 451175e | 2016-07-19 23:22:20 +0900 | [diff] [blame] | 21 | import io.netty.buffer.ByteBuf; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 22 | import org.onosproject.lisp.msg.types.LispAfiAddress; |
| 23 | |
| 24 | import java.util.List; |
Jian Li | 451175e | 2016-07-19 23:22:20 +0900 | [diff] [blame] | 25 | |
Jian Li | 20850d3 | 2016-08-04 02:15:57 +0900 | [diff] [blame] | 26 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 27 | |
Jian Li | 451175e | 2016-07-19 23:22:20 +0900 | [diff] [blame] | 28 | /** |
| 29 | * Default LISP map request message class. |
| 30 | */ |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 31 | public 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 Li | 451175e | 2016-07-19 23:22:20 +0900 | [diff] [blame] | 77 | @Override |
| 78 | public LispType getType() { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 79 | return LispType.LISP_MAP_REQUEST; |
Jian Li | 451175e | 2016-07-19 23:22:20 +0900 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public void writeTo(ByteBuf byteBuf) { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 84 | // TODO: serialize LispMapRequest message |
Jian Li | 451175e | 2016-07-19 23:22:20 +0900 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public Builder createBuilder() { |
Jian Li | 525fded | 2016-08-04 01:15:33 +0900 | [diff] [blame] | 89 | return new DefaultRequestBuilder(); |
Jian Li | 451175e | 2016-07-19 23:22:20 +0900 | [diff] [blame] | 90 | } |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 91 | |
| 92 | @Override |
| 93 | public boolean isAuthoritative() { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 94 | return this.authoritative; |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public boolean isMapDataPresent() { |
| 99 | return this.mapDataPresent; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public boolean isProbe() { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 104 | return this.probe; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public boolean isSmr() { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 109 | return this.smr; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public boolean isPitr() { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 114 | return this.pitr; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public boolean isSmrInvoked() { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 119 | return this.smrInvoked; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public byte getRecordCount() { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 124 | return this.recordCount; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public long getNonce() { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 129 | return this.nonce; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public LispAfiAddress getSourceEid() { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 134 | return this.sourceEid; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public List<LispAfiAddress> getItrRlocs() { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 139 | return ImmutableList.copyOf(itrRlocs); |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | @Override |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 143 | public List<LispEidRecord> getEids() { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 144 | return ImmutableList.copyOf(eidRecords); |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 145 | } |
| 146 | |
Jian Li | 20850d3 | 2016-08-04 02:15:57 +0900 | [diff] [blame] | 147 | @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 Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 192 | public static final class DefaultRequestBuilder implements RequestBuilder { |
| 193 | |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 194 | 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 Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 205 | |
| 206 | @Override |
| 207 | public LispType getType() { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 208 | return LispType.LISP_MAP_REQUEST; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | @Override |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 212 | public RequestBuilder withIsAuthoritative(boolean authoritative) { |
| 213 | this.authoritative = authoritative; |
| 214 | return this; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | @Override |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 218 | public RequestBuilder withIsProbe(boolean probe) { |
| 219 | this.probe = probe; |
| 220 | return this; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | @Override |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 224 | 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 Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | @Override |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 237 | public RequestBuilder withIsPitr(boolean pitr) { |
| 238 | this.pitr = pitr; |
| 239 | return this; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | @Override |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 243 | public RequestBuilder withIsSmrInvoked(boolean smrInvoked) { |
| 244 | this.smrInvoked = smrInvoked; |
| 245 | return this; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public RequestBuilder withRecordCount(byte recordCount) { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 250 | this.recordCount = recordCount; |
| 251 | return this; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | @Override |
| 255 | public RequestBuilder withNonce(long nonce) { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 256 | this.nonce = nonce; |
| 257 | return this; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | @Override |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 261 | 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 Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | @Override |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 273 | public RequestBuilder addEidRecord(LispEidRecord record) { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 274 | this.eidRecords.add(record); |
| 275 | return this; |
| 276 | } |
| 277 | |
| 278 | @Override |
Jian Li | 525fded | 2016-08-04 01:15:33 +0900 | [diff] [blame] | 279 | public LispMapRequest build() { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 280 | return new DefaultLispMapRequest(nonce, recordCount, sourceEid, itrRlocs, |
| 281 | eidRecords, authoritative, mapDataPresent, probe, smr, pitr, smrInvoked); |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 282 | } |
| 283 | } |
Jian Li | 451175e | 2016-07-19 23:22:20 +0900 | [diff] [blame] | 284 | } |