Jian Li
Committed by Thomas Vachuska

[ONOS-4718] Add more LCAF type address with augmented LCAF class

In this commit, we added List Type, Instance ID Type, Source/Dest
Key Type and Application Data Type LCAF address classes.

Change-Id: I39881714069a32c52474ee82f8a9acdfcdc862b7
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.lisp.msg.types;
17 +
18 +import java.util.Objects;
19 +
20 +import static com.google.common.base.MoreObjects.toStringHelper;
21 +
22 +/**
23 + * Application data type LCAF address class.
24 + *
25 + * Application data type is defined in draft-ietf-lisp-lcaf-13
26 + * https://tools.ietf.org/html/draft-ietf-lisp-lcaf-13#page-26
27 + *
28 + * 0 1 2 3
29 + * 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
30 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31 + * | AFI = 16387 | Rsvd1 | Flags |
32 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 + * | Type = 4 | Rsvd2 | 12 + n |
34 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 + * | IP TOS, IPv6 TC, or Flow Label | Protocol |
36 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 + * | Local Port (lower-range) | Local Port (upper-range) |
38 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 + * | Remote Port (lower-range) | Remote Port (upper-range) |
40 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 + * | AFI = x | Address ... |
42 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 + */
44 +public class LispAppDataLcafAddress extends LispLcafAddress {
45 +
46 + private final byte protocol;
47 + private final int ipTos;
48 + private final short localPort;
49 + private final short remotePort;
50 + private LispAfiAddress address;
51 +
52 + /**
53 + * Initializes application data type LCAF address.
54 + */
55 + public LispAppDataLcafAddress() {
56 + super(LispCanonicalAddressFormatEnum.APPLICATION_DATA);
57 + this.protocol = 0;
58 + this.ipTos = 0;
59 + this.localPort = 0;
60 + this.remotePort = 0;
61 + }
62 +
63 + /**
64 + * Initializes application data type LCAF address.
65 + *
66 + * @param protocol protocol number
67 + * @param ipTos ip type of service
68 + * @param localPort local port number
69 + * @param remotePort remote port number
70 + * @param address address
71 + */
72 + public LispAppDataLcafAddress(byte protocol, int ipTos, short localPort, short remotePort,
73 + LispAfiAddress address) {
74 + super(LispCanonicalAddressFormatEnum.APPLICATION_DATA);
75 + this.protocol = protocol;
76 + this.ipTos = ipTos;
77 + this.localPort = localPort;
78 + this.remotePort = remotePort;
79 + this.address = address;
80 + }
81 +
82 + /**
83 + * Obtains protocol number.
84 + *
85 + * @return protocol number
86 + */
87 + public byte getProtocol() {
88 + return protocol;
89 + }
90 +
91 + /**
92 + * Obtains IP type of service.
93 + *
94 + * @return IP type of service
95 + */
96 + public int getIpTos() {
97 + return ipTos;
98 + }
99 +
100 + /**
101 + * Obtains local port number.
102 + *
103 + * @return local port number
104 + */
105 + public short getLocalPort() {
106 + return localPort;
107 + }
108 +
109 + /**
110 + * Obtains remote port number.
111 + *
112 + * @return remote port number
113 + */
114 + public short getRemotePort() {
115 + return remotePort;
116 + }
117 +
118 + /**
119 + * Obtains address.
120 + *
121 + * @return address
122 + */
123 + public LispAfiAddress getAddress() {
124 + return address;
125 + }
126 +
127 + @Override
128 + public int hashCode() {
129 + final int prime = 31;
130 + int result = super.hashCode();
131 + result = prime * result + ((address == null) ? 0 : address.hashCode());
132 + result = prime * result + protocol;
133 + result = prime * result + ipTos;
134 + result = prime * result + localPort;
135 + result = prime * result + remotePort;
136 + return result;
137 + }
138 +
139 + @Override
140 + public boolean equals(Object obj) {
141 + if (this == obj) {
142 + return true;
143 + }
144 +
145 + if (obj instanceof LispAppDataLcafAddress) {
146 + final LispAppDataLcafAddress other = (LispAppDataLcafAddress) obj;
147 + return Objects.equals(this.address, other.address) &&
148 + Objects.equals(this.protocol, other.protocol) &&
149 + Objects.equals(this.ipTos, other.ipTos) &&
150 + Objects.equals(this.localPort, other.localPort) &&
151 + Objects.equals(this.remotePort, other.remotePort);
152 + }
153 + return false;
154 + }
155 +
156 + @Override
157 + public String toString() {
158 + return toStringHelper(this)
159 + .add("address", address)
160 + .add("protocol", protocol)
161 + .add("ip type of service", ipTos)
162 + .add("local port number", localPort)
163 + .add("remote port number", remotePort)
164 + .toString();
165 + }
166 +}
...@@ -21,22 +21,104 @@ import static com.google.common.base.MoreObjects.toStringHelper; ...@@ -21,22 +21,104 @@ import static com.google.common.base.MoreObjects.toStringHelper;
21 21
22 /** 22 /**
23 * LISP Canonical Address Formatted address class. 23 * LISP Canonical Address Formatted address class.
24 + *
25 + * 0 1 2 3
26 + * 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
27 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
28 + * | AFI = 16387 | Rsvd1 | Flags |
29 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30 + * | Type | Rsvd2 | Length |
31 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
24 */ 32 */
25 public class LispLcafAddress extends LispAfiAddress { 33 public class LispLcafAddress extends LispAfiAddress {
26 34
27 protected final LispCanonicalAddressFormatEnum lcafType; 35 protected final LispCanonicalAddressFormatEnum lcafType;
28 - protected final byte value; 36 + protected final byte reserved1;
37 + protected final byte reserved2;
38 + protected final byte flag;
39 + protected final byte length;
40 +
41 + /**
42 + * Initializes LCAF address.
43 + *
44 + * @param lcafType LCAF type
45 + * @param reserved1 reserved1 field
46 + * @param reserved2 reserved2 field
47 + * @param flag flag field
48 + * @param length length field
49 + */
50 + protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType,
51 + byte reserved1, byte reserved2, byte flag, byte length) {
52 + super(AddressFamilyIdentifierEnum.LCAF);
53 + this.lcafType = lcafType;
54 + this.reserved1 = reserved1;
55 + this.reserved2 = reserved2;
56 + this.flag = flag;
57 + this.length = length;
58 + }
59 +
60 + /**
61 + * Initializes LCAF address.
62 + *
63 + * @param lcafType LCAF type
64 + * @param reserved2 reserved2 field
65 + * @param flag flag field
66 + * @param length length field
67 + */
68 + protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType,
69 + byte reserved2, byte flag, byte length) {
70 + super(AddressFamilyIdentifierEnum.LCAF);
71 + this.lcafType = lcafType;
72 + this.reserved2 = reserved2;
73 + this.flag = flag;
74 + this.length = length;
75 + this.reserved1 = 0;
76 + }
77 +
78 + /**
79 + * Initializes LCAF address.
80 + *
81 + * @param lcafType LCAF type
82 + * @param reserved2 reserved2 field
83 + * @param length length field
84 + */
85 + protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType,
86 + byte reserved2, byte length) {
87 + super(AddressFamilyIdentifierEnum.LCAF);
88 + this.lcafType = lcafType;
89 + this.reserved2 = reserved2;
90 + this.length = length;
91 + this.reserved1 = 0;
92 + this.flag = 0;
93 + }
29 94
30 /** 95 /**
31 * Initializes LCAF address. 96 * Initializes LCAF address.
32 * 97 *
33 * @param lcafType LCAF type 98 * @param lcafType LCAF type
34 - * @param value LCAF value 99 + * @param reserved2 reserved2 field
35 */ 100 */
36 - protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType, byte value) { 101 + protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType, byte reserved2) {
37 super(AddressFamilyIdentifierEnum.LCAF); 102 super(AddressFamilyIdentifierEnum.LCAF);
38 this.lcafType = lcafType; 103 this.lcafType = lcafType;
39 - this.value = value; 104 + this.reserved2 = reserved2;
105 + this.reserved1 = 0;
106 + this.flag = 0;
107 + this.length = 0;
108 + }
109 +
110 + /**
111 + * Initializes LCAF address.
112 + *
113 + * @param lcafType LCAF type
114 + */
115 + protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType) {
116 + super(AddressFamilyIdentifierEnum.LCAF);
117 + this.lcafType = lcafType;
118 + this.reserved1 = 0;
119 + this.reserved2 = 0;
120 + this.flag = 0;
121 + this.length = 0;
40 } 122 }
41 123
42 /** 124 /**
...@@ -49,12 +131,39 @@ public class LispLcafAddress extends LispAfiAddress { ...@@ -49,12 +131,39 @@ public class LispLcafAddress extends LispAfiAddress {
49 } 131 }
50 132
51 /** 133 /**
52 - * Obtains LCAF value. 134 + * Obtains LCAF reserved1 value.
135 + *
136 + * @return LCAF reserved1 value
137 + */
138 + public byte getReserved1() {
139 + return reserved1;
140 + }
141 +
142 + /**
143 + * Obtains LCAF reserved2 value.
144 + *
145 + * @return LCAF reserved2 value
146 + */
147 + public byte getReserved2() {
148 + return reserved2;
149 + }
150 +
151 + /**
152 + * Obtains LCAF flag value.
153 + *
154 + * @return LCAF flag value
155 + */
156 + public byte getFlag() {
157 + return flag;
158 + }
159 +
160 + /**
161 + * Obtains LCAF length value.
53 * 162 *
54 - * @return LCAF value 163 + * @return LCAF length value
55 */ 164 */
56 - public byte getValue() { 165 + public byte getLength() {
57 - return value; 166 + return length;
58 } 167 }
59 168
60 @Override 169 @Override
...@@ -62,7 +171,10 @@ public class LispLcafAddress extends LispAfiAddress { ...@@ -62,7 +171,10 @@ public class LispLcafAddress extends LispAfiAddress {
62 final int prime = 31; 171 final int prime = 31;
63 int result = super.hashCode(); 172 int result = super.hashCode();
64 result = prime * result + ((lcafType == null) ? 0 : lcafType.hashCode()); 173 result = prime * result + ((lcafType == null) ? 0 : lcafType.hashCode());
65 - result = prime * result + value; 174 + result = prime * result + reserved1;
175 + result = prime * result + reserved2;
176 + result = prime * result + flag;
177 + result = prime * result + length;
66 return result; 178 return result;
67 } 179 }
68 180
...@@ -75,7 +187,10 @@ public class LispLcafAddress extends LispAfiAddress { ...@@ -75,7 +187,10 @@ public class LispLcafAddress extends LispAfiAddress {
75 if (obj instanceof LispLcafAddress) { 187 if (obj instanceof LispLcafAddress) {
76 final LispLcafAddress other = (LispLcafAddress) obj; 188 final LispLcafAddress other = (LispLcafAddress) obj;
77 return Objects.equals(this.lcafType, other.lcafType) && 189 return Objects.equals(this.lcafType, other.lcafType) &&
78 - Objects.equals(this.value, other.value); 190 + Objects.equals(this.reserved1, other.reserved1) &&
191 + Objects.equals(this.reserved2, other.reserved2) &&
192 + Objects.equals(this.flag, other.flag) &&
193 + Objects.equals(this.length, other.length);
79 } 194 }
80 return false; 195 return false;
81 } 196 }
...@@ -84,7 +199,10 @@ public class LispLcafAddress extends LispAfiAddress { ...@@ -84,7 +199,10 @@ public class LispLcafAddress extends LispAfiAddress {
84 public String toString() { 199 public String toString() {
85 return toStringHelper(this) 200 return toStringHelper(this)
86 .add("lcafType", lcafType) 201 .add("lcafType", lcafType)
87 - .add("lcafValue", value) 202 + .add("reserved1", reserved1)
203 + .add("reserved2", reserved2)
204 + .add("flag", flag)
205 + .add("length", length)
88 .toString(); 206 .toString();
89 } 207 }
90 } 208 }
......
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.lisp.msg.types;
17 +
18 +import java.util.List;
19 +import java.util.Objects;
20 +
21 +import static com.google.common.base.MoreObjects.toStringHelper;
22 +
23 +/**
24 + * List type LCAF address class.
25 + *
26 + * List type is defined in draft-ietf-lisp-lcaf-13
27 + * https://tools.ietf.org/html/draft-ietf-lisp-lcaf-13#page-21
28 + *
29 + * 0 1 2 3
30 + * 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
31 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 + * | AFI = 16387 | Rsvd1 | Flags |
33 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 + * | Type = 1 | Rsvd2 | 2 + 4 + 2 + 16 |
35 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 + * | AFI = 1 | IPv4 Address ... |
37 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + * | ... IPv4 Address | AFI = 2 |
39 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + * | IPv6 Address ... |
41 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 + * | ... IPv6 Address ... |
43 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 + * | ... IPv6 Address ... |
45 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 + * | ... IPv6 Address |
47 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 + */
49 +public class LispListLcafAddress extends LispLcafAddress {
50 +
51 + private static final byte LENGTH = 24;
52 + List<LispAfiAddress> addresses;
53 +
54 + /**
55 + * Initializes list type LCAF address.
56 + *
57 + * @param addresses a set of IPv4 and IPv6 addresses
58 + */
59 + public LispListLcafAddress(List<LispAfiAddress> addresses) {
60 + super(LispCanonicalAddressFormatEnum.LIST, LENGTH);
61 + }
62 +
63 + /**
64 + * Obtains a set of AFI addresses including IPv4 and IPv6.
65 + *
66 + * @return a set of AFI addresses
67 + */
68 + public List<LispAfiAddress> getAddresses() {
69 + return addresses;
70 + }
71 +
72 + @Override
73 + public int hashCode() {
74 + final int prime = 31;
75 + int result = super.hashCode();
76 + result = prime * result + ((addresses == null) ? 0 : addresses.hashCode());
77 + return result;
78 + }
79 +
80 + @Override
81 + public boolean equals(Object obj) {
82 + if (this == obj) {
83 + return true;
84 + }
85 +
86 + if (obj instanceof LispListLcafAddress) {
87 + final LispListLcafAddress other = (LispListLcafAddress) obj;
88 + return Objects.equals(this.addresses, other.addresses);
89 + }
90 + return false;
91 + }
92 +
93 + @Override
94 + public String toString() {
95 + return toStringHelper(this)
96 + .add("addresses", addresses)
97 + .toString();
98 + }
99 +}
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.lisp.msg.types;
17 +
18 +import java.util.Objects;
19 +
20 +import static com.google.common.base.MoreObjects.toStringHelper;
21 +
22 +/**
23 + * Instance ID type LCAF address class.
24 + * Instance ID type is defined in draft-ietf-lisp-lcaf-13
25 + * https://tools.ietf.org/html/draft-ietf-lisp-lcaf-13#page-7
26 + *
27 + * 0 1 2 3
28 + * 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
29 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30 + * | AFI = 16387 | Rsvd1 | Flags |
31 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 + * | Type = 2 | IID mask-len | 4 + n |
33 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 + * | Instance ID |
35 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 + * | AFI = x | Address ... |
37 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + */
39 +public class LispSegmentLcafAddress extends LispLcafAddress {
40 +
41 + private final LispAfiAddress address;
42 + private final int instanceId;
43 +
44 + /**
45 + * Initializes segment type LCAF address.
46 + *
47 + * @param idMaskLength Id mask length
48 + * @param instanceId instance id
49 + * @param address address
50 + */
51 + public LispSegmentLcafAddress(byte idMaskLength, int instanceId, LispAfiAddress address) {
52 + super(LispCanonicalAddressFormatEnum.SEGMENT, idMaskLength);
53 + this.address = address;
54 + this.instanceId = instanceId;
55 + }
56 +
57 + /**
58 + * Obtains address.
59 + *
60 + * @return address
61 + */
62 + public LispAfiAddress getAddress() {
63 + return address;
64 + }
65 +
66 + /**
67 + * Obtains instance id.
68 + *
69 + * @return instance id
70 + */
71 + public int getInstanceId() {
72 + return instanceId;
73 + }
74 +
75 + /**
76 + * Obtains id mask length.
77 + *
78 + * @return id mask length
79 + */
80 + public byte getIdMaskLength() {
81 + return reserved2;
82 + }
83 +
84 + @Override
85 + public int hashCode() {
86 + final int prime = 31;
87 + int result = super.hashCode();
88 + result = prime * result + ((address == null) ? 0 : address.hashCode());
89 + result = prime * result + instanceId;
90 + result = prime * result + reserved2;
91 + return result;
92 + }
93 +
94 + @Override
95 + public boolean equals(Object obj) {
96 + if (this == obj) {
97 + return true;
98 + }
99 +
100 + if (obj instanceof LispSegmentLcafAddress) {
101 + final LispSegmentLcafAddress other = (LispSegmentLcafAddress) obj;
102 + return Objects.equals(this.address, other.address) &&
103 + Objects.equals(this.instanceId, other.instanceId) &&
104 + Objects.equals(this.reserved2, other.reserved2);
105 + }
106 + return false;
107 + }
108 +
109 + @Override
110 + public String toString() {
111 + return toStringHelper(this)
112 + .add("address", address)
113 + .add("instanceId", instanceId)
114 + .add("idMaskLength", reserved2)
115 + .toString();
116 + }
117 +}
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.lisp.msg.types;
17 +
18 +import java.util.Objects;
19 +
20 +import static com.google.common.base.MoreObjects.toStringHelper;
21 +
22 +/**
23 + * Source/Dest key type LCAF address class.
24 + * Source destination key type is defined in draft-ietf-lisp-lcaf-13
25 + * https://tools.ietf.org/html/draft-ietf-lisp-lcaf-13#page-18
26 + *
27 + * 0 1 2 3
28 + * 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
29 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30 + * | AFI = 16387 | Rsvd1 | Flags |
31 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 + * | Type = 12 | Rsvd2 | 4 + n |
33 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 + * | Reserved | Source-ML | Dest-ML |
35 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 + * | AFI = x | Source-Prefix ... |
37 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + * | AFI = x | Destination-Prefix ... |
39 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + */
41 +public class LispSourceDestLcafAddress extends LispLcafAddress {
42 +
43 + private LispAfiAddress srcPrefix;
44 + private LispAfiAddress dstPrefix;
45 + private final byte srcMaskLength;
46 + private final byte dstMaskLength;
47 + private final short reserved;
48 +
49 + /**
50 + * Initializes source/dest key type LCAF address.
51 + */
52 + public LispSourceDestLcafAddress() {
53 + super(LispCanonicalAddressFormatEnum.SOURCE_DEST);
54 + srcMaskLength = 0;
55 + dstMaskLength = 0;
56 + reserved = 0;
57 + }
58 +
59 + /**
60 + * Initializes source/dest key type LCAF address.
61 + *
62 + * @param reserved reserved
63 + * @param srcMaskLength source mask length
64 + * @param dstMaskLength destination mask length
65 + * @param srcPrefix source address prefix
66 + * @param dstPrefix destination address prefix
67 + */
68 + public LispSourceDestLcafAddress(short reserved, byte srcMaskLength,
69 + byte dstMaskLength,
70 + LispAfiAddress srcPrefix,
71 + LispAfiAddress dstPrefix) {
72 + super(LispCanonicalAddressFormatEnum.SOURCE_DEST);
73 + this.reserved = reserved;
74 + this.srcMaskLength = srcMaskLength;
75 + this.dstMaskLength = dstMaskLength;
76 + this.srcPrefix = srcPrefix;
77 + this.dstPrefix = dstPrefix;
78 + }
79 +
80 + /**
81 + * Obtains source address prefix.
82 + *
83 + * @return source address prefix
84 + */
85 + public LispAfiAddress getSrcPrefix() {
86 + return srcPrefix;
87 + }
88 +
89 + /**
90 + * Obtains destination address prefix.
91 + *
92 + * @return destination address prefix
93 + */
94 + public LispAfiAddress getDstPrefix() {
95 + return dstPrefix;
96 + }
97 +
98 + /**
99 + * Obtains source mask length.
100 + *
101 + * @return source mask length
102 + */
103 + public byte getSrcMaskLength() {
104 + return srcMaskLength;
105 + }
106 +
107 + /**
108 + * Obtains destination mask length.
109 + *
110 + * @return destination mask length
111 + */
112 + public byte getDstMaskLength() {
113 + return dstMaskLength;
114 + }
115 +
116 + /**
117 + * Obtains reserved value.
118 + *
119 + * @return reserved value
120 + */
121 + public short getReserved() {
122 + return reserved;
123 + }
124 +
125 + @Override
126 + public int hashCode() {
127 + final int prime = 31;
128 + int result = super.hashCode();
129 + result = prime * result + ((srcPrefix == null) ? 0 : srcPrefix.hashCode());
130 + result = prime * result + ((dstPrefix == null) ? 0 : dstPrefix.hashCode());
131 + result = prime * result + srcMaskLength;
132 + result = prime * result + dstMaskLength;
133 + result = prime * result + reserved;
134 + return result;
135 + }
136 +
137 + @Override
138 + public boolean equals(Object obj) {
139 + if (this == obj) {
140 + return true;
141 + }
142 +
143 + if (obj instanceof LispSourceDestLcafAddress) {
144 + final LispSourceDestLcafAddress other = (LispSourceDestLcafAddress) obj;
145 + return Objects.equals(this.srcPrefix, other.srcPrefix) &&
146 + Objects.equals(this.dstPrefix, other.dstPrefix) &&
147 + Objects.equals(this.srcMaskLength, other.srcMaskLength) &&
148 + Objects.equals(this.dstMaskLength, other.dstMaskLength) &&
149 + Objects.equals(this.reserved, other.reserved);
150 + }
151 + return false;
152 + }
153 +
154 + @Override
155 + public String toString() {
156 + return toStringHelper(this)
157 + .add("source prefix", srcPrefix)
158 + .add("destination prefix", dstPrefix)
159 + .add("source mask length", srcMaskLength)
160 + .add("destination mask length", dstMaskLength)
161 + .add("reserved", reserved)
162 + .toString();
163 + }
164 +}