Skip to content

Commit b60c82b

Browse files
authored
Merge pull request #2286 from ControlSystemStudio/pva_beacons
PVA name search cleanup & doc
2 parents c674ca1 + 31efa93 commit b60c82b

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

core/pva/README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,15 @@ the tools provided by EPICS base:
130130
pvget demo
131131
pvmonitor demo
132132

133+
Protocol Test Tools
134+
-------------------
133135

136+
`pvasearchmonitor` or invoking the phoebus command line with `-main org.epics.pva.server.PVASearchMonitorMain`
137+
starts a tool that periodically lists received search requests.
138+
139+
`pvaclient beacons` or invoking the phoebus command line with `-main org.epics.pva.client.PVAClientMain beacons`
140+
starts a tool that lists received beacons.
141+
134142

135143
API Documentation
136144
-----------------
@@ -146,10 +154,15 @@ PVA Client:
146154

147155
* PVA Server list
148156
* Maintains pool of PVs
149-
* Registers new PVs with ChannelSearch
150-
* ChannelSearch: Exponential backup to ~30 seconds
157+
* Registers new PVs with ChannelSearch, which supports UDP and TCP searches,
158+
i.e. search via broadcast/multicast/unicase or via a name server
159+
* ChannelSearch: Linear backup of 1, 2, 3, .. seconds between repeated
160+
searches, setting to searching once every 30 seconds after about 7 minutes
161+
* Clients monitor beacons. If the search has settled to once every 30 seconds,
162+
any new beacon restarts the linear backup to facilitate faster reconnect.
163+
Beacons are not required for a reconnect, but they may accelerate it
151164
* Forward unicast searches to local multicast group
152-
* Creates TCPHandler when channel found.
165+
* Creates TCPHandler when channel found
153166
* Support "anonymous" or "ca"
154167
(with user from "user.name" property and host from InetAddress.getLocalHost().getHostName())
155168
* Echo test when no new data for a while,
@@ -184,4 +197,5 @@ PVA Server:
184197
TODO:
185198

186199
* Testing
200+
* Implement beacons in server
187201
* Handle fixed size or bounded arrays?

core/pva/src/main/java/org/epics/pva/client/ChannelSearch.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,20 @@ private class SearchedChannel
9898
}
9999
}
100100

101+
// SearchedChannels are tracked in two data structures
102+
//
103+
// - searched_channels (concurrent)
104+
// Fast lookup of channel by ID,
105+
// efficient `computeIfAbsent(cid, ..` mechanism for creating
106+
// at most one SearchedChannel per CID.
107+
// Allows checking if a channel is indeed searched,
108+
// and locating the channel for a search reply.
109+
//
110+
// - search_buckets (need to SYNC)
111+
// Efficiently schedule the search messages for all channels
112+
// up to MAX_SEARCH_PERIOD.
113+
101114
/** Map of searched channels by channel ID */
102-
// TODO Remove, just use search_buckets?
103115
private ConcurrentHashMap<Integer, SearchedChannel> searched_channels = new ConcurrentHashMap<>();
104116

105117
/** Search buckets
@@ -241,12 +253,10 @@ public PVAChannel unregister(final int channel_id)
241253
if (searched != null)
242254
{
243255
logger.log(Level.FINE, () -> "Unregister search for " + searched.channel.getName() + " " + channel_id);
244-
245-
synchronized (search_buckets)
246-
{
247-
for (LinkedList<SearchedChannel> bucket : search_buckets)
248-
bucket.remove(searched);
249-
}
256+
// NOT removing `searched` from all `search_buckets`.
257+
// Removal would be a slow, linear operation.
258+
// `runSearches()` will drop the channel from `search_buckets`
259+
// because it's no longer listed in `searched_channels`
250260

251261
return searched.channel;
252262
}

core/pva/src/main/java/org/epics/pva/common/SearchRequest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,16 @@ public String toString()
8585
public static SearchRequest decode(final InetSocketAddress from, final byte version,
8686
final int payload, final ByteBuffer buffer)
8787
{
88-
if (payload < 4+1+3+16+2+1+4+2)
88+
// pvinfo sends 0x1D=29 bytes:
89+
// Header and flags
90+
// 0000 - CA 02 00 03 1D 00 00 00 00 00 00 00 81 00 00 00 - ................
91+
// Return address
92+
// 0010 - 00 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 00 - ................
93+
// Return port uint16 0xB7C8, byte 0 protocols, uint16 0 channels
94+
// 0020 - C8 B7 00 00 00
95+
// Searches add 4 bytes for protocol (length 3) "tcp",
96+
// plus the list of names.
97+
if (payload < 4+1+3+16+2+1+2)
8998
{
9099
logger.log(Level.WARNING, "PVA client " + from + " sent only " + payload + " bytes for search request");
91100
return null;

0 commit comments

Comments
 (0)