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 Keep Alive Timer (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.
21 * C-Type = 1, Keep-alive timer value
22 * Timer object used to specify the maximum time interval over which a
23 * COPS message MUST be sent or received. The range of finite timeouts
24 * is 1 to 65535 seconds represented as an unsigned two-octet integer.
25 * The value of zero implies infinity.
27 public class COPSKATimer extends COPSTimer {
30 * Constructor generally used for sending messages
31 * @throws java.lang.IllegalArgumentException
33 public COPSKATimer(final short timeVal) {
34 this((short)0, timeVal);
38 * Constructor to override the reserved member value from 0
39 * @throws java.lang.IllegalArgumentException
41 public COPSKATimer(final short reserved, final short timeVal) {
42 this(new COPSObjHeader(CNum.KA, CType.DEF), reserved, timeVal);
46 * Constructor generally used when parsing the bytes of an inbound COPS message but can also be used when the
47 * COPSObjHeader information is known
48 * @param hdr - the object header
49 * @param reserved - ???
50 * @param timeVal - the timer value
51 * @throws java.lang.IllegalArgumentException
53 protected COPSKATimer(final COPSObjHeader hdr, final short reserved, final short timeVal) {
54 super(hdr, reserved, timeVal);
55 if (!hdr.getCNum().equals(CNum.KA))
56 throw new IllegalArgumentException("Invalid CNum value. Must be " + CNum.KA);
57 if (!hdr.getCType().equals(CType.DEF))
58 throw new IllegalArgumentException("Invalid CType value. Must be " + CType.DEF);
62 * Creates this object from a byte array
63 * @param objHdrData - the header
64 * @param dataPtr - the data to parse
65 * @return - a new Timer
66 * @throws java.lang.IllegalArgumentException
68 public static COPSKATimer parse(final COPSObjHeaderData objHdrData, byte[] dataPtr) {
70 reserved |= ((short) dataPtr[4]) << 8;
71 reserved |= ((short) dataPtr[5]) & 0xFF;
74 timerValue |= ((short) dataPtr[6]) << 8;
75 timerValue |= ((short) dataPtr[7]) & 0xFF;
77 return new COPSKATimer(objHdrData.header, reserved, timerValue);