p2p.c revision 4eaa471005973e11a6110b69fe990530b3b95a38
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai/************************************************************************
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * RSTP library - Rapid Spanning Tree (802.1t, 802.1w)
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Copyright (C) 2001-2003 Optical Access
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Author: Alex Rozin
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai *
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * This file is part of RSTP library.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai *
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * RSTP library is free software; you can redistribute it and/or modify it
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * under the terms of the GNU Lesser General Public License as published by the
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Free Software Foundation; version 2.1
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai *
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * RSTP library is distributed in the hope that it will be useful, but
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * WITHOUT ANY WARRANTY; without even the implied warranty of
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * General Public License for more details.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai *
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * You should have received a copy of the GNU Lesser General Public License
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * along with RSTP library; see the file COPYING. If not, write to the Free
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * 02111-1307, USA.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai **********************************************************************/
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai/* Point To Point MAC mode selection machine : 6.4.3, 6.5.1 */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai#include "base.h"
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai#include "stpm.h"
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai#include "stp_to.h" /* for STP_OUT_get_duplex */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai#define STATES { \
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai CHOOSE(INIT), \
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai CHOOSE(RECOMPUTE), \
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai CHOOSE(STABLE) \
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai}
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai#define GET_STATE_NAME STP_p2p_get_state_name
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai#include "choose.h"
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaistatic Bool
4eaa471005973e11a6110b69fe990530b3b95a38Rishi SrivatsavaicomputeP2P (PORT_T *port)
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai{
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai switch (port->adminPointToPointMac) {
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai case P2P_FORCE_TRUE:
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai return True;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai case P2P_FORCE_FALSE:
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai return False;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai default:
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai case P2P_AUTO:
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai return STP_OUT_get_duplex (port->port_index);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai }
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai}
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaivoid
4eaa471005973e11a6110b69fe990530b3b95a38Rishi SrivatsavaiSTP_p2p_enter_state (STATE_MACH_T* s)
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai{
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai register PORT_T* port = s->owner.port;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai switch (s->State) {
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai case BEGIN:
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai case INIT:
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai port->p2p_recompute = True;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai break;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai case RECOMPUTE:
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai port->operPointToPointMac = computeP2P (port);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai port->p2p_recompute = False;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai break;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai case STABLE:
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai break;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai }
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai}
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi SrivatsavaiBool
4eaa471005973e11a6110b69fe990530b3b95a38Rishi SrivatsavaiSTP_p2p_check_conditions (STATE_MACH_T* s)
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai{
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai register PORT_T* port = s->owner.port;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai switch (s->State) {
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai case BEGIN:
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai case INIT:
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai return STP_hop_2_state (s, STABLE);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai case RECOMPUTE:
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai return STP_hop_2_state (s, STABLE);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai case STABLE:
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai if (port->p2p_recompute) {
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai return STP_hop_2_state (s, RECOMPUTE);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai }
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai break;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai }
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai return False;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai}
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai