/* * @return true if slice exists, otherwise false * @param sliceName name of slice to check for existance */ public static boolean doesSliceExist(String sliceName) { List<String> slices = new ArrayList<String>(); try { slices = FVConfig.getAllSlices(); } catch (ConfigError e) { e.printStackTrace(); } return slices.contains(sliceName); }
@Override public Map<String, String> getSliceInfo(String sliceName) throws PermissionDeniedException, SliceNotFound { /* * relaxed security -- anyone can read slice info for now String user = * APIUserCred.getUserName(); if (!FVConfig.isSupervisor(user) && * !APIAuth.transitivelyCreated(user, sliceName)) throw new * PermissionDeniedException( * "not superuser or transitive slice creator"); */ if (!(doesSliceExist(sliceName))) { throw new SliceNotFound("Slice does not exist: " + sliceName); } HashMap<String, String> map = new HashMap<String, String>(); synchronized (FVConfig.class) { try { map.put("contact_email", FVConfig.getSliceEmail(sliceName)); map.put("controller_hostname", FVConfig.getSliceHost(sliceName)); map.put("controller_port", String.valueOf(FVConfig.getSlicePort(sliceName))); map.put("creator", FVConfig.getSliceCreator(sliceName)); map.put("drop_policy", FVConfig.getSlicePolicy(sliceName)); } catch (ConfigError e) { FVLog.log(LogLevel.CRIT, null, "malformed slice: " + e); e.printStackTrace(); } } long dpid; int connection = 1; // TODO: come back an architect this so we can walk the list of slicers, // not the list of classifiers, and then slicers for (Iterator<FVEventHandler> it = FlowVisor.getInstance().getHandlersCopy().iterator(); it.hasNext(); ) { FVEventHandler eventHandler = it.next(); if (eventHandler instanceof FVClassifier) { FVClassifier classifier = (FVClassifier) eventHandler; if (!classifier.isIdentified()) // only print switches have have // been identified continue; dpid = classifier.getDPID(); FVSlicer fvSlicer = classifier.getSlicerByName(sliceName); if (fvSlicer != null) { map.put( "connection_" + connection++, FlowSpaceUtil.dpidToString(dpid) + "-->" + fvSlicer.getConnectionName()); } } } return map; }
@Override public Collection<String> listSlices() throws PermissionDeniedException { /* * relaxed security; anyone can get a list of slices if * (!FVConfig.isSupervisor(APIUserCred.getUserName())) throw new * PermissionDeniedException( "listSlices only available to root"); */ List<String> slices = null; synchronized (FVConfig.class) { try { // this is synchronized List<String> entries = FVConfig.getAllSlices(); slices = new LinkedList<String>(entries); } catch (ConfigError e) { e.printStackTrace(); throw new RuntimeException("wtf!?: no SLICES subdir found in config"); } } return slices; }
/** * Create a new slice (without flowspace) * * <p>Slices that contain the field separator are rewritten with underscores * * @param sliceName Cannot contain FVConfig.FS == '!' * @param passwd Cleartext! FIXME * @param controller_url Reference controller pseudo-url, e.g., tcp:hostname[:port] * @param slice_email As a contract for the slice * @return success * @throws InvalidSliceName * @throws PermissionDeniedException * @throws DuplicateControllerException */ @Override public Boolean createSlice( String sliceName, String passwd, String controller_url, String drop_policy, String slice_email) throws MalformedControllerURL, InvalidSliceName, InvalidDropPolicy, PermissionDeniedException, DuplicateControllerException { // FIXME: make sure this user has perms to do this OP // for now, all slices can create other slices // FIXME: for now, only handle tcp, not ssl controller url String[] list = controller_url.split(":"); if (!FVConfig.isSupervisor(APIUserCred.getUserName())) throw new PermissionDeniedException("only superusers can create new slices"); if (list.length < 2) throw new MalformedControllerURL( "controller url needs to be of the form " + "proto:hostname[:port], e.g., tcp:yourhost.foo.com:6633, not: " + controller_url); if (!list[0].equals("tcp")) throw new MalformedControllerURL( "Flowvisor currently only supports 'tcp' proto, not: " + list[0]); int controller_port; if (list.length >= 3) controller_port = Integer.valueOf(list[2]); else controller_port = FVConfig.OFP_TCP_PORT; // createSlice is synchronized() if (drop_policy.equals("")) drop_policy = "exact"; else if (!drop_policy.equals("exact") && !drop_policy.equals("rule")) throw new InvalidDropPolicy( "Flowvisor currently supports an 'exact'" + " or a 'rule' based drop policy"); // We need to make sure this slice doesn't already exist List<String> slices = null; synchronized (FVConfig.class) { try { slices = FVConfig.getAllSlices(); } catch (ConfigError e) { e.printStackTrace(); throw new RuntimeException("no SLICES subdir found in config"); } for (Iterator<String> sliceIter = slices.iterator(); sliceIter.hasNext(); ) { String existingSlice = sliceIter.next(); if (sliceName.equals(existingSlice)) { throw new PermissionDeniedException("Cannot create slice with existing name."); } } } FVConfig.createSlice( sliceName, list[1], controller_port, drop_policy, passwd, slice_email, APIUserCred.getUserName()); FlowVisor.getInstance().checkPointConfig(); return true; }