blob: 760d1ad61f986709b5fc804c34e36bd4db99cc84 [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;
20
Jian Li20850d32016-08-04 02:15:57 +090021import static com.google.common.base.MoreObjects.toStringHelper;
22
Jian Li451175e2016-07-19 23:22:20 +090023/**
24 * Default LISP map reply message class.
25 */
Jian Lif59c0ad2016-08-02 18:11:30 +090026public final class DefaultLispMapReply implements LispMapReply {
27
28 private final long nonce;
29 private final byte recordCount;
30 private final boolean probe;
31 private final boolean etr;
32 private final boolean security;
33
34 /**
35 * A private constructor that protects object instantiation from external.
36 *
37 * @param nonce nonce
38 * @param recordCount record count number
39 * @param probe probe flag
40 * @param etr etr flag
41 * @param security security flag
42 */
43 private DefaultLispMapReply(long nonce, byte recordCount, boolean probe,
44 boolean etr, boolean security) {
45 this.nonce = nonce;
46 this.recordCount = recordCount;
47 this.probe = probe;
48 this.etr = etr;
49 this.security = security;
50 }
51
Jian Li451175e2016-07-19 23:22:20 +090052 @Override
53 public LispType getType() {
Jian Lif59c0ad2016-08-02 18:11:30 +090054 return LispType.LISP_MAP_REPLY;
Jian Li451175e2016-07-19 23:22:20 +090055 }
56
57 @Override
58 public void writeTo(ByteBuf byteBuf) {
Jian Lif59c0ad2016-08-02 18:11:30 +090059 // TODO: serialize LispMapReply message
Jian Li451175e2016-07-19 23:22:20 +090060 }
61
62 @Override
63 public Builder createBuilder() {
Jian Li525fded2016-08-04 01:15:33 +090064 return new DefaultReplyBuilder();
Jian Li451175e2016-07-19 23:22:20 +090065 }
Jian Li719b3bf2016-07-22 00:38:29 +090066
67 @Override
68 public boolean isProbe() {
Jian Lif59c0ad2016-08-02 18:11:30 +090069 return this.probe;
Jian Li719b3bf2016-07-22 00:38:29 +090070 }
71
72 @Override
73 public boolean isEtr() {
Jian Lif59c0ad2016-08-02 18:11:30 +090074 return this.etr;
Jian Li719b3bf2016-07-22 00:38:29 +090075 }
76
77 @Override
78 public boolean isSecurity() {
Jian Lif59c0ad2016-08-02 18:11:30 +090079 return this.security;
Jian Li719b3bf2016-07-22 00:38:29 +090080 }
81
82 @Override
83 public byte getRecordCount() {
Jian Lif59c0ad2016-08-02 18:11:30 +090084 return this.recordCount;
Jian Li719b3bf2016-07-22 00:38:29 +090085 }
86
87 @Override
88 public long getNonce() {
Jian Lif59c0ad2016-08-02 18:11:30 +090089 return this.nonce;
Jian Li719b3bf2016-07-22 00:38:29 +090090 }
91
Jian Li20850d32016-08-04 02:15:57 +090092 @Override
93 public String toString() {
94 return toStringHelper(this)
95 .add("type", getType())
96 .add("nonce", nonce)
97 .add("recordCount", recordCount)
98 .add("probe", probe)
99 .add("etr", etr)
100 .add("security", security).toString();
101 }
102
103 @Override
104 public boolean equals(Object o) {
105 if (this == o) {
106 return true;
107 }
108 if (o == null || getClass() != o.getClass()) {
109 return false;
110 }
111 DefaultLispMapReply that = (DefaultLispMapReply) o;
112 return Objects.equal(nonce, that.nonce) &&
113 Objects.equal(recordCount, that.recordCount) &&
114 Objects.equal(probe, that.probe) &&
115 Objects.equal(etr, that.etr) &&
116 Objects.equal(security, that.security);
117 }
118
119 @Override
120 public int hashCode() {
121 return Objects.hashCode(nonce, recordCount, probe, etr, security);
122 }
123
Jian Li719b3bf2016-07-22 00:38:29 +0900124 public static final class DefaultReplyBuilder implements ReplyBuilder {
125
Jian Lif59c0ad2016-08-02 18:11:30 +0900126 private long nonce;
127 private byte recordCount;
128 private boolean probe;
129 private boolean etr;
130 private boolean security;
Jian Li719b3bf2016-07-22 00:38:29 +0900131
132 @Override
133 public LispType getType() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900134 return LispType.LISP_MAP_REPLY;
Jian Li719b3bf2016-07-22 00:38:29 +0900135 }
136
137 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900138 public ReplyBuilder withIsProbe(boolean probe) {
139 this.probe = probe;
140 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900141 }
142
143 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900144 public ReplyBuilder withIsEtr(boolean etr) {
145 this.etr = etr;
146 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900147 }
148
149 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900150 public ReplyBuilder withIsSecurity(boolean security) {
151 this.security = security;
152 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900153 }
154
155 @Override
156 public ReplyBuilder withRecordCount(byte recordCount) {
Jian Lif59c0ad2016-08-02 18:11:30 +0900157 this.recordCount = recordCount;
158 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900159 }
160
161 @Override
162 public ReplyBuilder withNonce(long nonce) {
Jian Lif59c0ad2016-08-02 18:11:30 +0900163 this.nonce = nonce;
164 return this;
165 }
166
167 @Override
Jian Li525fded2016-08-04 01:15:33 +0900168 public LispMapReply build() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900169 return new DefaultLispMapReply(nonce, recordCount, probe, etr, security);
Jian Li719b3bf2016-07-22 00:38:29 +0900170 }
171 }
Jian Li451175e2016-07-19 23:22:20 +0900172}