~ubuntu-branches/ubuntu/saucy/nut/saucy

« back to all changes in this revision

Viewing changes to docs/design.txt

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2005-07-20 19:48:50 UTC
  • mto: (16.1.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20050720194850-oo61wjr33rrx2mre
Tags: upstream-2.0.2
ImportĀ upstreamĀ versionĀ 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
Desc: Network UPS Tools design document
2
2
File: design.txt
3
 
Date: 30 April 2003
 
3
Date: 14 March 2004
4
4
Auth: Russell Kroll <rkroll@exploits.org>
5
5
 
6
 
Here is the general layout for the software.  It has a layered scheme,
7
 
in which clients, the server, and the drivers are separated.  Layers 
8
 
communicate with each other using an agreed-upon protocol.
 
6
This software is designed around a layered scheme with drivers, a 
 
7
server and clients.   These layers communicate with text-based
 
8
protocols for easier maintenance and diagnostics.
9
9
 
10
10
The layering
11
11
============
39
39
---------------
40
40
 
41
41
The core of all DRIVERS maintains internal storage for every variable
42
 
that is known, and all of the auxiliary data for those variables.  It
 
42
that is known along with the auxiliary data for those variables.  It 
43
43
sends updates to this data to any process which connects to the Unix
44
44
domain socket.
45
45
 
46
 
The DRIVERS will also provide a full copy of their internal knowledge
47
 
upon receiving the "DUMPALL" command on the socket.  The dump is in the
48
 
same format as updates, and is followed by "DUMPDONE".  When "DUMPDONE"
49
 
has been received, the view is complete.
 
46
The DRIVERS will also provide a full atomic copy of their internal
 
47
knowledge upon receiving the "DUMPALL" command on the socket.  The dump
 
48
is in the same format as updates, and is followed by "DUMPDONE".  When
 
49
"DUMPDONE" has been received, the view is complete.
50
50
 
51
51
The SERVER will connect to the socket of each DRIVER and will request a
52
52
dump at that time.  It retains this data in local storage for later use.
53
 
It continues to listen on the socket for additional updates .
 
53
It continues to listen on the socket for additional updates.
54
54
 
55
55
This protocol is documented in sock-protocol.txt.
56
56
 
69
69
================
70
70
 
71
71
Instant commands is the term given to a set of actions that result in
72
 
something happening to the UPS.  Some of the common ones are BTEST1 to
73
 
initiate a battery test and FPTEST to test the front panel of the UPS.
 
72
something happening to the UPS.  Some of the common ones are
 
73
test.battery.start to initiate a battery test and test.panel.start to
 
74
test the front panel of the UPS.
74
75
 
75
76
They are passed to the SERVER from a CLIENT using an authenticated
76
77
network connection.  The SERVER first checks to make sure that the instant
79
80
information.
80
81
 
81
82
At this point, there is no confirmation to the SERVER of the command's
82
 
execution.  This is planned for a future release.  This has been delayed
83
 
since returning a response involves some potentially interesting timing
84
 
issues.  Remember that upsd services clients in a round-robin fashion,
85
 
so all queries must be lightweight and speedy.
 
83
execution.  This is (still) planned for a future release.  This has been
 
84
delayed since returning a response involves some potentially interesting
 
85
timing issues.  Remember that upsd services clients in a round-robin
 
86
fashion, so all queries must be lightweight and speedy.
86
87
 
87
88
Setting variables
88
89
=================
89
90
 
90
 
Some variables in the DRIVER can be changed, and carry the FLAG_RW flag.
91
 
Upon receiving a SET command from the CLIENT, the SERVER first verifies
92
 
that it is valid for that DRIVER in terms of writability and data type.
93
 
If those checks pass, it then sends the SET command through the socket,
94
 
much like the instant command design.
 
91
Some variables in the DRIVER or EQUIPMENT can be changed, and carry the
 
92
FLAG_RW flag.  Upon receiving a SET command from the CLIENT, the SERVER
 
93
first verifies that it is valid for that DRIVER in terms of writability
 
94
and data type.  If those checks pass, it then sends the SET command
 
95
through the socket, much like the instant command design.
95
96
 
96
97
The DRIVER is expected to commit the value to the EQUIPMENT and update
97
98
its internal representation of that variable.
109
110
 
110
111
1. EQUIPMENT reports on battery by setting flag in status register
111
112
 
112
 
2. DRIVER notices this flag and stores it in the status variable as
 
113
2. DRIVER notices this flag and stores it in the ups.status variable as
113
114
   OB.  This update gets pushed out to any listeners via the sockets.
114
115
 
115
116
3. SERVER upsd sees activity on the socket, reads it, parses it, and 
116
117
   commits the new data to its local version of the status variable. 
117
118
 
118
 
4. CLIENT upsmon does a routine poll of SERVER for "STATUS" and gets "OB".
 
119
4. CLIENT upsmon does a routine poll of SERVER for "ups.status" and
 
120
   gets "OB".
119
121
 
120
122
5. CLIENT upsmon then invokes its NOTIFYCMD which is upssched.
121
123
 
140
142
 
141
143
        [myups]
142
144
                driver = upsdriver
143
 
                port = /dev/port
 
145
                port = /dev/ttySx
144
146
 
145
147
3. upsd has a valid user for upsmon in upsd.users.
146
148
 
178
180
History
179
181
=======
180
182
 
181
 
Very old versions of this software only supported the notion of state
182
 
files.  Status was written into a static array ("the info array") by
183
 
drivers, and that array was stored on disk.  upsd would periodically
184
 
read that file into a local copy of that array.
 
183
The oldest versions of this software (1998) had no separation between
 
184
the driver and the network server and only supported the latest APC
 
185
Smart-UPS hardware as a result.  The network protocol used brittle
 
186
binary structs.  This had numerous bad implications for compatibility
 
187
and portability.
 
188
 
 
189
After the driver and server were separated, data was shared through the
 
190
state file concept.  Status was written into a static array (the "info
 
191
array") by drivers, and that array was stored on disk.  upsd would
 
192
periodically read that file into a local copy of that array.
185
193
 
186
194
Shared memory mode was added a bit later, and that removed some of the
187
195
lag from the status updates.  Unfortunately, it didn't have any locking