Committed by
Gerrit Code Review
[ONOS-2820] add implementation of floatingIpService api
Change-Id: I65a2643dcf0443fa4ae0cd647bcb42fa9e2a6e44
Showing
4 changed files
with
285 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 static com.google.common.base.MoreObjects.toStringHelper; | ||
| 19 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 20 | + | ||
| 21 | +import java.util.Objects; | ||
| 22 | + | ||
| 23 | +import org.onlab.packet.IpAddress; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * Default implementation of FloatingIp interface. | ||
| 27 | + */ | ||
| 28 | +public final class DefaultFloatingIp implements FloatingIp { | ||
| 29 | + | ||
| 30 | + private final FloatingIpId id; | ||
| 31 | + private final TenantId tenantId; | ||
| 32 | + private final TenantNetworkId networkId; | ||
| 33 | + private final VirtualPortId portId; | ||
| 34 | + private final RouterId routerId; | ||
| 35 | + private final IpAddress floatingIp; | ||
| 36 | + private final IpAddress fixedIp; | ||
| 37 | + private final Status status; | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * | ||
| 41 | + * Creates a floating Ip object. | ||
| 42 | + * | ||
| 43 | + * @param id floatingIp identifier | ||
| 44 | + * @param tenantId tenant identifier | ||
| 45 | + * @param networkId the identifier of network associated with the floating Ip | ||
| 46 | + * @param portId port identifier | ||
| 47 | + * @param routerId router identifier | ||
| 48 | + * @param floatingIp floatingIp address | ||
| 49 | + * @param fixedIp the fixed Ip associated with the floating Ip | ||
| 50 | + * @param status the floating Ip status | ||
| 51 | + */ | ||
| 52 | + public DefaultFloatingIp(FloatingIpId id, TenantId tenantId, | ||
| 53 | + TenantNetworkId networkId, VirtualPortId portId, | ||
| 54 | + RouterId routerId, IpAddress floatingIp, | ||
| 55 | + IpAddress fixedIp, Status status) { | ||
| 56 | + this.id = checkNotNull(id, "id cannot be null"); | ||
| 57 | + this.tenantId = checkNotNull(tenantId, "tenantId cannot be null"); | ||
| 58 | + this.networkId = checkNotNull(networkId, "networkId cannot be null"); | ||
| 59 | + this.portId = portId; | ||
| 60 | + this.routerId = routerId; | ||
| 61 | + this.floatingIp = checkNotNull(floatingIp, "floatingIp cannot be null"); | ||
| 62 | + this.fixedIp = fixedIp; | ||
| 63 | + this.status = checkNotNull(status, "status cannot be null"); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + @Override | ||
| 67 | + public FloatingIpId id() { | ||
| 68 | + return id; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public TenantId tenantId() { | ||
| 73 | + return tenantId; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + @Override | ||
| 77 | + public TenantNetworkId networkId() { | ||
| 78 | + return networkId; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + @Override | ||
| 82 | + public VirtualPortId portId() { | ||
| 83 | + return portId; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + @Override | ||
| 87 | + public RouterId routerId() { | ||
| 88 | + return routerId; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + @Override | ||
| 92 | + public IpAddress floatingIp() { | ||
| 93 | + return floatingIp; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + @Override | ||
| 97 | + public IpAddress fixedIp() { | ||
| 98 | + return fixedIp; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + @Override | ||
| 102 | + public Status status() { | ||
| 103 | + return status; | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + @Override | ||
| 107 | + public int hashCode() { | ||
| 108 | + return Objects.hash(id, tenantId, networkId, portId, routerId, | ||
| 109 | + floatingIp, fixedIp, status); | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + @Override | ||
| 113 | + public boolean equals(Object obj) { | ||
| 114 | + if (this == obj) { | ||
| 115 | + return true; | ||
| 116 | + } | ||
| 117 | + if (obj instanceof DefaultFloatingIp) { | ||
| 118 | + final DefaultFloatingIp that = (DefaultFloatingIp) obj; | ||
| 119 | + return Objects.equals(this.id, that.id) | ||
| 120 | + && Objects.equals(this.tenantId, that.tenantId) | ||
| 121 | + && Objects.equals(this.networkId, that.networkId) | ||
| 122 | + && Objects.equals(this.portId, that.portId) | ||
| 123 | + && Objects.equals(this.routerId, that.routerId) | ||
| 124 | + && Objects.equals(this.floatingIp, that.floatingIp) | ||
| 125 | + && Objects.equals(this.fixedIp, that.fixedIp) | ||
| 126 | + && Objects.equals(this.status, that.status); | ||
| 127 | + } | ||
| 128 | + return false; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + @Override | ||
| 132 | + public String toString() { | ||
| 133 | + return toStringHelper(this).add("id", id).add("tenantId", tenantId) | ||
| 134 | + .add("networkId", networkId).add("portId", portId) | ||
| 135 | + .add("routerId", routerId).add("floatingIp", floatingIp) | ||
| 136 | + .add("fixedIp", fixedIp).add("floatingIpStatus", status) | ||
| 137 | + .toString(); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | +} |
apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/impl/FloatingIpManager.java
0 → 100644
This diff is collapsed. Click to expand it.
| 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 | + | ||
| 17 | +/** | ||
| 18 | + * Provides implementation of the FloatingIp service. | ||
| 19 | + */ | ||
| 20 | +package org.onosproject.vtnrsc.floatingip.impl; |
apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/floatingip/DefaultFloatingIpTest.java
0 → 100644
| 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.onlab.packet.IpAddress; | ||
| 25 | +import org.onosproject.vtnrsc.DefaultFloatingIp; | ||
| 26 | +import org.onosproject.vtnrsc.FloatingIp; | ||
| 27 | +import org.onosproject.vtnrsc.FloatingIpId; | ||
| 28 | +import org.onosproject.vtnrsc.RouterId; | ||
| 29 | +import org.onosproject.vtnrsc.TenantId; | ||
| 30 | +import org.onosproject.vtnrsc.TenantNetworkId; | ||
| 31 | +import org.onosproject.vtnrsc.VirtualPortId; | ||
| 32 | + | ||
| 33 | +import com.google.common.testing.EqualsTester; | ||
| 34 | + | ||
| 35 | +/** | ||
| 36 | + * Unit tests for DefaultFloatingIp class. | ||
| 37 | + */ | ||
| 38 | +public class DefaultFloatingIpTest { | ||
| 39 | + | ||
| 40 | + private String floatingIpIdStr1 = "5fb63824-4d5c-4b85-9f2f-ebb93c9ce3df"; | ||
| 41 | + private String floatingIpIdStr2 = "fa44f585-fe02-40d3-afe7-d1d7e5782c99"; | ||
| 42 | + private String floatingIpStr = "10.1.1.2"; | ||
| 43 | + private String fixedIpStr = "192.168.1.2"; | ||
| 44 | + private String tenantIdStr = "123"; | ||
| 45 | + private String tenantNetworkId = "1234567"; | ||
| 46 | + private String virtualPortId = "1212"; | ||
| 47 | + private String routerIdStr = "123"; | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * Checks that the DefaultFloatingIp class is immutable. | ||
| 51 | + */ | ||
| 52 | + @Test | ||
| 53 | + public void testImmutability() { | ||
| 54 | + assertThatClassIsImmutable(DefaultFloatingIp.class); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * Checks the operation of equals(). | ||
| 59 | + */ | ||
| 60 | + @Test | ||
| 61 | + public void testEquals() { | ||
| 62 | + final TenantId tenantId = TenantId.tenantId(tenantIdStr); | ||
| 63 | + final TenantNetworkId networkId = TenantNetworkId | ||
| 64 | + .networkId(tenantNetworkId); | ||
| 65 | + final VirtualPortId portId = VirtualPortId.portId(virtualPortId); | ||
| 66 | + final RouterId routerId = RouterId.valueOf(routerIdStr); | ||
| 67 | + final FloatingIpId id1 = FloatingIpId.of(floatingIpIdStr1); | ||
| 68 | + final FloatingIpId id2 = FloatingIpId.of(floatingIpIdStr2); | ||
| 69 | + final IpAddress floatingIpAddress = IpAddress.valueOf(floatingIpStr); | ||
| 70 | + final IpAddress fixedIpAddress = IpAddress.valueOf(fixedIpStr); | ||
| 71 | + | ||
| 72 | + FloatingIp fip1 = new DefaultFloatingIp(id1, tenantId, networkId, | ||
| 73 | + portId, routerId, | ||
| 74 | + floatingIpAddress, | ||
| 75 | + fixedIpAddress, | ||
| 76 | + FloatingIp.Status.ACTIVE); | ||
| 77 | + FloatingIp fip2 = new DefaultFloatingIp(id1, tenantId, networkId, | ||
| 78 | + portId, routerId, | ||
| 79 | + floatingIpAddress, | ||
| 80 | + fixedIpAddress, | ||
| 81 | + FloatingIp.Status.ACTIVE); | ||
| 82 | + FloatingIp fip3 = new DefaultFloatingIp(id2, tenantId, networkId, | ||
| 83 | + portId, routerId, | ||
| 84 | + floatingIpAddress, | ||
| 85 | + fixedIpAddress, | ||
| 86 | + FloatingIp.Status.ACTIVE); | ||
| 87 | + | ||
| 88 | + new EqualsTester().addEqualityGroup(fip1, fip2).addEqualityGroup(fip3) | ||
| 89 | + .testEquals(); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * Checks the construction of a DefaultFloatingIp object. | ||
| 94 | + */ | ||
| 95 | + @Test | ||
| 96 | + public void testConstruction() { | ||
| 97 | + final TenantId tenantId = TenantId.tenantId(tenantIdStr); | ||
| 98 | + final TenantNetworkId networkId = TenantNetworkId | ||
| 99 | + .networkId(tenantNetworkId); | ||
| 100 | + final VirtualPortId portId = VirtualPortId.portId(virtualPortId); | ||
| 101 | + final RouterId routerId = RouterId.valueOf(routerIdStr); | ||
| 102 | + final FloatingIpId id = FloatingIpId.of(floatingIpIdStr1); | ||
| 103 | + final IpAddress floatingIpAddress = IpAddress.valueOf(floatingIpStr); | ||
| 104 | + final IpAddress fixedIpAddress = IpAddress.valueOf(fixedIpStr); | ||
| 105 | + | ||
| 106 | + FloatingIp fip = new DefaultFloatingIp(id, tenantId, networkId, portId, | ||
| 107 | + routerId, floatingIpAddress, | ||
| 108 | + fixedIpAddress, | ||
| 109 | + FloatingIp.Status.ACTIVE); | ||
| 110 | + assertThat(id, is(notNullValue())); | ||
| 111 | + assertThat(id, is(fip.id())); | ||
| 112 | + assertThat(tenantId, is(notNullValue())); | ||
| 113 | + assertThat(tenantId, is(fip.tenantId())); | ||
| 114 | + assertThat(networkId, is(notNullValue())); | ||
| 115 | + assertThat(networkId, is(fip.networkId())); | ||
| 116 | + assertThat(portId, is(notNullValue())); | ||
| 117 | + assertThat(portId, is(fip.portId())); | ||
| 118 | + assertThat(routerId, is(notNullValue())); | ||
| 119 | + assertThat(routerId, is(fip.routerId())); | ||
| 120 | + assertThat(floatingIpAddress, is(notNullValue())); | ||
| 121 | + assertThat(floatingIpAddress, is(fip.floatingIp())); | ||
| 122 | + assertThat(fixedIpAddress, is(notNullValue())); | ||
| 123 | + assertThat(fixedIpAddress, is(fip.fixedIp())); | ||
| 124 | + } | ||
| 125 | +} |
-
Please register or login to post a comment