blob: 0bd98f1dbb144dc03f6bdb192d53cb8b5370dbea [file] [log] [blame]
Daniele Moro94660a02019-12-02 12:02:07 -08001/*
Joey Armstronga68e7852024-01-28 13:27:02 -05002 * Copyright 2019-2024 Open Networking Foundation (ONF) and the ONF Contributors
Daniele Moro94660a02019-12-02 12:02:07 -08003 *
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
17package org.opencord.bng.packets;
18
19/**
20 * PPP Protocol type enumerator.
21 */
22public enum PppProtocolType {
23 LCP(0xc021, "lcp", true),
24 IPCP(0x8021, "ipcp", true),
25 PAP(0xc023, "pap", true),
26 CHAP(0xc223, "chap", true),
27 IPv4(0x0021, "ipv4", false),
28 IPv6(0x0057, "ipv6", false),
29 NO_PROTOCOL(0, "no_proto", true);
30
31 private final short code;
32 private final String type;
33 private final boolean control;
34
35 /**
36 * Constructs new PPP Protocol types.
37 *
38 * @param code The PPP Protocol type.
39 * @param type Textual representation of the PPP Protocol type.
40 * @param control True if is control plane packet, false otherwise.
41 */
42 PppProtocolType(int code, String type, boolean control) {
43 this.code = (short) (code & 0xFFFF);
44 this.type = type;
45 this.control = control;
46 }
47
48 /**
49 * Lookups for a PPP Protocol type.
50 *
51 * @param code The code for PPP protocol.
52 * @return The PPPProtocol type
53 */
54 public static PppProtocolType lookup(short code) {
55 for (PppProtocolType type : PppProtocolType.values()) {
56 if (code == type.code()) {
57 return type;
58 }
59 }
60 return NO_PROTOCOL;
61 }
62
63 /**
64 * Returns code associated to the PPP protocol.
65 *
66 * @return The code for PPP protocol
67 */
68 public short code() {
69 return this.code;
70 }
71
72 /**
73 * Returns the string representation of the PPP protocol.
74 *
75 * @return The PPP protocol string representation
76 */
77 public String type() {
78 return this.type;
79 }
80
81 /**
82 * Checks if the PPP protocol is carrying control plane packets.
83 *
84 * @return True if the PPP protocol is for control plane packets, false
85 * otherwise
86 */
87 public boolean control() {
88 return this.control;
89 }
90}