/**
*    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.Set;
import java.util.HashSet;

import net.floodlightcontroller.core.internal.IOFSwitchService;
import net.floodlightcontroller.core.IOFSwitch;

import org.projectfloodlight.openflow.types.DatapathId;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
import net.floodlightcontroller.core.web.serializers.DPIDSerializer;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

/**
 * Get a list of switches connected to the controller
 * @author readams
 */
public class ControllerSwitchesResource extends ServerResource {
    
    public static final String DPID_ERROR = "Invalid switch DPID string. Must be a 64-bit value in the form 00:11:22:33:44:55:66:77.";
    public static class DatapathIDJsonSerializerWrapper {
        private final DatapathId dpid;
        private final String inetAddress; 
        private final long connectedSince;
        public DatapathIDJsonSerializerWrapper(DatapathId dpid, String inetAddress, long connectedSince) {
            this.dpid = dpid;
            this.inetAddress = inetAddress;
            this.connectedSince = connectedSince;
        }
        
        @JsonSerialize(using=DPIDSerializer.class)
        public DatapathId getSwitchDPID() {
            return dpid;
        }
        public String getInetAddress() {
            return inetAddress;
        }
        public long getConnectedSince() {
            return connectedSince;
        }



    }

    @Get("json")
    public Set<DatapathIDJsonSerializerWrapper> retrieve(){
        IOFSwitchService switchService = 
            (IOFSwitchService) getContext().getAttributes().
                get(IOFSwitchService.class.getCanonicalName());
        Set<DatapathIDJsonSerializerWrapper> dpidSets = new HashSet<DatapathIDJsonSerializerWrapper>();
        for(IOFSwitch sw: switchService.getAllSwitchMap().values()) {
            dpidSets.add(new DatapathIDJsonSerializerWrapper(sw.getId(), sw.getInetAddress().toString(),  sw.getConnectedSince().getTime()));

        }
        return dpidSets;
    }
}

@@ -892,16 +892,74 @@
 witch;%0A%0A
+import org.projectfloodlight.openflow.protocol.OFVersion;%0A
 import o
@@ -1678,32 +1678,70 @@
 connectedSince;%0A
+        private final String version;%0A
         public D
@@ -1827,16 +1827,35 @@
 tedSince
+, OFVersion version
 ) %7B%0A    
@@ -1966,32 +1966,79 @@
 connectedSince;%0A
+            this.version = version.toString();%0A
         %7D%0A      
@@ -2162,32 +2162,41 @@
 dpid;%0A        %7D%0A
+        %0A
         public S
@@ -2254,32 +2254,41 @@
 ress;%0A        %7D%0A
+        %0A
         public l
@@ -2358,18 +2358,107 @@
       %7D%0A
-%0A%0A
+        %0A        public String getOpenFlowVersion() %7B%0A            return version;%0A        %7D
 %0A    %7D%0A%0A
@@ -2532,16 +2532,17 @@
 trieve()
+ 
 %7B%0A      
@@ -2817,16 +2817,17 @@
      for
+ 
 (IOFSwit
@@ -2950,16 +2950,37 @@
 etId(), 
+%0A                    
 sw.getIn
@@ -3003,16 +3003,36 @@
 ring(), 
+%0A                   
  sw.getC
@@ -3056,16 +3056,68 @@
 etTime()
+,%0A                    sw.getOFFactory().getVersion()
 ));%0A%0A   
@@ -3155,9 +3155,8 @@
 %0A    %7D%0A%7D
-%0A

Include OpenFlow version in /wm/core/controller/switches/json REST API output