Skip to content
Snippets Groups Projects
Commit 16f9c44a authored by Ryan Izard's avatar Ryan Izard
Browse files

Merge branch 'master' of http://github.com/floodlight/floodlight into v1.0

parents db965ec9 49e66f5c
No related branches found
No related tags found
No related merge requests found
/**
* Copyright 2011, Big Switch Networks, Inc.
* Originally created by Amer Tahir
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
**/
package net.floodlightcontroller.firewall;
import org.restlet.resource.Get;
import org.restlet.resource.Put;
import org.restlet.data.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* Rest API endpoint to disable the firewall
*/
public class FirewallDisableResource extends FirewallResourceBase {
private static final Logger log = LoggerFactory.getLogger(FirewallDisableResource.class);
@Get("json")
public Object handleRequest() {
log.warn("call to FirewallDisableResource with method GET is not allowed. Use PUT: ");
setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
return "{\"status\" : \"failure\", \"details\" : \"Use PUT to disable firewall\"}";
}
@Put("json")
public Object handlePut() {
IFirewallService firewall = getFirewallService();
firewall.enableFirewall(false);
setStatus(Status.SUCCESS_OK);
return "{\"status\" : \"success\", \"details\" : \"firewall stopped\"}";
}
}
/**
* Copyright 2011, Big Switch Networks, Inc.
* Originally created by Amer Tahir
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
**/
package net.floodlightcontroller.firewall;
import org.restlet.resource.Get;
import org.restlet.resource.Put;
import org.restlet.data.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* Rest API endpoint to enable the firewall
*/
public class FirewallEnableResource extends FirewallResourceBase {
private static final Logger log = LoggerFactory.getLogger(FirewallEnableResource.class);
@Get("json")
public Object handleRequest() {
log.warn("call to FirewallDisableResource with method GET is not allowed. Use PUT: ");
setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
return "{\"status\" : \"failure\", \"details\" : \"Use PUT to enable firewall\"}";
}
@Put("json")
public Object handlePut() {
IFirewallService firewall = getFirewallService();
firewall.enableFirewall(true);
setStatus(Status.SUCCESS_OK);
return "{\"status\" : \"success\", \"details\" : \"firewall running\"}";
}
}
/**
* Copyright 2011, Big Switch Networks, Inc.
* Originally created by Amer Tahir
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
**/
package net.floodlightcontroller.firewall;
import org.restlet.resource.ServerResource;
/*
* Base class for Firewall REST API endpoints.
* Provides a convenience method to retrieve the firewall service
*/
class FirewallResourceBase extends ServerResource {
IFirewallService getFirewallService() {
return (IFirewallService)getContext().getAttributes().
get(IFirewallService.class.getCanonicalName());
}
}
/**
* Copyright 2011, Big Switch Networks, Inc.
* Originally created by Amer Tahir
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
**/
package net.floodlightcontroller.firewall;
import org.restlet.resource.Get;
/*
* REST API for retrieving the status of the firewall
*/
public class FirewallStatusResource extends FirewallResourceBase {
@Get("json")
public Object handleRequest() {
IFirewallService firewall = this.getFirewallService();
if (firewall.isEnabled())
return "{\"result\" : \"firewall enabled\"}";
else
return "{\"result\" : \"firewall disabled\"}";
}
}
/**
* Copyright 2011, Big Switch Networks, Inc.
* Originally created by Amer Tahir
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
**/
package net.floodlightcontroller.firewall;
import java.io.IOException;
import org.restlet.resource.Get;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FirewallStorageRulesResource extends FirewallResourceBase {
// REST API for retrieving rules from storage
private static final Logger log = LoggerFactory.getLogger(FirewallStorageRulesResource.class);
@Get("json")
public Object handleRequest() {
IFirewallService firewall = getFirewallService();
return firewall.getStorageRules();
}
}
......@@ -26,75 +26,42 @@ import com.fasterxml.jackson.databind.MappingJsonFactory;
import org.restlet.resource.Post;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
import org.restlet.data.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FirewallResource extends ServerResource {
protected static Logger log = LoggerFactory.getLogger(FirewallResource.class);
@Get("json")
public Object handleRequest() {
IFirewallService firewall =
(IFirewallService)getContext().getAttributes().
get(IFirewallService.class.getCanonicalName());
String op = (String) getRequestAttributes().get("op");
// REST API check status
if (op.equalsIgnoreCase("status")) {
if (firewall.isEnabled())
return "{\"result\" : \"firewall enabled\"}";
else
return "{\"result\" : \"firewall disabled\"}";
}
public class FirewallSubnetMaskResource extends FirewallResourceBase {
// REST API to get or set local subnet mask -- this only makes sense for one subnet
// will remove later
// REST API enable firewall
if (op.equalsIgnoreCase("enable")) {
firewall.enableFirewall(true);
return "{\"status\" : \"success\", \"details\" : \"firewall running\"}";
}
private static final Logger log = LoggerFactory.getLogger(FirewallSubnetMaskResource.class);
// REST API disable firewall
if (op.equalsIgnoreCase("disable")) {
firewall.enableFirewall(false);
return "{\"status\" : \"success\", \"details\" : \"firewall stopped\"}";
}
// REST API retrieving rules from storage
// currently equivalent to /wm/firewall/rules/json
if (op.equalsIgnoreCase("storageRules")) {
return firewall.getStorageRules();
}
// REST API set local subnet mask -- this only makes sense for one subnet
// will remove later
if (op.equalsIgnoreCase("subnet-mask")) {
return "{\"subnet-mask\":\"" + firewall.getSubnetMask() + "\"}";
}
@Get("json")
public Object handleRequest() {
IFirewallService firewall = getFirewallService();
// no known options found
return "{\"status\" : \"failure\", \"details\" : \"invalid operation\"}";
return "{\"subnet-mask\":\"" + firewall.getSubnetMask() + "\"}";
}
/**
* Allows setting of subnet mask
* @param fmJson The Subnet Mask in JSON format.
* @return A string status message
*/
@Post
public String handlePost(String fmJson) {
IFirewallService firewall =
(IFirewallService)getContext().getAttributes().
get(IFirewallService.class.getCanonicalName());
IFirewallService firewall = getFirewallService();
String newMask;
try {
newMask = jsonExtractSubnetMask(fmJson);
} catch (IOException e) {
log.error("Error parsing new subnet mask: " + fmJson, e);
setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return "{\"status\" : \"Error! Could not parse new subnet mask, see log for details.\"}";
}
firewall.setSubnetMask(newMask);
setStatus(Status.SUCCESS_OK);
return ("{\"status\" : \"subnet mask set\"}");
}
......
......@@ -28,8 +28,14 @@ public class FirewallWebRoutable implements RestletRoutable {
@Override
public Router getRestlet(Context context) {
Router router = new Router(context);
router.attach("/module/{op}/json", FirewallResource.class);
router.attach("/rules/json", FirewallRulesResource.class);
router.attach("/module/status/json", FirewallStatusResource.class);
router.attach("/module/enable/json", FirewallEnableResource.class);
router.attach("/module/disable/json", FirewallDisableResource.class);
router.attach("/module/subnet-mask/json", FirewallSubnetMaskResource.class);
router.attach("/module/storageRules/json", FirewallStorageRulesResource.class);
router.attach("/rules/json", FirewallRulesResource.class);
return router;
}
......
......@@ -124,7 +124,7 @@ public class StaticFlowEntryPusherResource extends ServerResource {
if (rows.containsKey(StaticFlowEntryPusher.COLUMN_ICMP6_TYPE)) {
icmp6_type = true;
ip6 = true;
if (((String) rows.get(StaticFlowEntryPusher.COLUMN_ICMP_TYPE)).startsWith("0x")) {
if (((String) rows.get(StaticFlowEntryPusher.COLUMN_ICMP6_TYPE)).startsWith("0x")) {
icmp_type = Integer.parseInt(((String) rows.get(StaticFlowEntryPusher.COLUMN_ICMP6_TYPE)).replaceFirst("0x", ""), 16);
} else {
icmp_type = Integer.parseInt((String) rows.get(StaticFlowEntryPusher.COLUMN_ICMP6_TYPE));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment