refactoring of listmappingservice into Northbound (future REST) and Southbound (LISP...
[lispflowmapping.git] / mappingservice / api / src / main / java / org / opendaylight / lispflowmapping / type / lisp / MapNotify.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=4 |              Reserved                 | 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 MapNotify {
49
50     /**
51      * P: This is the proxy Map-Reply bit. When set to 1, an ETR sends a
52      * Map-Register message requesting the Map-Server to proxy a Map-Reply. The
53      * Map-Server will send non-authoritative Map-Replies on behalf of the ETR.
54      * Details on this usage can be found in [RFC6833].
55      */
56     private boolean proxyMapReply;
57     /**
58      * M: This is the want-map-notify bit. When set to 1, an ETR is requesting a
59      * Map-Notify message to be returned in response to sending a Map-Register
60      * message. The Map-Notify message sent by a Map-Server is used to
61      * acknowledge receipt of a Map-Register message.
62      */
63     private boolean wantMapNotify;
64
65     /**
66      * Nonce: This 8-octet 'Nonce' field is set to 0 in Map-Register messages.
67      * Since the Map-Register message is authenticated, the 'Nonce' field is not
68      * currently used for any security function but may be in the future as part
69      * of an anti-replay solution.
70      */
71     private long nonce;
72
73     /**
74      * Key ID: This is a configured ID to find the configured Message
75      * Authentication Code (MAC) algorithm and key value used for the
76      * authentication function. See Section 14.4 for codepoint assignments.
77      */
78     private short keyId;
79
80     /**
81      * Authentication Data Length: This is the length in octets of the
82      * 'Authentication Data' field that follows this field. The length of the
83      * 'Authentication Data' field is dependent on the MAC algorithm used. The
84      * length field allows a device that doesn't know the MAC algorithm to
85      * correctly parse the packet. private short authenticationLength;
86      */
87
88     /**
89      * Authentication Data: This is the message digest used from the output of
90      * the MAC algorithm. The entire Map-Register payload is authenticated with
91      * this field preset to 0. After the MAC is computed, it is placed in this
92      * field. Implementations of this specification MUST include support for
93      * HMAC-SHA-1-96 [RFC2404], and support for HMAC-SHA-256-128 [RFC4868] is
94      * RECOMMENDED.
95      */
96     private byte[] authenticationData;
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 MapNotify() {
107         eidToLocatorRecords = new ArrayList<EidToLocatorRecord>();
108         setAuthenticationData(null);
109     }
110
111     public boolean isProxyMapReply() {
112         return proxyMapReply;
113     }
114
115     public MapNotify setProxyMapReply(boolean proxyMapReply) {
116         this.proxyMapReply = proxyMapReply;
117         return this;
118     }
119
120     public boolean isWantMapNotify() {
121         return wantMapNotify;
122     }
123
124     public MapNotify setWantMapNotify(boolean wantMapNotify) {
125         this.wantMapNotify = wantMapNotify;
126         return this;
127     }
128
129     public long getNonce() {
130         return nonce;
131     }
132
133     public MapNotify setNonce(long nonce) {
134         this.nonce = nonce;
135         return this;
136     }
137
138     public short getKeyId() {
139         return keyId;
140     }
141
142     public MapNotify setKeyId(short keyId) {
143         this.keyId = keyId;
144         return this;
145     }
146
147     public byte[] getAuthenticationData() {
148         return authenticationData;
149     }
150
151     public MapNotify setAuthenticationData(byte[] authenticationData) {
152         this.authenticationData = (authenticationData != null) ? authenticationData : NO_AUTHENTICATION_DATA;
153         return this;
154     }
155
156     public List<EidToLocatorRecord> getEidToLocatorRecords() {
157         return eidToLocatorRecords;
158     }
159
160     public void addEidToLocator(EidToLocatorRecord record) {
161         eidToLocatorRecords.add(record);
162     }
163
164     
165
166     public void setFromMapRegister(MapRegister mapRegister) {
167         setNonce(mapRegister.getNonce());
168         setKeyId(mapRegister.getKeyId());
169         byte[] authenticationData = mapRegister.getAuthenticationData();
170         if (authenticationData != null) {
171             authenticationData = authenticationData.clone();
172         }
173         setAuthenticationData(authenticationData);
174
175         for (EidToLocatorRecord eidToLocator : mapRegister.getEidToLocatorRecords()) {
176             addEidToLocator(eidToLocator.clone());
177         }
178     }
179
180     private static byte[] NO_AUTHENTICATION_DATA = new byte[] {};
181 }