CORD-536 Support bidirectional connectivity between two services with dependency
Change-Id: I6530cd6d4865567d878a8269e09b98f5694b0454
diff --git a/src/main/java/org/onosproject/cordvtn/CordVtn.java b/src/main/java/org/onosproject/cordvtn/CordVtn.java
index 4017d5a..2996557 100644
--- a/src/main/java/org/onosproject/cordvtn/CordVtn.java
+++ b/src/main/java/org/onosproject/cordvtn/CordVtn.java
@@ -209,7 +209,8 @@
}
@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 @@
}
log.info("Service dependency from {} to {} created.", tService.id().id(), pService.id().id());
- ruleInstaller.populateServiceDependencyRules(tService, pService);
+ ruleInstaller.populateServiceDependencyRules(tService, pService, isBidirectional);
}
@Override
diff --git a/src/main/java/org/onosproject/cordvtn/CordVtnRuleInstaller.java b/src/main/java/org/onosproject/cordvtn/CordVtnRuleInstaller.java
index 8b52c34..d1a0f24 100644
--- a/src/main/java/org/onosproject/cordvtn/CordVtnRuleInstaller.java
+++ b/src/main/java/org/onosproject/cordvtn/CordVtnRuleInstaller.java
@@ -254,8 +254,10 @@
*
* @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 @@
populateIndirectAccessRule(srcRange, serviceIp, outGroups);
populateDirectAccessRule(srcRange, dstRange);
+ if (isBidirectional) {
+ populateDirectAccessRule(dstRange, srcRange);
+ }
populateInServiceRule(inPorts, outGroups);
}
diff --git a/src/main/java/org/onosproject/cordvtn/CordVtnService.java b/src/main/java/org/onosproject/cordvtn/CordVtnService.java
index b5bef86..87125d4 100644
--- a/src/main/java/org/onosproject/cordvtn/CordVtnService.java
+++ b/src/main/java/org/onosproject/cordvtn/CordVtnService.java
@@ -44,8 +44,11 @@
*
* @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.
diff --git a/src/main/java/org/onosproject/cordvtn/rest/ServiceDependencyWebResource.java b/src/main/java/org/onosproject/cordvtn/rest/ServiceDependencyWebResource.java
index c5d1ded..e91c1b6 100644
--- a/src/main/java/org/onosproject/cordvtn/rest/ServiceDependencyWebResource.java
+++ b/src/main/java/org/onosproject/cordvtn/rest/ServiceDependencyWebResource.java
@@ -19,16 +19,13 @@
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 @@
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,10 +46,31 @@
@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();
+ }
+
+ /**
+ * Creates service dependencies with an access type extension between the services.
+ *
+ * @param tServiceId tenant service id
+ * @param pServiceId provider service id
+ * @param direction b for bidirectional access, otherwise unidirectional access
+ * @return 200 OK
+ */
+ @POST
+ @Path("{tenantServiceId}/{providerServiceId}/{direction}")
+ @Produces(MediaType.APPLICATION_JSON)
+ 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();
}
@@ -70,21 +89,4 @@
service.removeServiceDependency(CordServiceId.of(tServiceId), CordServiceId.of(pServiceId));
return Response.status(Response.Status.OK).build();
}
-
- /**
- * Updates service dependencies.
- *
- * @param serviceId service id
- * @param stream input JSON
- * @return 200 OK, or 400 Bad Request
- */
- @PUT
- @Path("{serviceId}")
- @Produces(MediaType.APPLICATION_JSON)
- @Consumes(MediaType.APPLICATION_JSON)
- public Response updateServiceDependency(@PathParam("serviceId") String serviceId,
- InputStream stream) {
- // TODO define input stream
- return Response.status(Response.Status.OK).build();
- }
}