-
Notifications
You must be signed in to change notification settings - Fork 88
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
Backup and restore network #1439
Conversation
@@ -135,10 +147,9 @@ | |||
File file = getFile(address); | |||
|
|||
ZigBeeNodeDao node = null; | |||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"))) { | |||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), CHARSET))) { |
Check warning
Code scanning / CodeQL
Potential input resource leak Warning
@@ -151,10 +162,9 @@ | |||
XStream stream = openStream(); | |||
File file = getFile(node.getIeeeAddress()); | |||
|
|||
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"))) { | |||
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), CHARSET))) { |
Check warning
Code scanning / CodeQL
Potential output resource leak Warning
@@ -173,10 +183,9 @@ | |||
XStream stream = openStream(); | |||
File file = getFile(key); | |||
|
|||
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"))) { | |||
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), CHARSET))) { |
Check warning
Code scanning / CodeQL
Potential output resource leak Warning
XStream stream = openStream(); | ||
File file = getFile(backup.getUuid()); | ||
|
||
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), CHARSET))) { |
Check warning
Code scanning / CodeQL
Potential output resource leak Warning
...zigbee.console.main/src/main/java/com/zsmartsystems/zigbee/console/main/ZigBeeDataStore.java
Fixed
Show fixed
Hide fixed
File file = getFile(uuid); | ||
|
||
ZigBeeNetworkBackupDao backup = null; | ||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), CHARSET))) { |
Check warning
Code scanning / CodeQL
Potential input resource leak Warning
* @param uuid the unique {@link UUID} referencing the backup to restore | ||
* @return | ||
*/ | ||
public boolean restoreBackup(UUID uuid) { |
Check notice
Code scanning / CodeQL
Useless parameter Note
* @param networkAddress the address to set | ||
* @return true if the address was set | ||
*/ | ||
default boolean setNwkAddress(int networkAddress) { |
Check notice
Code scanning / CodeQL
Useless parameter Note
8561dea
to
5d07e9f
Compare
com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/ZigBeeNetworkManager.java
Outdated
Show resolved
Hide resolved
com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/ZigBeeNetworkManager.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Chris Jackson <chris@cd-jackson.com>
Signed-off-by: Chris Jackson <chris@cd-jackson.com>
Signed-off-by: Chris Jackson <chris@cd-jackson.com>
Signed-off-by: Chris Jackson <chris@cd-jackson.com>
02152a1
to
109d174
Compare
This adds a more complete backup and restore implementation. Previously managing the node XML files was problematic since the library manages these files, meaning the user application couldn’t easily modify or replace them while the network was running. Conversely, replacing them with the network offline was problematic since the user much call
ZigBeeNetworkManager.startup(true)
to initialise the network, and this will remove all nodes and their XML files.With this PR, the backup information is now serialised as a single entity through the
ZigBeeDataStore
. New methods to backup and restore have been added to theZigBeeNetworkManager
that manage the removal of nodes, and initialisation of the system in the correct order.Summary of Changes at user level
ZigBeeNetworkDataStore
has the following new methods -:boolean writeBackup(ZigBeeNetworkBackupDao backup)
- the user MUST implement this method to store a backup.ZigBeeNetworkBackupDao readBackup(UUID uuid)
- the user MUST implement this method to read a backup from the store.Set<ZigBeeNetworkBackupDao> listBackups()
- the user MAY implement this method to read all the current backups. This is currently only used in the console so users implementing their own system may not require this.ZigBeeNetworkManager
has the following new methods -:UUID createBackup()
- creates a backup of the current network. This will store all data, including the network configuration (eg keys, channel, PANID etc) and the devices attached to the network, and returns aUUID
identifying the backup. Serialisation of the data is through theZigBeeNetworkDataStore.writeBackup
method.ZigBeeStatus restoreBackup(UUID uuid)
- restores a backup given theUUID
. This will read data from the data store using theZigBeeNetworkDataStore.readBackup
method, and will restore all nodes, and reconfigure the coordinator. This has been tested when running with an existing network - calling at other times may require further updates.Dongle changes
The following changes are made that do not directly impact users, but are added to lower level interfaces toward the coordinator -:
ZigBeeTransportTransmit
ZigBeeStatus setNetworkState(ZigBeeNetworkState networkState)
- this method allows theZigBeeNetworkManager
to take the coordinator offline during the restoration of a backup.boolean setIeeeAddress(IeeeAddress ieeeAddress)
- this method allows theZigBeeNetworkManager
to set theIeeeAddress
of the coordinator.boolean setNwkAddress(int networkAddress)
- this method allows theZigBeeNetworkManager
to set the network Address of the coordinator. Note that this is not used at this time, but was added to the interface for completeness.Note that this PR only adds this support to the
ZigBeeDongleEzsp
implementation (ie Silabs Ember / Gecko chipset).There is a limitation that the IEEE address can only be written to NVRAM once after which the token area needs erasing. Silabs introduced a function to do this in or around version 7.3 or 7.4. This is function ID 0x77, but in earlier versions of EZSP (prior to 7 I think) this ID was allocated to
becomeTrustCenter
. This PR removes thebecomeTrustCenter
function (it was not used in the library) and adds thetokenFactoryReset
function as0x77
. Further work may be need for this to work on older firmware (if it’s even possible).If the IEEE address doesn’t change (which should be the case if the network is backed up / restored using the same physical coordinator) then this will still work fine.
Console Application
The
netback
console command now hasbackup
,restore UUID
andlist
subcommands to manage backups. These are reasonably self explanatory and simply call the above methods in theZigBeeNetworkManager
.