LiunxPTP协议栈学习第三章
流程图:
初始化
struct port *port_open(const char *phc_device,
int phc_index,
enum timestamp_type timestamping,
int number,
struct interface *interface,
struct clock *clock)```
```c
if (number && unicast_client_initialize(p)) {
goto err_transport;
}
int unicast_client_initialize(struct port *p)
{
struct unicast_master_address *master, *peer;
struct config *cfg = clock_config(p->clock);
struct unicast_master_table *table;
int table_id;
table_id = config_get_int(cfg, p->name, "unicast_master_table");
if (!table_id) {
return 0;
}
STAILQ_FOREACH(table, &cfg->unicast_master_tables, list) {
if (table->table_index == table_id) {
break;
}
}
if (!table) {
pr_err("port %d: no table with id %d", portnum(p), table_id);
return -1;
}
table = clone_master_table(table);
if (!table) {
pr_err("low memory");
return -1;
}
peer = &table->peer_addr;
if (table->peer_name && str2addr(transport_type(p->trp),
table->peer_name, &peer->address)) {
pr_err("port %d: bad peer address: %s",
portnum(p), table->peer_name);
free_master_table(table);
return -1;
}
STAILQ_FOREACH(master, &table->addrs, list) {
if (master->type != transport_type(p->trp)) {
pr_warning("port %d: unicast master transport mismatch",
portnum(p));
}
if (p->delayMechanism == DM_P2P) {
master->sydymsk = P2P_SYDY_MASK;
} else {
master->sydymsk = E2E_SYDY_MASK;
}
}
table->port = portnum(p);
p->unicast_master_table = table;
p->unicast_req_duration =
config_get_int(cfg, p->name, "unicast_req_duration");
return 0;
}
上述是对单播客户端初始化,首先需要配置table_id,然后我们在配置的单播table表中找到对应的tbale_id对应的参数,这个单播table 表的参数如下所示:
这里主要就是把我们输入的参数绑定到port上。
int unicast_service_initialize(struct port *p)
{
struct config *cfg = clock_config(p->clock);
if (!config_get_int(cfg, p->name, "unicast_listen")) {
return 0;
}
if (config_set_section_int(cfg, p->name, "hybrid_e2e", 1