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 <richardcoch...@gmail.com>
---
 makefile      |  3 ++-
 mtab.h        |  2 ++
 unicast_fsm.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 unicast_fsm.h | 40 +++++++++++++++++++++++++++
 4 files changed, 130 insertions(+), 1 deletion(-)
 create mode 100644 unicast_fsm.c
 create mode 100644 unicast_fsm.h

diff --git a/makefile b/makefile
index fafacbe..a6e3eb5 100644
--- a/makefile
+++ b/makefile
@@ -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
diff --git a/mtab.h b/mtab.h
index d34bf9c..949929f 100644
--- a/mtab.h
+++ b/mtab.h
@@ -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;
diff --git a/unicast_fsm.c b/unicast_fsm.c
new file mode 100644
index 0000000..f356541
--- /dev/null
+++ b/unicast_fsm.c
@@ -0,0 +1,86 @@
+/**
+ * @file unicast_fsm.c
+ * @brief Unicast client state machine
+ * @note Copyright (C) 2018 Richard Cochran <richardcoch...@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;
+}
diff --git a/unicast_fsm.h b/unicast_fsm.h
new file mode 100644
index 0000000..49fc9b2
--- /dev/null
+++ b/unicast_fsm.h
@@ -0,0 +1,40 @@
+/**
+ * @file unicast_fsm.h
+ * @brief Unicast client state machine
+ * @note Copyright (C) 2018 Richard Cochran <richardcoch...@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
-- 
2.11.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to