00653738d13fdd6e527318c430b4f642398015ad
[hc2vpp.git] /
1 /*
2  * Copyright (c) 2018 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.hc2vpp.common.translate.util;
18
19 import static com.google.common.base.Preconditions.checkNotNull;
20
21 import io.fd.vpp.jvpp.core.types.FibMplsLabel;
22 import javax.annotation.Nonnull;
23
24 /**
25  * Utility for Translating between different representations of MPLS label.
26  */
27 public interface MplsLabelTranslator {
28     /**
29      * Make available also from static context.
30      */
31     MplsLabelTranslator INSTANCE = new MplsLabelTranslator() {
32     };
33
34     /**
35      * Builds {@link FibMplsLabel} from its YANG representation.
36      *
37      * @param label YANG representation of MPLS Label
38      * @return VPP representation of MPLS label
39      */
40     default FibMplsLabel translate(@Nonnull final Long label) {
41         checkNotNull(label, "MPLS label should not be null");
42         return translate(label.intValue());
43     }
44
45     /**
46      * Builds {@link FibMplsLabel} from int value.
47      *
48      * @param label MPLS Label value
49      * @return VPP representation of MPLS label
50      */
51     default FibMplsLabel translate(final int label) {
52         final FibMplsLabel fibMplsLabel = new FibMplsLabel();
53         fibMplsLabel.label = label;
54         return fibMplsLabel;
55     }
56 }