Ejemplo n.º 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;
  }
Ejemplo n.º 2
0
void sfl_agent_resetReceiver(SFLAgent *agent, SFLReceiver *receiver)
{
  SFLReceiver *rcv;
  SFLSampler *sm;
  SFLPoller *pl;

  /* tell samplers and pollers to stop sending to this receiver */
  /* first get his receiverIndex */
  u_int32_t rcvIdx = 0;
  for(rcv = agent->receivers; rcv != NULL; rcv = rcv->nxt)
    if(rcv == receiver) break;
  /* now tell anyone that is using it to stop */
  for(sm = agent->samplers; sm != NULL; sm = sm->nxt)
    if(sfl_sampler_get_sFlowFsReceiver(sm) == rcvIdx) sfl_sampler_set_sFlowFsReceiver(sm, 0);

  for(pl = agent->pollers; pl != NULL; pl = pl->nxt)
    if(sfl_poller_get_sFlowCpReceiver(pl) == rcvIdx) sfl_poller_set_sFlowCpReceiver(pl, 0);
}
Ejemplo n.º 3
0
/**
 * If the polling interval is > 0, adds an interface counter poller to 
 * sp->sFlow->agent or the adaptor representing the switch port. Returns
 * the added poller, or NULL if a poller was not added.
 */
static SFLPoller *addPoller(HSP *sp, SFLAdaptor *adaptor)
{
	uint32_t pollingInterval = sp->sFlow->sFlowSettings ? 
		sp->sFlow->sFlowSettings->pollingInterval : SFL_DEFAULT_POLLING_INTERVAL;
	if (pollingInterval <= 0) {
		return NULL;
	}
	SFLDataSource_instance switchDsi;
	SFL_DS_SET(switchDsi, SFL_DSCLASS_IFINDEX, adaptor->ifIndex, 0); 
	SFLPoller *poller = sfl_agent_addPoller(sp->sFlow->agent, 
											&switchDsi, 
											sp, 
											agentCB_getCounters);
	// remember the deviceName to make the lookups easier later.
	// We don't point directly to the SFLAdaptor object
	// in case it gets freed at some point. The deviceName is enough.
	poller->userData = my_strdup(adaptor->deviceName);
	myLog(LOG_INFO, "addPoller: added counter poller for %lu %s", 
		  adaptor->ifIndex, adaptor->deviceName);
	sfl_poller_set_sFlowCpInterval(poller, pollingInterval);
	sfl_poller_set_sFlowCpReceiver(poller, HSP_SFLOW_RECEIVER_INDEX);
	return poller;
}
Ejemplo n.º 4
0
void sfl_agent_resetReceiver(SFLAgent *agent, SFLReceiver *receiver)
{
    /* tell samplers and pollers to stop sending to this receiver */
    /* first get his receiverIndex */
    u_int32_t rcvIdx = 0;
    SFLReceiver *rcv = agent->receivers;
    for(; rcv != NULL; rcv = rcv->nxt) {
	rcvIdx++; /* thanks to Diego Valverde for pointing out this bugfix */
	if(rcv == receiver) {
	    /* now tell anyone that is using it to stop */
	    SFLSampler *sm = agent->samplers;
	    SFLPoller *pl = agent->pollers;

	    for(; sm != NULL; sm = sm->nxt)
		if(sfl_sampler_get_sFlowFsReceiver(sm) == rcvIdx) sfl_sampler_set_sFlowFsReceiver(sm, 0);

	    for(; pl != NULL; pl = pl->nxt)
		if(sfl_poller_get_sFlowCpReceiver(pl) == rcvIdx) sfl_poller_set_sFlowCpReceiver(pl, 0);

	    break;
	}
    }
}
Ejemplo n.º 5
0
  static SFLPoller *getPoller(HSP *sp, SFLAdaptor *adaptor)
  {
    HSPAdaptorNIO *adaptorNIO=(HSPAdaptorNIO *)adaptor->userData;
    if(adaptorNIO) {
      if(adaptorNIO->poller == NULL) {
	SFLDataSource_instance dsi;
	SFL_DS_SET(dsi, 0, adaptor->ifIndex, 0); // ds_class,ds_index,ds_instance
	HSPSFlow *sf = sp->sFlow;
	uint32_t pollingInterval = sf->sFlowSettings ?
	  sf->sFlowSettings->pollingInterval :
	  SFL_DEFAULT_POLLING_INTERVAL;
	adaptorNIO->poller = sfl_agent_addPoller(sf->agent, &dsi, sp, agentCB_getCounters_interface);
	sfl_poller_set_sFlowCpInterval(adaptorNIO->poller, pollingInterval);
	sfl_poller_set_sFlowCpReceiver(adaptorNIO->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.
	adaptorNIO->poller->userData = (void *)my_strdup(adaptor->deviceName);
      }
      return adaptorNIO->poller;
    }
    return NULL;
  }
Ejemplo n.º 6
0
static BOOL initAgent(HSP *sp)
{
	time_t now;
	HSPCollector *collector;
	SFLReceiver *receiver;
	uint32_t receiverIndex;
	SFLDataSource_instance dsi;
	uint32_t pollingInterval;
	HSPSFlow *sf = sp->sFlow;
	WSADATA WSAData;
	int WSARes = 0;

	myLog(LOG_INFO,"creating sfl agent\n");
	if (sf->collectors == NULL) {
		myLog(LOG_ERR,"No collectors defined\n");
		return FALSE;
	}
	assert(sf->agentIP.type);

	WORD word = MAKEWORD(2, 2);
	WSARes = WSAStartup(word,&WSAData);
	if (WSARes != 0) {
		myLog(LOG_ERR,"WSAStartup failed: %d",WSARes);
		exit(WSARes);
	}
	// open the sockets if not open already - one for v4 and another for v6
    if (sp->socket4 <= 0) {
		if ((sp->socket4 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
			myLog(LOG_ERR,"socket error");
		}
	}
	if (sp->socket6 <= 0) {
		if ((sp->socket6 = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
			myLog(LOG_ERR,"socket error");
		}
	}
	time(&now);
	sf->agent = (SFLAgent *)my_calloc(sizeof(SFLAgent));
	sfl_agent_init(sf->agent,
				   &sf->agentIP,
				   sf->subAgentId,
				   now,
				   now,
				   sp,
				   agentCB_alloc,
				   agentCB_free,
				   agentCB_error,
				   agentCB_sendPkt);
	// just one receiver - we are serious about making this lightweight for now
	collector = sf->collectors;
	receiver = sfl_agent_addReceiver(sf->agent);
	receiverIndex = HSP_SFLOW_RECEIVER_INDEX;
    
	// set the default receiver owner string
	sfl_receiver_set_sFlowRcvrOwner(receiver, "HyperV sFlow Agent");
    
	// set the timeout to infinity
	sfl_receiver_set_sFlowRcvrTimeout(receiver, 0xFFFFFFFF);

	// receiver address/port - set it for the first collector,  but
	// actually we'll send the same feed to all collectors.  This step
	// may not be necessary at all when we are using the sendPkt callback.
	sfl_receiver_set_sFlowRcvrAddress(receiver, &collector->ipAddr);
	sfl_receiver_set_sFlowRcvrPort(receiver, collector->udpPort);
    
	pollingInterval = sf->sFlowSettings ? sf->sFlowSettings->pollingInterval : SFL_DEFAULT_POLLING_INTERVAL;
	// add a single poller to represent the whole physical host
	if (pollingInterval > 0) {
		// ds_class = <physicalEntity>, ds_index = <my physical>, ds_instance = 0
		SFL_DS_SET(dsi, SFL_DSCLASS_PHYSICAL_ENTITY, HSP_DEFAULT_PHYSICAL_DSINDEX, 0);  
		sf->poller = sfl_agent_addPoller(sf->agent, &dsi, sp, agentCB_getCounters);
		sfl_poller_set_sFlowCpInterval(sf->poller, pollingInterval);
		sfl_poller_set_sFlowCpReceiver(sf->poller, receiverIndex);
	}
    return TRUE;
}
Ejemplo n.º 7
0
  static int initAgent(HSP *sp)
  {
	time_t now;
	HSPCollector *collector;
    SFLReceiver *receiver;
    uint32_t receiverIndex;
	SFLDataSource_instance dsi;
	uint32_t pollingInterval;
	HSPSFlow *sf = sp->sFlow;
	WSADATA WSAData;
	int WSARes = 0;

    MyLog(LOG_ERR,"creating sfl agent\n");

    if(sf->collectors == NULL) {
	  MyLog(LOG_ERR,"No collectors defined\n");
      return NO;
    }

    assert(sf->agentIP.type);

	WSARes = WSAStartup(MAKEWORD(2, 2),&WSAData);
    if(WSARes != 0){
		MyLog(LOG_ERR,"WSAStartup failed: %d\n",WSARes);
		exit(WSARes);
	}
    // open the sockets if not open already - one for v4 and another for v6
    if(sp->socket4 <= 0) {
      if((sp->socket4 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
		  MyLog(LOG_ERR,"socket error");
    }
    if(sp->socket6 <= 0) {
      if((sp->socket6 = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)) == -1)
		  MyLog(LOG_ERR,"socket error");
    }

	
    time(&now);
    sf->agent = (SFLAgent *)calloc(1, sizeof(SFLAgent));
    sfl_agent_init(sf->agent,
		   &sf->agentIP,
		   sf->subAgentId,
		   now,
		   now,
		   sp,
		   agentCB_alloc,
		   agentCB_free,
		   agentCB_error,
		   agentCB_sendPkt);
    // just one receiver - we are serious about making this lightweight for now
    collector = sf->collectors;
    receiver = sfl_agent_addReceiver(sf->agent);
    receiverIndex = 1;
    
    // claim the receiver slot
    sfl_receiver_set_sFlowRcvrOwner(receiver, "Virtual Switch sFlow Probe");
    
    // set the timeout to infinity
    sfl_receiver_set_sFlowRcvrTimeout(receiver, 0xFFFFFFFF);

    // receiver address/port - set it for the first collector,  but
    // actually we'll send the same feed to all collectors.  This step
    // may not be necessary at all when we are using the sendPkt callback.
    sfl_receiver_set_sFlowRcvrAddress(receiver, &collector->ipAddr);
    sfl_receiver_set_sFlowRcvrPort(receiver, collector->udpPort);
    
    pollingInterval = sf->sFlowSettings ? sf->sFlowSettings->pollingInterval : SFL_DEFAULT_POLLING_INTERVAL;
    
    // add a single poller to represent the whole physical host
    
    SFL_DS_SET(dsi, 2, 1, 0);  // ds_class = <physicalEntity>, ds_index = 1, ds_instance = 0
    sf->poller = sfl_agent_addPoller(sf->agent, &dsi, sp, agentCB_getCounters);
    sfl_poller_set_sFlowCpInterval(sf->poller, pollingInterval);
    sfl_poller_set_sFlowCpReceiver(sf->poller, receiverIndex);
    
    // add poller instances for each virtual machine $$$
    
    return YES;
  }