From 1ccfc771118ea67d65720f9e39e73e296852e69b Mon Sep 17 00:00:00 2001 From: kjwon15 Date: Thu, 29 Jan 2015 18:04:21 +0900 Subject: [PATCH 1/7] Cleanup dirty codes --- .../staticentrymanager/RestSwitchApi.java | 153 ++++++++---------- 1 file changed, 71 insertions(+), 82 deletions(-) diff --git a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java index 4c62871a..2b3d607c 100644 --- a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java +++ b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java @@ -46,6 +46,28 @@ public void handle(Request request, Response response) { } } + private void makeResult(Response response, Status status, String message) { + StringWriter sWriter = new StringWriter(); + JsonFactory jsonFactory = new JsonFactory(); + JsonGenerator jsonGenerator; + + try { + jsonGenerator = jsonFactory.createJsonGenerator(sWriter); + jsonGenerator.writeStartObject(); + jsonGenerator.writeFieldName("result"); + jsonGenerator.writeString(message); + jsonGenerator.writeEndObject(); + jsonGenerator.close(); + + String r = sWriter.toString(); + response.setEntity(r, MediaType.APPLICATION_JSON); + response.setStatus(status); + } catch (Exception e) { + e.printStackTrace(); + } + + } + /** * List entries. * @@ -54,12 +76,12 @@ public void handle(Request request, Response response) { */ private void handleGet(Request request, Response response) { String dpid = (String) request.getAttributes().get("dpid"); - Set flows = new HashSet(); if (! (dpid.toLowerCase().equals("all") || manager.isSwitchExists(dpid))) { - response.setStatus(Status.CLIENT_ERROR_NOT_FOUND); + makeResult(response, + Status.CLIENT_ERROR_NOT_FOUND, + "That switch is not exists."); return; - // FIXME: give reason why. } ObjectMapper om = new ObjectMapper(); @@ -85,16 +107,13 @@ private void handlePost(Request request, Response response) { String dpid = (String) request.getAttributes().get("dpid"); if (!manager.isSwitchExists(dpid)) { - response.setStatus(Status.CLIENT_ERROR_NOT_FOUND); + makeResult(response, + Status.CLIENT_ERROR_NOT_FOUND, + "That switch is not exists."); return; - // FIXME: give reason why. } String jsonString = request.getEntityAsText(); - StringWriter sWriter = new StringWriter(); - JsonFactory jsonFactory = new JsonFactory(); - JsonGenerator jsonGenerator; - String status; Map entry; Object flowName; @@ -102,7 +121,8 @@ private void handlePost(Request request, Response response) { try { entry = StaticFlowEntry.jsonToStaticFlowEntry(jsonString); if (entry == null) { - throw new Exception("The input is null"); + makeResult(response, Status.CLIENT_ERROR_BAD_REQUEST, "The input was null"); + return; } flowName = entry.get("name"); @@ -110,40 +130,36 @@ private void handlePost(Request request, Response response) { StaticFlowEntry.checkInputField(entry.keySet()); StaticFlowEntry.checkMatchPrerequisite(entry); manager.addFlow((String) flowName, entry, dpid); - status = "Entry pushed: " + flowName; + + String message = "Entry pushed: " + flowName; + makeResult(response, Status.SUCCESS_CREATED, message); } else { - status = "The name field is indispensable"; + makeResult(response, + Status.CLIENT_ERROR_BAD_REQUEST, + "The name field is indispensable"); } response.setStatus(Status.SUCCESS_CREATED); } catch (UnsupportedOperationException e) { - response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST); - status = "Fail to push entry: Wrong version for the switch"; + makeResult(response, + Status.CLIENT_ERROR_BAD_REQUEST, + "Fail to push entry: Wrong version for the switch"); } catch (StaticFlowEntryException e) { - response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST); - status = e.getReason(); + makeResult(response, + Status.CLIENT_ERROR_BAD_REQUEST, + e.getReason()); } catch (IOException e) { - response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST); - status = "Fail to parse JSON format"; + makeResult(response, + Status.CLIENT_ERROR_BAD_REQUEST, + "Fail to parse JSON format"); e.printStackTrace(); } catch (Exception e) { - response.setStatus(Status.SERVER_ERROR_INTERNAL); + makeResult(response, + Status.SERVER_ERROR_INTERNAL, + "Fail to insert entry"); e.printStackTrace(); - status = "Fail to insert entry"; } - try { - jsonGenerator = jsonFactory.createJsonGenerator(sWriter); - jsonGenerator.writeStartObject(); - jsonGenerator.writeFieldName("result"); - jsonGenerator.writeString(status); - jsonGenerator.writeEndObject(); - jsonGenerator.close(); - } catch (Exception e) { - e.printStackTrace(); - } - String r = sWriter.toString(); - response.setEntity(r, MediaType.APPLICATION_JSON); } /** @@ -154,11 +170,6 @@ private void handlePost(Request request, Response response) { private void handlePut(Request request, Response response) { String dpid = (String) request.getAttributes().get("dpid"); - StringWriter sWriter = new StringWriter(); - JsonFactory jsonFactory = new JsonFactory(); - JsonGenerator jsonGenerator; - String status; - if (!(dpid.toLowerCase().equals("all") || manager.isSwitchExists(dpid))) { response.setStatus(Status.CLIENT_ERROR_NOT_FOUND); return; @@ -169,46 +180,41 @@ private void handlePut(Request request, Response response) { if (dpid.toLowerCase().equals("all")) { if (!manager.getStaticFlowEntryStorage().getFlowModNameToDpidIndex().isEmpty()) { manager.reloadAllFlowsToSwitch(); - status = "All entries are reloaded to switches."; + makeResult(response, + Status.SUCCESS_OK, + "All entries are reloaded to switches."); } else { - status = "There is no entry"; + makeResult(response, + Status.CLIENT_ERROR_NOT_FOUND, + "There is no entry"); } } else { if (!manager.getStaticFlowEntryStorage().getDpidToFlowModNameIndex().isEmpty()) { manager.reloadFlowsToSwitch(dpid); - status = "Entries are reloaded to switch: " + dpid + "."; + makeResult(response, + Status.SUCCESS_OK, + "Entries are reloaded to switch: " + dpid + "."); } else { - status = "There is no entry"; + makeResult(response, + Status.CLIENT_ERROR_NOT_FOUND, + "There is no entry"); } } } catch (UnsupportedOperationException e) { - response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST); - status = "Fail to reload entry: Wrong version for the switch"; + makeResult(response, + Status.CLIENT_ERROR_BAD_REQUEST, + "Fail to reload entry: Wrong version for the switch"); } catch (Exception e) { e.printStackTrace(); - response.setStatus(Status.SERVER_ERROR_INTERNAL); - status = "Fail to reload entries to switches."; + makeResult(response, + Status.SERVER_ERROR_INTERNAL, + "Fail to reload entries to switches."); } - - try { - jsonGenerator = jsonFactory.createJsonGenerator(sWriter); - jsonGenerator.writeStartObject(); - jsonGenerator.writeFieldName("result"); - jsonGenerator.writeString(status); - jsonGenerator.writeEndObject(); - jsonGenerator.close(); - } - catch (Exception e) { - e.printStackTrace(); - } - - String r = sWriter.toString(); - response.setEntity(r, MediaType.APPLICATION_JSON); } /** @@ -219,11 +225,6 @@ private void handlePut(Request request, Response response) { private void handleDelete(Request request, Response response) { String dpid = (String) request.getAttributes().get("dpid"); - StringWriter sWriter = new StringWriter(); - JsonFactory jsonFactory = new JsonFactory(); - JsonGenerator jsonGenerator; - StringBuilder status = new StringBuilder(); - if (!(dpid.toLowerCase().equals("all") || manager.isSwitchExists(dpid))) { response.setStatus(Status.CLIENT_ERROR_NOT_FOUND); return; @@ -265,27 +266,15 @@ private void handleDelete(Request request, Response response) { } if (ret) { - status.append("All entries are cleared."); + makeResult(response, Status.SUCCESS_OK, "All entries are cleared."); } else { - status.append("Failure clearing entries: "); - status.append(exceptionlist); + makeResult(response, + Status.SERVER_ERROR_INTERNAL, + "Failure clearing entries: " + exceptionlist ); } } else { - status.append("There is no entry."); - } - - try { - jsonGenerator = jsonFactory.createJsonGenerator(sWriter); - jsonGenerator.writeStartObject(); - jsonGenerator.writeFieldName("result"); - jsonGenerator.writeString(status.toString()); - jsonGenerator.writeEndObject(); - jsonGenerator.close(); - } catch (Exception e) { - e.printStackTrace(); + makeResult(response, Status.CLIENT_ERROR_BAD_REQUEST, "There is no entry."); } - String r = sWriter.toString(); - response.setEntity(r, MediaType.APPLICATION_JSON); } } From 52dd71bab55e6b1c3f8a3c0f21f0a2e1b29984b2 Mon Sep 17 00:00:00 2001 From: kjwon15 Date: Mon, 2 Feb 2015 09:58:26 +0900 Subject: [PATCH 2/7] Write docstring, reformat code --- .../staticentrymanager/RestSwitchApi.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java index 2b3d607c..14b6c9a6 100644 --- a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java +++ b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java @@ -32,7 +32,7 @@ public RestSwitchApi(OFMStaticFlowEntryManager manager) { public void handle(Request request, Response response) { Method method = request.getMethod(); - if(method == Method.GET) { + if (method == Method.GET) { handleGet(request, response); } else if (method == Method.POST) { handlePost(request, response); @@ -46,6 +46,14 @@ public void handle(Request request, Response response) { } } + + /** + * Make json result for response. + * + * @param response {@link Response} to write status code. + * @param status {@link Status} Status code. + * @param message Message for this response. + */ private void makeResult(Response response, Status status, String message) { StringWriter sWriter = new StringWriter(); JsonFactory jsonFactory = new JsonFactory(); @@ -77,7 +85,7 @@ private void makeResult(Response response, Status status, String message) { private void handleGet(Request request, Response response) { String dpid = (String) request.getAttributes().get("dpid"); - if (! (dpid.toLowerCase().equals("all") || manager.isSwitchExists(dpid))) { + if (!(dpid.toLowerCase().equals("all") || manager.isSwitchExists(dpid))) { makeResult(response, Status.CLIENT_ERROR_NOT_FOUND, "That switch is not exists."); @@ -164,6 +172,7 @@ private void handlePost(Request request, Response response) { /** * Reload entries. + * * @param request * @param response */ @@ -183,33 +192,28 @@ private void handlePut(Request request, Response response) { makeResult(response, Status.SUCCESS_OK, "All entries are reloaded to switches."); - } - else { + } else { makeResult(response, Status.CLIENT_ERROR_NOT_FOUND, "There is no entry"); } - } - else { + } else { if (!manager.getStaticFlowEntryStorage().getDpidToFlowModNameIndex().isEmpty()) { manager.reloadFlowsToSwitch(dpid); makeResult(response, Status.SUCCESS_OK, "Entries are reloaded to switch: " + dpid + "."); - } - else { + } else { makeResult(response, Status.CLIENT_ERROR_NOT_FOUND, "There is no entry"); } } - } - catch (UnsupportedOperationException e) { + } catch (UnsupportedOperationException e) { makeResult(response, Status.CLIENT_ERROR_BAD_REQUEST, "Fail to reload entry: Wrong version for the switch"); - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); makeResult(response, Status.SERVER_ERROR_INTERNAL, @@ -219,6 +223,7 @@ private void handlePut(Request request, Response response) { /** * Clear switch. + * * @param request * @param response */ @@ -270,7 +275,7 @@ private void handleDelete(Request request, Response response) { } else { makeResult(response, Status.SERVER_ERROR_INTERNAL, - "Failure clearing entries: " + exceptionlist ); + "Failure clearing entries: " + exceptionlist); } } else { makeResult(response, Status.CLIENT_ERROR_BAD_REQUEST, "There is no entry."); From dd5d0da8d25858463a37df3b5259af8257c616c5 Mon Sep 17 00:00:00 2001 From: kjwon15 Date: Tue, 3 Feb 2015 17:22:46 +0900 Subject: [PATCH 3/7] Fix typo --- .../controller/module/staticentrymanager/RestSwitchApi.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java index 14b6c9a6..5a2abeb4 100644 --- a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java +++ b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java @@ -88,7 +88,7 @@ private void handleGet(Request request, Response response) { if (!(dpid.toLowerCase().equals("all") || manager.isSwitchExists(dpid))) { makeResult(response, Status.CLIENT_ERROR_NOT_FOUND, - "That switch is not exists."); + "That switch doesn't exists."); return; } @@ -117,7 +117,7 @@ private void handlePost(Request request, Response response) { if (!manager.isSwitchExists(dpid)) { makeResult(response, Status.CLIENT_ERROR_NOT_FOUND, - "That switch is not exists."); + "That switch doesn't exists."); return; } From ed44bc21bf287810642506305e7f07f48c5e1868 Mon Sep 17 00:00:00 2001 From: kjwon15 Date: Tue, 3 Feb 2015 17:37:31 +0900 Subject: [PATCH 4/7] Delete flow by name --- .../RESTDeleteByNameApi.java | 54 ------------------- .../staticentrymanager/RestSwitchApi.java | 24 +++++++++ .../StaticFlowEntryStorage.java | 23 ++++---- 3 files changed, 35 insertions(+), 66 deletions(-) delete mode 100644 Torpedo/src/etri/sdn/controller/module/staticentrymanager/RESTDeleteByNameApi.java diff --git a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RESTDeleteByNameApi.java b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RESTDeleteByNameApi.java deleted file mode 100644 index e798850c..00000000 --- a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RESTDeleteByNameApi.java +++ /dev/null @@ -1,54 +0,0 @@ -package etri.sdn.controller.module.staticentrymanager; - -import java.io.StringWriter; - -import org.codehaus.jackson.JsonFactory; -import org.codehaus.jackson.JsonGenerator; -import org.restlet.Request; -import org.restlet.Response; -import org.restlet.Restlet; -import org.restlet.data.MediaType; - -public class RESTDeleteByNameApi extends Restlet { - - private OFMStaticFlowEntryManager manager; - - public RESTDeleteByNameApi(OFMStaticFlowEntryManager manager) { - this.manager = manager; - } - - @Override - public void handle(Request request, Response response) { - StringWriter sWriter = new StringWriter(); - JsonFactory f = new JsonFactory(); - JsonGenerator g; - String status = null; - - String flowName = (String) request.getAttributes().get("name"); - - if ( !manager.getAllFlows().keySet().contains(flowName) ) { - status = "There is no entry"; - } else { - try { - manager.deleteFlow(flowName); - status = "Entry deleted: " + flowName; - } catch (Exception e){ - e.printStackTrace(); - } - } - - try { - g = f.createJsonGenerator(sWriter); - g.writeStartObject(); - g.writeFieldName("result"); - g.writeString(status); - g.writeEndObject(); - g.close(); - } catch (Exception e){ - e.printStackTrace(); - } - - String r = sWriter.toString(); - response.setEntity(r, MediaType.APPLICATION_JSON); - } -} diff --git a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java index 5a2abeb4..7e6b0aa6 100644 --- a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java +++ b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java @@ -229,7 +229,17 @@ private void handlePut(Request request, Response response) { */ private void handleDelete(Request request, Response response) { String dpid = (String) request.getAttributes().get("dpid"); + String name = (String) request.getAttributes().get("name"); + if (name != null) { + clearRules(response, dpid); + } else { + deleteRule(response, dpid, name); + } + + } + + private void clearRules(Response response, String dpid) { if (!(dpid.toLowerCase().equals("all") || manager.isSwitchExists(dpid))) { response.setStatus(Status.CLIENT_ERROR_NOT_FOUND); return; @@ -280,6 +290,20 @@ private void handleDelete(Request request, Response response) { } else { makeResult(response, Status.CLIENT_ERROR_BAD_REQUEST, "There is no entry."); } + } + private void deleteRule(Response response, String dpid, String name) { + if (!manager.getAllFlows().keySet().contains(name)) { + makeResult(response, Status.CLIENT_ERROR_NOT_FOUND, "There is no entry"); + return; + } + + try { + manager.deleteFlow(name); + makeResult(response, Status.SUCCESS_OK, "Entry deleted: " + name); + } catch (StaticFlowEntryException e) { + makeResult(response, Status.SERVER_ERROR_INTERNAL, e.getMessage()); + e.printStackTrace(); + } } } diff --git a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntryStorage.java b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntryStorage.java index a40932d5..99c6ede9 100644 --- a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntryStorage.java +++ b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntryStorage.java @@ -65,9 +65,12 @@ private void initRestApis() { * Array of RESTApi objects. * Each objects represent a REST call handler routine bound to a specific URI. */ + + RestSwitchApi restSwitchApi = new RestSwitchApi(manager); + RESTApi[] tmp = { /* - * LIST example + * LIST example * OF1.0,1.3: curl http://{controller_ip}:{rest_api_port}/wm/staticflowentry/all/json * curl http://{controller_ip}:{rest_api_port}/wm/staticflowentry/00:00:00:00:00:00:00:01/json * @@ -85,21 +88,17 @@ private void initRestApis() { * OF1.0,1.3: curl -X PUT http://{controller_ip}:{rest_api_port}/wm/staticflowentry/all/json * curl -X PUT http://{controller_ip}:{rest_api_port}/wm/staticflowentry/00:00:00:00:00:00:00:01/json * - */ - new RESTApi("/wm/staticflowentry/{dpid}/json", - new RestSwitchApi(manager)), - - /* * DELETE by name example - * OF1.0,1.3: curl -X DELETE -d '{"name":"s1"}' http://{controller_ip}:{rest_api_port}/wm/staticflowentry/json - * + * OF1.0,1.3: curl -X DELETE http://{controller_ip}:{rest_api_port}/wm/staticflowentry/00:00:00:00:00:00:00:01/s1/json + * * This object is an additional implements REST handler routines (i.e. RFC2616). * According to RFC2616, DELETE method cannot have data fields. */ - new RESTApi( - "/wm/staticflowentry/{dpid}/{name}/json", - new RESTDeleteByNameApi(manager) - ) + new RESTApi("/wm/staticflowentry/{dpid}/json", + restSwitchApi), + new RESTApi("/wm/staticflowentry/{dpid}/{name}/json", + restSwitchApi), + }; this.apis = tmp; From e461e588d9e876e382bda894853245c7af8f04e8 Mon Sep 17 00:00:00 2001 From: kjwon15 Date: Tue, 3 Feb 2015 17:50:48 +0900 Subject: [PATCH 5/7] Post flow more restful --- .../module/staticentrymanager/RestSwitchApi.java | 9 ++++++++- .../module/staticentrymanager/StaticFlowEntry.java | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java index 7e6b0aa6..a2b93af0 100644 --- a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java +++ b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/RestSwitchApi.java @@ -113,6 +113,13 @@ private void handleGet(Request request, Response response) { */ private void handlePost(Request request, Response response) { String dpid = (String) request.getAttributes().get("dpid"); + String name = (String) request.getAttributes().get("name"); + + if (name == null) { + // Post to /wm/staticflowentry/00:00~~00:00/json is not allowed. + makeResult(response, Status.CLIENT_ERROR_METHOD_NOT_ALLOWED, ""); + return; + } if (!manager.isSwitchExists(dpid)) { makeResult(response, @@ -127,7 +134,7 @@ private void handlePost(Request request, Response response) { Object flowName; try { - entry = StaticFlowEntry.jsonToStaticFlowEntry(jsonString); + entry = StaticFlowEntry.jsonToStaticFlowEntry(dpid, name, jsonString); if (entry == null) { makeResult(response, Status.CLIENT_ERROR_BAD_REQUEST, "The input was null"); return; diff --git a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntry.java b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntry.java index c0490525..11ffaa3e 100644 --- a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntry.java +++ b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntry.java @@ -949,7 +949,7 @@ private static List> jsonToActions(String jsontext) throws I * * @throws IOException */ - public static Map jsonToStaticFlowEntry(String jsontext) throws IOException { + public static Map jsonToStaticFlowEntry(String sw, String name, String jsontext) throws IOException { Map entry = new LinkedHashMap(); MappingJsonFactory f = new MappingJsonFactory(); ObjectMapper mapper = new ObjectMapper(f); @@ -970,6 +970,9 @@ else if (field.getKey() == "actions") { } } + entry.put("switch", sw); + entry.put("name", name); + // if (Main.debug){ // System.out.println("input entry : " + jsontext); // System.out.println("converted entry: " + entry); From 49559e904f49741f8e07455f10cae18141007490 Mon Sep 17 00:00:00 2001 From: kjwon15 Date: Tue, 3 Feb 2015 17:55:40 +0900 Subject: [PATCH 6/7] New example --- .../module/staticentrymanager/StaticFlowEntryStorage.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntryStorage.java b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntryStorage.java index 99c6ede9..352f5573 100644 --- a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntryStorage.java +++ b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntryStorage.java @@ -75,10 +75,9 @@ private void initRestApis() { * curl http://{controller_ip}:{rest_api_port}/wm/staticflowentry/00:00:00:00:00:00:00:01/json * * ADD example - * OF1.0,1.3: curl http://{controller_ip}:{rest_api_port}/wm/staticflowentry/all/json - * curl -d '{"name":"s1","priority":"101","eth_type":"0x0800","ipv4_src":"10.0.0.1","ipv4_dst":"10.0.0.2","active":"true","instructions":[{"apply_actions":[{"output":"2"}]}]}' http://{controller_ip}:{rest_api_port}/wm/staticflowentry/00:00:00:00:00:00:00:01/json - * curl -d '{"name":"s20","priority":"1001","eth_type":"0x0806","ipv4_dst":"10.0.0.4","active":"true","instructions":[{"apply_actions":[{"output":"3"}]}]}' http://{controller_ip}:{rest_api_port}/wm/staticflowentry/00:00:00:00:00:00:00:02/json - * curl -d '{"name":"s1","priority":"1001","eth_type":"0x0800","ipv4_dst":"10.0.0.3","active":"true","instructions":[{"apply_actions":[{"set_field":{"ipv4_dst":"10.0.0.2"}},{"output":"2"}]}]}' http://{controller_ip}:{rest_api_port}/wm/staticflowentry/00:00:00:00:00:00:00:01/json + * OF1.0,1.3: curl http://{controller_ip}:{rest_api_port}/wm/staticflowentry/00:00:00:00:00:00:00:01/s1/json -d '{"priority":"101","eth_type":"0x0800","ipv4_src":"10.0.0.1","ipv4_dst":"10.0.0.2","active":"true","instructions":[{"apply_actions":[{"output":"2"}]}]}' + * curl http://{controller_ip}:{rest_api_port}/wm/staticflowentry/00:00:00:00:00:00:00:02/s20/json -d '{"priority":"1001","eth_type":"0x0806","ipv4_dst":"10.0.0.4","active":"true","instructions":[{"apply_actions":[{"output":"3"}]}]}' + * curl http://{controller_ip}:{rest_api_port}/wm/staticflowentry/00:00:00:00:00:00:00:01/s1/json -d '{"priority":"1001","eth_type":"0x0800","ipv4_dst":"10.0.0.3","active":"true","instructions":[{"apply_actions":[{"set_field":{"ipv4_dst":"10.0.0.2"}},{"output":"2"}]}]}' * * CLEAR example * OF1.0,1.3: curl -X DELETE http://{controller_ip}:{rest_api_port}/wm/staticflowentry/all/json From c7c1913caa63f6cc3950a80d073ecc93f4d60779 Mon Sep 17 00:00:00 2001 From: kjwon15 Date: Wed, 25 Feb 2015 09:27:08 +0900 Subject: [PATCH 7/7] Indenting --- .../controller/module/firewall/RESTDeleteByIDApi.java | 4 ++-- .../module/staticentrymanager/StaticFlowEntry.java | 4 ++-- .../staticentrymanager/StaticFlowEntryStorage.java | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Torpedo/src/etri/sdn/controller/module/firewall/RESTDeleteByIDApi.java b/Torpedo/src/etri/sdn/controller/module/firewall/RESTDeleteByIDApi.java index 8a919302..a15a26a2 100644 --- a/Torpedo/src/etri/sdn/controller/module/firewall/RESTDeleteByIDApi.java +++ b/Torpedo/src/etri/sdn/controller/module/firewall/RESTDeleteByIDApi.java @@ -26,8 +26,8 @@ public void handle(Request request, Response response) { String ruleId = (String) request.getAttributes().get("ruleid"); - if ( manager.getFirewallStorage().getFirewallEntryTable().getFirewallEntry(ruleId) != null ) { - manager.deleteRule( Integer.parseInt(ruleId) ); + if (manager.getFirewallStorage().getFirewallEntryTable().getFirewallEntry(ruleId) != null) { + manager.deleteRule(Integer.parseInt(ruleId)); status = "Rule deleted"; } else { logger.error("Error! Can't delete, a rule with ID {} doesn't exist.", ruleId); diff --git a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntry.java b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntry.java index 11ffaa3e..e6799440 100644 --- a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntry.java +++ b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntry.java @@ -970,8 +970,8 @@ else if (field.getKey() == "actions") { } } - entry.put("switch", sw); - entry.put("name", name); + entry.put("switch", sw); + entry.put("name", name); // if (Main.debug){ // System.out.println("input entry : " + jsontext); diff --git a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntryStorage.java b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntryStorage.java index 352f5573..c915646d 100644 --- a/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntryStorage.java +++ b/Torpedo/src/etri/sdn/controller/module/staticentrymanager/StaticFlowEntryStorage.java @@ -66,11 +66,11 @@ private void initRestApis() { * Each objects represent a REST call handler routine bound to a specific URI. */ - RestSwitchApi restSwitchApi = new RestSwitchApi(manager); + RestSwitchApi restSwitchApi = new RestSwitchApi(manager); RESTApi[] tmp = { /* - * LIST example + * LIST example * OF1.0,1.3: curl http://{controller_ip}:{rest_api_port}/wm/staticflowentry/all/json * curl http://{controller_ip}:{rest_api_port}/wm/staticflowentry/00:00:00:00:00:00:00:01/json * @@ -94,9 +94,9 @@ private void initRestApis() { * According to RFC2616, DELETE method cannot have data fields. */ new RESTApi("/wm/staticflowentry/{dpid}/json", - restSwitchApi), - new RESTApi("/wm/staticflowentry/{dpid}/{name}/json", - restSwitchApi), + restSwitchApi), + new RESTApi("/wm/staticflowentry/{dpid}/{name}/json", + restSwitchApi), };