blob: 3126cc88e1110c7053c499d84bf3f7bd4fc3f1f9 [file] [log] [blame]
Jian Li672ebda2017-02-06 20:21:04 +09001/*
2 * Copyright 2017-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 * Abstract LISP record class that provide default implementations.
22 */
23public abstract class AbstractLispRecord implements LispRecord {
24
25 protected final int recordTtl;
26 protected final byte maskLength;
27 protected final LispMapReplyAction action;
28 protected final boolean authoritative;
29 protected final short mapVersionNumber;
30 protected final LispAfiAddress eidPrefixAfi;
31
32 protected AbstractLispRecord(int recordTtl, byte maskLength,
33 LispMapReplyAction action, boolean authoritative,
34 short mapVersionNumber, LispAfiAddress eidPrefixAfi) {
35 this.recordTtl = recordTtl;
36 this.maskLength = maskLength;
37 this.action = action;
38 this.authoritative = authoritative;
39 this.mapVersionNumber = mapVersionNumber;
40 this.eidPrefixAfi = eidPrefixAfi;
41 }
42
43 @Override
44 public int getRecordTtl() {
45 return recordTtl;
46 }
47
48 @Override
49 public byte getMaskLength() {
50 return maskLength;
51 }
52
53 @Override
54 public LispMapReplyAction getAction() {
55 return action;
56 }
57
58 @Override
59 public boolean isAuthoritative() {
60 return authoritative;
61 }
62
63 @Override
64 public short getMapVersionNumber() {
65 return mapVersionNumber;
66 }
67
68 @Override
69 public LispAfiAddress getEidPrefixAfi() {
70 return eidPrefixAfi;
71 }
72
73 public static class AbstractRecordBuilder<T> implements RecordBuilder<T> {
74
75 protected int recordTtl;
76 protected byte maskLength;
77 protected LispMapReplyAction action;
78 protected boolean authoritative;
79 protected short mapVersionNumber;
80 protected LispAfiAddress eidPrefixAfi;
81
82 @Override
83 public T withRecordTtl(int recordTtl) {
84 this.recordTtl = recordTtl;
85 return (T) this;
86 }
87
88 @Override
89 public T withMaskLength(byte maskLength) {
90 this.maskLength = maskLength;
91 return (T) this;
92 }
93
94 @Override
95 public T withAction(LispMapReplyAction action) {
96 this.action = action;
97 return (T) this;
98 }
99
100 @Override
101 public T withIsAuthoritative(boolean authoritative) {
102 this.authoritative = authoritative;
103 return (T) this;
104 }
105
106 @Override
107 public T withMapVersionNumber(short mapVersionNumber) {
108 this.mapVersionNumber = mapVersionNumber;
109 return (T) this;
110 }
111
112 @Override
113 public T withEidPrefixAfi(LispAfiAddress prefix) {
114 this.eidPrefixAfi = prefix;
115 return (T) this;
116 }
117 }
118}