Sequence ID rollover behavior

Document created by cdnadmin on Jan 24, 2014
Version 1Show Document
  • View in full screen mode
This document was generated from CDN thread

Created by: Christopher Verges on 18-07-2010 01:30:20 AM
In the reference agent, proto_next_seqid() uses a signed integer datatype that constantly increments.  At some point, this datatype will overflow.  What is the expected behavior in the protocol itself?  Should the implementing reference agent that is persisting the sequence ID cap and rollover at a certain point?
 
Example:
 
#define ENERGYWISE_MAX_SEQUENCE_ID     (32678)
 
int proto_next_seqid()
{
     static int id = 0;
     id = (id + 1) % ENERGYWISE_MAX_SEQUENCE_ID;
     return id;
}
 
Thanks,
Chris

Subject: RE: Sequence ID rollover behavior
Replied by: Brock Miller on 22-07-2010 12:58:01 AM
Hi Chris,
 
IOS will accept the number to roll over and takes this into consideration when calculating the sequence delta.
 
I.E.  Let's say you are persisting the sequence number in chunks of 100
last known sequence = 0xFFFFFFE0
new sequence after restart (+100) = 0x44
 
IOS will see this difference as integer 100 and allow the packet to come in, and subsequently update its last known sequence value.
 
---
 
As for the issue you are seeing, it looks like the switch is seeing a sequence that is less than the previously seen sequence when you were connected.  OR it could be seeing an exceedingly higher sequence number than before (i.e. a sequence of 1000 jumping all the way to 0x7FFFFFFF).
 
You can restart energywise on the switch in order to get your client reconnected.
 
Thanks

 

Subject: RE: Sequence ID rollover behavior
Replied by: Charles Schoening on 21-07-2010 07:09:50 PM
Its an error that service_energywise_next_seqid_type defines the return type as an int.  It should be a uint32_t.
 
EnergyWiseSdk.h:
 

typedef uint32_t (*service_energywise_next_seqid_type) ();

 
 
RefAgent.c:
 

#define ENERGYWISE_MAX_SEQUENCE_ID  (0xFFFFFFFF)
 
uint32_t
proto_next_seqid()
{
    static uint32_t id = 0;
    id = (id == ENERGYWISE_MAX_SEQUENCE_ID) ? 0 : (id+1);
    return id;
}

Subject: RE: Sequence ID rollover behavior
Replied by: Christopher Verges on 21-07-2010 09:09:28 PM
EnergyWiseSdk.h:
typedef uint32_t (*service_energywise_next_seqid_type) ();
 
RefAgent.c:
#define ENERGYWISE_MAX_SEQUENCE_ID  (0xFFFFFFFF)
 
uint32_t
proto_next_seqid()
{
    static uint32_t id = 0;
    id = (id == ENERGYWISE_MAX_SEQUENCE_ID) ? 0 : (id+1);
    return id;
}


Hi Brad,
 
As I understand the sample code posted, the EnergyWise protocol expects a 32-bit number that starts from 0x0 and counts up to 0xFFFFFFFF, inclusive.  Once the number exceeds 0xFFFFFFFF, the sequence ID will rollover to 0x0 again, where the counter will continue.  Is this correct?
 
Since many agents will be persisting the sequence ID by using a "chunked" approach (where "chunks" of IDs in 100-unit increments, for example, are stored in the database), it follows that the EnergyWise switch has some kind of checking to ensure that this rollover is appropriate.  Would you or Brock please explain how the switch knows that the rollover case has been encountered?
 
Thanks,
Chris

Subject: RE: Sequence ID rollover behavior
Replied by: Christopher Verges on 21-07-2010 10:44:20 PM
Hi Brad,
 
Made the changes, tried again, and got the following error on the Catalyst 3560 console:
 
Jul 21 22:41:54.951: NRGYZ:ENDPOINT:Event from endpoint 10.0.3.120 has bad sequence number 4294967196
 
This is equivalent to 0xFFFFFF9C.
 
Any suggestions?
 
Thanks,
Chris

Subject: RE: Sequence ID rollover behavior
Replied by: Christopher Verges on 22-07-2010 03:48:35 AM
IOS will accept the number to roll over and takes this into consideration when calculating the sequence delta.
 
I.E.  Let's say you are persisting the sequence number in chunks of 100
last known sequence = 0xFFFFFFE0
new sequence after restart (+100) = 0x44
 
IOS will see this difference as integer 100 and allow the packet to come in, and subsequently update its last known sequence value.

 
How does EnergyWise on the switch keep track of the valid sequence number(s)?  It sounds like it uses something similar to a TCP sliding window.  Is this an accurate analogy?  If so, what is the size of the window?  The maximum "chunk" size on the agent side will be related to that.
 
As for the issue you are seeing, it looks like the switch is seeing a sequence that is less than the previously seen sequence when you were connected.  OR it could be seeing an exceedingly higher sequence number than before (i.e. a sequence of 1000 jumping all the way to 0x7FFFFFFF).

 
I did force the sequence number to jump from 0x1000 to 0xFFFFFFE0, because I was tired of waiting for the system to hit the rollover condition.  :-)  I'll be more patient.  Knowing the maximum window size for valid sequence IDs will allow me to script "hops" for testing purposes so that we can emulate the rollover condition in regression.
 
Thanks,
Chris

Subject: RE: Sequence ID rollover behavior
Replied by: Brock Miller on 26-07-2010 10:52:08 PM
How does EnergyWise on the switch keep track of the valid sequence number(s)?  It sounds like it uses something similar to a TCP sliding window.  Is this an accurate analogy?  If so, what is the size of the window?  The maximum "chunk" size on the agent side will be related to that.


EnergyWise will remember that last known sequence number that it has seen from you as well as maintain a vector to indicate whether it ever received any of the previous 64 in-order sequence number values.  Upon receiving a new packet, EW will check if it is newer that the last known.  If yes, then the packet is considered new and accepted.  If the sequence is less than the last known, then EW will cross-check with the previous 64 in-order sequence numbers and verify whether this was previously received or not and only allow if it hasn't been received.

 

I did force the sequence number to jump from 0x1000 to 0xFFFFFFE0, because I was tired of waiting for the system to hit the rollover condition.  :-)  I'll be more patient.  Knowing the maximum window size for valid sequence IDs will allow me to script "hops" for testing purposes so that we can emulate the rollover condition in regression.
 



Maximum window size is one half of the horizon, or 0x7FFFFFFF.

Attachments

    Outcomes