blob: df9012a61a56615337bf489379251c41bb60dc2f [file] [log] [blame]
Jian Li10a09062016-07-26 23:58:50 +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 org.onosproject.lisp.msg.types.LispAfiAddress;
19
20/**
21 * Default implementation of LispMapRecord.
22 */
Jian Li631e62a2016-08-03 22:42:00 +090023public final class DefaultLispMapRecord implements LispMapRecord {
Jian Li10a09062016-07-26 23:58:50 +090024
Jian Li631e62a2016-08-03 22:42:00 +090025 private final int recordTtl;
26 private final int locatorCount;
27 private final byte maskLength;
28 private final LispMapReplyAction action;
29 private final boolean authoritative;
30 private final short mapVersionNumber;
31 private final LispAfiAddress eidPrefixAfi;
Jian Li10a09062016-07-26 23:58:50 +090032
Jian Li631e62a2016-08-03 22:42:00 +090033 /**
34 * A private constructor that protects object instantiation from external.
35 *
36 * @param recordTtl record time-to-live value
37 * @param locatorCount locator's count number
38 * @param maskLength mask length
39 * @param action lisp map reply action
40 * @param authoritative authoritative flag
41 * @param mapVersionNumber map version number
42 * @param eidPrefixAfi EID prefix AFI address
43 */
44 private DefaultLispMapRecord(int recordTtl, int locatorCount, byte maskLength,
45 LispMapReplyAction action, boolean authoritative,
46 short mapVersionNumber, LispAfiAddress eidPrefixAfi) {
47 this.recordTtl = recordTtl;
48 this.locatorCount = locatorCount;
49 this.maskLength = maskLength;
50 this.action = action;
51 this.authoritative = authoritative;
52 this.mapVersionNumber = mapVersionNumber;
53 this.eidPrefixAfi = eidPrefixAfi;
54 }
55
56 @Override
Jian Li10a09062016-07-26 23:58:50 +090057 public int getRecordTtl() {
58 return recordTtl;
59 }
60
Jian Li631e62a2016-08-03 22:42:00 +090061 @Override
Jian Li10a09062016-07-26 23:58:50 +090062 public int getLocatorCount() {
63 return locatorCount;
64 }
65
Jian Li631e62a2016-08-03 22:42:00 +090066 @Override
Jian Li10a09062016-07-26 23:58:50 +090067 public byte getMaskLength() {
68 return maskLength;
69 }
70
Jian Li631e62a2016-08-03 22:42:00 +090071 @Override
Jian Li10a09062016-07-26 23:58:50 +090072 public LispMapReplyAction getAction() {
73 return action;
74 }
75
Jian Li631e62a2016-08-03 22:42:00 +090076 @Override
Jian Li10a09062016-07-26 23:58:50 +090077 public boolean isAuthoritative() {
78 return authoritative;
79 }
80
Jian Li631e62a2016-08-03 22:42:00 +090081 @Override
Jian Li10a09062016-07-26 23:58:50 +090082 public short getMapVersionNumber() {
83 return mapVersionNumber;
84 }
85
Jian Li631e62a2016-08-03 22:42:00 +090086 @Override
Jian Li10a09062016-07-26 23:58:50 +090087 public LispAfiAddress getEidPrefixAfi() {
88 return eidPrefixAfi;
89 }
90
91 public static final class DefaultMapRecordBuilder implements MapRecordBuilder {
92
Jian Li631e62a2016-08-03 22:42:00 +090093 private int recordTtl;
94 private int locatorCount;
95 private byte maskLength;
96 private LispMapReplyAction action;
97 private boolean authoritative;
98 private short mapVersionNumber;
99 private LispAfiAddress eidPrefixAfi;
100
Jian Li10a09062016-07-26 23:58:50 +0900101 @Override
102 public MapRecordBuilder withRecordTtl(int recordTtl) {
Jian Li631e62a2016-08-03 22:42:00 +0900103 this.recordTtl = recordTtl;
104 return this;
Jian Li10a09062016-07-26 23:58:50 +0900105 }
106
107 @Override
108 public MapRecordBuilder withLocatorCount(int locatorCount) {
Jian Li631e62a2016-08-03 22:42:00 +0900109 this.locatorCount = locatorCount;
110 return this;
Jian Li10a09062016-07-26 23:58:50 +0900111 }
112
113 @Override
114 public MapRecordBuilder withMaskLength(byte maskLength) {
Jian Li631e62a2016-08-03 22:42:00 +0900115 this.maskLength = maskLength;
116 return this;
Jian Li10a09062016-07-26 23:58:50 +0900117 }
118
119 @Override
120 public MapRecordBuilder withAction(LispMapReplyAction action) {
Jian Li631e62a2016-08-03 22:42:00 +0900121 this.action = action;
122 return this;
Jian Li10a09062016-07-26 23:58:50 +0900123 }
124
125 @Override
126 public MapRecordBuilder withAuthoritative(boolean authoritative) {
Jian Li631e62a2016-08-03 22:42:00 +0900127 this.authoritative = authoritative;
128 return this;
Jian Li10a09062016-07-26 23:58:50 +0900129 }
130
131 @Override
132 public MapRecordBuilder withMapVersionNumber(short mapVersionNumber) {
Jian Li631e62a2016-08-03 22:42:00 +0900133 this.mapVersionNumber = mapVersionNumber;
134 return this;
Jian Li10a09062016-07-26 23:58:50 +0900135 }
136
137 @Override
138 public MapRecordBuilder withEidPrefixAfi(LispAfiAddress prefix) {
Jian Li631e62a2016-08-03 22:42:00 +0900139 this.eidPrefixAfi = prefix;
140 return this;
141 }
142
143 @Override
144 public LispMapRecord build() {
145 return new DefaultLispMapRecord(recordTtl, locatorCount, maskLength,
146 action, authoritative, mapVersionNumber, eidPrefixAfi);
Jian Li10a09062016-07-26 23:58:50 +0900147 }
148 }
149}