Committed by
Gerrit Code Review
[ONOS-2815]: add FloatingIpId and FloatingIpTest
Change-Id: Iae235c1f55543288eac475340467cdac618d4def
Showing
3 changed files
with
243 additions
and
0 deletions
1 | +/* | ||
2 | + * Copyright 2015 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.vtnrsc; | ||
17 | + | ||
18 | +import org.onlab.packet.IpAddress; | ||
19 | + | ||
20 | +/** | ||
21 | + * Representation of a floatingIp. | ||
22 | + */ | ||
23 | +public interface FloatingIp { | ||
24 | + | ||
25 | + /** | ||
26 | + * Coarse classification of the type of the FloatingIp. | ||
27 | + */ | ||
28 | + public enum Status { | ||
29 | + /** | ||
30 | + * Signifies that a floating Ip is currently active. | ||
31 | + */ | ||
32 | + ACTIVE, | ||
33 | + /** | ||
34 | + * Signifies that a floating Ip is currently inactive. | ||
35 | + */ | ||
36 | + INACTIVE | ||
37 | + } | ||
38 | + | ||
39 | + /** | ||
40 | + * Returns the floatingIp identifier. | ||
41 | + * | ||
42 | + * @return identifier | ||
43 | + */ | ||
44 | + FloatingIpId id(); | ||
45 | + | ||
46 | + /** | ||
47 | + * Returns the tenant identifier. | ||
48 | + * | ||
49 | + * @return the tenant identifier | ||
50 | + */ | ||
51 | + TenantId tenantId(); | ||
52 | + | ||
53 | + /** | ||
54 | + * Returns the network identifier. | ||
55 | + * | ||
56 | + * @return the network identifier | ||
57 | + */ | ||
58 | + TenantNetworkId networkId(); | ||
59 | + | ||
60 | + /** | ||
61 | + * Returns the port identifier. | ||
62 | + * | ||
63 | + * @return the port identifier | ||
64 | + */ | ||
65 | + VirtualPortId portId(); | ||
66 | + | ||
67 | + /** | ||
68 | + * Returns the router identifier. | ||
69 | + * | ||
70 | + * @return the router identifier | ||
71 | + */ | ||
72 | + RouterId routerId(); | ||
73 | + | ||
74 | + /** | ||
75 | + * Returns the floating ip address. | ||
76 | + * | ||
77 | + * @return floatingIp | ||
78 | + */ | ||
79 | + IpAddress floatingIp(); | ||
80 | + | ||
81 | + /** | ||
82 | + * Returns the fixed ip address. | ||
83 | + * | ||
84 | + * @return fixedIp | ||
85 | + */ | ||
86 | + IpAddress fixedIp(); | ||
87 | + | ||
88 | + /** | ||
89 | + * Returns the status of floating ip. | ||
90 | + * | ||
91 | + * @return floatingIpStatus | ||
92 | + */ | ||
93 | + Status status(); | ||
94 | +} |
1 | +/* | ||
2 | + * Copyright 2015 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.vtnrsc; | ||
17 | + | ||
18 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
19 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
20 | + | ||
21 | +import java.util.Objects; | ||
22 | +import java.util.UUID; | ||
23 | + | ||
24 | +/** | ||
25 | + * Immutable representation of a floating IP identifier. | ||
26 | + */ | ||
27 | +public final class FloatingIpId { | ||
28 | + private final UUID floatingIpId; | ||
29 | + | ||
30 | + // Public construction is prohibited | ||
31 | + private FloatingIpId(UUID floatingIpId) { | ||
32 | + this.floatingIpId = checkNotNull(floatingIpId, "floatingIpId cannot be null"); | ||
33 | + } | ||
34 | + | ||
35 | + /** | ||
36 | + * Creates a floating IP identifier. | ||
37 | + * | ||
38 | + * @param floatingIpId the UUID id of floating IP identifier | ||
39 | + * @return object of floating IP identifier | ||
40 | + */ | ||
41 | + public static FloatingIpId of(UUID floatingIpId) { | ||
42 | + return new FloatingIpId(floatingIpId); | ||
43 | + } | ||
44 | + | ||
45 | + /** | ||
46 | + * Creates a floating IP identifier. | ||
47 | + * | ||
48 | + * @param floatingIpId the floating IP identifier in string | ||
49 | + * @return object of floating IP identifier | ||
50 | + */ | ||
51 | + public static FloatingIpId of(String floatingIpId) { | ||
52 | + return new FloatingIpId(UUID.fromString(floatingIpId)); | ||
53 | + } | ||
54 | + | ||
55 | + /** | ||
56 | + * Returns the floating IP identifier. | ||
57 | + * | ||
58 | + * @return the floating IP identifier | ||
59 | + */ | ||
60 | + public UUID floatingIpId() { | ||
61 | + return floatingIpId; | ||
62 | + } | ||
63 | + | ||
64 | + @Override | ||
65 | + public int hashCode() { | ||
66 | + return floatingIpId.hashCode(); | ||
67 | + } | ||
68 | + | ||
69 | + @Override | ||
70 | + public boolean equals(Object obj) { | ||
71 | + if (this == obj) { | ||
72 | + return true; | ||
73 | + } | ||
74 | + if (obj instanceof FloatingIpId) { | ||
75 | + final FloatingIpId that = (FloatingIpId) obj; | ||
76 | + return Objects.equals(this.floatingIpId, that.floatingIpId); | ||
77 | + } | ||
78 | + return false; | ||
79 | + } | ||
80 | + | ||
81 | + @Override | ||
82 | + public String toString() { | ||
83 | + return toStringHelper(this).add("floatingIpId", floatingIpId).toString(); | ||
84 | + } | ||
85 | +} |
1 | +/* | ||
2 | + * Copyright 2015 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.vtnrsc.floatingip; | ||
17 | + | ||
18 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
19 | +import static org.hamcrest.Matchers.is; | ||
20 | +import static org.hamcrest.Matchers.notNullValue; | ||
21 | +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; | ||
22 | + | ||
23 | +import org.junit.Test; | ||
24 | +import org.onosproject.vtnrsc.FloatingIpId; | ||
25 | + | ||
26 | +import com.google.common.testing.EqualsTester; | ||
27 | + | ||
28 | +/** | ||
29 | + * Unit tests for FloatingIpId class. | ||
30 | + */ | ||
31 | +public class FloatingIpIdTest { | ||
32 | + private String floatingIpIdStr1 = "5fb63824-4d5c-4b85-9f2f-ebb93c9ce3df"; | ||
33 | + private String floatingIpIdStr2 = "fa44f585-fe02-40d3-afe7-d1d7e5782c99"; | ||
34 | + | ||
35 | + /** | ||
36 | + * Checks that the FloatingIpId class is immutable. | ||
37 | + */ | ||
38 | + @Test | ||
39 | + public void testImmutability() { | ||
40 | + assertThatClassIsImmutable(FloatingIpId.class); | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * Checks the operation of equals() methods. | ||
45 | + */ | ||
46 | + @Test | ||
47 | + public void testEquals() { | ||
48 | + FloatingIpId id1 = FloatingIpId.of(floatingIpIdStr1); | ||
49 | + FloatingIpId id2 = FloatingIpId.of(floatingIpIdStr1); | ||
50 | + FloatingIpId id3 = FloatingIpId.of(floatingIpIdStr2); | ||
51 | + new EqualsTester().addEqualityGroup(id1, id2).addEqualityGroup(id3) | ||
52 | + .testEquals(); | ||
53 | + } | ||
54 | + | ||
55 | + /** | ||
56 | + * Checks the construction of a FloatingIpId object. | ||
57 | + */ | ||
58 | + @Test | ||
59 | + public void testConstruction() { | ||
60 | + final FloatingIpId id = FloatingIpId.of(floatingIpIdStr1); | ||
61 | + assertThat(id, is(notNullValue())); | ||
62 | + assertThat(id.floatingIpId().toString(), is(floatingIpIdStr1)); | ||
63 | + } | ||
64 | +} |
-
Please register or login to post a comment