Rusty Eddy
Committed by Gerrit Code Review

Added a CODEC for the MRIB to be used by CLI and REST API

Change-Id: Ia57c2862a642f037b2098c4d143822b2d199bc07
...@@ -31,8 +31,9 @@ public final class IGMPProcessMembership { ...@@ -31,8 +31,9 @@ public final class IGMPProcessMembership {
31 * Process the IGMP Membership report. 31 * Process the IGMP Membership report.
32 * 32 *
33 * @param igmp the deserialized IGMP message. 33 * @param igmp the deserialized IGMP message.
34 + * @param receivedFrom the ConnectPoint this message came from.
34 */ 35 */
35 - public static void processMembership(IGMP igmp, ConnectPoint recievedFrom) { 36 + public static void processMembership(IGMP igmp, ConnectPoint receivedFrom) {
36 } 37 }
37 38
38 } 39 }
......
...@@ -31,6 +31,7 @@ public final class IGMPProcessQuery { ...@@ -31,6 +31,7 @@ public final class IGMPProcessQuery {
31 * Process the IGMP Membership Query message. 31 * Process the IGMP Membership Query message.
32 * 32 *
33 * @param igmp The deserialzed IGMP message 33 * @param igmp The deserialzed IGMP message
34 + * @param receivedFrom the ConnectPoint this message came from.
34 */ 35 */
35 public static void processQuery(IGMP igmp, ConnectPoint receivedFrom) { 36 public static void processQuery(IGMP igmp, ConnectPoint receivedFrom) {
36 } 37 }
......
1 /* 1 /*
2 - * Copyright 2014-2015 Open Networking Laboratory 2 + * Copyright 2015 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -18,11 +18,10 @@ package org.onosproject.mfwd.cli; ...@@ -18,11 +18,10 @@ package org.onosproject.mfwd.cli;
18 import org.apache.karaf.shell.commands.Argument; 18 import org.apache.karaf.shell.commands.Argument;
19 import org.apache.karaf.shell.commands.Command; 19 import org.apache.karaf.shell.commands.Command;
20 import org.onosproject.cli.AbstractShellCommand; 20 import org.onosproject.cli.AbstractShellCommand;
21 -
22 import org.onosproject.mfwd.impl.McastRouteTable; 21 import org.onosproject.mfwd.impl.McastRouteTable;
23 22
24 /** 23 /**
25 - * Delete a multicast route. 24 + * Deletes a multicast route.
26 */ 25 */
27 @Command(scope = "onos", name = "mcast-delete", 26 @Command(scope = "onos", name = "mcast-delete",
28 description = "Delete a multicast route flow") 27 description = "Delete a multicast route flow")
...@@ -43,5 +42,4 @@ public class McastDeleteCommand extends AbstractShellCommand { ...@@ -43,5 +42,4 @@ public class McastDeleteCommand extends AbstractShellCommand {
43 McastRouteTable mrib = McastRouteTable.getInstance(); 42 McastRouteTable mrib = McastRouteTable.getInstance();
44 mrib.removeRoute(sAddr, gAddr); 43 mrib.removeRoute(sAddr, gAddr);
45 } 44 }
46 -} 45 +}
47 -
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -17,7 +17,6 @@ package org.onosproject.mfwd.cli; ...@@ -17,7 +17,6 @@ package org.onosproject.mfwd.cli;
17 17
18 import org.apache.karaf.shell.commands.Argument; 18 import org.apache.karaf.shell.commands.Argument;
19 import org.apache.karaf.shell.commands.Command; 19 import org.apache.karaf.shell.commands.Command;
20 -import org.onlab.packet.IpPrefix;
21 import org.onosproject.cli.AbstractShellCommand; 20 import org.onosproject.cli.AbstractShellCommand;
22 21
23 import org.onosproject.mfwd.impl.McastConnectPoint; 22 import org.onosproject.mfwd.impl.McastConnectPoint;
...@@ -54,24 +53,7 @@ public class McastJoinCommand extends AbstractShellCommand { ...@@ -54,24 +53,7 @@ public class McastJoinCommand extends AbstractShellCommand {
54 @Override 53 @Override
55 protected void execute() { 54 protected void execute() {
56 McastRouteTable mrib = McastRouteTable.getInstance(); 55 McastRouteTable mrib = McastRouteTable.getInstance();
57 - IpPrefix mcast = IpPrefix.valueOf("224.0.0.0/4");
58 - IpPrefix saddr = IpPrefix.valueOf(sAddr);
59 - if (mcast.contains(saddr)) {
60 - print("Error: the source address " + sAddr + " must be an IPv4 unicast address");
61 - return;
62 - }
63 -
64 - IpPrefix gaddr = IpPrefix.valueOf(gAddr);
65 - if (!mcast.contains(gaddr)) {
66 - print("Error: " + gAddr + " must be a multicast group address");
67 - return;
68 - }
69 -
70 McastRouteBase mr = mrib.addRoute(sAddr, gAddr); 56 McastRouteBase mr = mrib.addRoute(sAddr, gAddr);
71 - if (mr == null) {
72 - print("Error: unable to save the multicast state");
73 - return;
74 - }
75 57
76 // Port format "of:0000000000000023/4" 58 // Port format "of:0000000000000023/4"
77 if (ingressPort != null) { 59 if (ingressPort != null) {
......
...@@ -16,21 +16,15 @@ ...@@ -16,21 +16,15 @@
16 package org.onosproject.mfwd.cli; 16 package org.onosproject.mfwd.cli;
17 17
18 import org.apache.karaf.shell.commands.Command; 18 import org.apache.karaf.shell.commands.Command;
19 -import org.onosproject.cli.AbstractShellCommand;
20 -import org.onosproject.net.ConnectPoint;
21 -import org.onlab.packet.IpPrefix;
22 19
23 -import java.util.Map; 20 +import com.fasterxml.jackson.databind.node.ObjectNode;
24 -import java.util.Set; 21 +import com.fasterxml.jackson.databind.JsonNode;
25 22
26 -import org.slf4j.Logger; 23 +import org.onosproject.cli.AbstractShellCommand;
27 import org.onosproject.mfwd.impl.McastRouteTable; 24 import org.onosproject.mfwd.impl.McastRouteTable;
28 -import org.onosproject.mfwd.impl.McastRouteGroup; 25 +import org.onosproject.mfwd.impl.MRibCodec;
29 -
30 -import com.fasterxml.jackson.databind.JsonNode;
31 -import com.fasterxml.jackson.databind.ObjectMapper;
32 -import com.fasterxml.jackson.databind.node.ArrayNode;
33 26
27 +import org.slf4j.Logger;
34 import static org.slf4j.LoggerFactory.getLogger; 28 import static org.slf4j.LoggerFactory.getLogger;
35 29
36 /** 30 /**
...@@ -40,6 +34,7 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -40,6 +34,7 @@ import static org.slf4j.LoggerFactory.getLogger;
40 public class McastShowCommand extends AbstractShellCommand { 34 public class McastShowCommand extends AbstractShellCommand {
41 35
42 private final Logger log = getLogger(getClass()); 36 private final Logger log = getLogger(getClass());
37 + private static final String MCAST_GROUP = "mcastgroup";
43 38
44 @Override 39 @Override
45 protected void execute() { 40 protected void execute() {
...@@ -52,43 +47,14 @@ public class McastShowCommand extends AbstractShellCommand { ...@@ -52,43 +47,14 @@ public class McastShowCommand extends AbstractShellCommand {
52 } 47 }
53 48
54 public JsonNode json(McastRouteTable mrt) { 49 public JsonNode json(McastRouteTable mrt) {
55 - ObjectMapper mapper = new ObjectMapper(); 50 + ObjectNode pushContent = new MRibCodec().encode(mrt , this);
56 - ArrayNode result = mapper.createArrayNode(); 51 + return pushContent;
57 - Map<IpPrefix, McastRouteGroup> mrib4 = mrt.getMrib4();
58 - for (McastRouteGroup mg : mrib4.values()) {
59 - String sAddr = "";
60 - String gAddr = "";
61 - String inPort = "";
62 - String outPorts = "";
63 - if (mg.getSaddr() != null) {
64 - sAddr = mg.getSaddr().toString();
65 - log.info("Multicast Source: " + sAddr);
66 - }
67 - if (mg.getGaddr() != null) {
68 - gAddr = mg.getGaddr().toString();
69 - log.info("Multicast Group: " + gAddr);
70 - }
71 - if (mg.getIngressPoint() != null) {
72 - inPort = mg.getIngressPoint().toString();
73 - log.info("Multicast Ingress: " + inPort);
74 - }
75 - Set<ConnectPoint> eps = mg.getEgressConnectPoints();
76 - if (eps != null && !eps.isEmpty()) {
77 - outPorts = eps.toString();
78 - }
79 - result.add(mapper.createObjectNode()
80 - .put("src", sAddr)
81 - .put("grp", gAddr)
82 - .put("inPort", inPort)
83 - .put("outPorts", outPorts));
84 - }
85 - return result;
86 } 52 }
87 53
88 /** 54 /**
89 * Displays multicast route table entries. 55 * Displays multicast route table entries.
90 * 56 *
91 - * @param mrt route table 57 + * @param mrt Mutlicast Route Table
92 */ 58 */
93 protected void printMrib4(McastRouteTable mrt) { 59 protected void printMrib4(McastRouteTable mrt) {
94 print(mrt.printMcastRouteTable()); 60 print(mrt.printMcastRouteTable());
......
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.mfwd.impl;
17 +
18 +import org.onosproject.codec.CodecContext;
19 +import org.onosproject.codec.JsonCodec;
20 +
21 +import org.onlab.packet.IpPrefix;
22 +
23 +import java.util.Set;
24 +import java.util.Map;
25 +import java.util.Collection;
26 +import java.util.Iterator;
27 +import java.util.Optional;
28 +
29 +import com.fasterxml.jackson.databind.node.ArrayNode;
30 +import com.fasterxml.jackson.databind.node.ObjectNode;
31 +import com.fasterxml.jackson.databind.JsonNode;
32 +import com.fasterxml.jackson.databind.node.JsonNodeFactory;
33 +
34 +import org.slf4j.Logger;
35 +import static org.slf4j.LoggerFactory.getLogger;
36 +
37 +/**
38 + * Encode and Decode the Multicast Route Table in JSON for CLI and REST commands.
39 + */
40 +public class MRibCodec extends JsonCodec<McastRouteTable> {
41 +
42 + private final Logger log = getLogger(getClass());
43 + private static final String SOURCE_ADDRESS = "sourceAddress";
44 + private static final String GROUP_ADDRESS = "groupAddress";
45 + private static final String INGRESS_POINT = "ingressPoint";
46 + private static final String EGRESS_POINT = "egressPoint";
47 + private static final String MCASTCONNECTPOINT = "McastConnectPoint";
48 + private static final String ELEMENTID = "elementId";
49 + private static final String PORTNUMBER = "portNumber";
50 + private static final String MCAST_GROUP = "mcastGroup";
51 +
52 + /**
53 + * Encode the MRIB into json format.
54 + *
55 + * @param mcastRouteTable McastRouteTable
56 + * @param context CodecContext
57 + * @return result ObjectNode
58 + */
59 + @Override
60 + public ObjectNode encode(McastRouteTable mcastRouteTable, CodecContext context) {
61 +
62 + final JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
63 + final ObjectNode macastRouteTabNode = nodeFactory.objectNode();
64 + ArrayNode mcastGroupNode = context.mapper().createArrayNode();
65 + Optional<McastRouteTable> mcastRouteTabOpt = Optional.ofNullable(mcastRouteTable);
66 +
67 + //checking whether the McastRouteTable is present.
68 + if (mcastRouteTabOpt.isPresent()) {
69 + Map<IpPrefix, McastRouteGroup> mrib4 = mcastRouteTabOpt.get().getMrib4();
70 + Optional<Map<IpPrefix, McastRouteGroup>> mrib4Opt = Optional.ofNullable(mrib4);
71 +
72 + //checking whether the mrib4 is present.
73 + if (mrib4Opt.isPresent()) {
74 +
75 + for (McastRouteGroup mg : mrib4Opt.get().values()) {
76 + Collection<McastRouteSource> mcastRoute = mg.getSources().values();
77 + Optional<Collection<McastRouteSource>> mcastRouteOpt = Optional.ofNullable(mcastRoute);
78 +
79 + //checking whether the McastRouteSource List is present.
80 + if (mcastRouteOpt.isPresent()) {
81 + for (McastRouteSource mcastRouteSource : mcastRouteOpt.get()) {
82 + mcastGroupNode.add(createMcastGroupNode(mcastRouteSource, context));
83 + }
84 + macastRouteTabNode.put(MCAST_GROUP, mcastGroupNode);
85 + }
86 + }
87 + }
88 + }
89 + return macastRouteTabNode;
90 + }
91 + /**
92 + * Method for creating the McastGroup object node.
93 + *
94 + * @param mcastRouteSource McastRouteSource
95 + */
96 + private ObjectNode createMcastGroupNode(McastRouteSource mcastRouteSource, CodecContext context) {
97 +
98 + final ObjectNode mcastGroupNode = context.mapper().createObjectNode();
99 + final ObjectNode ingressNode = context.mapper().createObjectNode();
100 + final ObjectNode egressNode = context.mapper().createObjectNode();
101 + final ArrayNode jsonLabelIds = context.mapper().createArrayNode();
102 + final String sAddr = mcastRouteSource.getSaddr().toString();
103 + final String gAddr = mcastRouteSource.getGaddr().toString();
104 +
105 + Optional<String> saddrOpt = Optional.ofNullable(sAddr);
106 + Optional<String> gaddrOpt = Optional.ofNullable(gAddr);
107 +
108 + //checking source address and group address are present.
109 + if (saddrOpt.isPresent() && gaddrOpt.isPresent()) {
110 + mcastGroupNode.put(SOURCE_ADDRESS, saddrOpt.get().toString());
111 + mcastGroupNode.put(GROUP_ADDRESS, gaddrOpt.get().toString());
112 + McastConnectPoint mcastIngCP = mcastRouteSource.getIngressPoint();
113 + Optional<McastConnectPoint> mcastIngCPOpt = Optional.ofNullable(mcastIngCP);
114 +
115 + //checking whether the ingress connection point is present.
116 + if (mcastIngCPOpt.isPresent()) {
117 + ingressNode.put(MCASTCONNECTPOINT, mcastConnectPoint(mcastIngCPOpt.get(), context));
118 + }
119 +
120 + mcastGroupNode.put(INGRESS_POINT , ingressNode);
121 + Set<McastConnectPoint> mcastEgCPSet = mcastRouteSource.getEgressPoints();
122 + Optional<Set<McastConnectPoint>> mcastEgCPOpt = Optional.ofNullable(mcastEgCPSet);
123 +
124 + //checking whether the egress connection points are present.
125 + if (mcastEgCPOpt.isPresent()) {
126 + for (final McastConnectPoint mcastConnectPoint : mcastEgCPOpt.get()) {
127 + jsonLabelIds.add(mcastConnectPoint(mcastConnectPoint, context));
128 + }
129 + }
130 +
131 + egressNode.put(MCASTCONNECTPOINT , jsonLabelIds);
132 + mcastGroupNode.put(EGRESS_POINT , egressNode);
133 + }
134 + return mcastGroupNode;
135 + }
136 +
137 + /**
138 + * Method for creating the McastConnectPoint object node.
139 + *
140 + * @param mcastConnectPoint McastConnectPoint
141 + * @param context CodecContext
142 + * @return mcastCpNode ObjectNode
143 + */
144 + private ObjectNode mcastConnectPoint(McastConnectPoint mcastConnectPoint, CodecContext context) {
145 + final ObjectNode mcastCpNode = context.mapper().createObjectNode();
146 + mcastCpNode.put(ELEMENTID , mcastConnectPoint.getConnectPoint().elementId().toString());
147 + mcastCpNode.put(PORTNUMBER , mcastConnectPoint.getConnectPoint().port().toLong());
148 + return mcastCpNode;
149 + }
150 +
151 + /**
152 + * Decode json format and insert into the flow table.
153 + *
154 + * @param json ObjectNode
155 + * @param context CodecContext
156 + * @return mr McastRouteBase
157 + */
158 + @Override
159 + public McastRouteTable decode(ObjectNode json, CodecContext context) {
160 +
161 + String macAddr = null;
162 + String portNo = null;
163 + String sAddr = json.path(SOURCE_ADDRESS).asText();
164 + String gAddr = json.path(GROUP_ADDRESS).asText();
165 + JsonNode inPntObjNode = (JsonNode) json.path(INGRESS_POINT);
166 + JsonNode egPntArrNode = (JsonNode) json.path(EGRESS_POINT);
167 +
168 + log.debug("sAddr :" + sAddr + " gAddr :" + gAddr + " inPntObjNode :" + inPntObjNode);
169 + log.debug("egPntArrNode :" + egPntArrNode.toString());
170 +
171 + McastRouteTable mrib = McastRouteTable.getInstance();
172 + McastRouteBase mr = mrib.addRoute(sAddr, gAddr);
173 + Optional<JsonNode> inPntOpt = Optional.ofNullable(inPntObjNode);
174 +
175 + if (inPntOpt.isPresent()) {
176 +
177 + JsonNode inMcastCP = inPntOpt.get().path(MCASTCONNECTPOINT);
178 + Optional<JsonNode> inCpOpt = Optional.ofNullable(inMcastCP);
179 +
180 + if (inCpOpt.isPresent()) {
181 + macAddr = inCpOpt.get().path(ELEMENTID).asText();
182 + portNo = inCpOpt.get().path(PORTNUMBER).asText();
183 + mr.addIngressPoint(macAddr + "/" + Long.parseLong(portNo));
184 + }
185 + }
186 +
187 + Optional<JsonNode> egPntOpt = Optional.ofNullable(egPntArrNode);
188 +
189 + if (egPntOpt.isPresent()) {
190 + JsonNode egMcastCP = egPntOpt.get().path(MCASTCONNECTPOINT);
191 + Optional<JsonNode> egMcCpOpt = Optional.ofNullable(egMcastCP);
192 +
193 + if (egMcCpOpt.isPresent()) {
194 + Iterator<JsonNode> egCpIt = egMcCpOpt.get().elements();
195 +
196 + while (egCpIt.hasNext()) {
197 +
198 + JsonNode egMcastCPObj = egCpIt.next();
199 + Optional<JsonNode> egMcCpObOpt = Optional.ofNullable(egMcastCPObj);
200 + if (egMcCpObOpt.isPresent()) {
201 + macAddr = egMcCpObOpt.get().path(ELEMENTID).asText();
202 + portNo = egMcCpObOpt.get().path(PORTNUMBER).asText();
203 + log.debug("macAddr egPort : " + macAddr + " portNo egPort :" + portNo);
204 + mr.addEgressPoint(macAddr + "/" + Long.parseLong(portNo), McastConnectPoint.JoinSource.STATIC);
205 + }
206 + }
207 + }
208 + }
209 + return mrib;
210 + }
211 +}
...@@ -130,6 +130,7 @@ interface McastRoute { ...@@ -130,6 +130,7 @@ interface McastRoute {
130 /** 130 /**
131 * Find the egress connect point if it exists. 131 * Find the egress connect point if it exists.
132 * 132 *
133 + * @param cp ConnectPoint to search for
133 * @return the connect point when found, null otherwise. 134 * @return the connect point when found, null otherwise.
134 */ 135 */
135 public McastConnectPoint findEgressConnectPoint(ConnectPoint cp); 136 public McastConnectPoint findEgressConnectPoint(ConnectPoint cp);
......
...@@ -15,58 +15,135 @@ ...@@ -15,58 +15,135 @@
15 */ 15 */
16 package org.onosproject.mfwd.rest; 16 package org.onosproject.mfwd.rest;
17 17
18 -import com.fasterxml.jackson.databind.JsonNode;
19 -import com.fasterxml.jackson.databind.ObjectMapper;
20 -
21 import java.io.IOException; 18 import java.io.IOException;
22 -import java.io.InputStream; 19 +import com.fasterxml.jackson.databind.ObjectMapper;
23 -import java.util.Map; 20 +import com.fasterxml.jackson.databind.node.ObjectNode;
24 21
22 +import javax.ws.rs.DefaultValue;
23 +import javax.ws.rs.QueryParam;
25 import javax.ws.rs.Consumes; 24 import javax.ws.rs.Consumes;
26 import javax.ws.rs.GET; 25 import javax.ws.rs.GET;
27 import javax.ws.rs.POST; 26 import javax.ws.rs.POST;
27 +import javax.ws.rs.DELETE;
28 import javax.ws.rs.Path; 28 import javax.ws.rs.Path;
29 import javax.ws.rs.Produces; 29 import javax.ws.rs.Produces;
30 import javax.ws.rs.core.MediaType; 30 import javax.ws.rs.core.MediaType;
31 import javax.ws.rs.core.Response; 31 import javax.ws.rs.core.Response;
32 32
33 -import org.onlab.packet.IpPrefix; 33 +import org.onosproject.mfwd.impl.McastConnectPoint;
34 -import org.onlab.rest.BaseResource;
35 -import org.onosproject.mfwd.impl.McastRouteGroup;
36 import org.onosproject.mfwd.impl.McastRouteTable; 34 import org.onosproject.mfwd.impl.McastRouteTable;
35 +import org.onosproject.mfwd.impl.McastRouteBase;
36 +import org.onosproject.mfwd.impl.MRibCodec;
37 +import org.onosproject.rest.AbstractWebResource;
38 +
39 +import org.slf4j.Logger;
40 +import static org.slf4j.LoggerFactory.getLogger;
37 41
38 /** 42 /**
39 * Rest API for Multicast Forwarding. 43 * Rest API for Multicast Forwarding.
40 */ 44 */
41 @Path("mcast") 45 @Path("mcast")
42 -public class McastResource extends BaseResource { 46 +public class McastResource extends AbstractWebResource {
47 +
48 + private final Logger log = getLogger(getClass());
49 + private static final String SOURCE_ADDRESS = "sourceAddress";
50 + private static final String GROUP_ADDRESS = "groupAddress";
51 + private static final String INGRESS_POINT = "ingressPoint";
52 + private static final String EGRESS_POINT = "egressPoint";
53 + private static final String MCAST_GROUP = "mcastGroup";
43 54
44 /** 55 /**
45 * Retrieve the multicast route table. 56 * Retrieve the multicast route table.
57 + *
46 * @return the multicast route table. 58 * @return the multicast route table.
47 * @throws IOException if an error occurs 59 * @throws IOException if an error occurs
48 */ 60 */
61 + @Path("show")
49 @GET 62 @GET
50 @Produces(MediaType.APPLICATION_JSON) 63 @Produces(MediaType.APPLICATION_JSON)
51 public Response showAll() throws IOException { 64 public Response showAll() throws IOException {
52 - ObjectMapper mapper = new ObjectMapper(); 65 + McastRouteTable mrt = McastRouteTable.getInstance();
53 - McastRouteTable mcastRouteTable = McastRouteTable.getInstance(); 66 + ObjectNode pushContent = new MRibCodec().encode(mrt , this);
54 - Map<IpPrefix, McastRouteGroup> map = mcastRouteTable.getMrib4(); 67 + return ok(pushContent.toString()).build();
55 - return Response.ok(mapper.createObjectNode().toString()).build();
56 } 68 }
57 69
58 /** 70 /**
59 - * Static join of a multicast flow. 71 + * Static join a multicast flow.
60 - * @param input source, group, ingress connectPoint egress connectPoints 72 + *
61 - * @return status of static join 73 + * @param sAddr source address to join
62 - * @throws IOException if an error occurs 74 + * @param gAddr group address to join
75 + * @param ports ingress and egress ConnectPoints to join
76 + * @return the Result of the join
77 + * @throws IOException if something failed with the join command
63 */ 78 */
79 + @Path("/join")
64 @POST 80 @POST
65 @Consumes(MediaType.APPLICATION_JSON) 81 @Consumes(MediaType.APPLICATION_JSON)
66 - @Produces(MediaType.APPLICATION_JSON) 82 + @Produces(MediaType.TEXT_PLAIN)
67 - public Response join(InputStream input) throws IOException { 83 + public Response join(@QueryParam("src") String sAddr,
84 + @QueryParam("grp") String gAddr,
85 + @DefaultValue("") @QueryParam("ports") String ports)
86 + throws IOException {
87 +
68 ObjectMapper mapper = new ObjectMapper(); 88 ObjectMapper mapper = new ObjectMapper();
69 - JsonNode cfg = mapper.readTree(input); 89 + log.debug("Source IP Address: " + sAddr);
70 - return null; 90 + log.debug("Destination IP Address: " + gAddr);
91 + log.debug("Ingress and Egress ports: " + ports);
92 +
93 + String output = "Insertion Faild";
94 + if (sAddr != null && gAddr != null && ports != null) {
95 +
96 + String[] portArr = ports.split(",");
97 + log.debug("Port Array Length: " + portArr.length);
98 + McastRouteTable mrt = McastRouteTable.getInstance();
99 + McastRouteBase mr = mrt.addRoute(sAddr, gAddr);
100 +
101 + // Port format "of:0000000000000023/4"
102 + log.debug("checking inside outer if: " + portArr.length);
103 +
104 + if (mr != null && portArr != null && portArr.length > 0) {
105 +
106 + String inCP = portArr[0];
107 + log.debug("Ingress port provided: " + inCP);
108 + mr.addIngressPoint(inCP);
109 +
110 + for (int i = 1; i < portArr.length; i++) {
111 + String egCP = portArr[i];
112 + log.debug("Egress port provided: " + egCP);
113 + mr.addEgressPoint(egCP, McastConnectPoint.JoinSource.STATIC);
114 + }
115 + mrt.printMcastRouteTable();
116 + output = "Successfully Inserted";
117 + }
118 + } else {
119 + output = "Please Insert the rest uri correctly";
120 + }
121 + return Response.ok(output).build();
122 + }
123 +
124 + /**
125 + * Delete multicast state.
126 + *
127 + * @param src address to be deleted
128 + * @param grp address to be deleted
129 + * @return status of delete if successful
130 + */
131 + @Path("/delete")
132 + @DELETE
133 + @Consumes(MediaType.TEXT_PLAIN)
134 + @Produces(MediaType.TEXT_PLAIN)
135 + public Response removeMcastFlow(@QueryParam("src") String src,
136 + @QueryParam("grp") String grp) {
137 +
138 + String resp = "Failed to delete";
139 + log.info("Source IP Address to delete: " + src);
140 + log.info("Destination IP Address to delete: " + grp);
141 + McastRouteTable mrt = McastRouteTable.getInstance();
142 + if (src != null && grp != null) {
143 + mrt.removeRoute(src, grp);
144 + resp = "Deleted flow for src " + src + " and grp " + grp;
145 + }
146 +
147 + return Response.ok(resp).build();
71 } 148 }
72 } 149 }
......