public static List<Flow> getFlows(String dpid) throws IOException,
			JSONException {

		List<Flow> flows = new ArrayList<Flow>();
		
		// If JSONObject is not supplied, get it.
			try {
				obj = (JSONObject) Deserializer.readJsonObjectFromURL("http://" + IP
						+ ":8080/wm/core/switch/" + dpid + "/flow/json").get(5, 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();
			}
		
		if (!obj.isNull(dpid)) {
			json = obj.getJSONArray(dpid);
			for (int i = 0; i < json.length(); i++) {
				obj = (JSONObject) json.get(i);
				Flow flow = new Flow(dpid);
				flow.setActions(ActionJSON.getActions(obj
						.getJSONArray("actions")));
				flow.setMatch(MatchJSON.getMatch(obj.getJSONObject("match")));
				flow.setPriority(String.valueOf(obj.getInt("priority")));
				if (obj.getInt("idleTimeout") != 0)
					flow.setIdleTimeOut(String.valueOf(obj
							.getInt("idleTimeout")));
				if (obj.getInt("hardTimeout") != 0)
					flow.setHardTimeOut(String.valueOf(obj
							.getInt("hardTimeout")));
				flow.setDurationSeconds(String.valueOf(obj
						.getInt("durationSeconds")));
				flow.setPacketCount(String.valueOf(obj.getInt("packetCount")));
				flow.setByteCount(FormatLong.formatBytes(obj.getLong("byteCount"),false,false));
				flows.add(flow);
			}
		}
		return flows;
	}