Package org.ka2ddo.ax25
Class AX25Stack
java.lang.Object
org.ka2ddo.ax25.AX25Stack
- All Implemented Interfaces:
Runnable
,FrameListener
,DebugCtl.DbgListener
This class implements the internal AX.25 (v2.2) protocol stack for a TNC (layer 2), as defined in the
AX.25 Link Access
Protocol for Amateur Packet Radio specification.
It does not implement the level 7 applications or any layer 3 protocols.
- Author:
- Andrew Pavlin, KA2DDO
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Time interval (in milliseconds) to wait for an acknowledgement from the other end of a AX.25 connection. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a listener for incoming AX.25 frames.static void
Register a listener to be informed when AX.25 connected-mode session state changes.void
Register an ParsedAX25MessageListener to be notified of incoming parsed level 3 protocol messages (other than APRS).void
consumeFrame
(AX25Frame frame) Queue one AX.25 frame (containing some sort of message) for parsing and processing.void
consumeFrameNow
(Connector connector, AX25Frame frame) Process an incoming AX.25 frame.static AX25Callsign[]
dupUnuseDigipeaters
(AX25Callsign[] srcRelays) Create a duplicate digipeater list from a source packet, but ensure all the has-been-repeated flags are cleared.void
fireConsumeAX25Frame
(AX25Frame frame, Connector connector) Send the specified incoming frame to all registered AX25FrameListeners.Get the map of all outstanding I-frame connected sessions observed by or end-pointed at this station.static ConnState
getConnState
(AX25Callsign src, AX25Callsign dst, boolean createIfNotPresent) Get the connection state of an I-frame connection session between the specified two callsigns, optionally creating the state object if it did not previously exist.int
Return the current number of backlogged frames to be processed by the AX25Stack thread.static String[]
Get the default list of digipeaters for this stack.static AX25Stack
Get a handle to the AX25Stack singleton.int
Return the maximum backlog ever incurred by the AX25Stack parser thread.int
Return the maximum allowed size of the queue.int
Return the number of AX.25 messages consumed by the AX25Stack.getParser
(byte pid) Get the protocol parsing handler for the specified protocol.static ReschedulableTimer
Get the retransmit timer for outbound AX.25 frames.static ConnState.ConnType
getStateOf
(AX25Callsign src, AX25Callsign dst) Get the connection state of an I-frame connection session between the specified two callsigns.static String
Get the destination callsign (tocall) that should be used for messages originated by this station.static Transmitting
Get the Transmitting object that this AX25Stack will use for implicit but unrouted transmissions.static boolean
Indicate whether this system accepts inbound connected-mode connection requests.boolean
isFrozen()
Report if parser thread is frozen.static boolean
isLocalDest
(String destCallsign) Test if this callsign is addressed to the local station.static boolean
isLocalDest
(AX25Callsign dest) Test if this callsign is addressed to the local station.boolean
processIBody
(AX25Frame frame, boolean isUI, Connector connector, long rcvTimestamp) This method consumes one information frame.void
processParsedAX25Message
(AX25Frame frame, AX25Message parsedMsg) Dispatch an AX.25 frame that was parsed into a higher-level protocol to all registered listeners.void
registerProtocolParser
(byte pid, AX25Parser parser) Register another protocol parsing handler for a particular AX.25 UI/I message PID.void
Remove a listener for incoming AX.25 frames.static void
removeConnState
(ConnState connState) Remove the specified ConnState object from the map of ConnState maps.static void
Unregister a listener to be informed when AX.25 connected-mode session state changes.void
Unregister an ParsedAX25MessageListener to be notified of incoming parsed level 3 protocol messages (other than APRS).static AX25Callsign[]
reverseDigipeaters
(AX25Callsign[] srcRelays) Reverse the order of a sequence of digipeaters (explicit and APRS aliases).void
run()
Private method to asynchronously consume AX25Frame objects for parsing.static void
setAllowInboundConnectedMode
(boolean allowInboundConnects) Specify whether this system accepts inbound connected-mode connection requests.void
Set the handler for inbound connection requests.void
Specify if a specific category of debug messages should be printed out.static void
setDigipeaters
(String[] digipeaters) Set the default list of digipeaters for this stack.void
setFrozen
(boolean frozen) Specify whether the AX.25 parser thread should be paused (frozen) to allow the user to view the output without it moving constantlystatic void
Set the destination callsign (tocall) that should be used for messages originated by this station.static void
setTransmitting
(Transmitting transmitting) Set the Transmitting object that this AX25Stack will use for implicit but unrouted transmissions.
-
Field Details
-
WAIT_FOR_ACK_T1_TIMER
public static final int WAIT_FOR_ACK_T1_TIMERTime interval (in milliseconds) to wait for an acknowledgement from the other end of a AX.25 connection.- See Also:
-
-
Method Details
-
getInstance
Get a handle to the AX25Stack singleton.- Returns:
- AX25Stack instance
-
getDigipeaters
Get the default list of digipeaters for this stack.- Returns:
- array of String digipeater aliases supported by this stack
-
setDigipeaters
Set the default list of digipeaters for this stack.- Parameters:
digipeaters
- array of String digipeater aliases
-
getToCall
Get the destination callsign (tocall) that should be used for messages originated by this station.- Returns:
- destination callsign (tocall)
-
setToCall
Set the destination callsign (tocall) that should be used for messages originated by this station.- Parameters:
toCall
- destination callsign (tocall)
-
setDebug
Specify if a specific category of debug messages should be printed out.- Specified by:
setDebug
in interfaceDebugCtl.DbgListener
- Parameters:
categoryName
- String name of category to enable debug logging forsetting
- boolean true or false to enable or disable debugging this category
-
getTransmitting
Get the Transmitting object that this AX25Stack will use for implicit but unrouted transmissions.- Returns:
- Transmitting object
-
setTransmitting
Set the Transmitting object that this AX25Stack will use for implicit but unrouted transmissions.- Parameters:
transmitting
- Transmitting object
-
getRetransTimer
Get the retransmit timer for outbound AX.25 frames.- Returns:
- ReschedulableTimer
-
isAllowInboundConnectedMode
public static boolean isAllowInboundConnectedMode()Indicate whether this system accepts inbound connected-mode connection requests.- Returns:
- boolean true if inbound connection requests should be accepted
-
setAllowInboundConnectedMode
public static void setAllowInboundConnectedMode(boolean allowInboundConnects) Specify whether this system accepts inbound connected-mode connection requests.- Parameters:
allowInboundConnects
- boolean true if inbound connection requests should be accepted
-
addAX25FrameListener
Add a listener for incoming AX.25 frames.- Parameters:
l
- AX25FrameListener to register
-
removeAX25FrameListener
Remove a listener for incoming AX.25 frames.- Parameters:
l
- AX25FrameListener to unregister
-
setConnectionRequestListener
Set the handler for inbound connection requests.- Parameters:
l
- ConnectionRequestListener to register
-
registerProtocolParser
Register another protocol parsing handler for a particular AX.25 UI/I message PID.- Parameters:
pid
- pid byte code for this protocolparser
- AX25Parser to handle receiving this protocol
-
getParser
Get the protocol parsing handler for the specified protocol.- Parameters:
pid
- level 3 protocol ID byte (as defined by the AX.25 protocol specification)- Returns:
- AX25Parser object, or null if no parser registered for the specified protocol
-
fireConsumeAX25Frame
Send the specified incoming frame to all registered AX25FrameListeners.- Parameters:
frame
- AX25Frame to dispatchconnector
- Connector that received the frame
-
consumeFrame
Queue one AX.25 frame (containing some sort of message) for parsing and processing.- Specified by:
consumeFrame
in interfaceFrameListener
- Parameters:
frame
- the AX25Frame to be processed
-
getCurrentBacklog
public int getCurrentBacklog()Return the current number of backlogged frames to be processed by the AX25Stack thread.- Returns:
- current queue size
-
getMaxBacklog
public int getMaxBacklog()Return the maximum backlog ever incurred by the AX25Stack parser thread.- Returns:
- maximum queue backlog
-
getMaxQueueCapacity
public int getMaxQueueCapacity()Return the maximum allowed size of the queue.- Returns:
- total capacity of the backlog queue
-
getNumConsumedMsgs
public int getNumConsumedMsgs()Return the number of AX.25 messages consumed by the AX25Stack.- Returns:
- count of messages consumed
-
run
public void run()Private method to asynchronously consume AX25Frame objects for parsing. This tries to prevent back-pressuring any sources (particularly fast-moving TCP connections to APRS-IS servers). Can only be executed from the singleton thread created by this class. -
isFrozen
public boolean isFrozen()Report if parser thread is frozen.- Returns:
- boolean true if parser thread is stopped
-
setFrozen
public void setFrozen(boolean frozen) Specify whether the AX.25 parser thread should be paused (frozen) to allow the user to view the output without it moving constantly- Parameters:
frozen
- boolean true to freeze the parser thread, or false to resume execution
-
consumeFrameNow
Process an incoming AX.25 frame.- Parameters:
connector
- Connector that received the frameframe
- AX25Frame to process
-
getConnectionMap
Get the map of all outstanding I-frame connected sessions observed by or end-pointed at this station.- Returns:
- Map by initiating callsign of Maps by destination callsign of connection states
-
getStateOf
Get the connection state of an I-frame connection session between the specified two callsigns.- Parameters:
src
- AX25Callsign of originating end of sessiondst
- AX25Callsign of receiving end of session- Returns:
- ConnType of the session, or ConnType.NONE if there is no such connection session known to this protocol stack
-
getConnState
public static ConnState getConnState(AX25Callsign src, AX25Callsign dst, boolean createIfNotPresent) Get the connection state of an I-frame connection session between the specified two callsigns, optionally creating the state object if it did not previously exist.- Parameters:
src
- AX25Callsign of originating end of sessiondst
- AX25Callsign of receiving end of sessioncreateIfNotPresent
- boolean true if a new ConnState object should be created and registered if it does not already exist- Returns:
- ConnState object for the requested session, or null if no such session exists and the caller did not request creating one
-
removeConnState
Remove the specified ConnState object from the map of ConnState maps. Usually done when a connection is closed.- Parameters:
connState
- ConnState object to remove from map
-
dupUnuseDigipeaters
Create a duplicate digipeater list from a source packet, but ensure all the has-been-repeated flags are cleared.- Parameters:
srcRelays
- array of digipeater callsign-SSID's to clone, or null if none- Returns:
- array of duplicated AX25Callsigns with all has-been-repeated flags cleared, or null if the source array was null or empty
-
reverseDigipeaters
Reverse the order of a sequence of digipeaters (explicit and APRS aliases).- Parameters:
srcRelays
- array of AX25Callsign indicating the path used to get from sender to recipient- Returns:
- array of AX25Callsigns needed to go from recipient back to sender
-
processIBody
This method consumes one information frame. The caller handles any flow control issues for I (versus UI) frames.- Parameters:
frame
- AX25Frame to be decodedisUI
- where frame was received in a UI AX.25 frame instead of an I frameconnector
- PortConnector over which message arrived, or null for file playbackrcvTimestamp
- time (in Java-standard milliseconds since Jan 1 1970 UTC) that message was received- Returns:
- boolean true if message has already been reported to listeners
-
processParsedAX25Message
Dispatch an AX.25 frame that was parsed into a higher-level protocol to all registered listeners.- Parameters:
frame
- AX25Frame of incoming messageparsedMsg
- AX25Message subclass containing protocol decoding of message
-
addParsedAX25MessageListener
Register an ParsedAX25MessageListener to be notified of incoming parsed level 3 protocol messages (other than APRS).- Parameters:
listener
- ParsedAX25MessageListener to register
-
removeParsedAX25MessageListener
Unregister an ParsedAX25MessageListener to be notified of incoming parsed level 3 protocol messages (other than APRS).- Parameters:
listener
- ParsedAX25MessageListener to unregister
-
isLocalDest
Test if this callsign is addressed to the local station.- Parameters:
dest
- AX25Callsign to test as a destination- Returns:
- boolean true if this callsign is for the local station
-
isLocalDest
Test if this callsign is addressed to the local station.- Parameters:
destCallsign
- String of AX.25 callsign-SSID to test as a destination- Returns:
- boolean true if this callsign is for the local station
-
addConnStateChangeListener
Register a listener to be informed when AX.25 connected-mode session state changes.- Parameters:
l
- ConnStateChangeListener to register
-
removeConnStateChangeListener
Unregister a listener to be informed when AX.25 connected-mode session state changes.- Parameters:
l
- ConnStateChangeListener to unregister
-