Created a client-type enumeration as part of the original COPS refactor and have...
[packetcable.git] / packetcable-driver / src / main / java / org / umu / cops / stack / COPSAcctTimer.java
1 /*
2  * Copyright (c) 2003 University of Murcia.  All rights reserved.
3  * --------------------------------------------------------------
4  * For more information, please see <http://www.umu.euro6ix.org/>.
5  */
6
7 package org.umu.cops.stack;
8
9
10 import org.umu.cops.stack.COPSObjHeader.CNum;
11 import org.umu.cops.stack.COPSObjHeader.CType;
12
13 /**
14  * COPS Accounting Timer Object (RFC 2748)
15  *
16  * Times are encoded as 2 octet integer values and are in units of
17  * seconds.  The timer value is treated as a delta.
18  *
19  * C-Num = 15,
20  * C-Type = 1, Accounting timer value
21  *
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.
30  */
31 public class COPSAcctTimer extends COPSTimer {
32
33     /**
34      * Constructor generally used for sending messages
35      * @param timeVal - the timer value
36      * @throws java.lang.IllegalArgumentException when the id parameter is null
37      */
38     public COPSAcctTimer(final short timeVal) {
39         this((short)0, timeVal);
40     }
41
42     /**
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
47      */
48     protected COPSAcctTimer(final short reserved, final short timeVal) {
49         this(new COPSObjHeader(CNum.ACCT_TIMER, CType.DEF), reserved, timeVal);
50     }
51
52     /**
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
59      */
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);
66     }
67
68     /**
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
74      */
75     public static COPSAcctTimer parse(final COPSObjHeaderData objHdrData, byte[] dataPtr) {
76         short reserved = 0;
77         reserved |= ((short) dataPtr[4]) << 8;
78         reserved |= ((short) dataPtr[5]) & 0xFF;
79
80         short timerValue = 0;
81         timerValue |= ((short) dataPtr[6]) << 8;
82         timerValue |= ((short) dataPtr[7]) & 0xFF;
83
84         return new COPSAcctTimer(objHdrData.header, reserved, timerValue);
85     }
86
87 }
88