blob: 9687e37787be2f450bc477034f42452323db2250 [file] [log] [blame]
Ari Saha79d7c252015-06-26 10:31:48 -07001/*
2 *
3 * * Copyright 2015 AT&T Foundry
4 * *
5 * * Licensed under the Apache License, Version 2.0 (the "License");
6 * * you may not use this file except in compliance with the License.
7 * * You may obtain a copy of the License at
8 * *
9 * * http://www.apache.org/licenses/LICENSE-2.0
10 * *
11 * * Unless required by applicable law or agreed to in writing, software
12 * * distributed under the License is distributed on an "AS IS" BASIS,
13 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * * See the License for the specific language governing permissions and
15 * * limitations under the License.
16 *
17 */
18
Jonathan Hart4a60bb32015-06-30 15:31:20 -070019package org.onlab.packet;
Ari Saha79d7c252015-06-26 10:31:48 -070020
Jonathan Hart4a60bb32015-06-30 15:31:20 -070021/**
22 * An attribute in a RADIUS packet.
23 */
Ari Saha79d7c252015-06-26 10:31:48 -070024public class RADIUSAttribute {
25 protected byte type;
26 protected byte length;
27 protected byte[] value;
28
Jonathan Hart4a60bb32015-06-30 15:31:20 -070029 // RADIUS attribute types
Ari Saha79d7c252015-06-26 10:31:48 -070030 public static final byte RADIUS_ATTR_USERNAME = 1;
31 public static final byte RADIUS_ATTR_NAS_IP = 4;
32 public static final byte RADIUS_ATTR_NAS_PORT = 5;
33 public static final byte RADIUS_ATTR_FRAMED_MTU = 12;
34 public static final byte RADIUS_ATTR_STATE = 24;
35 public static final byte RADIUS_ATTR_VENDOR_SPECIFIC = 26;
36 public static final byte RADIUS_ATTR_CALLING_STATION_ID = 31;
37 public static final byte RADIUS_ATTR_NAS_ID = 32;
38 public static final byte RADIUS_ATTR_ACCT_SESSION_ID = 44;
39 public static final byte RADIUS_ATTR_NAS_PORT_TYPE = 61;
40 public static final byte RADIUS_ATTR_EAP_MESSAGE = 79;
41 public static final byte RADIUS_ATTR_MESSAGE_AUTH = 80;
42 public static final byte RADIUS_ATTR_NAS_PORT_ID = 87;
43
Jonathan Hart4a60bb32015-06-30 15:31:20 -070044 /**
45 * Default constructor.
46 */
Ari Saha79d7c252015-06-26 10:31:48 -070047 public RADIUSAttribute() {
48 }
49
Jonathan Hart4a60bb32015-06-30 15:31:20 -070050 /**
51 * Constructs a RADIUS attribute with the give type, length and value.
52 *
53 * @param type type
54 * @param length length
55 * @param value value
56 */
Ari Saha79d7c252015-06-26 10:31:48 -070057 public RADIUSAttribute(final byte type, final byte length, final byte[] value) {
58 this.type = type;
59 this.length = length;
60 this.value = value;
61 }
62
Jonathan Hart4a60bb32015-06-30 15:31:20 -070063 /**
64 * Checks if the attribute type is valid.
65 *
66 * @return whether the type is valid or not
67 */
Ari Saha79d7c252015-06-26 10:31:48 -070068 public boolean isValidType() {
69 return this.type == RADIUS_ATTR_USERNAME ||
70 this.type == RADIUS_ATTR_NAS_IP ||
71 this.type == RADIUS_ATTR_NAS_PORT ||
72 this.type == RADIUS_ATTR_VENDOR_SPECIFIC ||
73 this.type == RADIUS_ATTR_CALLING_STATION_ID ||
74 this.type == RADIUS_ATTR_NAS_ID ||
75 this.type == RADIUS_ATTR_ACCT_SESSION_ID ||
76 this.type == RADIUS_ATTR_NAS_PORT_TYPE ||
77 this.type == RADIUS_ATTR_EAP_MESSAGE ||
78 this.type == RADIUS_ATTR_MESSAGE_AUTH ||
79 this.type == RADIUS_ATTR_NAS_PORT_ID;
80 }
81
82 /**
Jonathan Hart4a60bb32015-06-30 15:31:20 -070083 * Gets the attribute type.
84 *
Ari Saha79d7c252015-06-26 10:31:48 -070085 * @return the type
86 */
87 public byte getType() {
88 return this.type;
89 }
90
91 /**
Jonathan Hart4a60bb32015-06-30 15:31:20 -070092 * Sets the attribute type.
93 *
94 * @param type the code to set
Ari Saha79d7c252015-06-26 10:31:48 -070095 * @return this
96 */
97 public RADIUSAttribute setType(final byte type) {
98 this.type = type;
99 return this;
100 }
101
102 /**
Jonathan Hart4a60bb32015-06-30 15:31:20 -0700103 * Gets the attribute length.
104 *
Ari Saha79d7c252015-06-26 10:31:48 -0700105 * @return the length
106 */
107 public byte getLength() {
108 return this.length;
109 }
110
111 /**
Jonathan Hart4a60bb32015-06-30 15:31:20 -0700112 * Sets the attribute length.
113 *
114 * @param length the length to set
Ari Saha79d7c252015-06-26 10:31:48 -0700115 * @return this
116 */
117 public RADIUSAttribute setLength(final byte length) {
118 this.length = length;
119 return this;
120 }
121
122 /**
Jonathan Hart4a60bb32015-06-30 15:31:20 -0700123 * Gets the attribute value.
124 *
Ari Saha79d7c252015-06-26 10:31:48 -0700125 * @return the value
126 */
127 public byte[] getValue() {
128 return this.value;
129 }
130
131 /**
Jonathan Hart4a60bb32015-06-30 15:31:20 -0700132 * Sets the attribute value.
133 *
134 * @param value the data to set
Ari Saha79d7c252015-06-26 10:31:48 -0700135 * @return this
136 */
137 public RADIUSAttribute setValue(final byte[] value) {
138 this.value = value;
139 return this;
140 }
141
Ari Saha79d7c252015-06-26 10:31:48 -0700142}