HONEYCOMB-58 - Routing Api
[honeycomb.git] / lisp / lisp2vpp / src / main / java / io / fd / honeycomb / lisp / translate / read / dump / executor / params / MappingsDumpParams.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
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
17 package io.fd.honeycomb.lisp.translate.read.dump.executor.params;
18
19 import java.util.Arrays;
20
21 /**
22  * Parameters for executing dump of mappings
23  */
24 public final class MappingsDumpParams {
25
26     private final byte eidSet;
27     private final byte prefixLength;
28     private final int vni;
29     private final byte eidType;
30     private final byte[] eid;
31     private final byte filter;
32
33     private MappingsDumpParams(MappingsDumpParamsBuilder builder) {
34         this.eidSet = builder.eidSet;
35         this.prefixLength = builder.prefixLength;
36         this.vni = builder.vni;
37         this.eidType = builder.eidType;
38         this.eid = builder.eid;
39         this.filter = builder.filter;
40     }
41
42
43     public byte getEidSet() {
44         return eidSet;
45     }
46
47     public byte getPrefixLength() {
48         return prefixLength;
49     }
50
51     public int getVni() {
52         return vni;
53     }
54
55     public byte getEidType() {
56         return eidType;
57     }
58
59     public byte[] getEid() {
60         return eid;
61     }
62
63     public final byte getFilter() {
64         return filter;
65     }
66
67     @Override
68     public String toString() {
69         return "MappingsDumpParams{" +
70                 "eidSet=" + eidSet +
71                 ", prefixLength=" + prefixLength +
72                 ", vni=" + vni +
73                 ", eidType=" + eidType +
74                 ", eid=" + Arrays.toString(eid) +
75                 ", filter=" + filter +
76                 '}';
77     }
78
79     /**
80      * Type of requested mapping eid
81      */
82     public enum EidType {
83         IPV4(0),
84         IPV6(1),
85         MAC(2);
86
87         private final int value;
88
89         private EidType(final int value) {
90             this.value = value;
91         }
92
93         public static final EidType valueOf(int value) {
94             switch (value) {
95                 case 0:
96                     return IPV4;
97                 case 1:
98                     return IPV6;
99                 case 2:
100                     return MAC;
101                 default:
102                     throw new IllegalArgumentException("Illegal value");
103             }
104         }
105
106         public final int getValue() {
107             return this.value;
108         }
109     }
110
111     /**
112      * Type of requested mapping
113      */
114     public enum FilterType {
115         ALL(0),
116         LOCAL(1),
117         REMOTE(2);
118
119         private final int value;
120
121         private FilterType(final int value) {
122             this.value = value;
123         }
124
125         public final int getValue() {
126             return this.value;
127         }
128     }
129
130     public enum QuantityType {
131         ALL(0),
132         SPECIFIC(1);
133
134         private final int value;
135
136         private QuantityType(final int value) {
137             this.value = value;
138         }
139
140         public final int getValue() {
141             return this.value;
142         }
143     }
144
145     public static final class MappingsDumpParamsBuilder {
146         private byte eidSet;
147         private byte prefixLength;
148         private int vni;
149         private byte eidType;
150         private byte[] eid;
151         private byte filter;
152
153         public static final MappingsDumpParamsBuilder newInstance() {
154             return new MappingsDumpParamsBuilder();
155         }
156
157         public MappingsDumpParamsBuilder setEidSet(final QuantityType quantityType) {
158             this.eidSet = (byte) quantityType.getValue();
159             return this;
160         }
161
162         public MappingsDumpParamsBuilder setPrefixLength(final byte prefixLength) {
163             this.prefixLength = prefixLength;
164             return this;
165         }
166
167         public MappingsDumpParamsBuilder setVni(final int vni) {
168             this.vni = vni;
169             return this;
170         }
171
172         public MappingsDumpParamsBuilder setEidType(final EidType eidType) {
173             this.eidType = (byte) eidType.getValue();
174             return this;
175         }
176
177         public MappingsDumpParamsBuilder setEid(final byte[] eid) {
178             this.eid = eid;
179             return this;
180         }
181
182         public MappingsDumpParamsBuilder setFilter(final FilterType filterType) {
183             this.filter = (byte) filterType.getValue();
184             return this;
185         }
186
187         public MappingsDumpParams build() {
188             return new MappingsDumpParams(this);
189         }
190     }
191 }