Matteo Scandolo | 9f61949 | 2019-10-25 13:11:58 -0700 | [diff] [blame] | 1 | .. _ONU State Machine: |
| 2 | |
| 3 | ONU State Machine |
| 4 | ================= |
| 5 | |
Matteo Scandolo | e383d5d | 2019-10-25 14:47:27 -0700 | [diff] [blame] | 6 | In ``BBSim`` the device state is created using a state machine |
Matteo Scandolo | 9f61949 | 2019-10-25 13:11:58 -0700 | [diff] [blame] | 7 | library: `fsm <https://github.com/looplab/fsm>`__. |
| 8 | |
Matteo Scandolo | d02b79b | 2019-12-05 16:42:13 -0800 | [diff] [blame] | 9 | Here is a list of possible state transitions for an ONU in BBSim: |
Matteo Scandolo | 9f61949 | 2019-10-25 13:11:58 -0700 | [diff] [blame] | 10 | |
Matteo Scandolo | 5e081b5 | 2019-11-21 14:34:25 -0800 | [diff] [blame] | 11 | .. list-table:: ONU States |
| 12 | :widths: 10 35 10 45 |
| 13 | :header-rows: 1 |
Matteo Scandolo | 9f61949 | 2019-10-25 13:11:58 -0700 | [diff] [blame] | 14 | |
Matteo Scandolo | 5e081b5 | 2019-11-21 14:34:25 -0800 | [diff] [blame] | 15 | * - Transition |
| 16 | - Starting States |
| 17 | - End State |
| 18 | - Notes |
| 19 | * - |
| 20 | - |
| 21 | - created |
| 22 | - |
Zdravko Bozakov | c38f926 | 2019-11-27 02:50:05 +0100 | [diff] [blame] | 23 | * - initialize |
| 24 | - created, disabled |
| 25 | - initialized |
| 26 | - |
Matteo Scandolo | 5e081b5 | 2019-11-21 14:34:25 -0800 | [diff] [blame] | 27 | * - discover |
Zdravko Bozakov | c38f926 | 2019-11-27 02:50:05 +0100 | [diff] [blame] | 28 | - initialized |
Matteo Scandolo | 5e081b5 | 2019-11-21 14:34:25 -0800 | [diff] [blame] | 29 | - discovered |
| 30 | - |
| 31 | * - enable |
| 32 | - discovered, disabled |
| 33 | - enabled |
| 34 | - |
| 35 | * - receive_eapol_flow |
| 36 | - enabled, gem_port_added |
| 37 | - eapol_flow_received |
| 38 | - |
| 39 | * - add_gem_port |
| 40 | - enabled, eapol_flow_received |
| 41 | - gem_port_added |
| 42 | - We need to wait for both the flow and the gem port to come before moving to ``auth_started`` |
| 43 | * - start_auth |
| 44 | - eapol_flow_received, gem_port_added, eap_start_sent, eap_response_identity_sent, eap_response_challenge_sent, eap_response_success_received, auth_failed, dhcp_ack_received, dhcp_failed |
| 45 | - auth_started |
| 46 | - |
| 47 | * - eap_start_sent |
| 48 | - auth_started |
| 49 | - eap_start_sent |
| 50 | - |
| 51 | * - eap_response_identity_sent |
| 52 | - eap_start_sent |
| 53 | - eap_response_identity_sent |
| 54 | - |
| 55 | * - eap_response_challenge_sent |
| 56 | - eap_response_identity_sent |
| 57 | - eap_response_challenge_sent |
| 58 | - |
| 59 | * - eap_response_success_received |
| 60 | - eap_response_challenge_sent |
| 61 | - eap_response_success_received |
| 62 | - |
| 63 | * - auth_failed |
| 64 | - auth_started, eap_start_sent, eap_response_identity_sent, eap_response_challenge_sent |
| 65 | - auth_failed |
| 66 | - |
| 67 | * - start_dhcp |
| 68 | - eap_response_success_received, dhcp_discovery_sent, dhcp_request_sent, dhcp_ack_received, dhcp_failed |
| 69 | - dhcp_started |
| 70 | - |
| 71 | * - dhcp_discovery_sent |
| 72 | - dhcp_started |
| 73 | - dhcp_discovery_sent |
| 74 | - |
| 75 | * - dhcp_request_sent |
| 76 | - dhcp_discovery_sent |
| 77 | - dhcp_request_sent |
| 78 | - |
| 79 | * - dhcp_ack_received |
| 80 | - dhcp_request_sent |
| 81 | - dhcp_ack_received |
| 82 | - |
| 83 | * - dhcp_failed |
| 84 | - dhcp_started, dhcp_discovery_sent, dhcp_request_sent |
| 85 | - dhcp_failed |
| 86 | - |
Matteo Scandolo | 9f61949 | 2019-10-25 13:11:58 -0700 | [diff] [blame] | 87 | |
Matteo Scandolo | 5e081b5 | 2019-11-21 14:34:25 -0800 | [diff] [blame] | 88 | In addition some transition can be forced via the API, |
| 89 | check the previous table to verify when you can trigger those actions and |
| 90 | :ref:`BBSimCtl` for more informations about ``BBSimCtl``: |
| 91 | |
| 92 | .. list-table:: API State Transitions |
| 93 | :widths: 15 15 70 |
| 94 | :header-rows: 1 |
| 95 | |
| 96 | * - BBSimCtl command |
| 97 | - Transitions To |
| 98 | - Notes |
| 99 | * - shutdown |
| 100 | - disable |
Zack Williams | 4b0ef4d | 2019-12-18 14:25:20 -0700 | [diff] [blame^] | 101 | - Emulates a device shutdown. Sends a ``DyingGaspInd`` and then an ``OnuIndication{OperState: 'down'}`` |
Matteo Scandolo | 5e081b5 | 2019-11-21 14:34:25 -0800 | [diff] [blame] | 102 | * - poweron |
| 103 | - enable |
Zack Williams | 4b0ef4d | 2019-12-18 14:25:20 -0700 | [diff] [blame^] | 104 | - Emulates a device power on. Sends a ``OnuDiscInd`` and then an ``OnuIndication{OperState: 'up'}`` |
Matteo Scandolo | 5e081b5 | 2019-11-21 14:34:25 -0800 | [diff] [blame] | 105 | * - auth_restart |
| 106 | - start_auth |
| 107 | - Forces the ONU to send a new ``EapStart`` packet. |
| 108 | * - dhcp_restart |
| 109 | - start_dhcp |
| 110 | - Forces the ONU to send a new ``DHCPDiscovery`` packet. |
Matteo Scandolo | 9f61949 | 2019-10-25 13:11:58 -0700 | [diff] [blame] | 111 | |
| 112 | Below is a diagram of the state machine: |
| 113 | |
| 114 | - In blue PON related states |
| 115 | - In green EAPOL related states |
| 116 | - In yellow DHCP related states |
| 117 | - In purple operator driven states |
| 118 | |
| 119 | .. |
| 120 | TODO Evaluate http://blockdiag.com/en/seqdiag/examples.html |
| 121 | |
| 122 | .. graphviz:: |
| 123 | |
| 124 | digraph { |
Zdravko Bozakov | c38f926 | 2019-11-27 02:50:05 +0100 | [diff] [blame] | 125 | rankdir=TB |
| 126 | newrank=true |
Matteo Scandolo | 9f61949 | 2019-10-25 13:11:58 -0700 | [diff] [blame] | 127 | graph [pad="1,1" bgcolor="#cccccc"] |
| 128 | node [style=filled] |
| 129 | |
Zdravko Bozakov | c38f926 | 2019-11-27 02:50:05 +0100 | [diff] [blame] | 130 | subgraph { |
| 131 | node [fillcolor="#bee7fa"] |
Matteo Scandolo | 9f61949 | 2019-10-25 13:11:58 -0700 | [diff] [blame] | 132 | |
Zdravko Bozakov | c38f926 | 2019-11-27 02:50:05 +0100 | [diff] [blame] | 133 | created [peripheries=2] |
| 134 | initialized |
| 135 | discovered |
Zack Williams | 4b0ef4d | 2019-12-18 14:25:20 -0700 | [diff] [blame^] | 136 | { |
Zdravko Bozakov | c38f926 | 2019-11-27 02:50:05 +0100 | [diff] [blame] | 137 | rank=same |
| 138 | enabled |
| 139 | disabled [fillcolor="#f9d6ff"] |
| 140 | } |
| 141 | gem_port_added |
Matteo Scandolo | 9f61949 | 2019-10-25 13:11:58 -0700 | [diff] [blame] | 142 | |
Zdravko Bozakov | c38f926 | 2019-11-27 02:50:05 +0100 | [diff] [blame] | 143 | {created, disabled} -> initialized -> discovered -> enabled |
| 144 | } |
Matteo Scandolo | 9f61949 | 2019-10-25 13:11:58 -0700 | [diff] [blame] | 145 | |
Zdravko Bozakov | c38f926 | 2019-11-27 02:50:05 +0100 | [diff] [blame] | 146 | subgraph cluster_eapol { |
| 147 | style=rounded |
| 148 | style=dotted |
| 149 | node [fillcolor="#e6ffc2"] |
Zack Williams | 4b0ef4d | 2019-12-18 14:25:20 -0700 | [diff] [blame^] | 150 | |
Zdravko Bozakov | c38f926 | 2019-11-27 02:50:05 +0100 | [diff] [blame] | 151 | eapol_flow_received |
| 152 | auth_started |
| 153 | eap_start_sent |
| 154 | eap_response_identity_sent |
| 155 | eap_response_challenge_sent |
Zack Williams | 4b0ef4d | 2019-12-18 14:25:20 -0700 | [diff] [blame^] | 156 | { |
Zdravko Bozakov | c38f926 | 2019-11-27 02:50:05 +0100 | [diff] [blame] | 157 | rank=same |
| 158 | eap_response_success_received |
| 159 | auth_failed |
| 160 | } |
| 161 | |
| 162 | auth_started -> eap_start_sent -> eap_response_identity_sent -> eap_response_challenge_sent -> eap_response_success_received |
| 163 | auth_started -> auth_failed |
| 164 | eap_start_sent -> auth_failed |
| 165 | eap_response_identity_sent -> auth_failed |
| 166 | eap_response_challenge_sent -> auth_failed |
| 167 | |
| 168 | eap_start_sent -> auth_started |
| 169 | eap_response_identity_sent -> auth_started |
| 170 | eap_response_challenge_sent -> auth_started |
| 171 | |
| 172 | eap_response_success_received -> auth_started |
| 173 | auth_failed -> auth_started |
| 174 | } |
| 175 | |
| 176 | subgraph cluster_dhcp { |
| 177 | node [fillcolor="#fffacc"] |
| 178 | style=rounded |
| 179 | style=dotted |
Zack Williams | 4b0ef4d | 2019-12-18 14:25:20 -0700 | [diff] [blame^] | 180 | |
Zdravko Bozakov | c38f926 | 2019-11-27 02:50:05 +0100 | [diff] [blame] | 181 | dhcp_started |
| 182 | dhcp_discovery_sent |
| 183 | dhcp_request_sent |
Zack Williams | 4b0ef4d | 2019-12-18 14:25:20 -0700 | [diff] [blame^] | 184 | { |
Zdravko Bozakov | c38f926 | 2019-11-27 02:50:05 +0100 | [diff] [blame] | 185 | rank=same |
| 186 | dhcp_ack_received |
| 187 | dhcp_failed |
| 188 | } |
Zack Williams | 4b0ef4d | 2019-12-18 14:25:20 -0700 | [diff] [blame^] | 189 | |
Zdravko Bozakov | c38f926 | 2019-11-27 02:50:05 +0100 | [diff] [blame] | 190 | dhcp_started -> dhcp_discovery_sent -> dhcp_request_sent -> dhcp_ack_received |
| 191 | dhcp_started -> dhcp_failed |
| 192 | dhcp_discovery_sent -> dhcp_failed |
| 193 | dhcp_request_sent -> dhcp_failed |
| 194 | dhcp_ack_received dhcp_failed |
| 195 | |
| 196 | dhcp_discovery_sent -> dhcp_started |
| 197 | dhcp_request_sent -> dhcp_started |
| 198 | dhcp_ack_received -> dhcp_started |
| 199 | dhcp_failed -> dhcp_started |
| 200 | } |
Matteo Scandolo | 9f61949 | 2019-10-25 13:11:58 -0700 | [diff] [blame] | 201 | enabled -> gem_port_added -> eapol_flow_received -> auth_started |
| 202 | enabled -> eapol_flow_received -> gem_port_added -> auth_started |
| 203 | |
Zdravko Bozakov | c38f926 | 2019-11-27 02:50:05 +0100 | [diff] [blame] | 204 | {dhcp_ack_received, dhcp_failed} -> auth_started |
Matteo Scandolo | e383d5d | 2019-10-25 14:47:27 -0700 | [diff] [blame] | 205 | |
Matteo Scandolo | 9f61949 | 2019-10-25 13:11:58 -0700 | [diff] [blame] | 206 | eap_response_success_received -> dhcp_started |
Matteo Scandolo | 9f61949 | 2019-10-25 13:11:58 -0700 | [diff] [blame] | 207 | |
| 208 | eap_response_success_received -> disabled |
| 209 | auth_failed -> disabled |
| 210 | dhcp_ack_received -> disabled |
| 211 | dhcp_failed -> disabled |
| 212 | disabled -> enabled |
Zack Williams | 4b0ef4d | 2019-12-18 14:25:20 -0700 | [diff] [blame^] | 213 | } |