/**
*    Copyright 2011, Big Switch Networks, Inc. 
*    Originally created by David Erickson, Stanford University
* 
*    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.core.web;

import java.util.Collection;

import net.floodlightcontroller.core.IFloodlightProviderService;
import net.floodlightcontroller.core.IOFSwitch;

import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;

/**
 * Get a list of switches connected to the controller
 * @author readams
 */
public class ControllerSwitchesResource extends ServerResource {
    @Get("json")
    public Collection<IOFSwitch> retrieve() {
        IFloodlightProviderService floodlightProvider = 
                (IFloodlightProviderService)getContext().getAttributes().
                    get(IFloodlightProviderService.class.getCanonicalName());
        return floodlightProvider.getSwitches().values();
    }
}

@@ -759,16 +759,44 @@
 llection
+s;%0Aimport java.util.Iterator
 ;%0A%0Aimpor
@@ -903,16 +903,167 @@
 Switch;%0A
+import net.floodlightcontroller.util.FilterIterator;%0A%0Aimport org.openflow.util.HexString;%0Aimport org.restlet.data.Form;%0Aimport org.restlet.data.Status;
 %0Aimport 
@@ -1279,16 +1279,191 @@
 ource %7B%0A
+    public static final String DPID_ERROR = %0A            %22Invalid Switch DPID: must be a 64-bit quantity, expressed in %22 + %0A            %22hex as AA:BB:CC:DD:EE:FF:00:11%22;%0A    %0A
     @Get
@@ -1482,26 +1482,24 @@
  public 
-Collection
+Iterator
 %3CIOFSwit
@@ -1724,24 +1724,25 @@
 ame());%0A
+%0A
         
 return f
@@ -1737,56 +1737,1218 @@
     
-return floodlightProvider.getSwitches().values()
+Long switchDPID = null;%0A        %0A        Form form = getQuery();%0A        String dpid = form.getFirstValue(%22dpid%22, true);%0A        if (dpid != null) %7B%0A            try %7B%0A                switchDPID = HexString.toLong(dpid);%0A            %7D catch (Exception e) %7B%0A                setStatus(Status.CLIENT_ERROR_BAD_REQUEST, DPID_ERROR);%0A                return null;%0A            %7D%0A        %7D%0A        if (switchDPID != null) %7B%0A            IOFSwitch sw = %0A                    floodlightProvider.getSwitches().get(switchDPID);%0A            if (sw != null)%0A                return Collections.singleton(sw).iterator();%0A            return Collections.%3CIOFSwitch%3EemptySet().iterator();%0A        %7D%0A        final String dpidStartsWith = %0A                form.getFirstValue(%22dpid__startswith%22, true);%0A        Iterator%3CIOFSwitch%3E switer = %0A                floodlightProvider.getSwitches().values().iterator();%0A        if (dpidStartsWith != null) %7B%0A            return new FilterIterator%3CIOFSwitch%3E(switer) %7B%0A                @Override%0A                protected boolean matches(IOFSwitch value) %7B%0A                    return value.getStringId().startsWith(dpidStartsWith);%0A                %7D%0A            %7D;%0A        %7D %0A        return switer
 ;%0A  

Add support for dpid and dpid__startswith parameters to switch REST API