blob: 583820ea1002e43bf7b6ccdf66de342a0c96d8df [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska7d693f52014-10-21 19:17:57 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska7d693f52014-10-21 19:17:57 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska7d693f52014-10-21 19:17:57 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cli.net;
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070017
18import org.onlab.packet.Ethernet;
19
20/**
21 * Allowed values for Ethernet types. Used by the CLI completer for
22 * connectivity based intent L2 parameters.
23 */
24public enum EthType {
25 /** ARP. */
26 ARP(Ethernet.TYPE_ARP),
27 /** RARP. */
28 RARP(Ethernet.TYPE_RARP),
29 /** IPV4. */
30 IPV4(Ethernet.TYPE_IPV4),
31 /** LLDP. */
32 LLDP(Ethernet.TYPE_LLDP),
33 /** BSN. */
34 BSN(Ethernet.TYPE_BSN);
35
36 private short value;
37
38 /**
39 * Constructs an EthType with the given value.
40 *
Jonathan Hart6e948282014-11-17 22:50:42 -080041 * @param value value to use when this EthType is seen
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070042 */
43 private EthType(short value) {
44 this.value = value;
45 }
46
47 /**
48 * Gets the value to use for this EthType.
49 *
50 * @return short value to use for this EthType
51 */
52 public short value() {
53 return this.value;
54 }
Jonathan Hart6e948282014-11-17 22:50:42 -080055
56 /**
57 * Parse a string input that could contain an EthType value. The value
58 * may appear in the string either as a known protocol name (one of the
59 * values of this enum), or a numeric protocol value.
60 *
61 * @param input the input string to parse
62 * @return the numeric value of the parsed Ethernet type
63 * @throws IllegalArgumentException if the input string does not contain a
64 * value that can be parsed into an Ethernet type
65 */
66 public static short parseFromString(String input) {
67 try {
68 return valueOf(input).value();
69 } catch (IllegalArgumentException e) {
70 // The input is not a known Ethernet type name, let's see if it's an
71 // Ethernet type value (short). We parse with Integer to handle
72 // unsigned values correctly.
73 try {
74 return (short) Integer.parseInt(input);
75 } catch (NumberFormatException e1) {
76 throw new IllegalArgumentException(
77 "EthType value must be either a string protocol name"
78 + " or a 16-bit protocol value");
79 }
80 }
81 }
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070082}