Exemplo n.º 1
0
 @Override
 public boolean setMaximumFlowMods(String sliceName, String dpid, String maxFlowMods)
     throws PermissionDeniedException {
   String user = APIUserCred.getUserName();
   if (!APIAuth.transitivelyCreated(user, sliceName) && !FVConfig.isSupervisor(user))
     throw new PermissionDeniedException(
         "User " + user + " does not have perms to set the flow mod limit for slice " + sliceName);
   Long dp = FlowSpaceUtil.parseDPID(dpid);
   int limit = Integer.parseInt(maxFlowMods);
   FVLog.log(
       LogLevel.DEBUG,
       null,
       "Setting flowmod limit for slice "
           + sliceName
           + " for dpid "
           + dpid
           + " to "
           + maxFlowMods);
   try {
     if (dp == FlowEntry.ALL_DPIDS) SliceImpl.getProxy().setMaxFlowMods(sliceName, limit);
     else SwitchImpl.getProxy().setMaxFlowMods(sliceName, dp, limit);
   } catch (ConfigError e) {
     return false;
   }
   return true;
 }
Exemplo n.º 2
0
 public Integer getCurrentFlowMods(String sliceName, String dpid)
     throws PermissionDeniedException, SliceNotFound, DPIDNotFound {
   String user = APIUserCred.getUserName();
   if (!APIAuth.transitivelyCreated(user, sliceName) && !FVConfig.isSupervisor(user))
     throw new PermissionDeniedException(
         "User "
             + user
             + " does not have perms to get the current flow mod value for slice "
             + sliceName);
   Long dp = FlowSpaceUtil.parseDPID(dpid);
   if (dp == FlowEntry.ALL_DPIDS) return getSliceLimits().getSliceFMLimit(sliceName);
   else return lookupClassifier(dp).getCurrentFlowModCounter(sliceName);
 }
Exemplo n.º 3
0
 @Override
 public String getSwitchStats(String dpidStr) throws DPIDNotFound, PermissionDeniedException {
   long dpid = FlowSpaceUtil.parseDPID(dpidStr);
   for (Iterator<FVEventHandler> it = FlowVisor.getInstance().getHandlersCopy().iterator();
       it.hasNext(); ) {
     FVEventHandler eventHandler = it.next();
     if (eventHandler instanceof FVClassifier) {
       FVClassifier classifier = (FVClassifier) eventHandler;
       if (classifier.getDPID() == dpid) return classifier.getStats().combinedString();
     }
   }
   throw new DPIDNotFound("dpid not found: " + dpidStr);
 }
Exemplo n.º 4
0
 @Override
 public Integer getMaximumFlowMods(String sliceName, String dpid)
     throws PermissionDeniedException {
   String user = APIUserCred.getUserName();
   if (!APIAuth.transitivelyCreated(user, sliceName) && !FVConfig.isSupervisor(user))
     throw new PermissionDeniedException(
         "User " + user + " does not have perms to get the flow mod limit for slice " + sliceName);
   Long dp = FlowSpaceUtil.parseDPID(dpid);
   try {
     if (dp == FlowEntry.ALL_DPIDS) return SliceImpl.getProxy().getMaxFlowMods(sliceName);
     else return SwitchImpl.getProxy().getMaxFlowMods(sliceName, dp);
   } catch (ConfigError e) {
     FVLog.log(LogLevel.DEBUG, null, "Unable to get flow mod limit; " + e.getMessage());
     return null;
   }
 }
Exemplo n.º 5
0
  @Override
  public String getFloodPerm(String dpidStr) throws PermissionDeniedException {
    String user = APIUserCred.getUserName();
    if (!FVConfig.isSupervisor(user))
      throw new PermissionDeniedException(
          "User " + user + " does not have perms to obtain the flood perms of " + dpidStr);
    FVLog.log(LogLevel.DEBUG, null, "Setting flood perm for : ", dpidStr);
    long dpid = FlowSpaceUtil.parseDPID(dpidStr);
    try {
      return SwitchImpl.getProxy().getFloodPerm(dpid);

    } catch (ConfigError e) {
      FVLog.log(LogLevel.ALERT, null, "Unable to set floodperm", e.getMessage());
    }
    return null;
  }
Exemplo n.º 6
0
 @Override
 public Map<String, List<Map<String, String>>> getSliceRewriteDB(String sliceName, String dpidStr)
     throws DPIDNotFound, SliceNotFound, PermissionDeniedException {
   long dpid = FlowSpaceUtil.parseDPID(dpidStr);
   FVSlicer fvSlicer = lookupSlicer(sliceName, dpid);
   Map<String, List<Map<String, String>>> ret = new HashMap<String, List<Map<String, String>>>();
   FlowRewriteDB flowRewriteDB = fvSlicer.getFlowRewriteDB();
   synchronized (flowRewriteDB) {
     for (FlowDBEntry original : flowRewriteDB.originals()) {
       Map<String, String> originalMap = original.toBracketMap();
       List<Map<String, String>> rewrites = new LinkedList<Map<String, String>>();
       for (FlowDBEntry rewrite : flowRewriteDB.getRewrites(original)) {
         rewrites.add(rewrite.toBracketMap());
       }
       ret.put(BracketParse.encode(originalMap), rewrites);
     }
   }
   return ret;
 }
Exemplo n.º 7
0
  public static void main(String args[]) throws FileNotFoundException, ConfigError {
    if (args.length < 3) {
      System.err.println("Usage: <config.xml> <dpid> <ofmatch>");
      System.exit(1);
    }

    FVConfig.readFromFile(args[0]);
    long dpid = FlowSpaceUtil.parseDPID(args[1]);
    FVMatch packet = new FVMatch();
    packet.fromString(args[2]);

    System.err.println(
        "Looking up packet '" + packet + "' on dpid=" + FlowSpaceUtil.dpidToString(dpid));
    List<FlowEntry> entries = FVConfig.getFlowSpaceFlowMap().matches(dpid, packet);

    System.err.println("Matches found: " + entries.size());
    if (entries.size() > 1) System.err.println("WARN: only sending to the first match");
    for (FlowEntry flowEntry : entries) {
      System.out.println(flowEntry);
    }
  }
Exemplo n.º 8
0
 @Override
 public Collection<Map<String, String>> getSwitchFlowDB(String dpidStr) throws DPIDNotFound {
   boolean found = false;
   long dpid = FlowSpaceUtil.parseDPID(dpidStr);
   List<Map<String, String>> ret = new LinkedList<Map<String, String>>();
   for (Iterator<FVEventHandler> it = FlowVisor.getInstance().getHandlersCopy().iterator();
       it.hasNext(); ) {
     FVEventHandler eventHandler = it.next();
     if (eventHandler instanceof FVClassifier) {
       FVClassifier classifier = (FVClassifier) eventHandler;
       if (dpid == classifier.getDPID() || dpid == FlowEntry.ALL_DPIDS) {
         synchronized (classifier) {
           for (Iterator<FlowDBEntry> it2 = classifier.getFlowDB().iterator(); it2.hasNext(); ) {
             ret.add(it2.next().toBracketMap());
           }
         }
         found = true;
       }
     }
   }
   if (!found) throw new DPIDNotFound("dpid not found: " + dpidStr);
   return ret;
 }
Exemplo n.º 9
0
  @SuppressWarnings("unchecked")
  private void insert(HashMap<String, Object> row) throws IOException {
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet set = null;
    int sliceid = -1;
    int ruleid = -1;
    try {
      conn = settings.getConnection();
      ps = conn.prepareStatement(SFLOWMAP, Statement.RETURN_GENERATED_KEYS);
      if (row.get(DPID) == null) ps.setNull(1, Types.BIGINT);
      else ps.setLong(1, FlowSpaceUtil.parseDPID(((String) row.get(DPID))));
      if (row.get(PRIO) == null) ps.setNull(2, Types.INTEGER);
      else ps.setInt(2, ((Double) row.get(PRIO)).intValue());
      if (row.get(INPORT) == null) ps.setNull(3, Types.SMALLINT);
      else ps.setShort(3, ((Double) row.get(INPORT)).shortValue());
      if (row.get(VLAN) == null) ps.setNull(4, Types.SMALLINT);
      else ps.setShort(4, ((Double) row.get(VLAN)).shortValue());
      if (row.get(VPCP) == null) ps.setNull(5, Types.SMALLINT);
      else ps.setShort(5, ((Double) row.get(VPCP)).shortValue());
      if (row.get(DLSRC) == null) ps.setNull(6, Types.BIGINT);
      else ps.setLong(6, FlowSpaceUtil.parseMac(((String) row.get(DLSRC))));
      if (row.get(DLDST) == null) ps.setNull(7, Types.BIGINT);
      else ps.setLong(7, FlowSpaceUtil.parseMac(((String) row.get(DLDST))));
      if (row.get(DLTYPE) == null) ps.setNull(8, Types.SMALLINT);
      else ps.setShort(8, ((Double) row.get(DLTYPE)).shortValue());
      if (row.get(NWSRC) == null) ps.setNull(9, Types.INTEGER);
      else ps.setInt(9, ((Double) row.get(NWSRC)).intValue());
      if (row.get(NWDST) == null) ps.setNull(10, Types.INTEGER);
      else ps.setInt(10, ((Long) row.get(NWDST)).intValue());
      if (row.get(NWPROTO) == null) ps.setNull(11, Types.SMALLINT);
      else ps.setShort(11, ((Double) row.get(NWPROTO)).shortValue());
      if (row.get(NWTOS) == null) ps.setNull(12, Types.SMALLINT);
      else ps.setShort(12, ((Double) row.get(NWTOS)).shortValue());
      if (row.get(TPSRC) == null) ps.setNull(13, Types.SMALLINT);
      else ps.setShort(13, ((Double) row.get(TPSRC)).shortValue());
      if (row.get(TPDST) == null) ps.setNull(14, Types.SMALLINT);
      else ps.setShort(14, ((Double) row.get(TPDST)).shortValue());
      if (row.get(FORCED_QUEUE) == null) ps.setInt(15, -1);
      else ps.setInt(15, ((Double) row.get(FORCED_QUEUE)).intValue());
      if (row.get(WILDCARDS) == null) ps.setNull(16, Types.INTEGER);
      else ps.setInt(16, ((Double) row.get(WILDCARDS)).intValue());

      if (ps.executeUpdate() == 0)
        FVLog.log(LogLevel.WARN, null, "Flow rule insertion failed... siliently.");
      set = ps.getGeneratedKeys();
      set.next();
      ruleid = set.getInt(1);

      for (HashMap<String, Double> item : ((ArrayList<HashMap<String, Double>>) row.get(ACTION))) {
        for (Entry<String, Double> entry : item.entrySet()) {
          ps = conn.prepareStatement(SLICEID);
          ps.setString(1, entry.getKey());
          set = ps.executeQuery();
          if (set.next()) sliceid = set.getInt("id");
          else {
            sliceid = -1;
            System.err.println(
                "Inserting rule with action on unknown slice "
                    + entry.getKey()
                    + "; hope you know what you are doing...");
          }
          ps = conn.prepareStatement(SACTIONS);
          ps.setInt(1, ruleid);
          ps.setInt(2, sliceid);
          ps.setInt(3, ((Double) entry.getValue()).intValue());

          if (ps.executeUpdate() == 0)
            FVLog.log(LogLevel.WARN, null, "Action insertion failed... siliently.");
        }
      }
      if (row.get(QUEUE) == null) return;
      ps = conn.prepareStatement(SQUEUES);
      ps.setInt(1, ruleid);
      for (Double queue_id : (ArrayList<Double>) row.get(QUEUE)) {
        ps.setInt(2, queue_id.intValue());
        if (ps.executeUpdate() == 0)
          FVLog.log(LogLevel.WARN, null, "Queue insertion failed... siliently.");
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      close(set);
      close(ps);
      close(conn);
    }
  }