https://github.com/opencomputeproject/SAI
The Switch Abstraction Interface defines the API to provide a vendor-independent way of controlling forwarding elements, such as a switching ASIC, an NPU or a software switch in a uniform manner.
简单理解,SAI是对转发芯片进行一层功能抽象,SDK为每个模块(如VLAN/PORT/FDB等)提供一组函数集,API通过函数集调用SDK接口从而实现转发面的配置管理;另外实现了一套事件处理回调处理。
不足之处:
1)转发芯片功能抽象不稳定,导致接口或参数频繁变化
2)无协议报文处理模块
3)事件处理功能不完整
4)函数集居然不是注册方式
1、main(saiserver.cpp)
1)创建转发芯片:create_switch
sai_api_query(SAI_API_SWITCH, (void**)&sai_switch_api);
attr[0].id = SAI_SWITCH_ATTR_INIT_SWITCH;
attr[0].value.booldata = true;
attr[1].id = SAI_SWITCH_ATTR_SWITCH_STATE_CHANGE_NOTIFY;
attr[1].value.ptr = reinterpret_cast<sai_pointer_t>(&on_switch_state_change); //注册事件处理函数
attr[2].id = SAI_SWITCH_ATTR_SHUTDOWN_REQUEST_NOTIFY;
attr[2].value.ptr = reinterpret_cast<sai_pointer_t>(&on_shutdown_request);
attr[3].id = SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY;
attr[3].value.ptr = reinterpret_cast<sai_pointer_t>(&on_fdb_event);
attr[4].id = SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY;
attr[4].value.ptr = reinterpret_cast<