예제 #1
0
void FlowContext::SetOpts(OptArgs &opts, Json::Value& json_params)
{
	string fo = RetrieveParameterString(opts, json_params, '-', "flow-order", "");
	if(fo.length() > 0)
	{
		if ( flowOrder )
			free ( flowOrder );
		
		flowOrder = strdup ( fo.c_str() );
		numFlowsPerCycle = strlen ( flowOrder );
		flowOrderOverride = true;
	}

	int tmp_flowlimit = RetrieveParameterInt(opts, json_params, '-', "flowlimit", -1);
	if(tmp_flowlimit >= 0)
	{
		SetFlowLimit( tmp_flowlimit );
	}

	vector<int> vec;
	RetrieveParameterVectorInt(opts, json_params, '-', "start-flow-plus-interval", "0,0", vec);
	if(vec.size() == 2)
	{
		if( vec[1] > 0)
		{
			SetFlowRange(vec[0], vec[1]);
		}
	}
	else
	{
        fprintf ( stderr, "Option Error: start-flow-plus-interval format wrong, not size = 2\n" );
        exit ( EXIT_FAILURE );
	}
}
예제 #2
0
bool FlowControllerImpl::SetFlowLimit(int ns, FlowType type, int lower, int upper)
{
  if (lower < -1 || upper < -1) 
  {
    log_error("invliad flow limit parameter, lower %d; upper %d", lower, upper);
    return false;
  }
  if (ns == -1)
  {
    bool success = true;
    for (size_t i = 0; i < MAXAREA; ++i)
      if (SetFlowLimit(i, type, lower, upper) == false)
        success = false;
    return success;
  } 
  else
  {
    FlowLimit limit = GetFlowLimit(ns, type);
    if (upper != -1)
      limit.upper = upper;
    if (lower != -1)
      limit.lower = lower;

    if (limit.lower > limit.upper)
    {
      log_error("%d > %d is invalid", limit.lower, limit.upper);
      return false;
    }

    ASSERTNS(ns);
    log_info("set(or get) flow limit bound, ns %d; type %s; lower %d; upper %d", 
        ns, FlowTypeStr(type), lower, upper);
    switch (type) 
    {
     case IN:
      if (lower >= 0)
        atomic_set(&flows_[ns].in.lower_bound, lower);
      if (upper >= 0)
        atomic_set(&flows_[ns].in.upper_bound, upper);
      break;
     case OUT:
      if (lower >= 0)
        atomic_set(&flows_[ns].out.lower_bound, lower);
      if (upper >= 0)
        atomic_set(&flows_[ns].out.upper_bound, upper);
      break;
     case OPS:
      if (lower >= 0)
        atomic_set(&flows_[ns].ops.lower_bound, lower);
      if (upper >= 0)
        atomic_set(&flows_[ns].ops.upper_bound, upper);
      break;
     default:
      log_error("unknow type %d", type);
      break;
    }
  }
  return true;
}
예제 #3
0
FlowControllerImpl::FlowControllerImpl(int ns)
    : stop_(false),
      cal_interval_second_(2),
      mutex_(new flstorage::Mutex())
{
  bzero(flows_, sizeof(flows_));
  SetFlowLimit(-1, IN, DEFAULT_NET_LOWER, DEFAULT_NET_UPPER);
  SetFlowLimit(-1, OUT, DEFAULT_NET_LOWER, DEFAULT_NET_UPPER);
  SetFlowLimit(-1, OPS, DEFAULT_OPS_LOWER, DEFAULT_OPS_UPPER);
  SetFlowLimit(MAXAREA, IN, DEFAULT_TOTAL_NET_LOWER, DEFAULT_TOTAL_NET_UPPER);
  SetFlowLimit(MAXAREA, OUT, DEFAULT_TOTAL_NET_LOWER, DEFAULT_TOTAL_NET_UPPER);
  SetFlowLimit(MAXAREA, OPS, DEFAULT_TOTAL_OPS_LOWER, DEFAULT_TOTAL_OPS_UPPER);
}
예제 #4
0
void FlowContext::SetOpts(OptArgs &opts, Json::Value& json_params)
{
	string fo = RetrieveParameterString(opts, json_params, '-', "flow-order", "");
	if(fo.length() > 0)
	{
		if ( flowOrder )
			free ( flowOrder );
    // upgrade floworder to all-caps(!)
    // otherwise problems as the code does direct char compares
    for (unsigned int i=0; i<fo.size(); i++){
      fo.at(i) = toupper(fo.at(i));
    }
		
		flowOrder = strdup ( fo.c_str() );
		numFlowsPerCycle = strlen ( flowOrder );
		flowOrderOverride = true;
	}

	int tmp_flowlimit = RetrieveParameterInt(opts, json_params, '-', "flowlimit", -1);
	if(tmp_flowlimit >= 0)
	{
		SetFlowLimit( tmp_flowlimit );
	}

	vector<int> vec;
	RetrieveParameterVectorInt(opts, json_params, '-', "start-flow-plus-interval", "0,0", vec);
	if(vec.size() == 2)
	{
		if( vec[1] > 0)
		{
			SetFlowRange(vec[0], vec[1]);
		}
	}
	else
	{
        fprintf ( stderr, "Option Error: start-flow-plus-interval format wrong, not size = 2\n" );
        exit ( EXIT_FAILURE );
	}
}