blob: f0825fb13608d9c05fd31a94d4a51e734af26e88 [file] [log] [blame]
Jian Li40f4d6c2017-12-14 00:07:21 +09001/*
2 * Copyright 2017-present Open Networking Foundation
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.incubator.protobuf.models.net.meter;
17
18import org.onosproject.grpc.net.meter.models.BandEnumsProto;
19import org.onosproject.net.meter.Band;
20import org.slf4j.Logger;
21import org.slf4j.LoggerFactory;
22
23import java.util.Optional;
24
25/**
26 * gRPC message conversion related utilities for band enums.
27 */
28public final class BandEnumsProtoTranslator {
29
30 private static final Logger log = LoggerFactory.getLogger(BandEnumsProtoTranslator.class);
31
32 /**
33 * Translates gRPC enum Band Type to ONOS enum.
34 *
35 * @param bandType BandType in gRPC enum
36 * @return equivalent in ONOS enum
37 */
Jian Li1aaa64d2017-12-14 11:25:39 +090038 public static Optional<Band.Type> translate(BandEnumsProto.BandTypeProto bandType) {
Jian Li40f4d6c2017-12-14 00:07:21 +090039 switch (bandType) {
40 case DROP:
41 return Optional.of(Band.Type.DROP);
42 case REMARK:
43 return Optional.of(Band.Type.REMARK);
44 case EXPERIMENTAL:
45 return Optional.of(Band.Type.EXPERIMENTAL);
46 default:
47 log.warn("Unrecognized BandType gRPC message: {}", bandType);
48 return Optional.empty();
49 }
50 }
51
52 // Utility class not intended for instantiation.
53 private BandEnumsProtoTranslator() {}
54}