blob: f2a56893357e5d7f82737922a9f1d539b671ebc0 [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
18import io.netty.buffer.ByteBuf;
19
20/**
21 * Default LISP map reply message class.
22 */
Jian Lif59c0ad2016-08-02 18:11:30 +090023public final class DefaultLispMapReply implements LispMapReply {
24
25 private final long nonce;
26 private final byte recordCount;
27 private final boolean probe;
28 private final boolean etr;
29 private final boolean security;
30
31 /**
32 * A private constructor that protects object instantiation from external.
33 *
34 * @param nonce nonce
35 * @param recordCount record count number
36 * @param probe probe flag
37 * @param etr etr flag
38 * @param security security flag
39 */
40 private DefaultLispMapReply(long nonce, byte recordCount, boolean probe,
41 boolean etr, boolean security) {
42 this.nonce = nonce;
43 this.recordCount = recordCount;
44 this.probe = probe;
45 this.etr = etr;
46 this.security = security;
47 }
48
Jian Li451175e2016-07-19 23:22:20 +090049 @Override
50 public LispType getType() {
Jian Lif59c0ad2016-08-02 18:11:30 +090051 return LispType.LISP_MAP_REPLY;
Jian Li451175e2016-07-19 23:22:20 +090052 }
53
54 @Override
55 public void writeTo(ByteBuf byteBuf) {
Jian Lif59c0ad2016-08-02 18:11:30 +090056 // TODO: serialize LispMapReply message
Jian Li451175e2016-07-19 23:22:20 +090057 }
58
59 @Override
60 public Builder createBuilder() {
Jian Li525fded2016-08-04 01:15:33 +090061 return new DefaultReplyBuilder();
Jian Li451175e2016-07-19 23:22:20 +090062 }
Jian Li719b3bf2016-07-22 00:38:29 +090063
64 @Override
65 public boolean isProbe() {
Jian Lif59c0ad2016-08-02 18:11:30 +090066 return this.probe;
Jian Li719b3bf2016-07-22 00:38:29 +090067 }
68
69 @Override
70 public boolean isEtr() {
Jian Lif59c0ad2016-08-02 18:11:30 +090071 return this.etr;
Jian Li719b3bf2016-07-22 00:38:29 +090072 }
73
74 @Override
75 public boolean isSecurity() {
Jian Lif59c0ad2016-08-02 18:11:30 +090076 return this.security;
Jian Li719b3bf2016-07-22 00:38:29 +090077 }
78
79 @Override
80 public byte getRecordCount() {
Jian Lif59c0ad2016-08-02 18:11:30 +090081 return this.recordCount;
Jian Li719b3bf2016-07-22 00:38:29 +090082 }
83
84 @Override
85 public long getNonce() {
Jian Lif59c0ad2016-08-02 18:11:30 +090086 return this.nonce;
Jian Li719b3bf2016-07-22 00:38:29 +090087 }
88
89 public static final class DefaultReplyBuilder implements ReplyBuilder {
90
Jian Lif59c0ad2016-08-02 18:11:30 +090091 private long nonce;
92 private byte recordCount;
93 private boolean probe;
94 private boolean etr;
95 private boolean security;
Jian Li719b3bf2016-07-22 00:38:29 +090096
97 @Override
98 public LispType getType() {
Jian Lif59c0ad2016-08-02 18:11:30 +090099 return LispType.LISP_MAP_REPLY;
Jian Li719b3bf2016-07-22 00:38:29 +0900100 }
101
102 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900103 public ReplyBuilder withIsProbe(boolean probe) {
104 this.probe = probe;
105 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900106 }
107
108 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900109 public ReplyBuilder withIsEtr(boolean etr) {
110 this.etr = etr;
111 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900112 }
113
114 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900115 public ReplyBuilder withIsSecurity(boolean security) {
116 this.security = security;
117 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900118 }
119
120 @Override
121 public ReplyBuilder withRecordCount(byte recordCount) {
Jian Lif59c0ad2016-08-02 18:11:30 +0900122 this.recordCount = recordCount;
123 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900124 }
125
126 @Override
127 public ReplyBuilder withNonce(long nonce) {
Jian Lif59c0ad2016-08-02 18:11:30 +0900128 this.nonce = nonce;
129 return this;
130 }
131
132 @Override
Jian Li525fded2016-08-04 01:15:33 +0900133 public LispMapReply build() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900134 return new DefaultLispMapReply(nonce, recordCount, probe, etr, security);
Jian Li719b3bf2016-07-22 00:38:29 +0900135 }
136 }
Jian Li451175e2016-07-19 23:22:20 +0900137}