19cd2d7a5SSteven/*
29cd2d7a5SSteven * Copyright (c) 2017 Cisco and/or its affiliates.
39cd2d7a5SSteven * Licensed under the Apache License, Version 2.0 (the "License");
49cd2d7a5SSteven * you may not use this file except in compliance with the License.
59cd2d7a5SSteven * You may obtain a copy of the License at:
69cd2d7a5SSteven *
79cd2d7a5SSteven *     http://www.apache.org/licenses/LICENSE-2.0
89cd2d7a5SSteven *
99cd2d7a5SSteven * Unless required by applicable law or agreed to in writing, software
109cd2d7a5SSteven * distributed under the License is distributed on an "AS IS" BASIS,
119cd2d7a5SSteven * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
129cd2d7a5SSteven * See the License for the specific language governing permissions and
139cd2d7a5SSteven * limitations under the License.
149cd2d7a5SSteven */
159cd2d7a5SSteven
169cd2d7a5SSteven#ifndef __included_lacp_protocol_h__
179cd2d7a5SSteven#define __included_lacp_protocol_h__
189cd2d7a5SSteven
199cd2d7a5SSteven#include <vnet/ethernet/ethernet.h>
209cd2d7a5SSteven#include <vnet/bonding/node.h>
219cd2d7a5SSteven
229cd2d7a5SSteven#define LACP_CHURN_DETECTION_TIME       60
239cd2d7a5SSteven#define LACP_AGGREGATE_WAIT_TIME        2.0
249cd2d7a5SSteven
259cd2d7a5SSteven#define LACP_SUBTYPE                    1
269cd2d7a5SSteven#define LACP_ACTOR_LACP_VERSION         1
279cd2d7a5SSteven
289cd2d7a5SSteven#define foreach_lacp_tlv        \
299cd2d7a5SSteven  _ (TERMINATOR_INFORMATION, 0) \
309cd2d7a5SSteven  _ (ACTOR_INFORMATION, 1)      \
319cd2d7a5SSteven  _ (PARTNER_INFORMATION , 2)   \
329cd2d7a5SSteven  _ (COLLECTOR_INFORMATION, 3)
339cd2d7a5SSteven
349cd2d7a5SSteventypedef enum
359cd2d7a5SSteven{
369cd2d7a5SSteven#define _(f,n) LACP_##f = (n),
379cd2d7a5SSteven  foreach_lacp_tlv
389cd2d7a5SSteven#undef _
399cd2d7a5SSteven} lacp_tlv_t;
409cd2d7a5SSteven
419cd2d7a5SSteven#define foreach_lacp_port  \
429cd2d7a5SSteven  _ (UNSELECTED, 0)        \
439cd2d7a5SSteven  _ (SELECTED, 1)          \
449cd2d7a5SSteven  _ (STANDBY, 2)
459cd2d7a5SSteven
469cd2d7a5SSteventypedef enum
479cd2d7a5SSteven{
489cd2d7a5SSteven#define _(f,n) LACP_PORT_##f = (n),
499cd2d7a5SSteven  foreach_lacp_port
509cd2d7a5SSteven#undef _
519cd2d7a5SSteven} lacp_port_t;
529cd2d7a5SSteven
539cd2d7a5SSteven/* Port state */
549cd2d7a5SSteven#define foreach_lacp_state	     	     \
559cd2d7a5SSteven  _(0, LACP_ACTIVITY, "activity")	     \
569cd2d7a5SSteven  _(1, LACP_TIMEOUT, "lacp timeout")         \
579cd2d7a5SSteven  _(2, AGGREGATION, "aggregation")           \
589cd2d7a5SSteven  _(3, SYNCHRONIZATION, "synchronization")   \
599cd2d7a5SSteven  _(4, COLLECTING, "collecting")            \
609cd2d7a5SSteven  _(5, DISTRIBUTING, "distributing")         \
619cd2d7a5SSteven  _(6, DEFAULTED, "defaulted")               \
629cd2d7a5SSteven  _(7, EXPIRED, "expired")
639cd2d7a5SSteven
64002723c4SSteven Luong#define LACP_STEADY_STATE (LACP_STATE_SYNCHRONIZATION | \
65002723c4SSteven Luong			   LACP_STATE_COLLECTING |      \
66002723c4SSteven Luong			   LACP_STATE_DISTRIBUTING)
67002723c4SSteven Luong
689cd2d7a5SSteventypedef enum
699cd2d7a5SSteven{
709cd2d7a5SSteven#define _(a, b, c) LACP_STATE_##b = (1 << a),
719cd2d7a5SSteven  foreach_lacp_state
729cd2d7a5SSteven#undef _
739cd2d7a5SSteven} lacp_state_t;
749cd2d7a5SSteven
759cd2d7a5SSteven#define foreach_lacp_state_flag	     	                \
76b2ffc697SSteven  _(0, LACP_STATE_LACP_ACTIVITY, "activity")	        \
779cd2d7a5SSteven  _(1, LACP_STATE_LACP_TIMEOUT, "lacp timeout")         \
789cd2d7a5SSteven  _(2, LACP_STATE_AGGREGATION, "aggregation")           \
799cd2d7a5SSteven  _(3, LACP_STATE_SYNCHRONIZATION, "synchronization")   \
809cd2d7a5SSteven  _(4, LACP_STATE_COLLECTIING, "collecting")            \
819cd2d7a5SSteven  _(5, LACP_STATE_DISTRIBUTING, "distributing")         \
829cd2d7a5SSteven  _(6, LACP_STATE_DEFAULTED, "defaulted")               \
839cd2d7a5SSteven  _(7, LACP_STATE_EXPIRED, "expired")
849cd2d7a5SSteven
859cd2d7a5SSteventypedef struct
869cd2d7a5SSteven{
879cd2d7a5SSteven  u8 bit;
889cd2d7a5SSteven  char *str;
899cd2d7a5SSteven} lacp_state_struct;
909cd2d7a5SSteven
919cd2d7a5SSteventypedef struct
929cd2d7a5SSteven{
939cd2d7a5SSteven  u8 bit;
949cd2d7a5SSteven  char *str;
959cd2d7a5SSteven} lacp_event_struct;
969cd2d7a5SSteven
979cd2d7a5SSteven#define LACP_MAX_TX_IN_SECOND           3
989cd2d7a5SSteven#define LACP_DEFAULT_PORT_PRIORITY      0x00ff
999cd2d7a5SSteven#define LACP_DEFAULT_SYSTEM_PRIORITY    0xffff
1009cd2d7a5SSteven
1019cd2d7a5SSteventypedef CLIB_PACKED (struct
1029cd2d7a5SSteven		     {
1039cd2d7a5SSteven		     u8 tlv_type;
1049cd2d7a5SSteven		     u8 tlv_length;
1059cd2d7a5SSteven		     lacp_port_info_t port_info; u8 reserved[3];
1069cd2d7a5SSteven		     }) lacp_actor_partner_t;
1079cd2d7a5SSteven
1089cd2d7a5SSteventypedef CLIB_PACKED (struct
1099cd2d7a5SSteven		     {
1109cd2d7a5SSteven		     u8 tlv_type; u8 tlv_length; u16 max_delay;
1119cd2d7a5SSteven		     u8 reserved[12];
1129cd2d7a5SSteven		     }) lacp_collector_t;
1139cd2d7a5SSteven
1149cd2d7a5SSteventypedef CLIB_PACKED (struct
1159cd2d7a5SSteven		     {
1169cd2d7a5SSteven		     u8 tlv_type; u8 tlv_length;
1179cd2d7a5SSteven		     u8 pad[50];
1189cd2d7a5SSteven		     }) lacp_terminator_t;
1199cd2d7a5SSteven
1209cd2d7a5SSteventypedef CLIB_PACKED (struct
1219cd2d7a5SSteven		     {
1229cd2d7a5SSteven		     u8 subtype; u8 version_number;
1239cd2d7a5SSteven		     lacp_actor_partner_t actor; lacp_actor_partner_t partner;
1249cd2d7a5SSteven		     lacp_collector_t collector; lacp_terminator_t terminator;
1259cd2d7a5SSteven		     }) lacp_pdu_t;
1269cd2d7a5SSteven
1279cd2d7a5SSteventypedef CLIB_PACKED (struct
1289cd2d7a5SSteven		     {
1299cd2d7a5SSteven		     ethernet_header_t ethernet; lacp_pdu_t lacp;
1309cd2d7a5SSteven		     }) ethernet_lacp_pdu_t;
1319cd2d7a5SSteven
1329cd2d7a5SSteven#define MARKER_SUBTYPE                  2
1339cd2d7a5SSteven#define MARKER_PROTOCOL_VERSION         1
1349cd2d7a5SSteven
1359cd2d7a5SSteven#define foreach_marker_tlv      \
1369cd2d7a5SSteven  _ (TERMINATOR_INFORMATION, 0) \
1379cd2d7a5SSteven  _ (INFORMATION, 1)            \
1389cd2d7a5SSteven  _ (RESPONSE_INFORMATION , 2)
1399cd2d7a5SSteven
1409cd2d7a5SSteventypedef enum
1419cd2d7a5SSteven{
1429cd2d7a5SSteven#define _(f,n) MARKER_##f = (n),
1439cd2d7a5SSteven  foreach_marker_tlv
1449cd2d7a5SSteven#undef _
1459cd2d7a5SSteven} marker_tlv_t;
1469cd2d7a5SSteven
1479cd2d7a5SSteventypedef CLIB_PACKED (struct
1489cd2d7a5SSteven		     {
1499cd2d7a5SSteven		     u8 tlv_type; u8 tlv_length;
1509cd2d7a5SSteven		     u8 reserved[90];
1519cd2d7a5SSteven		     }) marker_terminator_t;
1529cd2d7a5SSteven
1539cd2d7a5SSteventypedef CLIB_PACKED (struct
1549cd2d7a5SSteven		     {
1559cd2d7a5SSteven		     u8 tlv_type;
1569cd2d7a5SSteven		     u8 tlv_length;
1579cd2d7a5SSteven		     u16 requester_port; u8 requester_system[6];
1589cd2d7a5SSteven		     u32 requester_transaction_id; u8 pad[2];
1599cd2d7a5SSteven		     }) marker_information_t;
1609cd2d7a5SSteven
1619cd2d7a5SSteventypedef CLIB_PACKED (struct
1629cd2d7a5SSteven		     {
1639cd2d7a5SSteven		     u8 subtype;
1649cd2d7a5SSteven		     u8 version_number;
1659cd2d7a5SSteven		     marker_information_t marker_info;
1669cd2d7a5SSteven		     marker_terminator_t terminator;
1679cd2d7a5SSteven		     }) marker_pdu_t;
1689cd2d7a5SSteven
1699cd2d7a5SSteventypedef CLIB_PACKED (struct
1709cd2d7a5SSteven		     {
1719cd2d7a5SSteven		     ethernet_header_t ethernet; marker_pdu_t marker;
1729cd2d7a5SSteven		     }) ethernet_marker_pdu_t;
1739cd2d7a5SSteven
1749cd2d7a5SSteven#endif /* __included_lacp_protocol_h__ */
1759cd2d7a5SSteven
1769cd2d7a5SSteven/*
1779cd2d7a5SSteven * fd.io coding-style-patch-verification: ON
1789cd2d7a5SSteven *
1799cd2d7a5SSteven * Local Variables:
1809cd2d7a5SSteven * eval: (c-set-style "gnu")
1819cd2d7a5SSteven * End:
1829cd2d7a5SSteven */
183