Avnu / OpenAvnu

OpenAvnu - an Avnu sponsored repository for Time Sensitive Network (TSN and AVB) technology
464 stars 289 forks source link

Piority1 cannot be set by daemon_cl -f gptpcfg.ini #803

Open LancyYan opened 6 years ago

LancyYan commented 6 years ago

Hi,

I tried to set priority1 = 10 inside gptpcfg.ini file, with command "daemon_cl eth0 -f gptpcfg.ini", but it cannot take effect and still remain the default priority1 =248. Can you help me with this?

[ptp]

# Priority1 value
# It can assume values between 0 and 255.
# The lower the number, the higher the priority for the BMCA.
priority1 = 10

https://github.com/AVnu/OpenAvnu/blob/master/daemons/gptp/gptp_cfg.ini

Thanks, Lancy

pinealservo commented 6 years ago

I think there may still be some issues with the way various configuration methods for gptp work together.

I just checked the code; there's unfortunately a conflict with the order that things are initialized in the Linux daemon code such that the priority1 value read from the config file can't be used because that part of the code is initialized before the config file is even read.

At the moment, the only way to set the priority1 value is with the -R command line flag.

If you wanted to try to fix it, the relevant code is here: https://github.com/AVnu/OpenAvnu/blob/master/daemons/gptp/linux/src/daemon_cl.cpp

The pClock variable gets the freshly created IEEE1588Clock value based on the priority1 read from the command line in the statement starting on line 378, while the block starting on 401 is what reads the config file. You'll see there are a couple of other options read and even printed out there that aren't actually used.

I don't remember if there's a reason the config file isn't read before the IEEE1588Clock is created, but if there's no reason for it then it's probably possible to just move the whole if(use_config_file) section to right before where pClock is set, and then the priority1 variable can be set to the value read from the config file.

One caveat there is that if anyone currently has a their gptp startup script setting the priority1 value on the command line but also has a different priority1 left in the config file, just moving the code so that the config file works would break that setup; the config file would take priority over the command line. If you decide to fix this, you might want to set a flag if priority1 is set via the command line so that it's not set by the config file in that case.