Package controller.util

Examples of controller.util.JSONObject


       if(!updateSwitch)
         sw = new Switch(dpid);
      
              List<Port> ports = new ArrayList<Port>();
              Map<String, Future<Object>> stats;
            JSONObject descriptionObj = null, aggregateObj = null, portObj = null, featuresObj = null;
                try {
          stats = (Map<String, Future<Object>>) futureStats.get(dpid).get(5L, TimeUnit.SECONDS);
          // Don't bother if we are updating this switch, since description is static
          if(!updateSwitch)
            descriptionObj = (JSONObject)stats.get("description").get(5L, TimeUnit.SECONDS);
          aggregateObj = (JSONObject)stats.get("aggregate").get(5L, TimeUnit.SECONDS);
                  portObj = (JSONObject)stats.get("port").get(5L, TimeUnit.SECONDS);
                  featuresObj = (JSONObject)stats.get("features").get(5L, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (ExecutionException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (TimeoutException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

                // Description stats
                if(!updateSwitch && descriptionObj != null){
                  descriptionObj = descriptionObj.getJSONArray(dpid).getJSONObject(0);
                  sw.setManufacturerDescription(descriptionObj.getString("manufacturerDescription"));
                  sw.setHardwareDescription(descriptionObj.getString("hardwareDescription"));
                  sw.setSoftwareDescription(descriptionObj.getString("softwareDescription"));
                  sw.setSerialNumber(descriptionObj.getString("serialNumber"));
                  sw.setDatapathDescription(descriptionObj.getString("datapathDescription"));
              
               
                // Aggregate stats, ignore
                if(aggregateObj != null){
                    aggregateObj = aggregateObj.getJSONArray(dpid).getJSONObject(0);
                    sw.setPacketCount(String.valueOf(aggregateObj.getInt("packetCount")));
                    sw.setByteCount(String.valueOf(aggregateObj.getInt("byteCount")));
                    sw.setFlowCount(String.valueOf(aggregateObj.getInt("flowCount")));
                }
               
                // Flow Stats
                sw.setFlows(FlowJSON.getFlows(dpid));
               
                // Port and Features stats
                JSONArray json = portObj.getJSONArray(sw.getDpid());
                JSONObject objtwo = featuresObj.getJSONObject(sw.getDpid());
                JSONArray jsontwo = objtwo.getJSONArray("ports");
                for(int i = 0; i < json.length(); i++)
                {
                    obj = (JSONObject)json.get(i);
                    Port port = new Port(String.valueOf(obj.getInt("portNumber")));
                    port.setReceivePackets(FormatLong.formatPackets(obj.getLong("receivePackets"), false, false));
View Full Code Here


  @SuppressWarnings("unchecked")
  public static void updateSwitch(Switch sw) throws JSONException{
   
    String dpid = sw.getDpid();
    List<Port> ports = new ArrayList<Port>();
    JSONObject obj, portObj = null, featuresObj = null;
    Map<String, Future<Object>> stats;
    // Start the rest calls, true is passed since we are updating and don't care about the description
    Future<Object> futureStat  = SwitchJSON.startSwitchRestCalls(dpid, true);
   
    try {
      stats = (Map<String, Future<Object>>) futureStat.get(5L, TimeUnit.SECONDS);
            portObj = (JSONObject)stats.get("port").get(5L, TimeUnit.SECONDS);
            featuresObj = (JSONObject)stats.get("features").get(5L, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ExecutionException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (TimeoutException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

     // Flow Stats
        try {
      sw.setFlows(FlowJSON.getFlows(dpid));
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
       
     // Port and Features stats
        JSONArray json = portObj.getJSONArray(sw.getDpid());
        JSONObject objtwo = featuresObj.getJSONObject(sw.getDpid());
        JSONArray jsontwo = objtwo.getJSONArray("ports");
        for(int i = 0; i < json.length(); i++)
        {
            obj = (JSONObject)json.get(i);
            Port port = new Port(String.valueOf(obj.getInt("portNumber")));
            port.setReceivePackets(FormatLong.formatPackets(obj.getLong("receivePackets"), false, false));
View Full Code Here

        }
        wr.close();
        rd.close();

        // Wrap the response
        JSONObject json = new JSONObject(jsonResponse);
       
        // Make sure the firewall pusher throws no errors
        if (json.getString("status").equals("Rule added") ) {
            for (Rule r : FloodlightProvider.getRules()) {
                System.out.println("r:" + r.serialize());
                System.out.println("rule" + rule.serialize());
                if (rule.equals(r)) {
                    return "Rule successfully pushed!";
                }
            }
            // If not found give user guidance
            return "Rule was not pushed... Check your controller log for more details.";
        } else {
            return json.getString("status");
        }
    }
View Full Code Here

            jsonResponse = jsonResponse.concat(line);
        }
        wr.close();
        rd.close();

        JSONObject json = new JSONObject(jsonResponse);
        // Return result string from key "status"
        return json.getString("status");
    }
View Full Code Here

    }
    wr.close();
    rd.close();

    // Wrap the response
    JSONObject json = new JSONObject(jsonResponse);
   
    // Make sure the static flow pusher throws no errors
    if (json.getString("status").equals("Entry pushed") || json.getString("status").equals(warning)) {
      // Get actual flows, we pass null as first parameter to denote that we are not supplying a JSON object
      List<Flow> actualFlows = FloodlightProvider.getRealFlows(flow.getSwitch(), true);
      // Compare the flow you just pushed with those actually on the switch
      // If found, success message printed.
      for (Flow actualFlow : actualFlows) {
          System.out.println("actual" + actualFlow.serialize());
          System.out.println("flow" + flow.serialize());
        if (flow.equals(actualFlow)) {
          return "Flow successfully pushed down to switches";
        }
      }
      // If not found give user guidance
      return "Flow pushed but not recognized on any switches. It may have been dropped by the switch of modified by the static flow pusher on the controller." +
          " Check your controller log for more details.";
    } else {
      return json.getString("status");
    }
  }
View Full Code Here

      jsonResponse = jsonResponse.concat(line);
    }
    wr.close();
    rd.close();

    JSONObject json = new JSONObject(jsonResponse);
    // Return result string from key "status"
    return json.getString("status");
  }
View Full Code Here

TOP

Related Classes of controller.util.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.