Committed by
Thomas Vachuska
[ONOS-4718] Add several data types used for addressing LISP locator
Change-Id: If6263957b2ce1d9a6a07bbc12f4fb9c9e2fa7616
Showing
9 changed files
with
432 additions
and
7 deletions
protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/types/AddressFamilyIdentifierEnum.java
0 → 100644
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 | +/** | ||
19 | + * Address Family Identifier (AFI) Enumeration class. | ||
20 | + * | ||
21 | + * An enumeration of AFIs defined by iana. | ||
22 | + * Now, we only declare 10 enums, more enums will be declared later on. | ||
23 | + * | ||
24 | + * http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml | ||
25 | + */ | ||
26 | +public enum AddressFamilyIdentifierEnum { | ||
27 | + | ||
28 | + NO_ADDRESS(0), IP(1), IP6(2), DNS(16), DISTINGUISHED_NAME(17), AS(18), LCAF(16387), | ||
29 | + MAC(16389), OUI(16391), UNKNOWN(-1); | ||
30 | + | ||
31 | + private short ianaCode; | ||
32 | + | ||
33 | + AddressFamilyIdentifierEnum(int ianaCode) { | ||
34 | + this.ianaCode = (short) ianaCode; | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * Obtains iana code value. | ||
39 | + * | ||
40 | + * @return iana code value | ||
41 | + */ | ||
42 | + public short getIanaCode() { | ||
43 | + return ianaCode; | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * Obtains AFI enum by providing iana code value. | ||
48 | + * | ||
49 | + * @param ianaCode iana code value | ||
50 | + * @return AFI enum | ||
51 | + */ | ||
52 | + public static AddressFamilyIdentifierEnum valueOf(short ianaCode) { | ||
53 | + for (AddressFamilyIdentifierEnum val : values()) { | ||
54 | + if (val.getIanaCode() == ianaCode) { | ||
55 | + return val; | ||
56 | + } | ||
57 | + } | ||
58 | + return UNKNOWN; | ||
59 | + } | ||
60 | +} |
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 | +/** | ||
19 | + * LISP Locator address typed by Address Family Identifier (AFI). | ||
20 | + */ | ||
21 | +public abstract class LispAfiAddress { | ||
22 | + | ||
23 | + private final AddressFamilyIdentifierEnum afi; | ||
24 | + | ||
25 | + /** | ||
26 | + * Initializes AFI enumeration value. | ||
27 | + * | ||
28 | + * @param afi address family identifier | ||
29 | + */ | ||
30 | + protected LispAfiAddress(AddressFamilyIdentifierEnum afi) { | ||
31 | + this.afi = afi; | ||
32 | + } | ||
33 | + | ||
34 | + /** | ||
35 | + * Obtains AFI enumeration value. | ||
36 | + * | ||
37 | + * @return AFI enumeration value | ||
38 | + */ | ||
39 | + public AddressFamilyIdentifierEnum getAfi() { | ||
40 | + return afi; | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public int hashCode() { | ||
45 | + final int prime = 31; | ||
46 | + int result = 1; | ||
47 | + result = prime * result + ((afi == null) ? 0 : afi.hashCode()); | ||
48 | + return result; | ||
49 | + } | ||
50 | + | ||
51 | + @Override | ||
52 | + public boolean equals(Object obj) { | ||
53 | + if (this == obj) { | ||
54 | + return true; | ||
55 | + } | ||
56 | + | ||
57 | + if (obj == null) { | ||
58 | + return false; | ||
59 | + } | ||
60 | + | ||
61 | + if (getClass() != obj.getClass()) { | ||
62 | + return false; | ||
63 | + } | ||
64 | + | ||
65 | + LispAfiAddress other = (LispAfiAddress) obj; | ||
66 | + if (afi != other.afi) { | ||
67 | + return false; | ||
68 | + } | ||
69 | + return true; | ||
70 | + } | ||
71 | +} |
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 | +/** | ||
19 | + * The identifier of Autonomous System (AS). | ||
20 | + */ | ||
21 | +public class LispAsAddress extends LispAfiAddress { | ||
22 | + | ||
23 | + private final int asNum; | ||
24 | + | ||
25 | + /** | ||
26 | + * Initializes AS identifier number. | ||
27 | + * | ||
28 | + * @param num AS number | ||
29 | + */ | ||
30 | + public LispAsAddress(int num) { | ||
31 | + super(AddressFamilyIdentifierEnum.AS); | ||
32 | + this.asNum = num; | ||
33 | + } | ||
34 | + | ||
35 | + /** | ||
36 | + * Obtains AS identifier number. | ||
37 | + * | ||
38 | + * @return AS number | ||
39 | + */ | ||
40 | + public int getASNum() { | ||
41 | + return asNum; | ||
42 | + } | ||
43 | + | ||
44 | + @Override | ||
45 | + public int hashCode() { | ||
46 | + final int prime = 31; | ||
47 | + int result = super.hashCode(); | ||
48 | + result = prime * result + asNum; | ||
49 | + return result; | ||
50 | + } | ||
51 | + | ||
52 | + @Override | ||
53 | + public boolean equals(Object obj) { | ||
54 | + if (this == obj) { | ||
55 | + return true; | ||
56 | + } | ||
57 | + | ||
58 | + if (!super.equals(obj)) { | ||
59 | + return false; | ||
60 | + } | ||
61 | + | ||
62 | + if (getClass() != obj.getClass()) { | ||
63 | + return false; | ||
64 | + } | ||
65 | + | ||
66 | + LispAsAddress other = (LispAsAddress) obj; | ||
67 | + if (asNum != other.asNum) { | ||
68 | + return false; | ||
69 | + } | ||
70 | + return true; | ||
71 | + } | ||
72 | + | ||
73 | + @Override | ||
74 | + public String toString() { | ||
75 | + return String.valueOf(asNum); | ||
76 | + } | ||
77 | +} |
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 org.onlab.packet.IpAddress; | ||
19 | + | ||
20 | +/** | ||
21 | + * IP address that is used by LISP Locator. | ||
22 | + */ | ||
23 | +public abstract class LispIpAddress extends LispAfiAddress { | ||
24 | + | ||
25 | + protected final IpAddress address; | ||
26 | + | ||
27 | + /** | ||
28 | + * Initializes LISP locator's IP address with AFI enum. | ||
29 | + * | ||
30 | + * @param address IP address | ||
31 | + * @param afi AFI enum | ||
32 | + */ | ||
33 | + protected LispIpAddress(IpAddress address, AddressFamilyIdentifierEnum afi) { | ||
34 | + super(afi); | ||
35 | + this.address = address; | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * Obtains LISP locator's IP address. | ||
40 | + * | ||
41 | + * @return IP address | ||
42 | + */ | ||
43 | + public IpAddress getAddress() { | ||
44 | + return address; | ||
45 | + } | ||
46 | + | ||
47 | + @Override | ||
48 | + public int hashCode() { | ||
49 | + return address.hashCode(); | ||
50 | + } | ||
51 | + | ||
52 | + @Override | ||
53 | + public boolean equals(Object obj) { | ||
54 | + return address.equals(obj); | ||
55 | + } | ||
56 | + | ||
57 | + @Override | ||
58 | + public String toString() { | ||
59 | + return address.toString(); | ||
60 | + } | ||
61 | +} |
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 org.onlab.packet.IpAddress; | ||
19 | + | ||
20 | +import static com.google.common.base.Preconditions.checkArgument; | ||
21 | + | ||
22 | +/** | ||
23 | + * IPv4 address that is used by LISP Locator. | ||
24 | + */ | ||
25 | +public class LispIpv4Address extends LispIpAddress { | ||
26 | + | ||
27 | + /** | ||
28 | + * Initializes LISP locator's IPv4 address. | ||
29 | + * | ||
30 | + * @param address IP address | ||
31 | + */ | ||
32 | + public LispIpv4Address(IpAddress address) { | ||
33 | + super(address, AddressFamilyIdentifierEnum.IP); | ||
34 | + checkArgument(address.isIp4()); | ||
35 | + } | ||
36 | +} |
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 org.onlab.packet.IpAddress; | ||
19 | + | ||
20 | +import static com.google.common.base.Preconditions.checkArgument; | ||
21 | + | ||
22 | +/** | ||
23 | + * IPv6 address that is used by LISP Locator. | ||
24 | + */ | ||
25 | +public class LispIpv6Address extends LispIpAddress { | ||
26 | + | ||
27 | + /** | ||
28 | + * Initializes LISP locator's IPv6 address. | ||
29 | + * | ||
30 | + * @param address IP address | ||
31 | + */ | ||
32 | + public LispIpv6Address(IpAddress address) { | ||
33 | + super(address, AddressFamilyIdentifierEnum.IP); | ||
34 | + checkArgument(address.isIp6()); | ||
35 | + } | ||
36 | +} |
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 org.onlab.packet.MacAddress; | ||
19 | + | ||
20 | +/** | ||
21 | + * MAC address that is used by LISP Locator. | ||
22 | + */ | ||
23 | +public class LispMacAddress extends LispAfiAddress { | ||
24 | + | ||
25 | + protected final MacAddress address; | ||
26 | + | ||
27 | + /** | ||
28 | + * Initializes MAC address. | ||
29 | + * | ||
30 | + * @param address MAC address | ||
31 | + */ | ||
32 | + public LispMacAddress(MacAddress address) { | ||
33 | + super(AddressFamilyIdentifierEnum.MAC); | ||
34 | + this.address = address; | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * Obtains LISP locator's MAC address. | ||
39 | + * | ||
40 | + * @return MAC address | ||
41 | + */ | ||
42 | + public MacAddress getAddress() { | ||
43 | + return address; | ||
44 | + } | ||
45 | + | ||
46 | + @Override | ||
47 | + public int hashCode() { | ||
48 | + return address.hashCode(); | ||
49 | + } | ||
50 | + | ||
51 | + @Override | ||
52 | + public boolean equals(Object obj) { | ||
53 | + return address.equals(obj); | ||
54 | + } | ||
55 | + | ||
56 | + @Override | ||
57 | + public String toString() { | ||
58 | + return address.toString(); | ||
59 | + } | ||
60 | +} |
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 | +/** | ||
19 | + * No address. | ||
20 | + */ | ||
21 | +public class LispNoAddress extends LispAfiAddress { | ||
22 | + | ||
23 | + /** | ||
24 | + * Initializes no address. | ||
25 | + */ | ||
26 | + public LispNoAddress() { | ||
27 | + super(AddressFamilyIdentifierEnum.NO_ADDRESS); | ||
28 | + } | ||
29 | +} |
... | @@ -13,12 +13,7 @@ | ... | @@ -13,12 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.lisp.msg; | ||
17 | - | ||
18 | /** | 16 | /** |
19 | - * Remove me. | 17 | + * LISP message data type. |
20 | */ | 18 | */ |
21 | -@Deprecated | 19 | +package org.onosproject.lisp.msg.types; |
22 | -public abstract class PlaceHolder { | ||
23 | - | ||
24 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment