Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.lisp.msg.protocols; |
| 17 | |
| 18 | import org.onosproject.lisp.msg.types.LispAfiAddress; |
| 19 | |
| 20 | /** |
| 21 | * Default implementation of LispMapRecord. |
| 22 | */ |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 23 | public final class DefaultLispMapRecord implements LispMapRecord { |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 24 | |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 25 | 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 Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 32 | |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 33 | /** |
| 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 Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 57 | public int getRecordTtl() { |
| 58 | return recordTtl; |
| 59 | } |
| 60 | |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 61 | @Override |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 62 | public int getLocatorCount() { |
| 63 | return locatorCount; |
| 64 | } |
| 65 | |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 66 | @Override |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 67 | public byte getMaskLength() { |
| 68 | return maskLength; |
| 69 | } |
| 70 | |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 71 | @Override |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 72 | public LispMapReplyAction getAction() { |
| 73 | return action; |
| 74 | } |
| 75 | |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 76 | @Override |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 77 | public boolean isAuthoritative() { |
| 78 | return authoritative; |
| 79 | } |
| 80 | |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 81 | @Override |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 82 | public short getMapVersionNumber() { |
| 83 | return mapVersionNumber; |
| 84 | } |
| 85 | |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 86 | @Override |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 87 | public LispAfiAddress getEidPrefixAfi() { |
| 88 | return eidPrefixAfi; |
| 89 | } |
| 90 | |
| 91 | public static final class DefaultMapRecordBuilder implements MapRecordBuilder { |
| 92 | |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 93 | 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 Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 101 | @Override |
| 102 | public MapRecordBuilder withRecordTtl(int recordTtl) { |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 103 | this.recordTtl = recordTtl; |
| 104 | return this; |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public MapRecordBuilder withLocatorCount(int locatorCount) { |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 109 | this.locatorCount = locatorCount; |
| 110 | return this; |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public MapRecordBuilder withMaskLength(byte maskLength) { |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 115 | this.maskLength = maskLength; |
| 116 | return this; |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public MapRecordBuilder withAction(LispMapReplyAction action) { |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 121 | this.action = action; |
| 122 | return this; |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public MapRecordBuilder withAuthoritative(boolean authoritative) { |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 127 | this.authoritative = authoritative; |
| 128 | return this; |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public MapRecordBuilder withMapVersionNumber(short mapVersionNumber) { |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 133 | this.mapVersionNumber = mapVersionNumber; |
| 134 | return this; |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public MapRecordBuilder withEidPrefixAfi(LispAfiAddress prefix) { |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 139 | 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 Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | } |