1N/A/************************************************************************
1N/A * RSTP library - Rapid Spanning Tree (802.1t, 802.1w)
1N/A * Copyright (C) 2001-2003 Optical Access
1N/A * Author: Alex Rozin
1N/A *
1N/A * This file is part of RSTP library.
1N/A *
1N/A * RSTP library is free software; you can redistribute it and/or modify it
1N/A * under the terms of the GNU Lesser General Public License as published by the
1N/A * Free Software Foundation; version 2.1
1N/A *
1N/A * RSTP library is distributed in the hope that it will be useful, but
1N/A * WITHOUT ANY WARRANTY; without even the implied warranty of
1N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
1N/A * General Public License for more details.
1N/A *
1N/A * You should have received a copy of the GNU Lesser General Public License
1N/A * along with RSTP library; see the file COPYING. If not, write to the Free
1N/A * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1N/A * 02111-1307, USA.
1N/A **********************************************************************/
1N/A
1N/A/* "Times" API : bridgeTime, rootTimes, portTimes, designatedTimes, msgTimes */
1N/A
1N/A#include "base.h"
1N/A
1N/Aint
1N/ASTP_compare_times (IN TIMEVALUES_T *t1, IN TIMEVALUES_T *t2)
1N/A{
1N/A if (t1->MessageAge < t2->MessageAge) return -1;
1N/A if (t1->MessageAge > t2->MessageAge) return 1;
1N/A
1N/A if (t1->MaxAge < t2->MaxAge) return -2;
1N/A if (t1->MaxAge > t2->MaxAge) return 2;
1N/A
1N/A if (t1->ForwardDelay < t2->ForwardDelay) return -3;
1N/A if (t1->ForwardDelay > t2->ForwardDelay) return 3;
1N/A
1N/A if (t1->HelloTime < t2->HelloTime) return -4;
1N/A if (t1->HelloTime > t2->HelloTime) return 4;
1N/A
1N/A return 0;
1N/A}
1N/A
1N/Avoid
1N/ASTP_get_times (IN BPDU_BODY_T *b, OUT TIMEVALUES_T *v)
1N/A{
1N/A /* LINTED: alignment */
1N/A v->MessageAge = ntohs (*((unsigned short*) b->message_age)) >> 8;
1N/A /* LINTED: alignment */
1N/A v->MaxAge = ntohs (*((unsigned short*) b->max_age)) >> 8;
1N/A /* LINTED: alignment */
1N/A v->ForwardDelay = ntohs (*((unsigned short*) b->forward_delay)) >> 8;
1N/A /* LINTED: alignment */
1N/A v->HelloTime = ntohs (*((unsigned short*) b->hello_time)) >> 8;
1N/A}
1N/A
1N/Avoid
1N/ASTP_set_times (IN TIMEVALUES_T *v, OUT BPDU_BODY_T *b)
1N/A{
1N/A unsigned short mt;
1N/A #define STP_SET_TIME(f, t) \
1N/A mt = htons (f << 8); \
1N/A (void) memcpy (t, &mt, 2);
1N/A
1N/A STP_SET_TIME(v->MessageAge, b->message_age);
1N/A STP_SET_TIME(v->MaxAge, b->max_age);
1N/A STP_SET_TIME(v->ForwardDelay, b->forward_delay);
1N/A STP_SET_TIME(v->HelloTime, b->hello_time);
1N/A}
1N/A
1N/Avoid
1N/ASTP_copy_times (OUT TIMEVALUES_T *t, IN TIMEVALUES_T *f)
1N/A{
1N/A t->MessageAge = f->MessageAge;
1N/A t->MaxAge = f->MaxAge;
1N/A t->ForwardDelay = f->ForwardDelay;
1N/A t->HelloTime = f->HelloTime;
1N/A}
1N/A