blob: ee42dd1339e37025d020756aa28b800d243d0097 [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 Li451175e2016-07-19 23:22:20 +090019import io.netty.buffer.ByteBuf;
Jian Li26069e22016-08-10 22:00:52 +090020import org.onosproject.lisp.msg.exceptions.LispParseError;
Jian Li451175e2016-07-19 23:22:20 +090021
Jian Li20850d32016-08-04 02:15:57 +090022import static com.google.common.base.MoreObjects.toStringHelper;
23
Jian Li451175e2016-07-19 23:22:20 +090024/**
25 * Default LISP map reply message class.
26 */
Jian Lif59c0ad2016-08-02 18:11:30 +090027public final class DefaultLispMapReply implements LispMapReply {
28
29 private final long nonce;
30 private final byte recordCount;
31 private final boolean probe;
32 private final boolean etr;
33 private final boolean security;
34
35 /**
36 * A private constructor that protects object instantiation from external.
37 *
38 * @param nonce nonce
39 * @param recordCount record count number
40 * @param probe probe flag
41 * @param etr etr flag
42 * @param security security flag
43 */
44 private DefaultLispMapReply(long nonce, byte recordCount, boolean probe,
45 boolean etr, boolean security) {
46 this.nonce = nonce;
47 this.recordCount = recordCount;
48 this.probe = probe;
49 this.etr = etr;
50 this.security = security;
51 }
52
Jian Li451175e2016-07-19 23:22:20 +090053 @Override
54 public LispType getType() {
Jian Lif59c0ad2016-08-02 18:11:30 +090055 return LispType.LISP_MAP_REPLY;
Jian Li451175e2016-07-19 23:22:20 +090056 }
57
58 @Override
59 public void writeTo(ByteBuf byteBuf) {
Jian Lif59c0ad2016-08-02 18:11:30 +090060 // TODO: serialize LispMapReply message
Jian Li451175e2016-07-19 23:22:20 +090061 }
62
63 @Override
64 public Builder createBuilder() {
Jian Li525fded2016-08-04 01:15:33 +090065 return new DefaultReplyBuilder();
Jian Li451175e2016-07-19 23:22:20 +090066 }
Jian Li719b3bf2016-07-22 00:38:29 +090067
68 @Override
69 public boolean isProbe() {
Jian Lif59c0ad2016-08-02 18:11:30 +090070 return this.probe;
Jian Li719b3bf2016-07-22 00:38:29 +090071 }
72
73 @Override
74 public boolean isEtr() {
Jian Lif59c0ad2016-08-02 18:11:30 +090075 return this.etr;
Jian Li719b3bf2016-07-22 00:38:29 +090076 }
77
78 @Override
79 public boolean isSecurity() {
Jian Lif59c0ad2016-08-02 18:11:30 +090080 return this.security;
Jian Li719b3bf2016-07-22 00:38:29 +090081 }
82
83 @Override
84 public byte getRecordCount() {
Jian Lif59c0ad2016-08-02 18:11:30 +090085 return this.recordCount;
Jian Li719b3bf2016-07-22 00:38:29 +090086 }
87
88 @Override
89 public long getNonce() {
Jian Lif59c0ad2016-08-02 18:11:30 +090090 return this.nonce;
Jian Li719b3bf2016-07-22 00:38:29 +090091 }
92
Jian Li20850d32016-08-04 02:15:57 +090093 @Override
94 public String toString() {
95 return toStringHelper(this)
96 .add("type", getType())
97 .add("nonce", nonce)
98 .add("recordCount", recordCount)
99 .add("probe", probe)
100 .add("etr", etr)
101 .add("security", security).toString();
102 }
103
104 @Override
105 public boolean equals(Object o) {
106 if (this == o) {
107 return true;
108 }
109 if (o == null || getClass() != o.getClass()) {
110 return false;
111 }
112 DefaultLispMapReply that = (DefaultLispMapReply) o;
113 return Objects.equal(nonce, that.nonce) &&
114 Objects.equal(recordCount, that.recordCount) &&
115 Objects.equal(probe, that.probe) &&
116 Objects.equal(etr, that.etr) &&
117 Objects.equal(security, that.security);
118 }
119
120 @Override
121 public int hashCode() {
122 return Objects.hashCode(nonce, recordCount, probe, etr, security);
123 }
124
Jian Li719b3bf2016-07-22 00:38:29 +0900125 public static final class DefaultReplyBuilder implements ReplyBuilder {
126
Jian Lif59c0ad2016-08-02 18:11:30 +0900127 private long nonce;
128 private byte recordCount;
129 private boolean probe;
130 private boolean etr;
131 private boolean security;
Jian Li719b3bf2016-07-22 00:38:29 +0900132
133 @Override
134 public LispType getType() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900135 return LispType.LISP_MAP_REPLY;
Jian Li719b3bf2016-07-22 00:38:29 +0900136 }
137
138 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900139 public ReplyBuilder withIsProbe(boolean probe) {
140 this.probe = probe;
141 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900142 }
143
144 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900145 public ReplyBuilder withIsEtr(boolean etr) {
146 this.etr = etr;
147 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900148 }
149
150 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900151 public ReplyBuilder withIsSecurity(boolean security) {
152 this.security = security;
153 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900154 }
155
156 @Override
157 public ReplyBuilder withRecordCount(byte recordCount) {
Jian Lif59c0ad2016-08-02 18:11:30 +0900158 this.recordCount = recordCount;
159 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900160 }
161
162 @Override
163 public ReplyBuilder withNonce(long nonce) {
Jian Lif59c0ad2016-08-02 18:11:30 +0900164 this.nonce = nonce;
165 return this;
166 }
167
168 @Override
Jian Li525fded2016-08-04 01:15:33 +0900169 public LispMapReply build() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900170 return new DefaultLispMapReply(nonce, recordCount, probe, etr, security);
Jian Li719b3bf2016-07-22 00:38:29 +0900171 }
172 }
Jian Li26069e22016-08-10 22:00:52 +0900173
174 /**
175 * A private LISP message reader for MapReply message.
176 */
177 private static class ReplyReader implements LispMessageReader<LispMapReply> {
178
179 @Override
180 public LispMapReply readFrom(ByteBuf byteBuf) throws LispParseError {
181 return null;
182 }
183 }
Jian Li451175e2016-07-19 23:22:20 +0900184}