xref: /onnv-gate/usr/src/lib/librstp/common/times.c (revision 10491:8893b747ecdf)
1*10491SRishi.Srivatsavai@Sun.COM /************************************************************************
2*10491SRishi.Srivatsavai@Sun.COM  * RSTP library - Rapid Spanning Tree (802.1t, 802.1w)
3*10491SRishi.Srivatsavai@Sun.COM  * Copyright (C) 2001-2003 Optical Access
4*10491SRishi.Srivatsavai@Sun.COM  * Author: Alex Rozin
5*10491SRishi.Srivatsavai@Sun.COM  *
6*10491SRishi.Srivatsavai@Sun.COM  * This file is part of RSTP library.
7*10491SRishi.Srivatsavai@Sun.COM  *
8*10491SRishi.Srivatsavai@Sun.COM  * RSTP library is free software; you can redistribute it and/or modify it
9*10491SRishi.Srivatsavai@Sun.COM  * under the terms of the GNU Lesser General Public License as published by the
10*10491SRishi.Srivatsavai@Sun.COM  * Free Software Foundation; version 2.1
11*10491SRishi.Srivatsavai@Sun.COM  *
12*10491SRishi.Srivatsavai@Sun.COM  * RSTP library is distributed in the hope that it will be useful, but
13*10491SRishi.Srivatsavai@Sun.COM  * WITHOUT ANY WARRANTY; without even the implied warranty of
14*10491SRishi.Srivatsavai@Sun.COM  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
15*10491SRishi.Srivatsavai@Sun.COM  * General Public License for more details.
16*10491SRishi.Srivatsavai@Sun.COM  *
17*10491SRishi.Srivatsavai@Sun.COM  * You should have received a copy of the GNU Lesser General Public License
18*10491SRishi.Srivatsavai@Sun.COM  * along with RSTP library; see the file COPYING.  If not, write to the Free
19*10491SRishi.Srivatsavai@Sun.COM  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20*10491SRishi.Srivatsavai@Sun.COM  * 02111-1307, USA.
21*10491SRishi.Srivatsavai@Sun.COM  **********************************************************************/
22*10491SRishi.Srivatsavai@Sun.COM 
23*10491SRishi.Srivatsavai@Sun.COM /* "Times" API : bridgeTime, rootTimes, portTimes, designatedTimes, msgTimes */
24*10491SRishi.Srivatsavai@Sun.COM 
25*10491SRishi.Srivatsavai@Sun.COM #include "base.h"
26*10491SRishi.Srivatsavai@Sun.COM 
27*10491SRishi.Srivatsavai@Sun.COM int
STP_compare_times(IN TIMEVALUES_T * t1,IN TIMEVALUES_T * t2)28*10491SRishi.Srivatsavai@Sun.COM STP_compare_times (IN TIMEVALUES_T *t1, IN TIMEVALUES_T *t2)
29*10491SRishi.Srivatsavai@Sun.COM {
30*10491SRishi.Srivatsavai@Sun.COM   if (t1->MessageAge < t2->MessageAge)     return -1;
31*10491SRishi.Srivatsavai@Sun.COM   if (t1->MessageAge > t2->MessageAge)     return  1;
32*10491SRishi.Srivatsavai@Sun.COM 
33*10491SRishi.Srivatsavai@Sun.COM   if (t1->MaxAge < t2->MaxAge)             return -2;
34*10491SRishi.Srivatsavai@Sun.COM   if (t1->MaxAge > t2->MaxAge)             return  2;
35*10491SRishi.Srivatsavai@Sun.COM 
36*10491SRishi.Srivatsavai@Sun.COM   if (t1->ForwardDelay < t2->ForwardDelay) return -3;
37*10491SRishi.Srivatsavai@Sun.COM   if (t1->ForwardDelay > t2->ForwardDelay) return  3;
38*10491SRishi.Srivatsavai@Sun.COM 
39*10491SRishi.Srivatsavai@Sun.COM   if (t1->HelloTime < t2->HelloTime)       return -4;
40*10491SRishi.Srivatsavai@Sun.COM   if (t1->HelloTime > t2->HelloTime)       return  4;
41*10491SRishi.Srivatsavai@Sun.COM 
42*10491SRishi.Srivatsavai@Sun.COM   return 0;
43*10491SRishi.Srivatsavai@Sun.COM }
44*10491SRishi.Srivatsavai@Sun.COM 
45*10491SRishi.Srivatsavai@Sun.COM void
STP_get_times(IN BPDU_BODY_T * b,OUT TIMEVALUES_T * v)46*10491SRishi.Srivatsavai@Sun.COM STP_get_times (IN BPDU_BODY_T *b, OUT TIMEVALUES_T *v)
47*10491SRishi.Srivatsavai@Sun.COM {
48*10491SRishi.Srivatsavai@Sun.COM   /* LINTED: alignment */
49*10491SRishi.Srivatsavai@Sun.COM   v->MessageAge =   ntohs (*((unsigned short*) b->message_age))   >> 8;
50*10491SRishi.Srivatsavai@Sun.COM   /* LINTED: alignment */
51*10491SRishi.Srivatsavai@Sun.COM   v->MaxAge =       ntohs (*((unsigned short*) b->max_age))       >> 8;
52*10491SRishi.Srivatsavai@Sun.COM   /* LINTED: alignment */
53*10491SRishi.Srivatsavai@Sun.COM   v->ForwardDelay = ntohs (*((unsigned short*) b->forward_delay)) >> 8;
54*10491SRishi.Srivatsavai@Sun.COM   /* LINTED: alignment */
55*10491SRishi.Srivatsavai@Sun.COM   v->HelloTime =    ntohs (*((unsigned short*) b->hello_time))    >> 8;
56*10491SRishi.Srivatsavai@Sun.COM }
57*10491SRishi.Srivatsavai@Sun.COM 
58*10491SRishi.Srivatsavai@Sun.COM void
STP_set_times(IN TIMEVALUES_T * v,OUT BPDU_BODY_T * b)59*10491SRishi.Srivatsavai@Sun.COM STP_set_times (IN TIMEVALUES_T *v, OUT BPDU_BODY_T *b)
60*10491SRishi.Srivatsavai@Sun.COM {
61*10491SRishi.Srivatsavai@Sun.COM   unsigned short mt;
62*10491SRishi.Srivatsavai@Sun.COM   #define STP_SET_TIME(f, t)        \
63*10491SRishi.Srivatsavai@Sun.COM      mt = htons (f << 8);           \
64*10491SRishi.Srivatsavai@Sun.COM      (void) memcpy (t, &mt, 2);
65*10491SRishi.Srivatsavai@Sun.COM 
66*10491SRishi.Srivatsavai@Sun.COM   STP_SET_TIME(v->MessageAge,   b->message_age);
67*10491SRishi.Srivatsavai@Sun.COM   STP_SET_TIME(v->MaxAge,       b->max_age);
68*10491SRishi.Srivatsavai@Sun.COM   STP_SET_TIME(v->ForwardDelay, b->forward_delay);
69*10491SRishi.Srivatsavai@Sun.COM   STP_SET_TIME(v->HelloTime,    b->hello_time);
70*10491SRishi.Srivatsavai@Sun.COM }
71*10491SRishi.Srivatsavai@Sun.COM 
72*10491SRishi.Srivatsavai@Sun.COM void
STP_copy_times(OUT TIMEVALUES_T * t,IN TIMEVALUES_T * f)73*10491SRishi.Srivatsavai@Sun.COM STP_copy_times (OUT TIMEVALUES_T *t, IN TIMEVALUES_T *f)
74*10491SRishi.Srivatsavai@Sun.COM {
75*10491SRishi.Srivatsavai@Sun.COM   t->MessageAge = f->MessageAge;
76*10491SRishi.Srivatsavai@Sun.COM   t->MaxAge = f->MaxAge;
77*10491SRishi.Srivatsavai@Sun.COM   t->ForwardDelay = f->ForwardDelay;
78*10491SRishi.Srivatsavai@Sun.COM   t->HelloTime = f->HelloTime;
79*10491SRishi.Srivatsavai@Sun.COM }
80*10491SRishi.Srivatsavai@Sun.COM 
81