Merge "Copyright"
[packetcable.git] / packetcable-driver / src / main / java / org / umu / cops / stack / COPSIpv4InInterface.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 import org.umu.cops.stack.COPSObjHeader.CNum;
10 import org.umu.cops.stack.COPSObjHeader.CType;
11
12 /**
13  * COPS IPv4 Input Address (RFC 2748)
14  *
15  * The In-Interface Object is used to identify the incoming interface on
16  * which a particular request applies and the address where the received
17  * message originated. For flows or messages generated from the PEP's
18  * local host, the loop back address and ifindex are used.
19  *
20  * This Interface object is also used to identify the incoming
21  * (receiving) interface via its ifindex. The ifindex may be used to
22  * differentiate between sub-interfaces and unnumbered interfaces (see
23  * RSVP's LIH for an example). When SNMP is supported by the PEP, this
24  * ifindex integer MUST correspond to the same integer value for the
25  * interface in the SNMP MIB-II interface index table.
26  *
27  * Note: The ifindex specified in the In-Interface is typically relative
28  * to the flow of the underlying protocol messages. The ifindex is the
29  * interface on which the protocol message was received.
30  *
31  * C-Num = 3
32  *
33  * C-Type = 1, IPv4 Address + Interface
34  *
35  * 0             1              2             3
36  * +--------------+--------------+--------------+--------------+
37  * |                   IPv4 Address format                     |
38  * +--------------+--------------+--------------+--------------+
39  * |                          ifindex                          |
40  * +--------------+--------------+--------------+--------------+
41  *
42  * For this type of the interface object, the IPv4 address specifies the
43  * IP address that the incoming message came from.
44  */
45 public class COPSIpv4InInterface extends COPSIpv4Interface {
46
47     /**
48      * Constructor generally used for sending messages
49      * @param ifindex - the interface value
50      * @param addr - the IPv4 address
51      * @throws java.lang.IllegalArgumentException
52      */
53     public COPSIpv4InInterface(final COPSIpv4Address addr, final int ifindex) {
54         this(new COPSObjHeader(CNum.ININTF, CType.DEF), addr, ifindex);
55     }
56
57     /**
58      * Constructor generally used when parsing the bytes of an inbound COPS message but can also be used when the
59      * COPSObjHeader information is known
60      * @param objHdr - the object header
61      * @param ifindex - the interface value
62      * @param addr - the IPv4 address
63      * @throws java.lang.IllegalArgumentException
64      */
65     protected COPSIpv4InInterface(final COPSObjHeader objHdr, final COPSIpv4Address addr, final int ifindex) {
66         super(objHdr, addr, ifindex);
67         if (!objHdr.getCNum().equals(CNum.ININTF))
68             throw new IllegalArgumentException("CNum must be of type - " + CNum.ININTF);
69         if (!objHdr.getCType().equals(CType.DEF))
70             throw new IllegalArgumentException("CType must be of type - " + CType.DEF);
71     }
72
73     /**
74      * Creates this object from a byte array
75      * @param objHdrData - the header
76      * @param dataPtr - the data to parse
77      * @return - a new Timer
78      * @throws java.lang.IllegalArgumentException
79      */
80     public static COPSIpv4InInterface parse(final COPSObjHeaderData objHdrData, final byte[] dataPtr) {
81         return new COPSIpv4InInterface(objHdrData.header, COPSIpv4Interface.parseAddress(dataPtr),
82                 COPSIpv4Interface.parseIfIndex(dataPtr));
83     }
84
85     public boolean isInInterface() { return true; }
86 }