Jonathan Hart
Committed by Gerrit Code Review

Add ability to add mcast sinks via REST API

Change-Id: Ie757537a8b514bfec1e468628dac1a8faa4405fc
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
17 package org.onosproject.rest.resources; 17 package org.onosproject.rest.resources;
18 18
19 import com.fasterxml.jackson.databind.node.ObjectNode; 19 import com.fasterxml.jackson.databind.node.ObjectNode;
20 +import com.google.common.annotations.Beta;
21 +import org.onlab.packet.IpAddress;
22 +import org.onosproject.net.ConnectPoint;
20 import org.onosproject.net.mcast.McastRoute; 23 import org.onosproject.net.mcast.McastRoute;
21 import org.onosproject.net.mcast.MulticastRouteService; 24 import org.onosproject.net.mcast.MulticastRouteService;
22 import org.onosproject.rest.AbstractWebResource; 25 import org.onosproject.rest.AbstractWebResource;
...@@ -26,6 +29,7 @@ import javax.ws.rs.DELETE; ...@@ -26,6 +29,7 @@ import javax.ws.rs.DELETE;
26 import javax.ws.rs.GET; 29 import javax.ws.rs.GET;
27 import javax.ws.rs.POST; 30 import javax.ws.rs.POST;
28 import javax.ws.rs.Path; 31 import javax.ws.rs.Path;
32 +import javax.ws.rs.PathParam;
29 import javax.ws.rs.Produces; 33 import javax.ws.rs.Produces;
30 import javax.ws.rs.core.MediaType; 34 import javax.ws.rs.core.MediaType;
31 import javax.ws.rs.core.Response; 35 import javax.ws.rs.core.Response;
...@@ -37,6 +41,7 @@ import java.util.Set; ...@@ -37,6 +41,7 @@ import java.util.Set;
37 /** 41 /**
38 * Manage the multicast routing information. 42 * Manage the multicast routing information.
39 */ 43 */
44 +@Beta
40 @Path("mcast") 45 @Path("mcast")
41 public class MulticastRouteWebResource extends AbstractWebResource { 46 public class MulticastRouteWebResource extends AbstractWebResource {
42 47
...@@ -103,4 +108,40 @@ public class MulticastRouteWebResource extends AbstractWebResource { ...@@ -103,4 +108,40 @@ public class MulticastRouteWebResource extends AbstractWebResource {
103 } 108 }
104 return Response.noContent().build(); 109 return Response.noContent().build();
105 } 110 }
111 +
112 + /**
113 + * Create a sink for a multicast route.
114 + * Creates a new sink for an existing multicast route.
115 + *
116 + * @onos.rsModel McastSinkPost
117 + * @param group group IP address
118 + * @param source source IP address
119 + * @param stream sink JSON
120 + * @return status of the request - CREATED if the JSON is correct,
121 + * BAD_REQUEST if the JSON is invalid
122 + */
123 + @POST
124 + @Consumes(MediaType.APPLICATION_JSON)
125 + @Produces(MediaType.APPLICATION_JSON)
126 + @Path("sinks/{group}/{source}")
127 + public Response addSinks(@PathParam("group") String group,
128 + @PathParam("source") String source,
129 + InputStream stream) {
130 + MulticastRouteService service = get(MulticastRouteService.class);
131 + try {
132 + McastRoute route = new McastRoute(IpAddress.valueOf(source), IpAddress.valueOf(group),
133 + McastRoute.Type.STATIC);
134 + ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
135 + jsonTree.path("sinks").forEach(node -> {
136 + ConnectPoint sink = ConnectPoint.deviceConnectPoint(node.asText());
137 + service.addSink(route, sink);
138 + });
139 + } catch (IOException ex) {
140 + throw new IllegalArgumentException(ex);
141 + }
142 +
143 + return Response
144 + .created(URI.create(""))
145 + .build();
146 + }
106 } 147 }
......
1 +{
2 + "type": "object",
3 + "title": "sinks",
4 + "required": [
5 + "sinks"
6 + ],
7 + "properties": {
8 + "sinks": {
9 + "type": "array",
10 + "xml": {
11 + "name": "sinks",
12 + "wrapped": true
13 + },
14 + "items": {
15 + "type": "string",
16 + "title": "sink",
17 + "example": "of:0000000000000001/1"
18 + }
19 + }
20 + }
21 +}