Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PVST Feature enable #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/stp_externs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern struct STPD_CONTEXT stpd_context;
extern STP_GLOBAL stp_global;
extern uint32_t g_max_stp_port;
extern uint16_t g_stp_bmp_po_offset;
struct timeval g_stp_100ms_tv;
extern struct timeval g_stp_100ms_tv;
extern MAC_ADDRESS bridge_group_address;
extern MAC_ADDRESS pvst_bridge_group_address;
extern MAC_ADDRESS g_stp_base_mac_addr;
Expand Down
4 changes: 2 additions & 2 deletions include/stp_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ typedef struct
#define STPD_INCR_PKT_COUNT(x, y) (g_stpd_intf_stats[x]->y)++
#define STPD_GET_PKT_COUNT(x, y) (g_stpd_intf_stats[x]->y)

struct tm *g_tm;
struct timespec g_ts;
extern struct tm *g_tm;
extern struct timespec g_ts;

typedef struct
{
Expand Down
2 changes: 1 addition & 1 deletion include/stp_netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ typedef struct netlink_db_s
}netlink_db_t;

typedef void stp_netlink_cb_ptr (netlink_db_t *if_db, uint8_t add, bool init_in_prog);
stp_netlink_cb_ptr *stp_netlink_cb;
extern stp_netlink_cb_ptr *stp_netlink_cb;

#define PRINT_MAC_FORMAT "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx"
#define PRINT_MAC_VAL(x) *(char *)x,*((char *)x)+1,*((char *)x)+2,*((char *)x)+3,*((char *)x)+4,*((char *)x)+5
Expand Down
1 change: 1 addition & 0 deletions lib/applog.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ int applog_write(int priority, const char *fmt, ...);

#define APP_LOG_LEVEL_MIN (APP_LOG_LEVEL_EMERG)
#define APP_LOG_LEVEL_DEFAULT (APP_LOG_LEVEL_ERR)
//#define APP_LOG_LEVEL_DEFAULT (APP_LOG_LEVEL_DEBUG)
#define APP_LOG_LEVEL_MAX (APP_LOG_LEVEL_DEBUG)

#define APP_LOG_STATUS_OK (0)
Expand Down
3 changes: 2 additions & 1 deletion stp/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ else
DBGFLAGS = -g -DNDEBUG
endif

libstp_a_CFLAGS = -Werror $(COV_CFLAGS)
#libstp_a_CFLAGS = -Werror $(COV_CFLAGS)
libstp_a_CFLAGS = $(COV_CFLAGS)
libstp_a_SOURCES = stp.c stp_pkt.c stp_data.c stp_debug.c stp_intf.c stp_main.c stp_mgr.c stp_netlink.c stp_timer.c stp_util.c
10 changes: 8 additions & 2 deletions stp/stp.c
Original file line number Diff line number Diff line change
Expand Up @@ -881,9 +881,12 @@ void send_config_bpdu(STP_CLASS* stp_class, PORT_ID port_number)


if (!g_sstp_enabled)
{
stputil_send_pvst_bpdu(stp_class, port_number, CONFIG_BPDU_TYPE);
else
} else
{
stputil_send_bpdu(stp_class, port_number, CONFIG_BPDU_TYPE);
}
}

void send_tcn_bpdu(STP_CLASS* stp_class, PORT_ID port_number)
Expand All @@ -896,7 +899,10 @@ void send_tcn_bpdu(STP_CLASS* stp_class, PORT_ID port_number)
return;

if (!g_sstp_enabled)
{
stputil_send_pvst_bpdu(stp_class, port_number, TCN_BPDU_TYPE);
else
} else
{
stputil_send_bpdu(stp_class, port_number, TCN_BPDU_TYPE);
}
}
25 changes: 24 additions & 1 deletion stp/stp_intf.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/

#include "stp_inc.h"
#include <stdio.h>
#include <ctype.h>

int stp_intf_get_netlink_fd()
{
Expand Down Expand Up @@ -421,10 +423,14 @@ bool stp_intf_update_po_members(netlink_db_t * if_db, INTERFACE_NODE * node)
}
}


INTERFACE_NODE * stp_intf_update_intf_db(netlink_db_t *if_db, uint8_t is_add, bool init_in_prog, bool eth_if)
{
INTERFACE_NODE *node = NULL;
uint32_t port_id = 0;
char *ifname_trim;
char num_str[ STP_ETH_NAME_PREFIX_LEN ];
int index=0, i;

if(is_add)
{
Expand All @@ -438,7 +444,24 @@ INTERFACE_NODE * stp_intf_update_intf_db(netlink_db_t *if_db, uint8_t is_add, bo
/* Update port id */
if(eth_if)
{
port_id = strtol(((char *)if_db->ifname + STP_ETH_NAME_PREFIX_LEN), NULL, 10);
//Ensure that Inerface name contains min STP_ETH_NAME_PREFIX_LEN chars
if (strlen((char *)if_db->ifname) < STP_ETH_NAME_PREFIX_LEN)
{
STP_LOG_ERR("Port id update failed for invalid interface name: %s", if_db->ifname);
return node;
}
// Perform the conversion using strtol
ifname_trim = (char *)if_db->ifname + STP_ETH_NAME_PREFIX_LEN;
memset(num_str,0, sizeof(num_str));
for (i=0; ifname_trim[i] != '\0' && index < STP_ETH_NAME_PREFIX_LEN; i++)
{
if (isdigit(ifname_trim[i]) )
{
num_str[index++] = ifname_trim[i];
}
}
num_str[index] = '\0';
port_id = strtol(num_str, NULL, 10);
node->port_id = port_id;

/* Derive Max Port */
Expand Down
7 changes: 5 additions & 2 deletions stp/stp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/

#include "stp_main.h"
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>

STPD_CONTEXT stpd_context;

Expand All @@ -32,7 +35,7 @@ int stpd_ipc_init()
STP_LOG_ERR("ipc socket error %s", strerror(errno));
return -1;
}

// setup socket address structure
memset(&sa, 0, sizeof(struct sockaddr_un));
sa.sun_family = AF_UNIX;
Expand All @@ -54,7 +57,7 @@ int stpd_ipc_init()
return -1;
}

STP_LOG_DEBUG("ipc init done");
STP_LOG_DEBUG("stpd: ipc init done");

return 0;
}
Expand Down
6 changes: 1 addition & 5 deletions stp/stp_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "stp_inc.h"
#include "stp_main.h"
#include <stdio.h>

MAC_ADDRESS g_stp_base_mac_addr;

Expand Down Expand Up @@ -73,7 +74,6 @@ struct event *stpmgr_libevent_create(struct event_base *base,
STP_LOG_DEBUG("base : %p, sock : %d, flags : %x, cb_fn : %p", base, sock, flags, cb_fn);
if (tv)
STP_LOG_DEBUG("tv.sec : %u, tv.usec : %u", tv->tv_sec, tv->tv_usec);

return ev;
}
}
Expand Down Expand Up @@ -115,7 +115,6 @@ void stpmgr_initialize_stp_class(STP_CLASS *stp_class, VLAN_ID vlan_id)
stp_index = GET_STP_INDEX(stp_class);

stp_class->vlan_id = vlan_id;

stputil_set_bridge_priority(&stp_class->bridge_info.bridge_id, STP_DFLT_PRIORITY, vlan_id);
NET_TO_HOST_MAC(&stp_class->bridge_info.bridge_id.address, &g_stp_base_mac_addr);

Expand Down Expand Up @@ -1125,8 +1124,6 @@ static bool stpmgr_config_fastspan(PORT_ID port_id, bool enable)

if (enable)
{
if(is_member(g_fastspan_config_mask, port_id))
return ret;
set_mask_bit(g_fastspan_config_mask, port_id);
set_mask_bit(g_fastspan_mask, port_id);
stpsync_update_port_fast(stp_intf_get_port_name(port_id), true);
Expand Down Expand Up @@ -1490,7 +1487,6 @@ static void stpmgr_process_bridge_config_msg(void *msg)
pmsg->opcode, pmsg->stp_mode, pmsg->rootguard_timeout, pmsg->base_mac_addr[0],
pmsg->base_mac_addr[1], pmsg->base_mac_addr[2], pmsg->base_mac_addr[3],
pmsg->base_mac_addr[4], pmsg->base_mac_addr[5]);

if (pmsg->opcode == STP_SET_COMMAND)
{
stp_global.enable = true;
Expand Down
3 changes: 2 additions & 1 deletion stp/stp_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
* limitations under the License.
*/

#include "stp_netlink.h"
#include <stp_netlink.h>

stp_netlink_cb_ptr *stp_netlink_cb;
int stp_intf_get_netlink_fd();


Expand Down
14 changes: 14 additions & 0 deletions stpd_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,25 @@
*/

#include <iostream>
#include "swss/logger.h"

using namespace std;

extern "C" void stpd_main();

int main(int argc, char **argv)
{

swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG);
SWSS_LOG_ENTER();

swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_NOTICE);

swss::Logger::linkToDbNative("stpd");


SWSS_LOG_NOTICE("--- Starting stpd ---");

stpd_main();
return 0;
}
Expand Down
36 changes: 18 additions & 18 deletions stpsync/stp_sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,94 +48,94 @@ StpSync::StpSync(DBConnector *db, DBConnector *cfgDb) :

DBConnector db(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector cfgDb(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
StpSync sync(&db, &cfgDb);
StpSync stpSync(&db, &cfgDb);

extern "C" {

void stpsync_add_vlan_to_instance(uint16_t vlan_id, uint16_t instance)
{
sync.addVlanToInstance(vlan_id, instance);
stpSync.addVlanToInstance(vlan_id, instance);
}

void stpsync_del_vlan_from_instance(uint16_t vlan_id, uint16_t instance)
{
sync.delVlanFromInstance(vlan_id, instance);
stpSync.delVlanFromInstance(vlan_id, instance);
}

void stpsync_update_stp_class(STP_VLAN_TABLE * stp_vlan)
{
sync.updateStpVlanInfo(stp_vlan);
stpSync.updateStpVlanInfo(stp_vlan);
}

void stpsync_del_stp_class(uint16_t vlan_id)
{
sync.delStpVlanInfo(vlan_id);
stpSync.delStpVlanInfo(vlan_id);
}

void stpsync_update_port_class(STP_VLAN_PORT_TABLE * stp_vlan_intf)
{
sync.updateStpVlanInterfaceInfo(stp_vlan_intf);
stpSync.updateStpVlanInterfaceInfo(stp_vlan_intf);
}

void stpsync_del_port_class(char * if_name, uint16_t vlan_id)
{
sync.delStpVlanInterfaceInfo(if_name, vlan_id);
stpSync.delStpVlanInterfaceInfo(if_name, vlan_id);
}

void stpsync_update_port_state(char * ifName, uint16_t instance, uint8_t state)
{
sync.updateStpPortState(ifName, instance, state);
stpSync.updateStpPortState(ifName, instance, state);
}

void stpsync_del_port_state(char * ifName, uint16_t instance)
{
sync.delStpPortState(ifName, instance);
stpSync.delStpPortState(ifName, instance);
}

#if 0
void stpsync_update_vlan_port_state(char * ifName, uint16_t vlan_id, uint8_t state)
{
sync.updateStpVlanPortState(ifName, vlan_id, state);
stpSync.updateStpVlanPortState(ifName, vlan_id, state);
}

void stpsync_del_vlan_port_state(char * ifName, uint16_t vlan_id)
{
sync.delStpVlanPortState(ifName, vlan_id);
stpSync.delStpVlanPortState(ifName, vlan_id);
}
#endif
void stpsync_update_fastage_state(uint16_t vlan_id, bool add)
{
sync.updateStpVlanFastage(vlan_id, add);
stpSync.updateStpVlanFastage(vlan_id, add);
}

void stpsync_update_port_admin_state(char * ifName, bool up, bool physical)
{
sync.updatePortAdminState(ifName, up, physical);
stpSync.updatePortAdminState(ifName, up, physical);
}

uint32_t stpsync_get_port_speed(char * ifName)
{
return sync.getPortSpeed(ifName);
return stpSync.getPortSpeed(ifName);
}

void stpsync_update_bpdu_guard_shutdown(char * ifName, bool enabled)
{
sync.updateBpduGuardShutdown(ifName, enabled);
stpSync.updateBpduGuardShutdown(ifName, enabled);
}

void stpsync_update_port_fast(char * ifName, bool enabled)
{
sync.updatePortFast(ifName, enabled);
stpSync.updatePortFast(ifName, enabled);
}

void stpsync_del_stp_port(char * ifName)
{
sync.delStpInterface(ifName);
stpSync.delStpInterface(ifName);
}

void stpsync_clear_appdb_stp_tables(void)
{
sync.clearAllStpAppDbTables();
stpSync.clearAllStpAppDbTables();
}
}

Expand Down
Loading