@Override
  public JSONRPC2Response process(final Map<String, Object> params) {
    try {

      final Number tid =
          HandlerUtils.<Number>fetchField(MonitoringHandler.TENANT, params, true, null);
      final Number dpid =
          HandlerUtils.<Number>fetchField(MonitoringHandler.VDPID, params, false, -1);
      final OVXMap map = OVXMap.getInstance();
      final LinkedList<Map<String, Object>> flows = new LinkedList<Map<String, Object>>();
      if (dpid.longValue() == -1) {
        HashMap<String, Object> res = new HashMap<String, Object>();
        for (OVXSwitch vsw : map.getVirtualNetwork(tid.intValue()).getSwitches()) {
          flows.clear();
          final Collection<OVXFlowMod> fms = vsw.getFlowTable().getFlowTable();
          for (final OVXFlowMod flow : fms) {
            final Map<String, Object> entry = flow.toMap();
            flows.add(entry);
          }
          res.put(vsw.getSwitchName(), flows.clone());
        }
        this.resp = new JSONRPC2Response(res, 0);
      } else {

        final OVXSwitch vsw = map.getVirtualNetwork(tid.intValue()).getSwitch(dpid.longValue());
        final Collection<OVXFlowMod> fms = vsw.getFlowTable().getFlowTable();
        for (final OVXFlowMod flow : fms) {
          final Map<String, Object> entry = flow.toMap();
          flows.add(entry);
        }
        this.resp = new JSONRPC2Response(flows, 0);
      }

    } catch (ClassCastException | MissingRequiredField e) {
      this.resp =
          new JSONRPC2Response(
              new JSONRPC2Error(
                  JSONRPC2Error.INVALID_PARAMS.getCode(),
                  this.cmdName() + ": Unable to fetch virtual topology : " + e.getMessage()),
              0);
    } catch (final InvalidDPIDException e) {
      this.resp =
          new JSONRPC2Response(
              new JSONRPC2Error(
                  JSONRPC2Error.INVALID_PARAMS.getCode(),
                  this.cmdName() + ": Unable to fetch virtual topology : " + e.getMessage()),
              0);
    } catch (NetworkMappingException e) {
      this.resp =
          new JSONRPC2Response(
              new JSONRPC2Error(
                  JSONRPC2Error.INVALID_PARAMS.getCode(),
                  this.cmdName() + ": Unable to fetch virtual topology : " + e.getMessage()),
              0);
    }

    return this.resp;
  }
Exemple #2
0
 @Override
 public void removeVirtualSwitch(OVXSwitch virtualSwitch) {
   if (this.virtualSwitchMap.containsKey(virtualSwitch)) {
     ArrayList<PhysicalSwitch> physicalSwitches = this.virtualSwitchMap.get(virtualSwitch);
     for (PhysicalSwitch physicalSwitch : physicalSwitches) {
       if (this.physicalSwitchMap.get(physicalSwitch).containsKey(virtualSwitch.getTenantId())) {
         this.physicalSwitchMap.get(physicalSwitch).remove(virtualSwitch.getTenantId());
       }
     }
     this.virtualSwitchMap.remove(virtualSwitch);
   }
 }
Exemple #3
0
 /**
  * Sets up the mapping from the physicalSwitch to the tenant ID and virtualSwitch which has been
  * specified.
  *
  * @param physicalSwitch A PhysicalSwitch object which is found in the PhysicalNetwork
  * @param virtualSwitch An OVXSwitch object which is found in the OVXNetwork
  */
 private void addPhysicalSwitch(
     final PhysicalSwitch physicalSwitch, final OVXSwitch virtualSwitch) {
   ConcurrentHashMap<Integer, OVXSwitch> switchMap = this.physicalSwitchMap.get(physicalSwitch);
   if (switchMap == null) {
     switchMap = new ConcurrentHashMap<Integer, OVXSwitch>();
     this.physicalSwitchMap.put(physicalSwitch, switchMap);
   }
   switchMap.put(virtualSwitch.getTenantId(), virtualSwitch);
 }