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