Introduce the unicast client finite state machine.

In order to implement client side unicast negotiation, state is needed
per port and master.  This patch adds the needed state machines.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2018-03-27 15:12:12 -07:00
parent e22dc6b113
commit 0fffa6c4b5
4 changed files with 130 additions and 1 deletions

View File

@ -26,7 +26,8 @@ PRG = ptp4l hwstamp_ctl nsm phc2sys phc_ctl pmc timemaster
OBJ = bmc.o clock.o clockadj.o clockcheck.o config.o e2e_tc.o fault.o \
filter.o fsm.o hash.o linreg.o mave.o mmedian.o msg.o ntpshm.o nullf.o phc.o \
pi.o port.o print.o ptp4l.o p2p_tc.o raw.o rtnl.o servo.o sk.o stats.o tc.o \
telecom.o tlv.o transport.o tsproc.o udp.o udp6.o uds.o util.o version.o
telecom.o tlv.o transport.o tsproc.o udp.o udp6.o uds.o unicast_fsm.o util.o \
version.o
OBJECTS = $(OBJ) hwstamp_ctl.o nsm.o phc2sys.o phc_ctl.o pmc.o pmc_common.o \
sysoff.o timemaster.o

2
mtab.h
View File

@ -26,11 +26,13 @@
#include "address.h"
#include "pdt.h"
#include "transport.h"
#include "unicast_fsm.h"
struct unicast_master_address {
STAILQ_ENTRY(unicast_master_address) list;
struct PortIdentity portIdentity;
enum transport_type type;
enum unicast_state state;
struct address address;
unsigned int granted;
unsigned int sydymsk;

86
unicast_fsm.c 100644
View File

@ -0,0 +1,86 @@
/**
* @file unicast_fsm.c
* @brief Unicast client state machine
* @note Copyright (C) 2018 Richard Cochran <richardcochran@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA.
*/
#include "unicast_fsm.h"
enum unicast_state unicast_fsm(enum unicast_state state, enum unicast_event ev)
{
enum unicast_state next = state;
switch (state) {
case UC_WAIT:
switch (ev) {
case UC_EV_GRANT_ANN:
next = UC_HAVE_ANN;
break;
case UC_EV_SELECTED:
case UC_EV_GRANT_SYDY:
case UC_EV_UNSELECTED:
case UC_EV_CANCEL:
break;
}
break;
case UC_HAVE_ANN:
switch (ev) {
case UC_EV_GRANT_ANN:
break;
case UC_EV_SELECTED:
next = UC_NEED_SYDY;
break;
case UC_EV_GRANT_SYDY:
case UC_EV_UNSELECTED:
break;
case UC_EV_CANCEL:
next = UC_WAIT;
break;
}
break;
case UC_NEED_SYDY:
switch (ev) {
case UC_EV_GRANT_ANN:
case UC_EV_SELECTED:
break;
case UC_EV_GRANT_SYDY:
next = UC_HAVE_SYDY;
break;
case UC_EV_UNSELECTED:
next = UC_HAVE_ANN;
break;
case UC_EV_CANCEL:
next = UC_WAIT;
break;
}
break;
case UC_HAVE_SYDY:
switch (ev) {
case UC_EV_GRANT_ANN:
case UC_EV_SELECTED:
case UC_EV_GRANT_SYDY:
break;
case UC_EV_UNSELECTED:
next = UC_HAVE_ANN;
break;
case UC_EV_CANCEL:
next = UC_WAIT;
break;
}
break;
}
return next;
}

40
unicast_fsm.h 100644
View File

@ -0,0 +1,40 @@
/**
* @file unicast_fsm.h
* @brief Unicast client state machine
* @note Copyright (C) 2018 Richard Cochran <richardcochran@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA.
*/
#ifndef HAVE_UNICAST_FSM_H
#define HAVE_UNICAST_FSM_H
enum unicast_state {
UC_WAIT,
UC_HAVE_ANN,
UC_NEED_SYDY,
UC_HAVE_SYDY,
};
enum unicast_event {
UC_EV_GRANT_ANN,
UC_EV_SELECTED,
UC_EV_GRANT_SYDY,
UC_EV_UNSELECTED,
UC_EV_CANCEL,
};
enum unicast_state unicast_fsm(enum unicast_state state, enum unicast_event ev);
#endif