Author Topic: coldstart trap on m5223x application  (Read 7491 times)

Offline marcelgrando

  • Newbie
  • *
  • Posts: 2
    • View Profile
coldstart trap on m5223x application
« on: May 25, 2011, 02:33:21 PM »
Hi Mark, in my application i'm monitoring some variables like a humidity, temperature... and using the snmp for sending traps. In the original code, the part of varbindings was not been implemented. Then I implemented the part of varbindings which I use when the traps are not standards.
My problem is, in the application i've an archive called "controleSNMPv1.c", and in the task fnTaskMonitoramentoSNMP only in the first iteration I send the coldstart trap like this:
Code: [Select]
void fnTaskMonitoramentoSNMP(TTASKTABLE * ptrTaskTable )
{
static unsigned char startTask = 0;
if(startTask == 0)
{
fnGenerateTrap(SNMP_COLDSTART, 0, 0, 0);
startTask++;
}
        :
        :
}

When I capture the traps in Wireshark, sometimes many of coldstart traps are sent. Why many of coldstart traps are sent if this is the only reference to coldstart trap in my code?

OBS: How i said, in the original code, the part of varbindings was not been implemented. Then I implemented the part of varbindings which I use when the traps are not standards. So the header of my fnGenerateTrap is:
Code: [Select]
int fnGenerateTrap(unsigned char ucTrap, unsigned char ucSpecificCode, unsigned char *varBinding, unsigned char tamanho);Where "*varBinding" is a pointer to the array of virBindings and "tamanho" is the size of this array.

Best Regards,

Marcel.
Marcel T. Grando

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: coldstart trap on m5223x application
« Reply #1 on: May 29, 2011, 10:49:08 PM »
Hi Marcel

I don't know whether you are using the simple SNMP file or one of the more complete V1 or V2 versions (see the SNMP sub-directorie in the "Stack" folder). However fnGenerateTrap() will construct a trap and call fnSendUDP() to actually send the UDP frame. Sending a UDP frame is only possible when the MAC address of the destination is known and so can fail (with return value NO_ARP_ENTRY). When this takes place the ARP task will inform the SNMP task when the address can be resolved (usually a few ms later) and then the message can be sent again (see fnRetry()).

If you are seeing the UDP frame repeated maybe there is a problem with the retry part? Does this help you identify someting?

Regards

Mark




Offline marcelgrando

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: coldstart trap on m5223x application
« Reply #2 on: June 08, 2011, 01:59:03 PM »
Hi Mark, thanks for the tips.
I looked the function fnRetry() and I saw that this function calls another function called fnResendSNMPTrap().
In fnResendSNMPTrap() I read the trap type and when the trap is coldstart one flag is increased and in the others iterations if the trap type is coldstart the function dont call the fnGenerateTrap() function.
Also I have included the guarda_trap variable because in the old way the function was called twice, sending out two traps despite the control.
The code is shown below:
Code: [Select]
static void fnResendSNMPTrap(void)
{
    static char coldstart_control = 0;
    int guarda_trap;
    guarda_trap = fnGenerateTrap(trap_list[0].ucTrapType, trap_list[0].ucTrapSpecificCode, 0, 0);
//    if (fnGenerateTrap(trap_list[0].ucTrapType, trap_list[0].ucTrapSpecificCode, 0, 0) == 0) {                     
if (guarda_trap == 0) {   
        int iTrapQueue = 1;                                              // frame could be delivered this time so delete it from the queue
        while (--ucTrapCnt != 0)
        {                                       // any further in queue are also sent now
            if(coldstart_control == 0 && trap_list[iTrapQueue].ucTrapType == SNMP_COLDSTART)
            {
            coldstart_control++;
            guarda_trap;
//            fnGenerateTrap(trap_list[iTrapQueue].ucTrapType, trap_list[iTrapQueue].ucTrapSpecificCode, 0, 0);
            iTrapQueue++;           
            } else {
            if(coldstart_control == 1 && trap_list[iTrapQueue].ucTrapType == SNMP_COLDSTART)
            {
            iTrapQueue++;
            } else {
            guarda_trap;
//            fnGenerateTrap(trap_list[iTrapQueue].ucTrapType, trap_list[iTrapQueue].ucTrapSpecificCode, 0, 0);
            iTrapQueue++;
            }
            }
        }
    }
}
Thanks for your time Mark

Best Regards,

Marcel.
« Last Edit: June 08, 2011, 02:52:21 PM by marcelgrando »
Marcel T. Grando