Пример #1
0
  static SFLSampler *getSampler(HSP *sp, char *devName, uint32_t ifIndex)
  {
    SFLSampler *sampler = sfl_agent_getSamplerByIfIndex(sp->sFlow->agent, ifIndex);
    if(sampler == NULL) {
      SFLDataSource_instance dsi;
      SFL_DS_SET(dsi, 0, ifIndex, 0); // ds_class,ds_index,ds_instance
      HSPSFlow *sf = sp->sFlow;
      // add sampler (with sub-sampling rate), and poller too
      uint32_t samplingRate = sf->sFlowSettings->ulogSubSamplingRate;
      sampler = sfl_agent_addSampler(sf->agent, &dsi);
      sfl_sampler_set_sFlowFsPacketSamplingRate(sampler, samplingRate);
      sfl_sampler_set_sFlowFsReceiver(sampler, HSP_SFLOW_RECEIVER_INDEX);
      if(devName) {
	uint32_t pollingInterval = sf->sFlowSettings ?
	  sf->sFlowSettings->pollingInterval :
	  SFL_DEFAULT_POLLING_INTERVAL;
	SFLPoller *poller = sfl_agent_addPoller(sf->agent, &dsi, sp, agentCB_getCounters_interface);
	sfl_poller_set_sFlowCpInterval(poller, pollingInterval);
	sfl_poller_set_sFlowCpReceiver(poller, HSP_SFLOW_RECEIVER_INDEX);
	// remember the device name to make the lookups easier later.
	// Don't want to point directly to the SFLAdaptor or SFLAdaptorNIO object
	// in case it gets freed at some point.  The device name is enough.
	poller->userData = (void *)my_strdup(devName);
      }
    }
    return sampler;
  }
Пример #2
0
SFLSampler *sfl_agent_addSampler(SFLAgent *agent, SFLDataSource_instance *pdsi)
{
    /* Keep the list sorted. */
    SFLSampler *prev = NULL, *sm = agent->samplers;
    for(; sm != NULL; prev = sm, sm = sm->nxt) {
	int64_t cmp = sfl_dsi_compare(pdsi, &sm->dsi);
	if(cmp == 0) return sm;  /* found - return existing one */
	if(cmp < 0) break;       /* insert here */
    }
    /* either we found the insert point, or reached the end of the list...*/

    {
	SFLSampler *newsm = (SFLSampler *)sflAlloc(agent, sizeof(SFLSampler));
	sfl_sampler_init(newsm, agent, pdsi);
	if(prev) prev->nxt = newsm;
	else agent->samplers = newsm;
	newsm->nxt = sm;

	/* see if we should go in the ifIndex jumpTable */
	if(SFL_DS_CLASS(newsm->dsi) == 0) {
	    SFLSampler *test = sfl_agent_getSamplerByIfIndex(agent, SFL_DS_INDEX(newsm->dsi));
	    if(test && (SFL_DS_INSTANCE(newsm->dsi) < SFL_DS_INSTANCE(test->dsi))) {
		/* replace with this new one because it has a lower ds_instance number */
		sfl_agent_jumpTableRemove(agent, test);
		test = NULL;
	    }
	    if(test == NULL) sfl_agent_jumpTableAdd(agent, newsm);
	}
	return newsm;
    }
}
Пример #3
0
/**
 * Searches for existing sampler with ifIndex and returns it. If there is no
 * existing sampler with the ifIndex, creates a new one (and a poller) and
 * returns it.
 */
static SFLSampler *getSampler(HSP *sp, char *devName, uint32_t ifIndex)
{
	SFLSampler *sampler = sfl_agent_getSamplerByIfIndex(sp->sFlow->agent, ifIndex);
	if (sampler == NULL) {
		SFLDataSource_instance dsi;
		SFL_DS_SET(dsi, 0, ifIndex, 0); // ds_class=0 interface
		HSPSFlow *sf = sp->sFlow;
		uint32_t samplingRate = sp->sFlow->sFlowSettings->samplingRate;
		sampler = sfl_agent_addSampler(sf->agent, &dsi);
		sampler->userData = (void *)my_strdup(devName);
		sfl_sampler_set_sFlowFsPacketSamplingRate(sampler, samplingRate);
		sfl_sampler_set_sFlowFsReceiver(sampler, HSP_SFLOW_RECEIVER_INDEX);
	}
	return sampler;
}