blob: 1ec7dc69b7d0d3fd8eaaaeb794ec70206ddc2373 [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 Lif59c0ad2016-08-02 18:11:30 +090018import com.google.common.collect.ImmutableList;
19import com.google.common.collect.Lists;
Jian Li451175e2016-07-19 23:22:20 +090020import io.netty.buffer.ByteBuf;
Jian Li719b3bf2016-07-22 00:38:29 +090021import org.onosproject.lisp.msg.types.LispAfiAddress;
22
23import java.util.List;
Jian Li451175e2016-07-19 23:22:20 +090024
25/**
26 * Default LISP map request message class.
27 */
Jian Lif59c0ad2016-08-02 18:11:30 +090028public final class DefaultLispMapRequest implements LispMapRequest {
29
30 private final long nonce;
31 private final byte recordCount;
32 private final LispAfiAddress sourceEid;
33 private final List<LispAfiAddress> itrRlocs;
34 private final List<LispEidRecord> eidRecords;
35 private final boolean authoritative;
36 private final boolean mapDataPresent;
37 private final boolean probe;
38 private final boolean smr;
39 private final boolean pitr;
40 private final boolean smrInvoked;
41
42 /**
43 * A private constructor that protects object instantiation from external.
44 *
45 * @param nonce nonce
46 * @param recordCount record count number
47 * @param sourceEid source EID address
48 * @param itrRlocs a collection of ITR RLOCs
49 * @param eidRecords a collection of EID records
50 * @param authoritative authoritative flag
51 * @param mapDataPresent map data present flag
52 * @param probe probe flag
53 * @param smr smr flag
54 * @param pitr pitr flag
55 * @param smrInvoked smrInvoked flag
56 */
57 private DefaultLispMapRequest(long nonce, byte recordCount, LispAfiAddress sourceEid,
58 List<LispAfiAddress> itrRlocs, List<LispEidRecord> eidRecords,
59 boolean authoritative, boolean mapDataPresent, boolean probe,
60 boolean smr, boolean pitr, boolean smrInvoked) {
61 this.nonce = nonce;
62 this.recordCount = recordCount;
63 this.sourceEid = sourceEid;
64 this.itrRlocs = itrRlocs;
65 this.eidRecords = eidRecords;
66 this.authoritative = authoritative;
67 this.mapDataPresent = mapDataPresent;
68 this.probe = probe;
69 this.smr = smr;
70 this.pitr = pitr;
71 this.smrInvoked = smrInvoked;
72 }
73
Jian Li451175e2016-07-19 23:22:20 +090074 @Override
75 public LispType getType() {
Jian Lif59c0ad2016-08-02 18:11:30 +090076 return LispType.LISP_MAP_REQUEST;
Jian Li451175e2016-07-19 23:22:20 +090077 }
78
79 @Override
80 public void writeTo(ByteBuf byteBuf) {
Jian Lif59c0ad2016-08-02 18:11:30 +090081 // TODO: serialize LispMapRequest message
Jian Li451175e2016-07-19 23:22:20 +090082 }
83
84 @Override
85 public Builder createBuilder() {
Jian Li525fded2016-08-04 01:15:33 +090086 return new DefaultRequestBuilder();
Jian Li451175e2016-07-19 23:22:20 +090087 }
Jian Li719b3bf2016-07-22 00:38:29 +090088
89 @Override
90 public boolean isAuthoritative() {
Jian Lif59c0ad2016-08-02 18:11:30 +090091 return this.authoritative;
92 }
93
94 @Override
95 public boolean isMapDataPresent() {
96 return this.mapDataPresent;
Jian Li719b3bf2016-07-22 00:38:29 +090097 }
98
99 @Override
100 public boolean isProbe() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900101 return this.probe;
Jian Li719b3bf2016-07-22 00:38:29 +0900102 }
103
104 @Override
105 public boolean isSmr() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900106 return this.smr;
Jian Li719b3bf2016-07-22 00:38:29 +0900107 }
108
109 @Override
110 public boolean isPitr() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900111 return this.pitr;
Jian Li719b3bf2016-07-22 00:38:29 +0900112 }
113
114 @Override
115 public boolean isSmrInvoked() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900116 return this.smrInvoked;
Jian Li719b3bf2016-07-22 00:38:29 +0900117 }
118
119 @Override
120 public byte getRecordCount() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900121 return this.recordCount;
Jian Li719b3bf2016-07-22 00:38:29 +0900122 }
123
124 @Override
125 public long getNonce() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900126 return this.nonce;
Jian Li719b3bf2016-07-22 00:38:29 +0900127 }
128
129 @Override
130 public LispAfiAddress getSourceEid() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900131 return this.sourceEid;
Jian Li719b3bf2016-07-22 00:38:29 +0900132 }
133
134 @Override
135 public List<LispAfiAddress> getItrRlocs() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900136 return ImmutableList.copyOf(itrRlocs);
Jian Li719b3bf2016-07-22 00:38:29 +0900137 }
138
139 @Override
Jian Li10a09062016-07-26 23:58:50 +0900140 public List<LispEidRecord> getEids() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900141 return ImmutableList.copyOf(eidRecords);
Jian Li719b3bf2016-07-22 00:38:29 +0900142 }
143
144 public static final class DefaultRequestBuilder implements RequestBuilder {
145
Jian Lif59c0ad2016-08-02 18:11:30 +0900146 private long nonce;
147 private byte recordCount;
148 private LispAfiAddress sourceEid;
149 private List<LispAfiAddress> itrRlocs = Lists.newArrayList();
150 private List<LispEidRecord> eidRecords = Lists.newArrayList();
151 private boolean authoritative;
152 private boolean mapDataPresent;
153 private boolean probe;
154 private boolean smr;
155 private boolean pitr;
156 private boolean smrInvoked;
Jian Li719b3bf2016-07-22 00:38:29 +0900157
158 @Override
159 public LispType getType() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900160 return LispType.LISP_MAP_REQUEST;
Jian Li719b3bf2016-07-22 00:38:29 +0900161 }
162
163 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900164 public RequestBuilder withIsAuthoritative(boolean authoritative) {
165 this.authoritative = authoritative;
166 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900167 }
168
169 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900170 public RequestBuilder withIsProbe(boolean probe) {
171 this.probe = probe;
172 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900173 }
174
175 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900176 public RequestBuilder withIsMapDataPresent(boolean mapDataPresent) {
177 this.mapDataPresent = mapDataPresent;
178 return this;
179 }
180
181
182 @Override
183 public RequestBuilder withIsSmr(boolean smr) {
184 this.smr = smr;
185 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900186 }
187
188 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900189 public RequestBuilder withIsPitr(boolean pitr) {
190 this.pitr = pitr;
191 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900192 }
193
194 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900195 public RequestBuilder withIsSmrInvoked(boolean smrInvoked) {
196 this.smrInvoked = smrInvoked;
197 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900198 }
199
200 @Override
201 public RequestBuilder withRecordCount(byte recordCount) {
Jian Lif59c0ad2016-08-02 18:11:30 +0900202 this.recordCount = recordCount;
203 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900204 }
205
206 @Override
207 public RequestBuilder withNonce(long nonce) {
Jian Lif59c0ad2016-08-02 18:11:30 +0900208 this.nonce = nonce;
209 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900210 }
211
212 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900213 public RequestBuilder withSourceEid(LispAfiAddress sourceEid) {
214 this.sourceEid = sourceEid;
215 return this;
216 }
217
218 @Override
219 public RequestBuilder addItrRloc(LispAfiAddress itrRloc) {
220 this.itrRlocs.add(itrRloc);
221 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900222 }
223
224 @Override
Jian Li10a09062016-07-26 23:58:50 +0900225 public RequestBuilder addEidRecord(LispEidRecord record) {
Jian Lif59c0ad2016-08-02 18:11:30 +0900226 this.eidRecords.add(record);
227 return this;
228 }
229
230 @Override
Jian Li525fded2016-08-04 01:15:33 +0900231 public LispMapRequest build() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900232 return new DefaultLispMapRequest(nonce, recordCount, sourceEid, itrRlocs,
233 eidRecords, authoritative, mapDataPresent, probe, smr, pitr, smrInvoked);
Jian Li719b3bf2016-07-22 00:38:29 +0900234 }
235 }
Jian Li451175e2016-07-19 23:22:20 +0900236}