Пример #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
/**
 * 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;
}
Пример #3
0
  static SFLSampler *getSampler(HSP *sp, SFLAdaptor *adaptor)
  {
    HSPAdaptorNIO *adaptorNIO=(HSPAdaptorNIO *)adaptor->userData;
    if(adaptorNIO) {
      if(adaptorNIO->sampler == NULL) {
	SFLDataSource_instance dsi;
	SFL_DS_SET(dsi, 0, adaptor->ifIndex, 0); // ds_class,ds_index,ds_instance
	HSPSFlow *sf = sp->sFlow;
	// add sampler (with sub-sampling rate)
	uint32_t samplingRate = sf->sFlowSettings->ulogSubSamplingRate;
	adaptorNIO->sampler = sfl_agent_addSampler(sf->agent, &dsi);
	sfl_sampler_set_sFlowFsPacketSamplingRate(adaptorNIO->sampler, samplingRate);
	sfl_sampler_set_sFlowFsReceiver(adaptorNIO->sampler, HSP_SFLOW_RECEIVER_INDEX);
	// and make sure we have a poller too
	getPoller(sp, adaptor);
      }
      return adaptorNIO->sampler;
    }
    return NULL;
  }
Пример #4
0
void sfl_sampler_init(SFLSampler *sampler, SFLAgent *agent, SFLDataSource_instance *pdsi)
{
  /* copy the dsi in case it points to sampler->dsi, which we are about to clear.
     (Thanks to Jagjit Choudray of Force 10 Networks for pointing out this bug) */
  SFLDataSource_instance dsi = *pdsi;

  /* preserve the *nxt pointer too, in case we are resetting this poller and it is
     already part of the agent's linked list (thanks to Matt Woodly for pointing this out) */
  SFLSampler *nxtPtr = sampler->nxt;
  
  /* clear everything */
  memset(sampler, 0, sizeof(*sampler));
  
  /* restore the linked list ptr */
  sampler->nxt = nxtPtr;
  
  /* now copy in the parameters */
  sampler->agent = agent;
  sampler->dsi = dsi;
  
  /* set defaults */
  sfl_sampler_set_sFlowFsMaximumHeaderSize(sampler, SFL_DEFAULT_HEADER_SIZE);
  sfl_sampler_set_sFlowFsPacketSamplingRate(sampler, SFL_DEFAULT_SAMPLING_RATE);
}