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