Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 1 | /* |
| 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 Hart | 4a60bb3 | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 19 | package org.onlab.packet; |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 20 | |
Jonathan Hart | 4a60bb3 | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 21 | /** |
| 22 | * An attribute in a RADIUS packet. |
| 23 | */ |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 24 | public class RADIUSAttribute { |
| 25 | protected byte type; |
| 26 | protected byte length; |
| 27 | protected byte[] value; |
| 28 | |
Jonathan Hart | 4a60bb3 | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 29 | // RADIUS attribute types |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 30 | 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 Hart | 4a60bb3 | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 44 | /** |
| 45 | * Default constructor. |
| 46 | */ |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 47 | public RADIUSAttribute() { |
| 48 | } |
| 49 | |
Jonathan Hart | 4a60bb3 | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 50 | /** |
| 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 Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 57 | 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 Hart | 4a60bb3 | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 63 | /** |
| 64 | * Checks if the attribute type is valid. |
| 65 | * |
| 66 | * @return whether the type is valid or not |
| 67 | */ |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 68 | 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 Hart | 4a60bb3 | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 83 | * Gets the attribute type. |
| 84 | * |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 85 | * @return the type |
| 86 | */ |
| 87 | public byte getType() { |
| 88 | return this.type; |
| 89 | } |
| 90 | |
| 91 | /** |
Jonathan Hart | 4a60bb3 | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 92 | * Sets the attribute type. |
| 93 | * |
| 94 | * @param type the code to set |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 95 | * @return this |
| 96 | */ |
| 97 | public RADIUSAttribute setType(final byte type) { |
| 98 | this.type = type; |
| 99 | return this; |
| 100 | } |
| 101 | |
| 102 | /** |
Jonathan Hart | 4a60bb3 | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 103 | * Gets the attribute length. |
| 104 | * |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 105 | * @return the length |
| 106 | */ |
| 107 | public byte getLength() { |
| 108 | return this.length; |
| 109 | } |
| 110 | |
| 111 | /** |
Jonathan Hart | 4a60bb3 | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 112 | * Sets the attribute length. |
| 113 | * |
| 114 | * @param length the length to set |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 115 | * @return this |
| 116 | */ |
| 117 | public RADIUSAttribute setLength(final byte length) { |
| 118 | this.length = length; |
| 119 | return this; |
| 120 | } |
| 121 | |
| 122 | /** |
Jonathan Hart | 4a60bb3 | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 123 | * Gets the attribute value. |
| 124 | * |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 125 | * @return the value |
| 126 | */ |
| 127 | public byte[] getValue() { |
| 128 | return this.value; |
| 129 | } |
| 130 | |
| 131 | /** |
Jonathan Hart | 4a60bb3 | 2015-06-30 15:31:20 -0700 | [diff] [blame] | 132 | * Sets the attribute value. |
| 133 | * |
| 134 | * @param value the data to set |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 135 | * @return this |
| 136 | */ |
| 137 | public RADIUSAttribute setValue(final byte[] value) { |
| 138 | this.value = value; |
| 139 | return this; |
| 140 | } |
| 141 | |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 142 | } |