port: Provide methods to set and get the link status.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2016-07-30 15:03:48 +02:00
parent e995cf7f52
commit 5e3156da15
2 changed files with 27 additions and 0 deletions

13
port.c
View File

@ -117,6 +117,7 @@ struct port {
int path_trace_enabled;
int rx_timestamp_offset;
int tx_timestamp_offset;
int link_status;
struct fault_interval flt_interval_pertype[FT_CNT];
enum fault_type last_fault_type;
unsigned int versionNumber; /*UInteger4*/
@ -2357,6 +2358,17 @@ int port_number(struct port *p)
return portnum(p);
}
int port_link_status_get(struct port *p)
{
return p->link_status;
}
void port_link_status_set(struct port *p, int up)
{
p->link_status = up ? 1 : 0;
pr_notice("port %hu: link %s", portnum(p), up ? "up" : "down");
}
int port_manage(struct port *p, struct port *ingress, struct ptp_message *msg)
{
struct management_tlv *mgt;
@ -2573,6 +2585,7 @@ struct port *port_open(int phc_index,
p->path_trace_enabled = config_get_int(cfg, p->name, "path_trace_enabled");
p->rx_timestamp_offset = config_get_int(cfg, p->name, "ingressLatency");
p->tx_timestamp_offset = config_get_int(cfg, p->name, "egressLatency");
p->link_status = 1;
p->clock = clock;
p->trp = transport_create(cfg, transport);
if (!p->trp)

14
port.h
View File

@ -126,6 +126,20 @@ struct PortIdentity port_identity(struct port *p);
*/
int port_number(struct port *p);
/**
* Obtain the link status of a port.
* @param p A port instance.
* @return One (1) if the link is up, zero otherwise.
*/
int port_link_status_get(struct port *p);
/**
* Sets the link status for a port.
* @param p A port instance.
* @param up Pass one (1) if the link is up and zero if down.
*/
void port_link_status_set(struct port *p, int up);
/**
* Manage a port according to a given message.
* @param p A pointer previously obtained via port_open().