2 * Copyright (c) 2003 University of Murcia. All rights reserved.
3 * --------------------------------------------------------------
4 * For more information, please see <http://www.umu.euro6ix.org/>.
7 package org.umu.cops.stack;
10 import org.umu.cops.stack.COPSObjHeader.CNum;
11 import org.umu.cops.stack.COPSObjHeader.CType;
14 * COPS Accounting Timer Object (RFC 2748)
16 * Times are encoded as 2 octet integer values and are in units of
17 * seconds. The timer value is treated as a delta.
20 * C-Type = 1, Accounting timer value
22 * Optional timer value used to determine the minimum interval between
23 * periodic accounting type reports. It is used by the PDP to describe
24 * to the PEP an acceptable interval between unsolicited accounting
25 * updates via Report messages where applicable. It provides a method
26 * for the PDP to control the amount of accounting traffic seen by the
27 * network. The range of finite time values is 1 to 65535 seconds
28 * represented as an unsigned two-octet integer. A value of zero means
29 * there SHOULD be no unsolicited accounting updates.
31 public class COPSAcctTimer extends COPSTimer {
34 * Constructor generally used for sending messages
35 * @param timeVal - the timer value
36 * @throws java.lang.IllegalArgumentException when the id parameter is null
38 public COPSAcctTimer(final short timeVal) {
39 this((short)0, timeVal);
43 * Constructor generally used for sending messages with some reserved value
44 * @param reserved - ???
45 * @param timeVal - the timer value
46 * @throws java.lang.IllegalArgumentException when the id parameter is null
48 protected COPSAcctTimer(final short reserved, final short timeVal) {
49 this(new COPSObjHeader(CNum.ACCT_TIMER, CType.DEF), reserved, timeVal);
53 * Constructor generally used when parsing the bytes of an inbound COPS message but can also be used when the
54 * COPSObjHeader information is known
55 * @param header - the object header
56 * @param reserved - ???
57 * @param timeVal - the timer value
58 * @throws java.lang.IllegalArgumentException
60 protected COPSAcctTimer(final COPSObjHeader header, final short reserved, final short timeVal) {
61 super(header, reserved, timeVal);
62 if (!header.getCNum().equals(CNum.ACCT_TIMER))
63 throw new IllegalArgumentException("Invalid CNum value. Must be " + CNum.ACCT_TIMER);
64 if (!header.getCType().equals(CType.DEF))
65 throw new IllegalArgumentException("Invalid CType value. Must be " + CType.DEF);
69 * Creates this object from a byte array
70 * @param objHdrData - the header
71 * @param dataPtr - the data to parse
72 * @return - a new Timer
73 * @throws java.lang.IllegalArgumentException
75 public static COPSAcctTimer parse(final COPSObjHeaderData objHdrData, byte[] dataPtr) {
77 reserved |= ((short) dataPtr[4]) << 8;
78 reserved |= ((short) dataPtr[5]) & 0xFF;
81 timerValue |= ((short) dataPtr[6]) << 8;
82 timerValue |= ((short) dataPtr[7]) & 0xFF;
84 return new COPSAcctTimer(objHdrData.header, reserved, timerValue);