changed license year
[lispflowmapping.git] / mappingservice / api / src / main / java / org / opendaylight / lispflowmapping / type / lisp / MapRegister.java
1 /*
2  * Copyright (c) 2014 Contextream, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.lispflowmapping.type.lisp;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14 import javax.xml.bind.annotation.XmlAccessType;
15 import javax.xml.bind.annotation.XmlAccessorType;
16 import javax.xml.bind.annotation.XmlElement;
17 import javax.xml.bind.annotation.XmlRootElement;
18
19 /**
20  * <pre>
21  *         0                   1                   2                   3
22  *         0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
23  *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
24  *        |Type=3 |P|            Reserved               |M| Record Count  |
25  *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
26  *        |                         Nonce . . .                           |
27  *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
28  *        |                         . . . Nonce                           |
29  *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30  *        |            Key ID             |  Authentication Data Length   |
31  *        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32  *        ~                     Authentication Data                       ~
33  *    +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34  *    |   |                          Record TTL                           |
35  *    |   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36  *    R   | Locator Count | EID mask-len  | ACT |A|      Reserved         |
37  *    e   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38  *    c   | Rsvd  |  Map-Version Number   |        EID-Prefix-AFI         |
39  *    o   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40  *    r   |                          EID-Prefix                           |
41  *    d   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42  *    |  /|    Priority   |    Weight     |  M Priority   |   M Weight    |
43  *    | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44  *    | o |        Unused Flags     |L|p|R|           Loc-AFI             |
45  *    | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46  *    |  \|                             Locator                           |
47  *    +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48  * </pre>
49  * 
50  * @author gmainzer
51  * 
52  */
53
54 @XmlRootElement
55 @XmlAccessorType(XmlAccessType.NONE)
56 public class MapRegister {
57     /**
58      * P: This is the proxy Map-Reply bit. When set to 1, an ETR sends a
59      * Map-Register message requesting the Map-Server to proxy a Map-Reply. The
60      * Map-Server will send non-authoritative Map-Replies on behalf of the ETR.
61      * Details on this usage can be found in [RFC6833].
62      */
63     @XmlElement
64     private boolean proxyMapReply;
65     /**
66      * M: This is the want-map-notify bit. When set to 1, an ETR is requesting a
67      * Map-Notify message to be returned in response to sending a Map-Register
68      * message. The Map-Notify message sent by a Map-Server is used to
69      * acknowledge receipt of a Map-Register message.
70      */
71     private boolean wantMapNotify;
72
73     /**
74      * Nonce: This 8-octet 'Nonce' field is set to 0 in Map-Register messages.
75      * Since the Map-Register message is authenticated, the 'Nonce' field is not
76      * currently used for any security function but may be in the future as part
77      * of an anti-replay solution.
78      */
79     @XmlElement
80     private long nonce;
81
82     /**
83      * Key ID: This is a configured ID to find the configured Message
84      * Authentication Code (MAC) algorithm and key value used for the
85      * authentication function. See Section 14.4 for codepoint assignments.
86      */
87     @XmlElement
88     private short keyId;
89
90     /**
91      * Authentication Data Length: This is the length in octets of the
92      * 'Authentication Data' field that follows this field. The length of the
93      * 'Authentication Data' field is dependent on the MAC algorithm used. The
94      * length field allows a device that doesn't know the MAC algorithm to
95      * correctly parse the packet. private short authenticationLength;
96      */
97
98     /**
99      * Authentication Data: This is the message digest used from the output of
100      * the MAC algorithm. The entire Map-Register payload is authenticated with
101      * this field preset to 0. After the MAC is computed, it is placed in this
102      * field. Implementations of this specification MUST include support for
103      * HMAC-SHA-1-96 [RFC2404], and support for HMAC-SHA-256-128 [RFC4868] is
104      * RECOMMENDED.
105      */
106
107     private byte[] authenticationData;
108
109     /**
110      * The representation in bytes of the map register.
111      */
112     private byte[] mapRegisterBytes;
113
114     /**
115      * Record Count: This is the number of records in this Map-Register message.
116      * A record is comprised of that portion of the packet labeled 'Record'
117      * above and occurs the number of times equal to Record Count.
118      * 
119      * private byte recordCount;
120      */
121     @XmlElement
122     private List<EidToLocatorRecord> eidToLocatorRecords;
123
124     public MapRegister() {
125         eidToLocatorRecords = new ArrayList<EidToLocatorRecord>();
126         setAuthenticationData(null);
127     }
128
129     public void addEidToLocator(EidToLocatorRecord record) {
130         eidToLocatorRecords.add(record);
131     }
132
133     public List<EidToLocatorRecord> getEidToLocatorRecords() {
134         return eidToLocatorRecords;
135     }
136
137     public boolean isProxyMapReply() {
138         return proxyMapReply;
139     }
140
141     public void setProxyMapReply(boolean proxyMapReply) {
142         this.proxyMapReply = proxyMapReply;
143     }
144
145     public byte[] getAuthenticationData() {
146         return authenticationData;
147     }
148
149     public MapRegister setAuthenticationData(byte[] authenticationData) {
150         this.authenticationData = (authenticationData != null) ? authenticationData : NO_AUTHENTICATION_DATA;
151         return this;
152     }
153
154     public boolean isWantMapNotify() {
155         return wantMapNotify;
156     }
157
158     public MapRegister setWantMapNotify(boolean wantMapNotify) {
159         this.wantMapNotify = wantMapNotify;
160         return this;
161     }
162
163     public long getNonce() {
164         return nonce;
165     }
166
167     public MapRegister setNonce(long nonce) {
168         this.nonce = nonce;
169         return this;
170     }
171
172     public short getKeyId() {
173         return keyId;
174     }
175
176     public MapRegister setKeyId(short keyId) {
177         this.keyId = keyId;
178         return this;
179     }
180
181     public byte[] getMapRegisterBytes() {
182         return mapRegisterBytes;
183     }
184
185     public MapRegister setMapRegisterBytes(byte[] mapRegisterBytes) {
186         this.mapRegisterBytes = mapRegisterBytes;
187         return this;
188     }
189
190     private static byte[] NO_AUTHENTICATION_DATA = new byte[] {};
191 }