Hyunsun Moon
Committed by Gerrit Code Review

CORD-536 Support bidirectional connectivity between two services with dependency

Change-Id: I6530cd6d4865567d878a8269e09b98f5694b0454
......@@ -209,7 +209,8 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro
}
@Override
public void createServiceDependency(CordServiceId tServiceId, CordServiceId pServiceId) {
public void createServiceDependency(CordServiceId tServiceId, CordServiceId pServiceId,
boolean isBidirectional) {
CordService tService = getCordService(tServiceId);
CordService pService = getCordService(pServiceId);
......@@ -219,7 +220,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro
}
log.info("Service dependency from {} to {} created.", tService.id().id(), pService.id().id());
ruleInstaller.populateServiceDependencyRules(tService, pService);
ruleInstaller.populateServiceDependencyRules(tService, pService, isBidirectional);
}
@Override
......
......@@ -254,8 +254,10 @@ public class CordVtnRuleInstaller {
*
* @param tService tenant cord service
* @param pService provider cord service
* @param isBidirectional true to enable bidirectional connection between two services
*/
public void populateServiceDependencyRules(CordService tService, CordService pService) {
public void populateServiceDependencyRules(CordService tService, CordService pService,
boolean isBidirectional) {
checkNotNull(tService);
checkNotNull(pService);
......@@ -280,6 +282,9 @@ public class CordVtnRuleInstaller {
populateIndirectAccessRule(srcRange, serviceIp, outGroups);
populateDirectAccessRule(srcRange, dstRange);
if (isBidirectional) {
populateDirectAccessRule(dstRange, srcRange);
}
populateInServiceRule(inPorts, outGroups);
}
......
......@@ -44,8 +44,11 @@ public interface CordVtnService {
*
* @param tServiceId id of the service which has a dependency
* @param pServiceId id of the service which provide dependency
* @param isBidirectional true to enable bidirectional connectivity between two services
*/
void createServiceDependency(CordServiceId tServiceId, CordServiceId pServiceId);
void createServiceDependency(CordServiceId tServiceId,
CordServiceId pServiceId,
boolean isBidirectional);
/**
* Removes all dependencies from a given tenant service.
......
......@@ -19,16 +19,13 @@ import org.onosproject.cordvtn.CordVtnService;
import org.onosproject.cordvtn.CordServiceId;
import org.onosproject.rest.AbstractWebResource;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.InputStream;
/**
* Manages service dependency.
......@@ -37,9 +34,10 @@ import java.io.InputStream;
public class ServiceDependencyWebResource extends AbstractWebResource {
private final CordVtnService service = get(CordVtnService.class);
private static final String BIDIRECTION = "b";
/**
* Creates service dependencies.
* Creates service dependencies with unidirectional access between the services.
*
* @param tServiceId tenant service id
* @param pServiceId provider service id
......@@ -48,43 +46,47 @@ public class ServiceDependencyWebResource extends AbstractWebResource {
@POST
@Path("{tenantServiceId}/{providerServiceId}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response createServiceDependency(@PathParam("tenantServiceId") String tServiceId,
@PathParam("providerServiceId") String pServiceId) {
service.createServiceDependency(CordServiceId.of(tServiceId), CordServiceId.of(pServiceId));
service.createServiceDependency(CordServiceId.of(tServiceId),
CordServiceId.of(pServiceId),
false);
return Response.status(Response.Status.OK).build();
}
/**
* Removes service dependencies.
* Creates service dependencies with an access type extension between the services.
*
* @param tServiceId tenant service id
* @param pServiceId provider service id
* @return 200 OK, or 400 Bad Request
* @param direction b for bidirectional access, otherwise unidirectional access
* @return 200 OK
*/
@DELETE
@Path("{tenantServiceId}/{providerServiceId}")
@POST
@Path("{tenantServiceId}/{providerServiceId}/{direction}")
@Produces(MediaType.APPLICATION_JSON)
public Response removeServiceDependency(@PathParam("tenantServiceId") String tServiceId,
@PathParam("providerServiceId") String pServiceId) {
service.removeServiceDependency(CordServiceId.of(tServiceId), CordServiceId.of(pServiceId));
public Response createServiceDependency(@PathParam("tenantServiceId") String tServiceId,
@PathParam("providerServiceId") String pServiceId,
@PathParam("direction") String direction) {
service.createServiceDependency(CordServiceId.of(tServiceId),
CordServiceId.of(pServiceId),
direction.equals(BIDIRECTION));
return Response.status(Response.Status.OK).build();
}
/**
* Updates service dependencies.
* Removes service dependencies.
*
* @param serviceId service id
* @param stream input JSON
* @param tServiceId tenant service id
* @param pServiceId provider service id
* @return 200 OK, or 400 Bad Request
*/
@PUT
@Path("{serviceId}")
@DELETE
@Path("{tenantServiceId}/{providerServiceId}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response updateServiceDependency(@PathParam("serviceId") String serviceId,
InputStream stream) {
// TODO define input stream
public Response removeServiceDependency(@PathParam("tenantServiceId") String tServiceId,
@PathParam("providerServiceId") String pServiceId) {
service.removeServiceDependency(CordServiceId.of(tServiceId), CordServiceId.of(pServiceId));
return Response.status(Response.Status.OK).build();
}
}
......