The second patch of an estimated 4 to complete the COPS message refactoring as descri...
[packetcable.git] / packetcable-driver / src / main / java / org / umu / cops / stack / COPSIpv6InInterface.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 IPv6 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-Type = 2, IPv6 Address + Interface
32  *
33  * 0             1              2             3
34  * +--------------+--------------+--------------+--------------+
35  * |                                                           |
36  * +                                                           +
37  * |                                                           |
38  * +                    IPv6 Address format                    +
39  * |                                                           |
40  * +                                                           +
41  * |                                                           |
42  * +--------------+--------------+--------------+--------------+
43  * |                          ifindex                          |
44  * +--------------+--------------+--------------+--------------+
45  *
46  * For this type of the interface object, the IPv6 address specifies the
47  * IP address that the incoming message came from. The ifindex is used
48  * to refer to the MIB-II defined local incoming interface on the PEP as
49  * described above.
50  */
51 public class COPSIpv6InInterface extends COPSIpv6Interface {
52
53     /**
54      * Constructor generally used for sending messages
55      * @param ifindex - the interface value
56      * @param addr - the IPv6 address
57      * @throws java.lang.IllegalArgumentException
58      */
59     public COPSIpv6InInterface(final COPSIpv6Address addr, final int ifindex) {
60         super(new COPSObjHeader(CNum.ININTF, CType.STATELESS), addr, ifindex);
61     }
62
63     /**
64      * Constructor generally used when parsing the bytes of an inbound COPS message but can also be used when the
65      * COPSObjHeader information is known
66      * @param objHdr - the object header
67      * @param ifindex - the interface value
68      * @param addr - the IPv6 address
69      * @throws java.lang.IllegalArgumentException
70      */
71     protected COPSIpv6InInterface(final COPSObjHeader objHdr, final COPSIpv6Address addr, final int ifindex) {
72         super(objHdr, addr, ifindex);
73         if (!objHdr.getCNum().equals(CNum.ININTF))
74             throw new IllegalArgumentException("CNum must be of type - " + CNum.ININTF);
75         if (!objHdr.getCType().equals(CType.STATELESS))
76             throw new IllegalArgumentException("CType must be of type - " + CType.STATELESS);
77     }
78
79     /**
80      * Creates this object from a byte array
81      * @param objHdrData - the header
82      * @param dataPtr - the data to parse
83      * @return - a new Timer
84      * @throws java.lang.IllegalArgumentException
85      */
86     public static COPSIpv6InInterface parse(final COPSObjHeaderData objHdrData, final byte[] dataPtr) {
87         return new COPSIpv6InInterface(objHdrData.header, COPSIpv6Interface.parseAddress(dataPtr),
88                 COPSIpv6Interface.parseIfIndex(dataPtr));
89     }
90
91     public boolean isInInterface() { return true; }
92 }
93
94