Committed by
Gerrit Code Review
[ONOS-2248]The implementation of port resource service.
Change-Id: I4ad8422f9bc199e2e56166c041adece8de707e5d
Showing
11 changed files
with
531 additions
and
58 deletions
apps/vtnrsc/features.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
| 2 | +<!-- | ||
| 3 | + ~ Copyright 2015 Open Networking Laboratory | ||
| 4 | + ~ | ||
| 5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 6 | + ~ you may not use this file except in compliance with the License. | ||
| 7 | + ~ You may obtain a copy of the License at | ||
| 8 | + ~ | ||
| 9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| 10 | + ~ | ||
| 11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
| 12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| 13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 14 | + ~ See the License for the specific language governing permissions and | ||
| 15 | + ~ limitations under the License. | ||
| 16 | + --> | ||
| 17 | +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}"> | ||
| 18 | + <repository>mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features</repository> | ||
| 19 | + <feature name="onos-app-vtnrsc" version="@FEATURE-VERSION" | ||
| 20 | + description="ONOS app vtnrsc components"> | ||
| 21 | + <feature>onos-api</feature> | ||
| 22 | + <bundle>mvn:org.onosproject/onos-app-vtnrsc/@ONOS-VERSION | ||
| 23 | + </bundle> | ||
| 24 | + </feature> | ||
| 25 | +</features> |
| 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.app.vtnrsc; | ||
| 17 | + | ||
| 18 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
| 19 | + | ||
| 20 | +import java.util.Collection; | ||
| 21 | +import java.util.Map; | ||
| 22 | +import java.util.Objects; | ||
| 23 | + | ||
| 24 | +import org.onlab.packet.MacAddress; | ||
| 25 | +import org.onosproject.net.DeviceId; | ||
| 26 | +import org.onosproject.net.HostId; | ||
| 27 | + | ||
| 28 | +/** | ||
| 29 | + * Default implementation of VirtualPort interface . | ||
| 30 | + */ | ||
| 31 | +public final class DefaultVirtualPort implements VirtualPort { | ||
| 32 | + private final VirtualPortId id; | ||
| 33 | + private final TenantNetworkId networkId; | ||
| 34 | + private final Boolean adminStateUp; | ||
| 35 | + private final String name; | ||
| 36 | + private final State state; | ||
| 37 | + private final MacAddress macAddress; | ||
| 38 | + private final TenantId tenantId; | ||
| 39 | + private final String deviceOwner; | ||
| 40 | + private final DeviceId deviceId; | ||
| 41 | + private final FixedIp fixedIp; | ||
| 42 | + private final HostId bindingHostId; | ||
| 43 | + private final String bindingVnicType; | ||
| 44 | + private final String bindingVifType; | ||
| 45 | + private final String bindingVifDetails; | ||
| 46 | + private final Collection<AllowedAddressPair> allowedAddressPairs; | ||
| 47 | + private final Collection<SecurityGroup> securityGroups; | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * Creates a VirtualPort object. | ||
| 51 | + * | ||
| 52 | + * @param id the virtual port identifier | ||
| 53 | + * @param networkId the network identifier | ||
| 54 | + * @param adminStateUp adminStateup true or false | ||
| 55 | + * @param strMap the map of properties of virtual port | ||
| 56 | + * @param state virtual port state | ||
| 57 | + * @param macAddress the MAC address | ||
| 58 | + * @param tenantId the tenant identifier | ||
| 59 | + * @param deviceId the device identifier | ||
| 60 | + * @param fixedIp the fixed IP | ||
| 61 | + * @param bindingHostId the binding host identifier | ||
| 62 | + * @param allowedAddressPairs the collection of allowdeAddressPairs | ||
| 63 | + * @param securityGroups the collection of securityGroups | ||
| 64 | + */ | ||
| 65 | + public DefaultVirtualPort(VirtualPortId id, | ||
| 66 | + TenantNetworkId networkId, | ||
| 67 | + Boolean adminStateUp, | ||
| 68 | + Map<String, String> strMap, | ||
| 69 | + State state, | ||
| 70 | + MacAddress macAddress, | ||
| 71 | + TenantId tenantId, | ||
| 72 | + DeviceId deviceId, | ||
| 73 | + FixedIp fixedIp, | ||
| 74 | + HostId bindingHostId, | ||
| 75 | + Collection<AllowedAddressPair> allowedAddressPairs, | ||
| 76 | + Collection<SecurityGroup> securityGroups) { | ||
| 77 | + this.id = id; | ||
| 78 | + this.networkId = networkId; | ||
| 79 | + this.adminStateUp = adminStateUp; | ||
| 80 | + this.name = strMap.get("name"); | ||
| 81 | + this.state = state; | ||
| 82 | + this.macAddress = macAddress; | ||
| 83 | + this.tenantId = tenantId; | ||
| 84 | + this.deviceOwner = strMap.get("deviceOwner"); | ||
| 85 | + this.deviceId = deviceId; | ||
| 86 | + this.fixedIp = fixedIp; | ||
| 87 | + this.bindingHostId = bindingHostId; | ||
| 88 | + this.bindingVnicType = strMap.get("bindingVnicType"); | ||
| 89 | + this.bindingVifType = strMap.get("bindingVifType"); | ||
| 90 | + this.bindingVifDetails = strMap.get("bindingVifDetails"); | ||
| 91 | + this.allowedAddressPairs = allowedAddressPairs; | ||
| 92 | + this.securityGroups = securityGroups; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + @Override | ||
| 96 | + public VirtualPortId portId() { | ||
| 97 | + return id; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + @Override | ||
| 101 | + public TenantNetworkId networkId() { | ||
| 102 | + return networkId; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + @Override | ||
| 106 | + public String name() { | ||
| 107 | + return name; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + @Override | ||
| 111 | + public boolean adminStateUp() { | ||
| 112 | + return adminStateUp; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + @Override | ||
| 116 | + public State state() { | ||
| 117 | + return state; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + @Override | ||
| 121 | + public MacAddress macAddress() { | ||
| 122 | + return macAddress; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + @Override | ||
| 126 | + public TenantId tenantId() { | ||
| 127 | + return tenantId; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + @Override | ||
| 131 | + public DeviceId deviceId() { | ||
| 132 | + return deviceId; | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + @Override | ||
| 136 | + public String deviceOwner() { | ||
| 137 | + return deviceOwner; | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + @Override | ||
| 141 | + public Collection<AllowedAddressPair> allowedAddressPairs() { | ||
| 142 | + return allowedAddressPairs; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + @Override | ||
| 146 | + public FixedIp fixedIps() { | ||
| 147 | + return fixedIp; | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + @Override | ||
| 151 | + public HostId bindingHostId() { | ||
| 152 | + return bindingHostId; | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + @Override | ||
| 156 | + public String bindingVnicType() { | ||
| 157 | + return bindingVifType; | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + @Override | ||
| 161 | + public String bindingVifType() { | ||
| 162 | + return bindingVifType; | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + @Override | ||
| 166 | + public String bindingVifDetails() { | ||
| 167 | + return bindingVifDetails; | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + @Override | ||
| 171 | + public Collection<SecurityGroup> securityGroups() { | ||
| 172 | + return securityGroups; | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + @Override | ||
| 176 | + public int hashCode() { | ||
| 177 | + return Objects.hash(id, networkId, adminStateUp, name, state, | ||
| 178 | + macAddress, tenantId, deviceId, deviceOwner, | ||
| 179 | + allowedAddressPairs, fixedIp, bindingHostId, | ||
| 180 | + bindingVnicType, bindingVifType, bindingVifDetails, | ||
| 181 | + securityGroups); | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + @Override | ||
| 185 | + public boolean equals(Object obj) { | ||
| 186 | + if (this == obj) { | ||
| 187 | + return true; | ||
| 188 | + } | ||
| 189 | + if (obj instanceof DefaultVirtualPort) { | ||
| 190 | + final DefaultVirtualPort that = (DefaultVirtualPort) obj; | ||
| 191 | + return Objects.equals(this.id, that.id) | ||
| 192 | + && Objects.equals(this.networkId, that.networkId) | ||
| 193 | + && Objects.equals(this.adminStateUp, that.adminStateUp) | ||
| 194 | + && Objects.equals(this.state, that.state) | ||
| 195 | + && Objects.equals(this.name, that.name) | ||
| 196 | + && Objects.equals(this.tenantId, that.tenantId) | ||
| 197 | + && Objects.equals(this.macAddress, that.macAddress) | ||
| 198 | + && Objects.equals(this.deviceId, that.deviceId) | ||
| 199 | + && Objects.equals(this.deviceOwner, that.deviceOwner) | ||
| 200 | + && Objects.equals(this.allowedAddressPairs, | ||
| 201 | + that.allowedAddressPairs) | ||
| 202 | + && Objects.equals(this.fixedIp, that.fixedIp) | ||
| 203 | + && Objects.equals(this.bindingHostId, that.bindingHostId) | ||
| 204 | + && Objects.equals(this.bindingVifDetails, | ||
| 205 | + that.bindingVifDetails) | ||
| 206 | + && Objects.equals(this.bindingVifType, that.bindingVifType) | ||
| 207 | + && Objects.equals(this.bindingVnicType, | ||
| 208 | + that.bindingVnicType) | ||
| 209 | + && Objects.equals(this.securityGroups, that.securityGroups); | ||
| 210 | + } | ||
| 211 | + return false; | ||
| 212 | + } | ||
| 213 | + | ||
| 214 | + @Override | ||
| 215 | + public String toString() { | ||
| 216 | + return toStringHelper(this).add("id", id).add("network_id", networkId) | ||
| 217 | + .add("adminStateUp", adminStateUp).add("state", state) | ||
| 218 | + .add("name", name).add("state", state) | ||
| 219 | + .add("macAddress", macAddress).add("tenantId", tenantId) | ||
| 220 | + .add("deviced", deviceId).add("deviceOwner", deviceOwner) | ||
| 221 | + .add("allowedAddressPairs", allowedAddressPairs) | ||
| 222 | + .add("fixedIp", fixedIp).add("bindingHostId", bindingHostId) | ||
| 223 | + .add("bindingVnicType", bindingVnicType) | ||
| 224 | + .add("bindingVifDetails", bindingVifDetails) | ||
| 225 | + .add("bindingVifType", bindingVifType) | ||
| 226 | + .add("securityGroups", securityGroups).toString(); | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | +} |
| ... | @@ -22,7 +22,7 @@ import org.onosproject.net.DeviceId; | ... | @@ -22,7 +22,7 @@ import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.HostId; | 22 | import org.onosproject.net.HostId; |
| 23 | 23 | ||
| 24 | /** | 24 | /** |
| 25 | - * Representation of a virtual port. | 25 | + * Representation of the VirtualPort. |
| 26 | */ | 26 | */ |
| 27 | public interface VirtualPort { | 27 | public interface VirtualPort { |
| 28 | /** | 28 | /** |
| ... | @@ -50,7 +50,7 @@ public interface VirtualPort { | ... | @@ -50,7 +50,7 @@ public interface VirtualPort { |
| 50 | /** | 50 | /** |
| 51 | * Returns the network identifier. | 51 | * Returns the network identifier. |
| 52 | * | 52 | * |
| 53 | - * @return tenantNetwork ID | 53 | + * @return tenantNetwork identifier |
| 54 | */ | 54 | */ |
| 55 | TenantNetworkId networkId(); | 55 | TenantNetworkId networkId(); |
| 56 | 56 | ||
| ... | @@ -65,9 +65,9 @@ public interface VirtualPort { | ... | @@ -65,9 +65,9 @@ public interface VirtualPort { |
| 65 | * Returns the administrative status of the port,which is up(true) or | 65 | * Returns the administrative status of the port,which is up(true) or |
| 66 | * down(false). | 66 | * down(false). |
| 67 | * | 67 | * |
| 68 | - * @return true or false | 68 | + * @return true if the administrative status of the port is up |
| 69 | */ | 69 | */ |
| 70 | - Boolean adminStateUp(); | 70 | + boolean adminStateUp(); |
| 71 | 71 | ||
| 72 | /** | 72 | /** |
| 73 | * Returns the state. | 73 | * Returns the state. |
| ... | @@ -145,7 +145,7 @@ public interface VirtualPort { | ... | @@ -145,7 +145,7 @@ public interface VirtualPort { |
| 145 | * | 145 | * |
| 146 | * @return virtualPort bindingvifDetail | 146 | * @return virtualPort bindingvifDetail |
| 147 | */ | 147 | */ |
| 148 | - String bindingvifDetails(); | 148 | + String bindingVifDetails(); |
| 149 | 149 | ||
| 150 | /** | 150 | /** |
| 151 | * Returns the security groups. | 151 | * Returns the security groups. | ... | ... |
| ... | @@ -45,32 +45,30 @@ public interface VirtualPortService { | ... | @@ -45,32 +45,30 @@ public interface VirtualPortService { |
| 45 | 45 | ||
| 46 | /** | 46 | /** |
| 47 | * Returns the collection of the currently known virtualPort. | 47 | * Returns the collection of the currently known virtualPort. |
| 48 | - * | ||
| 49 | - * @return virtualPort. | ||
| 50 | */ | 48 | */ |
| 51 | Collection<VirtualPort> getPorts(); | 49 | Collection<VirtualPort> getPorts(); |
| 52 | 50 | ||
| 53 | /** | 51 | /** |
| 54 | * Returns the collection of the virtualPorts associated with the networkId. | 52 | * Returns the collection of the virtualPorts associated with the networkId. |
| 55 | * | 53 | * |
| 56 | - * @param networkId network identifier | 54 | + * @param networkId the network identifer |
| 57 | - * @return collection of virtualPort | 55 | + * @return collection of virtualPort. |
| 58 | */ | 56 | */ |
| 59 | Collection<VirtualPort> getPorts(TenantNetworkId networkId); | 57 | Collection<VirtualPort> getPorts(TenantNetworkId networkId); |
| 60 | 58 | ||
| 61 | /** | 59 | /** |
| 62 | * Returns the collection of the virtualPorts associated with the tenantId. | 60 | * Returns the collection of the virtualPorts associated with the tenantId. |
| 63 | * | 61 | * |
| 64 | - * @param tenantId tenant identifier | 62 | + * @param tenantId the tenant identifier |
| 65 | - * @return collection of virtualPort | 63 | + * @return collection of virtualPorts. |
| 66 | */ | 64 | */ |
| 67 | Collection<VirtualPort> getPorts(TenantId tenantId); | 65 | Collection<VirtualPort> getPorts(TenantId tenantId); |
| 68 | 66 | ||
| 69 | /** | 67 | /** |
| 70 | * Returns the collection of the virtualPorts associated with the deviceId. | 68 | * Returns the collection of the virtualPorts associated with the deviceId. |
| 71 | * | 69 | * |
| 72 | - * @param deviceId device identifier | 70 | + * @param deviceId the device identifier |
| 73 | - * @return collection of virtualPort | 71 | + * @return collection of virtualPort. |
| 74 | */ | 72 | */ |
| 75 | Collection<VirtualPort> getPorts(DeviceId deviceId); | 73 | Collection<VirtualPort> getPorts(DeviceId deviceId); |
| 76 | 74 | ||
| ... | @@ -86,7 +84,7 @@ public interface VirtualPortService { | ... | @@ -86,7 +84,7 @@ public interface VirtualPortService { |
| 86 | * Updates virtualPorts by virtualPorts. | 84 | * Updates virtualPorts by virtualPorts. |
| 87 | * | 85 | * |
| 88 | * @param virtualPorts the iterable collection of virtualPorts | 86 | * @param virtualPorts the iterable collection of virtualPorts |
| 89 | - * @return true if all given identifiers updated successfully | 87 | + * @return true if all given identifiers updated successfully. |
| 90 | */ | 88 | */ |
| 91 | boolean updatePorts(Iterable<VirtualPort> virtualPorts); | 89 | boolean updatePorts(Iterable<VirtualPort> virtualPorts); |
| 92 | 90 | ||
| ... | @@ -95,7 +93,7 @@ public interface VirtualPortService { | ... | @@ -95,7 +93,7 @@ public interface VirtualPortService { |
| 95 | * | 93 | * |
| 96 | * @param virtualPortIds the iterable collection of virtualPort identifiers | 94 | * @param virtualPortIds the iterable collection of virtualPort identifiers |
| 97 | * @return true or false if one with the given identifier to delete is | 95 | * @return true or false if one with the given identifier to delete is |
| 98 | - * successfully | 96 | + * successfully. |
| 99 | */ | 97 | */ |
| 100 | boolean removePorts(Iterable<VirtualPortId> virtualPortIds); | 98 | boolean removePorts(Iterable<VirtualPortId> virtualPortIds); |
| 101 | } | 99 | } | ... | ... |
| ... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.app.vtnrsc.virtualport.impl; | 16 | package org.onosproject.app.vtnrsc.virtualport.impl; |
| 17 | 17 | ||
| 18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 19 | + | ||
| 18 | import java.util.Collection; | 20 | import java.util.Collection; |
| 19 | import java.util.Collections; | 21 | import java.util.Collections; |
| 20 | 22 | ||
| ... | @@ -25,17 +27,17 @@ import org.apache.felix.scr.annotations.Reference; | ... | @@ -25,17 +27,17 @@ import org.apache.felix.scr.annotations.Reference; |
| 25 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 27 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 26 | import org.apache.felix.scr.annotations.Service; | 28 | import org.apache.felix.scr.annotations.Service; |
| 27 | import org.onlab.util.KryoNamespace; | 29 | import org.onlab.util.KryoNamespace; |
| 30 | +import org.onosproject.net.DeviceId; | ||
| 31 | +import org.onosproject.store.service.EventuallyConsistentMap; | ||
| 32 | +import org.onosproject.store.service.MultiValuedTimestamp; | ||
| 33 | +import org.onosproject.store.service.StorageService; | ||
| 34 | +import org.onosproject.store.service.WallClockTimestamp; | ||
| 28 | import org.onosproject.app.vtnrsc.TenantId; | 35 | import org.onosproject.app.vtnrsc.TenantId; |
| 29 | import org.onosproject.app.vtnrsc.TenantNetworkId; | 36 | import org.onosproject.app.vtnrsc.TenantNetworkId; |
| 30 | import org.onosproject.app.vtnrsc.VirtualPort; | 37 | import org.onosproject.app.vtnrsc.VirtualPort; |
| 31 | import org.onosproject.app.vtnrsc.VirtualPortId; | 38 | import org.onosproject.app.vtnrsc.VirtualPortId; |
| 32 | import org.onosproject.app.vtnrsc.tenantnetwork.TenantNetworkService; | 39 | import org.onosproject.app.vtnrsc.tenantnetwork.TenantNetworkService; |
| 33 | import org.onosproject.app.vtnrsc.virtualport.VirtualPortService; | 40 | import org.onosproject.app.vtnrsc.virtualport.VirtualPortService; |
| 34 | -import org.onosproject.net.DeviceId; | ||
| 35 | -import org.onosproject.store.service.EventuallyConsistentMap; | ||
| 36 | -import org.onosproject.store.service.MultiValuedTimestamp; | ||
| 37 | -import org.onosproject.store.service.StorageService; | ||
| 38 | -import org.onosproject.store.service.WallClockTimestamp; | ||
| 39 | import org.slf4j.Logger; | 41 | import org.slf4j.Logger; |
| 40 | import org.slf4j.LoggerFactory; | 42 | import org.slf4j.LoggerFactory; |
| 41 | 43 | ||
| ... | @@ -45,8 +47,15 @@ import org.slf4j.LoggerFactory; | ... | @@ -45,8 +47,15 @@ import org.slf4j.LoggerFactory; |
| 45 | @Component(immediate = true) | 47 | @Component(immediate = true) |
| 46 | @Service | 48 | @Service |
| 47 | public class VirtualPortManager implements VirtualPortService { | 49 | public class VirtualPortManager implements VirtualPortService { |
| 50 | + | ||
| 48 | private final Logger log = LoggerFactory.getLogger(getClass()); | 51 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 49 | 52 | ||
| 53 | + private static final String VIRTUALPORT_ID_NULL = "VirtualPort ID cannot be null"; | ||
| 54 | + private static final String VIRTUALPORT_NOT_NULL = "VirtualPort cannot be null"; | ||
| 55 | + private static final String TENANTID_NOT_NULL = "TenantId cannot be null"; | ||
| 56 | + private static final String NETWORKID_NOT_NULL = "NetworkId cannot be null"; | ||
| 57 | + private static final String DEVICEID_NOT_NULL = "DeviceId cannot be null"; | ||
| 58 | + | ||
| 50 | private EventuallyConsistentMap<VirtualPortId, VirtualPort> vPortStore; | 59 | private EventuallyConsistentMap<VirtualPortId, VirtualPort> vPortStore; |
| 51 | 60 | ||
| 52 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 61 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| ... | @@ -74,14 +83,13 @@ public class VirtualPortManager implements VirtualPortService { | ... | @@ -74,14 +83,13 @@ public class VirtualPortManager implements VirtualPortService { |
| 74 | 83 | ||
| 75 | @Override | 84 | @Override |
| 76 | public boolean exists(VirtualPortId vPortId) { | 85 | public boolean exists(VirtualPortId vPortId) { |
| 86 | + checkNotNull(vPortId, VIRTUALPORT_ID_NULL); | ||
| 77 | return vPortStore.containsKey(vPortId); | 87 | return vPortStore.containsKey(vPortId); |
| 78 | } | 88 | } |
| 79 | 89 | ||
| 80 | @Override | 90 | @Override |
| 81 | public VirtualPort getPort(VirtualPortId vPortId) { | 91 | public VirtualPort getPort(VirtualPortId vPortId) { |
| 82 | - if (!exists(vPortId)) { | 92 | + checkNotNull(vPortId, VIRTUALPORT_ID_NULL); |
| 83 | - return null; | ||
| 84 | - } | ||
| 85 | return vPortStore.get(vPortId); | 93 | return vPortStore.get(vPortId); |
| 86 | } | 94 | } |
| 87 | 95 | ||
| ... | @@ -92,81 +100,93 @@ public class VirtualPortManager implements VirtualPortService { | ... | @@ -92,81 +100,93 @@ public class VirtualPortManager implements VirtualPortService { |
| 92 | 100 | ||
| 93 | @Override | 101 | @Override |
| 94 | public Collection<VirtualPort> getPorts(TenantNetworkId networkId) { | 102 | public Collection<VirtualPort> getPorts(TenantNetworkId networkId) { |
| 95 | - Collection<VirtualPort> vPortWithNetworkId = | 103 | + checkNotNull(networkId, NETWORKID_NOT_NULL); |
| 96 | - Collections.unmodifiableCollection(vPortStore.values()); | 104 | + Collection<VirtualPort> vPortWithNetworkIds = vPortStore.values(); |
| 97 | - if (networkId == null || !networkService.exists(networkId)) { | 105 | + for (VirtualPort vPort : vPortWithNetworkIds) { |
| 98 | - return null; | ||
| 99 | - } | ||
| 100 | - for (VirtualPort vPort : vPortWithNetworkId) { | ||
| 101 | if (!vPort.networkId().equals(networkId)) { | 106 | if (!vPort.networkId().equals(networkId)) { |
| 102 | - vPortWithNetworkId.remove(vPort); | 107 | + vPortWithNetworkIds.remove(vPort); |
| 103 | } | 108 | } |
| 104 | } | 109 | } |
| 105 | - return vPortWithNetworkId; | 110 | + return vPortWithNetworkIds; |
| 106 | } | 111 | } |
| 107 | 112 | ||
| 108 | @Override | 113 | @Override |
| 109 | public Collection<VirtualPort> getPorts(TenantId tenantId) { | 114 | public Collection<VirtualPort> getPorts(TenantId tenantId) { |
| 110 | - Collection<VirtualPort> vPortWithTenantId = | 115 | + checkNotNull(tenantId, TENANTID_NOT_NULL); |
| 111 | - Collections.unmodifiableCollection(vPortStore.values()); | 116 | + Collection<VirtualPort> vPortWithTenantIds = vPortStore.values(); |
| 112 | - if (tenantId == null) { | 117 | + for (VirtualPort vPort : vPortWithTenantIds) { |
| 113 | - return null; | ||
| 114 | - } | ||
| 115 | - for (VirtualPort vPort : vPortWithTenantId) { | ||
| 116 | if (!vPort.tenantId().equals(tenantId)) { | 118 | if (!vPort.tenantId().equals(tenantId)) { |
| 117 | - vPortWithTenantId.remove(vPort); | 119 | + vPortWithTenantIds.remove(vPort); |
| 118 | } | 120 | } |
| 119 | } | 121 | } |
| 120 | - return vPortWithTenantId; | 122 | + return vPortWithTenantIds; |
| 121 | } | 123 | } |
| 122 | 124 | ||
| 123 | @Override | 125 | @Override |
| 124 | public Collection<VirtualPort> getPorts(DeviceId deviceId) { | 126 | public Collection<VirtualPort> getPorts(DeviceId deviceId) { |
| 125 | - Collection<VirtualPort> vPortWithDeviceId = | 127 | + checkNotNull(deviceId, DEVICEID_NOT_NULL); |
| 126 | - Collections.unmodifiableCollection(vPortStore.values()); | 128 | + Collection<VirtualPort> vPortWithDeviceIds = vPortStore.values(); |
| 127 | - if (deviceId == null) { | 129 | + for (VirtualPort vPort : vPortWithDeviceIds) { |
| 128 | - return null; | ||
| 129 | - } | ||
| 130 | - for (VirtualPort vPort : vPortWithDeviceId) { | ||
| 131 | if (!vPort.deviceId().equals(deviceId)) { | 130 | if (!vPort.deviceId().equals(deviceId)) { |
| 132 | - vPortWithDeviceId.remove(vPort); | 131 | + vPortWithDeviceIds.remove(vPort); |
| 133 | } | 132 | } |
| 134 | } | 133 | } |
| 135 | - return vPortWithDeviceId; | 134 | + return vPortWithDeviceIds; |
| 136 | } | 135 | } |
| 137 | 136 | ||
| 138 | @Override | 137 | @Override |
| 139 | public boolean createPorts(Iterable<VirtualPort> vPorts) { | 138 | public boolean createPorts(Iterable<VirtualPort> vPorts) { |
| 140 | - for (VirtualPort vPort:vPorts) { | 139 | + checkNotNull(vPorts, VIRTUALPORT_NOT_NULL); |
| 141 | - log.info("vPortId is {} ", vPort.portId().toString()); | 140 | + for (VirtualPort vPort : vPorts) { |
| 141 | + log.debug("vPortId is {} ", vPort.portId().toString()); | ||
| 142 | vPortStore.put(vPort.portId(), vPort); | 142 | vPortStore.put(vPort.portId(), vPort); |
| 143 | + if (!vPortStore.containsKey(vPort.portId())) { | ||
| 144 | + log.debug("the virtualPort created failed whose identifier was {} ", | ||
| 145 | + vPort.portId().toString()); | ||
| 146 | + return false; | ||
| 147 | + } | ||
| 143 | } | 148 | } |
| 144 | return true; | 149 | return true; |
| 145 | } | 150 | } |
| 146 | 151 | ||
| 147 | @Override | 152 | @Override |
| 148 | public boolean updatePorts(Iterable<VirtualPort> vPorts) { | 153 | public boolean updatePorts(Iterable<VirtualPort> vPorts) { |
| 149 | - Boolean flag = false; | 154 | + checkNotNull(vPorts, VIRTUALPORT_NOT_NULL); |
| 150 | if (vPorts != null) { | 155 | if (vPorts != null) { |
| 151 | - for (VirtualPort vPort:vPorts) { | 156 | + for (VirtualPort vPort : vPorts) { |
| 152 | vPortStore.put(vPort.portId(), vPort); | 157 | vPortStore.put(vPort.portId(), vPort); |
| 153 | - flag = true; | 158 | + if (!vPortStore.containsKey(vPort.portId())) { |
| 159 | + log.debug("the virtualPort did not exist whose identifier was {}", | ||
| 160 | + vPort.portId().toString()); | ||
| 161 | + return false; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + vPortStore.put(vPort.portId(), vPort); | ||
| 165 | + | ||
| 166 | + if (!vPort.equals(vPortStore.get(vPort.portId()))) { | ||
| 167 | + log.debug("the virtualPort updated failed whose identifier was {}", | ||
| 168 | + vPort.portId().toString()); | ||
| 169 | + return false; | ||
| 170 | + } | ||
| 154 | } | 171 | } |
| 155 | } | 172 | } |
| 156 | - return flag; | 173 | + return true; |
| 157 | } | 174 | } |
| 158 | 175 | ||
| 159 | @Override | 176 | @Override |
| 160 | public boolean removePorts(Iterable<VirtualPortId> vPortIds) { | 177 | public boolean removePorts(Iterable<VirtualPortId> vPortIds) { |
| 161 | - Boolean flag = false; | 178 | + checkNotNull(vPortIds, VIRTUALPORT_ID_NULL); |
| 162 | if (vPortIds != null) { | 179 | if (vPortIds != null) { |
| 163 | - for (VirtualPortId vPortId:vPortIds) { | 180 | + for (VirtualPortId vPortId : vPortIds) { |
| 164 | vPortStore.remove(vPortId); | 181 | vPortStore.remove(vPortId); |
| 165 | - flag = true; | 182 | + if (vPortStore.containsKey(vPortId)) { |
| 166 | - log.info("The result of removing vPortId is {}", flag.toString()); | 183 | + log.debug("the virtualPort removed failed whose identifier was {}", |
| 184 | + vPortId.toString()); | ||
| 185 | + return false; | ||
| 186 | + } | ||
| 167 | } | 187 | } |
| 168 | } | 188 | } |
| 169 | - return flag; | 189 | + return true; |
| 170 | } | 190 | } |
| 171 | 191 | ||
| 172 | } | 192 | } | ... | ... |
| 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.app.vtnrsc.web; | ||
| 17 | + | ||
| 18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 19 | + | ||
| 20 | +import org.onosproject.app.vtnrsc.AllowedAddressPair; | ||
| 21 | +import org.onosproject.codec.CodecContext; | ||
| 22 | +import org.onosproject.codec.JsonCodec; | ||
| 23 | + | ||
| 24 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| 25 | + | ||
| 26 | +/** | ||
| 27 | + * VirtualPort AllowedAddressPair codec. | ||
| 28 | + */ | ||
| 29 | +public final class AllowedAddressPairCodec extends JsonCodec<AllowedAddressPair> { | ||
| 30 | + | ||
| 31 | + @Override | ||
| 32 | + public ObjectNode encode(AllowedAddressPair alocAddPair, CodecContext context) { | ||
| 33 | + checkNotNull(alocAddPair, "AllowedAddressPair cannot be null"); | ||
| 34 | + ObjectNode result = context.mapper().createObjectNode() | ||
| 35 | + .put("ip_address", alocAddPair.ip().toString()) | ||
| 36 | + .put("mac_address", alocAddPair.mac().toString()); | ||
| 37 | + return result; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | +} |
| 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.app.vtnrsc.web; | ||
| 17 | + | ||
| 18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 19 | + | ||
| 20 | +import org.onosproject.app.vtnrsc.FixedIp; | ||
| 21 | +import org.onosproject.codec.CodecContext; | ||
| 22 | +import org.onosproject.codec.JsonCodec; | ||
| 23 | + | ||
| 24 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| 25 | + | ||
| 26 | +/** | ||
| 27 | + * VirtualPort FixedIp codec. | ||
| 28 | + */ | ||
| 29 | +public final class FixedIpCodec extends JsonCodec<FixedIp> { | ||
| 30 | + | ||
| 31 | + @Override | ||
| 32 | + public ObjectNode encode(FixedIp fixIp, CodecContext context) { | ||
| 33 | + checkNotNull(fixIp, "FixedIp cannot be null"); | ||
| 34 | + ObjectNode result = context.mapper().createObjectNode() | ||
| 35 | + .put("subnet_id", fixIp.subnetId().toString()) | ||
| 36 | + .put("ip_address", fixIp.ip().toString()); | ||
| 37 | + return result; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | +} |
| 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.app.vtnrsc.web; | ||
| 17 | + | ||
| 18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 19 | + | ||
| 20 | +import org.onosproject.app.vtnrsc.SecurityGroup; | ||
| 21 | +import org.onosproject.codec.CodecContext; | ||
| 22 | +import org.onosproject.codec.JsonCodec; | ||
| 23 | + | ||
| 24 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| 25 | + | ||
| 26 | +/** | ||
| 27 | + * Virtualport SecurityGroup codec. | ||
| 28 | + */ | ||
| 29 | +public final class SecurityGroupCodec extends JsonCodec<SecurityGroup> { | ||
| 30 | + | ||
| 31 | + @Override | ||
| 32 | + public ObjectNode encode(SecurityGroup securGroup, CodecContext context) { | ||
| 33 | + checkNotNull(securGroup, "SecurityGroup cannot be null"); | ||
| 34 | + ObjectNode result = context.mapper().createObjectNode() | ||
| 35 | + .put("security_group", securGroup.securityGroup()); | ||
| 36 | + return result; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | +} |
| 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.app.vtnrsc.web; | ||
| 17 | + | ||
| 18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 19 | + | ||
| 20 | +import org.onosproject.codec.CodecContext; | ||
| 21 | +import org.onosproject.codec.JsonCodec; | ||
| 22 | +import org.onosproject.app.vtnrsc.VirtualPort; | ||
| 23 | + | ||
| 24 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| 25 | + | ||
| 26 | +/** | ||
| 27 | + * VirtualPort JSON codec. | ||
| 28 | + */ | ||
| 29 | +public final class VirtualPortCodec extends JsonCodec<VirtualPort> { | ||
| 30 | + @Override | ||
| 31 | + public ObjectNode encode(VirtualPort vPort, CodecContext context) { | ||
| 32 | + checkNotNull(vPort, "VPort cannot be null"); | ||
| 33 | + ObjectNode result = context | ||
| 34 | + .mapper() | ||
| 35 | + .createObjectNode() | ||
| 36 | + .put("id", vPort.portId().toString()) | ||
| 37 | + .put("network_id", vPort.networkId().toString()) | ||
| 38 | + .put("admin_state_up", vPort.adminStateUp()) | ||
| 39 | + .put("name", vPort.name().toString()) | ||
| 40 | + .put("status", vPort.state().toString()) | ||
| 41 | + .put("mac_address", vPort.macAddress().toString()) | ||
| 42 | + .put("tenant_id", vPort.tenantId().toString()) | ||
| 43 | + .put("device_id", vPort.deviceId().toString()) | ||
| 44 | + .put("device_owner", vPort.deviceOwner().toString()) | ||
| 45 | + .put("binding:vnic_type", vPort.bindingVnicType().toString()) | ||
| 46 | + .put("binding:Vif_type", vPort.bindingVifType().toString()) | ||
| 47 | + .put("binding:host_id", vPort.bindingHostId().mac().toString()) | ||
| 48 | + .put("binding:vif_details", vPort.bindingVifDetails().toString()); | ||
| 49 | + result.set("allowed_address_pairs", new AllowedAddressPairCodec().encode( | ||
| 50 | + vPort.allowedAddressPairs(), context)); | ||
| 51 | + result.set("fixed_ips", new FixedIpCodec().encode( | ||
| 52 | + vPort.fixedIps(), context)); | ||
| 53 | + result.set("security_groups", new SecurityGroupCodec().encode( | ||
| 54 | + vPort.securityGroups(), context)); | ||
| 55 | + return result; | ||
| 56 | + } | ||
| 57 | +} |
apps/vtnweb/features.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
| 2 | +<!-- | ||
| 3 | + ~ Copyright 2015 Open Networking Laboratory | ||
| 4 | + ~ | ||
| 5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 6 | + ~ you may not use this file except in compliance with the License. | ||
| 7 | + ~ You may obtain a copy of the License at | ||
| 8 | + ~ | ||
| 9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| 10 | + ~ | ||
| 11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
| 12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| 13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 14 | + ~ See the License for the specific language governing permissions and | ||
| 15 | + ~ limitations under the License. | ||
| 16 | + --> | ||
| 17 | +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}"> | ||
| 18 | + <repository>mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features</repository> | ||
| 19 | + <feature name="onos-app-vtnweb" version="@FEATURE-VERSION" | ||
| 20 | + description="ONOS app vtnweb components"> | ||
| 21 | + <feature>onos-app-vtnrsc</feature> | ||
| 22 | + <bundle>mvn:org.onosproject/vtnweb/@ONOS-VERSION | ||
| 23 | + </bundle> | ||
| 24 | + </feature> | ||
| 25 | +</features> |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment