summaryrefslogtreecommitdiffstats
path: root/lisp/lisp2vpp/src/main/java/io/fd/honeycomb/lisp/translate/read/dump/executor/params/MappingsDumpParams.java
blob: 1f7990c9bfecca57c9f00b9ea2e94c4713df8385 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
 * Copyright (c) 2016 Cisco and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.fd.honeycomb.lisp.translate.read.dump.executor.params;

import io.fd.honeycomb.lisp.translate.read.dump.executor.MappingsDumpExecutor;
import java.util.Arrays;

/**
 * Parameters for executing {@link MappingsDumpExecutor}
 */
public final class MappingsDumpParams {

    private final byte eidSet;
    private final byte prefixLength;
    private final int vni;
    private final byte eidType;
    private final byte[] eid;
    private final byte filter;

    private MappingsDumpParams(MappingsDumpParamsBuilder builder) {
        this.eidSet = builder.eidSet;
        this.prefixLength = builder.prefixLength;
        this.vni = builder.vni;
        this.eidType = builder.eidType;
        this.eid = builder.eid;
        this.filter = builder.filter;
    }


    public byte getEidSet() {
        return eidSet;
    }

    public byte getPrefixLength() {
        return prefixLength;
    }

    public int getVni() {
        return vni;
    }

    public byte getEidType() {
        return eidType;
    }

    public byte[] getEid() {
        return eid;
    }

    public final byte getFilter() {
        return filter;
    }

    @Override
    public String toString() {
        return "MappingsDumpParams{" +
                "eidSet=" + eidSet +
                ", prefixLength=" + prefixLength +
                ", vni=" + vni +
                ", eidType=" + eidType +
                ", eid=" + Arrays.toString(eid) +
                ", filter=" + filter +
                '}';
    }

    /**
     * Type of requested mapping eid
     */
    public enum EidType {
        IPV4(0),
        IPV6(1),
        MAC(2);

        private final int value;

        private EidType(final int value) {
            this.value = value;
        }

        public static final EidType valueOf(int value) {
            switch (value) {
                case 0:
                    return IPV4;
                case 1:
                    return IPV6;
                case 2:
                    return MAC;
                default:
                    throw new IllegalArgumentException("Illegal value");
            }
        }

        public final int getValue() {
            return this.value;
        }
    }

    /**
     * Type of requested mapping
     */
    public enum FilterType {
        ALL(0),
        LOCAL(1),
        REMOTE(2);

        private final int value;

        private FilterType(final int value) {
            this.value = value;
        }

        public final int getValue() {
            return this.value;
        }
    }

    public enum QuantityType {
        ALL(0),
        SPECIFIC(1);

        private final int value;

        private QuantityType(final int value) {
            this.value = value;
        }

        public final int getValue() {
            return this.value;
        }
    }

    public static final class MappingsDumpParamsBuilder {
        private byte eidSet;
        private byte prefixLength;
        private int vni;
        private byte eidType;
        private byte[] eid;
        private byte filter;

        public static final MappingsDumpParamsBuilder newInstance() {
            return new MappingsDumpParamsBuilder();
        }

        public MappingsDumpParamsBuilder setEidSet(final QuantityType quantityType) {
            this.eidSet = (byte) quantityType.getValue();
            return this;
        }

        public MappingsDumpParamsBuilder setPrefixLength(final byte prefixLength) {
            this.prefixLength = prefixLength;
            return this;
        }

        public MappingsDumpParamsBuilder setVni(final int vni) {
            this.vni = vni;
            return this;
        }

        public MappingsDumpParamsBuilder setEidType(final EidType eidType) {
            this.eidType = (byte) eidType.getValue();
            return this;
        }

        public MappingsDumpParamsBuilder setEid(final byte[] eid) {
            this.eid = eid;
            return this;
        }

        public MappingsDumpParamsBuilder setFilter(final FilterType filterType) {
            this.filter = (byte) filterType.getValue();
            return this;
        }

        public MappingsDumpParams build() {
            return new MappingsDumpParams(this);
        }
    }
}