[Falcon] CORD-366 Implemented CORD service dependency API and pipeline
Done - Implement service dependency APIs - Populate or remove basic tenant connectivity rules when VM created or removed - Populate direct/indirect service access rules when service dependency created - Remove service dependency rules Todo - Add/remove bucket to proper group when a VM is created or terminated - Populate service dependency rules for existing VMs when service is activated - Cleanup flow rules remove Change-Id: I1daaf7ac9b41d7f2694605cb9b75f12d42144dbd
Showing
6 changed files
with
81 additions
and
211 deletions
| ... | @@ -18,8 +18,18 @@ package org.onosproject.cordvtn; | ... | @@ -18,8 +18,18 @@ package org.onosproject.cordvtn; |
| 18 | import com.google.common.base.MoreObjects; | 18 | import com.google.common.base.MoreObjects; |
| 19 | import org.onlab.packet.IpAddress; | 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.IpPrefix; | 20 | import org.onlab.packet.IpPrefix; |
| 21 | +import org.onosproject.net.Host; | ||
| 22 | +import org.onosproject.openstackswitching.OpenstackNetwork; | ||
| 23 | +import org.onosproject.openstackswitching.OpenstackSubnet; | ||
| 21 | 24 | ||
| 25 | +import java.util.Map; | ||
| 22 | import java.util.Objects; | 26 | import java.util.Objects; |
| 27 | +import java.util.Set; | ||
| 28 | + | ||
| 29 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 30 | +import static org.onosproject.cordvtn.CordService.ServiceType.*; | ||
| 31 | +import static org.onosproject.cordvtn.CordService.ServiceType.PRIVATE; | ||
| 32 | +import static org.onosproject.cordvtn.CordService.ServiceType.PUBLIC_INDIRECT; | ||
| 23 | 33 | ||
| 24 | public final class CordService { | 34 | public final class CordService { |
| 25 | 35 | ||
| ... | @@ -36,23 +46,25 @@ public final class CordService { | ... | @@ -36,23 +46,25 @@ public final class CordService { |
| 36 | private final ServiceType serviceType; | 46 | private final ServiceType serviceType; |
| 37 | private final IpPrefix serviceIpRange; | 47 | private final IpPrefix serviceIpRange; |
| 38 | private final IpAddress serviceIp; | 48 | private final IpAddress serviceIp; |
| 49 | + private final Map<Host, IpAddress> hosts; | ||
| 50 | + private final Set<CordServiceId> tenantServices; | ||
| 39 | 51 | ||
| 40 | /** | 52 | /** |
| 41 | * Default constructor. | 53 | * Default constructor. |
| 42 | * | 54 | * |
| 43 | - * @param id service id, which is identical to OpenStack network id | 55 | + * @param vNet OpenStack network |
| 44 | - * @param segmentationId segmentation id, which is identical to VNI | 56 | + * @param hosts host and tunnel ip map |
| 45 | - * @param serviceType service type | 57 | + * @param tenantServices list of tenant service ids |
| 46 | - * @param serviceIpRange service ip range | ||
| 47 | - * @param serviceIp service ip | ||
| 48 | */ | 58 | */ |
| 49 | - public CordService(CordServiceId id, long segmentationId, ServiceType serviceType, | 59 | + public CordService(OpenstackNetwork vNet, OpenstackSubnet subnet, |
| 50 | - IpPrefix serviceIpRange, IpAddress serviceIp) { | 60 | + Map<Host, IpAddress> hosts, Set<CordServiceId> tenantServices) { |
| 51 | - this.id = id; | 61 | + this.id = CordServiceId.of(vNet.id()); |
| 52 | - this.segmentationId = segmentationId; | 62 | + this.segmentationId = Long.parseLong(vNet.segmentId()); |
| 53 | - this.serviceType = serviceType; | 63 | + this.serviceType = getServiceType(vNet.name()); |
| 54 | - this.serviceIpRange = serviceIpRange; | 64 | + this.serviceIpRange = IpPrefix.valueOf(subnet.cidr()); |
| 55 | - this.serviceIp = serviceIp; | 65 | + this.serviceIp = IpAddress.valueOf(subnet.gatewayIp()); |
| 66 | + this.hosts = hosts; | ||
| 67 | + this.tenantServices = tenantServices; | ||
| 56 | } | 68 | } |
| 57 | 69 | ||
| 58 | /** | 70 | /** |
| ... | @@ -100,6 +112,24 @@ public final class CordService { | ... | @@ -100,6 +112,24 @@ public final class CordService { |
| 100 | return serviceIp; | 112 | return serviceIp; |
| 101 | } | 113 | } |
| 102 | 114 | ||
| 115 | + /** | ||
| 116 | + * Returns hosts associated with this service. | ||
| 117 | + * | ||
| 118 | + * @return list of hosts | ||
| 119 | + */ | ||
| 120 | + public Map<Host, IpAddress> hosts() { | ||
| 121 | + return hosts; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + /** | ||
| 125 | + * Returns tenant service IDs. | ||
| 126 | + * | ||
| 127 | + * @return list of tenant service id | ||
| 128 | + */ | ||
| 129 | + public Set<CordServiceId> tenantServices() { | ||
| 130 | + return tenantServices; | ||
| 131 | + } | ||
| 132 | + | ||
| 103 | @Override | 133 | @Override |
| 104 | public int hashCode() { | 134 | public int hashCode() { |
| 105 | return Objects.hash(id); | 135 | return Objects.hash(id); |
| ... | @@ -125,6 +155,33 @@ public final class CordService { | ... | @@ -125,6 +155,33 @@ public final class CordService { |
| 125 | .add("serviceType", serviceType) | 155 | .add("serviceType", serviceType) |
| 126 | .add("serviceIpRange", serviceIpRange) | 156 | .add("serviceIpRange", serviceIpRange) |
| 127 | .add("serviceIp", serviceIp) | 157 | .add("serviceIp", serviceIp) |
| 158 | + .add("tenantServices", tenantServices) | ||
| 128 | .toString(); | 159 | .toString(); |
| 129 | } | 160 | } |
| 161 | + | ||
| 162 | + /** | ||
| 163 | + * Returns network type from network name. | ||
| 164 | + * It assumes that network name contains network type. | ||
| 165 | + * | ||
| 166 | + * @param netName network name | ||
| 167 | + * @return network type, or null if it doesn't match any type | ||
| 168 | + */ | ||
| 169 | + private ServiceType getServiceType(String netName) { | ||
| 170 | + checkNotNull(netName); | ||
| 171 | + | ||
| 172 | + String name = netName.toUpperCase(); | ||
| 173 | + if (name.contains(PRIVATE_DIRECT.toString())) { | ||
| 174 | + return PRIVATE_DIRECT; | ||
| 175 | + } else if (name.contains(PRIVATE_INDIRECT.toString())) { | ||
| 176 | + return PRIVATE_INDIRECT; | ||
| 177 | + } else if (name.contains(PUBLIC_DIRECT.toString())) { | ||
| 178 | + return PUBLIC_DIRECT; | ||
| 179 | + } else if (name.contains(PUBLIC_INDIRECT.toString())) { | ||
| 180 | + return PUBLIC_INDIRECT; | ||
| 181 | + } else if (name.contains(PRIVATE.toString())) { | ||
| 182 | + return PRIVATE; | ||
| 183 | + } else { | ||
| 184 | + return null; | ||
| 185 | + } | ||
| 186 | + } | ||
| 130 | } | 187 | } | ... | ... |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
| ... | @@ -69,15 +69,16 @@ public interface CordVtnService { | ... | @@ -69,15 +69,16 @@ public interface CordVtnService { |
| 69 | /** | 69 | /** |
| 70 | * Creates dependencies for a given tenant service. | 70 | * Creates dependencies for a given tenant service. |
| 71 | * | 71 | * |
| 72 | - * @param tenantCordServiceId id of the service which has a dependency | 72 | + * @param tServiceId id of the service which has a dependency |
| 73 | - * @param providerCordServiceId id of the service which provide dependency | 73 | + * @param pServiceId id of the service which provide dependency |
| 74 | */ | 74 | */ |
| 75 | - void createServiceDependency(CordServiceId tenantCordServiceId, CordServiceId providerCordServiceId); | 75 | + void createServiceDependency(CordServiceId tServiceId, CordServiceId pServiceId); |
| 76 | 76 | ||
| 77 | /** | 77 | /** |
| 78 | * Removes all dependencies from a given tenant service. | 78 | * Removes all dependencies from a given tenant service. |
| 79 | * | 79 | * |
| 80 | - * @param tenantCordServiceId id of the service which has a dependency | 80 | + * @param tServiceId id of the service which has a dependency |
| 81 | + * @param pServiceId id of the service which provide dependency | ||
| 81 | */ | 82 | */ |
| 82 | - void removeServiceDependency(CordServiceId tenantCordServiceId); | 83 | + void removeServiceDependency(CordServiceId tServiceId, CordServiceId pServiceId); |
| 83 | } | 84 | } | ... | ... |
| 1 | -/* | ||
| 2 | - * Copyright 2014-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.cordvtn; | ||
| 17 | - | ||
| 18 | -import org.onlab.packet.IpAddress; | ||
| 19 | -import org.onlab.packet.MacAddress; | ||
| 20 | -import org.onosproject.net.Port; | ||
| 21 | - | ||
| 22 | -import java.util.List; | ||
| 23 | - | ||
| 24 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
| 25 | - | ||
| 26 | -/** | ||
| 27 | - * Contains destination information. | ||
| 28 | - */ | ||
| 29 | -public final class DestinationInfo { | ||
| 30 | - | ||
| 31 | - private final Port output; | ||
| 32 | - private final List<IpAddress> ip; | ||
| 33 | - private final MacAddress mac; | ||
| 34 | - private final IpAddress remoteIp; | ||
| 35 | - private final long tunnelId; | ||
| 36 | - | ||
| 37 | - /** | ||
| 38 | - * Creates a new destination information. | ||
| 39 | - * | ||
| 40 | - * @param output output port | ||
| 41 | - * @param ip destination ip address | ||
| 42 | - * @param mac destination mac address | ||
| 43 | - * @param remoteIp tunnel remote ip address | ||
| 44 | - * @param tunnelId segment id | ||
| 45 | - */ | ||
| 46 | - public DestinationInfo(Port output, List<IpAddress> ip, MacAddress mac, | ||
| 47 | - IpAddress remoteIp, long tunnelId) { | ||
| 48 | - this.output = checkNotNull(output); | ||
| 49 | - this.ip = ip; | ||
| 50 | - this.mac = mac; | ||
| 51 | - this.remoteIp = remoteIp; | ||
| 52 | - this.tunnelId = tunnelId; | ||
| 53 | - } | ||
| 54 | - | ||
| 55 | - /** | ||
| 56 | - * Returns output port. | ||
| 57 | - * | ||
| 58 | - * @return port | ||
| 59 | - */ | ||
| 60 | - public Port output() { | ||
| 61 | - return output; | ||
| 62 | - } | ||
| 63 | - | ||
| 64 | - /** | ||
| 65 | - * Returns destination ip addresses. | ||
| 66 | - * | ||
| 67 | - * @return list of ip address | ||
| 68 | - */ | ||
| 69 | - public List<IpAddress> ip() { | ||
| 70 | - return ip; | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - /** | ||
| 74 | - * Returns destination mac address. | ||
| 75 | - * | ||
| 76 | - * @return mac address | ||
| 77 | - */ | ||
| 78 | - public MacAddress mac() { | ||
| 79 | - return mac; | ||
| 80 | - } | ||
| 81 | - | ||
| 82 | - /** | ||
| 83 | - * Returns tunnel remote ip address. | ||
| 84 | - * | ||
| 85 | - * @return ip address | ||
| 86 | - */ | ||
| 87 | - public IpAddress remoteIp() { | ||
| 88 | - return remoteIp; | ||
| 89 | - } | ||
| 90 | - | ||
| 91 | - /** | ||
| 92 | - * Returns tunnel id. | ||
| 93 | - * | ||
| 94 | - * @return tunnel id | ||
| 95 | - */ | ||
| 96 | - public long tunnelId() { | ||
| 97 | - return tunnelId; | ||
| 98 | - } | ||
| 99 | - | ||
| 100 | - /** | ||
| 101 | - * Returns a new destination info builder. | ||
| 102 | - * | ||
| 103 | - * @return destination info builder | ||
| 104 | - */ | ||
| 105 | - public static DestinationInfo.Builder builder(Port output) { | ||
| 106 | - return new Builder(output); | ||
| 107 | - } | ||
| 108 | - | ||
| 109 | - /** | ||
| 110 | - * DestinationInfo builder class. | ||
| 111 | - */ | ||
| 112 | - public static final class Builder { | ||
| 113 | - | ||
| 114 | - private final Port output; | ||
| 115 | - private List<IpAddress> ip; | ||
| 116 | - private MacAddress mac; | ||
| 117 | - private IpAddress remoteIp; | ||
| 118 | - private long tunnelId; | ||
| 119 | - | ||
| 120 | - /** | ||
| 121 | - * Creates a new destination information builder. | ||
| 122 | - * | ||
| 123 | - * @param output output port | ||
| 124 | - */ | ||
| 125 | - public Builder(Port output) { | ||
| 126 | - this.output = checkNotNull(output, "Output port cannot be null"); | ||
| 127 | - } | ||
| 128 | - | ||
| 129 | - /** | ||
| 130 | - * Sets the destination ip address. | ||
| 131 | - * | ||
| 132 | - * @param ip ip address | ||
| 133 | - * @return destination info builder | ||
| 134 | - */ | ||
| 135 | - public Builder setIp(List<IpAddress> ip) { | ||
| 136 | - this.ip = checkNotNull(ip, "IP cannot be null"); | ||
| 137 | - return this; | ||
| 138 | - } | ||
| 139 | - | ||
| 140 | - /** | ||
| 141 | - * Sets the destination mac address. | ||
| 142 | - * | ||
| 143 | - * @param mac mac address | ||
| 144 | - * @return destination info builder | ||
| 145 | - */ | ||
| 146 | - public Builder setMac(MacAddress mac) { | ||
| 147 | - this.mac = checkNotNull(mac, "MAC address cannot be null"); | ||
| 148 | - return this; | ||
| 149 | - } | ||
| 150 | - | ||
| 151 | - /** | ||
| 152 | - * Sets the tunnel remote ip address. | ||
| 153 | - * | ||
| 154 | - * @param remoteIp ip address | ||
| 155 | - * @return destination info builder | ||
| 156 | - */ | ||
| 157 | - public Builder setRemoteIp(IpAddress remoteIp) { | ||
| 158 | - this.remoteIp = checkNotNull(remoteIp, "Remote IP address cannot be null"); | ||
| 159 | - return this; | ||
| 160 | - } | ||
| 161 | - | ||
| 162 | - /** | ||
| 163 | - * Sets the tunnel id. | ||
| 164 | - * | ||
| 165 | - * @param tunnelId tunnel id | ||
| 166 | - * @return destination info builder | ||
| 167 | - */ | ||
| 168 | - public Builder setTunnelId(long tunnelId) { | ||
| 169 | - this.tunnelId = checkNotNull(tunnelId, "Tunnel ID cannot be null"); | ||
| 170 | - return this; | ||
| 171 | - } | ||
| 172 | - | ||
| 173 | - /** | ||
| 174 | - * Build a destination information. | ||
| 175 | - * | ||
| 176 | - * @return destination info object | ||
| 177 | - */ | ||
| 178 | - public DestinationInfo build() { | ||
| 179 | - return new DestinationInfo(this); | ||
| 180 | - } | ||
| 181 | - } | ||
| 182 | - | ||
| 183 | - private DestinationInfo(Builder builder) { | ||
| 184 | - output = builder.output; | ||
| 185 | - ip = builder.ip; | ||
| 186 | - mac = builder.mac; | ||
| 187 | - remoteIp = builder.remoteIp; | ||
| 188 | - tunnelId = builder.tunnelId; | ||
| 189 | - } | ||
| 190 | -} |
| ... | @@ -58,14 +58,16 @@ public class ServiceDependencyWebResource extends AbstractWebResource { | ... | @@ -58,14 +58,16 @@ public class ServiceDependencyWebResource extends AbstractWebResource { |
| 58 | /** | 58 | /** |
| 59 | * Removes service dependencies. | 59 | * Removes service dependencies. |
| 60 | * | 60 | * |
| 61 | - * @param serviceId service id | 61 | + * @param tServiceId tenant service id |
| 62 | + * @param pServiceId provider service id | ||
| 62 | * @return 200 OK, or 400 Bad Request | 63 | * @return 200 OK, or 400 Bad Request |
| 63 | */ | 64 | */ |
| 64 | @DELETE | 65 | @DELETE |
| 65 | - @Path("{serviceId}") | 66 | + @Path("{tenantServiceId}/{providerServiceId}") |
| 66 | @Produces(MediaType.APPLICATION_JSON) | 67 | @Produces(MediaType.APPLICATION_JSON) |
| 67 | - public Response removeServiceDependency(@PathParam("serviceId") String serviceId) { | 68 | + public Response removeServiceDependency(@PathParam("tenantServiceId") String tServiceId, |
| 68 | - service.removeServiceDependency(CordServiceId.of(serviceId)); | 69 | + @PathParam("providerServiceId") String pServiceId) { |
| 70 | + service.removeServiceDependency(CordServiceId.of(tServiceId), CordServiceId.of(pServiceId)); | ||
| 69 | return Response.status(Response.Status.OK).build(); | 71 | return Response.status(Response.Status.OK).build(); |
| 70 | } | 72 | } |
| 71 | 73 | ... | ... |
-
Please register or login to post a comment